diff --git a/.changeset/cold-years-study.md b/.changeset/cold-years-study.md new file mode 100644 index 00000000..65068a71 --- /dev/null +++ b/.changeset/cold-years-study.md @@ -0,0 +1,5 @@ +--- +'@protocolink/logics': minor +--- + +add IOLEND diff --git a/.env.iota.pb b/.env.iota.pb index 19039ea5..93c8c8a3 100644 --- a/.env.iota.pb +++ b/.env.iota.pb @@ -1,3 +1,3 @@ CHAIN_ID=8822 -BLOCK_NUMBER=292100 +BLOCK_NUMBER=1126425 HTTP_RPC_URL=https://json-rpc.evm.iotaledger.net diff --git a/src/logics/index.ts b/src/logics/index.ts index af5166ae..9719c2fc 100644 --- a/src/logics/index.ts +++ b/src/logics/index.ts @@ -3,6 +3,7 @@ export * as aavev3 from './aave-v3'; export * as balancerv2 from './balancer-v2'; export * as compoundv2 from './compound-v2'; export * as compoundv3 from './compound-v3'; +export * as iolend from './iolend'; export * as magicsea from './magicsea'; export * as morphoblue from './morphoblue'; export * as openoceanv2 from './openocean-v2'; diff --git a/src/logics/iolend/abis/DebtTokenBase.json b/src/logics/iolend/abis/DebtTokenBase.json new file mode 100644 index 00000000..269b9394 --- /dev/null +++ b/src/logics/iolend/abis/DebtTokenBase.json @@ -0,0 +1,44 @@ +[ + { + "inputs": [ + { + "internalType": "address", + "name": "delegatee", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "approveDelegation", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "fromUser", + "type": "address" + }, + { + "internalType": "address", + "name": "toUser", + "type": "address" + } + ], + "name": "borrowAllowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/src/logics/iolend/abis/LendingPool.json b/src/logics/iolend/abis/LendingPool.json new file mode 100644 index 00000000..ea413785 --- /dev/null +++ b/src/logics/iolend/abis/LendingPool.json @@ -0,0 +1,1163 @@ +[ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "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": "delegatee", + "type": "address" + } + ], + "name": "delegateWithdraw", + "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": "delegatee", + "type": "address" + } + ], + "name": "undelegateWithdraw", + "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" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "asset", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "address", + "name": "onBehalfOf", + "type": "address" + } + ], + "name": "withdraw", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "user", + "type": "address" + } + ], + "name": "withdrawDelegatesOf", + "outputs": [ + { + "internalType": "address[]", + "name": "", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/src/logics/iolend/abis/LendingPoolAddressesProvider.json b/src/logics/iolend/abis/LendingPoolAddressesProvider.json new file mode 100644 index 00000000..2d5b6250 --- /dev/null +++ b/src/logics/iolend/abis/LendingPoolAddressesProvider.json @@ -0,0 +1,502 @@ +[ + { + "inputs": [ + { + "internalType": "string", + "name": "marketId", + "type": "string" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "bytes32", + "name": "id", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "newAddress", + "type": "address" + }, + { + "indexed": false, + "internalType": "bool", + "name": "hasProxy", + "type": "bool" + } + ], + "name": "AddressSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "newAddress", + "type": "address" + } + ], + "name": "ConfigurationAdminUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "newAddress", + "type": "address" + } + ], + "name": "EmergencyAdminUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "newAddress", + "type": "address" + } + ], + "name": "LendingPoolCollateralManagerUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "newAddress", + "type": "address" + } + ], + "name": "LendingPoolConfiguratorUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "newAddress", + "type": "address" + } + ], + "name": "LendingPoolUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "newAddress", + "type": "address" + } + ], + "name": "LendingRateOracleUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "newMarketId", + "type": "string" + } + ], + "name": "MarketIdSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "newAddress", + "type": "address" + } + ], + "name": "PriceOracleUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "bytes32", + "name": "id", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "newAddress", + "type": "address" + } + ], + "name": "ProxyCreated", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "id", + "type": "bytes32" + } + ], + "name": "getAddress", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getEmergencyAdmin", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getLendingPool", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getLendingPoolCollateralManager", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getLendingPoolConfigurator", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getLendingRateOracle", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getLiquidationFeeTo", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getMarketId", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getPoolAdmin", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getPriceOracle", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "id", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "newAddress", + "type": "address" + } + ], + "name": "setAddress", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "id", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "implementationAddress", + "type": "address" + } + ], + "name": "setAddressAsProxy", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "emergencyAdmin", + "type": "address" + } + ], + "name": "setEmergencyAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "manager", + "type": "address" + } + ], + "name": "setLendingPoolCollateralManager", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "configurator", + "type": "address" + } + ], + "name": "setLendingPoolConfiguratorImpl", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + } + ], + "name": "setLendingPoolImpl", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "lendingRateOracle", + "type": "address" + } + ], + "name": "setLendingRateOracle", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "liquidationFeeTo", + "type": "address" + } + ], + "name": "setLiquidationFeeTo", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "marketId", + "type": "string" + } + ], + "name": "setMarketId", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "admin", + "type": "address" + } + ], + "name": "setPoolAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "priceOracle", + "type": "address" + } + ], + "name": "setPriceOracle", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/src/logics/iolend/abis/ProtocolDataProvider.json b/src/logics/iolend/abis/ProtocolDataProvider.json new file mode 100644 index 00000000..6da4e3f1 --- /dev/null +++ b/src/logics/iolend/abis/ProtocolDataProvider.json @@ -0,0 +1,297 @@ +[ + { + "inputs": [ + { + "internalType": "contract ILendingPoolAddressesProvider", + "name": "addressesProvider", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [], + "name": "ADDRESSES_PROVIDER", + "outputs": [ + { + "internalType": "contract ILendingPoolAddressesProvider", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getAllATokens", + "outputs": [ + { + "components": [ + { + "internalType": "string", + "name": "symbol", + "type": "string" + }, + { + "internalType": "address", + "name": "tokenAddress", + "type": "address" + } + ], + "internalType": "struct AaveProtocolDataProvider.TokenData[]", + "name": "", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getAllReservesTokens", + "outputs": [ + { + "components": [ + { + "internalType": "string", + "name": "symbol", + "type": "string" + }, + { + "internalType": "address", + "name": "tokenAddress", + "type": "address" + } + ], + "internalType": "struct AaveProtocolDataProvider.TokenData[]", + "name": "", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "asset", + "type": "address" + } + ], + "name": "getReserveConfigurationData", + "outputs": [ + { + "internalType": "uint256", + "name": "decimals", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "ltv", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidationThreshold", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidationBonus", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "reserveFactor", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "usageAsCollateralEnabled", + "type": "bool" + }, + { + "internalType": "bool", + "name": "borrowingEnabled", + "type": "bool" + }, + { + "internalType": "bool", + "name": "stableBorrowRateEnabled", + "type": "bool" + }, + { + "internalType": "bool", + "name": "isActive", + "type": "bool" + }, + { + "internalType": "bool", + "name": "isFrozen", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "asset", + "type": "address" + } + ], + "name": "getReserveData", + "outputs": [ + { + "internalType": "uint256", + "name": "availableLiquidity", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalStableDebt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalVariableDebt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityRate", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "variableBorrowRate", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "stableBorrowRate", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "averageStableBorrowRate", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityIndex", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "variableBorrowIndex", + "type": "uint256" + }, + { + "internalType": "uint40", + "name": "lastUpdateTimestamp", + "type": "uint40" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "asset", + "type": "address" + } + ], + "name": "getReserveTokensAddresses", + "outputs": [ + { + "internalType": "address", + "name": "aTokenAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "stableDebtTokenAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "variableDebtTokenAddress", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "asset", + "type": "address" + }, + { + "internalType": "address", + "name": "user", + "type": "address" + } + ], + "name": "getUserReserveData", + "outputs": [ + { + "internalType": "uint256", + "name": "currentATokenBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "currentStableDebt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "currentVariableDebt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "principalStableDebt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "scaledVariableDebt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "stableBorrowRate", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityRate", + "type": "uint256" + }, + { + "internalType": "uint40", + "name": "stableRateLastUpdated", + "type": "uint40" + }, + { + "internalType": "bool", + "name": "usageAsCollateralEnabled", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/src/logics/iolend/configs.ts b/src/logics/iolend/configs.ts new file mode 100644 index 00000000..00350283 --- /dev/null +++ b/src/logics/iolend/configs.ts @@ -0,0 +1,32 @@ +import * as common from '@protocolink/common'; + +export const protocolId = 'iolend'; + +type ContractNames = 'ProtocolDataProvider'; + +export interface Config { + chainId: number; + contract: Record; +} + +export const configs: Config[] = [ + { + chainId: common.ChainId.iota, + contract: { + ProtocolDataProvider: '0x779a294CF4D200936881c4c8d0771b8a1935fB5B', + }, + }, +]; + +export const [supportedChainIds, configMap] = configs.reduce( + (accumulator, config) => { + accumulator[0].push(config.chainId); + accumulator[1][config.chainId] = config; + return accumulator; + }, + [[], {}] as [number[], Record] +); + +export function getContractAddress(chainId: number, name: ContractNames) { + return configMap[chainId].contract[name]; +} diff --git a/src/logics/iolend/contracts/DebtTokenBase.ts b/src/logics/iolend/contracts/DebtTokenBase.ts new file mode 100644 index 00000000..d7461f3f --- /dev/null +++ b/src/logics/iolend/contracts/DebtTokenBase.ts @@ -0,0 +1,104 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BigNumber, + BigNumberish, + BytesLike, + CallOverrides, + ContractTransaction, + Overrides, + PopulatedTransaction, + Signer, + utils, +} from 'ethers'; +import type { FunctionFragment, Result } from '@ethersproject/abi'; +import type { Listener, Provider } from '@ethersproject/providers'; +import type { TypedEventFilter, TypedEvent, TypedListener, OnEvent } from './common'; + +export interface DebtTokenBaseInterface extends utils.Interface { + functions: { + 'approveDelegation(address,uint256)': FunctionFragment; + 'borrowAllowance(address,address)': FunctionFragment; + }; + + getFunction(nameOrSignatureOrTopic: 'approveDelegation' | 'borrowAllowance'): FunctionFragment; + + encodeFunctionData(functionFragment: 'approveDelegation', values: [string, BigNumberish]): string; + encodeFunctionData(functionFragment: 'borrowAllowance', values: [string, string]): string; + + decodeFunctionResult(functionFragment: 'approveDelegation', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'borrowAllowance', data: BytesLike): Result; + + events: {}; +} + +export interface DebtTokenBase extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: DebtTokenBaseInterface; + + queryFilter( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>; + + listeners(eventFilter?: TypedEventFilter): Array>; + listeners(eventName?: string): Array; + removeAllListeners(eventFilter: TypedEventFilter): this; + removeAllListeners(eventName?: string): this; + off: OnEvent; + on: OnEvent; + once: OnEvent; + removeListener: OnEvent; + + functions: { + approveDelegation( + delegatee: string, + amount: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + borrowAllowance(fromUser: string, toUser: string, overrides?: CallOverrides): Promise<[BigNumber]>; + }; + + approveDelegation( + delegatee: string, + amount: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + borrowAllowance(fromUser: string, toUser: string, overrides?: CallOverrides): Promise; + + callStatic: { + approveDelegation(delegatee: string, amount: BigNumberish, overrides?: CallOverrides): Promise; + + borrowAllowance(fromUser: string, toUser: string, overrides?: CallOverrides): Promise; + }; + + filters: {}; + + estimateGas: { + approveDelegation( + delegatee: string, + amount: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + borrowAllowance(fromUser: string, toUser: string, overrides?: CallOverrides): Promise; + }; + + populateTransaction: { + approveDelegation( + delegatee: string, + amount: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + borrowAllowance(fromUser: string, toUser: string, overrides?: CallOverrides): Promise; + }; +} diff --git a/src/logics/iolend/contracts/LendingPool.ts b/src/logics/iolend/contracts/LendingPool.ts new file mode 100644 index 00000000..a73933d8 --- /dev/null +++ b/src/logics/iolend/contracts/LendingPool.ts @@ -0,0 +1,1321 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BigNumber, + BigNumberish, + BytesLike, + CallOverrides, + ContractTransaction, + Overrides, + PopulatedTransaction, + Signer, + utils, +} from 'ethers'; +import type { FunctionFragment, Result, EventFragment } from '@ethersproject/abi'; +import type { Listener, Provider } from '@ethersproject/providers'; +import type { TypedEventFilter, TypedEvent, TypedListener, OnEvent } from './common'; + +export declare namespace DataTypes { + export type ReserveConfigurationMapStruct = { data: BigNumberish }; + + export type ReserveConfigurationMapStructOutput = [BigNumber] & { + data: BigNumber; + }; + + export type ReserveDataStruct = { + configuration: DataTypes.ReserveConfigurationMapStruct; + liquidityIndex: BigNumberish; + variableBorrowIndex: BigNumberish; + currentLiquidityRate: BigNumberish; + currentVariableBorrowRate: BigNumberish; + currentStableBorrowRate: BigNumberish; + lastUpdateTimestamp: BigNumberish; + aTokenAddress: string; + stableDebtTokenAddress: string; + variableDebtTokenAddress: string; + interestRateStrategyAddress: string; + id: BigNumberish; + }; + + export type ReserveDataStructOutput = [ + DataTypes.ReserveConfigurationMapStructOutput, + BigNumber, + BigNumber, + BigNumber, + BigNumber, + BigNumber, + number, + string, + string, + string, + string, + number + ] & { + configuration: DataTypes.ReserveConfigurationMapStructOutput; + liquidityIndex: BigNumber; + variableBorrowIndex: BigNumber; + currentLiquidityRate: BigNumber; + currentVariableBorrowRate: BigNumber; + currentStableBorrowRate: BigNumber; + lastUpdateTimestamp: number; + aTokenAddress: string; + stableDebtTokenAddress: string; + variableDebtTokenAddress: string; + interestRateStrategyAddress: string; + id: number; + }; + + export type UserConfigurationMapStruct = { data: BigNumberish }; + + export type UserConfigurationMapStructOutput = [BigNumber] & { + data: BigNumber; + }; +} + +export interface LendingPoolInterface extends utils.Interface { + functions: { + 'FLASHLOAN_PREMIUM_TOTAL()': FunctionFragment; + 'LENDINGPOOL_REVISION()': FunctionFragment; + 'MAX_NUMBER_RESERVES()': FunctionFragment; + 'MAX_STABLE_RATE_BORROW_SIZE_PERCENT()': FunctionFragment; + 'borrow(address,uint256,uint256,uint16,address)': FunctionFragment; + 'delegateWithdraw(address)': FunctionFragment; + 'deposit(address,uint256,address,uint16)': FunctionFragment; + 'finalizeTransfer(address,address,address,uint256,uint256,uint256)': FunctionFragment; + 'flashLoan(address,address[],uint256[],uint256[],address,bytes,uint16)': FunctionFragment; + 'getAddressesProvider()': FunctionFragment; + 'getConfiguration(address)': FunctionFragment; + 'getReserveData(address)': FunctionFragment; + 'getReserveNormalizedIncome(address)': FunctionFragment; + 'getReserveNormalizedVariableDebt(address)': FunctionFragment; + 'getReservesList()': FunctionFragment; + 'getUserAccountData(address)': FunctionFragment; + 'getUserConfiguration(address)': FunctionFragment; + 'initReserve(address,address,address,address,address)': FunctionFragment; + 'initialize(address)': FunctionFragment; + 'liquidationCall(address,address,address,uint256,bool)': FunctionFragment; + 'paused()': FunctionFragment; + 'rebalanceStableBorrowRate(address,address)': FunctionFragment; + 'repay(address,uint256,uint256,address)': FunctionFragment; + 'setConfiguration(address,uint256)': FunctionFragment; + 'setPause(bool)': FunctionFragment; + 'setReserveInterestRateStrategyAddress(address,address)': FunctionFragment; + 'setUserUseReserveAsCollateral(address,bool)': FunctionFragment; + 'swapBorrowRateMode(address,uint256)': FunctionFragment; + 'undelegateWithdraw(address)': FunctionFragment; + 'withdraw(address,uint256,address)': FunctionFragment; + 'withdraw(address,uint256,address,address)': FunctionFragment; + 'withdrawDelegatesOf(address)': FunctionFragment; + }; + + getFunction( + nameOrSignatureOrTopic: + | 'FLASHLOAN_PREMIUM_TOTAL' + | 'LENDINGPOOL_REVISION' + | 'MAX_NUMBER_RESERVES' + | 'MAX_STABLE_RATE_BORROW_SIZE_PERCENT' + | 'borrow' + | 'delegateWithdraw' + | 'deposit' + | 'finalizeTransfer' + | 'flashLoan' + | 'getAddressesProvider' + | 'getConfiguration' + | 'getReserveData' + | 'getReserveNormalizedIncome' + | 'getReserveNormalizedVariableDebt' + | 'getReservesList' + | 'getUserAccountData' + | 'getUserConfiguration' + | 'initReserve' + | 'initialize' + | 'liquidationCall' + | 'paused' + | 'rebalanceStableBorrowRate' + | 'repay' + | 'setConfiguration' + | 'setPause' + | 'setReserveInterestRateStrategyAddress' + | 'setUserUseReserveAsCollateral' + | 'swapBorrowRateMode' + | 'undelegateWithdraw' + | 'withdraw(address,uint256,address)' + | 'withdraw(address,uint256,address,address)' + | 'withdrawDelegatesOf' + ): FunctionFragment; + + encodeFunctionData(functionFragment: 'FLASHLOAN_PREMIUM_TOTAL', values?: undefined): string; + encodeFunctionData(functionFragment: 'LENDINGPOOL_REVISION', values?: undefined): string; + encodeFunctionData(functionFragment: 'MAX_NUMBER_RESERVES', values?: undefined): string; + encodeFunctionData(functionFragment: 'MAX_STABLE_RATE_BORROW_SIZE_PERCENT', values?: undefined): string; + encodeFunctionData( + functionFragment: 'borrow', + values: [string, BigNumberish, BigNumberish, BigNumberish, string] + ): string; + encodeFunctionData(functionFragment: 'delegateWithdraw', values: [string]): string; + encodeFunctionData(functionFragment: 'deposit', values: [string, BigNumberish, string, BigNumberish]): string; + encodeFunctionData( + functionFragment: 'finalizeTransfer', + values: [string, string, string, BigNumberish, BigNumberish, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: 'flashLoan', + values: [string, string[], BigNumberish[], BigNumberish[], string, BytesLike, BigNumberish] + ): string; + encodeFunctionData(functionFragment: 'getAddressesProvider', values?: undefined): string; + encodeFunctionData(functionFragment: 'getConfiguration', values: [string]): string; + encodeFunctionData(functionFragment: 'getReserveData', values: [string]): string; + encodeFunctionData(functionFragment: 'getReserveNormalizedIncome', values: [string]): string; + encodeFunctionData(functionFragment: 'getReserveNormalizedVariableDebt', values: [string]): string; + encodeFunctionData(functionFragment: 'getReservesList', values?: undefined): string; + encodeFunctionData(functionFragment: 'getUserAccountData', values: [string]): string; + encodeFunctionData(functionFragment: 'getUserConfiguration', values: [string]): string; + encodeFunctionData(functionFragment: 'initReserve', values: [string, string, string, string, string]): string; + encodeFunctionData(functionFragment: 'initialize', values: [string]): string; + encodeFunctionData( + functionFragment: 'liquidationCall', + values: [string, string, string, BigNumberish, boolean] + ): string; + encodeFunctionData(functionFragment: 'paused', values?: undefined): string; + encodeFunctionData(functionFragment: 'rebalanceStableBorrowRate', values: [string, string]): string; + encodeFunctionData(functionFragment: 'repay', values: [string, BigNumberish, BigNumberish, string]): string; + encodeFunctionData(functionFragment: 'setConfiguration', values: [string, BigNumberish]): string; + encodeFunctionData(functionFragment: 'setPause', values: [boolean]): string; + encodeFunctionData(functionFragment: 'setReserveInterestRateStrategyAddress', values: [string, string]): string; + encodeFunctionData(functionFragment: 'setUserUseReserveAsCollateral', values: [string, boolean]): string; + encodeFunctionData(functionFragment: 'swapBorrowRateMode', values: [string, BigNumberish]): string; + encodeFunctionData(functionFragment: 'undelegateWithdraw', values: [string]): string; + encodeFunctionData( + functionFragment: 'withdraw(address,uint256,address)', + values: [string, BigNumberish, string] + ): string; + encodeFunctionData( + functionFragment: 'withdraw(address,uint256,address,address)', + values: [string, BigNumberish, string, string] + ): string; + encodeFunctionData(functionFragment: 'withdrawDelegatesOf', values: [string]): string; + + decodeFunctionResult(functionFragment: 'FLASHLOAN_PREMIUM_TOTAL', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'LENDINGPOOL_REVISION', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'MAX_NUMBER_RESERVES', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'MAX_STABLE_RATE_BORROW_SIZE_PERCENT', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'borrow', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'delegateWithdraw', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'deposit', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'finalizeTransfer', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'flashLoan', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getAddressesProvider', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getConfiguration', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getReserveData', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getReserveNormalizedIncome', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getReserveNormalizedVariableDebt', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getReservesList', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getUserAccountData', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getUserConfiguration', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'initReserve', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'initialize', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'liquidationCall', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'paused', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'rebalanceStableBorrowRate', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'repay', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setConfiguration', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setPause', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setReserveInterestRateStrategyAddress', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setUserUseReserveAsCollateral', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'swapBorrowRateMode', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'undelegateWithdraw', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'withdraw(address,uint256,address)', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'withdraw(address,uint256,address,address)', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'withdrawDelegatesOf', data: BytesLike): Result; + + events: { + 'Borrow(address,address,address,uint256,uint256,uint256,uint16)': EventFragment; + 'Deposit(address,address,address,uint256,uint16)': EventFragment; + 'FlashLoan(address,address,address,uint256,uint256,uint16)': EventFragment; + 'LiquidationCall(address,address,address,uint256,uint256,address,bool)': EventFragment; + 'Paused()': EventFragment; + 'RebalanceStableBorrowRate(address,address)': EventFragment; + 'Repay(address,address,address,uint256)': EventFragment; + 'ReserveDataUpdated(address,uint256,uint256,uint256,uint256,uint256)': EventFragment; + 'ReserveUsedAsCollateralDisabled(address,address)': EventFragment; + 'ReserveUsedAsCollateralEnabled(address,address)': EventFragment; + 'Swap(address,address,uint256)': EventFragment; + 'Unpaused()': EventFragment; + 'Withdraw(address,address,address,uint256)': EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: 'Borrow'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'Deposit'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'FlashLoan'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LiquidationCall'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'Paused'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'RebalanceStableBorrowRate'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'Repay'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'ReserveDataUpdated'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'ReserveUsedAsCollateralDisabled'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'ReserveUsedAsCollateralEnabled'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'Swap'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'Unpaused'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'Withdraw'): EventFragment; +} + +export interface BorrowEventObject { + reserve: string; + user: string; + onBehalfOf: string; + amount: BigNumber; + borrowRateMode: BigNumber; + borrowRate: BigNumber; + referral: number; +} +export type BorrowEvent = TypedEvent< + [string, string, string, BigNumber, BigNumber, BigNumber, number], + BorrowEventObject +>; + +export type BorrowEventFilter = TypedEventFilter; + +export interface DepositEventObject { + reserve: string; + user: string; + onBehalfOf: string; + amount: BigNumber; + referral: number; +} +export type DepositEvent = TypedEvent<[string, string, string, BigNumber, number], DepositEventObject>; + +export type DepositEventFilter = TypedEventFilter; + +export interface FlashLoanEventObject { + target: string; + initiator: string; + asset: string; + amount: BigNumber; + premium: BigNumber; + referralCode: number; +} +export type FlashLoanEvent = TypedEvent<[string, string, string, BigNumber, BigNumber, number], FlashLoanEventObject>; + +export type FlashLoanEventFilter = TypedEventFilter; + +export interface LiquidationCallEventObject { + collateralAsset: string; + debtAsset: string; + user: string; + debtToCover: BigNumber; + liquidatedCollateralAmount: BigNumber; + liquidator: string; + receiveAToken: boolean; +} +export type LiquidationCallEvent = TypedEvent< + [string, string, string, BigNumber, BigNumber, string, boolean], + LiquidationCallEventObject +>; + +export type LiquidationCallEventFilter = TypedEventFilter; + +export interface PausedEventObject {} +export type PausedEvent = TypedEvent<[], PausedEventObject>; + +export type PausedEventFilter = TypedEventFilter; + +export interface RebalanceStableBorrowRateEventObject { + reserve: string; + user: string; +} +export type RebalanceStableBorrowRateEvent = TypedEvent<[string, string], RebalanceStableBorrowRateEventObject>; + +export type RebalanceStableBorrowRateEventFilter = TypedEventFilter; + +export interface RepayEventObject { + reserve: string; + user: string; + repayer: string; + amount: BigNumber; +} +export type RepayEvent = TypedEvent<[string, string, string, BigNumber], RepayEventObject>; + +export type RepayEventFilter = TypedEventFilter; + +export interface ReserveDataUpdatedEventObject { + reserve: string; + liquidityRate: BigNumber; + stableBorrowRate: BigNumber; + variableBorrowRate: BigNumber; + liquidityIndex: BigNumber; + variableBorrowIndex: BigNumber; +} +export type ReserveDataUpdatedEvent = TypedEvent< + [string, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber], + ReserveDataUpdatedEventObject +>; + +export type ReserveDataUpdatedEventFilter = TypedEventFilter; + +export interface ReserveUsedAsCollateralDisabledEventObject { + reserve: string; + user: string; +} +export type ReserveUsedAsCollateralDisabledEvent = TypedEvent< + [string, string], + ReserveUsedAsCollateralDisabledEventObject +>; + +export type ReserveUsedAsCollateralDisabledEventFilter = TypedEventFilter; + +export interface ReserveUsedAsCollateralEnabledEventObject { + reserve: string; + user: string; +} +export type ReserveUsedAsCollateralEnabledEvent = TypedEvent< + [string, string], + ReserveUsedAsCollateralEnabledEventObject +>; + +export type ReserveUsedAsCollateralEnabledEventFilter = TypedEventFilter; + +export interface SwapEventObject { + reserve: string; + user: string; + rateMode: BigNumber; +} +export type SwapEvent = TypedEvent<[string, string, BigNumber], SwapEventObject>; + +export type SwapEventFilter = TypedEventFilter; + +export interface UnpausedEventObject {} +export type UnpausedEvent = TypedEvent<[], UnpausedEventObject>; + +export type UnpausedEventFilter = TypedEventFilter; + +export interface WithdrawEventObject { + reserve: string; + user: string; + to: string; + amount: BigNumber; +} +export type WithdrawEvent = TypedEvent<[string, string, string, BigNumber], WithdrawEventObject>; + +export type WithdrawEventFilter = TypedEventFilter; + +export interface LendingPool extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: LendingPoolInterface; + + queryFilter( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>; + + listeners(eventFilter?: TypedEventFilter): Array>; + listeners(eventName?: string): Array; + removeAllListeners(eventFilter: TypedEventFilter): this; + removeAllListeners(eventName?: string): this; + off: OnEvent; + on: OnEvent; + once: OnEvent; + removeListener: OnEvent; + + functions: { + FLASHLOAN_PREMIUM_TOTAL(overrides?: CallOverrides): Promise<[BigNumber]>; + + LENDINGPOOL_REVISION(overrides?: CallOverrides): Promise<[BigNumber]>; + + MAX_NUMBER_RESERVES(overrides?: CallOverrides): Promise<[BigNumber]>; + + MAX_STABLE_RATE_BORROW_SIZE_PERCENT(overrides?: CallOverrides): Promise<[BigNumber]>; + + borrow( + asset: string, + amount: BigNumberish, + interestRateMode: BigNumberish, + referralCode: BigNumberish, + onBehalfOf: string, + overrides?: Overrides & { from?: string } + ): Promise; + + delegateWithdraw(delegatee: string, overrides?: Overrides & { from?: string }): Promise; + + deposit( + asset: string, + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + finalizeTransfer( + asset: string, + from: string, + to: string, + amount: BigNumberish, + balanceFromBefore: BigNumberish, + balanceToBefore: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + flashLoan( + receiverAddress: string, + assets: string[], + amounts: BigNumberish[], + modes: BigNumberish[], + onBehalfOf: string, + params: BytesLike, + referralCode: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + getAddressesProvider(overrides?: CallOverrides): Promise<[string]>; + + getConfiguration( + asset: string, + overrides?: CallOverrides + ): Promise<[DataTypes.ReserveConfigurationMapStructOutput]>; + + getReserveData(asset: string, overrides?: CallOverrides): Promise<[DataTypes.ReserveDataStructOutput]>; + + getReserveNormalizedIncome(asset: string, overrides?: CallOverrides): Promise<[BigNumber]>; + + getReserveNormalizedVariableDebt(asset: string, overrides?: CallOverrides): Promise<[BigNumber]>; + + getReservesList(overrides?: CallOverrides): Promise<[string[]]>; + + getUserAccountData( + user: string, + overrides?: CallOverrides + ): Promise< + [BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber] & { + totalCollateralETH: BigNumber; + totalDebtETH: BigNumber; + availableBorrowsETH: BigNumber; + currentLiquidationThreshold: BigNumber; + ltv: BigNumber; + healthFactor: BigNumber; + } + >; + + getUserConfiguration( + user: string, + overrides?: CallOverrides + ): Promise<[DataTypes.UserConfigurationMapStructOutput]>; + + initReserve( + asset: string, + aTokenAddress: string, + stableDebtAddress: string, + variableDebtAddress: string, + interestRateStrategyAddress: string, + overrides?: Overrides & { from?: string } + ): Promise; + + initialize(provider: string, overrides?: Overrides & { from?: string }): Promise; + + liquidationCall( + collateralAsset: string, + debtAsset: string, + user: string, + debtToCover: BigNumberish, + receiveAToken: boolean, + overrides?: Overrides & { from?: string } + ): Promise; + + paused(overrides?: CallOverrides): Promise<[boolean]>; + + rebalanceStableBorrowRate( + asset: string, + user: string, + overrides?: Overrides & { from?: string } + ): Promise; + + repay( + asset: string, + amount: BigNumberish, + rateMode: BigNumberish, + onBehalfOf: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setConfiguration( + asset: string, + configuration: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + setPause(val: boolean, overrides?: Overrides & { from?: string }): Promise; + + setReserveInterestRateStrategyAddress( + asset: string, + rateStrategyAddress: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setUserUseReserveAsCollateral( + asset: string, + useAsCollateral: boolean, + overrides?: Overrides & { from?: string } + ): Promise; + + swapBorrowRateMode( + asset: string, + rateMode: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + undelegateWithdraw(delegatee: string, overrides?: Overrides & { from?: string }): Promise; + + 'withdraw(address,uint256,address)'( + asset: string, + amount: BigNumberish, + to: string, + overrides?: Overrides & { from?: string } + ): Promise; + + 'withdraw(address,uint256,address,address)'( + asset: string, + amount: BigNumberish, + to: string, + onBehalfOf: string, + overrides?: Overrides & { from?: string } + ): Promise; + + withdrawDelegatesOf(user: string, overrides?: CallOverrides): Promise<[string[]]>; + }; + + FLASHLOAN_PREMIUM_TOTAL(overrides?: CallOverrides): Promise; + + LENDINGPOOL_REVISION(overrides?: CallOverrides): Promise; + + MAX_NUMBER_RESERVES(overrides?: CallOverrides): Promise; + + MAX_STABLE_RATE_BORROW_SIZE_PERCENT(overrides?: CallOverrides): Promise; + + borrow( + asset: string, + amount: BigNumberish, + interestRateMode: BigNumberish, + referralCode: BigNumberish, + onBehalfOf: string, + overrides?: Overrides & { from?: string } + ): Promise; + + delegateWithdraw(delegatee: string, overrides?: Overrides & { from?: string }): Promise; + + deposit( + asset: string, + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + finalizeTransfer( + asset: string, + from: string, + to: string, + amount: BigNumberish, + balanceFromBefore: BigNumberish, + balanceToBefore: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + flashLoan( + receiverAddress: string, + assets: string[], + amounts: BigNumberish[], + modes: BigNumberish[], + onBehalfOf: string, + params: BytesLike, + referralCode: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + getAddressesProvider(overrides?: CallOverrides): Promise; + + getConfiguration(asset: string, overrides?: CallOverrides): Promise; + + getReserveData(asset: string, overrides?: CallOverrides): Promise; + + getReserveNormalizedIncome(asset: string, overrides?: CallOverrides): Promise; + + getReserveNormalizedVariableDebt(asset: string, overrides?: CallOverrides): Promise; + + getReservesList(overrides?: CallOverrides): Promise; + + getUserAccountData( + user: string, + overrides?: CallOverrides + ): Promise< + [BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber] & { + totalCollateralETH: BigNumber; + totalDebtETH: BigNumber; + availableBorrowsETH: BigNumber; + currentLiquidationThreshold: BigNumber; + ltv: BigNumber; + healthFactor: BigNumber; + } + >; + + getUserConfiguration(user: string, overrides?: CallOverrides): Promise; + + initReserve( + asset: string, + aTokenAddress: string, + stableDebtAddress: string, + variableDebtAddress: string, + interestRateStrategyAddress: string, + overrides?: Overrides & { from?: string } + ): Promise; + + initialize(provider: string, overrides?: Overrides & { from?: string }): Promise; + + liquidationCall( + collateralAsset: string, + debtAsset: string, + user: string, + debtToCover: BigNumberish, + receiveAToken: boolean, + overrides?: Overrides & { from?: string } + ): Promise; + + paused(overrides?: CallOverrides): Promise; + + rebalanceStableBorrowRate( + asset: string, + user: string, + overrides?: Overrides & { from?: string } + ): Promise; + + repay( + asset: string, + amount: BigNumberish, + rateMode: BigNumberish, + onBehalfOf: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setConfiguration( + asset: string, + configuration: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + setPause(val: boolean, overrides?: Overrides & { from?: string }): Promise; + + setReserveInterestRateStrategyAddress( + asset: string, + rateStrategyAddress: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setUserUseReserveAsCollateral( + asset: string, + useAsCollateral: boolean, + overrides?: Overrides & { from?: string } + ): Promise; + + swapBorrowRateMode( + asset: string, + rateMode: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + undelegateWithdraw(delegatee: string, overrides?: Overrides & { from?: string }): Promise; + + 'withdraw(address,uint256,address)'( + asset: string, + amount: BigNumberish, + to: string, + overrides?: Overrides & { from?: string } + ): Promise; + + 'withdraw(address,uint256,address,address)'( + asset: string, + amount: BigNumberish, + to: string, + onBehalfOf: string, + overrides?: Overrides & { from?: string } + ): Promise; + + withdrawDelegatesOf(user: string, overrides?: CallOverrides): Promise; + + callStatic: { + FLASHLOAN_PREMIUM_TOTAL(overrides?: CallOverrides): Promise; + + LENDINGPOOL_REVISION(overrides?: CallOverrides): Promise; + + MAX_NUMBER_RESERVES(overrides?: CallOverrides): Promise; + + MAX_STABLE_RATE_BORROW_SIZE_PERCENT(overrides?: CallOverrides): Promise; + + borrow( + asset: string, + amount: BigNumberish, + interestRateMode: BigNumberish, + referralCode: BigNumberish, + onBehalfOf: string, + overrides?: CallOverrides + ): Promise; + + delegateWithdraw(delegatee: string, overrides?: CallOverrides): Promise; + + deposit( + asset: string, + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + overrides?: CallOverrides + ): Promise; + + finalizeTransfer( + asset: string, + from: string, + to: string, + amount: BigNumberish, + balanceFromBefore: BigNumberish, + balanceToBefore: BigNumberish, + overrides?: CallOverrides + ): Promise; + + flashLoan( + receiverAddress: string, + assets: string[], + amounts: BigNumberish[], + modes: BigNumberish[], + onBehalfOf: string, + params: BytesLike, + referralCode: BigNumberish, + overrides?: CallOverrides + ): Promise; + + getAddressesProvider(overrides?: CallOverrides): Promise; + + getConfiguration(asset: string, overrides?: CallOverrides): Promise; + + getReserveData(asset: string, overrides?: CallOverrides): Promise; + + getReserveNormalizedIncome(asset: string, overrides?: CallOverrides): Promise; + + getReserveNormalizedVariableDebt(asset: string, overrides?: CallOverrides): Promise; + + getReservesList(overrides?: CallOverrides): Promise; + + getUserAccountData( + user: string, + overrides?: CallOverrides + ): Promise< + [BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber] & { + totalCollateralETH: BigNumber; + totalDebtETH: BigNumber; + availableBorrowsETH: BigNumber; + currentLiquidationThreshold: BigNumber; + ltv: BigNumber; + healthFactor: BigNumber; + } + >; + + getUserConfiguration(user: string, overrides?: CallOverrides): Promise; + + initReserve( + asset: string, + aTokenAddress: string, + stableDebtAddress: string, + variableDebtAddress: string, + interestRateStrategyAddress: string, + overrides?: CallOverrides + ): Promise; + + initialize(provider: string, overrides?: CallOverrides): Promise; + + liquidationCall( + collateralAsset: string, + debtAsset: string, + user: string, + debtToCover: BigNumberish, + receiveAToken: boolean, + overrides?: CallOverrides + ): Promise; + + paused(overrides?: CallOverrides): Promise; + + rebalanceStableBorrowRate(asset: string, user: string, overrides?: CallOverrides): Promise; + + repay( + asset: string, + amount: BigNumberish, + rateMode: BigNumberish, + onBehalfOf: string, + overrides?: CallOverrides + ): Promise; + + setConfiguration(asset: string, configuration: BigNumberish, overrides?: CallOverrides): Promise; + + setPause(val: boolean, overrides?: CallOverrides): Promise; + + setReserveInterestRateStrategyAddress( + asset: string, + rateStrategyAddress: string, + overrides?: CallOverrides + ): Promise; + + setUserUseReserveAsCollateral(asset: string, useAsCollateral: boolean, overrides?: CallOverrides): Promise; + + swapBorrowRateMode(asset: string, rateMode: BigNumberish, overrides?: CallOverrides): Promise; + + undelegateWithdraw(delegatee: string, overrides?: CallOverrides): Promise; + + 'withdraw(address,uint256,address)'( + asset: string, + amount: BigNumberish, + to: string, + overrides?: CallOverrides + ): Promise; + + 'withdraw(address,uint256,address,address)'( + asset: string, + amount: BigNumberish, + to: string, + onBehalfOf: string, + overrides?: CallOverrides + ): Promise; + + withdrawDelegatesOf(user: string, overrides?: CallOverrides): Promise; + }; + + filters: { + 'Borrow(address,address,address,uint256,uint256,uint256,uint16)'( + reserve?: string | null, + user?: null, + onBehalfOf?: string | null, + amount?: null, + borrowRateMode?: null, + borrowRate?: null, + referral?: BigNumberish | null + ): BorrowEventFilter; + Borrow( + reserve?: string | null, + user?: null, + onBehalfOf?: string | null, + amount?: null, + borrowRateMode?: null, + borrowRate?: null, + referral?: BigNumberish | null + ): BorrowEventFilter; + + 'Deposit(address,address,address,uint256,uint16)'( + reserve?: string | null, + user?: null, + onBehalfOf?: string | null, + amount?: null, + referral?: BigNumberish | null + ): DepositEventFilter; + Deposit( + reserve?: string | null, + user?: null, + onBehalfOf?: string | null, + amount?: null, + referral?: BigNumberish | null + ): DepositEventFilter; + + 'FlashLoan(address,address,address,uint256,uint256,uint16)'( + target?: string | null, + initiator?: string | null, + asset?: string | null, + amount?: null, + premium?: null, + referralCode?: null + ): FlashLoanEventFilter; + FlashLoan( + target?: string | null, + initiator?: string | null, + asset?: string | null, + amount?: null, + premium?: null, + referralCode?: null + ): FlashLoanEventFilter; + + 'LiquidationCall(address,address,address,uint256,uint256,address,bool)'( + collateralAsset?: string | null, + debtAsset?: string | null, + user?: string | null, + debtToCover?: null, + liquidatedCollateralAmount?: null, + liquidator?: null, + receiveAToken?: null + ): LiquidationCallEventFilter; + LiquidationCall( + collateralAsset?: string | null, + debtAsset?: string | null, + user?: string | null, + debtToCover?: null, + liquidatedCollateralAmount?: null, + liquidator?: null, + receiveAToken?: null + ): LiquidationCallEventFilter; + + 'Paused()'(): PausedEventFilter; + Paused(): PausedEventFilter; + + 'RebalanceStableBorrowRate(address,address)'( + reserve?: string | null, + user?: string | null + ): RebalanceStableBorrowRateEventFilter; + RebalanceStableBorrowRate(reserve?: string | null, user?: string | null): RebalanceStableBorrowRateEventFilter; + + 'Repay(address,address,address,uint256)'( + reserve?: string | null, + user?: string | null, + repayer?: string | null, + amount?: null + ): RepayEventFilter; + Repay(reserve?: string | null, user?: string | null, repayer?: string | null, amount?: null): RepayEventFilter; + + 'ReserveDataUpdated(address,uint256,uint256,uint256,uint256,uint256)'( + reserve?: string | null, + liquidityRate?: null, + stableBorrowRate?: null, + variableBorrowRate?: null, + liquidityIndex?: null, + variableBorrowIndex?: null + ): ReserveDataUpdatedEventFilter; + ReserveDataUpdated( + reserve?: string | null, + liquidityRate?: null, + stableBorrowRate?: null, + variableBorrowRate?: null, + liquidityIndex?: null, + variableBorrowIndex?: null + ): ReserveDataUpdatedEventFilter; + + 'ReserveUsedAsCollateralDisabled(address,address)'( + reserve?: string | null, + user?: string | null + ): ReserveUsedAsCollateralDisabledEventFilter; + ReserveUsedAsCollateralDisabled( + reserve?: string | null, + user?: string | null + ): ReserveUsedAsCollateralDisabledEventFilter; + + 'ReserveUsedAsCollateralEnabled(address,address)'( + reserve?: string | null, + user?: string | null + ): ReserveUsedAsCollateralEnabledEventFilter; + ReserveUsedAsCollateralEnabled( + reserve?: string | null, + user?: string | null + ): ReserveUsedAsCollateralEnabledEventFilter; + + 'Swap(address,address,uint256)'(reserve?: string | null, user?: string | null, rateMode?: null): SwapEventFilter; + Swap(reserve?: string | null, user?: string | null, rateMode?: null): SwapEventFilter; + + 'Unpaused()'(): UnpausedEventFilter; + Unpaused(): UnpausedEventFilter; + + 'Withdraw(address,address,address,uint256)'( + reserve?: string | null, + user?: string | null, + to?: string | null, + amount?: null + ): WithdrawEventFilter; + Withdraw(reserve?: string | null, user?: string | null, to?: string | null, amount?: null): WithdrawEventFilter; + }; + + estimateGas: { + FLASHLOAN_PREMIUM_TOTAL(overrides?: CallOverrides): Promise; + + LENDINGPOOL_REVISION(overrides?: CallOverrides): Promise; + + MAX_NUMBER_RESERVES(overrides?: CallOverrides): Promise; + + MAX_STABLE_RATE_BORROW_SIZE_PERCENT(overrides?: CallOverrides): Promise; + + borrow( + asset: string, + amount: BigNumberish, + interestRateMode: BigNumberish, + referralCode: BigNumberish, + onBehalfOf: string, + overrides?: Overrides & { from?: string } + ): Promise; + + delegateWithdraw(delegatee: string, overrides?: Overrides & { from?: string }): Promise; + + deposit( + asset: string, + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + finalizeTransfer( + asset: string, + from: string, + to: string, + amount: BigNumberish, + balanceFromBefore: BigNumberish, + balanceToBefore: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + flashLoan( + receiverAddress: string, + assets: string[], + amounts: BigNumberish[], + modes: BigNumberish[], + onBehalfOf: string, + params: BytesLike, + referralCode: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + getAddressesProvider(overrides?: CallOverrides): Promise; + + getConfiguration(asset: string, overrides?: CallOverrides): Promise; + + getReserveData(asset: string, overrides?: CallOverrides): Promise; + + getReserveNormalizedIncome(asset: string, overrides?: CallOverrides): Promise; + + getReserveNormalizedVariableDebt(asset: string, overrides?: CallOverrides): Promise; + + getReservesList(overrides?: CallOverrides): Promise; + + getUserAccountData(user: string, overrides?: CallOverrides): Promise; + + getUserConfiguration(user: string, overrides?: CallOverrides): Promise; + + initReserve( + asset: string, + aTokenAddress: string, + stableDebtAddress: string, + variableDebtAddress: string, + interestRateStrategyAddress: string, + overrides?: Overrides & { from?: string } + ): Promise; + + initialize(provider: string, overrides?: Overrides & { from?: string }): Promise; + + liquidationCall( + collateralAsset: string, + debtAsset: string, + user: string, + debtToCover: BigNumberish, + receiveAToken: boolean, + overrides?: Overrides & { from?: string } + ): Promise; + + paused(overrides?: CallOverrides): Promise; + + rebalanceStableBorrowRate( + asset: string, + user: string, + overrides?: Overrides & { from?: string } + ): Promise; + + repay( + asset: string, + amount: BigNumberish, + rateMode: BigNumberish, + onBehalfOf: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setConfiguration( + asset: string, + configuration: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + setPause(val: boolean, overrides?: Overrides & { from?: string }): Promise; + + setReserveInterestRateStrategyAddress( + asset: string, + rateStrategyAddress: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setUserUseReserveAsCollateral( + asset: string, + useAsCollateral: boolean, + overrides?: Overrides & { from?: string } + ): Promise; + + swapBorrowRateMode( + asset: string, + rateMode: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + undelegateWithdraw(delegatee: string, overrides?: Overrides & { from?: string }): Promise; + + 'withdraw(address,uint256,address)'( + asset: string, + amount: BigNumberish, + to: string, + overrides?: Overrides & { from?: string } + ): Promise; + + 'withdraw(address,uint256,address,address)'( + asset: string, + amount: BigNumberish, + to: string, + onBehalfOf: string, + overrides?: Overrides & { from?: string } + ): Promise; + + withdrawDelegatesOf(user: string, overrides?: CallOverrides): Promise; + }; + + populateTransaction: { + FLASHLOAN_PREMIUM_TOTAL(overrides?: CallOverrides): Promise; + + LENDINGPOOL_REVISION(overrides?: CallOverrides): Promise; + + MAX_NUMBER_RESERVES(overrides?: CallOverrides): Promise; + + MAX_STABLE_RATE_BORROW_SIZE_PERCENT(overrides?: CallOverrides): Promise; + + borrow( + asset: string, + amount: BigNumberish, + interestRateMode: BigNumberish, + referralCode: BigNumberish, + onBehalfOf: string, + overrides?: Overrides & { from?: string } + ): Promise; + + delegateWithdraw(delegatee: string, overrides?: Overrides & { from?: string }): Promise; + + deposit( + asset: string, + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + finalizeTransfer( + asset: string, + from: string, + to: string, + amount: BigNumberish, + balanceFromBefore: BigNumberish, + balanceToBefore: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + flashLoan( + receiverAddress: string, + assets: string[], + amounts: BigNumberish[], + modes: BigNumberish[], + onBehalfOf: string, + params: BytesLike, + referralCode: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + getAddressesProvider(overrides?: CallOverrides): Promise; + + getConfiguration(asset: string, overrides?: CallOverrides): Promise; + + getReserveData(asset: string, overrides?: CallOverrides): Promise; + + getReserveNormalizedIncome(asset: string, overrides?: CallOverrides): Promise; + + getReserveNormalizedVariableDebt(asset: string, overrides?: CallOverrides): Promise; + + getReservesList(overrides?: CallOverrides): Promise; + + getUserAccountData(user: string, overrides?: CallOverrides): Promise; + + getUserConfiguration(user: string, overrides?: CallOverrides): Promise; + + initReserve( + asset: string, + aTokenAddress: string, + stableDebtAddress: string, + variableDebtAddress: string, + interestRateStrategyAddress: string, + overrides?: Overrides & { from?: string } + ): Promise; + + initialize(provider: string, overrides?: Overrides & { from?: string }): Promise; + + liquidationCall( + collateralAsset: string, + debtAsset: string, + user: string, + debtToCover: BigNumberish, + receiveAToken: boolean, + overrides?: Overrides & { from?: string } + ): Promise; + + paused(overrides?: CallOverrides): Promise; + + rebalanceStableBorrowRate( + asset: string, + user: string, + overrides?: Overrides & { from?: string } + ): Promise; + + repay( + asset: string, + amount: BigNumberish, + rateMode: BigNumberish, + onBehalfOf: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setConfiguration( + asset: string, + configuration: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + setPause(val: boolean, overrides?: Overrides & { from?: string }): Promise; + + setReserveInterestRateStrategyAddress( + asset: string, + rateStrategyAddress: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setUserUseReserveAsCollateral( + asset: string, + useAsCollateral: boolean, + overrides?: Overrides & { from?: string } + ): Promise; + + swapBorrowRateMode( + asset: string, + rateMode: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + undelegateWithdraw(delegatee: string, overrides?: Overrides & { from?: string }): Promise; + + 'withdraw(address,uint256,address)'( + asset: string, + amount: BigNumberish, + to: string, + overrides?: Overrides & { from?: string } + ): Promise; + + 'withdraw(address,uint256,address,address)'( + asset: string, + amount: BigNumberish, + to: string, + onBehalfOf: string, + overrides?: Overrides & { from?: string } + ): Promise; + + withdrawDelegatesOf(user: string, overrides?: CallOverrides): Promise; + }; +} diff --git a/src/logics/iolend/contracts/LendingPoolAddressesProvider.ts b/src/logics/iolend/contracts/LendingPoolAddressesProvider.ts new file mode 100644 index 00000000..0cf0ddcb --- /dev/null +++ b/src/logics/iolend/contracts/LendingPoolAddressesProvider.ts @@ -0,0 +1,609 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BigNumber, + BytesLike, + CallOverrides, + ContractTransaction, + Overrides, + PopulatedTransaction, + Signer, + utils, +} from 'ethers'; +import type { FunctionFragment, Result, EventFragment } from '@ethersproject/abi'; +import type { Listener, Provider } from '@ethersproject/providers'; +import type { TypedEventFilter, TypedEvent, TypedListener, OnEvent } from './common'; + +export interface LendingPoolAddressesProviderInterface extends utils.Interface { + functions: { + 'getAddress(bytes32)': FunctionFragment; + 'getEmergencyAdmin()': FunctionFragment; + 'getLendingPool()': FunctionFragment; + 'getLendingPoolCollateralManager()': FunctionFragment; + 'getLendingPoolConfigurator()': FunctionFragment; + 'getLendingRateOracle()': FunctionFragment; + 'getLiquidationFeeTo()': FunctionFragment; + 'getMarketId()': FunctionFragment; + 'getPoolAdmin()': FunctionFragment; + 'getPriceOracle()': FunctionFragment; + 'owner()': FunctionFragment; + 'renounceOwnership()': FunctionFragment; + 'setAddress(bytes32,address)': FunctionFragment; + 'setAddressAsProxy(bytes32,address)': FunctionFragment; + 'setEmergencyAdmin(address)': FunctionFragment; + 'setLendingPoolCollateralManager(address)': FunctionFragment; + 'setLendingPoolConfiguratorImpl(address)': FunctionFragment; + 'setLendingPoolImpl(address)': FunctionFragment; + 'setLendingRateOracle(address)': FunctionFragment; + 'setLiquidationFeeTo(address)': FunctionFragment; + 'setMarketId(string)': FunctionFragment; + 'setPoolAdmin(address)': FunctionFragment; + 'setPriceOracle(address)': FunctionFragment; + 'transferOwnership(address)': FunctionFragment; + }; + + getFunction( + nameOrSignatureOrTopic: + | 'getAddress' + | 'getEmergencyAdmin' + | 'getLendingPool' + | 'getLendingPoolCollateralManager' + | 'getLendingPoolConfigurator' + | 'getLendingRateOracle' + | 'getLiquidationFeeTo' + | 'getMarketId' + | 'getPoolAdmin' + | 'getPriceOracle' + | 'owner' + | 'renounceOwnership' + | 'setAddress' + | 'setAddressAsProxy' + | 'setEmergencyAdmin' + | 'setLendingPoolCollateralManager' + | 'setLendingPoolConfiguratorImpl' + | 'setLendingPoolImpl' + | 'setLendingRateOracle' + | 'setLiquidationFeeTo' + | 'setMarketId' + | 'setPoolAdmin' + | 'setPriceOracle' + | 'transferOwnership' + ): FunctionFragment; + + encodeFunctionData(functionFragment: 'getAddress', values: [BytesLike]): string; + encodeFunctionData(functionFragment: 'getEmergencyAdmin', values?: undefined): string; + encodeFunctionData(functionFragment: 'getLendingPool', values?: undefined): string; + encodeFunctionData(functionFragment: 'getLendingPoolCollateralManager', values?: undefined): string; + encodeFunctionData(functionFragment: 'getLendingPoolConfigurator', values?: undefined): string; + encodeFunctionData(functionFragment: 'getLendingRateOracle', values?: undefined): string; + encodeFunctionData(functionFragment: 'getLiquidationFeeTo', values?: undefined): string; + encodeFunctionData(functionFragment: 'getMarketId', values?: undefined): string; + encodeFunctionData(functionFragment: 'getPoolAdmin', values?: undefined): string; + encodeFunctionData(functionFragment: 'getPriceOracle', values?: undefined): string; + encodeFunctionData(functionFragment: 'owner', values?: undefined): string; + encodeFunctionData(functionFragment: 'renounceOwnership', values?: undefined): string; + encodeFunctionData(functionFragment: 'setAddress', values: [BytesLike, string]): string; + encodeFunctionData(functionFragment: 'setAddressAsProxy', values: [BytesLike, string]): string; + encodeFunctionData(functionFragment: 'setEmergencyAdmin', values: [string]): string; + encodeFunctionData(functionFragment: 'setLendingPoolCollateralManager', values: [string]): string; + encodeFunctionData(functionFragment: 'setLendingPoolConfiguratorImpl', values: [string]): string; + encodeFunctionData(functionFragment: 'setLendingPoolImpl', values: [string]): string; + encodeFunctionData(functionFragment: 'setLendingRateOracle', values: [string]): string; + encodeFunctionData(functionFragment: 'setLiquidationFeeTo', values: [string]): string; + encodeFunctionData(functionFragment: 'setMarketId', values: [string]): string; + encodeFunctionData(functionFragment: 'setPoolAdmin', values: [string]): string; + encodeFunctionData(functionFragment: 'setPriceOracle', values: [string]): string; + encodeFunctionData(functionFragment: 'transferOwnership', values: [string]): string; + + decodeFunctionResult(functionFragment: 'getAddress', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getEmergencyAdmin', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getLendingPool', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getLendingPoolCollateralManager', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getLendingPoolConfigurator', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getLendingRateOracle', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getLiquidationFeeTo', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getMarketId', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getPoolAdmin', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getPriceOracle', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'owner', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'renounceOwnership', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setAddress', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setAddressAsProxy', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setEmergencyAdmin', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setLendingPoolCollateralManager', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setLendingPoolConfiguratorImpl', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setLendingPoolImpl', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setLendingRateOracle', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setLiquidationFeeTo', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setMarketId', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setPoolAdmin', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setPriceOracle', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'transferOwnership', data: BytesLike): Result; + + events: { + 'AddressSet(bytes32,address,bool)': EventFragment; + 'ConfigurationAdminUpdated(address)': EventFragment; + 'EmergencyAdminUpdated(address)': EventFragment; + 'LendingPoolCollateralManagerUpdated(address)': EventFragment; + 'LendingPoolConfiguratorUpdated(address)': EventFragment; + 'LendingPoolUpdated(address)': EventFragment; + 'LendingRateOracleUpdated(address)': EventFragment; + 'MarketIdSet(string)': EventFragment; + 'OwnershipTransferred(address,address)': EventFragment; + 'PriceOracleUpdated(address)': EventFragment; + 'ProxyCreated(bytes32,address)': EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: 'AddressSet'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'ConfigurationAdminUpdated'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'EmergencyAdminUpdated'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LendingPoolCollateralManagerUpdated'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LendingPoolConfiguratorUpdated'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LendingPoolUpdated'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LendingRateOracleUpdated'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'MarketIdSet'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'OwnershipTransferred'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'PriceOracleUpdated'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'ProxyCreated'): EventFragment; +} + +export interface AddressSetEventObject { + id: string; + newAddress: string; + hasProxy: boolean; +} +export type AddressSetEvent = TypedEvent<[string, string, boolean], AddressSetEventObject>; + +export type AddressSetEventFilter = TypedEventFilter; + +export interface ConfigurationAdminUpdatedEventObject { + newAddress: string; +} +export type ConfigurationAdminUpdatedEvent = TypedEvent<[string], ConfigurationAdminUpdatedEventObject>; + +export type ConfigurationAdminUpdatedEventFilter = TypedEventFilter; + +export interface EmergencyAdminUpdatedEventObject { + newAddress: string; +} +export type EmergencyAdminUpdatedEvent = TypedEvent<[string], EmergencyAdminUpdatedEventObject>; + +export type EmergencyAdminUpdatedEventFilter = TypedEventFilter; + +export interface LendingPoolCollateralManagerUpdatedEventObject { + newAddress: string; +} +export type LendingPoolCollateralManagerUpdatedEvent = TypedEvent< + [string], + LendingPoolCollateralManagerUpdatedEventObject +>; + +export type LendingPoolCollateralManagerUpdatedEventFilter = TypedEventFilter; + +export interface LendingPoolConfiguratorUpdatedEventObject { + newAddress: string; +} +export type LendingPoolConfiguratorUpdatedEvent = TypedEvent<[string], LendingPoolConfiguratorUpdatedEventObject>; + +export type LendingPoolConfiguratorUpdatedEventFilter = TypedEventFilter; + +export interface LendingPoolUpdatedEventObject { + newAddress: string; +} +export type LendingPoolUpdatedEvent = TypedEvent<[string], LendingPoolUpdatedEventObject>; + +export type LendingPoolUpdatedEventFilter = TypedEventFilter; + +export interface LendingRateOracleUpdatedEventObject { + newAddress: string; +} +export type LendingRateOracleUpdatedEvent = TypedEvent<[string], LendingRateOracleUpdatedEventObject>; + +export type LendingRateOracleUpdatedEventFilter = TypedEventFilter; + +export interface MarketIdSetEventObject { + newMarketId: string; +} +export type MarketIdSetEvent = TypedEvent<[string], MarketIdSetEventObject>; + +export type MarketIdSetEventFilter = TypedEventFilter; + +export interface OwnershipTransferredEventObject { + previousOwner: string; + newOwner: string; +} +export type OwnershipTransferredEvent = TypedEvent<[string, string], OwnershipTransferredEventObject>; + +export type OwnershipTransferredEventFilter = TypedEventFilter; + +export interface PriceOracleUpdatedEventObject { + newAddress: string; +} +export type PriceOracleUpdatedEvent = TypedEvent<[string], PriceOracleUpdatedEventObject>; + +export type PriceOracleUpdatedEventFilter = TypedEventFilter; + +export interface ProxyCreatedEventObject { + id: string; + newAddress: string; +} +export type ProxyCreatedEvent = TypedEvent<[string, string], ProxyCreatedEventObject>; + +export type ProxyCreatedEventFilter = TypedEventFilter; + +export interface LendingPoolAddressesProvider extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: LendingPoolAddressesProviderInterface; + + queryFilter( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>; + + listeners(eventFilter?: TypedEventFilter): Array>; + listeners(eventName?: string): Array; + removeAllListeners(eventFilter: TypedEventFilter): this; + removeAllListeners(eventName?: string): this; + off: OnEvent; + on: OnEvent; + once: OnEvent; + removeListener: OnEvent; + + functions: { + getAddress(id: BytesLike, overrides?: CallOverrides): Promise<[string]>; + + getEmergencyAdmin(overrides?: CallOverrides): Promise<[string]>; + + getLendingPool(overrides?: CallOverrides): Promise<[string]>; + + getLendingPoolCollateralManager(overrides?: CallOverrides): Promise<[string]>; + + getLendingPoolConfigurator(overrides?: CallOverrides): Promise<[string]>; + + getLendingRateOracle(overrides?: CallOverrides): Promise<[string]>; + + getLiquidationFeeTo(overrides?: CallOverrides): Promise<[string]>; + + getMarketId(overrides?: CallOverrides): Promise<[string]>; + + getPoolAdmin(overrides?: CallOverrides): Promise<[string]>; + + getPriceOracle(overrides?: CallOverrides): Promise<[string]>; + + owner(overrides?: CallOverrides): Promise<[string]>; + + renounceOwnership(overrides?: Overrides & { from?: string }): Promise; + + setAddress( + id: BytesLike, + newAddress: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setAddressAsProxy( + id: BytesLike, + implementationAddress: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setEmergencyAdmin(emergencyAdmin: string, overrides?: Overrides & { from?: string }): Promise; + + setLendingPoolCollateralManager( + manager: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setLendingPoolConfiguratorImpl( + configurator: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setLendingPoolImpl(pool: string, overrides?: Overrides & { from?: string }): Promise; + + setLendingRateOracle( + lendingRateOracle: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setLiquidationFeeTo( + liquidationFeeTo: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setMarketId(marketId: string, overrides?: Overrides & { from?: string }): Promise; + + setPoolAdmin(admin: string, overrides?: Overrides & { from?: string }): Promise; + + setPriceOracle(priceOracle: string, overrides?: Overrides & { from?: string }): Promise; + + transferOwnership(newOwner: string, overrides?: Overrides & { from?: string }): Promise; + }; + + getAddress(id: BytesLike, overrides?: CallOverrides): Promise; + + getEmergencyAdmin(overrides?: CallOverrides): Promise; + + getLendingPool(overrides?: CallOverrides): Promise; + + getLendingPoolCollateralManager(overrides?: CallOverrides): Promise; + + getLendingPoolConfigurator(overrides?: CallOverrides): Promise; + + getLendingRateOracle(overrides?: CallOverrides): Promise; + + getLiquidationFeeTo(overrides?: CallOverrides): Promise; + + getMarketId(overrides?: CallOverrides): Promise; + + getPoolAdmin(overrides?: CallOverrides): Promise; + + getPriceOracle(overrides?: CallOverrides): Promise; + + owner(overrides?: CallOverrides): Promise; + + renounceOwnership(overrides?: Overrides & { from?: string }): Promise; + + setAddress( + id: BytesLike, + newAddress: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setAddressAsProxy( + id: BytesLike, + implementationAddress: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setEmergencyAdmin(emergencyAdmin: string, overrides?: Overrides & { from?: string }): Promise; + + setLendingPoolCollateralManager( + manager: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setLendingPoolConfiguratorImpl( + configurator: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setLendingPoolImpl(pool: string, overrides?: Overrides & { from?: string }): Promise; + + setLendingRateOracle( + lendingRateOracle: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setLiquidationFeeTo( + liquidationFeeTo: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setMarketId(marketId: string, overrides?: Overrides & { from?: string }): Promise; + + setPoolAdmin(admin: string, overrides?: Overrides & { from?: string }): Promise; + + setPriceOracle(priceOracle: string, overrides?: Overrides & { from?: string }): Promise; + + transferOwnership(newOwner: string, overrides?: Overrides & { from?: string }): Promise; + + callStatic: { + getAddress(id: BytesLike, overrides?: CallOverrides): Promise; + + getEmergencyAdmin(overrides?: CallOverrides): Promise; + + getLendingPool(overrides?: CallOverrides): Promise; + + getLendingPoolCollateralManager(overrides?: CallOverrides): Promise; + + getLendingPoolConfigurator(overrides?: CallOverrides): Promise; + + getLendingRateOracle(overrides?: CallOverrides): Promise; + + getLiquidationFeeTo(overrides?: CallOverrides): Promise; + + getMarketId(overrides?: CallOverrides): Promise; + + getPoolAdmin(overrides?: CallOverrides): Promise; + + getPriceOracle(overrides?: CallOverrides): Promise; + + owner(overrides?: CallOverrides): Promise; + + renounceOwnership(overrides?: CallOverrides): Promise; + + setAddress(id: BytesLike, newAddress: string, overrides?: CallOverrides): Promise; + + setAddressAsProxy(id: BytesLike, implementationAddress: string, overrides?: CallOverrides): Promise; + + setEmergencyAdmin(emergencyAdmin: string, overrides?: CallOverrides): Promise; + + setLendingPoolCollateralManager(manager: string, overrides?: CallOverrides): Promise; + + setLendingPoolConfiguratorImpl(configurator: string, overrides?: CallOverrides): Promise; + + setLendingPoolImpl(pool: string, overrides?: CallOverrides): Promise; + + setLendingRateOracle(lendingRateOracle: string, overrides?: CallOverrides): Promise; + + setLiquidationFeeTo(liquidationFeeTo: string, overrides?: CallOverrides): Promise; + + setMarketId(marketId: string, overrides?: CallOverrides): Promise; + + setPoolAdmin(admin: string, overrides?: CallOverrides): Promise; + + setPriceOracle(priceOracle: string, overrides?: CallOverrides): Promise; + + transferOwnership(newOwner: string, overrides?: CallOverrides): Promise; + }; + + filters: { + 'AddressSet(bytes32,address,bool)'(id?: null, newAddress?: string | null, hasProxy?: null): AddressSetEventFilter; + AddressSet(id?: null, newAddress?: string | null, hasProxy?: null): AddressSetEventFilter; + + 'ConfigurationAdminUpdated(address)'(newAddress?: string | null): ConfigurationAdminUpdatedEventFilter; + ConfigurationAdminUpdated(newAddress?: string | null): ConfigurationAdminUpdatedEventFilter; + + 'EmergencyAdminUpdated(address)'(newAddress?: string | null): EmergencyAdminUpdatedEventFilter; + EmergencyAdminUpdated(newAddress?: string | null): EmergencyAdminUpdatedEventFilter; + + 'LendingPoolCollateralManagerUpdated(address)'( + newAddress?: string | null + ): LendingPoolCollateralManagerUpdatedEventFilter; + LendingPoolCollateralManagerUpdated(newAddress?: string | null): LendingPoolCollateralManagerUpdatedEventFilter; + + 'LendingPoolConfiguratorUpdated(address)'(newAddress?: string | null): LendingPoolConfiguratorUpdatedEventFilter; + LendingPoolConfiguratorUpdated(newAddress?: string | null): LendingPoolConfiguratorUpdatedEventFilter; + + 'LendingPoolUpdated(address)'(newAddress?: string | null): LendingPoolUpdatedEventFilter; + LendingPoolUpdated(newAddress?: string | null): LendingPoolUpdatedEventFilter; + + 'LendingRateOracleUpdated(address)'(newAddress?: string | null): LendingRateOracleUpdatedEventFilter; + LendingRateOracleUpdated(newAddress?: string | null): LendingRateOracleUpdatedEventFilter; + + 'MarketIdSet(string)'(newMarketId?: null): MarketIdSetEventFilter; + MarketIdSet(newMarketId?: null): MarketIdSetEventFilter; + + 'OwnershipTransferred(address,address)'( + previousOwner?: string | null, + newOwner?: string | null + ): OwnershipTransferredEventFilter; + OwnershipTransferred(previousOwner?: string | null, newOwner?: string | null): OwnershipTransferredEventFilter; + + 'PriceOracleUpdated(address)'(newAddress?: string | null): PriceOracleUpdatedEventFilter; + PriceOracleUpdated(newAddress?: string | null): PriceOracleUpdatedEventFilter; + + 'ProxyCreated(bytes32,address)'(id?: null, newAddress?: string | null): ProxyCreatedEventFilter; + ProxyCreated(id?: null, newAddress?: string | null): ProxyCreatedEventFilter; + }; + + estimateGas: { + getAddress(id: BytesLike, overrides?: CallOverrides): Promise; + + getEmergencyAdmin(overrides?: CallOverrides): Promise; + + getLendingPool(overrides?: CallOverrides): Promise; + + getLendingPoolCollateralManager(overrides?: CallOverrides): Promise; + + getLendingPoolConfigurator(overrides?: CallOverrides): Promise; + + getLendingRateOracle(overrides?: CallOverrides): Promise; + + getLiquidationFeeTo(overrides?: CallOverrides): Promise; + + getMarketId(overrides?: CallOverrides): Promise; + + getPoolAdmin(overrides?: CallOverrides): Promise; + + getPriceOracle(overrides?: CallOverrides): Promise; + + owner(overrides?: CallOverrides): Promise; + + renounceOwnership(overrides?: Overrides & { from?: string }): Promise; + + setAddress(id: BytesLike, newAddress: string, overrides?: Overrides & { from?: string }): Promise; + + setAddressAsProxy( + id: BytesLike, + implementationAddress: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setEmergencyAdmin(emergencyAdmin: string, overrides?: Overrides & { from?: string }): Promise; + + setLendingPoolCollateralManager(manager: string, overrides?: Overrides & { from?: string }): Promise; + + setLendingPoolConfiguratorImpl(configurator: string, overrides?: Overrides & { from?: string }): Promise; + + setLendingPoolImpl(pool: string, overrides?: Overrides & { from?: string }): Promise; + + setLendingRateOracle(lendingRateOracle: string, overrides?: Overrides & { from?: string }): Promise; + + setLiquidationFeeTo(liquidationFeeTo: string, overrides?: Overrides & { from?: string }): Promise; + + setMarketId(marketId: string, overrides?: Overrides & { from?: string }): Promise; + + setPoolAdmin(admin: string, overrides?: Overrides & { from?: string }): Promise; + + setPriceOracle(priceOracle: string, overrides?: Overrides & { from?: string }): Promise; + + transferOwnership(newOwner: string, overrides?: Overrides & { from?: string }): Promise; + }; + + populateTransaction: { + getAddress(id: BytesLike, overrides?: CallOverrides): Promise; + + getEmergencyAdmin(overrides?: CallOverrides): Promise; + + getLendingPool(overrides?: CallOverrides): Promise; + + getLendingPoolCollateralManager(overrides?: CallOverrides): Promise; + + getLendingPoolConfigurator(overrides?: CallOverrides): Promise; + + getLendingRateOracle(overrides?: CallOverrides): Promise; + + getLiquidationFeeTo(overrides?: CallOverrides): Promise; + + getMarketId(overrides?: CallOverrides): Promise; + + getPoolAdmin(overrides?: CallOverrides): Promise; + + getPriceOracle(overrides?: CallOverrides): Promise; + + owner(overrides?: CallOverrides): Promise; + + renounceOwnership(overrides?: Overrides & { from?: string }): Promise; + + setAddress( + id: BytesLike, + newAddress: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setAddressAsProxy( + id: BytesLike, + implementationAddress: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setEmergencyAdmin(emergencyAdmin: string, overrides?: Overrides & { from?: string }): Promise; + + setLendingPoolCollateralManager( + manager: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setLendingPoolConfiguratorImpl( + configurator: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setLendingPoolImpl(pool: string, overrides?: Overrides & { from?: string }): Promise; + + setLendingRateOracle( + lendingRateOracle: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setLiquidationFeeTo( + liquidationFeeTo: string, + overrides?: Overrides & { from?: string } + ): Promise; + + setMarketId(marketId: string, overrides?: Overrides & { from?: string }): Promise; + + setPoolAdmin(admin: string, overrides?: Overrides & { from?: string }): Promise; + + setPriceOracle(priceOracle: string, overrides?: Overrides & { from?: string }): Promise; + + transferOwnership(newOwner: string, overrides?: Overrides & { from?: string }): Promise; + }; +} diff --git a/src/logics/iolend/contracts/ProtocolDataProvider.ts b/src/logics/iolend/contracts/ProtocolDataProvider.ts new file mode 100644 index 00000000..c30d1600 --- /dev/null +++ b/src/logics/iolend/contracts/ProtocolDataProvider.ts @@ -0,0 +1,331 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { BaseContract, BigNumber, BytesLike, CallOverrides, PopulatedTransaction, Signer, utils } from 'ethers'; +import type { FunctionFragment, Result } from '@ethersproject/abi'; +import type { Listener, Provider } from '@ethersproject/providers'; +import type { TypedEventFilter, TypedEvent, TypedListener, OnEvent } from './common'; + +export declare namespace AaveProtocolDataProvider { + export type TokenDataStruct = { symbol: string; tokenAddress: string }; + + export type TokenDataStructOutput = [string, string] & { + symbol: string; + tokenAddress: string; + }; +} + +export interface ProtocolDataProviderInterface extends utils.Interface { + functions: { + 'ADDRESSES_PROVIDER()': FunctionFragment; + 'getAllATokens()': FunctionFragment; + 'getAllReservesTokens()': FunctionFragment; + 'getReserveConfigurationData(address)': FunctionFragment; + 'getReserveData(address)': FunctionFragment; + 'getReserveTokensAddresses(address)': FunctionFragment; + 'getUserReserveData(address,address)': FunctionFragment; + }; + + getFunction( + nameOrSignatureOrTopic: + | 'ADDRESSES_PROVIDER' + | 'getAllATokens' + | 'getAllReservesTokens' + | 'getReserveConfigurationData' + | 'getReserveData' + | 'getReserveTokensAddresses' + | 'getUserReserveData' + ): FunctionFragment; + + encodeFunctionData(functionFragment: 'ADDRESSES_PROVIDER', values?: undefined): string; + encodeFunctionData(functionFragment: 'getAllATokens', values?: undefined): string; + encodeFunctionData(functionFragment: 'getAllReservesTokens', values?: undefined): string; + encodeFunctionData(functionFragment: 'getReserveConfigurationData', values: [string]): string; + encodeFunctionData(functionFragment: 'getReserveData', values: [string]): string; + encodeFunctionData(functionFragment: 'getReserveTokensAddresses', values: [string]): string; + encodeFunctionData(functionFragment: 'getUserReserveData', values: [string, string]): string; + + decodeFunctionResult(functionFragment: 'ADDRESSES_PROVIDER', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getAllATokens', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getAllReservesTokens', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getReserveConfigurationData', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getReserveData', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getReserveTokensAddresses', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getUserReserveData', data: BytesLike): Result; + + events: {}; +} + +export interface ProtocolDataProvider extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: ProtocolDataProviderInterface; + + queryFilter( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>; + + listeners(eventFilter?: TypedEventFilter): Array>; + listeners(eventName?: string): Array; + removeAllListeners(eventFilter: TypedEventFilter): this; + removeAllListeners(eventName?: string): this; + off: OnEvent; + on: OnEvent; + once: OnEvent; + removeListener: OnEvent; + + functions: { + ADDRESSES_PROVIDER(overrides?: CallOverrides): Promise<[string]>; + + getAllATokens(overrides?: CallOverrides): Promise<[AaveProtocolDataProvider.TokenDataStructOutput[]]>; + + getAllReservesTokens(overrides?: CallOverrides): Promise<[AaveProtocolDataProvider.TokenDataStructOutput[]]>; + + getReserveConfigurationData( + asset: string, + overrides?: CallOverrides + ): Promise< + [BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, boolean, boolean, boolean, boolean, boolean] & { + decimals: BigNumber; + ltv: BigNumber; + liquidationThreshold: BigNumber; + liquidationBonus: BigNumber; + reserveFactor: BigNumber; + usageAsCollateralEnabled: boolean; + borrowingEnabled: boolean; + stableBorrowRateEnabled: boolean; + isActive: boolean; + isFrozen: boolean; + } + >; + + getReserveData( + asset: string, + overrides?: CallOverrides + ): Promise< + [BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, number] & { + availableLiquidity: BigNumber; + totalStableDebt: BigNumber; + totalVariableDebt: BigNumber; + liquidityRate: BigNumber; + variableBorrowRate: BigNumber; + stableBorrowRate: BigNumber; + averageStableBorrowRate: BigNumber; + liquidityIndex: BigNumber; + variableBorrowIndex: BigNumber; + lastUpdateTimestamp: number; + } + >; + + getReserveTokensAddresses( + asset: string, + overrides?: CallOverrides + ): Promise< + [string, string, string] & { + aTokenAddress: string; + stableDebtTokenAddress: string; + variableDebtTokenAddress: string; + } + >; + + getUserReserveData( + asset: string, + user: string, + overrides?: CallOverrides + ): Promise< + [BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, number, boolean] & { + currentATokenBalance: BigNumber; + currentStableDebt: BigNumber; + currentVariableDebt: BigNumber; + principalStableDebt: BigNumber; + scaledVariableDebt: BigNumber; + stableBorrowRate: BigNumber; + liquidityRate: BigNumber; + stableRateLastUpdated: number; + usageAsCollateralEnabled: boolean; + } + >; + }; + + ADDRESSES_PROVIDER(overrides?: CallOverrides): Promise; + + getAllATokens(overrides?: CallOverrides): Promise; + + getAllReservesTokens(overrides?: CallOverrides): Promise; + + getReserveConfigurationData( + asset: string, + overrides?: CallOverrides + ): Promise< + [BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, boolean, boolean, boolean, boolean, boolean] & { + decimals: BigNumber; + ltv: BigNumber; + liquidationThreshold: BigNumber; + liquidationBonus: BigNumber; + reserveFactor: BigNumber; + usageAsCollateralEnabled: boolean; + borrowingEnabled: boolean; + stableBorrowRateEnabled: boolean; + isActive: boolean; + isFrozen: boolean; + } + >; + + getReserveData( + asset: string, + overrides?: CallOverrides + ): Promise< + [BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, number] & { + availableLiquidity: BigNumber; + totalStableDebt: BigNumber; + totalVariableDebt: BigNumber; + liquidityRate: BigNumber; + variableBorrowRate: BigNumber; + stableBorrowRate: BigNumber; + averageStableBorrowRate: BigNumber; + liquidityIndex: BigNumber; + variableBorrowIndex: BigNumber; + lastUpdateTimestamp: number; + } + >; + + getReserveTokensAddresses( + asset: string, + overrides?: CallOverrides + ): Promise< + [string, string, string] & { + aTokenAddress: string; + stableDebtTokenAddress: string; + variableDebtTokenAddress: string; + } + >; + + getUserReserveData( + asset: string, + user: string, + overrides?: CallOverrides + ): Promise< + [BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, number, boolean] & { + currentATokenBalance: BigNumber; + currentStableDebt: BigNumber; + currentVariableDebt: BigNumber; + principalStableDebt: BigNumber; + scaledVariableDebt: BigNumber; + stableBorrowRate: BigNumber; + liquidityRate: BigNumber; + stableRateLastUpdated: number; + usageAsCollateralEnabled: boolean; + } + >; + + callStatic: { + ADDRESSES_PROVIDER(overrides?: CallOverrides): Promise; + + getAllATokens(overrides?: CallOverrides): Promise; + + getAllReservesTokens(overrides?: CallOverrides): Promise; + + getReserveConfigurationData( + asset: string, + overrides?: CallOverrides + ): Promise< + [BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, boolean, boolean, boolean, boolean, boolean] & { + decimals: BigNumber; + ltv: BigNumber; + liquidationThreshold: BigNumber; + liquidationBonus: BigNumber; + reserveFactor: BigNumber; + usageAsCollateralEnabled: boolean; + borrowingEnabled: boolean; + stableBorrowRateEnabled: boolean; + isActive: boolean; + isFrozen: boolean; + } + >; + + getReserveData( + asset: string, + overrides?: CallOverrides + ): Promise< + [BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, number] & { + availableLiquidity: BigNumber; + totalStableDebt: BigNumber; + totalVariableDebt: BigNumber; + liquidityRate: BigNumber; + variableBorrowRate: BigNumber; + stableBorrowRate: BigNumber; + averageStableBorrowRate: BigNumber; + liquidityIndex: BigNumber; + variableBorrowIndex: BigNumber; + lastUpdateTimestamp: number; + } + >; + + getReserveTokensAddresses( + asset: string, + overrides?: CallOverrides + ): Promise< + [string, string, string] & { + aTokenAddress: string; + stableDebtTokenAddress: string; + variableDebtTokenAddress: string; + } + >; + + getUserReserveData( + asset: string, + user: string, + overrides?: CallOverrides + ): Promise< + [BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, number, boolean] & { + currentATokenBalance: BigNumber; + currentStableDebt: BigNumber; + currentVariableDebt: BigNumber; + principalStableDebt: BigNumber; + scaledVariableDebt: BigNumber; + stableBorrowRate: BigNumber; + liquidityRate: BigNumber; + stableRateLastUpdated: number; + usageAsCollateralEnabled: boolean; + } + >; + }; + + filters: {}; + + estimateGas: { + ADDRESSES_PROVIDER(overrides?: CallOverrides): Promise; + + getAllATokens(overrides?: CallOverrides): Promise; + + getAllReservesTokens(overrides?: CallOverrides): Promise; + + getReserveConfigurationData(asset: string, overrides?: CallOverrides): Promise; + + getReserveData(asset: string, overrides?: CallOverrides): Promise; + + getReserveTokensAddresses(asset: string, overrides?: CallOverrides): Promise; + + getUserReserveData(asset: string, user: string, overrides?: CallOverrides): Promise; + }; + + populateTransaction: { + ADDRESSES_PROVIDER(overrides?: CallOverrides): Promise; + + getAllATokens(overrides?: CallOverrides): Promise; + + getAllReservesTokens(overrides?: CallOverrides): Promise; + + getReserveConfigurationData(asset: string, overrides?: CallOverrides): Promise; + + getReserveData(asset: string, overrides?: CallOverrides): Promise; + + getReserveTokensAddresses(asset: string, overrides?: CallOverrides): Promise; + + getUserReserveData(asset: string, user: string, overrides?: CallOverrides): Promise; + }; +} diff --git a/src/logics/iolend/contracts/common.ts b/src/logics/iolend/contracts/common.ts new file mode 100644 index 00000000..6cfb1042 --- /dev/null +++ b/src/logics/iolend/contracts/common.ts @@ -0,0 +1,30 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { Listener } from '@ethersproject/providers'; +import type { Event, EventFilter } from 'ethers'; + +export interface TypedEvent = any, TArgsObject = any> extends Event { + args: TArgsArray & TArgsObject; +} + +export interface TypedEventFilter<_TEvent extends TypedEvent> extends EventFilter {} + +export interface TypedListener { + (...listenerArg: [...__TypechainArgsArray, TEvent]): void; +} + +type __TypechainArgsArray = T extends TypedEvent ? U : never; + +export interface OnEvent { + (eventFilter: TypedEventFilter, listener: TypedListener): TRes; + (eventName: string, listener: Listener): TRes; +} + +export type MinEthersFactory = { + deploy(...a: ARGS[]): Promise; +}; + +export type GetContractTypeFromFactory = F extends MinEthersFactory ? C : never; + +export type GetARGsTypeFromFactory = F extends MinEthersFactory ? Parameters : never; diff --git a/src/logics/iolend/contracts/factories/DebtTokenBase__factory.ts b/src/logics/iolend/contracts/factories/DebtTokenBase__factory.ts new file mode 100644 index 00000000..5b06acb9 --- /dev/null +++ b/src/logics/iolend/contracts/factories/DebtTokenBase__factory.ts @@ -0,0 +1,62 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from 'ethers'; +import type { Provider } from '@ethersproject/providers'; +import type { DebtTokenBase, DebtTokenBaseInterface } from '../DebtTokenBase'; + +const _abi = [ + { + inputs: [ + { + internalType: 'address', + name: 'delegatee', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'approveDelegation', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'fromUser', + type: 'address', + }, + { + internalType: 'address', + name: 'toUser', + type: 'address', + }, + ], + name: 'borrowAllowance', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, +] as const; + +export class DebtTokenBase__factory { + static readonly abi = _abi; + static createInterface(): DebtTokenBaseInterface { + return new utils.Interface(_abi) as DebtTokenBaseInterface; + } + static connect(address: string, signerOrProvider: Signer | Provider): DebtTokenBase { + return new Contract(address, _abi, signerOrProvider) as DebtTokenBase; + } +} diff --git a/src/logics/iolend/contracts/factories/LendingPoolAddressesProvider__factory.ts b/src/logics/iolend/contracts/factories/LendingPoolAddressesProvider__factory.ts new file mode 100644 index 00000000..cb7a06e3 --- /dev/null +++ b/src/logics/iolend/contracts/factories/LendingPoolAddressesProvider__factory.ts @@ -0,0 +1,523 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from 'ethers'; +import type { Provider } from '@ethersproject/providers'; +import type { + LendingPoolAddressesProvider, + LendingPoolAddressesProviderInterface, +} from '../LendingPoolAddressesProvider'; + +const _abi = [ + { + inputs: [ + { + internalType: 'string', + name: 'marketId', + type: 'string', + }, + ], + stateMutability: 'nonpayable', + type: 'constructor', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'bytes32', + name: 'id', + type: 'bytes32', + }, + { + indexed: true, + internalType: 'address', + name: 'newAddress', + type: 'address', + }, + { + indexed: false, + internalType: 'bool', + name: 'hasProxy', + type: 'bool', + }, + ], + name: 'AddressSet', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'newAddress', + type: 'address', + }, + ], + name: 'ConfigurationAdminUpdated', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'newAddress', + type: 'address', + }, + ], + name: 'EmergencyAdminUpdated', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'newAddress', + type: 'address', + }, + ], + name: 'LendingPoolCollateralManagerUpdated', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'newAddress', + type: 'address', + }, + ], + name: 'LendingPoolConfiguratorUpdated', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'newAddress', + type: 'address', + }, + ], + name: 'LendingPoolUpdated', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'newAddress', + type: 'address', + }, + ], + name: 'LendingRateOracleUpdated', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'string', + name: 'newMarketId', + type: 'string', + }, + ], + name: 'MarketIdSet', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'previousOwner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'OwnershipTransferred', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'newAddress', + type: 'address', + }, + ], + name: 'PriceOracleUpdated', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'bytes32', + name: 'id', + type: 'bytes32', + }, + { + indexed: true, + internalType: 'address', + name: 'newAddress', + type: 'address', + }, + ], + name: 'ProxyCreated', + type: 'event', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'id', + type: 'bytes32', + }, + ], + name: 'getAddress', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getEmergencyAdmin', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getLendingPool', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getLendingPoolCollateralManager', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getLendingPoolConfigurator', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getLendingRateOracle', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getLiquidationFeeTo', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getMarketId', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getPoolAdmin', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getPriceOracle', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'owner', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'renounceOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'id', + type: 'bytes32', + }, + { + internalType: 'address', + name: 'newAddress', + type: 'address', + }, + ], + name: 'setAddress', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'id', + type: 'bytes32', + }, + { + internalType: 'address', + name: 'implementationAddress', + type: 'address', + }, + ], + name: 'setAddressAsProxy', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'emergencyAdmin', + type: 'address', + }, + ], + name: 'setEmergencyAdmin', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'manager', + type: 'address', + }, + ], + name: 'setLendingPoolCollateralManager', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'configurator', + type: 'address', + }, + ], + name: 'setLendingPoolConfiguratorImpl', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'pool', + type: 'address', + }, + ], + name: 'setLendingPoolImpl', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'lendingRateOracle', + type: 'address', + }, + ], + name: 'setLendingRateOracle', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'liquidationFeeTo', + type: 'address', + }, + ], + name: 'setLiquidationFeeTo', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'string', + name: 'marketId', + type: 'string', + }, + ], + name: 'setMarketId', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'admin', + type: 'address', + }, + ], + name: 'setPoolAdmin', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'priceOracle', + type: 'address', + }, + ], + name: 'setPriceOracle', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'transferOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, +] as const; + +export class LendingPoolAddressesProvider__factory { + static readonly abi = _abi; + static createInterface(): LendingPoolAddressesProviderInterface { + return new utils.Interface(_abi) as LendingPoolAddressesProviderInterface; + } + static connect(address: string, signerOrProvider: Signer | Provider): LendingPoolAddressesProvider { + return new Contract(address, _abi, signerOrProvider) as LendingPoolAddressesProvider; + } +} diff --git a/src/logics/iolend/contracts/factories/LendingPool__factory.ts b/src/logics/iolend/contracts/factories/LendingPool__factory.ts new file mode 100644 index 00000000..2fd3d874 --- /dev/null +++ b/src/logics/iolend/contracts/factories/LendingPool__factory.ts @@ -0,0 +1,1181 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from 'ethers'; +import type { Provider } from '@ethersproject/providers'; +import type { LendingPool, LendingPoolInterface } from '../LendingPool'; + +const _abi = [ + { + inputs: [], + stateMutability: 'nonpayable', + type: 'constructor', + }, + { + 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: 'delegatee', + type: 'address', + }, + ], + name: 'delegateWithdraw', + 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: 'delegatee', + type: 'address', + }, + ], + name: 'undelegateWithdraw', + 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', + }, + { + inputs: [ + { + internalType: 'address', + name: 'asset', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'address', + name: 'onBehalfOf', + type: 'address', + }, + ], + name: 'withdraw', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'user', + type: 'address', + }, + ], + name: 'withdrawDelegatesOf', + outputs: [ + { + internalType: 'address[]', + name: '', + type: 'address[]', + }, + ], + stateMutability: 'view', + type: 'function', + }, +] as const; + +export class LendingPool__factory { + static readonly abi = _abi; + static createInterface(): LendingPoolInterface { + return new utils.Interface(_abi) as LendingPoolInterface; + } + static connect(address: string, signerOrProvider: Signer | Provider): LendingPool { + return new Contract(address, _abi, signerOrProvider) as LendingPool; + } +} diff --git a/src/logics/iolend/contracts/factories/ProtocolDataProvider__factory.ts b/src/logics/iolend/contracts/factories/ProtocolDataProvider__factory.ts new file mode 100644 index 00000000..6d5596ce --- /dev/null +++ b/src/logics/iolend/contracts/factories/ProtocolDataProvider__factory.ts @@ -0,0 +1,315 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from 'ethers'; +import type { Provider } from '@ethersproject/providers'; +import type { ProtocolDataProvider, ProtocolDataProviderInterface } from '../ProtocolDataProvider'; + +const _abi = [ + { + inputs: [ + { + internalType: 'contract ILendingPoolAddressesProvider', + name: 'addressesProvider', + type: 'address', + }, + ], + stateMutability: 'nonpayable', + type: 'constructor', + }, + { + inputs: [], + name: 'ADDRESSES_PROVIDER', + outputs: [ + { + internalType: 'contract ILendingPoolAddressesProvider', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getAllATokens', + outputs: [ + { + components: [ + { + internalType: 'string', + name: 'symbol', + type: 'string', + }, + { + internalType: 'address', + name: 'tokenAddress', + type: 'address', + }, + ], + internalType: 'struct AaveProtocolDataProvider.TokenData[]', + name: '', + type: 'tuple[]', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getAllReservesTokens', + outputs: [ + { + components: [ + { + internalType: 'string', + name: 'symbol', + type: 'string', + }, + { + internalType: 'address', + name: 'tokenAddress', + type: 'address', + }, + ], + internalType: 'struct AaveProtocolDataProvider.TokenData[]', + name: '', + type: 'tuple[]', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'asset', + type: 'address', + }, + ], + name: 'getReserveConfigurationData', + outputs: [ + { + internalType: 'uint256', + name: 'decimals', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'ltv', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'liquidationThreshold', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'liquidationBonus', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'reserveFactor', + type: 'uint256', + }, + { + internalType: 'bool', + name: 'usageAsCollateralEnabled', + type: 'bool', + }, + { + internalType: 'bool', + name: 'borrowingEnabled', + type: 'bool', + }, + { + internalType: 'bool', + name: 'stableBorrowRateEnabled', + type: 'bool', + }, + { + internalType: 'bool', + name: 'isActive', + type: 'bool', + }, + { + internalType: 'bool', + name: 'isFrozen', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'asset', + type: 'address', + }, + ], + name: 'getReserveData', + outputs: [ + { + internalType: 'uint256', + name: 'availableLiquidity', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'totalStableDebt', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'totalVariableDebt', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'liquidityRate', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'variableBorrowRate', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'stableBorrowRate', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'averageStableBorrowRate', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'liquidityIndex', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'variableBorrowIndex', + type: 'uint256', + }, + { + internalType: 'uint40', + name: 'lastUpdateTimestamp', + type: 'uint40', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'asset', + type: 'address', + }, + ], + name: 'getReserveTokensAddresses', + outputs: [ + { + internalType: 'address', + name: 'aTokenAddress', + type: 'address', + }, + { + internalType: 'address', + name: 'stableDebtTokenAddress', + type: 'address', + }, + { + internalType: 'address', + name: 'variableDebtTokenAddress', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'asset', + type: 'address', + }, + { + internalType: 'address', + name: 'user', + type: 'address', + }, + ], + name: 'getUserReserveData', + outputs: [ + { + internalType: 'uint256', + name: 'currentATokenBalance', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'currentStableDebt', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'currentVariableDebt', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'principalStableDebt', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'scaledVariableDebt', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'stableBorrowRate', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'liquidityRate', + type: 'uint256', + }, + { + internalType: 'uint40', + name: 'stableRateLastUpdated', + type: 'uint40', + }, + { + internalType: 'bool', + name: 'usageAsCollateralEnabled', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, +] as const; + +export class ProtocolDataProvider__factory { + static readonly abi = _abi; + static createInterface(): ProtocolDataProviderInterface { + return new utils.Interface(_abi) as ProtocolDataProviderInterface; + } + static connect(address: string, signerOrProvider: Signer | Provider): ProtocolDataProvider { + return new Contract(address, _abi, signerOrProvider) as ProtocolDataProvider; + } +} diff --git a/src/logics/iolend/contracts/factories/index.ts b/src/logics/iolend/contracts/factories/index.ts new file mode 100644 index 00000000..d489ff33 --- /dev/null +++ b/src/logics/iolend/contracts/factories/index.ts @@ -0,0 +1,7 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export { DebtTokenBase__factory } from './DebtTokenBase__factory'; +export { LendingPool__factory } from './LendingPool__factory'; +export { LendingPoolAddressesProvider__factory } from './LendingPoolAddressesProvider__factory'; +export { ProtocolDataProvider__factory } from './ProtocolDataProvider__factory'; diff --git a/src/logics/iolend/contracts/index.ts b/src/logics/iolend/contracts/index.ts new file mode 100644 index 00000000..b51fa23d --- /dev/null +++ b/src/logics/iolend/contracts/index.ts @@ -0,0 +1,12 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export type { DebtTokenBase } from './DebtTokenBase'; +export type { LendingPool } from './LendingPool'; +export type { LendingPoolAddressesProvider } from './LendingPoolAddressesProvider'; +export type { ProtocolDataProvider } from './ProtocolDataProvider'; +export * as factories from './factories'; +export { DebtTokenBase__factory } from './factories/DebtTokenBase__factory'; +export { LendingPool__factory } from './factories/LendingPool__factory'; +export { LendingPoolAddressesProvider__factory } from './factories/LendingPoolAddressesProvider__factory'; +export { ProtocolDataProvider__factory } from './factories/ProtocolDataProvider__factory'; diff --git a/src/logics/iolend/index.ts b/src/logics/iolend/index.ts new file mode 100644 index 00000000..d97d7c8b --- /dev/null +++ b/src/logics/iolend/index.ts @@ -0,0 +1,9 @@ +export * from './configs'; +export * from './contracts'; +export * from './logic.borrow'; +export * from './logic.deposit'; +export * from './logic.repay'; +export * from './logic.withdraw'; +export * from './service'; +export * from './types'; +export * from './tokens'; diff --git a/src/logics/iolend/logic.borrow.test.ts b/src/logics/iolend/logic.borrow.test.ts new file mode 100644 index 00000000..dd861d6c --- /dev/null +++ b/src/logics/iolend/logic.borrow.test.ts @@ -0,0 +1,71 @@ +import { BorrowLogic, BorrowLogicFields } from './logic.borrow'; +import { InterestRateMode } from './types'; +import { LendingPool__factory } from './contracts'; +import { LogicTestCase } from 'test/types'; +import { Service } from './service'; +import * as common from '@protocolink/common'; +import { constants, utils } from 'ethers'; +import * as core from '@protocolink/core'; +import { expect } from 'chai'; + +describe('Iolend BorrowLogic', () => { + context('Test getTokenList', async () => { + BorrowLogic.supportedChainIds.forEach((chainId) => { + it(`network: ${common.toNetworkId(chainId)}`, async () => { + const logic = new BorrowLogic(chainId); + const tokenList = await logic.getTokenList(); + expect(tokenList).to.have.lengthOf.above(0); + }); + }); + }); + + context('Test build', () => { + const chainId = common.ChainId.iota; + const logic = new BorrowLogic(chainId); + let lendingPoolAddress: string; + const iface = LendingPool__factory.createInterface(); + const account = '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa'; + + before(async () => { + const service = new Service(chainId); + lendingPoolAddress = await service.getLendingPoolAddress(); + }); + + const testCases: LogicTestCase[] = [ + { + fields: { + output: new common.TokenAmount(common.iotaTokens.IOTA, '1'), + interestRateMode: InterestRateMode.variable, + }, + }, + { + fields: { + output: new common.TokenAmount(common.iotaTokens.wIOTA, '1'), + interestRateMode: InterestRateMode.variable, + }, + }, + { + fields: { + output: new common.TokenAmount(common.iotaTokens.USDT, '1'), + interestRateMode: InterestRateMode.variable, + }, + }, + ]; + + testCases.forEach(({ fields }) => { + it(`borrow ${fields.output.token.symbol}`, async () => { + const routerLogic = await logic.build(fields, { account }); + const sig = routerLogic.data.substring(0, 10); + const { output } = fields; + + expect(routerLogic.to).to.eq(lendingPoolAddress); + expect(utils.isBytesLike(routerLogic.data)).to.be.true; + expect(sig).to.eq(iface.getSighash('borrow')); + expect(routerLogic.inputs).to.deep.eq([]); + expect(routerLogic.wrapMode).to.eq(output.token.isNative ? core.WrapMode.unwrapAfter : core.WrapMode.none); + expect(routerLogic.approveTo).to.eq(constants.AddressZero); + expect(routerLogic.callback).to.eq(constants.AddressZero); + }); + }); + }); +}); diff --git a/src/logics/iolend/logic.borrow.ts b/src/logics/iolend/logic.borrow.ts new file mode 100644 index 00000000..40bec848 --- /dev/null +++ b/src/logics/iolend/logic.borrow.ts @@ -0,0 +1,23 @@ +import { Service } from './service'; +import * as aavev2 from 'src/modules/aavev2'; +import * as core from '@protocolink/core'; +import { protocolId, supportedChainIds } from './configs'; +import { providers } from 'ethers'; + +export type BorrowLogicFields = aavev2.BorrowLogicFields; + +export type BorrowLogicOptions = aavev2.BorrowLogicOptions; + +export type BorrowLogicTokenList = aavev2.BorrowLogicTokenList; + +export class BorrowLogic + extends aavev2.BorrowLogic + implements core.LogicTokenListInterface, core.LogicBuilderInterface +{ + static protocolId = protocolId; + static readonly supportedChainIds = supportedChainIds; + + constructor(chainId: number, provider?: providers.Provider) { + super({ chainId, provider, service: new Service(chainId, provider) }); + } +} diff --git a/src/logics/iolend/logic.deposit.test.ts b/src/logics/iolend/logic.deposit.test.ts new file mode 100644 index 00000000..017edec6 --- /dev/null +++ b/src/logics/iolend/logic.deposit.test.ts @@ -0,0 +1,99 @@ +import { DepositLogic, DepositLogicFields } from './logic.deposit'; +import { LendingPool__factory } from './contracts'; +import { LogicTestCase } from 'test/types'; +import { Service } from './service'; +import * as common from '@protocolink/common'; +import { constants, utils } from 'ethers'; +import * as core from '@protocolink/core'; +import { expect } from 'chai'; +import { iotaTokens } from './tokens'; + +describe('Iolend DepositLogic', function () { + context('Test getTokenList', async function () { + DepositLogic.supportedChainIds.forEach((chainId) => { + it(`network: ${common.toNetworkId(chainId)}`, async function () { + const logic = new DepositLogic(chainId); + const tokenList = await logic.getTokenList(); + expect(tokenList).to.have.lengthOf.above(0); + }); + }); + }); + + context('Test build', function () { + const chainId = common.ChainId.iota; + const logic = new DepositLogic(chainId); + let lendingPoolAddress: string; + const iface = LendingPool__factory.createInterface(); + const account = '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa'; + + before(async function () { + const service = new Service(chainId); + lendingPoolAddress = await service.getLendingPoolAddress(); + }); + + const testCases: LogicTestCase[] = [ + { + fields: { + input: new common.TokenAmount(common.iotaTokens.IOTA, '1'), + output: new common.TokenAmount(iotaTokens.iWIOTA, '1'), + }, + }, + { + fields: { + input: new common.TokenAmount(common.iotaTokens.WETH, '1'), + output: new common.TokenAmount(iotaTokens.iWETH, '1'), + }, + }, + { + fields: { + input: new common.TokenAmount(common.iotaTokens.USDT, '1'), + output: new common.TokenAmount(iotaTokens.iUSDT, '1'), + }, + }, + { + fields: { + input: new common.TokenAmount(common.iotaTokens.IOTA, '1'), + output: new common.TokenAmount(iotaTokens.iWIOTA, '1'), + balanceBps: 5000, + }, + }, + { + fields: { + input: new common.TokenAmount(common.iotaTokens.WETH, '1'), + output: new common.TokenAmount(iotaTokens.iWETH, '1'), + balanceBps: 5000, + }, + }, + { + fields: { + input: new common.TokenAmount(common.iotaTokens.USDT, '1'), + output: new common.TokenAmount(iotaTokens.iUSDT, '1'), + balanceBps: 5000, + }, + }, + ]; + + testCases.forEach(({ fields }) => { + it(`deposit ${fields.input.token.symbol}${fields.balanceBps ? ' with balanceBps' : ''}`, async function () { + const routerLogic = await logic.build(fields, { account }); + const sig = routerLogic.data.substring(0, 10); + const { input, balanceBps } = fields; + + expect(routerLogic.to).to.eq(lendingPoolAddress); + expect(utils.isBytesLike(routerLogic.data)).to.be.true; + expect(sig).to.eq(iface.getSighash('deposit')); + expect(routerLogic.inputs[0].token).to.eq(input.token.wrapped.address); + if (balanceBps) { + expect(routerLogic.inputs[0].balanceBps).to.eq(balanceBps); + expect(routerLogic.inputs[0].amountOrOffset).to.eq(common.getParamOffset(1)); + } else { + expect(routerLogic.inputs[0].balanceBps).to.eq(core.BPS_NOT_USED); + expect(routerLogic.inputs[0].amountOrOffset).eq(input.amountWei); + } + expect(routerLogic.wrapMode).to.eq(input.token.isNative ? core.WrapMode.wrapBefore : core.WrapMode.none); + expect(routerLogic.approveTo).to.eq(constants.AddressZero); + expect(routerLogic.callback).to.eq(constants.AddressZero); + }); + }); + }); +}); diff --git a/src/logics/iolend/logic.deposit.ts b/src/logics/iolend/logic.deposit.ts new file mode 100644 index 00000000..91a05a8f --- /dev/null +++ b/src/logics/iolend/logic.deposit.ts @@ -0,0 +1,26 @@ +import { Service } from './service'; +import * as aavev2 from 'src/modules/aavev2'; +import { protocolId, supportedChainIds } from './configs'; +import { providers } from 'ethers'; + +export type DepositLogicTokenList = aavev2.DepositLogicTokenList; + +export type DepositLogicParams = aavev2.DepositLogicParams; + +export type DepositLogicFields = aavev2.DepositLogicFields; + +export type DepositLogicOptions = aavev2.DepositLogicOptions; + +export class DepositLogic extends aavev2.DepositLogics { + static protocolId = protocolId; + static readonly supportedChainIds = supportedChainIds; + + constructor(chainId: number, provider?: providers.Provider) { + super({ chainId, provider, service: new Service(chainId, provider) }); + } + + async getTokenList() { + const reserveTokens = await this.service.getSupplyTokens(); + return aavev2.createDepositTokenList(reserveTokens, 'aToken'); + } +} diff --git a/src/logics/iolend/logic.repay.test.ts b/src/logics/iolend/logic.repay.test.ts new file mode 100644 index 00000000..b2f26816 --- /dev/null +++ b/src/logics/iolend/logic.repay.test.ts @@ -0,0 +1,103 @@ +import { InterestRateMode } from './types'; +import { LendingPool__factory } from './contracts'; +import { LogicTestCase } from 'test/types'; +import { RepayLogic, RepayLogicFields } from './logic.repay'; +import { Service } from './service'; +import * as common from '@protocolink/common'; +import { constants, utils } from 'ethers'; +import * as core from '@protocolink/core'; +import { expect } from 'chai'; + +describe('Iolend RepayLogic', () => { + context('Test getTokenList', async () => { + RepayLogic.supportedChainIds.forEach((chainId) => { + it(`network: ${common.toNetworkId(chainId)}`, async () => { + const logic = new RepayLogic(chainId); + const tokenList = await logic.getTokenList(); + expect(tokenList).to.have.lengthOf.above(0); + }); + }); + }); + + context('Test build', () => { + const chainId = common.ChainId.iota; + const logic = new RepayLogic(chainId); + let lendingPoolAddress: string; + const iface = LendingPool__factory.createInterface(); + + before(async () => { + const service = new Service(chainId); + lendingPoolAddress = await service.getLendingPoolAddress(); + }); + + const testCases: LogicTestCase[] = [ + { + fields: { + input: new common.TokenAmount(common.iotaTokens.IOTA, '100'), + interestRateMode: InterestRateMode.variable, + borrower: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa', + }, + }, + { + fields: { + input: new common.TokenAmount(common.iotaTokens.wIOTA, '100'), + interestRateMode: InterestRateMode.variable, + borrower: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa', + }, + }, + { + fields: { + input: new common.TokenAmount(common.iotaTokens.USDT, '100'), + interestRateMode: InterestRateMode.variable, + borrower: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa', + }, + }, + { + fields: { + input: new common.TokenAmount(common.iotaTokens.IOTA, '100'), + interestRateMode: InterestRateMode.variable, + borrower: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa', + balanceBps: 5000, + }, + }, + { + fields: { + input: new common.TokenAmount(common.iotaTokens.wIOTA, '100'), + interestRateMode: InterestRateMode.variable, + borrower: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa', + balanceBps: 5000, + }, + }, + { + fields: { + input: new common.TokenAmount(common.iotaTokens.USDT, '100'), + interestRateMode: InterestRateMode.variable, + borrower: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa', + balanceBps: 5000, + }, + }, + ]; + + testCases.forEach(({ fields }) => { + it(`repay ${fields.input.token.symbol}${fields.balanceBps ? ' with balanceBps' : ''}`, async () => { + const routerLogic = await logic.build(fields); + const sig = routerLogic.data.substring(0, 10); + const { input, balanceBps } = fields; + + expect(routerLogic.to).to.eq(lendingPoolAddress); + expect(utils.isBytesLike(routerLogic.data)).to.be.true; + expect(sig).to.eq(iface.getSighash('repay')); + if (balanceBps) { + expect(routerLogic.inputs[0].balanceBps).to.eq(balanceBps); + expect(routerLogic.inputs[0].amountOrOffset).to.eq(common.getParamOffset(1)); + } else { + expect(routerLogic.inputs[0].balanceBps).to.eq(core.BPS_NOT_USED); + expect(routerLogic.inputs[0].amountOrOffset).eq(input.amountWei); + } + expect(routerLogic.wrapMode).to.eq(input.token.isNative ? core.WrapMode.wrapBefore : core.WrapMode.none); + expect(routerLogic.approveTo).to.eq(constants.AddressZero); + expect(routerLogic.callback).to.eq(constants.AddressZero); + }); + }); + }); +}); diff --git a/src/logics/iolend/logic.repay.ts b/src/logics/iolend/logic.repay.ts new file mode 100644 index 00000000..85f3ecfb --- /dev/null +++ b/src/logics/iolend/logic.repay.ts @@ -0,0 +1,23 @@ +import { Service } from './service'; +import * as aavev2 from 'src/modules/aavev2'; +import * as core from '@protocolink/core'; +import { protocolId, supportedChainIds } from './configs'; +import { providers } from 'ethers'; + +export type RepayLogicTokenList = aavev2.RepayLogicTokenList; + +export type RepayLogicParams = aavev2.RepayLogicParams; + +export type RepayLogicFields = aavev2.RepayLogicFields; + +export class RepayLogic + extends aavev2.RepayLogic + implements core.LogicTokenListInterface, core.LogicOracleInterface, core.LogicBuilderInterface +{ + static protocolId = protocolId; + static readonly supportedChainIds = supportedChainIds; + + constructor(chainId: number, provider?: providers.Provider) { + super({ chainId, provider, service: new Service(chainId, provider) }); + } +} diff --git a/src/logics/iolend/logic.withdraw.test.ts b/src/logics/iolend/logic.withdraw.test.ts new file mode 100644 index 00000000..d3482d4e --- /dev/null +++ b/src/logics/iolend/logic.withdraw.test.ts @@ -0,0 +1,97 @@ +import { LogicTestCase } from 'test/types'; +import { Service } from './service'; +import { WithdrawLogic, WithdrawLogicFields } from './logic.withdraw'; +import * as common from '@protocolink/common'; +import { constants, utils } from 'ethers'; +import * as core from '@protocolink/core'; +import { expect } from 'chai'; +import { iotaTokens } from './tokens'; + +describe('Iolend WithdrawLogic', () => { + context('Test getTokenList', async () => { + WithdrawLogic.supportedChainIds.forEach((chainId) => { + it(`network: ${common.toNetworkId(chainId)}`, async () => { + const logic = new WithdrawLogic(chainId); + const tokenList = await logic.getTokenList(); + expect(tokenList).to.have.lengthOf.above(0); + }); + }); + }); + + context('Test build', () => { + const chainId = common.ChainId.iota; + const logic = new WithdrawLogic(chainId); + let lendingPoolAddress: string; + const account = '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa'; + + before(async () => { + const service = new Service(chainId); + lendingPoolAddress = await service.getLendingPoolAddress(); + }); + + const testCases: LogicTestCase[] = [ + { + fields: { + input: new common.TokenAmount(iotaTokens.iWIOTA, '100'), + output: new common.TokenAmount(common.iotaTokens.IOTA, '100'), + }, + }, + { + fields: { + input: new common.TokenAmount(iotaTokens.iWIOTA, '100'), + output: new common.TokenAmount(common.iotaTokens.wIOTA, '100'), + }, + }, + { + fields: { + input: new common.TokenAmount(iotaTokens.iUSDT, '100'), + output: new common.TokenAmount(common.iotaTokens.USDT, '100'), + }, + }, + { + fields: { + input: new common.TokenAmount(iotaTokens.iWIOTA, '100'), + output: new common.TokenAmount(common.iotaTokens.IOTA, '100'), + balanceBps: 5000, + }, + }, + { + fields: { + input: new common.TokenAmount(iotaTokens.iWIOTA, '100'), + output: new common.TokenAmount(common.iotaTokens.wIOTA, '100'), + balanceBps: 5000, + }, + }, + { + fields: { + input: new common.TokenAmount(iotaTokens.iUSDT, '100'), + output: new common.TokenAmount(common.iotaTokens.USDT, '100'), + balanceBps: 5000, + }, + }, + ]; + + testCases.forEach(({ fields }) => { + it(`withdraw ${fields.output.token.symbol}${fields.balanceBps ? ' with balanceBps' : ''}`, async () => { + const routerLogic = await logic.build(fields, { account }); + const sig = routerLogic.data.substring(0, 10); + const { input, output, balanceBps } = fields; + + expect(routerLogic.to).to.eq(lendingPoolAddress); + expect(utils.isBytesLike(routerLogic.data)).to.be.true; + expect(sig).to.be.eq('0x69328dec'); // cmp sig directly to avoid Error: multiple matching functions + expect(routerLogic.inputs[0].token).to.eq(input.token.address); + if (balanceBps) { + expect(routerLogic.inputs[0].balanceBps).to.eq(balanceBps); + expect(routerLogic.inputs[0].amountOrOffset).to.eq(common.getParamOffset(1)); + } else { + expect(routerLogic.inputs[0].balanceBps).to.eq(core.BPS_NOT_USED); + expect(routerLogic.inputs[0].amountOrOffset).eq(input.amountWei); + } + expect(routerLogic.wrapMode).to.eq(output.token.isNative ? core.WrapMode.unwrapAfter : core.WrapMode.none); + expect(routerLogic.approveTo).to.eq(constants.AddressZero); + expect(routerLogic.callback).to.eq(constants.AddressZero); + }); + }); + }); +}); diff --git a/src/logics/iolend/logic.withdraw.ts b/src/logics/iolend/logic.withdraw.ts new file mode 100644 index 00000000..f5498fe6 --- /dev/null +++ b/src/logics/iolend/logic.withdraw.ts @@ -0,0 +1,30 @@ +import { Service } from './service'; +import * as aavev2 from 'src/modules/aavev2'; +import * as core from '@protocolink/core'; +import { protocolId, supportedChainIds } from './configs'; +import { providers } from 'ethers'; + +export type WithdrawLogicTokenList = aavev2.WithdrawLogicTokenList; + +export type WithdrawLogicParams = aavev2.WithdrawLogicParams; + +export type WithdrawLogicFields = aavev2.WithdrawLogicFields; + +export type WithdrawLogicOptions = aavev2.WithdrawLogicOptions; + +export class WithdrawLogic + extends aavev2.WithdrawLogic + implements core.LogicTokenListInterface, core.LogicOracleInterface, core.LogicBuilderInterface +{ + static protocolId = protocolId; + static readonly supportedChainIds = supportedChainIds; + + constructor(chainId: number, provider?: providers.Provider) { + super({ chainId, provider, service: new Service(chainId, provider) }); + } + + async getTokenList() { + const reserveTokens = await this.service.getSupplyTokens(); + return aavev2.createWithdrawTokenList(reserveTokens, 'aToken'); + } +} diff --git a/src/logics/iolend/service.ts b/src/logics/iolend/service.ts new file mode 100644 index 00000000..ed0597f3 --- /dev/null +++ b/src/logics/iolend/service.ts @@ -0,0 +1,210 @@ +import { + DebtTokenBase__factory, + LendingPoolAddressesProvider__factory, + LendingPool__factory, + ProtocolDataProvider, + ProtocolDataProvider__factory, +} from './contracts'; +import { InterestRateMode, ReserveTokens } from './types'; +import { LendingPoolInterface } from './contracts/LendingPool'; +import { ProtocolDataProviderInterface } from './contracts/ProtocolDataProvider'; +import * as common from '@protocolink/common'; +import { constants } from 'ethers'; +import { getContractAddress } from './configs'; +import invariant from 'tiny-invariant'; + +export class Service extends common.Web3Toolkit { + private _protocolDataProvider?: ProtocolDataProvider; + + get protocolDataProvider() { + if (!this._protocolDataProvider) { + this._protocolDataProvider = ProtocolDataProvider__factory.connect( + getContractAddress(this.chainId, 'ProtocolDataProvider'), + this.provider + ); + } + return this._protocolDataProvider; + } + + private _protocolDataProviderIface?: ProtocolDataProviderInterface; + + get protocolDataProviderIface() { + if (!this._protocolDataProviderIface) { + this._protocolDataProviderIface = ProtocolDataProvider__factory.createInterface(); + } + return this._protocolDataProviderIface; + } + + private _lendingPoolIface?: LendingPoolInterface; + + get lendingPoolIface() { + if (!this._lendingPoolIface) { + this._lendingPoolIface = LendingPool__factory.createInterface(); + } + return this._lendingPoolIface; + } + + private lendingPoolAddress?: string; + + async getLendingPoolAddress() { + if (!this.lendingPoolAddress) { + const addressProviderAddress = await this.protocolDataProvider.ADDRESSES_PROVIDER(); + this.lendingPoolAddress = await LendingPoolAddressesProvider__factory.connect( + addressProviderAddress, + this.provider + ).getLendingPool(); + } + + return this.lendingPoolAddress; + } + + private reserveTokens?: ReserveTokens[]; + private reserveMap?: Record; + + async getReserveTokens() { + if (!this.reserveTokens || !this.reserveMap) { + const tokenAddresses: string[] = []; + const reserveTokens: ReserveTokens[] = []; + const reserveMap: Record = {}; + + const lendingPoolAddress = await this.getLendingPoolAddress(); + const assetAddresses = await LendingPool__factory.connect(lendingPoolAddress, this.provider).getReservesList(); + + const calls: common.Multicall3.CallStruct[] = assetAddresses.flatMap((assetAddress) => [ + { + target: this.protocolDataProvider.address, + callData: this.protocolDataProviderIface.encodeFunctionData('getReserveConfigurationData', [assetAddress]), + }, + { + target: this.protocolDataProvider.address, + callData: this.protocolDataProviderIface.encodeFunctionData('getReserveTokensAddresses', [assetAddress]), + }, + ]); + const { returnData } = await this.multicall3.callStatic.aggregate(calls); + + assetAddresses.forEach((assetAddress, i) => { + const { isActive, isFrozen, borrowingEnabled } = this.protocolDataProviderIface.decodeFunctionResult( + 'getReserveConfigurationData', + returnData[i * 2] + ); + + const { aTokenAddress, stableDebtTokenAddress, variableDebtTokenAddress } = + this.protocolDataProviderIface.decodeFunctionResult('getReserveTokensAddresses', returnData[i * 2 + 1]); + + reserveMap[assetAddress] = { + isSupplyEnabled: isActive && !isFrozen, + isBorrowEnabled: isActive && !isFrozen && borrowingEnabled, + }; + + tokenAddresses.push(assetAddress, aTokenAddress, stableDebtTokenAddress, variableDebtTokenAddress); + }); + + const tokens = await this.getTokens(tokenAddresses); + + for (let i = 0; i < tokens.length; i += 4) { + const asset = tokens[i]; + const aToken = tokens[i + 1]; + const stableDebtToken = tokens[i + 2]; + const variableDebtToken = tokens[i + 3]; + + const reserveToken: ReserveTokens = { + ...reserveMap[asset.address], + asset, + aToken, + stableDebtToken, + variableDebtToken, + }; + + reserveTokens.push(reserveToken); + + reserveMap[asset.address] = reserveToken; + + // Add aToken address as key for quick lookup + reserveMap[aToken.address] = reserveToken; + } + + this.reserveTokens = reserveTokens; + this.reserveMap = reserveMap; + } + + return { reserveTokens: this.reserveTokens, reserveMap: this.reserveMap }; + } + + async getAssets() { + const { reserveTokens } = await this.getReserveTokens(); + return reserveTokens.map(({ asset }) => asset); + } + + async getATokens() { + const { reserveTokens } = await this.getReserveTokens(); + return reserveTokens.map(({ aToken }) => aToken); + } + + async getSupplyTokens() { + const { reserveTokens } = await this.getReserveTokens(); + return reserveTokens.filter(({ isSupplyEnabled }) => isSupplyEnabled); + } + + async getBorrowTokens() { + const { reserveTokens } = await this.getReserveTokens(); + return reserveTokens.filter(({ isBorrowEnabled }) => isBorrowEnabled); + } + + async toAToken(asset: common.Token) { + const { reserveMap } = await this.getReserveTokens(); + + const aToken = reserveMap[asset.wrapped.address]?.aToken; + invariant(aToken?.address !== constants.AddressZero, `unsupported asset: ${asset.wrapped.address}`); + + return aToken; + } + + async toATokens(assets: common.Token[]) { + return Promise.all(assets.map((asset) => this.toAToken(asset))); + } + + async toAsset(aToken: common.Token) { + const { reserveMap } = await this.getReserveTokens(); + + const asset = reserveMap[aToken.address]?.asset; + invariant(asset, `unsupported aToken: ${aToken.address}`); + + return asset; + } + + async getDebtTokenAddress(asset: common.Token, interestRateMode: InterestRateMode) { + const { reserveMap } = await this.getReserveTokens(); + + const { stableDebtToken, variableDebtToken } = reserveMap[asset.wrapped.address]; + invariant(stableDebtToken || variableDebtToken, `unsupported aToken: ${asset.wrapped.address}`); + + return interestRateMode === InterestRateMode.variable ? variableDebtToken.address : stableDebtToken.address; + } + + async isDelegationApproved( + account: string, + delegateeAddress: string, + assetAmount: common.TokenAmount, + interestRateMode: InterestRateMode + ) { + const debtTokenAddress = await this.getDebtTokenAddress(assetAmount.token, interestRateMode); + const borrowAllowance = await DebtTokenBase__factory.connect(debtTokenAddress, this.provider).borrowAllowance( + account, + delegateeAddress + ); + + return borrowAllowance.gte(assetAmount.amountWei); + } + + async buildApproveDelegationTransactionRequest( + delegateeAddress: string, + assetAmount: common.TokenAmount, + interestRateMode: InterestRateMode + ): Promise { + const to = await this.getDebtTokenAddress(assetAmount.token, interestRateMode); + const iface = DebtTokenBase__factory.createInterface(); + const data = iface.encodeFunctionData('approveDelegation', [delegateeAddress, constants.MaxUint256]); + + return { to, data }; + } +} diff --git a/src/logics/iolend/tokens/data/iota.json b/src/logics/iolend/tokens/data/iota.json new file mode 100644 index 00000000..a753c02a --- /dev/null +++ b/src/logics/iolend/tokens/data/iota.json @@ -0,0 +1,23 @@ +{ + "iWIOTA": { + "chainId": 8822, + "address": "0xdad653B668b0E10D665eAdAe0A873c69f5280c45", + "decimals": 18, + "symbol": "iWIOTA", + "name": "IO Lend interest bearing WIOTA" + }, + "iUSDT": { + "chainId": 8822, + "address": "0x7fA6e7C26Fac91541306B0240f930599F6e1D041", + "decimals": 6, + "symbol": "iUSDC", + "name": "IO Lend interest bearing USDT" + }, + "iWETH": { + "chainId": 8822, + "address": "0xe8d4c068c26B6fd6EFbf828d2097f1A94035159D", + "decimals": 18, + "symbol": "iWETH", + "name": "IO Lend interest bearing WETH" + } +} diff --git a/src/logics/iolend/tokens/index.ts b/src/logics/iolend/tokens/index.ts new file mode 100644 index 00000000..de19de42 --- /dev/null +++ b/src/logics/iolend/tokens/index.ts @@ -0,0 +1,6 @@ +import * as common from '@protocolink/common'; +import iotaTokensJSON from './data/iota.json'; + +type IotaTokenSymbols = keyof typeof iotaTokensJSON; + +export const iotaTokens = common.toTokenMap(iotaTokensJSON); diff --git a/src/logics/iolend/types.ts b/src/logics/iolend/types.ts new file mode 100644 index 00000000..672afeac --- /dev/null +++ b/src/logics/iolend/types.ts @@ -0,0 +1,16 @@ +import * as common from '@protocolink/common'; + +export interface ReserveTokens { + asset: common.Token; + aToken: common.Token; + stableDebtToken: common.Token; + variableDebtToken: common.Token; + isSupplyEnabled: boolean; + isBorrowEnabled: boolean; +} + +export enum InterestRateMode { + none = 0, + stable = 1, + variable = 2, +} diff --git a/src/modules/aavev2/types.ts b/src/modules/aavev2/types.ts index e0229822..a9adeae1 100644 --- a/src/modules/aavev2/types.ts +++ b/src/modules/aavev2/types.ts @@ -1,4 +1,5 @@ import { Service as AaveV2Service } from 'src/logics/aave-v2'; +import { Service as IolendService } from 'src/logics/iolend'; import { Service as RadiantV2Service } from 'src/logics/radiant-v2'; import { providers } from 'ethers'; @@ -8,7 +9,7 @@ export enum InterestRateMode { variable = 2, } -export type serviceType = AaveV2Service | RadiantV2Service; +export type serviceType = AaveV2Service | IolendService | RadiantV2Service; export interface LogicOptions { chainId: number; diff --git a/test/logics/iolend/borrow.test.ts b/test/logics/iolend/borrow.test.ts new file mode 100644 index 00000000..4c57154f --- /dev/null +++ b/test/logics/iolend/borrow.test.ts @@ -0,0 +1,85 @@ +import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; +import { claimToken, getChainId, snapshotAndRevertEach } from '@protocolink/test-helpers'; +import * as common from '@protocolink/common'; +import * as core from '@protocolink/core'; +import { expect } from 'chai'; +import * as helpers from './helpers'; +import hre from 'hardhat'; +import * as iolend from 'src/logics/iolend'; + +describe('iota-pb: Test Iolend Borrow Logic', () => { + let chainId: number; + let users: SignerWithAddress[]; + + before(async () => { + chainId = await getChainId(); + const [, user1, user2] = await hre.ethers.getSigners(); + users = [user1, user2]; + await claimToken( + chainId, + user1.address, + common.iotaTokens.USDT, + '5000', + '0x7fA6e7C26Fac91541306B0240f930599F6e1D041' + ); + await claimToken( + chainId, + user2.address, + common.iotaTokens.wIOTA, + '10000', + '0x260817581206317e2665080a2e66854e922269d0' + ); + }); + + snapshotAndRevertEach(); + + const testCases = [ + { + userIndex: 0, + deposit: new common.TokenAmount(common.iotaTokens.USDT, '1000'), + output: new common.TokenAmount(common.iotaTokens.wIOTA, '100'), + interestRateMode: iolend.InterestRateMode.variable, + }, + { + userIndex: 0, + deposit: new common.TokenAmount(common.iotaTokens.USDT, '1000'), + output: new common.TokenAmount(common.iotaTokens.IOTA, '100'), + interestRateMode: iolend.InterestRateMode.variable, + }, + { + userIndex: 1, + deposit: new common.TokenAmount(common.iotaTokens.wIOTA, '1000'), + output: new common.TokenAmount(common.iotaTokens.USDT, '10'), + interestRateMode: iolend.InterestRateMode.variable, + }, + { + userIndex: 1, + deposit: new common.TokenAmount(common.iotaTokens.wIOTA, '10000'), + output: new common.TokenAmount(common.iotaTokens.USDT, '100'), + interestRateMode: iolend.InterestRateMode.variable, + }, + ]; + + testCases.forEach(({ userIndex, deposit, output, interestRateMode }, i) => { + it(`case ${i + 1}`, async () => { + // 1. deposit and approve delegation + const user = users[userIndex]; + await helpers.deposit(chainId, user, deposit); + await helpers.approveDelegation(chainId, user, output, interestRateMode); + + // 2. build tokensReturn + const tokensReturn = [output.token.elasticAddress]; + + // 3. build router logics + const routerLogics: core.DataType.LogicStruct[] = []; + const iolendBorrowLogic = new iolend.BorrowLogic(chainId); + routerLogics.push(await iolendBorrowLogic.build({ output, interestRateMode }, { account: user.address })); + + // 4. send router tx + const routerKit = new core.RouterKit(chainId); + const transactionRequest = routerKit.buildExecuteTransactionRequest({ routerLogics, tokensReturn }); + await expect(user.sendTransaction(transactionRequest)).to.not.be.reverted; + await expect(user.address).to.changeBalance(output.token, output.amount); + }); + }); +}); diff --git a/test/logics/iolend/deposit.test.ts b/test/logics/iolend/deposit.test.ts new file mode 100644 index 00000000..0b296b2f --- /dev/null +++ b/test/logics/iolend/deposit.test.ts @@ -0,0 +1,101 @@ +import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; +import { claimToken, getChainId, snapshotAndRevertEach } from '@protocolink/test-helpers'; +import * as common from '@protocolink/common'; +import * as core from '@protocolink/core'; +import { expect } from 'chai'; +import hre from 'hardhat'; +import * as iolend from 'src/logics/iolend'; +import * as utils from 'test/utils'; + +describe('iota-pb: Test Iolend Deposit Logic', () => { + let chainId: number; + let user: SignerWithAddress; + + before(async () => { + chainId = await getChainId(); + [, user] = await hre.ethers.getSigners(); + await claimToken( + chainId, + user.address, + common.iotaTokens.wIOTA, + '100', + '0x260817581206317e2665080a2e66854e922269d0' + ); + await claimToken( + chainId, + user.address, + common.iotaTokens.USDT, + '100', + '0x7fA6e7C26Fac91541306B0240f930599F6e1D041' + ); + }); + + snapshotAndRevertEach(); + + const testCases = [ + { + input: new common.TokenAmount(common.iotaTokens.IOTA, '1'), + tokenOut: iolend.iotaTokens.iWIOTA, + }, + { + input: new common.TokenAmount(common.iotaTokens.wIOTA, '1'), + tokenOut: iolend.iotaTokens.iWIOTA, + }, + { + input: new common.TokenAmount(common.iotaTokens.USDT, '1'), + tokenOut: iolend.iotaTokens.iUSDT, + }, + { + input: new common.TokenAmount(common.iotaTokens.IOTA, '1'), + tokenOut: iolend.iotaTokens.iWIOTA, + balanceBps: 5000, + }, + { + input: new common.TokenAmount(common.iotaTokens.wIOTA, '1'), + tokenOut: iolend.iotaTokens.iWIOTA, + balanceBps: 5000, + }, + { + input: new common.TokenAmount(common.iotaTokens.USDT, '1'), + tokenOut: iolend.iotaTokens.iUSDT, + balanceBps: 5000, + }, + ]; + + testCases.forEach(({ input, tokenOut, balanceBps }, i) => { + it(`case ${i + 1}`, async () => { + // 1. get output + const iolendDepositLogic = new iolend.DepositLogic(chainId); + const { output } = await iolendDepositLogic.quote({ input, tokenOut }); + + // 2. build funds, tokensReturn + const tokensReturn = [output.token.elasticAddress]; + const funds = new common.TokenAmounts(); + if (balanceBps) { + funds.add(utils.calcRequiredAmountByBalanceBps(input, balanceBps)); + tokensReturn.push(input.token.elasticAddress); + } else { + funds.add(input); + } + + // 3. build router logics + const routerLogics: core.DataType.LogicStruct[] = []; + routerLogics.push(await iolendDepositLogic.build({ input, output, balanceBps }, { account: user.address })); + + // 4. get router permit2 datas + const permit2Datas = await utils.getRouterPermit2Datas(chainId, user, funds.erc20); + + // 5. send router tx + const routerKit = new core.RouterKit(chainId); + const transactionRequest = routerKit.buildExecuteTransactionRequest({ + permit2Datas, + routerLogics, + tokensReturn, + value: funds.native?.amountWei ?? 0, + }); + await expect(user.sendTransaction(transactionRequest)).to.not.be.reverted; + await expect(user.address).to.changeBalance(input.token, -input.amount); + await expect(user.address).to.changeBalance(output.token, output.amount, 1); + }); + }); +}); diff --git a/test/logics/iolend/helpers.ts b/test/logics/iolend/helpers.ts new file mode 100644 index 00000000..9abaa973 --- /dev/null +++ b/test/logics/iolend/helpers.ts @@ -0,0 +1,67 @@ +import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; +import { approve } from '@protocolink/test-helpers'; +import * as common from '@protocolink/common'; +import * as core from '@protocolink/core'; +import { expect } from 'chai'; +import hre from 'hardhat'; +import * as iolend from 'src/logics/iolend'; + +export async function deposit(chainId: number, user: SignerWithAddress, assetAmount: common.TokenAmount) { + assetAmount = new common.TokenAmount(assetAmount.token.wrapped, assetAmount.amount); + + const service = new iolend.Service(chainId, hre.ethers.provider); + const lendingPoolAddress = await service.getLendingPoolAddress(); + await approve(user, lendingPoolAddress, assetAmount); + await expect( + iolend.LendingPool__factory.connect(lendingPoolAddress, user).deposit( + assetAmount.token.address, + assetAmount.amountWei, + user.address, + 0 + ) + ).to.not.be.reverted; +} + +export async function approveDelegation( + chainId: number, + user: SignerWithAddress, + assetAmount: common.TokenAmount, + interestRateMode: iolend.InterestRateMode +) { + const routerKit = new core.RouterKit(chainId); + const agent = await routerKit.calcAgent(user.address); + + const service = new iolend.Service(chainId, hre.ethers.provider); + const isDelegationApproved = await service.isDelegationApproved(user.address, agent, assetAmount, interestRateMode); + if (!isDelegationApproved) { + const tx = await service.buildApproveDelegationTransactionRequest(agent, assetAmount, interestRateMode); + await expect(user.sendTransaction(tx)).to.not.be.reverted; + } +} + +export async function borrow( + chainId: number, + user: SignerWithAddress, + assetAmount: common.TokenAmount, + interestRateMode: iolend.InterestRateMode +) { + if (assetAmount.token.isNative) { + const wrappedToken = assetAmount.token.wrapped; + await expect(common.WETH__factory.connect(wrappedToken.address, user).deposit({ value: assetAmount.amountWei })).to + .not.be.reverted; + assetAmount = new common.TokenAmount(wrappedToken, assetAmount.amount); + } + + const service = new iolend.Service(chainId, hre.ethers.provider); + const lendingPoolAddress = await service.getLendingPoolAddress(); + await approve(user, lendingPoolAddress, assetAmount); + await expect( + iolend.LendingPool__factory.connect(lendingPoolAddress, user).borrow( + assetAmount.token.address, + assetAmount.amountWei, + interestRateMode, + 0, + user.address + ) + ).to.not.be.reverted; +} diff --git a/test/logics/iolend/repay.test.ts b/test/logics/iolend/repay.test.ts new file mode 100644 index 00000000..d0d99fc2 --- /dev/null +++ b/test/logics/iolend/repay.test.ts @@ -0,0 +1,142 @@ +import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; +import { claimToken, getChainId, snapshotAndRevertEach } from '@protocolink/test-helpers'; +import * as common from '@protocolink/common'; +import * as core from '@protocolink/core'; +import { expect } from 'chai'; +import * as helpers from './helpers'; +import hre from 'hardhat'; +import * as iolend from 'src/logics/iolend'; +import * as utils from 'test/utils'; + +describe('iota-pb: Test Iolend Repay Logic', () => { + let chainId: number; + let users: SignerWithAddress[]; + + before(async () => { + chainId = await getChainId(); + const [, user1, user2] = await hre.ethers.getSigners(); + users = [user1, user2]; + await claimToken( + chainId, + user1.address, + common.iotaTokens.USDT, + '5000', + '0x7fA6e7C26Fac91541306B0240f930599F6e1D041' + ); + await claimToken( + chainId, + user1.address, + common.iotaTokens.wIOTA, + '5000', + '0x260817581206317e2665080a2e66854e922269d0' + ); + await claimToken( + chainId, + user2.address, + common.iotaTokens.USDT, + '5000', + '0x7fA6e7C26Fac91541306B0240f930599F6e1D041' + ); + await claimToken( + chainId, + user2.address, + common.iotaTokens.wIOTA, + '5000', + '0x260817581206317e2665080a2e66854e922269d0' + ); + }); + + snapshotAndRevertEach(); + + const testCases = [ + { + userIndex: 0, + deposit: new common.TokenAmount(common.iotaTokens.USDT, '5000'), + borrow: new common.TokenAmount(common.iotaTokens.IOTA, '100'), + interestRateMode: iolend.InterestRateMode.variable, + }, + { + userIndex: 0, + deposit: new common.TokenAmount(common.iotaTokens.USDT, '5000'), + borrow: new common.TokenAmount(common.iotaTokens.wIOTA, '100'), + interestRateMode: iolend.InterestRateMode.variable, + }, + { + userIndex: 1, + deposit: new common.TokenAmount(common.iotaTokens.wIOTA, '1000'), + borrow: new common.TokenAmount(common.iotaTokens.USDT, '1'), + interestRateMode: iolend.InterestRateMode.variable, + }, + { + // done + userIndex: 0, + deposit: new common.TokenAmount(common.iotaTokens.USDT, '5000'), + borrow: new common.TokenAmount(common.iotaTokens.IOTA, '100'), + interestRateMode: iolend.InterestRateMode.variable, + balanceBps: 5000, + }, + { + userIndex: 0, + deposit: new common.TokenAmount(common.iotaTokens.USDT, '5000'), + borrow: new common.TokenAmount(common.iotaTokens.wIOTA, '100'), + interestRateMode: iolend.InterestRateMode.variable, + balanceBps: 5000, + }, + { + userIndex: 1, + deposit: new common.TokenAmount(common.iotaTokens.wIOTA, '1000'), + borrow: new common.TokenAmount(common.iotaTokens.USDT, '1'), + interestRateMode: iolend.InterestRateMode.variable, + balanceBps: 5000, + }, + ]; + + testCases.forEach(({ userIndex, deposit, borrow, interestRateMode, balanceBps }, i) => { + it(`case ${i + 1}`, async () => { + // 1. deposit and borrow first + const user = users[userIndex]; + await helpers.deposit(chainId, user, deposit); + await helpers.borrow(chainId, user, borrow, interestRateMode); + + // 2. get user debt + const iolendRepayLogic = new iolend.RepayLogic(chainId, hre.ethers.provider); + let quotation = await iolendRepayLogic.quote({ + borrower: user.address, + tokenIn: borrow.token, + interestRateMode, + }); + const { input } = quotation; + + // 3. build funds and tokensReturn + const funds = new common.TokenAmounts(); + if (balanceBps) { + funds.add(utils.calcRequiredAmountByBalanceBps(input, balanceBps)); + } else { + funds.add(input); + } + const tokensReturn = [input.token.elasticAddress]; + + // 4. build router logics + const routerLogics: core.DataType.LogicStruct[] = []; + routerLogics.push(await iolendRepayLogic.build({ input, interestRateMode, borrower: user.address, balanceBps })); + + // 5. get router permit2 datas + const permit2Datas = await utils.getRouterPermit2Datas(chainId, user, funds.erc20); + + // 6. send router tx + const routerKit = new core.RouterKit(chainId); + const transactionRequest = routerKit.buildExecuteTransactionRequest({ + permit2Datas, + routerLogics, + tokensReturn, + value: funds.native?.amountWei ?? 0, + }); + await expect(user.sendTransaction(transactionRequest)).to.not.be.reverted; + await expect(user.address).to.changeBalance(input.token, -input.amount, 200); + + // 7. check user's debt should be zero + quotation = await iolendRepayLogic.quote({ borrower: user.address, tokenIn: borrow.token, interestRateMode }); + expect(quotation.input.amountWei).to.eq(0); + }); + }); +}); diff --git a/test/logics/iolend/withdraw.test.ts b/test/logics/iolend/withdraw.test.ts new file mode 100644 index 00000000..625bb585 --- /dev/null +++ b/test/logics/iolend/withdraw.test.ts @@ -0,0 +1,101 @@ +import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; +import { claimToken, getChainId, snapshotAndRevertEach } from '@protocolink/test-helpers'; +import * as common from '@protocolink/common'; +import * as core from '@protocolink/core'; +import { expect } from 'chai'; +import * as helpers from './helpers'; +import hre from 'hardhat'; +import * as iolend from 'src/logics/iolend'; +import * as utils from 'test/utils'; + +describe('iota-pb: Test iolend Withdraw Logic', () => { + let chainId: number; + let user: SignerWithAddress; + + before(async () => { + chainId = await getChainId(); + [, user] = await hre.ethers.getSigners(); + await claimToken( + chainId, + user.address, + common.iotaTokens.USDT, + '5000', + '0x7fA6e7C26Fac91541306B0240f930599F6e1D041' + ); + await claimToken( + chainId, + user.address, + common.iotaTokens.wIOTA, + '1000', + '0x03bde2983e2a8d6306411a4532e2f91cfb04051b' + ); + }); + + snapshotAndRevertEach(); + + const testCases = [ + { + input: new common.TokenAmount(iolend.iotaTokens.iWIOTA, '100'), + tokenOut: common.iotaTokens.wIOTA, + }, + { + input: new common.TokenAmount(iolend.iotaTokens.iWIOTA, '100'), + tokenOut: common.iotaTokens.IOTA, + }, + { + input: new common.TokenAmount(iolend.iotaTokens.iUSDT, '1'), + tokenOut: common.iotaTokens.USDT, + }, + { + input: new common.TokenAmount(iolend.iotaTokens.iWIOTA, '100'), + tokenOut: common.iotaTokens.wIOTA, + balanceBps: 5000, + }, + { + input: new common.TokenAmount(iolend.iotaTokens.iWIOTA, '100'), + tokenOut: common.iotaTokens.IOTA, + balanceBps: 5000, + }, + { + input: new common.TokenAmount(iolend.iotaTokens.iUSDT, '1'), + tokenOut: common.iotaTokens.USDT, + balanceBps: 5000, + }, + ]; + + testCases.forEach(({ input, tokenOut, balanceBps }, i) => { + it(`case ${i + 1}`, async () => { + // 1. deposit first + const assetsAmount = new common.TokenAmount(tokenOut, input.clone().add(input.amount).amount); + await helpers.deposit(chainId, user, assetsAmount); + + // 2. get output + const iolendWithdrawLogic = new iolend.WithdrawLogic(chainId); + const { output } = await iolendWithdrawLogic.quote({ input, tokenOut }); + + // 3. build funds, tokensReturn + const tokensReturn = [output.token.elasticAddress]; + const funds = new common.TokenAmounts(); + if (balanceBps) { + funds.add(utils.calcRequiredAmountByBalanceBps(input, balanceBps)); + tokensReturn.push(input.token.elasticAddress); + } else { + funds.add(input); + } + + // 4. build router logics + const routerLogics: core.DataType.LogicStruct[] = []; + routerLogics.push(await iolendWithdrawLogic.build({ input, output, balanceBps }, { account: user.address })); + + // 5. get router permit2 datas + const permit2Datas = await utils.getRouterPermit2Datas(chainId, user, funds.erc20); + + // 6. send router tx + const routerKit = new core.RouterKit(chainId); + const transactionRequest = routerKit.buildExecuteTransactionRequest({ permit2Datas, routerLogics, tokensReturn }); + await expect(user.sendTransaction(transactionRequest)).to.not.be.reverted; + await expect(user.address).to.changeBalance(input.token, -input.amount, 1); + await expect(user.address).to.changeBalance(output.token, output.amount); + }); + }); +});