根据白皮书,当一个位置在范围内时
未收费用=流动性( feeGrowthGlobal - feeGrowthOutsidelowerTick - feeGrowthOutsideUpperTick - feeGrowthInside)
但对于稳定的硬币,feeGrowthGlobal - feeGrowthOutsideLowerTick - feeGrowthOutsideUpperTick似乎是负的,导致负的未收取的费用。
示例
{
"id": "149982",
"liquidity": "70751535817529022692995",
"pool": {
"feeGrowthGlobal0X128": "1218682304163016184766177108699434636279"
},
"tickLower": {
"feeGrowthOutside0X128": "1145577432605598277662216874263285465942"
},
"tickUpper": {
"feeGrowthOutside0X128": "1125981180184479101654443162252506477054"
},
"token0": {
"symbol": "DAI"
},
"token1": {
"symbol": "WETH"
}
},1218682304163016184766177108699434636279 - 1145577432605598277662216874263285465942 - 1125981180184479101654443162252506477054 = -1052876308627061194550482927816357306717
发布于 2023-01-02 17:21:15
我的两分钱:
我编写了一个函数,该函数执行静态调用,在其他函数中传递最大可收集值,以查看要收集多少挂起。
export const calculatePendingFees = async (
tokenId: number,
recipient: string,
amount0Max: BigNumber,
amount1Max: BigNumber,
chainId: number
) => {
try {
const params = {
tokenId: tokenId,
recipient: recipient,
amount0Max: amount0Max,
amount1Max: amount1Max,
}
const nonfungible = new ethers.Contract(
NONFUNGIBLE_POSITION_MANAGER_ADDRESS[chainId],
Nonfungiblepositionmanager.abi,
PROVIDER[chainId]
)
const feesGenerated = await nonfungible.callStatic.collect(params)
return feesGenerated
} catch (error) {
console.log(error.message, "calculate fees error")
}
}对于amount0Max和amount1Max,您可以使用以下内容:
const MAX_UINT128 = BigNumber.from(2).pow(128).sub(1)此函数将返回未收取的费用:)
发布于 2023-02-22 20:24:17
在对无符号整数值进行数学计算时,需要考虑潜在的流量低于或过流的情况。更具体地说,Uniswap V3契约期望feeGrowthGlobal - feeGrowthOutsideLowerTick - feeGrowthOutsideUpperTick公式包装-大约256位(即模块),如果您的语言本机实现BigInts (例如BigInts),这可能会令人惊讶。例如,我的Python Pyuv3正确地处理了这个问题。
https://ethereum.stackexchange.com/questions/114295
复制相似问题