Skip to content

Commit

Permalink
feat: add mapping for detailed response
Browse files Browse the repository at this point in the history
  • Loading branch information
npty committed Nov 8, 2024
1 parent eadfa07 commit 1934599
Showing 1 changed file with 71 additions and 2 deletions.
73 changes: 71 additions & 2 deletions src/libs/AxelarQueryAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,35 @@ interface HopParams {
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
*/
interface DetailedFeeResponse {
isExpressSupported: boolean;
baseFee: string;
expressFee: string;
executionFee: string;
executionFeeWithMultiplier: string;
totalFee: string;
details?: HopFeeDetails[];
}

interface EstimateMultihopFeeOptions {
showDetailedFees?: boolean;
}
Expand Down Expand Up @@ -509,7 +538,7 @@ export class AxelarQueryAPI {
public async estimateMultihopFee(
hops: HopParams[],
options?: EstimateMultihopFeeOptions
): Promise<string | AxelarQueryAPIFeeResponse> {
): Promise<string | DetailedFeeResponse> {
if (hops.length === 0) {
throw new Error("At least one hop parameter must be provided");
}
Expand All @@ -526,6 +555,10 @@ export class AxelarQueryAPI {
showDetailedFees: options?.showDetailedFees ?? false,
});

if (options?.showDetailedFees) {
return this.mapToDetailedFeeResponse(response);
}

return response;
} catch (error) {
if (error instanceof Error) {
Expand All @@ -545,7 +578,10 @@ export class AxelarQueryAPI {
* @returns Promise containing the estimated fees
* @throws {Error} If config loading fails or required parameters are missing
*/
public async estimateAmplifierFee(params: HopParams, options?: EstimateMultihopFeeOptions) {
public async estimateAmplifierFee(
params: HopParams,
options?: EstimateMultihopFeeOptions
): Promise<string | DetailedFeeResponse> {
const config = await importS3Config(this.environment);
const axelarChainId = config["axelar"]?.axelarId || "axelar";

Expand Down Expand Up @@ -811,4 +847,37 @@ export class AxelarQueryAPI {
if (!assetConfig) throw `Asset ${denom} not found`;
return assetConfig.wrapped_erc20 ? assetConfig.wrapped_erc20 : denom;
}

/**
* Maps raw API response to simplified hop fee details
*/
private mapToHopFeeDetails(rawHopDetails: any): HopFeeDetails {
return {
isExpressSupported: rawHopDetails.isExpressSupported,
baseFee: rawHopDetails.baseFee,
expressFee: rawHopDetails.expressFee,
executionFee: rawHopDetails.executionFee,
executionFeeWithMultiplier: rawHopDetails.executionFeeWithMultiplier,
totalFee: rawHopDetails.totalFee,
gasLimit: rawHopDetails.gasLimit,
gasLimitWithL1Fee: rawHopDetails.gasLimitWithL1Fee,
gasMultiplier: rawHopDetails.gasMultiplier,
minGasPrice: rawHopDetails.minGasPrice,
};
}

/**
* Maps raw API response to simplified detailed fee response
*/
private mapToDetailedFeeResponse(rawResponse: any): DetailedFeeResponse {
return {
isExpressSupported: rawResponse.isExpressSupported,
baseFee: rawResponse.baseFee,
expressFee: rawResponse.expressFee,
executionFee: rawResponse.executionFee,
executionFeeWithMultiplier: rawResponse.executionFeeWithMultiplier,
totalFee: rawResponse.totalFee,
details: rawResponse.details?.map(this.mapToHopFeeDetails),
};
}
}

0 comments on commit 1934599

Please sign in to comment.