AlkemiEarnVerified.sol
↗ Extends: Exponential, SafeToken

Structs

Balance

1
struct Balance {
2
uint256 principal,
3
uint256 interestIndex
4
}
Copied!

Market

1
struct Market {
2
bool isSupported,
3
uint256 blockNumber,
4
contract InterestRateModel interestRateModel,
5
uint256 totalSupply,
6
uint256 supplyRateMantissa,
7
uint256 supplyIndex,
8
uint256 totalBorrows,
9
uint256 borrowRateMantissa,
10
uint256 borrowIndex
11
}
Copied!

SupplyLocalVars

1
struct SupplyLocalVars {
2
uint256 startingBalance,
3
uint256 newSupplyIndex,
4
uint256 userSupplyCurrent,
5
uint256 userSupplyUpdated,
6
uint256 newTotalSupply,
7
uint256 currentCash,
8
uint256 updatedCash,
9
uint256 newSupplyRateMantissa,
10
uint256 newBorrowIndex,
11
uint256 newBorrowRateMantissa
12
}
Copied!

WithdrawLocalVars

1
struct WithdrawLocalVars {
2
uint256 withdrawAmount,
3
uint256 startingBalance,
4
uint256 newSupplyIndex,
5
uint256 userSupplyCurrent,
6
uint256 userSupplyUpdated,
7
uint256 newTotalSupply,
8
uint256 currentCash,
9
uint256 updatedCash,
10
uint256 newSupplyRateMantissa,
11
uint256 newBorrowIndex,
12
uint256 newBorrowRateMantissa,
13
uint256 withdrawCapacity,
14
struct Exponential.Exp accountLiquidity,
15
struct Exponential.Exp accountShortfall,
16
struct Exponential.Exp ethValueOfWithdrawal
17
}
Copied!

AccountValueLocalVars

1
struct AccountValueLocalVars {
2
address assetAddress,
3
uint256 collateralMarketsLength,
4
uint256 newSupplyIndex,
5
uint256 userSupplyCurrent,
6
uint256 newBorrowIndex,
7
uint256 userBorrowCurrent,
8
struct Exponential.Exp borrowTotalValue,
9
struct Exponential.Exp sumBorrows,
10
struct Exponential.Exp supplyTotalValue,
11
struct Exponential.Exp sumSupplies
12
}
Copied!

PayBorrowLocalVars

1
struct PayBorrowLocalVars {
2
uint256 newBorrowIndex,
3
uint256 userBorrowCurrent,
4
uint256 repayAmount,
5
uint256 userBorrowUpdated,
6
uint256 newTotalBorrows,
7
uint256 currentCash,
8
uint256 updatedCash,
9
uint256 newSupplyIndex,
10
uint256 newSupplyRateMantissa,
11
uint256 newBorrowRateMantissa,
12
uint256 startingBalance
13
}
Copied!

BorrowLocalVars

1
struct BorrowLocalVars {
2
uint256 newBorrowIndex,
3
uint256 userBorrowCurrent,
4
uint256 borrowAmountWithFee,
5
uint256 userBorrowUpdated,
6
uint256 newTotalBorrows,
7
uint256 currentCash,
8
uint256 updatedCash,
9
uint256 newSupplyIndex,
10
uint256 newSupplyRateMantissa,
11
uint256 newBorrowRateMantissa,
12
uint256 startingBalance,
13
struct Exponential.Exp accountLiquidity,
14
struct Exponential.Exp accountShortfall,
15
struct Exponential.Exp ethValueOfBorrowAmountWithFee
16
}
Copied!

LiquidateLocalVars

