From 4d2718f8f28798db3b8b9bc242e0faef260081f2 Mon Sep 17 00:00:00 2001 From: Chris Jacobs Date: Thu, 17 Oct 2024 13:33:24 -0700 Subject: [PATCH] feat: arm - fix from - add in waitForEvents which may prove useful later --- abi/governed-upgradeability-proxy.json | 183 +++++++++++++++++++++++ src/abi/governed-upgradeability-proxy.ts | 74 +++++++++ src/main-mainnet.ts | 2 +- src/processor.ts | 2 +- src/utils/waitForEvents.ts | 52 +++++++ 5 files changed, 311 insertions(+), 2 deletions(-) create mode 100644 abi/governed-upgradeability-proxy.json create mode 100644 src/abi/governed-upgradeability-proxy.ts create mode 100644 src/utils/waitForEvents.ts diff --git a/abi/governed-upgradeability-proxy.json b/abi/governed-upgradeability-proxy.json new file mode 100644 index 0000000..67ffd3f --- /dev/null +++ b/abi/governed-upgradeability-proxy.json @@ -0,0 +1,183 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousGovernor", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newGovernor", + "type": "address" + } + ], + "name": "GovernorshipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousGovernor", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newGovernor", + "type": "address" + } + ], + "name": "PendingGovernorshipTransfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "implementation", + "type": "address" + } + ], + "name": "Upgraded", + "type": "event" + }, + { + "stateMutability": "payable", + "type": "fallback" + }, + { + "inputs": [], + "name": "admin", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "claimGovernance", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "governor", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "implementation", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_logic", + "type": "address" + }, + { + "internalType": "address", + "name": "_initGovernor", + "type": "address" + }, + { + "internalType": "bytes", + "name": "_data", + "type": "bytes" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "isGovernor", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_newGovernor", + "type": "address" + } + ], + "name": "transferGovernance", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + } + ], + "name": "upgradeTo", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "upgradeToAndCall", + "outputs": [], + "stateMutability": "payable", + "type": "function" + } +] \ No newline at end of file diff --git a/src/abi/governed-upgradeability-proxy.ts b/src/abi/governed-upgradeability-proxy.ts new file mode 100644 index 0000000..d91b4fe --- /dev/null +++ b/src/abi/governed-upgradeability-proxy.ts @@ -0,0 +1,74 @@ +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 = { + GovernorshipTransferred: event("0xc7c0c772add429241571afb3805861fb3cfa2af374534088b76cdb4325a87e9a", "GovernorshipTransferred(address,address)", {"previousGovernor": indexed(p.address), "newGovernor": indexed(p.address)}), + PendingGovernorshipTransfer: event("0xa39cc5eb22d0f34d8beaefee8a3f17cc229c1a1d1ef87a5ad47313487b1c4f0d", "PendingGovernorshipTransfer(address,address)", {"previousGovernor": indexed(p.address), "newGovernor": indexed(p.address)}), + Upgraded: event("0xbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b", "Upgraded(address)", {"implementation": indexed(p.address)}), +} + +export const functions = { + admin: viewFun("0xf851a440", "admin()", {}, p.address), + claimGovernance: fun("0x5d36b190", "claimGovernance()", {}, ), + governor: viewFun("0x0c340a24", "governor()", {}, p.address), + implementation: viewFun("0x5c60da1b", "implementation()", {}, p.address), + initialize: fun("0xcf7a1d77", "initialize(address,address,bytes)", {"_logic": p.address, "_initGovernor": p.address, "_data": p.bytes}, ), + isGovernor: viewFun("0xc7af3352", "isGovernor()", {}, p.bool), + transferGovernance: fun("0xd38bfff4", "transferGovernance(address)", {"_newGovernor": p.address}, ), + upgradeTo: fun("0x3659cfe6", "upgradeTo(address)", {"newImplementation": p.address}, ), + upgradeToAndCall: fun("0x4f1ef286", "upgradeToAndCall(address,bytes)", {"newImplementation": p.address, "data": p.bytes}, ), +} + +export class Contract extends ContractBase { + + admin() { + return this.eth_call(functions.admin, {}) + } + + governor() { + return this.eth_call(functions.governor, {}) + } + + implementation() { + return this.eth_call(functions.implementation, {}) + } + + isGovernor() { + return this.eth_call(functions.isGovernor, {}) + } +} + +/// Event types +export type GovernorshipTransferredEventArgs = EParams +export type PendingGovernorshipTransferEventArgs = EParams +export type UpgradedEventArgs = EParams + +/// Function types +export type AdminParams = FunctionArguments +export type AdminReturn = FunctionReturn + +export type ClaimGovernanceParams = FunctionArguments +export type ClaimGovernanceReturn = FunctionReturn + +export type GovernorParams = FunctionArguments +export type GovernorReturn = FunctionReturn + +export type ImplementationParams = FunctionArguments +export type ImplementationReturn = FunctionReturn + +export type InitializeParams = FunctionArguments +export type InitializeReturn = FunctionReturn + +export type IsGovernorParams = FunctionArguments +export type IsGovernorReturn = FunctionReturn + +export type TransferGovernanceParams = FunctionArguments +export type TransferGovernanceReturn = FunctionReturn + +export type UpgradeToParams = FunctionArguments +export type UpgradeToReturn = FunctionReturn + +export type UpgradeToAndCallParams = FunctionArguments +export type UpgradeToAndCallReturn = FunctionReturn + diff --git a/src/main-mainnet.ts b/src/main-mainnet.ts index cfdde00..4670219 100644 --- a/src/main-mainnet.ts +++ b/src/main-mainnet.ts @@ -43,7 +43,7 @@ export const processor = { coingeckoProcessor, ...createOriginARMProcessors({ name: 'origin-arm', - from: 20987227, + from: 20987226, armAddress: '0x85b78aca6deae198fbf201c82daf6ca21942acc6', liquidityProviderControllerAddress: '0xf54ebff575f699d281645c6F14Fe427dFFE629CF', }), diff --git a/src/processor.ts b/src/processor.ts index 56b1ddf..b911384 100644 --- a/src/processor.ts +++ b/src/processor.ts @@ -71,7 +71,7 @@ export interface Processor { name?: string from?: number initialize?: (ctx: Context) => Promise // To only be run once per `sqd process`. - setup?: (p: ReturnType, chain: Chain) => void + setup?: (p: ReturnType, chain?: Chain) => void process: (ctx: Context) => Promise } export const createProcessor = (p: Processor) => p diff --git a/src/utils/waitForEvents.ts b/src/utils/waitForEvents.ts new file mode 100644 index 0000000..3d99b7c --- /dev/null +++ b/src/utils/waitForEvents.ts @@ -0,0 +1,52 @@ +import { Context, Processor } from '@processor' + +import { LogFilter } from './logFilter' + +/** + * *** not fully tested *** + */ +export const waitForEvents = ({ + processors, + proxyAddresses, + logFilters, + requirements, +}: { + processors: Processor[] + proxyAddresses: string[] + logFilters: LogFilter[] + requirements: (context: Context) => Promise +}): Processor[] => { + let requirementsMet = 0 + return processors.map((processor) => ({ + ...processor, + setup: async (evmBatchProcessor) => { + for (const logFilter of logFilters) { + evmBatchProcessor.addLog(logFilter.value) + } + processor.setup?.(evmBatchProcessor) + }, + initialize: async (ctx: Context) => { + await processor.initialize?.(ctx) + if (await requirements(ctx)) { + requirementsMet = logFilters.length + } + }, + process: async (ctx: Context) => { + if (requirementsMet >= logFilters.length) { + return processor.process(ctx) + } else { + for (const block of ctx.blocks) { + if (requirementsMet >= logFilters.length) { + return processor.process(ctx) + } else { + for (const filter of logFilters) { + if (block.logs.find((log) => filter.matches(log))) { + requirementsMet++ + } + } + } + } + } + }, + })) +}