Uniswap最近推出了一款新的通用路由器(博客此处:https://docs.uniswap.org/contracts/universal-router/technical-reference)
我使用Uniswap和以太将一个事务解码为如下所示:
TransactionDescription {
args: [
'0x0b00',
[
'0x0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000009184e72a000',
'0x0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000009184e72a00000000000000000000000000000000000000000000000000000000000000038e000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc20001f4dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000000000000000000000'
],
BigNumber { _hex: '0x63c87f23', _isBigNumber: true },
commands: '0x0b00',
inputs: [
'0x0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000009184e72a000',
'0x0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000009184e72a00000000000000000000000000000000000000000000000000000000000000038e000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc20001f4dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000000000000000000000'
],
deadline: BigNumber { _hex: '0x63c87f23', _isBigNumber: true }
],
functionFragment: {
type: 'function',
name: 'execute',
constant: false,
inputs: [ [ParamType], [ParamType], [ParamType] ],
outputs: [],
payable: true,
stateMutability: 'payable',
gas: null,
_isFragment: true,
constructor: [Function: FunctionFragment] {
from: [Function (anonymous)],
fromObject: [Function (anonymous)],
fromString: [Function (anonymous)],
isFunctionFragment: [Function (anonymous)]
},
format: [Function (anonymous)]
},
name: 'execute',
signature: 'execute(bytes,bytes[],uint256)',
sighash: '0x3593564c',
value: BigNumber {
_hex: '0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000063c87f2300000000000000000000000000000000000000000000000000000000000000020b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000009184e72a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000009184e72a00000000000000000000000000000000000000000000000000000000000000038e000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc20001f4dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000000000000000000000',
_isBigNumber: true
}
}
但是,我无法理解如何将输入解码为正确的值。
技术参考建议输入的字节数组应该包含以下内容:
The second parameter for the function is an array of bytes strings. Each element in the array is the abi-encoded input that will be used for the respective command.
V3_SWAP_EXACT_IN
address The recipient of the output of the trade
uint256 The amount of input tokens for the trade
uint256 The minimum amount of output tokens the user wants
bytes The UniswapV3 encoded path to trade along
bool A flag for whether the input tokens should come from the msg.sender (through Permit2) or whether the funds are already in the UniversalRouter
但是,字节数组的长度仅为2:
inputs: [
'0x0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000009184e72a000',
'0x0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000009184e72a00000000000000000000000000000000000000000000000000000000000000038e000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc20001f4dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000000000000000000000'
],
我在这里误解了什么?我如何解码一个通用路由器事务?
发布于 2023-01-21 16:30:13
这种误解似乎来自于投入。
您可以看到,在您提到的对象中有以下几行:
commands: '0x0b00',
inputs: [
'0x0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000009184e72a000',
'0x0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000009184e72a00000000000000000000000000000000000000000000000000000000000000038e000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc20001f4dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000000000000000000000'
],
其中命令(Commands.sol)被解释为:
这就是为什么在输入数组中看到两个元素的原因。第一个元素是对应于第一个函数(WRAP_ETH)的输入,数组中的第二个元素是对应于V3_SWAP_EXACT_IN的输入。
例如,让我们看一下第一个函数,并对其进行解码。
//inputs[0] split every 64 characters
0000000000000000000000000000000000000000000000000000000000000002 //addres of recipient
000000000000000000000000000000000000000000000000000009184e72a000 //amount of ETH
使用同样的方法,您可以为V3_SWAP_EXACT_IN做同样的事情。
注意,如果您有ABI,可能会有一些工具来对这些信息进行默认解码,但这就是为什么您只看到两个输入。
https://ethereum.stackexchange.com/questions/143239
复制相似问题