1
struct LiquidateLocalVars {
2
address targetAccount,
3
address assetBorrow,
4
address liquidator,
5
address assetCollateral,
6
uint256 newBorrowIndex_UnderwaterAsset,
7
uint256 newSupplyIndex_UnderwaterAsset,
8
uint256 newBorrowIndex_CollateralAsset,
9
uint256 newSupplyIndex_CollateralAsset,
10
uint256 currentBorrowBalance_TargetUnderwaterAsset,
11
uint256 updatedBorrowBalance_TargetUnderwaterAsset,
12
uint256 newTotalBorrows_ProtocolUnderwaterAsset,
13
uint256 startingBorrowBalance_TargetUnderwaterAsset,
14
uint256 startingSupplyBalance_TargetCollateralAsset,
15
uint256 startingSupplyBalance_LiquidatorCollateralAsset,
16
uint256 currentSupplyBalance_TargetCollateralAsset,
17
uint256 updatedSupplyBalance_TargetCollateralAsset,
18
uint256 currentSupplyBalance_LiquidatorCollateralAsset,
19
uint256 updatedSupplyBalance_LiquidatorCollateralAsset,
20
uint256 newTotalSupply_ProtocolCollateralAsset,
21
uint256 currentCash_ProtocolUnderwaterAsset,
22
uint256 updatedCash_ProtocolUnderwaterAsset,
23
uint256 newSupplyRateMantissa_ProtocolUnderwaterAsset,
24
uint256 newBorrowRateMantissa_ProtocolUnderwaterAsset,
25
uint256 discountedRepayToEvenAmount,
26
uint256 discountedBorrowDenominatedCollateral,
27
uint256 maxCloseableBorrowAmount_TargetUnderwaterAsset,
28
uint256 closeBorrowAmount_TargetUnderwaterAsset,
29
uint256 seizeSupplyAmount_TargetCollateralAsset,
30
uint256 reimburseAmount,
31
struct Exponential.Exp collateralPrice,
32
struct Exponential.Exp underwaterAssetPrice
33
}
Copied!

Contract Members

Constants & Variables
1
//internal members
2
uint256 internal initialInterestIndex;
3
uint256 internal defaultOriginationFee;
4
uint256 internal defaultCollateralRatio;
5
uint256 internal defaultLiquidationDiscount;
6
7
//public members
8
uint256 public minimumCollateralRatioMantissa;
9
uint256 public maximumLiquidationDiscountMantissa;
10
address public pendingAdmin;
11
address public admin;
12
mapping(address => bool) public managers;
13
contract ChainLink public priceOracle;
14
mapping(address => mapping(address => struct AlkemiEarnVerified.Balance)) public supplyBalances;
15
mapping(address => mapping(address => struct AlkemiEarnVerified.Balance)) public borrowBalances;
16
contract AlkemiWETH public WETHContract;
17
mapping(address => struct AlkemiEarnVerified.Market) public markets;
18
address[] public collateralMarkets;
19
struct Exponential.Exp public collateralRatio;
20
struct Exponential.Exp public originationFee;
21
struct Exponential.Exp public liquidationDiscount;
22
bool public paused;
23
mapping(address => bool) public KYCAdmins;
24
mapping(address => bool) public customersWithKYC;
25
mapping(address => bool) public liquidators;
26
mapping(address => mapping(address => uint256)) public originationFeeBalance;
27
contract RewardControlInterface public rewardControl;
28
uint256 public closeFactorMantissa;
29
uint256 public _guardCounter;
30
31
//private members
32
bool private initializationDone;
33
address private oracle;
34
address private wethAddress;
Copied!
Events
1
event LiquidatorChanged(address indexed Liquidator, bool newStatus);
2
event SupplyReceived(address account, address asset, uint256 amount, uint256 startingBalance, uint256 newBalance);
3
event SupplyWithdrawn(address account, address asset, uint256 amount, uint256 startingBalance, uint256 newBalance);
4
event BorrowTaken(address account, address asset, uint256 amount, uint256 startingBalance, uint256 borrowAmountWithFee, uint256 newBalance);
5
event BorrowRepaid(address account, address asset, uint256 amount, uint256 startingBalance, uint256 newBalance);
6
event BorrowLiquidated(address indexed targetAccount, address assetBorrow, uint256 borrowBalanceAccumulated, uint256 amountRepaid, address indexed liquidator, address assetCollateral, uint256 amountSeized);
7
event EquityWithdrawn(address indexed asset, uint256 equityAvailableBefore, uint256 amount, address indexed owner);
8
event KYCAdminChanged(address indexed KYCAdmin, bool newStatus);
9
event KYCCustomerChanged(address indexed KYCCustomer, bool newStatus);
Copied!

Modifiers

  • onlyOwner
  • onlyCustomerWithKYC
  • nonReentrant

onlyOwner

Modifier to check if the caller is the admin of the contract
1
modifier onlyOwner() internal
Copied!
Arguments
Name
Type
Description

onlyCustomerWithKYC

Modifier to check if the caller is KYC verified
1
modifier onlyCustomerWithKYC() internal
Copied!
Arguments
Name
Type
Description

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.
1
modifier nonReentrant() internal
Copied!
Arguments
Name
Type
Description

