Sub-Adapters 8
Preview and test each sub adapter.
Ren Bitcoin-Ethereum (ren-bitcoin-ethereum)
Ren Bitcoin-Solana (ren-bitcoin-solana)
Ren Bitcoin-BSC (ren-bitcoin-bsc)
Ren Bitcoin-Avalanche (ren-bitcoin-avalanche)
Ren Bitcoin-Fantom (ren-bitcoin-fantom)
Ren Bitcoin-Optimism (ren-bitcoin-optimism)
Ren Bitcoin-Arbitrum One (ren-bitcoin-arbitrum-one)
Ren Bitcoin-Polygon (ren-bitcoin-polygon)
Adapter Code
Check the entire code written for the Adapter.
Source code
Showing TS source.
1export const name = 'Ren Bridged Assets';
2export const version = '0.0.3';
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: 'btc',
21 nativeChain: 'bitcoin',
22 coingeckoId: 'bitcoin',
23 wrappersByChain: {
24 ethereum: {
25 address: '0xEB4C2781e4ebA804CE9a9803C67d0893436bB27D',
26 decimals: 8,
27 },
28 bsc: {
29 address: '0xfCe146bF3146100cfe5dB4129cf6C82b0eF4Ad8c',
30 decimals: 8,
31 },
32 fantom: {
33 address: '0xDBf31dF14B66535aF65AaC99C32e9eA844e14501',
34 decimals: 8,
35 },
36 avalanche: {
37 address: '0xDBf31dF14B66535aF65AaC99C32e9eA844e14501',
38 decimals: 8,
39 },
40 'arbitrum-one': {
41 address: '0xDBf31dF14B66535aF65AaC99C32e9eA844e14501',
42 decimals: 8,
43 },
44 optimism: {
45 address: '0x85f6583762Bc76d775eAB9A7456db344f12409F7',
46 decimals: 8,
47 },
48 polygon: {
49 address: '0xDBf31dF14B66535aF65AaC99C32e9eA844e14501',
50 decimals: 8,
51 },
52 solana: {
53 address: 'CDJWUqTcYTVAKXAVXoQZFes5JUFc7owSeq7eMQcDSbo5',
54 decimals: 8,
55 },
56 // acala: {
57 // address: '0x0000000000000000000100000000000000000014',
58 // decimals: 12,
59 // },
60 },
61 },
62];
63
64const chains: Chain[] = [
65 {
66 id: 'bitcoin',
67 name: 'Bitcoin',
68 },
69 {
70 id: 'ethereum',
71 name: 'Ethereum',
72 },
73 {
74 id: 'solana',
75 name: 'Solana',
76 },
77 {
78 id: 'bsc',
79 name: 'BSC',
80 },
81 {
82 id: 'avalanche',
83 name: 'Avalanche',
84 },
85 {
86 id: 'fantom',
87 name: 'Fantom',
88 },
89 {
90 id: 'optimism',
91 name: 'Optimism',
92 },
93 {
94 id: 'arbitrum-one',
95 name: 'Arbitrum One',
96 },
97 {
98 id: 'polygon',
99 name: 'Polygon',
100 },
101 // {
102 // id: 'acala',
103 // name: 'Acala',
104 // },
105]
106
107export function setup(sdk: Context) {
108 sdk.ethers.addProvider('avalanche', 'https://api.avax.network/ext/bc/C/rpc');
109 sdk.ethers.addProvider('fantom', 'https://rpc.ankr.com/fantom/');
110
111 const getEVMSupply = (chain: string) => async (addr: string) => {
112 const supply = await sdk.ethers.getERC20Contract(addr, chain).totalSupply();
113 return parseInt(supply.toString());
114 }
115
116 const getSolanaTokenSupply = async (addr: string) => {
117 const data = await sdk.http.post('https://api.mainnet-beta.solana.com', {
118 jsonrpc: "2.0",
119 id: 1,
120 method: "getTokenSupply",
121 params: [addr],
122 });
123 return parseInt(data.result.value.amount);
124 }
125
126 const getSupply: { [chain: string]: (addr: string) => Promise<number> } = {
127 ethereum: getEVMSupply('ethereum'),
128 bsc: getEVMSupply('bsc'),
129 avalanche: getEVMSupply('avalanche'),
130 fantom: getEVMSupply('fantom'),
131 optimism: getEVMSupply('optimism'),
132 'arbitrum-one': getEVMSupply('arbitrum-one'),
133 polygon: getEVMSupply('polygon'),
134 solana: getSolanaTokenSupply,
135 }
136
137 const getBridged = async (chainA: string, chainB: string) => {
138 let total = 0;
139 for (const asset of assets) {
140 if (asset.nativeChain === chainA && asset.wrappersByChain[chainB]) {
141 const [wrapperSupply, price] = await Promise.all([
142 getSupply[chainB](asset.wrappersByChain[chainB].address),
143 asset.stablecoin ? Promise.resolve(1) : sdk.coinGecko.getCurrentPrice(asset.coingeckoId),
144 ]);
145 const wrapperSupplyDecimal = wrapperSupply / (10 ** asset.wrappersByChain[chainB].decimals);
146 const bridgedValue = wrapperSupplyDecimal * price;
147 total += bridgedValue;
148 }
149 }
150 return total;
151 }
152
153 sdk.registerBundle('ren', {
154 name: 'Ren',
155 icon: sdk.ipfs.getDataURILoader('QmQnRxS7jjLXVPcUJNtkidddynYiZQ4t9UpGMaAFuKbK4H', 'image/svg+xml'),
156 category: 'unknown',
157 });
158
159 // Bitcoin is the only substantial asset bridged, so skip the rest
160 for (let i = 0; i < /*chains.length*/1; i += 1) {
161 for (let j = i + 1; j < chains.length; j += 1) {
162 const chainA = chains[i];
163 const chainB = chains[j];
164
165 sdk.register({
166 id: `ren-${chainA.id}-${chainB.id}`,
167 bundle: 'ren',
168 queries: {
169 currentValueBridgedAToB: () => getBridged(chainA.id, chainB.id),
170 currentValueBridgedBToA: () => getBridged(chainB.id, chainA.id),
171 },
172 metadata: {
173 name: `Ren ${chainA.name}-${chainB.name}`,
174 icon: sdk.ipfs.getDataURILoader('QmQnRxS7jjLXVPcUJNtkidddynYiZQ4t9UpGMaAFuKbK4H', 'image/svg+xml'),
175 chainA: chainA.id,
176 chainB: chainB.id,
177 },
178 })
179 }
180 }
181}
182
It's something off?
Report it to the discussion board on Discord, we will take care of it.