Sub-Adapters 10

Preview and test each sub adapter.

Wormhole - Ethereum-Solana (wormhole-ethereum-solana)

Wormhole - Ethereum-BSC (wormhole-ethereum-bsc)

Wormhole - Ethereum-Avalanche (wormhole-ethereum-avalanche)

Wormhole - Ethereum-NEAR (wormhole-ethereum-near)

Wormhole - Solana-BSC (wormhole-solana-bsc)

Wormhole - Solana-Avalanche (wormhole-solana-avalanche)

Wormhole - Solana-NEAR (wormhole-solana-near)

Wormhole - BSC-Avalanche (wormhole-bsc-avalanche)

Wormhole - BSC-NEAR (wormhole-bsc-near)

Wormhole - Avalanche-NEAR (wormhole-avalanche-near)

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'Wormhole Bridged Assets';
2export const version = '0.0.5';
3export const license = 'MIT';
4
5interface Asset {
6  id: string
7  nativeChain: string
8  wrappersByChain: { [chain: string]: { address: string, decimals?: number } }
9  stablecoin?: boolean
10  coingeckoId?: string
11}
12
13interface Chain {
14  id: string
15  name: string
16}
17
18const assets: Asset[] = [
19  {
20    id: 'eth',
21    nativeChain: 'ethereum',
22    coingeckoId: 'ethereum',
23    wrappersByChain: {
24      solana: {
25        address: '7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs',
26        decimals: 8,
27      },
28      bsc: {
29        address: '0x4DB5a66E937A9F4473fA95b1cAF1d1E1D62E29EA',
30      },
31      avalanche: {
32        address: '0x8b82a291f83ca07af22120aba21632088fc92931',
33      },
34    },
35  },
36  {
37    id: 'usdc',
38    nativeChain: 'ethereum',
39    stablecoin: true,
40    wrappersByChain: {
41      solana: {
42        address: 'A9mUU4qviSctJVPJdBJWkb28deg915LYJKrzQ19ji3FM',
43        decimals: 6,
44      },
45      bsc: {
46        address: '0xB04906e95AB5D797aDA81508115611fee694c2b3',
47        decimals: 6,
48      },
49      polygon: {
50        address: '0x4318cb63a2b8edf2de971e2f17f77097e499459d',
51        decimals: 6,
52      },
53    },
54  },
55  {
56    id: 'usdc-sol',
57    nativeChain: 'solana',
58    stablecoin: true,
59    wrappersByChain: {
60      ethereum: {
61        address: '0x41f7B8b9b897276b7AAE926a9016935280b44E97',
62        decimals: 6,
63      },
64    },
65  },
66  {
67    id: 'usdt',
68    nativeChain: 'ethereum',
69    stablecoin: true,
70    wrappersByChain: {
71      solana: {
72        address: 'Dn4noZ5jgGfkntzcQSUZ8czkreiZ1ForXYoV2H8Dm7S1',
73        decimals: 6,
74      },
75      bsc: {
76        address: '0x524bC91Dc82d6b90EF29F76A3ECAaBAffFD490Bc',
77        decimals: 6,
78      },
79    },
80  },
81  {
82    id: 'sol',
83    nativeChain: 'solana',
84    coingeckoId: 'solana',
85    wrappersByChain: {
86      ethereum: {
87        address: '0xD31a59c85aE9D8edEFeC411D448f90841571b89c',
88        decimals: 9,
89      },
90      bsc: {
91        address: '0xfA54fF1a158B5189Ebba6ae130CEd6bbd3aEA76e',
92        decimals: 9,
93      },
94      avalanche: {
95        address: '0xfe6b19286885a4f7f55adad09c3cd1f906d2478f',
96        decimals: 9,
97      },
98    },
99  },
100  {
101    id: 'avax',
102    nativeChain: 'avalanche',
103    coingeckoId: 'avalanche-2',
104    wrappersByChain: {
105      solana: {
106        address: 'KgV1GvrHQmRBY8sHQQeUKwTm2r2h8t4C8qt12Cw1HVE',
107        decimals: 8,
108      },
109      ethereum: {
110        address: '0x85f138bfee4ef8e540890cfb48f620571d67eda3',
111      },
112      bsc: {
113        address: '0x96412902aa9aff61e13f085e70d3152c6ef2a817',
114      },
115    },
116  },
117  {
118    id: 'bnb',
119    nativeChain: 'bsc',
120    coingeckoId: 'binancecoin',
121    wrappersByChain: {
122      solana: {
123        address: '9gP2kCy3wA1ctvYWQk75guqXuHfrEomqydHLtcTCqiLa',
124        decimals: 8,
125      },
126      ethereum: {
127        address: '0x418d75f65a02b3d53b2418fb8e1fe493759c7605',
128      },
129      avalanche: {
130        address: '0x442f7f22b1ee2c842beaff52880d4573e9201158',
131      },
132    },
133  },
134  {
135    id: 'busd',
136    nativeChain: 'bsc',
137    stablecoin: true,
138    wrappersByChain: {
139      ethereum: {
140        address: '0x7B4B0B9b024109D182dCF3831222fbdA81369423',
141      },
142      polygon: {
143        address: '0xa8d394fe7380b8ce6145d5f85e6ac22d4e91acde',
144      },
145    },
146  },
147  {
148    id: 'ftt',
149    nativeChain: 'ethereum',
150    coingeckoId: 'ftx-token',
151    wrappersByChain: {
152      solana: {
153        address: 'EzfgjvkSwthhgHaceR3LnKXUoRkP6NUhfghdaHAj1tUv',
154        decimals: 8,
155      },
156    },
157  },
158  {
159    id: 'ldo',
160    nativeChain: 'ethereum',
161    coingeckoId: 'lido-dao',
162    wrappersByChain: {
163      solana: {
164        address: 'HZRCwxP2Vq9PCpPXooayhJ2bxTpo5xfpQrwB1svh332p',
165        decimals: 8,
166      },
167    },
168  },
169  {
170    id: 'sweat',
171    nativeChain: 'near',
172    coingeckoId: 'sweatcoin',
173    wrappersByChain: {
174      ethereum: {
175        address: '0xb4b9dc1c77bdbb135ea907fd5a08094d98883a35',
176      },
177    },
178  },
179];
180
181const chains: Chain[] = [
182  {
183    id: 'ethereum',
184    name: 'Ethereum',
185  },
186  {
187    id: 'solana',
188    name: 'Solana',
189  },
190  {
191    id: 'bsc',
192    name: 'BSC',
193  },
194  {
195    id: 'avalanche',
196    name: 'Avalanche',
197  },
198  {
199    id: 'near',
200    name: 'NEAR',
201  },
202]
203
204export function setup(sdk: Context) {
205  const getEVMSupply = (chain: string) => async (addr: string) => {
206    const supply = await sdk.ethers.getERC20Contract(addr, chain).totalSupply();
207    return parseInt(supply.toString());
208  }
209
210  const getSolanaTokenSupply = async (addr: string) => {
211    const data = await sdk.http.post('https://api.mainnet-beta.solana.com', {
212      jsonrpc: "2.0",
213      id: 1,
214      method: "getTokenSupply",
215      params: [addr],
216    });
217    return parseInt(data.result.value.amount);
218  }
219
220  const getSupply: { [chain: string]: (addr: string) => Promise<number> } = {
221    ethereum: getEVMSupply('ethereum'),
222    bsc: getEVMSupply('bsc'),
223    avalanche: getEVMSupply('avalanche'),
224    solana: getSolanaTokenSupply,
225  }
226
227  const getBridged = async (chainA: string, chainB: string) => {
228    let total = 0;
229    for (const asset of assets) {
230      if (asset.nativeChain === chainA && asset.wrappersByChain[chainB]) {
231        const [wrapperSupply, price] = await Promise.all([
232          getSupply[chainB](asset.wrappersByChain[chainB].address),
233          asset.stablecoin ? Promise.resolve(1) : sdk.coinGecko.getCurrentPrice(asset.coingeckoId),
234        ]);
235        const decimals = asset.wrappersByChain[chainB].decimals || 18;
236        const wrapperSupplyDecimal = wrapperSupply / (10 ** decimals);
237        const bridgedValue = wrapperSupplyDecimal * price;
238        total += bridgedValue;
239      }
240    }
241    return total;
242  }
243
244  sdk.registerBundle('wormhole', {
245    name: 'Wormhole',
246    icon: sdk.ipfs.getDataURILoader('QmSrrpVYatpEt8Mvyd4kDrBvxwgYGNvXzB7fZWmhHRBzGy', 'image/svg+xml'),
247    category: 'multisig',
248    requiredSigners: 13,
249    totalSigners: 19,
250    description: 'Wormhole is a cross-chain interoperability protocol. Cross-chain messages are '
251      + 'relayed by a set of 19 "guardians", who publicly known.',
252  });
253
254  for (let i = 0; i < chains.length; i += 1) {
255    for (let j = i + 1; j < chains.length; j += 1) {
256      const chainA = chains[i];
257      const chainB = chains[j];
258
259      sdk.register({
260        id: `wormhole-${chainA.id}-${chainB.id}`,
261        bundle: 'wormhole',
262        queries: {
263          currentValueBridgedAToB: () => getBridged(chainA.id, chainB.id),
264          currentValueBridgedBToA: () => getBridged(chainB.id, chainA.id),
265        },
266        metadata: {
267          name: `Wormhole`,
268          icon: sdk.ipfs.getDataURILoader('QmSrrpVYatpEt8Mvyd4kDrBvxwgYGNvXzB7fZWmhHRBzGy', 'image/svg+xml'),
269          subtitle: `${chainA.name}-${chainB.name}`,
270          chainA: chainA.id,
271          chainAName: chainA.name,
272          chainB: chainB.id,
273          chainBName: chainB.name,
274        },
275      })
276    }
277  }
278}
279

It's something off?

Report it to the discussion board on Discord, we will take care of it.

Adapter Info

Version

0.0.5

License

MIT

IPFS CID

QmXXc2uuUEvZ9cGr9YC3xes5tgDZ5DjkyJWm1Zuq2EHWb7

CID (source)

QmY3sgDgS6kGGAwQ7BmfcEQzugVWpibwS22Pn5mgTk1YQZ

Collections

Author

mihal.eth