@uniswap/token-list-bridge-utils 1.0.8 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/chainId.d.ts +2 -1
- package/dist/constants/types.d.ts +6 -25
- package/dist/index.d.ts +2 -2
- package/dist/providers/ArbitrumMappingProvider.d.ts +2 -3
- package/dist/providers/MappingProvider.d.ts +2 -4
- package/dist/providers/OptimismMappingProvider.d.ts +2 -3
- package/dist/providers/index.d.ts +1 -1
- package/dist/token-list-bridge-utils.cjs.development.js +265 -136
- package/dist/token-list-bridge-utils.cjs.development.js.map +1 -1
- package/dist/token-list-bridge-utils.cjs.production.min.js +1 -1
- package/dist/token-list-bridge-utils.cjs.production.min.js.map +1 -1
- package/dist/token-list-bridge-utils.esm.js +265 -136
- package/dist/token-list-bridge-utils.esm.js.map +1 -1
- package/package.json +2 -1
- package/src/constants/chainId.ts +2 -0
- package/src/constants/types.ts +7 -25
- package/src/index.test.ts +3 -3
- package/src/index.ts +9 -15
- package/src/providers/ArbitrumMappingProvider.ts +2 -1
- package/src/providers/MappingProvider.ts +2 -2
- package/src/providers/OptimismMappingProvider.ts +2 -1
- package/src/providers/PolygonMappingProvider.ts +9 -15
- package/src/providers/index.ts +144 -60
- package/src/utils.ts +1 -1
|
@@ -1,30 +1,11 @@
|
|
|
1
1
|
export interface PolygonMappedToken {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
count: number;
|
|
6
|
-
created_at: string;
|
|
7
|
-
decimals: number;
|
|
8
|
-
deleted: boolean;
|
|
9
|
-
id: number;
|
|
10
|
-
map_type: 'POS';
|
|
11
|
-
mintable: boolean;
|
|
12
|
-
name: string;
|
|
13
|
-
new_child_token: string;
|
|
14
|
-
new_mintable: boolean;
|
|
15
|
-
owner: string;
|
|
16
|
-
reason: string;
|
|
17
|
-
reason_for_remapping: string;
|
|
18
|
-
remapping_allowed: boolean;
|
|
19
|
-
remapping_request_submitted: boolean;
|
|
20
|
-
remapping_verified: boolean;
|
|
21
|
-
root_token: string;
|
|
22
|
-
status: number;
|
|
23
|
-
symbol: string;
|
|
24
|
-
token_type: string;
|
|
25
|
-
updated_at: string;
|
|
26
|
-
uri: string;
|
|
2
|
+
rootToken: string;
|
|
3
|
+
childToken: string;
|
|
4
|
+
isPos?: boolean;
|
|
27
5
|
}
|
|
6
|
+
export declare type GenericMappedTokenData = {
|
|
7
|
+
[key: string]: string | undefined;
|
|
8
|
+
};
|
|
28
9
|
export declare type PolygonMappedTokenData = {
|
|
29
10
|
[key: string]: PolygonMappedToken;
|
|
30
11
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -9,10 +9,10 @@ import { TokenListOrFetchableTokenList } from './utils';
|
|
|
9
9
|
export declare function chainify(l1TokenListOrPathOrUrl: TokenListOrFetchableTokenList): Promise<TokenList>;
|
|
10
10
|
/**
|
|
11
11
|
* Given a network and a TokenList, returns the TokenList with `extensions` filled.
|
|
12
|
-
* @param
|
|
12
|
+
* @param l2ChainIds layer 2 chainIds to operate on
|
|
13
13
|
* @param l1TokenListOrPathOrUrl either an L1 TokenList object or a path/url to a TokenList
|
|
14
14
|
* @returns L1 TokenList with `extensions` filled for the given network
|
|
15
15
|
*/
|
|
16
|
-
export declare function chainifyTokenList(
|
|
16
|
+
export declare function chainifyTokenList(l2ChainIds: Array<ChainId>, l1TokenListOrPathOrUrl: TokenListOrFetchableTokenList): Promise<TokenList>;
|
|
17
17
|
/** Merges two token lists, resolving conflicts to primary list. */
|
|
18
18
|
export declare function mergeTokenLists(primary: TokenList, secondary: TokenList): TokenList;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { MappingProvider } from './MappingProvider';
|
|
2
2
|
import { TokenList } from '@uniswap/token-lists';
|
|
3
|
+
import { GenericMappedTokenData } from '../constants/types';
|
|
3
4
|
/**
|
|
4
5
|
* This provider provides the l1->l2(Arbitrum) address mappings using the arbitrum SDK.
|
|
5
6
|
*/
|
|
6
7
|
export declare class ArbitrumMappingProvider implements MappingProvider {
|
|
7
8
|
l1TokenList: TokenList;
|
|
8
9
|
constructor(l1TokenList: TokenList);
|
|
9
|
-
provide(): Promise<
|
|
10
|
-
[key: string]: string | undefined;
|
|
11
|
-
}>;
|
|
10
|
+
provide(): Promise<GenericMappedTokenData>;
|
|
12
11
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { PolygonMappedTokenData } from '../constants/types';
|
|
1
|
+
import { GenericMappedTokenData, PolygonMappedTokenData } from '../constants/types';
|
|
2
2
|
export interface MappingProvider {
|
|
3
|
-
provide(): Promise<PolygonMappedTokenData |
|
|
4
|
-
[key: string]: string | undefined;
|
|
5
|
-
}>;
|
|
3
|
+
provide(): Promise<PolygonMappedTokenData | GenericMappedTokenData>;
|
|
6
4
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { MappingProvider } from './MappingProvider';
|
|
2
|
+
import { GenericMappedTokenData } from '../constants/types';
|
|
2
3
|
/**
|
|
3
4
|
* The Optimism L2 mapping (linked above) is manually maintained by the Optimism team.
|
|
4
5
|
*
|
|
5
6
|
* This provider provides the l1->l2(Optimism) token mappings.
|
|
6
7
|
*/
|
|
7
8
|
export declare class OptimismMappingProvider implements MappingProvider {
|
|
8
|
-
provide(): Promise<
|
|
9
|
-
[key: string]: string | undefined;
|
|
10
|
-
}>;
|
|
9
|
+
provide(): Promise<GenericMappedTokenData>;
|
|
11
10
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ChainId } from '../constants/chainId';
|
|
2
2
|
import { TokenList } from '@uniswap/token-lists';
|
|
3
|
-
export declare function buildList(
|
|
3
|
+
export declare function buildList(l2ChainIds: Array<ChainId>, l1TokenList: TokenList): Promise<TokenList>;
|
|
@@ -896,6 +896,7 @@ var ChainId;
|
|
|
896
896
|
ChainId[ChainId["OPTIMISTIC_KOVAN"] = 69] = "OPTIMISTIC_KOVAN";
|
|
897
897
|
ChainId[ChainId["POLYGON"] = 137] = "POLYGON";
|
|
898
898
|
ChainId[ChainId["POLYGON_MUMBAI"] = 80001] = "POLYGON_MUMBAI";
|
|
899
|
+
ChainId[ChainId["CELO"] = 42220] = "CELO";
|
|
899
900
|
})(ChainId || (ChainId = {}));
|
|
900
901
|
|
|
901
902
|
function compareTokenInfos(t1, t2) {
|
|
@@ -1098,7 +1099,8 @@ function getRpcUrl(chainId) {
|
|
|
1098
1099
|
return 'https://cloudflare-eth.com/';
|
|
1099
1100
|
|
|
1100
1101
|
case ChainId.OPTIMISM:
|
|
1101
|
-
return 'https://
|
|
1102
|
+
return 'https://rpc.ankr.com/optimism';
|
|
1103
|
+
// seems to have higher rate limit than https://mainnet.optimism.io/
|
|
1102
1104
|
|
|
1103
1105
|
case ChainId.OPTIMISTIC_KOVAN:
|
|
1104
1106
|
return 'https://kovan.optimism.io';
|
|
@@ -1370,8 +1372,8 @@ var OptimismMappingProvider = /*#__PURE__*/function () {
|
|
|
1370
1372
|
return OptimismMappingProvider;
|
|
1371
1373
|
}();
|
|
1372
1374
|
|
|
1373
|
-
var url = 'https://
|
|
1374
|
-
var
|
|
1375
|
+
var url = 'https://open-api.polygon.technology/api/v1/info/all-mappings';
|
|
1376
|
+
var access_token = '504afd90-3228-4df9-9d88-9b4d70646101';
|
|
1375
1377
|
/**
|
|
1376
1378
|
* The Polygon team manually maintains the mapping via user submissions at
|
|
1377
1379
|
* https://mapper.polygon.technology.
|
|
@@ -1386,48 +1388,34 @@ var PolygonMappingProvider = /*#__PURE__*/function () {
|
|
|
1386
1388
|
|
|
1387
1389
|
_proto.provide = /*#__PURE__*/function () {
|
|
1388
1390
|
var _provide = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
1389
|
-
var
|
|
1391
|
+
var response, tokens, _iterator, _step, token;
|
|
1390
1392
|
|
|
1391
1393
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
1392
1394
|
while (1) {
|
|
1393
1395
|
switch (_context.prev = _context.next) {
|
|
1394
1396
|
case 0:
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
+
_context.next = 2;
|
|
1398
|
+
return axios__default["default"].get(url, {
|
|
1399
|
+
headers: {
|
|
1400
|
+
'x-access-token': access_token
|
|
1401
|
+
}
|
|
1402
|
+
});
|
|
1397
1403
|
|
|
1398
1404
|
case 2:
|
|
1399
|
-
|
|
1400
|
-
_context.next = 5;
|
|
1401
|
-
return axios__default["default"].get("" + url + params + offset);
|
|
1402
|
-
|
|
1403
|
-
case 5:
|
|
1404
1405
|
response = _context.sent;
|
|
1406
|
+
tokens = {};
|
|
1405
1407
|
|
|
1406
|
-
|
|
1407
|
-
_context.next = 11;
|
|
1408
|
-
break;
|
|
1409
|
-
}
|
|
1410
|
-
|
|
1411
|
-
for (_iterator = _createForOfIteratorHelperLoose(response.data.data.mapping); !(_step = _iterator()).done;) {
|
|
1408
|
+
for (_iterator = _createForOfIteratorHelperLoose(response.data); !(_step = _iterator()).done;) {
|
|
1412
1409
|
token = _step.value;
|
|
1413
|
-
tokens[token.root_token.toLowerCase()] = token;
|
|
1414
|
-
}
|
|
1415
1410
|
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1411
|
+
if (token.isPos) {
|
|
1412
|
+
tokens[token.rootToken.toLowerCase()] = token;
|
|
1413
|
+
}
|
|
1419
1414
|
}
|
|
1420
1415
|
|
|
1421
|
-
offset += 200;
|
|
1422
|
-
return _context.abrupt("continue", 2);
|
|
1423
|
-
|
|
1424
|
-
case 11:
|
|
1425
|
-
return _context.abrupt("break", 14);
|
|
1426
|
-
|
|
1427
|
-
case 14:
|
|
1428
1416
|
return _context.abrupt("return", tokens);
|
|
1429
1417
|
|
|
1430
|
-
case
|
|
1418
|
+
case 6:
|
|
1431
1419
|
case "end":
|
|
1432
1420
|
return _context.stop();
|
|
1433
1421
|
}
|
|
@@ -1614,103 +1602,139 @@ var abi = [{
|
|
|
1614
1602
|
type: 'event'
|
|
1615
1603
|
}];
|
|
1616
1604
|
|
|
1617
|
-
var web3 = /*#__PURE__*/new Web3__default["default"]();
|
|
1605
|
+
var web3 = /*#__PURE__*/new Web3__default["default"](); // chains we support fetching mappings for (can be different than the l2ChainIds arg for buildList)
|
|
1606
|
+
|
|
1607
|
+
var SUPPORTED_L2_CHAINS = [ChainId.ARBITRUM_ONE, ChainId.POLYGON, ChainId.OPTIMISM];
|
|
1618
1608
|
function buildList(_x, _x2) {
|
|
1619
1609
|
return _buildList.apply(this, arguments);
|
|
1620
1610
|
} // using a symbol lookup contract call to check whether the token exists on the L2
|
|
1621
1611
|
|
|
1622
1612
|
function _buildList() {
|
|
1623
|
-
_buildList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
1624
|
-
var
|
|
1613
|
+
_buildList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(l2ChainIds, l1TokenList) {
|
|
1614
|
+
var multiChainedTokens, chainIdToMappingsMap, _loop, _iterator, _step, tokenList;
|
|
1625
1615
|
|
|
1626
|
-
return _regeneratorRuntime.wrap(function
|
|
1616
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context3) {
|
|
1627
1617
|
while (1) {
|
|
1628
|
-
switch (
|
|
1618
|
+
switch (_context3.prev = _context3.next) {
|
|
1629
1619
|
case 0:
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
return
|
|
1620
|
+
multiChainedTokens = [];
|
|
1621
|
+
_context3.next = 3;
|
|
1622
|
+
return generateTokenMappings(l2ChainIds, l1TokenList);
|
|
1633
1623
|
|
|
1634
1624
|
case 3:
|
|
1635
|
-
|
|
1636
|
-
|
|
1625
|
+
chainIdToMappingsMap = _context3.sent;
|
|
1626
|
+
_loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
|
|
1627
|
+
var l1Token, chainIdToChildTokenDetailsMap, l2MappingExtension;
|
|
1628
|
+
return _regeneratorRuntime.wrap(function _loop$(_context2) {
|
|
1629
|
+
while (1) {
|
|
1630
|
+
switch (_context2.prev = _context2.next) {
|
|
1631
|
+
case 0:
|
|
1632
|
+
l1Token = _step.value;
|
|
1633
|
+
|
|
1634
|
+
if (!(l1Token.chainId === ChainId.MAINNET)) {
|
|
1635
|
+
_context2.next = 7;
|
|
1636
|
+
break;
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
chainIdToChildTokenDetailsMap = {};
|
|
1640
|
+
l2MappingExtension = {
|
|
1641
|
+
extensions: {
|
|
1642
|
+
bridgeInfo: {}
|
|
1643
|
+
}
|
|
1644
|
+
}; // build out the extensions.bridgeInfo data containing mappings for each L2 chain
|
|
1645
|
+
|
|
1646
|
+
_context2.next = 6;
|
|
1647
|
+
return Promise.all(l2ChainIds.map( /*#__PURE__*/function () {
|
|
1648
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(chainId) {
|
|
1649
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
1650
|
+
while (1) {
|
|
1651
|
+
switch (_context.prev = _context.next) {
|
|
1652
|
+
case 0:
|
|
1653
|
+
_context.next = 2;
|
|
1654
|
+
return getChildTokenDetails(l1Token, chainId, chainIdToMappingsMap);
|
|
1655
|
+
|
|
1656
|
+
case 2:
|
|
1657
|
+
chainIdToChildTokenDetailsMap[chainId] = _context.sent;
|
|
1658
|
+
|
|
1659
|
+
if (chainIdToChildTokenDetailsMap[chainId].childTokenValid) {
|
|
1660
|
+
l2MappingExtension.extensions.bridgeInfo[chainId] = {
|
|
1661
|
+
tokenAddress: chainIdToChildTokenDetailsMap[chainId].childTokenAddress
|
|
1662
|
+
};
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
case 4:
|
|
1666
|
+
case "end":
|
|
1667
|
+
return _context.stop();
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
}, _callee);
|
|
1671
|
+
}));
|
|
1672
|
+
|
|
1673
|
+
return function (_x10) {
|
|
1674
|
+
return _ref.apply(this, arguments);
|
|
1675
|
+
};
|
|
1676
|
+
}()));
|
|
1677
|
+
|
|
1678
|
+
case 6:
|
|
1679
|
+
// build the TokenInfo objects with bridgeInfo extension
|
|
1680
|
+
l2ChainIds.concat([ChainId.MAINNET]).forEach(function (chainId) {
|
|
1681
|
+
if (chainId === ChainId.MAINNET || chainIdToChildTokenDetailsMap[chainId].childTokenValid) {
|
|
1682
|
+
var _bridgeInfo;
|
|
1683
|
+
|
|
1684
|
+
var tokenInfo = chainId === ChainId.MAINNET ? _extends({}, l1Token, {
|
|
1685
|
+
extensions: Object.keys(l2MappingExtension.extensions.bridgeInfo).length > 0 ? {
|
|
1686
|
+
bridgeInfo: l2MappingExtension.extensions.bridgeInfo
|
|
1687
|
+
} : undefined
|
|
1688
|
+
}) : _extends({}, l1Token, {
|
|
1689
|
+
chainId: chainId,
|
|
1690
|
+
address: chainIdToChildTokenDetailsMap[chainId].childTokenAddress,
|
|
1691
|
+
extensions: {
|
|
1692
|
+
bridgeInfo: (_bridgeInfo = {}, _bridgeInfo[ChainId.MAINNET] = {
|
|
1693
|
+
tokenAddress: ethers.ethers.utils.getAddress(l1Token.address)
|
|
1694
|
+
}, _bridgeInfo)
|
|
1695
|
+
}
|
|
1696
|
+
});
|
|
1697
|
+
multiChainedTokens.push(tokenInfo);
|
|
1698
|
+
}
|
|
1699
|
+
});
|
|
1700
|
+
|
|
1701
|
+
case 7:
|
|
1702
|
+
case "end":
|
|
1703
|
+
return _context2.stop();
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
}, _loop);
|
|
1707
|
+
});
|
|
1637
1708
|
_iterator = _createForOfIteratorHelperLoose(l1TokenList.tokens);
|
|
1638
1709
|
|
|
1639
1710
|
case 6:
|
|
1640
1711
|
if ((_step = _iterator()).done) {
|
|
1641
|
-
|
|
1712
|
+
_context3.next = 10;
|
|
1642
1713
|
break;
|
|
1643
1714
|
}
|
|
1644
1715
|
|
|
1645
|
-
|
|
1646
|
-
childToken = tokenAddressMap[rootToken.address.toLowerCase()];
|
|
1647
|
-
childTokenAddress = childToken ? ethers.ethers.utils.getAddress(typeof childToken === 'object' ? childToken.child_token : childToken) : undefined;
|
|
1648
|
-
_context.t0 = Boolean;
|
|
1649
|
-
_context.t1 = childTokenAddress && (typeof childToken === 'object' ? !childToken.deleted : true);
|
|
1650
|
-
|
|
1651
|
-
if (!_context.t1) {
|
|
1652
|
-
_context.next = 16;
|
|
1653
|
-
break;
|
|
1654
|
-
}
|
|
1655
|
-
|
|
1656
|
-
_context.next = 15;
|
|
1657
|
-
return hasExistingTokenContract(childTokenAddress, chainId);
|
|
1658
|
-
|
|
1659
|
-
case 15:
|
|
1660
|
-
_context.t1 = _context.sent;
|
|
1661
|
-
|
|
1662
|
-
case 16:
|
|
1663
|
-
_context.t2 = _context.t1;
|
|
1664
|
-
childTokenValid = (0, _context.t0)(_context.t2);
|
|
1665
|
-
|
|
1666
|
-
if (rootToken.chainId === ChainId.MAINNET) {
|
|
1667
|
-
// build extension info if available
|
|
1668
|
-
toRootExtensions = childTokenValid ? {
|
|
1669
|
-
extensions: {
|
|
1670
|
-
bridgeInfo: (_bridgeInfo = {}, _bridgeInfo[rootToken.chainId] = {
|
|
1671
|
-
tokenAddress: ethers.ethers.utils.getAddress(rootToken.address)
|
|
1672
|
-
}, _bridgeInfo)
|
|
1673
|
-
}
|
|
1674
|
-
} : {};
|
|
1675
|
-
toChildExtensions = childTokenValid ? {
|
|
1676
|
-
extensions: {
|
|
1677
|
-
bridgeInfo: (_bridgeInfo2 = {}, _bridgeInfo2[chainId] = {
|
|
1678
|
-
tokenAddress: childTokenAddress
|
|
1679
|
-
}, _bridgeInfo2)
|
|
1680
|
-
}
|
|
1681
|
-
} : {};
|
|
1682
|
-
rootTokenInfo = _extends({}, rootToken, toChildExtensions);
|
|
1683
|
-
|
|
1684
|
-
if (childTokenValid) {
|
|
1685
|
-
childTokenInfo = _extends({}, rootToken, {
|
|
1686
|
-
chainId: chainId,
|
|
1687
|
-
address: childTokenAddress
|
|
1688
|
-
}, toRootExtensions);
|
|
1689
|
-
mappedTokens.push(childTokenInfo);
|
|
1690
|
-
}
|
|
1691
|
-
|
|
1692
|
-
mappedTokens.push(rootTokenInfo);
|
|
1693
|
-
}
|
|
1716
|
+
return _context3.delegateYield(_loop(), "t0", 8);
|
|
1694
1717
|
|
|
1695
|
-
case
|
|
1696
|
-
|
|
1718
|
+
case 8:
|
|
1719
|
+
_context3.next = 6;
|
|
1697
1720
|
break;
|
|
1698
1721
|
|
|
1699
|
-
case
|
|
1722
|
+
case 10:
|
|
1723
|
+
// build and return final chainified token list
|
|
1700
1724
|
tokenList = {
|
|
1701
|
-
name: "(
|
|
1725
|
+
name: "(ChainIds: " + l2ChainIds + ") " + l1TokenList.name,
|
|
1702
1726
|
timestamp: new Date().toISOString(),
|
|
1703
1727
|
version: l1TokenList.version,
|
|
1704
|
-
tokens:
|
|
1728
|
+
tokens: multiChainedTokens.sort(compareTokenInfos)
|
|
1705
1729
|
};
|
|
1706
|
-
return
|
|
1730
|
+
return _context3.abrupt("return", tokenList);
|
|
1707
1731
|
|
|
1708
|
-
case
|
|
1732
|
+
case 12:
|
|
1709
1733
|
case "end":
|
|
1710
|
-
return
|
|
1734
|
+
return _context3.stop();
|
|
1711
1735
|
}
|
|
1712
1736
|
}
|
|
1713
|
-
},
|
|
1737
|
+
}, _callee2);
|
|
1714
1738
|
}));
|
|
1715
1739
|
return _buildList.apply(this, arguments);
|
|
1716
1740
|
}
|
|
@@ -1720,35 +1744,36 @@ function hasExistingTokenContract(_x3, _x4) {
|
|
|
1720
1744
|
}
|
|
1721
1745
|
|
|
1722
1746
|
function _hasExistingTokenContract() {
|
|
1723
|
-
_hasExistingTokenContract = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
1747
|
+
_hasExistingTokenContract = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(address, chainId) {
|
|
1724
1748
|
var contract;
|
|
1725
|
-
return _regeneratorRuntime.wrap(function
|
|
1749
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context4) {
|
|
1726
1750
|
while (1) {
|
|
1727
|
-
switch (
|
|
1751
|
+
switch (_context4.prev = _context4.next) {
|
|
1728
1752
|
case 0:
|
|
1729
|
-
|
|
1753
|
+
web3.setProvider(getRpcUrl(chainId));
|
|
1754
|
+
_context4.prev = 1;
|
|
1730
1755
|
contract = new web3.eth.Contract(abi, address);
|
|
1731
|
-
|
|
1756
|
+
_context4.next = 5;
|
|
1732
1757
|
return getTokenSymbolFromContract(contract);
|
|
1733
1758
|
|
|
1734
|
-
case
|
|
1735
|
-
|
|
1759
|
+
case 5:
|
|
1760
|
+
_context4.next = 10;
|
|
1736
1761
|
break;
|
|
1737
1762
|
|
|
1738
|
-
case
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
return
|
|
1742
|
-
|
|
1743
|
-
case 9:
|
|
1744
|
-
return _context2.abrupt("return", true);
|
|
1763
|
+
case 7:
|
|
1764
|
+
_context4.prev = 7;
|
|
1765
|
+
_context4.t0 = _context4["catch"](1);
|
|
1766
|
+
return _context4.abrupt("return", false);
|
|
1745
1767
|
|
|
1746
1768
|
case 10:
|
|
1769
|
+
return _context4.abrupt("return", true);
|
|
1770
|
+
|
|
1771
|
+
case 11:
|
|
1747
1772
|
case "end":
|
|
1748
|
-
return
|
|
1773
|
+
return _context4.stop();
|
|
1749
1774
|
}
|
|
1750
1775
|
}
|
|
1751
|
-
},
|
|
1776
|
+
}, _callee3, null, [[1, 7]]);
|
|
1752
1777
|
}));
|
|
1753
1778
|
return _hasExistingTokenContract.apply(this, arguments);
|
|
1754
1779
|
}
|
|
@@ -1765,10 +1790,123 @@ function getMappingProvider(chainId, l1TokenList) {
|
|
|
1765
1790
|
return new PolygonMappingProvider();
|
|
1766
1791
|
|
|
1767
1792
|
default:
|
|
1768
|
-
throw new Error("Chain " + chainId + " not supported.");
|
|
1793
|
+
throw new Error("Chain " + chainId + " not supported for fetching mappings.");
|
|
1769
1794
|
}
|
|
1770
1795
|
}
|
|
1771
1796
|
|
|
1797
|
+
function generateTokenMappings(_x5, _x6) {
|
|
1798
|
+
return _generateTokenMappings.apply(this, arguments);
|
|
1799
|
+
} // handles both string and object cases for childToken (Polygon mappings return object)
|
|
1800
|
+
|
|
1801
|
+
|
|
1802
|
+
function _generateTokenMappings() {
|
|
1803
|
+
_generateTokenMappings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(chainIds, l1TokenList) {
|
|
1804
|
+
var chainIdToMappingsMap, _iterator2, _step2, chainId;
|
|
1805
|
+
|
|
1806
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context5) {
|
|
1807
|
+
while (1) {
|
|
1808
|
+
switch (_context5.prev = _context5.next) {
|
|
1809
|
+
case 0:
|
|
1810
|
+
chainIdToMappingsMap = {};
|
|
1811
|
+
_iterator2 = _createForOfIteratorHelperLoose(chainIds);
|
|
1812
|
+
|
|
1813
|
+
case 2:
|
|
1814
|
+
if ((_step2 = _iterator2()).done) {
|
|
1815
|
+
_context5.next = 10;
|
|
1816
|
+
break;
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
chainId = _step2.value;
|
|
1820
|
+
|
|
1821
|
+
if (!SUPPORTED_L2_CHAINS.includes(chainId)) {
|
|
1822
|
+
_context5.next = 8;
|
|
1823
|
+
break;
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
_context5.next = 7;
|
|
1827
|
+
return getMappingProvider(chainId, l1TokenList).provide();
|
|
1828
|
+
|
|
1829
|
+
case 7:
|
|
1830
|
+
chainIdToMappingsMap[chainId] = _context5.sent;
|
|
1831
|
+
|
|
1832
|
+
case 8:
|
|
1833
|
+
_context5.next = 2;
|
|
1834
|
+
break;
|
|
1835
|
+
|
|
1836
|
+
case 10:
|
|
1837
|
+
return _context5.abrupt("return", chainIdToMappingsMap);
|
|
1838
|
+
|
|
1839
|
+
case 11:
|
|
1840
|
+
case "end":
|
|
1841
|
+
return _context5.stop();
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
}, _callee4);
|
|
1845
|
+
}));
|
|
1846
|
+
return _generateTokenMappings.apply(this, arguments);
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
function getChildTokenDetails(_x7, _x8, _x9) {
|
|
1850
|
+
return _getChildTokenDetails.apply(this, arguments);
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
function _getChildTokenDetails() {
|
|
1854
|
+
_getChildTokenDetails = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(l1Token, chainId, chainIdToMappingsMap) {
|
|
1855
|
+
var _l1Token$extensions, _l1Token$extensions$b, _l1Token$extensions$b2;
|
|
1856
|
+
|
|
1857
|
+
var existingMapping, childToken, childTokenAddress, childTokenValid;
|
|
1858
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context6) {
|
|
1859
|
+
while (1) {
|
|
1860
|
+
switch (_context6.prev = _context6.next) {
|
|
1861
|
+
case 0:
|
|
1862
|
+
existingMapping = l1Token == null ? void 0 : (_l1Token$extensions = l1Token.extensions) == null ? void 0 : (_l1Token$extensions$b = _l1Token$extensions.bridgeInfo) == null ? void 0 : (_l1Token$extensions$b2 = _l1Token$extensions$b[chainId]) == null ? void 0 : _l1Token$extensions$b2.tokenAddress; // use the externally fetched mappings if manual entry doesn't exist for the token/chain mapping
|
|
1863
|
+
// and the given L2 chain is supported for fetching mappings
|
|
1864
|
+
|
|
1865
|
+
if (!(SUPPORTED_L2_CHAINS.includes(chainId) && existingMapping === undefined)) {
|
|
1866
|
+
_context6.next = 13;
|
|
1867
|
+
break;
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
childToken = chainIdToMappingsMap[chainId][l1Token.address.toLowerCase()];
|
|
1871
|
+
childTokenAddress = childToken ? ethers.ethers.utils.getAddress(typeof childToken === 'object' ? childToken.childToken : childToken) : undefined;
|
|
1872
|
+
_context6.t0 = Boolean;
|
|
1873
|
+
_context6.t1 = childTokenAddress;
|
|
1874
|
+
|
|
1875
|
+
if (!_context6.t1) {
|
|
1876
|
+
_context6.next = 10;
|
|
1877
|
+
break;
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
_context6.next = 9;
|
|
1881
|
+
return hasExistingTokenContract(childTokenAddress, chainId);
|
|
1882
|
+
|
|
1883
|
+
case 9:
|
|
1884
|
+
_context6.t1 = _context6.sent;
|
|
1885
|
+
|
|
1886
|
+
case 10:
|
|
1887
|
+
_context6.t2 = _context6.t1;
|
|
1888
|
+
childTokenValid = (0, _context6.t0)(_context6.t2);
|
|
1889
|
+
return _context6.abrupt("return", {
|
|
1890
|
+
childTokenValid: childTokenValid,
|
|
1891
|
+
childTokenAddress: childTokenAddress
|
|
1892
|
+
});
|
|
1893
|
+
|
|
1894
|
+
case 13:
|
|
1895
|
+
return _context6.abrupt("return", {
|
|
1896
|
+
childTokenValid: !!existingMapping,
|
|
1897
|
+
childTokenAddress: existingMapping
|
|
1898
|
+
});
|
|
1899
|
+
|
|
1900
|
+
case 14:
|
|
1901
|
+
case "end":
|
|
1902
|
+
return _context6.stop();
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
}, _callee5);
|
|
1906
|
+
}));
|
|
1907
|
+
return _getChildTokenDetails.apply(this, arguments);
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1772
1910
|
/**
|
|
1773
1911
|
* Verifies that for each token with extensions.bridgeInfo defined, for every
|
|
1774
1912
|
* chainId there exists a token with that chainId at the root-level of the
|
|
@@ -1842,14 +1980,14 @@ function chainify(_x) {
|
|
|
1842
1980
|
}
|
|
1843
1981
|
/**
|
|
1844
1982
|
* Given a network and a TokenList, returns the TokenList with `extensions` filled.
|
|
1845
|
-
* @param
|
|
1983
|
+
* @param l2ChainIds layer 2 chainIds to operate on
|
|
1846
1984
|
* @param l1TokenListOrPathOrUrl either an L1 TokenList object or a path/url to a TokenList
|
|
1847
1985
|
* @returns L1 TokenList with `extensions` filled for the given network
|
|
1848
1986
|
*/
|
|
1849
1987
|
|
|
1850
1988
|
function _chainify() {
|
|
1851
1989
|
_chainify = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenListOrPathOrUrl) {
|
|
1852
|
-
var l1TokenList,
|
|
1990
|
+
var l1TokenList, l2Chains, chainified;
|
|
1853
1991
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
1854
1992
|
while (1) {
|
|
1855
1993
|
switch (_context.prev = _context.next) {
|
|
@@ -1859,25 +1997,16 @@ function _chainify() {
|
|
|
1859
1997
|
|
|
1860
1998
|
case 2:
|
|
1861
1999
|
l1TokenList = _context.sent;
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
case 5:
|
|
1866
|
-
optimisimed = _context.sent;
|
|
1867
|
-
_context.next = 8;
|
|
1868
|
-
return chainifyTokenList(ChainId.POLYGON, l1TokenListOrPathOrUrl);
|
|
1869
|
-
|
|
1870
|
-
case 8:
|
|
1871
|
-
polygoned = _context.sent;
|
|
1872
|
-
_context.next = 11;
|
|
1873
|
-
return chainifyTokenList(ChainId.ARBITRUM_ONE, l1TokenListOrPathOrUrl);
|
|
2000
|
+
l2Chains = [ChainId.POLYGON, ChainId.ARBITRUM_ONE, ChainId.OPTIMISM, ChainId.CELO];
|
|
2001
|
+
_context.next = 6;
|
|
2002
|
+
return chainifyTokenList(l2Chains, l1TokenListOrPathOrUrl);
|
|
1874
2003
|
|
|
1875
|
-
case
|
|
1876
|
-
|
|
2004
|
+
case 6:
|
|
2005
|
+
chainified = _context.sent;
|
|
1877
2006
|
return _context.abrupt("return", mergeTokenLists(l1TokenList, // providing l1 first to make sure duplicated tokens resolve to this list
|
|
1878
|
-
|
|
2007
|
+
chainified));
|
|
1879
2008
|
|
|
1880
|
-
case
|
|
2009
|
+
case 8:
|
|
1881
2010
|
case "end":
|
|
1882
2011
|
return _context.stop();
|
|
1883
2012
|
}
|
|
@@ -1893,7 +2022,7 @@ function chainifyTokenList(_x2, _x3) {
|
|
|
1893
2022
|
/** Merges two token lists, resolving conflicts to primary list. */
|
|
1894
2023
|
|
|
1895
2024
|
function _chainifyTokenList() {
|
|
1896
|
-
_chainifyTokenList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(
|
|
2025
|
+
_chainifyTokenList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(l2ChainIds, l1TokenListOrPathOrUrl) {
|
|
1897
2026
|
var l1TokenList, tokenList;
|
|
1898
2027
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
1899
2028
|
while (1) {
|
|
@@ -1906,7 +2035,7 @@ function _chainifyTokenList() {
|
|
|
1906
2035
|
case 3:
|
|
1907
2036
|
l1TokenList = _context2.sent;
|
|
1908
2037
|
_context2.next = 6;
|
|
1909
|
-
return buildList(
|
|
2038
|
+
return buildList(l2ChainIds, l1TokenList);
|
|
1910
2039
|
|
|
1911
2040
|
case 6:
|
|
1912
2041
|
tokenList = _context2.sent;
|