relevant tag icon
Euler Asset Token
copy icon
euler-xyz
• version 1.0.0
Finance
Token
ERC20

Euler Asset Token

Every market has an EToken. This is the primary interface for the tokenisation of assets in the Euler protocol: -deposit: Transfer tokens from your wallet into Euler, and receive interest earning tokens in return. -withdraw: Redeem your ETokens for the underlying tokens, which are transfered from Euler to your wallet, along with any interest accrued. Additionally, ETokens provide an ERC-20 compliant interface which allows you to transfer and approve transfers of your ETokens, as is typical. Like Compound, but unlike AAVE, these tokens have static balances. That is, accrued interest will not cause the value returned from balanceOf to increase. Rather, that fixed balance entitles you to reclaim more and more of the underlying asset as time progresses. Although the AAVE model is conceptually nicer, experience has shown that increasing balance tokens causes a lot of pain to integrators. In particular, if you transfer X ETokens into a pool contract and later withdraw that same X, you have not earned any interest and the pool has some left over dust ETokens that typically aren't allocated to anyone. A downside of the Compound model is that the values returned from balanceOf are in internal bookkeeping units and don't really have any meaning to external users. There is of course a balanceOfUnderlying method (named the same as Compound's method, which may become a defacto standard) that returns the amount in terms of the underlying and does increase block to block.

*Visit desktop site to download or deploy

Version

1.0.0

Creator

euler-xyz

Last Publish

1/16/2023
Any contract you deploy is yours.
Fully owned and controlled by your wallet.
Documentation
Source Code
CALLER() :
This function is used to retrieve the underlying asset, storage, and proxy address associated with a given eToken. It does this by first unpacking the trailing parameters of the function call, which will contain the proxy address of the eToken. It then uses this proxy address to look up the associated AssetStorage struct in the eTokenLookup mapping. Finally, it retrieves the underlying asset address from the AssetStorage struct and returns it, along with the AssetStorage struct and the proxy address. (autogenerated documentation)
name() :
This function is an external view function that returns a string containing the name of the Euler Pool and the name of the underlying ERC20 token. It does this by first getting the address of the caller, then using that address to get the name of the underlying ERC20 token, and finally combining the two strings and returning the result. (autogenerated documentation)
symbol() :
This function is used to retrieve the symbol of an ERC20 token. It does this by using the CALLER() function to get the address of the underlying token, then using the IERC20 interface to call the symbol() function and return the symbol as a string. (autogenerated documentation)
decimals() :
This function is a pure function that returns an unsigned 8-bit integer (uint8). It returns the value 18, which is the number of decimal places used in the Ethereum blockchain. This is the number of decimal places used to represent the smallest unit of Ether (wei). (autogenerated documentation)
underlyingAsset() :
This function is used to retrieve the address of the underlying asset associated with a particular contract. It works by calling the CALLER() function, which returns the address of the caller, and then using that address to look up the underlying asset associated with the contract. The function then returns the address of the underlying asset. (autogenerated documentation)
totalSupply() :
This function is used to retrieve the total supply of a given asset. It does this by first retrieving the caller's underlying address and asset storage from the blockchain. It then uses these values to load the asset cache in read-only mode. Finally, it returns the total balances stored in the asset cache. (autogenerated documentation)
totalSupplyUnderlying() :
This function returns the total supply of an underlying asset. It does this by first retrieving the underlying asset and its associated storage from the caller, then loading the asset cache in read-only mode. Finally, it calculates the total supply of the underlying asset by converting the total balance of the asset to the underlying amount, divided by the underlying decimal scaler. (autogenerated documentation)
balanceOf(address) :
This function returns the balance of a given account. It does this by accessing the AssetStorage storage assetStorage and retrieving the balance of the given account from the users mapping. (autogenerated documentation)
balanceOfUnderlying(address) :
This function returns the balance of a given account in terms of the underlying asset. It does this by first retrieving the underlying asset and the associated asset storage from the caller, then loading the asset cache in read-only mode. Finally, it calculates the balance of the given account in terms of the underlying asset by using the balanceToUnderlyingAmount function and dividing it by the underlyingDecimalsScaler. (autogenerated documentation)
reserveBalance() :
This function is used to retrieve the reserve balance of an asset from the AssetCache. It takes in the address of the underlying asset and the AssetStorage, and then uses these to load the AssetCache in read-only mode. Finally, it returns the reserve balance stored in the AssetCache. (autogenerated documentation)
reserveBalanceUnderlying() :
This function returns the amount of the underlying asset held in reserve by the contract. It does this by first retrieving the AssetStorage and AssetCache associated with the caller (the underlying asset) from the contract storage. It then uses the balanceToUnderlyingAmount function to convert the reserve balance stored in the AssetCache to the amount of the underlying asset held in reserve, and divides this amount by the underlyingDecimalsScaler to return the amount in the correct units. (autogenerated documentation)
convertBalanceToUnderlying() :
This function converts a given balance of an asset to its underlying amount. It does this by first retrieving the asset's storage data from the caller, then loading the asset's cache in read-only mode. Finally, it uses the balanceToUnderlyingAmount function to convert the balance to its underlying amount, and divides the result by the asset's underlyingDecimalsScaler to get the final result. (autogenerated documentation)
convertUnderlyingToBalance() :
This function converts an amount of an underlying asset (such as ETH) into a balance of a tokenized asset (such as a stablecoin). It does this by first loading the asset cache for the underlying asset from storage, then decoding the external amount of the underlying asset, and finally converting it to a balance of the tokenized asset. (autogenerated documentation)
touch() :
This function is an external non-reentrant function that updates the interest rate of an asset stored in an AssetStorage. It first loads the asset cache from the AssetStorage, then updates the interest rate of the asset, and finally logs the asset status. (autogenerated documentation)
deposit() :
This function is used to deposit tokens into a sub-account. It takes two parameters, a subAccountId and an amount. First, it retrieves the underlying address, asset storage, proxy address, and message sender from the caller. It then emits a RequestDeposit event and loads the asset cache from the asset storage. It then checks if the amount is equal to the maximum uint value, and if so, sets the amount to the balance of the message sender. It then decodes the external amount and pulls the tokens from the message sender. It then calculates the amount transferred and updates the pool size. It then increases the balance of the proxy address and checks the liquidity of the account. Finally, it logs the asset status. (autogenerated documentation)
withdraw() :
This function allows a user to withdraw a specified amount of tokens from a sub-account. It first updates the average liquidity of the account, then emits a RequestWithdraw event. It then loads the asset cache from the asset storage, calculates the amount of tokens to withdraw, and pushes the tokens to the user's address. It then decreases the balance of the proxy address and checks the liquidity of the account. Finally, it logs the asset status. (autogenerated documentation)
mint() :
This function is used to mint a given amount of a given asset for a given sub-account. It first updates the average liquidity of the account, then emits a RequestMint event. It then decodes the external amount of the asset, converts it to an internal balance, and increases the balance of the proxy address and the borrow of the dToken address for the given account. Finally, it checks the liquidity of the account and logs the asset status. (autogenerated documentation)
burn() :
This function allows a user to burn a certain amount of a given asset from their sub-account. It first updates the average liquidity of the account, then loads the asset cache from the asset storage. It then calculates the amount of the asset that the user is currently owed, and if the amount they are trying to burn is greater than the amount they are owed, it sets the amount to the amount they are owed. It then withdraws the amount from the proxy address and decreases the balance of the account. Finally, it decreases the amount of the asset that the user has borrowed and checks the liquidity of the account. (autogenerated documentation)
approve(address) :
This function allows the owner of a contract to approve a spender to spend a certain amount of tokens from the contract's balance. It works by calling the approveSubAccount() function, which checks if the spender is allowed to spend the amount of tokens specified, and if so, it updates the contract's balance accordingly. (autogenerated documentation)
approveSubAccount(address) :
This function allows a user to approve a sub-account to spend a certain amount of tokens on their behalf. It takes in a subAccountId, spender address, and amount as parameters. It first checks that the spender is not the same as the account, then sets the allowance in the assetStorage. Finally, it emits an approval event via the proxyAddr. (autogenerated documentation)
allowance(address,address) :
This function allows a user to check the amount of tokens that have been approved for transfer from one address (the holder) to another address (the spender). It does this by accessing the AssetStorage contract and retrieving the eTokenAllowance mapping, which stores the amount of tokens approved for transfer from the holder to the spender. The function then returns this value. (autogenerated documentation)
transfer(address) :
This function is used to transfer a specified amount of tokens from the address of the contract (address(0)) to a specified address (to). It returns a boolean value indicating whether the transfer was successful or not. The function is marked as reentrantOK, which means that it can be called from other functions without causing any issues. (autogenerated documentation)
transferFromMax(address,address) :
This function is a reentrant function that transfers the maximum amount of tokens from one address (from) to another address (to). It does this by calling the transferFrom function, passing in the from address, the to address, and the balance of the from address stored in the AssetStorage users mapping. (autogenerated documentation)
transferFrom(address,address) :
This function is used to transfer a specified amount of eTokens from one address to another. It first checks that the from and to addresses are not the same, and then emits a RequestTransferEToken event. It then checks that the sender has sufficient allowance from the from address, and if so, subtracts the amount from the allowance. It then calls the transferBalance function to transfer the amount from the from address to the to address. Finally, it checks the liquidity of both the from and to addresses, and logs the asset status. (autogenerated documentation)
donateToReserves() :
This function allows a user to donate a specified amount of an underlying asset to the reserves of the asset. It takes two parameters, the subAccountId of the user and the amount to donate. It first retrieves the address of the user's subaccount, updates the average liquidity of the account, and emits a RequestDonate event. It then loads the asset cache, checks that the user has enough balance to donate the specified amount, and calculates the new balance of the user. The reserve balance of the asset is then updated, and Withdraw and Transfer events are emitted. Finally, the asset status is logged. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i euler-asset-token
copy icon

Last Publish

1/16/2023

Version

1.0.0

Creator

euler-xyz

Cookbook is free.
Any contract you deploy is yours.
Your contract is owned and controlled by you.