Skip to content

Commit 00fbc20

Browse files
authored
Merge pull request #366 from DefiLlama/axelar
Axelar
2 parents 6cc4cd1 + f6801de commit 00fbc20

File tree

5 files changed

+47
-49
lines changed

5 files changed

+47
-49
lines changed

src/adapters/axelar/index.ts

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ import { BridgeAdapter, PartialContractEventParams } from "../../helpers/bridgeA
22
import { constructTransferParams } from "../../helpers/eventParams";
33
import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions";
44
import { BigNumber } from "ethers";
5-
import { fetchAssets, getTokenAddress } from "../squid/utils";
6-
import { getItsTokens } from "./utils";
7-
8-
5+
import { getTokenAddress } from "../squid/utils";
6+
import { getAssets, getItsTokens } from "./utils";
97

108
const axelarChains = {
119
arbitrum: {
@@ -241,11 +239,9 @@ const constructParams = (chain: SupportedChains) => {
241239
const itsAddy = axelarContractAddress.its;
242240

243241
return async (fromBlock: number, toBlock: number) => {
244-
245-
const assets = await fetchAssets();
242+
const assets = await getAssets();
246243
const itsAssets = await getItsTokens();
247244

248-
249245
//legacy
250246
const depositV1 = constructTransferParams(gatewayAddy, true, {
251247
excludeFrom: [gatewayAddy, nullAddress],
@@ -260,7 +256,6 @@ const constructParams = (chain: SupportedChains) => {
260256
includeFrom: [gatewayAddy],
261257
});
262258

263-
264259
const tokenSentEvent = {
265260
...TokenSentParams,
266261
target: gatewayAddy,
@@ -305,15 +300,13 @@ const constructParams = (chain: SupportedChains) => {
305300
amount: (log: any) => BigNumber.from(log.amount),
306301
to: (log: any) => log.destinationAddress,
307302
token: (log: any) => {
308-
const asset = itsAssets.find((item: any) =>
309-
item.id.toLowerCase() === log.tokenId.toLowerCase()
310-
);
303+
const asset = itsAssets.find((item: any) => item.id.toLowerCase() === log.tokenId.toLowerCase());
311304
return asset && asset.chains && asset.chains[chain] && asset.chains[chain].tokenAddress
312305
? asset.chains[chain].tokenAddress
313-
: '';
314-
}
315-
}
316-
}
306+
: "";
307+
},
308+
},
309+
};
317310

318311
const interchainTransferReceivedEvent = {
319312
...InterchainTransferReceivedParams,
@@ -323,13 +316,11 @@ const constructParams = (chain: SupportedChains) => {
323316
amount: (log: any) => BigNumber.from(log.amount),
324317
to: (log: any) => log.destinationAddress,
325318
token: (log: any) => {
326-
const asset = itsAssets.find((item: any) =>
327-
item.id.toLowerCase() === log.tokenId.toLowerCase()
328-
);
329-
return asset && asset.chains && asset.chains[chain] && asset.chains[chain].tokenAddress
319+
const asset = itsAssets.find((item: any) => item.id.toLowerCase() === log.tokenId.toLowerCase());
320+
asset && asset.chains && asset.chains[chain] && asset.chains[chain].tokenAddress
330321
? asset.chains[chain].tokenAddress
331-
: '';
332-
}
322+
: "";
323+
},
333324
},
334325
};
335326

@@ -344,7 +335,7 @@ const constructParams = (chain: SupportedChains) => {
344335
interchainTransferReceivedEvent
345336
);
346337
return await getTxDataFromEVMEventLogs("axelar", chain, fromBlock, toBlock, eventParams);
347-
}
338+
};
348339
};
349340
const adapter: BridgeAdapter = {
350341
arbitrum: constructParams("arbitrum"),
@@ -353,12 +344,12 @@ const adapter: BridgeAdapter = {
353344
blast: constructParams("blast"),
354345
bsc: constructParams("bsc"),
355346
celo: constructParams("celo"),
356-
cfg: constructParams("cfg"), //centrifuge
347+
cfg: constructParams("cfg"), //cfg
357348
ethereum: constructParams("ethereum"),
358349
fantom: constructParams("fantom"),
359350
filecoin: constructParams("filecoin"),
360351
fraxtal: constructParams("fraxtal"),
361-
imx: constructParams("imx"), //immutable
352+
imx: constructParams("imx"),
362353
kava: constructParams("kava"),
363354
linea: constructParams("linea"),
364355
mantle: constructParams("mantle"),

src/adapters/axelar/utils.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ export const getItsTokens = () =>
66
fetch("https://api.axelarscan.io/api/getITSAssets", {
77
method: "GET",
88
headers: { "Content-Type": "application/json" },
9-
}).then((res) => res.json())
9+
}).then((res: any) => res.json())
1010
);
1111

1212

