将字段打包到单个字节参数中(&Q;) [英] Field packing into a single "byte param" field

查看:19
本文介绍了将字段打包到单个字节参数中(&Q;)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试验AAVE的FlashLiqudidationAdapter.sol,它需要一个包含address,address,address,uint256,boolparams字段,但每当我编码和提交事务时,它都会在_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"

这篇关于将字段打包到单个字节参数中(&Q;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