@pioneer-platform/pioneer-caip 9.2.15 → 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 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: (chain: string, symbol: string, ticker: any, type: string) => any;
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: any;
128
+ address: string | null;
130
129
  } | null;
131
- export { thorchainToCaip, tokenToCaip, caipToThorchain, caipToRango, caipToNetworkId };
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.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;
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,54 +249,57 @@ var NetworkIdToRangoName = function (networkId) {
247
249
  exports.NetworkIdToRangoName = NetworkIdToRangoName;
248
250
  var tokenToCaip = function (token) {
249
251
  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;
252
+ var caip = void 0;
253
+ console.log("token", token);
263
254
  if (token.address) {
264
- ticker = symbol.split('-')[0];
265
- type = 'token';
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
- type = 'native';
269
- ticker = symbol;
263
+ // For native tokens, use the identifier as it is
264
+ caip = thorchainToCaip(token.identifier);
265
+ token.type = 'native';
270
266
  }
271
- var caip = thorchainToCaip(chain, symbol, ticker, type);
272
- token.networkId = exports.ChainToNetworkId[chain];
267
+ token.networkId = exports.ChainToNetworkId[token.chain];
273
268
  token.caip = caip;
274
- token.symbol = symbol;
275
- token.ticker = ticker;
276
- token.type = type;
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 (chain, symbol, ticker, type) {
280
+ var thorchainToCaip = function (identifier) {
286
281
  try {
287
282
  var caip = void 0;
288
- var key = chain + '.' + symbol; // Concatenate chain and symbol
289
- console.log("key:", key);
290
- switch (key) {
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) {
291
298
  case "OSMO.ATOM":
292
- // Specific case for OSMO.ATOM
293
299
  caip = 'cosmos:osmosis-1/ibc:B011C1A0AD5E717F674BA59FD8E05B2F946E4FD41C9CB3311C95F7ED4B815620';
294
300
  break;
295
301
  case "AVAX.WETH":
296
- console.log("WETH detected");
297
- caip = exports.ChainToCaip[chain];
302
+ caip = exports.ChainToCaip['AVAX'];
298
303
  break;
299
304
  case "BSC.BNB":
300
305
  caip = exports.shortListNameToCaip['bnbsmartchain'];
@@ -314,21 +319,10 @@ var thorchainToCaip = function (chain, symbol, ticker, type) {
314
319
  caip = exports.shortListNameToCaip[chain.toLowerCase()];
315
320
  break;
316
321
  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
- }
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
332
326
  break;
333
327
  }
334
328
  return caip;
@@ -369,7 +363,7 @@ var caipToThorchain = function (caip, ticker) {
369
363
  return null;
370
364
  }
371
365
  // Use the ticker as is without converting to uppercase
372
- return "".concat(chain, ".").concat(ticker, "-").concat(contractAddress.toUpperCase());
366
+ return "".concat(chain, ".").concat(ticker, "-").concat(contractAddress);
373
367
  }
374
368
  else {
375
369
  // Handling native tokens
@@ -385,15 +379,13 @@ exports.caipToThorchain = caipToThorchain;
385
379
  var caipToRango = function (caip, ticker) {
386
380
  try {
387
381
  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
382
+ var rangoName = (0, exports.NetworkIdToRangoName)(networkId);
390
383
  var symbol = ticker;
391
- var address = null;
384
+ var address = null; // Default to null
392
385
  // For ERC20 tokens, the contract address is included in the CAIP
393
386
  if (tokenInfo && tokenInfo.startsWith('erc20:')) {
394
387
  address = tokenInfo.split(':')[1];
395
388
  }
396
- // Check if the Rango name is found
397
389
  if (!rangoName) {
398
390
  console.error('Rango name not found for networkId:', networkId);
399
391
  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.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__/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
  },