@xchainjs/xchain-thorchain 0.21.0 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/lib/client.d.ts +20 -2
- package/lib/index.esm.js +79 -59
- package/lib/index.js +78 -59
- package/lib/types/client-types.d.ts +3 -0
- package/lib/util.d.ts +11 -12
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
+
# v0.22.1 (2022-02-16)
|
|
2
|
+
|
|
3
|
+
## Fix
|
|
4
|
+
|
|
5
|
+
- Increase limit for `DEFAULT_GAS_VALUE` from 2000000 to 3000000 to accommodate recent increases in gas used that go above the old limit
|
|
6
|
+
|
|
7
|
+
# v0.22.0 (2022-02-06)
|
|
8
|
+
|
|
9
|
+
## Add
|
|
10
|
+
|
|
11
|
+
- Option to pass `ChainIds` into constructor
|
|
12
|
+
- getter / setter for `chainId` in `Client`
|
|
13
|
+
|
|
14
|
+
## Breaking change
|
|
15
|
+
|
|
16
|
+
- `buildDepositTx` needs `chainId` to be passed - all params are set as object
|
|
17
|
+
- Remove `enum ChainId` + `getChainId` + `isChainId` from `utils`
|
|
18
|
+
|
|
19
|
+
# v0.21.2 (2022-02-04)
|
|
20
|
+
|
|
21
|
+
## Fix
|
|
22
|
+
|
|
23
|
+
- Use latest axios@0.25.0
|
|
24
|
+
- xchain-client@0.11.1
|
|
25
|
+
- @xchainjs/xchain-util@0.5.1
|
|
26
|
+
- @xchainjs/xchain-cosmos@0.16.1
|
|
27
|
+
|
|
28
|
+
# v.0.21.1 (2022-02-04)
|
|
29
|
+
|
|
30
|
+
## Fix
|
|
31
|
+
|
|
32
|
+
- Fix chain id for `testnet` #477
|
|
33
|
+
|
|
34
|
+
## Add
|
|
35
|
+
|
|
36
|
+
- Helper `isChainId`
|
|
37
|
+
- `enum ChainId`
|
|
38
|
+
|
|
1
39
|
# v.0.21.0 (2022-02-02)
|
|
2
40
|
|
|
3
41
|
## Breaking change
|
package/lib/client.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { CosmosSDKClient, RPCTxResult } from '@xchainjs/xchain-cosmos';
|
|
|
3
3
|
import { Asset } from '@xchainjs/xchain-util';
|
|
4
4
|
import { PrivKey, PubKey } from 'cosmos-client';
|
|
5
5
|
import { StdTx } from 'cosmos-client/x/auth';
|
|
6
|
-
import { ClientUrl, DepositParam, ExplorerUrls, NodeUrl, ThorchainClientParams, TxOfflineParams } from './types';
|
|
6
|
+
import { ChainId, ClientUrl, DepositParam, ExplorerUrls, NodeUrl, ThorchainClientParams, TxOfflineParams } from './types';
|
|
7
7
|
/**
|
|
8
8
|
* Interface for custom Thorchain client
|
|
9
9
|
*/
|
|
@@ -21,6 +21,7 @@ declare class Client implements ThorchainClient, XChainClient {
|
|
|
21
21
|
private network;
|
|
22
22
|
private clientUrl;
|
|
23
23
|
private explorerUrls;
|
|
24
|
+
private chainIds;
|
|
24
25
|
private phrase;
|
|
25
26
|
private rootDerivationPaths;
|
|
26
27
|
private cosmosClient;
|
|
@@ -34,7 +35,7 @@ declare class Client implements ThorchainClient, XChainClient {
|
|
|
34
35
|
*
|
|
35
36
|
* @throws {"Invalid phrase"} Thrown if the given phase is invalid.
|
|
36
37
|
*/
|
|
37
|
-
constructor({ network, phrase, clientUrl, explorerUrls, rootDerivationPaths, }: XChainClientParams & ThorchainClientParams);
|
|
38
|
+
constructor({ network, phrase, clientUrl, explorerUrls, rootDerivationPaths, chainIds, }: XChainClientParams & ThorchainClientParams);
|
|
38
39
|
/**
|
|
39
40
|
* Purge client.
|
|
40
41
|
*
|
|
@@ -83,6 +84,23 @@ declare class Client implements ThorchainClient, XChainClient {
|
|
|
83
84
|
* @returns {string} The explorer url for thorchain based on the current network.
|
|
84
85
|
*/
|
|
85
86
|
getExplorerUrl(): string;
|
|
87
|
+
/**
|
|
88
|
+
* Sets chain id
|
|
89
|
+
*
|
|
90
|
+
* @param {ChainId} chainId Chain id to update
|
|
91
|
+
* @param {Network} network (optional) Network for given chainId. If `network`not set, current network of the client is used
|
|
92
|
+
*
|
|
93
|
+
* @returns {void}
|
|
94
|
+
*/
|
|
95
|
+
setChainId(chainId: ChainId, network?: Network): void;
|
|
96
|
+
/**
|
|
97
|
+
* Gets chain id
|
|
98
|
+
*
|
|
99
|
+
* @param {Network} network (optional) Network to get chain id from. If `network`not set, current network of the client is used
|
|
100
|
+
*
|
|
101
|
+
* @returns {ChainId} Chain id based on the current network.
|
|
102
|
+
*/
|
|
103
|
+
getChainId(network?: Network): ChainId;
|
|
86
104
|
/**
|
|
87
105
|
* Get cosmos client
|
|
88
106
|
* @returns {CosmosSDKClient} current cosmos client
|
package/lib/index.esm.js
CHANGED
|
@@ -115,7 +115,7 @@ var msgNativeTxFromJson = function (value) {
|
|
|
115
115
|
};
|
|
116
116
|
|
|
117
117
|
var DECIMAL = 8;
|
|
118
|
-
var DEFAULT_GAS_VALUE = '
|
|
118
|
+
var DEFAULT_GAS_VALUE = '3000000';
|
|
119
119
|
var DEPOSIT_GAS_VALUE = '500000000';
|
|
120
120
|
var MAX_TX_COUNT = 100;
|
|
121
121
|
/**
|
|
@@ -198,23 +198,6 @@ var getPrefix = function (network) {
|
|
|
198
198
|
return 'tthor';
|
|
199
199
|
}
|
|
200
200
|
};
|
|
201
|
-
/**
|
|
202
|
-
* Get the chain id.
|
|
203
|
-
*
|
|
204
|
-
* @param {Network} network
|
|
205
|
-
* @returns {string} The chain id based on the network.
|
|
206
|
-
*
|
|
207
|
-
*/
|
|
208
|
-
var getChainId = function (network) {
|
|
209
|
-
switch (network) {
|
|
210
|
-
case Network.Mainnet:
|
|
211
|
-
return 'thorchain';
|
|
212
|
-
case Network.Stagenet:
|
|
213
|
-
return 'thorchain-stagenet';
|
|
214
|
-
case Network.Testnet:
|
|
215
|
-
return 'thorchain';
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
201
|
/**
|
|
219
202
|
* Register Codecs based on the prefix.
|
|
220
203
|
*
|
|
@@ -292,46 +275,52 @@ var getTxType = function (txData, encoding) {
|
|
|
292
275
|
/**
|
|
293
276
|
* Structure StdTx from MsgNativeTx.
|
|
294
277
|
*
|
|
295
|
-
* @param {
|
|
278
|
+
* @param {MsgNativeTx} msgNativeTx Msg of type `MsgNativeTx`.
|
|
279
|
+
* @param {string} nodeUrl Node url
|
|
280
|
+
* @param {chainId} ChainId Chain id of the network
|
|
281
|
+
*
|
|
296
282
|
* @returns {Tx} The transaction details of the given transaction id.
|
|
297
283
|
*
|
|
298
284
|
* @throws {"Invalid client url"} Thrown if the client url is an invalid one.
|
|
299
285
|
*/
|
|
300
|
-
var buildDepositTx = function (
|
|
301
|
-
var
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
286
|
+
var buildDepositTx = function (_a) {
|
|
287
|
+
var msgNativeTx = _a.msgNativeTx, nodeUrl = _a.nodeUrl, chainId = _a.chainId;
|
|
288
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
289
|
+
var data, networkChainId, response, fee, unsignedStdTx;
|
|
290
|
+
var _b, _c;
|
|
291
|
+
return __generator(this, function (_d) {
|
|
292
|
+
switch (_d.label) {
|
|
293
|
+
case 0: return [4 /*yield*/, axios.get(nodeUrl + "/cosmos/base/tendermint/v1beta1/node_info")];
|
|
294
|
+
case 1:
|
|
295
|
+
data = (_d.sent()).data;
|
|
296
|
+
networkChainId = data.default_node_info.network;
|
|
297
|
+
if (!networkChainId || chainId !== networkChainId)
|
|
298
|
+
throw new Error("Invalid network (asked: " + chainId + " / returned: " + networkChainId);
|
|
299
|
+
return [4 /*yield*/, axios.post(nodeUrl + "/thorchain/deposit", {
|
|
300
|
+
coins: msgNativeTx.coins,
|
|
301
|
+
memo: msgNativeTx.memo,
|
|
302
|
+
base_req: {
|
|
303
|
+
chain_id: chainId,
|
|
304
|
+
from: msgNativeTx.signer,
|
|
305
|
+
},
|
|
306
|
+
})];
|
|
307
|
+
case 2:
|
|
308
|
+
response = (_d.sent()).data;
|
|
309
|
+
if (!response || !response.value)
|
|
310
|
+
throw new Error('Invalid client url');
|
|
311
|
+
fee = (_c = (_b = response.value) === null || _b === void 0 ? void 0 : _b.fee) !== null && _c !== void 0 ? _c : { amount: [] };
|
|
312
|
+
unsignedStdTx = StdTx.fromJSON({
|
|
313
|
+
msg: response.value.msg,
|
|
314
|
+
// override fee
|
|
315
|
+
fee: __assign(__assign({}, fee), { gas: DEPOSIT_GAS_VALUE }),
|
|
316
|
+
signatures: [],
|
|
317
|
+
memo: '',
|
|
318
|
+
});
|
|
319
|
+
return [2 /*return*/, unsignedStdTx];
|
|
320
|
+
}
|
|
321
|
+
});
|
|
333
322
|
});
|
|
334
|
-
}
|
|
323
|
+
};
|
|
335
324
|
/**
|
|
336
325
|
* Get the balance of a given address.
|
|
337
326
|
*
|
|
@@ -480,13 +469,17 @@ var Client = /** @class */ (function () {
|
|
|
480
469
|
* @throws {"Invalid phrase"} Thrown if the given phase is invalid.
|
|
481
470
|
*/
|
|
482
471
|
function Client(_a) {
|
|
483
|
-
var _b;
|
|
472
|
+
var _b, _c;
|
|
484
473
|
var _this = this;
|
|
485
|
-
var
|
|
474
|
+
var _d = _a.network, network = _d === void 0 ? Network.Testnet : _d, phrase = _a.phrase, clientUrl = _a.clientUrl, explorerUrls = _a.explorerUrls, _e = _a.rootDerivationPaths, rootDerivationPaths = _e === void 0 ? (_b = {},
|
|
486
475
|
_b[Network.Mainnet] = "44'/931'/0'/0/",
|
|
487
476
|
_b[Network.Stagenet] = "44'/931'/0'/0/",
|
|
488
477
|
_b[Network.Testnet] = "44'/931'/0'/0/",
|
|
489
|
-
_b) :
|
|
478
|
+
_b) : _e, _f = _a.chainIds, chainIds = _f === void 0 ? (_c = {},
|
|
479
|
+
_c[Network.Mainnet] = 'thorchain',
|
|
480
|
+
_c[Network.Stagenet] = 'thorchain-stagenet',
|
|
481
|
+
_c[Network.Testnet] = 'thorchain-v1',
|
|
482
|
+
_c) : _f;
|
|
490
483
|
this.phrase = '';
|
|
491
484
|
/**
|
|
492
485
|
* Get transaction history of a given address with pagination options.
|
|
@@ -556,10 +549,11 @@ var Client = /** @class */ (function () {
|
|
|
556
549
|
this.network = network;
|
|
557
550
|
this.clientUrl = clientUrl || getDefaultClientUrl();
|
|
558
551
|
this.explorerUrls = explorerUrls || getDefaultExplorerUrls();
|
|
552
|
+
this.chainIds = chainIds;
|
|
559
553
|
this.rootDerivationPaths = rootDerivationPaths;
|
|
560
554
|
this.cosmosClient = new CosmosSDKClient({
|
|
561
555
|
server: this.getClientUrl().node,
|
|
562
|
-
chainId: getChainId(this.network),
|
|
556
|
+
chainId: this.getChainId(this.network),
|
|
563
557
|
prefix: getPrefix(this.network),
|
|
564
558
|
});
|
|
565
559
|
if (phrase)
|
|
@@ -631,6 +625,28 @@ var Client = /** @class */ (function () {
|
|
|
631
625
|
Client.prototype.getExplorerUrl = function () {
|
|
632
626
|
return this.explorerUrls.root[this.network];
|
|
633
627
|
};
|
|
628
|
+
/**
|
|
629
|
+
* Sets chain id
|
|
630
|
+
*
|
|
631
|
+
* @param {ChainId} chainId Chain id to update
|
|
632
|
+
* @param {Network} network (optional) Network for given chainId. If `network`not set, current network of the client is used
|
|
633
|
+
*
|
|
634
|
+
* @returns {void}
|
|
635
|
+
*/
|
|
636
|
+
Client.prototype.setChainId = function (chainId, network) {
|
|
637
|
+
var _a;
|
|
638
|
+
this.chainIds = __assign(__assign({}, this.chainIds), (_a = {}, _a[network || this.network] = chainId, _a));
|
|
639
|
+
};
|
|
640
|
+
/**
|
|
641
|
+
* Gets chain id
|
|
642
|
+
*
|
|
643
|
+
* @param {Network} network (optional) Network to get chain id from. If `network`not set, current network of the client is used
|
|
644
|
+
*
|
|
645
|
+
* @returns {ChainId} Chain id based on the current network.
|
|
646
|
+
*/
|
|
647
|
+
Client.prototype.getChainId = function (network) {
|
|
648
|
+
return this.chainIds[network || this.network];
|
|
649
|
+
};
|
|
634
650
|
/**
|
|
635
651
|
* Get cosmos client
|
|
636
652
|
* @returns {CosmosSDKClient} current cosmos client
|
|
@@ -872,7 +888,11 @@ var Client = /** @class */ (function () {
|
|
|
872
888
|
memo: memo,
|
|
873
889
|
signer: signer,
|
|
874
890
|
});
|
|
875
|
-
return [4 /*yield*/, buildDepositTx(
|
|
891
|
+
return [4 /*yield*/, buildDepositTx({
|
|
892
|
+
msgNativeTx: msgNativeTx,
|
|
893
|
+
nodeUrl: this.getClientUrl().node,
|
|
894
|
+
chainId: this.getChainId(),
|
|
895
|
+
})];
|
|
876
896
|
case 2:
|
|
877
897
|
unsignedStdTx = _k.sent();
|
|
878
898
|
privateKey = this.getPrivKey(walletIndex);
|
|
@@ -1011,4 +1031,4 @@ var Client = /** @class */ (function () {
|
|
|
1011
1031
|
return Client;
|
|
1012
1032
|
}());
|
|
1013
1033
|
|
|
1014
|
-
export { Client, DECIMAL, DEFAULT_GAS_VALUE, DEPOSIT_GAS_VALUE, MAX_TX_COUNT, MsgNativeTx, assetFromDenom, buildDepositTx, getBalance,
|
|
1034
|
+
export { Client, DECIMAL, DEFAULT_GAS_VALUE, DEPOSIT_GAS_VALUE, MAX_TX_COUNT, MsgNativeTx, assetFromDenom, buildDepositTx, getBalance, getDefaultClientUrl, getDefaultExplorerUrls, getDefaultFees, getDenom, getDepositTxDataFromLogs, getExplorerAddressUrl, getExplorerTxUrl, getExplorerUrl, getPrefix, getTxType, isAssetRuneNative, isBroadcastSuccess, isMsgMultiSend, isMsgSend, msgNativeTxFromJson, registerCodecs };
|
package/lib/index.js
CHANGED
|
@@ -123,7 +123,7 @@ var msgNativeTxFromJson = function (value) {
|
|
|
123
123
|
};
|
|
124
124
|
|
|
125
125
|
var DECIMAL = 8;
|
|
126
|
-
var DEFAULT_GAS_VALUE = '
|
|
126
|
+
var DEFAULT_GAS_VALUE = '3000000';
|
|
127
127
|
var DEPOSIT_GAS_VALUE = '500000000';
|
|
128
128
|
var MAX_TX_COUNT = 100;
|
|
129
129
|
/**
|
|
@@ -206,23 +206,6 @@ var getPrefix = function (network) {
|
|
|
206
206
|
return 'tthor';
|
|
207
207
|
}
|
|
208
208
|
};
|
|
209
|
-
/**
|
|
210
|
-
* Get the chain id.
|
|
211
|
-
*
|
|
212
|
-
* @param {Network} network
|
|
213
|
-
* @returns {string} The chain id based on the network.
|
|
214
|
-
*
|
|
215
|
-
*/
|
|
216
|
-
var getChainId = function (network) {
|
|
217
|
-
switch (network) {
|
|
218
|
-
case xchainClient.Network.Mainnet:
|
|
219
|
-
return 'thorchain';
|
|
220
|
-
case xchainClient.Network.Stagenet:
|
|
221
|
-
return 'thorchain-stagenet';
|
|
222
|
-
case xchainClient.Network.Testnet:
|
|
223
|
-
return 'thorchain';
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
209
|
/**
|
|
227
210
|
* Register Codecs based on the prefix.
|
|
228
211
|
*
|
|
@@ -300,46 +283,52 @@ var getTxType = function (txData, encoding) {
|
|
|
300
283
|
/**
|
|
301
284
|
* Structure StdTx from MsgNativeTx.
|
|
302
285
|
*
|
|
303
|
-
* @param {
|
|
286
|
+
* @param {MsgNativeTx} msgNativeTx Msg of type `MsgNativeTx`.
|
|
287
|
+
* @param {string} nodeUrl Node url
|
|
288
|
+
* @param {chainId} ChainId Chain id of the network
|
|
289
|
+
*
|
|
304
290
|
* @returns {Tx} The transaction details of the given transaction id.
|
|
305
291
|
*
|
|
306
292
|
* @throws {"Invalid client url"} Thrown if the client url is an invalid one.
|
|
307
293
|
*/
|
|
308
|
-
var buildDepositTx = function (
|
|
309
|
-
var
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
294
|
+
var buildDepositTx = function (_a) {
|
|
295
|
+
var msgNativeTx = _a.msgNativeTx, nodeUrl = _a.nodeUrl, chainId = _a.chainId;
|
|
296
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
297
|
+
var data, networkChainId, response, fee, unsignedStdTx;
|
|
298
|
+
var _b, _c;
|
|
299
|
+
return __generator(this, function (_d) {
|
|
300
|
+
switch (_d.label) {
|
|
301
|
+
case 0: return [4 /*yield*/, axios__default['default'].get(nodeUrl + "/cosmos/base/tendermint/v1beta1/node_info")];
|
|
302
|
+
case 1:
|
|
303
|
+
data = (_d.sent()).data;
|
|
304
|
+
networkChainId = data.default_node_info.network;
|
|
305
|
+
if (!networkChainId || chainId !== networkChainId)
|
|
306
|
+
throw new Error("Invalid network (asked: " + chainId + " / returned: " + networkChainId);
|
|
307
|
+
return [4 /*yield*/, axios__default['default'].post(nodeUrl + "/thorchain/deposit", {
|
|
308
|
+
coins: msgNativeTx.coins,
|
|
309
|
+
memo: msgNativeTx.memo,
|
|
310
|
+
base_req: {
|
|
311
|
+
chain_id: chainId,
|
|
312
|
+
from: msgNativeTx.signer,
|
|
313
|
+
},
|
|
314
|
+
})];
|
|
315
|
+
case 2:
|
|
316
|
+
response = (_d.sent()).data;
|
|
317
|
+
if (!response || !response.value)
|
|
318
|
+
throw new Error('Invalid client url');
|
|
319
|
+
fee = (_c = (_b = response.value) === null || _b === void 0 ? void 0 : _b.fee) !== null && _c !== void 0 ? _c : { amount: [] };
|
|
320
|
+
unsignedStdTx = auth.StdTx.fromJSON({
|
|
321
|
+
msg: response.value.msg,
|
|
322
|
+
// override fee
|
|
323
|
+
fee: __assign(__assign({}, fee), { gas: DEPOSIT_GAS_VALUE }),
|
|
324
|
+
signatures: [],
|
|
325
|
+
memo: '',
|
|
326
|
+
});
|
|
327
|
+
return [2 /*return*/, unsignedStdTx];
|
|
328
|
+
}
|
|
329
|
+
});
|
|
341
330
|
});
|
|
342
|
-
}
|
|
331
|
+
};
|
|
343
332
|
/**
|
|
344
333
|
* Get the balance of a given address.
|
|
345
334
|
*
|
|
@@ -488,13 +477,17 @@ var Client = /** @class */ (function () {
|
|
|
488
477
|
* @throws {"Invalid phrase"} Thrown if the given phase is invalid.
|
|
489
478
|
*/
|
|
490
479
|
function Client(_a) {
|
|
491
|
-
var _b;
|
|
480
|
+
var _b, _c;
|
|
492
481
|
var _this = this;
|
|
493
|
-
var
|
|
482
|
+
var _d = _a.network, network = _d === void 0 ? xchainClient.Network.Testnet : _d, phrase = _a.phrase, clientUrl = _a.clientUrl, explorerUrls = _a.explorerUrls, _e = _a.rootDerivationPaths, rootDerivationPaths = _e === void 0 ? (_b = {},
|
|
494
483
|
_b[xchainClient.Network.Mainnet] = "44'/931'/0'/0/",
|
|
495
484
|
_b[xchainClient.Network.Stagenet] = "44'/931'/0'/0/",
|
|
496
485
|
_b[xchainClient.Network.Testnet] = "44'/931'/0'/0/",
|
|
497
|
-
_b) :
|
|
486
|
+
_b) : _e, _f = _a.chainIds, chainIds = _f === void 0 ? (_c = {},
|
|
487
|
+
_c[xchainClient.Network.Mainnet] = 'thorchain',
|
|
488
|
+
_c[xchainClient.Network.Stagenet] = 'thorchain-stagenet',
|
|
489
|
+
_c[xchainClient.Network.Testnet] = 'thorchain-v1',
|
|
490
|
+
_c) : _f;
|
|
498
491
|
this.phrase = '';
|
|
499
492
|
/**
|
|
500
493
|
* Get transaction history of a given address with pagination options.
|
|
@@ -564,10 +557,11 @@ var Client = /** @class */ (function () {
|
|
|
564
557
|
this.network = network;
|
|
565
558
|
this.clientUrl = clientUrl || getDefaultClientUrl();
|
|
566
559
|
this.explorerUrls = explorerUrls || getDefaultExplorerUrls();
|
|
560
|
+
this.chainIds = chainIds;
|
|
567
561
|
this.rootDerivationPaths = rootDerivationPaths;
|
|
568
562
|
this.cosmosClient = new xchainCosmos.CosmosSDKClient({
|
|
569
563
|
server: this.getClientUrl().node,
|
|
570
|
-
chainId: getChainId(this.network),
|
|
564
|
+
chainId: this.getChainId(this.network),
|
|
571
565
|
prefix: getPrefix(this.network),
|
|
572
566
|
});
|
|
573
567
|
if (phrase)
|
|
@@ -639,6 +633,28 @@ var Client = /** @class */ (function () {
|
|
|
639
633
|
Client.prototype.getExplorerUrl = function () {
|
|
640
634
|
return this.explorerUrls.root[this.network];
|
|
641
635
|
};
|
|
636
|
+
/**
|
|
637
|
+
* Sets chain id
|
|
638
|
+
*
|
|
639
|
+
* @param {ChainId} chainId Chain id to update
|
|
640
|
+
* @param {Network} network (optional) Network for given chainId. If `network`not set, current network of the client is used
|
|
641
|
+
*
|
|
642
|
+
* @returns {void}
|
|
643
|
+
*/
|
|
644
|
+
Client.prototype.setChainId = function (chainId, network) {
|
|
645
|
+
var _a;
|
|
646
|
+
this.chainIds = __assign(__assign({}, this.chainIds), (_a = {}, _a[network || this.network] = chainId, _a));
|
|
647
|
+
};
|
|
648
|
+
/**
|
|
649
|
+
* Gets chain id
|
|
650
|
+
*
|
|
651
|
+
* @param {Network} network (optional) Network to get chain id from. If `network`not set, current network of the client is used
|
|
652
|
+
*
|
|
653
|
+
* @returns {ChainId} Chain id based on the current network.
|
|
654
|
+
*/
|
|
655
|
+
Client.prototype.getChainId = function (network) {
|
|
656
|
+
return this.chainIds[network || this.network];
|
|
657
|
+
};
|
|
642
658
|
/**
|
|
643
659
|
* Get cosmos client
|
|
644
660
|
* @returns {CosmosSDKClient} current cosmos client
|
|
@@ -880,7 +896,11 @@ var Client = /** @class */ (function () {
|
|
|
880
896
|
memo: memo,
|
|
881
897
|
signer: signer,
|
|
882
898
|
});
|
|
883
|
-
return [4 /*yield*/, buildDepositTx(
|
|
899
|
+
return [4 /*yield*/, buildDepositTx({
|
|
900
|
+
msgNativeTx: msgNativeTx,
|
|
901
|
+
nodeUrl: this.getClientUrl().node,
|
|
902
|
+
chainId: this.getChainId(),
|
|
903
|
+
})];
|
|
884
904
|
case 2:
|
|
885
905
|
unsignedStdTx = _k.sent();
|
|
886
906
|
privateKey = this.getPrivKey(walletIndex);
|
|
@@ -1028,7 +1048,6 @@ exports.MsgNativeTx = MsgNativeTx;
|
|
|
1028
1048
|
exports.assetFromDenom = assetFromDenom;
|
|
1029
1049
|
exports.buildDepositTx = buildDepositTx;
|
|
1030
1050
|
exports.getBalance = getBalance;
|
|
1031
|
-
exports.getChainId = getChainId;
|
|
1032
1051
|
exports.getDefaultClientUrl = getDefaultClientUrl;
|
|
1033
1052
|
exports.getDefaultExplorerUrls = getDefaultExplorerUrls;
|
|
1034
1053
|
exports.getDefaultFees = getDefaultFees;
|
|
@@ -11,9 +11,12 @@ export declare type ExplorerUrls = {
|
|
|
11
11
|
address: ExplorerUrl;
|
|
12
12
|
};
|
|
13
13
|
export declare type ExplorerUrl = Record<Network, string>;
|
|
14
|
+
export declare type ChainId = string;
|
|
15
|
+
export declare type ChainIds = Record<Network, ChainId>;
|
|
14
16
|
export declare type ThorchainClientParams = {
|
|
15
17
|
clientUrl?: ClientUrl;
|
|
16
18
|
explorerUrls?: ExplorerUrls;
|
|
19
|
+
chainIds?: ChainIds;
|
|
17
20
|
};
|
|
18
21
|
export declare type DepositParam = {
|
|
19
22
|
walletIndex?: number;
|
package/lib/util.d.ts
CHANGED
|
@@ -4,10 +4,10 @@ import { Asset } from '@xchainjs/xchain-util';
|
|
|
4
4
|
import { Msg } from 'cosmos-client';
|
|
5
5
|
import { StdTx } from 'cosmos-client/x/auth';
|
|
6
6
|
import { MsgMultiSend, MsgSend } from 'cosmos-client/x/bank';
|
|
7
|
-
import { ClientUrl, ExplorerUrls, TxData } from './types';
|
|
7
|
+
import { ChainId, ClientUrl, ExplorerUrls, TxData } from './types';
|
|
8
8
|
import { MsgNativeTx } from './types/messages';
|
|
9
9
|
export declare const DECIMAL = 8;
|
|
10
|
-
export declare const DEFAULT_GAS_VALUE = "
|
|
10
|
+
export declare const DEFAULT_GAS_VALUE = "3000000";
|
|
11
11
|
export declare const DEPOSIT_GAS_VALUE = "500000000";
|
|
12
12
|
export declare const MAX_TX_COUNT = 100;
|
|
13
13
|
/**
|
|
@@ -60,14 +60,6 @@ export declare const isBroadcastSuccess: (response: unknown) => boolean;
|
|
|
60
60
|
*
|
|
61
61
|
**/
|
|
62
62
|
export declare const getPrefix: (network: Network) => "thor" | "sthor" | "tthor";
|
|
63
|
-
/**
|
|
64
|
-
* Get the chain id.
|
|
65
|
-
*
|
|
66
|
-
* @param {Network} network
|
|
67
|
-
* @returns {string} The chain id based on the network.
|
|
68
|
-
*
|
|
69
|
-
*/
|
|
70
|
-
export declare const getChainId: (network: Network) => "thorchain" | "thorchain-stagenet";
|
|
71
63
|
/**
|
|
72
64
|
* Register Codecs based on the prefix.
|
|
73
65
|
*
|
|
@@ -99,12 +91,19 @@ export declare const getTxType: (txData: string, encoding: 'base64' | 'hex') =>
|
|
|
99
91
|
/**
|
|
100
92
|
* Structure StdTx from MsgNativeTx.
|
|
101
93
|
*
|
|
102
|
-
* @param {
|
|
94
|
+
* @param {MsgNativeTx} msgNativeTx Msg of type `MsgNativeTx`.
|
|
95
|
+
* @param {string} nodeUrl Node url
|
|
96
|
+
* @param {chainId} ChainId Chain id of the network
|
|
97
|
+
*
|
|
103
98
|
* @returns {Tx} The transaction details of the given transaction id.
|
|
104
99
|
*
|
|
105
100
|
* @throws {"Invalid client url"} Thrown if the client url is an invalid one.
|
|
106
101
|
*/
|
|
107
|
-
export declare const buildDepositTx: (msgNativeTx
|
|
102
|
+
export declare const buildDepositTx: ({ msgNativeTx, nodeUrl, chainId, }: {
|
|
103
|
+
msgNativeTx: MsgNativeTx;
|
|
104
|
+
nodeUrl: string;
|
|
105
|
+
chainId: ChainId;
|
|
106
|
+
}) => Promise<StdTx>;
|
|
108
107
|
/**
|
|
109
108
|
* Get the balance of a given address.
|
|
110
109
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-thorchain",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.1",
|
|
4
4
|
"description": "Custom Thorchain client and utilities used by XChainJS clients",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"THORChain",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/big.js": "^6.0.0",
|
|
36
|
-
"@xchainjs/xchain-client": "^0.11.
|
|
37
|
-
"@xchainjs/xchain-cosmos": "^0.16.
|
|
36
|
+
"@xchainjs/xchain-client": "^0.11.1",
|
|
37
|
+
"@xchainjs/xchain-cosmos": "^0.16.1",
|
|
38
38
|
"@xchainjs/xchain-crypto": "^0.2.4",
|
|
39
|
-
"@xchainjs/xchain-util": "^0.5.
|
|
40
|
-
"axios": "^0.
|
|
39
|
+
"@xchainjs/xchain-util": "^0.5.1",
|
|
40
|
+
"axios": "^0.25.0",
|
|
41
41
|
"cosmos-client": "0.39.2",
|
|
42
42
|
"nock": "^13.0.5"
|
|
43
43
|
},
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@xchainjs/xchain-client": "^0.11.
|
|
49
|
-
"@xchainjs/xchain-cosmos": "^0.16.
|
|
48
|
+
"@xchainjs/xchain-client": "^0.11.1",
|
|
49
|
+
"@xchainjs/xchain-cosmos": "^0.16.1",
|
|
50
50
|
"@xchainjs/xchain-crypto": "^0.2.4",
|
|
51
|
-
"@xchainjs/xchain-util": "^0.5.
|
|
52
|
-
"axios": "^0.
|
|
51
|
+
"@xchainjs/xchain-util": "^0.5.1",
|
|
52
|
+
"axios": "^0.25.0",
|
|
53
53
|
"cosmos-client": "0.39.2"
|
|
54
54
|
}
|
|
55
55
|
}
|