diff --git a/packages/delegated-sending-watcher/README.md b/packages/delegated-sending-watcher/README.md index 0e24055..0012c89 100644 --- a/packages/delegated-sending-watcher/README.md +++ b/packages/delegated-sending-watcher/README.md @@ -1,16 +1,6 @@ # delegated-sending-watcher -## Currently unsupported queries - -The watcher was generated in `eth_call` mode and does not support the following queries in its current state: - -* `getPoolStars(uint32 _who) returns (uint16[] stars)` - -* `getInviters() returns (uint32[] invs)` - -* `getInvited(uint32 _who) returns (uint32[] invd)` - -* `getPool(uint32 _point) returns (uint32 pool)` +This watcher has been generated based on the `DelegatedSending` contract deployed at [0xf6b461fe1ad4bd2ce25b23fe0aff2ac19b3dfa76](https://etherscan.io/address/0xf6b461fe1ad4bd2ce25b23fe0aff2ac19b3dfa76#code#L1) ## Setup diff --git a/packages/delegated-sending-watcher/src/artifacts/DelegatedSending.json b/packages/delegated-sending-watcher/src/artifacts/DelegatedSending.json index 2760405..ecff966 100644 --- a/packages/delegated-sending-watcher/src/artifacts/DelegatedSending.json +++ b/packages/delegated-sending-watcher/src/artifacts/DelegatedSending.json @@ -1,101 +1,17 @@ { "abi": [ { - "constant": true, - "inputs": [], - "name": "getInviters", - "outputs": [ - { - "name": "invs", - "type": "uint32[]" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "", - "type": "uint32" - } - ], - "name": "isInviter", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "", - "type": "uint32" - }, - { - "name": "", - "type": "uint16" - } - ], - "name": "poolStarsRegistered", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "", - "type": "uint32" - } - ], - "name": "invitedBy", - "outputs": [ - { - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, + "constant": false, "inputs": [ { - "name": "", + "name": "_for", "type": "uint32" - }, - { - "name": "", - "type": "uint16" - } - ], - "name": "pools", - "outputs": [ - { - "name": "", - "type": "uint16" } ], + "name": "resetPool", + "outputs": [], "payable": false, - "stateMutability": "view", + "stateMutability": "nonpayable", "type": "function" }, { @@ -132,7 +48,7 @@ "outputs": [ { "name": "", - "type": "uint32" + "type": "uint64" } ], "payable": false, @@ -167,33 +83,10 @@ "inputs": [ { "name": "", - "type": "uint256" + "type": "uint64" } ], - "name": "inviters", - "outputs": [ - { - "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "", - "type": "uint32" - }, - { - "name": "", - "type": "uint256" - } - ], - "name": "poolStars", + "name": "pools", "outputs": [ { "name": "", @@ -228,37 +121,14 @@ "inputs": [ { "name": "", - "type": "uint32" - }, - { - "name": "", - "type": "uint256" + "type": "uint16" } ], - "name": "invited", + "name": "limits", "outputs": [ { "name": "", - "type": "uint32" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "_point", - "type": "uint32" - } - ], - "name": "getPool", - "outputs": [ - { - "name": "pool", - "type": "uint32" + "type": "uint16" } ], "payable": false, @@ -266,22 +136,21 @@ "type": "function" }, { - "constant": true, + "constant": false, "inputs": [ { - "name": "_who", - "type": "uint32" - } - ], - "name": "getPoolStars", - "outputs": [ + "name": "_prefix", + "type": "uint16" + }, { - "name": "stars", - "type": "uint16[]" + "name": "_limit", + "type": "uint16" } ], + "name": "configureLimit", + "outputs": [], "payable": false, - "stateMutability": "view", + "stateMutability": "nonpayable", "type": "function" }, { @@ -298,47 +167,6 @@ "stateMutability": "view", "type": "function" }, - { - "constant": true, - "inputs": [ - { - "name": "_who", - "type": "uint32" - } - ], - "name": "getInvited", - "outputs": [ - { - "name": "invd", - "type": "uint32[]" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_as", - "type": "uint16" - }, - { - "name": "_for", - "type": "uint32" - }, - { - "name": "_size", - "type": "uint16" - } - ], - "name": "setPoolSize", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, { "inputs": [ { @@ -350,28 +178,6 @@ "stateMutability": "nonpayable", "type": "constructor" }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "prefix", - "type": "uint16" - }, - { - "indexed": true, - "name": "who", - "type": "uint32" - }, - { - "indexed": false, - "name": "size", - "type": "uint16" - } - ], - "name": "Pool", - "type": "event" - }, { "anonymous": false, "inputs": [ @@ -383,7 +189,7 @@ { "indexed": true, "name": "fromPool", - "type": "uint32" + "type": "uint64" }, { "indexed": false, diff --git a/packages/delegated-sending-watcher/src/client.ts b/packages/delegated-sending-watcher/src/client.ts index 0203123..3e373a7 100644 --- a/packages/delegated-sending-watcher/src/client.ts +++ b/packages/delegated-sending-watcher/src/client.ts @@ -26,15 +26,6 @@ export class Client { return canSend; } - async getGetPool (blockHash: string, contractAddress: string, _point: bigint): Promise { - const { getPool } = await this._client.query( - gql(queries.getPool), - { blockHash, contractAddress, _point } - ); - - return getPool; - } - async getCanReceive (blockHash: string, contractAddress: string, _recipient: string): Promise { const { canReceive } = await this._client.query( gql(queries.canReceive), diff --git a/packages/delegated-sending-watcher/src/database.ts b/packages/delegated-sending-watcher/src/database.ts index 9f861dd..145e9b0 100644 --- a/packages/delegated-sending-watcher/src/database.ts +++ b/packages/delegated-sending-watcher/src/database.ts @@ -21,10 +21,9 @@ import { StateSyncStatus } from './entity/StateSyncStatus'; import { BlockProgress } from './entity/BlockProgress'; import { State } from './entity/State'; import { CanSend } from './entity/CanSend'; -import { GetPool } from './entity/GetPool'; import { CanReceive } from './entity/CanReceive'; -export const ENTITIES = [CanSend, GetPool, CanReceive]; +export const ENTITIES = [CanSend, CanReceive]; export class Database implements DatabaseInterface { _config: ConnectionOptions; @@ -67,15 +66,6 @@ export class Database implements DatabaseInterface { }); } - async getGetPool ({ blockHash, contractAddress, _point }: { blockHash: string, contractAddress: string, _point: bigint }): Promise { - return this._conn.getRepository(GetPool) - .findOne({ - blockHash, - contractAddress, - _point - }); - } - async getCanReceive ({ blockHash, contractAddress, _recipient }: { blockHash: string, contractAddress: string, _recipient: string }): Promise { return this._conn.getRepository(CanReceive) .findOne({ @@ -91,12 +81,6 @@ export class Database implements DatabaseInterface { return repo.save(entity); } - async saveGetPool ({ blockHash, blockNumber, contractAddress, _point, value, proof }: DeepPartial): Promise { - const repo = this._conn.getRepository(GetPool); - const entity = repo.create({ blockHash, blockNumber, contractAddress, _point, value, proof }); - return repo.save(entity); - } - async saveCanReceive ({ blockHash, blockNumber, contractAddress, _recipient, value, proof }: DeepPartial): Promise { const repo = this._conn.getRepository(CanReceive); const entity = repo.create({ blockHash, blockNumber, contractAddress, _recipient, value, proof }); @@ -309,7 +293,6 @@ export class Database implements DatabaseInterface { _setPropColMaps (): void { this._propColMaps.CanSend = this._getPropertyColumnMapForEntity('CanSend'); - this._propColMaps.GetPool = this._getPropertyColumnMapForEntity('GetPool'); this._propColMaps.CanReceive = this._getPropertyColumnMapForEntity('CanReceive'); } } diff --git a/packages/delegated-sending-watcher/src/gql/queries/events.gql b/packages/delegated-sending-watcher/src/gql/queries/events.gql index 9621a51..12ccbf3 100644 --- a/packages/delegated-sending-watcher/src/gql/queries/events.gql +++ b/packages/delegated-sending-watcher/src/gql/queries/events.gql @@ -16,11 +16,6 @@ query events($blockHash: String!, $contractAddress: String!, $name: String){ contract eventIndex event{ - ... on PoolEvent { - prefix - who - size - } ... on SentEvent { prefix fromPool diff --git a/packages/delegated-sending-watcher/src/gql/queries/eventsInRange.gql b/packages/delegated-sending-watcher/src/gql/queries/eventsInRange.gql index a6ec50a..8161ad7 100644 --- a/packages/delegated-sending-watcher/src/gql/queries/eventsInRange.gql +++ b/packages/delegated-sending-watcher/src/gql/queries/eventsInRange.gql @@ -16,11 +16,6 @@ query eventsInRange($fromBlockNumber: Int!, $toBlockNumber: Int!){ contract eventIndex event{ - ... on PoolEvent { - prefix - who - size - } ... on SentEvent { prefix fromPool diff --git a/packages/delegated-sending-watcher/src/gql/queries/getInvited.gql b/packages/delegated-sending-watcher/src/gql/queries/getInvited.gql deleted file mode 100644 index 6739f15..0000000 --- a/packages/delegated-sending-watcher/src/gql/queries/getInvited.gql +++ /dev/null @@ -1,8 +0,0 @@ -query getInvited($blockHash: String!, $contractAddress: String!, $_who: BigInt!){ - getInvited(blockHash: $blockHash, contractAddress: $contractAddress, _who: $_who){ - value - proof{ - data - } - } -} \ No newline at end of file diff --git a/packages/delegated-sending-watcher/src/gql/queries/getInviters.gql b/packages/delegated-sending-watcher/src/gql/queries/getInviters.gql deleted file mode 100644 index 3df2b00..0000000 --- a/packages/delegated-sending-watcher/src/gql/queries/getInviters.gql +++ /dev/null @@ -1,8 +0,0 @@ -query getInviters($blockHash: String!, $contractAddress: String!){ - getInviters(blockHash: $blockHash, contractAddress: $contractAddress){ - value - proof{ - data - } - } -} \ No newline at end of file diff --git a/packages/delegated-sending-watcher/src/gql/queries/getPool.gql b/packages/delegated-sending-watcher/src/gql/queries/getPool.gql deleted file mode 100644 index 7d9f8b5..0000000 --- a/packages/delegated-sending-watcher/src/gql/queries/getPool.gql +++ /dev/null @@ -1,8 +0,0 @@ -query getPool($blockHash: String!, $contractAddress: String!, $_point: BigInt!){ - getPool(blockHash: $blockHash, contractAddress: $contractAddress, _point: $_point){ - value - proof{ - data - } - } -} \ No newline at end of file diff --git a/packages/delegated-sending-watcher/src/gql/queries/getPoolStars.gql b/packages/delegated-sending-watcher/src/gql/queries/getPoolStars.gql deleted file mode 100644 index accaa3f..0000000 --- a/packages/delegated-sending-watcher/src/gql/queries/getPoolStars.gql +++ /dev/null @@ -1,8 +0,0 @@ -query getPoolStars($blockHash: String!, $contractAddress: String!, $_who: BigInt!){ - getPoolStars(blockHash: $blockHash, contractAddress: $contractAddress, _who: $_who){ - value - proof{ - data - } - } -} \ No newline at end of file diff --git a/packages/delegated-sending-watcher/src/gql/queries/index.ts b/packages/delegated-sending-watcher/src/gql/queries/index.ts index 056cc3c..7af94a3 100644 --- a/packages/delegated-sending-watcher/src/gql/queries/index.ts +++ b/packages/delegated-sending-watcher/src/gql/queries/index.ts @@ -4,11 +4,7 @@ import path from 'path'; export const events = fs.readFileSync(path.join(__dirname, 'events.gql'), 'utf8'); export const eventsInRange = fs.readFileSync(path.join(__dirname, 'eventsInRange.gql'), 'utf8'); export const canSend = fs.readFileSync(path.join(__dirname, 'canSend.gql'), 'utf8'); -export const getPool = fs.readFileSync(path.join(__dirname, 'getPool.gql'), 'utf8'); export const canReceive = fs.readFileSync(path.join(__dirname, 'canReceive.gql'), 'utf8'); -export const getPoolStars = fs.readFileSync(path.join(__dirname, 'getPoolStars.gql'), 'utf8'); -export const getInviters = fs.readFileSync(path.join(__dirname, 'getInviters.gql'), 'utf8'); -export const getInvited = fs.readFileSync(path.join(__dirname, 'getInvited.gql'), 'utf8'); export const getSyncStatus = fs.readFileSync(path.join(__dirname, 'getSyncStatus.gql'), 'utf8'); export const getStateByCID = fs.readFileSync(path.join(__dirname, 'getStateByCID.gql'), 'utf8'); export const getState = fs.readFileSync(path.join(__dirname, 'getState.gql'), 'utf8'); diff --git a/packages/delegated-sending-watcher/src/gql/subscriptions/onEvent.gql b/packages/delegated-sending-watcher/src/gql/subscriptions/onEvent.gql index f0917d9..5df179b 100644 --- a/packages/delegated-sending-watcher/src/gql/subscriptions/onEvent.gql +++ b/packages/delegated-sending-watcher/src/gql/subscriptions/onEvent.gql @@ -16,11 +16,6 @@ subscription onEvent{ contract eventIndex event{ - ... on PoolEvent { - prefix - who - size - } ... on SentEvent { prefix fromPool diff --git a/packages/delegated-sending-watcher/src/indexer.ts b/packages/delegated-sending-watcher/src/indexer.ts index e7b0cd1..c592fe0 100644 --- a/packages/delegated-sending-watcher/src/indexer.ts +++ b/packages/delegated-sending-watcher/src/indexer.ts @@ -123,37 +123,6 @@ export class Indexer implements IndexerInterface { return result; } - async getPool (blockHash: string, contractAddress: string, _point: bigint): Promise { - const entity = await this._db.getGetPool({ blockHash, contractAddress, _point }); - if (entity) { - log('getPool: db hit.'); - - return { - value: entity.value, - proof: JSON.parse(entity.proof) - }; - } - - const { block: { number } } = await this._ethClient.getBlockByHash(blockHash); - const blockNumber = ethers.BigNumber.from(number).toNumber(); - - log('getPool: db miss, fetching from upstream server'); - - const abi = this._abiMap.get(KIND_DELEGATEDSENDING); - assert(abi); - - const contract = new ethers.Contract(contractAddress, abi, this._ethProvider); - const contractResult = await contract.getPool(_point, { blockTag: blockHash }); - - const value = ethers.BigNumber.from(contractResult).toBigInt(); - - const result: ValueResult = { value }; - - await this._db.saveGetPool({ blockHash, blockNumber, contractAddress, _point, value: result.value, proof: JSONbigNative.stringify(result.proof) }); - - return result; - } - async canReceive (blockHash: string, contractAddress: string, _recipient: string): Promise { const entity = await this._db.getCanReceive({ blockHash, contractAddress, _recipient }); if (entity) { @@ -184,51 +153,6 @@ export class Indexer implements IndexerInterface { return result; } - async getPoolStars (blockHash: string, contractAddress: string, _who: bigint): Promise { - log('getPoolStars: db miss, fetching from upstream server'); - - const abi = this._abiMap.get(KIND_DELEGATEDSENDING); - assert(abi); - - const contract = new ethers.Contract(contractAddress, abi, this._ethProvider); - const contractResult = await contract.getPoolStars(_who, { blockTag: blockHash }); - - const value = contractResult; - const result: ValueResult = { value }; - - return result; - } - - async getInviters (blockHash: string, contractAddress: string): Promise { - log('getInviters: db miss, fetching from upstream server'); - - const abi = this._abiMap.get(KIND_DELEGATEDSENDING); - assert(abi); - - const contract = new ethers.Contract(contractAddress, abi, this._ethProvider); - const contractResult = await contract.getInviters({ blockTag: blockHash }); - - const value = contractResult.map((val: ethers.BigNumber | number) => ethers.BigNumber.from(val).toBigInt()); - const result: ValueResult = { value }; - - return result; - } - - async getInvited (blockHash: string, contractAddress: string, _who: bigint): Promise { - log('getInvited: db miss, fetching from upstream server'); - - const abi = this._abiMap.get(KIND_DELEGATEDSENDING); - assert(abi); - - const contract = new ethers.Contract(contractAddress, abi, this._ethProvider); - const contractResult = await contract.getInvited(_who, { blockTag: blockHash }); - - const value = contractResult.map((val: ethers.BigNumber | number) => ethers.BigNumber.from(val).toBigInt()); - const result: ValueResult = { value }; - - return result; - } - async getStorageValue (storageLayout: StorageLayout, blockHash: string, contractAddress: string, variable: string, ...mappingKeys: MappingKey[]): Promise { return this._baseIndexer.getStorageValue( storageLayout, diff --git a/packages/delegated-sending-watcher/src/resolvers.ts b/packages/delegated-sending-watcher/src/resolvers.ts index d0425dd..bfccda0 100644 --- a/packages/delegated-sending-watcher/src/resolvers.ts +++ b/packages/delegated-sending-watcher/src/resolvers.ts @@ -90,24 +90,6 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher return indexer.canSend(blockHash, contractAddress, _as, _point); }, - getPool: ( - _: any, - { blockHash, contractAddress, _point }: { blockHash: string, contractAddress: string, _point: bigint }, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - __: any, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - info: GraphQLResolveInfo - ): Promise => { - log('getPool', blockHash, contractAddress, _point); - gqlTotalQueryCount.inc(1); - gqlQueryCount.labels('getPool').inc(1); - - // Set cache-control hints - // setGQLCacheHints(info, {}, gqlCacheConfig); - - return indexer.getPool(blockHash, contractAddress, _point); - }, - canReceive: ( _: any, { blockHash, contractAddress, _recipient }: { blockHash: string, contractAddress: string, _recipient: string }, @@ -126,60 +108,6 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher return indexer.canReceive(blockHash, contractAddress, _recipient); }, - getPoolStars: ( - _: any, - { blockHash, contractAddress, _who }: { blockHash: string, contractAddress: string, _who: bigint }, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - __: any, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - info: GraphQLResolveInfo - ): Promise => { - log('getPoolStars', blockHash, contractAddress, _who); - gqlTotalQueryCount.inc(1); - gqlQueryCount.labels('getPoolStars').inc(1); - - // Set cache-control hints - // setGQLCacheHints(info, {}, gqlCacheConfig); - - return indexer.getPoolStars(blockHash, contractAddress, _who); - }, - - getInviters: ( - _: any, - { blockHash, contractAddress }: { blockHash: string, contractAddress: string }, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - __: any, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - info: GraphQLResolveInfo - ): Promise => { - log('getInviters', blockHash, contractAddress); - gqlTotalQueryCount.inc(1); - gqlQueryCount.labels('getInviters').inc(1); - - // Set cache-control hints - // setGQLCacheHints(info, {}, gqlCacheConfig); - - return indexer.getInviters(blockHash, contractAddress); - }, - - getInvited: ( - _: any, - { blockHash, contractAddress, _who }: { blockHash: string, contractAddress: string, _who: bigint }, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - __: any, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - info: GraphQLResolveInfo - ): Promise => { - log('getInvited', blockHash, contractAddress, _who); - gqlTotalQueryCount.inc(1); - gqlQueryCount.labels('getInvited').inc(1); - - // Set cache-control hints - // setGQLCacheHints(info, {}, gqlCacheConfig); - - return indexer.getInvited(blockHash, contractAddress, _who); - }, - events: async (_: any, { blockHash, contractAddress, name }: { blockHash: string, contractAddress: string, name?: string }) => { log('events', blockHash, contractAddress, name); gqlTotalQueryCount.inc(1); diff --git a/packages/delegated-sending-watcher/src/schema.gql b/packages/delegated-sending-watcher/src/schema.gql index 287c81a..584c1a2 100644 --- a/packages/delegated-sending-watcher/src/schema.gql +++ b/packages/delegated-sending-watcher/src/schema.gql @@ -39,13 +39,7 @@ type ResultEvent { proof: Proof } -union Event = PoolEvent | SentEvent - -type PoolEvent { - prefix: Int! - who: BigInt! - size: Int! -} +union Event = SentEvent type SentEvent { prefix: Int! @@ -60,21 +54,6 @@ type ResultBoolean { proof: Proof } -type ResultBigInt { - value: BigInt! - proof: Proof -} - -type ResultIntArray { - value: [Int!]! - proof: Proof -} - -type ResultBigIntArray { - value: [BigInt!]! - proof: Proof -} - type SyncStatus { latestIndexedBlockHash: String! latestIndexedBlockNumber: Int! @@ -94,11 +73,7 @@ type Query { events(blockHash: String!, contractAddress: String!, name: String): [ResultEvent!] eventsInRange(fromBlockNumber: Int!, toBlockNumber: Int!): [ResultEvent!] canSend(blockHash: String!, contractAddress: String!, _as: BigInt!, _point: BigInt!): ResultBoolean! - getPool(blockHash: String!, contractAddress: String!, _point: BigInt!): ResultBigInt! canReceive(blockHash: String!, contractAddress: String!, _recipient: String!): ResultBoolean! - getPoolStars(blockHash: String!, contractAddress: String!, _who: BigInt!): ResultIntArray! - getInviters(blockHash: String!, contractAddress: String!): ResultBigIntArray! - getInvited(blockHash: String!, contractAddress: String!, _who: BigInt!): ResultBigIntArray! getSyncStatus: SyncStatus getStateByCID(cid: String!): ResultState getState(blockHash: String!, contractAddress: String!, kind: String): ResultState