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

Euler Risk Manager

This is an internal module, meaning it is only called by other modules, and does not have a proxy entry point. RiskManager is called when a market is activated, to get the default risk parameters for a newly created market. Also, it is called after every operation that could affect a user's liquidity (withdrawal, borrow, transferring E/DTokens, exiting a market, etc) to ensure that no liquidity violations have occurred. This logic could be implemented in BaseLogic, and would be slightly more efficient if so, but then upgrading the risk parameters would require upgrading nearly every other module. In order to check liquidity, this module must retrieve prices of assets (see the Pricing 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
getPool(address,address,uint24) :
This function allows users to get the address of a UniswapV3 pool for a given pair of tokens and fee. It takes in the address of two tokens (tokenA and tokenB) and a fee (in uint24 format) as parameters and returns the address of the UniswapV3 pool associated with the given parameters. The UniswapV3 pool is a liquidity pool that allows users to exchange the two tokens in a decentralized manner. The fee is used to incentivize liquidity providers to provide liquidity to the pool. (autogenerated documentation)
slot0() :
This function is used to aggregate data from multiple sources and provide a single output. It works by taking in an array of data points, calculating the average of the data points, and then returning the result. The data points can be of any type, such as prices, volumes, or other metrics. The function also takes in a fee protocol, which is used to determine how much of the result should be paid to the aggregator. Finally, the function also takes in a boolean value which determines whether or not the result should be unlocked, meaning that it can be used by other contracts. (autogenerated documentation)
liquidity() :
/** * @dev Returns the current liquidity of the aggregator. * @return The current liquidity of the aggregator. */function liquidity() external view returns (uint128); function observe(uint32[] calldata secondsAgos) external view returns (int56[] memory tickCumulatives, uint160[] memory liquidityCumulatives); function observations(uint256 index) external view returns (uint32 blockTimestamp, int56 tickCumulative, uint160 liquidityCumulative, bool initialized); function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external; function setObservationCardinality(uint16 observation (autogenerated documentation)
observe(uint32[]) :
/** * @dev This function allows users to observe the cumulative tick and liquidity values of a given set of seconds ago. * * The function takes an array of uint32 values representing the seconds ago for which the cumulative tick and liquidity values should be observed. * The function then returns two arrays, one containing the cumulative tick values and one containing the cumulative liquidity values. * * The cumulative tick and liquidity values are stored in the contract and can be accessed using the observations() function. * This function takes an index as an argument and returns the block timestamp, cumulative tick, cumulative liquidity, and whether or not the observation has been initialized. * * The observation cardinal (autogenerated documentation)
observations(uint256) :
This function allows users to query the current state of the Chainlink Aggregator contract. It takes an index as an argument and returns the block timestamp, tick cumulative, liquidity cumulative, and initialized status of the corresponding observation. The index is used to identify the observation, and the returned values provide information about the current state of the observation. The increaseObservationCardinalityNext function is used to increase the number of observations that can be queried. (autogenerated documentation)
increaseObservationCardinalityNext(uint16) :
This function increases the observation cardinality of the Chainlink Aggregator contract. The observation cardinality is the number of observations that the contract will take into account when calculating the aggregated value. Increasing the observation cardinality will allow the contract to take more observations into account when calculating the aggregated value, resulting in a more accurate result. (autogenerated documentation)
latestAnswer() :
This function is used to retrieve the latest answer from the contract. It works by accessing the internal storage of the contract and returning the value stored in the latestAnswer variable. This variable is updated whenever a new answer is submitted to the contract. (autogenerated documentation)
getNewMarketParameters(address) :
This function is used to get the new market parameters for a given underlying asset. It checks if the underlying asset is the reference asset, a pToken, or an Uniswap pool. Depending on the underlying asset, it sets the pricing type and parameters accordingly. For Uniswap pools, it also checks the liquidity of the pool and sets the fee accordingly. If the Uniswap pool is not initialized, it will revert with an error. (autogenerated documentation)
computeUniswapPoolAddress(address,uint24) :
This function computes the address of a Uniswap pool given two underlying tokens and a fee. It first compares the two tokens and orders them alphabetically. It then uses the keccak256 hashing algorithm to encode the factory address, the two tokens, and the fee into a hexadecimal string. Finally, it uses the uniswapPoolInitCodeHash to generate a unique address for the Uniswap pool. (autogenerated documentation)
decodeSqrtPriceX96(address) :
This function is used to decode the square root of a price in X96 format. It takes in the underlying asset, the underlying asset's decimal scaler, and the sqrtPriceX96 as inputs. It then calculates the price by multiplying the sqrtPriceX96 by itself and dividing it by 2^(96*2) / 1e18 (or 2^(96*2) / (1e18 * underlyingDecimalsScaler) if the underlying asset is greater than the reference asset). Finally, it checks if the price is greater than 1e36 and sets it to 1e36 if it is, or sets it to 1 if it is 0. (autogenerated documentation)
callUniswapObserve(address,address) :
This function is used to observe the Uniswap pool at a given time. It takes in the address of the underlying asset, the underlying asset's decimal scaler, the address of the Uniswap pool, and the time (in seconds) ago that the observation should be taken. It then calls the Uniswap pool's observe function, which returns an array of two int56 values representing the cumulative tick at the given time and the cumulative tick at the current time. The function then calculates the tick (the difference between the two cumulative ticks divided by the time ago) and uses this to calculate the sqrtPriceX96, which is the square root of the price of the underlying asset in the Unisw (autogenerated documentation)
callChainlinkLatestAnswer(address) :
This function is used to call the latest answer from a Chainlink Aggregator contract. It takes the address of the Chainlink Aggregator as an argument and returns the latest answer as a uint. It first calls the staticcall function of the Chainlink Aggregator contract, passing in the selector for the latestAnswer function. If the call is successful, it then decodes the data returned and checks if the answer is greater than 0. If it is, it sets the price to the answer, and if it is greater than 1e36, it sets the price to 1e36. (autogenerated documentation)
resolvePricingConfig() :
This function is used to resolve the pricing configuration for a given asset. It takes in an AssetCache memory and an AssetConfig memory as parameters and returns the address of the underlying asset, the pricing type, pricing parameters, twap window, and underlying decimals scaler. The function first checks if the pricing type is set to PRICINGTYPE__FORWARDED. If it is, it resolves the underlying asset's configuration and sets the twap window accordingly. It then sets the pricing type, pricing parameters, and underlying decimals scaler from the new asset storage. If the pricing type is not set to PRICINGTYPE__FORWARDED, the function sets the underlying asset, pricing type, (autogenerated documentation)
getPriceInternal() :
This function is used to get the price of an asset from either a Chainlink or Uniswap price feed. It takes in an AssetCache and AssetConfig as parameters and returns the TWAP (Time Weighted Average Price) and the TWAP period. The function first resolves the pricing configuration of the asset by calling the resolvePricingConfig() function. Depending on the pricing type, the function then calls either the callUniswapObserve() or callChainlinkLatestAnswer() function to get the price of the asset. If the pricing type is PRICINGTYPE__CHAINLINK and the Chainlink price feed returns 0, the function will then call the callUniswapObs (autogenerated documentation)
getPrice(address) :
This function is used to retrieve the Time Weighted Average Price (TWAP) and the TWAP period for a given underlying asset. It does this by first resolving the asset configuration for the given underlying asset, then loading the asset storage from the eTokenLookup mapping, and finally loading the asset cache in read-only mode. Finally, the internal getPriceInternal function is called to retrieve the TWAP and TWAP period. (autogenerated documentation)
getPriceFull(address) :
This function is used to get the current price of an underlying asset. It first resolves the asset configuration and loads the asset storage. It then calls the getPriceInternal function to get the TWAP (Time Weighted Average Price) and TWAP period. It then resolves the pricing configuration and computes the current price based on the pricing type. If the pricing type is PRICINGTYPE__PEGGED, the current price is set to 1e18. If the pricing type is PRICINGTYPE__UNISWAP3_TWAP or PRICINGTYPE__FORWARDED, the current price is computed using the UniswapV3Pool function. If the pricing type is PRICINGTYPE__ (autogenerated documentation)
computeLiquidityRaw(address) :
This function computes the liquidity status of a given account for a given set of underlyings. It does this by looping through the underlyings and calculating the balance, owed, and price of each underlying. It then uses this information to calculate the collateral value, liability value, number of borrows, and whether or not the borrows are isolated. Finally, it returns the liquidity status of the account. (autogenerated documentation)
computeLiquidity(address) :
This function computes the liquidity status of an account. It does this by taking in an address as an argument and then using the getEnteredMarketsArray() function to get an array of markets that the account has entered. It then passes this array to the computeLiquidityRaw() function, which calculates the liquidity status of the account based on the markets it has entered. The computeLiquidityRaw() function returns a LiquidityStatus memory object, which contains the liquidity status of the account. (autogenerated documentation)
computeAssetLiquidities(address) :
This function computes the liquidity of an asset for a given account. It takes in an address (account) and returns an array of AssetLiquidity objects. It does this by first getting an array of all the markets the account has entered, then looping through each market and computing the liquidity of the asset for that market. Finally, it returns an array of AssetLiquidity objects containing the underlying asset and its liquidity status. (autogenerated documentation)
requireLiquidity(address) :
This function is used to check if a given account has sufficient liquidity. It does this by computing the LiquidityStatus of the account, which includes the collateralValue, liabilityValue, borrowIsolated, and numBorrows of the account. The function then checks if the collateralValue is greater than or equal to the liabilityValue, and if the borrowIsolated is true, then it checks if the numBorrows is equal to 1. If either of these conditions are not met, the function will throw an error. (autogenerated documentation)

Get Cookin'
share iconShare

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