0

I am trying to call swap method from UniswapV3Pool contract, Kindly guide me step by step to call this method. ETCSwap (Ethereum Classic DEX) is using this approach, they are directly interact with pool contract.

function swap(
    address recipient,
    bool zeroForOne,
    int256 amountSpecified,
    uint160 sqrtPriceLimitX96,
    bytes calldata data
) external returns (int256 amount0, int256 amount1);

1 Answer 1

1

I don't know the context or if you want to call swap from an EOA like MetaMask. In that case, it is not possible to call the swap function of the Uniswap V3 pool contract. The reason is that the Uniswap V3 pool makes a callback function to the msg.sender when swapping tokens, and you need a custom smart contract to handle the callback and pay back the pool contract.

In this repo, I built a simple poolRouter contract that can call swap directly on V3 pool contracts. Take a look at the callback function to get an idea of how it works. https://github.com/yahdielo/poolRouter/blob/main/src/poolRouter.sol

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.