@shapeshiftoss/caip 2.4.0 → 2.5.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.
|
@@ -4,3 +4,10 @@ export declare const getSupportedBanxaAssets: () => {
|
|
|
4
4
|
CAIP19: string;
|
|
5
5
|
ticker: string;
|
|
6
6
|
}[];
|
|
7
|
+
/**
|
|
8
|
+
* Convert a banxa asset identifier to a Banxa chain identifier for use in Banxa HTTP URLs
|
|
9
|
+
*
|
|
10
|
+
* @param {string} banxaAssetId - a Banxa asset string referencing a specific asset; e.g., 'atom'
|
|
11
|
+
* @returns {string} - a Banxa chain identifier; e.g., 'cosmos'
|
|
12
|
+
*/
|
|
13
|
+
export declare const getBanxaBlockchainFromBanxaAssetTicker: (banxaAssetId: string) => string;
|
|
@@ -3,9 +3,11 @@ 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.getSupportedBanxaAssets = exports.CAIP19ToBanxaTicker = exports.banxaTickerToCAIP19 = void 0;
|
|
6
|
+
exports.getBanxaBlockchainFromBanxaAssetTicker = exports.getSupportedBanxaAssets = exports.CAIP19ToBanxaTicker = exports.banxaTickerToCAIP19 = void 0;
|
|
7
7
|
const entries_1 = __importDefault(require("lodash/entries"));
|
|
8
8
|
const toLower_1 = __importDefault(require("lodash/toLower"));
|
|
9
|
+
const caip2_1 = require("../../caip2/caip2");
|
|
10
|
+
const caip19_1 = require("../../caip19/caip19");
|
|
9
11
|
const CAIP19ToBanxaTickerMap = {
|
|
10
12
|
'bip122:000000000019d6689c085ae165831e93/slip44:0': 'btc',
|
|
11
13
|
'cosmos:cosmoshub-4/slip44:118': 'atom',
|
|
@@ -47,3 +49,28 @@ const getSupportedBanxaAssets = () => (0, entries_1.default)(CAIP19ToBanxaTicker
|
|
|
47
49
|
ticker
|
|
48
50
|
}));
|
|
49
51
|
exports.getSupportedBanxaAssets = getSupportedBanxaAssets;
|
|
52
|
+
/**
|
|
53
|
+
* map ChainIds to Banxa blockchain codes (ETH, BTC, COSMOS),
|
|
54
|
+
* since some Banxa assets could be on multiple chains and their default
|
|
55
|
+
* chain won't be exactly the same as ours.
|
|
56
|
+
*/
|
|
57
|
+
const chainIdToBanxaBlockchainCodeMap = {
|
|
58
|
+
'eip155:1': 'ETH',
|
|
59
|
+
'bip122:000000000019d6689c085ae165831e93': 'BTC',
|
|
60
|
+
'cosmos:cosmoshub-4': 'COSMOS'
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Convert a banxa asset identifier to a Banxa chain identifier for use in Banxa HTTP URLs
|
|
64
|
+
*
|
|
65
|
+
* @param {string} banxaAssetId - a Banxa asset string referencing a specific asset; e.g., 'atom'
|
|
66
|
+
* @returns {string} - a Banxa chain identifier; e.g., 'cosmos'
|
|
67
|
+
*/
|
|
68
|
+
const getBanxaBlockchainFromBanxaAssetTicker = (banxaAssetId) => {
|
|
69
|
+
const assetCAIP19 = (0, exports.banxaTickerToCAIP19)(banxaAssetId.toLowerCase());
|
|
70
|
+
if (!assetCAIP19)
|
|
71
|
+
throw new Error(`getBanxaBlockchainFromBanxaAssetTicker: ${banxaAssetId} is not supported`);
|
|
72
|
+
const { chain, network } = (0, caip19_1.fromCAIP19)(assetCAIP19);
|
|
73
|
+
const chainId = (0, caip2_1.toCAIP2)({ network, chain });
|
|
74
|
+
return chainIdToBanxaBlockchainCodeMap[chainId];
|
|
75
|
+
};
|
|
76
|
+
exports.getBanxaBlockchainFromBanxaAssetTicker = getBanxaBlockchainFromBanxaAssetTicker;
|