From 16cba407c84489ed9e2e8c080c46f85d8d1784ae Mon Sep 17 00:00:00 2001 From: Inkvi Date: Mon, 12 Aug 2024 16:22:28 -0700 Subject: [PATCH] Track wallet txs in OP and Base --- commands.json | 32 ++++++++++++++---- src/chains/wallets.ts | 60 ---------------------------------- src/chains/wallets/base.ts | 38 +++++++++++++++++++++ src/chains/wallets/eth.ts | 35 ++++++++++++++++++++ src/chains/wallets/optimism.ts | 38 +++++++++++++++++++++ src/handlers/wallets.ts | 31 ++++++++++++++++++ src/utils/ibc-processor.ts | 1 + 7 files changed, 169 insertions(+), 66 deletions(-) delete mode 100644 src/chains/wallets.ts create mode 100644 src/chains/wallets/base.ts create mode 100644 src/chains/wallets/eth.ts create mode 100644 src/chains/wallets/optimism.ts create mode 100644 src/handlers/wallets.ts diff --git a/commands.json b/commands.json index 4dd8b3c..0648b77 100644 --- a/commands.json +++ b/commands.json @@ -59,10 +59,20 @@ "deps": ["build", "migration:apply"], "cmd": ["node", "--require=dotenv/config", "lib/chains/backfill.js"] }, - "process:wallets": { + "process:eth:wallets": { "description": "Load .env and start the Wallets squid processor", "deps": ["build", "migration:apply"], - "cmd": ["node", "--require=dotenv/config", "lib/chains/wallets.js"] + "cmd": ["node", "--require=dotenv/config", "lib/chains/wallets/eth.js"] + }, + "process:base:wallets": { + "description": "Load .env and start the Base Wallets squid processor", + "deps": ["build", "migration:apply"], + "cmd": ["node", "--require=dotenv/config", "lib/chains/wallets/base.js"] + }, + "process:optimism:wallets": { + "description": "Load .env and start the Optimism Wallets squid processor", + "deps": ["build", "migration:apply"], + "cmd": ["node", "--require=dotenv/config", "lib/chains/wallets/optimism.js"] }, "process:prod:optimism": { "description": "Start the Optimism squid processor", @@ -80,10 +90,20 @@ "cmd": ["node", "lib/chains/backfill.js"], "hidden": true }, - "process:prod:wallets": { - "description": "Start the wallets squid processor", - "cmd": ["node", "lib/chains/wallets.js"], - "hidden": true + "process:prod:eth:wallets": { + "description": "Start the wallets squid processor", + "cmd": ["node", "lib/chains/wallets/eth.js"], + "hidden": true + }, + "process:prod:base:wallets": { + "description": "Start the wallets squid processor", + "cmd": ["node", "lib/chains/wallets/base.js"], + "hidden": true + }, + "process:prod:optimism:wallets": { + "description": "Start the wallets squid processor", + "cmd": ["node", "lib/chains/wallets/optimism.js"], + "hidden": true }, "serve": { "description": "Start the GraphQL API server", diff --git a/src/chains/wallets.ts b/src/chains/wallets.ts deleted file mode 100644 index 42c0381..0000000 --- a/src/chains/wallets.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { TypeormDatabase } from '@subsquid/typeorm-store' -import { IbcProcessor } from '../utils/ibc-processor' -import { MAX_BATCH_CALL_SIZE, VERSION } from "./constants"; -import { Transaction } from "../model"; - -const ADDRESSES: string[] = [ - process.env.BATCHER_ADDRESS!, - process.env.PROPOSER_ADDRESS!, -] - -let processor = IbcProcessor() - .setRpcEndpoint({ - url: process.env.TXS_RPC!, - rateLimit: Number(process.env.RPC_RATE_LIMIT!), - maxBatchCallSize: MAX_BATCH_CALL_SIZE, - }) - .addTransaction({ - from: ADDRESSES, - }) - .addTransaction({ - to: ADDRESSES, - }) - -if (process.env.TXS_GATEWAY) { - processor = processor.setGateway(process.env.TXS_GATEWAY) -} - -processor.run(new TypeormDatabase({ - supportHotBlocks: true, - isolationLevel: "REPEATABLE READ", - stateSchema: `txs_processor_${VERSION}` - }), - async (ctx) => { - let chainId = Number(await ctx._chain.client.call("eth_chainId")) - - let txs: Transaction[] = [] - for (let block of ctx.blocks) { - for (let tx of block.transactions) { - txs.push(new Transaction({ - id: tx.hash, - transactionHash: tx.hash, - blockNumber: BigInt(block.header.height), - blockTimestamp: BigInt(block.header.timestamp), - chainId: chainId, - from: tx.from, - to: tx.to, - value: BigInt(tx.value), - gas: BigInt(tx.gas), - gasPrice: BigInt(tx.gasPrice), - maxFeePerGas: tx.maxFeePerGas ? BigInt(tx.maxFeePerGas) : null, - maxPriorityFeePerGas: tx.maxPriorityFeePerGas ? BigInt(tx.maxPriorityFeePerGas) : null, - gasUsed: BigInt(tx.gasUsed), - cumulativeGasUsed: BigInt(tx.cumulativeGasUsed), - transactionType: tx.type, - })) - } - } - - await ctx.store.upsert(txs) - }) diff --git a/src/chains/wallets/base.ts b/src/chains/wallets/base.ts new file mode 100644 index 0000000..e8228c1 --- /dev/null +++ b/src/chains/wallets/base.ts @@ -0,0 +1,38 @@ +import { TypeormDatabase } from '@subsquid/typeorm-store' +import { IbcProcessor } from '../../utils/ibc-processor' +import { MAX_BATCH_CALL_SIZE, VERSION } from "../constants"; +import { handler } from "../../handlers/wallets"; + +const ADDRESSES: string[] = [ + process.env.FEE_VAULT_BASE!, + process.env.RELAYER_BASE!, +] + +let processor = IbcProcessor() + .setRpcEndpoint({ + url: process.env.BASE_RPC!, + rateLimit: Number(process.env.RPC_RATE_LIMIT!), + maxBatchCallSize: MAX_BATCH_CALL_SIZE, + }) + .setBlockRange({ + from: Number(process.env.DISPATCHER_ADDRESS_BASE_START_BLOCK!), + }) + .addTransaction({ + from: ADDRESSES, + }) + .addTransaction({ + to: ADDRESSES, + }) + +if (process.env.BASE_TXS_GATEWAY) { + processor = processor.setGateway(process.env.BASE_TXS_GATEWAY) +} + +processor.run(new TypeormDatabase({ + supportHotBlocks: true, + isolationLevel: "REPEATABLE READ", + stateSchema: `base_txs_processor_${VERSION}` + }), + async (ctx) => { + await handler(ctx) + }) diff --git a/src/chains/wallets/eth.ts b/src/chains/wallets/eth.ts new file mode 100644 index 0000000..0eff74b --- /dev/null +++ b/src/chains/wallets/eth.ts @@ -0,0 +1,35 @@ +import { TypeormDatabase } from '@subsquid/typeorm-store' +import { IbcProcessor } from '../../utils/ibc-processor' +import { MAX_BATCH_CALL_SIZE, VERSION } from "../constants"; +import { handler } from "../../handlers/wallets"; + +const ADDRESSES: string[] = [ + process.env.BATCHER_ADDRESS!, + process.env.PROPOSER_ADDRESS!, +] + +let processor = IbcProcessor() + .setRpcEndpoint({ + url: process.env.TXS_RPC!, + rateLimit: Number(process.env.RPC_RATE_LIMIT!), + maxBatchCallSize: MAX_BATCH_CALL_SIZE, + }) + .addTransaction({ + from: ADDRESSES, + }) + .addTransaction({ + to: ADDRESSES, + }) + +if (process.env.TXS_GATEWAY) { + processor = processor.setGateway(process.env.TXS_GATEWAY) +} + +processor.run(new TypeormDatabase({ + supportHotBlocks: true, + isolationLevel: "REPEATABLE READ", + stateSchema: `txs_processor_${VERSION}` + }), + async (ctx) => { + await handler(ctx) + }) diff --git a/src/chains/wallets/optimism.ts b/src/chains/wallets/optimism.ts new file mode 100644 index 0000000..2e937fb --- /dev/null +++ b/src/chains/wallets/optimism.ts @@ -0,0 +1,38 @@ +import { TypeormDatabase } from '@subsquid/typeorm-store' +import { IbcProcessor } from '../../utils/ibc-processor' +import { MAX_BATCH_CALL_SIZE, VERSION } from "../constants"; +import { handler } from "../../handlers/wallets"; + +const ADDRESSES: string[] = [ + process.env.FEE_VAULT_OPTIMISM!, + process.env.RELAYER_OPTIMISM!, +] + +let processor = IbcProcessor() + .setRpcEndpoint({ + url: process.env.OPTIMISM_RPC!, + rateLimit: Number(process.env.RPC_RATE_LIMIT!), + maxBatchCallSize: MAX_BATCH_CALL_SIZE, + }) + .setBlockRange({ + from: Number(process.env.DISPATCHER_ADDRESS_OPTIMISM_START_BLOCK!), + }) + .addTransaction({ + from: ADDRESSES, + }) + .addTransaction({ + to: ADDRESSES, + }) + +if (process.env.OPTIMISM_TXS_GATEWAY) { + processor = processor.setGateway(process.env.OPTIMISM_TXS_GATEWAY) +} + +processor.run(new TypeormDatabase({ + supportHotBlocks: true, + isolationLevel: "REPEATABLE READ", + stateSchema: `optimism_txs_processor_${VERSION}` + }), + async (ctx) => { + await handler(ctx) + }) diff --git a/src/handlers/wallets.ts b/src/handlers/wallets.ts new file mode 100644 index 0000000..bb54560 --- /dev/null +++ b/src/handlers/wallets.ts @@ -0,0 +1,31 @@ +import { Context } from "../utils/types"; +import { Transaction } from "../model"; + +export async function handler(ctx: Context) { + let chainId = Number(await ctx._chain.client.call("eth_chainId")) + + let txs: Transaction[] = [] + for (let block of ctx.blocks) { + for (let tx of block.transactions) { + txs.push(new Transaction({ + id: tx.hash, + transactionHash: tx.hash, + blockNumber: BigInt(block.header.height), + blockTimestamp: BigInt(block.header.timestamp), + chainId: chainId, + from: tx.from, + to: tx.to, + value: BigInt(tx.value), + gas: BigInt(tx.gas), + gasPrice: BigInt(tx.gasPrice), + maxFeePerGas: tx.maxFeePerGas ? BigInt(tx.maxFeePerGas) : null, + maxPriorityFeePerGas: tx.maxPriorityFeePerGas ? BigInt(tx.maxPriorityFeePerGas) : null, + gasUsed: BigInt(tx.gasUsed), + cumulativeGasUsed: BigInt(tx.cumulativeGasUsed), + transactionType: tx.type, + })) + } + } + + await ctx.store.upsert(txs) +} \ No newline at end of file diff --git a/src/utils/ibc-processor.ts b/src/utils/ibc-processor.ts index 6c70d42..24b97ec 100644 --- a/src/utils/ibc-processor.ts +++ b/src/utils/ibc-processor.ts @@ -27,6 +27,7 @@ export function IbcProcessor() { from: true, type: true, value: true, + status: true, } }) }