Skip to content

Commit 7ffa803

Browse files
committed
cleanup
1 parent 95686fc commit 7ffa803

File tree

10 files changed

+169
-1762
lines changed

10 files changed

+169
-1762
lines changed

evm/ts/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"test": "jest --config ./jest.config.ts"
4545
},
4646
"dependencies": {
47-
"@axelar-network/axelarjs-sdk": "^0.17.6-alpha.2",
4847
"@wormhole-foundation/sdk-definitions-ntt": "1.0.0",
4948
"ethers": "^6.5.1"
5049
},

evm/ts/src/axelar.ts

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,41 +34,42 @@ export interface GMPError {
3434
message: string;
3535
}
3636

37+
export function getAxelarApiUrl(network: Network): string {
38+
return network === "Mainnet"
39+
? "https://api.axelarscan.io"
40+
: "https://testnet.api.axelarscan.io";
41+
}
42+
43+
export function getAxelarChain(chain: Chain): string {
44+
const axelarChain = axelarChains[chain];
45+
if (!axelarChain) {
46+
throw new Error(`Unsupported axelar chain: ${chain}`);
47+
}
48+
return axelarChain;
49+
}
50+
3751
export async function getAxelarGasFee(
3852
network: Network,
3953
sourceChain: Chain,
4054
destinationChain: Chain,
4155
gasLimit: bigint,
4256
timeoutMs = 10000
4357
): Promise<bigint> {
44-
const baseUrl =
45-
network === "Mainnet"
46-
? "https://api.axelarscan.io/gmp/estimateGasFee"
47-
: "https://testnet.api.axelarscan.io/gmp/estimateGasFee";
48-
49-
const axelarSourceChain = axelarChains[sourceChain];
50-
if (!axelarSourceChain) {
51-
throw new Error(`Unsupported axelar source chain: ${sourceChain}`);
52-
}
53-
54-
const axelarDestinationChain = axelarChains[destinationChain];
55-
if (!axelarDestinationChain) {
56-
throw new Error(
57-
`Unsupported axelar destination chain: ${destinationChain}`
58-
);
59-
}
58+
const url = `${getAxelarApiUrl(network)}/gmp/estimateGasFee`;
59+
const axelarSourceChain = getAxelarChain(sourceChain);
60+
const axelarDestinationChain = getAxelarChain(destinationChain);
6061

6162
const maxRetries = 3;
6263
let lastResult: bigint | null = null;
6364

6465
// TODO: the Axelar API sometimes returns 0 gas fee. Retry a few times if we get 0.
65-
// The issue is intermittent and the Axelar team is looking into it.
66+
// The issue is intermittent and the Axelar team is looking into fixing it.
6667
for (let attempt = 0; attempt < maxRetries; attempt++) {
6768
const controller = new AbortController();
6869
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
6970

7071
try {
71-
const response = await fetch(baseUrl, {
72+
const response = await fetch(url, {
7273
method: "POST",
7374
headers: {
7475
"Content-Type": "application/json",
@@ -115,21 +116,15 @@ export async function getAxelarTransactionStatus(
115116
txHash: string,
116117
timeoutMs = 10000
117118
): Promise<{ status: GMPStatus | string; error?: GMPError }> {
118-
const baseUrl =
119-
network === "Mainnet"
120-
? "https://api.axelarscan.io"
121-
: "https://testnet.api.axelarscan.io";
122-
123-
const axelarSourceChain = axelarChains[sourceChain];
124-
if (!axelarSourceChain) {
125-
throw new Error(`Unsupported axelar source chain: ${sourceChain}`);
126-
}
119+
const url = `${getAxelarApiUrl(network)}/gmp/searchGMP`;
120+
121+
const axelarSourceChain = getAxelarChain(sourceChain);
127122

128123
const controller = new AbortController();
129124
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
130125

131126
try {
132-
const response = await fetch(`${baseUrl}/gmp/searchGMP`, {
127+
const response = await fetch(url, {
133128
method: "POST",
134129
headers: {
135130
"Content-Type": "application/json",

evm/ts/src/ethers-contracts/multiTokenNtt/1_1_0/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
/* Autogenerated file. Do not edit manually. */
22
/* tslint:disable */
33
/* eslint-disable */
4-
//import type * as gmpManagerSol from "./GmpManager.sol";
5-
//export type { gmpManagerSol };
6-
//import type * as multiTokenNttSol from "./MultiTokenNtt.sol";
7-
//export type { multiTokenNttSol };
8-
//export * as factories from "./factories/index.js";
94
export type { GmpManager } from "./GmpManager.sol/GmpManager.js";
105
export { GmpManager__factory } from "./factories/GmpManager.sol/GmpManager__factory.js";
116
export type { MultiTokenNtt } from "./MultiTokenNtt.sol/MultiTokenNtt.js";

evm/ts/src/multiTokenNtt.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,25 @@ export class EvmMultiTokenNtt<N extends Network, C extends EvmChains>
146146
);
147147
}
148148

149+
private static versionCache = new Map<string, string>();
150+
149151
static async getVersion(
150152
provider: ethers.Provider,
151153
contracts: Contracts & { multiTokenNtt?: MultiTokenNtt.Contracts }
152154
) {
155+
const multiTokenNtt = contracts.multiTokenNtt;
156+
if (!multiTokenNtt) {
157+
throw new Error("No multiTokenNtt contracts configured");
158+
}
159+
160+
const cacheKey = `${multiTokenNtt.chain}-${multiTokenNtt.manager}`;
161+
const cached = EvmMultiTokenNtt.versionCache.get(cacheKey);
162+
if (cached) {
163+
return cached;
164+
}
165+
153166
const contract = new ethers.Contract(
154-
contracts.multiTokenNtt!.manager,
167+
multiTokenNtt.manager,
155168
["function NTT_MANAGER_VERSION() public view returns (string)"],
156169
provider
157170
);
@@ -162,6 +175,7 @@ export class EvmMultiTokenNtt<N extends Network, C extends EvmChains>
162175
if (!abiVersion) {
163176
throw new Error("NTT_MANAGER_VERSION not found");
164177
}
178+
EvmMultiTokenNtt.versionCache.set(cacheKey, abiVersion);
165179
return abiVersion;
166180
} catch (e) {
167181
console.error(
@@ -252,7 +266,7 @@ export class EvmMultiTokenNtt<N extends Network, C extends EvmChains>
252266
case "wormhole":
253267
return {
254268
index: transceiver.index,
255-
payload: new Uint8Array([1]), // disable standard relayer
269+
payload: new Uint8Array([1]), // disable standard relayer, use executor route for automatic relay
256270
};
257271
case "axelar": {
258272
// If we fail to fetch the gas fee, then use 0 as a fallback.
@@ -626,6 +640,7 @@ export class EvmMultiTokenNtt<N extends Network, C extends EvmChains>
626640
);
627641
}
628642

643+
// Upper bound estimate of gas limit needed for transfer on the destination chain
629644
async estimateGasLimit(
630645
originalToken: MultiTokenNtt.OriginalTokenId
631646
): Promise<bigint> {

0 commit comments

Comments
 (0)