Sub-Adapters 8
Preview and test each sub adapter.
Binance Pegged Assets - ethereum (binance-peg-assets-ethereum)
Binance Pegged Assets - bitcoin (binance-peg-assets-bitcoin)
Binance Pegged Assets - avalanche (binance-peg-assets-avalanche)
Binance Pegged Assets - cosmoshub (binance-peg-assets-cosmoshub)
Binance Pegged Assets - near (binance-peg-assets-near)
Binance Pegged Assets - polkadot (binance-peg-assets-polkadot)
Binance Pegged Assets - solana (binance-peg-assets-solana)
Binance Pegged Assets - Bitcoin-Ethereum (binance-peg-assets-eth-bbtc)
Adapter Code
Check the entire code written for the Adapter.
Source code
Showing TS source.
1export const name = 'Binance-Pegged Assets';
2export const version = '0.0.4';
3export const license = 'MIT';
4
5const TOKEN_HUB = '0x0000000000000000000000000000000000001004'
6
7interface Token {
8 id: string
9 address: string
10 originChain: string
11 stablecoin?: boolean
12 coingeckoId?: string
13 decimals?: number
14}
15
16const tokens: Token[] = [
17 {
18 id: 'eth',
19 address: '0x2170ed0880ac9a755fd29b2688956bd959f933f8',
20 originChain: 'ethereum',
21 coingeckoId: 'ethereum',
22 },
23 {
24 id: 'btcb',
25 address: '0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c',
26 originChain: 'bitcoin',
27 coingeckoId: 'bitcoin',
28 },
29 {
30 id: 'usdc',
31 address: '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d',
32 originChain: 'ethereum',
33 stablecoin: true,
34 },
35 {
36 id: 'busd',
37 address: '0xe9e7cea3dedca5984780bafc599bd69add087d56',
38 originChain: 'ethereum',
39 stablecoin: true,
40 },
41 {
42 id: 'dai',
43 address: '0x1af3f329e8be154074d8769d1ffa4ee058b1dbc3',
44 originChain: 'ethereum',
45 stablecoin: true,
46 },
47 {
48 id: 'avax',
49 address: '0x1ce0c2827e2ef14d5c4f29a091d735a204794041',
50 originChain: 'avalanche',
51 coingeckoId: 'avalanche-2',
52 },
53 {
54 id: 'uni',
55 address: '0xbf5140a22578168fd562dccf235e5d43a02ce9b1',
56 originChain: 'ethereum',
57 coingeckoId: 'uniswap',
58 },
59 {
60 id: 'atom',
61 address: '0x0eb3a705fc54725037cc9e008bdede697f62f335',
62 originChain: 'cosmoshub',
63 coingeckoId: 'cosmos',
64 },
65 {
66 id: 'link',
67 address: '0xf8a0bf9cf54bb92f17374d9e9a321e6a111a51bd',
68 originChain: 'ethereum',
69 coingeckoId: 'chainlink',
70 },
71 {
72 id: 'near',
73 address: '0x1fa4a73a3f0133f0025378af00236f3abdee5d63',
74 originChain: 'near',
75 coingeckoId: 'near',
76 },
77 {
78 id: 'dot',
79 address: '0x7083609fCE4d1d8Dc0C979AAb8c869Ea2C873402',
80 originChain: 'polkadot',
81 coingeckoId: 'polkadot',
82 },
83 {
84 id: 'gmt',
85 address: '0x3019BF2a2eF8040C242C9a4c5c4BD4C81678b2A1',
86 originChain: 'solana',
87 coingeckoId: 'stepn',
88 decimals: 8,
89 },
90 {
91 id: 'uni',
92 address: '0xBf5140A22578168FD562DCcF235E5D43A02ce9B1',
93 originChain: 'ethereum',
94 coingeckoId: 'uniswap',
95 },
96];
97
98// Ethereum pegged:
99const bbtc: Token = {
100 id: 'bbtc',
101 address: '0x9be89d2a4cd102d8fecc6bf9da793be995c22541',
102 originChain: 'bitcoin',
103 coingeckoId: 'bitcoin',
104 decimals: 8,
105};
106// Insufficent value/liquidity to include
107// const dot: Token = {
108// id: 'dot',
109// address: '0x7884f51dc1410387371ce61747cb6264e1daee0b',
110// originChain: 'polkadot',
111// coingeckoId: 'polkadot',
112// decimals: 10,
113// };
114
115export function setup(sdk: Context) {
116 const getBridgedValue = async (token: Token, chain = 'bsc') => {
117 const tokenContract = sdk.ethers.getERC20Contract(token.address, chain);
118 const [supply, tokenHub, price] = await Promise.all([
119 tokenContract.totalSupply(),
120 tokenContract.balanceOf(TOKEN_HUB),
121 token.stablecoin ? Promise.resolve(1) : sdk.coinGecko.getCurrentPrice(token.coingeckoId),
122 ]);
123
124 const circSupply = (supply - tokenHub) / (10 ** (token.decimals || 18));
125 return circSupply * price;
126 }
127
128 const getBridgedAssets = async (chain: string) => {
129 const value = await Promise.all(tokens
130 .filter(token => token.originChain === chain)
131 .map(token => getBridgedValue(token))
132 );
133 return value.reduce((a, b) => a + b, 0);
134 }
135
136 const chains = new Set();
137
138 sdk.registerBundle('binance-peg', {
139 name: 'Binance-Peg',
140 icon: sdk.ipfs.getDataURILoader('QmYCfAzYWvHf1NBQodQedqGhs3QRZxCs1QeA4saneyTJgu', 'image/svg+xml'),
141 category: 'custodial',
142 website: 'https://www.bnbchain.org/en/assets-proof',
143 description: 'Binance-Pegged Tokens are assets issued by Binance to represent assets held '
144 + 'in Binance\s reserve. These assets must be depositted into a Binance account in order'
145 + 'to redeem for the underlying asset.',
146 });
147
148 for (const token of tokens) {
149 const chain = token.originChain;
150 if (!chains.has(chain)) {
151 chains.add(chain);
152
153 sdk.register({
154 id: `binance-peg-assets-${token.originChain}`,
155 bundle: 'binance-peg',
156 queries: {
157 currentValueBridgedAToB: async () => 0,
158 currentValueBridgedBToA: () => getBridgedAssets(chain),
159 },
160 metadata: {
161 name: 'Binance Pegged Assets',
162 subtitle: chain,
163 icon: sdk.ipfs.getDataURILoader('QmYCfAzYWvHf1NBQodQedqGhs3QRZxCs1QeA4saneyTJgu', 'image/svg+xml'),
164
165 chainA: 'bsc',
166 chainB: chain,
167 category: 'custodial',
168 }
169 });
170 }
171 }
172
173 sdk.register({
174 id: 'binance-peg-assets-eth-bbtc',
175 bundle: 'binance-peg',
176 queries: {
177 currentValueBridgedAToB: async () => 0,
178 currentValueBridgedBToA: () => getBridgedValue(bbtc, 'ethereum'),
179 },
180 metadata: {
181 name: 'Binance Pegged Assets',
182 subtitle: 'Bitcoin-Ethereum',
183 icon: sdk.ipfs.getDataURILoader('QmYCfAzYWvHf1NBQodQedqGhs3QRZxCs1QeA4saneyTJgu', 'image/svg+xml'),
184
185 chainA: 'ethereum',
186 chainB: 'bitcoin',
187 category: 'custodial',
188 },
189 });
190
191 // sdk.register({
192 // id: 'binance-peg-assets-eth-dot',
193 // bundle: 'binance-peg',
194 // queries: {
195 // currentValueBridgedAToB: async () => 0,
196 // currentValueBridgedBToA: () => getBridgedValue(dot, 'ethereum'),
197 // },
198 // metadata: {
199 // name: 'Binance Pegged Assets',
200 // subtitle: 'Polkadot-Ethereum',
201 // icon: sdk.ipfs.getDataURILoader('QmYCfAzYWvHf1NBQodQedqGhs3QRZxCs1QeA4saneyTJgu', 'image/svg+xml'),
202
203 // chainA: 'ethereum',
204 // chainB: 'polkadot',
205 // category: 'custodial',
206 // },
207 // });
208}
209
It's something off?
Report it to the discussion board on Discord, we will take care of it.