@shapeshiftoss/caip 2.5.0 → 2.5.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/README.md CHANGED
@@ -4,37 +4,37 @@ This package is ShapeShift's partial implementation of [CAIPs](https://github.co
4
4
 
5
5
  It is not exhaustive and is currently only used internally.
6
6
 
7
- ## CAIP-2 - Blockchain ID Specification
7
+ ## ChainId - Blockchain ID Specification
8
8
 
9
9
  https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md
10
10
 
11
11
  Usage
12
12
 
13
- ### `toCAIP2`
13
+ ### `toChainId`
14
14
 
15
15
  ```ts
16
16
  const chain = ChainTypes.Ethereum
17
17
  const network = NetworkTypes.MAINNET
18
- const result = toCAIP2({ chain, network })
18
+ const result = toChainId({ chain, network })
19
19
  expect(result).toEqual('eip155:1')
20
20
  ```
21
21
 
22
- ### `fromCAIP2`
22
+ ### `fromChainId`
23
23
 
24
24
  ```ts
25
- const ethCaip2 = 'eip155:1'
26
- const { chain, network } = fromCAIP2(ethCaip2)
25
+ const ethChainId = 'eip155:1'
26
+ const { chain, network } = fromChainId(ethChainId)
27
27
  expect(chain).toEqual(ChainTypes.Ethereum)
28
28
  expect(network).toEqual(NetworkTypes.MAINNET)
29
29
  ```
30
30
 
31
- ## CAIP-19 - Asset Type and Asset ID Specification
31
+ ## AssetId - Asset Type and Asset ID Specification
32
32
 
33
33
  https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-19.md
34
34
 
35
35
  Usage
36
36
 
37
- ### `toCAIP19`
37
+ ### `toAssetId`
38
38
 
39
39
  Ether
40
40
 
@@ -43,7 +43,7 @@ const chain = ChainTypes.Ethereum
43
43
  const network = NetworkTypes.MAINNET
44
44
  const assetNamespace = AssetNamespace.Slip44
45
45
  const assetReference = AssetReference.Ethereum
46
- const result = toCAIP19({ chain, network, assetNamespace, assetReference })
46
+ const result = toAssetId({ chain, network, assetNamespace, assetReference })
47
47
  expect(result).toEqual('eip155:1/slip44:60')
48
48
  ```
49
49
 
@@ -54,17 +54,17 @@ const chain = ChainTypes.Ethereum
54
54
  const network = NetworkTypes.MAINNET
55
55
  const contractType = AssetNamespace.ERC20
56
56
  const tokenId = '0xc770eefad204b5180df6a14ee197d99d808ee52d'
57
- const result = toCAIP19({ chain, network, contractType, tokenId })
57
+ const result = toAssetId({ chain, network, contractType, tokenId })
58
58
  expect(result).toEqual('eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d')
59
59
  ```
60
60
 
61
- ### `fromCAIP19`
61
+ ### `fromAssetId`
62
62
 
63
63
  Ether
64
64
 
65
65
  ```ts
66
- const caip19 = 'eip155:1/slip44:60'
67
- const { chain, network, contractType, tokenId } = fromCAIP19(caip19)
66
+ const assetId = 'eip155:1/slip44:60'
67
+ const { chain, network, contractType, tokenId } = fromAssetId(assetId)
68
68
  expect(chain).toEqual(ChainTypes.Ethereum)
69
69
  expect(network).toEqual(NetworkTypes.MAINNET)
70
70
  expect(contractType).toEqual(AssetNamespace.Slip44)
@@ -74,8 +74,8 @@ expect(tokenId).toEqual(AssetReference.Ethereum)
74
74
  ERC20 token
75
75
 
76
76
  ```ts
77
- const caip19 = 'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d'
78
- const { chain, network, contractType, tokenId } = fromCAIP19(caip19)
77
+ const assetId = 'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d'
78
+ const { chain, network, contractType, tokenId } = fromAssetId(assetId)
79
79
  expect(chain).toEqual(ChainTypes.Ethereum)
80
80
  expect(network).toEqual(NetworkTypes.MAINNET)
81
81
  expect(contractType).toEqual(AssetNamespace.ERC20)
@@ -84,9 +84,9 @@ expect(tokenId).toEqual('0xc770eefad204b5180df6a14ee197d99d808ee52d')
84
84
 
85
85
  ## Adapters
86
86
 
87
- Adapters map CAIP-19 asset ids and map them to vendor-specific (e.g. CoinGecko) IDs.
87
+ Adapters map asset IDs and map them to vendor-specific (e.g. CoinGecko) IDs.
88
88
 
89
- This allows us to use CAIP-19 IDs internally and keep any vendor IDs at the boundary.
89
+ This allows us to use asset IDs internally and keep any vendor IDs at the boundary.
90
90
 
91
91
  ### Generate
92
92
 
@@ -102,11 +102,11 @@ and commit the generated `adapter.json` files.
102
102
  ### Usage
103
103
 
104
104
  ```ts
105
- console.log(coingeckoToCAIP19('shapeshift-fox-token'))
105
+ console.log(coingeckoToAssetId('shapeshift-fox-token'))
106
106
 
107
107
  eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d
108
108
 
109
- console.log(CAIP19ToCoingecko('bip122:000000000019d6689c085ae165831e93/slip44:0'))
109
+ console.log(assetIdToCoingecko('bip122:000000000019d6689c085ae165831e93/slip44:0'))
110
110
 
111
111
  bitcoin
112
112
  ```
@@ -0,0 +1,15 @@
1
+ import { ChainId } from '../chainId/chainId';
2
+ export declare type AccountId = string;
3
+ declare type ToAccountIdArgs = {
4
+ chainId: ChainId;
5
+ account: string;
6
+ };
7
+ declare type ToAccountId = (args: ToAccountIdArgs) => string;
8
+ export declare const toAccountId: ToAccountId;
9
+ declare type FromAccountIdReturn = {
10
+ chainId: string;
11
+ account: string;
12
+ };
13
+ declare type FromAccountId = (accountId: string) => FromAccountIdReturn;
14
+ export declare const fromAccountId: FromAccountId;
15
+ export {};
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fromAccountId = exports.toAccountId = void 0;
4
+ const chainId_1 = require("../chainId/chainId");
5
+ const toAccountId = ({ chainId, account }) => {
6
+ if (!(0, chainId_1.isChainId)(chainId)) {
7
+ throw new Error(`toAccountId: invalid ChainId ${chainId}`);
8
+ }
9
+ if (!account) {
10
+ throw new Error(`toAccountId: account is required`);
11
+ }
12
+ const [namespace] = chainId.split(':');
13
+ // we lowercase eth accounts as per the draft spec
14
+ // it's not explicit, but cHecKsUM can be recovered from lowercase eth accounts
15
+ // we don't lowercase bitcoin addresses as they'll fail checksum
16
+ const outputAccount = namespace === chainId_1.ChainNamespace.Ethereum ? account.toLowerCase() : account;
17
+ return `${chainId}:${outputAccount}`;
18
+ };
19
+ exports.toAccountId = toAccountId;
20
+ const fromAccountId = (accountId) => {
21
+ const parts = accountId.split(':');
22
+ if (parts.length !== 3) {
23
+ throw new Error(`fromAccountId: invalid AccountId ${accountId}`);
24
+ }
25
+ const chainId = parts.slice(0, 2).join(':');
26
+ if (!(0, chainId_1.isChainId)(chainId)) {
27
+ throw new Error(`fromAccountId: invalid ChainId ${chainId}`);
28
+ }
29
+ const account = parts[2];
30
+ if (!account) {
31
+ throw new Error(`fromAccountId: account required`);
32
+ }
33
+ const [namespace] = chainId.split(':');
34
+ // we lowercase eth accounts as per the draft spec
35
+ // it's not explicit, but cHecKsUM can be recovered from lowercase eth accounts
36
+ // we don't lowercase bitcoin addresses as they'll fail checksum
37
+ const outputAccount = namespace === chainId_1.ChainNamespace.Ethereum ? account.toLowerCase() : account;
38
+ return { chainId, account: outputAccount };
39
+ };
40
+ exports.fromAccountId = fromAccountId;
@@ -1,7 +1,7 @@
1
- export declare const banxaTickerToCAIP19: (id: string) => string | undefined;
2
- export declare const CAIP19ToBanxaTicker: (caip19: string) => string | undefined;
1
+ export declare const banxaTickerToAssetId: (id: string) => string | undefined;
2
+ export declare const AssetIdToBanxaTicker: (assetId: string) => string | undefined;
3
3
  export declare const getSupportedBanxaAssets: () => {
4
- CAIP19: string;
4
+ assetId: string;
5
5
  ticker: string;
6
6
  }[];
