-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fix from - add in waitForEvents which may prove useful later
- Loading branch information
Showing
5 changed files
with
311 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<typeof events.GovernorshipTransferred> | ||
export type PendingGovernorshipTransferEventArgs = EParams<typeof events.PendingGovernorshipTransfer> | ||
export type UpgradedEventArgs = EParams<typeof events.Upgraded> | ||
|
||
/// Function types | ||
export type AdminParams = FunctionArguments<typeof functions.admin> | ||
export type AdminReturn = FunctionReturn<typeof functions.admin> | ||
|
||
export type ClaimGovernanceParams = FunctionArguments<typeof functions.claimGovernance> | ||
export type ClaimGovernanceReturn = FunctionReturn<typeof functions.claimGovernance> | ||
|
||
export type GovernorParams = FunctionArguments<typeof functions.governor> | ||
export type GovernorReturn = FunctionReturn<typeof functions.governor> | ||
|
||
export type ImplementationParams = FunctionArguments<typeof functions.implementation> | ||
export type ImplementationReturn = FunctionReturn<typeof functions.implementation> | ||
|
||
export type InitializeParams = FunctionArguments<typeof functions.initialize> | ||
export type InitializeReturn = FunctionReturn<typeof functions.initialize> | ||
|
||
export type IsGovernorParams = FunctionArguments<typeof functions.isGovernor> | ||
export type IsGovernorReturn = FunctionReturn<typeof functions.isGovernor> | ||
|
||
export type TransferGovernanceParams = FunctionArguments<typeof functions.transferGovernance> | ||
export type TransferGovernanceReturn = FunctionReturn<typeof functions.transferGovernance> | ||
|
||
export type UpgradeToParams = FunctionArguments<typeof functions.upgradeTo> | ||
export type UpgradeToReturn = FunctionReturn<typeof functions.upgradeTo> | ||
|
||
export type UpgradeToAndCallParams = FunctionArguments<typeof functions.upgradeToAndCall> | ||
export type UpgradeToAndCallReturn = FunctionReturn<typeof functions.upgradeToAndCall> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<boolean> | ||
}): 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++ | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
})) | ||
} |