我无法通过 quoteExactInputSingle -uniswap-v3-quoter 获得正确的 amountOut

问题描述 投票:0回答:1
const Web3 = require("web3")
const fs = require('fs')

let web3 = new Web3('http://127.0.0.1:8545')

let myABI = JSON.parse(fs.readFileSync('./0_abi/Quoter.abi').toString())

let addrQuoter = '0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6' // quoter
let addrTokenIn = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' // ETH
let addrTokenOut = '0x6B175474E89094C44Da98b954EedeAC495271d0F' // DAI

let fee = 500 // 0.05%
let amountIn = 3
let sqrtPriceLimitX96 = 0

let myContract = new web3.eth.Contract(myABI, addrQuoter)

myContract.methods.quoteExactInputSingle(
    addrTokenIn,
    addrTokenOut,
    fee,
    amountIn,
    sqrtPriceLimitX96).call((err, res) => {
    if (err) return console.log(err)
    console.log(res)
})

如果 amountIn 为 1,则 res 为 0
如果amountIn为2,则res为2730,接近真实市场价格
如果 amountIn 为 3,则 res 为 5461,
...
所以实际的 amountIn 是 (amountIn - 1)
为什么?
而且流动性有限。但随着 amountIn 变大, amountOut 也会变大。 \

javascript web3js pool uniswap
1个回答
0
投票

1 表示 1 wei,而不是 1 ether。因此,如果 amountIn 为 1,则 amountIn 已全部支付费用。

© www.soinside.com 2019 - 2024. All rights reserved.