LendingPool
LendingPool
合约是协议的主合约,其公开了所有可以使用 solidity 或 web3 库调用的面向用户的操作。
LendingPool
中方法:deposit, borrow, withdraw, repay
仅适用于 ERC20,如果想要使用 native token 进行 deposit,borrow,withdraw 以及 repay,请使用WETHGateway
Methods
deposit()
function deposit(address asset, uint256 amount, address onBehalfOf, uint16 referralCode)
将一定数量 amount
的资产asset
存入协议中,mint 相同数量的对应 aToken,并将其转移到 onBehalfOf
地址。
可以传递 0
作为 referralCode
在存款时,LendingPool
合约必须通过 allowance()
方法获得足够的授权,才能代表 msg.sender
支出至少与存款金额相等的资金。这可以通过标准的 ERC20 approve()
方法进行授权 。
参数名称 | 类型 | 描述 |
---|---|---|
asset |
address | 基础资产的地址 |
amount |
uint256 | 存款金额,以 wei 为单位 |
onBehalfOf |
address | 将接收 aTokens 的地址。 当将 aToken 发送给调用者时,请使用 msg.sender |
referralCode |
uint16 | 推荐计划的推荐代码。使用 0 表示无引用。 |
withdraw()
function withdraw(address asset, uint256 amount, address to)
取款的资产amount
的数量amount
,即赎回基础资产 token 并销毁 aToken。
当提现到另一个地址to
时,msg.sender
应该持有 aToken
,它将被 lendingPool 销毁。
参数名称 | 类型 | 描述 |
---|---|---|
asset |
address | 基础资产的地址(不是 aToken) |
amount |
uint256 | 要取出的金额,用 wei 表示。使用 type(uint).max 提取全部金额 |
to |
address | 接收asset 的地址 |
borrow()
function borrow(address asset, uint256 amount, uint256 interestRateMode, uint16 referralCode, address onBehalfOf)
使用 interestRateMode
借入amount
数量的asset
,将金额发送给 msg.sender
,债务由 onBehalfOf
承担。
Note:onBehalfOf
必须通过 deposit
存入了足够的抵押品,或者通过 approveDelegation()
将信用委托给 msg.sender
。更多信息,参阅 Credit Delegation
参数名称 | 类型 | 描述 |
---|---|---|
asset |
address | 基础资产的地址 |
amount |
uint256 | 借入的金额,以 wei 单位表示 |
interestRateMode |
uint256 | 借款债务的类型 Stable:1,Variable:2 |
referralCode |
uint16 | 推荐计划的推荐代码。使用 0 表示无引用。 |
onBehalfOf |
address | 将产生债务的用户的地址 不代表其他用户调用时使用 msg.sender |
swapBorrowRateMode()
function swapBorrowRateMode(address asset, uint256 rateMode)
在 stable 和 variable 之间切换 msg.sender
的 borrow rate 模式。
参数名称 | 类型 | 描述 |
---|---|---|
asset |
address | 基础资产的地址 |
rateMode |
uint256 | 用户要切换的 rate 模式 Stable:1,Variable:2 |
setUserUseReserveAsCollateral()
function setUserUseReserveAsCollateral(address asset, bool useAsCollateral)
设置 msg.sender
的 asset
是否用作抵押品。
参数名称 | 类型 | 描述 |
---|---|---|
asset |
address | 基础资产的地址 |
useAsCollateral |
bool | 如果资产应用作抵押品:true |
liquidationCall()
function liquidationCall(address collateral, address debt, address user, uint256 debtToCover, bool receiveAToken)
清算健康因子(health factor)低于 1 的头寸。另请参考 Liquidation 指南
当头寸的健康因子低于 1 时,liquidators 代替借款人偿还部分/全部未偿还的借款金额,同时获得折扣额的抵押品作为回报(也称为清算的“奖金”)。清算人可以决定如果它们想直接获得等量的抵押品 aTokens,或者直接获得基础资产,则仓位的健康因子回增加,使健康因子高于 1。
清算人只能关闭由平仓因子(close factor)定义的一定数量的抵押品。当前平仓因子(close factor)为 0.5。换句话说,清算人最多只能清算头寸中待偿还金额的 50%。清算折扣适用于此金额。
清算人必须 approve()``LendingPool
合约,以使用用于清算的asset
的底层 ERC20 的debtToCover
。
注意:
- 大多数情况下**,\盈利的清算人会选择尽可能多地清算(用户仓位的 50%)
debtToCover
参数可以设置为uint(-1)
,协议将以平仓因子允许的最高可能清算进行。- 要检查用户的健康状况,请使用
getUserAccountData()
参数名称 | 类型 | 描述 |
---|---|---|
collateral |
address | 抵押储备金地址 |
debt |
address | 负债储备金地址 |
user |
address | 借款人地址 |
debeToCover |
uint256 | 清算人将偿还的asset 债务金额 |
receiveAToken |
bool | 若为true ,用户将收到与购买的抵押品等值的aTokens 。如果为false ,则用户直接受到基础资产。 |
flashLoan()
function flashLoan(address receiverAddress, address[] calldata assets, uint256[] calldata amounts, uint256[] modes, address onBehalfOf, bytes calldata params, uint256 referralCode)
将请求的amounts
数量的 assets
发送到 receiverAddress
合约,并传递包含的 params
如果在交易结束时,flash loaned amounts
+ fee 未归还,则交易有:
- 如果关联模式
mod
为 0,revert。 - 若关联模式
mod
为 1,则onBehalfOf
会产生稳定利率的债务 - 若关联模式
mod
为 2,则onBehalfOf
会产生浮动利率的债务。
接受闪电贷金额的合约必须符合 IFlashLoanReceiver
接口。详细信息,请参阅 闪电贷指南。
参数名称 | 类型 | 描述 |
---|---|---|
receiverAddress |
address | 接受资金的合约地址 必须实现 IFlashLoanReceiver 接口 |
assets |
address[] |
flashLoan 的储备地址 |
amount |
uint256[] |
向 flashloan 借款的总assets 金额 这需要包含与 asstes 相同数量的元素 |
modes |
uint256[] |
若未归还 flashloan 时开立的债务类型 0:不开启任何债务,只回滚 1:stable mode debt 2:variable mode debt |
onBehalfOf |
address | 如果关联模式不为0 ,则产生的债务将计算到onBehalfOf 地址 Note:onBehalfOf 必须已经批准了对 msg.sender 的关联资产的足够借款限额 |
params |
bytes | receiverAddress 合约使用的字节码编码参数 |
referralCode |
uint16 | 推荐计划的推荐代码。使用 0 表示无引用。 |
View Methods
getReserveData()
function getReserveData(address asset)
返回预留的状态和配置。
参数名称 | 类型 | 描述 |
---|---|---|
asset |
address | 储备的地址 |
返回值:
参数名称 | 类型 | 描述 |
---|---|---|
configuration |
uint256 | 有关为何使用 bitmask 的详细信息,请参阅白皮书。 要了解有关这些值的更多信息,请参阅 Risk 文档。 - 位 0-15:LTV(贷款价值比) - 位 16-31:清算阈值 - 位 32-47:清算奖励 - 位 48-55:小数位数 decimal - 位 56:储备处于激活状态 - 位 57:储备已冻结 - 位 58:借款功能已启用 - 位 59:启用了稳定利率借款 - 位 60-63:保留 - 位 64-79:储备因子所有百分比值均为 1e4,即百分比加上两位小数。小数位数表示为 1e2关于清算奖励的说明: 105% 清算奖励 = 100% 本金 + 5% 奖励 |
liquidityIndex |
uint128 | 流动性指数(单位:ray 10^27 ) |
variableBorrowIndex |
uint128 | 浮动利率借款的指数(单位:ray) |
currentLiquidityRate |
uint128 | 当前供应/流动性/存款利率(单位:ray) |
currentVariableBorrowRate |
uint128 | 当前浮动利率借款的利率(单位:ray) |
currentStableBorrowRate |
uint128 | 当前稳定利率借款的利率(单位:ray) |
lastUpdateTimestamp |
uint40 | 上次更新储备数据的时间戳 |
aTokenAddress |
address | 关联 aToken 的地址(代币化存款) |
stableDebtTokenAddress |
address | 相关稳定利率债务代币的地址 |
variableDebtTokenAddress |
address | 关联 Variable Debt 代币的地址 |
interestRateStrategyAddress |
address | 利率策略地址。相关信息,请参阅 Risk 文档。 |
id |
uint8 | 在现有储备列表中的位置 |
getUserAccountData()
function getUserAccountData(address user)
返回所有预留的用户账户数据。
参数名称 | 类型 | 描述 |
---|---|---|
user |
address | 用户地址 |
返回值
参数名称 | 类型 | 描述 |
---|---|---|
totalCollateralETH |
uint256 | 使用的 ETH 总抵押品(wei decimal uint) |
totalDebtETH |
uint256 | 用户以 ETH 为单位的总债务(wei decimal uint) |
availableBorrowsETH |
uint256 | 用户剩余的借款能力(wei decimal uint) |
currentLiquidationThreshold |
uint256 | 用户的清算阈值 - 抵押品储备的清算阈值加权平均值 (1e4 格式 => 百分比加两位小数) |
ltv |
uint256 | 用户的最大贷款价值比(LTV)- 抵押品储备的最大 LTV 加权平均值 (1e4 格式 => 百分比加两位小数) |
healthFactor |
uint256 | 用户当前的健康因子 |
getConfiguration()
function getConfiguration(address asset)
返回储备金的配置
参数名称 | 类型 | 描述 |
---|---|---|
asset |
address | 储备金的地址 |
返回值
返回值类型 | 描述 |
---|---|
uint256 | 有关为何使用 bitmask 的详细信息,请参阅白皮书。 要了解有关这些值的更多信息,请参阅 Risk 文档。 - 位 0-15:LTV(贷款价值比) - 位 16-31:清算阈值 - 位 32-47:清算奖励 - 位 48-55:小数位数 decimal - 位 56:储备处于激活状态 - 位 57:储备已冻结 - 位 58:借款功能已启用 - 位 59:启用了稳定利率借款 - 位 60-63:保留 - 位 64-79:储备因子所有百分比值均为 1e4,即百分比加上两位小数。小数位数表示为 1e2关于清算奖励的说明: 105% 清算奖励 = 100% 本金 + 5% 奖励 |
getUserConfiguration()
function getUserConfiguration(address user)
返回所有储备中的用户配置
参数名称 | 类型 | 描述 |
---|---|---|
user |
address | user 的地址 |
返回值
返回值类型 | 描述 |
---|---|
uint256 | 有关为何使用位掩码(bitmask)的详细信息,请参阅白皮书。位掩码被分为几对位,每对位对应一个资产。每对位的第一位表示该资产是否被用户用作抵押品,第二位表示该资产是否被借用。对应的资产在 getReservesList() 中与其位置一致。例如,返回的十六进制值为 0x40020 (十进制值为 262176),它对应的二进制形式为 1000000000000100000 。如果将该二进制值从右往左每两位一组进行格式化,结果为 1 00 00 00 00 00 00 10 00 00 。如果从右向左查看这些二进制对,第三对为 10 ,getReserveList() 中列出的第三个储备资产是 WETH。因此,1 表示 WETH 被用作抵押品,0 表示该用户没有借入 WETH。继续查看最左侧的二进制对,结果为 1 ,可以表示为 01 。这是第 10 对,在 getReserveList() 中对应的是 DAI。因此,0 表示 DAI 没有被用作抵押品,1 表示该用户借用了 DAI。简而言之,如果用户使用 WETH 作为抵押品并借入了 DAI,返回的值将为 0x40020 (十六进制)或 262176(十进制)。 |
getReserveNormalizedIncome()
function getReserveNormalizedIncome(address asset)
返回每单位资产的标准化收入。
返回值 表示没有收入。随着时间的推移,收入会累积起来。值表示对于每个资产单位,已累计两个单位的收入。
参数名称 | 类型 | 描述 |
---|---|---|
asset |
address | 储备的地址 |
getReserveNormalizedVariableDebt()
function getReserveNormalizedVariableDebt(address asset)
返回每单位资产的标准化浮动利率债务。
返回值 表示没有负债。随着时间的推移,债务会累积起来。值表示对于每个资产单位,已产生两个债务单位。
参数名称 | 类型 | 描述 |
---|---|---|
asset |
address | 储备地址 |
paused()
function paused()
如果 LendingPool
已暂停,则返回true
。
getReservesList()
function getReservesList()
返回已初始化的预留项的列表。
getAddressesProvider()
function getAddressesProvider()
返回 addresses provider。
Error Codes
为了减少 gas 使用量和代码大小,aave 合约返回编号错误。如果您正在调用协议并收到编号错误,您可以使用我们的错误代码参考指南来了解错误编号的含义。或者,您也可以通过检查 Errors.sol
来查找数字所代表的内容
ABI
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "reserve",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "onBehalfOf",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "borrowRateMode",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "borrowRate",
"type": "uint256"
},
{
"indexed": true,
"internalType": "uint16",
"name": "referral",
"type": "uint16"
}
],
"name": "Borrow",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "reserve",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "onBehalfOf",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"indexed": true,
"internalType": "uint16",
"name": "referral",
"type": "uint16"
}
],
"name": "Deposit",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "target",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "initiator",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "asset",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "premium",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint16",
"name": "referralCode",
"type": "uint16"
}
],
"name": "FlashLoan",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "collateralAsset",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "debtAsset",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "debtToCover",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "liquidatedCollateralAmount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "address",
"name": "liquidator",
"type": "address"
},
{
"indexed": false,
"internalType": "bool",
"name": "receiveAToken",
"type": "bool"
}
],
"name": "LiquidationCall",
"type": "event"
},
{
"anonymous": false,
"inputs": [],
"name": "Paused",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "reserve",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
}
],
"name": "RebalanceStableBorrowRate",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "reserve",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "repayer",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "Repay",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "reserve",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "liquidityRate",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "stableBorrowRate",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "variableBorrowRate",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "liquidityIndex",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "variableBorrowIndex",
"type": "uint256"
}
],
"name": "ReserveDataUpdated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "reserve",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
}
],
"name": "ReserveUsedAsCollateralDisabled",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "reserve",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
}
],
"name": "ReserveUsedAsCollateralEnabled",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "reserve",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "rateMode",
"type": "uint256"
}
],
"name": "Swap",
"type": "event"
},
{
"anonymous": false,
"inputs": [],
"name": "Unpaused",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "reserve",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "Withdraw",
"type": "event"
},
{
"inputs": [],
"name": "FLASHLOAN_PREMIUM_TOTAL",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "LENDINGPOOL_REVISION",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "MAX_NUMBER_RESERVES",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "MAX_STABLE_RATE_BORROW_SIZE_PERCENT",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "asset",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "interestRateMode",
"type": "uint256"
},
{
"internalType": "uint16",
"name": "referralCode",
"type": "uint16"
},
{
"internalType": "address",
"name": "onBehalfOf",
"type": "address"
}
],
"name": "borrow",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "asset",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "address",
"name": "onBehalfOf",
"type": "address"
},
{
"internalType": "uint16",
"name": "referralCode",
"type": "uint16"
}
],
"name": "deposit",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "asset",
"type": "address"
},
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "balanceFromBefore",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "balanceToBefore",
"type": "uint256"
}
],
"name": "finalizeTransfer",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "receiverAddress",
"type": "address"
},
{
"internalType": "address[]",
"name": "assets",
"type": "address[]"
},
{
"internalType": "uint256[]",
"name": "amounts",
"type": "uint256[]"
},
{
"internalType": "uint256[]",
"name": "modes",
"type": "uint256[]"
},
{
"internalType": "address",
"name": "onBehalfOf",
"type": "address"
},
{
"internalType": "bytes",
"name": "params",
"type": "bytes"
},
{
"internalType": "uint16",
"name": "referralCode",
"type": "uint16"
}
],
"name": "flashLoan",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "getAddressesProvider",
"outputs": [
{
"internalType": "contract ILendingPoolAddressesProvider",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "asset",
"type": "address"
}
],
"name": "getConfiguration",
"outputs": [
{
"components": [
{
"internalType": "uint256",
"name": "data",
"type": "uint256"
}
],
"internalType": "struct DataTypes.ReserveConfigurationMap",
"name": "",
"type": "tuple"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "asset",
"type": "address"
}
],
"name": "getReserveData",
"outputs": [
{
"components": [
{
"components": [
{
"internalType": "uint256",
"name": "data",
"type": "uint256"
}
],
"internalType": "struct DataTypes.ReserveConfigurationMap",
"name": "configuration",
"type": "tuple"
},
{
"internalType": "uint128",
"name": "liquidityIndex",
"type": "uint128"
},
{
"internalType": "uint128",
"name": "variableBorrowIndex",
"type": "uint128"
},
{
"internalType": "uint128",
"name": "currentLiquidityRate",
"type": "uint128"
},
{
"internalType": "uint128",
"name": "currentVariableBorrowRate",
"type": "uint128"
},
{
"internalType": "uint128",
"name": "currentStableBorrowRate",
"type": "uint128"
},
{
"internalType": "uint40",
"name": "lastUpdateTimestamp",
"type": "uint40"
},
{
"internalType": "address",
"name": "aTokenAddress",
"type": "address"
},
{
"internalType": "address",
"name": "stableDebtTokenAddress",
"type": "address"
},
{
"internalType": "address",
"name": "variableDebtTokenAddress",
"type": "address"
},
{
"internalType": "address",
"name": "interestRateStrategyAddress",
"type": "address"
},
{
"internalType": "uint8",
"name": "id",
"type": "uint8"
}
],
"internalType": "struct DataTypes.ReserveData",
"name": "",
"type": "tuple"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "asset",
"type": "address"
}
],
"name": "getReserveNormalizedIncome",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "asset",
"type": "address"
}
],
"name": "getReserveNormalizedVariableDebt",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getReservesList",
"outputs": [
{
"internalType": "address[]",
"name": "",
"type": "address[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "user",
"type": "address"
}
],
"name": "getUserAccountData",
"outputs": [
{
"internalType": "uint256",
"name": "totalCollateralETH",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "totalDebtETH",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "availableBorrowsETH",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "currentLiquidationThreshold",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "ltv",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "healthFactor",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "user",
"type": "address"
}
],
"name": "getUserConfiguration",
"outputs": [
{
"components": [
{
"internalType": "uint256",
"name": "data",
"type": "uint256"
}
],
"internalType": "struct DataTypes.UserConfigurationMap",
"name": "",
"type": "tuple"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "asset",
"type": "address"
},
{
"internalType": "address",
"name": "aTokenAddress",
"type": "address"
},
{
"internalType": "address",
"name": "stableDebtAddress",
"type": "address"
},
{
"internalType": "address",
"name": "variableDebtAddress",
"type": "address"
},
{
"internalType": "address",
"name": "interestRateStrategyAddress",
"type": "address"
}
],
"name": "initReserve",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "contract ILendingPoolAddressesProvider",
"name": "provider",
"type": "address"
}
],
"name": "initialize",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "collateralAsset",
"type": "address"
},
{
"internalType": "address",
"name": "debtAsset",
"type": "address"
},
{
"internalType": "address",
"name": "user",
"type": "address"
},
{
"internalType": "uint256",
"name": "debtToCover",
"type": "uint256"
},
{
"internalType": "bool",
"name": "receiveAToken",
"type": "bool"
}
],
"name": "liquidationCall",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "paused",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "asset",
"type": "address"
},
{
"internalType": "address",
"name": "user",
"type": "address"
}
],
"name": "rebalanceStableBorrowRate",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "asset",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "rateMode",
"type": "uint256"
},
{
"internalType": "address",
"name": "onBehalfOf",
"type": "address"
}
],
"name": "repay",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "asset",
"type": "address"
},
{
"internalType": "uint256",
"name": "configuration",
"type": "uint256"
}
],
"name": "setConfiguration",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bool",
"name": "val",
"type": "bool"
}
],
"name": "setPause",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "asset",
"type": "address"
},
{
"internalType": "address",
"name": "rateStrategyAddress",
"type": "address"
}
],
"name": "setReserveInterestRateStrategyAddress",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "asset",
"type": "address"
},
{
"internalType": "bool",
"name": "useAsCollateral",
"type": "bool"
}
],
"name": "setUserUseReserveAsCollateral",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "asset",
"type": "address"
},
{
"internalType": "uint256",
"name": "rateMode",
"type": "uint256"
}
],
"name": "swapBorrowRateMode",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "asset",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "address",
"name": "to",
"type": "address"
}
],
"name": "withdraw",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
]
ILendingPool
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import {ILendingPoolAddressesProvider} from './ILendingPoolAddressesProvider.sol';
import {DataTypes} from './DataTypes.sol';
interface ILendingPool {
/**
* @dev Emitted on deposit()
* @param reserve The address of the underlying asset of the reserve
* @param user The address initiating the deposit
* @param onBehalfOf The beneficiary of the deposit, receiving the aTokens
* @param amount The amount deposited
* @param referral The referral code used
**/
event Deposit(
address indexed reserve,
address user,
address indexed onBehalfOf,
uint256 amount,
uint16 indexed referral
);
/**
* @dev Emitted on withdraw()
* @param reserve The address of the underlyng asset being withdrawn
* @param user The address initiating the withdrawal, owner of aTokens
* @param to Address that will receive the underlying
* @param amount The amount to be withdrawn
**/
event Withdraw(address indexed reserve, address indexed user, address indexed to, uint256 amount);
/**
* @dev Emitted on borrow() and flashLoan() when debt needs to be opened
* @param reserve The address of the underlying asset being borrowed
* @param user The address of the user initiating the borrow(), receiving the funds on borrow() or just
* initiator of the transaction on flashLoan()
* @param onBehalfOf The address that will be getting the debt
* @param amount The amount borrowed out
* @param borrowRateMode The rate mode: 1 for Stable, 2 for Variable
* @param borrowRate The numeric rate at which the user has borrowed
* @param referral The referral code used
**/
event Borrow(
address indexed reserve,
address user,
address indexed onBehalfOf,
uint256 amount,
uint256 borrowRateMode,
uint256 borrowRate,
uint16 indexed referral
);
/**
* @dev Emitted on repay()
* @param reserve The address of the underlying asset of the reserve
* @param user The beneficiary of the repayment, getting his debt reduced
* @param repayer The address of the user initiating the repay(), providing the funds
* @param amount The amount repaid
**/
event Repay(
address indexed reserve,
address indexed user,
address indexed repayer,
uint256 amount
);
/**
* @dev Emitted on swapBorrowRateMode()
* @param reserve The address of the underlying asset of the reserve
* @param user The address of the user swapping his rate mode
* @param rateMode The rate mode that the user wants to swap to
**/
event Swap(address indexed reserve, address indexed user, uint256 rateMode);
/**
* @dev Emitted on setUserUseReserveAsCollateral()
* @param reserve The address of the underlying asset of the reserve
* @param user The address of the user enabling the usage as collateral
**/
event ReserveUsedAsCollateralEnabled(address indexed reserve, address indexed user);
/**
* @dev Emitted on setUserUseReserveAsCollateral()
* @param reserve The address of the underlying asset of the reserve
* @param user The address of the user enabling the usage as collateral
**/
event ReserveUsedAsCollateralDisabled(address indexed reserve, address indexed user);
/**
* @dev Emitted on rebalanceStableBorrowRate()
* @param reserve The address of the underlying asset of the reserve
* @param user The address of the user for which the rebalance has been executed
**/
event RebalanceStableBorrowRate(address indexed reserve, address indexed user);
/**
* @dev Emitted on flashLoan()
* @param target The address of the flash loan receiver contract
* @param initiator The address initiating the flash loan
* @param asset The address of the asset being flash borrowed
* @param amount The amount flash borrowed
* @param premium The fee flash borrowed
* @param referralCode The referral code used
**/
event FlashLoan(
address indexed target,
address indexed initiator,
address indexed asset,
uint256 amount,
uint256 premium,
uint16 referralCode
);
/**
* @dev Emitted when the pause is triggered.
*/
event Paused();
/**
* @dev Emitted when the pause is lifted.
*/
event Unpaused();
/**
* @dev Emitted when a borrower is liquidated. This event is emitted by the LendingPool via
* LendingPoolCollateral manager using a DELEGATECALL
* This allows to have the events in the generated ABI for LendingPool.
* @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation
* @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation
* @param user The address of the borrower getting liquidated
* @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover
* @param liquidatedCollateralAmount The amount of collateral received by the liiquidator
* @param liquidator The address of the liquidator
* @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants
* to receive the underlying collateral asset directly
**/
event LiquidationCall(
address indexed collateralAsset,
address indexed debtAsset,
address indexed user,
uint256 debtToCover,
uint256 liquidatedCollateralAmount,
address liquidator,
bool receiveAToken
);
/**
* @dev Emitted when the state of a reserve is updated. NOTE: This event is actually declared
* in the ReserveLogic library and emitted in the updateInterestRates() function. Since the function is internal,
* the event will actually be fired by the LendingPool contract. The event is therefore replicated here so it
* gets added to the LendingPool ABI
* @param reserve The address of the underlying asset of the reserve
* @param liquidityRate The new liquidity rate
* @param stableBorrowRate The new stable borrow rate
* @param variableBorrowRate The new variable borrow rate
* @param liquidityIndex The new liquidity index
* @param variableBorrowIndex The new variable borrow index
**/
event ReserveDataUpdated(
address indexed reserve,
uint256 liquidityRate,
uint256 stableBorrowRate,
uint256 variableBorrowRate,
uint256 liquidityIndex,
uint256 variableBorrowIndex
);
/**
* @dev Deposits an `amount` of underlying asset into the reserve, receiving in return overlying aTokens.
* - E.g. User deposits 100 USDC and gets in return 100 aUSDC
* @param asset The address of the underlying asset to deposit
* @param amount The amount to be deposited
* @param onBehalfOf The address that will receive the aTokens, same as msg.sender if the user
* wants to receive them on his own wallet, or a different address if the beneficiary of aTokens
* is a different wallet
* @param referralCode 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
**/
function deposit(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode
) external;
/**
* @dev Withdraws an `amount` of underlying asset from the reserve, burning the equivalent aTokens owned
* E.g. User has 100 aUSDC, calls withdraw() and receives 100 USDC, burning the 100 aUSDC
* @param asset The address of the underlying asset to withdraw
* @param amount The underlying amount to be withdrawn
* - Send the value type(uint256).max in order to withdraw the whole aToken balance
* @param to Address that will receive the underlying, same as msg.sender if the user
* wants to receive it on his own wallet, or a different address if the beneficiary is a
* different wallet
* @return The final amount withdrawn
**/
function withdraw(
address asset,
uint256 amount,
address to
) external returns (uint256);
/**
* @dev Allows users to borrow a specific `amount` of the reserve underlying asset, provided that the borrower
* already deposited enough collateral, or he was given enough allowance by a credit delegator on the
* corresponding debt token (StableDebtToken or VariableDebtToken)
* - E.g. User borrows 100 USDC passing as `onBehalfOf` his own address, receiving the 100 USDC in his wallet
* and 100 stable/variable debt tokens, depending on the `interestRateMode`
* @param asset The address of the underlying asset to borrow
* @param amount The amount to be borrowed
* @param interestRateMode The interest rate mode at which the user wants to borrow: 1 for Stable, 2 for Variable
* @param referralCode 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
* @param onBehalfOf Address of the user who will receive the debt. Should be the address of the borrower itself
* calling the function if he wants to borrow against his own collateral, or the address of the credit delegator
* if he has been given credit delegation allowance
**/
function borrow(
address asset,
uint256 amount,
uint256 interestRateMode,
uint16 referralCode,
address onBehalfOf
) external;
/**
* @notice Repays a borrowed `amount` on a specific reserve, burning the equivalent debt tokens owned
* - E.g. User repays 100 USDC, burning 100 variable/stable debt tokens of the `onBehalfOf` address
* @param asset The address of the borrowed underlying asset previously borrowed
* @param amount The amount to repay
* - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode`
* @param rateMode The interest rate mode at of the debt the user wants to repay: 1 for Stable, 2 for Variable
* @param onBehalfOf Address of the user who will get his debt reduced/removed. Should be the address of the
* user calling the function if he wants to reduce/remove his own debt, or the address of any other
* other borrower whose debt should be removed
* @return The final amount repaid
**/
function repay(
address asset,
uint256 amount,
uint256 rateMode,
address onBehalfOf
) external returns (uint256);
/**
* @dev Allows a borrower to swap his debt between stable and variable mode, or viceversa
* @param asset The address of the underlying asset borrowed
* @param rateMode The rate mode that the user wants to swap to
**/
function swapBorrowRateMode(address asset, uint256 rateMode) external;
/**
* @dev Rebalances the stable interest rate of a user to the current stable rate defined on the reserve.
* - Users can be rebalanced if the following conditions are satisfied:
* 1. Usage ratio is above 95%
* 2. the current deposit APY is below REBALANCE_UP_THRESHOLD * maxVariableBorrowRate, which means that too much has been
* borrowed at a stable rate and depositors are not earning enough
* @param asset The address of the underlying asset borrowed
* @param user The address of the user to be rebalanced
**/
function rebalanceStableBorrowRate(address asset, address user) external;
/**
* @dev Allows depositors to enable/disable a specific deposited asset as collateral
* @param asset The address of the underlying asset deposited
* @param useAsCollateral `true` if the user wants to use the deposit as collateral, `false` otherwise
**/
function setUserUseReserveAsCollateral(address asset, bool useAsCollateral) external;
/**
* @dev Function to liquidate a non-healthy position collateral-wise, with Health Factor below 1
* - The caller (liquidator) covers `debtToCover` amount of debt of the user getting liquidated, and receives
* a proportionally amount of the `collateralAsset` plus a bonus to cover market risk
* @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation
* @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation
* @param user The address of the borrower getting liquidated
* @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover
* @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants
* to receive the underlying collateral asset directly
**/
function liquidationCall(
address collateralAsset,
address debtAsset,
address user,
uint256 debtToCover,
bool receiveAToken
) external;
/**
* @dev Allows smartcontracts to access the liquidity of the pool within one transaction,
* as long as the amount taken plus a fee is returned.
* IMPORTANT There are security concerns for developers of flashloan receiver contracts that must be kept into consideration.
* For further details please visit https://developers.aave.com
* @param receiverAddress The address of the contract receiving the funds, implementing the IFlashLoanReceiver interface
* @param assets The addresses of the assets being flash-borrowed
* @param amounts The amounts amounts being flash-borrowed
* @param modes Types of the debt to open if the flash loan is not returned:
* 0 -> Don't open any debt, just revert if funds can't be transferred from the receiver
* 1 -> Open debt at stable rate for the value of the amount flash-borrowed to the `onBehalfOf` address
* 2 -> Open debt at variable rate for the value of the amount flash-borrowed to the `onBehalfOf` address
* @param onBehalfOf The address that will receive the debt in the case of using on `modes` 1 or 2
* @param params Variadic packed params to pass to the receiver as extra information
* @param referralCode 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
**/
function flashLoan(
address receiverAddress,
address[] calldata assets,
uint256[] calldata amounts,
uint256[] calldata modes,
address onBehalfOf,
bytes calldata params,
uint16 referralCode
) external;
/**
* @dev Returns the user account data across all the reserves
* @param user The address of the user
* @return totalCollateralETH the total collateral in ETH of the user
* @return totalDebtETH the total debt in ETH of the user
* @return availableBorrowsETH the borrowing power left of the user
* @return currentLiquidationThreshold the liquidation threshold of the user
* @return ltv the loan to value of the user
* @return healthFactor the current health factor of the user
**/
function getUserAccountData(address user)
external
view
returns (
uint256 totalCollateralETH,
uint256 totalDebtETH,
uint256 availableBorrowsETH,
uint256 currentLiquidationThreshold,
uint256 ltv,
uint256 healthFactor
);
function initReserve(
address reserve,
address aTokenAddress,
address stableDebtAddress,
address variableDebtAddress,
address interestRateStrategyAddress
) external;
function setReserveInterestRateStrategyAddress(address reserve, address rateStrategyAddress)
external;
function setConfiguration(address reserve, uint256 configuration) external;
/**
* @dev Returns the configuration of the reserve
* @param asset The address of the underlying asset of the reserve
* @return The configuration of the reserve
**/
function getConfiguration(address asset)
external
view
returns (DataTypes.ReserveConfigurationMap memory);
/**
* @dev Returns the configuration of the user across all the reserves
* @param user The user address
* @return The configuration of the user
**/
function getUserConfiguration(address user)
external
view
returns (DataTypes.UserConfigurationMap memory);
/**
* @dev Returns the normalized income normalized income of the reserve
* @param asset The address of the underlying asset of the reserve
* @return The reserve's normalized income
*/
function getReserveNormalizedIncome(address asset) external view returns (uint256);
/**
* @dev Returns the normalized variable debt per unit of asset
* @param asset The address of the underlying asset of the reserve
* @return The reserve normalized variable debt
*/
function getReserveNormalizedVariableDebt(address asset) external view returns (uint256);
/**
* @dev Returns the state and configuration of the reserve
* @param asset The address of the underlying asset of the reserve
* @return The state of the reserve
**/
function getReserveData(address asset) external view returns (DataTypes.ReserveData memory);
function finalizeTransfer(
address asset,
address from,
address to,
uint256 amount,
uint256 balanceFromAfter,
uint256 balanceToBefore
) external;
function getReservesList() external view returns (address[] memory);
function getAddressesProvider() external view returns (ILendingPoolAddressesProvider);
function setPause(bool val) external;
function paused() external view returns (bool);
}