Refactor how maxGasLimit is defined & handled
Context
- Bifrost currently enforces a maximum of 400_000 gas units for all aggregation calls
- We have opportunities to connect TC with other protocols that require more than 400_000 gas units Side note: I believe the enforcement of this limit in Bifrost is not doing what it should, and the implementation confuses gasCost & gasUnits. https://gitlab.com/thorchain/thornode/-/blob/develop/bifrost/pkg/chainclients/ethereum/ethereum.go#L547
Weaknesses of the current solution
- Not all EVM chains calculate gas units the same way
- Ethereum UniV3 normal swap: ~190k gas units
- Ethereum UniV3 dex aggregation: ~260k gas units
- Arbitrum UniV3 normal swap: ~950k gas units (example for gas units, not what we are attempting to daisy-chain)
- Limit what actions/protocols can be daisy-chained with TC
- Gas consumed by each contract is predictable and varies very little. It would be better protection for users and the protocol to have lower limits on contracts we know consume less gas.
Suggested solution
- Add gas limit to the aggregator/dex_mainnet.go https://gitlab.com/thorchain/thornode/-/blob/develop/x/thorchain/aggregators/dex_mainnet.go
From [chain, contractAddress]
to [chain, contractAddress, maxGasUnits]
- From this line
https://gitlab.com/thorchain/thornode/-/blob/develop/bifrost/pkg/chainclients/ethereum/ethereum.go#L530
if isNaN(estimatedGas) || estimatedGas > maxLimitForContract
--> just send gas asset to user
This allows more flexibility for integrators to innovate and connect TC with any protocols while keeping the gas limits within the purview of TC during the whitelisting process.
Edited by Oleg Petrov