Skip to content

Conversation

benjamin852
Copy link
Contributor

@benjamin852 benjamin852 commented Sep 28, 2025

why?

fixing previously introduced bugs for hedera est gas fee

  • ...
  • Task: ?

how?

reverted scaleGasValue to be what is passed in for msg.value of txs and only using returned value from estimateItsFee for gasValue param in ITS function calls.

  • ...

testing

tested ITS functionality with + without gas to confirm api runs when nothing is set and gasValue is hardcoded if user chooses to pass in gasValue param in script.

  • ...

Note

Separates ITS gasValue from payable value, adds bidirectional gas scaling, and updates call sites to use the correct amounts.

  • Utils:
    • Update estimateITSFee to return { gasValue, gasFeeValue }; handle API 0/error, stringify large numbers, and derive EVM gasValue via downscaling.
    • Enhance scaleGasValue(chain, gasValue, up=true) to support up/down scaling with BigNumber.
  • ITS/Factory (EVM):
    • Use returned { gasValue, gasFeeValue } across actions: deployRemoteInterchainToken, deployRemoteCanonicalInterchainToken, linkToken, interchain-transfer, register-token-metadata.
    • Pass gasValue as function arg and gasFeeValue as transaction value in overrides.

Written by Cursor Bugbot for commit ee361f9. This will update automatically on new commits. Configure here.

Greptile Overview

Updated On: 2025-09-28 18:24:38 UTC

Summary

This PR fixes a gas estimation bug for Hedera by separating the concerns of gasValue (used in ITS function calls) and transaction msg.value (which may need scaling for chains like Hedera).

Key Changes:

  • Moved scaleGasValue function from common/utils.js to evm/utils.js where it's actually used
  • Modified estimateITSFee to return raw gasValue when provided, instead of applying scaling
  • Updated ITS and InterchainTokenFactory calls to use scaleGasValue(chain, gasValue) for transaction value parameter only
  • Added BigNumber import to common/utils.js for proper return type from estimateITSFee

The fix ensures that Hedera's lower decimal precision gas values are handled correctly - raw values are used for ITS function parameters while scaled values are used for transaction values when gasScalingFactor is configured.

Confidence Score: 4/5

  • This PR is safe to merge with low risk as it fixes a specific gas estimation bug
  • Score reflects a well-targeted bug fix with proper separation of concerns between gas estimation and transaction value scaling, tested functionality, and clean code organization
  • No files require special attention - all changes follow established patterns

Important Files Changed

File Analysis

Filename        Score        Overview
common/utils.js 4/5 Removed scaleGasValue function and simplified estimateITSFee to return raw gasValue when provided, fixing gas estimation bug for Hedera
evm/utils.js 5/5 Added scaleGasValue function and BigNumber import for proper gas scaling in transaction values
evm/its.js 5/5 Updated to use scaleGasValue for transaction value parameter while keeping gasValue raw for ITS function calls
evm/interchainTokenFactory.js 5/5 Updated to use scaleGasValue for transaction value parameter in deployRemoteInterchainToken and registerCanonicalInterchainToken calls

Sequence Diagram

sequenceDiagram
    participant User
    participant ITS as ITS/Factory
    participant EstimateFee as estimateITSFee()
    participant ScaleGas as scaleGasValue()
    participant Chain as Blockchain

    User->>ITS: Call ITS function (gasValue)
    ITS->>EstimateFee: estimateITSFee(chain, destChain, env, eventType, gasValue)
    
    alt gasValue provided
        EstimateFee-->>ITS: return gasValue (unchanged)
    else gasValue = 'auto'  
        EstimateFee->>Chain: HTTP request to axelarscanApi
        Chain-->>EstimateFee: gas estimate response
        EstimateFee-->>ITS: return BigNumber.from(response)
    end
    
    ITS->>ScaleGas: scaleGasValue(chain, gasValue)
    
    alt chain.gasScalingFactor exists
        ScaleGas-->>ITS: gasValue * 10^gasScalingFactor (for msg.value)
    else no scaling factor
        ScaleGas-->>ITS: gasValue (unchanged)
    end
    
    ITS->>Chain: Execute transaction with<br/>- gasValue: raw value (for ITS function)<br/>- value: scaled value (for msg.value)
    Chain-->>User: Transaction result
Loading

@benjamin852 benjamin852 self-assigned this Sep 28, 2025
@benjamin852 benjamin852 requested a review from a team as a code owner September 28, 2025 18:21
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@benjamin852 benjamin852 changed the title fix: revert scale value to be msg.value of txs and separate it from e… fix: hedera gas estimation Sep 29, 2025
Copy link
Member

@milapsheth milapsheth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved pending comment

@benjamin852 benjamin852 changed the title fix: hedera gas estimation fix: fix scaling gas requirement for hedera gas estimation Sep 29, 2025
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@isi8787 isi8787 merged commit 5d3eeec into main Sep 30, 2025
11 checks passed
@isi8787 isi8787 deleted the fix/gas-scaling branch September 30, 2025 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants