Pool
Last updated
Last updated
The pool.sol
contract is the main user facing contract of the protocol. It exposes the liquidity management methods that can be invoked using either Solidity or Web3 libraries.
function supply(address asset, uint256 amount, address onBehalfOf, uint16 referralCode)
The referralCode
is emitted in Supply event and can be for third party referral integrations. To activate referral feature and obtain a unique referral code, integrators need to submit proposal to Maker Governance.
When supplying, the Pool
contract must have**allowance()
to spend funds on behalf ofmsg.sender
** for at-least**amount
** for the asset
being supplied. This can be done via the standard ERC20 approve()
method on the underlying token contract
Referral supply is currently inactive, you can pass 0
as referralCode
. This program may be activated in the future through an Maker Governance proposal
Param Name | Type | Description |
---|---|---|
function supplyWithPermit(address asset, uint256 amount, address onBehalfOf, uint16 referralCode, uint256 deadline, uint8 permitV, permitR, bytes32 permitS)
Supply with transfer approval of supplied asset via permit function. This method removes the need for separate approval tx before supplying asset to the pool.
Permit signature must be signed by msg.sender
with spender as Pool address.
Referral program is currently inactive, you can pass 0
as referralCode
. This program may be activated in the future through an Maker Governance proposal
Call Params
function withdraw(address asset, uint256 amount, address to)
Withdraws amount
of the underlying asset
, i.e. redeems the underlying token and burns the spTokens.
If user has any existing debt backed by the underlying token, then the max amount available to withdraw is the amount that will not leave user health factor < 1 after withdrawal.
When withdrawingto
another address, msg.sender
should have spToken
that will be burned by Pool .
Call Params
function borrow(address asset, uint256 amount, uint256 interestRateMode, uint16 referralCode, address onBehalfOf)
Borrows amount
of asset
with interestRateMode
, sending the amount
to msg.sender
, with the debt being incurred by onBehalfOf
.
Note: If onBehalfOf
is not same as msg.sender
, then onBehalfOf
must have supplied enough collateral via supply()
and have delegated credit to msg.sender
via approveDelegation()
.
Referral program is currently inactive, you can pass 0
as referralCode
. This program may be activated in the future through an Maker Governance proposal
Call Params
function repay(address asset, uint256 amount, uint256 rateMode, address onBehalfOf)
Repays onBehalfOf
's debt amount
of asset
which has a rateMode
.
When repaying, the Pool
contract must have**allowance()
to spend funds on behalf ofmsg.sender
** for at-least**amount
** for the asset
you are repaying with. This can be done via the standard ERC20 approve()
method on the underlying token contract.
Referral program is currently inactive, you can pass 0
as referralCode
. This program may be activated in the future through an Maker Governance proposal
Call Params
function repayWithPermit(address asset, uint256 amount, uint256 interestRateMode, address onBehalfOf, uint256 deadline, uint8 permitV, permitR, bytes32 permitS)
Repay with transfer approval of borrowed asset via permit function. This method removes the need for separate approval tx before repaying asset to the pool.
Permit signature must be signed by msg.sender
with spender value as Pool
address.
Call Params
function repayWithSpTokens(address asset,uint256 amount,uint256 interestRateMode)
Allows user to repay with spTokens of the underlying debt asset without any approvals eg. Pay DAI debt using aDAI tokens.
Call Params
function swapBorrowRateMode(address asset, uint256 rateMode)
Swaps msg.sender
's borrow rate mode between stable and variable.
Call Params
function rebalanceStableBorrowRate(address asset, address user)
Rebalances stable borrow rate of the user
for given asset
. In case of liquidity crunches on the protocol, stable rate borrows might need to be rebalanced to bring back equilibrium between the borrow and supply rates.
Call Params
function setUserUseReserveAsCollateral(address asset, bool useAsCollateral)
Sets the asset
of msg.sender
to be used as collateral or not.
An asset in Isolation Mode can be enabled to use as collateral only if no other asset is already enabled to use as collateral.
User won’t be able to disable an asset as collateral if they have an outstanding debt position which could be left with HF < HEALTH_FACTOR_LIQUIDATION_THRESHOLD
on disabling the given asset as collateral.
Call Params
function liquidationCall(address collateral, address debt, address user, uint256 debtToCover, bool receiveSpToken)
Liquidate positions with a health factor below 1.
When the health factor of a position is below 1, liquidators repay part or all of the outstanding borrowed amount on behalf of the borrower, while receiving a discounted amount of collateral in return (also known as a liquidation 'bonus"). Liquidators can decide if they want to receive an equivalent amount of collateral spTokens instead of the underlying asset. When the liquidation is completed successfully, the health factor of the position is increased, bringing the health factor above 1.
Liquidators can only close a certain amount of collateral defined by a close factor. Currently the close factor is 0.5. In other words, liquidators can only liquidate a maximum of 50% of the amount pending to be repaid in a position. The liquidation discount applies to this amount.
Liquidators must `approve()` the `Pool` contract to use `debtToCover` of the underlying ERC20 of the`asset` used for the liquidation.
NOTES
In most scenarios, profitable liquidators will choose to liquidate as much as they can (50% of the user
position).
debtToCover
parameter can be set to uint(-1)
and the protocol will proceed with the highest possible liquidation allowed by the close factor.
To check a user's health factor, use getUserAccountData()
.
Call Params
function flashLoan( address receiverAddress, address[] calldata assets, uint256[] calldata amounts, uint256[] interestRateModes, address onBehalfOf, bytes calldata params, uint16 referralCode)
Allows users to access liquidity of the pool for given list of assets for one transaction as long as the amount taken plus fee is returned or debt position is opened by the end of transaction.
If no debt position is opened, receiver must approve the Pool contract for at least the amount borrowed + fee, else transaction will revert.
Flash loan fee is waived for the approved flashBorrowers
Referral program is currently inactive, you can pass 0
as referralCode
. This program may be activated in the future through an Maker Governance proposal
Call Params
function flashLoanSimple( address receiverAddress, address asset, uint256 amount, bytes calldata params, uint16 referralCode)
Allows users to access liquidity of one reserve or one transaction as long as the amount taken plus fee is returned.
Receiver must approve the Pool contract for at least the amount borrowed + fee, else transaction will revert.
Does not waive few for approved flashBorrowers nor allow opening a debt position instead of repaying.
Referral program is currently inactive, you can pass 0
as referralCode
. This program may be activated in the future through an Maker Governance proposal
Call Params
function mintToTreasury(address[] calldata assets)
Mints reserve income accrued to treasury (as per the reserve factor) for the given list of assets.
Call Params
function setUserEMode(uint8 categoryId)
Updates the user efficiency mode category. The category id must be a valid id already defined by Pool or Risk Admins
Will revert if user is borrowing non-compatible asset or change will drop HF < HEALTH_FACTOR_LIQUIDATION_THRESHOLD
Call Params
mintUnbacked (asset, amount, onBehalfOf, referralCode)
Allows contracts, with BRIDGE
role permission, to mint unbacked spTokens to the onBehalfOf
address. This method is part of the Spark Lend Portal feature.
Only available to the addresses withBRIDGE
role. Bridge addresses can be whitelisted by the governance.
backUnbacked (asset, amount, fee)
Allows contracts, with BRIDGE
role permission, to back the currently unbacked spTokens with amount
of underlying asset and pay fee
. This method is part of the Spark Lend Portal feature.
Only available to the addresses withBRIDGE
role. Bridge addresses can be whitelisted by the governance.
function rescueTokens(address token, address to, uint256 amount)
Rescue and transfer tokens locked in this contract.
Only available toPOOL_ADMIN
role. Pool admin is selected by the governance.
function getReserveData(address asset)
Returns the state and configuration of the reserve.
Call Params
Return Values
function getUserAccountData(address user)
Returns the user account data across all the reserves
Call params
Return Values
function getConfiguration(address asset)
Returns the configuration of the reserve.
Call Params
Return Values
function getUserConfiguration(address user)
Returns the configuration of the user across all the reserves.
Call Params
Return Values
function getReserveNormalizedIncome(address asset)
Returns the ongoing normalized income for the reserve.
A value of 1e27 means there is no income. As time passes, the yield is accrued. A value of 2*1e27 means for each unit of asset one unit of income has been accrued.
Return Value
function getReserveNormalizedVariableDebt(address asset)
Returns the ongoing normalized variable debt for the reserve.
A value of 1e27 means there is no debt. As time passes, the debt is accrued. A value of 2*1e27 means that for each unit of debt, one unit worth of interest has been accumulated.
Return Value
function getReservesList()
Returns the list of initialized reserves.
function getEModeCategoryData(uint8 id)
Returns category data for the given eModeCategory id.
Return Values
function getUserEMode(address user)
Returns eModeCategory Id of the user’s eMode. 0 ⇒ no eMode.
function FLASHLOAN_PREMIUM_TOTAL() public view returns (uint128)
Returns the percent of total flashloan premium paid by the borrower. A part of this premium is added to reserve's liquidity index i.e. paid to the liquidity provider and the other part is paid to the protocol i.e. accrued to the treasury.
function FLASHLOAN_PREMIUM_TO_PROTOCOL() public view returns (uint128)
Returns the percent of flashloan premium that is accrued to the treasury.
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Param Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Param | Type | Description |
---|---|---|
Param | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Type | Description |
---|---|
Type | Description |
---|---|
Type | Description |
---|---|
asset
address
address of the asset being supplied to the pool.
amount
uint256
amount of asset being supplied.
onBehalfOf
address
address that will receive the corresponding spTokens. Note: only the onBehalfOf address will be able to withdraw asset from the pool.
referralCode
uint16
unique code for 3rd party referral program integration. Use 0 for no referral.
asset
address
Address of underlying asset being supplied. Same asset as used in permit s,v,r
amount
uint256
Amount of asset to be supplied and signed for approval. Same amount as used in permit s,v,r
onBehalfOf
address
Address that will receive the spTokens.
referralCode
uint16
unique code for 3rd party referral program integration. Use 0 for no referral.
deadline
uint256
unix timestamp up-till which signature will be valid
permitV
uint8
Signature parameter v
permitR
bytes32
Signature parameter r
permitS
bytes32
Signature parameter s
asset
address
address of the underlying asset, not the spToken
amount
uint256
amount deposited, expressed in wei units. Use type(uint).max
to withdraw the entire balance.
to
address
address that will receive the asset
asset
address
address of the underlying asset
amount
uint256
amount to be borrowed, expressed in wei units
interestRateMode
uint256
the type of borrow debt. Stable: 1, Variable: 2
referralCode
uint16
referral code for our referral program. Use 0 for no referral code.
onBehalfOf
address
address of user who will incur the debt. Use msg.sender when not calling on behalf of a different user.
asset
address
address of the underlying asset
amount
uint256
Amount of underlying asset being repaid. Use uint(-1) to repay the entire debt, ONLY when the repayment is not executed on behalf of a 3rd party. In case of repayments on behalf of another user, it's recommended to send an _amount slightly higher than the current borrowed amount.
rateMode
uint256
the type of debt being repaid. Stable: 1, Variable: 2
onBehalfOf
address
address of user who will incur the debt. Use msg.sender when not calling on behalf of a different user.
asset
address
Address of underlying asset being supplied. Same asset as used in permit s,v,r
amount
uint256
Amount of asset to be supplied and signed for approval. Same amount as used in permit s,v,r
interestRateMode
uint256
the type of debt being repaid. Stable: 1, Variable: 2
onBehalfOf
address
Address that will receive the spTokens.
deadline
uint256
unix timestamp up-till which signature will be valid
permitV
uint8
Signature parameter v
permitR
bytes32
Signature parameter r
permitS
bytes32
Signature parameter s
asset
address
Address of the underlying asset to be repaid
amount
uint256
Amount of underlying asset being repaid. Use uint256(-1) to pay without leaving spToken dust
interestRateMode
uint256
Interest rate mode of the debt position 1 - stable 2 - variable
asset
address
address of the underlying asset
rateMode
uint256
the rate mode the user is swapping from. Stable: 1, Variable: 2
asset
address
Address of the underlying token that has been borrowed for which the position is being rebalanced.
user
address
Address of the user being rebalanced.
asset
address
address of the underlying asset to be used as collateral
useAsCollateral
bool
true if the asset should be used as collateral
collateral
address
address of the collateral reserve
debt
address
address of the debt reserve
user
address
address of the borrower
debtToCover
uint256
amount of asset debt that the liquidator will repay
receiveSpToken
bool
if true, the user receives the spTokens equivalent of the purchased collateral. If false, the user receives the underlying asset directly.
receiverAddress
address
Address of the contract that will receive the flash borrowed funds. Must implement the IFlashLoanReceiver interface.
assets
address[]
Addresses of the underlying assets that will be flash borrowed
amounts
uint256[]
Amounts of assets being requested for flash borrow. This needs to contain the same number of entries as assets.
modes
uint256[]
the types of debt position to open if the flashloan is not returned. 0: no open debt. (amount+fee must be paid in this case or revert) 1: stable mode debt 2: variable mode debt
onBehalfOf
address
if the associated mode is not0 then the incurred debt will be applied to the onBehalfOfaddress. Note: onBehalfOf must already have approved sufficient borrow allowance of the associated asset to msg.sender
params
bytes
Arbitrary bytes-encoded params that will be passed to executeOperation() method of the receiver contract.
referralCode
uint16
Referral Code used for 3rd party integration referral. The unique referral id is can be requested via governance proposal
receiverAddress
address
Address of the contract that will receive the flash borrowed funds. Must implement the IFlashLoanReceiver interface.
asset
address
Address of the underlying asset that will be flash borrowed.
amount
uint256
Amount of asset being requested for flash borrow
params
bytes
Arbitrary bytes-encoded params that will be passed to executeOperation() method of the receiver contract.
referralCode
uint16
Referral Code used for 3rd party integration referral. The unique referral id is can be requested via governance proposal
assets
address[]
List of assets for which accrued income is minted
categoryId
uint8
eMode category id (0 - 255) defined by Risk or Pool Admins. categoryId == 0 ⇒ non E-mode category.
asset
address
address of the underlying asset token
amount
uint256
the amount to be minted
onBehalfOf
address
the address which will receive the spTokens
referralCode
uint16
Code used to register the integrator originating the operation, for potential rewards 0 if the action is executed directly by the user, without any middle-man
asset
address
address of the underlying asset to repay
amount
uint256
amount of asset supplied to back the unbacked tokens
fee
uint256
amount paid in fee
asset
address
address of the underlying reserve asset.
configuration
uint256
Reserve configuration. bit 0-15: LTV bit 16-31: Liquidation threshold bit 32-47: Liquidation bonus bit 48-55: Decimals bit 56: reserve is active bit 57: reserve is frozen bit 58: borrowing is enabled bit 59: stable rate borrowing enabled bit 60: asset is paused bit 61: borrowing in isolation mode is enabled bit 62-63: reserved bit 64-79: reserve factor bit 80-115: borrow cap in whole tokens, 0 ⇒ no cap bit 116-151: supply cap in whole tokens, 0 ⇒ no cap bit 152-167: liquidation protocol fee bit 168-175: eMode category bit 176-211: unbacked mint cap in whole tokens, 0 ⇒ no cap bit 212-251: debt ceiling for isolation mode with decimals bit 252-255: unused
liquidityIndex
uint128
yield generated by reserve during time interval since lastUpdatedTimestamp. Expressed in ray
currentLiquidityRate
uint128
current supply rate. Expressed in ray
variableBorrowIndex
uint128
yield accrued by reserve during time interval since lastUpdatedTimestamp. Expressed in ray
currentVariableBorrowRate
uint128
current variable borrow rate. Expressed in ray
currentStableBorrowRate
uint128
current stable borrow rate. Expressed in ray
lastUpdateTimestamp
uint40
timestamp of when reserve data was last updated. Used for yield calculation.
id
uint16
reserve’s position in the list of active reserves.
spTokenAddress
address
address of associated spToken
stableDebtTokenAddress
address
address of associated stable debt token
variableDebtTokenAddress
address
address of associated variable debt token
interestRateStrategyAddress
address
address of interest rate strategy.
accruedToTreasury
uint128
the current treasury balance (scaled)
unbacked
uint128
the outstanding unbacked spTokens minted through the bridging feature
isolationModeTotalDebt
uint128
the outstanding debt borrowed against this asset in isolation mode
user
address
address of the user
totalCollateralBase
uint256
total collateral of the user, in market’s base currency
totalDebtBase
uint256
total debt of the user, in market’s base currency
availableBorrowsBase
uint256
borrowing power left of the user, in market’s base currency
currentLiquidationThreshold
uint256
liquidation threshold of the user
ltv
uint256
Loan To Value of the user
healthFactor
uint256
current health factor of the user
asset
address
address of the underlying reserve asset.
configuration
uint256
Reserve configuration. bit 0-15: LTV bit 16-31: Liquidation threshold bit 32-47: Liquidation bonus bit 48-55: Decimals bit 56: reserve is active bit 57: reserve is frozen bit 58: borrowing is enabled bit 59: stable rate borrowing enabled bit 60: asset is paused bit 61: borrowing in isolation mode is enabled bit 62-63: reserved bit 64-79: reserve factor bit 80-115: borrow cap in whole tokens, 0 ⇒ no cap bit 116-151: supply cap in whole tokens, 0 ⇒ no cap bit 152-167: liquidation protocol fee bit 168-175: eMode category bit 176-211: unbacked mint cap in whole tokens, 0 ⇒ no cap bit 212-251: debt ceiling for isolation mode with decimals bit 252-255: unused
user
address
address of the user
uint256
Bitmap of the users collaterals and borrows. Its divided into pairs of bits, one pair for each asset. The first bit of the pair indicates if it is being used as collateral by the user, the second bit indicates if it is being borrowed. The corresponding assets are in the same position as getReservesList() For example, if the hex value returned is 0x40020, which represents a decimal value of 262176, then in binary it is 1000000000000100000. If we format the binary value into pairs, starting from the right, we get 1 00 00 00 00 00 00 10 00 00. If we start from the right and move left in the above binary pairs, the third pair is 10. Therefore the 1 indicates that third asset from the reserveList is used as collateral, and 0 indicates it has not been borrowed by this user.
uint256
Normalized income, expressed in ray
uint256
Normalized debt, expressed in ray
uint16
loan to value (ltv) for the given eModeCategory id
uint16
liquidationThreshold for the given eModeCategory id
uint16
liquidationBonus for the given eModeCategory id
address
custom price source for the eMode category
string
custom label describing the eMode category