Skip to content

Commit

Permalink
feat: arm
Browse files Browse the repository at this point in the history
- fix from
- add in waitForEvents which may prove useful later
  • Loading branch information
apexearth committed Oct 17, 2024
1 parent a99ae9b commit 4d2718f
Show file tree
Hide file tree
Showing 5 changed files with 311 additions and 2 deletions.
183 changes: 183 additions & 0 deletions abi/governed-upgradeability-proxy.json
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"
}
]
74 changes: 74 additions & 0 deletions src/abi/governed-upgradeability-proxy.ts
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>

2 changes: 1 addition & 1 deletion src/main-mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const processor = {
coingeckoProcessor,
...createOriginARMProcessors({
name: 'origin-arm',
from: 20987227,
from: 20987226,
armAddress: '0x85b78aca6deae198fbf201c82daf6ca21942acc6',
liquidityProviderControllerAddress: '0xf54ebff575f699d281645c6F14Fe427dFFE629CF',
}),
Expand Down
2 changes: 1 addition & 1 deletion src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export interface Processor {
name?: string
from?: number
initialize?: (ctx: Context) => Promise<void> // To only be run once per `sqd process`.
setup?: (p: ReturnType<typeof createSquidProcessor>, chain: Chain) => void
setup?: (p: ReturnType<typeof createSquidProcessor>, chain?: Chain) => void
process: (ctx: Context) => Promise<void>
}
export const createProcessor = (p: Processor) => p
Expand Down
52 changes: 52 additions & 0 deletions src/utils/waitForEvents.ts
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++
}
}
}
}
}
},
}))
}

0 comments on commit 4d2718f

Please sign in to comment.