From 1c3fd3520f615b17332b919b0ee636bedb17b5c1 Mon Sep 17 00:00:00 2001 From: Timur Badretdinov Date: Mon, 18 Mar 2024 23:20:42 +0000 Subject: [PATCH] Conditional contract indexing based on env var --- ponder.config.ts | 683 +++++++++++++++++++++++------------------- src/entryPoint_0_6.ts | 36 ++- src/entryPoint_0_7.ts | 36 ++- src/utils.ts | 7 + 4 files changed, 420 insertions(+), 342 deletions(-) create mode 100644 src/utils.ts diff --git a/ponder.config.ts b/ponder.config.ts index 43adb7b..da71126 100644 --- a/ponder.config.ts +++ b/ponder.config.ts @@ -3,6 +3,7 @@ import { http } from 'viem'; import entryPoint06Abi from './abi/entryPoint_0_6'; import entryPoint07Abi from './abi/entryPoint_0_7'; +import { isIndexing0_6, isIndexing0_7 } from './src/utils'; const ENTRYPOINT_0_6_ADDRESS = '0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789'; const ENTRYPOINT_0_7_ADDRESS = '0x0000000071727de22e5e9d8baf0edac6f37da032'; @@ -128,322 +129,384 @@ export default createConfig({ abi: entryPoint06Abi, address: ENTRYPOINT_0_6_ADDRESS, network: { - ethereum: process.env.PONDER_RPC_URL_1 - ? { - startBlock: 17012204, - } - : undefined, - goerli: process.env.PONDER_RPC_URL_5 - ? { - startBlock: 8801632, - } - : undefined, - sepolia: process.env.PONDER_RPC_URL_11155111 - ? { - startBlock: 3257815, - } - : undefined, - bsc: process.env.PONDER_RPC_URL_56 - ? { - startBlock: 27202729, - } - : undefined, - bscTestnet: process.env.PONDER_RPC_URL_97 - ? { - startBlock: 28789129, - } - : undefined, - polygon: process.env.PONDER_RPC_URL_137 - ? { - startBlock: 41335185, - } - : undefined, - polygonMumbai: process.env.PONDER_RPC_URL_80001 - ? { - startBlock: 34166156, - } - : undefined, - polygonZkevm: process.env.PONDER_RPC_URL_1101 - ? { - startBlock: 184258, - } - : undefined, - polygonZkevmTestnet: process.env.PONDER_RPC_URL_1442 - ? { - startBlock: 578113, - } - : undefined, - fantom: process.env.PONDER_RPC_URL_250 - ? { - startBlock: 63515111, - } - : undefined, - fantomTestnet: process.env.PONDER_RPC_URL_4002 - ? { - startBlock: 15987221, - } - : undefined, - opMainnet: process.env.PONDER_RPC_URL_10 - ? { - startBlock: 88234528, - } - : undefined, - opSepolia: process.env.PONDER_RPC_URL_11155420 - ? { - startBlock: 3593614, - } - : undefined, - arbitrum: process.env.PONDER_RPC_URL_42161 - ? { - startBlock: 78720307, - } - : undefined, - arbitrumSepolia: process.env.PONDER_RPC_URL_421614 - ? { - startBlock: 623334, - } - : undefined, - arbitrumNova: process.env.PONDER_RPC_URL_42170 - ? { - startBlock: 7494602, - } - : undefined, - moonriver: process.env.PONDER_RPC_URL_1285 - ? { - startBlock: 4798917, - } - : undefined, - moonbeam: process.env.PONDER_RPC_URL_1284 - ? { - startBlock: 4026730, - } - : undefined, - moonbaseAlpha: process.env.PONDER_RPC_URL_1287 - ? { - startBlock: 4735374, - } - : undefined, - cronos: process.env.PONDER_RPC_URL_25 - ? { - startBlock: 9728229, - } - : undefined, - gnosis: process.env.PONDER_RPC_URL_100 - ? { - startBlock: 27364185, - } - : undefined, - gnosisChiado: process.env.PONDER_RPC_URL_10200 - ? { - startBlock: 3728232, - } - : undefined, - celo: process.env.PONDER_RPC_URL_42220 - ? { - startBlock: 21062508, - } - : undefined, - celoAlfajores: process.env.PONDER_RPC_URL_44787 - ? { - startBlock: 17649236, - } - : undefined, - linea: process.env.PONDER_RPC_URL_59144 - ? { - startBlock: 915, - } - : undefined, - lineaTestnet: process.env.PONDER_RPC_URL_59140 - ? { - startBlock: 465300, - } - : undefined, - base: process.env.PONDER_RPC_URL_8453 - ? { - startBlock: 1854367, - } - : undefined, - baseSepolia: process.env.PONDER_RPC_URL_84532 - ? { - startBlock: 1128910, - } - : undefined, - scroll: process.env.PONDER_RPC_URL_534352 - ? { - startBlock: 17, - } - : undefined, - scrollSepolia: process.env.PONDER_RPC_URL_534351 - ? { - startBlock: 91, - } - : undefined, - opBnb: process.env.PONDER_RPC_URL_204 - ? { - startBlock: 1125290, - } - : undefined, - opBnbTestnet: process.env.PONDER_RPC_URL_5611 - ? { - startBlock: 2108065, - } - : undefined, - kroma: process.env.PONDER_RPC_URL_255 - ? { - startBlock: 5197622, - } - : undefined, - kromaTestnet: process.env.PONDER_RPC_URL_2358 - ? { - startBlock: 7783408, - } - : undefined, - avalancheC: process.env.PONDER_RPC_URL_43114 - ? { - startBlock: 28865255, - } - : undefined, - avalancheFuji: process.env.PONDER_RPC_URL_43113 - ? { - startBlock: 20797033, - } - : undefined, - zora: process.env.PONDER_RPC_URL_7777777 - ? { - startBlock: 5223236, - } - : undefined, - zoraSepolia: process.env.PONDER_RPC_URL_999999999 - ? { - startBlock: 3465249, - } - : undefined, + ethereum: + process.env.PONDER_RPC_URL_1 && isIndexing0_6 + ? { + startBlock: 17012204, + } + : undefined, + goerli: + process.env.PONDER_RPC_URL_5 && isIndexing0_6 + ? { + startBlock: 8801632, + } + : undefined, + sepolia: + process.env.PONDER_RPC_URL_11155111 && isIndexing0_6 + ? { + startBlock: 3257815, + } + : undefined, + bsc: + process.env.PONDER_RPC_URL_56 && isIndexing0_6 + ? { + startBlock: 27202729, + } + : undefined, + bscTestnet: + process.env.PONDER_RPC_URL_97 && isIndexing0_6 + ? { + startBlock: 28789129, + } + : undefined, + polygon: + process.env.PONDER_RPC_URL_137 && isIndexing0_6 + ? { + startBlock: 41335185, + } + : undefined, + polygonMumbai: + process.env.PONDER_RPC_URL_80001 && isIndexing0_6 + ? { + startBlock: 34166156, + } + : undefined, + polygonZkevm: + process.env.PONDER_RPC_URL_1101 && isIndexing0_6 + ? { + startBlock: 184258, + } + : undefined, + polygonZkevmTestnet: + process.env.PONDER_RPC_URL_1442 && isIndexing0_6 + ? { + startBlock: 578113, + } + : undefined, + fantom: + process.env.PONDER_RPC_URL_250 && isIndexing0_6 + ? { + startBlock: 63515111, + } + : undefined, + fantomTestnet: + process.env.PONDER_RPC_URL_4002 && isIndexing0_6 + ? { + startBlock: 15987221, + } + : undefined, + opMainnet: + process.env.PONDER_RPC_URL_10 && isIndexing0_6 + ? { + startBlock: 88234528, + } + : undefined, + opSepolia: + process.env.PONDER_RPC_URL_11155420 && isIndexing0_6 + ? { + startBlock: 3593614, + } + : undefined, + arbitrum: + process.env.PONDER_RPC_URL_42161 && isIndexing0_6 + ? { + startBlock: 78720307, + } + : undefined, + arbitrumSepolia: + process.env.PONDER_RPC_URL_421614 && isIndexing0_6 + ? { + startBlock: 623334, + } + : undefined, + arbitrumNova: + process.env.PONDER_RPC_URL_42170 && isIndexing0_6 + ? { + startBlock: 7494602, + } + : undefined, + moonriver: + process.env.PONDER_RPC_URL_1285 && isIndexing0_6 + ? { + startBlock: 4798917, + } + : undefined, + moonbeam: + process.env.PONDER_RPC_URL_1284 && isIndexing0_6 + ? { + startBlock: 4026730, + } + : undefined, + moonbaseAlpha: + process.env.PONDER_RPC_URL_1287 && isIndexing0_6 + ? { + startBlock: 4735374, + } + : undefined, + cronos: + process.env.PONDER_RPC_URL_25 && isIndexing0_6 + ? { + startBlock: 9728229, + } + : undefined, + gnosis: + process.env.PONDER_RPC_URL_100 && isIndexing0_6 + ? { + startBlock: 27364185, + } + : undefined, + gnosisChiado: + process.env.PONDER_RPC_URL_10200 && isIndexing0_6 + ? { + startBlock: 3728232, + } + : undefined, + celo: + process.env.PONDER_RPC_URL_42220 && isIndexing0_6 + ? { + startBlock: 21062508, + } + : undefined, + celoAlfajores: + process.env.PONDER_RPC_URL_44787 && isIndexing0_6 + ? { + startBlock: 17649236, + } + : undefined, + linea: + process.env.PONDER_RPC_URL_59144 && isIndexing0_6 + ? { + startBlock: 915, + } + : undefined, + lineaTestnet: + process.env.PONDER_RPC_URL_59140 && isIndexing0_6 + ? { + startBlock: 465300, + } + : undefined, + base: + process.env.PONDER_RPC_URL_8453 && isIndexing0_6 + ? { + startBlock: 1854367, + } + : undefined, + baseSepolia: + process.env.PONDER_RPC_URL_84532 && isIndexing0_6 + ? { + startBlock: 1128910, + } + : undefined, + scroll: + process.env.PONDER_RPC_URL_534352 && isIndexing0_6 + ? { + startBlock: 17, + } + : undefined, + scrollSepolia: + process.env.PONDER_RPC_URL_534351 && isIndexing0_6 + ? { + startBlock: 91, + } + : undefined, + opBnb: + process.env.PONDER_RPC_URL_204 && isIndexing0_6 + ? { + startBlock: 1125290, + } + : undefined, + opBnbTestnet: + process.env.PONDER_RPC_URL_5611 && isIndexing0_6 + ? { + startBlock: 2108065, + } + : undefined, + kroma: + process.env.PONDER_RPC_URL_255 && isIndexing0_6 + ? { + startBlock: 5197622, + } + : undefined, + kromaTestnet: + process.env.PONDER_RPC_URL_2358 && isIndexing0_6 + ? { + startBlock: 7783408, + } + : undefined, + avalancheC: + process.env.PONDER_RPC_URL_43114 && isIndexing0_6 + ? { + startBlock: 28865255, + } + : undefined, + avalancheFuji: + process.env.PONDER_RPC_URL_43113 && isIndexing0_6 + ? { + startBlock: 20797033, + } + : undefined, + zora: + process.env.PONDER_RPC_URL_7777777 && isIndexing0_6 + ? { + startBlock: 5223236, + } + : undefined, + zoraSepolia: + process.env.PONDER_RPC_URL_999999999 && isIndexing0_6 + ? { + startBlock: 3465249, + } + : undefined, }, }, 'EntryPoint0.7': { abi: entryPoint07Abi, address: ENTRYPOINT_0_7_ADDRESS, network: { - ethereum: process.env.PONDER_RPC_URL_1 - ? { - startBlock: 19274877, - } - : undefined, - goerli: process.env.PONDER_RPC_URL_5 - ? { - startBlock: 10568981, - } - : undefined, - sepolia: process.env.PONDER_RPC_URL_11155111 - ? { - startBlock: 5328753, - } - : undefined, - bsc: process.env.PONDER_RPC_URL_56 - ? { - startBlock: 36326227, - } - : undefined, - bscTestnet: process.env.PONDER_RPC_URL_97 - ? { - startBlock: 38058129, - } - : undefined, - polygon: process.env.PONDER_RPC_URL_137 - ? { - startBlock: 53784988, - } - : undefined, - polygonMumbai: process.env.PONDER_RPC_URL_80001 - ? { - startBlock: 46345465, - } - : undefined, - opMainnet: process.env.PONDER_RPC_URL_10 - ? { - startBlock: 116453058, - } - : undefined, - opSepolia: process.env.PONDER_RPC_URL_11155420 - ? { - startBlock: 8448043, - } - : undefined, - arbitrum: process.env.PONDER_RPC_URL_42161 - ? { - startBlock: 182947891, - } - : undefined, - arbitrumSepolia: process.env.PONDER_RPC_URL_421614 - ? { - startBlock: 16853333, - } - : undefined, - gnosis: process.env.PONDER_RPC_URL_100 - ? { - startBlock: 32559861, - } - : undefined, - celo: process.env.PONDER_RPC_URL_42220 - ? { - startBlock: 24242863, - } - : undefined, - celoAlfajores: process.env.PONDER_RPC_URL_44787 - ? { - startBlock: 22698902, - } - : undefined, - linea: process.env.PONDER_RPC_URL_59144 - ? { - startBlock: 2506675, - } - : undefined, - base: process.env.PONDER_RPC_URL_8453 - ? { - startBlock: 10920348, - } - : undefined, - baseSepolia: process.env.PONDER_RPC_URL_84532 - ? { - startBlock: 6556474, - } - : undefined, - scroll: process.env.PONDER_RPC_URL_534352 - ? { - startBlock: 3591634, - } - : undefined, - scrollSepolia: process.env.PONDER_RPC_URL_534351 - ? { - startBlock: 3061869, - } - : undefined, - opBnb: process.env.PONDER_RPC_URL_204 - ? { - startBlock: 17130896, - } - : undefined, - avalancheC: process.env.PONDER_RPC_URL_43114 - ? { - startBlock: 41958878, - } - : undefined, - avalancheFuji: process.env.PONDER_RPC_URL_43113 - ? { - startBlock: 30305092, - } - : undefined, - zora: process.env.PONDER_RPC_URL_7777777 - ? { - startBlock: 11017288, - } - : undefined, - zoraSepolia: process.env.PONDER_RPC_URL_999999999 - ? { - startBlock: 5324224, - } - : undefined, + ethereum: + process.env.PONDER_RPC_URL_1 && isIndexing0_7 + ? { + startBlock: 19274877, + } + : undefined, + goerli: + process.env.PONDER_RPC_URL_5 && isIndexing0_7 + ? { + startBlock: 10568981, + } + : undefined, + sepolia: + process.env.PONDER_RPC_URL_11155111 && isIndexing0_7 + ? { + startBlock: 5328753, + } + : undefined, + bsc: + process.env.PONDER_RPC_URL_56 && isIndexing0_7 + ? { + startBlock: 36326227, + } + : undefined, + bscTestnet: + process.env.PONDER_RPC_URL_97 && isIndexing0_7 + ? { + startBlock: 38058129, + } + : undefined, + polygon: + process.env.PONDER_RPC_URL_137 && isIndexing0_7 + ? { + startBlock: 53784988, + } + : undefined, + polygonMumbai: + process.env.PONDER_RPC_URL_80001 && isIndexing0_7 + ? { + startBlock: 46345465, + } + : undefined, + opMainnet: + process.env.PONDER_RPC_URL_10 && isIndexing0_7 + ? { + startBlock: 116453058, + } + : undefined, + opSepolia: + process.env.PONDER_RPC_URL_11155420 && isIndexing0_7 + ? { + startBlock: 8448043, + } + : undefined, + arbitrum: + process.env.PONDER_RPC_URL_42161 && isIndexing0_7 + ? { + startBlock: 182947891, + } + : undefined, + arbitrumSepolia: + process.env.PONDER_RPC_URL_421614 && isIndexing0_7 + ? { + startBlock: 16853333, + } + : undefined, + gnosis: + process.env.PONDER_RPC_URL_100 && isIndexing0_7 + ? { + startBlock: 32559861, + } + : undefined, + celo: + process.env.PONDER_RPC_URL_42220 && isIndexing0_7 + ? { + startBlock: 24242863, + } + : undefined, + celoAlfajores: + process.env.PONDER_RPC_URL_44787 && isIndexing0_7 + ? { + startBlock: 22698902, + } + : undefined, + linea: + process.env.PONDER_RPC_URL_59144 && isIndexing0_7 + ? { + startBlock: 2506675, + } + : undefined, + base: + process.env.PONDER_RPC_URL_8453 && isIndexing0_7 + ? { + startBlock: 10920348, + } + : undefined, + baseSepolia: + process.env.PONDER_RPC_URL_84532 && isIndexing0_7 + ? { + startBlock: 6556474, + } + : undefined, + scroll: + process.env.PONDER_RPC_URL_534352 && isIndexing0_7 + ? { + startBlock: 3591634, + } + : undefined, + scrollSepolia: + process.env.PONDER_RPC_URL_534351 && isIndexing0_7 + ? { + startBlock: 3061869, + } + : undefined, + opBnb: + process.env.PONDER_RPC_URL_204 && isIndexing0_7 + ? { + startBlock: 17130896, + } + : undefined, + avalancheC: + process.env.PONDER_RPC_URL_43114 && isIndexing0_7 + ? { + startBlock: 41958878, + } + : undefined, + avalancheFuji: + process.env.PONDER_RPC_URL_43113 && isIndexing0_7 + ? { + startBlock: 30305092, + } + : undefined, + zora: + process.env.PONDER_RPC_URL_7777777 && isIndexing0_7 + ? { + startBlock: 11017288, + } + : undefined, + zoraSepolia: + process.env.PONDER_RPC_URL_999999999 && isIndexing0_7 + ? { + startBlock: 5324224, + } + : undefined, }, }, }, diff --git a/src/entryPoint_0_6.ts b/src/entryPoint_0_6.ts index 9aa1d0a..f45cad1 100644 --- a/src/entryPoint_0_6.ts +++ b/src/entryPoint_0_6.ts @@ -1,19 +1,23 @@ import { ponder } from '@/generated'; -ponder.on('EntryPoint0.6:UserOperationEvent', async ({ event, context }) => { - await context.db.UserOp.create({ - id: `${context.network.chainId}-${event.args.userOpHash}`, - data: { - hash: event.args.userOpHash, - chainId: context.network.chainId, - txHash: event.transaction.hash, - actualGasCost: event.args.actualGasCost, - actualGasUsed: event.args.actualGasUsed, - nonce: event.args.nonce, - paymaster: event.args.paymaster, - sender: event.args.sender, - success: event.args.success, - entryPoint: event.log.address, - }, +import { isIndexing0_6 } from './utils'; + +if (isIndexing0_6) { + ponder.on('EntryPoint0.6:UserOperationEvent', async ({ event, context }) => { + await context.db.UserOp.create({ + id: `${context.network.chainId}-${event.args.userOpHash}`, + data: { + hash: event.args.userOpHash, + chainId: context.network.chainId, + txHash: event.transaction.hash, + actualGasCost: event.args.actualGasCost, + actualGasUsed: event.args.actualGasUsed, + nonce: event.args.nonce, + paymaster: event.args.paymaster, + sender: event.args.sender, + success: event.args.success, + entryPoint: event.log.address, + }, + }); }); -}); +} diff --git a/src/entryPoint_0_7.ts b/src/entryPoint_0_7.ts index 2d1c302..c9739c0 100644 --- a/src/entryPoint_0_7.ts +++ b/src/entryPoint_0_7.ts @@ -1,19 +1,23 @@ import { ponder } from '@/generated'; -ponder.on('EntryPoint0.7:UserOperationEvent', async ({ event, context }) => { - await context.db.UserOp.create({ - id: `${context.network.chainId}-${event.args.userOpHash}`, - data: { - hash: event.args.userOpHash, - chainId: context.network.chainId, - txHash: event.transaction.hash, - actualGasCost: event.args.actualGasCost, - actualGasUsed: event.args.actualGasUsed, - nonce: event.args.nonce, - paymaster: event.args.paymaster, - sender: event.args.sender, - success: event.args.success, - entryPoint: event.log.address, - }, +import { isIndexing0_7 } from './utils'; + +if (isIndexing0_7) { + ponder.on('EntryPoint0.7:UserOperationEvent', async ({ event, context }) => { + await context.db.UserOp.create({ + id: `${context.network.chainId}-${event.args.userOpHash}`, + data: { + hash: event.args.userOpHash, + chainId: context.network.chainId, + txHash: event.transaction.hash, + actualGasCost: event.args.actualGasCost, + actualGasUsed: event.args.actualGasUsed, + nonce: event.args.nonce, + paymaster: event.args.paymaster, + sender: event.args.sender, + success: event.args.success, + entryPoint: event.log.address, + }, + }); }); -}); +} diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..34541a1 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,7 @@ +const ponderEntryPointVersion = process.env.PONDER_ENTRYPOINT_VERSION || '0.7'; +const isIndexing0_6 = + ponderEntryPointVersion === '0.6' || ponderEntryPointVersion === 'all'; +const isIndexing0_7 = + ponderEntryPointVersion === '0.7' || ponderEntryPointVersion === 'all'; + +export { isIndexing0_6, isIndexing0_7 };