1
1
import * as curvePoolBoosterAbi from '@abi/otoken-curve-pool-booster'
2
- import { Block , Context , blockFrequencyUpdater , defineProcessor , logFilter } from '@originprotocol/squid-utils'
2
+ import { PoolBoosterCampaign , PoolBoosterFeeCollected } from '@model'
3
+ import { Context , blockFrequencyUpdater , defineProcessor , logFilter } from '@originprotocol/squid-utils'
3
4
import { EvmBatchProcessor } from '@subsquid/evm-processor'
4
5
5
- export const createCurvePoolBoosterProcessor = ( params : { address : string ; otokenAddress : string ; from : number } ) => {
6
+ export const createCurvePoolBoosterProcessor = ( params : { otokenAddress : string ; from : number } ) => {
6
7
const frequencyUpdate = blockFrequencyUpdater ( { from : params . from } )
8
+
7
9
const bribeCreatedFilter = logFilter ( {
8
10
topic0 : [ curvePoolBoosterAbi . events . FeeCollected . topic ] ,
9
11
range : { from : params . from } ,
@@ -12,45 +14,73 @@ export const createCurvePoolBoosterProcessor = (params: { address: string; otoke
12
14
topic0 : [ curvePoolBoosterAbi . events . CampaignCreated . topic ] ,
13
15
range : { from : params . from } ,
14
16
} )
15
- const campaignClosedFilter = logFilter ( {
16
- topic0 : [ curvePoolBoosterAbi . events . CampaignClosed . topic ] ,
17
- range : { from : params . from } ,
18
- } )
19
17
const campaignIdUpdatedFilter = logFilter ( {
20
18
topic0 : [ curvePoolBoosterAbi . events . CampaignIdUpdated . topic ] ,
21
19
range : { from : params . from } ,
22
20
} )
21
+ const campaignClosedFilter = logFilter ( {
22
+ topic0 : [ curvePoolBoosterAbi . events . CampaignClosed . topic ] ,
23
+ range : { from : params . from } ,
24
+ } )
25
+
23
26
return defineProcessor ( {
24
- name : `curve-pool-booster- ${ params . address } ` ,
27
+ name : `curve-pool-booster` ,
25
28
setup : ( processor : EvmBatchProcessor ) => {
26
29
processor . addLog ( bribeCreatedFilter . value )
27
30
} ,
28
31
process : async ( ctx : Context ) => {
32
+ const campaigns = new Map < string , PoolBoosterCampaign > ( )
33
+ const feesCollected = new Map < string , PoolBoosterFeeCollected > ( )
34
+
29
35
for ( const block of ctx . blocksWithContent ) {
30
36
for ( const log of block . logs ) {
31
37
if ( campaignCreatedFilter . matches ( log ) ) {
32
38
const data = curvePoolBoosterAbi . events . CampaignCreated . decode ( log )
33
- console . log ( data )
34
- }
35
- if ( campaignClosedFilter . matches ( log ) ) {
36
- const data = curvePoolBoosterAbi . events . CampaignClosed . decode ( log )
37
- console . log ( data )
39
+ const id = `${ ctx . chain . id } -${ log . address } `
40
+ const campaign = new PoolBoosterCampaign ( {
41
+ id,
42
+ chainId : ctx . chain . id ,
43
+ address : log . address ,
44
+ gauge : data . gauge ,
45
+ rewardToken : data . rewardToken ,
46
+ maxRewardPerVote : data . maxRewardPerVote ,
47
+ totalRewardAmount : data . totalRewardAmount ,
48
+ } )
49
+ campaigns . set ( id , campaign )
38
50
}
39
51
if ( campaignIdUpdatedFilter . matches ( log ) ) {
40
52
const data = curvePoolBoosterAbi . events . CampaignIdUpdated . decode ( log )
41
- console . log ( data )
53
+ const id = `${ ctx . chain . id } -${ log . address } `
54
+ let campaign = campaigns . get ( id ) || ( await ctx . store . get ( PoolBoosterCampaign , id ) )
55
+ if ( campaign ) {
56
+ campaign . campaignId = data . newId
57
+ }
58
+ }
59
+ if ( campaignClosedFilter . matches ( log ) ) {
60
+ const id = `${ ctx . chain . id } -${ log . address } `
61
+ let campaign = campaigns . get ( id ) || ( await ctx . store . get ( PoolBoosterCampaign , id ) )
62
+ if ( campaign ) {
63
+ campaign . closed = true
64
+ }
42
65
}
43
66
if ( bribeCreatedFilter . matches ( log ) ) {
44
67
const data = curvePoolBoosterAbi . events . FeeCollected . decode ( log )
45
- console . log ( data )
68
+ const feeCollected = new PoolBoosterFeeCollected ( {
69
+ id : `${ ctx . chain . id } -${ log . id } ` ,
70
+ chainId : ctx . chain . id ,
71
+ address : log . address ,
72
+ feeCollector : data . feeCollector ,
73
+ feeAmount : data . feeAmount ,
74
+ timestamp : new Date ( block . header . timestamp ) ,
75
+ blockNumber : block . header . height ,
76
+ txHash : log . transactionHash ,
77
+ } )
78
+ feesCollected . set ( feeCollected . id , feeCollected )
46
79
}
47
80
}
48
81
}
49
- await frequencyUpdate ( ctx , async ( ctx : Context , block : Block ) => {
50
- const curvePoolBooster = new curvePoolBoosterAbi . Contract ( ctx , block . header , params . address )
51
- const feeCollector = await curvePoolBooster . feeCollector ( )
52
- console . log ( feeCollector )
53
- } )
82
+ await ctx . store . insert ( [ ...campaigns . values ( ) ] )
83
+ await ctx . store . insert ( [ ...feesCollected . values ( ) ] )
54
84
} ,
55
85
} )
56
86
}
0 commit comments