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)
})
if amountIn is 1, res is 0
if amountIn is 2, res is 2730, close to the real market price
if amountIn is 3, res is 5461,
...
so the real amountIn is (amountIn - 1)
why?
And the liquidity is limited. But as the amountIn become bigger, the amountOut is bigger. \
1 means 1 wei, not 1 ether. So, if amountIn is 1, the amountIn is paid for fee totally.