@@ -4,10 +4,11 @@ import { last } from 'lodash'
44import * as erc20Abi from '@abi/erc20'
55import * as originLidoArmAbi from '@abi/origin-lido-arm'
66import * 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'
88import { Block , Context , Processor } from '@processor'
99import { EvmBatchProcessor } from '@subsquid/evm-processor'
1010import { createERC20SimpleTracker } from '@templates/erc20-simple'
11+ import { createEventProcessor } from '@templates/events/createEventProcessor'
1112import { blockFrequencyTracker } from '@utils/blockFrequencyUpdater'
1213import { calculateAPY } from '@utils/calculateAPY'
1314import { 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