13-
// TODO
14-
// custom tokens dont seem to be getting queried for example token from this tx
15-
// https://axelarscan.io/gmp/0x83d2af2f18c63349d755ce2f3fd3ff4a7990ebd0e61458200f60504e198c843d
13+
export const getAssets = () =>
14+
retry(() =>
15+
fetch("https://api.axelarscan.io/api/getAssets", {
16+
method: "GET",
17+
headers: { "Content-Type": "application/json" },
18+
}).then((res: any) => res.json())
19+
);
20+
21+
// TODO
22+
// custom tokens dont seem to be getting queried for example token from this tx
23+
// https://axelarscan.io/gmp/0x83d2af2f18c63349d755ce2f3fd3ff4a7990ebd0e61458200f60504e198c843d

src/adapters/squid/utils.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,18 @@ export const getTokenId = (token: string, chain: string): string => {
6464
return `${chain}:${token.toLowerCase()}`;
6565
}
6666

67-
export const getTokenAddress = (symbol: string, chain: string, assets: any[]) => {
68-
// Handle native token address
69-
if (symbol === "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE") {
70-
return symbol;
71-
}
72-
73-
symbol = getSymbol(symbol);
74-
chain = getChain(chain);
75-
let tokenAddress = assets.find((asset) => asset.symbol === symbol)?.addresses?.[chain]?.address;
76-
77-
if (tokenAddress == undefined) tokenAddress = "0x000000000000000000000000000000000000dEaD"
67+
export const getTokenAddress = (symbol: string, chain: string, assets: any[]) => {
68+
// Handle native token address
69+
if (symbol === "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE") {
70+
return symbol;
71+
}
72+
symbol = getSymbol(symbol);
73+
chain = getChain(chain);
74+
let tokenAddress = assets.find((asset) => asset.symbol === symbol
75+
)?.addresses?.[chain == 'imx' ? 'immutable' : chain]?.address
76+
if (tokenAddress == undefined) tokenAddress = "0x000000000000000000000000000000000000dEaD"
7877

79-
return tokenAddress;
78+
return tokenAddress;
8079
}
8180

8281
const getChain = (chain: string) => {
@@ -98,8 +97,8 @@ const getSymbol = (rawSymbol: string) => {
9897
let symbol: string = rawSymbol;
9998
if (symbol.startsWith("axl-")) symbol = symbol.slice(4);
10099
if (symbol.startsWith("axl")) symbol = symbol.slice(3);
101-
102-
const nativeTokenMap: {[key: string]: string} = {
100+
101+
const nativeTokenMap: { [key: string]: string } = {
103102
"AVAX": "WAVAX",
104103
"FTM": "WFTM",
105104
"BNB": "WBNB",
@@ -130,7 +129,7 @@ export const fetchAssets = () => {
130129
body: JSON.stringify({
131130
method: "getAssets",
132131
}),
133-
}).then((res) => res.json())
132+
}).then((res: any) => res.json())
134133
);
135134
}
136135

@@ -189,8 +188,8 @@ export const isStablecoin = (tokenAddress: string, chain: string) => {
189188
// Add helper function to convert chain ID to name
190189
export const getChainNameFromId = (chainId: string | number): string => {
191190
// Convert number to hex string if needed
192-
const hexChainId = typeof chainId === "number" ?
193-
"0x" + chainId.toString(16) :
191+
const hexChainId = typeof chainId === "number" ?
192+
"0x" + chainId.toString(16) :
194193
chainId.toLowerCase();
195194

196195
return chainIdToName[hexChainId] || "unknown";
@@ -215,10 +214,10 @@ export const fetchWithRetry = async (url: string, maxRetries = 5) => {
215214
const response = await fetch(url);
216215
if (response.status === 429) {
217216
// Get retry-after header or use exponential backoff
218-
const retryAfter = response.headers.get('retry-after') ?
219-
parseInt(response.headers.get('retry-after') || '1') :
217+
const retryAfter = response.headers.get('retry-after') ?
218+
parseInt(response.headers.get('retry-after') || '1') :
220219
Math.pow(2, retries) * 1000;
221-
220+
222221
console.log(`Rate limited. Retrying after ${retryAfter}ms...`);
223222
await new Promise(resolve => setTimeout(resolve, retryAfter));
224223
retries++;

src/adapters/test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ const testAdapter = async () => {
6868
const startBlock = number - parseInt(numberOfBlocks);
6969
console.log(`Getting event logs on chain ${contractsChain} from block ${startBlock} to ${number}.`);
7070
const eventLogs = await adapterChainEventsFn(startBlock, number);
71-
// console.log(eventLogs)
7271
console.log(`Found ${eventLogs.length} event logs on chain ${contractsChain}.`);
7372
for (const log of eventLogs) {
7473
console.log(`[${contractsChain}] ${log.isDeposit ? "Deposit" : "Withdrawal"} ${log.txHash}`);

src/helpers/processTransactions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ export const getTxDataFromEVMEventLogs = async (
288288
let toFilter = await filter.custom(provider, iface, txLog.transactionHash);
289289
if (toFilter) dataKeysToFilter.push(i);
290290
}
291+
291292
if (getTokenFromReceipt && getTokenFromReceipt.token) {
292293
const txReceipt = await provider.getTransactionReceipt(txLog.transactionHash);
293294
if (!txReceipt) {

0 commit comments

Comments
 (0)