Functions

  • initializer()
  • ()
  • _changeKYCAdmin(address KYCAdmin, bool newStatus)
  • _changeCustomerKYC(address customer, bool newStatus)
  • _changeLiquidator(address liquidator, bool newStatus)
  • min(uint256 a, uint256 b)
  • addCollateralMarket(address asset)
  • calculateInterestIndex(uint256 startingInterestIndex, uint256 interestRateMantissa, uint256 blockStart, uint256 blockEnd)
  • calculateBalance(uint256 startingBalance, uint256 interestIndexStart, uint256 interestIndexEnd)
  • getPriceForAssetAmount(address asset, uint256 assetAmount, bool mulCollatRatio)
  • 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, address wethContractAddress, address _rewardControl)
  • _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)
  • supplyEther(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)
  • refreshAlkIndex(address market, address user, bool isSupply, bool isVerified)
  • getMarketBalances(address asset)
  • revertIfError(enum ErrorReporter.Error err)

initializer

AlkemiEarnVerified is the core contract
1
function initializer() public nonpayable
Copied!
Arguments
Name
Type
Description

Do not pay directly into AlkemiEarnVerified, please use supply.
1
function () public payable
Copied!
Arguments
Name
Type
Description

_changeKYCAdmin

Function for use by the admin of the contract to add or remove KYC Admins
1
function _changeKYCAdmin(address KYCAdmin, bool newStatus) public nonpayable onlyOwner
Copied!
Arguments
Name
Type
Description
KYCAdmin
address
newStatus
bool

_changeCustomerKYC

Function for use by the KYC admins to add or remove KYC Customers
1
function _changeCustomerKYC(address customer, bool newStatus) public nonpayable
Copied!
Arguments
Name
Type
Description
customer
address
newStatus
bool

_changeLiquidator

Function for use by the admin of the contract to add or remove Liquidators
1
function _changeLiquidator(address liquidator, bool newStatus) public nonpayable onlyOwner
Copied!
Arguments
Name
Type
Description
liquidator
address
newStatus
bool

min

Simple function to calculate min between two numbers.
1
function min(uint256 a, uint256 b) internal pure
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
a
uint256
b
uint256

addCollateralMarket

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.
1
function addCollateralMarket(address asset) internal nonpayable
Copied!
Arguments
Name
Type
Description
asset
address

calculateInterestIndex

Calculates a new supply index based on the prevailing interest rates applied over time This is defined as we multiply the most recent supply index by (1 + blocks times rate)
1
function calculateInterestIndex(uint256 startingInterestIndex, uint256 interestRateMantissa, uint256 blockStart, uint256 blockEnd) internal pure
2
returns(enum ErrorReporter.Error, uint256)
Copied!
Returns
Return value is expressed in 1e18 scale
Arguments
Name
Type
Description
startingInterestIndex
uint256
interestRateMantissa
uint256
blockStart
uint256
blockEnd
uint256

calculateBalance

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
1
function calculateBalance(uint256 startingBalance, uint256 interestIndexStart, uint256 interestIndexEnd) internal pure
2
returns(enum ErrorReporter.Error, uint256)
Copied!
Returns
Return value is expressed in 1e18 scale
Arguments
Name
Type
Description
startingBalance
uint256
interestIndexStart
uint256
interestIndexEnd
uint256

getPriceForAssetAmount

Gets the price for the amount specified of the given asset.
1
function getPriceForAssetAmount(address asset, uint256 assetAmount, bool mulCollatRatio) internal view
2
returns(enum ErrorReporter.Error, struct Exponential.Exp)
Copied!
Returns
Return value is expressed in a magnified scale per token decimals
Arguments
Name
Type
Description
asset
address
assetAmount
uint256
mulCollatRatio
bool

calculateBorrowAmountWithFee

Calculates the origination fee added to a given borrowAmount This is simply (1 + originationFee) * borrowAmount
1
function calculateBorrowAmountWithFee(uint256 borrowAmount) internal view
2
returns(enum ErrorReporter.Error, uint256)
Copied!
Returns
Return value is expressed in 1e18 scale
Arguments
Name
Type
Description
borrowAmount
uint256

fetchAssetPrice

fetches the price of asset from the PriceOracle and converts it to Exp
1
function fetchAssetPrice(address asset) internal view
2
returns(enum ErrorReporter.Error, struct Exponential.Exp)
Copied!
Returns
Return value is expressed in a magnified scale per token decimals
Arguments
Name
Type
Description
asset
address
asset whose price should be fetched

assetPrices

