Skip to content

Commit

Permalink
chore: remove estimateAmplifierFee
Browse files Browse the repository at this point in the history
  • Loading branch information
npty committed Nov 11, 2024
1 parent dba7ffc commit e5347a0
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 186 deletions.
49 changes: 0 additions & 49 deletions src/libs/AxelarQueryAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,55 +568,6 @@ export class AxelarQueryAPI {
}
}

/**
* Estimates the fee for an Amplifier transaction by splitting it into two hops:
* 1. Source chain to Axelar
* 2. Axelar to destination chain
*
* @param params Parameters for the end-to-end transfer
* @param options Optional parameters for fee estimation
* @returns Promise containing the estimated fees
* @throws {Error} If config loading fails or required parameters are missing
*/
public async estimateAmplifierFee(
params: HopParams,
options?: EstimateMultihopFeeOptions
): Promise<string | DetailedFeeResponse> {
const config = await importS3Config(this.environment);
const axelarChainId = config["axelar"]?.axelarId || "axelar";

const hops = [
{
sourceChain: params.sourceChain,
destinationChain: axelarChainId,
gasLimit: params.gasLimit,
sourceTokenSymbol: params.sourceTokenSymbol,
sourceTokenAddress: params.sourceTokenAddress,
sourceContractAddress: params.sourceContractAddress,
},
{
sourceChain: axelarChainId,
destinationChain: params.destinationChain,
gasLimit: params.gasLimit,
symbol: params.symbol,
minGasPrice: params.minGasPrice,
executeData: params.executeData,
destinationContractAddress: params.destinationContractAddress,
amountInUnits: params.amountInUnits,
},
];

// Clean up undefined values to make it easier for validation
const cleanHop = (hop: HopParams): HopParams => {
return Object.fromEntries(
Object.entries(hop).filter(([_, value]) => value !== undefined)
) as HopParams;
};

// Estimate fees for both hops
return this.estimateMultihopFee(hops.map(cleanHop), options);
}

/**
* Get the denom for an asset given its symbol on a chain
* @param symbol
Expand Down
137 changes: 0 additions & 137 deletions src/libs/test/AxelarQueryAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,143 +342,6 @@ describe("AxelarQueryAPI", () => {
});
});

describe("estimateAmplifierFee", () => {
let amplifierApi: AxelarQueryAPI;
let mockImportS3Config: SpyInstance;
let mockEstimateMultihopFee: SpyInstance;

beforeEach(async () => {
amplifierApi = new AxelarQueryAPI({
environment: Environment.DEVNET,
});

mockImportS3Config = vi
.spyOn(await import("../../chains"), "importS3Config")
.mockResolvedValueOnce({
axelar: {
axelarId: "axelar-test",
},
});

// Mock estimateMultihopFee to avoid duplication of its tests
mockEstimateMultihopFee = vi
.spyOn(amplifierApi, "estimateMultihopFee")
.mockResolvedValue("1");
});

afterEach(() => {
vi.resetAllMocks();
});

test("should correctly split into two hops using config axelarId", async () => {
const params = {
sourceChain: "ethereum",
destinationChain: "avalanche",
gasLimit: "700000",
sourceTokenSymbol: "axlUSDC",
};

await amplifierApi.estimateAmplifierFee(params);

expect(mockEstimateMultihopFee).toHaveBeenCalledWith(
[
{
sourceChain: params.sourceChain,
destinationChain: "axelar-test",
gasLimit: params.gasLimit,
sourceTokenSymbol: params.sourceTokenSymbol,
},
{
sourceChain: "axelar-test",
destinationChain: params.destinationChain,
gasLimit: "700000",
},
],
undefined
);
});

test("should use default axelarId when not in config", async () => {
mockImportS3Config.mockResolvedValueOnce({});

const params = {
sourceChain: "ethereum",
destinationChain: "avalanche",
gasLimit: "700000",
};

await amplifierApi.estimateAmplifierFee(params);

expect(mockEstimateMultihopFee).toHaveBeenCalledWith(
[
{
sourceChain: params.sourceChain,
destinationChain: "axelar-test",
gasLimit: params.gasLimit,
},
{
sourceChain: "axelar-test",
destinationChain: params.destinationChain,
gasLimit: params.gasLimit,
},
],
undefined
);
});

test("should pass through all relevant parameters to correct hops", async () => {
const params = {
sourceChain: "ethereum",
destinationChain: "avalanche",
gasLimit: "700000",
sourceTokenSymbol: "axlUSDC",
sourceContractAddress: "0xsource",
destinationContractAddress: "0xdest",
executeData: "0xdata",
amountInUnits: "1000000",
};

await amplifierApi.estimateAmplifierFee(params);

expect(mockEstimateMultihopFee).toHaveBeenCalledWith(
[
{
sourceChain: "ethereum",
destinationChain: "axelar-test",
gasLimit: "700000",
sourceTokenSymbol: "axlUSDC",
sourceContractAddress: "0xsource",
},
{
sourceChain: "axelar-test",
destinationChain: "avalanche",
gasLimit: "700000",
destinationContractAddress: "0xdest",
executeData: "0xdata",
amountInUnits: "1000000",
},
],
undefined
);
});

test("should pass through showDetailedFees option", async () => {
const params = {
sourceChain: "ethereum",
destinationChain: "avalanche",
gasLimit: "700000",
};

await amplifierApi.estimateAmplifierFee(params, {
showDetailedFees: true,
});

expect(mockEstimateMultihopFee).toHaveBeenCalledWith(expect.any(Array), {
showDetailedFees: true,
});
});
});

describe("estimateGasFee", () => {
test("It should return estimated gas amount that makes sense for USDC", async () => {
const gasAmount = await api.estimateGasFee(
Expand Down

0 comments on commit e5347a0

Please sign in to comment.