AlkemiEarnPublic.sol
Last updated
Was this helpful?
Last updated
Was this helpful?
View Source:
↗ Extends: ,
Constants & Variables
Events
nonReentrant
Prevents a contract from calling itself, directly or indirectly. If you mark a function nonReentrant
, you should also mark it external
. Calling one nonReentrant
function from another is not supported. Instead, you can implement a private
function doing the actual work, and an external
wrapper marked as nonReentrant
.
Arguments
Name
Type
Description
initializer()
()
min(uint256 a, uint256 b)
addCollateralMarket(address asset)
getCollateralMarketsLength()
calculateInterestIndex(uint256 startingInterestIndex, uint256 interestRateMantissa, uint256 blockStart, uint256 blockEnd)
calculateBalance(uint256 startingBalance, uint256 interestIndexStart, uint256 interestIndexEnd)
getPriceForAssetAmount(address asset, uint256 assetAmount)
getPriceForAssetAmountMulCollatRatio(address asset, uint256 assetAmount)
calculateBorrowAmountWithFee(uint256 borrowAmount)
fetchAssetPrice(address asset)
assetPrices(address asset)
getAssetAmountForValue(address asset, struct Exponential.Exp ethValue)
_adminFunctions(address newPendingAdmin, address newOracle, bool requestedState, uint256 originationFeeMantissa, uint256 newCloseFactorMantissa)
_acceptAdmin()
getAccountLiquidity(address account)
getSupplyBalance(address account, address asset)
getBorrowBalance(address account, address asset)
_supportMarket(address asset, InterestRateModel interestRateModel)
_suspendMarket(address asset)
_setRiskParameters(uint256 collateralRatioMantissa, uint256 liquidationDiscountMantissa)
_setMarketInterestRateModel(address asset, InterestRateModel interestRateModel)
_withdrawEquity(address asset, uint256 amount)
setWethAddress(address wethContractAddress)
supplyEther(address user, uint256 etherAmount)
revertEtherToUser(address user, uint256 etherAmount)
supply(address asset, uint256 amount)
withdrawEther(address user, uint256 etherAmount)
withdraw(address asset, uint256 requestedAmount)
calculateAccountLiquidity(address userAddress)
calculateAccountValuesInternal(address userAddress)
calculateAccountValues(address userAddress)
repayBorrow(address asset, uint256 amount)
liquidateBorrow(address targetAccount, address assetBorrow, address assetCollateral, uint256 requestedAmountClose)
calculateDiscountedRepayToEvenAmount(address targetAccount, struct Exponential.Exp underwaterAssetPrice, address assetBorrow)
calculateDiscountedBorrowDenominatedCollateral(struct Exponential.Exp underwaterAssetPrice, struct Exponential.Exp collateralPrice, uint256 supplyCurrent_TargetCollateralAsset)
calculateAmountSeize(struct Exponential.Exp underwaterAssetPrice, struct Exponential.Exp collateralPrice, uint256 closeBorrowAmount_TargetUnderwaterAsset)
borrow(address asset, uint256 amount)
supplyOriginationFeeAsAdmin(address asset, address user, uint256 amount, uint256 newSupplyIndex)
setRewardControlAddress(address _rewardControl)
refreshAlkSupplyIndex(address market, address supplier, bool isVerified)
refreshAlkBorrowIndex(address market, address borrower, bool isVerified)
getMarketBalances(address asset)
revertIfError(enum ErrorReporter.Error err)
AlkemiEarnPublic
is the core contract
Arguments
Name
Type
Description
Do not pay directly into AlkemiEarnPublic, please use supply
.
Arguments
Name
Type
Description
Simple function to calculate min between two numbers.
Arguments
Name
Type
Description
a
uint256
b
uint256
Adds a given asset to the list of collateral markets. This operation is impossible to reverse. Note: this will not add the asset if it already exists.
Arguments
Name
Type
Description
asset
address
return the number of elements in collateralMarkets
Returns
the length of collateralMarkets
Arguments
Name
Type
Description
Calculates a new supply/borrow index based on the prevailing interest rates applied over time This is defined as we multiply the most recent supply/borrow index by (1 + blocks times rate)
Returns
Return value is expressed in 1e18 scale
Arguments
Name
Type
Description
startingInterestIndex
uint256
interestRateMantissa
uint256
blockStart
uint256
blockEnd
uint256
Calculates a new balance based on a previous balance and a pair of interest indices This is defined as: The user's last balance checkpoint is multiplied by the currentSupplyIndex value and divided by the user's checkpoint index value
Returns
Return value is expressed in 1e18 scale
Arguments
Name
Type
Description
startingBalance
uint256
interestIndexStart
uint256
interestIndexEnd
uint256
Gets the price for the amount specified of the given asset.
Returns
Return value is expressed in a magnified scale per token decimals
Arguments
Name
Type
Description
asset
address
assetAmount
uint256
Gets the price for the amount specified of the given asset multiplied by the current collateral ratio (i.e., assetAmountWei collateralRatio oraclePrice = totalValueInEth). We will group this as (oraclePrice * collateralRatio) * assetAmountWei
Returns
Return value is expressed in a magnified scale per token decimals
Arguments
Name
Type
Description
asset
address
assetAmount
uint256
Calculates the origination fee added to a given borrowAmount This is simply (1 + originationFee) * borrowAmount
Returns
Return value is expressed in 1e18 scale
Arguments
Name
Type
Description
borrowAmount
uint256
fetches the price of asset from the PriceOracle and converts it to Exp
Returns
Return value is expressed in a magnified scale per token decimals
Arguments
Name
Type
Description
asset
address
asset whose price should be fetched
Reads scaled price of specified asset from the price oracle
Returns
0 on an error or missing price, the price scaled by 1e18 otherwise
Arguments
Name
Type
Description
asset
address
Asset whose price should be retrieved
Gets the amount of the specified asset given the specified Eth value ethValue / oraclePrice = assetAmountWei If there's no oraclePrice, this returns (Error.DIVISION_BY_ZERO, 0)
Returns
Return value is expressed in a magnified scale per token decimals
Arguments
Name
Type
Description
asset
address
ethValue
struct Exponential.Exp
Admin Functions. The newPendingAdmin must call _acceptAdmin
to finalize the transfer.
Returns
uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
Arguments
Name
Type
Description
newPendingAdmin
address
New pending admin
newOracle
address
New oracle address
requestedState
bool
value to assign to paused
originationFeeMantissa
uint256
rational collateral ratio, scaled by 1e18.
newCloseFactorMantissa
uint256
Accepts transfer of admin rights. msg.sender must be pendingAdmin
Returns
uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
Arguments
Name
Type
Description
returns the liquidity for given account. a positive result indicates ability to borrow, whereas a negative result indicates a shortfall which may be liquidated
Returns
signed integer in terms of eth-wei (negative indicates a shortfall)
Arguments
Name
Type
Description
account
address
the account to examine
return supply balance with any accumulated interest for asset
belonging to account
Returns
uint supply balance on success, throws on failed assertion otherwise
Arguments
Name
Type
Description
account
address
the account to examine
asset
address
the market asset whose supply balance belonging to account
should be checked
return borrow balance with any accumulated interest for asset
belonging to account
Returns
uint borrow balance on success, throws on failed assertion otherwise
Arguments
Name
Type
Description
account
address
the account to examine
asset
address
the market asset whose borrow balance belonging to account
should be checked
Supports a given market (asset) for use
Returns
uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
Arguments
Name
Type
Description
asset
address
Asset to support; MUST already have a non-zero price set
interestRateModel
InterestRateModel
InterestRateModel to use for the asset
Suspends a given supported market (asset) from use. Assets in this state do count for collateral, but users may only withdraw, payBorrow, and liquidate the asset. The liquidate function no longer checks collateralization.
Returns
uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
Arguments
Name
Type
Description
asset
address
Asset to suspend
Sets the risk parameters: collateral ratio and liquidation discount
Returns
uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
Arguments
Name
Type
Description
collateralRatioMantissa
uint256
rational collateral ratio, scaled by 1e18. The de-scaled value must be >= 1.1
liquidationDiscountMantissa
uint256
rational liquidation discount, scaled by 1e18. The de-scaled value must be <= 0.1 and must be less than (descaled collateral ratio minus 1)
Sets the interest rate model for a given market
Returns
uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
Arguments
Name
Type
Description
asset
address
Asset to support
interestRateModel
InterestRateModel
withdraws amount
of asset
from equity for asset, as long as amount
<= equity. Equity = cash + borrows - supply
Returns
uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
Arguments
Name
Type
Description
asset
address
asset whose equity should be withdrawn
amount
uint256
amount of equity to withdraw; must not exceed equity available
Set WETH token contract address
Arguments
Name
Type
Description
wethContractAddress
address
Enter the WETH token address
Convert Ether supplied by user into WETH tokens and then supply corresponding WETH to user
Returns
errors if any
Arguments
Name
Type
Description
user
address
User account address
etherAmount
uint256
Amount of ether to be converted to WETH
Revert Ether paid by user back to user's account in case transaction fails due to some other reason
Arguments
Name
Type
Description
user
address
User account address
etherAmount
uint256
Amount of ether to be sent back to user
supply amount
of asset
(which must be supported) to msg.sender
in the protocol
Returns
uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
Arguments
Name
Type
Description
asset
address
The market asset to supply
amount
uint256
The amount to supply
withdraw amount
of ether
from sender's account to sender's address
Arguments
Name
Type
Description
user
address
User account address
etherAmount
uint256
Amount of ether to be converted to WETH
withdraw amount
of asset
from sender's account to sender's address
Returns
uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
Arguments
Name
Type
Description
asset
address
The market asset to withdraw
requestedAmount
uint256
The amount to withdraw (or -1 for max)
Gets the user's account liquidity and account shortfall balances. This includes any accumulated interest thus far but does NOT actually update anything in storage, it simply calculates the account liquidity and shortfall with liquidity being returned as the first Exp, ie (Error, accountLiquidity, accountShortfall).
Returns
Return values are expressed in 1e18 scale
Arguments
Name
Type
Description
userAddress
address
Gets the ETH values of the user's accumulated supply and borrow balances, scaled by 10e18. This includes any accumulated interest thus far but does NOT actually update anything in storage
Returns
(error code, sum ETH value of supplies scaled by 10e18, sum ETH value of borrows scaled by 10e18)
Arguments
Name
Type
Description
userAddress
address
account for which to sum values
Gets the ETH values of the user's accumulated supply and borrow balances, scaled by 10e18. This includes any accumulated interest thus far but does NOT actually update anything in storage
Returns
(uint 0=success; otherwise a failure (see ErrorReporter.sol for details), sum ETH value of supplies scaled by 10e18, sum ETH value of borrows scaled by 10e18)
Arguments
Name
Type
Description
userAddress
address
account for which to sum values
Users repay borrowed assets from their own address to the protocol.
Returns
uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
Arguments
Name
Type
Description
asset
address
The market asset to repay
amount
uint256
The amount to repay (or -1 for max)
users repay all or some of an underwater borrow and receive collateral
Returns
uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
Arguments
Name
Type
Description
targetAccount
address
The account whose borrow should be liquidated
assetBorrow
address
The market asset to repay
assetCollateral
address
The borrower's market asset to receive in exchange
requestedAmountClose
uint256
The amount to repay (or -1 for max)
This should ONLY be called if market is supported. It returns shortfall / [Oracle price for the borrow * (collateralRatio - liquidationDiscount - 1)] If the market isn't supported, we support liquidation of asset regardless of shortfall because we want borrows of the unsupported asset to be closed. Note that if collateralRatio = liquidationDiscount + 1, then the denominator will be zero and the function will fail with DIVISION_BY_ZERO.
Returns
Return values are expressed in 1e18 scale
Arguments
Name
Type
Description
targetAccount
address
underwaterAssetPrice
struct Exponential.Exp
assetBorrow
address
discountedBorrowDenominatedCollateral = [supplyCurrent / (1 + liquidationDiscount)] * (Oracle price for the collateral / Oracle price for the borrow)
Returns
Return values are expressed in 1e18 scale
Arguments
Name
Type
Description
underwaterAssetPrice
struct Exponential.Exp
collateralPrice
struct Exponential.Exp
supplyCurrent_TargetCollateralAsset
uint256
returns closeBorrowAmount_TargetUnderwaterAsset (1+liquidationDiscount) priceBorrow/priceCollateral
Returns
Return values are expressed in 1e18 scale
Arguments
Name
Type
Description
underwaterAssetPrice
struct Exponential.Exp
collateralPrice
struct Exponential.Exp
closeBorrowAmount_TargetUnderwaterAsset
uint256
Users borrow assets from the protocol to their own address
Returns
uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
Arguments
Name
Type
Description
asset
address
The market asset to borrow
amount
uint256
The amount to borrow
supply amount
of asset
(which must be supported) to admin
in the protocol
Returns
uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
Arguments
Name
Type
Description
asset
address
The market asset to supply
user
address
amount
uint256
The amount to supply
newSupplyIndex
uint256
Set the address of the Reward Control contract to be triggered to accrue ALK rewards for participants
Returns
uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
Arguments
Name
Type
Description
_rewardControl
address
The address of the underlying reward control contract
Trigger the underlying Reward Control contract to accrue ALK supply rewards for the supplier on the specified market
Arguments
Name
Type
Description
market
address
The address of the market to accrue rewards
supplier
address
The address of the supplier to accrue rewards
isVerified
bool
Verified / Public protocol
Trigger the underlying Reward Control contract to accrue ALK borrow rewards for the borrower on the specified market
Arguments
Name
Type
Description
market
address
The address of the market to accrue rewards
borrower
address
The address of the borrower to accrue rewards
isVerified
bool
Verified / Public protocol
Get supply and borrows for a market
Returns
updated supply and borrows
Arguments
Name
Type
Description
asset
address
The market asset to find balances of
Function to revert in case of an internal exception
Arguments
Name
Type
Description
err
enum ErrorReporter.Error