在研究自动swap相关功能,遇到如下问题: 1、接口的函数定义:
interface IBakerySwapRouter {
function swapTokensForExactTokens(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
}
2、我的合约中的函数定义及调用
IBakerySwapRouter CBakeryRouter=IBakerySwapRouter(合约地址);
function _fSwap(uint _amountIn) payable public{
CBakeryRouter.swapExactTokensForTokens(
_amountIn,
1,
[0xeD24FC36d5Ee211Ea25A80239Fb8C4Cfd80f12Ee],
0x5e9B3cdBa58249aBCCc0C7B9F53391194a8f128F,
1823748811
);
}
3、编译时出现如下错误:
TypeError: Invalid type for argument in function call. Invalid implicit conversion from address payable[1] memory to address[] memory requested.
[0xeD24FC36d5Ee211Ea25A80239Fb8C4Cfd80f12Ee],
先构造一个address[] memory path , 参考代码:
address[] memory path = new address[](1);
path[0] = 0xeD24FC36d5Ee211Ea25A80239Fb8C4Cfd80f12Ee;
router.swapTokensForExactTokens(
_amountIn,
1,
path,
0x5e9B3cdBa58249aBCCc0C7B9F53391194a8f128F,
1823748811
);