Uniswap

UniswapV3 獲得無人認領的費用

  • March 1, 2022

在此處輸入圖像描述

如何呼叫 UniswapV3 合約或 Uniswap sdk-v3 檢索無人認領的費用(見螢幕截圖的綠色矩形)?

我想顯示投資的總流動性(每對),包括應計費用。

從 Uniswap V3 頭寸獲取流動性和應計無人認領費用的以下解決方案:

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);

引用自:https://ethereum.stackexchange.com/questions/122569