Sub-Adapters 10
Preview and test each sub adapter.
Multichain - Ethereum-Avalanche (multichain-ethereum-avalanche)
Multichain - Ethereum-BNB Chain (multichain-ethereum-bsc)
Multichain - Ethereum-Fantom (multichain-ethereum-fantom)
Multichain - Ethereum-Moonbeam (multichain-ethereum-moonbeam)
Multichain - Avalanche-BNB Chain (multichain-avalanche-bsc)
Multichain - Avalanche-Fantom (multichain-avalanche-fantom)
Multichain - Avalanche-Moonbeam (multichain-avalanche-moonbeam)
Multichain - BNB Chain-Fantom (multichain-bsc-fantom)
Multichain - BNB Chain-Moonbeam (multichain-bsc-moonbeam)
Multichain - Fantom-Moonbeam (multichain-fantom-moonbeam)
Adapter Code
Check the entire code written for the Adapter.
Source code
Showing TS source.
1export const name = 'Multichain Bridged Assets';
2export const version = '0.0.6';
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 fantom: {
25 address: '0x74b23882a30290451A17c44f4F05243b6b58C76d',
26 decimals: 18,
27 },
28 moonbeam: {
29 address: '0xfa9343c3897324496a05fc75abed6bac29f8a40f',
30 decimals: 18,
31 },
32 },
33 },
34 {
35 id: 'usdt',
36 nativeChain: 'ethereum',
37 stablecoin: true,
38 wrappersByChain: {
39 fantom: {
40 address: '0x049d68029688eabf473097a2fc38ef61633a3c7a',
41 decimals: 6,
42 },
43 moonbeam: {
44 address: '0xefaeee334f0fd1712f9a8cc375f427d9cdd40d73',
45 decimals: 6,
46 },
47 },
48 },
49 {
50 id: 'usdc',
51 nativeChain: 'ethereum',
52 stablecoin: true,
53 wrappersByChain: {
54 fantom: {
55 address: '0x04068DA6C83AFCFA0e13ba15A6696662335D5B75',
56 decimals: 6,
57 },
58 moonbeam: {
59 address: '0x818ec0a7fe18ff94269904fced6ae3dae6d6dc0b',
60 decimals: 6,
61 },
62 },
63 },
64 {
65 id: 'dai',
66 nativeChain: 'ethereum',
67 stablecoin: true,
68 wrappersByChain: {
69 moonbeam: {
70 address: '0x765277eebeca2e31912c9946eae1021199b39c61',
71 decimals: 18,
72 },
73 },
74 },
75 {
76 id: 'wbtc',
77 nativeChain: 'ethereum',
78 coingeckoId: 'bitcoin',
79 wrappersByChain: {
80 moonbeam: {
81 address: '0x922d641a426dcffaef11680e5358f34d97d112e1',
82 decimals: 8,
83 },
84 },
85 },
86 {
87 id: 'ftm',
88 nativeChain: 'fantom',
89 coingeckoId: 'fantom',
90 wrappersByChain: {
91 // It appears this is _not_ a bridged token...
92 // ethereum: {
93 // address: '0x4e15361fd6b4bb609fa63c81a2be19d873717870',
94 // decimals: 18,
95 // },
96 moonbeam: {
97 address: '0xc19281f22a075e0f10351cd5d6ea9f0ac63d4327',
98 decimals: 18,
99 },
100 },
101 },
102 {
103 id: 'busd',
104 nativeChain: 'bsc',
105 stablecoin: true,
106 wrappersByChain: {
107 moonbeam: {
108 address: '0xA649325Aa7C5093d12D6F98EB4378deAe68CE23F',
109 decimals: 18,
110 },
111 },
112 },
113 {
114 id: 'avax',
115 nativeChain: 'avalanche',
116 coingeckoId: 'avalanche-2',
117 wrappersByChain: {
118 moonbeam: {
119 address: '0x4792C1EcB969B036eb51330c63bD27899A13D84e',
120 decimals: 18,
121 },
122 },
123 },
124 {
125 id: 'ldo',
126 nativeChain: 'ethereum',
127 coingeckoId: 'lido-dao',
128 wrappersByChain: {
129 moonbeam: {
130 address: '0x9fda7ceec4c18008096c2fe2b85f05dc300f94d0',
131 decimals: 18,
132 },
133 },
134 },
135 {
136 id: 'matic',
137 nativeChain: 'ethereum',
138 coingeckoId: 'matic-network',
139 wrappersByChain: {
140 moonbeam: {
141 address: '0x3405a1bd46b85c5c029483fbecf2f3e611026e45',
142 decimals: 18,
143 },
144 },
145 },
146];
147
148const chains: Chain[] = [
149 {
150 id: 'ethereum',
151 name: 'Ethereum',
152 },
153 {
154 id: 'avalanche',
155 name: 'Avalanche'
156 },
157 {
158 id: 'bsc',
159 name: 'BNB Chain',
160 },
161 {
162 id: 'fantom',
163 name: 'Fantom',
164 },
165 {
166 id: 'moonbeam',
167 name: 'Moonbeam',
168 },
169]
170
171export function setup(sdk: Context) {
172 const getEVMSupply = async (chain: string, addr: string) => {
173 const supply = await sdk.ethers.getERC20Contract(addr, chain).totalSupply();
174 return parseInt(supply.toString());
175 }
176
177 const getBridged = async (chainA: string, chainB: string) => {
178 let total = 0;
179 for (const asset of assets) {
180 if (asset.nativeChain === chainA && asset.wrappersByChain[chainB]) {
181 const [wrapperSupply, price] = await Promise.all([
182 getEVMSupply(chainB, asset.wrappersByChain[chainB].address),
183 asset.stablecoin ? Promise.resolve(1) : sdk.coinGecko.getCurrentPrice(asset.coingeckoId),
184 ]);
185 const wrapperSupplyDecimal = wrapperSupply / (10 ** asset.wrappersByChain[chainB].decimals);
186 const bridgedValue = wrapperSupplyDecimal * price;
187 total += bridgedValue;
188 }
189 }
190 return total;
191 }
192
193 const metadata = {
194 description: 'Multichain is a protocol for routing messages and assets across various blockchains using a network of distributed nodes.',
195 securityModel: 'Multichain relies on a network of individual nodes (described as "MPC Network") to monitor network activity. These nodes aggregate signatures off-chain to generate the on-chain transactions needed to facilitate the bridge activity. The number of signers, their identities, as well as the signer selection process is unknown at this time.',
196 website: 'https://multichain.org',
197 icon: sdk.ipfs.getDataURILoader('Qma3EuqaBNUMX3sSHqAzmwKVBNxV7UL8dZCfzyu4XXq9WX', 'image/svg+xml'),
198 category: 'multisig',
199 };
200
201 sdk.registerBundle('multichain', {
202 ...metadata,
203 name: 'Multichain',
204 });
205
206 for (let i = 0; i < chains.length; i += 1) {
207 for (let j = i + 1; j < chains.length; j += 1) {
208 const chainA = chains[i];
209 const chainB = chains[j];
210
211 sdk.register({
212 id: `multichain-${chainA.id}-${chainB.id}`,
213 bundle: 'multichain',
214 queries: {
215 currentValueBridgedAToB: () => getBridged(chainA.id, chainB.id),
216 currentValueBridgedBToA: () => getBridged(chainB.id, chainA.id),
217 },
218 metadata: {
219 ...metadata,
220 name: `Multichain`,
221 subtitle: `${chainA.name}-${chainB.name}`,
222 chainA: chainA.id,
223 chainAName: chainA.name,
224 chainB: chainB.id,
225 chainBName: chainB.name,
226 },
227 })
228 }
229 }
230}
231
It's something off?
Report it to the discussion board on Discord, we will take care of it.