Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add estimateMultihopFee function #336

Merged
merged 9 commits into from
Nov 22, 2024

Conversation

npty
Copy link
Member

@npty npty commented Nov 8, 2024

Description

https://axelarnetwork.atlassian.net/browse/AXE-6367

This PR adds a function estimateMultihopFee to estimate gas fee for multiple-hops route.

Please note: The devnet amplifier configuration URL is temporarily set to https://melted-fayth-nptytn-57e5d396.koyeb.app/chain/devnet-amplifier. This will be updated once the official URL becomes available.

Implementation

The function is a wrapper for a call to the endpoint /gmp/estimateGasFeeForNHops in axelarscan api. It validates given source chains and destination chains before making the api call.

Usage

The estimateMultihopFee method provides flexible gas fee estimation for complex multi-hop transfers. This is particularly useful for:

  • Two-way transfers
  • ITS Hub
  • Complex cross-chain interactions
const api = new AxelarQueryAPI({
  environment: Environment.DEVNET,
});

// ITS Hub
const fee = await api.estimateMultihopFee([
  {
    sourceChain: "avalanche-fuji",
    destinationChain: "axelarnet",
    gasLimit: "700000",
  },
  {
    sourceChain: "axelarnet",
    destinationChain: "sui-test2",
    gasLimit: "700000",
  }
]);

// Two-way transfer with detailed fees
const twoWayFee = await api.estimateMultihopFee([
  // First transfer: Chain A -> Chain B
  {
    sourceChain: "ethereum",
    destinationChain: "avalanche",
    gasLimit: "700000",
    sourceTokenSymbol: "axlUSDC",
  },
  // Return transfer: Chain B -> Chain A
  {
    sourceChain: "avalanche",
    destinationChain: "ethereum",
    gasLimit: "500000",
    sourceTokenSymbol: "axlUSDC",
  }
], {
  showDetailedFees: true
});

// Complex multi-hop with express and custom parameters
const complexFee = await api.estimateMultihopFee([
  // First hop with express eligibility check
  {
    sourceChain: "ethereum",
    destinationChain: "polygon",
    gasLimit: "700000",
    sourceTokenSymbol: "USDC",
    sourceTokenAddress: "0xSource1...",
    sourceContractAddress: "0xContract1...",
    gasMultiplier: 1.1
  },
  // Intermediate hop
  {
    sourceChain: "polygon",
    destinationChain: "avalanche",
    gasLimit: "500000",
    minGasPrice: "1000000000",
    symbol: "axlUSDC"
  },
  // Final hop with contract execution
  {
    sourceChain: "avalanche",
    destinationChain: "fantom",
    gasLimit: "800000",
    executeData: "0x...",
    destinationContractAddress: "0xDest3...",
    amountInUnits: "1000000"
  }
]);

Blockers For Merging

  • Needdevnet-amplifier config with latest sui contract info (same as this one) deployed to s3. I've hardcoded it to point to the raw file in the github repo instead.

@npty npty changed the title feat: add estimateMultiHopFees feat: add estimateMultiHopFees and estimateAmplifierFee Nov 8, 2024
@npty npty changed the title feat: add estimateMultiHopFees and estimateAmplifierFee feat: add estimateMultihopFee and estimateAmplifierFee Nov 8, 2024
@npty npty self-assigned this Nov 8, 2024
@npty npty marked this pull request as draft November 8, 2024 12:45
@npty npty changed the title feat: add estimateMultihopFee and estimateAmplifierFee feat: add estimateMultihopFee Nov 11, 2024
@npty npty changed the title feat: add estimateMultihopFee feat: add estimateMultihopFee function Nov 11, 2024
@npty npty marked this pull request as ready for review November 11, 2024 11:48
@canhtrinh
Copy link
Collaborator

Looks good! as a follow up @npty, we should build this into the main estimateGasFee function as well

@canhtrinh canhtrinh merged commit ca73c2f into main Nov 22, 2024
4 checks passed
@canhtrinh canhtrinh deleted the feat/estimate-gas-fee-for-hops branch November 22, 2024 19:55
@npty npty mentioned this pull request Jan 15, 2025
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