UsdnNoRebase

Git Source

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

NameTypeDescription
namestringThe name of the ERC20 token.
symbolstringThe 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

NameTypeDescription
valueuint256Amount 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

NameTypeDescription
accountaddressAccount to burn tokens from.
valueuint256Amount 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

NameTypeDescription
accountaddressThe account to query.

Returns

NameTypeDescription
shares_uint256The number of shares.

totalShares

Returns the total number of shares in existence.

function totalShares() external view returns (uint256 shares_);

Returns

NameTypeDescription
shares_uint256The 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

NameTypeDescription
amountSharesuint256The amount of shares to convert to tokens.

Returns

NameTypeDescription
tokens_uint256The 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

NameTypeDescription
amountSharesuint256The amount of shares to convert to tokens.

Returns

NameTypeDescription
tokens_uint256The 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

NameTypeDescription
amountTokensuint256The amount of tokens to convert to shares.

Returns

NameTypeDescription
shares_uint256The 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

NameTypeDescription
divisor_uint256The current divisor.

rebaseHandler

Gets the rebase handler address, which is called whenever a rebase happens.

function rebaseHandler() external pure returns (IRebaseCallback);

Returns

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

NameTypeDescription
maxTokens_uint256The 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

NameTypeDescription
toaddressRecipient of the shares.
valueuint256Number of shares to transfer.

Returns

NameTypeDescription
success_boolIndicates 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

NameTypeDescription
fromaddressThe owner of the shares.
toaddressRecipient of the shares.
valueuint256Number of shares to transfer.

Returns

NameTypeDescription
success_boolIndicates 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

NameTypeDescription
valueuint256Amount 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

NameTypeDescription
accountaddressAccount to burn shares from.
valueuint256Amount 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

NameTypeDescription
toaddressAccount to receive the new shares.
amountuint256Amount 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

NameTypeDescription
toaddressAccount to receive the new shares.
amountuint256Amount of shares to mint.

Returns

NameTypeDescription
mintedTokens_uint256Amount 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

NameTypeDescription
<none>uint256

Returns

NameTypeDescription
rebased_boolWhether a rebase happened.
oldDivisor_uint256The previous value of the divisor.
callbackResult_bytesThe 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

NameTypeDescription
<none>IRebaseCallback