From 6a1eff9219833203839d2295ae61e66db5c7212a Mon Sep 17 00:00:00 2001 From: Damian Paszkowski Date: Wed, 23 Nov 2022 12:26:21 +0100 Subject: [PATCH 1/4] add missing oracles (#173) (#174) --- src/addresses/mainnet.json | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/addresses/mainnet.json b/src/addresses/mainnet.json index 17a179b..5446e3e 100644 --- a/src/addresses/mainnet.json +++ b/src/addresses/mainnet.json @@ -253,5 +253,15 @@ "PIP_RETH": "0xee7f0b350aa119b3d05dc733a4621a81972f7d47", "MCD_CLIP_RETH_A": "0x27ca5e525ea473ed52ea9423cd08ccc081d96a98", "MCD_CLIP_CALC_RETH_A": "0xc59b62afc96cf9737f717b5e5815070c0f154396", - "MCD_JOIN_RETH_A": "0xc6424e862f1462281b0a5fac078e4b63006bdebf" + "MCD_JOIN_RETH_A": "0xc6424e862f1462281b0a5fac078e4b63006bdebf", + "WSTETH": "0xd3d2E2692501A5c9Ca623199D38826e513033a17", + "PIP_WSTETH": "0xFe7a2aC0B945f12089aEEB6eCebf4F384D9f043F", + "MCD_JOIN_WSTETH_A": "0x10CD5fbe1b404B7E19Ef964B63939907bdaf42E2", + "MCD_CLIP_WSTETH_A": "0x49A33A28C4C7D9576ab28898F4C9ac7e52EA457A", + "MCD_CLIP_CALC_WSTETH_A": "0x15282b886675cc1Ce04590148f456428E87eaf13", + "CRVV1ETHSTETH": "0x06325440D014e39736583c165C2963BA99fAf14E", + "PIP_CRVV1ETHSTETH": "0xEa508F82728927454bd3ce853171b0e2705880D4", + "MCD_JOIN_CRVV1ETHSTETH_A": "0x82D8bfDB61404C796385f251654F6d7e92092b5D", + "MCD_CLIP_CRVV1ETHSTETH_A": "0x1926862F899410BfC19FeFb8A3C69C7Aed22463a", + "MCD_CLIP_CALC_CRVV1ETHSTETH_A": "0x8a4780acABadcae1a297b2eAe5DeEbd7d50DEeB8" } From 2e8321886a34b64ac7a614b47457894b6dfd1907 Mon Sep 17 00:00:00 2001 From: Damian Paszkowski Date: Wed, 1 Mar 2023 17:12:04 +0100 Subject: [PATCH 2/4] [SC-8246] Copy of aave to aave_v3 (#190) Co-authored-by: Jakub Swierczek Co-authored-by: James Tuckett --- abis/aave-v3-pool.json | 1715 ++++++++++++++++++ src/borrow/migrations/049-aave-v3-schema.sql | 62 + src/borrow/transformers/aavev3Transformer.ts | 91 + src/config.goerli.ts | 10 + src/config.mainnet.ts | 10 + 5 files changed, 1888 insertions(+) create mode 100644 abis/aave-v3-pool.json create mode 100644 src/borrow/migrations/049-aave-v3-schema.sql create mode 100644 src/borrow/transformers/aavev3Transformer.ts diff --git a/abis/aave-v3-pool.json b/abis/aave-v3-pool.json new file mode 100644 index 0000000..a2a068e --- /dev/null +++ b/abis/aave-v3-pool.json @@ -0,0 +1,1715 @@ +[ + { + "inputs": [ + { + "internalType": "contract IPoolAddressesProvider", + "name": "provider", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "reserve", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "backer", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "fee", + "type": "uint256" + } + ], + "name": "BackUnbacked", + "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": false, + "internalType": "enum DataTypes.InterestRateMode", + "name": "interestRateMode", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "borrowRate", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "uint16", + "name": "referralCode", + "type": "uint16" + } + ], + "name": "Borrow", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "target", + "type": "address" + }, + { + "indexed": false, + "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": "enum DataTypes.InterestRateMode", + "name": "interestRateMode", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "premium", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "uint16", + "name": "referralCode", + "type": "uint16" + } + ], + "name": "FlashLoan", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "asset", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "totalDebt", + "type": "uint256" + } + ], + "name": "IsolationModeTotalDebtUpdated", + "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": [ + { + "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": "referralCode", + "type": "uint16" + } + ], + "name": "MintUnbacked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "reserve", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountMinted", + "type": "uint256" + } + ], + "name": "MintedToTreasury", + "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" + }, + { + "indexed": false, + "internalType": "bool", + "name": "useATokens", + "type": "bool" + } + ], + "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": 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": "referralCode", + "type": "uint16" + } + ], + "name": "Supply", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "reserve", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "indexed": false, + "internalType": "enum DataTypes.InterestRateMode", + "name": "interestRateMode", + "type": "uint8" + } + ], + "name": "SwapBorrowRateMode", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "categoryId", + "type": "uint8" + } + ], + "name": "UserEModeSet", + "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": "ADDRESSES_PROVIDER", + "outputs": [ + { + "internalType": "contract IPoolAddressesProvider", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "BRIDGE_PROTOCOL_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "FLASHLOAN_PREMIUM_TOTAL", + "outputs": [ + { + "internalType": "uint128", + "name": "", + "type": "uint128" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "FLASHLOAN_PREMIUM_TO_PROTOCOL", + "outputs": [ + { + "internalType": "uint128", + "name": "", + "type": "uint128" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_NUMBER_RESERVES", + "outputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_STABLE_RATE_BORROW_SIZE_PERCENT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "POOL_REVISION", + "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": "fee", + "type": "uint256" + } + ], + "name": "backUnbacked", + "outputs": [], + "stateMutability": "nonpayable", + "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": "uint8", + "name": "id", + "type": "uint8" + }, + { + "components": [ + { + "internalType": "uint16", + "name": "ltv", + "type": "uint16" + }, + { + "internalType": "uint16", + "name": "liquidationThreshold", + "type": "uint16" + }, + { + "internalType": "uint16", + "name": "liquidationBonus", + "type": "uint16" + }, + { + "internalType": "address", + "name": "priceSource", + "type": "address" + }, + { + "internalType": "string", + "name": "label", + "type": "string" + } + ], + "internalType": "struct DataTypes.EModeCategory", + "name": "category", + "type": "tuple" + } + ], + "name": "configureEModeCategory", + "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" + } + ], + "name": "dropReserve", + "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": "interestRateModes", + "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": [ + { + "internalType": "address", + "name": "receiverAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "asset", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "params", + "type": "bytes" + }, + { + "internalType": "uint16", + "name": "referralCode", + "type": "uint16" + } + ], + "name": "flashLoanSimple", + "outputs": [], + "stateMutability": "nonpayable", + "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": "uint8", + "name": "id", + "type": "uint8" + } + ], + "name": "getEModeCategoryData", + "outputs": [ + { + "components": [ + { + "internalType": "uint16", + "name": "ltv", + "type": "uint16" + }, + { + "internalType": "uint16", + "name": "liquidationThreshold", + "type": "uint16" + }, + { + "internalType": "uint16", + "name": "liquidationBonus", + "type": "uint16" + }, + { + "internalType": "address", + "name": "priceSource", + "type": "address" + }, + { + "internalType": "string", + "name": "label", + "type": "string" + } + ], + "internalType": "struct DataTypes.EModeCategory", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "id", + "type": "uint16" + } + ], + "name": "getReserveAddressById", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "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": "currentLiquidityRate", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "variableBorrowIndex", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "currentVariableBorrowRate", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "currentStableBorrowRate", + "type": "uint128" + }, + { + "internalType": "uint40", + "name": "lastUpdateTimestamp", + "type": "uint40" + }, + { + "internalType": "uint16", + "name": "id", + "type": "uint16" + }, + { + "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": "uint128", + "name": "accruedToTreasury", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "unbacked", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "isolationModeTotalDebt", + "type": "uint128" + } + ], + "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": "totalCollateralBase", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalDebtBase", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "availableBorrowsBase", + "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": "user", + "type": "address" + } + ], + "name": "getUserEMode", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "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 IPoolAddressesProvider", + "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": [ + { + "internalType": "address[]", + "name": "assets", + "type": "address[]" + } + ], + "name": "mintToTreasury", + "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": "mintUnbacked", + "outputs": [], + "stateMutability": "nonpayable", + "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": "interestRateMode", + "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": "amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "interestRateMode", + "type": "uint256" + } + ], + "name": "repayWithATokens", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "asset", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "interestRateMode", + "type": "uint256" + }, + { + "internalType": "address", + "name": "onBehalfOf", + "type": "address" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + }, + { + "internalType": "uint8", + "name": "permitV", + "type": "uint8" + }, + { + "internalType": "bytes32", + "name": "permitR", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "permitS", + "type": "bytes32" + } + ], + "name": "repayWithPermit", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "rescueTokens", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "asset", + "type": "address" + } + ], + "name": "resetIsolationModeTotalDebt", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "asset", + "type": "address" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "data", + "type": "uint256" + } + ], + "internalType": "struct DataTypes.ReserveConfigurationMap", + "name": "configuration", + "type": "tuple" + } + ], + "name": "setConfiguration", + "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": "uint8", + "name": "categoryId", + "type": "uint8" + } + ], + "name": "setUserEMode", + "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": "amount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "onBehalfOf", + "type": "address" + }, + { + "internalType": "uint16", + "name": "referralCode", + "type": "uint16" + } + ], + "name": "supply", + "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" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + }, + { + "internalType": "uint8", + "name": "permitV", + "type": "uint8" + }, + { + "internalType": "bytes32", + "name": "permitR", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "permitS", + "type": "bytes32" + } + ], + "name": "supplyWithPermit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "asset", + "type": "address" + }, + { + "internalType": "uint256", + "name": "interestRateMode", + "type": "uint256" + } + ], + "name": "swapBorrowRateMode", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "protocolFee", + "type": "uint256" + } + ], + "name": "updateBridgeProtocolFee", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "flashLoanPremiumTotal", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "flashLoanPremiumToProtocol", + "type": "uint128" + } + ], + "name": "updateFlashloanPremiums", + "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" + } +] diff --git a/src/borrow/migrations/049-aave-v3-schema.sql b/src/borrow/migrations/049-aave-v3-schema.sql new file mode 100644 index 0000000..8e59452 --- /dev/null +++ b/src/borrow/migrations/049-aave-v3-schema.sql @@ -0,0 +1,62 @@ +CREATE SCHEMA aave_v3; + +create sequence aave_v3.reserve_data_updated_id_seq + as integer; + + +create table aave_v3.reserve_data_updated +( + id serial primary key, + liquidity_rate numeric(78) not null, + stable_borrow_rate numeric(78) not null, + variable_borrow_rate numeric(78) not null, + liquidity_index numeric(78) not null, + variable_borrow_index numeric(78) not null, + log_index integer not null, + tx_id integer not null references vulcan2x.transaction + on delete cascade, + block_id integer not null references vulcan2x.block + on delete cascade, + reserve varchar(50), + unique (tx_id, log_index) +); + + +create materialized view aave_v3.reserve_data_daily_averages as +SELECT avg(rdu.variable_borrow_rate) AS variable_borrow_rate, + rdu.reserve, + date_trunc('day'::text, timezone('utc'::text, b."timestamp")) AS date +FROM aave_v3.reserve_data_updated rdu + JOIN vulcan2x.block b ON rdu.block_id = b.id +GROUP BY rdu.reserve, (date_trunc('day'::text, timezone('utc'::text, b."timestamp"))); + +create index reserve_data_daily_averages_reserve_idx_v3 + on aave_v3.reserve_data_daily_averages (reserve); + +create index reserve_data_daily_averages_date_idx_v3 + on aave_v3.reserve_data_daily_averages (date); + + +create function api.aave_v3_yield_rate(start_date date, end_date date, multiple numeric, + reserve_address text) returns api.yield + language plpgsql +as +$$ +declare + result api.yield; +begin + select avg( + (lpts.post_total_pooled_ether - lpts.pre_total_pooled_ether) * 365 * 24 * 60 * 60 / + (lpts.pre_total_pooled_ether * lpts.time_elapsed) * 100 * 0.9 + * multiple - br.variable_borrow_rate * 100 / 1e27 * (multiple - 1)) as net_annualised_yield + from lido.post_total_shares lpts + join vulcan2x.block b on lpts.block_id = b.id + join aave_v3.reserve_data_daily_averages br + on br.date = date_trunc('day', b.timestamp at time zone 'utc') and br.reserve = reserve_address + where br.date >= start_date + and br.date <= end_date + into result; + -- details here: https://www.notion.so/oazo/Yield-calculation-for-stETH-ETH-1b70d660039a4587ae781410dbc4c5fb + return result; +end; +$$; diff --git a/src/borrow/transformers/aavev3Transformer.ts b/src/borrow/transformers/aavev3Transformer.ts new file mode 100644 index 0000000..7716b64 --- /dev/null +++ b/src/borrow/transformers/aavev3Transformer.ts @@ -0,0 +1,91 @@ +import { flatten, max, min } from 'lodash'; +import { Dictionary } from 'ts-essentials'; + +import { handleEvents, FullEventInfo } from '@oasisdex/spock-utils/dist/transformers/common'; +import { + getExtractorName, + PersistedLog, + SimpleProcessorDefinition, +} from '@oasisdex/spock-utils/dist/extractors/rawEventDataExtractor'; +import { BlockTransformer } from '@oasisdex/spock-etl/dist/processors/types'; +import { LocalServices } from '@oasisdex/spock-etl/dist/services/types'; +import { normalizeAddressDefinition } from '../../utils'; + +const aavePool = require('../../../abis/aave-v3-pool.json'); + +async function handleReserveDataUpdated( + params: Dictionary, + log: PersistedLog, + services: LocalServices, + isRebuilding: boolean, +): Promise { + const values = { + reserve: params.reserve.toString().toLowerCase(), + liquidityRate: params.liquidityRate.toString(), + stableBorrowRate: params.stableBorrowRate.toString(), + variableBorrowRate: params.variableBorrowRate.toString(), + liquidityIndex: params.liquidityIndex.toString(), + variableBorrowIndex: params.variableBorrowIndex.toString(), + + log_index: log.log_index, + tx_id: log.tx_id, + block_id: log.block_id, + }; + + const returned: { id: number } = await services.tx.one( + `INSERT INTO aave_v3.reserve_data_updated(liquidity_rate, stable_borrow_rate, variable_borrow_rate, + liquidity_index, variable_borrow_index, + log_index, tx_id, block_id, reserve) + VALUES (\${liquidityRate}, \${stableBorrowRate}, \${variableBorrowRate}, \${liquidityIndex}, + \${variableBorrowIndex}, + \${log_index}, \${tx_id}, \${block_id}, \${reserve}) returning id;`, + values, + ); + + const shouldRefresh = !isRebuilding && returned.id % 10 === 0; // refresh view takes around 12 seconds, so don't refresh when rebuilding from scratch // refresh every approx. 6 minutes + + if (shouldRefresh) { + await services.tx.none(`refresh materialized view aave_v3.reserve_data_daily_averages;`); + } +} + +const landingPoolHandlers = (isRebuilding: boolean) => ({ + async ReserveDataUpdated(services: LocalServices, { event, log }: FullEventInfo): Promise { + await handleReserveDataUpdated(event.params, log, services, isRebuilding); + }, +}); + +export const getAavev3LendingPoolTransformerName = (address: string) => + `aavev3-lending-pool-transformer-${address}`; +export const aavev3LendingPoolTransformer: ( + addresses: (string | SimpleProcessorDefinition)[], +) => BlockTransformer[] = addresses => { + return addresses.map(_deps => { + const deps = normalizeAddressDefinition(_deps); + + return { + name: getAavev3LendingPoolTransformerName(deps.address), + dependencies: [getExtractorName(deps.address)], + startingBlock: deps.startingBlock, + transform: async (services, _logs) => { + const logs = flatten(_logs); + if (logs.length === 0) { + return; + } + + const blocks = Array.from(new Set(logs.map(log => log.block_id))); + const minBlock: number = min(blocks); + const maxBlock: number = max(blocks); + + const isRebuilding = minBlock !== maxBlock; + + await handleEvents( + services, + aavePool, + flatten(_logs), + landingPoolHandlers(isRebuilding), + ); + }, + }; + }); +}; diff --git a/src/config.goerli.ts b/src/config.goerli.ts index 94d5fe3..3ee00a8 100644 --- a/src/config.goerli.ts +++ b/src/config.goerli.ts @@ -65,6 +65,7 @@ import { automationEventEnhancerTransformerEthPriceV1, automationEventEnhancerTransformerEthPriceV2, } from './borrow/transformers/automationEventEnhancer'; +import { aavev3LendingPoolTransformer } from './borrow/transformers/aavev3Transformer'; const AutomationBotABI = require('../abis/automation-bot.json'); @@ -298,6 +299,13 @@ const aaveLendingPool = [ }, ]; +const aavev3Pool = [ + { + address: '0x7b5C526B7F8dfdff278b4a3e045083FBA4028790', + startingBlock: 8300001 + } +]; + const lido = [ { address: '0x24d8451bc07e7af4ba94f69acdd9ad3c6579d9fb', @@ -319,6 +327,7 @@ export const config: UserProvidedSpockConfig = { ...makeRawLogExtractors(multiply), ...makeRawLogExtractors(exchange), ...makeRawLogExtractors(aaveLendingPool), + ...makeRawLogExtractors(aavev3Pool), ...makeRawLogExtractors(lido), ...makeRawEventBasedOnTopicExtractor(flipper), ...makeRawEventBasedOnDSNoteTopic(flipperNotes), @@ -374,6 +383,7 @@ export const config: UserProvidedSpockConfig = { automationEventEnhancerTransformerEthPriceV2(automationBotV2, oraclesTransformers), ...redeemerTransformer(redeemer), ...aaveLendingPoolTransformer(aaveLendingPool), + ...aavev3LendingPoolTransformer(aavev3Pool), ...lidoTransformer(lido), ], migrations: { diff --git a/src/config.mainnet.ts b/src/config.mainnet.ts index 0e30204..7ba9c82 100644 --- a/src/config.mainnet.ts +++ b/src/config.mainnet.ts @@ -61,6 +61,7 @@ import { automationEventEnhancerTransformerEthPriceV1, automationEventEnhancerTransformerEthPriceV2, } from './borrow/transformers/automationEventEnhancer'; +import { aavev3LendingPoolTransformer } from './borrow/transformers/aavev3Transformer'; const mainnetAddresses = require('./addresses/mainnet.json'); @@ -282,6 +283,13 @@ const aaveLendingPool = [ }, ]; +const aavev3Pool = [ + { + address: '0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2', + startingBlock: 16291127 + } +]; + export const config: UserProvidedSpockConfig = { startingBlock: GENESIS, extractors: [ @@ -291,6 +299,7 @@ export const config: UserProvidedSpockConfig = { ...makeRawLogExtractors(redeemer), ...makeRawLogExtractors(lido), ...makeRawLogExtractors(aaveLendingPool), + ...makeRawLogExtractors(aavev3Pool), ...makeRawLogExtractors([vat]), ...makeRawLogExtractors([automationBot]), ...makeRawLogExtractors([automationBotV2]), @@ -354,6 +363,7 @@ export const config: UserProvidedSpockConfig = { ...redeemerTransformer(redeemer), ...lidoTransformer(lido), ...aaveLendingPoolTransformer(aaveLendingPool), + ...aavev3LendingPoolTransformer(aavev3Pool), ], migrations: { borrow: join(__dirname, './borrow/migrations'), From fd83d239100624351fa0a336cd8ac0fa8eaff8bb Mon Sep 17 00:00:00 2001 From: Halaprix Date: Wed, 29 Mar 2023 15:35:19 +0200 Subject: [PATCH 3/4] FEAT - add CRVV1 (#196) --- src/borrow/transformers/oraclesTransformer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/borrow/transformers/oraclesTransformer.ts b/src/borrow/transformers/oraclesTransformer.ts index 1db38c9..1f0b8a0 100644 --- a/src/borrow/transformers/oraclesTransformer.ts +++ b/src/borrow/transformers/oraclesTransformer.ts @@ -34,7 +34,7 @@ interface Price { } function isLPToken(token: string): boolean { - return token.startsWith('UNIV2') || token.startsWith('GUNIV3'); + return token.startsWith('UNIV2') || token.startsWith('GUNIV3') || token.startsWith('CRVV1'); } function storageHexToBigNumber(uint256: string) { From 3bfe6df781923fa956026a64f44abe02c63fe531 Mon Sep 17 00:00:00 2001 From: Halaprix Date: Wed, 2 Aug 2023 15:19:43 +0200 Subject: [PATCH 4/4] chore: release 20230802 (#219) * adding new GH Actions workflows * setting final GHA triggers * removing old GH Actions workflows * chore: updates after aave v3 sl fix (#218) --------- Co-authored-by: cristidas --- .github/workflows/aws-prod.yml | 8 ++++---- .github/workflows/aws-staging.yml | 12 ++++++------ package.json | 2 +- src/config.mainnet.ts | 4 ++++ yarn.lock | 8 ++++---- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.github/workflows/aws-prod.yml b/.github/workflows/aws-prod.yml index d5adc58..c2fa43f 100644 --- a/.github/workflows/aws-prod.yml +++ b/.github/workflows/aws-prod.yml @@ -11,10 +11,10 @@ jobs: runs-on: ubuntu-latest env: AWS_REGION: us-east-1 - ECR_REPO_NAME: oazo-bcache-prod - ETL_SERVICE_NAME: oazo-bcache-etl-mainnet-prod - API_SERVICE_NAME: oazo-bcache-api-mainnet-prod - CLUSTER_NAME: oazo-bcache-prod + ECR_REPO_NAME: cache-prod + ETL_SERVICE_NAME: cache-etl-mainnet-prod + API_SERVICE_NAME: cache-api-mainnet-prod + CLUSTER_NAME: cache-prod steps: - name: Checkout diff --git a/.github/workflows/aws-staging.yml b/.github/workflows/aws-staging.yml index 0b0108e..73132e9 100644 --- a/.github/workflows/aws-staging.yml +++ b/.github/workflows/aws-staging.yml @@ -11,12 +11,12 @@ jobs: runs-on: ubuntu-latest env: AWS_REGION: eu-central-1 - ECR_REPO_NAME: oazo-bcache-staging - GOERLI_ETL_SERVICE_NAME: oazo-bcache-etl-goerli-staging - GOERLI_API_SERVICE_NAME: oazo-bcache-api-goerli-staging - MAINNET_ETL_SERVICE_NAME: oazo-bcache-etl-mainnet-staging - MAINNET_API_SERVICE_NAME: oazo-bcache-api-mainnet-staging - CLUSTER_NAME: oazo-bcache-staging + ECR_REPO_NAME: cache-staging + GOERLI_ETL_SERVICE_NAME: cache-etl-goerli-staging + GOERLI_API_SERVICE_NAME: cache-api-goerli-staging + MAINNET_ETL_SERVICE_NAME: cache-etl-mainnet-staging + MAINNET_API_SERVICE_NAME: cache-api-mainnet-staging + CLUSTER_NAME: cache-staging steps: - name: Checkout diff --git a/package.json b/package.json index 3b40cc1..b4aa2b3 100644 --- a/package.json +++ b/package.json @@ -41,12 +41,12 @@ }, "dependencies": { "@google-cloud/bigquery": "^3.0.0", + "@oasisdex/automation": "^1.5.0", "@oasisdex/spock-etl": "^0.1.5", "@oasisdex/spock-graphql-api": "^0.1.2", "@oasisdex/spock-test-utils": "^0.1.1", "@oasisdex/spock-utils": "^0.1.0", "@oasisdex/spock-validation": "^0.1.0", - "@oasisdex/automation": "1.5.0-alpha.8", "abi-decoder": "^1.2.0", "aws-sdk": "^2.1232.0", "bignumber.js": "^8.0.2", diff --git a/src/config.mainnet.ts b/src/config.mainnet.ts index 4ba48a4..da49365 100644 --- a/src/config.mainnet.ts +++ b/src/config.mainnet.ts @@ -200,6 +200,10 @@ const commandMapping = [ command_address: '0x65127d52aaeb356b45c6dcb3da36f4fc6ff738ef', kind: 'aave-stop-loss', }, + { + command_address: '0x52a9bc9a904b9ee6a4714ef883ccf14cb7283b0f', + kind: 'aave-stop-loss', + }, ].map(({ command_address, kind }) => ({ command_address: command_address.toLowerCase(), kind })); const addresses = { diff --git a/yarn.lock b/yarn.lock index 25cf82a..d7d1b1b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -455,10 +455,10 @@ "@types/yargs" "^15.0.0" chalk "^4.0.0" -"@oasisdex/automation@1.5.0-alpha.8": - version "1.5.0-alpha.8" - resolved "https://registry.yarnpkg.com/@oasisdex/automation/-/automation-1.5.0-alpha.8.tgz#0660f0bb27cfbfcd18f1d5e959a84855059690c6" - integrity sha512-Q9aHj65/L9yl9c+roctxPsn1SI5g8zFMRwdibgwzsqOOSe6PdBHIxhbXtsfreygLhI8+qd8SWdZd7nx4CISpvg== +"@oasisdex/automation@^1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@oasisdex/automation/-/automation-1.5.0.tgz#b5201f039921f79aee4efe22b77fa460296aec58" + integrity sha512-fqhWTtJwzyLYLgE4y0hCi4W5CwPtQp/+8Vzfdv0fOT86KUBgpvwAvI9Qs4WI0ahCZiGozJE/q+eixSo8/WPN/Q== dependencies: ethers "^5.6.2"