Skip to content

Commit 35c2383

Browse files
authored
Regenerate watcher to backfill event data (#45)
* Regenerate watcher with latest codegen * Make new Event columns nullable * Add a script to backfill event data * Revert "Make new Event columns nullable" This reverts commit fdcab98. * Use backfill events data command from @cerc-io/cli * Update package json script
1 parent 6313d4a commit 35c2383

File tree

8 files changed

+227
-71
lines changed

8 files changed

+227
-71
lines changed

environments/local.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# Flag to specify whether RPC endpoint supports block hash as block tag parameter
2424
rpcSupportsBlockHashParam = false
2525

26-
# Server GQL config
26+
# GQL server config
2727
[server.gql]
2828
path = "/graphql"
2929

@@ -45,6 +45,14 @@
4545
maxAge = 15
4646
timeTravelMaxAge = 86400 # 1 day
4747

48+
# ETH RPC server config
49+
[server.ethRPC]
50+
enabled = true
51+
path = "/rpc"
52+
53+
# Max number of logs that can be returned in a single getLogs request (default: 10000)
54+
getLogsResultLimit = 10000
55+
4856
[metrics]
4957
host = "127.0.0.1"
5058
port = 9000

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cerc-io/sushiswap-v3-watcher-ts",
3-
"version": "0.1.16",
3+
"version": "0.1.17",
44
"description": "sushiswap-v3-watcher-ts",
55
"private": true,
66
"main": "dist/index.js",
@@ -25,7 +25,8 @@
2525
"import-state": "DEBUG=vulcanize:* node --enable-source-maps dist/cli/import-state.js",
2626
"import-state:dev": "DEBUG=vulcanize:* ts-node src/cli/import-state.ts",
2727
"inspect-cid": "DEBUG=vulcanize:* ts-node src/cli/inspect-cid.ts",
28-
"index-block": "DEBUG=vulcanize:* ts-node src/cli/index-block.ts"
28+
"index-block": "DEBUG=vulcanize:* ts-node src/cli/index-block.ts",
29+
"backfill-events-data": "DEBUG=vulcanize:* YARN_CHILD_PROCESS=true node --enable-source-maps dist/cli/backfill-events-data.js"
2930
},
3031
"repository": {
3132
"type": "git",
@@ -39,11 +40,11 @@
3940
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
4041
"dependencies": {
4142
"@apollo/client": "^3.3.19",
42-
"@cerc-io/cli": "^0.2.103",
43-
"@cerc-io/ipld-eth-client": "^0.2.103",
44-
"@cerc-io/solidity-mapper": "^0.2.103",
45-
"@cerc-io/util": "^0.2.103",
46-
"@cerc-io/graph-node": "^0.2.103",
43+
"@cerc-io/cli": "^0.2.108",
44+
"@cerc-io/ipld-eth-client": "^0.2.108",
45+
"@cerc-io/solidity-mapper": "^0.2.108",
46+
"@cerc-io/util": "^0.2.108",
47+
"@cerc-io/graph-node": "^0.2.108",
4748
"@ethersproject/providers": "^5.4.4",
4849
"debug": "^4.3.1",
4950
"decimal.js": "^10.3.1",

src/cli/backfill-events-data.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// Copyright 2024 Vulcanize, Inc.
3+
//
4+
5+
import 'reflect-metadata';
6+
import debug from 'debug';
7+
8+
import { BackfillEventsDataCmd } from '@cerc-io/cli';
9+
10+
import { Database } from '../database';
11+
import { Event } from '../entity/Event';
12+
13+
const log = debug('vulcanize:backfill-events-data');
14+
15+
const main = async (): Promise<void> => {
16+
const backFillCmd = new BackfillEventsDataCmd();
17+
await backFillCmd.init(Database);
18+
19+
await backFillCmd.exec(Event);
20+
};
21+
22+
main().catch(err => {
23+
log(err);
24+
}).finally(() => {
25+
process.exit(0);
26+
});

src/database.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ export class Database implements DatabaseInterface {
169169
return this._baseDatabase.getEventsInRange(repo, fromBlockNumber, toBlockNumber);
170170
}
171171

172+
async getEvents (options: FindManyOptions<Event>): Promise<Array<Event>> {
173+
const repo = this._conn.getRepository(Event);
174+
175+
return this._baseDatabase.getEvents(repo, options);
176+
}
177+
172178
async saveEventEntity (queryRunner: QueryRunner, entity: Event): Promise<Event> {
173179
const repo = queryRunner.manager.getRepository(Event);
174180
return this._baseDatabase.saveEventEntity(repo, entity);

src/entity/Event.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ export class Event {
2727
@Column('varchar', { length: 256 })
2828
eventName!: string;
2929

30+
@Column('varchar', { length: 66 })
31+
topic0!: string;
32+
33+
@Column('varchar', { length: 66, nullable: true })
34+
topic1!: string | null;
35+
36+
@Column('varchar', { length: 66, nullable: true })
37+
topic2!: string | null;
38+
39+
@Column('varchar', { length: 66, nullable: true })
40+
topic3!: string | null;
41+
42+
@Column('varchar')
43+
data!: string;
44+
3045
@Column('text')
3146
eventInfo!: string;
3247

src/indexer.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ export class Indexer implements IndexerInterface {
192192
return this._storageLayoutMap;
193193
}
194194

195+
get contractMap (): Map<string, ethers.utils.Interface> {
196+
return this._contractMap;
197+
}
198+
195199
get graphWatcher (): GraphWatcher {
196200
return this._graphWatcher;
197201
}
@@ -503,6 +507,10 @@ export class Indexer implements IndexerInterface {
503507
return this._baseIndexer.watchContract(address, kind, checkpoint, startingBlock, context);
504508
}
505509

510+
async removeContract (address: string, kind: string): Promise<void> {
511+
return this._baseIndexer.removeContract(address, kind);
512+
}
513+
506514
updateStateStatusMap (address: string, stateStatus: StateStatus): void {
507515
this._baseIndexer.updateStateStatusMap(address, stateStatus);
508516
}
@@ -543,6 +551,10 @@ export class Indexer implements IndexerInterface {
543551
return this._baseIndexer.getEventsInRange(fromBlockNumber, toBlockNumber, this._serverConfig.gql.maxEventsBlockRange);
544552
}
545553

554+
async getEvents (options: FindManyOptions<Event>): Promise<Array<Event>> {
555+
return this._db.getEvents(options);
556+
}
557+
546558
async getSyncStatus (): Promise<SyncStatus | undefined> {
547559
return this._baseIndexer.getSyncStatus();
548560
}

src/schema.gql

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4775,8 +4775,8 @@ type Token {
47754775
totalValueLockedUSD: BigDecimal!
47764776
totalValueLockedUSDUntracked: BigDecimal!
47774777
derivedETH: BigDecimal!
4778-
whitelistPools: [Pool!]!
4779-
tokenDayData: [TokenDayData!]!
4778+
whitelistPools(where: Pool_filter, orderBy: Pool_orderBy, orderDirection: OrderDirection, first: Int = 100, skip: Int = 0): [Pool!]!
4779+
tokenDayData(where: TokenDayData_filter, orderBy: TokenDayData_orderBy, orderDirection: OrderDirection, first: Int = 100, skip: Int = 0): [TokenDayData!]!
47804780
}
47814781

47824782
type Pool {
@@ -4809,13 +4809,13 @@ type Pool {
48094809
totalValueLockedUSD: BigDecimal!
48104810
totalValueLockedUSDUntracked: BigDecimal!
48114811
liquidityProviderCount: BigInt!
4812-
poolHourData: [PoolHourData!]!
4813-
poolDayData: [PoolDayData!]!
4814-
mints: [Mint!]!
4815-
burns: [Burn!]!
4816-
swaps: [Swap!]!
4817-
collects: [Collect!]!
4818-
ticks: [Tick!]!
4812+
poolHourData(where: PoolHourData_filter, orderBy: PoolHourData_orderBy, orderDirection: OrderDirection, first: Int = 100, skip: Int = 0): [PoolHourData!]!
4813+
poolDayData(where: PoolDayData_filter, orderBy: PoolDayData_orderBy, orderDirection: OrderDirection, first: Int = 100, skip: Int = 0): [PoolDayData!]!
4814+
mints(where: Mint_filter, orderBy: Mint_orderBy, orderDirection: OrderDirection, first: Int = 100, skip: Int = 0): [Mint!]!
4815+
burns(where: Burn_filter, orderBy: Burn_orderBy, orderDirection: OrderDirection, first: Int = 100, skip: Int = 0): [Burn!]!
4816+
swaps(where: Swap_filter, orderBy: Swap_orderBy, orderDirection: OrderDirection, first: Int = 100, skip: Int = 0): [Swap!]!
4817+
collects(where: Collect_filter, orderBy: Collect_orderBy, orderDirection: OrderDirection, first: Int = 100, skip: Int = 0): [Collect!]!
4818+
ticks(where: Tick_filter, orderBy: Tick_orderBy, orderDirection: OrderDirection, first: Int = 100, skip: Int = 0): [Tick!]!
48194819
}
48204820

48214821
type PoolHourData {
@@ -4889,11 +4889,11 @@ type Transaction {
48894889
timestamp: BigInt!
48904890
gasUsed: BigInt!
48914891
gasPrice: BigInt!
4892-
mints: [Mint!]!
4893-
burns: [Burn!]!
4894-
swaps: [Swap!]!
4895-
flashed: [Flash!]!
4896-
collects: [Collect!]!
4892+
mints(where: Mint_filter, orderBy: Mint_orderBy, orderDirection: OrderDirection, first: Int = 100, skip: Int = 0): [Mint!]!
4893+
burns(where: Burn_filter, orderBy: Burn_orderBy, orderDirection: OrderDirection, first: Int = 100, skip: Int = 0): [Burn!]!
4894+
swaps(where: Swap_filter, orderBy: Swap_orderBy, orderDirection: OrderDirection, first: Int = 100, skip: Int = 0): [Swap!]!
4895+
flashed(where: Flash_filter, orderBy: Flash_orderBy, orderDirection: OrderDirection, first: Int = 100, skip: Int = 0): [Flash!]!
4896+
collects(where: Collect_filter, orderBy: Collect_orderBy, orderDirection: OrderDirection, first: Int = 100, skip: Int = 0): [Collect!]!
48974897
}
48984898

48994899
type Burn {
@@ -5025,8 +5025,8 @@ type Position {
50255025
transaction: Transaction!
50265026
feeGrowthInside0LastX128: BigInt!
50275027
feeGrowthInside1LastX128: BigInt!
5028-
increaseEvents: [IncreaseEvent!]!
5029-
decreaseEvents: [IncreaseEvent!]!
5028+
increaseEvents(where: IncreaseEvent_filter, orderBy: IncreaseEvent_orderBy, orderDirection: OrderDirection, first: Int = 100, skip: Int = 0): [IncreaseEvent!]!
5029+
decreaseEvents(where: IncreaseEvent_filter, orderBy: IncreaseEvent_orderBy, orderDirection: OrderDirection, first: Int = 100, skip: Int = 0): [IncreaseEvent!]!
50305030
}
50315031

50325032
type IncreaseEvent {

0 commit comments

Comments
 (0)