RebasingERC20
Inherits: Context, IRebasingERC20, IERC20Metadata, IERC20Errors, ERC20Permit
Title: RebasingERC20
Author: Socks&Flops
Implementation of the {IRebasingERC20} interface.
State Variables
sharesOf
mapping(address account => uint256 shares) public override sharesOf
totalShares
The total amount of the shares token
uint256 public override totalShares
decimalsOffset
The decimals offset. The number of decimals to offset the shares by. Used to protect against inflation attacks.
uint8 public immutable override decimalsOffset
Functions
constructor
Constructor
constructor(string memory name_, string memory symbol_, uint8 decimalsOffset_)
ERC20(name_, symbol_)
ERC20Permit(name_);
Parameters
| Name | Type | Description |
|---|---|---|
name_ | string | The name of the token |
symbol_ | string | The symbol of the token |
decimalsOffset_ | uint8 | The number of decimals to pad the internal shares with to avoid precision loss |
_totalSupply
Internal function to get the total supply of the token
function _totalSupply() internal view virtual returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The total supply of the token |
totalSupply
Returns the value of tokens in existence.
function totalSupply() public view virtual override(ERC20, IERC20) returns (uint256);
convertToAssets
Converts the amount of shares to the corresponding amount of underlying token
function convertToAssets(uint256 shares) public view virtual returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
shares | uint256 | The amount of shares |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The corresponding amount of underlying token |
convertToShares
Converts the amount of underlying token to the corresponding amount of shares
function convertToShares(uint256 assets) public view virtual returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
assets | uint256 | The amount of underlying token |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The corresponding amount of shares |
balanceOf
Returns the value of tokens owned by account.
function balanceOf(address account) public view virtual override(ERC20, IERC20) returns (uint256);
_update
Modification of OZ:ERC20:_update. Manipulates shares instead of fixed balances
function _update(address from, address to, uint256 value) internal virtual override;