Skip to content

Commit

Permalink
Merge pull request #51 from OriginProtocol/feat/oeth-withdrawals
Browse files Browse the repository at this point in the history
feat: add soeth withdrawal processor
  • Loading branch information
apexearth authored Jul 31, 2024
2 parents 5e08410 + cc54587 commit ab8888e
Show file tree
Hide file tree
Showing 10 changed files with 3,054 additions and 8 deletions.
1,648 changes: 1,648 additions & 0 deletions abi/oeth-vault.json

Large diffs are not rendered by default.

715 changes: 715 additions & 0 deletions db/migrations/1721737477772-Data.js

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,7 @@ type OETHStrategyDailyStat @entity {
"""
Total ETH value
"""
holdings: [OETHStrategyHoldingDailyStat]
@derivedFrom(field: "strategyDailyStatId")
holdings: [OETHStrategyHoldingDailyStat] @derivedFrom(field: "strategyDailyStatId")
}

type OETHStrategyHoldingDailyStat @entity {
Expand Down Expand Up @@ -742,7 +741,20 @@ type OETHRewardTokenCollected @entity {
recipient: String!
rewardToken: String!
amount: BigInt!
}type OGV @entity {
}

type OETHWithdrawalRequest @entity {
id: ID!
timestamp: DateTime! @index
blockNumber: Int! @index
requestId: BigInt!
withdrawer: String!
amount: BigInt!
queued: BigInt!
claimed: Boolean!
txHash: String! @index
}
type OGV @entity {
id: ID!
timestamp: DateTime! @index
blockNumber: Int! @index
Expand Down
17 changes: 14 additions & 3 deletions schema/oeth.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ type OETHStrategyDailyStat @entity {
"""
Total ETH value
"""
holdings: [OETHStrategyHoldingDailyStat]
@derivedFrom(field: "strategyDailyStatId")
holdings: [OETHStrategyHoldingDailyStat] @derivedFrom(field: "strategyDailyStatId")
}

type OETHStrategyHoldingDailyStat @entity {
Expand Down Expand Up @@ -170,4 +169,16 @@ type OETHRewardTokenCollected @entity {
recipient: String!
rewardToken: String!
amount: BigInt!
}
}

type OETHWithdrawalRequest @entity {
id: ID!
timestamp: DateTime! @index
blockNumber: Int! @index
requestId: BigInt!
withdrawer: String!
amount: BigInt!
queued: BigInt!
claimed: Boolean!
txHash: String! @index
}
522 changes: 522 additions & 0 deletions src/abi/oeth-vault.ts

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/main-oeth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as fraxStaking from './oeth/processors/frax-staking'
import * as morphoAave from './oeth/processors/morpho-aave'
import * as strategies from './oeth/processors/strategies'
import * as vault from './oeth/processors/vault'
import * as withdrawals from './oeth/processors/withdrawals'
import * as validateOeth from './oeth/validators/validate-oeth'

export const processor = {
Expand All @@ -30,6 +31,7 @@ export const processor = {
balancerMetaPoolStrategy,
strategies,
exchangeRates,
withdrawals,
],
postProcessors: [exchangeRatesPostProcessor, dailyStats, processStatus('oeth')],
validators: [validateOeth],
Expand Down
1 change: 1 addition & 0 deletions src/model/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export * from "./oethStrategyDailyStat.model"
export * from "./oethStrategyHoldingDailyStat.model"
export * from "./oethCollateralDailyStat.model"
export * from "./oethRewardTokenCollected.model"
export * from "./oethWithdrawalRequest.model"
export * from "./ogv.model"
export * from "./ogvAddress.model"
export * from "./ogvLockupTxLog.model"
Expand Down
38 changes: 38 additions & 0 deletions src/model/generated/oethWithdrawalRequest.model.ts
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
}
88 changes: 88 additions & 0 deletions src/oeth/processors/withdrawals.ts
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)
}
}
13 changes: 11 additions & 2 deletions src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export const createSquidProcessor = (
) => {
const url = process.env[rpc_env] || 'http://localhost:8545'
console.log(`RPC URL: ${url}`)
return new EvmBatchProcessor()
.setGateway(lookupArchive(archive))

const processor = new EvmBatchProcessor()
.setRpcEndpoint({
url,
maxBatchCallSize: url.includes('alchemy.com') ? 1 : 100,
Expand Down Expand Up @@ -59,6 +59,15 @@ export const createSquidProcessor = (
createResultAddress: true,
},
})

if (process.env.DISABLE_ARCHIVE !== 'true') {
console.log(`Archive: ${archive}`)
processor.setGateway(lookupArchive(archive))
}else{
console.log(`Archive disabled`)
}

return processor
}

interface Processor {
Expand Down

0 comments on commit ab8888e

Please sign in to comment.