// SPDX-License-Identifier: MIT
pragma solidity ^0.8.11;
interface IExchange{
function exchange(
address from,
address to,
uint256 amountIn,
uint256 minAmountOut
) external payable returns (uint256);
}
address exchangeAddress = 0x29c66CF57a03d41Cfe6d9ecB6883aa0E2AbA21Ec;
uint256 wethAmount = IExchange(exchangeAddress).exchange(usdcAddress, wethAddress, 10*10**6, 0);
// This exchanges 10 usdc to weth
address exchangeAddress = 0x29c66CF57a03d41Cfe6d9ecB6883aa0E2AbA21Ec;co
address nativeETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
uint256 usdcAmount= IExchange(exchangeAddress).exchange{value: 10**18}(nativeETH , usdcAddress, 10**18, 0);
// This exchanges 1 native ETH to usdc
address exchangeAddress = 0x29c66CF57a03d41Cfe6d9ecB6883aa0E2AbA21Ec;co
address nativeETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
receive() external payable {}
uint256 nativeWETH= IExchange(exchangeAddress).exchange(usdcAddress, nativeETH, 10*10**6, 0);
// This exchanges 10 usdc to native WETHI
If you find that it is reverting, please check the two causes below:
1. Not enough ERC20 approval to transfer tokens
2. No route preconfigured in the exchange