@chain-registry/utils 0.11.0 → 1.0.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/CHANGELOG.md +8 -0
- package/main/utils.js +81 -73
- package/package.json +2 -2
- package/types/utils.d.ts +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [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)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @chain-registry/utils
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [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)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @chain-registry/utils
|
package/main/utils.js
CHANGED
|
@@ -5,11 +5,13 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.ibcDenom = exports.getWasmChannel = exports.getTransferChannel = exports.getNonTransferChannel = exports.getIbcInfo = exports.
|
|
8
|
+
exports.ibcDenom = exports.getWasmChannel = exports.getTransferChannel = exports.getNonTransferChannel = exports.getIbcInfo = exports.getIbcDenomByBase = exports.getIbcAssets = exports.getIbcAssetPath = exports.getCw20Assets = exports.getAssetLists = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
11
|
|
|
10
12
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
13
|
|
|
12
|
-
var
|
|
14
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
15
|
|
|
14
16
|
var _sha = require("sha.js");
|
|
15
17
|
|
|
@@ -32,7 +34,7 @@ var ibcDenom = function ibcDenom(paths, coinMinimalDenom) {
|
|
|
32
34
|
try {
|
|
33
35
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
34
36
|
var path = _step.value;
|
|
35
|
-
prefixes.push("".concat(path.
|
|
37
|
+
prefixes.push("".concat(path.port_id, "/").concat(path.channel_id));
|
|
36
38
|
}
|
|
37
39
|
} catch (err) {
|
|
38
40
|
_iterator.e(err);
|
|
@@ -83,105 +85,111 @@ var getWasmChannel = function getWasmChannel(info) {
|
|
|
83
85
|
|
|
84
86
|
exports.getWasmChannel = getWasmChannel;
|
|
85
87
|
|
|
86
|
-
var
|
|
88
|
+
var getIbcAssetPath = function getIbcAssetPath(ibc, chain, counterparty, assets, base) {
|
|
89
|
+
var _asset$traces$filter, _asset$traces, _asset$traces$filter2;
|
|
90
|
+
|
|
87
91
|
var ibcInfo = getIbcInfo(ibc, chain, counterparty);
|
|
88
92
|
|
|
89
|
-
if (ibcInfo) {
|
|
90
|
-
|
|
93
|
+
if (!ibcInfo) {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
91
96
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
97
|
+
var channel = base.startsWith('cw20:') ? getWasmChannel(ibcInfo) : getTransferChannel(ibcInfo);
|
|
98
|
+
|
|
99
|
+
if (!channel) {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
95
102
|
|
|
96
|
-
|
|
103
|
+
var channelInfo;
|
|
97
104
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
105
|
+
if (ibcInfo.chain_1.chain_name === chain) {
|
|
106
|
+
channelInfo = channel.chain_1;
|
|
107
|
+
} else {
|
|
108
|
+
channelInfo = channel.chain_2;
|
|
109
|
+
}
|
|
103
110
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
111
|
+
var memo = [channelInfo];
|
|
112
|
+
var assetList = assets.find(function (_ref) {
|
|
113
|
+
var chain_name = _ref.chain_name;
|
|
114
|
+
return chain_name === counterparty;
|
|
115
|
+
});
|
|
108
116
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
117
|
+
if (!assetList) {
|
|
118
|
+
return memo;
|
|
119
|
+
}
|
|
112
120
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
// portId: channelInfo.port_id,
|
|
133
|
-
// channelId: channelInfo.channel_id
|
|
134
|
-
// }
|
|
135
|
-
// ],
|
|
136
|
-
// base
|
|
137
|
-
// );
|
|
138
|
-
// }
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return ibcDenom([{
|
|
142
|
-
portId: channelInfo.port_id,
|
|
143
|
-
channelId: channelInfo.channel_id
|
|
144
|
-
}], base);
|
|
121
|
+
var asset = assetList.assets.find(function (asset) {
|
|
122
|
+
return asset.base === base;
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
if (!asset) {
|
|
126
|
+
console.log("no ".concat(base, " found in ").concat(counterparty));
|
|
127
|
+
return memo;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
var traces = (_asset$traces$filter = (_asset$traces = asset.traces) === null || _asset$traces === void 0 ? void 0 : (_asset$traces$filter2 = _asset$traces.filter) === null || _asset$traces$filter2 === void 0 ? void 0 : _asset$traces$filter2.call(_asset$traces, function (trace) {
|
|
131
|
+
return trace.type === 'ibc' || trace.type === 'ibc-cw20';
|
|
132
|
+
})) !== null && _asset$traces$filter !== void 0 ? _asset$traces$filter : [];
|
|
133
|
+
|
|
134
|
+
if (!traces.length) {
|
|
135
|
+
return memo;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (traces.length > 1) {
|
|
139
|
+
throw new Error('contact maintainers: multi-hop not yet supported');
|
|
145
140
|
}
|
|
141
|
+
|
|
142
|
+
var _traces = (0, _slicedToArray2["default"])(traces, 1),
|
|
143
|
+
trace = _traces[0];
|
|
144
|
+
|
|
145
|
+
return [].concat(memo, (0, _toConsumableArray2["default"])(getIbcAssetPath(ibc, counterparty, trace.counterparty.chain_name, assets, trace.counterparty.base_denom // base
|
|
146
|
+
)));
|
|
146
147
|
};
|
|
147
148
|
|
|
148
|
-
exports.
|
|
149
|
+
exports.getIbcAssetPath = getIbcAssetPath;
|
|
149
150
|
|
|
150
|
-
var
|
|
151
|
+
var getIbcDenomByBase = function getIbcDenomByBase(ibc, chain, counterparty, assets, base) {
|
|
151
152
|
var ibcInfo = getIbcInfo(ibc, chain, counterparty);
|
|
152
153
|
|
|
153
154
|
if (ibcInfo) {
|
|
154
|
-
var
|
|
155
|
+
var _asset$traces2, _asset$traces2$find, _ibcTrace$counterpart, _ibcTrace$counterpart2;
|
|
156
|
+
|
|
157
|
+
var channel = base.startsWith('cw20:') ? getWasmChannel(ibcInfo) : getTransferChannel(ibcInfo);
|
|
155
158
|
|
|
156
159
|
if (!channel) {
|
|
157
160
|
return;
|
|
158
161
|
}
|
|
159
162
|
|
|
160
|
-
var
|
|
163
|
+
var ibcPath = getIbcAssetPath(ibc, chain, counterparty, assets, base);
|
|
164
|
+
var assetList = assets.find(function (_ref2) {
|
|
165
|
+
var chain_name = _ref2.chain_name;
|
|
166
|
+
return chain_name === counterparty;
|
|
167
|
+
});
|
|
161
168
|
|
|
162
|
-
if (
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
169
|
+
if (!assetList) {
|
|
170
|
+
console.warn("missing asset list for ".concat(counterparty)); // could be incorrect...
|
|
171
|
+
|
|
172
|
+
return ibcDenom(ibcPath, base);
|
|
166
173
|
}
|
|
167
174
|
|
|
168
|
-
var
|
|
169
|
-
|
|
170
|
-
return chain_name === counterparty;
|
|
175
|
+
var asset = assetList.assets.find(function (asset) {
|
|
176
|
+
return asset.base === base;
|
|
171
177
|
});
|
|
172
178
|
|
|
173
|
-
if (!
|
|
174
|
-
|
|
179
|
+
if (!asset) {
|
|
180
|
+
console.warn("no ".concat(base, " found in ").concat(counterparty));
|
|
181
|
+
return ibcDenom(ibcPath, base);
|
|
175
182
|
}
|
|
176
183
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
184
|
+
var ibcTrace = (_asset$traces2 = asset.traces) === null || _asset$traces2 === void 0 ? void 0 : (_asset$traces2$find = _asset$traces2.find) === null || _asset$traces2$find === void 0 ? void 0 : _asset$traces2$find.call(_asset$traces2, function (trace) {
|
|
185
|
+
return trace.type === 'ibc';
|
|
186
|
+
});
|
|
187
|
+
var baseDenom = (_ibcTrace$counterpart = ibcTrace === null || ibcTrace === void 0 ? void 0 : (_ibcTrace$counterpart2 = ibcTrace.counterparty) === null || _ibcTrace$counterpart2 === void 0 ? void 0 : _ibcTrace$counterpart2.base_denom) !== null && _ibcTrace$counterpart !== void 0 ? _ibcTrace$counterpart : asset.base;
|
|
188
|
+
return ibcDenom(ibcPath, baseDenom);
|
|
181
189
|
}
|
|
182
190
|
};
|
|
183
191
|
|
|
184
|
-
exports.
|
|
192
|
+
exports.getIbcDenomByBase = getIbcDenomByBase;
|
|
185
193
|
|
|
186
194
|
var getIbcAssets = function getIbcAssets(chainName, ibc, assets) {
|
|
187
195
|
var chainIbcInfo = ibc.filter(function (i) {
|
|
@@ -296,7 +304,7 @@ var getCw20Assets = function getCw20Assets(chainName, ibc, assets) {
|
|
|
296
304
|
var cw20Assets = counterpartyAssets.assets.filter(function (a) {
|
|
297
305
|
return a.base.startsWith('cw20:');
|
|
298
306
|
}).map(function (asset) {
|
|
299
|
-
var denom =
|
|
307
|
+
var denom = getIbcDenomByBase(ibc, chainName, counterparty, //
|
|
300
308
|
assets, asset.base);
|
|
301
309
|
|
|
302
310
|
var newAsset = _objectSpread({}, asset);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chain-registry/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.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",
|
|
@@ -78,5 +78,5 @@
|
|
|
78
78
|
"cross-fetch": "^3.1.5",
|
|
79
79
|
"sha.js": "^2.4.11"
|
|
80
80
|
},
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "3f6b00c23df64fdac243ae5b6af41a69fcf27755"
|
|
82
82
|
}
|
package/types/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AssetList, IBCInfo } from '@chain-registry/types';
|
|
2
2
|
export declare const ibcDenom: (paths: {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
port_id: string;
|
|
4
|
+
channel_id: string;
|
|
5
5
|
}[], coinMinimalDenom: string) => string;
|
|
6
6
|
export declare const getIbcInfo: (ibc: IBCInfo[], chain: string, counterparty: string) => IBCInfo;
|
|
7
7
|
export declare const getTransferChannel: (info: IBCInfo) => {
|
|
@@ -43,8 +43,8 @@ export declare const getWasmChannel: (info: IBCInfo) => {
|
|
|
43
43
|
version: string;
|
|
44
44
|
tags?: object;
|
|
45
45
|
};
|
|
46
|
+
export declare const getIbcAssetPath: (ibc: IBCInfo[], chain: string, counterparty: string, assets: AssetList[], base: string) => any;
|
|
46
47
|
export declare const getIbcDenomByBase: (ibc: IBCInfo[], chain: string, counterparty: string, assets: AssetList[], base: string) => string;
|
|
47
|
-
export declare const getIbcDenomByBaseForCw20: (ibc: IBCInfo[], chain: string, counterparty: string, assets: AssetList[], base: string) => string;
|
|
48
48
|
export declare const getIbcAssets: (chainName: string, ibc: IBCInfo[], assets: AssetList[]) => {
|
|
49
49
|
chain_name: string;
|
|
50
50
|
assets: any;
|