@chain-registry/utils 1.24.0 → 1.25.1

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/esm/ibc.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { sha256 } from 'sha.js';
2
+ import { getNativeAssets } from './utils';
2
3
  export const ibcDenom = (paths, coinMinimalDenom) => {
3
4
  const prefixes = [];
4
5
  for (const path of paths) {
@@ -365,3 +366,24 @@ export const getAssetLists = (chainName, ibc, assets) => {
365
366
  ];
366
367
  }, []);
367
368
  };
369
+ export const getNativeAssetLists = (chainName, ibc, _assets) => {
370
+ const assets = getNativeAssets(_assets);
371
+ const ibcAssetLists = getIbcAssets(chainName, ibc, assets);
372
+ const cw20Assets = getCw20Assets(chainName, ibc, assets);
373
+ return ibcAssetLists.reduce((m, v) => {
374
+ const chain = v.chain_name;
375
+ const assets = [...v.assets];
376
+ const cw20 = cw20Assets.find((a) => a.chain_name === chain);
377
+ if (cw20) {
378
+ // @ts-ignore
379
+ [].push.apply(assets, cw20.assets);
380
+ }
381
+ return [
382
+ {
383
+ chain_name: chain,
384
+ assets
385
+ },
386
+ ...m
387
+ ];
388
+ }, []);
389
+ };
package/esm/utils.js CHANGED
@@ -6,3 +6,29 @@ export const customFind = (array, filterFn) => {
6
6
  }
7
7
  return filteredItems[0];
8
8
  };
9
+ export const getNativeAssets = (assets) => {
10
+ return assets.map(list => {
11
+ const clone = JSON.parse(JSON.stringify(list));
12
+ clone.assets = list.assets.filter(asset => {
13
+ switch (true) {
14
+ case asset.base.startsWith('factory/'):
15
+ return false;
16
+ case asset.base.startsWith('ft') && list.chain_name === 'bitsong':
17
+ return false;
18
+ case asset.base.startsWith('erc20/'):
19
+ return true;
20
+ case asset.base.startsWith('ibc/'):
21
+ return false;
22
+ case asset.base.startsWith('cw20:'):
23
+ return true;
24
+ default:
25
+ if (!asset.traces || !asset.traces.length) {
26
+ // asset.type_asset = 'sdk.coin'
27
+ return true;
28
+ }
29
+ return false;
30
+ }
31
+ });
32
+ return clone;
33
+ });
34
+ };
package/ibc.d.ts CHANGED
@@ -33,3 +33,4 @@ export declare const getIbcDenomByBase: (ibc: IBCInfo[], chain: string, counterp
33
33
  export declare const getIbcAssets: (chainName: string, ibc: IBCInfo[], assets: AssetList[]) => AssetList[];
34
34
  export declare const getCw20Assets: (chainName: string, ibc: IBCInfo[], assets: AssetList[]) => AssetList[];
35
35
  export declare const getAssetLists: (chainName: string, ibc: IBCInfo[], assets: AssetList[]) => any[];
36
+ export declare const getNativeAssetLists: (chainName: string, ibc: IBCInfo[], _assets: AssetList[]) => any[];
package/ibc.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAssetLists = exports.getCw20Assets = exports.getIbcAssets = exports.getIbcDenomByBase = exports.getIbcAssetPath = exports.getWasmChannel = exports.getNonTransferChannel = exports.getTransferChannel = exports.getIbcInfo = exports.ibcDenom = void 0;
3
+ exports.getNativeAssetLists = exports.getAssetLists = exports.getCw20Assets = exports.getIbcAssets = exports.getIbcDenomByBase = exports.getIbcAssetPath = exports.getWasmChannel = exports.getNonTransferChannel = exports.getTransferChannel = exports.getIbcInfo = exports.ibcDenom = void 0;
4
4
  const sha_js_1 = require("sha.js");
5
+ const utils_1 = require("./utils");
5
6
  const ibcDenom = (paths, coinMinimalDenom) => {
6
7
  const prefixes = [];
7
8
  for (const path of paths) {
@@ -378,3 +379,25 @@ const getAssetLists = (chainName, ibc, assets) => {
378
379
  }, []);
379
380
  };
380
381
  exports.getAssetLists = getAssetLists;
382
+ const getNativeAssetLists = (chainName, ibc, _assets) => {
383
+ const assets = (0, utils_1.getNativeAssets)(_assets);
384
+ const ibcAssetLists = (0, exports.getIbcAssets)(chainName, ibc, assets);
385
+ const cw20Assets = (0, exports.getCw20Assets)(chainName, ibc, assets);
386
+ return ibcAssetLists.reduce((m, v) => {
387
+ const chain = v.chain_name;
388
+ const assets = [...v.assets];
389
+ const cw20 = cw20Assets.find((a) => a.chain_name === chain);
390
+ if (cw20) {
391
+ // @ts-ignore
392
+ [].push.apply(assets, cw20.assets);
393
+ }
394
+ return [
395
+ {
396
+ chain_name: chain,
397
+ assets
398
+ },
399
+ ...m
400
+ ];
401
+ }, []);
402
+ };
403
+ exports.getNativeAssetLists = getNativeAssetLists;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chain-registry/utils",
3
- "version": "1.24.0",
3
+ "version": "1.25.1",
4
4
  "description": "Chain Registry Utils",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "homepage": "https://github.com/cosmology-tech/chain-registry",
@@ -31,7 +31,7 @@
31
31
  "@types/sha.js": "^2.4.0"
32
32
  },
