-
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.
Merge pull request #51 from OriginProtocol/feat/oeth-withdrawals
feat: add soeth withdrawal processor
- Loading branch information
Showing
10 changed files
with
3,054 additions
and
8 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,38 @@ | ||
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, DateTimeColumn as DateTimeColumn_, Index as Index_, IntColumn as IntColumn_, BigIntColumn as BigIntColumn_, StringColumn as StringColumn_, BooleanColumn as BooleanColumn_} from "@subsquid/typeorm-store" | ||
|
||
@Entity_() | ||
export class OETHWithdrawalRequest { | ||
constructor(props?: Partial<OETHWithdrawalRequest>) { | ||
Object.assign(this, props) | ||
} | ||
|
||
@PrimaryColumn_() | ||
id!: string | ||
|
||
@Index_() | ||
@DateTimeColumn_({nullable: false}) | ||
timestamp!: Date | ||
|
||
@Index_() | ||
@IntColumn_({nullable: false}) | ||
blockNumber!: number | ||
|
||
@BigIntColumn_({nullable: false}) | ||
requestId!: bigint | ||
|
||
@StringColumn_({nullable: false}) | ||
withdrawer!: string | ||
|
||
@BigIntColumn_({nullable: false}) | ||
amount!: bigint | ||
|
||
@BigIntColumn_({nullable: false}) | ||
queued!: bigint | ||
|
||
@BooleanColumn_({nullable: false}) | ||
claimed!: boolean | ||
|
||
@Index_() | ||
@StringColumn_({nullable: false}) | ||
txHash!: string | ||
} |
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,88 @@ | ||
import * as oethVault from '@abi/oeth-vault' | ||
import { OETHWithdrawalRequest } from '@model' | ||
import { Context } from '@processor' | ||
import { EvmBatchProcessor } from '@subsquid/evm-processor' | ||
import { OETH_VAULT_ADDRESS } from '@utils/addresses' | ||
import { logFilter } from '@utils/logFilter' | ||
|
||
export const from = 20428558 | ||
|
||
interface ProcessResult { | ||
withdrawalRequests: Map<string, OETHWithdrawalRequest> | ||
} | ||
|
||
const withdrawalRequestedFilter = logFilter({ | ||
address: [OETH_VAULT_ADDRESS], | ||
topic0: [oethVault.events.WithdrawalRequested.topic], | ||
range: { from }, | ||
}) | ||
const withdrawalClaimedFilter = logFilter({ | ||
address: [OETH_VAULT_ADDRESS], | ||
topic0: [oethVault.events.WithdrawalClaimed.topic], | ||
range: { from }, | ||
}) | ||
|
||
export const setup = (processor: EvmBatchProcessor) => { | ||
processor.addLog(withdrawalRequestedFilter.value) | ||
processor.addLog(withdrawalClaimedFilter.value) | ||
} | ||
|
||
export const process = async (ctx: Context) => { | ||
const result: ProcessResult = { | ||
withdrawalRequests: new Map<string, OETHWithdrawalRequest>(), | ||
} | ||
|
||
for (const block of ctx.blocks) { | ||
for (const log of block.logs) { | ||
if (withdrawalRequestedFilter.matches(log)) { | ||
await processWithdrawalRequested(ctx, result, block, log) | ||
} else if (withdrawalClaimedFilter.matches(log)) { | ||
await processWithdrawalClaimed(ctx, result, block, log) | ||
} | ||
} | ||
} | ||
|
||
await ctx.store.upsert([...result.withdrawalRequests.values()]) | ||
} | ||
|
||
const processWithdrawalRequested = async ( | ||
ctx: Context, | ||
result: ProcessResult, | ||
block: Context['blocks'][number], | ||
log: Context['blocks'][number]['logs'][number], | ||
) => { | ||
const data = oethVault.events.WithdrawalRequested.decode(log) | ||
|
||
const withdrawalRequest = new OETHWithdrawalRequest({ | ||
id: `${data._withdrawer.toLowerCase()}:${data._requestId}`, | ||
blockNumber: block.header.height, | ||
timestamp: new Date(block.header.timestamp), | ||
requestId: data._requestId, | ||
amount: data._amount, | ||
claimed: false, | ||
queued: data._queued, | ||
withdrawer: data._withdrawer.toLowerCase(), | ||
txHash: log.transactionHash, | ||
}) | ||
result.withdrawalRequests.set(withdrawalRequest.id, withdrawalRequest) | ||
} | ||
|
||
const processWithdrawalClaimed = async ( | ||
ctx: Context, | ||
result: ProcessResult, | ||
block: Context['blocks'][number], | ||
log: Context['blocks'][number]['logs'][number], | ||
) => { | ||
const data = oethVault.events.WithdrawalClaimed.decode(log) | ||
const id = `${data._withdrawer.toLowerCase()}:${data._requestId}` | ||
let updated | ||
if (result.withdrawalRequests.has(id)) { | ||
updated = result.withdrawalRequests.get(id) | ||
} else { | ||
updated = await ctx.store.findOneBy(OETHWithdrawalRequest, { id }) | ||
} | ||
if (updated) { | ||
updated.claimed = true | ||
result.withdrawalRequests.set(id, updated) | ||
} | ||
} |
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