UsdnNoRebase
Inherits: IUsdn, ERC20Permit, ERC20Burnable, Ownable
The USDN token supports the USDN Protocol. It is minted when assets are deposited into the USDN Protocol vault and burned when withdrawn. While the original USDN token implement rebases to inflates its supply to stay as close to a certain price as possible, this version removes all of this logic to be used with a protocol that does not have any target price.
As rebasing is completely disabled, 1 share always equals to 1 token, and the divisor never changes.
State Variables
MINTER_ROLE
Gets the minter role signature.
Only here to match the IUsdn
interface, this contract uses Ownable
instead.
bytes32 public constant MINTER_ROLE = "";
REBASER_ROLE
Gets the rebaser role signature.
Only here to match the IUsdn
interface, this contract uses Ownable
instead.
bytes32 public constant REBASER_ROLE = "";
MAX_DIVISOR
Gets the maximum value of the divisor, which is also the initial value.
Only here to match the IUsdn
interface, this contract does not use shares.
uint256 public constant MAX_DIVISOR = 1;
MIN_DIVISOR
Gets the minimum acceptable value of the divisor.
Only here to match the IUsdn
interface, this contract does not use shares.
uint256 public constant MIN_DIVISOR = 1;
Functions
constructor
constructor(string memory name, string memory symbol) ERC20(name, symbol) ERC20Permit(name) Ownable(msg.sender);
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the ERC20 token. |
symbol | string | The symbol of the ERC20 token. |
nonces
Returns the current nonce for owner
. This value must be
included whenever a signature is generated for {permit}.
Every successful call to {permit} increases owner
's nonce by one. This
prevents a signature from being used multiple times.
function nonces(address owner) public view override(IERC20Permit, ERC20Permit) returns (uint256);
burn
Destroys a value
amount of tokens from the caller, reducing the total supply.
function burn(uint256 value) public override(ERC20Burnable, IUsdn);
Parameters
Name | Type | Description |
---|---|---|
value | uint256 | Amount of tokens to burn, is internally converted to the proper shares amounts. |
burnFrom
Destroys a value
amount of tokens from account
, deducting from the caller's allowance.
function burnFrom(address account, uint256 value) public override(ERC20Burnable, IUsdn);
Parameters
Name | Type | Description |
---|---|---|
account | address | Account to burn tokens from. |
value | uint256 | Amount of tokens to burn, is internally converted to the proper shares amounts. |
sharesOf
Returns the number of shares owned by account
.
function sharesOf(address account) public view returns (uint256 shares_);
Parameters
Name | Type | Description |
---|---|---|
account | address | The account to query. |
Returns
Name | Type | Description |
---|---|---|
shares_ | uint256 | The number of shares. |
totalShares
Returns the total number of shares in existence.
function totalShares() external view returns (uint256 shares_);
Returns
Name | Type | Description |
---|---|---|
shares_ | uint256 | The number of shares. |
convertToTokens
Converts a number of shares to the corresponding amount of tokens.
The conversion never overflows as we are performing a division. The conversion rounds to the nearest amount of tokens that minimizes the error when converting back to shares.
function convertToTokens(uint256 amountShares) external pure returns (uint256 tokens_);
Parameters
Name | Type | Description |
---|---|---|
amountShares | uint256 | The amount of shares to convert to tokens. |
Returns
Name | Type | Description |
---|---|---|
tokens_ | uint256 | The corresponding amount of tokens. |
convertToTokensRoundUp
Converts a number of shares to the corresponding amount of tokens, rounding up.
Use this function to determine the amount of a token approval, as we always round up when deducting from a token transfer allowance.
function convertToTokensRoundUp(uint256 amountShares) external pure returns (uint256 tokens_);
Parameters
Name | Type | Description |
---|---|---|
amountShares | uint256 | The amount of shares to convert to tokens. |
Returns
Name | Type | Description |
---|---|---|
tokens_ | uint256 | The corresponding amount of tokens, rounded up. |
convertToShares
Converts a number of tokens to the corresponding amount of shares.
The conversion reverts with UsdnMaxTokensExceeded
if the corresponding amount of shares overflows.
function convertToShares(uint256 amountTokens) public pure returns (uint256 shares_);
Parameters
Name | Type | Description |
---|---|---|
amountTokens | uint256 | The amount of tokens to convert to shares. |
Returns
Name | Type | Description |
---|---|---|
shares_ | uint256 | The corresponding amount of shares. |
divisor
Gets the current value of the divisor that converts between tokens and shares.
function divisor() external pure returns (uint256 divisor_);
Returns
Name | Type | Description |
---|---|---|
divisor_ | uint256 | The current divisor. |
rebaseHandler
Gets the rebase handler address, which is called whenever a rebase happens.
function rebaseHandler() external pure returns (IRebaseCallback);
Returns
Name | Type | Description |
---|---|---|
<none> | IRebaseCallback | rebaseHandler_ The rebase handler address. |
maxTokens
Returns the current maximum tokens supply, given the current divisor.
This function is used to check if a conversion operation would overflow.
function maxTokens() public pure returns (uint256 maxTokens_);
Returns
Name | Type | Description |
---|---|---|
maxTokens_ | uint256 | The maximum number of tokens that can exist. |
transferShares
Transfers a given amount of shares from the msg.sender
to to
.
function transferShares(address to, uint256 value) external returns (bool success_);
Parameters
Name | Type | Description |
---|---|---|
to | address | Recipient of the shares. |
value | uint256 | Number of shares to transfer. |
Returns
Name | Type | Description |
---|---|---|
success_ | bool | Indicates whether the transfer was successfully executed. |
transferSharesFrom
Transfers a given amount of shares from the from
to to
.
There should be sufficient allowance for the spender. Be mindful of the rebase logic. The allowance is in
tokens. So, after a rebase, the same amount of shares will be worth a higher amount of tokens. In that case,
the allowance of the initial approval will not be enough to transfer the new amount of tokens. This can
also happen when your transaction is in the mempool and the rebase happens before your transaction. Also note
that the amount of tokens deduced from the allowance is rounded up, so the convertToTokensRoundUp
function
should be used when converting shares into an allowance value.
function transferSharesFrom(address from, address to, uint256 value) external returns (bool success_);
Parameters
Name | Type | Description |
---|---|---|
from | address | The owner of the shares. |
to | address | Recipient of the shares. |
value | uint256 | Number of shares to transfer. |
Returns
Name | Type | Description |
---|---|---|
success_ | bool | Indicates whether the transfer was successfully executed. |
burnShares
Destroys a value
amount of shares from the caller, reducing the total supply.
function burnShares(uint256 value) external;
Parameters
Name | Type | Description |
---|---|---|
value | uint256 | Amount of shares to burn. |
burnSharesFrom
Destroys a value
amount of shares from account
, deducting from the caller's allowance.
There should be sufficient allowance for the spender. Be mindful of the rebase logic. The allowance is in
tokens. So, after a rebase, the same amount of shares will be worth a higher amount of tokens. In that case,
the allowance of the initial approval will not be enough to transfer the new amount of tokens. This can
also happen when your transaction is in the mempool and the rebase happens before your transaction. Also note
that the amount of tokens deduced from the allowance is rounded up, so the convertToTokensRoundUp
function
should be used when converting shares into an allowance value.
function burnSharesFrom(address account, uint256 value) public;
Parameters
Name | Type | Description |
---|---|---|
account | address | Account to burn shares from. |
value | uint256 | Amount of shares to burn. |
mint
Mints new shares, providing a token value.
Caller must have the MINTER_ROLE.
function mint(address to, uint256 amount) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
to | address | Account to receive the new shares. |
amount | uint256 | Amount of tokens to mint, is internally converted to the proper shares amounts. |
mintShares
Mints new shares, providing a share value.
Caller must have the MINTER_ROLE.
function mintShares(address to, uint256 amount) external onlyOwner returns (uint256 mintedTokens_);
Parameters
Name | Type | Description |
---|---|---|
to | address | Account to receive the new shares. |
amount | uint256 | Amount of shares to mint. |
Returns
Name | Type | Description |
---|---|---|
mintedTokens_ | uint256 | Amount of tokens that were minted (informational). |
rebase
Decreases the global divisor, which effectively grows all balances and the total supply.
If the provided divisor is larger than or equal to the current divisor value, no rebase will happen
If the new divisor is smaller than MIN_DIVISOR
, the value will be clamped to MIN_DIVISOR
.
Caller must have the REBASER_ROLE
.
function rebase(uint256) external pure returns (bool rebased_, uint256 oldDivisor_, bytes memory callbackResult_);
Parameters
Name | Type | Description |
---|---|---|
<none> | uint256 |
Returns
Name | Type | Description |
---|---|---|
rebased_ | bool | Whether a rebase happened. |
oldDivisor_ | uint256 | The previous value of the divisor. |
callbackResult_ | bytes | The result of the callback, if a rebase happened and a callback handler is defined. |
setRebaseHandler
Sets the rebase handler address.
Emits a RebaseHandlerUpdated
event.
If set to the zero address, no handler will be called after a rebase.
Caller must have the DEFAULT_ADMIN_ROLE
.
function setRebaseHandler(IRebaseCallback) external pure;
Parameters
Name | Type | Description |
---|---|---|
<none> | IRebaseCallback |