Reads scaled price of specified asset from the price oracle
1
function assetPrices(address asset) public view
2
returns(uint256)
Copied!
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

getAssetAmountForValue

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)
1
function getAssetAmountForValue(address asset, struct Exponential.Exp ethValue) internal view
2
returns(enum ErrorReporter.Error, uint256)
Copied!
Returns
Return value is expressed in a magnified scale per token decimals
Arguments
Name
Type
Description
asset
address
ethValue
struct Exponential.Exp

_adminFunctions

Admin Functions. The newPendingAdmin must call _acceptAdmin to finalize the transfer.
1
function _adminFunctions(address newPendingAdmin, address newOracle, bool requestedState, uint256 originationFeeMantissa, uint256 newCloseFactorMantissa, address wethContractAddress, address _rewardControl) public nonpayable onlyOwner
2
returns(uint256)
Copied!
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
new Close Factor, scaled by 1e18
wethContractAddress
address
WETH Contract Address
_rewardControl
address
Reward Control Address

_acceptAdmin

Accepts transfer of admin rights. msg.sender must be pendingAdmin
1
function _acceptAdmin() public nonpayable
Copied!
Arguments
Name
Type
Description

getAccountLiquidity

returns the liquidity for given account. a positive result indicates ability to borrow, whereas a negative result indicates a shortfall which may be liquidated
1
function getAccountLiquidity(address account) public view
2
returns(int256)
Copied!
Returns
signed integer in terms of eth-wei (negative indicates a shortfall)
Arguments
Name
Type
Description
account
address
the account to examine

getSupplyBalance

return supply balance with any accumulated interest for asset belonging to account
1
function getSupplyBalance(address account, address asset) public view
2
returns(uint256)
Copied!
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

getBorrowBalance

return borrow balance with any accumulated interest for asset belonging to account
1
function getBorrowBalance(address account, address asset) public view
2
returns(uint256)
Copied!
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

_supportMarket

Supports a given market (asset) for use
1
function _supportMarket(address asset, InterestRateModel interestRateModel) public nonpayable onlyOwner
2
returns(uint256)
Copied!
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

_suspendMarket

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.
1
function _suspendMarket(address asset) public nonpayable onlyOwner
2
returns(uint256)
Copied!
Returns
uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
Arguments
Name
Type
Description
asset
address
Asset to suspend

_setRiskParameters

Sets the risk parameters: collateral ratio and liquidation discount
1
function _setRiskParameters(uint256 collateralRatioMantissa, uint256 liquidationDiscountMantissa) public nonpayable onlyOwner
2
returns(uint256)
Copied!
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)

_setMarketInterestRateModel

Sets the interest rate model for a given market
1
function _setMarketInterestRateModel(address asset, InterestRateModel interestRateModel) public nonpayable onlyOwner
2
returns(uint256)
Copied!
Returns
uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
Arguments
Name
Type
Description
asset
address
Asset to support
interestRateModel
InterestRateModel

_withdrawEquity

withdraws amount of asset from equity for asset, as long as amount <= equity. Equity = cash + borrows - supply
1
function _withdrawEquity(address asset, uint256 amount) public nonpayable onlyOwner
2
returns(uint256)
Copied!
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

supplyEther

Convert Ether supplied by user into WETH tokens and then supply corresponding WETH to user
1
function supplyEther(uint256 etherAmount) internal nonpayable
2
returns(uint256)
Copied!
Returns
errors if any
Arguments
Name
Type
Description
etherAmount
uint256
Amount of ether to be converted to WETH

revertEtherToUser

Revert Ether paid by user back to user's account in case transaction fails due to some other reason
1
function revertEtherToUser(address user, uint256 etherAmount) internal nonpayable
Copied!
Arguments
Name
Type
Description
user
address
User account address
etherAmount
uint256
Amount of ether to be sent back to user

supply

supply amount of asset (which must be supported) to msg.sender in the protocol
1
function supply(address asset, uint256 amount) public payable nonReentrant onlyCustomerWithKYC
2
returns(uint256)
Copied!
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

withdrawEther

withdraw amount of ether from sender's account to sender's address
1
function withdrawEther(address user, uint256 etherAmount) internal nonpayable
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
user
address
User account address
etherAmount
uint256
Amount of ether to be converted to WETH

withdraw

withdraw amount of asset from sender's account to sender's address
1
function withdraw(address asset, uint256 requestedAmount) public nonpayable nonReentrant
2
returns(uint256)
Copied!
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)

