Skip to main content

RebasingERC20

Git Source

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

NameTypeDescription
name_stringThe name of the token
symbol_stringThe symbol of the token
decimalsOffset_uint8The 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

NameTypeDescription
<none>uint256The 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

NameTypeDescription
sharesuint256The amount of shares

Returns

NameTypeDescription
<none>uint256The 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

NameTypeDescription
assetsuint256The amount of underlying token

Returns

NameTypeDescription
<none>uint256The 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;