From 618dd56d8ac33cdf9ea3f2e9b3e37c73b97ba273 Mon Sep 17 00:00:00 2001 From: toniocodo Date: Tue, 9 Jul 2024 08:39:29 +0200 Subject: [PATCH 01/11] feat: add soeth withdrawal processor --- abi/oeth-vault.json | 1648 +++++++++++++++++ ...41703954-Data.js => 1720507056186-Data.js} | 10 +- schema.graphql | 17 +- schema/oeth.graphql | 16 +- src/abi/oeth-vault.ts | 522 ++++++ src/main-oeth.ts | 8 +- src/model/generated/index.ts | 1 + .../generated/oethWithdrawalRequest.model.ts | 34 + src/oeth/processors/withdrawals.ts | 74 + 9 files changed, 2317 insertions(+), 13 deletions(-) create mode 100644 abi/oeth-vault.json rename db/migrations/{1719941703954-Data.js => 1720507056186-Data.js} (98%) create mode 100644 src/abi/oeth-vault.ts create mode 100644 src/model/generated/oethWithdrawalRequest.model.ts create mode 100644 src/oeth/processors/withdrawals.ts diff --git a/abi/oeth-vault.json b/abi/oeth-vault.json new file mode 100644 index 00000000..3d8da5fb --- /dev/null +++ b/abi/oeth-vault.json @@ -0,0 +1,1648 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "_threshold", + "type": "uint256" + } + ], + "name": "AllocateThresholdUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_asset", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "_strategy", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "AssetAllocated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_asset", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "_strategy", + "type": "address" + } + ], + "name": "AssetDefaultStrategyUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_asset", + "type": "address" + } + ], + "name": "AssetSupported", + "type": "event" + }, + { + "anonymous": false, + "inputs": [], + "name": "CapitalPaused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [], + "name": "CapitalUnpaused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "_dripper", + "type": "address" + } + ], + "name": "DripperChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "maxSupplyDiff", + "type": "uint256" + } + ], + "name": "MaxSupplyDiffChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_addr", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_value", + "type": "uint256" + } + ], + "name": "Mint", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_priceProvider", + "type": "address" + } + ], + "name": "PriceProviderUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [], + "name": "RebasePaused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "_threshold", + "type": "uint256" + } + ], + "name": "RebaseThresholdUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [], + "name": "RebaseUnpaused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_addr", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_value", + "type": "uint256" + } + ], + "name": "Redeem", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "_redeemFeeBps", + "type": "uint256" + } + ], + "name": "RedeemFeeUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_address", + "type": "address" + } + ], + "name": "StrategistUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_addr", + "type": "address" + } + ], + "name": "StrategyApproved", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_addr", + "type": "address" + } + ], + "name": "StrategyRemoved", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "_basis", + "type": "uint256" + } + ], + "name": "SwapAllowedUndervalueChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_asset", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_basis", + "type": "uint256" + } + ], + "name": "SwapSlippageChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "_fromAsset", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "_toAsset", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_fromAssetAmount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_toAssetAmount", + "type": "uint256" + } + ], + "name": "Swapped", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_address", + "type": "address" + } + ], + "name": "SwapperChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_address", + "type": "address" + } + ], + "name": "TrusteeAddressChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "_basis", + "type": "uint256" + } + ], + "name": "TrusteeFeeBpsChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "_vaultBuffer", + "type": "uint256" + } + ], + "name": "VaultBufferUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "_claimable", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_newClaimable", + "type": "uint256" + } + ], + "name": "WithdrawalClaimable", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "_withdrawer", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "_requestId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "WithdrawalClaimed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "_withdrawer", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "_requestId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_queued", + "type": "uint256" + } + ], + "name": "WithdrawalRequested", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "_to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_yield", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_fee", + "type": "uint256" + } + ], + "name": "YieldDistribution", + "type": "event" + }, + { + "inputs": [], + "name": "addWithdrawalQueueLiquidity", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "allocate", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "allowedSwapUndervalue", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_addr", + "type": "address" + } + ], + "name": "approveStrategy", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_asset", + "type": "address" + } + ], + "name": "assetDefaultStrategies", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "autoAllocateThreshold", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "burnForStrategy", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "cacheWETHAssetIndex", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "calculateRedeemOutputs", + "outputs": [ + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "capitalPaused", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_asset", + "type": "address" + } + ], + "name": "checkBalance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "claimGovernance", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "requestId", + "type": "uint256" + } + ], + "name": "claimWithdrawal", + "outputs": [ + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256[]", + "name": "requestIds", + "type": "uint256[]" + } + ], + "name": "claimWithdrawals", + "outputs": [ + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + }, + { + "internalType": "uint256", + "name": "totalAmount", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_strategyToAddress", + "type": "address" + }, + { + "internalType": "address[]", + "name": "_assets", + "type": "address[]" + }, + { + "internalType": "uint256[]", + "name": "_amounts", + "type": "uint256[]" + } + ], + "name": "depositToStrategy", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "getAllAssets", + "outputs": [ + { + "internalType": "address[]", + "name": "", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getAllStrategies", + "outputs": [ + { + "internalType": "address[]", + "name": "", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_asset", + "type": "address" + } + ], + "name": "getAssetConfig", + "outputs": [ + { + "components": [ + { + "internalType": "bool", + "name": "isSupported", + "type": "bool" + }, + { + "internalType": "enum VaultStorage.UnitConversion", + "name": "unitConversion", + "type": "uint8" + }, + { + "internalType": "uint8", + "name": "decimals", + "type": "uint8" + }, + { + "internalType": "uint16", + "name": "allowedOracleSlippageBps", + "type": "uint16" + } + ], + "internalType": "struct VaultStorage.Asset", + "name": "config", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getAssetCount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getStrategyCount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "governor", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_asset", + "type": "address" + } + ], + "name": "isSupportedAsset", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "maxSupplyDiff", + "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": "_minimumOusdAmount", + "type": "uint256" + } + ], + "name": "mint", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "mintForStrategy", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "netOusdMintForStrategyThreshold", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "netOusdMintedForStrategy", + "outputs": [ + { + "internalType": "int256", + "name": "", + "type": "int256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ousdMetaStrategy", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "pauseCapital", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "pauseRebase", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "priceProvider", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "asset", + "type": "address" + } + ], + "name": "priceUnitMint", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "asset", + "type": "address" + } + ], + "name": "priceUnitRedeem", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "rebase", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "rebasePaused", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "rebaseThreshold", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_minimumUnitAmount", + "type": "uint256" + } + ], + "name": "redeem", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_minimumUnitAmount", + "type": "uint256" + } + ], + "name": "redeemAll", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "redeemFeeBps", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_asset", + "type": "address" + } + ], + "name": "removeAsset", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_addr", + "type": "address" + } + ], + "name": "removeStrategy", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "requestWithdrawal", + "outputs": [ + { + "internalType": "uint256", + "name": "requestId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "queued", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "setAdminImpl", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_asset", + "type": "address" + }, + { + "internalType": "address", + "name": "_strategy", + "type": "address" + } + ], + "name": "setAssetDefaultStrategy", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_threshold", + "type": "uint256" + } + ], + "name": "setAutoAllocateThreshold", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_dripper", + "type": "address" + } + ], + "name": "setDripper", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_maxSupplyDiff", + "type": "uint256" + } + ], + "name": "setMaxSupplyDiff", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_threshold", + "type": "uint256" + } + ], + "name": "setNetOusdMintForStrategyThreshold", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_asset", + "type": "address" + }, + { + "internalType": "uint16", + "name": "_allowedOracleSlippageBps", + "type": "uint16" + } + ], + "name": "setOracleSlippage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_ousdMetaStrategy", + "type": "address" + } + ], + "name": "setOusdMetaStrategy", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_priceProvider", + "type": "address" + } + ], + "name": "setPriceProvider", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_threshold", + "type": "uint256" + } + ], + "name": "setRebaseThreshold", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_redeemFeeBps", + "type": "uint256" + } + ], + "name": "setRedeemFeeBps", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_address", + "type": "address" + } + ], + "name": "setStrategistAddr", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "_percentageBps", + "type": "uint16" + } + ], + "name": "setSwapAllowedUndervalue", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_swapperAddr", + "type": "address" + } + ], + "name": "setSwapper", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_address", + "type": "address" + } + ], + "name": "setTrusteeAddress", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_basis", + "type": "uint256" + } + ], + "name": "setTrusteeFeeBps", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_vaultBuffer", + "type": "uint256" + } + ], + "name": "setVaultBuffer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "strategistAddr", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_asset", + "type": "address" + }, + { + "internalType": "uint8", + "name": "_supportsAsset", + "type": "uint8" + } + ], + "name": "supportAsset", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "fromAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "toAsset", + "type": "address" + }, + { + "internalType": "uint256", + "name": "fromAssetAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minToAssetAmount", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "swapCollateral", + "outputs": [ + { + "internalType": "uint256", + "name": "toAssetAmount", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "swapper", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalValue", + "outputs": [ + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_newGovernor", + "type": "address" + } + ], + "name": "transferGovernance", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_asset", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "transferToken", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "trusteeAddress", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "trusteeFeeBps", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "unpauseCapital", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "unpauseRebase", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "vaultBuffer", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "weth", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "wethAssetIndex", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "withdrawAllFromStrategies", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_strategyAddr", + "type": "address" + } + ], + "name": "withdrawAllFromStrategy", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_strategyFromAddress", + "type": "address" + }, + { + "internalType": "address[]", + "name": "_assets", + "type": "address[]" + }, + { + "internalType": "uint256[]", + "name": "_amounts", + "type": "uint256[]" + } + ], + "name": "withdrawFromStrategy", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "withdrawalQueueMetadata", + "outputs": [ + { + "components": [ + { + "internalType": "uint128", + "name": "queued", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "claimable", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "claimed", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "nextWithdrawalIndex", + "type": "uint128" + } + ], + "internalType": "struct VaultStorage.WithdrawalQueueMetadata", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "requestId", + "type": "uint256" + } + ], + "name": "withdrawalRequests", + "outputs": [ + { + "components": [ + { + "internalType": "address", + "name": "withdrawer", + "type": "address" + }, + { + "internalType": "bool", + "name": "claimed", + "type": "bool" + }, + { + "internalType": "uint128", + "name": "amount", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "queued", + "type": "uint128" + } + ], + "internalType": "struct VaultStorage.WithdrawalRequest", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/db/migrations/1719941703954-Data.js b/db/migrations/1720507056186-Data.js similarity index 98% rename from db/migrations/1719941703954-Data.js rename to db/migrations/1720507056186-Data.js index 2d843183..59735a22 100644 --- a/db/migrations/1719941703954-Data.js +++ b/db/migrations/1720507056186-Data.js @@ -1,5 +1,5 @@ -module.exports = class Data1719941703954 { - name = 'Data1719941703954' +module.exports = class Data1720507056186 { + name = 'Data1720507056186' async up(db) { await db.query(`CREATE TABLE "es_token" ("id" character varying NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "block_number" integer NOT NULL, "circulating" numeric NOT NULL, "staked" numeric NOT NULL, "total" numeric NOT NULL, CONSTRAINT "PK_69bef9eb94d9a5d42d726d1e661" PRIMARY KEY ("id"))`) @@ -218,6 +218,9 @@ module.exports = class Data1719941703954 { await db.query(`CREATE TABLE "oeth_reward_token_collected" ("id" character varying NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "block_number" integer NOT NULL, "strategy" text NOT NULL, "recipient" text NOT NULL, "reward_token" text NOT NULL, "amount" numeric NOT NULL, CONSTRAINT "PK_47098cc5fbc7cb95c2374fa33cd" PRIMARY KEY ("id"))`) await db.query(`CREATE INDEX "IDX_81a9fa43ae4a6ae63e4103127b" ON "oeth_reward_token_collected" ("timestamp") `) await db.query(`CREATE INDEX "IDX_d36c78b9c3e9d737f067638bc4" ON "oeth_reward_token_collected" ("block_number") `) + await db.query(`CREATE TABLE "oeth_withdrawal_request" ("id" character varying NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "block_number" integer NOT NULL, "request_id" numeric NOT NULL, "withdrawer" text NOT NULL, "amount" numeric NOT NULL, "queued" numeric NOT NULL, "claimed" boolean NOT NULL, CONSTRAINT "PK_93e4b80f8ae8723a3b38f94b26a" PRIMARY KEY ("id"))`) + await db.query(`CREATE INDEX "IDX_22ebb6be552c90b2c99b165cde" ON "oeth_withdrawal_request" ("timestamp") `) + await db.query(`CREATE INDEX "IDX_fd1acb337d03a48f775c22edcd" ON "oeth_withdrawal_request" ("block_number") `) await db.query(`CREATE TABLE "ogv" ("id" character varying NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "block_number" integer NOT NULL, "circulating" numeric NOT NULL, "staked" numeric NOT NULL, "total" numeric NOT NULL, CONSTRAINT "PK_f16038abf451ce82bd03ea54ee7" PRIMARY KEY ("id"))`) await db.query(`CREATE INDEX "IDX_2418a8b8b92b2f5977be761cf9" ON "ogv" ("timestamp") `) await db.query(`CREATE INDEX "IDX_b8f20bcf48e4aa77e0f48d77db" ON "ogv" ("block_number") `) @@ -569,6 +572,9 @@ module.exports = class Data1719941703954 { await db.query(`DROP TABLE "oeth_reward_token_collected"`) await db.query(`DROP INDEX "public"."IDX_81a9fa43ae4a6ae63e4103127b"`) await db.query(`DROP INDEX "public"."IDX_d36c78b9c3e9d737f067638bc4"`) + await db.query(`DROP TABLE "oeth_withdrawal_request"`) + await db.query(`DROP INDEX "public"."IDX_22ebb6be552c90b2c99b165cde"`) + await db.query(`DROP INDEX "public"."IDX_fd1acb337d03a48f775c22edcd"`) await db.query(`DROP TABLE "ogv"`) await db.query(`DROP INDEX "public"."IDX_2418a8b8b92b2f5977be761cf9"`) await db.query(`DROP INDEX "public"."IDX_b8f20bcf48e4aa77e0f48d77db"`) diff --git a/schema.graphql b/schema.graphql index 2c0e3eaa..864c7ab0 100644 --- a/schema.graphql +++ b/schema.graphql @@ -701,8 +701,7 @@ type OETHStrategyDailyStat @entity { """ Total ETH value """ - holdings: [OETHStrategyHoldingDailyStat] - @derivedFrom(field: "strategyDailyStatId") + holdings: [OETHStrategyHoldingDailyStat] @derivedFrom(field: "strategyDailyStatId") } type OETHStrategyHoldingDailyStat @entity { @@ -741,7 +740,19 @@ type OETHRewardTokenCollected @entity { recipient: String! rewardToken: String! amount: BigInt! -}type OGV @entity { +} + +type OETHWithdrawalRequest @entity { + id: ID! + timestamp: DateTime! @index + blockNumber: Int! @index + requestId: BigInt! + withdrawer: String! + amount: BigInt! + queued: BigInt! + claimed: Boolean! +} +type OGV @entity { id: ID! timestamp: DateTime! @index blockNumber: Int! @index diff --git a/schema/oeth.graphql b/schema/oeth.graphql index 4e254184..572a3973 100644 --- a/schema/oeth.graphql +++ b/schema/oeth.graphql @@ -130,8 +130,7 @@ type OETHStrategyDailyStat @entity { """ Total ETH value """ - holdings: [OETHStrategyHoldingDailyStat] - @derivedFrom(field: "strategyDailyStatId") + holdings: [OETHStrategyHoldingDailyStat] @derivedFrom(field: "strategyDailyStatId") } type OETHStrategyHoldingDailyStat @entity { @@ -170,4 +169,15 @@ type OETHRewardTokenCollected @entity { recipient: String! rewardToken: String! amount: BigInt! -} \ No newline at end of file +} + +type OETHWithdrawalRequest @entity { + id: ID! + timestamp: DateTime! @index + blockNumber: Int! @index + requestId: BigInt! + withdrawer: String! + amount: BigInt! + queued: BigInt! + claimed: Boolean! +} diff --git a/src/abi/oeth-vault.ts b/src/abi/oeth-vault.ts new file mode 100644 index 00000000..ecfbe0f4 --- /dev/null +++ b/src/abi/oeth-vault.ts @@ -0,0 +1,522 @@ +import * as p from '@subsquid/evm-codec' +import { event, fun, viewFun, indexed, ContractBase } from '@subsquid/evm-abi' +import type { EventParams as EParams, FunctionArguments, FunctionReturn } from '@subsquid/evm-abi' + +export const events = { + AllocateThresholdUpdated: event("0x2ec5fb5a3d2703edc461252d92ccd2799c3c74f01d97212b20388207fa17ae45", "AllocateThresholdUpdated(uint256)", {"_threshold": p.uint256}), + AssetAllocated: event("0x41b99659f6ba0803f444aff29e5bf6e26dd86a3219aff92119d69710a956ba8d", "AssetAllocated(address,address,uint256)", {"_asset": p.address, "_strategy": p.address, "_amount": p.uint256}), + AssetDefaultStrategyUpdated: event("0xba58ce12801c949fa65f41c46ed108671c219baf945fa48d21026cea99ff252a", "AssetDefaultStrategyUpdated(address,address)", {"_asset": p.address, "_strategy": p.address}), + AssetSupported: event("0x4f1ac48525e50059cc1cc6e0e1940ece0dd653a4db4841538d6aef036be2fb7b", "AssetSupported(address)", {"_asset": p.address}), + CapitalPaused: event("0x71f0e5b62f846a22e0b4d159e516e62fa9c2b8eb570be15f83e67d98a2ee51e0", "CapitalPaused()", {}), + CapitalUnpaused: event("0x891ebab18da80ebeeea06b1b1cede098329c4c008906a98370c2ac7a80b571cb", "CapitalUnpaused()", {}), + DripperChanged: event("0xaf2910d9759321733de15af1827a49830692912adeb2b3646334861f2cd2eed4", "DripperChanged(address)", {"_dripper": indexed(p.address)}), + MaxSupplyDiffChanged: event("0x95201f9c21f26877223b1ff4073936a6484c35495649e60e55730497aeb60d93", "MaxSupplyDiffChanged(uint256)", {"maxSupplyDiff": p.uint256}), + Mint: event("0x0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d4121396885", "Mint(address,uint256)", {"_addr": p.address, "_value": p.uint256}), + PriceProviderUpdated: event("0xb266add5f3044b17d27db796af992cecbe413921b4e8aaaee03c719e16b9806a", "PriceProviderUpdated(address)", {"_priceProvider": p.address}), + RebasePaused: event("0x8cff26a5985614b3d30629cc4ab83824bf115aec971b718d8f2f99562032e972", "RebasePaused()", {}), + RebaseThresholdUpdated: event("0x39367850377ac04920a9a670f2180e7a94d83b15ad302e59875ec58fd10bd37d", "RebaseThresholdUpdated(uint256)", {"_threshold": p.uint256}), + RebaseUnpaused: event("0xbc044409505c95b6b851433df96e1beae715c909d8e7c1d6d7ab783300d4e3b9", "RebaseUnpaused()", {}), + Redeem: event("0x222838db2794d11532d940e8dec38ae307ed0b63cd97c233322e221f998767a6", "Redeem(address,uint256)", {"_addr": p.address, "_value": p.uint256}), + RedeemFeeUpdated: event("0xd6c7508d6658ccee36b7b7d7fd72e5cbaeefb40c64eff24e9ae7470e846304ee", "RedeemFeeUpdated(uint256)", {"_redeemFeeBps": p.uint256}), + StrategistUpdated: event("0x869e0abd13cc3a975de7b93be3df1cb2255c802b1cead85963cc79d99f131bee", "StrategistUpdated(address)", {"_address": p.address}), + StrategyApproved: event("0x960dd94cbb79169f09a4e445d58b895df2d9bffa5b31055d0932d801724a20d1", "StrategyApproved(address)", {"_addr": p.address}), + StrategyRemoved: event("0x09a1db4b80c32706328728508c941a6b954f31eb5affd32f236c1fd405f8fea4", "StrategyRemoved(address)", {"_addr": p.address}), + SwapAllowedUndervalueChanged: event("0xf12c00256bee2b6facb111a88a9b1cff86e79132939b44f1353212d6f7469557", "SwapAllowedUndervalueChanged(uint256)", {"_basis": p.uint256}), + SwapSlippageChanged: event("0x8d22e9d2cbe8bb65a3c4412bd8970743864512a1a0e004e8d00fb96277b78b94", "SwapSlippageChanged(address,uint256)", {"_asset": p.address, "_basis": p.uint256}), + Swapped: event("0xa078c4190abe07940190effc1846be0ccf03ad6007bc9e93f9697d0b460befbb", "Swapped(address,address,uint256,uint256)", {"_fromAsset": indexed(p.address), "_toAsset": indexed(p.address), "_fromAssetAmount": p.uint256, "_toAssetAmount": p.uint256}), + SwapperChanged: event("0x7d7719313229e558c5a3893cad2eb86a86a049156d1d9ebd5c63a8eedefd1c03", "SwapperChanged(address)", {"_address": p.address}), + TrusteeAddressChanged: event("0x1e4af5ac389e8cde1bdaa6830881b6c987c62a45cfb3b33d27d805cde3b57750", "TrusteeAddressChanged(address)", {"_address": p.address}), + TrusteeFeeBpsChanged: event("0x56287a45051933ea374811b3d5d165033047be5572cac676f7c28b8be4f746c7", "TrusteeFeeBpsChanged(uint256)", {"_basis": p.uint256}), + VaultBufferUpdated: event("0x41ecb23a0e7865b25f38c268b7c3012220d822929e9edff07326e89d5bb822b5", "VaultBufferUpdated(uint256)", {"_vaultBuffer": p.uint256}), + WithdrawalClaimable: event("0xee79a0c43d3993055690b54e074b5153e8bae8d1a872b656dedb64aa8f463333", "WithdrawalClaimable(uint256,uint256)", {"_claimable": p.uint256, "_newClaimable": p.uint256}), + WithdrawalClaimed: event("0x2d43eb174787155132b52ddb6b346e2dca99302eac3df4466dbeff953d3c84d1", "WithdrawalClaimed(address,uint256,uint256)", {"_withdrawer": indexed(p.address), "_requestId": indexed(p.uint256), "_amount": p.uint256}), + WithdrawalRequested: event("0x38e3d972947cfef94205163d483d6287ef27eb312e20cb8e0b13a49989db232e", "WithdrawalRequested(address,uint256,uint256,uint256)", {"_withdrawer": indexed(p.address), "_requestId": indexed(p.uint256), "_amount": p.uint256, "_queued": p.uint256}), + YieldDistribution: event("0x09516ecf4a8a86e59780a9befc6dee948bc9e60a36e3be68d31ea817ee8d2c80", "YieldDistribution(address,uint256,uint256)", {"_to": p.address, "_yield": p.uint256, "_fee": p.uint256}), +} + +export const functions = { + addWithdrawalQueueLiquidity: fun("0xb9b17f9f", "addWithdrawalQueueLiquidity()", {}, ), + allocate: fun("0xabaa9916", "allocate()", {}, ), + allowedSwapUndervalue: viewFun("0x4bed3bc0", "allowedSwapUndervalue()", {}, p.uint256), + approveStrategy: fun("0x3b8ae397", "approveStrategy(address)", {"_addr": p.address}, ), + assetDefaultStrategies: viewFun("0xa403e4d5", "assetDefaultStrategies(address)", {"_asset": p.address}, p.address), + autoAllocateThreshold: viewFun("0x9fa1826e", "autoAllocateThreshold()", {}, p.uint256), + burnForStrategy: fun("0x6217f3ea", "burnForStrategy(uint256)", {"_amount": p.uint256}, ), + cacheWETHAssetIndex: fun("0x44c54707", "cacheWETHAssetIndex()", {}, ), + calculateRedeemOutputs: viewFun("0x67bd7ba3", "calculateRedeemOutputs(uint256)", {"_amount": p.uint256}, p.array(p.uint256)), + capitalPaused: viewFun("0xe6cc5432", "capitalPaused()", {}, p.bool), + checkBalance: viewFun("0x5f515226", "checkBalance(address)", {"_asset": p.address}, p.uint256), + claimGovernance: fun("0x5d36b190", "claimGovernance()", {}, ), + claimWithdrawal: fun("0xf8444436", "claimWithdrawal(uint256)", {"requestId": p.uint256}, p.uint256), + claimWithdrawals: fun("0x48e30f54", "claimWithdrawals(uint256[])", {"requestIds": p.array(p.uint256)}, {"amounts": p.array(p.uint256), "totalAmount": p.uint256}), + depositToStrategy: fun("0x840c4c7a", "depositToStrategy(address,address[],uint256[])", {"_strategyToAddress": p.address, "_assets": p.array(p.address), "_amounts": p.array(p.uint256)}, ), + getAllAssets: viewFun("0x2acada4d", "getAllAssets()", {}, p.array(p.address)), + getAllStrategies: viewFun("0xc3b28864", "getAllStrategies()", {}, p.array(p.address)), + getAssetConfig: viewFun("0x6ec3ab67", "getAssetConfig(address)", {"_asset": p.address}, p.struct({"isSupported": p.bool, "unitConversion": p.uint8, "decimals": p.uint8, "allowedOracleSlippageBps": p.uint16})), + getAssetCount: viewFun("0xa0aead4d", "getAssetCount()", {}, p.uint256), + getStrategyCount: viewFun("0x31e19cfa", "getStrategyCount()", {}, p.uint256), + governor: viewFun("0x0c340a24", "governor()", {}, p.address), + initialize: fun("0x485cc955", "initialize(address,address)", {"_0": p.address, "_1": p.address}, ), + isSupportedAsset: viewFun("0x9be918e6", "isSupportedAsset(address)", {"_asset": p.address}, p.bool), + maxSupplyDiff: viewFun("0x8e510b52", "maxSupplyDiff()", {}, p.uint256), + mint: fun("0x156e29f6", "mint(address,uint256,uint256)", {"_asset": p.address, "_amount": p.uint256, "_minimumOusdAmount": p.uint256}, ), + mintForStrategy: fun("0xab80dafb", "mintForStrategy(uint256)", {"_amount": p.uint256}, ), + netOusdMintForStrategyThreshold: viewFun("0x7a2202f3", "netOusdMintForStrategyThreshold()", {}, p.uint256), + netOusdMintedForStrategy: viewFun("0xe45cc9f0", "netOusdMintedForStrategy()", {}, p.int256), + ousdMetaStrategy: viewFun("0x18ce56bd", "ousdMetaStrategy()", {}, p.address), + pauseCapital: fun("0x3dbc911f", "pauseCapital()", {}, ), + pauseRebase: fun("0xc5f00841", "pauseRebase()", {}, ), + priceProvider: viewFun("0xb888879e", "priceProvider()", {}, p.address), + priceUnitMint: viewFun("0x3b8fe28d", "priceUnitMint(address)", {"asset": p.address}, p.uint256), + priceUnitRedeem: viewFun("0x5b60f9fc", "priceUnitRedeem(address)", {"asset": p.address}, p.uint256), + rebase: fun("0xaf14052c", "rebase()", {}, ), + rebasePaused: viewFun("0x53ca9f24", "rebasePaused()", {}, p.bool), + rebaseThreshold: viewFun("0x52d38e5d", "rebaseThreshold()", {}, p.uint256), + redeem: fun("0x7cbc2373", "redeem(uint256,uint256)", {"_amount": p.uint256, "_minimumUnitAmount": p.uint256}, ), + redeemAll: fun("0x7136a7a6", "redeemAll(uint256)", {"_minimumUnitAmount": p.uint256}, ), + redeemFeeBps: viewFun("0x09f6442c", "redeemFeeBps()", {}, p.uint256), + removeAsset: fun("0x4a5e42b1", "removeAsset(address)", {"_asset": p.address}, ), + removeStrategy: fun("0x175188e8", "removeStrategy(address)", {"_addr": p.address}, ), + requestWithdrawal: fun("0x9ee679e8", "requestWithdrawal(uint256)", {"_amount": p.uint256}, {"requestId": p.uint256, "queued": p.uint256}), + setAdminImpl: fun("0xfc0cfeee", "setAdminImpl(address)", {"_0": p.address}, ), + setAssetDefaultStrategy: fun("0xbc90106b", "setAssetDefaultStrategy(address,address)", {"_asset": p.address, "_strategy": p.address}, ), + setAutoAllocateThreshold: fun("0xb2c9336d", "setAutoAllocateThreshold(uint256)", {"_threshold": p.uint256}, ), + setDripper: fun("0x2e9958ab", "setDripper(address)", {"_dripper": p.address}, ), + setMaxSupplyDiff: fun("0x663e64ce", "setMaxSupplyDiff(uint256)", {"_maxSupplyDiff": p.uint256}, ), + setNetOusdMintForStrategyThreshold: fun("0x636e6c40", "setNetOusdMintForStrategyThreshold(uint256)", {"_threshold": p.uint256}, ), + setOracleSlippage: fun("0x7b9a7096", "setOracleSlippage(address,uint16)", {"_asset": p.address, "_allowedOracleSlippageBps": p.uint16}, ), + setOusdMetaStrategy: fun("0xd58e3b3a", "setOusdMetaStrategy(address)", {"_ousdMetaStrategy": p.address}, ), + setPriceProvider: fun("0x372aa224", "setPriceProvider(address)", {"_priceProvider": p.address}, ), + setRebaseThreshold: fun("0xb890ebf6", "setRebaseThreshold(uint256)", {"_threshold": p.uint256}, ), + setRedeemFeeBps: fun("0xeb03654b", "setRedeemFeeBps(uint256)", {"_redeemFeeBps": p.uint256}, ), + setStrategistAddr: fun("0x773540b3", "setStrategistAddr(address)", {"_address": p.address}, ), + setSwapAllowedUndervalue: fun("0xe829cc16", "setSwapAllowedUndervalue(uint16)", {"_percentageBps": p.uint16}, ), + setSwapper: fun("0x9c82f2a4", "setSwapper(address)", {"_swapperAddr": p.address}, ), + setTrusteeAddress: fun("0x2da845a8", "setTrusteeAddress(address)", {"_address": p.address}, ), + setTrusteeFeeBps: fun("0x0acbda75", "setTrusteeFeeBps(uint256)", {"_basis": p.uint256}, ), + setVaultBuffer: fun("0x8ec489a2", "setVaultBuffer(uint256)", {"_vaultBuffer": p.uint256}, ), + strategistAddr: viewFun("0x570d8e1d", "strategistAddr()", {}, p.address), + supportAsset: fun("0x6c7561e8", "supportAsset(address,uint8)", {"_asset": p.address, "_supportsAsset": p.uint8}, ), + swapCollateral: fun("0x50ba711c", "swapCollateral(address,address,uint256,uint256,bytes)", {"fromAsset": p.address, "toAsset": p.address, "fromAssetAmount": p.uint256, "minToAssetAmount": p.uint256, "data": p.bytes}, p.uint256), + swapper: viewFun("0x2b3297f9", "swapper()", {}, p.address), + totalValue: viewFun("0xd4c3eea0", "totalValue()", {}, p.uint256), + transferGovernance: fun("0xd38bfff4", "transferGovernance(address)", {"_newGovernor": p.address}, ), + transferToken: fun("0x1072cbea", "transferToken(address,uint256)", {"_asset": p.address, "_amount": p.uint256}, ), + trusteeAddress: viewFun("0x49c1d54d", "trusteeAddress()", {}, p.address), + trusteeFeeBps: viewFun("0x207134b0", "trusteeFeeBps()", {}, p.uint256), + unpauseCapital: fun("0x94828ffd", "unpauseCapital()", {}, ), + unpauseRebase: fun("0x09f49bf5", "unpauseRebase()", {}, ), + vaultBuffer: viewFun("0x1edfe3da", "vaultBuffer()", {}, p.uint256), + weth: viewFun("0x3fc8cef3", "weth()", {}, p.address), + wethAssetIndex: viewFun("0x54c6d858", "wethAssetIndex()", {}, p.uint256), + withdrawAllFromStrategies: fun("0xc9919112", "withdrawAllFromStrategies()", {}, ), + withdrawAllFromStrategy: fun("0x597c8910", "withdrawAllFromStrategy(address)", {"_strategyAddr": p.address}, ), + withdrawFromStrategy: fun("0xae69f3cb", "withdrawFromStrategy(address,address[],uint256[])", {"_strategyFromAddress": p.address, "_assets": p.array(p.address), "_amounts": p.array(p.uint256)}, ), + withdrawalQueueMetadata: viewFun("0x362bd1a3", "withdrawalQueueMetadata()", {}, p.struct({"queued": p.uint128, "claimable": p.uint128, "claimed": p.uint128, "nextWithdrawalIndex": p.uint128})), + withdrawalRequests: viewFun("0x937b2581", "withdrawalRequests(uint256)", {"requestId": p.uint256}, p.struct({"withdrawer": p.address, "claimed": p.bool, "amount": p.uint128, "queued": p.uint128})), +} + +export class Contract extends ContractBase { + + allowedSwapUndervalue() { + return this.eth_call(functions.allowedSwapUndervalue, {}) + } + + assetDefaultStrategies(_asset: AssetDefaultStrategiesParams["_asset"]) { + return this.eth_call(functions.assetDefaultStrategies, {_asset}) + } + + autoAllocateThreshold() { + return this.eth_call(functions.autoAllocateThreshold, {}) + } + + calculateRedeemOutputs(_amount: CalculateRedeemOutputsParams["_amount"]) { + return this.eth_call(functions.calculateRedeemOutputs, {_amount}) + } + + capitalPaused() { + return this.eth_call(functions.capitalPaused, {}) + } + + checkBalance(_asset: CheckBalanceParams["_asset"]) { + return this.eth_call(functions.checkBalance, {_asset}) + } + + getAllAssets() { + return this.eth_call(functions.getAllAssets, {}) + } + + getAllStrategies() { + return this.eth_call(functions.getAllStrategies, {}) + } + + getAssetConfig(_asset: GetAssetConfigParams["_asset"]) { + return this.eth_call(functions.getAssetConfig, {_asset}) + } + + getAssetCount() { + return this.eth_call(functions.getAssetCount, {}) + } + + getStrategyCount() { + return this.eth_call(functions.getStrategyCount, {}) + } + + governor() { + return this.eth_call(functions.governor, {}) + } + + isSupportedAsset(_asset: IsSupportedAssetParams["_asset"]) { + return this.eth_call(functions.isSupportedAsset, {_asset}) + } + + maxSupplyDiff() { + return this.eth_call(functions.maxSupplyDiff, {}) + } + + netOusdMintForStrategyThreshold() { + return this.eth_call(functions.netOusdMintForStrategyThreshold, {}) + } + + netOusdMintedForStrategy() { + return this.eth_call(functions.netOusdMintedForStrategy, {}) + } + + ousdMetaStrategy() { + return this.eth_call(functions.ousdMetaStrategy, {}) + } + + priceProvider() { + return this.eth_call(functions.priceProvider, {}) + } + + priceUnitMint(asset: PriceUnitMintParams["asset"]) { + return this.eth_call(functions.priceUnitMint, {asset}) + } + + priceUnitRedeem(asset: PriceUnitRedeemParams["asset"]) { + return this.eth_call(functions.priceUnitRedeem, {asset}) + } + + rebasePaused() { + return this.eth_call(functions.rebasePaused, {}) + } + + rebaseThreshold() { + return this.eth_call(functions.rebaseThreshold, {}) + } + + redeemFeeBps() { + return this.eth_call(functions.redeemFeeBps, {}) + } + + strategistAddr() { + return this.eth_call(functions.strategistAddr, {}) + } + + swapper() { + return this.eth_call(functions.swapper, {}) + } + + totalValue() { + return this.eth_call(functions.totalValue, {}) + } + + trusteeAddress() { + return this.eth_call(functions.trusteeAddress, {}) + } + + trusteeFeeBps() { + return this.eth_call(functions.trusteeFeeBps, {}) + } + + vaultBuffer() { + return this.eth_call(functions.vaultBuffer, {}) + } + + weth() { + return this.eth_call(functions.weth, {}) + } + + wethAssetIndex() { + return this.eth_call(functions.wethAssetIndex, {}) + } + + withdrawalQueueMetadata() { + return this.eth_call(functions.withdrawalQueueMetadata, {}) + } + + withdrawalRequests(requestId: WithdrawalRequestsParams["requestId"]) { + return this.eth_call(functions.withdrawalRequests, {requestId}) + } +} + +/// Event types +export type AllocateThresholdUpdatedEventArgs = EParams +export type AssetAllocatedEventArgs = EParams +export type AssetDefaultStrategyUpdatedEventArgs = EParams +export type AssetSupportedEventArgs = EParams +export type CapitalPausedEventArgs = EParams +export type CapitalUnpausedEventArgs = EParams +export type DripperChangedEventArgs = EParams +export type MaxSupplyDiffChangedEventArgs = EParams +export type MintEventArgs = EParams +export type PriceProviderUpdatedEventArgs = EParams +export type RebasePausedEventArgs = EParams +export type RebaseThresholdUpdatedEventArgs = EParams +export type RebaseUnpausedEventArgs = EParams +export type RedeemEventArgs = EParams +export type RedeemFeeUpdatedEventArgs = EParams +export type StrategistUpdatedEventArgs = EParams +export type StrategyApprovedEventArgs = EParams +export type StrategyRemovedEventArgs = EParams +export type SwapAllowedUndervalueChangedEventArgs = EParams +export type SwapSlippageChangedEventArgs = EParams +export type SwappedEventArgs = EParams +export type SwapperChangedEventArgs = EParams +export type TrusteeAddressChangedEventArgs = EParams +export type TrusteeFeeBpsChangedEventArgs = EParams +export type VaultBufferUpdatedEventArgs = EParams +export type WithdrawalClaimableEventArgs = EParams +export type WithdrawalClaimedEventArgs = EParams +export type WithdrawalRequestedEventArgs = EParams +export type YieldDistributionEventArgs = EParams + +/// Function types +export type AddWithdrawalQueueLiquidityParams = FunctionArguments +export type AddWithdrawalQueueLiquidityReturn = FunctionReturn + +export type AllocateParams = FunctionArguments +export type AllocateReturn = FunctionReturn + +export type AllowedSwapUndervalueParams = FunctionArguments +export type AllowedSwapUndervalueReturn = FunctionReturn + +export type ApproveStrategyParams = FunctionArguments +export type ApproveStrategyReturn = FunctionReturn + +export type AssetDefaultStrategiesParams = FunctionArguments +export type AssetDefaultStrategiesReturn = FunctionReturn + +export type AutoAllocateThresholdParams = FunctionArguments +export type AutoAllocateThresholdReturn = FunctionReturn + +export type BurnForStrategyParams = FunctionArguments +export type BurnForStrategyReturn = FunctionReturn + +export type CacheWETHAssetIndexParams = FunctionArguments +export type CacheWETHAssetIndexReturn = FunctionReturn + +export type CalculateRedeemOutputsParams = FunctionArguments +export type CalculateRedeemOutputsReturn = FunctionReturn + +export type CapitalPausedParams = FunctionArguments +export type CapitalPausedReturn = FunctionReturn + +export type CheckBalanceParams = FunctionArguments +export type CheckBalanceReturn = FunctionReturn + +export type ClaimGovernanceParams = FunctionArguments +export type ClaimGovernanceReturn = FunctionReturn + +export type ClaimWithdrawalParams = FunctionArguments +export type ClaimWithdrawalReturn = FunctionReturn + +export type ClaimWithdrawalsParams = FunctionArguments +export type ClaimWithdrawalsReturn = FunctionReturn + +export type DepositToStrategyParams = FunctionArguments +export type DepositToStrategyReturn = FunctionReturn + +export type GetAllAssetsParams = FunctionArguments +export type GetAllAssetsReturn = FunctionReturn + +export type GetAllStrategiesParams = FunctionArguments +export type GetAllStrategiesReturn = FunctionReturn + +export type GetAssetConfigParams = FunctionArguments +export type GetAssetConfigReturn = FunctionReturn + +export type GetAssetCountParams = FunctionArguments +export type GetAssetCountReturn = FunctionReturn + +export type GetStrategyCountParams = FunctionArguments +export type GetStrategyCountReturn = FunctionReturn + +export type GovernorParams = FunctionArguments +export type GovernorReturn = FunctionReturn + +export type InitializeParams = FunctionArguments +export type InitializeReturn = FunctionReturn + +export type IsSupportedAssetParams = FunctionArguments +export type IsSupportedAssetReturn = FunctionReturn + +export type MaxSupplyDiffParams = FunctionArguments +export type MaxSupplyDiffReturn = FunctionReturn + +export type MintParams = FunctionArguments +export type MintReturn = FunctionReturn + +export type MintForStrategyParams = FunctionArguments +export type MintForStrategyReturn = FunctionReturn + +export type NetOusdMintForStrategyThresholdParams = FunctionArguments +export type NetOusdMintForStrategyThresholdReturn = FunctionReturn + +export type NetOusdMintedForStrategyParams = FunctionArguments +export type NetOusdMintedForStrategyReturn = FunctionReturn + +export type OusdMetaStrategyParams = FunctionArguments +export type OusdMetaStrategyReturn = FunctionReturn + +export type PauseCapitalParams = FunctionArguments +export type PauseCapitalReturn = FunctionReturn + +export type PauseRebaseParams = FunctionArguments +export type PauseRebaseReturn = FunctionReturn + +export type PriceProviderParams = FunctionArguments +export type PriceProviderReturn = FunctionReturn + +export type PriceUnitMintParams = FunctionArguments +export type PriceUnitMintReturn = FunctionReturn + +export type PriceUnitRedeemParams = FunctionArguments +export type PriceUnitRedeemReturn = FunctionReturn + +export type RebaseParams = FunctionArguments +export type RebaseReturn = FunctionReturn + +export type RebasePausedParams = FunctionArguments +export type RebasePausedReturn = FunctionReturn + +export type RebaseThresholdParams = FunctionArguments +export type RebaseThresholdReturn = FunctionReturn + +export type RedeemParams = FunctionArguments +export type RedeemReturn = FunctionReturn + +export type RedeemAllParams = FunctionArguments +export type RedeemAllReturn = FunctionReturn + +export type RedeemFeeBpsParams = FunctionArguments +export type RedeemFeeBpsReturn = FunctionReturn + +export type RemoveAssetParams = FunctionArguments +export type RemoveAssetReturn = FunctionReturn + +export type RemoveStrategyParams = FunctionArguments +export type RemoveStrategyReturn = FunctionReturn + +export type RequestWithdrawalParams = FunctionArguments +export type RequestWithdrawalReturn = FunctionReturn + +export type SetAdminImplParams = FunctionArguments +export type SetAdminImplReturn = FunctionReturn + +export type SetAssetDefaultStrategyParams = FunctionArguments +export type SetAssetDefaultStrategyReturn = FunctionReturn + +export type SetAutoAllocateThresholdParams = FunctionArguments +export type SetAutoAllocateThresholdReturn = FunctionReturn + +export type SetDripperParams = FunctionArguments +export type SetDripperReturn = FunctionReturn + +export type SetMaxSupplyDiffParams = FunctionArguments +export type SetMaxSupplyDiffReturn = FunctionReturn + +export type SetNetOusdMintForStrategyThresholdParams = FunctionArguments +export type SetNetOusdMintForStrategyThresholdReturn = FunctionReturn + +export type SetOracleSlippageParams = FunctionArguments +export type SetOracleSlippageReturn = FunctionReturn + +export type SetOusdMetaStrategyParams = FunctionArguments +export type SetOusdMetaStrategyReturn = FunctionReturn + +export type SetPriceProviderParams = FunctionArguments +export type SetPriceProviderReturn = FunctionReturn + +export type SetRebaseThresholdParams = FunctionArguments +export type SetRebaseThresholdReturn = FunctionReturn + +export type SetRedeemFeeBpsParams = FunctionArguments +export type SetRedeemFeeBpsReturn = FunctionReturn + +export type SetStrategistAddrParams = FunctionArguments +export type SetStrategistAddrReturn = FunctionReturn + +export type SetSwapAllowedUndervalueParams = FunctionArguments +export type SetSwapAllowedUndervalueReturn = FunctionReturn + +export type SetSwapperParams = FunctionArguments +export type SetSwapperReturn = FunctionReturn + +export type SetTrusteeAddressParams = FunctionArguments +export type SetTrusteeAddressReturn = FunctionReturn + +export type SetTrusteeFeeBpsParams = FunctionArguments +export type SetTrusteeFeeBpsReturn = FunctionReturn + +export type SetVaultBufferParams = FunctionArguments +export type SetVaultBufferReturn = FunctionReturn + +export type StrategistAddrParams = FunctionArguments +export type StrategistAddrReturn = FunctionReturn + +export type SupportAssetParams = FunctionArguments +export type SupportAssetReturn = FunctionReturn + +export type SwapCollateralParams = FunctionArguments +export type SwapCollateralReturn = FunctionReturn + +export type SwapperParams = FunctionArguments +export type SwapperReturn = FunctionReturn + +export type TotalValueParams = FunctionArguments +export type TotalValueReturn = FunctionReturn + +export type TransferGovernanceParams = FunctionArguments +export type TransferGovernanceReturn = FunctionReturn + +export type TransferTokenParams = FunctionArguments +export type TransferTokenReturn = FunctionReturn + +export type TrusteeAddressParams = FunctionArguments +export type TrusteeAddressReturn = FunctionReturn + +export type TrusteeFeeBpsParams = FunctionArguments +export type TrusteeFeeBpsReturn = FunctionReturn + +export type UnpauseCapitalParams = FunctionArguments +export type UnpauseCapitalReturn = FunctionReturn + +export type UnpauseRebaseParams = FunctionArguments +export type UnpauseRebaseReturn = FunctionReturn + +export type VaultBufferParams = FunctionArguments +export type VaultBufferReturn = FunctionReturn + +export type WethParams = FunctionArguments +export type WethReturn = FunctionReturn + +export type WethAssetIndexParams = FunctionArguments +export type WethAssetIndexReturn = FunctionReturn + +export type WithdrawAllFromStrategiesParams = FunctionArguments +export type WithdrawAllFromStrategiesReturn = FunctionReturn + +export type WithdrawAllFromStrategyParams = FunctionArguments +export type WithdrawAllFromStrategyReturn = FunctionReturn + +export type WithdrawFromStrategyParams = FunctionArguments +export type WithdrawFromStrategyReturn = FunctionReturn + +export type WithdrawalQueueMetadataParams = FunctionArguments +export type WithdrawalQueueMetadataReturn = FunctionReturn + +export type WithdrawalRequestsParams = FunctionArguments +export type WithdrawalRequestsReturn = FunctionReturn + diff --git a/src/main-oeth.ts b/src/main-oeth.ts index 5aebb80d..33ed4ca3 100644 --- a/src/main-oeth.ts +++ b/src/main-oeth.ts @@ -15,6 +15,7 @@ import * as fraxStaking from './oeth/processors/frax-staking' import * as morphoAave from './oeth/processors/morpho-aave' import * as strategies from './oeth/processors/strategies' import * as vault from './oeth/processors/vault' +import * as withdrawals from './oeth/processors/withdrawals' import * as validateOeth from './oeth/validators/validate-oeth' export const processor = { @@ -30,12 +31,9 @@ export const processor = { balancerMetaPoolStrategy, strategies, exchangeRates, + withdrawals, ], - postProcessors: [ - exchangeRatesPostProcessor, - dailyStats, - processStatus('oeth'), - ], + postProcessors: [exchangeRatesPostProcessor, dailyStats, processStatus('oeth')], validators: [validateOeth], } export default processor diff --git a/src/model/generated/index.ts b/src/model/generated/index.ts index 56efea1c..545eb4ca 100644 --- a/src/model/generated/index.ts +++ b/src/model/generated/index.ts @@ -59,6 +59,7 @@ export * from "./oethStrategyDailyStat.model" export * from "./oethStrategyHoldingDailyStat.model" export * from "./oethCollateralDailyStat.model" export * from "./oethRewardTokenCollected.model" +export * from "./oethWithdrawalRequest.model" export * from "./ogv.model" export * from "./ogvAddress.model" export * from "./ogvLockupTxLog.model" diff --git a/src/model/generated/oethWithdrawalRequest.model.ts b/src/model/generated/oethWithdrawalRequest.model.ts new file mode 100644 index 00000000..bd40350a --- /dev/null +++ b/src/model/generated/oethWithdrawalRequest.model.ts @@ -0,0 +1,34 @@ +import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, DateTimeColumn as DateTimeColumn_, Index as Index_, IntColumn as IntColumn_, BigIntColumn as BigIntColumn_, StringColumn as StringColumn_, BooleanColumn as BooleanColumn_} from "@subsquid/typeorm-store" + +@Entity_() +export class OETHWithdrawalRequest { + constructor(props?: Partial) { + Object.assign(this, props) + } + + @PrimaryColumn_() + id!: string + + @Index_() + @DateTimeColumn_({nullable: false}) + timestamp!: Date + + @Index_() + @IntColumn_({nullable: false}) + blockNumber!: number + + @BigIntColumn_({nullable: false}) + requestId!: bigint + + @StringColumn_({nullable: false}) + withdrawer!: string + + @BigIntColumn_({nullable: false}) + amount!: bigint + + @BigIntColumn_({nullable: false}) + queued!: bigint + + @BooleanColumn_({nullable: false}) + claimed!: boolean +} diff --git a/src/oeth/processors/withdrawals.ts b/src/oeth/processors/withdrawals.ts new file mode 100644 index 00000000..fb4a70cb --- /dev/null +++ b/src/oeth/processors/withdrawals.ts @@ -0,0 +1,74 @@ +import * as oethVault from '@abi/oeth-vault' +import { OETHWithdrawalRequest } from '@model' +import { Context } from '@processor' +import { EvmBatchProcessor } from '@subsquid/evm-processor' +import { OETH_VAULT_ADDRESS } from '@utils/addresses' + +export const from = 20264539 // TODO update with actual update blocknumber + +interface ProcessResult { + withdrawalRequests: OETHWithdrawalRequest[] +} + +export const setup = (processor: EvmBatchProcessor) => { + processor.addLog({ + address: [OETH_VAULT_ADDRESS], + topic0: [oethVault.events.WithdrawalRequested.topic], + range: { from }, + }) + processor.addLog({ + address: [OETH_VAULT_ADDRESS], + topic0: [oethVault.events.WithdrawalClaimed.topic], + range: { from }, + }) +} + +export const process = async (ctx: Context) => { + const result: ProcessResult = { + withdrawalRequests: [], + } + + for (const block of ctx.blocks) { + for (const log of block.logs) { + await processWithdrawalRequested(ctx, result, block, log) + await processWithdrawalClaimed(ctx, result, block, log) + } + } + + await ctx.store.insert(result.withdrawalRequests) +} + +const processWithdrawalRequested = async ( + ctx: Context, + result: ProcessResult, + block: Context['blocks'][number], + log: Context['blocks'][number]['logs'][number], +) => { + const data = oethVault.events.WithdrawalRequested.decode(log) + const withdrawalRequest = new OETHWithdrawalRequest({ + id: log.id, + blockNumber: block.header.height, + timestamp: new Date(block.header.timestamp), + requestId: data._requestId, + amount: data._amount, + claimed: false, + queued: data._queued, + withdrawer: data._withdrawer, + }) + result.withdrawalRequests.push(withdrawalRequest) +} + +const processWithdrawalClaimed = async ( + ctx: Context, + result: ProcessResult, + block: Context['blocks'][number], + log: Context['blocks'][number]['logs'][number], +) => { + const data = oethVault.events.WithdrawalClaimed.decode(log) + const foundIndex = result.withdrawalRequests.findIndex( + (r) => r.requestId === data._requestId && r.withdrawer?.toLowerCase() === data._withdrawer?.toLowerCase(), + ) + if (foundIndex > -1) { + result.withdrawalRequests[foundIndex] = { ...result.withdrawalRequests[foundIndex], claimed: true } + } +} From fb6196d8e71063059743a0be68aae5eace5c5576 Mon Sep 17 00:00:00 2001 From: toniocodo Date: Tue, 9 Jul 2024 09:06:53 +0200 Subject: [PATCH 02/11] feat: use logFilter --- src/oeth/processors/withdrawals.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/oeth/processors/withdrawals.ts b/src/oeth/processors/withdrawals.ts index fb4a70cb..cfdbeb8e 100644 --- a/src/oeth/processors/withdrawals.ts +++ b/src/oeth/processors/withdrawals.ts @@ -3,6 +3,7 @@ import { OETHWithdrawalRequest } from '@model' import { Context } from '@processor' import { EvmBatchProcessor } from '@subsquid/evm-processor' import { OETH_VAULT_ADDRESS } from '@utils/addresses' +import { logFilter } from '@utils/logFilter' export const from = 20264539 // TODO update with actual update blocknumber @@ -10,17 +11,20 @@ interface ProcessResult { withdrawalRequests: OETHWithdrawalRequest[] } +const withdrawalRequestedFilter = logFilter({ + address: [OETH_VAULT_ADDRESS], + topic0: [oethVault.events.WithdrawalRequested.topic], + range: { from }, +}) +const withdrawalClaimedFilter = logFilter({ + address: [OETH_VAULT_ADDRESS], + topic0: [oethVault.events.WithdrawalClaimed.topic], + range: { from }, +}) + export const setup = (processor: EvmBatchProcessor) => { - processor.addLog({ - address: [OETH_VAULT_ADDRESS], - topic0: [oethVault.events.WithdrawalRequested.topic], - range: { from }, - }) - processor.addLog({ - address: [OETH_VAULT_ADDRESS], - topic0: [oethVault.events.WithdrawalClaimed.topic], - range: { from }, - }) + processor.addLog(withdrawalRequestedFilter.value) + processor.addLog(withdrawalClaimedFilter.value) } export const process = async (ctx: Context) => { From 3aa26d2c2a5de7a062b03e0086b46ebdc5bd2bf0 Mon Sep 17 00:00:00 2001 From: toniocodo Date: Tue, 9 Jul 2024 09:07:32 +0200 Subject: [PATCH 03/11] feat: lower case address --- src/oeth/processors/withdrawals.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/oeth/processors/withdrawals.ts b/src/oeth/processors/withdrawals.ts index cfdbeb8e..e0838854 100644 --- a/src/oeth/processors/withdrawals.ts +++ b/src/oeth/processors/withdrawals.ts @@ -57,7 +57,7 @@ const processWithdrawalRequested = async ( amount: data._amount, claimed: false, queued: data._queued, - withdrawer: data._withdrawer, + withdrawer: data._withdrawer?.toLowerCase(), }) result.withdrawalRequests.push(withdrawalRequest) } From f30c185f72ef25f77fb3157bc1b25adfc05b2fb3 Mon Sep 17 00:00:00 2001 From: toniocodo Date: Tue, 9 Jul 2024 09:10:25 +0200 Subject: [PATCH 04/11] feat: actually filter logs --- src/oeth/processors/withdrawals.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/oeth/processors/withdrawals.ts b/src/oeth/processors/withdrawals.ts index e0838854..fe9e9e4d 100644 --- a/src/oeth/processors/withdrawals.ts +++ b/src/oeth/processors/withdrawals.ts @@ -34,8 +34,11 @@ export const process = async (ctx: Context) => { for (const block of ctx.blocks) { for (const log of block.logs) { - await processWithdrawalRequested(ctx, result, block, log) - await processWithdrawalClaimed(ctx, result, block, log) + if (withdrawalRequestedFilter.matches(log)) { + await processWithdrawalRequested(ctx, result, block, log) + } else if (withdrawalClaimedFilter.matches(log)) { + await processWithdrawalClaimed(ctx, result, block, log) + } } } From acd067387a6e2ab3c6ec7439f904dfd66ac7f733 Mon Sep 17 00:00:00 2001 From: toniocodo Date: Tue, 9 Jul 2024 09:52:31 +0200 Subject: [PATCH 05/11] feat: use Map instead of array, handle no context case --- src/oeth/processors/withdrawals.ts | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/oeth/processors/withdrawals.ts b/src/oeth/processors/withdrawals.ts index fe9e9e4d..ad0774ef 100644 --- a/src/oeth/processors/withdrawals.ts +++ b/src/oeth/processors/withdrawals.ts @@ -8,7 +8,7 @@ import { logFilter } from '@utils/logFilter' export const from = 20264539 // TODO update with actual update blocknumber interface ProcessResult { - withdrawalRequests: OETHWithdrawalRequest[] + withdrawalRequests: Map } const withdrawalRequestedFilter = logFilter({ @@ -29,7 +29,7 @@ export const setup = (processor: EvmBatchProcessor) => { export const process = async (ctx: Context) => { const result: ProcessResult = { - withdrawalRequests: [], + withdrawalRequests: new Map(), } for (const block of ctx.blocks) { @@ -42,7 +42,7 @@ export const process = async (ctx: Context) => { } } - await ctx.store.insert(result.withdrawalRequests) + await ctx.store.upsert([...result.withdrawalRequests.values()]) } const processWithdrawalRequested = async ( @@ -52,17 +52,18 @@ const processWithdrawalRequested = async ( log: Context['blocks'][number]['logs'][number], ) => { const data = oethVault.events.WithdrawalRequested.decode(log) + const withdrawalRequest = new OETHWithdrawalRequest({ - id: log.id, + id: `${data._withdrawer.toLowerCase()}:${data._requestId}`, blockNumber: block.header.height, timestamp: new Date(block.header.timestamp), requestId: data._requestId, amount: data._amount, claimed: false, queued: data._queued, - withdrawer: data._withdrawer?.toLowerCase(), + withdrawer: data._withdrawer.toLowerCase(), }) - result.withdrawalRequests.push(withdrawalRequest) + result.withdrawalRequests.set(withdrawalRequest.id, withdrawalRequest) } const processWithdrawalClaimed = async ( @@ -72,10 +73,17 @@ const processWithdrawalClaimed = async ( log: Context['blocks'][number]['logs'][number], ) => { const data = oethVault.events.WithdrawalClaimed.decode(log) - const foundIndex = result.withdrawalRequests.findIndex( - (r) => r.requestId === data._requestId && r.withdrawer?.toLowerCase() === data._withdrawer?.toLowerCase(), - ) - if (foundIndex > -1) { - result.withdrawalRequests[foundIndex] = { ...result.withdrawalRequests[foundIndex], claimed: true } + const id = `${data._withdrawer.toLowerCase()}:${data._requestId}` + let updated + if (result.withdrawalRequests.has(id)) { + updated = result.withdrawalRequests.get(id) + } else { + updated = await ctx.store.findOneBy(OETHWithdrawalRequest, { + requestId: data._requestId, + withdrawer: data._withdrawer.toLowerCase(), + }) + } + if (updated) { + result.withdrawalRequests.set(id, { ...updated, claimed: true }) } } From 7fe0af19f4814b279671c1e41f428239b42d806e Mon Sep 17 00:00:00 2001 From: toniocodo Date: Tue, 9 Jul 2024 09:53:31 +0200 Subject: [PATCH 06/11] feat: search by id --- src/oeth/processors/withdrawals.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/oeth/processors/withdrawals.ts b/src/oeth/processors/withdrawals.ts index ad0774ef..945daf32 100644 --- a/src/oeth/processors/withdrawals.ts +++ b/src/oeth/processors/withdrawals.ts @@ -78,10 +78,7 @@ const processWithdrawalClaimed = async ( if (result.withdrawalRequests.has(id)) { updated = result.withdrawalRequests.get(id) } else { - updated = await ctx.store.findOneBy(OETHWithdrawalRequest, { - requestId: data._requestId, - withdrawer: data._withdrawer.toLowerCase(), - }) + updated = await ctx.store.findOneBy(OETHWithdrawalRequest, { id }) } if (updated) { result.withdrawalRequests.set(id, { ...updated, claimed: true }) From fce7a0857c34f6b230cf7e820bd2908c42398fae Mon Sep 17 00:00:00 2001 From: toniocodo Date: Tue, 9 Jul 2024 19:09:11 +0200 Subject: [PATCH 07/11] feat: change updating method --- src/oeth/processors/withdrawals.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/oeth/processors/withdrawals.ts b/src/oeth/processors/withdrawals.ts index 945daf32..68bc3051 100644 --- a/src/oeth/processors/withdrawals.ts +++ b/src/oeth/processors/withdrawals.ts @@ -81,6 +81,7 @@ const processWithdrawalClaimed = async ( updated = await ctx.store.findOneBy(OETHWithdrawalRequest, { id }) } if (updated) { - result.withdrawalRequests.set(id, { ...updated, claimed: true }) + updated.claimed = true + result.withdrawalRequests.set(id, updated) } } From 12d05041f620371866da00da5e389ea2f6a4d535 Mon Sep 17 00:00:00 2001 From: toniocodo Date: Wed, 10 Jul 2024 18:59:55 +0200 Subject: [PATCH 08/11] chore: migrations --- .../{1720507056186-Data.js => 1720630758066-Data.js} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename db/migrations/{1720507056186-Data.js => 1720630758066-Data.js} (99%) diff --git a/db/migrations/1720507056186-Data.js b/db/migrations/1720630758066-Data.js similarity index 99% rename from db/migrations/1720507056186-Data.js rename to db/migrations/1720630758066-Data.js index 59735a22..a1ab043c 100644 --- a/db/migrations/1720507056186-Data.js +++ b/db/migrations/1720630758066-Data.js @@ -1,5 +1,5 @@ -module.exports = class Data1720507056186 { - name = 'Data1720507056186' +module.exports = class Data1720630758066 { + name = 'Data1720630758066' async up(db) { await db.query(`CREATE TABLE "es_token" ("id" character varying NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "block_number" integer NOT NULL, "circulating" numeric NOT NULL, "staked" numeric NOT NULL, "total" numeric NOT NULL, CONSTRAINT "PK_69bef9eb94d9a5d42d726d1e661" PRIMARY KEY ("id"))`) From dff9f817f8ff656924688ce845440d5284942b42 Mon Sep 17 00:00:00 2001 From: toniocodo Date: Thu, 11 Jul 2024 21:07:21 +0200 Subject: [PATCH 09/11] feat: add withdrawal txHash --- .../{1720630758066-Data.js => 1720724777473-Data.js} | 8 +++++--- schema.graphql | 1 + schema/oeth.graphql | 1 + src/model/generated/oethWithdrawalRequest.model.ts | 4 ++++ src/oeth/processors/withdrawals.ts | 1 + 5 files changed, 12 insertions(+), 3 deletions(-) rename db/migrations/{1720630758066-Data.js => 1720724777473-Data.js} (99%) diff --git a/db/migrations/1720630758066-Data.js b/db/migrations/1720724777473-Data.js similarity index 99% rename from db/migrations/1720630758066-Data.js rename to db/migrations/1720724777473-Data.js index a1ab043c..ebc1a7fe 100644 --- a/db/migrations/1720630758066-Data.js +++ b/db/migrations/1720724777473-Data.js @@ -1,5 +1,5 @@ -module.exports = class Data1720630758066 { - name = 'Data1720630758066' +module.exports = class Data1720724777473 { + name = 'Data1720724777473' async up(db) { await db.query(`CREATE TABLE "es_token" ("id" character varying NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "block_number" integer NOT NULL, "circulating" numeric NOT NULL, "staked" numeric NOT NULL, "total" numeric NOT NULL, CONSTRAINT "PK_69bef9eb94d9a5d42d726d1e661" PRIMARY KEY ("id"))`) @@ -218,9 +218,10 @@ module.exports = class Data1720630758066 { await db.query(`CREATE TABLE "oeth_reward_token_collected" ("id" character varying NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "block_number" integer NOT NULL, "strategy" text NOT NULL, "recipient" text NOT NULL, "reward_token" text NOT NULL, "amount" numeric NOT NULL, CONSTRAINT "PK_47098cc5fbc7cb95c2374fa33cd" PRIMARY KEY ("id"))`) await db.query(`CREATE INDEX "IDX_81a9fa43ae4a6ae63e4103127b" ON "oeth_reward_token_collected" ("timestamp") `) await db.query(`CREATE INDEX "IDX_d36c78b9c3e9d737f067638bc4" ON "oeth_reward_token_collected" ("block_number") `) - await db.query(`CREATE TABLE "oeth_withdrawal_request" ("id" character varying NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "block_number" integer NOT NULL, "request_id" numeric NOT NULL, "withdrawer" text NOT NULL, "amount" numeric NOT NULL, "queued" numeric NOT NULL, "claimed" boolean NOT NULL, CONSTRAINT "PK_93e4b80f8ae8723a3b38f94b26a" PRIMARY KEY ("id"))`) + await db.query(`CREATE TABLE "oeth_withdrawal_request" ("id" character varying NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "block_number" integer NOT NULL, "request_id" numeric NOT NULL, "withdrawer" text NOT NULL, "amount" numeric NOT NULL, "queued" numeric NOT NULL, "claimed" boolean NOT NULL, "tx_hash" text NOT NULL, CONSTRAINT "PK_93e4b80f8ae8723a3b38f94b26a" PRIMARY KEY ("id"))`) await db.query(`CREATE INDEX "IDX_22ebb6be552c90b2c99b165cde" ON "oeth_withdrawal_request" ("timestamp") `) await db.query(`CREATE INDEX "IDX_fd1acb337d03a48f775c22edcd" ON "oeth_withdrawal_request" ("block_number") `) + await db.query(`CREATE INDEX "IDX_2733a93f9fc9cf900ac1de1a0d" ON "oeth_withdrawal_request" ("tx_hash") `) await db.query(`CREATE TABLE "ogv" ("id" character varying NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "block_number" integer NOT NULL, "circulating" numeric NOT NULL, "staked" numeric NOT NULL, "total" numeric NOT NULL, CONSTRAINT "PK_f16038abf451ce82bd03ea54ee7" PRIMARY KEY ("id"))`) await db.query(`CREATE INDEX "IDX_2418a8b8b92b2f5977be761cf9" ON "ogv" ("timestamp") `) await db.query(`CREATE INDEX "IDX_b8f20bcf48e4aa77e0f48d77db" ON "ogv" ("block_number") `) @@ -575,6 +576,7 @@ module.exports = class Data1720630758066 { await db.query(`DROP TABLE "oeth_withdrawal_request"`) await db.query(`DROP INDEX "public"."IDX_22ebb6be552c90b2c99b165cde"`) await db.query(`DROP INDEX "public"."IDX_fd1acb337d03a48f775c22edcd"`) + await db.query(`DROP INDEX "public"."IDX_2733a93f9fc9cf900ac1de1a0d"`) await db.query(`DROP TABLE "ogv"`) await db.query(`DROP INDEX "public"."IDX_2418a8b8b92b2f5977be761cf9"`) await db.query(`DROP INDEX "public"."IDX_b8f20bcf48e4aa77e0f48d77db"`) diff --git a/schema.graphql b/schema.graphql index 864c7ab0..4faf7ac7 100644 --- a/schema.graphql +++ b/schema.graphql @@ -751,6 +751,7 @@ type OETHWithdrawalRequest @entity { amount: BigInt! queued: BigInt! claimed: Boolean! + txHash: String! @index } type OGV @entity { id: ID! diff --git a/schema/oeth.graphql b/schema/oeth.graphql index 572a3973..7172b804 100644 --- a/schema/oeth.graphql +++ b/schema/oeth.graphql @@ -180,4 +180,5 @@ type OETHWithdrawalRequest @entity { amount: BigInt! queued: BigInt! claimed: Boolean! + txHash: String! @index } diff --git a/src/model/generated/oethWithdrawalRequest.model.ts b/src/model/generated/oethWithdrawalRequest.model.ts index bd40350a..982d170b 100644 --- a/src/model/generated/oethWithdrawalRequest.model.ts +++ b/src/model/generated/oethWithdrawalRequest.model.ts @@ -31,4 +31,8 @@ export class OETHWithdrawalRequest { @BooleanColumn_({nullable: false}) claimed!: boolean + + @Index_() + @StringColumn_({nullable: false}) + txHash!: string } diff --git a/src/oeth/processors/withdrawals.ts b/src/oeth/processors/withdrawals.ts index 68bc3051..a4b3e27a 100644 --- a/src/oeth/processors/withdrawals.ts +++ b/src/oeth/processors/withdrawals.ts @@ -62,6 +62,7 @@ const processWithdrawalRequested = async ( claimed: false, queued: data._queued, withdrawer: data._withdrawer.toLowerCase(), + txHash: log.transactionHash, }) result.withdrawalRequests.set(withdrawalRequest.id, withdrawalRequest) } From 5797fa2d674dfdd977014b723614be9721405f44 Mon Sep 17 00:00:00 2001 From: toniocodo Date: Thu, 11 Jul 2024 21:07:57 +0200 Subject: [PATCH 10/11] feat: add disable archive flag --- src/processor.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/processor.ts b/src/processor.ts index 435e24cd..bfabdb04 100644 --- a/src/processor.ts +++ b/src/processor.ts @@ -22,8 +22,8 @@ export const createSquidProcessor = ( ) => { const url = process.env[rpc_env] || 'http://localhost:8545' console.log(`RPC URL: ${url}`) - return new EvmBatchProcessor() - .setGateway(lookupArchive(archive)) + + const processor = new EvmBatchProcessor() .setRpcEndpoint({ url, maxBatchCallSize: url.includes('alchemy.com') ? 1 : 100, @@ -59,6 +59,15 @@ export const createSquidProcessor = ( createResultAddress: true, }, }) + + if (process.env.DISABLE_ARCHIVE !== 'true') { + console.log(`Archive: ${archive}`) + processor.setGateway(lookupArchive(archive)) + }else{ + console.log(`Archive disabled`) + } + + return processor } interface Processor { From 007ae84b3d078dfa56b8354738f7df657a17ad18 Mon Sep 17 00:00:00 2001 From: toniocodo Date: Wed, 31 Jul 2024 21:33:30 +0200 Subject: [PATCH 11/11] feat: update block number --- src/oeth/processors/withdrawals.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/oeth/processors/withdrawals.ts b/src/oeth/processors/withdrawals.ts index a4b3e27a..bfcfb2fb 100644 --- a/src/oeth/processors/withdrawals.ts +++ b/src/oeth/processors/withdrawals.ts @@ -5,7 +5,7 @@ import { EvmBatchProcessor } from '@subsquid/evm-processor' import { OETH_VAULT_ADDRESS } from '@utils/addresses' import { logFilter } from '@utils/logFilter' -export const from = 20264539 // TODO update with actual update blocknumber +export const from = 20428558 interface ProcessResult { withdrawalRequests: Map