Skip to content

Commit

Permalink
Track wallet txs in OP and Base
Browse files Browse the repository at this point in the history
  • Loading branch information
Inkvi authored and Inkvi committed Aug 16, 2024
1 parent 7243809 commit 16cba40
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 66 deletions.
32 changes: 26 additions & 6 deletions commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
60 changes: 0 additions & 60 deletions src/chains/wallets.ts

This file was deleted.

38 changes: 38 additions & 0 deletions src/chains/wallets/base.ts
Original file line number Diff line number Diff line change
@@ -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)
})
35 changes: 35 additions & 0 deletions src/chains/wallets/eth.ts
Original file line number Diff line number Diff line change
@@ -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)
})
38 changes: 38 additions & 0 deletions src/chains/wallets/optimism.ts
Original file line number Diff line number Diff line change
@@ -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)
})
31 changes: 31 additions & 0 deletions src/handlers/wallets.ts
Original file line number Diff line number Diff line change
@@ -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)
}
1 change: 1 addition & 0 deletions src/utils/ibc-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function IbcProcessor() {
from: true,
type: true,
value: true,
status: true,
}
})
}

0 comments on commit 16cba40

Please sign in to comment.