33
33
  "dependencies": {
34
- "@chain-registry/types": "^0.23.0",
34
+ "@chain-registry/types": "^0.24.1",
35
35
  "bignumber.js": "9.1.1",
36
36
  "sha.js": "^2.4.11"
37
37
  },
@@ -41,5 +41,5 @@
41
41
  "cosmos",
42
42
  "interchain"
43
43
  ],
44
- "gitHead": "796f4aef739279d4d8d35b89394afd004c29513e"
44
+ "gitHead": "ed022d4b92ac3c17782d38b84a28a780ee3e535b"
45
45
  }
package/utils.d.ts CHANGED
@@ -1 +1,3 @@
1
+ import { AssetList } from "@chain-registry/types";
1
2
  export declare const customFind: <T>(array: T[], filterFn: (item: T) => boolean) => T | undefined;
3
+ export declare const getNativeAssets: (assets: AssetList[]) => AssetList[];
package/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.customFind = void 0;
3
+ exports.getNativeAssets = exports.customFind = void 0;
4
4
  const customFind = (array, filterFn) => {
5
5
  const filteredItems = array.filter(filterFn);
6
6
  const filterCount = filteredItems.length;
@@ -10,3 +10,30 @@ const customFind = (array, filterFn) => {
10
10
  return filteredItems[0];
11
11
  };
12
12
  exports.customFind = customFind;
13
+ const getNativeAssets = (assets) => {
14
+ return assets.map(list => {
15
+ const clone = JSON.parse(JSON.stringify(list));
16
+ clone.assets = list.assets.filter(asset => {
17
+ switch (true) {
18
+ case asset.base.startsWith('factory/'):
19
+ return false;
20
+ case asset.base.startsWith('ft') && list.chain_name === 'bitsong':
21
+ return false;
22
+ case asset.base.startsWith('erc20/'):
23
+ return true;
24
+ case asset.base.startsWith('ibc/'):
25
+ return false;
26
+ case asset.base.startsWith('cw20:'):
27
+ return true;
28
+ default:
29
+ if (!asset.traces || !asset.traces.length) {
30
+ // asset.type_asset = 'sdk.coin'
31
+ return true;
32
+ }
33
+ return false;
34
+ }
35
+ });
36
+ return clone;
37
+ });
38
+ };
39
+ exports.getNativeAssets = getNativeAssets;