@shapeshiftoss/caip 8.15.0 → 8.16.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/CHANGELOG.md +726 -0
- package/dist/accountId/accountId.d.ts +9 -9
- package/dist/accountId/accountId.js +16 -20
- package/dist/accountId/accountId.test.js +107 -0
- package/dist/adapters/banxa/index.d.ts +6 -5
- package/dist/adapters/banxa/index.js +60 -38
- package/dist/adapters/coinbase/generate.js +4 -8
- package/dist/adapters/coinbase/generated/index.js +2 -8
- package/dist/adapters/coinbase/index.d.ts +1 -1
- package/dist/adapters/coinbase/index.js +7 -15
- package/dist/adapters/coinbase/utils.d.ts +2 -2
- package/dist/adapters/coinbase/utils.js +11 -23
- package/dist/adapters/coincap/generate.js +5 -7
- package/dist/adapters/coincap/generated/cosmos_thorchain-1/adapter.json +1 -0
- package/dist/adapters/coincap/generated/eip155_1/adapter.json +1 -1
- package/dist/adapters/coincap/generated/index.d.ts +2 -3
- package/dist/adapters/coincap/generated/index.js +8 -22
- package/dist/adapters/coincap/index.d.ts +2 -1
- package/dist/adapters/coincap/index.js +9 -38
- package/dist/adapters/coincap/index.test.js +92 -0
- package/dist/adapters/coincap/utils.d.ts +1 -1
- package/dist/adapters/coincap/utils.js +21 -32
- package/dist/adapters/coincap/utils.test.d.ts +4 -0
- package/dist/adapters/coincap/utils.test.js +163 -0
- package/dist/adapters/coingecko/generate.js +5 -7
- package/dist/adapters/coingecko/generated/cosmos_mayachain-mainnet-v1/adapter.json +1 -0
- package/dist/adapters/coingecko/generated/cosmos_thorchain-1/adapter.json +1 -0
- package/dist/adapters/coingecko/generated/eip155_1/adapter.json +1 -1
- package/dist/adapters/coingecko/generated/eip155_10/adapter.json +1 -1
- package/dist/adapters/coingecko/generated/eip155_100/adapter.json +1 -0
- package/dist/adapters/coingecko/generated/eip155_137/adapter.json +1 -0
- package/dist/adapters/coingecko/generated/eip155_42161/adapter.json +1 -0
- package/dist/adapters/coingecko/generated/eip155_42170/adapter.json +1 -0
- package/dist/adapters/coingecko/generated/eip155_43114/adapter.json +1 -1
- package/dist/adapters/coingecko/generated/eip155_56/adapter.json +1 -1
- package/dist/adapters/coingecko/generated/eip155_8453/adapter.json +1 -0
- package/dist/adapters/coingecko/generated/index.d.ts +9 -3
- package/dist/adapters/coingecko/generated/index.js +18 -28
- package/dist/adapters/coingecko/generated/solana_5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/adapter.json +1 -0
- package/dist/adapters/coingecko/index.d.ts +16 -14
- package/dist/adapters/coingecko/index.js +87 -73
- package/dist/adapters/coingecko/index.test.d.ts +1 -0
- package/dist/adapters/coingecko/index.test.js +274 -0
- package/dist/adapters/coingecko/utils.d.ts +4 -6
- package/dist/adapters/coingecko/utils.js +141 -59
- package/dist/adapters/coingecko/utils.test.d.ts +1 -0
- package/dist/adapters/coingecko/utils.test.js +188 -0
- package/dist/adapters/index.d.ts +0 -5
- package/dist/adapters/index.js +6 -27
- package/dist/adapters/mtpelerin/index.d.ts +1 -61
- package/dist/adapters/mtpelerin/index.js +96 -88
- package/dist/adapters/onramper/index.d.ts +2 -2
- package/dist/adapters/onramper/index.js +1483 -62
- package/dist/assetId/assetId.d.ts +14 -13
- package/dist/assetId/assetId.js +81 -57
- package/dist/assetId/assetId.test.d.ts +1 -0
- package/dist/assetId/assetId.test.js +336 -0
- package/dist/chainId/chainId.d.ts +11 -10
- package/dist/chainId/chainId.js +14 -16
- package/dist/chainId/chainId.test.d.ts +1 -0
- package/dist/chainId/chainId.test.js +88 -0
- package/dist/constants.d.ts +57 -38
- package/dist/constants.js +135 -108
- package/dist/index.js +7 -36
- package/dist/typeGuards.d.ts +5 -3
- package/dist/typeGuards.js +34 -40
- package/dist/utils.d.ts +7 -8
- package/dist/utils.js +23 -67
- package/dist/utils.test.d.ts +1 -0
- package/dist/utils.test.js +162 -0
- package/package.json +11 -30
- package/dist/adapters/coincap/generated/cosmos_osmosis-1/adapter.json +0 -1
- package/dist/adapters/coincap/generated/cosmos_thorchain-mainnet-v1/adapter.json +0 -1
- package/dist/adapters/coingecko/generated/cosmos_osmosis-1/adapter.json +0 -1
- package/dist/adapters/coingecko/generated/cosmos_thorchain-mainnet-v1/adapter.json +0 -1
- package/dist/adapters/gem/index.d.ts +0 -2
- package/dist/adapters/gem/index.js +0 -39
- package/dist/adapters/junopay/index.d.ts +0 -7
- package/dist/adapters/junopay/index.js +0 -52
- package/dist/adapters/osmosis/generate.js +0 -13
- package/dist/adapters/osmosis/generated/cosmos_osmosis-1/adapter.json +0 -1022
- package/dist/adapters/osmosis/generated/index.d.ts +0 -2
- package/dist/adapters/osmosis/generated/index.js +0 -8
- package/dist/adapters/osmosis/index.d.ts +0 -6
- package/dist/adapters/osmosis/index.js +0 -54
- package/dist/adapters/osmosis/utils.d.ts +0 -37
- package/dist/adapters/osmosis/utils.js +0 -90
- package/dist/adapters/thortrading/index.d.ts +0 -5
- package/dist/adapters/thortrading/index.js +0 -44
- package/dist/adapters/yearn/generate.js +0 -9
- package/dist/adapters/yearn/generated/eip155_1/adapter.json +0 -1
- package/dist/adapters/yearn/generated/index.d.ts +0 -2
- package/dist/adapters/yearn/generated/index.js +0 -8
- package/dist/adapters/yearn/index.d.ts +0 -2
- package/dist/adapters/yearn/index.js +0 -41
- package/dist/adapters/yearn/utils.d.ts +0 -7
- package/dist/adapters/yearn/utils.js +0 -62
- /package/dist/{adapters/osmosis/generate.d.ts → accountId/accountId.test.d.ts} +0 -0
- /package/dist/adapters/{yearn/generate.d.ts → coincap/index.test.d.ts} +0 -0
package/dist/typeGuards.js
CHANGED
|
@@ -1,50 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
const { 1: chainNamespace, 2: chainReference, 3: assetNamespace } = matches;
|
|
20
|
-
return ((0, exports.isChainNamespace)(chainNamespace) &&
|
|
21
|
-
(0, exports.isChainReference)(chainReference) &&
|
|
22
|
-
(0, exports.isAssetNamespace)(assetNamespace));
|
|
1
|
+
import { fromChainId } from './chainId/chainId';
|
|
2
|
+
import { ASSET_NAMESPACE, ASSET_REFERENCE, CHAIN_NAMESPACE, CHAIN_REFERENCE, VALID_CHAIN_IDS, } from './constants';
|
|
3
|
+
import { isValidChainPartsPair } from './utils';
|
|
4
|
+
export const isChainNamespace = (maybeChainNamespace) => Object.values(CHAIN_NAMESPACE).includes(maybeChainNamespace);
|
|
5
|
+
export const isChainReference = (maybeChainReference) => Object.values(CHAIN_REFERENCE).includes(maybeChainReference);
|
|
6
|
+
export const isAssetNamespace = (maybeAssetNamespace) => Object.values(ASSET_NAMESPACE).includes(maybeAssetNamespace);
|
|
7
|
+
export const isAssetReference = (maybeAssetReference) => Object.values(ASSET_REFERENCE).includes(maybeAssetReference);
|
|
8
|
+
// NOTE: perf critical - benchmark any changes
|
|
9
|
+
export const isAssetId = (maybeAssetId) => {
|
|
10
|
+
const slashIdx = maybeAssetId.indexOf('/');
|
|
11
|
+
const chainId = maybeAssetId.substring(0, slashIdx);
|
|
12
|
+
const assetParts = maybeAssetId.substring(slashIdx + 1);
|
|
13
|
+
const { chainNamespace, chainReference } = fromChainId(chainId);
|
|
14
|
+
const idx = assetParts.indexOf(':');
|
|
15
|
+
const assetNamespace = assetParts.substring(0, idx);
|
|
16
|
+
return isAssetIdParts(chainNamespace, chainReference, assetNamespace);
|
|
23
17
|
};
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
18
|
+
// NOTE: perf critical - benchmark any changes
|
|
19
|
+
export const isAssetIdParts = (maybeChainNamespace, maybeChainReference, maybeAssetNamespace) => {
|
|
20
|
+
return (!!VALID_CHAIN_IDS[maybeChainNamespace]?.includes(maybeChainReference) && isAssetNamespace(maybeAssetNamespace));
|
|
21
|
+
};
|
|
22
|
+
// NOTE: perf critical - benchmark any changes
|
|
23
|
+
export const isChainId = (maybeChainId) => {
|
|
24
|
+
const { chainNamespace, chainReference } = fromChainId(maybeChainId);
|
|
25
|
+
return !!VALID_CHAIN_IDS[chainNamespace]?.includes(chainReference);
|
|
26
|
+
};
|
|
27
|
+
export const isChainIdParts = (chainNamespace, chainReference) => {
|
|
28
|
+
return !!VALID_CHAIN_IDS[chainNamespace]?.includes(chainReference);
|
|
33
29
|
};
|
|
34
|
-
exports.isChainId = isChainId;
|
|
35
30
|
const getTypeGuardAssertion = (typeGuard, message) => {
|
|
36
31
|
return (value) => {
|
|
37
32
|
if ((value && !typeGuard(value)) || !value)
|
|
38
33
|
throw new Error(`${message}: ${value}`);
|
|
39
34
|
};
|
|
40
35
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const assertValidChainPartsPair = (chainNamespace, chainReference) => {
|
|
47
|
-
if (!
|
|
36
|
+
export const assertIsChainId = getTypeGuardAssertion(isChainId, 'assertIsChainId: unsupported ChainId');
|
|
37
|
+
export const assertIsChainNamespace = getTypeGuardAssertion(isChainNamespace, 'assertIsChainNamespace: unsupported ChainNamespace');
|
|
38
|
+
export const assertIsChainReference = getTypeGuardAssertion(isChainReference, 'assertIsChainReference: unsupported ChainReference');
|
|
39
|
+
export const assertIsAssetNamespace = getTypeGuardAssertion(isAssetNamespace, 'assertIsAssetNamespace: unsupported AssetNamespace');
|
|
40
|
+
export const assertIsAssetReference = getTypeGuardAssertion(isAssetReference, 'assertIsAssetReference: unsupported AssetReference');
|
|
41
|
+
export const assertValidChainPartsPair = (chainNamespace, chainReference) => {
|
|
42
|
+
if (!isValidChainPartsPair(chainNamespace, chainReference))
|
|
48
43
|
throw new Error(`toAssetId: Chain Reference ${chainReference} not supported for Chain Namespace ${chainNamespace}`);
|
|
49
44
|
};
|
|
50
|
-
exports.assertValidChainPartsPair = assertValidChainPartsPair;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { AccountId } from './accountId/accountId';
|
|
2
|
-
import { AssetId } from './assetId/assetId';
|
|
3
|
-
import { ChainId, ChainNamespace, ChainReference } from './chainId/chainId';
|
|
4
|
-
export declare const parseAssetIdRegExp: RegExp;
|
|
1
|
+
import type { AccountId } from './accountId/accountId';
|
|
2
|
+
import type { AssetId } from './assetId/assetId';
|
|
3
|
+
import type { ChainId, ChainNamespace, ChainReference } from './chainId/chainId';
|
|
5
4
|
export declare const accountIdToChainId: (accountId: AccountId) => ChainId;
|
|
6
5
|
export declare const accountIdToSpecifier: (accountId: AccountId) => string;
|
|
7
6
|
export declare const isValidChainPartsPair: (chainNamespace: ChainNamespace, chainReference: ChainReference) => boolean;
|
|
8
|
-
export declare const
|
|
7
|
+
export declare const generateAssetIdFromCosmosSdkDenom: (denom: string, nativeAssetId: AssetId) => AssetId;
|
|
9
8
|
export declare const bitcoinAssetMap: {
|
|
10
9
|
[x: string]: string;
|
|
11
10
|
};
|
|
@@ -21,14 +20,14 @@ export declare const litecoinAssetMap: {
|
|
|
21
20
|
export declare const cosmosAssetMap: {
|
|
22
21
|
[x: string]: string;
|
|
23
22
|
};
|
|
24
|
-
export declare const
|
|
23
|
+
export declare const thorchainAssetMap: {
|
|
25
24
|
[x: string]: string;
|
|
26
25
|
};
|
|
27
|
-
export declare const
|
|
26
|
+
export declare const mayachainAssetMap: {
|
|
28
27
|
[x: string]: string;
|
|
29
28
|
};
|
|
30
29
|
interface Flavoring<FlavorT> {
|
|
31
30
|
_type?: FlavorT;
|
|
32
31
|
}
|
|
33
|
-
export
|
|
32
|
+
export type Nominal<T, FlavorT> = T & Flavoring<FlavorT>;
|
|
34
33
|
export {};
|
package/dist/utils.js
CHANGED
|
@@ -1,73 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.thorchainAssetMap = exports.osmosisAssetMap = exports.cosmosAssetMap = exports.litecoinAssetMap = exports.dogecoinAssetMap = exports.bitcoinCashAssetMap = exports.bitcoinAssetMap = exports.generateAssetIdFromOsmosisDenom = exports.isValidChainPartsPair = exports.accountIdToSpecifier = exports.accountIdToChainId = exports.parseAssetIdRegExp = void 0;
|
|
27
|
-
const accountId_1 = require("./accountId/accountId");
|
|
28
|
-
const assetId_1 = require("./assetId/assetId");
|
|
29
|
-
const constants = __importStar(require("./constants"));
|
|
30
|
-
// https://regex101.com/r/xqVzV2/1
|
|
31
|
-
exports.parseAssetIdRegExp = /([-a-z\d]{3,8}):([-a-zA-Z\d]{1,32})\/([-a-z\d]{3,8}):([-a-zA-Z/\d]+)/;
|
|
32
|
-
const accountIdToChainId = (accountId) => (0, accountId_1.fromAccountId)(accountId).chainId;
|
|
33
|
-
exports.accountIdToChainId = accountIdToChainId;
|
|
34
|
-
const accountIdToSpecifier = (accountId) => (0, accountId_1.fromAccountId)(accountId).account;
|
|
35
|
-
exports.accountIdToSpecifier = accountIdToSpecifier;
|
|
36
|
-
const isValidChainPartsPair = (chainNamespace, chainReference) => { var _a; return ((_a = constants.VALID_CHAIN_IDS[chainNamespace]) === null || _a === void 0 ? void 0 : _a.includes(chainReference)) || false; };
|
|
37
|
-
exports.isValidChainPartsPair = isValidChainPartsPair;
|
|
38
|
-
const generateAssetIdFromOsmosisDenom = (denom) => {
|
|
39
|
-
if (denom.startsWith('u') && denom !== 'uosmo') {
|
|
40
|
-
return (0, assetId_1.toAssetId)({
|
|
41
|
-
assetNamespace: constants.ASSET_NAMESPACE.native,
|
|
42
|
-
assetReference: denom,
|
|
43
|
-
chainId: constants.osmosisChainId,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
1
|
+
import { fromAccountId } from './accountId/accountId';
|
|
2
|
+
import { fromAssetId, toAssetId } from './assetId/assetId';
|
|
3
|
+
import * as constants from './constants';
|
|
4
|
+
import { tcyAssetId } from './constants';
|
|
5
|
+
const mayaTokenAssetId = 'cosmos:mayachain-mainnet-v1/slip44:maya';
|
|
6
|
+
export const accountIdToChainId = (accountId) => fromAccountId(accountId).chainId;
|
|
7
|
+
export const accountIdToSpecifier = (accountId) => fromAccountId(accountId).account;
|
|
8
|
+
export const isValidChainPartsPair = (chainNamespace, chainReference) => constants.VALID_CHAIN_IDS[chainNamespace]?.includes(chainReference) || false;
|
|
9
|
+
export const generateAssetIdFromCosmosSdkDenom = (denom, nativeAssetId) => {
|
|
10
|
+
if (denom === 'tcy')
|
|
11
|
+
return tcyAssetId;
|
|
12
|
+
if (denom === 'maya')
|
|
13
|
+
return mayaTokenAssetId;
|
|
46
14
|
if (denom.startsWith('ibc')) {
|
|
47
|
-
return
|
|
15
|
+
return toAssetId({
|
|
48
16
|
assetNamespace: constants.ASSET_NAMESPACE.ibc,
|
|
49
17
|
assetReference: denom.split('/')[1],
|
|
50
|
-
chainId:
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
if (denom.startsWith('gamm')) {
|
|
54
|
-
return (0, assetId_1.toAssetId)({
|
|
55
|
-
assetNamespace: constants.ASSET_NAMESPACE.ibc,
|
|
56
|
-
assetReference: denom,
|
|
57
|
-
chainId: constants.osmosisChainId,
|
|
18
|
+
chainId: fromAssetId(nativeAssetId).chainId,
|
|
58
19
|
});
|
|
59
20
|
}
|
|
60
|
-
return
|
|
61
|
-
assetNamespace: constants.ASSET_NAMESPACE.slip44,
|
|
62
|
-
assetReference: constants.ASSET_REFERENCE.Osmosis,
|
|
63
|
-
chainId: constants.osmosisChainId,
|
|
64
|
-
});
|
|
21
|
+
return nativeAssetId;
|
|
65
22
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
exports.thorchainAssetMap = { [constants.thorchainAssetId]: 'thorchain' };
|
|
23
|
+
export const bitcoinAssetMap = { [constants.btcAssetId]: 'bitcoin' };
|
|
24
|
+
export const bitcoinCashAssetMap = { [constants.bchAssetId]: 'bitcoin-cash' };
|
|
25
|
+
export const dogecoinAssetMap = { [constants.dogeAssetId]: 'dogecoin' };
|
|
26
|
+
export const litecoinAssetMap = { [constants.ltcAssetId]: 'litecoin' };
|
|
27
|
+
export const cosmosAssetMap = { [constants.cosmosAssetId]: 'cosmos' };
|
|
28
|
+
export const thorchainAssetMap = { [constants.thorchainAssetId]: 'thorchain' };
|
|
29
|
+
export const mayachainAssetMap = { [constants.mayachainAssetId]: 'cacao' };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { toAssetId } from './assetId/assetId';
|
|
3
|
+
import { ASSET_NAMESPACE, ASSET_REFERENCE, btcAssetId, btcChainId, CHAIN_NAMESPACE, CHAIN_REFERENCE, cosmosAssetId, cosmosChainId, ethAssetId, ethChainId, } from './constants';
|
|
4
|
+
import { assertIsAssetNamespace, assertIsAssetReference, assertIsChainId, assertIsChainNamespace, assertIsChainReference, assertValidChainPartsPair, isAssetId, isAssetNamespace, isAssetReference, isChainId, isChainNamespace, isChainReference, } from './typeGuards';
|
|
5
|
+
import { accountIdToChainId, accountIdToSpecifier, generateAssetIdFromCosmosSdkDenom, isValidChainPartsPair, } from './utils';
|
|
6
|
+
describe('accountIdToChainId', () => {
|
|
7
|
+
it('can get eth chainId from accountId', () => {
|
|
8
|
+
const accountId = 'eip155:1:0xdef1cafe';
|
|
9
|
+
const chainId = accountIdToChainId(accountId);
|
|
10
|
+
expect(chainId).toEqual(ethChainId);
|
|
11
|
+
});
|
|
12
|
+
it('can get btc chainId from accountId', () => {
|
|
13
|
+
const accountId = 'bip122:000000000019d6689c085ae165831e93:xpubfoobarbaz';
|
|
14
|
+
const chainId = accountIdToChainId(accountId);
|
|
15
|
+
expect(chainId).toEqual(btcChainId);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
describe('accountIdToSpecifier', () => {
|
|
19
|
+
it('can get eth address from accountId', () => {
|
|
20
|
+
const address = '0xdef1cafe';
|
|
21
|
+
const accountId = 'eip155:1:0xdef1cafe';
|
|
22
|
+
const result = accountIdToSpecifier(accountId);
|
|
23
|
+
expect(result).toEqual(address);
|
|
24
|
+
});
|
|
25
|
+
it('can get xpub from accountId', () => {
|
|
26
|
+
const xpub = 'xpubfoobarbaz';
|
|
27
|
+
const accountId = 'bip122:000000000019d6689c085ae165831e93:xpubfoobarbaz';
|
|
28
|
+
const result = accountIdToSpecifier(accountId);
|
|
29
|
+
expect(result).toEqual(xpub);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
describe('isValidChainPartsPair', () => {
|
|
33
|
+
it('correctly validates pairs', () => {
|
|
34
|
+
expect(isValidChainPartsPair(CHAIN_NAMESPACE.Utxo, CHAIN_REFERENCE.BitcoinMainnet)).toEqual(true);
|
|
35
|
+
expect(isValidChainPartsPair(CHAIN_NAMESPACE.Evm, CHAIN_REFERENCE.BitcoinMainnet)).toEqual(false);
|
|
36
|
+
expect(isValidChainPartsPair('invalid', CHAIN_REFERENCE.BitcoinMainnet)).toEqual(false);
|
|
37
|
+
expect(isValidChainPartsPair(CHAIN_NAMESPACE.Evm, 'invalid')).toEqual(false);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
describe('type guard', () => {
|
|
41
|
+
describe('isChainNamespace', () => {
|
|
42
|
+
it('correctly determines type', () => {
|
|
43
|
+
expect(isChainNamespace(CHAIN_NAMESPACE.Utxo)).toEqual(true);
|
|
44
|
+
expect(isChainNamespace(CHAIN_NAMESPACE.Evm)).toEqual(true);
|
|
45
|
+
expect(isChainNamespace('invalid')).toEqual(false);
|
|
46
|
+
expect(isChainNamespace('')).toEqual(false);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
describe('isChainReference', () => {
|
|
50
|
+
it('correctly determines type', () => {
|
|
51
|
+
expect(isChainReference(CHAIN_REFERENCE.EthereumMainnet)).toEqual(true);
|
|
52
|
+
expect(isChainReference(CHAIN_REFERENCE.BitcoinMainnet)).toEqual(true);
|
|
53
|
+
expect(isChainReference('invalid')).toEqual(false);
|
|
54
|
+
expect(isChainReference('')).toEqual(false);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
describe('isValidChainId', () => {
|
|
58
|
+
it('correctly determines type', () => {
|
|
59
|
+
expect(isChainId(ethChainId)).toEqual(true);
|
|
60
|
+
expect(isChainId(btcChainId)).toEqual(true);
|
|
61
|
+
expect(isChainId(cosmosChainId)).toEqual(true);
|
|
62
|
+
expect(isChainId('invalid')).toEqual(false);
|
|
63
|
+
expect(isChainId('')).toEqual(false);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
describe('isAssetNamespace', () => {
|
|
67
|
+
it('correctly determines type', () => {
|
|
68
|
+
expect(isAssetNamespace(ASSET_NAMESPACE.erc20)).toEqual(true);
|
|
69
|
+
expect(isAssetNamespace(ASSET_NAMESPACE.erc721)).toEqual(true);
|
|
70
|
+
expect(isAssetNamespace('invalid')).toEqual(false);
|
|
71
|
+
expect(isAssetNamespace('')).toEqual(false);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
describe('isAssetReference', () => {
|
|
75
|
+
it('correctly determines type', () => {
|
|
76
|
+
expect(isAssetReference(ASSET_REFERENCE.Bitcoin)).toEqual(true);
|
|
77
|
+
expect(isAssetReference(ASSET_REFERENCE.Ethereum)).toEqual(true);
|
|
78
|
+
expect(isAssetReference('invalid')).toEqual(false);
|
|
79
|
+
expect(isAssetReference('')).toEqual(false);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
describe('isAssetId', () => {
|
|
83
|
+
it('correctly determines type', () => {
|
|
84
|
+
expect(isAssetId(btcAssetId)).toEqual(true);
|
|
85
|
+
expect(isAssetId(ethAssetId)).toEqual(true);
|
|
86
|
+
expect(isAssetId(cosmosAssetId)).toEqual(true);
|
|
87
|
+
expect(isAssetId('invalid')).toEqual(false);
|
|
88
|
+
expect(isAssetId('')).toEqual(false);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
describe('type guard assertion', () => {
|
|
93
|
+
describe('assertIsChainId', () => {
|
|
94
|
+
it('correctly asserts type', () => {
|
|
95
|
+
expect(() => assertIsChainId(ethChainId)).not.toThrow();
|
|
96
|
+
expect(() => assertIsChainId(btcChainId)).not.toThrow();
|
|
97
|
+
expect(() => assertIsChainId(cosmosChainId)).not.toThrow();
|
|
98
|
+
expect(() => assertIsChainId('invalid')).toThrow();
|
|
99
|
+
expect(() => assertIsChainId('')).toThrow();
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
describe('assertIsChainNamespace', () => {
|
|
103
|
+
it('correctly asserts type', () => {
|
|
104
|
+
expect(() => assertIsChainNamespace(CHAIN_NAMESPACE.Utxo)).not.toThrow();
|
|
105
|
+
expect(() => assertIsChainNamespace(CHAIN_NAMESPACE.Evm)).not.toThrow();
|
|
106
|
+
expect(() => assertIsChainNamespace('invalid')).toThrow();
|
|
107
|
+
expect(() => assertIsChainNamespace('')).toThrow();
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
describe('assertIsChainReference', () => {
|
|
111
|
+
it('correctly asserts type', () => {
|
|
112
|
+
expect(() => assertIsChainReference(CHAIN_REFERENCE.EthereumMainnet)).not.toThrow();
|
|
113
|
+
expect(() => assertIsChainReference(CHAIN_REFERENCE.BitcoinMainnet)).not.toThrow();
|
|
114
|
+
expect(() => assertIsChainReference('invalid')).toThrow();
|
|
115
|
+
expect(() => assertIsChainReference('')).toThrow();
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
describe('assertIsAssetNamespace', () => {
|
|
119
|
+
it('correctly asserts type', () => {
|
|
120
|
+
expect(() => assertIsAssetNamespace(ASSET_NAMESPACE.erc20)).not.toThrow();
|
|
121
|
+
expect(() => assertIsAssetNamespace(ASSET_NAMESPACE.erc721)).not.toThrow();
|
|
122
|
+
expect(() => assertIsAssetNamespace('invalid')).toThrow();
|
|
123
|
+
expect(() => assertIsAssetNamespace('')).toThrow();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
describe('assertIsAssetReference', () => {
|
|
127
|
+
it('correctly asserts type', () => {
|
|
128
|
+
expect(() => assertIsAssetReference(ASSET_REFERENCE.Bitcoin)).not.toThrow();
|
|
129
|
+
expect(() => assertIsAssetReference(ASSET_REFERENCE.Ethereum)).not.toThrow();
|
|
130
|
+
expect(() => assertIsAssetReference('invalid')).toThrow();
|
|
131
|
+
expect(() => assertIsAssetReference('')).toThrow();
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
describe('assertValidChainPartsPair', () => {
|
|
135
|
+
it('correctly asserts type', () => {
|
|
136
|
+
expect(() => assertValidChainPartsPair(CHAIN_NAMESPACE.Utxo, CHAIN_REFERENCE.BitcoinMainnet)).not.toThrow();
|
|
137
|
+
expect(() => assertValidChainPartsPair(CHAIN_NAMESPACE.Utxo, CHAIN_REFERENCE.EthereumMainnet)).toThrow();
|
|
138
|
+
expect(() => assertValidChainPartsPair('invalid', CHAIN_REFERENCE.BitcoinMainnet)).toThrow();
|
|
139
|
+
expect(() => assertValidChainPartsPair(CHAIN_NAMESPACE.Evm, 'invalid')).toThrow();
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
describe('generateAssetIdFromCosmosDenom', () => {
|
|
143
|
+
it('correctly generates ATOM native asset id', () => {
|
|
144
|
+
const nativeAssetId = toAssetId({
|
|
145
|
+
assetNamespace: ASSET_NAMESPACE.slip44,
|
|
146
|
+
assetReference: ASSET_REFERENCE.Cosmos,
|
|
147
|
+
chainId: cosmosChainId,
|
|
148
|
+
});
|
|
149
|
+
const result = generateAssetIdFromCosmosSdkDenom('uatom', cosmosAssetId);
|
|
150
|
+
expect(result).toEqual(nativeAssetId);
|
|
151
|
+
});
|
|
152
|
+
it('correctly generates cosmoshub IBC asset id', () => {
|
|
153
|
+
const ibcAssetId = toAssetId({
|
|
154
|
+
assetNamespace: ASSET_NAMESPACE.ibc,
|
|
155
|
+
assetReference: '14F9BC3E44B8A9C1BE1FB08980FAB87034C9905EF17CF2F5008FC085218811CC',
|
|
156
|
+
chainId: cosmosChainId,
|
|
157
|
+
});
|
|
158
|
+
const result = generateAssetIdFromCosmosSdkDenom('ibc/14F9BC3E44B8A9C1BE1FB08980FAB87034C9905EF17CF2F5008FC085218811CC', cosmosAssetId);
|
|
159
|
+
expect(result).toEqual(ibcAssetId);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
});
|
package/package.json
CHANGED
|
@@ -1,42 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshiftoss/caip",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.16.1",
|
|
4
4
|
"description": "CAIP Implementation",
|
|
5
|
-
"
|
|
5
|
+
"repository": "https://github.com/shapeshift/web",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"main": "
|
|
8
|
-
"types": "
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
12
|
"publishConfig": {
|
|
13
13
|
"access": "public"
|
|
14
14
|
},
|
|
15
|
-
"repository": {
|
|
16
|
-
"type": "git",
|
|
17
|
-
"url": "https://github.com/shapeshift/lib"
|
|
18
|
-
},
|
|
19
15
|
"scripts": {
|
|
20
|
-
"build": "yarn clean && yarn
|
|
21
|
-
"clean": "rm -rf dist
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"generate
|
|
25
|
-
"generate
|
|
26
|
-
"generate-yearn": "ts-node -P tsconfig.build.json src/adapters/yearn/generate.ts",
|
|
27
|
-
"generate-osmosis": "ts-node -P tsconfig.build.json src/adapters/osmosis/generate.ts",
|
|
28
|
-
"generate": "yarn generate-coingecko && yarn generate-coincap && yarn generate-yearn && yarn generate-osmosis",
|
|
29
|
-
"prepare": "yarn build",
|
|
30
|
-
"test": "jest test",
|
|
31
|
-
"type-check": "tsc --project ./tsconfig.build.json --noEmit"
|
|
32
|
-
},
|
|
33
|
-
"peerDependencies": {
|
|
34
|
-
"@shapeshiftoss/types": "^8.1.0"
|
|
35
|
-
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@shapeshiftoss/types": "^8.1.0",
|
|
38
|
-
"@yfi/sdk": "^1.2.0",
|
|
39
|
-
"axios": "^0.26.1",
|
|
40
|
-
"ts-node": "^10.7.0"
|
|
16
|
+
"build": "yarn clean && yarn run -T tsc --build",
|
|
17
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
18
|
+
"dev": "yarn run -T tsc --build --watch",
|
|
19
|
+
"generate": "yarn generate:coingecko && yarn generate:coincap",
|
|
20
|
+
"generate:coingecko": "yarn build && yarn run -T tsx src/adapters/coingecko/generate.ts",
|
|
21
|
+
"generate:coincap": "yarn build && yarn run -T tsx src/adapters/coincap/generate.ts"
|
|
41
22
|
}
|
|
42
|
-
}
|
|
23
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{ "cosmos:osmosis-1/slip44:118": "osmosis" }
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{ "cosmos:thorchain-mainnet-v1/slip44:931": "thorchain" }
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{ "cosmos:osmosis-1/slip44:118": "osmosis" }
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{ "cosmos:thorchain-mainnet-v1/slip44:931": "thorchain" }
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.assetIdToGemTicker = exports.gemTickerToAssetId = void 0;
|
|
7
|
-
const invert_1 = __importDefault(require("lodash/invert"));
|
|
8
|
-
const toLower_1 = __importDefault(require("lodash/toLower"));
|
|
9
|
-
const assetIdToGemAssetIdMap = {
|
|
10
|
-
'bip122:000000000019d6689c085ae165831e93/slip44:0': 'bitcoin',
|
|
11
|
-
'bip122:00000000001a91e3dace36e2be3bf030/slip44:3': 'dogecoin',
|
|
12
|
-
'bip122:000000000000000000651ef99cb9fcbe/slip44:145': 'bitcoin-cash',
|
|
13
|
-
'bip122:12a765e31ffd4059bada1e25190f6e98/slip44:2': 'litecoin',
|
|
14
|
-
'eip155:1/slip44:60': 'ethereum',
|
|
15
|
-
'eip155:1/erc20:0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9': 'aave',
|
|
16
|
-
'eip155:1/erc20:0x0d8775f648430679a709e98d2b0cb6250d2887ef': 'basic-attention-token',
|
|
17
|
-
'eip155:1/erc20:0x4fabb145d64652a948d72533023f6e7a623c7c53': 'busd',
|
|
18
|
-
'eip155:1/erc20:0xc00e94cb662c3520282e6f5717214004a7f26888': 'compound-coin',
|
|
19
|
-
'eip155:1/erc20:0xd533a949740bb3306d119cc777fa900ba034cd52': 'curve-dao',
|
|
20
|
-
'eip155:1/erc20:0x6b175474e89094c44da98b954eedeac495271d0f': 'dai',
|
|
21
|
-
'eip155:1/erc20:0x056fd409e1d7a124bd7017459dfea2f387b6d5cd': 'gemini-dollar',
|
|
22
|
-
'eip155:1/erc20:0x514910771af9ca656af840dff83e8264ecf986ca': 'chainlink',
|
|
23
|
-
'eip155:1/erc20:0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2': 'maker',
|
|
24
|
-
'eip155:1/erc20:0x75231f58b43240c9718dd58b4967c5114342a86c': 'okb',
|
|
25
|
-
'eip155:1/erc20:0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f': 'synthetix-network-token',
|
|
26
|
-
'eip155:1/erc20:0xa4bdb11dc0a2bec88d24a3aa1e6bb17201112ebe': 'usds',
|
|
27
|
-
'eip155:1/erc20:0xdac17f958d2ee523a2206206994597c13d831ec7': 'tether',
|
|
28
|
-
'eip155:1/erc20:0x04fa0d235c4abf4bcf4787af4cf447de572ef828': 'universal-market-access',
|
|
29
|
-
'eip155:1/erc20:0x1f9840a85d5af5bf1d1762f925bdaddc4201f984': 'uniswap',
|
|
30
|
-
'eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': 'usd-coin',
|
|
31
|
-
'eip155:1/erc20:0x2260fac5e5542a773aa44fbcfedf7c193bc2c599': 'wrapped-bitcoin',
|
|
32
|
-
'eip155:1/erc20:0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2': 'weth',
|
|
33
|
-
'eip155:1/erc20:0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e': 'yearn-finance',
|
|
34
|
-
};
|
|
35
|
-
const gemAssetIdToAssetIdMap = (0, invert_1.default)(assetIdToGemAssetIdMap);
|
|
36
|
-
const gemTickerToAssetId = (id) => gemAssetIdToAssetIdMap[id];
|
|
37
|
-
exports.gemTickerToAssetId = gemTickerToAssetId;
|
|
38
|
-
const assetIdToGemTicker = (assetId) => assetIdToGemAssetIdMap[(0, toLower_1.default)(assetId)];
|
|
39
|
-
exports.assetIdToGemTicker = assetIdToGemTicker;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AssetId } from '../../assetId/assetId';
|
|
2
|
-
export declare const junoPayTickerToAssetId: (id: string) => AssetId | undefined;
|
|
3
|
-
export declare const assetIdToJunoPayTicker: (assetId: string) => string | undefined;
|
|
4
|
-
export declare const getSupportedJunoPayAssets: () => {
|
|
5
|
-
assetId: string;
|
|
6
|
-
ticker: string;
|
|
7
|
-
}[];
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getSupportedJunoPayAssets = exports.assetIdToJunoPayTicker = exports.junoPayTickerToAssetId = void 0;
|
|
7
|
-
const entries_1 = __importDefault(require("lodash/entries"));
|
|
8
|
-
const invert_1 = __importDefault(require("lodash/invert"));
|
|
9
|
-
const toLower_1 = __importDefault(require("lodash/toLower"));
|
|
10
|
-
const constants_1 = require("../../constants");
|
|
11
|
-
// source data https://docs.juno.finance/developers/reference/onjuno-pay/onjuno-pay-integration-guide
|
|
12
|
-
const assetIdToJunoPayTickerMap = {
|
|
13
|
-
[constants_1.avalancheAssetId]: 'avax',
|
|
14
|
-
[constants_1.btcAssetId]: 'btc',
|
|
15
|
-
[constants_1.cosmosAssetId]: 'atom',
|
|
16
|
-
[constants_1.ethAssetId]: 'eth',
|
|
17
|
-
'eip155:1/erc20:0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9': 'aave',
|
|
18
|
-
'eip155:1/erc20:0xbb0e17ef65f82ab018d8edd776e8dd940327b28b': 'axs',
|
|
19
|
-
'eip155:1/erc20:0x4d224452801aced8b2f0aebe155379bb5d594381': 'ape',
|
|
20
|
-
'eip155:1/erc20:0x0d8775f648430679a709e98d2b0cb6250d2887ef': 'bat',
|
|
21
|
-
'eip155:1/erc20:0x4fabb145d64652a948d72533023f6e7a623c7c53': 'busd',
|
|
22
|
-
'eip155:1/erc20:0x3506424f91fd33084466f402d5d97f05f8e3b4af': 'chz',
|
|
23
|
-
'eip155:1/erc20:0x41e5560054824ea6b0732e656e3ad64e20e94e45': 'cvc',
|
|
24
|
-
'eip155:1/erc20:0xc00e94cb662c3520282e6f5717214004a7f26888': 'comp',
|
|
25
|
-
'eip155:1/erc20:0x6b175474e89094c44da98b954eedeac495271d0f': 'dai',
|
|
26
|
-
'eip155:1/erc20:0xf629cbd94d3791c9250152bd8dfbdf380e2a3b9c': 'enj',
|
|
27
|
-
'eip155:1/erc20:0x4e15361fd6b4bb609fa63c81a2be19d873717870': 'ftm',
|
|
28
|
-
'eip155:1/erc20:0x165440036ce972c5f8ebef667086707e48b2623e': 'grt',
|
|
29
|
-
'eip155:1/erc20:0xf57e7e7c23978c3caec3c3548e3d615c346e79ff': 'imx',
|
|
30
|
-
'eip155:1/erc20:0x514910771af9ca656af840dff83e8264ecf986ca': 'link',
|
|
31
|
-
'eip155:1/erc20:0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2': 'mkr',
|
|
32
|
-
'eip155:1/erc20:0x0f5d2fb29fb7d3cfee444a200298f468908cc942': 'mana',
|
|
33
|
-
'eip155:1/erc20:0xd26114cd6ee289accf82350c8d8487fedb8a0c07': 'omg',
|
|
34
|
-
'eip155:1/erc20:0x57ab1ec28d129707052df4df418d58a2d46d5f51': 'susd',
|
|
35
|
-
'eip155:1/erc20:0x6b3595068778dd592e39a122f4f5a5cf09c90fe2': 'sushi',
|
|
36
|
-
'eip155:1/erc20:0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f': 'snx',
|
|
37
|
-
'eip155:1/erc20:0x1f9840a85d5af5bf1d1762f925bdaddc4201f984': 'uni',
|
|
38
|
-
'eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': 'usdc',
|
|
39
|
-
'eip155:1/erc20:0x8e870d67f660d95d5be530380d0ec0bd388289e1': 'usdp',
|
|
40
|
-
'eip155:1/erc20:0xdac17f958d2ee523a2206206994597c13d831ec7': 'usdt',
|
|
41
|
-
'eip155:1/erc20:0x2260fac5e5542a773aa44fbcfedf7c193bc2c599': 'wbtc',
|
|
42
|
-
};
|
|
43
|
-
const junoPayTickerToAssetIdMap = (0, invert_1.default)(assetIdToJunoPayTickerMap);
|
|
44
|
-
const junoPayTickerToAssetId = (id) => junoPayTickerToAssetIdMap[id];
|
|
45
|
-
exports.junoPayTickerToAssetId = junoPayTickerToAssetId;
|
|
46
|
-
const assetIdToJunoPayTicker = (assetId) => assetIdToJunoPayTickerMap[(0, toLower_1.default)(assetId)];
|
|
47
|
-
exports.assetIdToJunoPayTicker = assetIdToJunoPayTicker;
|
|
48
|
-
const getSupportedJunoPayAssets = () => (0, entries_1.default)(assetIdToJunoPayTickerMap).map(([assetId, ticker]) => ({
|
|
49
|
-
assetId,
|
|
50
|
-
ticker,
|
|
51
|
-
}));
|
|
52
|
-
exports.getSupportedJunoPayAssets = getSupportedJunoPayAssets;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const index_1 = require("./index");
|
|
4
|
-
const utils_1 = require("./utils");
|
|
5
|
-
const main = async () => {
|
|
6
|
-
const data = await (0, utils_1.fetchData)({
|
|
7
|
-
tokensUrl: index_1.osmosisGetTokensUrl,
|
|
8
|
-
lpTokensUrl: index_1.osmosisGetLpTokensUrl,
|
|
9
|
-
});
|
|
10
|
-
const output = (0, utils_1.parseData)(data);
|
|
11
|
-
await (0, utils_1.writeFiles)(output);
|
|
12
|
-
};
|
|
13
|
-
main();
|