I’m trying to create a node.js software which, on the polygon network, on uniswap v3, increasing the liquidity for a position for the wbtc/matic pair (pool id 1597116, fee 0.05%), calculates how many matics are needed.
I created a polygon wallet with around $30, I opened a position (https://app.uniswap.org/pools/1597116) to provide liquidity to uniswap, wbtc/matic pair, fee 0.05%.
I created this little program with the help of claude3.
My expectation: Know how many matics are needed to increase the position by 0.0002 wbtc
ethers 6.12.0
const { ethers, JsonRpcProvider } = require('ethers');
const infuraKey = '...';
const walletAddress = '...';
const privateKey = '...';
const INFURA_URL = `https://polygon-mainnet.infura.io/v3/${infuraKey}`;
const { abi: IUniswapV3PoolABI } = require('@uniswap/v3-core/artifacts/contracts/interfaces/IUniswapV3Pool.sol/IUniswapV3Pool.json');
const { abi: INonfungiblePositionManagerABI } = require('@uniswap/v3-periphery/artifacts/contracts/interfaces/INonfungiblePositionManager.sol/INonfungiblePositionManager.json');
const provider = new JsonRpcProvider(INFURA_URL)
const wallet = new ethers.Wallet(privateKey, provider);
const poolAddress = '0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6';
const positionManagerAddress = '0xC36442b4a4522E871399CD717aBDD847Ab11FE88';
const poolContract = new ethers.Contract(poolAddress, IUniswapV3PoolABI, provider);
const positionManagerContract = new ethers.Contract(positionManagerAddress, INonfungiblePositionManagerABI, wallet);
async function main() {
console.log("ethers.version: ",ethers.version);
const tokenId = 1597116;
const wbtcAmount = ethers.parseUnits('0.0002', 8); // WBTC amount to be added
// Get current liquidity and token reserves
const [liquidity, , , token0Reserve, token1Reserve] = await Promise.all([
positionManagerContract.positions(tokenId),
poolContract.slot0(),
poolContract.token0(),
poolContract.token1(),
]);
// Calculate the amount of MATIC needed to increase liquidity
const token0Amount = wbtcAmount;
const token1Amount = await poolContract.quote(token0Amount, token0Reserve, token1Reserve);
console.log(`To increase liquidity by 1 WBTC, you need ${ethers.utils.formatUnits(token1Amount, 18)} MATIC`);
}
main().catch((error) => {
console.error(error);
process.exit(1);
});
i got this error:
Error: missing revert data (action=”call”, data=null, reason=null, transaction={ “data”: “0x3850c7bd”, “to”: “0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6” }, invocation=null, revert=null, code=CALL_EXCEPTION, version=6.12.0)
at makeError (C:nodejsnode_modulesetherslib.commonjsutilserrors.js:129:21)
at getBuiltinCallException (C:nodejsnode_modulesetherslib.commonjsabiabi-coder.js:105:37)
at AbiCoder.getBuiltinCallException (C:nodejsnode_modulesetherslib.commonjsabiabi-coder.js:206:16)
at JsonRpcProvider.getRpcError (C:nodejsnode_modulesetherslib.commonjsprovidersprovider-jsonrpc.js:668:43)
at C:nodejsnode_modulesetherslib.commonjsprovidersprovider-jsonrpc.js:302:45
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: ‘CALL_EXCEPTION’,
action: ‘call’,
data: null,
reason: null,
transaction: {
to: ‘[…]’,
data: ‘0x3850c7bd’
},
invocation: null,
revert: null,
shortMessage: ‘missing revert data’,
info: {
error: { code: -32000, message: ‘execution reverted’ },
payload: { method: ‘eth_call’, params: [Array], id: 2, jsonrpc: ‘2.0’ }
}
}