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
- Eth Mainnet
- Polygon, Optimism
- Returns a
Position
entity for the giventokenId
if found. - If not found, retrieves a position by directly querying the
NonfungiblePositionManager
contract using the ABI. InvokesfactoryContract.getPool()
and passing it theposition
's parameterstoken0
,token1
andfee
to find thepool
contract address. - Then creates a new position entity for the tokenId and set the metadata properties using
position
read earlier from theNonfungiblePositionManager
contract. Sets the metrics toZERO_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
- Position - Read/Create Without Saving
ABI Dependencies:
- NonfungiblePositionManager.json
Dependencies:
Invoked at:
In addition to mainnet:
- initializes
position.collectedToken0
andposition.collectedToken1
values.
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
andposition.feeGrowthInside1LastX128
for the position represented bytokenId
by reading the value from theNonfungiblePositionManager
triggering theevent
.
Entities
- Position - Update Fields Without Saving
ABI Dependencies:
- NonfungiblePositionManager.json
Invoked at:
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
- PositionSnapshot() - Create
Dependencies:
Invoked at:
handleIncreaseLiquidity()
Params:
- event (IncreaseLiquidity): Entity for a IncreaseLiquidity event emitted by NonfungiblePositionManager Contract
ReturnType: void
- Eth Mainnet
- Polygon
- Optimism
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()
, passingevent.params.tokenId
andevent
as parameters. - Updates fields
position.liquidity
,position.depositedToken0
andposition.depositedToken1
. - Triggers
updateFeeVars()
andsavePositionSnapshot()
Entities
Dependencies:
Invoked at:
handleDecreaseLiquidity()
Params:
- event (DecreaseLiquidity): Entity for a DecreaseLiquidity event emitted by NonfungiblePositionManager Contract
ReturnType: void
- Eth Mainnet
- Polygon
- Optimism
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()
, passingevent.params.tokenId
andevent
as parameters. - Updates fields
position.liquidity
,position.withdrawnToken0
andposition.withdrawnToken1
. - Triggers
updateFeeVars()
andsavePositionSnapshot()
Entities
Dependencies:
Invoked at:
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.
- Eth Mainnet
- Polygon
- Optimism
- Fetches the position entity using
getPosition()
, passingevent.params.tokenId
andevent
as parameters. - Updates fields
position.collectedFeesToken0
andposition.collectedFeesToken1
by adding theevent.params.amount0
after adjusting it withtoken.decimals
. - Triggers
updateFeeVars()
andsavePositionSnapshot()
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
Dependencies:
Invoked at:
Differs from mainnet at the following areas:
- Updates fields
position.collectedToken0
andposition.collectedToken1
by adding theevent.params.amount0
andevent.params.amount1
after adjusting them withtoken.decimals
. - Updates fields
position.collectedFeesToken0
andposition.collectedFeesToken1
by subtractingposition.withdrawnToken
fromposition.collectedToken
. - Updates field
position.amountCollectedUSD
by derivingamount0
andamount1
in their respective USD priced usingbundle.ethPriceUSD
andtoken.derivedETH
and adding to the existing value.
Additional Entities
- Bundle - Read
Differs from mainnet at the following areas:
- Returns without any changes if token0 or token1 entities are null.
- Updates fields
position.collectedToken0
andposition.collectedToken1
by adding theevent.params.amount0
andevent.params.amount1
after adjusting them withtoken.decimals
. - Updates fields
position.collectedFeesToken0
andposition.collectedFeesToken1
by subtractingposition.withdrawnToken
fromposition.collectedToken
.
Additional Entities Referenced
- Bundle - Read
handleTransfer()
Params:
- event (Transfer): Entity for a Transfer event emitted by NonfungiblePositionManager Contract
ReturnType: void
- Fetches the position entity using
getPosition()
, passingevent.params.tokenId
andevent
as parameters. - Sets
position.owner
withevent.params.to
. - Triggers
savePositionSnapshot()
.
Entities
- Position - Write