Solidity Interface & Canonical Declaration
function swapTokensForExactTokens(uint256 amountOut, uint256 amountInMax, address[] path, address to, uint256 deadline) external returns (uint256[] memory amounts)
在限制最大输入代币量的前提下,兑换出确定数量的目标输出代币。
理论基础执行 Gas: 110,000 ~ 190,000 gas
返回值类型: uint256[]
Calldata 调用数据 ABI 编码布局账本
| Calldata Offset | Type | Parameter Name | Semantic Role |
|---|---|---|---|
| 0x00 ~ 0x03 (4B) | bytes4 | Method ID (msg.sig) | swapTokensForExactTokens(uint256,uint256,address[],address,uint256) 的 4 字节函数选择器 |
| 0x04 ~ 0x23 (32B) | uint256 | amountOut | 希望获得的精确目标输出数量 |
| 0x24 ~ 0x43 (32B) | uint256 | amountInMax | 愿意支付的最大输入代币上限 |
| 0x44 ~ 0x63 (32B) | address[] | path | 兑换路径 |
| 0x64 ~ 0x83 (32B) | address | to | 接收地址 |
| 0x84 ~ 0xa3 (32B) | uint256 | deadline | 有效截止时间戳 |
Keccak-256 密码学哈希推导链
标准 ASCII 签名字符串: swapTokensForExactTokens(uint256,uint256,address[],address,uint256)
完整 256 位 Keccak 哈希: 0x8803dbeef1adfe1a9306daa835152093f0a5085700e080f4de0d56162dfadb09
截取前 4 字节 (Big-Endian): 0x8803dbee
EVM 运行时调度器汇编代码特征 (Dispatcher Opcodes)
// 1. Load the first 32 bytes of transaction calldata
[0x0000] PUSH1 0x00
[0x0002] CALLDATALOAD
// 2. Right-shift by 224 bits (0xe0) to isolate the 4-byte selector
[0x0003] PUSH1 0xe0
[0x0005] SHR
// 3. Match against target selector 0x8803dbee and branch
[0x0006] DUP1
[0x0007] PUSH4 0x8803dbee
[0x000c] EQ
[0x000d] PUSH2 0x0050
[0x0010] JUMPI // Jump to implementation if matched