Sub-Adapters 1
Preview and test each sub adapter.
Polygon (polygon)
Metadata
- ID
- polygon
- name
"Polygon"
- icon
- chainA
"ethereum"
- chainB
"polygon"
- category
"multisig"
Queries
Adapter Code
Check the entire code written for the Adapter.
Source code
Showing TS source.
1export const name = 'Polygon Bridge';
2export const version = '0.0.2';
3export const license = 'MIT';
4
5const ETHER_BRIDGE = '0x8484Ef722627bf18ca5Ae6BcF031c23E6e922B30'
6const ERC_20_BRIDGE = '0x40ec5b33f54e0e8a33a975908c5ba1c14e5bbbdf'
7const MATIC_BRIDGE = '0x401F6c983eA34274ec46f84D70b31C151321188b'
8const MATIC_TOKEN = '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0'
9
10interface Token {
11 id: string
12 address: string
13 stablecoin?: boolean
14 coingeckoId?: string
15 decimals?: number
16}
17
18const tokens: Token[] = [
19 {
20 id: 'USDC',
21 address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
22 stablecoin: true,
23 decimals: 6,
24 },
25 {
26 id: 'USDT',
27 address: '0xdac17f958d2ee523a2206206994597c13d831ec7',
28 stablecoin: true,
29 decimals: 6,
30 },
31 {
32 id: 'Dai',
33 address: '0x6b175474e89094c44da98b954eedeac495271d0f',
34 stablecoin: true,
35 },
36 {
37 id: 'aavegochi',
38 address: '0x3F382DbD960E3a9bbCeaE22651E88158d2791550',
39 coingeckoId: 'aavegotchi',
40 },
41]
42
43export function setup(sdk: Context) {
44 const getDepositted = async () => {
45 const [
46 ethDepositted,
47 ethPrice,
48 maticDepositted,
49 maticPrice,
50 otherValues,
51 ] = await Promise.all([
52 sdk.ethers.getProvider('ethereum').getBalance(ETHER_BRIDGE),
53 sdk.coinGecko.getCurrentPrice('ethereum'),
54
55 sdk.ethers.getERC20Contract(MATIC_TOKEN).balanceOf(MATIC_BRIDGE),
56 sdk.coinGecko.getCurrentPrice('matic-network'),
57
58 Promise.all(tokens.map(async (token) => {
59 const [bridged, price] = await Promise.all([
60 sdk.ethers.getERC20Contract(token.address).balanceOf(ERC_20_BRIDGE),
61 token.stablecoin ? Promise.resolve(1) : sdk.defiLlama.getCurrentPrice('coingecko', token.coingeckoId),
62 ]);
63
64 const bridgedDecimal = bridged.toString() / (10 ** (token.decimals || 18));
65 return bridgedDecimal * price;
66 })),
67 ]);
68
69 const ethValue = ethDepositted.toString() / 1e18 * ethPrice;
70 const maticValue = maticDepositted.toString() / 1e18 * maticPrice;
71 const otherValue = otherValues.reduce((a, b) => a + b, 0);
72 return ethValue + otherValue + maticValue;
73 }
74
75 const getReverse = async () => {
76 return 0;
77 }
78
79 sdk.registerBundle('polygon', {
80 name: 'Polygon',
81 icon: sdk.ipfs.getDataURILoader('QmcakfgwRpoXotCQdBc8fos31X4p9ujvJBuigSh9C59cKS', 'image/svg+xml'),
82 category: 'light-client',
83 });
84
85 sdk.register({
86 id: 'polygon',
87 bundle: 'polygon',
88 queries: {
89 currentValueBridgedAToB: getDepositted,
90 currentValueBridgedBToA: getReverse,
91 },
92 metadata: {
93 name: 'Polygon',
94 icon: sdk.ipfs.getDataURILoader('QmcakfgwRpoXotCQdBc8fos31X4p9ujvJBuigSh9C59cKS', 'image/svg+xml'),
95
96 chainA: 'ethereum',
97 chainB: 'polygon',
98 category: 'multisig',
99 },
100 });
101}
102
It's something off?
Report it to the discussion board on Discord, we will take care of it.