怎么使用Uniswap中的UniversalRouter

我想通过UniversalRouter中的execute函数来完成ETH和ERC20 token的swap功能,我试图在swap函数中调用execute函数,它是这样的

function execute(bytes calldata commands, bytes[] calldata inputs, uint256 deadline)
        external
        payable
        checkDeadline(deadline)
    {
        execute(commands, inputs);
    }

这里还有一个Arbiscan上执行交易的一个例子

Function: execute(bytes commands,bytes[] inputs,uint256 deadline)

MethodID: 0x3593564c
[0]:  0000000000000000000000000000000000000000000000000000000000000060
[1]:  00000000000000000000000000000000000000000000000000000000000000a0
[2]:  0000000000000000000000000000000000000000000000000000000063fdeb90
[3]:  0000000000000000000000000000000000000000000000000000000000000002
[4]:  0b00000000000000000000000000000000000000000000000000000000000000
[5]:  0000000000000000000000000000000000000000000000000000000000000002
[6]:  0000000000000000000000000000000000000000000000000000000000000040
[7]:  00000000000000000000000000000000000000000000000000000000000000a0
[8]:  0000000000000000000000000000000000000000000000000000000000000040
[9]:  0000000000000000000000000000000000000000000000000000000000000002
[10]: 000000000000000000000000000000000000000000000000000aa87bee538000
[11]: 0000000000000000000000000000000000000000000000000000000000000100
[12]: 0000000000000000000000000000000000000000000000000000000000000001
[13]: 000000000000000000000000000000000000000000000000000aa87bee538000
[14]: 00000000000000000000000000000000000000000000000000eb08bf1ab3308a
[15]: 00000000000000000000000000000000000000000000000000000000000000a0
[16]: 0000000000000000000000000000000000000000000000000000000000000000
[17]: 000000000000000000000000000000000000000000000000000000000000002b
[18]: 82af49447d8a07e3bd95bd0d56f35241523fbab1000bb8fc5a1a6eb076a2c7ad
[19]: 06ed22c90d7e710e35ad0a000000000000000000000000000000000000000000

我不知道我应该如何构造出commands和inputs参数以使我能够调用它,有相关的资料或者实现案例可以参考吗?希望社区的大佬们可以帮忙解答下我的困惑。 相关链接:代码https://github.com/Uniswap/universal-router/blob/main/contracts/UniversalRouter.sol 交易https://arbiscan.io/tx/0xb1151d16a8dd84696ec81f9c9c61ec9aa8759099ae51765ba9877ee2313c897f

请先 登录 后评论

2 个回答

深山樵夫
请先 登录 后评论
Tiny熊
  擅长:智能合约,以太坊
请先 登录 后评论
  • 3 关注
  • 1 收藏,3571 浏览
  • Joe 提出于 2023-03-13 23:01