hyperlane-xyz / fuel-contracts

5 stars 2 forks source link

InterchainGasPaymaster and StorageGasOracle implementations #52

Closed tkporter closed 1 year ago

tkporter commented 1 year ago

Fixes #8, #44, and #6 (there's a new configurable feature)

A note on the token exchange rate scale

Note that unlike the Solidity version, this uses a TOKEN_EXCHANGE_RATE_SCALE of 1e19 instead of 1e10. We originally chose 1e10 in Solidity because we wrongly assumed native tokens will generally be on the same order of magnitude, this is what LZ uses, and didn't put too much thought into the implications.

However the Fuel base asset is going to have 9 decimals, not 18, which means that the conversion between the Fuel base asset and remote tokens like Ethereum is going to many orders of magnitude different!

These are the best options I see:

  1. Provide more precision in the 128 bit token exchange rate to account for decimal differences in the exchange rate. Note len(str(2 ** 128)) = 39, so 19 decimals of precision means there would be 20 digits on the left side of the decimal and 19 on the right. This is more equal than the currently used 10 decimals
  2. Have the IGP also store the # of decimals of remote chains and use this when performing the conversion. The exchange rate would then be exchange rate between whole tokens.

I ended up going with (1) because it doesn't require more storage reads, but I could see 2 being useful

We may want to consider making a change to the Solidity implementation to be consistent - though note that for high decimal chains (18) that want to quote payments for low decimals chains (9, like Fuel), this involves a higher exchange rate on chain, which means that they're not impacted by only having 10 decimals of precision. E.g. an exchange rate posted to Ethereum that would signify the remote has 9 decimals but otherwise has the exact same value would be 1e9 * 1e10