7
7
  /**
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getBanxaBlockchainFromBanxaAssetTicker = exports.getSupportedBanxaAssets = exports.CAIP19ToBanxaTicker = exports.banxaTickerToCAIP19 = void 0;
6
+ exports.getBanxaBlockchainFromBanxaAssetTicker = exports.getSupportedBanxaAssets = exports.AssetIdToBanxaTicker = exports.banxaTickerToAssetId = void 0;
7
7
  const entries_1 = __importDefault(require("lodash/entries"));
8
8
  const toLower_1 = __importDefault(require("lodash/toLower"));
9
- const caip2_1 = require("../../caip2/caip2");
10
- const caip19_1 = require("../../caip19/caip19");
11
- const CAIP19ToBanxaTickerMap = {
9
+ const assetId_1 = require("../../assetId/assetId");
10
+ const chainId_1 = require("../../chainId/chainId");
11
+ const AssetIdToBanxaTickerMap = {
12
12
  'bip122:000000000019d6689c085ae165831e93/slip44:0': 'btc',
13
13
  'cosmos:cosmoshub-4/slip44:118': 'atom',
14
14
  'eip155:1/slip44:60': 'eth',
@@ -39,13 +39,13 @@ const CAIP19ToBanxaTickerMap = {
39
39
  'eip155:1/erc20:0x2260fac5e5542a773aa44fbcfedf7c193bc2c599': 'wbtc'
40
40
  };
41
41
  const invert = (data) => Object.entries(data).reduce((acc, [k, v]) => ((acc[v] = k), acc), {});
42
- const banxaTickerToCAIP19Map = invert(CAIP19ToBanxaTickerMap);
43
- const banxaTickerToCAIP19 = (id) => banxaTickerToCAIP19Map[id];
44
- exports.banxaTickerToCAIP19 = banxaTickerToCAIP19;
45
- const CAIP19ToBanxaTicker = (caip19) => CAIP19ToBanxaTickerMap[(0, toLower_1.default)(caip19)];
46
- exports.CAIP19ToBanxaTicker = CAIP19ToBanxaTicker;
47
- const getSupportedBanxaAssets = () => (0, entries_1.default)(CAIP19ToBanxaTickerMap).map(([CAIP19, ticker]) => ({
48
- CAIP19,
42
+ const banxaTickerToAssetIdMap = invert(AssetIdToBanxaTickerMap);
43
+ const banxaTickerToAssetId = (id) => banxaTickerToAssetIdMap[id];
44
+ exports.banxaTickerToAssetId = banxaTickerToAssetId;
45
+ const AssetIdToBanxaTicker = (assetId) => AssetIdToBanxaTickerMap[(0, toLower_1.default)(assetId)];
46
+ exports.AssetIdToBanxaTicker = AssetIdToBanxaTicker;
47
+ const getSupportedBanxaAssets = () => (0, entries_1.default)(AssetIdToBanxaTickerMap).map(([assetId, ticker]) => ({
48
+ assetId,
49
49
  ticker
50
50
  }));
51
51
  exports.getSupportedBanxaAssets = getSupportedBanxaAssets;
@@ -66,11 +66,11 @@ const chainIdToBanxaBlockchainCodeMap = {
66
66
  * @returns {string} - a Banxa chain identifier; e.g., 'cosmos'
67
67
  */
68
68
  const getBanxaBlockchainFromBanxaAssetTicker = (banxaAssetId) => {
69
- const assetCAIP19 = (0, exports.banxaTickerToCAIP19)(banxaAssetId.toLowerCase());
70
- if (!assetCAIP19)
69
+ const assetAssetId = (0, exports.banxaTickerToAssetId)(banxaAssetId.toLowerCase());
70
+ if (!assetAssetId)
71
71
  throw new Error(`getBanxaBlockchainFromBanxaAssetTicker: ${banxaAssetId} is not supported`);
72
- const { chain, network } = (0, caip19_1.fromCAIP19)(assetCAIP19);
73
- const chainId = (0, caip2_1.toCAIP2)({ network, chain });
72
+ const { chain, network } = (0, assetId_1.fromAssetId)(assetAssetId);
73
+ const chainId = (0, chainId_1.toChainId)({ network, chain });
74
74
  return chainIdToBanxaBlockchainCodeMap[chainId];
75
75
  };
76
76
  exports.getBanxaBlockchainFromBanxaAssetTicker = getBanxaBlockchainFromBanxaAssetTicker;
@@ -1,3 +1,3 @@
1
1
  export declare const coincapUrl = "https://api.coincap.io/v2/assets?limit=2000";
2
- export declare const coincapToCAIP19: (id: string) => string | undefined;
3
- export declare const CAIP19ToCoinCap: (caip19: string) => string | undefined;
2
+ export declare const coincapToAssetId: (id: string) => string | undefined;
3
+ export declare const assetIdToCoinCap: (assetId: string) => string | undefined;
@@ -26,17 +26,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.CAIP19ToCoinCap = exports.coincapToCAIP19 = exports.coincapUrl = void 0;
29
+ exports.assetIdToCoinCap = exports.coincapToAssetId = exports.coincapUrl = void 0;
30
30
  const toLower_1 = __importDefault(require("lodash/toLower"));
31
31
  const adapters = __importStar(require("./generated"));
32
32
  exports.coincapUrl = 'https://api.coincap.io/v2/assets?limit=2000';
