@chain-registry/utils 1.18.2 → 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} +24 -13
- package/main/index.js +23 -12
- package/package.json +2 -2
- 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 -462
- package/main/asset-list-util.js +0 -109
- package/main/fees.js +0 -14
- 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
|
@@ -9,12 +9,12 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
9
9
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
11
|
var _sha = require("sha.js");
|
|
12
|
-
function ownKeys(
|
|
13
|
-
function _objectSpread(
|
|
12
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
14
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
15
15
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
16
16
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
17
|
-
var ibcDenom =
|
|
17
|
+
var ibcDenom = function ibcDenom(paths, coinMinimalDenom) {
|
|
18
18
|
var prefixes = [];
|
|
19
19
|
var _iterator = _createForOfIteratorHelper(paths),
|
|
20
20
|
_step;
|
|
@@ -32,30 +32,35 @@ var ibcDenom = exports.ibcDenom = function ibcDenom(paths, coinMinimalDenom) {
|
|
|
32
32
|
var denom = "".concat(prefix, "/").concat(coinMinimalDenom);
|
|
33
33
|
return 'ibc/' + Buffer.from(new Uint8Array(new _sha.sha256().update(Buffer.from(denom)).digest())).toString('hex').toUpperCase();
|
|
34
34
|
};
|
|
35
|
+
exports.ibcDenom = ibcDenom;
|
|
35
36
|
var findInfo = function findInfo(ibc, to, from) {
|
|
36
37
|
return ibc.find(function (i) {
|
|
37
38
|
return i.chain_1.chain_name === from && i.chain_2.chain_name === to;
|
|
38
39
|
});
|
|
39
40
|
};
|
|
40
|
-
var getIbcInfo =
|
|
41
|
+
var getIbcInfo = function getIbcInfo(ibc, chain, counterparty) {
|
|
41
42
|
return findInfo(ibc, chain, counterparty) || findInfo(ibc, counterparty, chain);
|
|
42
43
|
};
|
|
43
|
-
|
|
44
|
+
exports.getIbcInfo = getIbcInfo;
|
|
45
|
+
var getTransferChannel = function getTransferChannel(info) {
|
|
44
46
|
return info.channels.find(function (channel) {
|
|
45
47
|
return channel.chain_1.port_id === 'transfer' && channel.chain_2.port_id === 'transfer';
|
|
46
48
|
});
|
|
47
49
|
};
|
|
48
|
-
|
|
50
|
+
exports.getTransferChannel = getTransferChannel;
|
|
51
|
+
var getNonTransferChannel = function getNonTransferChannel(info) {
|
|
49
52
|
return info.channels.find(function (channel) {
|
|
50
53
|
return channel.chain_1.port_id !== 'transfer' && channel.chain_2.port_id === 'transfer' || channel.chain_1.port_id === 'transfer' && channel.chain_2.port_id !== 'transfer';
|
|
51
54
|
});
|
|
52
55
|
};
|
|
53
|
-
|
|
56
|
+
exports.getNonTransferChannel = getNonTransferChannel;
|
|
57
|
+
var getWasmChannel = function getWasmChannel(info) {
|
|
54
58
|
return info.channels.find(function (channel) {
|
|
55
59
|
return channel.chain_1.port_id.startsWith('wasm.') && channel.chain_2.port_id === 'transfer' || channel.chain_1.port_id === 'transfer' && channel.chain_2.port_id.startsWith('wasm');
|
|
56
60
|
});
|
|
57
61
|
};
|
|
58
|
-
|
|
62
|
+
exports.getWasmChannel = getWasmChannel;
|
|
63
|
+
var getIbcAssetPath = function getIbcAssetPath(ibc, chain, counterparty, assets, base) {
|
|
59
64
|
var _asset$traces$filter, _asset$traces, _asset$traces$filter2;
|
|
60
65
|
var ibcInfo = getIbcInfo(ibc, chain, counterparty);
|
|
61
66
|
if (!ibcInfo) {
|
|
@@ -102,7 +107,8 @@ var getIbcAssetPath = exports.getIbcAssetPath = function getIbcAssetPath(ibc, ch
|
|
|
102
107
|
// base
|
|
103
108
|
)));
|
|
104
109
|
};
|
|
105
|
-
|
|
110
|
+
exports.getIbcAssetPath = getIbcAssetPath;
|
|
111
|
+
var getIbcDenomByBase = function getIbcDenomByBase(ibc, chain, counterparty, assets, base) {
|
|
106
112
|
var ibcInfo = getIbcInfo(ibc, chain, counterparty);
|
|
107
113
|
if (ibcInfo) {
|
|
108
114
|
var _asset$traces2, _asset$traces2$find, _ibcTrace$counterpart, _ibcTrace$counterpart2;
|
|
@@ -134,7 +140,8 @@ var getIbcDenomByBase = exports.getIbcDenomByBase = function getIbcDenomByBase(i
|
|
|
134
140
|
return ibcDenom(ibcPath, baseDenom);
|
|
135
141
|
}
|
|
136
142
|
};
|
|
137
|
-
|
|
143
|
+
exports.getIbcDenomByBase = getIbcDenomByBase;
|
|
144
|
+
var getIbcAssets = function getIbcAssets(chainName, ibc, assets) {
|
|
138
145
|
var chainIbcInfo = ibc.filter(function (i) {
|
|
139
146
|
return i.chain_1.chain_name === chainName || i.chain_2.chain_name === chainName;
|
|
140
147
|
});
|
|
@@ -209,6 +216,7 @@ var getIbcAssets = exports.getIbcAssets = function getIbcAssets(chainName, ibc,
|
|
|
209
216
|
chain_name: v.counterparty.chain_name
|
|
210
217
|
// port: v.counterparty.port_id
|
|
211
218
|
},
|
|
219
|
+
|
|
212
220
|
chain: {
|
|
213
221
|
// dst_denom
|
|
214
222
|
channel_id: v.chain.channel_id
|
|
@@ -237,7 +245,8 @@ var getIbcAssets = exports.getIbcAssets = function getIbcAssets(chainName, ibc,
|
|
|
237
245
|
};
|
|
238
246
|
});
|
|
239
247
|
};
|
|
240
|
-
|
|
248
|
+
exports.getIbcAssets = getIbcAssets;
|
|
249
|
+
var getCw20Assets = function getCw20Assets(chainName, ibc, assets) {
|
|
241
250
|
var chainIbcInfo = ibc.filter(function (i) {
|
|
242
251
|
return i.chain_1.chain_name === chainName || i.chain_2.chain_name === chainName;
|
|
243
252
|
});
|
|
@@ -334,7 +343,8 @@ var getCw20Assets = exports.getCw20Assets = function getCw20Assets(chainName, ib
|
|
|
334
343
|
};
|
|
335
344
|
});
|
|
336
345
|
};
|
|
337
|
-
|
|
346
|
+
exports.getCw20Assets = getCw20Assets;
|
|
347
|
+
var getAssetLists = function getAssetLists(chainName, ibc, assets) {
|
|
338
348
|
var ibcAssetLists = getIbcAssets(chainName, ibc, assets);
|
|
339
349
|
var cw20Assets = getCw20Assets(chainName, ibc, assets);
|
|
340
350
|
return ibcAssetLists.reduce(function (m, v) {
|
|
@@ -351,4 +361,5 @@ var getAssetLists = exports.getAssetLists = function getAssetLists(chainName, ib
|
|
|
351
361
|
assets: assets
|
|
352
362
|
}].concat((0, _toConsumableArray2["default"])(m));
|
|
353
363
|
}, []);
|
|
354
|
-
};
|
|
364
|
+
};
|
|
365
|
+
exports.getAssetLists = getAssetLists;
|
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",
|
|
@@ -76,5 +76,5 @@
|
|
|
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,462 +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.2](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.18.1...@chain-registry/utils@1.18.2) (2024-02-27)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
## [1.18.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.18.0...@chain-registry/utils@1.18.1) (2024-02-26)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# [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)
|
|
23
|
-
|
|
24
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
## [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)
|
|
31
|
-
|
|
32
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
## [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)
|
|
39
|
-
|
|
40
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
## [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)
|
|
47
|
-
|
|
48
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
# [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)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
### Features
|
|
58
|
-
|
|
59
|
-
* add chainName as optional param ([d415f33](https://github.com/cosmology-tech/chain-registry/commit/d415f33dc96651e5bb4ede689220d89ad11fe9d9))
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
## [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)
|
|
66
|
-
|
|
67
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
# [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)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
### Features
|
|
77
|
-
|
|
78
|
-
* add getCoinGeckoIdByDenom method ([b05e67b](https://github.com/cosmology-tech/chain-registry/commit/b05e67b4b54258412d359745b1cd095987c67eb6))
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
# [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)
|
|
85
|
-
|
|
86
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
# [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)
|
|
93
|
-
|
|
94
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
## [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)
|
|
101
|
-
|
|
102
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
## [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)
|
|
109
|
-
|
|
110
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
# [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)
|
|
117
|
-
|
|
118
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
# [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)
|
|
125
|
-
|
|
126
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
# [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)
|
|
133
|
-
|
|
134
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
# [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)
|
|
141
|
-
|
|
142
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
## [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)
|
|
149
|
-
|
|
150
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
# [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)
|
|
157
|
-
|
|
158
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
# [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)
|
|
165
|
-
|
|
166
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
# [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)
|
|
173
|
-
|
|
174
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
# [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)
|
|
181
|
-
|
|
182
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
# [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)
|
|
189
|
-
|
|
190
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
# [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)
|
|
197
|
-
|
|
198
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
# [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)
|
|
205
|
-
|
|
206
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
## [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)
|
|
213
|
-
|
|
214
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
# [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)
|
|
221
|
-
|
|
222
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
# [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)
|
|
229
|
-
|
|
230
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
## [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)
|
|
237
|
-
|
|
238
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
# [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)
|
|
245
|
-
|
|
246
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
# [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)
|
|
253
|
-
|
|
254
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
## [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)
|
|
261
|
-
|
|
262
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
## [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)
|
|
269
|
-
|
|
270
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
# [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)
|
|
277
|
-
|
|
278
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
# [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)
|
|
285
|
-
|
|
286
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
# [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)
|
|
293
|
-
|
|
294
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
## [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)
|
|
301
|
-
|
|
302
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
## [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)
|
|
309
|
-
|
|
310
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
## [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)
|
|
317
|
-
|
|
318
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
# [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)
|
|
325
|
-
|
|
326
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
## [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)
|
|
333
|
-
|
|
334
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
## [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)
|
|
341
|
-
|
|
342
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
## [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)
|
|
349
|
-
|
|
350
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
# [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)
|
|
357
|
-
|
|
358
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
## [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)
|
|
365
|
-
|
|
366
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
# [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)
|
|
373
|
-
|
|
374
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
# [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)
|
|
381
|
-
|
|
382
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
## [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)
|
|
389
|
-
|
|
390
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
# [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)
|
|
397
|
-
|
|
398
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
## [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)
|
|
405
|
-
|
|
406
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
# 0.2.0 (2022-08-13)
|
|
413
|
-
|
|
414
|
-
**Note:** Version bump only for package @chain-registry/utils
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
# [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)
|
|
421
|
-
|
|
422
|
-
**Note:** Version bump only for package chain-registry-utils
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
## 0.0.6 (2022-07-25)
|
|
429
|
-
|
|
430
|
-
**Note:** Version bump only for package chain-registry-utils
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
## [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)
|
|
437
|
-
|
|
438
|
-
**Note:** Version bump only for package chain-registry-utils
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
## [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)
|
|
445
|
-
|
|
446
|
-
**Note:** Version bump only for package chain-registry-utils
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
## 0.0.3 (2022-07-12)
|
|
453
|
-
|
|
454
|
-
**Note:** Version bump only for package chain-registry-utils
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
## 0.0.2 (2022-07-12)
|
|
461
|
-
|
|
462
|
-
**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,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getGasPriceStep = void 0;
|
|
7
|
-
var getGasPriceStep = exports.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
|
-
};
|
|
@@ -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
|