Sub-Adapters 7
Preview and test each sub adapter.
Osmosis/Cosmos Hub IBC (osmosis-cosmoshub)
Osmosis/Juno IBC (osmosis-juno)
Cosmos Hub/Juno IBC (cosmoshub-juno)
Osmosis/Secret Network IBC (osmosis-secretnetwork)
Osmosis/EVMOS IBC (osmosis-evmos)
Cosmos Hub/EVMOS IBC (cosmoshub-evmos)
Cosmos Hub/Secret Network IBC (cosmoshub-secretnetwork)
Adapter Code
Check the entire code written for the Adapter.
Source code
Showing TS source.
1export const name = 'IBC Bridged Assets';
2export const version = '0.1.4';
3export const license = 'MIT';
4export const changeLog = 'Add Hub/Secret';
5
6const bridges = [
7 {
8 id: 'osmosis-cosmoshub',
9 name: 'Osmosis/Cosmos Hub IBC',
10 chainA: {
11 chain: 'osmosis',
12 escrow: 'osmo1a53udazy8ayufvy0s434pfwjcedzqv347h34au',
13 },
14 chainB: {
15 chain: 'cosmoshub',
16 escrow: 'cosmos1x54ltnyg88k0ejmk8ytwrhd3ltm84xehrnlslf',
17 },
18 },
19 {
20 id: 'osmosis-juno',
21 name: 'Osmosis/Juno IBC',
22 chainA: {
23 chain: 'osmosis',
24 escrow: 'osmo1uf085y7mpup6hl5cactwgnt5dfuysh5z63h42g',
25 },
26 chainB: {
27 chain: 'juno',
28 escrow: 'juno1a53udazy8ayufvy0s434pfwjcedzqv34q7p7vj',
29 },
30 },
31 {
32 id: 'cosmoshub-juno',
33 name: 'Cosmos Hub/Juno IBC',
34 chainA: {
35 chain: 'cosmoshub',
36 escrow: 'cosmos1ju6tlfclulxumtt2kglvnxduj5d93a64r5czge',
37 },
38 chainB: {
39 chain: 'juno',
40 escrow: 'juno1kq2rzz6fq2q7fsu75a9g7cpzjeanmk687hxyug',
41 }
42 },
43 {
44 id: 'osmosis-secretnetwork',
45 name: 'Osmosis/Secret Network IBC',
46 chainA: {
47 chain: 'osmosis',
48 escrow: 'osmo188npdeccnax34adzf404csdezl8ulv6axv250m',
49 },
50 chainB: {
51 chain: 'secretnetwork',
52 escrow: 'secret1kq2rzz6fq2q7fsu75a9g7cpzjeanmk682q3kxg',
53 },
54 },
55 {
56 id: 'osmosis-evmos',
57 name: 'Osmosis/EVMOS IBC',
58 chainA: {
59 chain: 'osmosis',
60 escrow: 'osmo125dgaejga0q9wc6jcpf75lh6aeeyvrdz88xvzd',
61 },
62 chainB: {
63 chain: 'evmos',
64 escrow: 'evmos1a53udazy8ayufvy0s434pfwjcedzqv345dnt3x',
65 },
66 },
67 {
68 id: 'cosmoshub-evmos',
69 name: 'Cosmos Hub/EVMOS IBC',
70 chainA: {
71 chain: 'cosmoshub',
72 escrow: 'cosmos1387hmv7nprazgd7e48asp3uk0php3270w8wthy',
73 },
74 chainB: {
75 chain: 'evmos',
76 escrow: 'evmos1krtrt5dvhnw5j46ljgah7q5f9pm3vvakpzscgt',
77 },
78 },
79 {
80 id: 'cosmoshub-secretnetwork',
81 name: 'Cosmos Hub/Secret Network IBC',
82 chainA: {
83 chain: 'cosmoshub',
84 escrow: 'cosmos1tssxslxqr92zg2grk95d86vq30raru6pl8x8pn',
85 },
86 chainB: {
87 chain: 'secretnetwork',
88 escrow: 'secret1a53udazy8ayufvy0s434pfwjcedzqv345fkvkj',
89 },
90 },
91];
92
93const assets: any = {
94 uosmo: {
95 coingeckoId: 'osmosis',
96 },
97 uatom: {
98 coingeckoId: 'cosmos',
99 },
100 ujuno: {
101 coingeckoId: 'juno-network',
102 },
103 uscrt: {
104 coingeckoId: 'secret',
105 },
106 aevmos: {
107 coingeckoId: 'evmos',
108 decimals: 18,
109 },
110}
111
112const chains: any = {
113 osmosis: {
114 lcd: 'https://lcd.osmosis.zone',
115 },
116 cosmoshub: {
117 lcd: 'https://cosmos-mainnet-rpc.allthatnode.com:1317/',
118 },
119 axelar: {
120 lcd: 'https://axelar-lcd.quickapi.com/',
121 },
122 juno: {
123 lcd: 'https://lcd-juno.itastakers.com/',
124 },
125 secretnetwork: {
126 lcd: 'https://api.scrt.network',
127 },
128 evmos: {
129 lcd: 'https://api-evmos-ia.cosmosia.notional.ventures',
130 },
131}
132
133export function setup(sdk: Context) {
134 const getBalances = async (lcd: string, address: string) => {
135 let balances: any[] = [];
136
137 let pagiationKey = null
138 for (let i = 0; i < 20; i += 1) {
139 let url = `${lcd}/cosmos/bank/v1beta1/balances/${address}`
140 if (pagiationKey) {
141 url += `?pagination.key=${pagiationKey}`
142 }
143 const response = await sdk.http.get(url)
144
145 balances = [...balances, ...response.balances];
146
147 pagiationKey = response.pagination.next_key
148 if (!pagiationKey) {
149 break
150 }
151 }
152
153 return balances;
154 }
155
156 const getBridged = async (lcd: string, escrow: string) => {
157 const balances = await getBalances(lcd, escrow);
158
159 let total = 0;
160 for (const balance of balances) {
161 if (balance.denom.indexOf('ibc/') !== 0) {
162 const denom = balance.denom;
163 if (assets[denom]) {
164 const price = await sdk.defiLlama.getCurrentPrice('coingecko', assets[denom].coingeckoId);
165 const amountDecimal = balance.amount / (10 ** (assets[denom].decimals || 6));
166 const value = price * amountDecimal;
167 total += value;
168 }
169 }
170 }
171
172 return total;
173 }
174
175 sdk.registerBundle('ibc', {
176 name: 'IBC',
177 icon: sdk.ipfs.getDataURILoader('QmXuNeBVkrfc3zNesdvv9BrWHBsE475uCGcEo3hBgHXLXM', 'image/svg+xml'),
178 category: 'light-client',
179 });
180
181 for (const bridge of bridges) {
182 sdk.register({
183 id: bridge.id,
184 bundle: 'ibc',
185 queries: {
186 currentValueBridgedAToB: () => getBridged(chains[bridge.chainA.chain].lcd, bridge.chainA.escrow),
187 currentValueBridgedBToA: () => getBridged(chains[bridge.chainB.chain].lcd, bridge.chainB.escrow),
188 },
189 metadata: {
190 name: bridge.name,
191 icon: sdk.ipfs.getDataURILoader('QmXuNeBVkrfc3zNesdvv9BrWHBsE475uCGcEo3hBgHXLXM', 'image/svg+xml'),
192
193 chainA: bridge.chainA.chain,
194 chainB: bridge.chainB.chain,
195 category: 'light-client',
196 },
197 });
198 }
199}
200
It's something off?
Report it to the discussion board on Discord, we will take care of it.