Skip to content

Commit 7a377e3

Browse files
committed
v55
- fix how fees are tracked
1 parent 4ea5fed commit 7a377e3

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ export const createOriginARMProcessors = ({
4343
topic0: [originLidoArmAbi.events.RedeemRequested.topic],
4444
range: { from },
4545
})
46+
const feeCollectedFilter = logFilter({
47+
address: [armAddress],
48+
topic0: [originLidoArmAbi.events.FeeCollected.topic],
49+
range: { from },
50+
})
4651
const tracker = blockFrequencyTracker({ from })
4752
let armEntity: Arm
4853
let initialized = false
@@ -86,6 +91,7 @@ export const createOriginARMProcessors = ({
8691
p.addLog(redeemClaimedFilter.value)
8792
p.addLog(depositFilter.value)
8893
p.addLog(withdrawalFilter.value)
94+
p.addLog(feeCollectedFilter.value)
8995
},
9096
initialize,
9197
process: async (ctx: Context) => {
@@ -106,7 +112,7 @@ export const createOriginARMProcessors = ({
106112
}))
107113
)
108114
}
109-
const getCurrentState = async (block: Block, extra?: { deposit: bigint; withdrawal: bigint }) => {
115+
const getCurrentState = async (block: Block) => {
110116
const stateId = getStateId(block)
111117
if (states[states.length - 1]?.id === stateId) {
112118
return states[states.length - 1]
@@ -147,9 +153,9 @@ export const createOriginARMProcessors = ({
147153
totalAssetsCap,
148154
totalSupply,
149155
assetsPerShare,
150-
totalDeposits: (previousState?.totalDeposits ?? 0n) + (extra?.deposit ?? 0n),
151-
totalWithdrawals: (previousState?.totalWithdrawals ?? 0n) + (extra?.withdrawal ?? 0n),
152-
totalFees: feesAccrued,
156+
totalDeposits: previousState?.totalDeposits ?? 0n,
157+
totalWithdrawals: previousState?.totalWithdrawals ?? 0n,
158+
totalFees: previousState?.totalFees ?? 0n,
153159
totalYield: 0n,
154160
})
155161
armStateEntity.totalYield = calculateTotalYield(armStateEntity)
@@ -159,7 +165,6 @@ export const createOriginARMProcessors = ({
159165
const calculateTotalYield = (state: ArmState) =>
160166
state.totalAssets - state.totalDeposits + state.totalWithdrawals
161167

162-
// ArmWithdrawalRequest
163168
for (const block of ctx.blocks) {
164169
if (tracker(ctx, block)) {
165170
// ArmState
@@ -204,6 +209,7 @@ export const createOriginARMProcessors = ({
204209
dailyStatsMap.set(currentDayId, armDailyStatEntity)
205210
}
206211
for (const log of block.logs) {
212+
// ArmWithdrawalRequest
207213
if (redeemRequestedFilter.matches(log)) {
208214
const event = originLidoArmAbi.events.RedeemRequested.decode(log)
209215
const eventId = `${ctx.chain.id}:${armAddress}:${event.requestId}`
@@ -243,6 +249,11 @@ export const createOriginARMProcessors = ({
243249
state.totalWithdrawals += event.assets
244250
state.totalYield = calculateTotalYield(state)
245251
}
252+
if (feeCollectedFilter.matches(log)) {
253+
const event = originLidoArmAbi.events.FeeCollected.decode(log)
254+
const state = await getCurrentState(block)
255+
state.totalFees += event.fee
256+
}
246257
}
247258
}
248259
await ctx.store.insert(states)

0 commit comments

Comments
 (0)