@pioneer-platform/pioneer-caip 9.2.14 → 9.2.16
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 +3 -4
- package/lib/data.js +51 -54
- package/package.json +3 -2
package/lib/data.d.ts
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
declare const caipToNetworkId: (caip: string) => string;
|
2
1
|
export declare const evmCaips: {
|
3
2
|
ethereum: string;
|
4
3
|
base: string;
|
@@ -121,11 +120,11 @@ export declare const shortListRangoNameToNetworkId: {
|
|
121
120
|
};
|
122
121
|
export declare const NetworkIdToRangoName: (networkId: string) => string | null;
|
123
122
|
declare let tokenToCaip: (token: any) => any;
|
124
|
-
declare let thorchainToCaip: (
|
123
|
+
declare let thorchainToCaip: (identifier: string) => string;
|
125
124
|
declare let caipToThorchain: (caip: string, ticker: string) => string | null;
|
126
125
|
declare let caipToRango: (caip: string, ticker: string) => {
|
127
126
|
blockchain: string;
|
128
127
|
symbol: string;
|
129
|
-
address:
|
128
|
+
address: string | null;
|
130
129
|
} | null;
|
131
|
-
export { thorchainToCaip, tokenToCaip, caipToThorchain, caipToRango
|
130
|
+
export { thorchainToCaip, tokenToCaip, caipToThorchain, caipToRango };
|
package/lib/data.js
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
"use strict";
|
2
|
+
/*
|
3
|
+
Caip tools
|
4
|
+
|
5
|
+
This file contains tools for working with CAIP-10 and CAIP-19 identifiers. and transactions layres
|
6
|
+
|
7
|
+
*/
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
4
|
-
var caipToNetworkId = function (caip) {
|
5
|
-
return caip.split('/')[0];
|
6
|
-
};
|
7
|
-
exports.caipToNetworkId = caipToNetworkId;
|
9
|
+
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;
|
8
10
|
exports.evmCaips = {
|
9
11
|
ethereum: 'eip155:1/slip44:60',
|
10
12
|
base: 'eip155:8453/slip44:60',
|
@@ -247,53 +249,57 @@ var NetworkIdToRangoName = function (networkId) {
|
|
247
249
|
exports.NetworkIdToRangoName = NetworkIdToRangoName;
|
248
250
|
var tokenToCaip = function (token) {
|
249
251
|
try {
|
250
|
-
|
251
|
-
|
252
|
-
var chain = void 0, symbol = void 0;
|
253
|
-
if (parts.length >= 2) {
|
254
|
-
chain = parts[0];
|
255
|
-
symbol = parts.slice(1).join('.'); // Re-join the remaining parts excluding the first
|
256
|
-
}
|
257
|
-
else {
|
258
|
-
// Fallback to the original method if there's only one or no period
|
259
|
-
chain = token.identifier.split('.')[0];
|
260
|
-
symbol = token.identifier.split('.')[1];
|
261
|
-
}
|
262
|
-
var type = void 0, ticker = void 0;
|
252
|
+
var caip = void 0;
|
253
|
+
console.log("token", token);
|
263
254
|
if (token.address) {
|
264
|
-
|
265
|
-
|
255
|
+
// For ERC20 tokens
|
256
|
+
var networkId = exports.ChainToNetworkId[token.chain];
|
257
|
+
if (!networkId)
|
258
|
+
throw new Error("Unsupported chain: ".concat(token.chain));
|
259
|
+
caip = "".concat(networkId, "/erc20:").concat(token.address);
|
260
|
+
token.type = 'token';
|
266
261
|
}
|
267
262
|
else {
|
268
|
-
|
269
|
-
|
263
|
+
// For native tokens, use the identifier as it is
|
264
|
+
caip = thorchainToCaip(token.identifier);
|
265
|
+
token.type = 'native';
|
270
266
|
}
|
271
|
-
|
272
|
-
token.networkId = exports.ChainToNetworkId[chain];
|
267
|
+
token.networkId = exports.ChainToNetworkId[token.chain];
|
273
268
|
token.caip = caip;
|
274
|
-
token.symbol = symbol
|
275
|
-
|
276
|
-
token.
|
277
|
-
// Get pubkey for chain
|
269
|
+
token.symbol = token.identifier.split('.')[1]; // Assuming the symbol is the second part of the identifier
|
270
|
+
// Keeping the original ticker unchanged
|
271
|
+
// token.ticker = token.address ? token.identifier.split('.')[1].split('-')[0] : token.identifier.split('.')[1];
|
278
272
|
return token;
|
279
273
|
}
|
280
274
|
catch (e) {
|
281
275
|
console.error(e);
|
276
|
+
return null;
|
282
277
|
}
|
283
278
|
};
|
284
279
|
exports.tokenToCaip = tokenToCaip;
|
285
|
-
var thorchainToCaip = function (
|
280
|
+
var thorchainToCaip = function (identifier) {
|
286
281
|
try {
|
287
282
|
var caip = void 0;
|
288
|
-
var
|
289
|
-
|
283
|
+
var parts = identifier.split('.');
|
284
|
+
var chain = parts[0];
|
285
|
+
var rest = parts.length > 1 ? parts.slice(1).join('.') : null;
|
286
|
+
var symbolAndContract = rest ? rest.split('-') : [null, null];
|
287
|
+
var symbol = symbolAndContract[0];
|
288
|
+
var contract = symbolAndContract[1];
|
289
|
+
if (contract) {
|
290
|
+
var networkId = exports.ChainToNetworkId[chain];
|
291
|
+
if (!networkId)
|
292
|
+
throw new Error("Unsupported chain: ".concat(chain));
|
293
|
+
caip = "".concat(networkId, "/erc20:").concat(contract);
|
294
|
+
return caip;
|
295
|
+
}
|
296
|
+
console.log("key:", identifier);
|
297
|
+
switch (identifier) {
|
290
298
|
case "OSMO.ATOM":
|
291
|
-
console.log("IBC atom detected");
|
292
299
|
caip = 'cosmos:osmosis-1/ibc:B011C1A0AD5E717F674BA59FD8E05B2F946E4FD41C9CB3311C95F7ED4B815620';
|
293
300
|
break;
|
294
301
|
case "AVAX.WETH":
|
295
|
-
|
296
|
-
caip = exports.ChainToCaip[chain];
|
302
|
+
caip = exports.ChainToCaip['AVAX'];
|
297
303
|
break;
|
298
304
|
case "BSC.BNB":
|
299
305
|
caip = exports.shortListNameToCaip['bnbsmartchain'];
|
@@ -313,21 +319,10 @@ var thorchainToCaip = function (chain, symbol, ticker, type) {
|
|
313
319
|
caip = exports.shortListNameToCaip[chain.toLowerCase()];
|
314
320
|
break;
|
315
321
|
default:
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
var networkId = exports.ChainToNetworkId[chain];
|
321
|
-
console.log("networkId: ", networkId);
|
322
|
-
if (symbol.indexOf(".") > -1) {
|
323
|
-
var contract = symbol.split("-")[1];
|
324
|
-
caip = "".concat(networkId, "/erc20:").concat(contract);
|
325
|
-
}
|
326
|
-
else {
|
327
|
-
console.error({ chain: chain, symbol: symbol, ticker: ticker, type: type });
|
328
|
-
throw Error("Unable to parse CAIP! TODO!");
|
329
|
-
}
|
330
|
-
}
|
322
|
+
var networkId = exports.ChainToNetworkId[chain];
|
323
|
+
if (!networkId)
|
324
|
+
throw new Error("Unsupported chain: ".concat(chain));
|
325
|
+
caip = exports.ChainToCaip[chain] || networkId; // Fallback to networkId if no direct mapping
|
331
326
|
break;
|
332
327
|
}
|
333
328
|
return caip;
|
@@ -350,6 +345,10 @@ var caipToThorchain = function (caip, ticker) {
|
|
350
345
|
console.error("No matching chain symbol found for network ID", networkId);
|
351
346
|
return null;
|
352
347
|
}
|
348
|
+
// Special handling for 'OSMO.ATOM'
|
349
|
+
if (networkId === 'cosmos:osmosis-1' && ticker === 'ATOM') {
|
350
|
+
return 'OSMO.ATOM';
|
351
|
+
}
|
353
352
|
// Handling contract tokens
|
354
353
|
if (caip.includes('erc20')) {
|
355
354
|
if (!ticker) {
|
@@ -364,7 +363,7 @@ var caipToThorchain = function (caip, ticker) {
|
|
364
363
|
return null;
|
365
364
|
}
|
366
365
|
// Use the ticker as is without converting to uppercase
|
367
|
-
return "".concat(chain, ".").concat(ticker, "-").concat(contractAddress
|
366
|
+
return "".concat(chain, ".").concat(ticker, "-").concat(contractAddress);
|
368
367
|
}
|
369
368
|
else {
|
370
369
|
// Handling native tokens
|
@@ -380,15 +379,13 @@ exports.caipToThorchain = caipToThorchain;
|
|
380
379
|
var caipToRango = function (caip, ticker) {
|
381
380
|
try {
|
382
381
|
var _a = caip.split('/'), networkId = _a[0], tokenInfo = _a[1];
|
383
|
-
var rangoName = (0, exports.NetworkIdToRangoName)(networkId);
|
384
|
-
// Extracting the symbol and address
|
382
|
+
var rangoName = (0, exports.NetworkIdToRangoName)(networkId);
|
385
383
|
var symbol = ticker;
|
386
|
-
var address = null;
|
384
|
+
var address = null; // Default to null
|
387
385
|
// For ERC20 tokens, the contract address is included in the CAIP
|
388
386
|
if (tokenInfo && tokenInfo.startsWith('erc20:')) {
|
389
387
|
address = tokenInfo.split(':')[1];
|
390
388
|
}
|
391
|
-
// Check if the Rango name is found
|
392
389
|
if (!rangoName) {
|
393
390
|
console.error('Rango name not found for networkId:', networkId);
|
394
391
|
return null;
|
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.16",
|
4
4
|
"main": "./lib/index.js",
|
5
5
|
"types": "./lib/main.d.ts",
|
6
6
|
"_moduleAliases": {
|
@@ -9,7 +9,8 @@
|
|
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__/test-module.js",
|
13
|
+
"test-suite": "npm run build && node __tests__/tests-common.js",
|
13
14
|
"build:watch": "npm run build && onchange 'src/**/*.ts' -- npm run build",
|
14
15
|
"prepublish": "npm run build"
|
15
16
|
},
|