@chain-registry/utils 1.18.0 → 1.19.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/main/assets.js +136 -0
- package/main/calc.js +68 -0
- package/main/chains.js +54 -0
- package/main/{utils.js → ibc.js} +2 -1
- package/main/index.js +23 -12
- package/package.json +3 -3
- package/types/assets.d.ts +25 -0
- package/types/calc.d.ts +14 -0
- package/types/chains.d.ts +14 -0
- package/types/index.d.ts +4 -3
- package/CHANGELOG.md +0 -446
- package/main/asset-list-util.js +0 -109
- package/main/fees.js +0 -15
- package/types/asset-list-util.d.ts +0 -27
- package/types/fees.d.ts +0 -6
- package/types/registry.d.ts +0 -45
- /package/types/{utils.d.ts → ibc.d.ts} +0 -0
package/main/assets.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
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.getAssetBySymbol = exports.getAssetByDenom = exports.customFind = void 0;
|
|
7
|
+
var 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
|
+
};
|
|
15
|
+
exports.customFind = customFind;
|
|
16
|
+
var getAssetByKeyValue = function getAssetByKeyValue(assets, key, value, chainName) {
|
|
17
|
+
var filteredAssets = assets.filter(function (_ref) {
|
|
18
|
+
var chain_name = _ref.chain_name;
|
|
19
|
+
return !chainName || chain_name === chainName;
|
|
20
|
+
}).flatMap(function (_ref2) {
|
|
21
|
+
var assets = _ref2.assets;
|
|
22
|
+
return assets;
|
|
23
|
+
});
|
|
24
|
+
return customFind(filteredAssets, function (asset) {
|
|
25
|
+
return asset[key] === value;
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
var getAssetByDenom = function getAssetByDenom(assets, denom, chainName) {
|
|
29
|
+
return getAssetByKeyValue(assets, 'base', denom, chainName);
|
|
30
|
+
};
|
|
31
|
+
exports.getAssetByDenom = getAssetByDenom;
|
|
32
|
+
var getAssetBySymbol = function getAssetBySymbol(assets, symbol, chainName) {
|
|
33
|
+
return getAssetByKeyValue(assets, 'symbol', symbol, chainName);
|
|
34
|
+
};
|
|
35
|
+
exports.getAssetBySymbol = getAssetBySymbol;
|
|
36
|
+
var getDenomByCoinGeckoId = function getDenomByCoinGeckoId(assets, coinGeckoId, chainName) {
|
|
37
|
+
var _getAssetByKeyValue;
|
|
38
|
+
return (_getAssetByKeyValue = getAssetByKeyValue(assets, 'coingecko_id', coinGeckoId, chainName)) === null || _getAssetByKeyValue === void 0 ? void 0 : _getAssetByKeyValue.base;
|
|
39
|
+
};
|
|
40
|
+
exports.getDenomByCoinGeckoId = getDenomByCoinGeckoId;
|
|
41
|
+
var getCoinGeckoIdByDenom = function getCoinGeckoIdByDenom(assets, denom) {
|
|
42
|
+
var _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
43
|
+
chainName = _ref3.chainName,
|
|
44
|
+
_ref3$allowTestnet = _ref3.allowTestnet,
|
|
45
|
+
allowTestnet = _ref3$allowTestnet === void 0 ? false : _ref3$allowTestnet,
|
|
46
|
+
_ref3$customAssetFilt = _ref3.customAssetFilter,
|
|
47
|
+
customAssetFilter = _ref3$customAssetFilt === void 0 ? function () {
|
|
48
|
+
return true;
|
|
49
|
+
} : _ref3$customAssetFilt,
|
|
50
|
+
_ref3$excludedChainNa = _ref3.excludedChainNames,
|
|
51
|
+
excludedChainNames = _ref3$excludedChainNa === void 0 ? [] : _ref3$excludedChainNa;
|
|
52
|
+
var filteredAssetLists = assets.filter(function (_ref4) {
|
|
53
|
+
var chain_name = _ref4.chain_name;
|
|
54
|
+
return (!chainName || chain_name === chainName) && (allowTestnet || !chain_name.includes('testnet')) && !excludedChainNames.includes(chain_name);
|
|
55
|
+
});
|
|
56
|
+
var filteredAssets = filteredAssetLists.flatMap(function (_ref5) {
|
|
57
|
+
var assets = _ref5.assets;
|
|
58
|
+
return assets;
|
|
59
|
+
}).filter(function (_ref6) {
|
|
60
|
+
var coingecko_id = _ref6.coingecko_id;
|
|
61
|
+
return coingecko_id;
|
|
62
|
+
}).filter(customAssetFilter);
|
|
63
|
+
var asset = filteredAssets.find(function (_ref7) {
|
|
64
|
+
var base = _ref7.base;
|
|
65
|
+
return base === denom;
|
|
66
|
+
});
|
|
67
|
+
return asset === null || asset === void 0 ? void 0 : asset.coingecko_id;
|
|
68
|
+
};
|
|
69
|
+
exports.getCoinGeckoIdByDenom = getCoinGeckoIdByDenom;
|
|
70
|
+
var getSymbolByDenom = function getSymbolByDenom(assets, denom, chainName) {
|
|
71
|
+
var _getAssetByDenom;
|
|
72
|
+
return (_getAssetByDenom = getAssetByDenom(assets, denom, chainName)) === null || _getAssetByDenom === void 0 ? void 0 : _getAssetByDenom.symbol;
|
|
73
|
+
};
|
|
74
|
+
exports.getSymbolByDenom = getSymbolByDenom;
|
|
75
|
+
var getDenomBySymbol = function getDenomBySymbol(assets, symbol, chainName) {
|
|
76
|
+
var _getAssetByKeyValue2;
|
|
77
|
+
return (_getAssetByKeyValue2 = getAssetByKeyValue(assets, 'symbol', symbol, chainName)) === null || _getAssetByKeyValue2 === void 0 ? void 0 : _getAssetByKeyValue2.base;
|
|
78
|
+
};
|
|
79
|
+
exports.getDenomBySymbol = getDenomBySymbol;
|
|
80
|
+
var getExponentFromAsset = function getExponentFromAsset(asset) {
|
|
81
|
+
var _asset$denom_units$fi;
|
|
82
|
+
return (_asset$denom_units$fi = asset.denom_units.find(function (_ref8) {
|
|
83
|
+
var denom = _ref8.denom;
|
|
84
|
+
return denom === asset.display;
|
|
85
|
+
})) === null || _asset$denom_units$fi === void 0 ? void 0 : _asset$denom_units$fi.exponent;
|
|
86
|
+
};
|
|
87
|
+
exports.getExponentFromAsset = getExponentFromAsset;
|
|
88
|
+
var getExponentByDenom = function getExponentByDenom(assets, denom, chainName) {
|
|
89
|
+
var asset = getAssetByDenom(assets, denom, chainName);
|
|
90
|
+
return asset ? getExponentFromAsset(asset) : undefined;
|
|
91
|
+
};
|
|
92
|
+
exports.getExponentByDenom = getExponentByDenom;
|
|
93
|
+
var getExponentBySymbol = function getExponentBySymbol(assets, symbol, chainName) {
|
|
94
|
+
var asset = getAssetBySymbol(assets, symbol, chainName);
|
|
95
|
+
return asset ? getExponentFromAsset(asset) : undefined;
|
|
96
|
+
};
|
|
97
|
+
exports.getExponentBySymbol = getExponentBySymbol;
|
|
98
|
+
var getNativeTokenByChainName = function getNativeTokenByChainName(assets, chainName) {
|
|
99
|
+
var assetList = customFind(assets, function (assetList) {
|
|
100
|
+
return assetList.chain_name === chainName && !assetList.assets[0].base.startsWith('ibc/');
|
|
101
|
+
});
|
|
102
|
+
return assetList === null || assetList === void 0 ? void 0 : assetList.assets[0];
|
|
103
|
+
};
|
|
104
|
+
exports.getNativeTokenByChainName = getNativeTokenByChainName;
|
|
105
|
+
var getTokenLogoByDenom = function getTokenLogoByDenom(assets, denom, chainName) {
|
|
106
|
+
var asset = getAssetByDenom(assets, denom, chainName);
|
|
107
|
+
return Object.values((asset === null || asset === void 0 ? void 0 : asset.logo_URIs) || {})[0];
|
|
108
|
+
};
|
|
109
|
+
exports.getTokenLogoByDenom = getTokenLogoByDenom;
|
|
110
|
+
var getChainLogo = function getChainLogo(assets, chainName) {
|
|
111
|
+
var nativeToken = getNativeTokenByChainName(assets, chainName);
|
|
112
|
+
return Object.values((nativeToken === null || nativeToken === void 0 ? void 0 : nativeToken.logo_URIs) || {})[0];
|
|
113
|
+
};
|
|
114
|
+
exports.getChainLogo = getChainLogo;
|
|
115
|
+
var getTokenNameByDenom = function getTokenNameByDenom(assets, denom, chainName) {
|
|
116
|
+
var asset = getAssetByDenom(assets, denom, chainName);
|
|
117
|
+
return asset === null || asset === void 0 ? void 0 : asset.name;
|
|
118
|
+
};
|
|
119
|
+
exports.getTokenNameByDenom = getTokenNameByDenom;
|
|
120
|
+
var getChainNameByDenom = function getChainNameByDenom(assets, denom) {
|
|
121
|
+
var _customFind;
|
|
122
|
+
var isIbcDenom = denom.startsWith('ibc/');
|
|
123
|
+
if (isIbcDenom) {
|
|
124
|
+
var _asset$traces, _asset$traces$find, _asset$traces$find$co;
|
|
125
|
+
var _asset = getAssetByDenom(assets, denom);
|
|
126
|
+
return _asset === null || _asset === void 0 ? void 0 : (_asset$traces = _asset.traces) === null || _asset$traces === void 0 ? void 0 : (_asset$traces$find = _asset$traces.find(function (t) {
|
|
127
|
+
return t.type === 'ibc';
|
|
128
|
+
})) === 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;
|
|
129
|
+
}
|
|
130
|
+
return (_customFind = customFind(assets, function (assetList) {
|
|
131
|
+
return assetList.assets.some(function (asset) {
|
|
132
|
+
return asset.base === denom;
|
|
133
|
+
});
|
|
134
|
+
})) === null || _customFind === void 0 ? void 0 : _customFind.chain_name;
|
|
135
|
+
};
|
|
136
|
+
exports.getChainNameByDenom = getChainNameByDenom;
|
package/main/calc.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.roundDown = exports.mapCoinGeckoPricesToDenoms = exports.convertDollarValueToBaseUnit = exports.convertDisplayUnitToBaseUnit = exports.convertBaseUnitToDollarValue = exports.convertBaseUnitToDisplayUnit = void 0;
|
|
8
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
9
|
+
var _assets = require("./assets");
|
|
10
|
+
var mapCoinGeckoPricesToDenoms = function mapCoinGeckoPricesToDenoms(assets, prices) {
|
|
11
|
+
return Object.keys(prices).reduce(function (res, geckoId) {
|
|
12
|
+
var denom = (0, _assets.getDenomByCoinGeckoId)(assets, geckoId);
|
|
13
|
+
if (!denom) {
|
|
14
|
+
throw new Error("No denom found for CoinGecko ID: ".concat(geckoId));
|
|
15
|
+
}
|
|
16
|
+
res[denom] = prices[geckoId].usd;
|
|
17
|
+
return res;
|
|
18
|
+
}, {});
|
|
19
|
+
};
|
|
20
|
+
exports.mapCoinGeckoPricesToDenoms = mapCoinGeckoPricesToDenoms;
|
|
21
|
+
var roundDown = function roundDown(value) {
|
|
22
|
+
return new _bignumber["default"](value).decimalPlaces(0, _bignumber["default"].ROUND_DOWN).toString();
|
|
23
|
+
};
|
|
24
|
+
exports.roundDown = roundDown;
|
|
25
|
+
var getAssetInfo = function getAssetInfo(assets, symbol, chainName) {
|
|
26
|
+
var asset = (0, _assets.getAssetBySymbol)(assets, symbol, chainName);
|
|
27
|
+
var denom = asset === null || asset === void 0 ? void 0 : asset.base;
|
|
28
|
+
var exponent = asset ? (0, _assets.getExponentFromAsset)(asset) : undefined;
|
|
29
|
+
if (!denom || !exponent) {
|
|
30
|
+
throw new Error("No denom or exponent found for symbol: ".concat(symbol));
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
denom: denom,
|
|
34
|
+
exponent: exponent
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
var shiftDecimalPlaces = function shiftDecimalPlaces(amount, exponent) {
|
|
38
|
+
var direction = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
39
|
+
return new _bignumber["default"](amount).shiftedBy(exponent * direction).toString();
|
|
40
|
+
};
|
|
41
|
+
var convertBaseUnitToDollarValue = function convertBaseUnitToDollarValue(assets, prices, symbol, amount, chainName) {
|
|
42
|
+
var _getAssetInfo = getAssetInfo(assets, symbol, chainName),
|
|
43
|
+
denom = _getAssetInfo.denom,
|
|
44
|
+
exponent = _getAssetInfo.exponent;
|
|
45
|
+
var baseAmount = shiftDecimalPlaces(amount, exponent, -1);
|
|
46
|
+
return new _bignumber["default"](baseAmount).multipliedBy(prices[denom]).toString();
|
|
47
|
+
};
|
|
48
|
+
exports.convertBaseUnitToDollarValue = convertBaseUnitToDollarValue;
|
|
49
|
+
var convertDollarValueToBaseUnit = function convertDollarValueToBaseUnit(assets, prices, symbol, value, chainName) {
|
|
50
|
+
var _getAssetInfo2 = getAssetInfo(assets, symbol, chainName),
|
|
51
|
+
denom = _getAssetInfo2.denom,
|
|
52
|
+
exponent = _getAssetInfo2.exponent;
|
|
53
|
+
var baseAmount = new _bignumber["default"](value).dividedBy(prices[denom]).toString();
|
|
54
|
+
return roundDown(shiftDecimalPlaces(baseAmount, exponent));
|
|
55
|
+
};
|
|
56
|
+
exports.convertDollarValueToBaseUnit = convertDollarValueToBaseUnit;
|
|
57
|
+
var convertBaseUnitToDisplayUnit = function convertBaseUnitToDisplayUnit(assets, symbol, amount, chainName) {
|
|
58
|
+
var _getAssetInfo3 = getAssetInfo(assets, symbol, chainName),
|
|
59
|
+
exponent = _getAssetInfo3.exponent;
|
|
60
|
+
return shiftDecimalPlaces(amount, exponent, -1);
|
|
61
|
+
};
|
|
62
|
+
exports.convertBaseUnitToDisplayUnit = convertBaseUnitToDisplayUnit;
|
|
63
|
+
var convertDisplayUnitToBaseUnit = function convertDisplayUnitToBaseUnit(assets, symbol, amount, chainName) {
|
|
64
|
+
var _getAssetInfo4 = getAssetInfo(assets, symbol, chainName),
|
|
65
|
+
exponent = _getAssetInfo4.exponent;
|
|
66
|
+
return roundDown(shiftDecimalPlaces(amount, exponent));
|
|
67
|
+
};
|
|
68
|
+
exports.convertDisplayUnitToBaseUnit = convertDisplayUnitToBaseUnit;
|
package/main/chains.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getGasPriceRangesFromChain = exports.getChainPrettyName = exports.getChainNameByChainId = exports.getChainIdByChainName = exports.getChainGasPriceRanges = exports.getChainByChainName = exports.getChainByChainId = exports.getChainBech32Prefix = void 0;
|
|
7
|
+
var _assets = require("./assets");
|
|
8
|
+
var getGasPriceRangesFromChain = function getGasPriceRangesFromChain(chain) {
|
|
9
|
+
var _chain$fees, _chain$fees$fee_token, _feeToken$low_gas_pri, _feeToken$average_gas, _feeToken$high_gas_pr;
|
|
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];
|
|
11
|
+
return {
|
|
12
|
+
low: (_feeToken$low_gas_pri = feeToken === null || feeToken === void 0 ? void 0 : feeToken.low_gas_price) !== null && _feeToken$low_gas_pri !== void 0 ? _feeToken$low_gas_pri : 0.01,
|
|
13
|
+
average: (_feeToken$average_gas = feeToken === null || feeToken === void 0 ? void 0 : feeToken.average_gas_price) !== null && _feeToken$average_gas !== void 0 ? _feeToken$average_gas : 0.025,
|
|
14
|
+
high: (_feeToken$high_gas_pr = feeToken === null || feeToken === void 0 ? void 0 : feeToken.high_gas_price) !== null && _feeToken$high_gas_pr !== void 0 ? _feeToken$high_gas_pr : 0.04
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
exports.getGasPriceRangesFromChain = getGasPriceRangesFromChain;
|
|
18
|
+
var getChainByChainName = function getChainByChainName(chains, chainName) {
|
|
19
|
+
return (0, _assets.customFind)(chains, function (chain) {
|
|
20
|
+
return chain.chain_name === chainName;
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
exports.getChainByChainName = getChainByChainName;
|
|
24
|
+
var getChainByChainId = function getChainByChainId(chains, chainId) {
|
|
25
|
+
return (0, _assets.customFind)(chains, function (chain) {
|
|
26
|
+
return chain.chain_id === chainId;
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
exports.getChainByChainId = getChainByChainId;
|
|
30
|
+
var getChainNameByChainId = function getChainNameByChainId(chains, chainId) {
|
|
31
|
+
var _getChainByChainId;
|
|
32
|
+
return (_getChainByChainId = getChainByChainId(chains, chainId)) === null || _getChainByChainId === void 0 ? void 0 : _getChainByChainId.chain_name;
|
|
33
|
+
};
|
|
34
|
+
exports.getChainNameByChainId = getChainNameByChainId;
|
|
35
|
+
var getChainIdByChainName = function getChainIdByChainName(chains, chainName) {
|
|
36
|
+
var _getChainByChainName;
|
|
37
|
+
return (_getChainByChainName = getChainByChainName(chains, chainName)) === null || _getChainByChainName === void 0 ? void 0 : _getChainByChainName.chain_id;
|
|
38
|
+
};
|
|
39
|
+
exports.getChainIdByChainName = getChainIdByChainName;
|
|
40
|
+
var getChainGasPriceRanges = function getChainGasPriceRanges(chains, chainName) {
|
|
41
|
+
var chain = getChainByChainName(chains, chainName);
|
|
42
|
+
return chain ? getGasPriceRangesFromChain(chain) : undefined;
|
|
43
|
+
};
|
|
44
|
+
exports.getChainGasPriceRanges = getChainGasPriceRanges;
|
|
45
|
+
var getChainPrettyName = function getChainPrettyName(chains, chainName) {
|
|
46
|
+
var _getChainByChainName2;
|
|
47
|
+
return (_getChainByChainName2 = getChainByChainName(chains, chainName)) === null || _getChainByChainName2 === void 0 ? void 0 : _getChainByChainName2.pretty_name;
|
|
48
|
+
};
|
|
49
|
+
exports.getChainPrettyName = getChainPrettyName;
|
|
50
|
+
var getChainBech32Prefix = function getChainBech32Prefix(chains, chainName) {
|
|
51
|
+
var _getChainByChainName3;
|
|
52
|
+
return (_getChainByChainName3 = getChainByChainName(chains, chainName)) === null || _getChainByChainName3 === void 0 ? void 0 : _getChainByChainName3.bech32_prefix;
|
|
53
|
+
};
|
|
54
|
+
exports.getChainBech32Prefix = getChainBech32Prefix;
|
package/main/{utils.js → ibc.js}
RENAMED
|
@@ -98,7 +98,8 @@ var getIbcAssetPath = function getIbcAssetPath(ibc, chain, counterparty, assets,
|
|
|
98
98
|
return memo;
|
|
99
99
|
}
|
|
100
100
|
if (traces.length > 1) {
|
|
101
|
-
|
|
101
|
+
console.log(traces);
|
|
102
|
+
console.warn('contact maintainers: multi-hop not yet supported');
|
|
102
103
|
}
|
|
103
104
|
var _traces = (0, _slicedToArray2["default"])(traces, 1),
|
|
104
105
|
trace = _traces[0];
|
package/main/index.js
CHANGED
|
@@ -3,36 +3,47 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var
|
|
7
|
-
Object.keys(
|
|
6
|
+
var _ibc = require("./ibc");
|
|
7
|
+
Object.keys(_ibc).forEach(function (key) {
|
|
8
8
|
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] ===
|
|
9
|
+
if (key in exports && exports[key] === _ibc[key]) return;
|
|
10
10
|
Object.defineProperty(exports, key, {
|
|
11
11
|
enumerable: true,
|
|
12
12
|
get: function get() {
|
|
13
|
-
return
|
|
13
|
+
return _ibc[key];
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
});
|
|
17
|
-
var
|
|
18
|
-
Object.keys(
|
|
17
|
+
var _calc = require("./calc");
|
|
18
|
+
Object.keys(_calc).forEach(function (key) {
|
|
19
19
|
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] ===
|
|
20
|
+
if (key in exports && exports[key] === _calc[key]) return;
|
|
21
21
|
Object.defineProperty(exports, key, {
|
|
22
22
|
enumerable: true,
|
|
23
23
|
get: function get() {
|
|
24
|
-
return
|
|
24
|
+
return _calc[key];
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
|
-
var
|
|
29
|
-
Object.keys(
|
|
28
|
+
var _chains = require("./chains");
|
|
29
|
+
Object.keys(_chains).forEach(function (key) {
|
|
30
30
|
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] ===
|
|
31
|
+
if (key in exports && exports[key] === _chains[key]) return;
|
|
32
32
|
Object.defineProperty(exports, key, {
|
|
33
33
|
enumerable: true,
|
|
34
34
|
get: function get() {
|
|
35
|
-
return
|
|
35
|
+
return _chains[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
var _assets = require("./assets");
|
|
40
|
+
Object.keys(_assets).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _assets[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function get() {
|
|
46
|
+
return _assets[key];
|
|
36
47
|
}
|
|
37
48
|
});
|
|
38
49
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chain-registry/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.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",
|
|
@@ -72,9 +72,9 @@
|
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"@babel/runtime": "^7.21.0",
|
|
75
|
-
"@chain-registry/types": "^0.18.
|
|
75
|
+
"@chain-registry/types": "^0.18.1",
|
|
76
76
|
"bignumber.js": "9.1.1",
|
|
77
77
|
"sha.js": "^2.4.11"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "e57916824aad1598342fe9175e9e87b1ba0babcb"
|
|
80
80
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Asset, AssetDenomUnit, AssetList } from '@chain-registry/types';
|
|
2
|
+
export type Denom = AssetDenomUnit['denom'];
|
|
3
|
+
export type Exponent = AssetDenomUnit['exponent'];
|
|
4
|
+
export declare const customFind: <T>(array: T[], filterFn: (item: T) => boolean) => T;
|
|
5
|
+
export declare const getAssetByDenom: (assets: AssetList[], denom: Denom, chainName?: string) => Asset | undefined;
|
|
6
|
+
export declare const getAssetBySymbol: (assets: AssetList[], symbol: string, chainName?: string) => Asset | undefined;
|
|
7
|
+
export declare const getDenomByCoinGeckoId: (assets: AssetList[], coinGeckoId: string, chainName?: string) => Denom | undefined;
|
|
8
|
+
type GetCoinGeckoIdByDenomOptions = {
|
|
9
|
+
chainName?: string;
|
|
10
|
+
allowTestnet?: boolean;
|
|
11
|
+
customAssetFilter?: (asset: Asset) => boolean;
|
|
12
|
+
excludedChainNames?: string[];
|
|
13
|
+
};
|
|
14
|
+
export declare const getCoinGeckoIdByDenom: (assets: AssetList[], denom: Denom, { chainName, allowTestnet, customAssetFilter, excludedChainNames }?: GetCoinGeckoIdByDenomOptions) => string | undefined;
|
|
15
|
+
export declare const getSymbolByDenom: (assets: AssetList[], denom: Denom, chainName?: string) => string | undefined;
|
|
16
|
+
export declare const getDenomBySymbol: (assets: AssetList[], symbol: string, chainName?: string) => Denom | undefined;
|
|
17
|
+
export declare const getExponentFromAsset: (asset: Asset) => number | undefined;
|
|
18
|
+
export declare const getExponentByDenom: (assets: AssetList[], denom: Denom, chainName?: string) => Exponent | undefined;
|
|
19
|
+
export declare const getExponentBySymbol: (assets: AssetList[], symbol: string, chainName?: string) => Exponent | undefined;
|
|
20
|
+
export declare const getNativeTokenByChainName: (assets: AssetList[], chainName: string) => Asset | undefined;
|
|
21
|
+
export declare const getTokenLogoByDenom: (assets: AssetList[], denom: Denom, chainName?: string) => string | undefined;
|
|
22
|
+
export declare const getChainLogo: (assets: AssetList[], chainName: string) => string | undefined;
|
|
23
|
+
export declare const getTokenNameByDenom: (assets: AssetList[], denom: Denom, chainName?: string) => string | undefined;
|
|
24
|
+
export declare const getChainNameByDenom: (assets: AssetList[], denom: Denom) => string | undefined;
|
|
25
|
+
export {};
|
package/types/calc.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AssetList } from '@chain-registry/types';
|
|
2
|
+
import { Denom } from './assets';
|
|
3
|
+
export interface CoinGeckoUSDPrice {
|
|
4
|
+
usd: number;
|
|
5
|
+
}
|
|
6
|
+
export interface DenomPriceMap {
|
|
7
|
+
[key: Denom]: number;
|
|
8
|
+
}
|
|
9
|
+
export declare const mapCoinGeckoPricesToDenoms: (assets: AssetList[], prices: Record<string, CoinGeckoUSDPrice>) => DenomPriceMap;
|
|
10
|
+
export declare const roundDown: (value: number | string) => string;
|
|
11
|
+
export declare const convertBaseUnitToDollarValue: (assets: AssetList[], prices: DenomPriceMap, symbol: string, amount: string | number, chainName?: string) => string;
|
|
12
|
+
export declare const convertDollarValueToBaseUnit: (assets: AssetList[], prices: DenomPriceMap, symbol: string, value: string | number, chainName?: string) => string;
|
|
13
|
+
export declare const convertBaseUnitToDisplayUnit: (assets: AssetList[], symbol: string, amount: string | number, chainName?: string) => string;
|
|
14
|
+
export declare const convertDisplayUnitToBaseUnit: (assets: AssetList[], symbol: string, amount: string | number, chainName?: string) => string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Chain } from '@chain-registry/types';
|
|
2
|
+
export interface GasPriceRanges {
|
|
3
|
+
low: number;
|
|
4
|
+
average: number;
|
|
5
|
+
high: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const getGasPriceRangesFromChain: (chain: Chain) => GasPriceRanges;
|
|
8
|
+
export declare const getChainByChainName: (chains: Chain[], chainName: string) => Chain | undefined;
|
|
9
|
+
export declare const getChainByChainId: (chains: Chain[], chainId: string) => Chain | undefined;
|
|
10
|
+
export declare const getChainNameByChainId: (chains: Chain[], chainId: string) => string | undefined;
|
|
11
|
+
export declare const getChainIdByChainName: (chains: Chain[], chainName: string) => string | undefined;
|
|
12
|
+
export declare const getChainGasPriceRanges: (chains: Chain[], chainName: string) => GasPriceRanges | undefined;
|
|
13
|
+
export declare const getChainPrettyName: (chains: Chain[], chainName: string) => string | undefined;
|
|
14
|
+
export declare const getChainBech32Prefix: (chains: Chain[], chainName: string) => string | undefined;
|
package/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
1
|
+
export * from './ibc';
|
|
2
|
+
export * from './calc';
|
|
3
|
+
export * from './chains';
|
|
4
|
+
export * from './assets';
|
package/CHANGELOG.md
DELETED
|
@@ -1,446 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
# [1.18.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.17.3...@chain-registry/utils@1.18.0) (2024-01-25)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
## [1.17.3](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.17.2...@chain-registry/utils@1.17.3) (2024-01-19)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
## [1.17.2](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.17.1...@chain-registry/utils@1.17.2) (2024-01-19)
|
|
23
|
-
|
|
24
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
## [1.17.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.17.0...@chain-registry/utils@1.17.1) (2024-01-19)
|
|
31
|
-
|
|
32
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
# [1.17.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.16.1...@chain-registry/utils@1.17.0) (2023-12-20)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
### Features
|
|
42
|
-
|
|
43
|
-
* add chainName as optional param ([d415f33](https://github.com/cosmology-tech/chain-registry/commit/d415f33dc96651e5bb4ede689220d89ad11fe9d9))
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
## [1.16.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.16.0...@chain-registry/utils@1.16.1) (2023-12-15)
|
|
50
|
-
|
|
51
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
# [1.16.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.15.0...@chain-registry/utils@1.16.0) (2023-12-15)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
### Features
|
|
61
|
-
|
|
62
|
-
* add getCoinGeckoIdByDenom method ([b05e67b](https://github.com/cosmology-tech/chain-registry/commit/b05e67b4b54258412d359745b1cd095987c67eb6))
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
# [1.15.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.14.0...@chain-registry/utils@1.15.0) (2023-12-15)
|
|
69
|
-
|
|
70
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
# [1.14.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.13.2...@chain-registry/utils@1.14.0) (2023-09-15)
|
|
77
|
-
|
|
78
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
## [1.13.2](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.13.1...@chain-registry/utils@1.13.2) (2023-07-30)
|
|
85
|
-
|
|
86
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
## [1.13.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.13.0...@chain-registry/utils@1.13.1) (2023-07-12)
|
|
93
|
-
|
|
94
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
# [1.13.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.12.0...@chain-registry/utils@1.13.0) (2023-07-11)
|
|
101
|
-
|
|
102
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
# [1.12.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.11.0...@chain-registry/utils@1.12.0) (2023-07-08)
|
|
109
|
-
|
|
110
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
# [1.11.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.10.0...@chain-registry/utils@1.11.0) (2023-06-27)
|
|
117
|
-
|
|
118
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
# [1.10.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.9.1...@chain-registry/utils@1.10.0) (2023-04-20)
|
|
125
|
-
|
|
126
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
## [1.9.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.9.0...@chain-registry/utils@1.9.1) (2023-04-18)
|
|
133
|
-
|
|
134
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
# [1.9.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.8.0...@chain-registry/utils@1.9.0) (2023-04-18)
|
|
141
|
-
|
|
142
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
# [1.8.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.7.0...@chain-registry/utils@1.8.0) (2023-03-29)
|
|
149
|
-
|
|
150
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
# [1.7.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.6.0...@chain-registry/utils@1.7.0) (2023-03-02)
|
|
157
|
-
|
|
158
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
# [1.6.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.5.0...@chain-registry/utils@1.6.0) (2023-02-23)
|
|
165
|
-
|
|
166
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
# [1.5.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.4.0...@chain-registry/utils@1.5.0) (2023-02-08)
|
|
173
|
-
|
|
174
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
# [1.4.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.3.0...@chain-registry/utils@1.4.0) (2022-12-08)
|
|
181
|
-
|
|
182
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
# [1.3.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.2.1...@chain-registry/utils@1.3.0) (2022-11-10)
|
|
189
|
-
|
|
190
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
## [1.2.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.2.0...@chain-registry/utils@1.2.1) (2022-10-27)
|
|
197
|
-
|
|
198
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
# [1.2.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.1.0...@chain-registry/utils@1.2.0) (2022-10-20)
|
|
205
|
-
|
|
206
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
# [1.1.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.0.1...@chain-registry/utils@1.1.0) (2022-10-20)
|
|
213
|
-
|
|
214
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
## [1.0.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.0.0...@chain-registry/utils@1.0.1) (2022-10-20)
|
|
221
|
-
|
|
222
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
# [1.0.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.11.0...@chain-registry/utils@1.0.0) (2022-09-29)
|
|
229
|
-
|
|
230
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
# [0.11.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.10.2...@chain-registry/utils@0.11.0) (2022-09-20)
|
|
237
|
-
|
|
238
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
## [0.10.2](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.10.1...@chain-registry/utils@0.10.2) (2022-09-19)
|
|
245
|
-
|
|
246
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
## [0.10.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.10.0...@chain-registry/utils@0.10.1) (2022-09-19)
|
|
253
|
-
|
|
254
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
# [0.10.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.9.0...@chain-registry/utils@0.10.0) (2022-09-19)
|
|
261
|
-
|
|
262
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
# [0.9.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.8.0...@chain-registry/utils@0.9.0) (2022-09-16)
|
|
269
|
-
|
|
270
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
# [0.8.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.7.3...@chain-registry/utils@0.8.0) (2022-09-14)
|
|
277
|
-
|
|
278
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
## [0.7.3](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.7.2...@chain-registry/utils@0.7.3) (2022-09-08)
|
|
285
|
-
|
|
286
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
## [0.7.2](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.7.1...@chain-registry/utils@0.7.2) (2022-09-08)
|
|
293
|
-
|
|
294
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
## [0.7.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.7.0...@chain-registry/utils@0.7.1) (2022-09-07)
|
|
301
|
-
|
|
302
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
# [0.7.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.6.3...@chain-registry/utils@0.7.0) (2022-09-06)
|
|
309
|
-
|
|
310
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
## [0.6.3](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.6.2...@chain-registry/utils@0.6.3) (2022-08-31)
|
|
317
|
-
|
|
318
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
## [0.6.2](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.6.1...@chain-registry/utils@0.6.2) (2022-08-31)
|
|
325
|
-
|
|
326
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
## [0.6.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.6.0...@chain-registry/utils@0.6.1) (2022-08-31)
|
|
333
|
-
|
|
334
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
# [0.6.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.5.1...@chain-registry/utils@0.6.0) (2022-08-31)
|
|
341
|
-
|
|
342
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
## [0.5.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.5.0...@chain-registry/utils@0.5.1) (2022-08-23)
|
|
349
|
-
|
|
350
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
# [0.5.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.4.0...@chain-registry/utils@0.5.0) (2022-08-23)
|
|
357
|
-
|
|
358
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
# [0.4.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.3.1...@chain-registry/utils@0.4.0) (2022-08-20)
|
|
365
|
-
|
|
366
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
## [0.3.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.3.0...@chain-registry/utils@0.3.1) (2022-08-13)
|
|
373
|
-
|
|
374
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
# [0.3.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.2.1...@chain-registry/utils@0.3.0) (2022-08-13)
|
|
381
|
-
|
|
382
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
## [0.2.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.2.0...@chain-registry/utils@0.2.1) (2022-08-13)
|
|
389
|
-
|
|
390
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
# 0.2.0 (2022-08-13)
|
|
397
|
-
|
|
398
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
# [0.1.0](https://github.com/cosmology-tech/chain-registry/compare/chain-registry-utils@0.0.6...chain-registry-utils@0.1.0) (2022-08-12)
|
|
405
|
-
|
|
406
|
-
**Note:** Version bump only for package chain-registry-utils
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
## 0.0.6 (2022-07-25)
|
|
413
|
-
|
|
414
|
-
**Note:** Version bump only for package chain-registry-utils
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
## [0.0.5](https://github.com/cosmology-tech/chain-registry/compare/chain-registry-utils@0.0.4...chain-registry-utils@0.0.5) (2022-07-14)
|
|
421
|
-
|
|
422
|
-
**Note:** Version bump only for package chain-registry-utils
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
## [0.0.4](https://github.com/cosmology-tech/chain-registry/compare/chain-registry-utils@0.0.3...chain-registry-utils@0.0.4) (2022-07-14)
|
|
429
|
-
|
|
430
|
-
**Note:** Version bump only for package chain-registry-utils
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
## 0.0.3 (2022-07-12)
|
|
437
|
-
|
|
438
|
-
**Note:** Version bump only for package chain-registry-utils
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
## 0.0.2 (2022-07-12)
|
|
445
|
-
|
|
446
|
-
**Note:** Version bump only for package chain-registry-utils
|
package/main/asset-list-util.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.convertBaseUnitsToDisplayUnits = convertBaseUnitsToDisplayUnits;
|
|
8
|
-
exports.convertBaseUnitsToDollarValue = convertBaseUnitsToDollarValue;
|
|
9
|
-
exports.convertCoinGeckoPricesToDenomPriceMap = convertCoinGeckoPricesToDenomPriceMap;
|
|
10
|
-
exports.convertDollarValueToDenomUnits = convertDollarValueToDenomUnits;
|
|
11
|
-
exports.getAssetByDenom = getAssetByDenom;
|
|
12
|
-
exports.getChainDenomBySymbol = getChainDenomBySymbol;
|
|
13
|
-
exports.getCoinGeckoIdByDenom = getCoinGeckoIdByDenom;
|
|
14
|
-
exports.getDenomByCoinGeckoId = getDenomByCoinGeckoId;
|
|
15
|
-
exports.getExponentByDenom = getExponentByDenom;
|
|
16
|
-
exports.getSymbolByChainDenom = getSymbolByChainDenom;
|
|
17
|
-
exports.noDecimals = noDecimals;
|
|
18
|
-
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
19
|
-
function getAssetByKeyValue(assets, key, value, chainName) {
|
|
20
|
-
var filteredAssets = assets.filter(function (_ref) {
|
|
21
|
-
var chain_name = _ref.chain_name;
|
|
22
|
-
return !chainName || chain_name === chainName;
|
|
23
|
-
}).flatMap(function (_ref2) {
|
|
24
|
-
var assets = _ref2.assets;
|
|
25
|
-
return assets;
|
|
26
|
-
});
|
|
27
|
-
var matchingAssets = filteredAssets.filter(function (asset) {
|
|
28
|
-
return asset[key] === value;
|
|
29
|
-
});
|
|
30
|
-
if (matchingAssets.length === 0) {
|
|
31
|
-
throw new Error("No asset found for ".concat(key, " '").concat(value, "'"));
|
|
32
|
-
}
|
|
33
|
-
if (matchingAssets.length > 1) {
|
|
34
|
-
throw new Error("Ambiguity: ".concat(matchingAssets.length, " assets found for ").concat(key, " '").concat(value, "'"));
|
|
35
|
-
}
|
|
36
|
-
return matchingAssets[0];
|
|
37
|
-
}
|
|
38
|
-
function getAssetByDenom(assets, denom, chainName) {
|
|
39
|
-
return getAssetByKeyValue(assets, 'base', denom, chainName);
|
|
40
|
-
}
|
|
41
|
-
function getDenomByCoinGeckoId(assets, coinGeckoId, chainName) {
|
|
42
|
-
return getAssetByKeyValue(assets, 'coingecko_id', coinGeckoId, chainName).base;
|
|
43
|
-
}
|
|
44
|
-
function getCoinGeckoIdByDenom(assets, denom) {
|
|
45
|
-
var _asset$coingecko_id;
|
|
46
|
-
var _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
47
|
-
chainName = _ref3.chainName,
|
|
48
|
-
_ref3$allowTestnet = _ref3.allowTestnet,
|
|
49
|
-
allowTestnet = _ref3$allowTestnet === void 0 ? false : _ref3$allowTestnet,
|
|
50
|
-
_ref3$customAssetFilt = _ref3.customAssetFilter,
|
|
51
|
-
customAssetFilter = _ref3$customAssetFilt === void 0 ? function () {
|
|
52
|
-
return true;
|
|
53
|
-
} : _ref3$customAssetFilt,
|
|
54
|
-
_ref3$excludedChainNa = _ref3.excludedChainNames,
|
|
55
|
-
excludedChainNames = _ref3$excludedChainNa === void 0 ? [] : _ref3$excludedChainNa;
|
|
56
|
-
var filteredAssetLists = assets.filter(function (_ref4) {
|
|
57
|
-
var chain_name = _ref4.chain_name;
|
|
58
|
-
return (!chainName || chain_name === chainName) && (allowTestnet || !chain_name.includes('testnet')) && !excludedChainNames.includes(chain_name);
|
|
59
|
-
});
|
|
60
|
-
var filteredAssets = filteredAssetLists.flatMap(function (_ref5) {
|
|
61
|
-
var assets = _ref5.assets;
|
|
62
|
-
return assets;
|
|
63
|
-
}).filter(function (_ref6) {
|
|
64
|
-
var coingecko_id = _ref6.coingecko_id;
|
|
65
|
-
return coingecko_id;
|
|
66
|
-
}).filter(customAssetFilter);
|
|
67
|
-
var asset = filteredAssets.find(function (_ref7) {
|
|
68
|
-
var base = _ref7.base;
|
|
69
|
-
return base === denom;
|
|
70
|
-
});
|
|
71
|
-
return (_asset$coingecko_id = asset === null || asset === void 0 ? void 0 : asset.coingecko_id) !== null && _asset$coingecko_id !== void 0 ? _asset$coingecko_id : null;
|
|
72
|
-
}
|
|
73
|
-
function getSymbolByChainDenom(assets, denom, chainName) {
|
|
74
|
-
return getAssetByDenom(assets, denom, chainName).symbol;
|
|
75
|
-
}
|
|
76
|
-
function getChainDenomBySymbol(assets, symbol, chainName) {
|
|
77
|
-
return getAssetByKeyValue(assets, 'symbol', symbol, chainName).base;
|
|
78
|
-
}
|
|
79
|
-
function getExponentByDenom(assets, denom, chainName) {
|
|
80
|
-
var _unit$exponent;
|
|
81
|
-
var asset = getAssetByDenom(assets, denom, chainName);
|
|
82
|
-
var unit = asset.denom_units.find(function (_ref8) {
|
|
83
|
-
var denom = _ref8.denom;
|
|
84
|
-
return denom === asset.display;
|
|
85
|
-
});
|
|
86
|
-
return (_unit$exponent = unit === null || unit === void 0 ? void 0 : unit.exponent) !== null && _unit$exponent !== void 0 ? _unit$exponent : 0;
|
|
87
|
-
}
|
|
88
|
-
function convertCoinGeckoPricesToDenomPriceMap(assets, prices) {
|
|
89
|
-
return Object.keys(prices).reduce(function (res, geckoId) {
|
|
90
|
-
var denom = getDenomByCoinGeckoId(assets, geckoId);
|
|
91
|
-
res[denom] = prices[geckoId].usd;
|
|
92
|
-
return res;
|
|
93
|
-
}, {});
|
|
94
|
-
}
|
|
95
|
-
function noDecimals(num) {
|
|
96
|
-
return new _bignumber["default"](num).decimalPlaces(0, _bignumber["default"].ROUND_DOWN).toString();
|
|
97
|
-
}
|
|
98
|
-
function convertBaseUnitsToDollarValue(assets, prices, symbol, amount, chainName) {
|
|
99
|
-
var denom = getChainDenomBySymbol(assets, symbol, chainName);
|
|
100
|
-
return new _bignumber["default"](amount).shiftedBy(-getExponentByDenom(assets, denom, chainName)).multipliedBy(prices[denom]).toString();
|
|
101
|
-
}
|
|
102
|
-
function convertDollarValueToDenomUnits(assets, prices, symbol, value, chainName) {
|
|
103
|
-
var denom = getChainDenomBySymbol(assets, symbol, chainName);
|
|
104
|
-
return new _bignumber["default"](value).dividedBy(prices[denom]).shiftedBy(getExponentByDenom(assets, denom, chainName)).toString();
|
|
105
|
-
}
|
|
106
|
-
function convertBaseUnitsToDisplayUnits(assets, symbol, amount, chainName) {
|
|
107
|
-
var denom = getChainDenomBySymbol(assets, symbol, chainName);
|
|
108
|
-
return new _bignumber["default"](amount).shiftedBy(-getExponentByDenom(assets, denom, chainName)).toString();
|
|
109
|
-
}
|
package/main/fees.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getGasPriceStep = void 0;
|
|
7
|
-
var getGasPriceStep = function getGasPriceStep(chain) {
|
|
8
|
-
var _chain$fees$fee_token, _chain$fees, _chain$fees$fee_token2, _chain$fees$fee_token3, _chain$fees$fee_token4, _chain$fees2, _chain$fees2$fee_toke, _chain$fees2$fee_toke2, _chain$fees$fee_token5, _chain$fees3, _chain$fees3$fee_toke, _chain$fees3$fee_toke2;
|
|
9
|
-
return {
|
|
10
|
-
low: (_chain$fees$fee_token = (_chain$fees = chain.fees) === null || _chain$fees === void 0 ? void 0 : (_chain$fees$fee_token2 = _chain$fees.fee_tokens) === null || _chain$fees$fee_token2 === void 0 ? void 0 : (_chain$fees$fee_token3 = _chain$fees$fee_token2[0]) === null || _chain$fees$fee_token3 === void 0 ? void 0 : _chain$fees$fee_token3.low_gas_price) !== null && _chain$fees$fee_token !== void 0 ? _chain$fees$fee_token : 0.01,
|
|
11
|
-
average: (_chain$fees$fee_token4 = (_chain$fees2 = chain.fees) === null || _chain$fees2 === void 0 ? void 0 : (_chain$fees2$fee_toke = _chain$fees2.fee_tokens) === null || _chain$fees2$fee_toke === void 0 ? void 0 : (_chain$fees2$fee_toke2 = _chain$fees2$fee_toke[0]) === null || _chain$fees2$fee_toke2 === void 0 ? void 0 : _chain$fees2$fee_toke2.average_gas_price) !== null && _chain$fees$fee_token4 !== void 0 ? _chain$fees$fee_token4 : 0.025,
|
|
12
|
-
high: (_chain$fees$fee_token5 = (_chain$fees3 = chain.fees) === null || _chain$fees3 === void 0 ? void 0 : (_chain$fees3$fee_toke = _chain$fees3.fee_tokens) === null || _chain$fees3$fee_toke === void 0 ? void 0 : (_chain$fees3$fee_toke2 = _chain$fees3$fee_toke[0]) === null || _chain$fees3$fee_toke2 === void 0 ? void 0 : _chain$fees3$fee_toke2.high_gas_price) !== null && _chain$fees$fee_token5 !== void 0 ? _chain$fees$fee_token5 : 0.04
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
exports.getGasPriceStep = getGasPriceStep;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Asset, AssetDenomUnit, AssetList } from '@chain-registry/types';
|
|
2
|
-
export type CoinDenom = AssetDenomUnit['denom'];
|
|
3
|
-
export type Exponent = AssetDenomUnit['exponent'];
|
|
4
|
-
export interface CoinGeckoUSD {
|
|
5
|
-
usd: number;
|
|
6
|
-
}
|
|
7
|
-
export interface PriceHash {
|
|
8
|
-
[key: CoinDenom]: number;
|
|
9
|
-
}
|
|
10
|
-
export declare function getAssetByDenom(assets: AssetList[], denom: CoinDenom, chainName?: string): Asset;
|
|
11
|
-
export declare function getDenomByCoinGeckoId(assets: AssetList[], coinGeckoId: string, chainName?: string): CoinDenom;
|
|
12
|
-
type GetCoinGeckoIdByDenomOptions = {
|
|
13
|
-
chainName?: string;
|
|
14
|
-
allowTestnet?: boolean;
|
|
15
|
-
customAssetFilter?: (asset: Asset) => boolean;
|
|
16
|
-
excludedChainNames?: string[];
|
|
17
|
-
};
|
|
18
|
-
export declare function getCoinGeckoIdByDenom(assets: AssetList[], denom: CoinDenom, { chainName, allowTestnet, customAssetFilter, excludedChainNames }?: GetCoinGeckoIdByDenomOptions): string | null;
|
|
19
|
-
export declare function getSymbolByChainDenom(assets: AssetList[], denom: CoinDenom, chainName?: string): string;
|
|
20
|
-
export declare function getChainDenomBySymbol(assets: AssetList[], symbol: string, chainName?: string): CoinDenom;
|
|
21
|
-
export declare function getExponentByDenom(assets: AssetList[], denom: CoinDenom, chainName?: string): Exponent;
|
|
22
|
-
export declare function convertCoinGeckoPricesToDenomPriceMap(assets: AssetList[], prices: Record<string, CoinGeckoUSD>): PriceHash;
|
|
23
|
-
export declare function noDecimals(num: number | string): string;
|
|
24
|
-
export declare function convertBaseUnitsToDollarValue(assets: AssetList[], prices: PriceHash, symbol: string, amount: string | number, chainName?: string): string;
|
|
25
|
-
export declare function convertDollarValueToDenomUnits(assets: AssetList[], prices: PriceHash, symbol: string, value: string | number, chainName?: string): string;
|
|
26
|
-
export declare function convertBaseUnitsToDisplayUnits(assets: AssetList[], symbol: string, amount: string | number, chainName?: string): string;
|
|
27
|
-
export {};
|
package/types/fees.d.ts
DELETED
package/types/registry.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { AssetList, Chain, ChainRegistry, IBCInfo } from '@chain-registry/types';
|
|
2
|
-
export interface ChainRegistryFetcherOptions {
|
|
3
|
-
assetLists?: AssetList[];
|
|
4
|
-
chains?: Chain[];
|
|
5
|
-
ibcData?: IBCInfo[];
|
|
6
|
-
urls?: string[];
|
|
7
|
-
}
|
|
8
|
-
export interface ChainInfoOptions {
|
|
9
|
-
chain_name: string;
|
|
10
|
-
fetcher: ChainRegistryFetcher;
|
|
11
|
-
}
|
|
12
|
-
export declare class ChainInfo {
|
|
13
|
-
chain_name: string;
|
|
14
|
-
fetcher: ChainRegistryFetcher;
|
|
15
|
-
protected _asset_list: AssetList;
|
|
16
|
-
protected _asset_lists: AssetList[];
|
|
17
|
-
protected _chain: Chain;
|
|
18
|
-
protected _ibc_data: IBCInfo[];
|
|
19
|
-
constructor(options: ChainInfoOptions);
|
|
20
|
-
refresh(): void;
|
|
21
|
-
get nativeAssetLists(): AssetList;
|
|
22
|
-
get chain(): Chain;
|
|
23
|
-
get assetLists(): any[];
|
|
24
|
-
}
|
|
25
|
-
export declare class ChainRegistryFetcher implements ChainRegistry {
|
|
26
|
-
protected _asset_lists: AssetList[];
|
|
27
|
-
protected _chains: Chain[];
|
|
28
|
-
protected _ibc_data: IBCInfo[];
|
|
29
|
-
urls: string[];
|
|
30
|
-
constructor(options?: ChainRegistryFetcherOptions);
|
|
31
|
-
get assetLists(): AssetList[];
|
|
32
|
-
getChainAssetList(chainName: string): AssetList;
|
|
33
|
-
getGeneratedAssetLists(chainName: string): AssetList[];
|
|
34
|
-
get chains(): Chain[];
|
|
35
|
-
getChain(chainName: string): Chain;
|
|
36
|
-
get ibcData(): IBCInfo[];
|
|
37
|
-
getChainIbcData(chainName: string): IBCInfo[];
|
|
38
|
-
getChainInfo(chainName: string): ChainInfo;
|
|
39
|
-
upsertChain(data: Chain): void;
|
|
40
|
-
updateAssetList(data: AssetList): void;
|
|
41
|
-
upsertIbcData(data: IBCInfo): void;
|
|
42
|
-
update(data: Chain | AssetList | IBCInfo): void;
|
|
43
|
-
fetch(url: any): Promise<void>;
|
|
44
|
-
fetchUrls(): Promise<void[]>;
|
|
45
|
-
}
|
|
File without changes
|