mirror of
https://github.com/cerc-io/watcher-ts
synced 2024-11-19 20:36:19 +00:00
Handle Position Manager DecreaseLiquidity event. (#148)
Co-authored-by: nabarun <nabarun@deepstacksoft.com>
This commit is contained in:
parent
3477366458
commit
c1ef96ba2e
@ -70,6 +70,14 @@ interface IncreaseLiquidityEvent {
|
||||
amount1: bigint;
|
||||
}
|
||||
|
||||
interface DecreaseLiquidityEvent {
|
||||
__typename: 'DecreaseLiquidityEvent';
|
||||
tokenId: bigint;
|
||||
liquidity: bigint;
|
||||
amount0: bigint;
|
||||
amount1: bigint;
|
||||
}
|
||||
|
||||
interface Block {
|
||||
number: number;
|
||||
hash: string;
|
||||
@ -85,7 +93,7 @@ interface ResultEvent {
|
||||
block: Block;
|
||||
tx: Transaction;
|
||||
contract: string;
|
||||
event: PoolCreatedEvent | InitializeEvent | MintEvent | BurnEvent | SwapEvent | IncreaseLiquidityEvent;
|
||||
event: PoolCreatedEvent | InitializeEvent | MintEvent | BurnEvent | SwapEvent | IncreaseLiquidityEvent | DecreaseLiquidityEvent;
|
||||
proof: {
|
||||
data: string;
|
||||
}
|
||||
@ -153,6 +161,11 @@ export class EventWatcher {
|
||||
this._handleIncreaseLiquidity(block, contract, tx, event as IncreaseLiquidityEvent);
|
||||
break;
|
||||
|
||||
case 'DecreaseLiquidityEvent':
|
||||
log('NFPM DecreaseLiquidity event', contract);
|
||||
this._handleDecreaseLiquidity(block, contract, tx, event as DecreaseLiquidityEvent);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -731,7 +744,7 @@ export class EventWatcher {
|
||||
return;
|
||||
}
|
||||
|
||||
// Temp fix.
|
||||
// Temp fix from Subgraph mapping code.
|
||||
if (utils.getAddress(position.pool.id) === utils.getAddress('0x8fe8d9bb8eeba3ed688069c3d6b556c9ca258248')) {
|
||||
return;
|
||||
}
|
||||
@ -753,6 +766,36 @@ export class EventWatcher {
|
||||
await this._savePositionSnapshot(position, block, tx);
|
||||
}
|
||||
|
||||
async _handleDecreaseLiquidity (block: Block, contractAddress: string, tx: Transaction, event: DecreaseLiquidityEvent): Promise<void> {
|
||||
const { number: blockNumber } = block;
|
||||
const position = await this._getPosition(block, contractAddress, tx, BigInt(event.tokenId));
|
||||
|
||||
// Position was not able to be fetched.
|
||||
if (position == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Temp fix from Subgraph mapping code.
|
||||
if (utils.getAddress(position.pool.id) === utils.getAddress('0x8fe8d9bb8eeba3ed688069c3d6b556c9ca258248')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const token0 = position.token0;
|
||||
const token1 = position.token1;
|
||||
const amount0 = convertTokenToDecimal(BigInt(event.amount0), BigInt(token0.decimals));
|
||||
const amount1 = convertTokenToDecimal(BigInt(event.amount1), BigInt(token1.decimals));
|
||||
|
||||
position.liquidity = BigInt(position.liquidity) - BigInt(event.liquidity);
|
||||
position.depositedToken0 = position.depositedToken0.plus(amount0);
|
||||
position.depositedToken1 = position.depositedToken1.plus(amount1);
|
||||
|
||||
await this._updateFeeVars(position, block, contractAddress, BigInt(event.tokenId));
|
||||
|
||||
await this._db.savePosition(position, blockNumber);
|
||||
|
||||
await this._savePositionSnapshot(position, block, tx);
|
||||
}
|
||||
|
||||
async _getPosition (block: Block, contractAddress: string, tx: Transaction, tokenId: bigint): Promise<Position | null> {
|
||||
const { number: blockNumber, hash: blockHash, timestamp: blockTimestamp } = block;
|
||||
const { hash: txHash } = tx;
|
||||
|
@ -81,6 +81,13 @@ export class Client {
|
||||
amount0
|
||||
amount1
|
||||
}
|
||||
|
||||
... on DecreaseLiquidityEvent {
|
||||
tokenId
|
||||
liquidity
|
||||
amount0
|
||||
amount1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user