From dfa2f49625d65c93dbbe97c0cc0a78b4fa0a2da0 Mon Sep 17 00:00:00 2001 From: William Poulin Date: Mon, 18 Dec 2023 21:50:57 -0500 Subject: [PATCH] fix(gearbox): Fixed lending app tokens v2 and added lending app tokens v3 (#3160) --- .../abis/gearbox-lending-token-v-3.json | 734 +++++++ .../contracts/viem.contract-factory.ts | 4 + .../contracts/viem/GearboxLendingTokenV3.ts | 1736 +++++++++++++++++ src/apps/gearbox/contracts/viem/index.ts | 2 + ...ts => gearbox.lending-v2.token-fetcher.ts} | 75 +- .../gearbox.lending-v3.token-fetcher.ts | 79 + src/apps/gearbox/gearbox.module.ts | 10 +- 7 files changed, 2608 insertions(+), 32 deletions(-) create mode 100644 src/apps/gearbox/contracts/abis/gearbox-lending-token-v-3.json create mode 100644 src/apps/gearbox/contracts/viem/GearboxLendingTokenV3.ts rename src/apps/gearbox/ethereum/{gearbox.lending.token-fetcher.ts => gearbox.lending-v2.token-fetcher.ts} (74%) create mode 100644 src/apps/gearbox/ethereum/gearbox.lending-v3.token-fetcher.ts diff --git a/src/apps/gearbox/contracts/abis/gearbox-lending-token-v-3.json b/src/apps/gearbox/contracts/abis/gearbox-lending-token-v-3.json new file mode 100644 index 000000000..49d25c464 --- /dev/null +++ b/src/apps/gearbox/contracts/abis/gearbox-lending-token-v-3.json @@ -0,0 +1,734 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "addressProvider_", "type": "address" }, + { "internalType": "address", "name": "underlyingToken_", "type": "address" }, + { "internalType": "address", "name": "interestRateModel_", "type": "address" }, + { "internalType": "uint256", "name": "totalDebtLimit_", "type": "uint256" }, + { "internalType": "string", "name": "name_", "type": "string" }, + { "internalType": "string", "name": "symbol_", "type": "string" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { "inputs": [], "name": "CallerNotConfiguratorException", "type": "error" }, + { "inputs": [], "name": "CallerNotControllerException", "type": "error" }, + { "inputs": [], "name": "CallerNotCreditManagerException", "type": "error" }, + { "inputs": [], "name": "CallerNotPausableAdminException", "type": "error" }, + { "inputs": [], "name": "CallerNotPoolQuotaKeeperException", "type": "error" }, + { "inputs": [], "name": "CallerNotUnpausableAdminException", "type": "error" }, + { "inputs": [], "name": "CreditManagerCantBorrowException", "type": "error" }, + { "inputs": [], "name": "IncompatibleCreditManagerException", "type": "error" }, + { "inputs": [], "name": "IncompatiblePoolQuotaKeeperException", "type": "error" }, + { "inputs": [], "name": "IncorrectParameterException", "type": "error" }, + { "inputs": [], "name": "InvalidShortString", "type": "error" }, + { "inputs": [], "name": "RegisteredCreditManagerOnlyException", "type": "error" }, + { "inputs": [], "name": "SafeTransferFailed", "type": "error" }, + { "inputs": [], "name": "SafeTransferFromFailed", "type": "error" }, + { + "inputs": [{ "internalType": "string", "name": "str", "type": "string" }], + "name": "StringTooLong", + "type": "error" + }, + { "inputs": [], "name": "ZeroAddressException", "type": "error" }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "internalType": "address", "name": "creditManager", "type": "address" }], + "name": "AddCreditManager", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "spender", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "creditManager", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "creditAccount", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "Borrow", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "sender", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "assets", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "shares", "type": "uint256" } + ], + "name": "Deposit", + "type": "event" + }, + { "anonymous": false, "inputs": [], "name": "EIP712DomainChanged", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "creditManager", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "loss", "type": "uint256" } + ], + "name": "IncurUncoveredLoss", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "internalType": "address", "name": "newController", "type": "address" }], + "name": "NewController", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "address", "name": "account", "type": "address" }], + "name": "Paused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "onBehalfOf", "type": "address" }, + { "indexed": true, "internalType": "uint256", "name": "referralCode", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "Refer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "creditManager", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "borrowedAmount", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "profit", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "loss", "type": "uint256" } + ], + "name": "Repay", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "creditManager", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "newLimit", "type": "uint256" } + ], + "name": "SetCreditManagerDebtLimit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "internalType": "address", "name": "newInterestRateModel", "type": "address" }], + "name": "SetInterestRateModel", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "internalType": "address", "name": "newPoolQuotaKeeper", "type": "address" }], + "name": "SetPoolQuotaKeeper", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "uint256", "name": "limit", "type": "uint256" }], + "name": "SetTotalDebtLimit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "uint256", "name": "fee", "type": "uint256" }], + "name": "SetWithdrawFee", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "from", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "address", "name": "account", "type": "address" }], + "name": "Unpaused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "sender", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "receiver", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "assets", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "shares", "type": "uint256" } + ], + "name": "Withdraw", + "type": "event" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "acl", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "addressProvider", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" } + ], + "name": "allowance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "approve", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "asset", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "availableLiquidity", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "account", "type": "address" }], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "baseInterestIndex", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "baseInterestIndexLU", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "baseInterestRate", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "contractsRegister", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "controller", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "shares", "type": "uint256" }], + "name": "convertToAssets", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "assets", "type": "uint256" }], + "name": "convertToShares", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "creditManager", "type": "address" }], + "name": "creditManagerBorrowable", + "outputs": [{ "internalType": "uint256", "name": "borrowable", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "creditManager", "type": "address" }], + "name": "creditManagerBorrowed", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "creditManager", "type": "address" }], + "name": "creditManagerDebtLimit", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "creditManagers", + "outputs": [{ "internalType": "address[]", "name": "", "type": "address[]" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "subtractedValue", "type": "uint256" } + ], + "name": "decreaseAllowance", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "assets", "type": "uint256" }, + { "internalType": "address", "name": "receiver", "type": "address" } + ], + "name": "deposit", + "outputs": [{ "internalType": "uint256", "name": "shares", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "assets", "type": "uint256" }, + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "uint256", "name": "referralCode", "type": "uint256" } + ], + "name": "depositWithReferral", + "outputs": [{ "internalType": "uint256", "name": "shares", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "eip712Domain", + "outputs": [ + { "internalType": "bytes1", "name": "fields", "type": "bytes1" }, + { "internalType": "string", "name": "name", "type": "string" }, + { "internalType": "string", "name": "version", "type": "string" }, + { "internalType": "uint256", "name": "chainId", "type": "uint256" }, + { "internalType": "address", "name": "verifyingContract", "type": "address" }, + { "internalType": "bytes32", "name": "salt", "type": "bytes32" }, + { "internalType": "uint256[]", "name": "extensions", "type": "uint256[]" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "expectedLiquidity", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "expectedLiquidityLU", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "addedValue", "type": "uint256" } + ], + "name": "increaseAllowance", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "interestRateModel", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "lastBaseInterestUpdate", + "outputs": [{ "internalType": "uint40", "name": "", "type": "uint40" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "lastQuotaRevenueUpdate", + "outputs": [{ "internalType": "uint40", "name": "", "type": "uint40" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "borrowedAmount", "type": "uint256" }, + { "internalType": "address", "name": "creditAccount", "type": "address" } + ], + "name": "lendCreditAccount", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "maxDeposit", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "maxMint", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "owner", "type": "address" }], + "name": "maxRedeem", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "owner", "type": "address" }], + "name": "maxWithdraw", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "shares", "type": "uint256" }, + { "internalType": "address", "name": "receiver", "type": "address" } + ], + "name": "mint", + "outputs": [{ "internalType": "uint256", "name": "assets", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "shares", "type": "uint256" }, + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "uint256", "name": "referralCode", "type": "uint256" } + ], + "name": "mintWithReferral", + "outputs": [{ "internalType": "uint256", "name": "assets", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "owner", "type": "address" }], + "name": "nonces", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { "inputs": [], "name": "pause", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "paused", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "permit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "poolQuotaKeeper", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "assets", "type": "uint256" }], + "name": "previewDeposit", + "outputs": [{ "internalType": "uint256", "name": "shares", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "shares", "type": "uint256" }], + "name": "previewMint", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "shares", "type": "uint256" }], + "name": "previewRedeem", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "assets", "type": "uint256" }], + "name": "previewWithdraw", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "quotaRevenue", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "shares", "type": "uint256" }, + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "address", "name": "owner", "type": "address" } + ], + "name": "redeem", + "outputs": [{ "internalType": "uint256", "name": "assets", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "repaidAmount", "type": "uint256" }, + { "internalType": "uint256", "name": "profit", "type": "uint256" }, + { "internalType": "uint256", "name": "loss", "type": "uint256" } + ], + "name": "repayCreditAccount", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "newController", "type": "address" }], + "name": "setController", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "creditManager", "type": "address" }, + { "internalType": "uint256", "name": "newLimit", "type": "uint256" } + ], + "name": "setCreditManagerDebtLimit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "newInterestRateModel", "type": "address" }], + "name": "setInterestRateModel", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "newPoolQuotaKeeper", "type": "address" }], + "name": "setPoolQuotaKeeper", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "newQuotaRevenue", "type": "uint256" }], + "name": "setQuotaRevenue", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "newLimit", "type": "uint256" }], + "name": "setTotalDebtLimit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "newWithdrawFee", "type": "uint256" }], + "name": "setWithdrawFee", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "supplyRate", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalAssets", + "outputs": [{ "internalType": "uint256", "name": "assets", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalBorrowed", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalDebtLimit", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transfer", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "treasury", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "underlyingToken", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { "inputs": [], "name": "unpause", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [{ "internalType": "int256", "name": "quotaRevenueDelta", "type": "int256" }], + "name": "updateQuotaRevenue", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "version", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "assets", "type": "uint256" }, + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "address", "name": "owner", "type": "address" } + ], + "name": "withdraw", + "outputs": [{ "internalType": "uint256", "name": "shares", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "withdrawFee", + "outputs": [{ "internalType": "uint16", "name": "", "type": "uint16" }], + "stateMutability": "view", + "type": "function" + } +] diff --git a/src/apps/gearbox/contracts/viem.contract-factory.ts b/src/apps/gearbox/contracts/viem.contract-factory.ts index 4504d2397..1057115ed 100644 --- a/src/apps/gearbox/contracts/viem.contract-factory.ts +++ b/src/apps/gearbox/contracts/viem.contract-factory.ts @@ -9,6 +9,7 @@ import { ContractsRegister__factory, CreditManagerV2__factory, DieselToken__factory, + GearboxLendingTokenV3__factory, PhantomToken__factory, PoolService__factory, } from './viem'; @@ -34,6 +35,9 @@ export class GearboxViemContractFactory { dieselToken({ address, network }: ContractOpts) { return DieselToken__factory.connect(address, this.appToolkit.getViemNetworkProvider(network)); } + gearboxLendingTokenV3({ address, network }: ContractOpts) { + return GearboxLendingTokenV3__factory.connect(address, this.appToolkit.getViemNetworkProvider(network)); + } phantomToken({ address, network }: ContractOpts) { return PhantomToken__factory.connect(address, this.appToolkit.getViemNetworkProvider(network)); } diff --git a/src/apps/gearbox/contracts/viem/GearboxLendingTokenV3.ts b/src/apps/gearbox/contracts/viem/GearboxLendingTokenV3.ts new file mode 100644 index 000000000..89de3e5b3 --- /dev/null +++ b/src/apps/gearbox/contracts/viem/GearboxLendingTokenV3.ts @@ -0,0 +1,1736 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import { getContract, GetContractReturnType, PublicClient } from 'viem'; + +export const gearboxLendingTokenV3Abi = [ + { + inputs: [ + { + internalType: 'address', + name: 'addressProvider_', + type: 'address', + }, + { + internalType: 'address', + name: 'underlyingToken_', + type: 'address', + }, + { + internalType: 'address', + name: 'interestRateModel_', + type: 'address', + }, + { + internalType: 'uint256', + name: 'totalDebtLimit_', + type: 'uint256', + }, + { + internalType: 'string', + name: 'name_', + type: 'string', + }, + { + internalType: 'string', + name: 'symbol_', + type: 'string', + }, + ], + stateMutability: 'nonpayable', + type: 'constructor', + }, + { + inputs: [], + name: 'CallerNotConfiguratorException', + type: 'error', + }, + { + inputs: [], + name: 'CallerNotControllerException', + type: 'error', + }, + { + inputs: [], + name: 'CallerNotCreditManagerException', + type: 'error', + }, + { + inputs: [], + name: 'CallerNotPausableAdminException', + type: 'error', + }, + { + inputs: [], + name: 'CallerNotPoolQuotaKeeperException', + type: 'error', + }, + { + inputs: [], + name: 'CallerNotUnpausableAdminException', + type: 'error', + }, + { + inputs: [], + name: 'CreditManagerCantBorrowException', + type: 'error', + }, + { + inputs: [], + name: 'IncompatibleCreditManagerException', + type: 'error', + }, + { + inputs: [], + name: 'IncompatiblePoolQuotaKeeperException', + type: 'error', + }, + { + inputs: [], + name: 'IncorrectParameterException', + type: 'error', + }, + { + inputs: [], + name: 'InvalidShortString', + type: 'error', + }, + { + inputs: [], + name: 'RegisteredCreditManagerOnlyException', + type: 'error', + }, + { + inputs: [], + name: 'SafeTransferFailed', + type: 'error', + }, + { + inputs: [], + name: 'SafeTransferFromFailed', + type: 'error', + }, + { + inputs: [ + { + internalType: 'string', + name: 'str', + type: 'string', + }, + ], + name: 'StringTooLong', + type: 'error', + }, + { + inputs: [], + name: 'ZeroAddressException', + type: 'error', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'creditManager', + type: 'address', + }, + ], + name: 'AddCreditManager', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'value', + type: 'uint256', + }, + ], + name: 'Approval', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'creditManager', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'creditAccount', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'Borrow', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'sender', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'assets', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'shares', + type: 'uint256', + }, + ], + name: 'Deposit', + type: 'event', + }, + { + anonymous: false, + inputs: [], + name: 'EIP712DomainChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'creditManager', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'loss', + type: 'uint256', + }, + ], + name: 'IncurUncoveredLoss', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'newController', + type: 'address', + }, + ], + name: 'NewController', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'Paused', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'onBehalfOf', + type: 'address', + }, + { + indexed: true, + internalType: 'uint256', + name: 'referralCode', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'Refer', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'creditManager', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'borrowedAmount', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'profit', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'loss', + type: 'uint256', + }, + ], + name: 'Repay', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'creditManager', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'newLimit', + type: 'uint256', + }, + ], + name: 'SetCreditManagerDebtLimit', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'newInterestRateModel', + type: 'address', + }, + ], + name: 'SetInterestRateModel', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'newPoolQuotaKeeper', + type: 'address', + }, + ], + name: 'SetPoolQuotaKeeper', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint256', + name: 'limit', + type: 'uint256', + }, + ], + name: 'SetTotalDebtLimit', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint256', + name: 'fee', + type: 'uint256', + }, + ], + name: 'SetWithdrawFee', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'from', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'to', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'value', + type: 'uint256', + }, + ], + name: 'Transfer', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'Unpaused', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'sender', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'receiver', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'assets', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'shares', + type: 'uint256', + }, + ], + name: 'Withdraw', + type: 'event', + }, + { + inputs: [], + name: 'DOMAIN_SEPARATOR', + outputs: [ + { + internalType: 'bytes32', + name: '', + type: 'bytes32', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'acl', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'addressProvider', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + ], + name: 'allowance', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'approve', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'asset', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'availableLiquidity', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'balanceOf', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'baseInterestIndex', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'baseInterestIndexLU', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'baseInterestRate', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'contractsRegister', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'controller', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'shares', + type: 'uint256', + }, + ], + name: 'convertToAssets', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'assets', + type: 'uint256', + }, + ], + name: 'convertToShares', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'creditManager', + type: 'address', + }, + ], + name: 'creditManagerBorrowable', + outputs: [ + { + internalType: 'uint256', + name: 'borrowable', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'creditManager', + type: 'address', + }, + ], + name: 'creditManagerBorrowed', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'creditManager', + type: 'address', + }, + ], + name: 'creditManagerDebtLimit', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'creditManagers', + outputs: [ + { + internalType: 'address[]', + name: '', + type: 'address[]', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'decimals', + outputs: [ + { + internalType: 'uint8', + name: '', + type: 'uint8', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'subtractedValue', + type: 'uint256', + }, + ], + name: 'decreaseAllowance', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'assets', + type: 'uint256', + }, + { + internalType: 'address', + name: 'receiver', + type: 'address', + }, + ], + name: 'deposit', + outputs: [ + { + internalType: 'uint256', + name: 'shares', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'assets', + type: 'uint256', + }, + { + internalType: 'address', + name: 'receiver', + type: 'address', + }, + { + internalType: 'uint256', + name: 'referralCode', + type: 'uint256', + }, + ], + name: 'depositWithReferral', + outputs: [ + { + internalType: 'uint256', + name: 'shares', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'eip712Domain', + outputs: [ + { + internalType: 'bytes1', + name: 'fields', + type: 'bytes1', + }, + { + internalType: 'string', + name: 'name', + type: 'string', + }, + { + internalType: 'string', + name: 'version', + type: 'string', + }, + { + internalType: 'uint256', + name: 'chainId', + type: 'uint256', + }, + { + internalType: 'address', + name: 'verifyingContract', + type: 'address', + }, + { + internalType: 'bytes32', + name: 'salt', + type: 'bytes32', + }, + { + internalType: 'uint256[]', + name: 'extensions', + type: 'uint256[]', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'expectedLiquidity', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'expectedLiquidityLU', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'addedValue', + type: 'uint256', + }, + ], + name: 'increaseAllowance', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'interestRateModel', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'lastBaseInterestUpdate', + outputs: [ + { + internalType: 'uint40', + name: '', + type: 'uint40', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'lastQuotaRevenueUpdate', + outputs: [ + { + internalType: 'uint40', + name: '', + type: 'uint40', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'borrowedAmount', + type: 'uint256', + }, + { + internalType: 'address', + name: 'creditAccount', + type: 'address', + }, + ], + name: 'lendCreditAccount', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'maxDeposit', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'maxMint', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + ], + name: 'maxRedeem', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + ], + name: 'maxWithdraw', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'shares', + type: 'uint256', + }, + { + internalType: 'address', + name: 'receiver', + type: 'address', + }, + ], + name: 'mint', + outputs: [ + { + internalType: 'uint256', + name: 'assets', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'shares', + type: 'uint256', + }, + { + internalType: 'address', + name: 'receiver', + type: 'address', + }, + { + internalType: 'uint256', + name: 'referralCode', + type: 'uint256', + }, + ], + name: 'mintWithReferral', + outputs: [ + { + internalType: 'uint256', + name: 'assets', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'name', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + ], + name: 'nonces', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'pause', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'paused', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'value', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'deadline', + type: 'uint256', + }, + { + internalType: 'uint8', + name: 'v', + type: 'uint8', + }, + { + internalType: 'bytes32', + name: 'r', + type: 'bytes32', + }, + { + internalType: 'bytes32', + name: 's', + type: 'bytes32', + }, + ], + name: 'permit', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'poolQuotaKeeper', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'assets', + type: 'uint256', + }, + ], + name: 'previewDeposit', + outputs: [ + { + internalType: 'uint256', + name: 'shares', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'shares', + type: 'uint256', + }, + ], + name: 'previewMint', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'shares', + type: 'uint256', + }, + ], + name: 'previewRedeem', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'assets', + type: 'uint256', + }, + ], + name: 'previewWithdraw', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'quotaRevenue', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'shares', + type: 'uint256', + }, + { + internalType: 'address', + name: 'receiver', + type: 'address', + }, + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + ], + name: 'redeem', + outputs: [ + { + internalType: 'uint256', + name: 'assets', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'repaidAmount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'profit', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'loss', + type: 'uint256', + }, + ], + name: 'repayCreditAccount', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'newController', + type: 'address', + }, + ], + name: 'setController', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'creditManager', + type: 'address', + }, + { + internalType: 'uint256', + name: 'newLimit', + type: 'uint256', + }, + ], + name: 'setCreditManagerDebtLimit', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'newInterestRateModel', + type: 'address', + }, + ], + name: 'setInterestRateModel', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'newPoolQuotaKeeper', + type: 'address', + }, + ], + name: 'setPoolQuotaKeeper', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'newQuotaRevenue', + type: 'uint256', + }, + ], + name: 'setQuotaRevenue', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'newLimit', + type: 'uint256', + }, + ], + name: 'setTotalDebtLimit', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'newWithdrawFee', + type: 'uint256', + }, + ], + name: 'setWithdrawFee', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'supplyRate', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'symbol', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'totalAssets', + outputs: [ + { + internalType: 'uint256', + name: 'assets', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'totalBorrowed', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'totalDebtLimit', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'totalSupply', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'transfer', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'from', + type: 'address', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'transferFrom', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'treasury', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'underlyingToken', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'unpause', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'int256', + name: 'quotaRevenueDelta', + type: 'int256', + }, + ], + name: 'updateQuotaRevenue', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'version', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'assets', + type: 'uint256', + }, + { + internalType: 'address', + name: 'receiver', + type: 'address', + }, + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + ], + name: 'withdraw', + outputs: [ + { + internalType: 'uint256', + name: 'shares', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'withdrawFee', + outputs: [ + { + internalType: 'uint16', + name: '', + type: 'uint16', + }, + ], + stateMutability: 'view', + type: 'function', + }, +] as const; + +export type GearboxLendingTokenV3 = typeof gearboxLendingTokenV3Abi; +export type GearboxLendingTokenV3Contract = GetContractReturnType; + +export class GearboxLendingTokenV3__factory { + static connect(address: string, client: PublicClient) { + return getContract({ address, abi: gearboxLendingTokenV3Abi, publicClient: client }); + } +} diff --git a/src/apps/gearbox/contracts/viem/index.ts b/src/apps/gearbox/contracts/viem/index.ts index e3bcfb741..a5884f3c4 100644 --- a/src/apps/gearbox/contracts/viem/index.ts +++ b/src/apps/gearbox/contracts/viem/index.ts @@ -7,6 +7,7 @@ export type { AirdropDistributor } from './AirdropDistributor'; export type { ContractsRegister } from './ContractsRegister'; export type { CreditManagerV2 } from './CreditManagerV2'; export type { DieselToken } from './DieselToken'; +export type { GearboxLendingTokenV3 } from './GearboxLendingTokenV3'; export type { PhantomToken } from './PhantomToken'; export type { PoolService } from './PoolService'; @@ -15,5 +16,6 @@ export { AirdropDistributor__factory } from './AirdropDistributor'; export { ContractsRegister__factory } from './ContractsRegister'; export { CreditManagerV2__factory } from './CreditManagerV2'; export { DieselToken__factory } from './DieselToken'; +export { GearboxLendingTokenV3__factory } from './GearboxLendingTokenV3'; export { PhantomToken__factory } from './PhantomToken'; export { PoolService__factory } from './PoolService'; diff --git a/src/apps/gearbox/ethereum/gearbox.lending.token-fetcher.ts b/src/apps/gearbox/ethereum/gearbox.lending-v2.token-fetcher.ts similarity index 74% rename from src/apps/gearbox/ethereum/gearbox.lending.token-fetcher.ts rename to src/apps/gearbox/ethereum/gearbox.lending-v2.token-fetcher.ts index cd47a44ba..f7683c983 100644 --- a/src/apps/gearbox/ethereum/gearbox.lending.token-fetcher.ts +++ b/src/apps/gearbox/ethereum/gearbox.lending-v2.token-fetcher.ts @@ -1,5 +1,6 @@ import { Inject } from '@nestjs/common'; import { formatUnits } from 'ethers/lib/utils'; +import { compact } from 'lodash'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; @@ -13,19 +14,16 @@ import { GetPricePerShareParams, GetUnderlyingTokensParams, } from '~position/template/app-token.template.types'; -import { Network } from '~types/network.interface'; import { GearboxViemContractFactory } from '../contracts'; import { DieselToken } from '../contracts/viem'; -const network = Network.ETHEREUM_MAINNET; - interface GearboxLendingDefinition extends DefaultAppTokenDefinition { poolAddress: string; } @PositionTemplate() -export class EthereumGearboxLendingTokenFetcher extends AppTokenTemplatePositionFetcher< +export class EthereumGearboxLendingV2TokenFetcher extends AppTokenTemplatePositionFetcher< DieselToken, DefaultAppTokenDataProps, GearboxLendingDefinition @@ -37,37 +35,43 @@ export class EthereumGearboxLendingTokenFetcher extends AppTokenTemplatePosition super(appToolkit); } - groupLabel = 'Lending'; + groupLabel = 'Lending V2'; - async getAddresses({ multicall }: GetAddressesParams): Promise { - const contractsRegister = this.gearboxContractFactory.contractsRegister({ - address: '0xa50d4e7d8946a7c90652339cdbd262c375d54d99', - network, - }); + getContract(address: string) { + return this.gearboxContractFactory.dieselToken({ address, network: this.network }); + } - return contractsRegister.read.getPools().then(v => [...v]); + async getAddresses({ definitions }: GetAddressesParams) { + return definitions.map(v => v.address); } async getDefinitions({ multicall }: GetDefinitionsParams): Promise { const contractsRegister = this.gearboxContractFactory.contractsRegister({ address: '0xa50d4e7d8946a7c90652339cdbd262c375d54d99', - network, + network: this.network, }); - const poolAddresses = await contractsRegister.read.getPools().then(v => [...v]); - - const dieselTokens = await Promise.all( - poolAddresses.map(poolAddress => { - const contract = this.gearboxContractFactory.poolService({ address: poolAddress, network }); - return multicall.wrap(contract).read.dieselToken(); + const poolAddresses = await multicall + .wrap(contractsRegister) + .read.getPools() + .then(v => [...v]); + + const definitions = await Promise.all( + poolAddresses.map(async poolAddress => { + const contract = this.gearboxContractFactory.poolService({ address: poolAddress, network: this.network }); + try { + const dieselTokenAddressRaw = await multicall.wrap(contract).read.dieselToken(); + return { + address: dieselTokenAddressRaw.toLowerCase(), + poolAddress, + }; + } catch (error) { + return null; + } }), ); - return poolAddresses.map((pool, idx) => ({ address: dieselTokens[idx], poolAddress: pool })); - } - - getContract(address: string) { - return this.gearboxContractFactory.dieselToken({ address, network }); + return compact(definitions); } async getLiquidity({ @@ -75,14 +79,20 @@ export class EthereumGearboxLendingTokenFetcher extends AppTokenTemplatePosition definition, appToken, }: GetDataPropsParams): Promise { - const poolContract = this.gearboxContractFactory.poolService({ address: definition.poolAddress, network }); + const poolContract = this.gearboxContractFactory.poolService({ + address: definition.poolAddress, + network: this.network, + }); const [liquidity, underlyingToken] = await Promise.all([ multicall.wrap(poolContract).read.expectedLiquidity(), multicall.wrap(poolContract).read.underlyingToken(), ]); - const tokenContract = this.appToolkit.globalViemContracts.erc20({ address: underlyingToken, network }); + const tokenContract = this.appToolkit.globalViemContracts.erc20({ + address: underlyingToken, + network: this.network, + }); const underlyingTokenDecimals = await multicall.wrap(tokenContract).read.decimals(); const underlyingBalance = +formatUnits(liquidity, underlyingTokenDecimals); @@ -97,7 +107,10 @@ export class EthereumGearboxLendingTokenFetcher extends AppTokenTemplatePosition definition, multicall, }: GetUnderlyingTokensParams) { - const poolContract = this.gearboxContractFactory.poolService({ address: definition.poolAddress, network }); + const poolContract = this.gearboxContractFactory.poolService({ + address: definition.poolAddress, + network: this.network, + }); const underlyingTokenAddress = await multicall.wrap(poolContract).read.underlyingToken(); return [{ address: underlyingTokenAddress, network: this.network }]; } @@ -107,7 +120,10 @@ export class EthereumGearboxLendingTokenFetcher extends AppTokenTemplatePosition definition, multicall, }: GetPricePerShareParams) { - const poolContract = this.gearboxContractFactory.poolService({ address: definition.poolAddress, network }); + const poolContract = this.gearboxContractFactory.poolService({ + address: definition.poolAddress, + network: this.network, + }); const [underlying, underlyingToken, dieselTokenTotalSupply, dieselTokenDecimals] = await Promise.all([ multicall.wrap(poolContract).read.expectedLiquidity(), @@ -116,7 +132,10 @@ export class EthereumGearboxLendingTokenFetcher extends AppTokenTemplatePosition multicall.wrap(dieselTokenContract).read.decimals(), ]); - const underlyingTokenContract = this.appToolkit.globalViemContracts.erc20({ address: underlyingToken, network }); + const underlyingTokenContract = this.appToolkit.globalViemContracts.erc20({ + address: underlyingToken, + network: this.network, + }); const underlyingTokenDecimals = await underlyingTokenContract.read.decimals(); const pricePerShare = +formatUnits(underlying, underlyingTokenDecimals) / +formatUnits(dieselTokenTotalSupply, dieselTokenDecimals); diff --git a/src/apps/gearbox/ethereum/gearbox.lending-v3.token-fetcher.ts b/src/apps/gearbox/ethereum/gearbox.lending-v3.token-fetcher.ts new file mode 100644 index 000000000..928a45360 --- /dev/null +++ b/src/apps/gearbox/ethereum/gearbox.lending-v3.token-fetcher.ts @@ -0,0 +1,79 @@ +import { Inject } from '@nestjs/common'; +import { BigNumber } from 'ethers'; +import { compact } from 'lodash'; + +import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; +import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher'; +import { + DefaultAppTokenDefinition, + GetAddressesParams, + GetDefinitionsParams, + GetPricePerShareParams, + GetUnderlyingTokensParams, +} from '~position/template/app-token.template.types'; + +import { GearboxViemContractFactory } from '../contracts'; +import { GearboxLendingTokenV3 } from '../contracts/viem'; + +@PositionTemplate() +export class EthereumGearboxLendingV3TokenFetcher extends AppTokenTemplatePositionFetcher { + constructor( + @Inject(APP_TOOLKIT) readonly appToolkit: IAppToolkit, + @Inject(GearboxViemContractFactory) private readonly gearboxContractFactory: GearboxViemContractFactory, + ) { + super(appToolkit); + } + + groupLabel = 'Lending V3'; + + getContract(address: string) { + return this.gearboxContractFactory.gearboxLendingTokenV3({ address, network: this.network }); + } + + async getAddresses({ definitions }: GetAddressesParams) { + return definitions.map(v => v.address); + } + + async getDefinitions({ multicall }: GetDefinitionsParams): Promise { + const contractsRegister = this.gearboxContractFactory.contractsRegister({ + address: '0xa50d4e7d8946a7c90652339cdbd262c375d54d99', + network: this.network, + }); + + const poolAddresses = await multicall + .wrap(contractsRegister) + .read.getPools() + .then(v => [...v]); + + const definitions = await Promise.all( + poolAddresses.map(async poolAddress => { + const contract = this.gearboxContractFactory.gearboxLendingTokenV3({ + address: poolAddress, + network: this.network, + }); + try { + await multicall.wrap(contract).read.asset(); + return { + address: poolAddress, + }; + } catch (error) { + return null; + } + }), + ); + + return compact(definitions); + } + + async getUnderlyingTokenDefinitions({ contract }: GetUnderlyingTokensParams) { + return [{ address: await contract.read.asset(), network: this.network }]; + } + + async getPricePerShare({ appToken, contract }: GetPricePerShareParams) { + const amount = BigNumber.from((1e18).toString()).toString(); + const ratioRaw = await contract.read.convertToAssets([BigInt(amount)]); + const ratio = Number(ratioRaw) / 10 ** appToken.decimals; + return [ratio]; + } +} diff --git a/src/apps/gearbox/gearbox.module.ts b/src/apps/gearbox/gearbox.module.ts index c1114077a..331126264 100644 --- a/src/apps/gearbox/gearbox.module.ts +++ b/src/apps/gearbox/gearbox.module.ts @@ -4,19 +4,21 @@ import { AbstractApp } from '~app/app.dynamic-module'; import { GearboxViemContractFactory } from './contracts'; import { EthereumGearboxCreditAccountsContractPositionFetcher } from './ethereum/gearbox.credit-accounts.contract-position-fetcher'; -import { EthereumGearboxLendingTokenFetcher } from './ethereum/gearbox.lending.token-fetcher'; +import { EthereumGearboxLendingV2TokenFetcher } from './ethereum/gearbox.lending-v2.token-fetcher'; +import { EthereumGearboxLendingV3TokenFetcher } from './ethereum/gearbox.lending-v3.token-fetcher'; import { EthereumGearboxPhantomTokenFetcher } from './ethereum/gearbox.phantom.token-fetcher'; import { EthereumGearboxRewardsPositionFetcher } from './ethereum/gearbox.rewards.contract-position-fetcher'; import { EthereumGearboxRewardsMerkleCache } from './ethereum/gearbox.rewards.merkle-cache'; @Module({ providers: [ + GearboxViemContractFactory, + EthereumGearboxRewardsMerkleCache, EthereumGearboxCreditAccountsContractPositionFetcher, - EthereumGearboxLendingTokenFetcher, + EthereumGearboxLendingV2TokenFetcher, + EthereumGearboxLendingV3TokenFetcher, EthereumGearboxPhantomTokenFetcher, EthereumGearboxRewardsPositionFetcher, - GearboxViemContractFactory, - EthereumGearboxRewardsMerkleCache, ], }) export class GearboxAppModule extends AbstractApp() {}