@shapeshiftoss/caip 8.14.0 → 8.16.0
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 -0
- package/dist/adapters/coingecko/generated/eip155_8453/adapter.json +1 -0
- package/dist/adapters/coingecko/generated/index.d.ts +10 -3
- package/dist/adapters/coingecko/generated/index.js +18 -26
- package/dist/adapters/coingecko/generated/solana_5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/adapter.json +1 -0
- package/dist/adapters/coingecko/index.d.ts +17 -14
- package/dist/adapters/coingecko/index.js +89 -72
- 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 +148 -50
- 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 +63 -38
- package/dist/constants.js +139 -99
- 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
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { ChainId, ChainNamespace, ChainReference } from '../chainId/chainId';
|
|
2
|
-
import { Nominal } from '../utils';
|
|
3
|
-
export
|
|
4
|
-
|
|
1
|
+
import type { ChainId, ChainNamespace, ChainReference } from '../chainId/chainId';
|
|
2
|
+
import type { Nominal } from '../utils';
|
|
3
|
+
export type AccountId = Nominal<string, 'AccountId'>;
|
|
4
|
+
type ToAccountIdWithChainId = {
|
|
5
5
|
chainId: ChainId;
|
|
6
6
|
account: string;
|
|
7
7
|
chainNamespace?: never;
|
|
8
8
|
chainReference?: never;
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
type ToAccountIdWithChainIdParts = {
|
|
11
11
|
chainId?: never;
|
|
12
12
|
account: string;
|
|
13
13
|
chainNamespace: ChainNamespace;
|
|
14
14
|
chainReference: ChainReference;
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
type ToAccountIdArgs = ToAccountIdWithChainId | ToAccountIdWithChainIdParts;
|
|
17
|
+
type ToAccountId = (args: ToAccountIdArgs) => AccountId;
|
|
18
18
|
export declare const toAccountId: ToAccountId;
|
|
19
|
-
|
|
19
|
+
type FromAccountIdReturn = {
|
|
20
20
|
chainId: ChainId;
|
|
21
21
|
account: string;
|
|
22
22
|
chainNamespace: ChainNamespace;
|
|
23
23
|
chainReference: ChainReference;
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
type FromAccountId = (accountId: AccountId) => FromAccountIdReturn;
|
|
26
26
|
export declare const fromAccountId: FromAccountId;
|
|
27
27
|
export declare const toCAIP10: ToAccountId;
|
|
28
28
|
export declare const fromCAIP10: FromAccountId;
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
const typeGuards_1 = require("../typeGuards");
|
|
7
|
-
const toAccountId = ({ chainId: maybeChainId, chainNamespace: maybeChainNamespace, chainReference: maybeChainReference, account, }) => {
|
|
1
|
+
import { fromChainId, toChainId } from '../chainId/chainId';
|
|
2
|
+
import { CHAIN_NAMESPACE } from '../constants';
|
|
3
|
+
import { assertIsChainId, assertIsChainNamespace, assertIsChainReference } from '../typeGuards';
|
|
4
|
+
export const toAccountId = ({ chainId: maybeChainId, chainNamespace: maybeChainNamespace, chainReference: maybeChainReference, account, }) => {
|
|
8
5
|
if (!account)
|
|
9
6
|
throw new Error(`toAccountId: account is required`);
|
|
10
|
-
const chainId = maybeChainId
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
const chainId = maybeChainId ??
|
|
8
|
+
toChainId({ chainNamespace: maybeChainNamespace, chainReference: maybeChainReference });
|
|
9
|
+
assertIsChainId(chainId);
|
|
10
|
+
const { chainNamespace } = fromChainId(chainId);
|
|
13
11
|
// we lowercase eth accounts as per the draft spec
|
|
14
12
|
// it's not explicit, but cHecKsUM can be recovered from lowercase eth accounts
|
|
15
13
|
// we don't lowercase bitcoin addresses as they'll fail checksum
|
|
16
|
-
const outputAccount = chainNamespace ===
|
|
14
|
+
const outputAccount = chainNamespace === CHAIN_NAMESPACE.Evm ? account.toLowerCase() : account;
|
|
17
15
|
return `${chainId}:${outputAccount}`;
|
|
18
16
|
};
|
|
19
|
-
|
|
20
|
-
const fromAccountId = (accountId) => {
|
|
17
|
+
export const fromAccountId = accountId => {
|
|
21
18
|
const parts = accountId.split(':');
|
|
22
19
|
if (parts.length !== 3) {
|
|
23
20
|
throw new Error(`fromAccountId: invalid AccountId ${accountId}`);
|
|
@@ -25,9 +22,9 @@ const fromAccountId = (accountId) => {
|
|
|
25
22
|
const chainNamespace = parts[0];
|
|
26
23
|
const chainReference = parts[1];
|
|
27
24
|
const chainId = parts.slice(0, 2).join(':');
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
assertIsChainNamespace(chainNamespace);
|
|
26
|
+
assertIsChainReference(chainReference);
|
|
27
|
+
assertIsChainId(chainId);
|
|
31
28
|
const account = parts[2];
|
|
32
29
|
if (!account) {
|
|
33
30
|
throw new Error(`fromAccountId: account required`);
|
|
@@ -35,9 +32,8 @@ const fromAccountId = (accountId) => {
|
|
|
35
32
|
// we lowercase eth accounts as per the draft spec
|
|
36
33
|
// it's not explicit, but cHecKsUM can be recovered from lowercase eth accounts
|
|
37
34
|
// we don't lowercase bitcoin addresses as they'll fail checksum
|
|
38
|
-
const outputAccount = chainNamespace ===
|
|
35
|
+
const outputAccount = chainNamespace === CHAIN_NAMESPACE.Evm ? account.toLowerCase() : account;
|
|
39
36
|
return { chainId, account: outputAccount, chainNamespace, chainReference };
|
|
40
37
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
exports.fromCAIP10 = exports.fromAccountId;
|
|
38
|
+
export const toCAIP10 = toAccountId;
|
|
39
|
+
export const fromCAIP10 = fromAccountId;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { toChainId } from '../chainId/chainId';
|
|
3
|
+
import { CHAIN_NAMESPACE, CHAIN_REFERENCE } from '../constants';
|
|
4
|
+
import { fromAccountId, fromCAIP10, toAccountId, toCAIP10 } from './accountId';
|
|
5
|
+
describe('toAccountId', () => {
|
|
6
|
+
it('should have matching CAIP10 aliases', () => {
|
|
7
|
+
expect(toAccountId).toEqual(toCAIP10);
|
|
8
|
+
expect(fromAccountId).toEqual(fromCAIP10);
|
|
9
|
+
});
|
|
10
|
+
it('throws on invalid chainId', () => {
|
|
11
|
+
const chainNamespace = 'eeep';
|
|
12
|
+
const chainReference = '123';
|
|
13
|
+
const chainId = `${chainNamespace}:${chainReference}`;
|
|
14
|
+
const account = '0xa44c286ba83bb771cd0107b2c1df678435bd1535';
|
|
15
|
+
expect(() => toAccountId({ chainId, account })).toThrow();
|
|
16
|
+
expect(() => toAccountId({ chainNamespace, chainReference, account })).toThrow();
|
|
17
|
+
});
|
|
18
|
+
it('throws on empty account', () => {
|
|
19
|
+
const chainNamespace = CHAIN_NAMESPACE.Evm;
|
|
20
|
+
const chainReference = CHAIN_REFERENCE.EthereumMainnet;
|
|
21
|
+
const chainId = toChainId({ chainNamespace, chainReference });
|
|
22
|
+
const account = '';
|
|
23
|
+
expect(() => toAccountId({ chainId, account })).toThrow();
|
|
24
|
+
expect(() => toAccountId({ chainNamespace, chainReference, account })).toThrow();
|
|
25
|
+
});
|
|
26
|
+
it('accepts valid eth chainId and account', () => {
|
|
27
|
+
const chainNamespace = CHAIN_NAMESPACE.Evm;
|
|
28
|
+
const chainReference = CHAIN_REFERENCE.EthereumMainnet;
|
|
29
|
+
const chainId = toChainId({ chainNamespace, chainReference });
|
|
30
|
+
const account = '0xa44c286ba83bb771cd0107b2c1df678435bd1535';
|
|
31
|
+
const expectedAccountId = `${chainId}:${account}`;
|
|
32
|
+
expect(toAccountId({ chainId, account })).toEqual(expectedAccountId);
|
|
33
|
+
expect(toAccountId({ chainNamespace, chainReference, account })).toEqual(expectedAccountId);
|
|
34
|
+
});
|
|
35
|
+
it('lowercases eth address', () => {
|
|
36
|
+
const chainNamespace = CHAIN_NAMESPACE.Evm;
|
|
37
|
+
const chainReference = CHAIN_REFERENCE.EthereumMainnet;
|
|
38
|
+
const chainId = toChainId({ chainNamespace, chainReference });
|
|
39
|
+
const account = '0xA44C286BA83Bb771cd0107B2c1Df678435Bd1535';
|
|
40
|
+
const expectedAccountId = `${chainId}:${account.toLowerCase()}`;
|
|
41
|
+
expect(toAccountId({ chainId, account })).toEqual(expectedAccountId);
|
|
42
|
+
expect(toAccountId({ chainNamespace, chainReference, account })).toEqual(expectedAccountId);
|
|
43
|
+
});
|
|
44
|
+
it('does not lowercase bitcoin account', () => {
|
|
45
|
+
const chainNamespace = CHAIN_NAMESPACE.Utxo;
|
|
46
|
+
const chainReference = CHAIN_REFERENCE.BitcoinMainnet;
|
|
47
|
+
const chainId = toChainId({ chainNamespace, chainReference });
|
|
48
|
+
const account = '327aHcrjdooNUzG3qqZkuVZkm3MyjgxScn';
|
|
49
|
+
const expectedAccountId = `${chainId}:${account}`;
|
|
50
|
+
expect(toAccountId({ chainId, account })).toEqual(expectedAccountId);
|
|
51
|
+
expect(toAccountId({ chainNamespace, chainReference, account })).toEqual(expectedAccountId);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe('fromAccountId', () => {
|
|
55
|
+
it('throws on empty string', () => {
|
|
56
|
+
const accountId = '';
|
|
57
|
+
expect(() => fromAccountId(accountId)).toThrow();
|
|
58
|
+
});
|
|
59
|
+
it('returns chainId and account for bitcoin', () => {
|
|
60
|
+
const accountId = 'bip122:000000000019d6689c085ae165831e93:327aHcrjdooNUzG3qqZkuVZkm3MyjgxScn';
|
|
61
|
+
const { account, chainId, chainNamespace, chainReference } = fromAccountId(accountId);
|
|
62
|
+
const expectedAccount = '327aHcrjdooNUzG3qqZkuVZkm3MyjgxScn';
|
|
63
|
+
const expectedChainNamespace = CHAIN_NAMESPACE.Utxo;
|
|
64
|
+
const expectedChainReference = CHAIN_REFERENCE.BitcoinMainnet;
|
|
65
|
+
expect(account).toEqual(expectedAccount);
|
|
66
|
+
expect(chainNamespace).toEqual(expectedChainNamespace);
|
|
67
|
+
expect(chainReference).toEqual(expectedChainReference);
|
|
68
|
+
expect(chainId).toEqual(`${expectedChainNamespace}:${expectedChainReference}`);
|
|
69
|
+
});
|
|
70
|
+
it('returns chainId and account for dogecoin', () => {
|
|
71
|
+
const accountId = 'bip122:00000000001a91e3dace36e2be3bf030:DDFrdu2AyWCkgpdypkABTnL6FWBGKSAL8V';
|
|
72
|
+
const { account, chainId, chainNamespace, chainReference } = fromAccountId(accountId);
|
|
73
|
+
const expectedAccount = 'DDFrdu2AyWCkgpdypkABTnL6FWBGKSAL8V';
|
|
74
|
+
const expectedChainNamespace = CHAIN_NAMESPACE.Utxo;
|
|
75
|
+
const expectedChainReference = CHAIN_REFERENCE.DogecoinMainnet;
|
|
76
|
+
expect(account).toEqual(expectedAccount);
|
|
77
|
+
expect(chainNamespace).toEqual(expectedChainNamespace);
|
|
78
|
+
expect(chainReference).toEqual(expectedChainReference);
|
|
79
|
+
expect(chainId).toEqual(`${expectedChainNamespace}:${expectedChainReference}`);
|
|
80
|
+
});
|
|
81
|
+
it('returns chainId and account for eth', () => {
|
|
82
|
+
const accountId = 'eip155:1:0xa44c286ba83bb771cd0107b2c1df678435bd1535';
|
|
83
|
+
const { account, chainId, chainNamespace, chainReference } = fromAccountId(accountId);
|
|
84
|
+
const expectedAccount = '0xa44c286ba83bb771cd0107b2c1df678435bd1535';
|
|
85
|
+
const expectedChainNamespace = CHAIN_NAMESPACE.Evm;
|
|
86
|
+
const expectedChainReference = CHAIN_REFERENCE.EthereumMainnet;
|
|
87
|
+
expect(account).toEqual(expectedAccount);
|
|
88
|
+
expect(chainNamespace).toEqual(expectedChainNamespace);
|
|
89
|
+
expect(chainReference).toEqual(expectedChainReference);
|
|
90
|
+
expect(chainId).toEqual(`${expectedChainNamespace}:${expectedChainReference}`);
|
|
91
|
+
});
|
|
92
|
+
it('lowercases eth account', () => {
|
|
93
|
+
const accountId = 'eip155:1:0xA44C286BA83Bb771cd0107B2c1Df678435Bd1535';
|
|
94
|
+
const { account, chainId, chainNamespace, chainReference } = fromAccountId(accountId);
|
|
95
|
+
const expectedAccount = '0xa44c286ba83bb771cd0107b2c1df678435bd1535';
|
|
96
|
+
const expectedChainNamespace = CHAIN_NAMESPACE.Evm;
|
|
97
|
+
const expectedChainReference = CHAIN_REFERENCE.EthereumMainnet;
|
|
98
|
+
expect(account).toEqual(expectedAccount);
|
|
99
|
+
expect(chainNamespace).toEqual(expectedChainNamespace);
|
|
100
|
+
expect(chainReference).toEqual(expectedChainReference);
|
|
101
|
+
expect(chainId).toEqual(`${expectedChainNamespace}:${expectedChainReference}`);
|
|
102
|
+
});
|
|
103
|
+
it('throws on empty account', () => {
|
|
104
|
+
const accountId = 'eip155:1:';
|
|
105
|
+
expect(() => fromAccountId(accountId)).toThrow();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { AssetId } from '../../assetId/assetId';
|
|
2
|
+
import type { ChainId } from '../../chainId/chainId';
|
|
3
3
|
export declare const getSupportedBanxaAssets: () => {
|
|
4
4
|
assetId: string;
|
|
5
5
|
ticker: string;
|
|
6
6
|
}[];
|
|
7
|
+
export declare const assetIdToBanxaTicker: (assetId: AssetId) => string | undefined;
|
|
7
8
|
/**
|
|
8
|
-
* Convert a
|
|
9
|
+
* Convert a ChainId to a Banxa chain identifier for use in Banxa HTTP URLs
|
|
9
10
|
*
|
|
10
|
-
* @param {
|
|
11
|
+
* @param {ChainId} chainId - a ChainId
|
|
11
12
|
* @returns {string} - a Banxa chain identifier; e.g., 'cosmos'
|
|
12
13
|
*/
|
|
13
|
-
export declare const
|
|
14
|
+
export declare const getBanxaBlockchainFromChainId: (chainId: ChainId) => string;
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getBanxaBlockchainFromBanxaAssetTicker = exports.getSupportedBanxaAssets = exports.assetIdToBanxaTicker = exports.banxaTickerToAssetId = 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 assetId_1 = require("../../assetId/assetId");
|
|
11
|
-
const constants_1 = require("../../constants");
|
|
1
|
+
import entries from 'lodash/entries';
|
|
2
|
+
import { arbitrumAssetId, arbitrumChainId, avalancheAssetId, avalancheChainId, baseAssetId, baseChainId, bscAssetId, bscChainId, btcAssetId, btcChainId, cosmosAssetId, cosmosChainId, dogeAssetId, dogeChainId, ethAssetId, ethChainId, optimismAssetId, optimismChainId, polygonAssetId, polygonChainId, solanaChainId, solAssetId, thorchainAssetId, thorchainChainId, } from '../../constants';
|
|
12
3
|
/**
|
|
13
4
|
* https://docs.google.com/spreadsheets/d/1KU6J1Hl4vxBTIWCwWdrFfSadNltuFheQRoJyPrd0LMQ/edit#gid=631982242
|
|
14
5
|
* source of truth per banxa
|
|
15
6
|
*/
|
|
16
7
|
const AssetIdToBanxaTickerMap = {
|
|
17
|
-
[
|
|
18
|
-
[
|
|
19
|
-
[
|
|
20
|
-
[
|
|
21
|
-
[
|
|
8
|
+
[btcAssetId]: 'btc',
|
|
9
|
+
[dogeAssetId]: 'doge',
|
|
10
|
+
[cosmosAssetId]: 'atom',
|
|
11
|
+
[ethAssetId]: 'eth',
|
|
12
|
+
[avalancheAssetId]: 'avax',
|
|
13
|
+
[bscAssetId]: 'bnb',
|
|
14
|
+
[optimismAssetId]: 'eth',
|
|
15
|
+
[arbitrumAssetId]: 'eth',
|
|
16
|
+
[baseAssetId]: 'eth',
|
|
17
|
+
[polygonAssetId]: 'matic',
|
|
18
|
+
[thorchainAssetId]: 'rune',
|
|
19
|
+
[solAssetId]: 'sol',
|
|
22
20
|
'eip155:1/erc20:0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9': 'aave',
|
|
23
21
|
'eip155:1/erc20:0xbb0e17ef65f82ab018d8edd776e8dd940327b28b': 'axs',
|
|
24
22
|
'eip155:1/erc20:0x4d224452801aced8b2f0aebe155379bb5d594381': 'ape',
|
|
@@ -44,18 +42,37 @@ const AssetIdToBanxaTickerMap = {
|
|
|
44
42
|
'eip155:1/erc20:0x8e870d67f660d95d5be530380d0ec0bd388289e1': 'usdp',
|
|
45
43
|
'eip155:1/erc20:0xdac17f958d2ee523a2206206994597c13d831ec7': 'usdt',
|
|
46
44
|
'eip155:1/erc20:0x2260fac5e5542a773aa44fbcfedf7c193bc2c599': 'wbtc',
|
|
47
|
-
'eip155:
|
|
45
|
+
'eip155:1/erc20:0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e': 'yfi',
|
|
46
|
+
'eip155:1/erc20:0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0': 'matic',
|
|
47
|
+
'eip155:10/erc20:0x0b2c639c533813f4aa9d7837caf62653d097ff85': 'usdc',
|
|
48
|
+
'eip155:56/bep20:0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82': 'cake',
|
|
49
|
+
'eip155:56/bep20:0xf8a0bf9cf54bb92f17374d9e9a321e6a111a51bd': 'link',
|
|
50
|
+
'eip155:56/bep20:0x55d398326f99059ff775485246999027b3197955': 'usdt',
|
|
51
|
+
'eip155:56/bep20:0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d': 'usdc',
|
|
52
|
+
'eip155:56/bep20:0xfb6115445bff7b52feb98650c87f44907e58f802': 'aave',
|
|
53
|
+
'eip155:56/bep20:0x52ce071bd9b1c4b00a0b92d298c512478cad67e8': 'comp',
|
|
54
|
+
'eip155:56/bep20:0x7083609fce4d1d8dc0c979aab8c869ea2c873402': 'dot',
|
|
55
|
+
'eip155:56/bep20:0xcc42724c6683b7e57334c4e856f4c9965ed682bd': 'matic',
|
|
56
|
+
'eip155:56/bep20:0x1ce0c2827e2ef14d5c4f29a091d735a204794041': 'avax',
|
|
57
|
+
'eip155:56/bep20:0x947950bcc74888a40ffa2593c5798f11fc9124c4': 'sushi',
|
|
58
|
+
'eip155:56/bep20:0xbf5140a22578168fd562dccf235e5d43a02ce9b1': 'uni',
|
|
59
|
+
'eip155:137/erc20:0xc2132d05d31c914a87c6611c10748aeb04b58e8f': 'usdt',
|
|
60
|
+
'eip155:137/erc20:0x3c499c542cef5e3811e1192ce70d8cc03d5c3359': 'usdc',
|
|
61
|
+
'eip155:137/erc20:0x8f3cf7ad23cd3cadbd9735aff958023239c6a063': 'dai',
|
|
62
|
+
'eip155:8453/erc20:0x833589fcd6edb6e08f4c7c32d4f71b54bda02913': 'usdc',
|
|
63
|
+
'eip155:8453/erc20:0x50c5725949a6f0c72e6c4a641f24049a917db0cb': 'dai',
|
|
64
|
+
'eip155:42161/erc20:0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9': 'usdt',
|
|
65
|
+
'eip155:42161/erc20:0xaf88d065e77c8cc2239327c5edb3a432268e5831': 'usdc',
|
|
66
|
+
'eip155:43114/erc20:0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7': 'usdt',
|
|
67
|
+
'eip155:43114/erc20:0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e': 'usdc',
|
|
68
|
+
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v': 'usdc',
|
|
69
|
+
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB': 'usdt',
|
|
48
70
|
};
|
|
49
|
-
const
|
|
50
|
-
const banxaTickerToAssetId = (id) => banxaTickerToAssetIdMap[id];
|
|
51
|
-
exports.banxaTickerToAssetId = banxaTickerToAssetId;
|
|
52
|
-
const assetIdToBanxaTicker = (assetId) => AssetIdToBanxaTickerMap[(0, toLower_1.default)(assetId)];
|
|
53
|
-
exports.assetIdToBanxaTicker = assetIdToBanxaTicker;
|
|
54
|
-
const getSupportedBanxaAssets = () => (0, entries_1.default)(AssetIdToBanxaTickerMap).map(([assetId, ticker]) => ({
|
|
71
|
+
export const getSupportedBanxaAssets = () => entries(AssetIdToBanxaTickerMap).map(([assetId, ticker]) => ({
|
|
55
72
|
assetId,
|
|
56
73
|
ticker,
|
|
57
74
|
}));
|
|
58
|
-
|
|
75
|
+
export const assetIdToBanxaTicker = (assetId) => AssetIdToBanxaTickerMap[assetId];
|
|
59
76
|
/**
|
|
60
77
|
* map ChainIds to Banxa blockchain codes (ETH, BTC, COSMOS),
|
|
61
78
|
* since some Banxa assets could be on multiple chains and their default
|
|
@@ -65,23 +82,28 @@ exports.getSupportedBanxaAssets = getSupportedBanxaAssets;
|
|
|
65
82
|
* source of truth per banxa
|
|
66
83
|
*/
|
|
67
84
|
const chainIdToBanxaBlockchainCodeMap = {
|
|
68
|
-
[
|
|
69
|
-
[
|
|
70
|
-
[
|
|
71
|
-
[
|
|
72
|
-
[
|
|
85
|
+
[bscChainId]: 'BSC',
|
|
86
|
+
[ethChainId]: 'ETH',
|
|
87
|
+
[btcChainId]: 'BTC',
|
|
88
|
+
[cosmosChainId]: 'COSMOS',
|
|
89
|
+
[dogeChainId]: 'DOGE',
|
|
90
|
+
[avalancheChainId]: 'AVAX-C',
|
|
91
|
+
[optimismChainId]: 'OPTIMISM',
|
|
92
|
+
[polygonChainId]: 'MATIC',
|
|
93
|
+
[arbitrumChainId]: 'ARB',
|
|
94
|
+
[baseChainId]: 'BASE',
|
|
95
|
+
[thorchainChainId]: 'THORCHAIN',
|
|
96
|
+
[solanaChainId]: 'SOL',
|
|
73
97
|
};
|
|
74
98
|
/**
|
|
75
|
-
* Convert a
|
|
99
|
+
* Convert a ChainId to a Banxa chain identifier for use in Banxa HTTP URLs
|
|
76
100
|
*
|
|
77
|
-
* @param {
|
|
101
|
+
* @param {ChainId} chainId - a ChainId
|
|
78
102
|
* @returns {string} - a Banxa chain identifier; e.g., 'cosmos'
|
|
79
103
|
*/
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
-
if (!
|
|
83
|
-
throw new Error(`
|
|
84
|
-
|
|
85
|
-
return chainIdToBanxaBlockchainCodeMap[chainId];
|
|
104
|
+
export const getBanxaBlockchainFromChainId = (chainId) => {
|
|
105
|
+
const banxaChainId = chainIdToBanxaBlockchainCodeMap[chainId];
|
|
106
|
+
if (!banxaChainId)
|
|
107
|
+
throw new Error(`getBanxaBlockchainFromChainId: ${chainId} is not supported on Banxa`);
|
|
108
|
+
return banxaChainId;
|
|
86
109
|
};
|
|
87
|
-
exports.getBanxaBlockchainFromBanxaAssetTicker = getBanxaBlockchainFromBanxaAssetTicker;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const utils_1 = require("./utils");
|
|
4
|
-
// To run, install ts-node globally `npm i -g ts-node`
|
|
5
|
-
// From the caip package root. Run `ts-node ./src/adapters/coinbase/generate.ts`
|
|
1
|
+
import { getData, parseData, writeFiles } from './utils';
|
|
6
2
|
const main = async () => {
|
|
7
|
-
const coinbaseCurrencies = await
|
|
8
|
-
const output =
|
|
9
|
-
await
|
|
3
|
+
const coinbaseCurrencies = await getData();
|
|
4
|
+
const output = parseData(coinbaseCurrencies);
|
|
5
|
+
await writeFiles(output);
|
|
10
6
|
};
|
|
11
7
|
main();
|
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.tickerMap = void 0;
|
|
7
|
-
const adapter_json_1 = __importDefault(require("./adapter.json"));
|
|
8
|
-
exports.tickerMap = adapter_json_1.default;
|
|
1
|
+
import tickerMap from './adapter.json';
|
|
2
|
+
export { tickerMap };
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.assetIdToCoinbaseTicker = exports.coinbaseTickerToAssetId = void 0;
|
|
7
|
-
const invert_1 = __importDefault(require("lodash/invert"));
|
|
8
|
-
const toLower_1 = __importDefault(require("lodash/toLower"));
|
|
9
|
-
const generated_1 = require("./generated");
|
|
1
|
+
import invert from 'lodash/invert';
|
|
2
|
+
import toLower from 'lodash/toLower';
|
|
3
|
+
import { tickerMap } from './generated';
|
|
10
4
|
// As of 2022/06/13 (ETH/BTC/COSMOS assets)
|
|
11
|
-
const assetIdToCoinbaseTickerMap =
|
|
12
|
-
const coinbaseAssetIdToAssetIdMap = (
|
|
13
|
-
const coinbaseTickerToAssetId = (id) => coinbaseAssetIdToAssetIdMap[id];
|
|
14
|
-
|
|
15
|
-
const assetIdToCoinbaseTicker = (assetId) => assetIdToCoinbaseTickerMap[(0, toLower_1.default)(assetId)];
|
|
16
|
-
exports.assetIdToCoinbaseTicker = assetIdToCoinbaseTicker;
|
|
5
|
+
const assetIdToCoinbaseTickerMap = tickerMap;
|
|
6
|
+
const coinbaseAssetIdToAssetIdMap = invert(assetIdToCoinbaseTickerMap);
|
|
7
|
+
export const coinbaseTickerToAssetId = (id) => coinbaseAssetIdToAssetIdMap[id];
|
|
8
|
+
export const assetIdToCoinbaseTicker = (assetId) => assetIdToCoinbaseTickerMap[toLower(assetId)];
|
|
@@ -1,31 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.writeFiles = exports.getData = exports.parseData = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const toLower_1 = __importDefault(require("lodash/toLower"));
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import toLower from 'lodash/toLower';
|
|
10
4
|
function coinbaseCurrencyToAssetId(currency) {
|
|
11
|
-
var _a;
|
|
12
5
|
if (currency.id === 'BTC')
|
|
13
6
|
return 'bip122:000000000019d6689c085ae165831e93/slip44:0';
|
|
14
7
|
if (currency.id === 'ATOM')
|
|
15
8
|
return 'cosmos:cosmoshub-4/slip44:118';
|
|
16
|
-
if (currency.id === 'OSMO')
|
|
17
|
-
return 'cosmos:osmosis-1/slip44:118';
|
|
18
9
|
if (currency.id === 'ETH')
|
|
19
10
|
return 'eip155:1/slip44:60';
|
|
20
11
|
if (currency.default_network === 'ethereum') {
|
|
21
|
-
const addressQuery =
|
|
22
|
-
const address = addressQuery
|
|
23
|
-
return `eip155:1/erc20:${(
|
|
12
|
+
const addressQuery = currency.details.crypto_address_link?.split('token/')[1];
|
|
13
|
+
const address = addressQuery?.split('?a')[0];
|
|
14
|
+
return `eip155:1/erc20:${toLower(address)}`;
|
|
24
15
|
}
|
|
25
16
|
console.info(`Could not create assetId from coinbase asset ${currency.id}`);
|
|
26
17
|
return null;
|
|
27
18
|
}
|
|
28
|
-
function parseData(data) {
|
|
19
|
+
export function parseData(data) {
|
|
29
20
|
return data.reduce((acc, current) => {
|
|
30
21
|
const assetId = coinbaseCurrencyToAssetId(current);
|
|
31
22
|
if (!assetId)
|
|
@@ -34,10 +25,9 @@ function parseData(data) {
|
|
|
34
25
|
return acc;
|
|
35
26
|
}, {});
|
|
36
27
|
}
|
|
37
|
-
|
|
38
|
-
async function getData() {
|
|
28
|
+
export async function getData() {
|
|
39
29
|
try {
|
|
40
|
-
const { data } = await
|
|
30
|
+
const { data } = await axios.get('https://api.pro.coinbase.com/currencies');
|
|
41
31
|
return data;
|
|
42
32
|
}
|
|
43
33
|
catch (err) {
|
|
@@ -45,14 +35,12 @@ async function getData() {
|
|
|
45
35
|
return [];
|
|
46
36
|
}
|
|
47
37
|
}
|
|
48
|
-
exports.getData = getData;
|
|
49
38
|
const writeFile = async (data) => {
|
|
50
39
|
const path = './src/adapters/coinbase/generated/';
|
|
51
40
|
const file = 'adapter.json';
|
|
52
|
-
await
|
|
41
|
+
await fs.promises.writeFile(`${path}${file}`, JSON.stringify(data, null, 2));
|
|
53
42
|
};
|
|
54
|
-
const writeFiles = async (data) => {
|
|
43
|
+
export const writeFiles = async (data) => {
|
|
55
44
|
await writeFile(data);
|
|
56
45
|
console.info('Generated Coinbase AssetId adapter data.');
|
|
57
46
|
};
|
|
58
|
-
exports.writeFiles = writeFiles;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const index_1 = require("./index");
|
|
4
|
-
const utils_1 = require("./utils");
|
|
1
|
+
import { coincapAssetUrl } from './index';
|
|
2
|
+
import { fetchData, parseData, writeFiles } from './utils';
|
|
5
3
|
const main = async () => {
|
|
6
|
-
const data = await
|
|
7
|
-
const output =
|
|
8
|
-
await
|
|
4
|
+
const data = await fetchData(coincapAssetUrl);
|
|
5
|
+
const output = parseData(data);
|
|
6
|
+
await writeFiles(output);
|
|
9
7
|
};
|
|
10
8
|
main();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "cosmos:thorchain-1/slip44:931": "thorchain" }
|