poanetwork / ex_abi

The Ethereum ABI Interface
GNU General Public License v3.0
61 stars 43 forks source link

non-standard packed mode: `encodePacked` #139

Closed asteshin closed 1 year ago

asteshin commented 1 year ago

Hi. I did not find any like a abi.encodePacked() in current release. If so, will it be available soon or there is another reason for that? Thanks.

ayrat555 commented 1 year ago

hey. what for what usecases this packed encoding is used?

asteshin commented 1 year ago

Sure, the UniswapV3 has an entity called path which is encoded route of multihop swap, for example: path: abi.encodePacked(DAI, poolFee, USDC, poolFee, WETH9)

alisinabh commented 1 year ago

I can look into including the encodePacked to this library. The thing is encode packed is kind of getting deprecated but there are many projects (namely uniswap v3) still using it. @ayrat555 Do you think this can be included here?

@asteshin Meanwhile, you can encode it manually. Elixir has a very nice syntax for dealing with binaries. For the example of Uniswap you can do as following.

packed = <<dai_address:binary, pool_fee::unsigned-24, usdc_address::binary, pool_fee::unsigned-24, weth_address::binary>>

The addresses should be decoded (20 bytes long binaries) and not in hex.

ayrat555 commented 1 year ago

@alisinabh it would be a great addition to the library