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 estimateGasFeeGmp function #339

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 51 additions & 34 deletions src/libs/AxelarQueryAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
TransferFeeResponse,
} from "@axelar-network/axelarjs-types/axelar/nexus/v1beta1/query";
import { throwIfInvalidChainIds } from "../utils";
import { importS3Config, loadChains } from "../chains";

Check warning on line 23 in src/libs/AxelarQueryAPI.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/libs/AxelarQueryAPI.ts#L23

'importS3Config' is defined but never used (@typescript-eslint/no-unused-vars)
import s3 from "./TransactionRecoveryApi/constants/s3";
import { BigNumber, BigNumberish, ethers } from "ethers";
import { ChainInfo } from "../chains/types";
Expand Down Expand Up @@ -70,6 +70,42 @@
* The endpoint estimates and bundles the gas needed for L1 (L1GasLimit) automatically.
*/
gasLimit: string;
}

/**
* Represents detailed fee information for a single hop
*/
interface HopFeeDetails {
isExpressSupported: boolean;
baseFee: string;
expressFee: string;
executionFee: string;
executionFeeWithMultiplier: string;
totalFee: string;
gasLimit: string;
gasLimitWithL1Fee: string;
gasMultiplier: number;
minGasPrice: string;
}

/**
* Response for fee estimation with detailed breakdown
*/
export interface DetailedFeeResponse {
isExpressSupported: boolean;
baseFee: string;
expressFee: string;
executionFee: string;
executionFeeWithMultiplier: string;
totalFee: string;
details?: HopFeeDetails[];
}

interface EstimateMultihopFeeOptions {
/**
* If true, returns a `DetailedFeeResponse` instead of a `string`
*/
showDetailedFees?: boolean;

/**
* The multiplier of gas to be used on execution
Expand Down Expand Up @@ -110,39 +146,6 @@
amountInUnits?: string;
}

/**
* Represents detailed fee information for a single hop
*/
interface HopFeeDetails {
isExpressSupported: boolean;
baseFee: string;
expressFee: string;
executionFee: string;
executionFeeWithMultiplier: string;
totalFee: string;
gasLimit: string;
gasLimitWithL1Fee: string;
gasMultiplier: number;
minGasPrice: string;
}

/**
* Response for fee estimation with detailed breakdown
*/
export interface DetailedFeeResponse {
isExpressSupported: boolean;
baseFee: string;
expressFee: string;
executionFee: string;
executionFeeWithMultiplier: string;
totalFee: string;
details?: HopFeeDetails[];
}

interface EstimateMultihopFeeOptions {
showDetailedFees?: boolean;
}

export class AxelarQueryAPI {
readonly environment: Environment;
readonly lcdApi: RestService;
Expand Down Expand Up @@ -423,6 +426,20 @@
}

/**
* This method is a wrapper around `estimateMultihopFee` for GMP transaction.
* The `estimateGasFee` method is no longer maintained. We recommend using this function instead.
* @param hop The hop parameters for the GMP transaction
* @param options Optional parameters for fee estimation
* @throws {Error} If no hops are provided or chain validation fails
* @returns Promise containing the estimated fees if the showDetailedFees option is not provided, or an object containing the detailed fees if showDetailedFees is true
*/
public async estimateGMPFee(hop: HopParams, options?: EstimateMultihopFeeOptions) {
return this.estimateMultihopFee([hop], options);
}

/**
* @deprecated. We recommend using `estimateGMPFee` instead.
*
* Calculate estimated gas amount to pay for the gas receiver contract.
* @param sourceChainId Can be of the EvmChain enum or string. If string, should try to generalize to use the CHAINS constants (e.g. CHAINS.MAINNET.ETHEREUM)
* @param destinationChainId Can be of the EvmChain enum or string. If string, should try to generalize to use the CHAINS constants (e.g. CHAINS.MAINNET.ETHEREUM)
Expand Down Expand Up @@ -562,7 +579,7 @@
return response;
} catch (error) {
if (error instanceof Error) {
throw new Error(`Failed to estimate multi-hop gas fee: ${error.message}`);
throw new Error(`Failed to estimate gas fee: ${error.message}`);
}
throw error;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/test/AxelarQueryAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ describe("AxelarQueryAPI", () => {

mainnetResponses.forEach((response) => {
expect(response).toBeDefined();
expect(String(response).length).toBeLessThanOrEqual(6);
expect(String(response).length).toBeLessThanOrEqual(7);
});
});

Expand Down
Loading