Skip to content

Commit

Permalink
fix: Positions update in position manager
Browse files Browse the repository at this point in the history
  • Loading branch information
chef-huan committed Jun 1, 2023
1 parent 85e148c commit 569c557
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
8 changes: 6 additions & 2 deletions subgraphs/user-position-v3/template/mappings/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ export function handleMint(event: MintEvent): void {
transaction.tickLower = BigInt.fromI32(event.params.tickLower);
transaction.tickUpper = BigInt.fromI32(event.params.tickUpper);
transaction.increaseLiquidityAmount = event.params.amount;
transaction.pool = pool.id;

transaction.save();

updateUserPosition(event, transaction, pool.id);
updateUserPosition(event, transaction);
}

export function handleBurn(event: BurnEvent): void {
Expand Down Expand Up @@ -76,7 +78,9 @@ export function handleBurn(event: BurnEvent): void {
transaction.tickLower = BigInt.fromI32(event.params.tickLower);
transaction.tickUpper = BigInt.fromI32(event.params.tickUpper);
transaction.decreaseLiquidityAmount = event.params.amount;
transaction.pool = pool.id;

transaction.save();

updateUserPosition(event, transaction, pool.id);
updateUserPosition(event, transaction);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ import {
IncreaseLiquidity,
Transfer,
} from "../generated/NonfungiblePositionManager/NonfungiblePositionManager";
import { loadTransaction } from "../utils/schema";
import { loadTransaction, updateUserPosition } from "../utils/schema";
import { ADDRESS_ZERO } from "../utils/constants";
import { UserPosition } from "../generated/schema";

export function handleIncreaseLiquidity(event: IncreaseLiquidity): void {
let transaction = loadTransaction(event);
transaction.tokenId = event.params.tokenId;
transaction.save();
updateUserPosition(event, transaction);
}

export function handleDecreaseLiquidity(event: DecreaseLiquidity): void {
let transaction = loadTransaction(event);
transaction.tokenId = event.params.tokenId;
transaction.save();
updateUserPosition(event, transaction);
}

export function handleTransfer(event: Transfer): void {
Expand Down
3 changes: 2 additions & 1 deletion subgraphs/user-position-v3/template/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Pool @entity {
type Transaction @entity {
# txn hash
id: ID!
pool: Pool
# block txn was included in
blockNumber: BigInt!
# timestamp txn was confirmed
Expand Down Expand Up @@ -122,7 +123,7 @@ type UserPosition @entity {
id: ID!
owner: Bytes!
# pool position is within
pool: Pool!
pool: Pool

liquidity: BigInt!
tickLower: BigInt!
Expand Down
4 changes: 2 additions & 2 deletions subgraphs/user-position-v3/template/utils/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function loadTransaction(event: ethereum.Event): Transaction {
return transaction as Transaction;
}

export function updateUserPosition(event: ethereum.Event, tx: Transaction, poolId: string): void {
export function updateUserPosition(event: ethereum.Event, tx: Transaction): void {
if (
tx.isPositionUpdated === false &&
tx.tickLower !== null &&
Expand All @@ -29,7 +29,7 @@ export function updateUserPosition(event: ethereum.Event, tx: Transaction, poolI
if (userPosition === null) {
userPosition = new UserPosition(tx.tokenId.toString());
userPosition.liquidity = ZERO_BI;
userPosition.pool = poolId;
userPosition.pool = tx.pool;
userPosition.createdAtBlockNumber = event.block.number;
userPosition.createdAtTimestamp = event.block.timestamp;
}
Expand Down

0 comments on commit 569c557

Please sign in to comment.