Skip to content

Commit c3a67d5

Browse files
committed
improve processing performance of rebasing erc20 tokens
1 parent 2efa158 commit c3a67d5

File tree

16 files changed

+382
-109
lines changed

16 files changed

+382
-109
lines changed

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

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

schema.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,7 @@ type ERC20Holder @entity {
11461146
address: String! @index
11471147
account: String! @index
11481148
balance: BigInt!
1149+
rebasingCredits: BigInt # Only used for rebasing tokens
11491150
}
11501151

11511152
type ERC20State @entity {
@@ -1159,6 +1160,7 @@ type ERC20State @entity {
11591160
address: String!
11601161
totalSupply: BigInt!
11611162
holderCount: Int!
1163+
rebasingCreditsPerToken: BigInt # Only used for rebasing tokens
11621164
}
11631165

11641166
type ERC20Balance @entity {
@@ -1172,6 +1174,7 @@ type ERC20Balance @entity {
11721174
address: String! @index
11731175
account: String! @index
11741176
balance: BigInt!
1177+
rebasingCredits: BigInt # Only used for rebasing tokens
11751178
}
11761179

11771180
type ERC20Transfer @entity {

schema/general.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ type ERC20Holder @entity {
113113
address: String! @index
114114
account: String! @index
115115
balance: BigInt!
116+
rebasingCredits: BigInt # Only used for rebasing tokens
116117
}
117118

118119
type ERC20State @entity {
@@ -126,6 +127,7 @@ type ERC20State @entity {
126127
address: String!
127128
totalSupply: BigInt!
128129
holderCount: Int!
130+
rebasingCreditsPerToken: BigInt # Only used for rebasing tokens
129131
}
130132

131133
type ERC20Balance @entity {
@@ -139,6 +141,7 @@ type ERC20Balance @entity {
139141
address: String! @index
140142
account: String! @index
141143
balance: BigInt!
144+
rebasingCredits: BigInt # Only used for rebasing tokens
142145
}
143146

144147
type ERC20Transfer @entity {

src/base/erc20.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as otoken from '@abi/otoken'
22
import { createERC20Tracker } from '@templates/erc20'
33
import { createERC20SimpleTracker } from '@templates/erc20-simple'
4+
import { createRebasingERC20Tracker } from '@templates/erc20/erc20-rebasing'
45
import { OGN_BASE_ADDRESS } from '@utils/addresses'
56
import { baseAddresses } from '@utils/addresses-base'
67
import { logFilter } from '@utils/logFilter'
@@ -12,17 +13,25 @@ export const baseERC20s = [
1213
address: OGN_BASE_ADDRESS,
1314
}),
1415
// superOETHb
15-
createERC20Tracker({
16+
createRebasingERC20Tracker({
1617
from: 17819702,
1718
address: baseAddresses.tokens.superOETHb,
18-
rebaseFilters: [
19-
logFilter({
19+
rebasing: {
20+
rebaseEventFilter: logFilter({
2021
address: [baseAddresses.tokens.superOETHb],
2122
topic0: [otoken.events.TotalSupplyUpdatedHighres.topic],
2223
transaction: true,
2324
range: { from: 17819702 },
2425
}),
25-
],
26+
getCredits: async (ctx, block, address) => {
27+
const oToken = new otoken.Contract(ctx, block.header, baseAddresses.tokens.superOETHb)
28+
return oToken.creditsBalanceOfHighres(address).then((credits) => credits._1)
29+
},
30+
getCreditsPerToken: async (ctx, block) => {
31+
const oToken = new otoken.Contract(ctx, block.header, baseAddresses.tokens.superOETHb)
32+
return oToken.rebasingCreditsPerTokenHighres()
33+
},
34+
},
2635
}),
2736
// wsuperOETHb
2837
createERC20SimpleTracker({

src/base/super-oeth-b.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { parseEther } from 'viem'
22

3-
import { Context } from '@processor'
4-
import { EvmBatchProcessor } from '@subsquid/evm-processor'
53
import { getPositions } from '@templates/aerodrome/lp'
64
import { createOTokenProcessor } from '@templates/otoken'
75
import { createOTokenActivityProcessor } from '@templates/otoken/activity-processor/activity-processor'
@@ -39,6 +37,7 @@ const otokenProcessor = createOTokenProcessor({
3937
height,
4038
aerodromePools['CL1-WETH/superOETHb'],
4139
baseAddresses.superOETHb.strategies.amo,
40+
1,
4241
)
4342
return positions.reduce((acc, position) => acc + BigInt(position.amount1) + BigInt(position.staked1), 0n)
4443
},
@@ -62,18 +61,4 @@ const otokenWithdrawalsProcessor = createOTokenWithdrawalsProcessor({
6261
from: 21544908,
6362
})
6463

65-
export const superOETHb = {
66-
from: Math.min(otokenProcessor.from, otokenActivityProcessor.from),
67-
setup: (processor: EvmBatchProcessor) => {
68-
otokenProcessor.setup(processor)
69-
otokenActivityProcessor.setup(processor)
70-
otokenWithdrawalsProcessor.setup(processor)
71-
},
72-
process: async (ctx: Context) => {
73-
await Promise.all([
74-
otokenProcessor.process(ctx),
75-
otokenActivityProcessor.process(ctx),
76-
otokenWithdrawalsProcessor.process(ctx),
77-
])
78-
},
79-
}
64+
export const superOETHb = [otokenProcessor, otokenActivityProcessor, otokenWithdrawalsProcessor]

src/main-base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const processor = {
1515
stateSchema: 'base-processor',
1616
processors: [
1717
...baseERC20s,
18-
superOETHb,
18+
...superOETHb,
1919
baseStrategies,
2020
bridgedWoethStrategy,
2121
...aerodromeProcessors,

src/mainnet/processors/erc20s.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as otoken from '@abi/otoken'
22
import { createERC20Tracker } from '@templates/erc20'
33
import { createERC20SimpleTracker } from '@templates/erc20-simple'
4+
import { createRebasingERC20Tracker } from '@templates/erc20/erc20-rebasing'
45
import {
56
OETH_ADDRESS,
67
OETH_DRIPPER_ADDRESS,
@@ -40,19 +41,27 @@ const simpleTracks: Record<string, Parameters<typeof createERC20SimpleTracker>[0
4041
address: tokens.primeETH,
4142
},
4243
}
43-
const tracks: Record<string, Parameters<typeof createERC20Tracker>[0]> = {
44+
const tracks: Record<string, Parameters<typeof createERC20Tracker | typeof createRebasingERC20Tracker>[0]> = {
4445
// Origin Specific
4546
OETH: {
4647
from: 16935276,
4748
address: tokens.OETH,
48-
rebaseFilters: [
49-
logFilter({
49+
rebasing: {
50+
rebaseEventFilter: logFilter({
5051
address: [OETH_ADDRESS],
5152
topic0: [otoken.events.TotalSupplyUpdatedHighres.topic],
5253
transaction: true,
5354
range: { from: 16935276 },
5455
}),
55-
],
56+
getCredits: async (ctx, block, address) => {
57+
const oToken = new otoken.Contract(ctx, block.header, tokens.OETH)
58+
return oToken.creditsBalanceOfHighres(address).then((credits) => credits._1)
59+
},
60+
getCreditsPerToken: async (ctx, block) => {
61+
const oToken = new otoken.Contract(ctx, block.header, tokens.OETH)
62+
return oToken.rebasingCreditsPerTokenHighres()
63+
},
64+
},
5665
},
5766
wOETH: {
5867
from: 16933090,
@@ -120,10 +129,10 @@ export const addERC20Processing = (symbol: TokenSymbol, account: string) => {
120129
throw new Error('erc20s already initialized, check load order')
121130
}
122131
const track = tracks[symbol]
123-
if (track) {
132+
if ('accountFilter' in track) {
124133
// If there is no `accountFilter` then it is OK to have this as a noop. (we already want everything)
125134
track.accountFilter?.push(account)
126-
} else {
135+
} else if (!track) {
127136
throw new Error(`Symbol ${symbol} not added to \`tracks\``)
128137
}
129138
}

src/model/generated/erc20Balance.model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ export class ERC20Balance {
3434

3535
@BigIntColumn_({nullable: false})
3636
balance!: bigint
37+
38+
@BigIntColumn_({nullable: true})
39+
rebasingCredits!: bigint | undefined | null
3740
}

src/model/generated/erc20Holder.model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ export class ERC20Holder {
2626

2727
@BigIntColumn_({nullable: false})
2828
balance!: bigint
29+
30+
@BigIntColumn_({nullable: true})
31+
rebasingCredits!: bigint | undefined | null
2932
}

src/model/generated/erc20State.model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ export class ERC20State {
3232

3333
@IntColumn_({nullable: false})
3434
holderCount!: number
35+
36+
@BigIntColumn_({nullable: true})
37+
rebasingCreditsPerToken!: bigint | undefined | null
3538
}

0 commit comments

Comments
 (0)