Skip to content

Commit 33d3b4c

Browse files
committed
Reduce indexes ignore approvals
1 parent 303add5 commit 33d3b4c

File tree

4 files changed

+24
-127
lines changed

4 files changed

+24
-127
lines changed

config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ field_selection:
99
contracts:
1010
- name: ERC20
1111
events:
12-
- event: "Approval(address indexed owner, address indexed spender, uint256 value)"
1312
- event: "Transfer(address indexed from, address indexed to, uint256 value)"
1413

1514
chains:

schema.graphql

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ enum TransferType {
77
type Transfer @index(fields: ["token", ["blockTimestamp", "DESC"]]) {
88
id: ID! # ${chainId}_${token}_${blockNumber}_${logIndex}
99
chainId: Int!
10-
token: String! @index
10+
token: String!
1111
blockNumber: Int!
1212
blockTimestamp: Int!
1313
logIndex: Int!
1414
txHash: String! @index
15-
from: String! @index
16-
to: String! @index
15+
from: String!
16+
to: String!
1717
value: BigInt!
1818
transferType: TransferType!
1919
}
2020

2121
type Account @index(fields: ["token", ["balance", "DESC"]]) {
2222
id: ID! # ${chainId}-${token}-${address}
23-
chainId: Int! @index
24-
token: String! @index
23+
chainId: Int!
24+
token: String!
2525
address: String! @index
2626
balance: BigInt!
2727
totalVolumeIn: BigInt!
@@ -32,25 +32,12 @@ type Account @index(fields: ["token", ["balance", "DESC"]]) {
3232
firstSeenTimestamp: Int!
3333
lastActiveBlock: Int!
3434
lastActiveTimestamp: Int!
35-
approvalsGiven: [Approval!]! @derivedFrom(field: "owner")
36-
approvalsReceived: [Approval!]! @derivedFrom(field: "spender")
37-
}
38-
39-
type Approval @index(fields: ["token", "chainId"]) {
40-
id: ID! # ${chainId}-${token}-${owner}-${spender}
41-
chainId: Int! @index
42-
token: String! @index
43-
amount: BigInt!
44-
owner: Account!
45-
spender: Account!
46-
lastUpdatedBlock: Int!
47-
lastUpdatedTimestamp: Int!
4835
}
4936

5037
type TokenSupply @index(fields: ["chainId", "token"]) {
5138
id: ID! # ${chainId}-${token}-supply
5239
chainId: Int!
53-
token: String! @index
40+
token: String!
5441
totalSupply: BigInt!
5542
totalMinted: BigInt!
5643
totalBurned: BigInt!
@@ -65,9 +52,9 @@ type TokenSupply @index(fields: ["chainId", "token"]) {
6552

6653
type HourlySnapshot @index(fields: ["token", ["hourId", "DESC"]]) {
6754
id: ID! # ${chainId}-${token}-${hourId}
68-
chainId: Int! @index
69-
token: String! @index
70-
hourId: Int! @index
55+
chainId: Int!
56+
token: String!
57+
hourId: Int!
7158
hourStartTimestamp: Int!
7259
volume: BigInt!
7360
transferCount: Int!
@@ -83,9 +70,9 @@ type HourlySnapshot @index(fields: ["token", ["hourId", "DESC"]]) {
8370

8471
type DailySnapshot @index(fields: ["token", ["dayId", "DESC"]]) {
8572
id: ID! # ${chainId}-${token}-${dayId}
86-
chainId: Int! @index
87-
token: String! @index
88-
dayId: Int! @index
73+
chainId: Int!
74+
token: String!
75+
dayId: Int!
8976
dayStartTimestamp: Int!
9077
dailyVolume: BigInt!
9178
dailyTransferCount: Int!
@@ -104,9 +91,9 @@ type DailySnapshot @index(fields: ["token", ["dayId", "DESC"]]) {
10491

10592
type WeeklySnapshot @index(fields: ["token", ["weekId", "DESC"]]) {
10693
id: ID! # ${chainId}-${token}-${weekId}
107-
chainId: Int! @index
108-
token: String! @index
109-
weekId: Int! @index
94+
chainId: Int!
95+
token: String!
96+
weekId: Int!
11097
weekStartTimestamp: Int!
11198
weeklyVolume: BigInt!
11299
weeklyTransferCount: Int!
@@ -124,8 +111,8 @@ type WeeklySnapshot @index(fields: ["token", ["weekId", "DESC"]]) {
124111

125112
type CrossTokenDailySnapshot @index(fields: ["chainId", ["dayId", "DESC"]]) {
126113
id: ID! # ${chainId}-${dayId}
127-
chainId: Int! @index
128-
dayId: Int! @index
114+
chainId: Int!
115+
dayId: Int!
129116
dayStartTimestamp: Int!
130117
totalVolume: BigInt!
131118
totalTransferCount: Int!
@@ -137,21 +124,21 @@ type CrossTokenDailySnapshot @index(fields: ["chainId", ["dayId", "DESC"]]) {
137124
type AccountBalanceSnapshot @index(fields: ["account", "token", ["blockTimestamp", "DESC"]]) {
138125
id: ID! # ${chainId}-${token}-${address}-${blockNumber}-${logIndex}
139126
chainId: Int!
140-
token: String! @index
141-
account: String! @index
127+
token: String!
128+
account: String!
142129
blockNumber: Int!
143-
blockTimestamp: Int! @index
130+
blockTimestamp: Int!
144131
balance: BigInt!
145132
balanceChange: BigInt!
146133
txHash: String!
147134
}
148135

149136
type AccountDailyActivity @index(fields: ["account", "token", ["dayId", "DESC"]]) {
150137
id: ID! # ${chainId}-${token}-${address}-${dayId}
151-
chainId: Int! @index
152-
token: String! @index
153-
account: String! @index
154-
dayId: Int! @index
138+
chainId: Int!
139+
token: String!
140+
account: String!
141+
dayId: Int!
155142
transferCount: Int!
156143
volumeIn: BigInt!
157144
volumeOut: BigInt!

src/handlers/ERC20.ts

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -472,60 +472,3 @@ ERC20.Transfer.handler(async ({ event, context }) => {
472472
}
473473
});
474474

475-
ERC20.Approval.handler(async ({ event, context }) => {
476-
const chainId = event.chainId;
477-
const token = event.srcAddress;
478-
const owner = event.params.owner;
479-
const spender = event.params.spender;
480-
const blockNumber = event.block.number;
481-
const ts = event.block.timestamp;
482-
483-
// 1. Ensure owner Account exists
484-
const ownerId = getAccountId(chainId, token, owner);
485-
await context.Account.getOrCreate({
486-
id: ownerId,
487-
chainId,
488-
token,
489-
address: owner,
490-
balance: 0n,
491-
totalVolumeIn: 0n,
492-
totalVolumeOut: 0n,
493-
transfersIn: 0,
494-
transfersOut: 0,
495-
firstSeenBlock: blockNumber,
496-
firstSeenTimestamp: ts,
497-
lastActiveBlock: blockNumber,
498-
lastActiveTimestamp: ts,
499-
});
500-
501-
// 2. Ensure spender Account exists
502-
const spenderId = getAccountId(chainId, token, spender);
503-
await context.Account.getOrCreate({
504-
id: spenderId,
505-
chainId,
506-
token,
507-
address: spender,
508-
balance: 0n,
509-
totalVolumeIn: 0n,
510-
totalVolumeOut: 0n,
511-
transfersIn: 0,
512-
transfersOut: 0,
513-
firstSeenBlock: blockNumber,
514-
firstSeenTimestamp: ts,
515-
lastActiveBlock: blockNumber,
516-
lastActiveTimestamp: ts,
517-
});
518-
519-
// 3. Set/overwrite Approval entity
520-
const approvalId = `${chainId}-${token}-${owner}-${spender}`;
521-
context.Approval.set({
522-
id: approvalId,
523-
chainId,
524-
token,
525-
amount: event.params.value,
526-
owner_id: ownerId,
527-
spender_id: spenderId,
528-
lastUpdatedBlock: blockNumber,
529-
lastUpdatedTimestamp: ts,
530-
});
531-
});

src/indexer.test.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -296,35 +296,3 @@ describe("Unit: Transfer handler", () => {
296296
});
297297
});
298298

299-
describe("Unit: Approval handler", () => {
300-
it("Creates approval and ensures both accounts exist", async () => {
301-
const mockDb = MockDb.createMockDb();
302-
const owner = Addresses.mockAddresses[0]!;
303-
const spender = Addresses.mockAddresses[1]!;
304-
305-
const mockApproval = ERC20.Approval.createMockEvent({
306-
owner,
307-
spender,
308-
value: 1000000n,
309-
mockEventData: { srcAddress: USDC_ADDRESS, chainId: MOCK_CHAIN_ID },
310-
});
311-
312-
const result = await ERC20.Approval.processEvent({
313-
event: mockApproval,
314-
mockDb,
315-
});
316-
317-
const approvalId = `${MOCK_CHAIN_ID}-${USDC_ADDRESS}-${owner}-${spender}`;
318-
const approval = result.entities.Approval.get(approvalId);
319-
expect(approval).toBeDefined();
320-
expect(approval?.amount).toBe(1000000n);
321-
expect(approval?.token).toBe(USDC_ADDRESS);
322-
323-
expect(
324-
result.entities.Account.get(`${MOCK_CHAIN_ID}-${USDC_ADDRESS}-${owner}`)
325-
).toBeDefined();
326-
expect(
327-
result.entities.Account.get(`${MOCK_CHAIN_ID}-${USDC_ADDRESS}-${spender}`)
328-
).toBeDefined();
329-
});
330-
});

0 commit comments

Comments
 (0)