
如何检索无人认领的费用(见屏幕快照的绿色矩形),调用UniswapV3合同或UniswapSDKv3?
我想显示投资的总流动资金(每对),包括应计费用。
发布于 2022-03-01 10:10:37
从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
复制相似问题