@xchainjs/xchain-thorchain 0.19.3 → 0.20.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 +28 -0
- package/README.md +11 -1
- package/lib/client.d.ts +24 -4
- package/lib/index.esm.js +104 -17
- package/lib/index.js +104 -17
- package/lib/util.d.ts +4 -2
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
# v0.20.1 (2022-01-11)
|
|
2
|
+
|
|
3
|
+
## Fix
|
|
4
|
+
|
|
5
|
+
- Get chain ID from THORNode before posting to deposit handler.
|
|
6
|
+
|
|
7
|
+
# v.0.20.0 (2021-12-29)
|
|
8
|
+
|
|
9
|
+
## Breaking change
|
|
10
|
+
|
|
11
|
+
- Add stagenet environment handling for `Network` and `BaseXChainClient` to client
|
|
12
|
+
|
|
13
|
+
# v.0.19.5 (2021-11-22)
|
|
14
|
+
|
|
15
|
+
## Add
|
|
16
|
+
|
|
17
|
+
- Provide `transferOffline` method
|
|
18
|
+
|
|
19
|
+
# v.0.19.4 (2021-11-22)
|
|
20
|
+
|
|
21
|
+
## Add
|
|
22
|
+
|
|
23
|
+
- Provide `getPubKey` method to access public key
|
|
24
|
+
|
|
25
|
+
## Change
|
|
26
|
+
|
|
27
|
+
- Make `getPrivKey` method `public` to access private key
|
|
28
|
+
|
|
1
29
|
# v.0.19.3 (2021-10-31)
|
|
2
30
|
|
|
3
31
|
## Update
|
package/README.md
CHANGED
|
@@ -48,7 +48,17 @@ const client = new Client({ network: Network.Testnet, phrase: 'my secret phrase'
|
|
|
48
48
|
|
|
49
49
|
// get address
|
|
50
50
|
const address = client.getAddress()
|
|
51
|
-
console.log('address:',
|
|
51
|
+
console.log('address:', address) // address: tthor13gym97tmw3axj3hpewdggy2cr288d3qffr8skg
|
|
52
|
+
|
|
53
|
+
// get private key
|
|
54
|
+
const privKey = client.getPrivKey()
|
|
55
|
+
console.log('privKey:', privKey.toBase64()) // privKey: {your-private-key} base64 encoded
|
|
56
|
+
console.log('privKey:', privKey.toBuffer()) // privKey: {your-private-key} as `Buffer`
|
|
57
|
+
|
|
58
|
+
// get public key
|
|
59
|
+
const pubKey = client.getPubKey()
|
|
60
|
+
console.log('pubKey:', pubKey.toBase64()) // pubKey: {your-public-key} base64 encoded
|
|
61
|
+
console.log('pubKey:', pubKey.toBuffer()) // pubKey: {your-public-key} as `Buffer`
|
|
52
62
|
|
|
53
63
|
// get balances
|
|
54
64
|
const balances = await client.getBalance(address)
|
package/lib/client.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Address, Balance, Fees, Network, Tx, TxHash, TxHistoryParams, TxParams, TxsPage, XChainClient, XChainClientParams } from '@xchainjs/xchain-client';
|
|
2
|
-
import { CosmosSDKClient, RPCTxResult } from '@xchainjs/xchain-cosmos';
|
|
2
|
+
import { CosmosSDKClient, RPCTxResult, TxOfflineParams } from '@xchainjs/xchain-cosmos';
|
|
3
3
|
import { Asset } from '@xchainjs/xchain-util';
|
|
4
|
+
import { PrivKey, PubKey } from 'cosmos-client';
|
|
5
|
+
import { StdTx } from 'cosmos-client/x/auth';
|
|
4
6
|
import { ClientUrl, DepositParam, ExplorerUrls, NodeUrl, ThorchainClientParams } from './types';
|
|
5
7
|
/**
|
|
6
8
|
* Interface for custom Thorchain client
|
|
@@ -118,15 +120,26 @@ declare class Client implements ThorchainClient, XChainClient {
|
|
|
118
120
|
*/
|
|
119
121
|
getFullDerivationPath(index: number): string;
|
|
120
122
|
/**
|
|
121
|
-
*
|
|
122
|
-
* Get private key.
|
|
123
|
+
* Get private key
|
|
123
124
|
*
|
|
125
|
+
* @param {number} index the HD wallet index (optional)
|
|
124
126
|
* @returns {PrivKey} The private key generated from the given phrase
|
|
125
127
|
*
|
|
126
128
|
* @throws {"Phrase not set"}
|
|
127
129
|
* Throws an error if phrase has not been set before
|
|
128
130
|
* */
|
|
129
|
-
|
|
131
|
+
getPrivKey(index?: number): PrivKey;
|
|
132
|
+
/**
|
|
133
|
+
* Get public key
|
|
134
|
+
*
|
|
135
|
+
* @param {number} index the HD wallet index (optional)
|
|
136
|
+
*
|
|
137
|
+
* @returns {PubKey} The public key generated from the given phrase
|
|
138
|
+
*
|
|
139
|
+
* @throws {"Phrase not set"}
|
|
140
|
+
* Throws an error if phrase has not been set before
|
|
141
|
+
**/
|
|
142
|
+
getPubKey(index?: number): PubKey;
|
|
130
143
|
/**
|
|
131
144
|
* Get the current address.
|
|
132
145
|
*
|
|
@@ -193,6 +206,13 @@ declare class Client implements ThorchainClient, XChainClient {
|
|
|
193
206
|
* @returns {TxHash} The transaction hash.
|
|
194
207
|
*/
|
|
195
208
|
transfer({ walletIndex, asset, amount, recipient, memo }: TxParams): Promise<TxHash>;
|
|
209
|
+
/**
|
|
210
|
+
* Transfer without broadcast balances with MsgSend
|
|
211
|
+
*
|
|
212
|
+
* @param {TxOfflineParams} params The transfer offline options.
|
|
213
|
+
* @returns {StdTx} The signed transaction.
|
|
214
|
+
*/
|
|
215
|
+
transferOffline({ walletIndex, asset, amount, recipient, memo, from_balance, from_account_number, from_sequence, }: TxOfflineParams): Promise<StdTx>;
|
|
196
216
|
/**
|
|
197
217
|
* Get the fees.
|
|
198
218
|
*
|
package/lib/index.esm.js
CHANGED
|
@@ -191,6 +191,8 @@ var getPrefix = function (network) {
|
|
|
191
191
|
switch (network) {
|
|
192
192
|
case Network.Mainnet:
|
|
193
193
|
return 'thor';
|
|
194
|
+
case Network.Stagenet:
|
|
195
|
+
return 'sthor';
|
|
194
196
|
case Network.Testnet:
|
|
195
197
|
return 'tthor';
|
|
196
198
|
}
|
|
@@ -198,9 +200,20 @@ var getPrefix = function (network) {
|
|
|
198
200
|
/**
|
|
199
201
|
* Get the chain id.
|
|
200
202
|
*
|
|
203
|
+
* @param {Network} network
|
|
201
204
|
* @returns {string} The chain id based on the network.
|
|
205
|
+
*
|
|
202
206
|
*/
|
|
203
|
-
var getChainId = function () {
|
|
207
|
+
var getChainId = function (network) {
|
|
208
|
+
switch (network) {
|
|
209
|
+
case Network.Mainnet:
|
|
210
|
+
return 'thorchain';
|
|
211
|
+
case Network.Stagenet:
|
|
212
|
+
return 'thorchain-stagenet';
|
|
213
|
+
case Network.Testnet:
|
|
214
|
+
return 'thorchain';
|
|
215
|
+
}
|
|
216
|
+
};
|
|
204
217
|
/**
|
|
205
218
|
* Register Codecs based on the prefix.
|
|
206
219
|
*
|
|
@@ -284,19 +297,25 @@ var getTxType = function (txData, encoding) {
|
|
|
284
297
|
* @throws {"Invalid client url"} Thrown if the client url is an invalid one.
|
|
285
298
|
*/
|
|
286
299
|
var buildDepositTx = function (msgNativeTx, nodeUrl) { return __awaiter(void 0, void 0, void 0, function () {
|
|
287
|
-
var response, fee, unsignedStdTx;
|
|
300
|
+
var data, chainId, response, fee, unsignedStdTx;
|
|
288
301
|
var _a, _b;
|
|
289
302
|
return __generator(this, function (_c) {
|
|
290
303
|
switch (_c.label) {
|
|
291
|
-
case 0: return [4 /*yield*/, axios.
|
|
292
|
-
coins: msgNativeTx.coins,
|
|
293
|
-
memo: msgNativeTx.memo,
|
|
294
|
-
base_req: {
|
|
295
|
-
chain_id: getChainId(),
|
|
296
|
-
from: msgNativeTx.signer,
|
|
297
|
-
},
|
|
298
|
-
})];
|
|
304
|
+
case 0: return [4 /*yield*/, axios.get(nodeUrl + "/cosmos/base/tendermint/v1beta1/node_info")];
|
|
299
305
|
case 1:
|
|
306
|
+
data = (_c.sent()).data;
|
|
307
|
+
chainId = data.default_node_info.network;
|
|
308
|
+
if (!chainId || !(chainId == 'thorchain' || chainId == 'thorchain-stagenet'))
|
|
309
|
+
throw new Error('invalid network');
|
|
310
|
+
return [4 /*yield*/, axios.post(nodeUrl + "/thorchain/deposit", {
|
|
311
|
+
coins: msgNativeTx.coins,
|
|
312
|
+
memo: msgNativeTx.memo,
|
|
313
|
+
base_req: {
|
|
314
|
+
chain_id: chainId,
|
|
315
|
+
from: msgNativeTx.signer,
|
|
316
|
+
},
|
|
317
|
+
})];
|
|
318
|
+
case 2:
|
|
300
319
|
response = (_c.sent()).data;
|
|
301
320
|
if (!response || !response.value)
|
|
302
321
|
throw new Error('Invalid client url');
|
|
@@ -352,8 +371,12 @@ var getDefaultClientUrl = function () {
|
|
|
352
371
|
node: 'https://testnet.thornode.thorchain.info',
|
|
353
372
|
rpc: 'https://testnet.rpc.thorchain.info',
|
|
354
373
|
},
|
|
374
|
+
_a[Network.Stagenet] = {
|
|
375
|
+
node: 'https://stagenet-thornode.ninerealms.com',
|
|
376
|
+
rpc: 'https://stagenet-rpc.ninerealms.com',
|
|
377
|
+
},
|
|
355
378
|
_a[Network.Mainnet] = {
|
|
356
|
-
node: 'https://thornode.
|
|
379
|
+
node: 'https://thornode.ninerealms.com',
|
|
357
380
|
rpc: 'https://rpc.thorchain.info',
|
|
358
381
|
},
|
|
359
382
|
_a;
|
|
@@ -368,16 +391,19 @@ var getDefaultExplorerUrls = function () {
|
|
|
368
391
|
var _a, _b, _c;
|
|
369
392
|
var root = (_a = {},
|
|
370
393
|
_a[Network.Testnet] = DEFAULT_EXPLORER_URL + "?network=testnet",
|
|
394
|
+
_a[Network.Stagenet] = DEFAULT_EXPLORER_URL + "?network=stagenet",
|
|
371
395
|
_a[Network.Mainnet] = DEFAULT_EXPLORER_URL,
|
|
372
396
|
_a);
|
|
373
397
|
var txUrl = DEFAULT_EXPLORER_URL + "/tx";
|
|
374
398
|
var tx = (_b = {},
|
|
375
399
|
_b[Network.Testnet] = txUrl,
|
|
400
|
+
_b[Network.Stagenet] = txUrl,
|
|
376
401
|
_b[Network.Mainnet] = txUrl,
|
|
377
402
|
_b);
|
|
378
403
|
var addressUrl = DEFAULT_EXPLORER_URL + "/address";
|
|
379
404
|
var address = (_c = {},
|
|
380
405
|
_c[Network.Testnet] = addressUrl,
|
|
406
|
+
_c[Network.Stagenet] = addressUrl,
|
|
381
407
|
_c[Network.Mainnet] = addressUrl,
|
|
382
408
|
_c);
|
|
383
409
|
return {
|
|
@@ -411,6 +437,8 @@ var getExplorerAddressUrl = function (_a) {
|
|
|
411
437
|
switch (network) {
|
|
412
438
|
case Network.Mainnet:
|
|
413
439
|
return url;
|
|
440
|
+
case Network.Stagenet:
|
|
441
|
+
return url + "?network=stagenet";
|
|
414
442
|
case Network.Testnet:
|
|
415
443
|
return url + "?network=testnet";
|
|
416
444
|
}
|
|
@@ -429,6 +457,8 @@ var getExplorerTxUrl = function (_a) {
|
|
|
429
457
|
switch (network) {
|
|
430
458
|
case Network.Mainnet:
|
|
431
459
|
return url;
|
|
460
|
+
case Network.Stagenet:
|
|
461
|
+
return url + "?network=stagenet";
|
|
432
462
|
case Network.Testnet:
|
|
433
463
|
return url + "?network=testnet";
|
|
434
464
|
}
|
|
@@ -453,6 +483,7 @@ var Client = /** @class */ (function () {
|
|
|
453
483
|
var _this = this;
|
|
454
484
|
var _c = _a.network, network = _c === void 0 ? Network.Testnet : _c, phrase = _a.phrase, clientUrl = _a.clientUrl, explorerUrls = _a.explorerUrls, _d = _a.rootDerivationPaths, rootDerivationPaths = _d === void 0 ? (_b = {},
|
|
455
485
|
_b[Network.Mainnet] = "44'/931'/0'/0/",
|
|
486
|
+
_b[Network.Stagenet] = "44'/931'/0'/0/",
|
|
456
487
|
_b[Network.Testnet] = "44'/931'/0'/0/",
|
|
457
488
|
_b) : _d;
|
|
458
489
|
this.phrase = '';
|
|
@@ -527,7 +558,7 @@ var Client = /** @class */ (function () {
|
|
|
527
558
|
this.rootDerivationPaths = rootDerivationPaths;
|
|
528
559
|
this.cosmosClient = new CosmosSDKClient({
|
|
529
560
|
server: this.getClientUrl().node,
|
|
530
|
-
chainId: getChainId(),
|
|
561
|
+
chainId: getChainId(this.network),
|
|
531
562
|
prefix: getPrefix(this.network),
|
|
532
563
|
});
|
|
533
564
|
if (phrase)
|
|
@@ -653,18 +684,32 @@ var Client = /** @class */ (function () {
|
|
|
653
684
|
return this.rootDerivationPaths[this.network] + ("" + index);
|
|
654
685
|
};
|
|
655
686
|
/**
|
|
656
|
-
*
|
|
657
|
-
* Get private key.
|
|
687
|
+
* Get private key
|
|
658
688
|
*
|
|
689
|
+
* @param {number} index the HD wallet index (optional)
|
|
659
690
|
* @returns {PrivKey} The private key generated from the given phrase
|
|
660
691
|
*
|
|
661
692
|
* @throws {"Phrase not set"}
|
|
662
693
|
* Throws an error if phrase has not been set before
|
|
663
694
|
* */
|
|
664
|
-
Client.prototype.
|
|
695
|
+
Client.prototype.getPrivKey = function (index) {
|
|
665
696
|
if (index === void 0) { index = 0; }
|
|
666
697
|
return this.cosmosClient.getPrivKeyFromMnemonic(this.phrase, this.getFullDerivationPath(index));
|
|
667
698
|
};
|
|
699
|
+
/**
|
|
700
|
+
* Get public key
|
|
701
|
+
*
|
|
702
|
+
* @param {number} index the HD wallet index (optional)
|
|
703
|
+
*
|
|
704
|
+
* @returns {PubKey} The public key generated from the given phrase
|
|
705
|
+
*
|
|
706
|
+
* @throws {"Phrase not set"}
|
|
707
|
+
* Throws an error if phrase has not been set before
|
|
708
|
+
**/
|
|
709
|
+
Client.prototype.getPubKey = function (index) {
|
|
710
|
+
if (index === void 0) { index = 0; }
|
|
711
|
+
return this.getPrivKey(index).getPubKey();
|
|
712
|
+
};
|
|
668
713
|
/**
|
|
669
714
|
* Get the current address.
|
|
670
715
|
*
|
|
@@ -811,7 +856,7 @@ var Client = /** @class */ (function () {
|
|
|
811
856
|
return [4 /*yield*/, buildDepositTx(msgNativeTx, this.getClientUrl().node)];
|
|
812
857
|
case 2:
|
|
813
858
|
unsignedStdTx = _f.sent();
|
|
814
|
-
privateKey = this.
|
|
859
|
+
privateKey = this.getPrivKey(walletIndex);
|
|
815
860
|
accAddress = AccAddress.fromBech32(signer);
|
|
816
861
|
return [4 /*yield*/, this.cosmosClient.signAndBroadcast(unsignedStdTx, privateKey, accAddress)];
|
|
817
862
|
case 3: return [2 /*return*/, (_c = (_b = (_f.sent())) === null || _b === void 0 ? void 0 : _b.txhash) !== null && _c !== void 0 ? _c : ''];
|
|
@@ -844,7 +889,7 @@ var Client = /** @class */ (function () {
|
|
|
844
889
|
throw new Error('insufficient funds');
|
|
845
890
|
}
|
|
846
891
|
return [4 /*yield*/, this.cosmosClient.transfer({
|
|
847
|
-
privkey: this.
|
|
892
|
+
privkey: this.getPrivKey(walletIndex),
|
|
848
893
|
from: this.getAddress(walletIndex),
|
|
849
894
|
to: recipient,
|
|
850
895
|
amount: amount.amount().toString(),
|
|
@@ -865,6 +910,48 @@ var Client = /** @class */ (function () {
|
|
|
865
910
|
});
|
|
866
911
|
});
|
|
867
912
|
};
|
|
913
|
+
/**
|
|
914
|
+
* Transfer without broadcast balances with MsgSend
|
|
915
|
+
*
|
|
916
|
+
* @param {TxOfflineParams} params The transfer offline options.
|
|
917
|
+
* @returns {StdTx} The signed transaction.
|
|
918
|
+
*/
|
|
919
|
+
Client.prototype.transferOffline = function (_a) {
|
|
920
|
+
var _b = _a.walletIndex, walletIndex = _b === void 0 ? 0 : _b, _c = _a.asset, asset = _c === void 0 ? AssetRuneNative : _c, amount = _a.amount, recipient = _a.recipient, memo = _a.memo, _d = _a.from_balance, from_balance = _d === void 0 ? baseAmount('0', DECIMAL) : _d, _e = _a.from_account_number, from_account_number = _e === void 0 ? '0' : _e, _f = _a.from_sequence, from_sequence = _f === void 0 ? '0' : _f;
|
|
921
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
922
|
+
var fee, result;
|
|
923
|
+
return __generator(this, function (_g) {
|
|
924
|
+
switch (_g.label) {
|
|
925
|
+
case 0:
|
|
926
|
+
registerCodecs(getPrefix(this.network));
|
|
927
|
+
return [4 /*yield*/, this.getFees()];
|
|
928
|
+
case 1:
|
|
929
|
+
fee = _g.sent();
|
|
930
|
+
if (from_balance === baseAmount('0', DECIMAL) ||
|
|
931
|
+
from_balance.amount().lt(amount.amount().plus(fee[FeeOption.Average].amount()))) {
|
|
932
|
+
throw new Error('insufficient funds');
|
|
933
|
+
}
|
|
934
|
+
return [4 /*yield*/, this.cosmosClient.transferSignedOffline({
|
|
935
|
+
privkey: this.getPrivKey(walletIndex),
|
|
936
|
+
from: this.getAddress(walletIndex),
|
|
937
|
+
from_account_number: from_account_number,
|
|
938
|
+
from_sequence: from_sequence,
|
|
939
|
+
to: recipient,
|
|
940
|
+
amount: amount.amount().toString(),
|
|
941
|
+
asset: getDenom(asset),
|
|
942
|
+
memo: memo,
|
|
943
|
+
fee: {
|
|
944
|
+
amount: [],
|
|
945
|
+
gas: DEFAULT_GAS_VALUE,
|
|
946
|
+
},
|
|
947
|
+
})];
|
|
948
|
+
case 2:
|
|
949
|
+
result = _g.sent();
|
|
950
|
+
return [2 /*return*/, JSON.parse(codec.toJSONString(result)).value];
|
|
951
|
+
}
|
|
952
|
+
});
|
|
953
|
+
});
|
|
954
|
+
};
|
|
868
955
|
/**
|
|
869
956
|
* Get the fees.
|
|
870
957
|
*
|
package/lib/index.js
CHANGED
|
@@ -199,6 +199,8 @@ var getPrefix = function (network) {
|
|
|
199
199
|
switch (network) {
|
|
200
200
|
case xchainClient.Network.Mainnet:
|
|
201
201
|
return 'thor';
|
|
202
|
+
case xchainClient.Network.Stagenet:
|
|
203
|
+
return 'sthor';
|
|
202
204
|
case xchainClient.Network.Testnet:
|
|
203
205
|
return 'tthor';
|
|
204
206
|
}
|
|
@@ -206,9 +208,20 @@ var getPrefix = function (network) {
|
|
|
206
208
|
/**
|
|
207
209
|
* Get the chain id.
|
|
208
210
|
*
|
|
211
|
+
* @param {Network} network
|
|
209
212
|
* @returns {string} The chain id based on the network.
|
|
213
|
+
*
|
|
210
214
|
*/
|
|
211
|
-
var getChainId = function () {
|
|
215
|
+
var getChainId = function (network) {
|
|
216
|
+
switch (network) {
|
|
217
|
+
case xchainClient.Network.Mainnet:
|
|
218
|
+
return 'thorchain';
|
|
219
|
+
case xchainClient.Network.Stagenet:
|
|
220
|
+
return 'thorchain-stagenet';
|
|
221
|
+
case xchainClient.Network.Testnet:
|
|
222
|
+
return 'thorchain';
|
|
223
|
+
}
|
|
224
|
+
};
|
|
212
225
|
/**
|
|
213
226
|
* Register Codecs based on the prefix.
|
|
214
227
|
*
|
|
@@ -292,19 +305,25 @@ var getTxType = function (txData, encoding) {
|
|
|
292
305
|
* @throws {"Invalid client url"} Thrown if the client url is an invalid one.
|
|
293
306
|
*/
|
|
294
307
|
var buildDepositTx = function (msgNativeTx, nodeUrl) { return __awaiter(void 0, void 0, void 0, function () {
|
|
295
|
-
var response, fee, unsignedStdTx;
|
|
308
|
+
var data, chainId, response, fee, unsignedStdTx;
|
|
296
309
|
var _a, _b;
|
|
297
310
|
return __generator(this, function (_c) {
|
|
298
311
|
switch (_c.label) {
|
|
299
|
-
case 0: return [4 /*yield*/, axios__default['default'].
|
|
300
|
-
coins: msgNativeTx.coins,
|
|
301
|
-
memo: msgNativeTx.memo,
|
|
302
|
-
base_req: {
|
|
303
|
-
chain_id: getChainId(),
|
|
304
|
-
from: msgNativeTx.signer,
|
|
305
|
-
},
|
|
306
|
-
})];
|
|
312
|
+
case 0: return [4 /*yield*/, axios__default['default'].get(nodeUrl + "/cosmos/base/tendermint/v1beta1/node_info")];
|
|
307
313
|
case 1:
|
|
314
|
+
data = (_c.sent()).data;
|
|
315
|
+
chainId = data.default_node_info.network;
|
|
316
|
+
if (!chainId || !(chainId == 'thorchain' || chainId == 'thorchain-stagenet'))
|
|
317
|
+
throw new Error('invalid network');
|
|
318
|
+
return [4 /*yield*/, axios__default['default'].post(nodeUrl + "/thorchain/deposit", {
|
|
319
|
+
coins: msgNativeTx.coins,
|
|
320
|
+
memo: msgNativeTx.memo,
|
|
321
|
+
base_req: {
|
|
322
|
+
chain_id: chainId,
|
|
323
|
+
from: msgNativeTx.signer,
|
|
324
|
+
},
|
|
325
|
+
})];
|
|
326
|
+
case 2:
|
|
308
327
|
response = (_c.sent()).data;
|
|
309
328
|
if (!response || !response.value)
|
|
310
329
|
throw new Error('Invalid client url');
|
|
@@ -360,8 +379,12 @@ var getDefaultClientUrl = function () {
|
|
|
360
379
|
node: 'https://testnet.thornode.thorchain.info',
|
|
361
380
|
rpc: 'https://testnet.rpc.thorchain.info',
|
|
362
381
|
},
|
|
382
|
+
_a[xchainClient.Network.Stagenet] = {
|
|
383
|
+
node: 'https://stagenet-thornode.ninerealms.com',
|
|
384
|
+
rpc: 'https://stagenet-rpc.ninerealms.com',
|
|
385
|
+
},
|
|
363
386
|
_a[xchainClient.Network.Mainnet] = {
|
|
364
|
-
node: 'https://thornode.
|
|
387
|
+
node: 'https://thornode.ninerealms.com',
|
|
365
388
|
rpc: 'https://rpc.thorchain.info',
|
|
366
389
|
},
|
|
367
390
|
_a;
|
|
@@ -376,16 +399,19 @@ var getDefaultExplorerUrls = function () {
|
|
|
376
399
|
var _a, _b, _c;
|
|
377
400
|
var root = (_a = {},
|
|
378
401
|
_a[xchainClient.Network.Testnet] = DEFAULT_EXPLORER_URL + "?network=testnet",
|
|
402
|
+
_a[xchainClient.Network.Stagenet] = DEFAULT_EXPLORER_URL + "?network=stagenet",
|
|
379
403
|
_a[xchainClient.Network.Mainnet] = DEFAULT_EXPLORER_URL,
|
|
380
404
|
_a);
|
|
381
405
|
var txUrl = DEFAULT_EXPLORER_URL + "/tx";
|
|
382
406
|
var tx = (_b = {},
|
|
383
407
|
_b[xchainClient.Network.Testnet] = txUrl,
|
|
408
|
+
_b[xchainClient.Network.Stagenet] = txUrl,
|
|
384
409
|
_b[xchainClient.Network.Mainnet] = txUrl,
|
|
385
410
|
_b);
|
|
386
411
|
var addressUrl = DEFAULT_EXPLORER_URL + "/address";
|
|
387
412
|
var address = (_c = {},
|
|
388
413
|
_c[xchainClient.Network.Testnet] = addressUrl,
|
|
414
|
+
_c[xchainClient.Network.Stagenet] = addressUrl,
|
|
389
415
|
_c[xchainClient.Network.Mainnet] = addressUrl,
|
|
390
416
|
_c);
|
|
391
417
|
return {
|
|
@@ -419,6 +445,8 @@ var getExplorerAddressUrl = function (_a) {
|
|
|
419
445
|
switch (network) {
|
|
420
446
|
case xchainClient.Network.Mainnet:
|
|
421
447
|
return url;
|
|
448
|
+
case xchainClient.Network.Stagenet:
|
|
449
|
+
return url + "?network=stagenet";
|
|
422
450
|
case xchainClient.Network.Testnet:
|
|
423
451
|
return url + "?network=testnet";
|
|
424
452
|
}
|
|
@@ -437,6 +465,8 @@ var getExplorerTxUrl = function (_a) {
|
|
|
437
465
|
switch (network) {
|
|
438
466
|
case xchainClient.Network.Mainnet:
|
|
439
467
|
return url;
|
|
468
|
+
case xchainClient.Network.Stagenet:
|
|
469
|
+
return url + "?network=stagenet";
|
|
440
470
|
case xchainClient.Network.Testnet:
|
|
441
471
|
return url + "?network=testnet";
|
|
442
472
|
}
|
|
@@ -461,6 +491,7 @@ var Client = /** @class */ (function () {
|
|
|
461
491
|
var _this = this;
|
|
462
492
|
var _c = _a.network, network = _c === void 0 ? xchainClient.Network.Testnet : _c, phrase = _a.phrase, clientUrl = _a.clientUrl, explorerUrls = _a.explorerUrls, _d = _a.rootDerivationPaths, rootDerivationPaths = _d === void 0 ? (_b = {},
|
|
463
493
|
_b[xchainClient.Network.Mainnet] = "44'/931'/0'/0/",
|
|
494
|
+
_b[xchainClient.Network.Stagenet] = "44'/931'/0'/0/",
|
|
464
495
|
_b[xchainClient.Network.Testnet] = "44'/931'/0'/0/",
|
|
465
496
|
_b) : _d;
|
|
466
497
|
this.phrase = '';
|
|
@@ -535,7 +566,7 @@ var Client = /** @class */ (function () {
|
|
|
535
566
|
this.rootDerivationPaths = rootDerivationPaths;
|
|
536
567
|
this.cosmosClient = new xchainCosmos.CosmosSDKClient({
|
|
537
568
|
server: this.getClientUrl().node,
|
|
538
|
-
chainId: getChainId(),
|
|
569
|
+
chainId: getChainId(this.network),
|
|
539
570
|
prefix: getPrefix(this.network),
|
|
540
571
|
});
|
|
541
572
|
if (phrase)
|
|
@@ -661,18 +692,32 @@ var Client = /** @class */ (function () {
|
|
|
661
692
|
return this.rootDerivationPaths[this.network] + ("" + index);
|
|
662
693
|
};
|
|
663
694
|
/**
|
|
664
|
-
*
|
|
665
|
-
* Get private key.
|
|
695
|
+
* Get private key
|
|
666
696
|
*
|
|
697
|
+
* @param {number} index the HD wallet index (optional)
|
|
667
698
|
* @returns {PrivKey} The private key generated from the given phrase
|
|
668
699
|
*
|
|
669
700
|
* @throws {"Phrase not set"}
|
|
670
701
|
* Throws an error if phrase has not been set before
|
|
671
702
|
* */
|
|
672
|
-
Client.prototype.
|
|
703
|
+
Client.prototype.getPrivKey = function (index) {
|
|
673
704
|
if (index === void 0) { index = 0; }
|
|
674
705
|
return this.cosmosClient.getPrivKeyFromMnemonic(this.phrase, this.getFullDerivationPath(index));
|
|
675
706
|
};
|
|
707
|
+
/**
|
|
708
|
+
* Get public key
|
|
709
|
+
*
|
|
710
|
+
* @param {number} index the HD wallet index (optional)
|
|
711
|
+
*
|
|
712
|
+
* @returns {PubKey} The public key generated from the given phrase
|
|
713
|
+
*
|
|
714
|
+
* @throws {"Phrase not set"}
|
|
715
|
+
* Throws an error if phrase has not been set before
|
|
716
|
+
**/
|
|
717
|
+
Client.prototype.getPubKey = function (index) {
|
|
718
|
+
if (index === void 0) { index = 0; }
|
|
719
|
+
return this.getPrivKey(index).getPubKey();
|
|
720
|
+
};
|
|
676
721
|
/**
|
|
677
722
|
* Get the current address.
|
|
678
723
|
*
|
|
@@ -819,7 +864,7 @@ var Client = /** @class */ (function () {
|
|
|
819
864
|
return [4 /*yield*/, buildDepositTx(msgNativeTx, this.getClientUrl().node)];
|
|
820
865
|
case 2:
|
|
821
866
|
unsignedStdTx = _f.sent();
|
|
822
|
-
privateKey = this.
|
|
867
|
+
privateKey = this.getPrivKey(walletIndex);
|
|
823
868
|
accAddress = cosmosClient.AccAddress.fromBech32(signer);
|
|
824
869
|
return [4 /*yield*/, this.cosmosClient.signAndBroadcast(unsignedStdTx, privateKey, accAddress)];
|
|
825
870
|
case 3: return [2 /*return*/, (_c = (_b = (_f.sent())) === null || _b === void 0 ? void 0 : _b.txhash) !== null && _c !== void 0 ? _c : ''];
|
|
@@ -852,7 +897,7 @@ var Client = /** @class */ (function () {
|
|
|
852
897
|
throw new Error('insufficient funds');
|
|
853
898
|
}
|
|
854
899
|
return [4 /*yield*/, this.cosmosClient.transfer({
|
|
855
|
-
privkey: this.
|
|
900
|
+
privkey: this.getPrivKey(walletIndex),
|
|
856
901
|
from: this.getAddress(walletIndex),
|
|
857
902
|
to: recipient,
|
|
858
903
|
amount: amount.amount().toString(),
|
|
@@ -873,6 +918,48 @@ var Client = /** @class */ (function () {
|
|
|
873
918
|
});
|
|
874
919
|
});
|
|
875
920
|
};
|
|
921
|
+
/**
|
|
922
|
+
* Transfer without broadcast balances with MsgSend
|
|
923
|
+
*
|
|
924
|
+
* @param {TxOfflineParams} params The transfer offline options.
|
|
925
|
+
* @returns {StdTx} The signed transaction.
|
|
926
|
+
*/
|
|
927
|
+
Client.prototype.transferOffline = function (_a) {
|
|
928
|
+
var _b = _a.walletIndex, walletIndex = _b === void 0 ? 0 : _b, _c = _a.asset, asset = _c === void 0 ? xchainUtil.AssetRuneNative : _c, amount = _a.amount, recipient = _a.recipient, memo = _a.memo, _d = _a.from_balance, from_balance = _d === void 0 ? xchainUtil.baseAmount('0', DECIMAL) : _d, _e = _a.from_account_number, from_account_number = _e === void 0 ? '0' : _e, _f = _a.from_sequence, from_sequence = _f === void 0 ? '0' : _f;
|
|
929
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
930
|
+
var fee, result;
|
|
931
|
+
return __generator(this, function (_g) {
|
|
932
|
+
switch (_g.label) {
|
|
933
|
+
case 0:
|
|
934
|
+
registerCodecs(getPrefix(this.network));
|
|
935
|
+
return [4 /*yield*/, this.getFees()];
|
|
936
|
+
case 1:
|
|
937
|
+
fee = _g.sent();
|
|
938
|
+
if (from_balance === xchainUtil.baseAmount('0', DECIMAL) ||
|
|
939
|
+
from_balance.amount().lt(amount.amount().plus(fee[xchainClient.FeeOption.Average].amount()))) {
|
|
940
|
+
throw new Error('insufficient funds');
|
|
941
|
+
}
|
|
942
|
+
return [4 /*yield*/, this.cosmosClient.transferSignedOffline({
|
|
943
|
+
privkey: this.getPrivKey(walletIndex),
|
|
944
|
+
from: this.getAddress(walletIndex),
|
|
945
|
+
from_account_number: from_account_number,
|
|
946
|
+
from_sequence: from_sequence,
|
|
947
|
+
to: recipient,
|
|
948
|
+
amount: amount.amount().toString(),
|
|
949
|
+
asset: getDenom(asset),
|
|
950
|
+
memo: memo,
|
|
951
|
+
fee: {
|
|
952
|
+
amount: [],
|
|
953
|
+
gas: DEFAULT_GAS_VALUE,
|
|
954
|
+
},
|
|
955
|
+
})];
|
|
956
|
+
case 2:
|
|
957
|
+
result = _g.sent();
|
|
958
|
+
return [2 /*return*/, JSON.parse(cosmosClient.codec.toJSONString(result)).value];
|
|
959
|
+
}
|
|
960
|
+
});
|
|
961
|
+
});
|
|
962
|
+
};
|
|
876
963
|
/**
|
|
877
964
|
* Get the fees.
|
|
878
965
|
*
|
package/lib/util.d.ts
CHANGED
|
@@ -59,13 +59,15 @@ export declare const isBroadcastSuccess: (response: unknown) => boolean;
|
|
|
59
59
|
* @returns {string} The address prefix based on the network.
|
|
60
60
|
*
|
|
61
61
|
**/
|
|
62
|
-
export declare const getPrefix: (network: Network) => "thor" | "tthor";
|
|
62
|
+
export declare const getPrefix: (network: Network) => "thor" | "sthor" | "tthor";
|
|
63
63
|
/**
|
|
64
64
|
* Get the chain id.
|
|
65
65
|
*
|
|
66
|
+
* @param {Network} network
|
|
66
67
|
* @returns {string} The chain id based on the network.
|
|
68
|
+
*
|
|
67
69
|
*/
|
|
68
|
-
export declare const getChainId: () =>
|
|
70
|
+
export declare const getChainId: (network: Network) => "thorchain" | "thorchain-stagenet";
|
|
69
71
|
/**
|
|
70
72
|
* Register Codecs based on the prefix.
|
|
71
73
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-thorchain",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.1",
|
|
4
4
|
"description": "Custom Thorchain client and utilities used by XChainJS clients",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"THORChain",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/big.js": "^6.0.0",
|
|
36
|
-
"@xchainjs/xchain-client": "^0.
|
|
37
|
-
"@xchainjs/xchain-cosmos": "^0.
|
|
36
|
+
"@xchainjs/xchain-client": "^0.11.0",
|
|
37
|
+
"@xchainjs/xchain-cosmos": "^0.15.0",
|
|
38
38
|
"@xchainjs/xchain-crypto": "^0.2.4",
|
|
39
39
|
"@xchainjs/xchain-util": "^0.3.0",
|
|
40
40
|
"axios": "^0.21.0",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@xchainjs/xchain-client": "^0.
|
|
49
|
-
"@xchainjs/xchain-cosmos": "^0.
|
|
48
|
+
"@xchainjs/xchain-client": "^0.11.0",
|
|
49
|
+
"@xchainjs/xchain-cosmos": "^0.15.0",
|
|
50
50
|
"@xchainjs/xchain-crypto": "^0.2.4",
|
|
51
51
|
"@xchainjs/xchain-util": "^0.3.0",
|
|
52
52
|
"axios": "^0.21.0",
|
|
53
53
|
"cosmos-client": "0.39.2"
|
|
54
54
|
}
|
|
55
|
-
}
|
|
55
|
+
}
|