Tokenisation
Last updated
Was this helpful?
Last updated
Was this helpful?
The yield-generating, tokenized representation of supplies used throughout the Nexus protocol. They implement most of the standard EIP-20/ERC20 token methods with slight modifications, as well as Nexus-specific methods including:
scaledBalanceOf()
getScaledUserBalanceAndSupply()
scaledTotalSupply()
All zTokens also implement EIP-2612, which via the permit() function enables single transaction approve + actions.
zTokens are tokens minted and burnt upon supply and withdraw of assets to an Nexus market. zTokens denote the amount of crypto assets supplied to the protocol and the yield earned on those assets. The zTokens’ value is pegged to the value of the corresponding supplied asset at a 1:1 ratio and can be safely stored, transferred or traded. All yield collected by the zTokens' reserves are distributed to zToken holders directly by continuously increasing their wallet balance.
This contract is the implementation of the interest bearing token for the Nexus Protocol. It inherits the and token contracts.
All standard EIP20 methods are implemented for zTokens, such as balanceOf, transfer, transferFrom, approve, totalSupply etc.
balanceOf will always return the most up to date balance of the user, which includes their principal balance and the yield generated by the principal balance.
The source code is available on .
Called when zToken instance is initialized.
Input Parameters:
initializingPool
IPool
The address of the associated pool
treasury
address
The address of the treasury
underlyingAsset
address
The address of the underlying asset
incentivesController
IAaveIncentivesController
The address of the incentives controller for this zToken
zTokenDecimals
uint8
The decimals of the underlying asset
zTokenName
string
The name of the zToken
zTokenSymbol
string
The symbol of the zToken
params
bytes
A set of encoded parameters for additional initialization
Mints amount zTokens to user.
Input Parameters:
caller
address
The address performing the mint
onBehalfOf
address
The address of the user that will receive the minted zTokens
amount
uint256
The amount of tokens getting minted
index
uint256
The next liquidity index of the reserve
Return Values:
bool
true if the the previous balance of the user was 0
Burns zTokens from user and sends the equivalent amount of underlying to receiverOfUnderlying.
In some instances, the mint event could be emitted from a burn transaction if the amount to burn is less than the interest that the user accrued.
Input Parameters:
from
address
The address from which the zTokens will be burned
receiverOfUnderlying
address
The address that will receive the underlying asset
amount
uint256
The amount of tokens that will be burned
index
uint256
The next liquidity index of the reserve
Mints zTokens to the reserve treasury.
Input Parameters:
amount
uint256
The amount of tokens getting minted
index
uint256
The address that will receive the underlying asset
Transfers zTokens in the event of a borrow being liquidated, in case the liquidator reclaims the zToken.
Input Parameters:
from
address
The address getting liquidated, current owner of the zTokens
to
address
The recipient of zTokens
value
uint256
The amount of tokens getting transferred
Transfers the underlying asset to target.
Input Parameters:
user
address
The recipient of the underlying
amount
uint256
The amount getting transferred
Handles the underlying received by the zToken after the transfer has been completed.
The default implementation is empty as with standard ERC20 tokens, nothing needs to be done after the transfer is concluded. However in the future there may be zTokens that allow for example to stake the underlying to receive LM rewards. In that case, handleRepayment() would perform the staking of the underlying asset.
Input Parameters:
user
address
The user executing the repayment
onBehalfOf
address
`
The address for which the borrow position is repaid
amount
uint256
The amount getting repaid
Allows a user to permit another account (or contract) to use their funds using a signed message. This enables gas-less transactions and single approval/transfer transactions. Allow passing a signed message to approve spending.
Implements the permit function as for EIP-2612.
Input Parameters:
owner
address
The owner of the funds
spender
address
The spender of the funds
value
uint256
The amount the spender is permitted to spend
deadline
uint256
The deadline timestamp, use type(uint256).max for max/no deadline
v
uint8
The V signature parameter
r
bytes32
The R signature parameter
s
bytes32
The S signature parameter
Example of signing and utilizing permit:
Rescue and transfer tokens locked in this contract. Only callable by POOL_ADMIN.
Input Parameters:
token
address
The address of the token
to
address
The address of the recipient
amount
uint256
The amount of token to transfer
Returns the amount of tokens owned by user.
Overrides the base function.
Input Parameters:
user
address
The address of the user
Return Values:
uint256
The amount of tokens owned by user
Returns the amount of tokens in existence.
Overrides the base function.
Return Values:
uint256
The amount of tokens in existence
Returns the address of the Aave treasury, controlled by governance, receiving the fees on this zToken.
Return Values:
address
The address of the Aave treasury
Returns the address of the underlying reserve asset of this zToken (E.g. WETH for zWETH).
Return Values:
address
The address of the underlying asset
Get the domain separator for the token at the current chain.
Return cached value if chainId matches cache, otherwise recomputes separator.
Overrides the base function to fully implement IAToken.
Return Values:
bytes32
The domain separator of the token at current chain
Returns the nonce value for address specified as parameter. This is the nonce used when calling permit().
Overrides the base function to fully implement IAToken.
Input Parameters:
owner
address
The address of the owner
Return Values:
uint256
The nonce of the owner
Example:
Returns the revision number of the contract. Needs to be defined in the inherited class as a constant.
Returns 0x1.
Return Values:
uint256
The revision number
The tokenized borrow positions used throughout the Nexus protocol. Most of the standard EIP-20/ERC20 methods are disabled since debt tokens are non-transferrable.
Implements a variable debt token to track the borrowing positions of users at variable rate mode.
transfer and approve functionalities are disabled as variable debt tokens are non-transferable.
The vToken value is pegged 1:1 to the value of underlying borrowed asset and represents the current total amount owed to the protocol i.e. principal debt + interest accrued.
The VariableDebtToken contract inherits the DebtTokenBase and ScaledBalanceTokenBase token contracts.
The source code is available on GitHub.
Called when variableDebtToken instance is initialised.
Input Parameters:
initializingPool
IPool
The pool contract that is initializing this contract
underlyingAsset
address
The address of the underlying asset of this zToken (E.g. WETH for zWETH)
incentivesController
IAaveIncentivesController
The smart contract managing potential incentives distribution
debtTokenDecimals
uint8
The decimals of the variableDebtToken, same as the underlying asset's
debtTokenName
string
The name of the variable debt token
debtTokenSymbol
string
The symbol of the variable debt token
params
bytes
A set of encoded parameters for additional initialization
Mints the variable debt token to the onBehalfOf address.
Input Parameters:
user
address
The address receiving the borrowed underlying, being the delegatee in case of credit delegate, or same as onBehalfOf otherwise
onBehalfOf
address
The address receiving the variable debt tokens
amount
uint256
The amount of variable debt tokens to mint
index
uint256
The variable debt index of the reserve
Return Values:
bool
true if the previous balance of the user is 0, false otherwise
uint256
The scaled total debt of the reserve
Burns user variable debt.
In some instances, a burn transaction will emit a mint event if the amount to burn is less than the interest that the user accrued.
Input Parameters:
from
address
The address from which the debt will be burned
amount
uint256
The amount of debt tokens that will be burned
index
uint256
The variable debt index of the reserve
Return Values:
uint256
The scaled total debt of the reserve
Returns the address of the underlying asset of this variableDebtToken (e.g. WETH for variableDebtWETH)
Return Values:
address
The address of the underlying asset
Returns the amount of tokens owned by account - the most up to date accumulated debt (principal + interest) of the user.
Standard ERC20 function.
Input Parameters:
account
address
The balance of this address
Return Values:
uint256
The amount of tokens owned by account
Returns the amount of tokens in existence - the most up to date total debt accrued by all protocol users for that specific variable rate of debt token.
Standard ERC20 function.
Return Values:
uint256
The amount of tokens in existence
Returns the revision number of the contract. Needs to be defined in the inherited class as a constant.
Returns 0x1.
Return Values:
uint256
The revision number
Being non-transferrable, the variable debt token does not implement any of the standard ERC20 functions for transfer and allowance.
The following functions below will revert with the error code 80
, OPERATION_NOT_SUPPORTED
: transfer, allowance, approve, transferFrom, increaseAllowance, decreaseAllowance.
Used by the to transfer assets in borrow(), withdraw() and flashLoan().