@pioneer-platform/pioneer-caip 9.2.8 → 9.2.9
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/lib/data.d.ts +1 -0
- package/lib/data.js +35 -22
- package/package.json +2 -2
package/lib/data.d.ts
CHANGED
@@ -45,6 +45,7 @@ export declare enum Chain {
|
|
45
45
|
}
|
46
46
|
export declare const ChainToCaip: Record<string, string>;
|
47
47
|
export declare const ChainToNetworkId: Record<string, string>;
|
48
|
+
export declare const NetworkIdToChain: Record<string, string>;
|
48
49
|
export declare function getChainEnumValue(chainStr: string): Chain | undefined;
|
49
50
|
export declare const shortListSymbolToCoinGeckoPlatformId: {
|
50
51
|
ARB: string;
|
package/lib/data.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.caipToThorchain = exports.tokenToCaip = exports.thorchainToCaip = exports.shortListNameToCaip = exports.shortListSymbolToCaip = exports.shortListSymbolToCoinGeckoPlatformId = exports.getChainEnumValue = exports.ChainToNetworkId = exports.ChainToCaip = exports.Chain = exports.evmCaips = void 0;
|
3
|
+
exports.caipToThorchain = exports.tokenToCaip = exports.thorchainToCaip = exports.shortListNameToCaip = exports.shortListSymbolToCaip = exports.shortListSymbolToCoinGeckoPlatformId = exports.getChainEnumValue = exports.NetworkIdToChain = exports.ChainToNetworkId = exports.ChainToCaip = exports.Chain = exports.evmCaips = void 0;
|
4
4
|
exports.evmCaips = {
|
5
5
|
ethereum: 'eip155:1/slip44:60',
|
6
6
|
base: 'eip155:8453/slip44:60',
|
@@ -95,6 +95,12 @@ exports.ChainToNetworkId = {
|
|
95
95
|
'THOR': 'cosmos:thorchain-mainnet-v1',
|
96
96
|
'ZEC': 'bip122:0000000000196a45',
|
97
97
|
};
|
98
|
+
exports.NetworkIdToChain = Object.entries(exports.ChainToNetworkId)
|
99
|
+
.reduce(function (acc, _a) {
|
100
|
+
var key = _a[0], value = _a[1];
|
101
|
+
acc[value] = key;
|
102
|
+
return acc;
|
103
|
+
}, {});
|
98
104
|
function getChainEnumValue(chainStr) {
|
99
105
|
switch (chainStr) {
|
100
106
|
case 'ARB':
|
@@ -291,7 +297,7 @@ var thorchainToCaip = function (chain, symbol, ticker, type) {
|
|
291
297
|
//if token
|
292
298
|
if (symbol.indexOf("-") > -1) {
|
293
299
|
var contract = symbol.split("-")[1];
|
294
|
-
caip = "".concat(networkId, "
|
300
|
+
caip = "".concat(networkId, "/erc20:").concat(contract);
|
295
301
|
}
|
296
302
|
else {
|
297
303
|
console.error({ chain: chain, symbol: symbol, ticker: ticker, type: type });
|
@@ -310,31 +316,38 @@ exports.thorchainToCaip = thorchainToCaip;
|
|
310
316
|
// Caips do NOT include the token tickers!
|
311
317
|
var caipToThorchain = function (caip, ticker) {
|
312
318
|
try {
|
313
|
-
var
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
var
|
318
|
-
|
319
|
-
|
320
|
-
var _b = _a[_i], symbol = _b[0], thorChainNetworkId = _b[1];
|
321
|
-
var thorChainId = thorChainNetworkId.split(':')[1];
|
322
|
-
if (thorChainId === chainId) {
|
323
|
-
thorChainSymbol = symbol;
|
324
|
-
break;
|
325
|
-
}
|
326
|
-
}
|
327
|
-
if (!thorChainSymbol) {
|
328
|
-
console.error("No matching THORChain symbol found for network ID", networkId);
|
319
|
+
var networkId = caip.split('/')[0]; // Splitting off the network ID from the CAIP
|
320
|
+
console.log("networkId: ", networkId);
|
321
|
+
if (!networkId)
|
322
|
+
throw Error("Invalid CAIP!");
|
323
|
+
var chain = exports.NetworkIdToChain[networkId];
|
324
|
+
if (!chain) {
|
325
|
+
console.error("No matching chain symbol found for network ID", networkId);
|
329
326
|
return null;
|
330
327
|
}
|
331
|
-
|
332
|
-
|
328
|
+
// Handling contract tokens
|
329
|
+
if (caip.includes('erc20')) {
|
330
|
+
if (!ticker) {
|
331
|
+
console.error("Ticker is undefined for ERC20 token");
|
332
|
+
return null;
|
333
|
+
}
|
334
|
+
var parts = caip.split('/');
|
335
|
+
var contractPart = parts[1];
|
336
|
+
var contractAddress = contractPart.split(':')[1];
|
337
|
+
if (!contractAddress) {
|
338
|
+
console.error("Contract address is undefined for ERC20 token");
|
339
|
+
return null;
|
340
|
+
}
|
341
|
+
// Use the ticker as is without converting to uppercase
|
342
|
+
return "".concat(chain, ".").concat(ticker, "-").concat(contractAddress.toUpperCase());
|
343
|
+
}
|
344
|
+
else {
|
345
|
+
// Handling native tokens
|
346
|
+
return chain + "." + chain;
|
333
347
|
}
|
334
|
-
return thorChainSymbol;
|
335
348
|
}
|
336
349
|
catch (e) {
|
337
|
-
console.error("Error processing
|
350
|
+
console.error("Error processing network ID to THORChain", e);
|
338
351
|
return null;
|
339
352
|
}
|
340
353
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pioneer-platform/pioneer-caip",
|
3
|
-
"version": "9.2.
|
3
|
+
"version": "9.2.9",
|
4
4
|
"main": "./lib/index.js",
|
5
5
|
"types": "./lib/main.d.ts",
|
6
6
|
"_moduleAliases": {
|
@@ -9,7 +9,7 @@
|
|
9
9
|
"scripts": {
|
10
10
|
"npm": "npm i",
|
11
11
|
"build": "tsc -p .",
|
12
|
-
"test": "npm run build && node __tests__/
|
12
|
+
"test": "npm run build && node __tests__/tests-common.js",
|
13
13
|
"build:watch": "npm run build && onchange 'src/**/*.ts' -- npm run build",
|
14
14
|
"prepublish": "npm run build"
|
15
15
|
},
|