Skip to content

Commit fe39206

Browse files
committed
Add TraderateChanged for ARM
1 parent dbe7144 commit fe39206

File tree

8 files changed

+108
-32
lines changed

8 files changed

+108
-32
lines changed

db/migrations/1729897704620-Data.js renamed to db/migrations/1730140167059-Data.js

Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schema.graphql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,17 @@ type ArmWithdrawalRequest @entity {
824824
queued: BigInt!
825825
claimed: Boolean!
826826
}
827+
828+
type TraderateChanged @entity {
829+
id: ID!
830+
chainId: Int! @index
831+
txHash: String! @index
832+
timestamp: DateTime! @index
833+
blockNumber: Int! @index
834+
address: String! @index
835+
traderate0: BigInt!
836+
traderate1: BigInt!
837+
}
827838
type CoinGeckoCoinData @entity {
828839
id: ID!
829840
product: String! @index

schema/arm.graphql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,14 @@ type ArmWithdrawalRequest @entity {
7575
queued: BigInt!
7676
claimed: Boolean!
7777
}
78+
79+
type TraderateChanged @entity {
80+
id: ID!
81+
chainId: Int! @index
82+
txHash: String! @index
83+
timestamp: DateTime! @index
84+
blockNumber: Int! @index
85+
address: String! @index
86+
traderate0: BigInt!
87+
traderate1: BigInt!
88+
}

src/model/generated/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export * from "./arm.model"
5757
export * from "./armState.model"
5858
export * from "./armDailyStat.model"
5959
export * from "./armWithdrawalRequest.model"
60+
export * from "./traderateChanged.model"
6061
export * from "./coinGeckoCoinData.model"
6162
export * from "./esToken.model"
6263
export * from "./esAccount.model"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, IntColumn as IntColumn_, Index as Index_, StringColumn as StringColumn_, DateTimeColumn as DateTimeColumn_, BigIntColumn as BigIntColumn_} from "@subsquid/typeorm-store"
2+
3+
@Entity_()
4+
export class TraderateChanged {
5+
constructor(props?: Partial<TraderateChanged>) {
6+
Object.assign(this, props)
7+
}
8+
9+
@PrimaryColumn_()
10+
id!: string
11+
12+
@Index_()
13+
@IntColumn_({nullable: false})
14+
chainId!: number
15+
16+
@Index_()
17+
@StringColumn_({nullable: false})
18+
txHash!: string
19+
20+
@Index_()
21+
@DateTimeColumn_({nullable: false})
22+
timestamp!: Date
23+
24+
@Index_()
25+
@IntColumn_({nullable: false})
26+
blockNumber!: number
27+
28+
@Index_()
29+
@StringColumn_({nullable: false})
30+
address!: string
31+
32+
@BigIntColumn_({nullable: false})
33+
traderate0!: bigint
34+
35+
@BigIntColumn_({nullable: false})
36+
traderate1!: bigint
37+
}

