Closed Samboy76 closed 10 months ago
Have a problem invoking this code fragment in ethers/JS:
const routerABI = '[{"inputs":[{"internalType":"address","name":"_deployer","type":"address"},{"internalType":"address","name":"_factory","type":"address"},{"internalType":"address","name":"_WETH9","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"WETH9","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"deployer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int256","name":"amount0Delta","type":"int256"},{"internalType":"int256","name":"amount1Delta","type":"int256"},{"internalType":"bytes","name":"path","type":"bytes"}],"name":"pancakeV3SwapCallback","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"path","type":"bytes"},{"internalType":"uint256","name":"amountIn","type":"uint256"}],"name":"quoteExactInput","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint160[]","name":"sqrtPriceX96AfterList","type":"uint160[]"},{"internalType":"uint32[]","name":"initializedTicksCrossedList","type":"uint32[]"},{"internalType":"uint256","name":"gasEstimate","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"uint160","name":"sqrtPriceLimitX96","type":"uint160"}],"internalType":"struct IQuoterV2.QuoteExactInputSingleParams","name":"params","type":"tuple"}],"name":"quoteExactInputSingle","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint160","name":"sqrtPriceX96After","type":"uint160"},{"internalType":"uint32","name":"initializedTicksCrossed","type":"uint32"},{"internalType":"uint256","name":"gasEstimate","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"path","type":"bytes"},{"internalType":"uint256","name":"amountOut","type":"uint256"}],"name":"quoteExactOutput","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint160[]","name":"sqrtPriceX96AfterList","type":"uint160[]"},{"internalType":"uint32[]","name":"initializedTicksCrossedList","type":"uint32[]"},{"internalType":"uint256","name":"gasEstimate","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"uint160","name":"sqrtPriceLimitX96","type":"uint160"}],"internalType":"struct IQuoterV2.QuoteExactOutputSingleParams","name":"params","type":"tuple"}],"name":"quoteExactOutputSingle","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint160","name":"sqrtPriceX96After","type":"uint160"},{"internalType":"uint32","name":"initializedTicksCrossed","type":"uint32"},{"internalType":"uint256","name":"gasEstimate","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]'; const routerContract = new ethers.Contract( "0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997", routerABI, provider); const poolData = [ { tokenA: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', tokenB: '0xdac17f958d2ee523a2206206994597c13d831ec7', fee: 500 } ]; // Encode the pool data into bytes const encodePool = (data) => { const encoded = ethers.utils.defaultAbiCoder.encode( [ 'address tokenA', 'address tokenB', 'uint24 fee' ], [ data.tokenA, data.tokenB, data.fee, ] ); return encoded; }; // Create an array to hold the encoded pool data const pathData = poolData.map(encodePool); // Concatenate the encoded pool data into a single bytes string const pathBytes = ethers.utils.hexConcat(pathData); try { [amountOut,,,] = await routerContract.callStatic.quoteExactInput(pathBytes, tradeAmount.toString()); console.log("\amountOut:", amountOut); } catch (error) { console.log("\nError invoking quoteExactInput:", error); amountOut = 0; }
Keeps spitting out this same error every time I attempt to invoke quoteExactInput contract method:
_code: 'CALLEXCEPTION', method: 'quoteExactInput(bytes,uint256)', data: '0x', errorArgs: null, errorName: null, errorSignature: null, address: '0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997', args: [ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000000001f4', '100000000000000000000' ], transaction: { data: '0xcdca175300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000056bc75e2d631000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000000001f4', to: '0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997' }
I´ve tried consulting with chatGPT/other web communities and have attempted other approaches to no avail.
FYI, this quoteExactInput method relates to V2Quoter.sol smart contract in PancakeSwap v3
Appreciate your help as been bugging me for a few days now.
thanks
Apologies, issue lies with pancakeswap v3 v2Quoter, not with Uniswap v3
Have a problem invoking this code fragment in ethers/JS:
Keeps spitting out this same error every time I attempt to invoke quoteExactInput contract method:
_code: 'CALLEXCEPTION', method: 'quoteExactInput(bytes,uint256)', data: '0x', errorArgs: null, errorName: null, errorSignature: null, address: '0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997', args: [ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000000001f4', '100000000000000000000' ], transaction: { data: '0xcdca175300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000056bc75e2d631000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000000001f4', to: '0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997' }
I´ve tried consulting with chatGPT/other web communities and have attempted other approaches to no avail.
FYI, this quoteExactInput method relates to V2Quoter.sol smart contract in PancakeSwap v3
Appreciate your help as been bugging me for a few days now.
thanks