@pioneer-platform/pioneer-caip 9.2.15 → 9.2.17

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 CHANGED
@@ -1,4 +1,4 @@
1
- declare const caipToNetworkId: (caip: string) => string;
1
+ export declare const caipToNetworkId: (caip: string) => string;
2
2
  export declare const evmCaips: {
3
3
  ethereum: string;
4
4
  base: string;
@@ -121,11 +121,11 @@ export declare const shortListRangoNameToNetworkId: {
121
121
  };
122
122
  export declare const NetworkIdToRangoName: (networkId: string) => string | null;
123
123
  declare let tokenToCaip: (token: any) => any;
124
- declare let thorchainToCaip: (chain: string, symbol: string, ticker: any, type: string) => any;
124
+ declare let thorchainToCaip: (identifier: string) => string;
125
125
  declare let caipToThorchain: (caip: string, ticker: string) => string | null;
126
126
  declare let caipToRango: (caip: string, ticker: string) => {
127
127
  blockchain: string;
128
128
  symbol: string;
129
- address: any;
129
+ address: string | null;
130
130
  } | null;
131
- export { thorchainToCaip, tokenToCaip, caipToThorchain, caipToRango, caipToNetworkId };
131
+ export { thorchainToCaip, tokenToCaip, caipToThorchain, caipToRango };
package/lib/data.js CHANGED
@@ -1,8 +1,15 @@
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.caipToNetworkId = 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;
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 = exports.caipToNetworkId = void 0;
4
10
  var caipToNetworkId = function (caip) {
5
- return caip.split('/')[0];
11
+ var chain = caip.split(':')[0];
12
+ return "".concat(chain);
6
13
  };
7
14
  exports.caipToNetworkId = caipToNetworkId;
8
15
  exports.evmCaips = {
@@ -247,54 +254,57 @@ var NetworkIdToRangoName = function (networkId) {
247
254
  exports.NetworkIdToRangoName = NetworkIdToRangoName;
248
255
  var tokenToCaip = function (token) {
249
256
  try {
250
- // Handle identifiers with an extra period
251
- var parts = token.identifier.split('.');
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;
257
+ var caip = void 0;
258
+ console.log("token", token);
263
259
  if (token.address) {
264
- ticker = symbol.split('-')[0];
265
- type = 'token';
260
+ // For ERC20 tokens
261
+ var networkId = exports.ChainToNetworkId[token.chain];
262
+ if (!networkId)
263
+ throw new Error("Unsupported chain: ".concat(token.chain));
264
+ caip = "".concat(networkId, "/erc20:").concat(token.address);
265
+ token.type = 'token';
266
266
  }
267
267
  else {
268
- type = 'native';
269
- ticker = symbol;
268
+ // For native tokens, use the identifier as it is
269
+ caip = thorchainToCaip(token.identifier);
270
+ token.type = 'native';
270
271
  }
271
- var caip = thorchainToCaip(chain, symbol, ticker, type);
272
- token.networkId = exports.ChainToNetworkId[chain];
272
+ token.networkId = exports.ChainToNetworkId[token.chain];
273
273
  token.caip = caip;
274
- token.symbol = symbol;
275
- token.ticker = ticker;
276
- token.type = type;
277
- // Get pubkey for chain
274
+ token.symbol = token.identifier.split('.')[1]; // Assuming the symbol is the second part of the identifier
275
+ // Keeping the original ticker unchanged
276
+ // token.ticker = token.address ? token.identifier.split('.')[1].split('-')[0] : token.identifier.split('.')[1];
278
277
  return token;
279
278
  }
280
279
  catch (e) {
281
280
  console.error(e);
281
+ return null;
282
282
  }
283
283
  };
284
284
  exports.tokenToCaip = tokenToCaip;
285
- var thorchainToCaip = function (chain, symbol, ticker, type) {
285
+ var thorchainToCaip = function (identifier) {
286
286
  try {
287
287
  var caip = void 0;
288
- var key = chain + '.' + symbol; // Concatenate chain and symbol
289
- console.log("key:", key);
290
- switch (key) {
288
+ var parts = identifier.split('.');
289
+ var chain = parts[0];
290
+ var rest = parts.length > 1 ? parts.slice(1).join('.') : null;
291
+ var symbolAndContract = rest ? rest.split('-') : [null, null];
292
+ var symbol = symbolAndContract[0];
293
+ var contract = symbolAndContract[1];
294
+ if (contract) {
295
+ var networkId = exports.ChainToNetworkId[chain];
296
+ if (!networkId)
297
+ throw new Error("Unsupported chain: ".concat(chain));
298
+ caip = "".concat(networkId, "/erc20:").concat(contract);
299
+ return caip;
300
+ }
301
+ console.log("key:", identifier);
302
+ switch (identifier) {
291
303
  case "OSMO.ATOM":
292
- // Specific case for OSMO.ATOM
293
304
  caip = 'cosmos:osmosis-1/ibc:B011C1A0AD5E717F674BA59FD8E05B2F946E4FD41C9CB3311C95F7ED4B815620';
294
305
  break;
295
306
  case "AVAX.WETH":
296
- console.log("WETH detected");
297
- caip = exports.ChainToCaip[chain];
307
+ caip = exports.ChainToCaip['AVAX'];
298
308
  break;
299
309
  case "BSC.BNB":
300
310
  caip = exports.shortListNameToCaip['bnbsmartchain'];
@@ -314,21 +324,10 @@ var thorchainToCaip = function (chain, symbol, ticker, type) {
314
324
  caip = exports.shortListNameToCaip[chain.toLowerCase()];
315
325
  break;
316
326
  default:
317
- if (chain === symbol) {
318
- caip = exports.ChainToCaip[chain];
319
- }
320
- else {
321
- var networkId = exports.ChainToNetworkId[chain];
322
- console.log("networkId: ", networkId);
323
- if (symbol.indexOf(".") > -1) {
324
- var contract = symbol.split("-")[1];
325
- caip = "".concat(networkId, "/erc20:").concat(contract);
326
- }
327
- else {
328
- console.error({ chain: chain, symbol: symbol, ticker: ticker, type: type });
329
- throw Error("Unable to parse CAIP! TODO!");
330
- }
331
- }
327
+ var networkId = exports.ChainToNetworkId[chain];
328
+ if (!networkId)
329
+ throw new Error("Unsupported chain: ".concat(chain));
330
+ caip = exports.ChainToCaip[chain] || networkId; // Fallback to networkId if no direct mapping
332
331
  break;
333
332
  }
334
333
  return caip;
@@ -369,7 +368,7 @@ var caipToThorchain = function (caip, ticker) {
369
368
  return null;
370
369
  }
371
370
  // Use the ticker as is without converting to uppercase
372
- return "".concat(chain, ".").concat(ticker, "-").concat(contractAddress.toUpperCase());
371
+ return "".concat(chain, ".").concat(ticker, "-").concat(contractAddress);
373
372
  }
374
373
  else {
375
374
  // Handling native tokens
@@ -385,15 +384,13 @@ exports.caipToThorchain = caipToThorchain;
385
384
  var caipToRango = function (caip, ticker) {
386
385
  try {
387
386
  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
387
+ var rangoName = (0, exports.NetworkIdToRangoName)(networkId);
390
388
  var symbol = ticker;
391
- var address = null;
389
+ var address = null; // Default to null
392
390
  // For ERC20 tokens, the contract address is included in the CAIP
393
391
  if (tokenInfo && tokenInfo.startsWith('erc20:')) {
394
392
  address = tokenInfo.split(':')[1];
395
393
  }
396
- // Check if the Rango name is found
397
394
  if (!rangoName) {
398
395
  console.error('Rango name not found for networkId:', networkId);
399
396
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/pioneer-caip",
3
- "version": "9.2.15",
3
+ "version": "9.2.17",
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__/tests-common.js",
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
  },