mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-08-03 04:44:06 +00:00
Implement event watchers for NonFungiblePositionManager events. (#141)
Co-authored-by: nabarun <nabarun@deepstacksoft.com>
This commit is contained in:
parent
70e88b1004
commit
29c8c1f80f
@ -51,6 +51,14 @@ Example:
|
|||||||
$ yarn watch:contract --address 0xfE0034a874c2707c23F91D7409E9036F5e08ac34 --kind factory --startingBlock 100
|
$ 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
|
## Scripts
|
||||||
|
|
||||||
* `yarn server`
|
* `yarn server`
|
||||||
|
@ -26,7 +26,7 @@ import { Database } from '../database';
|
|||||||
type: 'string',
|
type: 'string',
|
||||||
require: true,
|
require: true,
|
||||||
demandOption: true,
|
demandOption: true,
|
||||||
describe: 'Kind of contract (factory|pool)'
|
describe: 'Kind of contract (factory|pool|nfpm)'
|
||||||
},
|
},
|
||||||
startingBlock: {
|
startingBlock: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
@ -2,6 +2,7 @@ import { Entity, PrimaryGeneratedColumn, Column, Index } from 'typeorm';
|
|||||||
|
|
||||||
export const KIND_FACTORY = 'factory';
|
export const KIND_FACTORY = 'factory';
|
||||||
export const KIND_POOL = 'pool';
|
export const KIND_POOL = 'pool';
|
||||||
|
export const KIND_NFPM = 'nfpm';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
@Index(['address'], { unique: true })
|
@Index(['address'], { unique: true })
|
||||||
|
@ -10,10 +10,11 @@ import { Config } from '@vulcanize/util';
|
|||||||
import { Database } from './database';
|
import { Database } from './database';
|
||||||
import { Event, UNKNOWN_EVENT_NAME } from './entity/Event';
|
import { Event, UNKNOWN_EVENT_NAME } from './entity/Event';
|
||||||
import { BlockProgress } from './entity/BlockProgress';
|
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 factoryABI from './artifacts/factory.json';
|
||||||
import poolABI from './artifacts/pool.json';
|
import poolABI from './artifacts/pool.json';
|
||||||
|
import nfpmABI from './artifacts/NonfungiblePositionManager.json';
|
||||||
|
|
||||||
// TODO: Move to config.
|
// TODO: Move to config.
|
||||||
const MAX_EVENTS_BLOCK_RANGE = 1000;
|
const MAX_EVENTS_BLOCK_RANGE = 1000;
|
||||||
@ -40,6 +41,7 @@ export class Indexer {
|
|||||||
|
|
||||||
_factoryContract: ethers.utils.Interface
|
_factoryContract: ethers.utils.Interface
|
||||||
_poolContract: ethers.utils.Interface
|
_poolContract: ethers.utils.Interface
|
||||||
|
_nfpmContract: ethers.utils.Interface
|
||||||
|
|
||||||
constructor (config: Config, db: Database, ethClient: EthClient) {
|
constructor (config: Config, db: Database, ethClient: EthClient) {
|
||||||
this._config = config;
|
this._config = config;
|
||||||
@ -49,6 +51,7 @@ export class Indexer {
|
|||||||
|
|
||||||
this._factoryContract = new ethers.utils.Interface(factoryABI);
|
this._factoryContract = new ethers.utils.Interface(factoryABI);
|
||||||
this._poolContract = new ethers.utils.Interface(poolABI);
|
this._poolContract = new ethers.utils.Interface(poolABI);
|
||||||
|
this._nfpmContract = new ethers.utils.Interface(nfpmABI);
|
||||||
}
|
}
|
||||||
|
|
||||||
getResultEvent (event: Event): ResultEvent {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,6 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
|
|||||||
return {
|
return {
|
||||||
BigInt: new BigInt('bigInt'),
|
BigInt: new BigInt('bigInt'),
|
||||||
|
|
||||||
ERC20Event: {
|
|
||||||
__resolveType () {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
FactoryEvent: {
|
FactoryEvent: {
|
||||||
__resolveType () {
|
__resolveType () {
|
||||||
return null;
|
return null;
|
||||||
|
@ -20,17 +20,6 @@ type ResultUInt256 {
|
|||||||
proof: Proof
|
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
|
# Factory Types
|
||||||
|
|
||||||
type ResultGetPool {
|
type ResultGetPool {
|
||||||
@ -104,8 +93,16 @@ type CollectEvent {
|
|||||||
amount1: BigInt!
|
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.
|
# All events emitted by the NonfungiblePositionManager contract.
|
||||||
union NonFungiblePositionManagerEvent = IncreaseLiquidityEvent | DecreaseLiquidityEvent | CollectEvent
|
union NonFungiblePositionManagerEvent = IncreaseLiquidityEvent | DecreaseLiquidityEvent | CollectEvent | TransferEvent
|
||||||
|
|
||||||
|
|
||||||
# Pool Events
|
# Pool Events
|
||||||
|
Loading…
Reference in New Issue
Block a user