将字段打包到单个字节参数中(&Q;)
问题描述
我正在试验AAVE的FlashLiqudidationAdapter.sol,它需要一个包含address,address,address,uint256,bool
的params
字段,但每当我编码和提交事务时,它都会在_decodeParameters
返回,这是一个函数,它将params
解包到智能合同中。我不确定我做错了什么。以下是我的纯(非编码)参数:
"0xb7c325266ec274feb1354021d27fa3e3379d840d,0xff682ff79feb2c057ec3ff1e083efdc66f9b37fb,0x1ea0B089673720e210552c624aFff9d67F8b1535,-1,0"
以下是已编码的参数):
b"000000000000000000000000b7c325266ec274feb1354021d27fa3e3379d840d000000000000000000000000ff682ff79feb2c057ec3ff1e083efdc66f9b37fb0000000000000000000000001ea0b089673720e210552c624afff9d67f8b1535ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000001"
这是整个交易:
tx = flash_loan.requestFlashLoan(["0xb7c325266ec274feb1354021d27fa3e3379d840d"], [(2.8134148508367174 / 2) * 1e18], [0], b"000000000000000000000000b7c325266ec274feb1354021d27fa3e3379d840d000000000000000000000000ff682ff79feb2c057ec3ff1e083efdc66f9b37fb0000000000000000000000001ea0b089673720e210552c624afff9d67f8b1535ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000001", {"gas_limit": "200000", "gas_price": Wei('4 gwei'), "from": account1, "allow_revert": True, "nonce": 46})
最后,这里是引用的_decodeParams
函数,如前所述,其中正在进行还原
/**
* @dev Decodes the information encoded in the flash loan params
* @param params Additional variadic field to include extra params. Expected parameters:
* address collateralAsset The collateral asset to claim
* address borrowedAsset The asset that must be covered and will be exchanged to pay the flash loan premium
* address user The user address with a Health Factor below 1
* uint256 debtToCover The amount of debt to cover
* bool useEthPath Use WETH as connector path between the collateralAsset and borrowedAsset at Uniswap
* @return LiquidationParams struct containing decoded params
*/
function _decodeParams(bytes memory params) internal pure returns (LiquidationParams memory) {
(
address collateralAsset,
address borrowedAsset,
address user,
uint256 debtToCover,
bool useEthPath
) = abi.decode(params, (address, address, address, uint256, bool));
return LiquidationParams(collateralAsset, borrowedAsset, user, debtToCover, useEthPath);
}
}
https://github.com/aave/protocol-v2/blob/master/contracts/adapters/FlashLiquidationAdapter.sol#L173-L184
注意,我使用的是固态编译器版本^0.6.12。
解决方案
Solidity要求类型BYTE以0x
开头,因此作为params
传递的正确字节字符串应如下所示:
b"0x000000000000000000000000b7c325266ec274feb1354021d27fa3e3379d840d000000000000000000000000ff682ff79feb2c057ec3ff1e083efdc66f9b37fb0000000000000000000000001ea0b089673720e210552c624afff9d67f8b1535ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000001"
相关文章