Skip to main content

position-manager.ts

File Missing

The complete file is missing for arbitrum-one

path: /src/mappings/position-manager.ts

getPosition()

Params:
- event (ethereum.Event): An event from the NFT Position Manager contract
- tokenId (BigInt): NFT Id for the staked position

ReturnType: Position | null
  • Returns a Position entity for the given tokenId if found.
  • If not found, retrieves a position by directly querying the NonfungiblePositionManager contract using the ABI. Invokes factoryContract.getPool() and passing it the position's parameters token0, token1 and fee to find the pool contract address.
  • Then creates a new position entity for the tokenId and set the metadata properties using position read earlier from the NonfungiblePositionManager contract. Sets the metrics to ZERO_BD.
No Position for same Block Mint and burn

In certain scenarios, the position is minted and burnt within the same block. The contract call to NonfungiblePositionManager to retrieve position data reverts in such scenarios as the position no longer exists.

Entities

  1. Position - Read/Create Without Saving

ABI Dependencies:

  1. NonfungiblePositionManager.json

Dependencies:

  1. factoryContract
  2. ZERO_BI
  3. ZERO_BD
  4. ADDRESS_ZERO
  5. loadTransaction()

Invoked at:

  1. handleIncreaseLiquidity()
  2. handleDecreaseLiquidity()
  3. handleCollect()
  4. handleTransfer()

updateFeeVars()

Params:
- position (Position): The position for which the fee variables are set
- event (ethereum.Event): An event from the NFT Position Manager contract
- tokenId (BigInt): NFT Id for the staked position

ReturnType: Position
  • Updates the fields position.feeGrowthInside0LastX128 and position.feeGrowthInside1LastX128 for the position represented by tokenId by reading the value from the NonfungiblePositionManager triggering the event.

Entities

  1. Position - Update Fields Without Saving

ABI Dependencies:

  1. NonfungiblePositionManager.json

Invoked at:

  1. handleIncreaseLiquidity()
  2. handleDecreaseLiquidity()
  3. handleCollect()

savePositionSnapshot()

Params:
- position (Position): Position entity for which the current state is saved as a snapshot
- event (ethereum.Event): NonfungiblePositionManager Contract event after which the snapshot is being saved

ReturnType: void
  • Saves the current values of a Position entity for future reference, including liquidity, tokens deposited and withdrawn, fee collected, feeGrowthInside.

Entities

  1. PositionSnapshot() - Create

Dependencies:

  1. loadTransaction()

Invoked at:

  1. handleIncreaseLiquidity()
  2. handleDecreaseLiquidity()
  3. handleCollect()
  4. handleTransfer()

handleIncreaseLiquidity()

Params:
- event (IncreaseLiquidity): Entity for a IncreaseLiquidity event emitted by NonfungiblePositionManager Contract

ReturnType: void
Ignored Blocks and Addresses
  • Block 14317993 is ignored by the function.
  • Pool address 0x8fe8d9bb8eeba3ed688069c3d6b556c9ca258248 (MULAN-USDT) is ignored by the function.
  • Fetches the position entity using getPosition(), passing event.params.tokenId and event as parameters.
  • Updates fields position.liquidity, position.depositedToken0 and position.depositedToken1.
  • Triggers updateFeeVars() and savePositionSnapshot()

Entities

  1. Position - Write
  2. Token - Read

Dependencies:

  1. getPosition()
  2. convertTokenToDecimal()
  3. updateFeeVars()
  4. savePositionSnapshot()

Invoked at:

  1. IncreaseLiquidity Event (Handler)

handleDecreaseLiquidity()

Params:
- event (DecreaseLiquidity): Entity for a DecreaseLiquidity event emitted by NonfungiblePositionManager Contract

ReturnType: void
Ignored Blocks and Addresses
  • Block 14317993 is ignored by the function.
  • Pool address 0x8fe8d9bb8eeba3ed688069c3d6b556c9ca258248 (MULAN-USDT) is ignored by the function.
  • Fetches the position entity using getPosition(), passing event.params.tokenId and event as parameters.
  • Updates fields position.liquidity, position.withdrawnToken0 and position.withdrawnToken1.
  • Triggers updateFeeVars() and savePositionSnapshot()

Entities

  1. Position - Write
  2. Token - Read

Dependencies:

  1. getPosition()
  2. convertTokenToDecimal()
  3. updateFeeVars()
  4. savePositionSnapshot()

Invoked at:

  1. DecreaseLiquidity Event (Handler)

handleCollect()

Params:
- event (Collect): Entity for a Collect event emitted by NonfungiblePositionManager Contract

ReturnType: void
Ignored Addresses
  • Pool address 0x8fe8d9bb8eeba3ed688069c3d6b556c9ca258248 (MULAN-USDT) is ignored by the function.
  • Fetches the position entity using getPosition(), passing event.params.tokenId and event as parameters.
  • Updates fields position.collectedFeesToken0 and position.collectedFeesToken1 by adding the event.params.amount0 after adjusting it with token.decimals.
  • Triggers updateFeeVars() and savePositionSnapshot()
Incorrect Collected Fees Token1 amount

event.params.amount0 (adjusted with token0.decimals) is added to both position.collectedFeesToken0 and position.collectedFeesToken1. This logic needs to be validated.

Entities

  1. Position - Write
  2. Token - Read

Dependencies:

  1. getPosition()
  2. convertTokenToDecimal()
  3. updateFeeVars()
  4. savePositionSnapshot()

Invoked at:

  1. Collect Event (Handler)

handleTransfer()

Params:
- event (Transfer): Entity for a Transfer event emitted by NonfungiblePositionManager Contract

ReturnType: void
  • Fetches the position entity using getPosition(), passing event.params.tokenId and event as parameters.
  • Sets position.owner with event.params.to.
  • Triggers savePositionSnapshot().

Entities

  1. Position - Write

Dependencies:

  1. getPosition()
  2. savePositionSnapshot()

Invoked at:

  1. Transfer Event (Handler)