@pioneer-platform/pioneer-caip 9.2.8 → 9.2.10
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 +20 -1
- package/lib/data.js +89 -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;
|
@@ -105,7 +106,25 @@ export declare const shortListNameToCaip: {
|
|
105
106
|
eos: string;
|
106
107
|
fio: string;
|
107
108
|
};
|
109
|
+
export declare const shortListRangoNameToNetworkId: {
|
110
|
+
COSMOS: string;
|
111
|
+
OSMOSIS: string;
|
112
|
+
AVAX_CCHAIN: string;
|
113
|
+
ETH: string;
|
114
|
+
THOR: string;
|
115
|
+
BCH: string;
|
116
|
+
LTC: string;
|
117
|
+
DASH: string;
|
118
|
+
DGB: string;
|
119
|
+
DOGE: string;
|
120
|
+
};
|
121
|
+
export declare const NetworkIdToRangoName: (networkId: string) => string | null;
|
108
122
|
declare let tokenToCaip: (token: any) => any;
|
109
123
|
declare let thorchainToCaip: (chain: string, symbol: string, ticker: string, type: string) => string;
|
110
124
|
declare let caipToThorchain: (caip: string, ticker: string) => string | null;
|
111
|
-
|
125
|
+
declare let caipToRango: (caip: string, ticker: string) => {
|
126
|
+
blockchain: string;
|
127
|
+
symbol: string;
|
128
|
+
address: any;
|
129
|
+
} | null;
|
130
|
+
export { thorchainToCaip, tokenToCaip, caipToThorchain, caipToRango };
|
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.caipToRango = exports.caipToThorchain = exports.tokenToCaip = exports.thorchainToCaip = exports.NetworkIdToRangoName = exports.shortListRangoNameToNetworkId = 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':
|
@@ -205,6 +211,36 @@ exports.shortListNameToCaip = {
|
|
205
211
|
eos: 'eip155:1:/erc20:0x86fa049857e0209aa7d9e616f7eb3b3b78ecfdb0',
|
206
212
|
fio: 'placeholder:caip:fio:native:fio-protocol'
|
207
213
|
};
|
214
|
+
exports.shortListRangoNameToNetworkId = {
|
215
|
+
COSMOS: 'cosmos:cosmoshub-4',
|
216
|
+
OSMOSIS: 'cosmos:osmosis-1',
|
217
|
+
AVAX_CCHAIN: 'eip155:43114',
|
218
|
+
ETH: 'eip155:1',
|
219
|
+
THOR: 'cosmos:thorchain-mainnet-v1',
|
220
|
+
BCH: 'bip122:000000000000000000651ef99cb9fcbe',
|
221
|
+
LTC: 'bip122:12a765e31ffd4059bada1e25190f6e98',
|
222
|
+
DASH: 'bip122:000007d91d1254d60e2dd1ae58038307',
|
223
|
+
DGB: 'bip122:digibytes-hash',
|
224
|
+
DOGE: 'bip122:00000000001a91e3dace36e2be3bf030'
|
225
|
+
};
|
226
|
+
var NetworkIdToRangoName = function (networkId) {
|
227
|
+
try {
|
228
|
+
// Inverting the mapping to find the Rango name based on networkId
|
229
|
+
for (var _i = 0, _a = Object.entries(exports.shortListRangoNameToNetworkId); _i < _a.length; _i++) {
|
230
|
+
var _b = _a[_i], rangoName = _b[0], rangoNetworkId = _b[1];
|
231
|
+
if (rangoNetworkId === networkId) {
|
232
|
+
return rangoName;
|
233
|
+
}
|
234
|
+
}
|
235
|
+
console.error('Rango name not found for networkId:', networkId);
|
236
|
+
return null;
|
237
|
+
}
|
238
|
+
catch (e) {
|
239
|
+
console.error("Error processing networkId to Rango Name", e);
|
240
|
+
return null;
|
241
|
+
}
|
242
|
+
};
|
243
|
+
exports.NetworkIdToRangoName = NetworkIdToRangoName;
|
208
244
|
var tokenToCaip = function (token) {
|
209
245
|
try {
|
210
246
|
// Handle identifiers with an extra period
|
@@ -291,7 +327,7 @@ var thorchainToCaip = function (chain, symbol, ticker, type) {
|
|
291
327
|
//if token
|
292
328
|
if (symbol.indexOf("-") > -1) {
|
293
329
|
var contract = symbol.split("-")[1];
|
294
|
-
caip = "".concat(networkId, "
|
330
|
+
caip = "".concat(networkId, "/erc20:").concat(contract);
|
295
331
|
}
|
296
332
|
else {
|
297
333
|
console.error({ chain: chain, symbol: symbol, ticker: ticker, type: type });
|
@@ -310,32 +346,63 @@ exports.thorchainToCaip = thorchainToCaip;
|
|
310
346
|
// Caips do NOT include the token tickers!
|
311
347
|
var caipToThorchain = function (caip, ticker) {
|
312
348
|
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);
|
349
|
+
var networkId = caip.split('/')[0]; // Splitting off the network ID from the CAIP
|
350
|
+
console.log("networkId: ", networkId);
|
351
|
+
if (!networkId)
|
352
|
+
throw Error("Invalid CAIP!");
|
353
|
+
var chain = exports.NetworkIdToChain[networkId];
|
354
|
+
if (!chain) {
|
355
|
+
console.error("No matching chain symbol found for network ID", networkId);
|
329
356
|
return null;
|
330
357
|
}
|
331
|
-
|
332
|
-
|
358
|
+
// Handling contract tokens
|
359
|
+
if (caip.includes('erc20')) {
|
360
|
+
if (!ticker) {
|
361
|
+
console.error("Ticker is undefined for ERC20 token");
|
362
|
+
return null;
|
363
|
+
}
|
364
|
+
var parts = caip.split('/');
|
365
|
+
var contractPart = parts[1];
|
366
|
+
var contractAddress = contractPart.split(':')[1];
|
367
|
+
if (!contractAddress) {
|
368
|
+
console.error("Contract address is undefined for ERC20 token");
|
369
|
+
return null;
|
370
|
+
}
|
371
|
+
// Use the ticker as is without converting to uppercase
|
372
|
+
return "".concat(chain, ".").concat(ticker, "-").concat(contractAddress.toUpperCase());
|
373
|
+
}
|
374
|
+
else {
|
375
|
+
// Handling native tokens
|
376
|
+
return chain + "." + chain;
|
333
377
|
}
|
334
|
-
return thorChainSymbol;
|
335
378
|
}
|
336
379
|
catch (e) {
|
337
|
-
console.error("Error processing
|
380
|
+
console.error("Error processing network ID to THORChain", e);
|
338
381
|
return null;
|
339
382
|
}
|
340
383
|
};
|
341
384
|
exports.caipToThorchain = caipToThorchain;
|
385
|
+
var caipToRango = function (caip, ticker) {
|
386
|
+
try {
|
387
|
+
var _a = caip.split('/'), networkId = _a[0], tokenInfo = _a[1];
|
388
|
+
var rangoName = (0, exports.NetworkIdToRangoName)(networkId); // Get the Rango name from the network ID
|
389
|
+
// Extracting the symbol and address
|
390
|
+
var symbol = ticker;
|
391
|
+
var address = null;
|
392
|
+
// For ERC20 tokens, the contract address is included in the CAIP
|
393
|
+
if (tokenInfo && tokenInfo.startsWith('erc20:')) {
|
394
|
+
address = tokenInfo.split(':')[1];
|
395
|
+
}
|
396
|
+
// Check if the Rango name is found
|
397
|
+
if (!rangoName) {
|
398
|
+
console.error('Rango name not found for networkId:', networkId);
|
399
|
+
return null;
|
400
|
+
}
|
401
|
+
return { blockchain: rangoName, symbol: symbol, address: address };
|
402
|
+
}
|
403
|
+
catch (e) {
|
404
|
+
console.error("Error processing CAIP to Rango", e);
|
405
|
+
return null;
|
406
|
+
}
|
407
|
+
};
|
408
|
+
exports.caipToRango = caipToRango;
|
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.10",
|
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
|
},
|