@shapeshiftoss/caip 4.0.0 → 5.0.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 +43 -34
- package/dist/accountId/accountId.d.ts +16 -5
- package/dist/accountId/accountId.js +15 -14
- package/dist/adapters/banxa/index.js +3 -5
- package/dist/adapters/coincap/utils.d.ts +10 -10
- package/dist/adapters/coincap/utils.js +11 -57
- package/dist/adapters/coingecko/utils.d.ts +10 -10
- package/dist/adapters/coingecko/utils.js +11 -57
- package/dist/adapters/osmosis/utils.js +7 -7
- package/dist/adapters/yearn/utils.js +9 -5
- package/dist/assetId/assetId.d.ts +19 -16
- package/dist/assetId/assetId.js +65 -66
- package/dist/chainId/chainId.d.ts +7 -28
- package/dist/chainId/chainId.js +11 -222
- package/dist/constants.d.ts +42 -0
- package/dist/constants.js +64 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/typeGuards.d.ts +14 -0
- package/dist/typeGuards.js +48 -0
- package/dist/utils.d.ts +14 -9
- package/dist/utils.js +57 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @shapeshiftoss/caip
|
|
2
2
|
|
|
3
3
|
This package is ShapeShift's partial implementation of [CAIPs](https://github.com/ChainAgnostic/CAIPs) - Chain Agnostic Improvement Protocols.
|
|
4
4
|
It is not exhaustive and is currently only used internally.
|
|
@@ -12,19 +12,19 @@ Usage
|
|
|
12
12
|
### `toChainId` | `toCAIP2`
|
|
13
13
|
|
|
14
14
|
```ts
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const result = toChainId({
|
|
15
|
+
const chainNamespace = CHAIN_NAMESPACE.Ethereum
|
|
16
|
+
const chainReference = CHAIN_REFERENCE.EthereumMainnet
|
|
17
|
+
const result = toChainId({ chainNamespace, chainReference })
|
|
18
18
|
expect(result).toEqual('eip155:1')
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
### `fromChainId` | `fromCAIP2`
|
|
22
22
|
|
|
23
23
|
```ts
|
|
24
|
-
const
|
|
25
|
-
const {
|
|
26
|
-
expect(
|
|
27
|
-
expect(
|
|
24
|
+
const ethereumChainId = 'eip155:1'
|
|
25
|
+
const { chainNamespace, chainReference } = fromChainId(ethereumChainId)
|
|
26
|
+
expect(chainNamespace).toEqual(CHAIN_NAMESPACE.Ethereum)
|
|
27
|
+
expect(chainReference).toEqual(CHAIN_REFERENCE.EthereumMainnet)
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
## AccountId (CAIP10) - Blockchain ID Specification
|
|
@@ -36,19 +36,24 @@ Usage
|
|
|
36
36
|
### `toAccountId` | `toCAIP10`
|
|
37
37
|
|
|
38
38
|
```ts
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
|
|
39
|
+
const chainNamespace = CHAIN_NAMESPACE.Ethereum
|
|
40
|
+
const chainReference = CHAIN_REFERENCE.EthereumMainnet
|
|
41
|
+
const chainId = toChainId({ chainNamespace, chainReference })
|
|
42
|
+
const account = '0xa44c286ba83bb771cd0107b2c1df678435bd1535'
|
|
43
|
+
const expectedAccountId = `${chainId}:${account}`
|
|
44
|
+
expect(toAccountId({ chainId, account })).toEqual('eip155:1:0xa44c286ba83bb771cd0107b2c1df678435bd1535')
|
|
45
|
+
expect(toAccountId({ chainNamespace, chainReference, account })).toEqual('eip155:1:0xa44c286ba83bb771cd0107b2c1df678435bd1535')
|
|
43
46
|
```
|
|
44
47
|
|
|
45
48
|
### `fromAccountId` | `fromCAIP10`
|
|
46
49
|
|
|
47
50
|
```ts
|
|
48
51
|
const accountId = 'eip155:1:0xa44c286ba83bb771cd0107b2c1df678435bd1535'
|
|
49
|
-
const { chainId,
|
|
52
|
+
const { account, chainId, chainNamespace, chainReference } = fromAccountId(accountId)
|
|
53
|
+
expect(account).toEqual(0xa44c286ba83bb771cd0107b2c1df678435bd1535)
|
|
54
|
+
expect(chainNamespace).toEqual('eip155')
|
|
55
|
+
expect(chainReference).toEqual('1')
|
|
50
56
|
expect(chainId).toEqual('eip155:1')
|
|
51
|
-
expect(account).toEqual('0xa44c286ba83bb771cd0107b2c1df678435bd1535')
|
|
52
57
|
```
|
|
53
58
|
|
|
54
59
|
## AssetId (CAIP19) - Asset Type and Asset ID Specification
|
|
@@ -62,23 +67,25 @@ Usage
|
|
|
62
67
|
Ether
|
|
63
68
|
|
|
64
69
|
```ts
|
|
65
|
-
const
|
|
66
|
-
const
|
|
70
|
+
const chainNamespace = CHAIN_NAMESPACE.Ethereum
|
|
71
|
+
const chainReference = CHAIN_REFERENCE.EthereumMainnet
|
|
72
|
+
const chainId = toChainId({ chainNamespace, chainReference })
|
|
67
73
|
const assetNamespace = 'slip44'
|
|
68
74
|
const assetReference = ASSET_REFERENCE.Ethereum
|
|
69
|
-
|
|
70
|
-
expect(
|
|
75
|
+
expect(toAssetId({ chainNamespace, chainReference, assetNamespace, assetReference })).toEqual('eip155:1/slip44:60')
|
|
76
|
+
expect(toAssetId({ chainId, assetNamespace, assetReference })).toEqual('eip155:1/slip44:60')
|
|
71
77
|
```
|
|
72
78
|
|
|
73
79
|
ERC20 token
|
|
74
80
|
|
|
75
81
|
```ts
|
|
76
|
-
const
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
expect(
|
|
82
|
+
const chainNamespace = CHAIN_NAMESPACE.Ethereum
|
|
83
|
+
const chainReference = CHAIN_REFERENCE.EthereumMainnet
|
|
84
|
+
const chainId = toChainId({ chainNamespace, chainReference })
|
|
85
|
+
const assetNamespace = 'erc20'
|
|
86
|
+
const assetReference = '0xc770eefad204b5180df6a14ee197d99d808ee52d'
|
|
87
|
+
expect(toAssetId({ chainNamespace, chainReference, assetNamespace, assetReference })).toEqual('eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d')
|
|
88
|
+
expect(toAssetId({ chainId, assetNamespace, assetReference })).toEqual('eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d')
|
|
82
89
|
```
|
|
83
90
|
|
|
84
91
|
### `fromAssetId` | `fromCAIP19`
|
|
@@ -87,22 +94,24 @@ Ether
|
|
|
87
94
|
|
|
88
95
|
```ts
|
|
89
96
|
const assetId = 'eip155:1/slip44:60'
|
|
90
|
-
const {
|
|
91
|
-
expect(
|
|
92
|
-
expect(
|
|
93
|
-
expect(
|
|
94
|
-
expect(
|
|
97
|
+
const { chainId, chainReference, chainNamespace, assetNamespace, assetReference } = fromAssetId(AssetId)
|
|
98
|
+
expect(chainNamespace).toEqual('eip155')
|
|
99
|
+
expect(chainReference).toEqual('1')
|
|
100
|
+
expect(chainId).toEqual('eip155:1')
|
|
101
|
+
expect(assetNamespace).toEqual('slip44')
|
|
102
|
+
expect(assetReference).toEqual('60')
|
|
95
103
|
```
|
|
96
104
|
|
|
97
105
|
ERC20 token
|
|
98
106
|
|
|
99
107
|
```ts
|
|
100
108
|
const assetId = 'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d'
|
|
101
|
-
const {
|
|
102
|
-
expect(
|
|
103
|
-
expect(
|
|
104
|
-
expect(
|
|
105
|
-
expect(
|
|
109
|
+
const { chainId, chainReference, chainNamespace, assetNamespace, assetReference } = fromAssetId(AssetId)
|
|
110
|
+
expect(chainNamespace).toEqual('eip155')
|
|
111
|
+
expect(chainReference).toEqual('1')
|
|
112
|
+
expect(chainId).toEqual('eip155:1')
|
|
113
|
+
expect(assetNamespace).toEqual('erc20')
|
|
114
|
+
expect(assetReference).toEqual('0xc770eefad204b5180df6a14ee197d99d808ee52d')
|
|
106
115
|
```
|
|
107
116
|
|
|
108
117
|
## Adapters
|
|
@@ -1,16 +1,27 @@
|
|
|
1
|
-
import { ChainId } from '../chainId/chainId';
|
|
1
|
+
import { ChainId, ChainNamespace, ChainReference } from '../chainId/chainId';
|
|
2
2
|
export declare type AccountId = string;
|
|
3
|
-
declare type
|
|
3
|
+
declare type ToAccountIdWithChainId = {
|
|
4
4
|
chainId: ChainId;
|
|
5
5
|
account: string;
|
|
6
|
+
chainNamespace?: never;
|
|
7
|
+
chainReference?: never;
|
|
6
8
|
};
|
|
7
|
-
declare type
|
|
9
|
+
declare type ToAccountIdWithChainIdParts = {
|
|
10
|
+
chainId?: never;
|
|
11
|
+
account: string;
|
|
12
|
+
chainNamespace: ChainNamespace;
|
|
13
|
+
chainReference: ChainReference;
|
|
14
|
+
};
|
|
15
|
+
declare type ToAccountIdArgs = ToAccountIdWithChainId | ToAccountIdWithChainIdParts;
|
|
16
|
+
declare type ToAccountId = (args: ToAccountIdArgs) => AccountId;
|
|
8
17
|
export declare const toAccountId: ToAccountId;
|
|
9
18
|
declare type FromAccountIdReturn = {
|
|
10
|
-
chainId:
|
|
19
|
+
chainId: ChainId;
|
|
11
20
|
account: string;
|
|
21
|
+
chainNamespace: ChainNamespace;
|
|
22
|
+
chainReference: ChainReference;
|
|
12
23
|
};
|
|
13
|
-
declare type FromAccountId = (accountId:
|
|
24
|
+
declare type FromAccountId = (accountId: AccountId) => FromAccountIdReturn;
|
|
14
25
|
export declare const fromAccountId: FromAccountId;
|
|
15
26
|
export declare const toCAIP10: ToAccountId;
|
|
16
27
|
export declare const fromCAIP10: FromAccountId;
|
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fromCAIP10 = exports.toCAIP10 = exports.fromAccountId = exports.toAccountId = void 0;
|
|
4
4
|
const chainId_1 = require("../chainId/chainId");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (!account) {
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const typeGuards_1 = require("../typeGuards");
|
|
7
|
+
const toAccountId = ({ chainId: maybeChainId, chainNamespace: maybeChainNamespace, chainReference: maybeChainReference, account }) => {
|
|
8
|
+
if (!account)
|
|
10
9
|
throw new Error(`toAccountId: account is required`);
|
|
11
|
-
}
|
|
12
|
-
|
|
10
|
+
const chainId = maybeChainId !== null && maybeChainId !== void 0 ? maybeChainId : (0, chainId_1.toChainId)({ chainNamespace: maybeChainNamespace, chainReference: maybeChainReference });
|
|
11
|
+
(0, typeGuards_1.assertIsChainId)(chainId);
|
|
12
|
+
const { chainNamespace } = (0, chainId_1.fromChainId)(chainId);
|
|
13
13
|
// we lowercase eth accounts as per the draft spec
|
|
14
14
|
// it's not explicit, but cHecKsUM can be recovered from lowercase eth accounts
|
|
15
15
|
// we don't lowercase bitcoin addresses as they'll fail checksum
|
|
16
|
-
const outputAccount =
|
|
16
|
+
const outputAccount = chainNamespace === constants_1.CHAIN_NAMESPACE.Ethereum ? account.toLowerCase() : account;
|
|
17
17
|
return `${chainId}:${outputAccount}`;
|
|
18
18
|
};
|
|
19
19
|
exports.toAccountId = toAccountId;
|
|
@@ -22,20 +22,21 @@ const fromAccountId = (accountId) => {
|
|
|
22
22
|
if (parts.length !== 3) {
|
|
23
23
|
throw new Error(`fromAccountId: invalid AccountId ${accountId}`);
|
|
24
24
|
}
|
|
25
|
+
const chainNamespace = parts[0];
|
|
26
|
+
const chainReference = parts[1];
|
|
25
27
|
const chainId = parts.slice(0, 2).join(':');
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
(0, typeGuards_1.assertIsChainNamespace)(chainNamespace);
|
|
29
|
+
(0, typeGuards_1.assertIsChainReference)(chainReference);
|
|
30
|
+
(0, typeGuards_1.assertIsChainId)(chainId);
|
|
29
31
|
const account = parts[2];
|
|
30
32
|
if (!account) {
|
|
31
33
|
throw new Error(`fromAccountId: account required`);
|
|
32
34
|
}
|
|
33
|
-
const [namespace] = chainId.split(':');
|
|
34
35
|
// we lowercase eth accounts as per the draft spec
|
|
35
36
|
// it's not explicit, but cHecKsUM can be recovered from lowercase eth accounts
|
|
36
37
|
// we don't lowercase bitcoin addresses as they'll fail checksum
|
|
37
|
-
const outputAccount =
|
|
38
|
-
return { chainId, account: outputAccount };
|
|
38
|
+
const outputAccount = chainNamespace === constants_1.CHAIN_NAMESPACE.Ethereum ? account.toLowerCase() : account;
|
|
39
|
+
return { chainId, account: outputAccount, chainNamespace, chainReference };
|
|
39
40
|
};
|
|
40
41
|
exports.fromAccountId = fromAccountId;
|
|
41
42
|
exports.toCAIP10 = exports.toAccountId;
|
|
@@ -7,7 +7,6 @@ exports.getBanxaBlockchainFromBanxaAssetTicker = exports.getSupportedBanxaAssets
|
|
|
7
7
|
const entries_1 = __importDefault(require("lodash/entries"));
|
|
8
8
|
const toLower_1 = __importDefault(require("lodash/toLower"));
|
|
9
9
|
const assetId_1 = require("../../assetId/assetId");
|
|
10
|
-
const chainId_1 = require("../../chainId/chainId");
|
|
11
10
|
const AssetIdToBanxaTickerMap = {
|
|
12
11
|
'bip122:000000000019d6689c085ae165831e93/slip44:0': 'btc',
|
|
13
12
|
'cosmos:cosmoshub-4/slip44:118': 'atom',
|
|
@@ -66,11 +65,10 @@ const chainIdToBanxaBlockchainCodeMap = {
|
|
|
66
65
|
* @returns {string} - a Banxa chain identifier; e.g., 'cosmos'
|
|
67
66
|
*/
|
|
68
67
|
const getBanxaBlockchainFromBanxaAssetTicker = (banxaAssetId) => {
|
|
69
|
-
const
|
|
70
|
-
if (!
|
|
68
|
+
const assetId = (0, exports.banxaTickerToAssetId)(banxaAssetId.toLowerCase());
|
|
69
|
+
if (!assetId)
|
|
71
70
|
throw new Error(`getBanxaBlockchainFromBanxaAssetTicker: ${banxaAssetId} is not supported`);
|
|
72
|
-
const {
|
|
73
|
-
const chainId = (0, chainId_1.toChainId)({ network, chain });
|
|
71
|
+
const { chainId } = (0, assetId_1.fromAssetId)(assetId);
|
|
74
72
|
return chainIdToBanxaBlockchainCodeMap[chainId];
|
|
75
73
|
};
|
|
76
74
|
exports.getBanxaBlockchainFromBanxaAssetTicker = getBanxaBlockchainFromBanxaAssetTicker;
|
|
@@ -15,15 +15,15 @@ export declare type CoinCapCoin = {
|
|
|
15
15
|
export declare const writeFiles: (data: Record<string, Record<string, string>>) => Promise<void>;
|
|
16
16
|
export declare const fetchData: (URL: string) => Promise<CoinCapCoin[]>;
|
|
17
17
|
export declare const parseEthData: (data: CoinCapCoin[]) => Record<string, string>;
|
|
18
|
-
export declare const makeBtcData: () => {
|
|
19
|
-
[x: string]: string;
|
|
20
|
-
};
|
|
21
|
-
export declare const makeCosmosHubData: () => {
|
|
22
|
-
[x: string]: string;
|
|
23
|
-
};
|
|
24
|
-
export declare const makeOsmosisData: () => {
|
|
25
|
-
[x: string]: string;
|
|
26
|
-
};
|
|
27
18
|
export declare const parseData: (d: CoinCapCoin[]) => {
|
|
28
|
-
|
|
19
|
+
"eip155:1": Record<string, string>;
|
|
20
|
+
"bip122:000000000019d6689c085ae165831e93": {
|
|
21
|
+
[x: string]: string;
|
|
22
|
+
};
|
|
23
|
+
"cosmos:cosmoshub-4": {
|
|
24
|
+
[x: string]: string;
|
|
25
|
+
};
|
|
26
|
+
"cosmos:osmosis-1": {
|
|
27
|
+
[x: string]: string;
|
|
28
|
+
};
|
|
29
29
|
};
|
|
@@ -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.parseData = exports.
|
|
7
|
-
const types_1 = require("@shapeshiftoss/types");
|
|
6
|
+
exports.parseData = exports.parseEthData = exports.fetchData = exports.writeFiles = void 0;
|
|
8
7
|
const axios_1 = __importDefault(require("axios"));
|
|
9
8
|
const fs_1 = __importDefault(require("fs"));
|
|
10
9
|
const assetId_1 = require("../../assetId/assetId");
|
|
11
|
-
const
|
|
10
|
+
const constants_1 = require("../../constants");
|
|
11
|
+
const utils_1 = require("../../utils");
|
|
12
12
|
const writeFiles = async (data) => {
|
|
13
13
|
const path = './src/adapters/coincap/generated/';
|
|
14
14
|
const file = '/adapter.json';
|
|
@@ -21,10 +21,10 @@ const fetchData = async (URL) => (await axios_1.default.get(URL)).data.data;
|
|
|
21
21
|
exports.fetchData = fetchData;
|
|
22
22
|
const parseEthData = (data) => {
|
|
23
23
|
const ethCoins = data.filter(({ id, explorer }) => (explorer && explorer.startsWith('https://etherscan.io/token/0x')) || id === 'ethereum');
|
|
24
|
-
const chain = types_1.ChainTypes.Ethereum;
|
|
25
|
-
const network = types_1.NetworkTypes.MAINNET;
|
|
26
24
|
return ethCoins.reduce((acc, { id, explorer }) => {
|
|
27
|
-
|
|
25
|
+
const chainNamespace = constants_1.CHAIN_NAMESPACE.Ethereum;
|
|
26
|
+
const chainReference = constants_1.CHAIN_REFERENCE.EthereumMainnet;
|
|
27
|
+
let assetReference = constants_1.ASSET_REFERENCE.Ethereum;
|
|
28
28
|
const assetNamespace = id === 'ethereum' ? 'slip44' : 'erc20';
|
|
29
29
|
if (id !== 'ethereum' && explorer) {
|
|
30
30
|
assetReference = explorer
|
|
@@ -32,64 +32,18 @@ const parseEthData = (data) => {
|
|
|
32
32
|
.split('#')[0]
|
|
33
33
|
.split('?')[0];
|
|
34
34
|
}
|
|
35
|
-
const assetId = (0, assetId_1.toAssetId)({
|
|
35
|
+
const assetId = (0, assetId_1.toAssetId)({ chainNamespace, chainReference, assetNamespace, assetReference });
|
|
36
36
|
acc[assetId] = id;
|
|
37
37
|
return acc;
|
|
38
38
|
}, {});
|
|
39
39
|
};
|
|
40
40
|
exports.parseEthData = parseEthData;
|
|
41
|
-
const makeBtcData = () => {
|
|
42
|
-
const chain = types_1.ChainTypes.Bitcoin;
|
|
43
|
-
const network = types_1.NetworkTypes.MAINNET;
|
|
44
|
-
const assetId = (0, assetId_1.toAssetId)({
|
|
45
|
-
chain,
|
|
46
|
-
network,
|
|
47
|
-
assetNamespace: 'slip44',
|
|
48
|
-
assetReference: assetId_1.ASSET_REFERENCE.Bitcoin
|
|
49
|
-
});
|
|
50
|
-
return { [assetId]: 'bitcoin' };
|
|
51
|
-
};
|
|
52
|
-
exports.makeBtcData = makeBtcData;
|
|
53
|
-
const makeCosmosHubData = () => {
|
|
54
|
-
const chain = types_1.ChainTypes.Cosmos;
|
|
55
|
-
const network = types_1.NetworkTypes.COSMOSHUB_MAINNET;
|
|
56
|
-
const assetId = (0, assetId_1.toAssetId)({
|
|
57
|
-
chain,
|
|
58
|
-
network,
|
|
59
|
-
assetNamespace: 'slip44',
|
|
60
|
-
assetReference: assetId_1.ASSET_REFERENCE.Cosmos
|
|
61
|
-
});
|
|
62
|
-
return { [assetId]: 'cosmos' };
|
|
63
|
-
};
|
|
64
|
-
exports.makeCosmosHubData = makeCosmosHubData;
|
|
65
|
-
const makeOsmosisData = () => {
|
|
66
|
-
const chain = types_1.ChainTypes.Osmosis;
|
|
67
|
-
const network = types_1.NetworkTypes.OSMOSIS_MAINNET;
|
|
68
|
-
const assetId = (0, assetId_1.toAssetId)({
|
|
69
|
-
chain,
|
|
70
|
-
network,
|
|
71
|
-
assetNamespace: 'slip44',
|
|
72
|
-
assetReference: assetId_1.ASSET_REFERENCE.Osmosis
|
|
73
|
-
});
|
|
74
|
-
return { [assetId]: 'osmosis' };
|
|
75
|
-
};
|
|
76
|
-
exports.makeOsmosisData = makeOsmosisData;
|
|
77
41
|
const parseData = (d) => {
|
|
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
|
-
chain: types_1.ChainTypes.Cosmos,
|
|
82
|
-
network: types_1.NetworkTypes.COSMOSHUB_MAINNET
|
|
83
|
-
});
|
|
84
|
-
const osmosisMainnet = (0, chainId_1.toChainId)({
|
|
85
|
-
chain: types_1.ChainTypes.Osmosis,
|
|
86
|
-
network: types_1.NetworkTypes.OSMOSIS_MAINNET
|
|
87
|
-
});
|
|
88
42
|
return {
|
|
89
|
-
[
|
|
90
|
-
[
|
|
91
|
-
[
|
|
92
|
-
[
|
|
43
|
+
[constants_1.ethChainId]: (0, exports.parseEthData)(d),
|
|
44
|
+
[constants_1.btcChainId]: (0, utils_1.makeBtcData)(),
|
|
45
|
+
[constants_1.cosmosChainId]: (0, utils_1.makeCosmosHubData)(),
|
|
46
|
+
[constants_1.osmosisChainId]: (0, utils_1.makeOsmosisData)()
|
|
93
47
|
};
|
|
94
48
|
};
|
|
95
49
|
exports.parseData = parseData;
|
|
@@ -9,15 +9,15 @@ export declare type CoingeckoCoin = {
|
|
|
9
9
|
export declare const writeFiles: (data: Record<string, Record<string, string>>) => Promise<void>;
|
|
10
10
|
export declare const fetchData: (URL: string) => Promise<CoingeckoCoin[]>;
|
|
11
11
|
export declare const parseEthData: (data: CoingeckoCoin[]) => Record<string, string>;
|
|
12
|
-
export declare const makeBtcData: () => {
|
|
13
|
-
[x: string]: string;
|
|
14
|
-
};
|
|
15
|
-
export declare const makeCosmosHubData: () => {
|
|
16
|
-
[x: string]: string;
|
|
17
|
-
};
|
|
18
|
-
export declare const makeOsmosisData: () => {
|
|
19
|
-
[x: string]: string;
|
|
20
|
-
};
|
|
21
12
|
export declare const parseData: (d: CoingeckoCoin[]) => {
|
|
22
|
-
|
|
13
|
+
"eip155:1": Record<string, string>;
|
|
14
|
+
"bip122:000000000019d6689c085ae165831e93": {
|
|
15
|
+
[x: string]: string;
|
|
16
|
+
};
|
|
17
|
+
"cosmos:cosmoshub-4": {
|
|
18
|
+
[x: string]: string;
|
|
19
|
+
};
|
|
20
|
+
"cosmos:osmosis-1": {
|
|
21
|
+
[x: string]: string;
|
|
22
|
+
};
|
|
23
23
|
};
|
|
@@ -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.parseData = exports.
|
|
7
|
-
const types_1 = require("@shapeshiftoss/types");
|
|
6
|
+
exports.parseData = exports.parseEthData = exports.fetchData = exports.writeFiles = void 0;
|
|
8
7
|
const axios_1 = __importDefault(require("axios"));
|
|
9
8
|
const fs_1 = __importDefault(require("fs"));
|
|
10
9
|
const assetId_1 = require("../../assetId/assetId");
|
|
11
|
-
const
|
|
10
|
+
const constants_1 = require("../../constants");
|
|
11
|
+
const utils_1 = require("../../utils");
|
|
12
12
|
const writeFiles = async (data) => {
|
|
13
13
|
const path = './src/adapters/coingecko/generated/';
|
|
14
14
|
const file = '/adapter.json';
|
|
@@ -21,69 +21,23 @@ const fetchData = async (URL) => (await axios_1.default.get(URL)).data;
|
|
|
21
21
|
exports.fetchData = fetchData;
|
|
22
22
|
const parseEthData = (data) => {
|
|
23
23
|
const ethCoins = data.filter(({ id, platforms }) => Boolean(platforms === null || platforms === void 0 ? void 0 : platforms.ethereum) || id === 'ethereum');
|
|
24
|
-
const
|
|
25
|
-
const
|
|
24
|
+
const chainNamespace = constants_1.CHAIN_NAMESPACE.Ethereum;
|
|
25
|
+
const chainReference = constants_1.CHAIN_REFERENCE.EthereumMainnet;
|
|
26
26
|
return ethCoins.reduce((acc, { id, platforms }) => {
|
|
27
27
|
const assetNamespace = id === 'ethereum' ? 'slip44' : 'erc20';
|
|
28
|
-
const assetReference = id === 'ethereum' ?
|
|
29
|
-
const assetId = (0, assetId_1.toAssetId)({
|
|
28
|
+
const assetReference = id === 'ethereum' ? constants_1.ASSET_REFERENCE.Ethereum : platforms === null || platforms === void 0 ? void 0 : platforms.ethereum;
|
|
29
|
+
const assetId = (0, assetId_1.toAssetId)({ chainNamespace, chainReference, assetNamespace, assetReference });
|
|
30
30
|
acc[assetId] = id;
|
|
31
31
|
return acc;
|
|
32
32
|
}, {});
|
|
33
33
|
};
|
|
34
34
|
exports.parseEthData = parseEthData;
|
|
35
|
-
const makeBtcData = () => {
|
|
36
|
-
const chain = types_1.ChainTypes.Bitcoin;
|
|
37
|
-
const network = types_1.NetworkTypes.MAINNET;
|
|
38
|
-
const assetId = (0, assetId_1.toAssetId)({
|
|
39
|
-
chain,
|
|
40
|
-
network,
|
|
41
|
-
assetNamespace: 'slip44',
|
|
42
|
-
assetReference: assetId_1.ASSET_REFERENCE.Bitcoin
|
|
43
|
-
});
|
|
44
|
-
return { [assetId]: 'bitcoin' };
|
|
45
|
-
};
|
|
46
|
-
exports.makeBtcData = makeBtcData;
|
|
47
|
-
const makeCosmosHubData = () => {
|
|
48
|
-
const chain = types_1.ChainTypes.Cosmos;
|
|
49
|
-
const network = types_1.NetworkTypes.COSMOSHUB_MAINNET;
|
|
50
|
-
const assetId = (0, assetId_1.toAssetId)({
|
|
51
|
-
chain,
|
|
52
|
-
network,
|
|
53
|
-
assetNamespace: 'slip44',
|
|
54
|
-
assetReference: assetId_1.ASSET_REFERENCE.Cosmos
|
|
55
|
-
});
|
|
56
|
-
return { [assetId]: 'cosmos' };
|
|
57
|
-
};
|
|
58
|
-
exports.makeCosmosHubData = makeCosmosHubData;
|
|
59
|
-
const makeOsmosisData = () => {
|
|
60
|
-
const chain = types_1.ChainTypes.Osmosis;
|
|
61
|
-
const network = types_1.NetworkTypes.OSMOSIS_MAINNET;
|
|
62
|
-
const assetId = (0, assetId_1.toAssetId)({
|
|
63
|
-
chain,
|
|
64
|
-
network,
|
|
65
|
-
assetNamespace: 'slip44',
|
|
66
|
-
assetReference: assetId_1.ASSET_REFERENCE.Osmosis
|
|
67
|
-
});
|
|
68
|
-
return { [assetId]: 'osmosis' };
|
|
69
|
-
};
|
|
70
|
-
exports.makeOsmosisData = makeOsmosisData;
|
|
71
35
|
const parseData = (d) => {
|
|
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
|
-
chain: types_1.ChainTypes.Cosmos,
|
|
76
|
-
network: types_1.NetworkTypes.COSMOSHUB_MAINNET
|
|
77
|
-
});
|
|
78
|
-
const osmosisMainnet = (0, chainId_1.toChainId)({
|
|
79
|
-
chain: types_1.ChainTypes.Osmosis,
|
|
80
|
-
network: types_1.NetworkTypes.OSMOSIS_MAINNET
|
|
81
|
-
});
|
|
82
36
|
return {
|
|
83
|
-
[
|
|
84
|
-
[
|
|
85
|
-
[
|
|
86
|
-
[
|
|
37
|
+
[constants_1.ethChainId]: (0, exports.parseEthData)(d),
|
|
38
|
+
[constants_1.btcChainId]: (0, utils_1.makeBtcData)(),
|
|
39
|
+
[constants_1.cosmosChainId]: (0, utils_1.makeCosmosHubData)(),
|
|
40
|
+
[constants_1.osmosisChainId]: (0, utils_1.makeOsmosisData)()
|
|
87
41
|
};
|
|
88
42
|
};
|
|
89
43
|
exports.parseData = parseData;
|
|
@@ -4,11 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.parseData = exports.parseOsmosisData = exports.fetchData = exports.writeFiles = void 0;
|
|
7
|
-
const types_1 = require("@shapeshiftoss/types");
|
|
8
7
|
const axios_1 = __importDefault(require("axios"));
|
|
9
8
|
const fs_1 = __importDefault(require("fs"));
|
|
10
9
|
const assetId_1 = require("../../assetId/assetId");
|
|
11
10
|
const chainId_1 = require("../../chainId/chainId");
|
|
11
|
+
const constants_1 = require("../../constants");
|
|
12
12
|
const writeFiles = async (data) => {
|
|
13
13
|
const path = './src/adapters/osmosis/generated/';
|
|
14
14
|
const file = '/adapter.json';
|
|
@@ -27,16 +27,16 @@ const parseOsmosisData = (data) => {
|
|
|
27
27
|
let assetNamespace;
|
|
28
28
|
let assetReference;
|
|
29
29
|
if (isNativeAsset) {
|
|
30
|
-
assetReference = isOsmo ?
|
|
30
|
+
assetReference = isOsmo ? constants_1.ASSET_REFERENCE.Osmosis : denom;
|
|
31
31
|
assetNamespace = isOsmo ? 'slip44' : 'native';
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
34
|
assetReference = denom.split('/')[1];
|
|
35
35
|
assetNamespace = 'ibc';
|
|
36
36
|
}
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const assetId = (0, assetId_1.toAssetId)({
|
|
37
|
+
const chainNamespace = constants_1.CHAIN_NAMESPACE.Cosmos;
|
|
38
|
+
const chainReference = constants_1.CHAIN_REFERENCE.OsmosisMainnet;
|
|
39
|
+
const assetId = (0, assetId_1.toAssetId)({ chainNamespace, chainReference, assetNamespace, assetReference });
|
|
40
40
|
acc[assetId] = symbol;
|
|
41
41
|
return acc;
|
|
42
42
|
}, {});
|
|
@@ -45,8 +45,8 @@ const parseOsmosisData = (data) => {
|
|
|
45
45
|
exports.parseOsmosisData = parseOsmosisData;
|
|
46
46
|
const parseData = (d) => {
|
|
47
47
|
const osmosisMainnet = (0, chainId_1.toChainId)({
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
chainNamespace: constants_1.CHAIN_NAMESPACE.Cosmos,
|
|
49
|
+
chainReference: constants_1.CHAIN_REFERENCE.OsmosisMainnet
|
|
50
50
|
});
|
|
51
51
|
return {
|
|
52
52
|
[osmosisMainnet]: (0, exports.parseOsmosisData)(d)
|
|
@@ -5,13 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.parseData = exports.parseEthData = exports.fetchData = exports.writeFiles = void 0;
|
|
7
7
|
const providers_1 = require("@ethersproject/providers");
|
|
8
|
-
const types_1 = require("@shapeshiftoss/types");
|
|
9
8
|
const sdk_1 = require("@yfi/sdk");
|
|
10
9
|
const fs_1 = __importDefault(require("fs"));
|
|
11
10
|
const toLower_1 = __importDefault(require("lodash/toLower"));
|
|
12
11
|
const uniqBy_1 = __importDefault(require("lodash/uniqBy"));
|
|
13
12
|
const assetId_1 = require("../../assetId/assetId");
|
|
14
13
|
const chainId_1 = require("../../chainId/chainId");
|
|
14
|
+
const constants_1 = require("../../constants");
|
|
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 });
|
|
@@ -35,15 +35,16 @@ const fetchData = async () => {
|
|
|
35
35
|
};
|
|
36
36
|
exports.fetchData = fetchData;
|
|
37
37
|
const parseEthData = (data) => {
|
|
38
|
-
const chain = types_1.ChainTypes.Ethereum;
|
|
39
38
|
const assetNamespace = 'erc20';
|
|
39
|
+
const chainNamespace = constants_1.CHAIN_NAMESPACE.Ethereum;
|
|
40
|
+
const chainReference = constants_1.CHAIN_REFERENCE.EthereumMainnet;
|
|
40
41
|
return data.reduce((acc, datum) => {
|
|
41
42
|
const { address } = datum;
|
|
42
43
|
const id = address;
|
|
43
44
|
const assetReference = (0, toLower_1.default)(address);
|
|
44
45
|
const assetId = (0, assetId_1.toAssetId)({
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
chainNamespace,
|
|
47
|
+
chainReference,
|
|
47
48
|
assetNamespace,
|
|
48
49
|
assetReference
|
|
49
50
|
});
|
|
@@ -53,7 +54,10 @@ const parseEthData = (data) => {
|
|
|
53
54
|
};
|
|
54
55
|
exports.parseEthData = parseEthData;
|
|
55
56
|
const parseData = (d) => {
|
|
56
|
-
const ethMainnet = (0, chainId_1.toChainId)({
|
|
57
|
+
const ethMainnet = (0, chainId_1.toChainId)({
|
|
58
|
+
chainNamespace: constants_1.CHAIN_NAMESPACE.Ethereum,
|
|
59
|
+
chainReference: constants_1.CHAIN_REFERENCE.EthereumMainnet
|
|
60
|
+
});
|
|
57
61
|
return { [ethMainnet]: (0, exports.parseEthData)(d) };
|
|
58
62
|
};
|
|
59
63
|
exports.parseData = parseData;
|
|
@@ -1,26 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ChainId, ChainNamespace, ChainReference } from '../chainId/chainId';
|
|
2
|
+
import { ASSET_NAMESPACE_STRINGS, ASSET_REFERENCE } from '../constants';
|
|
3
3
|
export declare type AssetId = string;
|
|
4
|
-
declare
|
|
5
|
-
export declare type AssetNamespace = typeof assetNamespaceStrings[number];
|
|
6
|
-
export declare const ASSET_REFERENCE: {
|
|
7
|
-
readonly Bitcoin: "0";
|
|
8
|
-
readonly Ethereum: "60";
|
|
9
|
-
readonly Cosmos: "118";
|
|
10
|
-
readonly Osmosis: "118";
|
|
11
|
-
};
|
|
4
|
+
export declare type AssetNamespace = typeof ASSET_NAMESPACE_STRINGS[number];
|
|
12
5
|
export declare type AssetReference = typeof ASSET_REFERENCE[keyof typeof ASSET_REFERENCE];
|
|
13
|
-
declare type
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
declare type ToAssetIdWithChainId = {
|
|
7
|
+
chainNamespace?: never;
|
|
8
|
+
chainReference?: never;
|
|
9
|
+
chainId: ChainId;
|
|
10
|
+
assetNamespace: AssetNamespace;
|
|
11
|
+
assetReference: AssetReference | string;
|
|
12
|
+
};
|
|
13
|
+
declare type ToAssetIdWithChainIdParts = {
|
|
14
|
+
chainNamespace: ChainNamespace;
|
|
15
|
+
chainReference: ChainReference;
|
|
16
|
+
chainId?: never;
|
|
16
17
|
assetNamespace: AssetNamespace;
|
|
17
18
|
assetReference: AssetReference | string;
|
|
18
19
|
};
|
|
19
|
-
declare type
|
|
20
|
+
export declare type ToAssetIdArgs = ToAssetIdWithChainId | ToAssetIdWithChainIdParts;
|
|
21
|
+
declare type ToAssetId = (args: ToAssetIdArgs) => AssetId;
|
|
20
22
|
export declare const toAssetId: ToAssetId;
|
|
21
23
|
declare type FromAssetIdReturn = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
chainNamespace: ChainNamespace;
|
|
25
|
+
chainReference: ChainReference;
|
|
26
|
+
chainId: ChainId;
|
|
24
27
|
assetNamespace: AssetNamespace;
|
|
25
28
|
assetReference: AssetReference | string;
|
|
26
29
|
};
|