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 Markets
copy icon
euler-xyz
• version 1.0.0
Finance
ERC20
Marketplace

Euler Markets

This module allows you to activate new markets on the Euler protocol. Any token can be activated, as long as there exists a Uniswap 3 pair between it and the reference asset (WETH version 9 in the standard deployment, although any 18-decimal token could be used). It also allows you to enter/exit markets, which controls which of your ETokens are used as collateral for your debts. This terminology was chosen deliberately to match Compound's, since many of our users will be familiar with Compound already. Unlike Compound which keeps both an array and a mapping for each user, we only keep an array. Upon analysis we realised that almost every access to the mapping will be done inside a transaction that also scans through the array (usually as a liquidity check) so the mapping was (nearly) redundant and we thus could eliminate an SSTORE when entering a market. Furthermore, instead of a normal length-prefixed storage array, we store the length in a packed slot that is loaded for other reasons. This saves an additional SSTORE since we don't need to update the array length, and saves and SLOAD on every liquidity check (more important post Berlin fork). Taking it one step further, there is also an optimisation where the first entered market address is stored in a special variable that is packed together with this length. Finally, the markets module allows external users to query for market configuration parameters (ie collateral factors) and current states (ie interest rates).

*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
activateMarket(address) :
This function activates a market for a given underlying asset. It takes the address of the underlying asset as an argument and checks if a market for that asset already exists. If not, it calls the doActivateMarket() function to create the market. (autogenerated documentation)
doActivateMarket(address) :
This function is used to activate a new market. It takes an address of the underlying asset as an argument and returns the address of the eToken associated with the market. It first checks if the market has already been activated, and if not, it creates a new proxy for the eToken and dToken associated with the market. It then stores the relevant information about the market in the underlyingLookup and dTokenLookup mappings. Finally, it emits an event to signal that the market has been activated and returns the address of the eToken. (autogenerated documentation)
activatePToken(address) :
This function activates a pToken (a tokenized version of a given underlying asset) on the Ethereum blockchain. It takes an address of the underlying asset as an argument and checks if the pToken has already been activated. If not, it resolves the asset configuration, creates a new pToken instance, and stores the underlying asset address and the pToken address in two lookup tables. Finally, it emits an event and activates the market for the pToken. (autogenerated documentation)
underlyingToEToken(address) :
This function takes an address of an underlying asset as an input and returns the address of the corresponding eToken. It works by looking up the eToken address in the underlyingLookup mapping, which stores the address of the eToken associated with each underlying asset. (autogenerated documentation)
underlyingToDToken(address) :
This function takes an address of an underlying asset as an input and returns the address of the corresponding dToken. It works by first looking up the eToken address associated with the underlying asset in the underlyingLookup mapping, then using that eToken address to look up the corresponding dToken address in the eTokenLookup mapping. (autogenerated documentation)
underlyingToPToken(address) :
This function allows users to look up the address of a pToken associated with a given underlying asset. It works by accessing a mapping (reversePTokenLookup) that stores the address of the pToken associated with each underlying asset. The function takes the address of the underlying asset as an input and returns the address of the associated pToken. (autogenerated documentation)
underlyingToAssetConfig(address) :
This function is used to retrieve the AssetConfig associated with a given underlying asset address. It works by calling the resolveAssetConfig() function, which looks up the AssetConfig associated with the given address in a mapping. The AssetConfig is then returned as a memory variable. (autogenerated documentation)
underlyingToAssetConfigUnresolved(address) :
This function is used to retrieve the AssetConfig associated with a given underlying asset. It takes an address of the underlying asset as an input and returns an AssetConfig memory object. The function first looks up the AssetConfig associated with the underlying asset in the underlyingLookup mapping. If the eTokenAddress associated with the AssetConfig is not equal to 0, the function returns the AssetConfig. Otherwise, it throws an error indicating that the market is not activated. (autogenerated documentation)
eTokenToUnderlying(address) :
This function allows users to look up the underlying asset associated with a given eToken address. It works by accessing the eTokenLookup mapping, which stores the address of the underlying asset associated with each eToken address. If the eToken address is not found in the mapping, an error is thrown. (autogenerated documentation)
dTokenToUnderlying(address) :
This function allows users to look up the underlying asset of a given dToken. It takes in an address of a dToken as an argument and returns the address of the underlying asset. It does this by first looking up the address of the corresponding eToken in the dTokenLookup mapping, then using that address to look up the underlying asset in the eTokenLookup mapping. If the dToken address is not found in the dTokenLookup mapping, an error is thrown. (autogenerated documentation)
eTokenToDToken(address) :
This function allows users to look up the address of a dToken associated with a given eToken. It takes an eToken address as an input and returns the address of the associated dToken. The function first looks up the address of the dToken associated with the given eToken in the eTokenLookup mapping. If the address is not found, the function will throw an error. (autogenerated documentation)
getAssetStorage(address) :
This function is used to retrieve the AssetStorage associated with a given underlying asset. It takes an address of the underlying asset as an argument and returns an AssetStorage object. It first looks up the eToken address associated with the underlying asset in the underlyingLookup mapping. If the eToken address is not 0, it then looks up the AssetStorage associated with the eToken address in the eTokenLookup mapping and returns it. (autogenerated documentation)
interestRateModel(address) :
This function retrieves the interest rate model associated with a given address. It does this by accessing the AssetStorage struct associated with the given address and returning the interestRateModel field. (autogenerated documentation)
interestRate(address) :
This function is used to retrieve the interest rate associated with a given address. It takes in an address as an argument and returns an int96 value representing the interest rate. The function does this by first retrieving the AssetStorage associated with the given address from the getAssetStorage() function, and then returning the interestRate value stored in the AssetStorage. (autogenerated documentation)
interestAccumulator(address) :
This function is used to retrieve the accumulated interest of a given address. It does this by first retrieving the asset storage associated with the given address, then loading the asset cache in read-only mode. Finally, it returns the interest accumulator value stored in the asset cache. (autogenerated documentation)
reserveFee(address) :
This function retrieves the reserve fee associated with a given underlying asset. It first checks the AssetStorage struct associated with the underlying asset to see if a reserve fee has been set. If it has, the function returns that value. If not, it returns the default reserve fee. (autogenerated documentation)
getPricingConfig(address) :
This function retrieves the pricing configuration for a given underlying asset. It takes the address of the underlying asset as an input and returns the pricing type, pricing parameters, and pricing forwarded address associated with the asset. The pricing type indicates the type of pricing mechanism used for the asset, such as a fixed rate or a forwarded rate. The pricing parameters provide additional information about the pricing mechanism, such as the fixed rate or the address of the pricing contract. The pricing forwarded address is only returned if the pricing type is set to forwarded, and it indicates the address of the contract that is forwarding the pricing information. (autogenerated documentation)
getChainlinkPriceFeedConfig(address) :
This function is used to retrieve the address of a Chainlink Aggregator associated with a given underlying asset. It does this by accessing the chainlinkPriceFeedLookup mapping, which stores the address of the Chainlink Aggregator associated with each underlying asset. The function takes the address of the underlying asset as an input and returns the address of the associated Chainlink Aggregator. (autogenerated documentation)
getEnteredMarkets(address) :
This function is used to retrieve an array of addresses of markets that the given account has entered. It works by calling the getEnteredMarketsArray() function, which returns an array of addresses of markets that the given account has entered. (autogenerated documentation)
enterMarket(address) :
This function allows a user to enter a new market with a given subAccountId. It first checks that the new market is activated by checking that the underlyingLookup[newMarket].eTokenAddress is not equal to 0. If it is, it will call the doEnterMarket function with the account and newMarket as parameters. (autogenerated documentation)
exitMarket(address) :
This function allows a user to exit a market. It takes in a subAccountId and an oldMarket address as parameters. It first checks the message sender and resolves the asset configuration for the oldMarket address. It then checks the user's balance and owed amount in the asset storage. If the owed amount is 0, it calls the doExitMarket function to exit the market. Finally, if the collateral factor is not 0 and the balance is not 0, it calls the checkLiquidity function. (autogenerated documentation)

Get Cookin'
share iconShare

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