calculateAccountLiquidity

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).
1
function calculateAccountLiquidity(address userAddress) internal view
2
returns(enum ErrorReporter.Error, struct Exponential.Exp, struct Exponential.Exp)
Copied!
Returns
Return values are expressed in 1e18 scale
Arguments
Name
Type
Description
userAddress
address

calculateAccountValuesInternal

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
1
function calculateAccountValuesInternal(address userAddress) internal view
2
returns(enum ErrorReporter.Error, struct Exponential.Exp, struct Exponential.Exp)
Copied!
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

calculateAccountValues

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
1
function calculateAccountValues(address userAddress) public view
2
returns(uint256, uint256, uint256)
Copied!
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

repayBorrow

Users repay borrowed assets from their own address to the protocol.
1
function repayBorrow(address asset, uint256 amount) public payable nonReentrant
2
returns(uint256)
Copied!
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)

liquidateBorrow

users repay all or some of an underwater borrow and receive collateral
1
function liquidateBorrow(address targetAccount, address assetBorrow, address assetCollateral, uint256 requestedAmountClose) public payable
2
returns(uint256)
Copied!
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)

calculateDiscountedRepayToEvenAmount

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.
1
function calculateDiscountedRepayToEvenAmount(address targetAccount, struct Exponential.Exp underwaterAssetPrice, address assetBorrow) internal view
2
returns(enum ErrorReporter.Error, uint256)
Copied!
Returns
Return values are expressed in 1e18 scale
Arguments
Name
Type
Description
targetAccount
address
underwaterAssetPrice
struct Exponential.Exp
assetBorrow
address

calculateDiscountedBorrowDenominatedCollateral

discountedBorrowDenominatedCollateral = [supplyCurrent / (1 + liquidationDiscount)] * (Oracle price for the collateral / Oracle price for the borrow)
1
function calculateDiscountedBorrowDenominatedCollateral(struct Exponential.Exp underwaterAssetPrice, struct Exponential.Exp collateralPrice, uint256 supplyCurrent_TargetCollateralAsset) internal view
2
returns(enum ErrorReporter.Error, uint256)
Copied!
Returns
Return values are expressed in 1e18 scale
Arguments
Name
Type
Description
underwaterAssetPrice
struct Exponential.Exp
collateralPrice
struct Exponential.Exp
supplyCurrent_TargetCollateralAsset
uint256

calculateAmountSeize

returns closeBorrowAmount_TargetUnderwaterAsset (1+liquidationDiscount) priceBorrow/priceCollateral
1
function calculateAmountSeize(struct Exponential.Exp underwaterAssetPrice, struct Exponential.Exp collateralPrice, uint256 closeBorrowAmount_TargetUnderwaterAsset) internal view
2
returns(enum ErrorReporter.Error, uint256)
Copied!
Returns
Return values are expressed in 1e18 scale
Arguments
Name
Type
Description
underwaterAssetPrice
struct Exponential.Exp
collateralPrice
struct Exponential.Exp
closeBorrowAmount_TargetUnderwaterAsset
uint256

borrow

Users borrow assets from the protocol to their own address
1
function borrow(address asset, uint256 amount) public nonpayable nonReentrant onlyCustomerWithKYC
2
returns(uint256)
Copied!
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

supplyOriginationFeeAsAdmin

supply amount of asset (which must be supported) to admin in the protocol
1
function supplyOriginationFeeAsAdmin(address asset, address user, uint256 amount, uint256 newSupplyIndex) private nonpayable
Copied!
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

refreshAlkIndex

Trigger the underlying Reward Control contract to accrue ALK supply rewards for the supplier on the specified market
1
function refreshAlkIndex(address market, address user, bool isSupply, bool isVerified) internal nonpayable
Copied!
Arguments
Name
Type
Description
market
address
The address of the market to accrue rewards
user
address
The address of the supplier/borrower to accrue rewards
isSupply
bool
Specifies if Supply or Borrow Index need to be updated
isVerified
bool
Verified / Public protocol

getMarketBalances

Get supply and borrows for a market
1
function getMarketBalances(address asset) public view
2
returns(uint256, uint256)
Copied!
Returns
updated supply and borrows
Arguments
Name
Type
Description
asset
address
The market asset to find balances of

revertIfError

Function to revert in case of an internal exception
1
function revertIfError(enum ErrorReporter.Error err) internal pure
Copied!
Arguments
Name
Type
Description
err
enum ErrorReporter.Error
Last modified 4mo ago