2

enter image description here

How can the unclaimed fees (see green rectangle of the screen shot) being retrieved calling the UniswapV3 contracts or the Uniswap sdk-v3?

I want to show the total liquidity invested (each pair) including the accrued fees.

1
  • In your pasted code many of the variables are not recognised. Could you please add the correct missing imports at the top of the pasted code? That would be a great help! Feb 23, 2023 at 10:55

1 Answer 1

4

The following solution to get the liquidity and accrued unclaimed fees from a Uniswap V3 position:

const { Pool } = require("@uniswap/v3-sdk");
const { Position } = require("@uniswap/v3-sdk");
const { ethers } = require("ethers");
const { BigNumber } = require("@ethersproject/bignumber");

const MAX_UINT128 = BigNumber.from(2).pow(128).sub(1);

/* GET POSITION LIQUIDITY */
const USDEURPool = new Pool(tokenUSD, 
                            tokenEUR, 
                            Number.parseInt(immutables.fee), 
                            state.sqrtPriceX96.toString(), 
                            state.liquidity.toString(), 
                            Number.parseInt(state.tick) );
const positionInfo = await positionmanagerContract.positions(1058);
const position = new Position({pool: USDEURPool, liquidity: positionInfo.liquidity.toString(), tickLower: positionInfo.tickLower, tickUpper: position.tickUpper});
console.log("amount0:", position.amount0.toSignificant(4));
console.log("amount1:", position.amount1.toSignificant(4));
// get more details such as currency infos from position, such as token symbol, etc.

/* GET ACCRUED UNCLAIMDED FEES */
// callStatic simulates a call without state changes
var results = await positionmanagerContract.callStatic.collect({tokenId: 1058,
                                                                recipient: owner, 
                                                                amount0Max: MAX_UINT128, 
                                                                amount1Max: MAX_UINT128}, {from: owner});
console.log("Fee0:",parseFloat(results.amount0)/100);
console.log("Fee1:",parseFloat(results.amount1)/100);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.