33
- const generatedCAIP19ToCoinCapMap = Object.values(adapters).reduce((acc, cur) => ({
33
+ const generatedAssetIdToCoinCapMap = Object.values(adapters).reduce((acc, cur) => ({
34
34
  ...acc,
35
35
  ...cur
36
36
  }));
37
37
  const invert = (data) => Object.entries(data).reduce((acc, [k, v]) => ((acc[v] = k), acc), {});
38
- const generatedCoinCapToCAIP19Map = invert(generatedCAIP19ToCoinCapMap);
39
- const coincapToCAIP19 = (id) => generatedCoinCapToCAIP19Map[id];
40
- exports.coincapToCAIP19 = coincapToCAIP19;
41
- const CAIP19ToCoinCap = (caip19) => generatedCAIP19ToCoinCapMap[(0, toLower_1.default)(caip19)];
42
- exports.CAIP19ToCoinCap = CAIP19ToCoinCap;
38
+ const generatedCoinCapToAssetIdMap = invert(generatedAssetIdToCoinCapMap);
39
+ const coincapToAssetId = (id) => generatedCoinCapToAssetIdMap[id];
40
+ exports.coincapToAssetId = coincapToAssetId;
41
+ const assetIdToCoinCap = (assetId) => generatedAssetIdToCoinCapMap[(0, toLower_1.default)(assetId)];
42
+ exports.assetIdToCoinCap = assetIdToCoinCap;
@@ -7,14 +7,14 @@ exports.parseData = exports.makeOsmosisData = exports.makeCosmosHubData = export
7
7
  const types_1 = require("@shapeshiftoss/types");
8
8
  const axios_1 = __importDefault(require("axios"));
9
9
  const fs_1 = __importDefault(require("fs"));
10
- const caip2_1 = require("../../caip2/caip2");
11
- const caip19_1 = require("../../caip19/caip19");
10
+ const assetId_1 = require("../../assetId/assetId");
11
+ const chainId_1 = require("../../chainId/chainId");
12
12
  const writeFiles = async (data) => {
13
13
  const path = './src/adapters/coincap/generated/';
14
14
  const file = '/adapter.json';
15
15
  const writeFile = async ([k, v]) => await fs_1.default.promises.writeFile(`${path}${k}${file}`.replace(':', '_'), JSON.stringify(v));
16
16
  await Promise.all(Object.entries(data).map(writeFile));
17
- console.info('Generated CoinCap CAIP19 adapter data.');
17
+ console.info('Generated CoinCap AssetId adapter data.');
18
18
  };
19
19
  exports.writeFiles = writeFiles;
20
20
  const fetchData = async (URL) => (await axios_1.default.get(URL)).data.data;
@@ -24,16 +24,16 @@ const parseEthData = (data) => {
24
24
  const chain = types_1.ChainTypes.Ethereum;
25
25
  const network = types_1.NetworkTypes.MAINNET;
26
26
  return ethCoins.reduce((acc, { id, explorer }) => {
27
- let assetReference = caip19_1.AssetReference.Ethereum;
28
- const assetNamespace = id === 'ethereum' ? caip19_1.AssetNamespace.Slip44 : caip19_1.AssetNamespace.ERC20;
27
+ let assetReference = assetId_1.AssetReference.Ethereum;
28
+ const assetNamespace = id === 'ethereum' ? assetId_1.AssetNamespace.Slip44 : assetId_1.AssetNamespace.ERC20;
29
29
  if (id !== 'ethereum' && explorer) {
30
30
  assetReference = explorer
31
31
  .replace('https://etherscan.io/token/', '')
32
32
  .split('#')[0]
33
33
  .split('?')[0];
34
34
  }
35
- const caip19 = (0, caip19_1.toCAIP19)({ chain, network, assetNamespace, assetReference });
36
- acc[caip19] = id;
35
+ const assetId = (0, assetId_1.toAssetId)({ chain, network, assetNamespace, assetReference });
36
+ acc[assetId] = id;
37
37
  return acc;
38
38
  }, {});
39
39
  };
@@ -41,47 +41,47 @@ exports.parseEthData = parseEthData;
41
41
  const makeBtcData = () => {
42
42
  const chain = types_1.ChainTypes.Bitcoin;
43
43
  const network = types_1.NetworkTypes.MAINNET;
44
- const caip19 = (0, caip19_1.toCAIP19)({
44
+ const assetId = (0, assetId_1.toAssetId)({
45
45
  chain,
46
46
  network,
47
- assetNamespace: caip19_1.AssetNamespace.Slip44,
48
- assetReference: caip19_1.AssetReference.Bitcoin
47
+ assetNamespace: assetId_1.AssetNamespace.Slip44,
48
+ assetReference: assetId_1.AssetReference.Bitcoin
49
49
  });
50
- return { [caip19]: 'bitcoin' };
50
+ return { [assetId]: 'bitcoin' };
51
51
  };
52
52
  exports.makeBtcData = makeBtcData;
53
53
  const makeCosmosHubData = () => {
54
54
  const chain = types_1.ChainTypes.Cosmos;
55
55
  const network = types_1.NetworkTypes.COSMOSHUB_MAINNET;
56
- const caip19 = (0, caip19_1.toCAIP19)({
56
+ const assetId = (0, assetId_1.toAssetId)({
57
57
  chain,
58
58
  network,
59
- assetNamespace: caip19_1.AssetNamespace.Slip44,
60
- assetReference: caip19_1.AssetReference.Cosmos
59
+ assetNamespace: assetId_1.AssetNamespace.Slip44,
60
+ assetReference: assetId_1.AssetReference.Cosmos
61
61
  });
62
- return { [caip19]: 'cosmos' };
62
+ return { [assetId]: 'cosmos' };
63
63
  };
64
64
  exports.makeCosmosHubData = makeCosmosHubData;
65
65
  const makeOsmosisData = () => {
66
66
  const chain = types_1.ChainTypes.Osmosis;
67
67
  const network = types_1.NetworkTypes.OSMOSIS_MAINNET;
68
- const caip19 = (0, caip19_1.toCAIP19)({
68
+ const assetId = (0, assetId_1.toAssetId)({
69
69
  chain,
70
70
  network,
71
- assetNamespace: caip19_1.AssetNamespace.Slip44,
72
- assetReference: caip19_1.AssetReference.Osmosis
71
+ assetNamespace: assetId_1.AssetNamespace.Slip44,
72
+ assetReference: assetId_1.AssetReference.Osmosis
73
73
  });
74
- return { [caip19]: 'osmosis' };
74
+ return { [assetId]: 'osmosis' };
75
75
  };
76
76
  exports.makeOsmosisData = makeOsmosisData;
77
77
  const parseData = (d) => {
78
- const ethereumMainnet = (0, caip2_1.toCAIP2)({ chain: types_1.ChainTypes.Ethereum, network: types_1.NetworkTypes.MAINNET });
79
- const bitcoinMainnet = (0, caip2_1.toCAIP2)({ chain: types_1.ChainTypes.Bitcoin, network: types_1.NetworkTypes.MAINNET });
80
- const cosmosHubMainnet = (0, caip2_1.toCAIP2)({
78
+ const ethereumMainnet = (0, chainId_1.toChainId)({ chain: types_1.ChainTypes.Ethereum, network: types_1.NetworkTypes.MAINNET });
79
+ const bitcoinMainnet = (0, chainId_1.toChainId)({ chain: types_1.ChainTypes.Bitcoin, network: types_1.NetworkTypes.MAINNET });
80
+ const cosmosHubMainnet = (0, chainId_1.toChainId)({
81
81
  chain: types_1.ChainTypes.Cosmos,
82
82
  network: types_1.NetworkTypes.COSMOSHUB_MAINNET
83
83
  });
84
- const osmosisMainnet = (0, caip2_1.toCAIP2)({
84
+ const osmosisMainnet = (0, chainId_1.toChainId)({
85
85
  chain: types_1.ChainTypes.Osmosis,
86
86
  network: types_1.NetworkTypes.OSMOSIS_MAINNET
87
87
  });
@@ -1,3 +1,3 @@
1
1
  export declare const coingeckoUrl = "https://api.coingecko.com/api/v3/coins/list?include_platform=true";
2
- export declare const coingeckoToCAIP19: (id: string) => string | undefined;
3
- export declare const CAIP19ToCoingecko: (caip19: string) => string | undefined;
2
+ export declare const coingeckoToAssetId: (id: string) => string | undefined;
3
+ export declare const assetIdToCoingecko: (assetId: string) => string | undefined;
@@ -26,17 +26,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.CAIP19ToCoingecko = exports.coingeckoToCAIP19 = exports.coingeckoUrl = void 0;
29
+ exports.assetIdToCoingecko = exports.coingeckoToAssetId = exports.coingeckoUrl = void 0;
30
30
  const toLower_1 = __importDefault(require("lodash/toLower"));
31
31
  const adapters = __importStar(require("./generated"));
32
32
  exports.coingeckoUrl = 'https://api.coingecko.com/api/v3/coins/list?include_platform=true';
33
- const generatedCAIP19ToCoingeckoMap = Object.values(adapters).reduce((acc, cur) => ({
33
+ const generatedAssetIdToCoingeckoMap = Object.values(adapters).reduce((acc, cur) => ({
34
34
  ...acc,
35
35
  ...cur
36
36
  }));
37
37
  const invert = (data) => Object.entries(data).reduce((acc, [k, v]) => ((acc[v] = k), acc), {});
38
- const generatedCoingeckoToCAIP19Map = invert(generatedCAIP19ToCoingeckoMap);
39
- const coingeckoToCAIP19 = (id) => generatedCoingeckoToCAIP19Map[id];
40
- exports.coingeckoToCAIP19 = coingeckoToCAIP19;
41
- const CAIP19ToCoingecko = (caip19) => generatedCAIP19ToCoingeckoMap[(0, toLower_1.default)(caip19)];
42
- exports.CAIP19ToCoingecko = CAIP19ToCoingecko;
38
+ const generatedCoingeckoToAssetIdMap = invert(generatedAssetIdToCoingeckoMap);
39
+ const coingeckoToAssetId = (id) => generatedCoingeckoToAssetIdMap[id];
40
+ exports.coingeckoToAssetId = coingeckoToAssetId;
41
+ const assetIdToCoingecko = (assetId) => generatedAssetIdToCoingeckoMap[(0, toLower_1.default)(assetId)];
42
+ exports.assetIdToCoingecko = assetIdToCoingecko;
@@ -7,14 +7,14 @@ exports.parseData = exports.makeOsmosisData = exports.makeCosmosHubData = export
7
7
  const types_1 = require("@shapeshiftoss/types");
8
8
  const axios_1 = __importDefault(require("axios"));
9
9
  const fs_1 = __importDefault(require("fs"));
10
- const caip2_1 = require("../../caip2/caip2");
11
- const caip19_1 = require("../../caip19/caip19");
10
+ const assetId_1 = require("../../assetId/assetId");
11
+ const chainId_1 = require("../../chainId/chainId");
12
12
  const writeFiles = async (data) => {
13
13
  const path = './src/adapters/coingecko/generated/';
14
14
  const file = '/adapter.json';
15
15
  const writeFile = async ([k, v]) => await fs_1.default.promises.writeFile(`${path}${k}${file}`.replace(':', '_'), JSON.stringify(v));
16
16
  await Promise.all(Object.entries(data).map(writeFile));
17
- console.info('Generated CoinGecko CAIP19 adapter data.');
17
+ console.info('Generated CoinGecko AssetId adapter data.');
18
18
  };
19
19
  exports.writeFiles = writeFiles;
20
20
  const fetchData = async (URL) => (await axios_1.default.get(URL)).data;
@@ -24,10 +24,10 @@ const parseEthData = (data) => {
24
24
  const chain = types_1.ChainTypes.Ethereum;
25
25
  const network = types_1.NetworkTypes.MAINNET;
26
26
  return ethCoins.reduce((acc, { id, platforms }) => {
27
- const assetNamespace = id === 'ethereum' ? caip19_1.AssetNamespace.Slip44 : caip19_1.AssetNamespace.ERC20;
28
- const assetReference = id === 'ethereum' ? caip19_1.AssetReference.Ethereum : platforms === null || platforms === void 0 ? void 0 : platforms.ethereum;
29
- const caip19 = (0, caip19_1.toCAIP19)({ chain, network, assetNamespace, assetReference });
30
- acc[caip19] = id;
27
+ const assetNamespace = id === 'ethereum' ? assetId_1.AssetNamespace.Slip44 : assetId_1.AssetNamespace.ERC20;
28
+ const assetReference = id === 'ethereum' ? assetId_1.AssetReference.Ethereum : platforms === null || platforms === void 0 ? void 0 : platforms.ethereum;
29
+ const assetId = (0, assetId_1.toAssetId)({ chain, network, assetNamespace, assetReference });
30
+ acc[assetId] = id;
31
31
  return acc;
32
32
  }, {});
33
33
  };
@@ -35,47 +35,47 @@ exports.parseEthData = parseEthData;
35
35
  const makeBtcData = () => {
36
36
  const chain = types_1.ChainTypes.Bitcoin;
37
37
  const network = types_1.NetworkTypes.MAINNET;
38
- const caip19 = (0, caip19_1.toCAIP19)({
38
+ const assetId = (0, assetId_1.toAssetId)({
39
39
  chain,
40
40
  network,
41
- assetNamespace: caip19_1.AssetNamespace.Slip44,
42
- assetReference: caip19_1.AssetReference.Bitcoin
41
+ assetNamespace: assetId_1.AssetNamespace.Slip44,
42
+ assetReference: assetId_1.AssetReference.Bitcoin
43
43
  });
44
- return { [caip19]: 'bitcoin' };
44
+ return { [assetId]: 'bitcoin' };
45
45
  };
46
46
  exports.makeBtcData = makeBtcData;
47
47
  const makeCosmosHubData = () => {
48
48
  const chain = types_1.ChainTypes.Cosmos;
49
49
  const network = types_1.NetworkTypes.COSMOSHUB_MAINNET;
50
- const caip19 = (0, caip19_1.toCAIP19)({
50
+ const assetId = (0, assetId_1.toAssetId)({
51
51
  chain,
52
52
  network,
53
- assetNamespace: caip19_1.AssetNamespace.Slip44,
54
- assetReference: caip19_1.AssetReference.Cosmos
53
+ assetNamespace: assetId_1.AssetNamespace.Slip44,
54
+ assetReference: assetId_1.AssetReference.Cosmos
55
55
  });
56
- return { [caip19]: 'cosmos' };
56
+ return { [assetId]: 'cosmos' };
57
57
  };
58
58
  exports.makeCosmosHubData = makeCosmosHubData;
59
59
  const makeOsmosisData = () => {
60
60
  const chain = types_1.ChainTypes.Osmosis;
61
61
  const network = types_1.NetworkTypes.OSMOSIS_MAINNET;
62
- const caip19 = (0, caip19_1.toCAIP19)({
62
+ const assetId = (0, assetId_1.toAssetId)({
63
63
  chain,
64
64
  network,
65
- assetNamespace: caip19_1.AssetNamespace.Slip44,
66
- assetReference: caip19_1.AssetReference.Osmosis
65
+ assetNamespace: assetId_1.AssetNamespace.Slip44,
66
+ assetReference: assetId_1.AssetReference.Osmosis
67
67
  });
68
- return { [caip19]: 'osmosis' };
68
+ return { [assetId]: 'osmosis' };
69
69
  };
70
70
  exports.makeOsmosisData = makeOsmosisData;
71
71
  const parseData = (d) => {
72
- const ethereumMainnet = (0, caip2_1.toCAIP2)({ chain: types_1.ChainTypes.Ethereum, network: types_1.NetworkTypes.MAINNET });
73
- const bitcoinMainnet = (0, caip2_1.toCAIP2)({ chain: types_1.ChainTypes.Bitcoin, network: types_1.NetworkTypes.MAINNET });
74
- const cosmosHubMainnet = (0, caip2_1.toCAIP2)({
72
+ const ethereumMainnet = (0, chainId_1.toChainId)({ chain: types_1.ChainTypes.Ethereum, network: types_1.NetworkTypes.MAINNET });
73
+ const bitcoinMainnet = (0, chainId_1.toChainId)({ chain: types_1.ChainTypes.Bitcoin, network: types_1.NetworkTypes.MAINNET });
74
+ const cosmosHubMainnet = (0, chainId_1.toChainId)({
75
75
  chain: types_1.ChainTypes.Cosmos,
76
76
  network: types_1.NetworkTypes.COSMOSHUB_MAINNET
77
77
  });
78
- const osmosisMainnet = (0, caip2_1.toCAIP2)({
78
+ const osmosisMainnet = (0, chainId_1.toChainId)({
79
79
  chain: types_1.ChainTypes.Osmosis,
80
80
  network: types_1.NetworkTypes.OSMOSIS_MAINNET
81
81
  });
@@ -1,2 +1,2 @@
1
- export declare const gemAssetIdToCAIP19: (id: string) => string | undefined;
2
- export declare const CAIP19ToGemAssetId: (caip19: string) => string | undefined;
1
+ export declare const gemAssetIdToAssetId: (id: string) => string | undefined;
2
+ export declare const assetIdToGemAssetId: (assetId: string) => string | undefined;
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CAIP19ToGemAssetId = exports.gemAssetIdToCAIP19 = void 0;
6
+ exports.assetIdToGemAssetId = exports.gemAssetIdToAssetId = void 0;
7
7
  const toLower_1 = __importDefault(require("lodash/toLower"));
8
- const CAIP19ToGemAssetIdMap = {
8
+ const assetIdToGemAssetIdMap = {
9
9
  'bip122:000000000019d6689c085ae165831e93/slip44:0': 'bitcoin',
10
10
  'eip155:1/slip44:60': 'ethereum',
11
11
  'eip155:1/erc20:0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9': 'aave',
@@ -29,8 +29,8 @@ const CAIP19ToGemAssetIdMap = {
29
29
  'eip155:1/erc20:0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e': 'yearn-finance'
30
30
  };
31
31
  const invert = (data) => Object.entries(data).reduce((acc, [k, v]) => ((acc[v] = k), acc), {});
32
- const gemAssetIdToCAIP19Map = invert(CAIP19ToGemAssetIdMap);
33
- const gemAssetIdToCAIP19 = (id) => gemAssetIdToCAIP19Map[id];
34
- exports.gemAssetIdToCAIP19 = gemAssetIdToCAIP19;
35
- const CAIP19ToGemAssetId = (caip19) => CAIP19ToGemAssetIdMap[(0, toLower_1.default)(caip19)];
36
- exports.CAIP19ToGemAssetId = CAIP19ToGemAssetId;
32
+ const gemAssetIdToAssetIdMap = invert(assetIdToGemAssetIdMap);
33
+ const gemAssetIdToAssetId = (id) => gemAssetIdToAssetIdMap[id];
34
+ exports.gemAssetIdToAssetId = gemAssetIdToAssetId;
35
+ const assetIdToGemAssetId = (assetId) => assetIdToGemAssetIdMap[(0, toLower_1.default)(assetId)];
36
+ exports.assetIdToGemAssetId = assetIdToGemAssetId;
@@ -1,3 +1,3 @@
1
1
  export declare const osmosisUrl = "https://api-osmosis.imperator.co/tokens/v2/all";
2
- export declare const osmosisToCAIP19: (id: string) => string | undefined;
3
- export declare const CAIP19ToOsmosis: (caip19: string) => string | undefined;
2
+ export declare const osmosisToAssetId: (id: string) => string | undefined;
3
+ export declare const assetIdToOsmosis: (assetId: string) => string | undefined;
@@ -23,16 +23,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.CAIP19ToOsmosis = exports.osmosisToCAIP19 = exports.osmosisUrl = void 0;
26
+ exports.assetIdToOsmosis = exports.osmosisToAssetId = exports.osmosisUrl = void 0;
27
27
  const adapters = __importStar(require("./generated"));
28
28
  exports.osmosisUrl = 'https://api-osmosis.imperator.co/tokens/v2/all';
29
- const generatedCAIP19ToOsmosisMap = Object.values(adapters).reduce((acc, cur) => ({
29
+ const generatedAssetIdToOsmosisMap = Object.values(adapters).reduce((acc, cur) => ({
30
30
  ...acc,
31
31
  ...cur
32
32
  }));
33
33
  const invert = (data) => Object.entries(data).reduce((acc, [k, v]) => ((acc[v] = k), acc), {});
34
- const generatedOsmosisToCAIP19Map = invert(generatedCAIP19ToOsmosisMap);
35
- const osmosisToCAIP19 = (id) => generatedOsmosisToCAIP19Map[id];
36
- exports.osmosisToCAIP19 = osmosisToCAIP19;
37
- const CAIP19ToOsmosis = (caip19) => generatedCAIP19ToOsmosisMap[caip19];
38
- exports.CAIP19ToOsmosis = CAIP19ToOsmosis;
34
+ const generatedOsmosisToAssetIdMap = invert(generatedAssetIdToOsmosisMap);
35
+ const osmosisToAssetId = (id) => generatedOsmosisToAssetIdMap[id];
36
+ exports.osmosisToAssetId = osmosisToAssetId;
37
+ const assetIdToOsmosis = (assetId) => generatedAssetIdToOsmosisMap[assetId];
38
+ exports.assetIdToOsmosis = assetIdToOsmosis;
@@ -7,14 +7,14 @@ exports.parseData = exports.parseOsmosisData = exports.fetchData = exports.write
7
7
  const types_1 = require("@shapeshiftoss/types");
8
8
  const axios_1 = __importDefault(require("axios"));
9
9
  const fs_1 = __importDefault(require("fs"));
10
- const caip2_1 = require("../../caip2/caip2");
11
- const caip19_1 = require("./../../caip19/caip19");
10
+ const assetId_1 = require("../../assetId/assetId");
11
+ const chainId_1 = require("../../chainId/chainId");
12
12
  const writeFiles = async (data) => {
13
13
  const path = './src/adapters/osmosis/generated/';
14
14
  const file = '/adapter.json';
15
15
  const writeFile = async ([k, v]) => await fs_1.default.promises.writeFile(`${path}${k}${file}`.replace(':', '_'), JSON.stringify(v));
16
16
  await Promise.all(Object.entries(data).map(writeFile));
17
- console.info('Generated Osmosis CAIP19 adapter data.');
17
+ console.info('Generated Osmosis AssetId adapter data.');
18
18
  };
19
19
  exports.writeFiles = writeFiles;
20
20
  const fetchData = async (URL) => (await axios_1.default.get(URL)).data;
@@ -28,24 +28,24 @@ const parseOsmosisData = (data) => {
28
28
  let assetReference;
29
29
  if (isNativeAsset) {
30
30
  // TODO(ryankk): remove `toString` when AssetReferences are changed to strings
31
- assetReference = isOsmo ? caip19_1.AssetReference.Osmosis.toString() : denom;
32
- assetNamespace = isOsmo ? caip19_1.AssetNamespace.Slip44 : caip19_1.AssetNamespace.NATIVE;
31
+ assetReference = isOsmo ? assetId_1.AssetReference.Osmosis.toString() : denom;
32
+ assetNamespace = isOsmo ? assetId_1.AssetNamespace.Slip44 : assetId_1.AssetNamespace.NATIVE;
33
33
  }
34
34
  else {
35
35
  assetReference = denom.split('/')[1];
36
- assetNamespace = caip19_1.AssetNamespace.IBC;
36
+ assetNamespace = assetId_1.AssetNamespace.IBC;
37
37
  }
38
38
  const chain = types_1.ChainTypes.Osmosis;
39
39
  const network = types_1.NetworkTypes.OSMOSIS_MAINNET;
40
- const caip19 = (0, caip19_1.toCAIP19)({ chain, network, assetNamespace, assetReference });
41
- acc[caip19] = symbol;
40
+ const assetId = (0, assetId_1.toAssetId)({ chain, network, assetNamespace, assetReference });
41
+ acc[assetId] = symbol;
42
42
  return acc;
43
43
  }, {});
44
44
  return results;
45
45
  };
46
46
  exports.parseOsmosisData = parseOsmosisData;
47
47
  const parseData = (d) => {
48
- const osmosisMainnet = (0, caip2_1.toCAIP2)({
48
+ const osmosisMainnet = (0, chainId_1.toChainId)({
49
49
  chain: types_1.ChainTypes.Osmosis,
50
50
  network: types_1.NetworkTypes.OSMOSIS_MAINNET
51
51
  });
@@ -1,2 +1,2 @@
1
- export declare const yearnToCAIP19: (id: string) => string;
2
- export declare const CAIP19ToYearn: (caip19: string) => string | undefined;
1
+ export declare const yearnToAssetId: (id: string) => string;
2
+ export declare const assetIdToYearn: (assetId: string) => string | undefined;
@@ -26,16 +26,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.CAIP19ToYearn = exports.yearnToCAIP19 = void 0;
29
+ exports.assetIdToYearn = exports.yearnToAssetId = void 0;
30
30
  const toLower_1 = __importDefault(require("lodash/toLower"));
31
31
  const adapters = __importStar(require("./generated"));
32
- const generatedCAIP19ToYearnMap = Object.values(adapters).reduce((acc, cur) => ({
32
+ const generatedAssedIdToYearnMap = Object.values(adapters).reduce((acc, cur) => ({
33
33
  ...acc,
34
34
  ...cur
35
35
  }));
36
36
  const invert = (data) => Object.entries(data).reduce((acc, [k, v]) => ((acc[v] = k), acc), {});
37
- const generatedYearnToCAIP19Map = invert(generatedCAIP19ToYearnMap);
38
- const yearnToCAIP19 = (id) => generatedYearnToCAIP19Map[id];
39
- exports.yearnToCAIP19 = yearnToCAIP19;
40
- const CAIP19ToYearn = (caip19) => generatedCAIP19ToYearnMap[(0, toLower_1.default)(caip19)];
41
- exports.CAIP19ToYearn = CAIP19ToYearn;
37
+ const generatedYearnToAssetIdMap = invert(generatedAssedIdToYearnMap);
38
+ const yearnToAssetId = (id) => generatedYearnToAssetIdMap[id];
39
+ exports.yearnToAssetId = yearnToAssetId;
40
+ const assetIdToYearn = (assetId) => generatedAssedIdToYearnMap[(0, toLower_1.default)(assetId)];
41
+ exports.assetIdToYearn = assetIdToYearn;
@@ -10,8 +10,8 @@ const sdk_1 = require("@yfi/sdk");
10
10
  const fs_1 = __importDefault(require("fs"));
11
11
  const toLower_1 = __importDefault(require("lodash/toLower"));
12
12
  const uniqBy_1 = __importDefault(require("lodash/uniqBy"));
13
- const caip2_1 = require("../../caip2/caip2");
14
- const caip19_1 = require("../../caip19/caip19");
13
+ const assetId_1 = require("../../assetId/assetId");
14
+ const chainId_1 = require("../../chainId/chainId");
15
15
  const network = 1; // 1 for mainnet
16
16
  const provider = new providers_1.JsonRpcProvider(process.env.REACT_APP_ETHEREUM_NODE_URL);
17
17
  const yearnSdk = new sdk_1.Yearn(network, { provider });
@@ -20,7 +20,7 @@ const writeFiles = async (data) => {
20
20
  const file = '/adapter.json';
21
21
  const writeFile = async ([k, v]) => await fs_1.default.promises.writeFile(`${path}${k}${file}`.replace(':', '_'), JSON.stringify(v));
22
22
  await Promise.all(Object.entries(data).map(writeFile));
23
- console.info('Generated Yearn CAIP19 adapter data.');
23
+ console.info('Generated Yearn AssetId adapter data.');
24
24
  };
25
25
  exports.writeFiles = writeFiles;
26
26
  const fetchData = async () => {
@@ -36,24 +36,24 @@ const fetchData = async () => {
36
36
  exports.fetchData = fetchData;
37
37
  const parseEthData = (data) => {
38
38
  const chain = types_1.ChainTypes.Ethereum;
39
- const assetNamespace = caip19_1.AssetNamespace.ERC20;
39
+ const assetNamespace = assetId_1.AssetNamespace.ERC20;
40
40
  return data.reduce((acc, datum) => {
41
41
  const { address } = datum;
42
42
  const id = address;
43
43
  const assetReference = (0, toLower_1.default)(address);
44
- const caip19 = (0, caip19_1.toCAIP19)({
44
+ const assetId = (0, assetId_1.toAssetId)({
45
45
  chain,
46
46
  network: types_1.NetworkTypes.MAINNET,
47
47
  assetNamespace,
48
48
  assetReference
49
49
  });
50
- acc[caip19] = id;
50
+ acc[assetId] = id;
51
51
  return acc;
52
52
  }, {});
53
53
  };
54
54
  exports.parseEthData = parseEthData;
55
55
  const parseData = (d) => {
56
- const ethMainnet = (0, caip2_1.toCAIP2)({ chain: types_1.ChainTypes.Ethereum, network: types_1.NetworkTypes.MAINNET });
56
+ const ethMainnet = (0, chainId_1.toChainId)({ chain: types_1.ChainTypes.Ethereum, network: types_1.NetworkTypes.MAINNET });
57
57
  return { [ethMainnet]: (0, exports.parseEthData)(d) };
58
58
  };
59
59
  exports.parseData = parseData;
@@ -1,9 +1,5 @@
1
1
  import { ChainTypes, NetworkTypes } from '@shapeshiftoss/types';
2
- import { ChainReference } from '../caip2/caip2';
3
- /**
4
- * @deprecated - Temporarily left in place for backwards compatibility, to be replaced with AssetId
5
- */
6
- export declare type CAIP19 = string;
2
+ import { ChainReference } from '../chainId/chainId';
7
3
  export declare type AssetId = string;
8
4
  export declare enum AssetNamespace {
9
5
  CW20 = "cw20",
@@ -20,19 +16,19 @@ export declare enum AssetReference {
20
16
  Cosmos = "118",
21
17
  Osmosis = "118"
22
18
  }
23
- declare type ToCAIP19Args = {
19
+ declare type ToAssetIdArgs = {
24
20
  chain: ChainTypes;
25
21
  network: NetworkTypes | ChainReference;
26
22
  assetNamespace: AssetNamespace;
27
23
  assetReference: AssetReference | string;
28
24
  };
29
- declare type ToCAIP19 = (args: ToCAIP19Args) => string;
30
- export declare const toCAIP19: ToCAIP19;
31
- declare type FromCAIP19Return = {
25
+ declare type ToAssetId = (args: ToAssetIdArgs) => string;
26
+ export declare const toAssetId: ToAssetId;
27
+ declare type FromAssetIdReturn = {
32
28
  chain: ChainTypes;
33
29
  network: NetworkTypes;
34
30
  assetNamespace: AssetNamespace;
35
31
  assetReference: AssetReference | string;
36
32
  };
37
- export declare const fromCAIP19: (caip19: string) => FromCAIP19Return;
33
+ export declare const fromAssetId: (assetId: string) => FromAssetIdReturn;
38
34
  export {};
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fromCAIP19 = exports.toCAIP19 = exports.AssetReference = exports.AssetNamespace = void 0;
3
+ exports.fromAssetId = exports.toAssetId = exports.AssetReference = exports.AssetNamespace = void 0;
4
4
  // https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-19.md
5
5
  const types_1 = require("@shapeshiftoss/types");
6
- const caip2_1 = require("../caip2/caip2");
6
+ const chainId_1 = require("../chainId/chainId");
7
7
  var AssetNamespace;
8
8
  (function (AssetNamespace) {
9
9
  AssetNamespace["CW20"] = "cw20";
@@ -55,45 +55,45 @@ const isValidSlip44 = (value) => {
55
55
  // slip44 has a max value of an unsigned 32-bit integer
56
56
  return !isNaN(n) && n >= 0 && n < 4294967296;
57
57
  };
58
- const toCAIP19 = (args) => {
58
+ const toAssetId = (args) => {
59
59
  const { chain, network, assetNamespace } = args;
60
60
  let { assetReference } = args;
61
61
  if (!chain)
62
- throw new Error('toCAIP19: No chain provided');
62
+ throw new Error('toAssetId: No chain provided');
63
63
  if (!network)
64
- throw new Error('toCAIP19: No chainReference Provided');
64
+ throw new Error('toAssetId: No chainReference Provided');
65
65
  if (!assetNamespace)
66
- throw new Error('toCAIP19: No assetNamespace provided');
66
+ throw new Error('toAssetId: No assetNamespace provided');
67
67
  if (!assetReference)
68
- throw new Error('toCAIP19: No assetReference provided');
69
- const caip2 = (0, caip2_1.toCAIP2)({ chain, network });
68
+ throw new Error('toAssetId: No assetReference provided');
69
+ const chainId = (0, chainId_1.toChainId)({ chain, network });
70
70
  if (!validAssetNamespaces[chain].includes(assetNamespace)) {
71
- throw new Error(`toCAIP19: Asset Namespace ${assetNamespace} not supported for chain ${chain}`);
71
+ throw new Error(`toAssetId: Asset Namespace ${assetNamespace} not supported for chain ${chain}`);
72
72
  }
73
73
  if (assetNamespace === AssetNamespace.Slip44 && !isValidSlip44(String(assetReference))) {
74
74
  throw new Error(`Invalid reference for namespace slip44`);
75
75
  }
76
76
  if ([AssetNamespace.ERC20, AssetNamespace.ERC721].includes(assetNamespace)) {
77
77
  if (!assetReference.startsWith('0x')) {
78
- throw new Error(`toCAIP19: assetReference must start with 0x: ${assetReference}`);
78
+ throw new Error(`toAssetId: assetReference must start with 0x: ${assetReference}`);
79
79
  }
80
80
  if (assetReference.length !== 42) {
81
- throw new Error(`toCAIP19: assetReference length must be 42, length: ${assetReference.length}`);
81
+ throw new Error(`toAssetId: assetReference length must be 42, length: ${assetReference.length}`);
82
82
  }
83
83
  // We make Eth contract addresses lower case to simplify comparisons
84
84
  assetReference = assetReference.toLowerCase();
85
85
  }
86
- return `${caip2}/${assetNamespace}:${assetReference}`;
86
+ return `${chainId}/${assetNamespace}:${assetReference}`;
87
87
  };
88
- exports.toCAIP19 = toCAIP19;
89
- const parseCaip19RegExp = /([-a-z\d]{3,8}):([-a-zA-Z\d]{1,32})\/([-a-z\d]{3,8}):([-a-zA-Z\d]+)/;
90
- const fromCAIP19 = (caip19) => {
88
+ exports.toAssetId = toAssetId;
89
+ const parseAssetIdRegExp = /([-a-z\d]{3,8}):([-a-zA-Z\d]{1,32})\/([-a-z\d]{3,8}):([-a-zA-Z\d]+)/;
90
+ const fromAssetId = (assetId) => {
91
91
  var _a;
92
- const matches = (_a = parseCaip19RegExp.exec(caip19)) !== null && _a !== void 0 ? _a : [];
92
+ const matches = (_a = parseAssetIdRegExp.exec(assetId)) !== null && _a !== void 0 ? _a : [];
93
93
  // We're okay casting these strings to enums because we check to make sure
94
94
  // they are valid enum values
95
- let chain = caip2_1.chainNamespaceToChainType[matches[1]];
96
- const network = caip2_1.chainReferenceToNetworkType[matches[2]];
95
+ let chain = chainId_1.chainNamespaceToChainType[matches[1]];
96
+ const network = chainId_1.chainReferenceToNetworkType[matches[2]];
97
97
  const assetNamespace = stringToEnum(AssetNamespace, matches[3]);
98
98
  let assetReference = matches[4];
99
99
  if (chain && network && assetNamespace && assetReference) {
@@ -110,6 +110,6 @@ const fromCAIP19 = (caip19) => {
110
110
  }
111
111
  return { chain, network, assetNamespace, assetReference };
112
112
  }
113
- throw new Error(`fromCAIP19: invalid CAIP19: ${caip19}`);
113
+ throw new Error(`fromAssetId: invalid AssetId: ${assetId}`);
114
114
  };
115
- exports.fromCAIP19 = fromCAIP19;
115
+ exports.fromAssetId = fromAssetId;
@@ -1,8 +1,4 @@
1
1
  import { ChainTypes, NetworkTypes } from '@shapeshiftoss/types';
2
- /**
3
- * @deprecated - Temporarily left in place for backwards compatibility, to be replaced with ChainId
4
- */
5
- export declare type CAIP2 = string;
6
2
  export declare type ChainId = string;
7
3
  export declare enum ChainNamespace {
8
4
  Ethereum = "eip155",
@@ -20,19 +16,19 @@ export declare enum ChainReference {
20
16
  OsmosisMainnet = "osmosis-1",
21
17
  OsmosisTestnet = "osmo-testnet-1"
22
18
  }
23
- declare type ToCAIP2Args = {
19
+ declare type ToChainIdArgs = {
24
20
  chain: ChainTypes;
25
21
  network: NetworkTypes | ChainReference;
26
22
  };
27
- export declare const toCAIP2: (args: ToCAIP2Args) => string;
28
- declare type FromCAIP2Return = {
23
+ export declare const toChainId: (args: ToChainIdArgs) => string;
24
+ declare type FromChainIdReturn = {
29
25
  chain: ChainTypes;
30
26
  network: NetworkTypes;
31
27
  };
32
- declare type FromCAIP2 = (caip2: string) => FromCAIP2Return;
33
- export declare const fromCAIP2: FromCAIP2;
34
- declare type IsCAIP2 = (caip2: string) => boolean;
35
- export declare const isCAIP2: IsCAIP2;
28
+ declare type FromChainId = (chainId: string) => FromChainIdReturn;
29
+ export declare const fromChainId: FromChainId;
30
+ declare type IsChainId = (chainId: string) => boolean;
31
+ export declare const isChainId: IsChainId;
36
32
  export declare const chainReferenceToNetworkType: Record<ChainReference, NetworkTypes>;
37
33
  export declare const networkTypeToChainReference: Record<NetworkTypes, ChainReference>;
38
34
  export declare const chainNamespaceToChainType: Record<ChainNamespace, ChainTypes>;
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.chainNamespaceToChainType = exports.networkTypeToChainReference = exports.chainReferenceToNetworkType = exports.isCAIP2 = exports.fromCAIP2 = exports.toCAIP2 = exports.ChainReference = exports.ChainNamespace = void 0;
7
+ exports.chainNamespaceToChainType = exports.networkTypeToChainReference = exports.chainReferenceToNetworkType = exports.isChainId = exports.fromChainId = exports.toChainId = exports.ChainReference = exports.ChainNamespace = void 0;
8
8
  const types_1 = require("@shapeshiftoss/types");
9
9
  const invert_1 = __importDefault(require("lodash/invert"));
10
10
  var ChainNamespace;
@@ -18,9 +18,9 @@ var ChainReference;
18
18
  ChainReference["EthereumMainnet"] = "1";
19
19
  ChainReference["EthereumRopsten"] = "3";
20
20
  ChainReference["EthereumRinkeby"] = "4";
21
- // EthereumKovan = '42', // currently unsupported by shapeshift
21
+ // EthereumKovan = '42', // currently unsupported by ShapeShift
22
22
  // https://github.com/bitcoin/bips/blob/master/bip-0122.mediawiki#definition-of-chain-id
23
- // caip2 uses max length of 32 chars of the genesis block
23
+ // chainId uses max length of 32 chars of the genesis block
24
24
  ChainReference["BitcoinMainnet"] = "000000000019d6689c085ae165831e93";
25
25
  ChainReference["BitcoinTestnet"] = "000000000933ea01ad0ee984209779ba";
26
26
  ChainReference["CosmosHubMainnet"] = "cosmoshub-4";
@@ -28,7 +28,7 @@ var ChainReference;
28
28
  ChainReference["OsmosisMainnet"] = "osmosis-1";
29
29
  ChainReference["OsmosisTestnet"] = "osmo-testnet-1";
30
30
  })(ChainReference = exports.ChainReference || (exports.ChainReference = {}));
31
- const shapeShiftToCAIP2 = Object.freeze({
31
+ const shapeShiftToChainId = Object.freeze({
32
32
  [types_1.ChainTypes.Ethereum]: {
33
33
  namespace: ChainNamespace.Ethereum,
34
34
  reference: {
@@ -59,12 +59,12 @@ const shapeShiftToCAIP2 = Object.freeze({
59
59
  }
60
60
  }
61
61
  });
62
- const toCAIP2 = (args) => {
62
+ const toChainId = (args) => {
63
63
  const { chain, network } = args;
64
- const namespace = shapeShiftToCAIP2[chain].namespace;
64
+ const namespace = shapeShiftToChainId[chain].namespace;
65
65
  switch (chain) {
66
66
  case types_1.ChainTypes.Ethereum: {
67
- const referenceMap = shapeShiftToCAIP2[chain].reference;
67
+ const referenceMap = shapeShiftToChainId[chain].reference;
68
68
  switch (network) {
69
69
  case types_1.NetworkTypes.MAINNET:
70
70
  case types_1.NetworkTypes.ETH_ROPSTEN:
@@ -76,7 +76,7 @@ const toCAIP2 = (args) => {
76
76
  break;
77
77
  }
78
78
  case types_1.ChainTypes.Bitcoin: {
79
- const referenceMap = shapeShiftToCAIP2[chain].reference;
79
+ const referenceMap = shapeShiftToChainId[chain].reference;
80
80
  switch (network) {
81
81
  case types_1.NetworkTypes.MAINNET:
82
82
  case types_1.NetworkTypes.TESTNET: {
@@ -87,7 +87,7 @@ const toCAIP2 = (args) => {
87
87
  break;
88
88
  }
89
89
  case types_1.ChainTypes.Cosmos: {
90
- const referenceMap = shapeShiftToCAIP2[chain].reference;
90
+ const referenceMap = shapeShiftToChainId[chain].reference;
91
91
  switch (network) {
92
92
  case types_1.NetworkTypes.COSMOSHUB_MAINNET:
93
93
  case types_1.NetworkTypes.COSMOSHUB_VEGA: {
@@ -98,7 +98,7 @@ const toCAIP2 = (args) => {
98
98
  break;
99
99
  }
100
100
  case types_1.ChainTypes.Osmosis: {
101
- const referenceMap = shapeShiftToCAIP2[chain].reference;
101
+ const referenceMap = shapeShiftToChainId[chain].reference;
102
102
  switch (network) {
103
103
  case types_1.NetworkTypes.OSMOSIS_MAINNET:
104
104
  case types_1.NetworkTypes.OSMOSIS_TESTNET: {
@@ -109,13 +109,13 @@ const toCAIP2 = (args) => {
109
109
  break;
110
110
  }
111
111
  }
112
- throw new Error(`toCAIP2: unsupported ${chain} network: ${network}`);
112
+ throw new Error(`toChainId: unsupported ${chain} network: ${network}`);
113
113
  };
114
- exports.toCAIP2 = toCAIP2;
115
- const fromCAIP2 = (caip2) => {
116
- const [c, n] = caip2.split(':');
114
+ exports.toChainId = toChainId;
115
+ const fromChainId = (chainId) => {
116
+ const [c, n] = chainId.split(':');
117
117
  if (!(c && n)) {
118
- throw new Error(`fromCAIP19: error parsing caip19, chain: ${c}, network: ${n}`);
118
+ throw new Error(`fromChainId: error parsing chainId, chain: ${c}, network: ${n}`);
119
119
  }
120
120
  switch (c) {
121
121
  case ChainNamespace.Cosmos: {
@@ -133,7 +133,7 @@ const fromCAIP2 = (caip2) => {
133
133
  return { chain: types_1.ChainTypes.Osmosis, network: types_1.NetworkTypes.OSMOSIS_TESTNET };
134
134
  }
135
135
  default: {
136
- throw new Error(`fromCAIP19: unsupported ${c} network: ${n}`);
136
+ throw new Error(`fromChainId: unsupported ${c} network: ${n}`);
137
137
  }
138
138
  }
139
139
  }
@@ -153,7 +153,7 @@ const fromCAIP2 = (caip2) => {
153
153
  return { chain, network };
154
154
  }
155
155
  default: {
156
- throw new Error(`fromCAIP19: unsupported ${c} network: ${n}`);
156
+ throw new Error(`fromChainId: unsupported ${c} network: ${n}`);
157
157
  }
158
158
  }
159
159
  }
@@ -169,18 +169,18 @@ const fromCAIP2 = (caip2) => {
169
169
  return { chain, network };
170
170
  }
171
171
  default: {
172
- throw new Error(`fromCAIP19: unsupported ${c} network: ${n}`);
172
+ throw new Error(`fromChainId: unsupported ${c} network: ${n}`);
173
173
  }
174
174
  }
175
175
  }
176
176
  }
177
- throw new Error(`fromCAIP19: unsupported chain: ${c}`);
177
+ throw new Error(`fromChainId: unsupported chain: ${c}`);
178
178
  };
179
- exports.fromCAIP2 = fromCAIP2;
180
- const isCAIP2 = (caip2) => {
181
- const [c, n] = caip2.split(':');
179
+ exports.fromChainId = fromChainId;
180
+ const isChainId = (chainId) => {
181
+ const [c, n] = chainId.split(':');
182
182
  if (!(c && n)) {
183
- throw new Error(`isCAIP2: error parsing caip19, chain: ${c}, network: ${n}`);
183
+ throw new Error(`isChainId: error parsing chainId, chain: ${c}, network: ${n}`);
184
184
  }
185
185
  switch (c) {
186
186
  case ChainNamespace.Cosmos: {
@@ -211,9 +211,9 @@ const isCAIP2 = (caip2) => {
211
211
  break;
212
212
  }
213
213
  }
214
- throw new Error(`isCAIP2: invalid caip2 ${caip2}`);
214
+ throw new Error(`isChainId: invalid ChainId ${chainId}`);
215
215
  };
216
- exports.isCAIP2 = isCAIP2;
216
+ exports.isChainId = isChainId;
217
217
  exports.chainReferenceToNetworkType = Object.freeze({
218
218
  [ChainReference.BitcoinMainnet]: types_1.NetworkTypes.MAINNET,
219
219
  [ChainReference.BitcoinTestnet]: types_1.NetworkTypes.TESTNET,
package/dist/index.d.ts CHANGED
@@ -1,8 +1,4 @@
1
- import * as adapters from './adapters';
2
- import * as caip2 from './caip2/caip2';
3
- import * as caip10 from './caip10/caip10';
4
- import * as caip19 from './caip19/caip19';
5
- export { adapters, caip2, caip19, caip10 };
6
- export * from './caip2/caip2';
7
- export * from './caip10/caip10';
8
- export * from './caip19/caip19';
1
+ export * as adapters from './adapters';
2
+ export * from './chainId/chainId';
3
+ export * from './accountId/accountId';
4
+ export * from './assetId/assetId';
package/dist/index.js CHANGED
@@ -26,17 +26,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.caip10 = exports.caip19 = exports.caip2 = exports.adapters = void 0;
30
- const adapters = __importStar(require("./adapters"));
31
- exports.adapters = adapters;
32
- // TODO: These all go away on the caip breaking change PR
33
- const caip2 = __importStar(require("./caip2/caip2"));
34
- exports.caip2 = caip2;
35
- const caip10 = __importStar(require("./caip10/caip10"));
36
- exports.caip10 = caip10;
37
- const caip19 = __importStar(require("./caip19/caip19"));
38
- exports.caip19 = caip19;
39
- // ENDTODO
40
- __exportStar(require("./caip2/caip2"), exports);
41
- __exportStar(require("./caip10/caip10"), exports);
42
- __exportStar(require("./caip19/caip19"), exports);
29
+ exports.adapters = void 0;
30
+ exports.adapters = __importStar(require("./adapters"));
31
+ __exportStar(require("./chainId/chainId"), exports);
32
+ __exportStar(require("./accountId/accountId"), exports);
33
+ __exportStar(require("./assetId/assetId"), exports);
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { ChainId } from './caip2/caip2';
2
- import { AccountId } from './caip10/caip10';
3
- import { AssetId } from './caip19/caip19';
1
+ import { AccountId } from './accountId/accountId';
2
+ import { AssetId } from './assetId/assetId';
3
+ import { ChainId } from './chainId/chainId';
4
4
  export declare const btcAssetId = "bip122:000000000019d6689c085ae165831e93/slip44:0";
5
5
  export declare const ethAssetId = "eip155:1/slip44:60";
6
6
  export declare const cosmosAssetId = "cosmos:cosmoshub-4/slip44:118";
@@ -11,4 +11,4 @@ export declare const chainIdToAssetId: Record<ChainId, AssetId>;
11
11
  export declare const assetIdToChainId: (assetId: AssetId) => string;
12
12
  export declare const accountIdToChainId: (accountId: AccountId) => ChainId;
13
13
  export declare const accountIdToSpecifier: (accountId: AccountId) => string;
14
- export declare const getChainReferenceFromChainId: (chainId: ChainId) => import("./caip2/caip2").ChainReference;
14
+ export declare const getChainReferenceFromChainId: (chainId: ChainId) => import("./chainId/chainId").ChainReference;
package/dist/utils.js CHANGED
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getChainReferenceFromChainId = exports.accountIdToSpecifier = exports.accountIdToChainId = exports.assetIdToChainId = exports.chainIdToAssetId = exports.cosmosChainId = exports.btcChainId = exports.ethChainId = exports.cosmosAssetId = exports.ethAssetId = exports.btcAssetId = void 0;
4
- const caip2_1 = require("./caip2/caip2");
5
- const caip10_1 = require("./caip10/caip10");
6
- const caip19_1 = require("./caip19/caip19");
4
+ const accountId_1 = require("./accountId/accountId");
5
+ const assetId_1 = require("./assetId/assetId");
6
+ const chainId_1 = require("./chainId/chainId");
7
7
  exports.btcAssetId = 'bip122:000000000019d6689c085ae165831e93/slip44:0';
8
8
  exports.ethAssetId = 'eip155:1/slip44:60';
9
9
  exports.cosmosAssetId = 'cosmos:cosmoshub-4/slip44:118';
@@ -16,13 +16,13 @@ exports.chainIdToAssetId = {
16
16
  [exports.cosmosChainId]: 'cosmos:cosmoshub-4/slip44:118'
17
17
  };
18
18
  const assetIdToChainId = (assetId) => {
19
- const { chain, network } = (0, caip19_1.fromCAIP19)(assetId);
20
- return (0, caip2_1.toCAIP2)({ chain, network });
19
+ const { chain, network } = (0, assetId_1.fromAssetId)(assetId);
20
+ return (0, chainId_1.toChainId)({ chain, network });
21
21
  };
22
22
  exports.assetIdToChainId = assetIdToChainId;
23
- const accountIdToChainId = (accountId) => (0, caip10_1.fromCAIP10)(accountId).caip2;
23
+ const accountIdToChainId = (accountId) => (0, accountId_1.fromAccountId)(accountId).chainId;
24
24
  exports.accountIdToChainId = accountIdToChainId;
25
- const accountIdToSpecifier = (accountId) => (0, caip10_1.fromCAIP10)(accountId).account;
25
+ const accountIdToSpecifier = (accountId) => (0, accountId_1.fromAccountId)(accountId).account;
26
26
  exports.accountIdToSpecifier = accountIdToSpecifier;
27
- const getChainReferenceFromChainId = (chainId) => caip2_1.networkTypeToChainReference[(0, caip2_1.fromCAIP2)(chainId).network];
27
+ const getChainReferenceFromChainId = (chainId) => chainId_1.networkTypeToChainReference[(0, chainId_1.fromChainId)(chainId).network];
28
28
  exports.getChainReferenceFromChainId = getChainReferenceFromChainId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/caip",
3
- "version": "2.5.0",
3
+ "version": "2.5.1",
4
4
  "description": "CAIP Implementation",
5
5
  "homepage": "",
6
6
  "license": "MIT",
@@ -1,19 +0,0 @@
1
- import { CAIP2 } from './../caip2/caip2';
2
- /**
3
- * @deprecated - Temporarily left in place for backwards compatibility, to be replaced with AccountId
4
- */
5
- export declare type CAIP10 = string;
6
- export declare type AccountId = string;
7
- declare type ToCAIP19Args = {
8
- caip2: CAIP2;
9
- account: string;
10
- };
11
- declare type ToCAIP10 = (args: ToCAIP19Args) => string;
12
- export declare const toCAIP10: ToCAIP10;
13
- declare type FromCAIP10Return = {
14
- caip2: string;
15
- account: string;
16
- };
17
- declare type FromCAIP10 = (caip10: string) => FromCAIP10Return;
18
- export declare const fromCAIP10: FromCAIP10;
19
- export {};
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fromCAIP10 = exports.toCAIP10 = void 0;
4
- const caip2_1 = require("./../caip2/caip2");
5
- const toCAIP10 = ({ caip2, account }) => {
6
- if (!(0, caip2_1.isCAIP2)(caip2)) {
7
- throw new Error(`toCAIP10: invalid caip2 ${caip2}`);
8
- }
9
- if (!account) {
10
- throw new Error(`toCAIP10: account is required`);
11
- }
12
- const [namespace] = caip2.split(':');
13
- // we lowercase eth accounts as per the draft spec
14
- // it's not explicit, but cHecKsUM can be recovered from lowercase eth accounts
15
- // we don't lowercase bitcoin addresses as they'll fail checksum
16
- const outputAccount = namespace === caip2_1.ChainNamespace.Ethereum ? account.toLowerCase() : account;
17
- return `${caip2}:${outputAccount}`;
18
- };
19
- exports.toCAIP10 = toCAIP10;
20
- const fromCAIP10 = (caip10) => {
21
- const parts = caip10.split(':');
22
- if (parts.length !== 3) {
23
- throw new Error(`fromCAIP10: invalid caip10 ${caip10}`);
24
- }
25
- const caip2 = parts.slice(0, 2).join(':');
26
- if (!(0, caip2_1.isCAIP2)(caip2)) {
27
- throw new Error(`fromCAIP10: invalid caip2 ${caip2}`);
28
- }
29
- const account = parts[2];
30
- if (!account) {
31
- throw new Error(`fromCAIP10: account required`);
32
- }
33
- const [namespace] = caip2.split(':');
34
- // we lowercase eth accounts as per the draft spec
35
- // it's not explicit, but cHecKsUM can be recovered from lowercase eth accounts
36
- // we don't lowercase bitcoin addresses as they'll fail checksum
37
- const outputAccount = namespace === caip2_1.ChainNamespace.Ethereum ? account.toLowerCase() : account;
38
- return { caip2, account: outputAccount };
39
- };
40
- exports.fromCAIP10 = fromCAIP10;