Skip to content

Commit

Permalink
Upgrade cerc-io dependencies and update watcher (#20)
Browse files Browse the repository at this point in the history
* Remove Indexer method fetchEventsAndSaveBlocks

* Add context column to Contract entity

* Upgrade cerc-io dependencies

* Update package version

* Set gqlPath to base URL

---------

Co-authored-by: neeraj <neeraj.rtly@gmail.com>
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
  • Loading branch information
3 people authored Nov 21, 2023
1 parent 9137916 commit 4783e5e
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 101 deletions.
1 change: 1 addition & 0 deletions environments/local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
host = "127.0.0.1"
port = 3008
kind = "active"
gqlPath = "/"

# Checkpointing state.
checkpointing = true
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cerc-io/sushiswap-v3-watcher-ts",
"version": "0.1.2",
"version": "0.1.3",
"description": "sushiswap-v3-watcher-ts",
"private": true,
"main": "dist/index.js",
Expand Down Expand Up @@ -39,11 +39,11 @@
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
"dependencies": {
"@apollo/client": "^3.3.19",
"@cerc-io/cli": "^0.2.72",
"@cerc-io/ipld-eth-client": "^0.2.72",
"@cerc-io/solidity-mapper": "^0.2.72",
"@cerc-io/util": "^0.2.72",
"@cerc-io/graph-node": "^0.2.72",
"@cerc-io/cli": "^0.2.73",
"@cerc-io/ipld-eth-client": "^0.2.73",
"@cerc-io/solidity-mapper": "^0.2.73",
"@cerc-io/util": "^0.2.73",
"@cerc-io/graph-node": "^0.2.73",
"@ethersproject/providers": "^5.4.4",
"debug": "^4.3.1",
"decimal.js": "^10.3.1",
Expand Down
4 changes: 2 additions & 2 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ export class Database implements DatabaseInterface {
return this._baseDatabase.saveBlockProgress(repo, block);
}

async saveContract (queryRunner: QueryRunner, address: string, kind: string, checkpoint: boolean, startingBlock: number): Promise<Contract> {
async saveContract (queryRunner: QueryRunner, address: string, kind: string, checkpoint: boolean, startingBlock: number, context?: any): Promise<Contract> {
const repo = queryRunner.manager.getRepository(Contract);

return this._baseDatabase.saveContract(repo, address, kind, checkpoint, startingBlock);
return this._baseDatabase.saveContract(repo, address, kind, checkpoint, startingBlock, context);
}

async updateSyncStatusIndexedBlock (queryRunner: QueryRunner, blockHash: string, blockNumber: number, force = false): Promise<SyncStatus> {
Expand Down
3 changes: 3 additions & 0 deletions src/entity/Contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ export class Contract {

@Column('integer')
startingBlock!: number;

@Column('jsonb', { nullable: true })
context!: Record<string, { data: any, type: number }>;
}
2 changes: 1 addition & 1 deletion src/gql/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const increaseEvent = fs.readFileSync(path.join(__dirname, 'increaseEvent
export const increaseEvents = fs.readFileSync(path.join(__dirname, 'increaseEvents.gql'), 'utf8');
export const decreaseEvent = fs.readFileSync(path.join(__dirname, 'decreaseEvent.gql'), 'utf8');
export const decreaseEvents = fs.readFileSync(path.join(__dirname, 'decreaseEvents.gql'), 'utf8');
export const _meta = fs.readFileSync(path.join(__dirname, '_meta.gql'), 'utf8');
export const getStateByCID = fs.readFileSync(path.join(__dirname, 'getStateByCID.gql'), 'utf8');
export const getState = fs.readFileSync(path.join(__dirname, 'getState.gql'), 'utf8');
export const getSyncStatus = fs.readFileSync(path.join(__dirname, 'getSyncStatus.gql'), 'utf8');
export const _meta = fs.readFileSync(path.join(__dirname, '_meta.gql'), 'utf8');
43 changes: 19 additions & 24 deletions src/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
Where,
QueryOptions,
BlockHeight,
ResultMeta,
updateSubgraphState,
dumpSubgraphState,
GraphWatcherInterface,
Expand All @@ -31,7 +32,6 @@ import {
Clients,
EthClient,
UpstreamConfig,
ResultMeta,
EthFullBlock,
EthFullTransaction,
ExtraEventData
Expand Down Expand Up @@ -131,8 +131,6 @@ export class Indexer implements IndexerInterface {
this._storageLayoutMap = new Map();
this._contractMap = new Map();
this.eventSignaturesMap = new Map();
let contractInterface: ethers.utils.Interface;
let eventSignatures: string[];

const { abi: FactoryABI } = FactoryArtifacts;

Expand All @@ -143,35 +141,35 @@ export class Indexer implements IndexerInterface {
assert(FactoryABI);
this._abiMap.set(KIND_FACTORY, FactoryABI);

contractInterface = new ethers.utils.Interface(FactoryABI);
this._contractMap.set(KIND_FACTORY, contractInterface);
const FactoryContractInterface = new ethers.utils.Interface(FactoryABI);
this._contractMap.set(KIND_FACTORY, FactoryContractInterface);

eventSignatures = Object.values(contractInterface.events).map(value => {
return contractInterface.getEventTopic(value);
const FactoryEventSignatures = Object.values(FactoryContractInterface.events).map(value => {
return FactoryContractInterface.getEventTopic(value);
});
this.eventSignaturesMap.set(KIND_FACTORY, eventSignatures);
this.eventSignaturesMap.set(KIND_FACTORY, FactoryEventSignatures);

assert(NonfungiblePositionManagerABI);
this._abiMap.set(KIND_NONFUNGIBLEPOSITIONMANAGER, NonfungiblePositionManagerABI);

contractInterface = new ethers.utils.Interface(NonfungiblePositionManagerABI);
this._contractMap.set(KIND_NONFUNGIBLEPOSITIONMANAGER, contractInterface);
const NonfungiblePositionManagerContractInterface = new ethers.utils.Interface(NonfungiblePositionManagerABI);
this._contractMap.set(KIND_NONFUNGIBLEPOSITIONMANAGER, NonfungiblePositionManagerContractInterface);

eventSignatures = Object.values(contractInterface.events).map(value => {
return contractInterface.getEventTopic(value);
const NonfungiblePositionManagerEventSignatures = Object.values(NonfungiblePositionManagerContractInterface.events).map(value => {
return NonfungiblePositionManagerContractInterface.getEventTopic(value);
});
this.eventSignaturesMap.set(KIND_NONFUNGIBLEPOSITIONMANAGER, eventSignatures);
this.eventSignaturesMap.set(KIND_NONFUNGIBLEPOSITIONMANAGER, NonfungiblePositionManagerEventSignatures);

assert(PoolABI);
this._abiMap.set(KIND_POOL, PoolABI);

contractInterface = new ethers.utils.Interface(PoolABI);
this._contractMap.set(KIND_POOL, contractInterface);
const PoolContractInterface = new ethers.utils.Interface(PoolABI);
this._contractMap.set(KIND_POOL, PoolContractInterface);

eventSignatures = Object.values(contractInterface.events).map(value => {
return contractInterface.getEventTopic(value);
const PoolEventSignatures = Object.values(PoolContractInterface.events).map(value => {
return PoolContractInterface.getEventTopic(value);
});
this.eventSignaturesMap.set(KIND_POOL, eventSignatures);
this.eventSignaturesMap.set(KIND_POOL, PoolEventSignatures);

this._entityTypesMap = new Map();
this._populateEntityTypesMap();
Expand Down Expand Up @@ -351,6 +349,7 @@ export class Indexer implements IndexerInterface {
return this._graphWatcher.getEntities(entity, this._relationsMap, block, where, queryOptions, selections);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async triggerIndexingOnEvent (event: Event, extraData: ExtraEventData): Promise<void> {
const resultEvent = this.getResultEvent(event);

Expand Down Expand Up @@ -471,8 +470,8 @@ export class Indexer implements IndexerInterface {
await this._graphWatcher.addContracts();
}

async watchContract (address: string, kind: string, checkpoint: boolean, startingBlock: number): Promise<void> {
return this._baseIndexer.watchContract(address, kind, checkpoint, startingBlock);
async watchContract (address: string, kind: string, checkpoint: boolean, startingBlock: number, context?: any): Promise<void> {
return this._baseIndexer.watchContract(address, kind, checkpoint, startingBlock, context);
}

updateStateStatusMap (address: string, stateStatus: StateStatus): void {
Expand Down Expand Up @@ -562,10 +561,6 @@ export class Indexer implements IndexerInterface {
return this._baseIndexer.getBlocksAtHeight(height, isPruned);
}

async fetchEventsAndSaveBlocks (blocks: DeepPartial<BlockProgress>[]): Promise<{ blockProgress: BlockProgress, events: DeepPartial<Event>[] }[]> {
return this._baseIndexer.fetchEventsAndSaveBlocks(blocks, this.eventSignaturesMap, this.parseEventNameAndArgs.bind(this));
}

async fetchAndSaveFilteredEventsAndBlocks (startBlock: number, endBlock: number): Promise<{
blockProgress: BlockProgress,
events: DeepPartial<Event>[],
Expand Down
16 changes: 8 additions & 8 deletions src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1011,14 +1011,6 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher
return state && state.block.isComplete ? getResultState(state) : undefined;
},

getSyncStatus: async () => {
log('getSyncStatus');
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('getSyncStatus').inc(1);

return indexer.getSyncStatus();
},

_meta: async (
_: any,
{ block = {} }: { block: BlockHeight }
Expand All @@ -1028,6 +1020,14 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher
gqlQueryCount.labels('_meta').inc(1);

return indexer.getMetaData(block);
},

getSyncStatus: async () => {
log('getSyncStatus');
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('getSyncStatus').inc(1);

return indexer.getSyncStatus();
}
}
};
Expand Down
26 changes: 13 additions & 13 deletions src/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -4654,6 +4654,18 @@ input DecreaseEvent_filter {
or: [DecreaseEvent_filter]
}

type _MetaBlock_ {
hash: Bytes
number: Int!
timestamp: Int
}

type _Meta_ {
block: _MetaBlock_!
deployment: String!
hasIndexingErrors: Boolean!
}

type ResultState {
block: _Block_!
contractAddress: String!
Expand All @@ -4669,18 +4681,6 @@ type SyncStatus {
latestCanonicalBlockNumber: Int!
}

type _MetaBlock_ {
hash: Bytes
number: Int!
timestamp: Int
}

type _Meta_ {
block: _MetaBlock_!
deployment: String!
hasIndexingErrors: Boolean!
}

type Query {
events(blockHash: String!, contractAddress: String!, name: String): [ResultEvent!]
eventsInRange(fromBlockNumber: Int!, toBlockNumber: Int!): [ResultEvent!]
Expand Down Expand Up @@ -4728,10 +4728,10 @@ type Query {
increaseEvents(block: Block_height, where: IncreaseEvent_filter, orderBy: IncreaseEvent_orderBy, orderDirection: OrderDirection, first: Int = 100, skip: Int = 0): [IncreaseEvent!]!
decreaseEvent(id: ID!, block: Block_height): DecreaseEvent
decreaseEvents(block: Block_height, where: DecreaseEvent_filter, orderBy: DecreaseEvent_orderBy, orderDirection: OrderDirection, first: Int = 100, skip: Int = 0): [DecreaseEvent!]!
_meta(block: Block_height): _Meta_
getStateByCID(cid: String!): ResultState
getState(blockHash: String!, contractAddress: String!, kind: String): ResultState
getSyncStatus: SyncStatus
_meta(block: Block_height): _Meta_
}

type Factory {
Expand Down
Loading

0 comments on commit 4783e5e

Please sign in to comment.