Sub-Adapters 10
Preview and test each sub adapter.
Axelar - Ethereum (axelar-ethereum)
Axelar - BSC (axelar-bsc)
Axelar - Avalanche (axelar-avalanche)
Axelar - Polygon (axelar-polygon)
Axelar - Fantom (axelar-fantom)
Axelar - Moonbeam (axelar-moonbeam)
IBC - Cosmos Hub/Axelar IBC (axelar-cosmoshub)
IBC - Osmosis/Axelar IBC (axelar-osmosis)
IBC - Juno/Axelar IBC (axelar-juno)
IBC - Evmos/Axelar IBC (axelar-evmos)
Adapter Code
Check the entire code written for the Adapter.
Source code
Showing TS source.
1export const name = 'Axelar Bridged';
2export const version = '0.0.6';
3export const license = 'MIT';
4
5const AXELAR_ICON = 'QmS9Gu4osnWCd3PPxwWrb3uUWCERGWAR4TSkjNQt4orUki';
6const IBC_ICON = 'QmXuNeBVkrfc3zNesdvv9BrWHBsE475uCGcEo3hBgHXLXM';
7
8const chains = [
9 {
10 id: 'ethereum',
11 },
12 {
13 id: 'bsc',
14 name: 'BSC',
15 axelarId: 'binance',
16 },
17 {
18 id: 'avalanche',
19 },
20 {
21 id: 'polygon',
22 },
23 {
24 id: 'fantom',
25 },
26 {
27 id: 'moonbeam',
28 },
29 // {
30 // name: 'aurora',
31 // },
32 {
33 id: 'cosmoshub',
34 name: 'Cosmos Hub',
35 ibc: true,
36 },
37 {
38 id: 'osmosis',
39 ibc: true,
40 },
41 {
42 id: 'juno',
43 ibc: true,
44 },
45 {
46 id: 'evmos',
47 ibc: true,
48 },
49]
50
51export function setup(sdk: Context) {
52 const getAssets = () => sdk.http.post('https://api.axelarscan.io/', {
53 collection: "assets",
54 path: null,
55 'module': "data",
56 });
57
58 let assetsCache: any = null;
59 const getAssetsCached = () => {
60 if (!assetsCache) {
61 assetsCache = getAssets();
62 }
63 return assetsCache;
64 }
65
66 const assetCache: { [id: string]: any } = {};
67 const getAssetTVL = (denom: string) => sdk.http.get(`https://cryptostats-api-proxy.vercel.app/api/v1/axelar/tvl/${denom}`)
68 .then(data => data.data[0]);
69
70 const getAssetCached = (denom: string) => {
71 if (!assetCache[denom]) {
72 assetCache[denom] = getAssetTVL(denom);
73 }
74 return assetCache[denom];
75 }
76
77 const getImports = (chain: any) => async () => {
78 const assets = await getAssetsCached()
79
80 const assetTVLs: any[] = await Promise.all(assets.map(async asset => getAssetCached(asset.id)));
81
82 let totalUSD = 0;
83 for (const asset of assetTVLs) {
84 const assetOnChain = asset.tvl[chain.axelarId || chain.id];
85 if (assetOnChain?.contract_data?.is_native) {
86 totalUSD += asset.price * assetOnChain.gateway_balance;
87 }
88 if (assetOnChain?.denom_data?.is_native) {
89 totalUSD += asset.price * assetOnChain.source_escrow_balance;
90 }
91 }
92
93 return totalUSD;
94 }
95
96 const getExports = (chain: any) => async () => {
97 const assets = await getAssets()
98 const assetTVLs: any[] = await Promise.all(assets.map(async asset => getAssetCached(asset.id)));
99
100 let totalUSD = 0;
101 for (const asset of assetTVLs) {
102 if (!asset.price) {
103 sdk.log.warn(`Skipping ${asset.asset}, no price`);
104 continue;
105 }
106
107 const assetOnChain = asset.tvl[chain.id];
108 if (assetOnChain?.contract_data && !assetOnChain.contract_data.is_native) {
109 totalUSD += asset.price * assetOnChain.supply;
110 }
111 if (assetOnChain?.denom_data && !assetOnChain.denom_data.is_native) {
112 totalUSD += asset.price * assetOnChain.supply;
113 }
114 }
115
116 return totalUSD;
117 }
118
119 sdk.registerBundle('axelar', {
120 name: 'Axelar',
121 icon: sdk.ipfs.getDataURILoader(AXELAR_ICON, 'image/svg+xml'),
122 category: 'multisig',
123 description: 'Axelar Network is a full-stack decentralized transport layer delivering secure cross-chain messages.',
124 });
125
126 for (const chain of chains) {
127 const name = chain.name || chain.id.charAt(0).toUpperCase() + chain.id.substring(1);
128 sdk.register({
129 id: `axelar-${chain.id}`,
130 bundle: chain.ibc ? 'ibc' : 'axelar',
131 queries: {
132 currentValueBridgedAToB: getExports(chain),
133 currentValueBridgedBToA: getImports(chain),
134 },
135 metadata: {
136 name: chain.ibc ? 'IBC' : 'Axelar',
137 subtitle: chain.ibc ? `${name}/Axelar IBC` : name,
138 icon: sdk.ipfs.getDataURILoader(chain.ibc ? IBC_ICON : AXELAR_ICON, 'image/svg+xml'),
139
140 chainA: 'axelar',
141 chainB: chain.id,
142 category: 'unknown',
143 },
144 });
145 }
146}
147
It's something off?
Report it to the discussion board on Discord, we will take care of it.