Skip to content

Commit 0da7cb7

Browse files
committed
pool booster wip
1 parent 64f1f0e commit 0da7cb7

File tree

6 files changed

+126
-27
lines changed

6 files changed

+126
-27
lines changed

db/migrations/1738623244696-Data.js renamed to db/migrations/1739243789291-Data.js

Lines changed: 10 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
@@ -339,6 +339,17 @@ type TransactionDetails @entity {
339339
effectiveGasPrice: BigInt!
340340
transactionFee: BigInt!
341341
}
342+
type PoolBoosterCampaign @entity {
343+
id: ID! @index
344+
chainId: Int! @index
345+
address: String! @index
346+
gauge: String! @index
347+
rewardToken: String!
348+
maxRewardPerVote: BigInt!
349+
totalRewardAmount: BigInt!
350+
campaignId: BigInt!
351+
closed: Boolean!
352+
}
342353
type OToken @entity {
343354
id: ID! @index
344355
chainId: Int! @index

src/model/generated/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export * from "./ogvDailyStat.model"
3030
export * from "./bridgeTransfer.model"
3131
export * from "./bridgeTransferState.model"
3232
export * from "./transactionDetails.model"
33+
export * from "./poolBoosterCampaign.model"
3334
export * from "./oToken.model"
3435
export * from "./woToken.model"
3536
export * from "./oTokenAsset.model"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, IntColumn as IntColumn_, Index as Index_, StringColumn as StringColumn_, BigIntColumn as BigIntColumn_, BooleanColumn as BooleanColumn_} from "@subsquid/typeorm-store"
2+
3+
@Entity_()
4+
export class PoolBoosterCampaign {
5+
constructor(props?: Partial<PoolBoosterCampaign>) {
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+
address!: string
19+
20+
@Index_()
21+
@StringColumn_({nullable: false})
22+
gauge!: string
23+
24+
@StringColumn_({nullable: false})
25+
rewardToken!: string
26+
27+
@BigIntColumn_({nullable: false})
28+
maxRewardPerVote!: bigint
29+
30+
@BigIntColumn_({nullable: false})
31+
totalRewardAmount!: bigint
32+
33+
@BigIntColumn_({nullable: false})
34+
campaignId!: bigint
35+
36+
@BooleanColumn_({nullable: false})
37+
closed!: boolean
38+
}
Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
type CurvePoolBoosterBribeCreated @entity {
1+
type PoolBoosterCampaign @entity {
22
id: ID! @index
33
chainId: Int! @index
4-
timestamp: DateTime! @index
5-
blockNumber: Int! @index
6-
otoken: String! @index
7-
gauge: String!
8-
maxRewardPerVote: BigInt!
4+
address: String! @index
5+
gauge: String! @index
6+
campaignId: BigInt
97
rewardToken: String!
8+
maxRewardPerVote: BigInt!
109
totalRewardAmount: BigInt!
10+
closed: Boolean!
11+
}
12+
13+
type PoolBoosterFeeCollected @entity {
14+
id: ID! @index
15+
chainId: Int! @index
16+
address: String! @index
17+
timestamp: DateTime! @index
18+
blockNumber: Int! @index
19+
feeCollector: String!
20+
feeAmount: BigInt!
21+
txHash: String!
1122
}
Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
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'
34
import { EvmBatchProcessor } from '@subsquid/evm-processor'
45

5-
export const createCurvePoolBoosterProcessor = (params: { address: string; otokenAddress: string; from: number }) => {
6+
export const createCurvePoolBoosterProcessor = (params: { otokenAddress: string; from: number }) => {
67
const frequencyUpdate = blockFrequencyUpdater({ from: params.from })
8+
79
const bribeCreatedFilter = logFilter({
810
topic0: [curvePoolBoosterAbi.events.FeeCollected.topic],
911
range: { from: params.from },
@@ -12,45 +14,73 @@ export const createCurvePoolBoosterProcessor = (params: { address: string; otoke
1214
topic0: [curvePoolBoosterAbi.events.CampaignCreated.topic],
1315
range: { from: params.from },
1416
})
15-
const campaignClosedFilter = logFilter({
16-
topic0: [curvePoolBoosterAbi.events.CampaignClosed.topic],
17-
range: { from: params.from },
18-
})
1917
const campaignIdUpdatedFilter = logFilter({
2018
topic0: [curvePoolBoosterAbi.events.CampaignIdUpdated.topic],
2119
range: { from: params.from },
2220
})
21+
const campaignClosedFilter = logFilter({
22+
topic0: [curvePoolBoosterAbi.events.CampaignClosed.topic],
23+
range: { from: params.from },
24+
})
25+
2326
return defineProcessor({
24-
name: `curve-pool-booster-${params.address}`,
27+
name: `curve-pool-booster`,
2528
setup: (processor: EvmBatchProcessor) => {
2629
processor.addLog(bribeCreatedFilter.value)
2730
},
2831
process: async (ctx: Context) => {
32+
const campaigns = new Map<string, PoolBoosterCampaign>()
33+
const feesCollected = new Map<string, PoolBoosterFeeCollected>()
34+
2935
for (const block of ctx.blocksWithContent) {
3036
for (const log of block.logs) {
3137
if (campaignCreatedFilter.matches(log)) {
3238
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)
3850
}
3951
if (campaignIdUpdatedFilter.matches(log)) {
4052
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+
}
4265
}
4366
if (bribeCreatedFilter.matches(log)) {
4467
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)
4679
}
4780
}
4881
}
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()])
5484
},
5585
})
5686
}

0 commit comments

Comments
 (0)