diff --git a/packages/uni-watcher/README.md b/packages/uni-watcher/README.md index d4ee5bf0..9a4acc8c 100644 --- a/packages/uni-watcher/README.md +++ b/packages/uni-watcher/README.md @@ -51,6 +51,14 @@ Example: $ yarn watch:contract --address 0xfE0034a874c2707c23F91D7409E9036F5e08ac34 --kind factory --startingBlock 100 ``` +Start watching the NonFungiblePositionManager contract: + +Example: + +```bash +$ yarn watch:contract --address 0xB171168C0df9457Ff3E3D795aE25Bf4f41e2FFE3 --kind nfpm --startingBlock 100 +``` + ## Scripts * `yarn server` diff --git a/packages/uni-watcher/src/cli/watch-contract.ts b/packages/uni-watcher/src/cli/watch-contract.ts index c49d42b8..5c981ee2 100644 --- a/packages/uni-watcher/src/cli/watch-contract.ts +++ b/packages/uni-watcher/src/cli/watch-contract.ts @@ -26,7 +26,7 @@ import { Database } from '../database'; type: 'string', require: true, demandOption: true, - describe: 'Kind of contract (factory|pool)' + describe: 'Kind of contract (factory|pool|nfpm)' }, startingBlock: { type: 'number', diff --git a/packages/uni-watcher/src/entity/Contract.ts b/packages/uni-watcher/src/entity/Contract.ts index 46755cce..a767ea3c 100644 --- a/packages/uni-watcher/src/entity/Contract.ts +++ b/packages/uni-watcher/src/entity/Contract.ts @@ -2,6 +2,7 @@ import { Entity, PrimaryGeneratedColumn, Column, Index } from 'typeorm'; export const KIND_FACTORY = 'factory'; export const KIND_POOL = 'pool'; +export const KIND_NFPM = 'nfpm'; @Entity() @Index(['address'], { unique: true }) diff --git a/packages/uni-watcher/src/indexer.ts b/packages/uni-watcher/src/indexer.ts index 32441e0d..71fedd93 100644 --- a/packages/uni-watcher/src/indexer.ts +++ b/packages/uni-watcher/src/indexer.ts @@ -10,10 +10,11 @@ import { Config } from '@vulcanize/util'; import { Database } from './database'; import { Event, UNKNOWN_EVENT_NAME } from './entity/Event'; import { BlockProgress } from './entity/BlockProgress'; -import { Contract, KIND_FACTORY, KIND_POOL } from './entity/Contract'; +import { Contract, KIND_FACTORY, KIND_POOL, KIND_NFPM } from './entity/Contract'; import factoryABI from './artifacts/factory.json'; import poolABI from './artifacts/pool.json'; +import nfpmABI from './artifacts/NonfungiblePositionManager.json'; // TODO: Move to config. const MAX_EVENTS_BLOCK_RANGE = 1000; @@ -40,6 +41,7 @@ export class Indexer { _factoryContract: ethers.utils.Interface _poolContract: ethers.utils.Interface + _nfpmContract: ethers.utils.Interface constructor (config: Config, db: Database, ethClient: EthClient) { this._config = config; @@ -49,6 +51,7 @@ export class Indexer { this._factoryContract = new ethers.utils.Interface(factoryABI); this._poolContract = new ethers.utils.Interface(poolABI); + this._nfpmContract = new ethers.utils.Interface(nfpmABI); } getResultEvent (event: Event): ResultEvent { @@ -212,6 +215,64 @@ export class Indexer { } } + break; + } + case KIND_NFPM: { + const logDescription = this._nfpmContract.parseLog({ data, topics }); + switch (logDescription.name) { + case 'IncreaseLiquidity': { + eventName = logDescription.name; + const { tokenId, liquidity, amount0, amount1 } = logDescription.args; + + eventInfo = { + tokenId: tokenId.toString(), + liquidity: liquidity.toString(), + amount0: amount0.toString(), + amount1: amount1.toString() + }; + + break; + } + case 'DecreaseLiquidity': { + eventName = logDescription.name; + const { tokenId, liquidity, amount0, amount1 } = logDescription.args; + + eventInfo = { + tokenId: tokenId.toString(), + liquidity: liquidity.toString(), + amount0: amount0.toString(), + amount1: amount1.toString() + }; + + break; + } + case 'Collect': { + eventName = logDescription.name; + const { tokenId, recipient, amount0, amount1 } = logDescription.args; + + eventInfo = { + tokenId: tokenId.toString(), + recipient, + amount0: amount0.toString(), + amount1: amount1.toString() + }; + + break; + } + case 'Transfer': { + eventName = logDescription.name; + const { from, to, tokenId } = logDescription.args; + + eventInfo = { + from, + to, + tokenId: tokenId.toString() + }; + + break; + } + } + break; } } diff --git a/packages/uni-watcher/src/resolvers.ts b/packages/uni-watcher/src/resolvers.ts index 9130e565..1e02f17f 100644 --- a/packages/uni-watcher/src/resolvers.ts +++ b/packages/uni-watcher/src/resolvers.ts @@ -11,12 +11,6 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch return { BigInt: new BigInt('bigInt'), - ERC20Event: { - __resolveType () { - return null; - } - }, - FactoryEvent: { __resolveType () { return null; diff --git a/packages/uni-watcher/src/schema.ts b/packages/uni-watcher/src/schema.ts index 0001e5fd..1b30751a 100644 --- a/packages/uni-watcher/src/schema.ts +++ b/packages/uni-watcher/src/schema.ts @@ -20,17 +20,6 @@ type ResultUInt256 { proof: Proof } -# ERC20 Events - -# event Transfer(address indexed from, address indexed to, uint256 value); -type TransferEvent { - from: String! - to: String! - value: BigInt! -} - -union ERC20Event = TransferEvent - # Factory Types type ResultGetPool { @@ -104,8 +93,16 @@ type CollectEvent { amount1: BigInt! } +# ERC721 Event +# event Transfer(address indexed from, address indexed to, uint256 tokenId); +type TransferEvent { + from: String! + to: String! + tokenId: BigInt! +} + # All events emitted by the NonfungiblePositionManager contract. -union NonFungiblePositionManagerEvent = IncreaseLiquidityEvent | DecreaseLiquidityEvent | CollectEvent +union NonFungiblePositionManagerEvent = IncreaseLiquidityEvent | DecreaseLiquidityEvent | CollectEvent | TransferEvent # Pool Events