Sub-Adapters 6
Preview and test each sub adapter.
LayerZero Aptos Bridge - Ethereum (aptos-ethereum)
LayerZero Aptos Bridge - Avalanche (aptos-avalanche)
LayerZero Aptos Bridge - BNB Chain (aptos-bsc)
LayerZero Aptos Bridge - Optimism (aptos-optimism)
LayerZero Aptos Bridge - Arbitrum One (aptos-arbitrum-one)
LayerZero Aptos Bridge - Polygon (aptos-polygon)
Adapter Code
Check the entire code written for the Adapter.
Source code
Showing TS source.
1export const name = 'Aptos Bridge';
2export const version = '0.1.1';
3export const license = 'MIT';
4
5interface Token {
6 stablecoin?: boolean
7 coingecko?: string
8 decimals?: number
9}
10
11const tokens: { [id: string]: Token } = {
12 ETH: {
13 coingecko: 'ethereum',
14 },
15 USDC: {
16 stablecoin: true,
17 decimals: 6,
18 },
19 USDD: {
20 stablecoin: true,
21 },
22 USDT: {
23 stablecoin: true,
24 decimals: 6,
25 },
26 BUSDT: {
27 stablecoin: true,
28 },
29}
30
31interface Chain {
32 id: string;
33 name?: string;
34 escrow: string;
35 tokens: any[];
36}
37
38const chains: Chain[] = [
39 {
40 id: 'ethereum',
41 escrow: '0x50002CdFe7CCb0C41F519c6Eb0653158d11cd907',
42 tokens: [
43 {
44 id: 'ETH',
45 address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
46 },
47 {
48 id: 'USDC',
49 address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
50 },
51 {
52 id: 'USDT',
53 address: '0xdac17f958d2ee523a2206206994597c13d831ec7',
54 },
55 ],
56 },
57 {
58 id: 'avalanche',
59 escrow: '0xA5972EeE0C9B5bBb89a5B16D1d65f94c9EF25166',
60 tokens: [
61 {
62 id: 'USDC',
63 address: '0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
64 },
65 {
66 id: 'USDT',
67 address: '0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7',
68 },
69 ],
70 },
71 {
72 id: 'bsc',
73 name: 'BNB Chain',
74 escrow: '0x2762409Baa1804D94D8c0bCFF8400B78Bf915D5B',
75 tokens: [
76 {
77 id: 'USDD',
78 address: '0xd17479997F34dd9156Deef8F95A52D81D265be9c',
79 },
80 {
81 id: 'BUSDT',
82 address: '0x55d398326f99059ff775485246999027b3197955',
83 },
84 ],
85 },
86 {
87 id: 'optimism',
88 escrow: '0x86Bb63148d17d445Ed5398ef26Aa05Bf76dD5b59',
89 tokens: [
90 {
91 id: 'ETH',
92 address: '0x4200000000000000000000000000000000000006',
93 },
94 {
95 id: 'USDC',
96 address: '0x7f5c764cbc14f9669b88837ca1490cca17c31607',
97 },
98 ],
99 },
100 {
101 id: 'arbitrum-one',
102 name: 'Arbitrum One',
103 escrow: '0x1BAcC2205312534375c8d1801C27D28370656cFf',
104 tokens: [
105 {
106 id: 'ETH',
107 address: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
108 },
109 {
110 id: 'USDC',
111 address: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8',
112 },
113 ],
114 },
115 {
116 id: 'polygon',
117 escrow: '0x488863D609F3A673875a914fBeE7508a1DE45eC6',
118 tokens: [
119 {
120 id: 'USDC',
121 address: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174',
122 },
123 {
124 id: 'USDT',
125 address: '0xc2132d05d31c914a87c6611c10748aeb04b58e8f',
126 },
127 ],
128 },
129]
130
131export function setup(sdk: Context) {
132 const getPrice = async (id: string): Promise<number> => {
133 const token = tokens[id];
134
135 if (!token) {
136 sdk.log.warn(`Token ${id} not found`);
137 return 0;
138 }
139 if (token.stablecoin) {
140 return 1;
141 }
142
143 const price = await sdk.defiLlama.getCurrentPrice('coingecko', token.coingecko);
144 return price;
145 }
146
147 const getBridged = async (chain: Chain) => {
148 const amounts = await Promise.all(
149 chain.tokens.map(async (token): Promise<number> => {
150 const [amount, price] = await Promise.all([
151 sdk.ethers.getERC20Contract(token.address, chain.id).balanceOf(chain.escrow),
152 getPrice(token.id),
153 ]);
154 const decimals = tokens[token.id] ? tokens[token.id].decimals || 18 : 0;
155 return amount / (10 ** decimals) * price;
156 })
157 );
158 sdk.log(amounts)
159
160 const sum = amounts.reduce((a, b) => a + b, 0);
161 return sum;
162 }
163
164 const metadata = {
165 name: 'LayerZero Aptos Bridge',
166 icon: sdk.ipfs.getDataURILoader('QmbuRx9b74p2b8gATPiFsEoeEdUSwnVQ5B1ksq6SyDH7q9', 'image/svg+xml'),
167 category: 'native',
168 };
169
170 sdk.registerBundle('aptos', metadata);
171
172 for (const chain of chains) {
173 sdk.register({
174 id: `aptos-${chain.id}`,
175 bundle: 'aptos',
176 queries: {
177 currentValueBridgedAToB: () => getBridged(chain),
178 currentValueBridgedBToA: async () => 0,
179 },
180 metadata: {
181 ...metadata,
182 subtitle: chain.name || `${chain.id.charAt(0).toUpperCase()}${chain.id.substr(1)}`,
183
184 chainA: chain.id,
185 chainB: 'aptos',
186 },
187 });
188 }
189}
190
It's something off?
Report it to the discussion board on Discord, we will take care of it.