@shapeshiftoss/caip 1.11.3 → 1.11.4

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.
@@ -8,7 +8,7 @@ const types_1 = require("@shapeshiftoss/types");
8
8
  const axios_1 = __importDefault(require("axios"));
9
9
  const fs_1 = __importDefault(require("fs"));
10
10
  const caip2_1 = require("../../caip2/caip2");
11
- const caip19_1 = require("./../../caip19/caip19");
11
+ const caip19_1 = require("../../caip19/caip19");
12
12
  const writeFiles = async (data) => {
13
13
  const path = './src/adapters/coincap/generated/';
14
14
  const file = '/adapter.json';
@@ -24,7 +24,7 @@ const parseEthData = (data) => {
24
24
  const chain = types_1.ChainTypes.Ethereum;
25
25
  const network = types_1.NetworkTypes.MAINNET;
26
26
  const contractType = types_1.ContractTypes.ERC20;
27
- const result = ethCoins.reduce((acc, { id, explorer }) => {
27
+ return ethCoins.reduce((acc, { id, explorer }) => {
28
28
  let tokenId;
29
29
  if (id !== 'ethereum' && explorer) {
30
30
  tokenId = explorer.replace('https://etherscan.io/token/', '').split('#')[0].split('?')[0];
@@ -33,7 +33,6 @@ const parseEthData = (data) => {
33
33
  acc[caip19] = id;
34
34
  return acc;
35
35
  }, {});
36
- return result;
37
36
  };
38
37
  exports.parseEthData = parseEthData;
39
38
  const makeBtcData = () => {
@@ -51,7 +50,7 @@ const makeCosmosHubData = () => {
51
50
  };
52
51
  exports.makeCosmosHubData = makeCosmosHubData;
53
52
  const makeOsmosisData = () => {
54
- const chain = types_1.ChainTypes.Cosmos;
53
+ const chain = types_1.ChainTypes.Osmosis;
55
54
  const network = types_1.NetworkTypes.OSMOSIS_MAINNET;
56
55
  const caip19 = (0, caip19_1.toCAIP19)({ chain, network });
57
56
  return { [caip19]: 'osmosis' };
@@ -65,7 +64,7 @@ const parseData = (d) => {
65
64
  network: types_1.NetworkTypes.COSMOSHUB_MAINNET
66
65
  });
67
66
  const osmosisMainnet = (0, caip2_1.toCAIP2)({
68
- chain: types_1.ChainTypes.Cosmos,
67
+ chain: types_1.ChainTypes.Osmosis,
69
68
  network: types_1.NetworkTypes.OSMOSIS_MAINNET
70
69
  });
71
70
  return {
@@ -8,7 +8,7 @@ const types_1 = require("@shapeshiftoss/types");
8
8
  const axios_1 = __importDefault(require("axios"));
9
9
  const fs_1 = __importDefault(require("fs"));
10
10
  const caip2_1 = require("../../caip2/caip2");
11
- const caip19_1 = require("./../../caip19/caip19");
11
+ const caip19_1 = require("../../caip19/caip19");
12
12
  const writeFiles = async (data) => {
13
13
  const path = './src/adapters/coingecko/generated/';
14
14
  const file = '/adapter.json';
@@ -24,13 +24,12 @@ const parseEthData = (data) => {
24
24
  const chain = types_1.ChainTypes.Ethereum;
25
25
  const network = types_1.NetworkTypes.MAINNET;
26
26
  const contractType = types_1.ContractTypes.ERC20;
27
- const result = ethCoins.reduce((acc, { id, platforms }) => {
27
+ return ethCoins.reduce((acc, { id, platforms }) => {
28
28
  const tokenId = platforms === null || platforms === void 0 ? void 0 : platforms.ethereum;
29
29
  const caip19 = (0, caip19_1.toCAIP19)({ chain, network, ...(tokenId ? { contractType, tokenId } : {}) });
30
30
  acc[caip19] = id;
31
31
  return acc;
32
32
  }, {});
33
- return result;
34
33
  };
35
34
  exports.parseEthData = parseEthData;
36
35
  const makeBtcData = () => {
@@ -48,7 +47,7 @@ const makeCosmosHubData = () => {
48
47
  };
49
48
  exports.makeCosmosHubData = makeCosmosHubData;
50
49
  const makeOsmosisData = () => {
51
- const chain = types_1.ChainTypes.Cosmos;
50
+ const chain = types_1.ChainTypes.Osmosis;
52
51
  const network = types_1.NetworkTypes.OSMOSIS_MAINNET;
53
52
  const caip19 = (0, caip19_1.toCAIP19)({ chain, network });
54
53
  return { [caip19]: 'osmosis' };
@@ -62,7 +61,7 @@ const parseData = (d) => {
62
61
  network: types_1.NetworkTypes.COSMOSHUB_MAINNET
63
62
  });
64
63
  const osmosisMainnet = (0, caip2_1.toCAIP2)({
65
- chain: types_1.ChainTypes.Cosmos,
64
+ chain: types_1.ChainTypes.Osmosis,
66
65
  network: types_1.NetworkTypes.OSMOSIS_MAINNET
67
66
  });
68
67
  return {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.fromCAIP19 = exports.toCAIP19 = exports.AssetReference = exports.AssetNamespace = void 0;
5
5
  const types_1 = require("@shapeshiftoss/types");
6
- const caip2_1 = require("./../caip2/caip2");
6
+ const caip2_1 = require("../caip2/caip2");
7
7
  var AssetNamespace;
8
8
  (function (AssetNamespace) {
9
9
  AssetNamespace["CW20"] = "cw20";
@@ -25,7 +25,8 @@ const toCAIP19 = ({ chain, network, contractType, tokenId, assetNamespace, asset
25
25
  switch (chain) {
26
26
  // TODO: There is no chain-level fungible token standard in Cosmos SDK, but CosmWasm chains have CW20/CW721
27
27
  // This should be implemented when we want to support tokens for Cosmos SDK chains
28
- case types_1.ChainTypes.Cosmos: {
28
+ case types_1.ChainTypes.Cosmos:
29
+ case types_1.ChainTypes.Osmosis: {
29
30
  if (!assetNamespace || !assetReference) {
30
31
  return `${caip2}/${AssetNamespace.Slip44}:${AssetReference.Cosmos}`;
31
32
  }
@@ -141,6 +142,7 @@ const fromCAIP19 = (caip19) => {
141
142
  }
142
143
  }
143
144
  }
145
+ case types_1.ChainTypes.Osmosis:
144
146
  case types_1.ChainTypes.Cosmos: {
145
147
  switch (namespace) {
146
148
  case AssetNamespace.Slip44: {
@@ -20,8 +20,7 @@ declare type ToCAIP2Args = {
20
20
  chain: ChainTypes;
21
21
  network: NetworkTypes;
22
22
  };
23
- declare type ToCAIP2 = (args: ToCAIP2Args) => string;
24
- export declare const toCAIP2: ToCAIP2;
23
+ export declare const toCAIP2: (args: ToCAIP2Args) => string;
25
24
  declare type FromCAIP2Return = {
26
25
  chain: ChainTypes;
27
26
  network: NetworkTypes;
@@ -24,72 +24,85 @@ var ChainReference;
24
24
  ChainReference["OsmosisMainnet"] = "osmosis-1";
25
25
  ChainReference["OsmosisTestnet"] = "osmo-testnet-1";
26
26
  })(ChainReference = exports.ChainReference || (exports.ChainReference = {}));
27
- const toCAIP2 = ({ chain, network }) => {
28
- const shapeShiftToCAIP2 = {
29
- [types_1.ChainTypes.Ethereum]: {
30
- namespace: ChainNamespace.Ethereum,
31
- reference: {
32
- [types_1.NetworkTypes.MAINNET]: ChainReference.EthereumMainnet,
33
- [types_1.NetworkTypes.ETH_ROPSTEN]: ChainReference.EthereumRopsten,
34
- [types_1.NetworkTypes.ETH_RINKEBY]: ChainReference.EthereumRinkeby
35
- }
36
- },
37
- [types_1.ChainTypes.Bitcoin]: {
38
- namespace: ChainNamespace.Bitcoin,
39
- reference: {
40
- [types_1.NetworkTypes.MAINNET]: ChainReference.BitcoinMainnet,
41
- [types_1.NetworkTypes.TESTNET]: ChainReference.BitcoinTestnet
42
- }
43
- },
44
- [types_1.ChainTypes.Cosmos]: {
45
- namespace: ChainNamespace.Cosmos,
46
- reference: {
47
- [types_1.NetworkTypes.COSMOSHUB_MAINNET]: ChainReference.CosmosHubMainnet,
48
- [types_1.NetworkTypes.COSMOSHUB_VEGA]: ChainReference.CosmosHubVega,
49
- [types_1.NetworkTypes.OSMOSIS_MAINNET]: ChainReference.OsmosisMainnet,
50
- [types_1.NetworkTypes.OSMOSIS_TESTNET]: ChainReference.OsmosisTestnet
51
- }
27
+ const shapeShiftToCAIP2 = Object.freeze({
28
+ [types_1.ChainTypes.Ethereum]: {
29
+ namespace: ChainNamespace.Ethereum,
30
+ reference: {
31
+ [types_1.NetworkTypes.MAINNET]: ChainReference.EthereumMainnet,
32
+ [types_1.NetworkTypes.ETH_ROPSTEN]: ChainReference.EthereumRopsten,
33
+ [types_1.NetworkTypes.ETH_RINKEBY]: ChainReference.EthereumRinkeby
34
+ }
35
+ },
36
+ [types_1.ChainTypes.Bitcoin]: {
37
+ namespace: ChainNamespace.Bitcoin,
38
+ reference: {
39
+ [types_1.NetworkTypes.MAINNET]: ChainReference.BitcoinMainnet,
40
+ [types_1.NetworkTypes.TESTNET]: ChainReference.BitcoinTestnet
41
+ }
42
+ },
43
+ [types_1.ChainTypes.Cosmos]: {
44
+ namespace: ChainNamespace.Cosmos,
45
+ reference: {
46
+ [types_1.NetworkTypes.COSMOSHUB_MAINNET]: ChainReference.CosmosHubMainnet,
47
+ [types_1.NetworkTypes.COSMOSHUB_VEGA]: ChainReference.CosmosHubVega
52
48
  }
53
- };
49
+ },
50
+ [types_1.ChainTypes.Osmosis]: {
51
+ namespace: ChainNamespace.Cosmos,
52
+ reference: {
53
+ [types_1.NetworkTypes.OSMOSIS_MAINNET]: ChainReference.OsmosisMainnet,
54
+ [types_1.NetworkTypes.OSMOSIS_TESTNET]: ChainReference.OsmosisTestnet
55
+ }
56
+ }
57
+ });
58
+ const toCAIP2 = (args) => {
59
+ const { chain, network } = args;
54
60
  const namespace = shapeShiftToCAIP2[chain].namespace;
55
61
  switch (chain) {
56
- case types_1.ChainTypes.Cosmos: {
62
+ case types_1.ChainTypes.Ethereum: {
57
63
  const referenceMap = shapeShiftToCAIP2[chain].reference;
58
64
  switch (network) {
59
- case types_1.NetworkTypes.COSMOSHUB_MAINNET:
60
- case types_1.NetworkTypes.COSMOSHUB_VEGA:
61
- case types_1.NetworkTypes.OSMOSIS_MAINNET:
62
- case types_1.NetworkTypes.OSMOSIS_TESTNET: {
65
+ case types_1.NetworkTypes.MAINNET:
66
+ case types_1.NetworkTypes.ETH_ROPSTEN:
67
+ case types_1.NetworkTypes.ETH_RINKEBY: {
63
68
  const reference = referenceMap[network];
64
- const caip2 = `${namespace}:${reference}`;
65
- return caip2;
69
+ return `${namespace}:${reference}`;
66
70
  }
67
71
  }
68
72
  break;
69
73
  }
70
- case types_1.ChainTypes.Ethereum: {
74
+ case types_1.ChainTypes.Bitcoin: {
71
75
  const referenceMap = shapeShiftToCAIP2[chain].reference;
72
76
  switch (network) {
73
77
  case types_1.NetworkTypes.MAINNET:
74
- case types_1.NetworkTypes.ETH_ROPSTEN:
75
- case types_1.NetworkTypes.ETH_RINKEBY: {
78
+ case types_1.NetworkTypes.TESTNET: {
76
79
  const reference = referenceMap[network];
77
- const caip2 = `${namespace}:${reference}`;
78
- return caip2;
80
+ return `${namespace}:${reference}`;
79
81
  }
80
82
  }
81
83
  break;
82
84
  }
83
- case types_1.ChainTypes.Bitcoin: {
85
+ case types_1.ChainTypes.Cosmos: {
84
86
  const referenceMap = shapeShiftToCAIP2[chain].reference;
85
87
  switch (network) {
86
- case types_1.NetworkTypes.MAINNET:
87
- case types_1.NetworkTypes.TESTNET: {
88
+ case types_1.NetworkTypes.COSMOSHUB_MAINNET:
89
+ case types_1.NetworkTypes.COSMOSHUB_VEGA: {
90
+ const reference = referenceMap[network];
91
+ return `${namespace}:${reference}`;
92
+ }
93
+ }
94
+ break;
95
+ }
96
+ case types_1.ChainTypes.Osmosis: {
97
+ const referenceMap = shapeShiftToCAIP2[chain].reference;
98
+ switch (network) {
99
+ case types_1.NetworkTypes.OSMOSIS_MAINNET:
100
+ case types_1.NetworkTypes.OSMOSIS_TESTNET: {
88
101
  const reference = referenceMap[network];
89
- const caip2 = `${namespace}:${reference}`;
90
- return caip2;
102
+ return `${namespace}:${reference}`;
91
103
  }
92
104
  }
105
+ break;
93
106
  }
94
107
  }
95
108
  throw new Error(`toCAIP2: unsupported ${chain} network: ${network}`);
@@ -102,23 +115,18 @@ const fromCAIP2 = (caip2) => {
102
115
  }
103
116
  switch (c) {
104
117
  case ChainNamespace.Cosmos: {
105
- const chain = types_1.ChainTypes.Cosmos;
106
118
  switch (n) {
107
119
  case ChainReference.CosmosHubMainnet: {
108
- const network = types_1.NetworkTypes.COSMOSHUB_MAINNET;
109
- return { chain, network };
120
+ return { chain: types_1.ChainTypes.Cosmos, network: types_1.NetworkTypes.COSMOSHUB_MAINNET };
110
121
  }
111
122
  case ChainReference.CosmosHubVega: {
112
- const network = types_1.NetworkTypes.COSMOSHUB_VEGA;
113
- return { chain, network };
123
+ return { chain: types_1.ChainTypes.Cosmos, network: types_1.NetworkTypes.COSMOSHUB_VEGA };
114
124
  }
115
125
  case ChainReference.OsmosisMainnet: {
116
- const network = types_1.NetworkTypes.OSMOSIS_MAINNET;
117
- return { chain, network };
126
+ return { chain: types_1.ChainTypes.Osmosis, network: types_1.NetworkTypes.OSMOSIS_MAINNET };
118
127
  }
119
128
  case ChainReference.OsmosisTestnet: {
120
- const network = types_1.NetworkTypes.OSMOSIS_TESTNET;
121
- return { chain, network };
129
+ return { chain: types_1.ChainTypes.Osmosis, network: types_1.NetworkTypes.OSMOSIS_TESTNET };
122
130
  }
123
131
  default: {
124
132
  throw new Error(`fromCAIP19: unsupported ${c} network: ${n}`);
@@ -175,6 +183,8 @@ const isCAIP2 = (caip2) => {
175
183
  switch (n) {
176
184
  case ChainReference.CosmosHubMainnet:
177
185
  case ChainReference.CosmosHubVega:
186
+ case ChainReference.OsmosisMainnet:
187
+ case ChainReference.OsmosisTestnet:
178
188
  return true;
179
189
  }
180
190
  break;
@@ -194,6 +204,7 @@ const isCAIP2 = (caip2) => {
194
204
  case ChainReference.BitcoinTestnet:
195
205
  return true;
196
206
  }
207
+ break;
197
208
  }
198
209
  }
199
210
  throw new Error(`isCAIP2: invalid caip2 ${caip2}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/caip",
3
- "version": "1.11.3",
3
+ "version": "1.11.4",
4
4
  "description": "CAIP Implementation",
5
5
  "homepage": "",
6
6
  "license": "MIT",