Request form
Cookbook may introduce a token in the future. Share and contribute to be eligible for future airdrops.
close icon
relevant tag icon
Euler Debt Token
copy icon
euler-xyz
• version 1.0.0
Finance
Debt
Token
ERC20

Euler Debt Token

Every market also has a DToken. This is the primary interface for the tokenisation of debts in the Euler protocol: -borrow: If you have sufficient collateral, Euler sends you the underlying tokens and issues you a corresponding amount of debt tokens. -repay: Transfer tokens from your wallet in order to burn the DTokens, which reduces your debt obligation. DTokens also implement a partially ERC-20 compliant interface. Unlike AAVE, where these are non-transferrable, DTokens can be transferred. The permissioning logic is the opposite of ETokens: While you can send your ETokens to anyone without their permission, with DTokens you can "take" anybody else's DTokens without their permission (assuming you have sufficient collateral). Similarly, just as you can approve another address to take some amount of your ETokens, you can use approveDebt() to grant another account permission to send you some amount of DTokens. The approveDebt() name was used instead of the ERC-20 approve() due to concerns that some contracts might unintentionally allow themselves to receive "negative value" tokens. As well as providing a flexible platform for debt trading and assignment, this system also permits easy transferring of debt positions between sub-accounts (see below). Unlike ETokens, DToken balances do increase block-to-block as interest is accrued. This means that in order to pay off a loan in full, you should specify MAX_UINT256 as the amount to pay off, so that all interest accrued at the point the repay transaction is mined gets repaid. Note that most Euler methods accept this MAX_UINT256 value to indicate that the contract should determine the maximum amount you can deposit/withdraw/borrow/repay at the time the transaction is mined. In the code you will also see INTERNAL_DEBT_PRECISION. This is because DTokens are tracked at a greater precision versus ETokens (27 decimals versus 18) so that interest compounding is more accurate. However, to present a common external decimals amount, this internal precision is hidden from external users of the contract. Note that these decimal place amounts remain the same even if the underlying token uses fewer decimal places than 18 (see the Decimals Normalisation section below).

*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
onFlashLoan() :
This function is used to facilitate a flash loan on the DToken contract. A flash loan is a type of loan that is taken out and repaid in a single transaction. This allows users to borrow funds without having to provide collateral or go through a lengthy approval process. The flash loan is taken out from a liquidity pool and is repaid with the same amount of tokens plus a fee. The data parameter is used to provide the necessary information for the flash loan, such as the amount of tokens to be borrowed and the address of the liquidity pool. The onFlashLoan function will then execute the flash loan and return the borrowed tokens to the user. (autogenerated documentation)
CALLER() :
This function is used to retrieve the underlying asset, storage, proxy address, and message sender associated with a given dToken. It does this by first unpacking the trailing parameters of the call, which should include the proxy address of the dToken. It then looks up the corresponding eToken address in the dTokenLookup mapping, and uses that to look up the associated asset storage in the eTokenLookup mapping. Finally, it returns the underlying asset, storage, proxy address, and message sender. (autogenerated documentation)
name() :
This function is an external view function that returns a string containing the name of the Euler Debt token 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, and then using the IERC20 interface to call the symbol() function of the token. The result is then encoded and returned as a string. (autogenerated documentation)
decimals() :
This function is used to retrieve the number of decimals associated with an asset stored in the AssetStorage contract. It does this by calling the CALLER() function to access the AssetStorage contract, and then returning the underlyingDecimals value stored in the contract. (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 calculate and return the total supply of a given asset. It does this by first retrieving the asset storage and asset cache from the caller, then calculating the total supply by dividing the total borrows by the internal debt precision and the underlying decimal scaler. (autogenerated documentation)
totalSupplyExact() :
This function is used to retrieve the total supply of a given asset. It works by first retrieving the underlying asset and the associated AssetStorage from the caller, then loading the AssetCache in read-only mode. Finally, it returns the totalBorrows value from the AssetCache, which is the total supply of the asset. (autogenerated documentation)
balanceOf(address) :
This function returns the balance of a given account in the underlying asset of the contract. It does this by first retrieving the underlying asset and the asset storage from the caller, then loading the asset cache in read-only mode. Finally, it calculates the current owed amount for the given account and divides it by the underlying asset's decimal scaler to get the balance in the underlying asset. (autogenerated documentation)
balanceOfExact(address) :
This function returns the exact balance of a given account. It does this by first retrieving the underlying asset and the asset storage from the caller, then loading the asset cache in a read-only mode. Finally, it uses the getCurrentOwedExact function to calculate the exact balance of the given account. (autogenerated documentation)
borrow() :
This function allows a user to borrow a specified amount of tokens from a pool of tokens. It first updates the average liquidity of the user's account, then emits a RequestBorrow event. It then loads the asset cache from the underlying asset storage and decodes the external amount of tokens to be borrowed. It then pushes the tokens to the user's account and increases the borrow amount in the asset storage. Finally, it checks the liquidity of the account and logs the asset status. (autogenerated documentation)
repay() :
This function allows a user to repay a loan from a sub-account. It first updates the average liquidity of the account, then emits a RequestRepay event. It then loads the asset cache from the underlying asset storage, and calculates the amount owed by the account. If the amount specified is greater than the amount owed, it is set to the amount owed. The function then pulls the tokens from the sender and decreases the borrow amount from the proxy address and the account. Finally, it logs the asset status. (autogenerated documentation)
flashLoan() :
This function allows a user to borrow a certain amount of a given underlying asset from the contract. The user must provide a data payload as part of the transaction. The contract then transfers the amount of the underlying asset to the user's address. The user can then use the asset for whatever purpose they wish. After the user is done with the asset, they must return it to the contract, otherwise an error will be thrown. (autogenerated documentation)
approveDebt(address) :
This function allows an account to approve a spender to spend a certain amount of debt 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 it loads the assetCache from the assetStorage, and sets the dTokenAllowance for the account and spender to the amount specified, or to the maximum amount if the amount specified is the maximum amount. Finally, it emits an approval event via the proxy address. (autogenerated documentation)
debtAllowance(address,address) :
This function is used to retrieve the allowance of a given holder and spender for a given asset. It takes two addresses as parameters, the holder and the spender, and returns the allowance as a uint. The function first retrieves the underlying asset and the associated asset storage, then loads the asset cache in read-only mode. It then retrieves the allowance from the asset storage and divides it by the underlying asset's decimal scaler to get the allowance in the correct units. Finally, it returns the allowance as a uint. (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)
transferFrom(address,address) :
This function is used to transfer debt tokens (dTokens) from one address to another. It first checks that the from and to addresses are not the same, and then emits a RequestTransferDToken event. It then decodes the external amount of dTokens to be transferred and checks if the sender has sufficient allowance to transfer the dTokens. If so, it calls the transferBorrow function to transfer the dTokens and then checks the liquidity of the to address. Finally, it logs the asset status. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i euler-debt-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.