src/oeth/processors/strategies.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,8 @@ const eventProcessors = [
171171
...OETH_NATIVE_STRATEGY_ADDRESSES.map((address) =>
172172
createEventProcessor({
173173
address,
174-
eventName: 'AccountingConsensusRewards',
175174
event: nativeStakingAbi.events.AccountingConsensusRewards,
176175
from: 20046251,
177-
Entity: AccountingConsensusRewards,
178176
mapEntity: (ctx, block, log, decoded) =>
179177
new AccountingConsensusRewards({
180178
id: `${ctx.chain.id}:${log.id}`,
@@ -188,10 +186,8 @@ const eventProcessors = [
188186
),
189187
createEventProcessor({
190188
address: addresses.oeth.nativeStakingFeeAccumulator,
191-
eventName: 'ExecutionRewardsCollected',
192189
event: feeAccumulatorAbi.events.ExecutionRewardsCollected,
193190
from: 20046238,
194-
Entity: ExecutionRewardsCollected,
195191
mapEntity: (ctx, block, log, decoded) =>
196192
new ExecutionRewardsCollected({
197193
id: `${ctx.chain.id}:${log.id}`,

src/templates/events/createEventProcessor.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ import { DecodedStruct, Struct } from '@subsquid/evm-codec'
55
import { EvmBatchProcessor } from '@subsquid/evm-processor'
66
import { Entity } from '@subsquid/typeorm-store/lib/store'
77
import { logFilter } from '@utils/logFilter'
8-
import { EntityClassT } from '@utils/type'
98

109
export const createEventProcessor = <T extends Struct, EventEntity extends Entity>(params: {
11-
eventName: string
1210
event: ReturnType<typeof event<T>>
1311
address: string
1412
from: number
15-
Entity: EntityClassT<EventEntity>
1613
mapEntity: (ctx: Context, block: Block, log: Log, decoded: DecodedStruct<IndexedCodecs<T>>) => EventEntity
1714
extraFilterArgs?: {
1815
topic1?: string[]
@@ -35,7 +32,7 @@ export const createEventProcessor = <T extends Struct, EventEntity extends Entit
3532
for (const log of block.logs) {
3633
if (filter.matches(log)) {
3734
const decoded = params.event.decode(log)
38-
const entity = new params.Entity(params.mapEntity(ctx, block, log, decoded))
35+
const entity = params.mapEntity(ctx, block, log, decoded)
3936
entities.push(entity)
4037
}
4138
}

src/templates/origin-arm/origin-arm.ts

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import { last } from 'lodash'
44
import * as erc20Abi from '@abi/erc20'
55
import * as originLidoArmAbi from '@abi/origin-lido-arm'
66
import * as originLidoArmCapManagerAbi from '@abi/origin-lido-arm-cap-manager'
7-
import { Arm, ArmDailyStat, ArmState, ArmWithdrawalRequest } from '@model'
7+
import { Arm, ArmDailyStat, ArmState, ArmWithdrawalRequest, TraderateChanged } from '@model'
88
import { Block, Context, Processor } from '@processor'
99
import { EvmBatchProcessor } from '@subsquid/evm-processor'
1010
import { createERC20SimpleTracker } from '@templates/erc20-simple'
11+
import { createEventProcessor } from '@templates/events/createEventProcessor'
1112
import { blockFrequencyTracker } from '@utils/blockFrequencyUpdater'
1213
import { calculateAPY } from '@utils/calculateAPY'
1314
import { logFilter } from '@utils/logFilter'
@@ -48,6 +49,23 @@ export const createOriginARMProcessors = ({
4849
topic0: [originLidoArmAbi.events.FeeCollected.topic],
4950
range: { from },
5051
})
52+
const tradeRateProcessor = createEventProcessor({
53+
event: originLidoArmAbi.events.TraderateChanged,
54+
address: armAddress,
55+
from,
56+
mapEntity: (ctx, block, log, decoded) => {
57+
return new TraderateChanged({
58+
id: `${ctx.chain.id}:${log.id}`,
59+
chainId: ctx.chain.id,
60+
txHash: log.transactionHash,
61+
timestamp: new Date(block.header.timestamp),
62+
blockNumber: block.header.height,
63+
address: armAddress,
64+
traderate0: decoded.traderate0,
65+
traderate1: decoded.traderate1,
66+
})
67+
},
68+
})
5169
const tracker = blockFrequencyTracker({ from })
5270
let armEntity: Arm
5371
let initialized = false
@@ -92,6 +110,7 @@ export const createOriginARMProcessors = ({
92110
p.addLog(depositFilter.value)
93111
p.addLog(withdrawalFilter.value)
94112
p.addLog(feeCollectedFilter.value)
113+
tradeRateProcessor.setup(p)
95114
},
96115
initialize,
97116
process: async (ctx: Context) => {
@@ -103,7 +122,7 @@ export const createOriginARMProcessors = ({
103122
const dailyStatsMap = new Map<string, ArmDailyStat>()
104123
const redemptionMap = new Map<string, ArmWithdrawalRequest>()
105124
const getStateId = (block: Block) => `${ctx.chain.id}:${block.header.height}:${armAddress}`
106-
const getPreviousState = async (block: Block) => {
125+
const getPreviousState = async () => {
107126
return (
108127
last(states) ??
109128
(await ctx.store.findOne(ArmState, {
@@ -117,28 +136,19 @@ export const createOriginARMProcessors = ({
117136
if (states[states.length - 1]?.id === stateId) {
118137
return states[states.length - 1]
119138
}
120-
const previousState = await getPreviousState(block)
139+
const previousState = await getPreviousState()
121140
const armContract = new originLidoArmAbi.Contract(ctx, block.header, armAddress)
122141
const controllerContract = new originLidoArmCapManagerAbi.Contract(ctx, block.header, capManagerAddress)
123-
const [
124-
assets0,
125-
assets1,
126-
outstandingAssets1,
127-
totalAssets,
128-
totalAssetsCap,
129-
totalSupply,
130-
assetsPerShare,
131-
feesAccrued,
132-
] = await Promise.all([
133-
new erc20Abi.Contract(ctx, block.header, armEntity.token0).balanceOf(armAddress),
134-
new erc20Abi.Contract(ctx, block.header, armEntity.token1).balanceOf(armAddress),
135-
armContract.lidoWithdrawalQueueAmount(),
136-
armContract.totalAssets(),
137-
controllerContract.totalAssetsCap(),
138-
armContract.totalSupply(),
139-
armContract.previewRedeem(10n ** 18n),
140-
armContract.feesAccrued(),
141-
])
142+
const [assets0, assets1, outstandingAssets1, totalAssets, totalAssetsCap, totalSupply, assetsPerShare] =
143+
await Promise.all([
144+
new erc20Abi.Contract(ctx, block.header, armEntity.token0).balanceOf(armAddress),
145+
new erc20Abi.Contract(ctx, block.header, armEntity.token1).balanceOf(armAddress),
146+
armContract.lidoWithdrawalQueueAmount(),
147+
armContract.totalAssets(),
148+
controllerContract.totalAssetsCap(),
149+
armContract.totalSupply(),
150+
armContract.previewRedeem(10n ** 18n),
151+
])
142152
const date = new Date(block.header.timestamp)
143153
const armStateEntity = new ArmState({
144154
id: stateId,
@@ -259,6 +269,7 @@ export const createOriginARMProcessors = ({
259269
await ctx.store.insert(states)
260270
await ctx.store.upsert([...dailyStatsMap.values()])
261271
await ctx.store.upsert([...redemptionMap.values()])
272+
await tradeRateProcessor.process(ctx)
262273
},
263274
},
264275
// The ARM is an ERC20, so we can use the ERC20SimpleTracker to track holder balances

0 commit comments

Comments
 (0)