@chain-registry/utils 1.19.17 → 1.20.0
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/README.md +293 -1
- package/main/assets.js +17 -12
- package/main/chains.js +3 -3
- package/main/utils.js +14 -0
- package/package.json +18 -3
- package/types/assets.d.ts +3 -2
- package/types/ibc.d.ts +15 -0
- package/types/index.d.ts +2 -2
- package/types/utils.d.ts +1 -0
package/README.md
CHANGED
|
@@ -12,7 +12,299 @@
|
|
|
12
12
|
<a href="https://www.npmjs.com/package/@chain-registry/utils"><img height="20" src="https://img.shields.io/github/package-json/v/cosmology-tech/chain-registry?filename=packages%2Futils%2Fpackage.json"></a>
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
|
|
16
|
+
This module provides utility functions for working with the data in the chain-registry, focusing on asset and chain data management within the interchain ecosystem.
|
|
17
|
+
|
|
18
|
+
- [Installation](#installation)
|
|
19
|
+
- [Usage](#usage)
|
|
20
|
+
- [Chain](#chain-utilities)
|
|
21
|
+
- [Examples](#chain-examples)
|
|
22
|
+
- [Functions](#chain-functions)
|
|
23
|
+
- [Asset](#asset-utilities)
|
|
24
|
+
- [Examples](#asset-examples)
|
|
25
|
+
- [Functions](#asset-functions)
|
|
26
|
+
- [IBC](#ibc-utilities)
|
|
27
|
+
- [Examples](#ibc-examples)
|
|
28
|
+
- [Functions](#ibc-functions)
|
|
29
|
+
- [Calculation](#calculation-utilities)
|
|
30
|
+
- [Examples](#calculation-examples)
|
|
31
|
+
- [Functions](#calculation-functions)
|
|
32
|
+
- [Related](#related)
|
|
33
|
+
- [Credits](#credits)
|
|
34
|
+
- [Disclaimer](#disclaimer)
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install @chain-registry/utils
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
### Chain Utilities
|
|
45
|
+
|
|
46
|
+
Chain Utilities enable the retrieval and management of blockchain-specific data, such as chain names, chain IDs, and gas prices.
|
|
47
|
+
|
|
48
|
+
#### Chain Examples
|
|
49
|
+
|
|
50
|
+
Import the functions from the package:
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
import {
|
|
54
|
+
getGasPriceRangesFromChain,
|
|
55
|
+
getChainByChainName,
|
|
56
|
+
getChainByChainId,
|
|
57
|
+
getChainNameByChainId,
|
|
58
|
+
getChainIdByChainName,
|
|
59
|
+
getChainGasPriceRanges,
|
|
60
|
+
getChainPrettyName,
|
|
61
|
+
getChainBech32Prefix
|
|
62
|
+
} from '@chain-registry/utils';
|
|
63
|
+
|
|
64
|
+
// import from chain-registry or your own Chain[]
|
|
65
|
+
import { chains } from 'chain-registry';
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
To retrieve a chain object by its name:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
const chain = getChainByChainName(chains, 'osmosis');
|
|
72
|
+
// { chain_name: 'osmosis', ... }
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
To get the chain ID by its name:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
const chainId = getChainIdByChainName(chains, 'osmosis');
|
|
79
|
+
// 'osmosis-1'
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
To get the pretty name of a chain:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
const prettyName = getChainPrettyName(chains, 'osmosis');
|
|
86
|
+
// 'Osmosis'
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
To find the gas price ranges for a chain:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
const gasPriceRanges = getChainGasPriceRanges(chains, 'osmosis');
|
|
93
|
+
// { low: number, average: number, high: number }
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### Chain Functions
|
|
97
|
+
|
|
98
|
+
- `getGasPriceRangesFromChain`: Returns the gas price ranges (low, average, high) for a given chain.
|
|
99
|
+
- `getChainByChainName`: Finds a chain by its name.
|
|
100
|
+
- `getChainByChainId`: Retrieves a chain by its chain ID.
|
|
101
|
+
- `getChainNameByChainId`: Gets the chain name associated with a given chain ID.
|
|
102
|
+
- `getChainIdByChainName`: Fetches the chain ID for a specified chain name.
|
|
103
|
+
- `getChainGasPriceRanges`: Provides the gas price ranges for a specified chain name.
|
|
104
|
+
- `getChainPrettyName`: Returns the pretty (display) name of the chain.
|
|
105
|
+
- `getChainBech32Prefix`: Gets the Bech32 prefix for a given chain.
|
|
106
|
+
|
|
107
|
+
### Asset Utilities
|
|
108
|
+
|
|
109
|
+
Asset Utilities facilitate access to details of blockchain assets, including denominations, symbols, and related chain data.
|
|
110
|
+
|
|
111
|
+
#### Asset Examples
|
|
112
|
+
|
|
113
|
+
Import the functions from the package:
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
import {
|
|
117
|
+
getAssetByDenom,
|
|
118
|
+
getAssetBySymbol,
|
|
119
|
+
getChainLogo,
|
|
120
|
+
getChainNameByDenom,
|
|
121
|
+
getChainNameByStakingDenom,
|
|
122
|
+
getCoinGeckoIdByDenom,
|
|
123
|
+
getDenomByCoinGeckoId,
|
|
124
|
+
getDenomBySymbol,
|
|
125
|
+
getExponentByDenom,
|
|
126
|
+
getExponentBySymbol,
|
|
127
|
+
getNativeTokenByChainName,
|
|
128
|
+
getSymbolByDenom,
|
|
129
|
+
getTokenLogoByDenom,
|
|
130
|
+
getTokenNameByDenom
|
|
131
|
+
} from '@chain-registry/utils';
|
|
132
|
+
|
|
133
|
+
// import from chain-registry or your own AssetList[]
|
|
134
|
+
import { assets } from 'chain-registry';
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
To find an asset by its denomination:
|
|
139
|
+
|
|
140
|
+
```js
|
|
141
|
+
const asset = getAssetByDenom(assets, 'uosmo', 'osmosis');
|
|
142
|
+
console.log(asset?.base); // 'uosmo'
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
To get the logo URL of a chain:
|
|
146
|
+
|
|
147
|
+
```js
|
|
148
|
+
const logo = getChainLogo(assets, 'comdex');
|
|
149
|
+
console.log(logo); // 'https://raw.githubusercontent.com/cosmos/chain-registry/master/comdex/images/cmdx.png'
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
To retrieve the CoinGecko ID by asset denomination:
|
|
153
|
+
|
|
154
|
+
```js
|
|
155
|
+
const coinGeckoId = getCoinGeckoIdByDenom(assets, 'uosmo');
|
|
156
|
+
console.log(coinGeckoId); // 'osmosis'
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### Asset Functions
|
|
160
|
+
|
|
161
|
+
- `getAssetByDenom`: Retrieve an asset by its denomination.
|
|
162
|
+
- `getAssetBySymbol`: Find an asset by its symbol.
|
|
163
|
+
- `getChainLogo`: Get the logo URL of a chain.
|
|
164
|
+
- `getChainNameByDenom`: Determine the chain name given an asset's denomination.
|
|
165
|
+
- `getChainNameByStakingDenom`: Find the chain name by its staking token denomination.
|
|
166
|
+
- `getCoinGeckoIdByDenom`: Get the CoinGecko ID associated with an asset denomination.
|
|
167
|
+
- `getDenomByCoinGeckoId`: Find the denomination for an asset given its CoinGecko ID.
|
|
168
|
+
- `getSymbolByDenom`: Retrieve the symbol associated with a denomination.
|
|
169
|
+
- `getDenomBySymbol`: Get the denomination of an asset by its symbol.
|
|
170
|
+
- `getExponentByDenom`: Find the exponent for a denomination.
|
|
171
|
+
- `getExponentBySymbol`: Get the exponent for a symbol.
|
|
172
|
+
- `getNativeTokenByChainName`: Retrieve the native token for a given chain name.
|
|
173
|
+
- `getTokenLogoByDenom`: Get the logo URL for a token by its denomination.
|
|
174
|
+
- `getTokenNameByDenom`: Find the name of a token by its denomination.
|
|
175
|
+
|
|
176
|
+
### IBC Utilities
|
|
177
|
+
|
|
178
|
+
IBC Utilities provide mechanisms to derive IBC denominations and trace IBC asset paths across multiple chains, enabling the management of inter-blockchain assets.
|
|
179
|
+
|
|
180
|
+
#### IBC Examples
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
import {
|
|
184
|
+
getIbcAssetPath,
|
|
185
|
+
getIbcDenomByBase,
|
|
186
|
+
ibcDenom
|
|
187
|
+
} from '@chain-registry/utils';
|
|
188
|
+
|
|
189
|
+
// import from chain-registry or your own data
|
|
190
|
+
import { assets, ibc } from 'chain-registry';
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
To get the IBC denomination for a specific asset:
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
const denom = getIbcDenomByBase(ibc, 'osmosis', 'akash', assets, 'uakt');
|
|
197
|
+
// denom should be the IBC hashed denomination string
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Example for AKT (Akash Token) on Osmosis:
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
const aktDenom = getIbcDenomByBase(ibc, 'osmosis', 'akash', assets, 'uakt');
|
|
204
|
+
console.log(aktDenom); // Expected: 'ibc/1480B8FD20AD5FCAE81EA87584D269547DD4D436843C1D20F15E00EB64743EF4'
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Example for STARS (Stargaze Token) on Osmosis:
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
const starsDenom = getIbcDenomByBase(ibc, 'osmosis', 'stargaze', assets, 'ustars');
|
|
211
|
+
console.log(starsDenom); // Expected: 'ibc/987C17B11ABC2B20019178ACE62929FE9840202CE79498E29FE8E5CB02B7C0A4'
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
#### IBC Functions
|
|
215
|
+
|
|
216
|
+
- `ibcDenom`: Generates the IBC denomination for an asset based on its transfer path.
|
|
217
|
+
- `getIbcAssetPath`: Determines the path an asset takes across chains in the IBC network.
|
|
218
|
+
- `getIbcDenomByBase`: Computes the IBC denomination for an asset from its base denomination.
|
|
219
|
+
|
|
220
|
+
### Calculation Utilities
|
|
221
|
+
|
|
222
|
+
These functions provide utilities for converting asset units and calculating their values based on market data.
|
|
223
|
+
|
|
224
|
+
#### Calculation Examples
|
|
225
|
+
|
|
226
|
+
```js
|
|
227
|
+
import {
|
|
228
|
+
mapCoinGeckoPricesToDenoms,
|
|
229
|
+
convertBaseUnitToDollarValue,
|
|
230
|
+
convertDollarValueToBaseUnit,
|
|
231
|
+
convertBaseUnitToDisplayUnit,
|
|
232
|
+
convertDisplayUnitToBaseUnit,
|
|
233
|
+
roundDown
|
|
234
|
+
} from '@chain-registry/utils';
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
This function maps prices obtained from CoinGecko to the corresponding denominations in the asset list, facilitating price-related calculations.
|
|
238
|
+
|
|
239
|
+
```ts
|
|
240
|
+
const priceMap = mapCoinGeckoPricesToDenoms(assets, coinGeckoPrices);
|
|
241
|
+
// priceMap will now contain a mapping of denominations to their USD prices
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
Convert an amount in the base unit of a specified asset to its dollar value using the provided price map.
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
const dollarValue = convertBaseUnitToDollarValue(assets, priceMap, 'OSMO', 1000000);
|
|
249
|
+
// dollarValue is the total value in USD of 1,000,000 base units of OSMO
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Convert a dollar value into the base unit of the specified asset, based on the current price.
|
|
253
|
+
|
|
254
|
+
```ts
|
|
255
|
+
const baseUnit = convertDollarValueToBaseUnit(assets, priceMap, 'OSMO', 100);
|
|
256
|
+
// baseUnit is the amount in base units of OSMO that equals 100 USD
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
Converts an amount from the base unit to the display unit for the specified asset.
|
|
260
|
+
|
|
261
|
+
```ts
|
|
262
|
+
const displayUnit = convertBaseUnitToDisplayUnit(assets, 'OSMO', 1000000);
|
|
263
|
+
// displayUnit is the representation of 1,000,000 base units in display units (e.g., OSMO)
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
Converts an amount from the display unit to the base unit for the specified asset.
|
|
267
|
+
|
|
268
|
+
```ts
|
|
269
|
+
const baseUnit = convertDisplayUnitToBaseUnit(assets, 'OSMO', 1);
|
|
270
|
+
// baseUnit is the amount in base units that corresponds to 1 display unit (e.g., 1 OSMO)
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Rounds down a number to the nearest integer, ensuring consistent lower-bound calculations in financial operations.
|
|
274
|
+
|
|
275
|
+
```ts
|
|
276
|
+
const rounded = roundDown(123.4567);
|
|
277
|
+
// rounded will be '123'
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
#### Calculation Functions
|
|
281
|
+
|
|
282
|
+
- `mapCoinGeckoPricesToDenoms`: Maps CoinGecko price data to asset denominations.
|
|
283
|
+
- `convertBaseUnitToDollarValue`: Converts an amount in the base unit of an asset to its dollar value.
|
|
284
|
+
- `convertDollarValueToBaseUnit`: Converts a dollar value into the base unit of a specified asset.
|
|
285
|
+
- `convertBaseUnitToDisplayUnit`: Converts an amount from the base unit to the display unit of an asset.
|
|
286
|
+
- `convertDisplayUnitToBaseUnit`: Converts an amount from the display unit to the base unit of an asset.
|
|
287
|
+
- `roundDown`: Rounds down a number to the nearest integer.
|
|
288
|
+
|
|
289
|
+
## Related
|
|
290
|
+
|
|
291
|
+
Checkout these related projects:
|
|
292
|
+
|
|
293
|
+
* [@cosmology/telescope](https://github.com/cosmology-tech/telescope) Your Frontend Companion for Building with TypeScript with Cosmos SDK Modules.
|
|
294
|
+
* [@cosmwasm/ts-codegen](https://github.com/CosmWasm/ts-codegen) Convert your CosmWasm smart contracts into dev-friendly TypeScript classes.
|
|
295
|
+
* [chain-registry](https://github.com/cosmology-tech/chain-registry) Everything from token symbols, logos, and IBC denominations for all assets you want to support in your application.
|
|
296
|
+
* [cosmos-kit](https://github.com/cosmology-tech/cosmos-kit) Experience the convenience of connecting with a variety of web3 wallets through a single, streamlined interface.
|
|
297
|
+
* [create-cosmos-app](https://github.com/cosmology-tech/create-cosmos-app) Set up a modern Cosmos app by running one command.
|
|
298
|
+
* [interchain-ui](https://github.com/cosmology-tech/interchain-ui) The Interchain Design System, empowering developers with a flexible, easy-to-use UI kit.
|
|
299
|
+
* [starship](https://github.com/cosmology-tech/starship) Unified Testing and Development for the Interchain.
|
|
300
|
+
|
|
16
301
|
## Credits
|
|
17
302
|
|
|
18
303
|
🛠 Built by Cosmology — if you like our tools, please consider delegating to [our validator ⚛️](https://cosmology.zone/validator)
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
## Disclaimer
|
|
307
|
+
|
|
308
|
+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED “AS IS”, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
|
|
309
|
+
|
|
310
|
+
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
|
package/main/assets.js
CHANGED
|
@@ -3,15 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getTokenNameByDenom = exports.getTokenLogoByDenom = exports.getSymbolByDenom = exports.getNativeTokenByChainName = exports.getExponentFromAsset = exports.getExponentBySymbol = exports.getExponentByDenom = exports.getDenomBySymbol = exports.getDenomByCoinGeckoId = exports.getCoinGeckoIdByDenom = exports.getChainNameByDenom = exports.getChainLogo = exports.
|
|
7
|
-
var
|
|
8
|
-
var filteredItems = array.filter(filterFn);
|
|
9
|
-
var filterCount = filteredItems.length;
|
|
10
|
-
if (filterCount > 1) {
|
|
11
|
-
throw new Error("Ambiguity Error: ".concat(filterCount, " items found."));
|
|
12
|
-
}
|
|
13
|
-
return filteredItems[0];
|
|
14
|
-
};
|
|
6
|
+
exports.getTokenNameByDenom = exports.getTokenLogoByDenom = exports.getSymbolByDenom = exports.getNativeTokenByChainName = exports.getExponentFromAsset = exports.getExponentBySymbol = exports.getExponentByDenom = exports.getDenomBySymbol = exports.getDenomByCoinGeckoId = exports.getCoinGeckoIdByDenom = exports.getChainNameByStakingDenom = exports.getChainNameByDenom = exports.getChainLogo = exports.getChainByStakingDenom = exports.getAssetBySymbol = exports.getAssetByDenom = void 0;
|
|
7
|
+
var _utils = require("./utils");
|
|
15
8
|
var getAssetByKeyValue = function getAssetByKeyValue(assets, key, value, chainName) {
|
|
16
9
|
var filteredAssets = assets.filter(function (_ref) {
|
|
17
10
|
var chain_name = _ref.chain_name;
|
|
@@ -20,7 +13,7 @@ var getAssetByKeyValue = function getAssetByKeyValue(assets, key, value, chainNa
|
|
|
20
13
|
var assets = _ref2.assets;
|
|
21
14
|
return assets;
|
|
22
15
|
});
|
|
23
|
-
return customFind(filteredAssets, function (asset) {
|
|
16
|
+
return (0, _utils.customFind)(filteredAssets, function (asset) {
|
|
24
17
|
return asset[key] === value;
|
|
25
18
|
});
|
|
26
19
|
};
|
|
@@ -86,7 +79,7 @@ var getExponentBySymbol = exports.getExponentBySymbol = function getExponentBySy
|
|
|
86
79
|
return asset ? getExponentFromAsset(asset) : undefined;
|
|
87
80
|
};
|
|
88
81
|
var getNativeTokenByChainName = exports.getNativeTokenByChainName = function getNativeTokenByChainName(assets, chainName) {
|
|
89
|
-
var assetList = customFind(assets, function (assetList) {
|
|
82
|
+
var assetList = (0, _utils.customFind)(assets, function (assetList) {
|
|
90
83
|
return assetList.chain_name === chainName && !assetList.assets[0].base.startsWith('ibc/');
|
|
91
84
|
});
|
|
92
85
|
return assetList === null || assetList === void 0 ? void 0 : assetList.assets[0];
|
|
@@ -113,9 +106,21 @@ var getChainNameByDenom = exports.getChainNameByDenom = function getChainNameByD
|
|
|
113
106
|
return t.type === 'ibc';
|
|
114
107
|
})) === null || _asset$traces$find === void 0 ? void 0 : (_asset$traces$find$co = _asset$traces$find.counterparty) === null || _asset$traces$find$co === void 0 ? void 0 : _asset$traces$find$co.chain_name;
|
|
115
108
|
}
|
|
116
|
-
return (_customFind = customFind(assets, function (assetList) {
|
|
109
|
+
return (_customFind = (0, _utils.customFind)(assets, function (assetList) {
|
|
117
110
|
return assetList.assets.some(function (asset) {
|
|
118
111
|
return asset.base === denom;
|
|
119
112
|
});
|
|
120
113
|
})) === null || _customFind === void 0 ? void 0 : _customFind.chain_name;
|
|
114
|
+
};
|
|
115
|
+
var getChainByStakingDenom = exports.getChainByStakingDenom = function getChainByStakingDenom(chains, denom) {
|
|
116
|
+
return (0, _utils.customFind)(chains, function (chain) {
|
|
117
|
+
var _chain$staking;
|
|
118
|
+
return !!((_chain$staking = chain.staking) !== null && _chain$staking !== void 0 && _chain$staking.staking_tokens.find(function (token) {
|
|
119
|
+
return token.denom === denom;
|
|
120
|
+
}));
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
var getChainNameByStakingDenom = exports.getChainNameByStakingDenom = function getChainNameByStakingDenom(chains, denom) {
|
|
124
|
+
var _getChainByStakingDen;
|
|
125
|
+
return (_getChainByStakingDen = getChainByStakingDenom(chains, denom)) === null || _getChainByStakingDen === void 0 ? void 0 : _getChainByStakingDen.chain_name;
|
|
121
126
|
};
|
package/main/chains.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getGasPriceRangesFromChain = exports.getChainPrettyName = exports.getChainNameByChainId = exports.getChainIdByChainName = exports.getChainGasPriceRanges = exports.getChainByChainName = exports.getChainByChainId = exports.getChainBech32Prefix = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _utils = require("./utils");
|
|
8
8
|
var getGasPriceRangesFromChain = exports.getGasPriceRangesFromChain = function getGasPriceRangesFromChain(chain) {
|
|
9
9
|
var _chain$fees, _chain$fees$fee_token, _feeToken$low_gas_pri, _feeToken$average_gas, _feeToken$high_gas_pr;
|
|
10
10
|
var feeToken = (_chain$fees = chain.fees) === null || _chain$fees === void 0 ? void 0 : (_chain$fees$fee_token = _chain$fees.fee_tokens) === null || _chain$fees$fee_token === void 0 ? void 0 : _chain$fees$fee_token[0];
|
|
@@ -15,12 +15,12 @@ var getGasPriceRangesFromChain = exports.getGasPriceRangesFromChain = function g
|
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
17
|
var getChainByChainName = exports.getChainByChainName = function getChainByChainName(chains, chainName) {
|
|
18
|
-
return (0,
|
|
18
|
+
return (0, _utils.customFind)(chains, function (chain) {
|
|
19
19
|
return chain.chain_name === chainName;
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
22
|
var getChainByChainId = exports.getChainByChainId = function getChainByChainId(chains, chainId) {
|
|
23
|
-
return (0,
|
|
23
|
+
return (0, _utils.customFind)(chains, function (chain) {
|
|
24
24
|
return chain.chain_id === chainId;
|
|
25
25
|
});
|
|
26
26
|
};
|
package/main/utils.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.customFind = void 0;
|
|
7
|
+
var customFind = exports.customFind = function customFind(array, filterFn) {
|
|
8
|
+
var filteredItems = array.filter(filterFn);
|
|
9
|
+
var filterCount = filteredItems.length;
|
|
10
|
+
if (filterCount > 1) {
|
|
11
|
+
throw new Error("Ambiguity Error: ".concat(filterCount, " items found."));
|
|
12
|
+
}
|
|
13
|
+
return filteredItems[0];
|
|
14
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chain-registry/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.0",
|
|
4
4
|
"description": "Chain Registry Utils",
|
|
5
5
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/cosmology-tech/chain-registry",
|
|
@@ -40,6 +40,21 @@
|
|
|
40
40
|
"bugs": {
|
|
41
41
|
"url": "https://github.com/cosmology-tech/chain-registry/issues"
|
|
42
42
|
},
|
|
43
|
+
"jest": {
|
|
44
|
+
"preset": "ts-jest",
|
|
45
|
+
"testEnvironment": "node",
|
|
46
|
+
"transform": {
|
|
47
|
+
"^.+\\.ts?$": "ts-jest"
|
|
48
|
+
},
|
|
49
|
+
"transformIgnorePatterns": [
|
|
50
|
+
"<rootDir>/node_modules/"
|
|
51
|
+
],
|
|
52
|
+
"testPathIgnorePatterns": [
|
|
53
|
+
"main/",
|
|
54
|
+
"module/",
|
|
55
|
+
"types/"
|
|
56
|
+
]
|
|
57
|
+
},
|
|
43
58
|
"devDependencies": {
|
|
44
59
|
"@babel/cli": "7.21.0",
|
|
45
60
|
"@babel/core": "7.21.4",
|
|
@@ -72,9 +87,9 @@
|
|
|
72
87
|
},
|
|
73
88
|
"dependencies": {
|
|
74
89
|
"@babel/runtime": "^7.21.0",
|
|
75
|
-
"@chain-registry/types": "^0.
|
|
90
|
+
"@chain-registry/types": "^0.19.0",
|
|
76
91
|
"bignumber.js": "9.1.1",
|
|
77
92
|
"sha.js": "^2.4.11"
|
|
78
93
|
},
|
|
79
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "a1c406b27dc7a91527a5239b565c5a528d3bb03b"
|
|
80
95
|
}
|
package/types/assets.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Asset, AssetDenomUnit, AssetList } from '@chain-registry/types';
|
|
1
|
+
import { Asset, AssetDenomUnit, AssetList, Chain } from '@chain-registry/types';
|
|
2
2
|
export type Denom = AssetDenomUnit['denom'];
|
|
3
3
|
export type Exponent = AssetDenomUnit['exponent'];
|
|
4
|
-
export declare const customFind: <T>(array: T[], filterFn: (item: T) => boolean) => T;
|
|
5
4
|
export declare const getAssetByDenom: (assets: AssetList[], denom: Denom, chainName?: string) => Asset | undefined;
|
|
6
5
|
export declare const getAssetBySymbol: (assets: AssetList[], symbol: string, chainName?: string) => Asset | undefined;
|
|
7
6
|
export declare const getDenomByCoinGeckoId: (assets: AssetList[], coinGeckoId: string, chainName?: string) => Denom | undefined;
|
|
@@ -22,4 +21,6 @@ export declare const getTokenLogoByDenom: (assets: AssetList[], denom: Denom, ch
|
|
|
22
21
|
export declare const getChainLogo: (assets: AssetList[], chainName: string) => string | undefined;
|
|
23
22
|
export declare const getTokenNameByDenom: (assets: AssetList[], denom: Denom, chainName?: string) => string | undefined;
|
|
24
23
|
export declare const getChainNameByDenom: (assets: AssetList[], denom: Denom) => string | undefined;
|
|
24
|
+
export declare const getChainByStakingDenom: (chains: Chain[], denom: Denom) => Chain | undefined;
|
|
25
|
+
export declare const getChainNameByStakingDenom: (chains: Chain[], denom: Denom) => string | undefined;
|
|
25
26
|
export {};
|
package/types/ibc.d.ts
CHANGED
|
@@ -7,40 +7,55 @@ export declare const getIbcInfo: (ibc: IBCInfo[], chain: string, counterparty: s
|
|
|
7
7
|
export declare const getTransferChannel: (info: IBCInfo) => {
|
|
8
8
|
chain_1: {
|
|
9
9
|
channel_id: string;
|
|
10
|
+
client_id?: string;
|
|
10
11
|
port_id: string;
|
|
12
|
+
connection_id?: string;
|
|
11
13
|
};
|
|
12
14
|
chain_2: {
|
|
13
15
|
channel_id: string;
|
|
16
|
+
client_id?: string;
|
|
14
17
|
port_id: string;
|
|
18
|
+
connection_id?: string;
|
|
15
19
|
};
|
|
16
20
|
ordering: string;
|
|
17
21
|
version: string;
|
|
22
|
+
fee_version?: string;
|
|
18
23
|
tags?: object;
|
|
19
24
|
};
|
|
20
25
|
export declare const getNonTransferChannel: (info: IBCInfo) => {
|
|
21
26
|
chain_1: {
|
|
22
27
|
channel_id: string;
|
|
28
|
+
client_id?: string;
|
|
23
29
|
port_id: string;
|
|
30
|
+
connection_id?: string;
|
|
24
31
|
};
|
|
25
32
|
chain_2: {
|
|
26
33
|
channel_id: string;
|
|
34
|
+
client_id?: string;
|
|
27
35
|
port_id: string;
|
|
36
|
+
connection_id?: string;
|
|
28
37
|
};
|
|
29
38
|
ordering: string;
|
|
30
39
|
version: string;
|
|
40
|
+
fee_version?: string;
|
|
31
41
|
tags?: object;
|
|
32
42
|
};
|
|
33
43
|
export declare const getWasmChannel: (info: IBCInfo) => {
|
|
34
44
|
chain_1: {
|
|
35
45
|
channel_id: string;
|
|
46
|
+
client_id?: string;
|
|
36
47
|
port_id: string;
|
|
48
|
+
connection_id?: string;
|
|
37
49
|
};
|
|
38
50
|
chain_2: {
|
|
39
51
|
channel_id: string;
|
|
52
|
+
client_id?: string;
|
|
40
53
|
port_id: string;
|
|
54
|
+
connection_id?: string;
|
|
41
55
|
};
|
|
42
56
|
ordering: string;
|
|
43
57
|
version: string;
|
|
58
|
+
fee_version?: string;
|
|
44
59
|
tags?: object;
|
|
45
60
|
};
|
|
46
61
|
export declare const getIbcAssetPath: (ibc: IBCInfo[], chain: string, counterparty: string, assets: AssetList[], base: string) => any;
|
package/types/index.d.ts
CHANGED
package/types/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const customFind: <T>(array: T[], filterFn: (item: T) => boolean) => T;
|