@shapeshiftoss/caip 1.10.2 → 1.11.3
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/adapters/coincap/generated/cosmos_cosmoshub-4/adapter.json +1 -0
- package/dist/adapters/coincap/generated/cosmos_osmosis-1/adapter.json +1 -0
- package/dist/adapters/coincap/generated/eip155_1/adapter.json +1 -1
- package/dist/adapters/coincap/generated/index.d.ts +3 -1
- package/dist/adapters/coincap/generated/index.js +5 -1
- package/dist/adapters/coincap/utils.d.ts +6 -0
- package/dist/adapters/coincap/utils.js +31 -4
- package/dist/adapters/coingecko/generated/cosmos_cosmoshub-4/adapter.json +1 -0
- package/dist/adapters/coingecko/generated/cosmos_osmosis-1/adapter.json +1 -0
- package/dist/adapters/coingecko/generated/eip155_1/adapter.json +1 -1
- package/dist/adapters/coingecko/generated/index.d.ts +3 -1
- package/dist/adapters/coingecko/generated/index.js +5 -1
- package/dist/adapters/coingecko/utils.d.ts +6 -0
- package/dist/adapters/coingecko/utils.js +31 -4
- package/dist/adapters/yearn/generated/eip155_1/adapter.json +1 -1
- package/dist/caip19/caip19.d.ts +11 -2
- package/dist/caip19/caip19.js +77 -6
- package/dist/caip2/caip2.d.ts +7 -2
- package/dist/caip2/caip2.js +60 -0
- package/package.json +4 -4
package/dist/caip19/caip19.d.ts
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import { ChainTypes, ContractTypes, NetworkTypes } from '@shapeshiftoss/types';
|
|
2
2
|
export declare type CAIP19 = string;
|
|
3
3
|
export declare enum AssetNamespace {
|
|
4
|
+
CW20 = "cw20",
|
|
5
|
+
CW721 = "cw721",
|
|
4
6
|
ERC20 = "erc20",
|
|
5
7
|
ERC721 = "erc721",
|
|
6
|
-
Slip44 = "slip44"
|
|
8
|
+
Slip44 = "slip44",
|
|
9
|
+
NATIVE = "native",
|
|
10
|
+
IBC = "ibc"
|
|
7
11
|
}
|
|
8
12
|
export declare enum AssetReference {
|
|
9
13
|
Bitcoin = 0,
|
|
10
|
-
Ethereum = 60
|
|
14
|
+
Ethereum = 60,
|
|
15
|
+
Cosmos = 118
|
|
11
16
|
}
|
|
12
17
|
declare type ToCAIP19Args = {
|
|
13
18
|
chain: ChainTypes;
|
|
14
19
|
network: NetworkTypes;
|
|
15
20
|
contractType?: ContractTypes;
|
|
16
21
|
tokenId?: string;
|
|
22
|
+
assetNamespace?: AssetNamespace;
|
|
23
|
+
assetReference?: string;
|
|
17
24
|
};
|
|
18
25
|
declare type ToCAIP19 = (args: ToCAIP19Args) => string;
|
|
19
26
|
export declare const toCAIP19: ToCAIP19;
|
|
@@ -22,6 +29,8 @@ declare type FromCAIP19Return = {
|
|
|
22
29
|
network: NetworkTypes;
|
|
23
30
|
contractType?: ContractTypes;
|
|
24
31
|
tokenId?: string;
|
|
32
|
+
assetNamespace?: AssetNamespace;
|
|
33
|
+
assetReference?: string;
|
|
25
34
|
};
|
|
26
35
|
declare type FromCAIP19 = (caip19: string) => FromCAIP19Return;
|
|
27
36
|
export declare const fromCAIP19: FromCAIP19;
|
package/dist/caip19/caip19.js
CHANGED
|
@@ -6,18 +6,40 @@ const types_1 = require("@shapeshiftoss/types");
|
|
|
6
6
|
const caip2_1 = require("./../caip2/caip2");
|
|
7
7
|
var AssetNamespace;
|
|
8
8
|
(function (AssetNamespace) {
|
|
9
|
+
AssetNamespace["CW20"] = "cw20";
|
|
10
|
+
AssetNamespace["CW721"] = "cw721";
|
|
9
11
|
AssetNamespace["ERC20"] = "erc20";
|
|
10
12
|
AssetNamespace["ERC721"] = "erc721";
|
|
11
13
|
AssetNamespace["Slip44"] = "slip44";
|
|
14
|
+
AssetNamespace["NATIVE"] = "native";
|
|
15
|
+
AssetNamespace["IBC"] = "ibc";
|
|
12
16
|
})(AssetNamespace = exports.AssetNamespace || (exports.AssetNamespace = {}));
|
|
13
17
|
var AssetReference;
|
|
14
18
|
(function (AssetReference) {
|
|
15
19
|
AssetReference[AssetReference["Bitcoin"] = 0] = "Bitcoin";
|
|
16
20
|
AssetReference[AssetReference["Ethereum"] = 60] = "Ethereum";
|
|
21
|
+
AssetReference[AssetReference["Cosmos"] = 118] = "Cosmos";
|
|
17
22
|
})(AssetReference = exports.AssetReference || (exports.AssetReference = {}));
|
|
18
|
-
const toCAIP19 = ({ chain, network, contractType, tokenId }) => {
|
|
23
|
+
const toCAIP19 = ({ chain, network, contractType, tokenId, assetNamespace, assetReference }) => {
|
|
19
24
|
const caip2 = (0, caip2_1.toCAIP2)({ chain, network });
|
|
20
25
|
switch (chain) {
|
|
26
|
+
// TODO: There is no chain-level fungible token standard in Cosmos SDK, but CosmWasm chains have CW20/CW721
|
|
27
|
+
// This should be implemented when we want to support tokens for Cosmos SDK chains
|
|
28
|
+
case types_1.ChainTypes.Cosmos: {
|
|
29
|
+
if (!assetNamespace || !assetReference) {
|
|
30
|
+
return `${caip2}/${AssetNamespace.Slip44}:${AssetReference.Cosmos}`;
|
|
31
|
+
}
|
|
32
|
+
switch (assetNamespace) {
|
|
33
|
+
case AssetNamespace.CW20:
|
|
34
|
+
case AssetNamespace.CW721:
|
|
35
|
+
case AssetNamespace.IBC:
|
|
36
|
+
case AssetNamespace.NATIVE:
|
|
37
|
+
return `${caip2}/${assetNamespace}:${assetReference}`;
|
|
38
|
+
default: {
|
|
39
|
+
throw new Error(`Could not construct CAIP19 chain: ${chain}, network: ${network}, assetNamespace: ${assetNamespace}, assetReference: ${assetReference}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
21
43
|
case types_1.ChainTypes.Ethereum: {
|
|
22
44
|
tokenId = tokenId === null || tokenId === void 0 ? void 0 : tokenId.toLowerCase();
|
|
23
45
|
if (contractType) {
|
|
@@ -57,6 +79,9 @@ const toCAIP19 = ({ chain, network, contractType, tokenId }) => {
|
|
|
57
79
|
case types_1.ChainTypes.Bitcoin: {
|
|
58
80
|
return `${caip2}/${AssetNamespace.Slip44}:${AssetReference.Bitcoin}`;
|
|
59
81
|
}
|
|
82
|
+
default: {
|
|
83
|
+
throw new Error(`Chain type not supported: ${chain}`);
|
|
84
|
+
}
|
|
60
85
|
}
|
|
61
86
|
};
|
|
62
87
|
exports.toCAIP19 = toCAIP19;
|
|
@@ -79,16 +104,13 @@ const fromCAIP19 = (caip19) => {
|
|
|
79
104
|
case AssetReference.Bitcoin: {
|
|
80
105
|
return { chain, network };
|
|
81
106
|
}
|
|
82
|
-
case AssetReference.Ethereum:
|
|
83
107
|
default: {
|
|
84
108
|
throw new Error(`fromCAIP19: invalid asset reference ${reference} on chain ${chain}`);
|
|
85
109
|
}
|
|
86
110
|
}
|
|
87
111
|
}
|
|
88
|
-
case AssetNamespace.ERC20:
|
|
89
|
-
case AssetNamespace.ERC721:
|
|
90
112
|
default: {
|
|
91
|
-
throw new Error(`fromCAIP19: invalid asset
|
|
113
|
+
throw new Error(`fromCAIP19: invalid asset namespace ${namespace} on chain ${chain}`);
|
|
92
114
|
}
|
|
93
115
|
}
|
|
94
116
|
}
|
|
@@ -99,7 +121,6 @@ const fromCAIP19 = (caip19) => {
|
|
|
99
121
|
case AssetReference.Ethereum: {
|
|
100
122
|
return { chain, network };
|
|
101
123
|
}
|
|
102
|
-
case AssetReference.Bitcoin:
|
|
103
124
|
default: {
|
|
104
125
|
throw new Error(`fromCAIP19: invalid asset reference ${reference} on chain ${chain}`);
|
|
105
126
|
}
|
|
@@ -115,6 +136,56 @@ const fromCAIP19 = (caip19) => {
|
|
|
115
136
|
const tokenId = referenceString.toLowerCase();
|
|
116
137
|
return { chain, network, contractType, tokenId };
|
|
117
138
|
}
|
|
139
|
+
default: {
|
|
140
|
+
throw new Error(`fromCAIP19: invalid asset namespace ${namespace} on chain ${chain}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
case types_1.ChainTypes.Cosmos: {
|
|
145
|
+
switch (namespace) {
|
|
146
|
+
case AssetNamespace.Slip44: {
|
|
147
|
+
switch (reference) {
|
|
148
|
+
case AssetReference.Cosmos: {
|
|
149
|
+
return { chain, network };
|
|
150
|
+
}
|
|
151
|
+
case AssetReference.Ethereum:
|
|
152
|
+
case AssetReference.Bitcoin:
|
|
153
|
+
default: {
|
|
154
|
+
throw new Error(`fromCAIP19: invalid asset namespace ${namespace} on chain ${chain}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
case AssetNamespace.CW20:
|
|
159
|
+
return {
|
|
160
|
+
chain,
|
|
161
|
+
network,
|
|
162
|
+
assetNamespace: AssetNamespace.CW20,
|
|
163
|
+
assetReference: referenceString
|
|
164
|
+
};
|
|
165
|
+
case AssetNamespace.CW721:
|
|
166
|
+
return {
|
|
167
|
+
chain,
|
|
168
|
+
network,
|
|
169
|
+
assetNamespace: AssetNamespace.CW721,
|
|
170
|
+
assetReference: referenceString
|
|
171
|
+
};
|
|
172
|
+
case AssetNamespace.IBC:
|
|
173
|
+
return {
|
|
174
|
+
chain,
|
|
175
|
+
network,
|
|
176
|
+
assetNamespace: AssetNamespace.IBC,
|
|
177
|
+
assetReference: referenceString
|
|
178
|
+
};
|
|
179
|
+
case AssetNamespace.NATIVE:
|
|
180
|
+
return {
|
|
181
|
+
chain,
|
|
182
|
+
network,
|
|
183
|
+
assetNamespace: AssetNamespace.NATIVE,
|
|
184
|
+
assetReference: referenceString
|
|
185
|
+
};
|
|
186
|
+
default: {
|
|
187
|
+
throw new Error(`fromCAIP19: invalid asset namespace ${namespace} on chain ${chain}`);
|
|
188
|
+
}
|
|
118
189
|
}
|
|
119
190
|
}
|
|
120
191
|
}
|
package/dist/caip2/caip2.d.ts
CHANGED
|
@@ -2,14 +2,19 @@ import { ChainTypes, NetworkTypes } from '@shapeshiftoss/types';
|
|
|
2
2
|
export declare type CAIP2 = string;
|
|
3
3
|
export declare enum ChainNamespace {
|
|
4
4
|
Ethereum = "eip155",
|
|
5
|
-
Bitcoin = "bip122"
|
|
5
|
+
Bitcoin = "bip122",
|
|
6
|
+
Cosmos = "cosmos"
|
|
6
7
|
}
|
|
7
8
|
export declare enum ChainReference {
|
|
8
9
|
EthereumMainnet = "1",
|
|
9
10
|
EthereumRopsten = "3",
|
|
10
11
|
EthereumRinkeby = "4",
|
|
11
12
|
BitcoinMainnet = "000000000019d6689c085ae165831e93",
|
|
12
|
-
BitcoinTestnet = "000000000933ea01ad0ee984209779ba"
|
|
13
|
+
BitcoinTestnet = "000000000933ea01ad0ee984209779ba",
|
|
14
|
+
CosmosHubMainnet = "cosmoshub-4",
|
|
15
|
+
CosmosHubVega = "vega-testnet",
|
|
16
|
+
OsmosisMainnet = "osmosis-1",
|
|
17
|
+
OsmosisTestnet = "osmo-testnet-1"
|
|
13
18
|
}
|
|
14
19
|
declare type ToCAIP2Args = {
|
|
15
20
|
chain: ChainTypes;
|
package/dist/caip2/caip2.js
CHANGED
|
@@ -7,6 +7,7 @@ var ChainNamespace;
|
|
|
7
7
|
(function (ChainNamespace) {
|
|
8
8
|
ChainNamespace["Ethereum"] = "eip155";
|
|
9
9
|
ChainNamespace["Bitcoin"] = "bip122";
|
|
10
|
+
ChainNamespace["Cosmos"] = "cosmos";
|
|
10
11
|
})(ChainNamespace = exports.ChainNamespace || (exports.ChainNamespace = {}));
|
|
11
12
|
var ChainReference;
|
|
12
13
|
(function (ChainReference) {
|
|
@@ -18,6 +19,10 @@ var ChainReference;
|
|
|
18
19
|
// caip2 uses max length of 32 chars of the genesis block
|
|
19
20
|
ChainReference["BitcoinMainnet"] = "000000000019d6689c085ae165831e93";
|
|
20
21
|
ChainReference["BitcoinTestnet"] = "000000000933ea01ad0ee984209779ba";
|
|
22
|
+
ChainReference["CosmosHubMainnet"] = "cosmoshub-4";
|
|
23
|
+
ChainReference["CosmosHubVega"] = "vega-testnet";
|
|
24
|
+
ChainReference["OsmosisMainnet"] = "osmosis-1";
|
|
25
|
+
ChainReference["OsmosisTestnet"] = "osmo-testnet-1";
|
|
21
26
|
})(ChainReference = exports.ChainReference || (exports.ChainReference = {}));
|
|
22
27
|
const toCAIP2 = ({ chain, network }) => {
|
|
23
28
|
const shapeShiftToCAIP2 = {
|
|
@@ -35,10 +40,33 @@ const toCAIP2 = ({ chain, network }) => {
|
|
|
35
40
|
[types_1.NetworkTypes.MAINNET]: ChainReference.BitcoinMainnet,
|
|
36
41
|
[types_1.NetworkTypes.TESTNET]: ChainReference.BitcoinTestnet
|
|
37
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
|
+
}
|
|
38
52
|
}
|
|
39
53
|
};
|
|
40
54
|
const namespace = shapeShiftToCAIP2[chain].namespace;
|
|
41
55
|
switch (chain) {
|
|
56
|
+
case types_1.ChainTypes.Cosmos: {
|
|
57
|
+
const referenceMap = shapeShiftToCAIP2[chain].reference;
|
|
58
|
+
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: {
|
|
63
|
+
const reference = referenceMap[network];
|
|
64
|
+
const caip2 = `${namespace}:${reference}`;
|
|
65
|
+
return caip2;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
42
70
|
case types_1.ChainTypes.Ethereum: {
|
|
43
71
|
const referenceMap = shapeShiftToCAIP2[chain].reference;
|
|
44
72
|
switch (network) {
|
|
@@ -73,6 +101,30 @@ const fromCAIP2 = (caip2) => {
|
|
|
73
101
|
throw new Error(`fromCAIP19: error parsing caip19, chain: ${c}, network: ${n}`);
|
|
74
102
|
}
|
|
75
103
|
switch (c) {
|
|
104
|
+
case ChainNamespace.Cosmos: {
|
|
105
|
+
const chain = types_1.ChainTypes.Cosmos;
|
|
106
|
+
switch (n) {
|
|
107
|
+
case ChainReference.CosmosHubMainnet: {
|
|
108
|
+
const network = types_1.NetworkTypes.COSMOSHUB_MAINNET;
|
|
109
|
+
return { chain, network };
|
|
110
|
+
}
|
|
111
|
+
case ChainReference.CosmosHubVega: {
|
|
112
|
+
const network = types_1.NetworkTypes.COSMOSHUB_VEGA;
|
|
113
|
+
return { chain, network };
|
|
114
|
+
}
|
|
115
|
+
case ChainReference.OsmosisMainnet: {
|
|
116
|
+
const network = types_1.NetworkTypes.OSMOSIS_MAINNET;
|
|
117
|
+
return { chain, network };
|
|
118
|
+
}
|
|
119
|
+
case ChainReference.OsmosisTestnet: {
|
|
120
|
+
const network = types_1.NetworkTypes.OSMOSIS_TESTNET;
|
|
121
|
+
return { chain, network };
|
|
122
|
+
}
|
|
123
|
+
default: {
|
|
124
|
+
throw new Error(`fromCAIP19: unsupported ${c} network: ${n}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
76
128
|
case ChainNamespace.Ethereum: {
|
|
77
129
|
const chain = types_1.ChainTypes.Ethereum;
|
|
78
130
|
switch (n) {
|
|
@@ -119,6 +171,14 @@ const isCAIP2 = (caip2) => {
|
|
|
119
171
|
throw new Error(`isCAIP2: error parsing caip19, chain: ${c}, network: ${n}`);
|
|
120
172
|
}
|
|
121
173
|
switch (c) {
|
|
174
|
+
case ChainNamespace.Cosmos: {
|
|
175
|
+
switch (n) {
|
|
176
|
+
case ChainReference.CosmosHubMainnet:
|
|
177
|
+
case ChainReference.CosmosHubVega:
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
122
182
|
case ChainNamespace.Ethereum: {
|
|
123
183
|
switch (n) {
|
|
124
184
|
case ChainReference.EthereumMainnet:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshiftoss/caip",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.3",
|
|
4
4
|
"description": "CAIP Implementation",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@shapeshiftoss/types": "^1.
|
|
32
|
+
"@shapeshiftoss/types": "^1.23.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@shapeshiftoss/types": "^1.
|
|
35
|
+
"@shapeshiftoss/types": "^1.23.0",
|
|
36
36
|
"@yfi/sdk": "^1.0.27",
|
|
37
|
-
"axios": "^0.
|
|
37
|
+
"axios": "^0.26.0"
|
|
38
38
|
}
|
|
39
39
|
}
|