首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UniswapV3获得无人认领的费用

UniswapV3获得无人认领的费用
EN

Ethereum用户
提问于 2022-02-25 13:15:15
回答 1查看 923关注 0票数 2

如何检索无人认领的费用(见屏幕快照的绿色矩形),调用UniswapV3合同或UniswapSDKv3?

我想显示投资的总流动资金(每对),包括应计费用。

EN

回答 1

Ethereum用户

回答已采纳

发布于 2022-03-01 10:10:37

从Uniswap V3头寸获得流动性和应计无人认领费用的解决方案如下:

代码语言:javascript
复制
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);
票数 2
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/122569

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档