@xchainjs/xchain-thorchain 0.22.2 → 0.23.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 +15 -0
- package/README.md +3 -1
- package/lib/index.esm.js +43 -12
- package/lib/index.js +44 -11
- package/lib/types/client-types.d.ts +10 -1
- package/lib/util.d.ts +11 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# v0.23.0 (2022-03-08)
|
|
2
|
+
|
|
3
|
+
## Add
|
|
4
|
+
|
|
5
|
+
- Helpers `getChainId` + `getChainIds`
|
|
6
|
+
|
|
7
|
+
## Breaking change
|
|
8
|
+
|
|
9
|
+
- `chainIds: ChainIds` is required to initialize `Client`
|
|
10
|
+
|
|
11
|
+
## Fix
|
|
12
|
+
|
|
13
|
+
- Request fees from THORChain and use `defaultFees` in case of server errors only
|
|
14
|
+
- Fix `defaultFees` to be 0.02 RUNE
|
|
15
|
+
|
|
1
16
|
# v0.22.2 (2022-02-17)
|
|
2
17
|
|
|
3
18
|
## Fix
|
package/README.md
CHANGED
|
@@ -44,7 +44,9 @@ Rate limits: No
|
|
|
44
44
|
import { Client } from '@xchainjs/xchain-thorchain'
|
|
45
45
|
|
|
46
46
|
// Create a `Client`
|
|
47
|
-
|
|
47
|
+
// Note: `chainIds` are required
|
|
48
|
+
const chainIds = getChainIds(getDefaultClientUrl()) // instead of `getDefaultClientUrl` you can pass custom API endpoints
|
|
49
|
+
const client = new Client({ network: Network.Testnet, phrase: 'my secret phrase', chainIds })
|
|
48
50
|
|
|
49
51
|
// get address
|
|
50
52
|
const address = client.getAddress()
|
package/lib/index.esm.js
CHANGED
|
@@ -272,6 +272,42 @@ var getDefaultFees = function () {
|
|
|
272
272
|
var getTxType = function (txData, encoding) {
|
|
273
273
|
return Buffer.from(txData, encoding).toString().slice(4);
|
|
274
274
|
};
|
|
275
|
+
/**
|
|
276
|
+
* Helper to get THORChain's chain id
|
|
277
|
+
* @param {string} nodeUrl THORNode url
|
|
278
|
+
*/
|
|
279
|
+
var getChainId = function (nodeUrl) { return __awaiter(void 0, void 0, void 0, function () {
|
|
280
|
+
var data;
|
|
281
|
+
var _a;
|
|
282
|
+
return __generator(this, function (_b) {
|
|
283
|
+
switch (_b.label) {
|
|
284
|
+
case 0: return [4 /*yield*/, axios.get(nodeUrl + "/cosmos/base/tendermint/v1beta1/node_info")];
|
|
285
|
+
case 1:
|
|
286
|
+
data = (_b.sent()).data;
|
|
287
|
+
return [2 /*return*/, ((_a = data === null || data === void 0 ? void 0 : data.default_node_info) === null || _a === void 0 ? void 0 : _a.network) || Promise.reject('Could not parse chain id')];
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
}); };
|
|
291
|
+
/**
|
|
292
|
+
* Helper to get all THORChain's chain id
|
|
293
|
+
* @param {ClientUrl} client urls (use `getDefaultClientUrl()` if you don't need to use custom urls)
|
|
294
|
+
*/
|
|
295
|
+
var getChainIds = function (client) { return __awaiter(void 0, void 0, void 0, function () {
|
|
296
|
+
return __generator(this, function (_a) {
|
|
297
|
+
return [2 /*return*/, Promise.all([
|
|
298
|
+
getChainId(client[Network.Testnet].node),
|
|
299
|
+
getChainId(client[Network.Stagenet].node),
|
|
300
|
+
getChainId(client[Network.Mainnet].node),
|
|
301
|
+
]).then(function (_a) {
|
|
302
|
+
var testnetId = _a[0], stagenetId = _a[1], mainnetId = _a[2];
|
|
303
|
+
return ({
|
|
304
|
+
testnet: testnetId,
|
|
305
|
+
stagenet: stagenetId,
|
|
306
|
+
mainnet: mainnetId,
|
|
307
|
+
});
|
|
308
|
+
})];
|
|
309
|
+
});
|
|
310
|
+
}); };
|
|
275
311
|
/**
|
|
276
312
|
* Structure StdTx from MsgNativeTx.
|
|
277
313
|
*
|
|
@@ -286,14 +322,13 @@ var getTxType = function (txData, encoding) {
|
|
|
286
322
|
var buildDepositTx = function (_a) {
|
|
287
323
|
var msgNativeTx = _a.msgNativeTx, nodeUrl = _a.nodeUrl, chainId = _a.chainId;
|
|
288
324
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
289
|
-
var
|
|
325
|
+
var networkChainId, response, fee, unsignedStdTx;
|
|
290
326
|
var _b, _c;
|
|
291
327
|
return __generator(this, function (_d) {
|
|
292
328
|
switch (_d.label) {
|
|
293
|
-
case 0: return [4 /*yield*/,
|
|
329
|
+
case 0: return [4 /*yield*/, getChainId(nodeUrl)];
|
|
294
330
|
case 1:
|
|
295
|
-
|
|
296
|
-
networkChainId = data.default_node_info.network;
|
|
331
|
+
networkChainId = _d.sent();
|
|
297
332
|
if (!networkChainId || chainId !== networkChainId)
|
|
298
333
|
throw new Error("Invalid network (asked: " + chainId + " / returned: " + networkChainId);
|
|
299
334
|
return [4 /*yield*/, axios.post(nodeUrl + "/thorchain/deposit", {
|
|
@@ -469,17 +504,13 @@ var Client = /** @class */ (function () {
|
|
|
469
504
|
* @throws {"Invalid phrase"} Thrown if the given phase is invalid.
|
|
470
505
|
*/
|
|
471
506
|
function Client(_a) {
|
|
472
|
-
var _b
|
|
507
|
+
var _b;
|
|
473
508
|
var _this = this;
|
|
474
|
-
var
|
|
509
|
+
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 = {},
|
|
475
510
|
_b[Network.Mainnet] = "44'/931'/0'/0/",
|
|
476
511
|
_b[Network.Stagenet] = "44'/931'/0'/0/",
|
|
477
512
|
_b[Network.Testnet] = "44'/931'/0'/0/",
|
|
478
|
-
_b) :
|
|
479
|
-
_c[Network.Mainnet] = 'thorchain',
|
|
480
|
-
_c[Network.Stagenet] = 'thorchain-stagenet',
|
|
481
|
-
_c[Network.Testnet] = 'thorchain-v1',
|
|
482
|
-
_c) : _f;
|
|
513
|
+
_b) : _d, chainIds = _a.chainIds;
|
|
483
514
|
this.phrase = '';
|
|
484
515
|
/**
|
|
485
516
|
* Get transaction history of a given address with pagination options.
|
|
@@ -1050,4 +1081,4 @@ var Client = /** @class */ (function () {
|
|
|
1050
1081
|
return Client;
|
|
1051
1082
|
}());
|
|
1052
1083
|
|
|
1053
|
-
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 };
|
|
1084
|
+
export { Client, DECIMAL, DEFAULT_GAS_VALUE, DEPOSIT_GAS_VALUE, MAX_TX_COUNT, MsgNativeTx, assetFromDenom, buildDepositTx, getBalance, getChainId, getChainIds, getDefaultClientUrl, getDefaultExplorerUrls, getDefaultFees, getDenom, getDepositTxDataFromLogs, getExplorerAddressUrl, getExplorerTxUrl, getExplorerUrl, getPrefix, getTxType, isAssetRuneNative, isBroadcastSuccess, isMsgMultiSend, isMsgSend, msgNativeTxFromJson, registerCodecs };
|
package/lib/index.js
CHANGED
|
@@ -280,6 +280,42 @@ var getDefaultFees = function () {
|
|
|
280
280
|
var getTxType = function (txData, encoding) {
|
|
281
281
|
return Buffer.from(txData, encoding).toString().slice(4);
|
|
282
282
|
};
|
|
283
|
+
/**
|
|
284
|
+
* Helper to get THORChain's chain id
|
|
285
|
+
* @param {string} nodeUrl THORNode url
|
|
286
|
+
*/
|
|
287
|
+
var getChainId = function (nodeUrl) { return __awaiter(void 0, void 0, void 0, function () {
|
|
288
|
+
var data;
|
|
289
|
+
var _a;
|
|
290
|
+
return __generator(this, function (_b) {
|
|
291
|
+
switch (_b.label) {
|
|
292
|
+
case 0: return [4 /*yield*/, axios__default['default'].get(nodeUrl + "/cosmos/base/tendermint/v1beta1/node_info")];
|
|
293
|
+
case 1:
|
|
294
|
+
data = (_b.sent()).data;
|
|
295
|
+
return [2 /*return*/, ((_a = data === null || data === void 0 ? void 0 : data.default_node_info) === null || _a === void 0 ? void 0 : _a.network) || Promise.reject('Could not parse chain id')];
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
}); };
|
|
299
|
+
/**
|
|
300
|
+
* Helper to get all THORChain's chain id
|
|
301
|
+
* @param {ClientUrl} client urls (use `getDefaultClientUrl()` if you don't need to use custom urls)
|
|
302
|
+
*/
|
|
303
|
+
var getChainIds = function (client) { return __awaiter(void 0, void 0, void 0, function () {
|
|
304
|
+
return __generator(this, function (_a) {
|
|
305
|
+
return [2 /*return*/, Promise.all([
|
|
306
|
+
getChainId(client[xchainClient.Network.Testnet].node),
|
|
307
|
+
getChainId(client[xchainClient.Network.Stagenet].node),
|
|
308
|
+
getChainId(client[xchainClient.Network.Mainnet].node),
|
|
309
|
+
]).then(function (_a) {
|
|
310
|
+
var testnetId = _a[0], stagenetId = _a[1], mainnetId = _a[2];
|
|
311
|
+
return ({
|
|
312
|
+
testnet: testnetId,
|
|
313
|
+
stagenet: stagenetId,
|
|
314
|
+
mainnet: mainnetId,
|
|
315
|
+
});
|
|
316
|
+
})];
|
|
317
|
+
});
|
|
318
|
+
}); };
|
|
283
319
|
/**
|
|
284
320
|
* Structure StdTx from MsgNativeTx.
|
|
285
321
|
*
|
|
@@ -294,14 +330,13 @@ var getTxType = function (txData, encoding) {
|
|
|
294
330
|
var buildDepositTx = function (_a) {
|
|
295
331
|
var msgNativeTx = _a.msgNativeTx, nodeUrl = _a.nodeUrl, chainId = _a.chainId;
|
|
296
332
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
297
|
-
var
|
|
333
|
+
var networkChainId, response, fee, unsignedStdTx;
|
|
298
334
|
var _b, _c;
|
|
299
335
|
return __generator(this, function (_d) {
|
|
300
336
|
switch (_d.label) {
|
|
301
|
-
case 0: return [4 /*yield*/,
|
|
337
|
+
case 0: return [4 /*yield*/, getChainId(nodeUrl)];
|
|
302
338
|
case 1:
|
|
303
|
-
|
|
304
|
-
networkChainId = data.default_node_info.network;
|
|
339
|
+
networkChainId = _d.sent();
|
|
305
340
|
if (!networkChainId || chainId !== networkChainId)
|
|
306
341
|
throw new Error("Invalid network (asked: " + chainId + " / returned: " + networkChainId);
|
|
307
342
|
return [4 /*yield*/, axios__default['default'].post(nodeUrl + "/thorchain/deposit", {
|
|
@@ -477,17 +512,13 @@ var Client = /** @class */ (function () {
|
|
|
477
512
|
* @throws {"Invalid phrase"} Thrown if the given phase is invalid.
|
|
478
513
|
*/
|
|
479
514
|
function Client(_a) {
|
|
480
|
-
var _b
|
|
515
|
+
var _b;
|
|
481
516
|
var _this = this;
|
|
482
|
-
var
|
|
517
|
+
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 = {},
|
|
483
518
|
_b[xchainClient.Network.Mainnet] = "44'/931'/0'/0/",
|
|
484
519
|
_b[xchainClient.Network.Stagenet] = "44'/931'/0'/0/",
|
|
485
520
|
_b[xchainClient.Network.Testnet] = "44'/931'/0'/0/",
|
|
486
|
-
_b) :
|
|
487
|
-
_c[xchainClient.Network.Mainnet] = 'thorchain',
|
|
488
|
-
_c[xchainClient.Network.Stagenet] = 'thorchain-stagenet',
|
|
489
|
-
_c[xchainClient.Network.Testnet] = 'thorchain-v1',
|
|
490
|
-
_c) : _f;
|
|
521
|
+
_b) : _d, chainIds = _a.chainIds;
|
|
491
522
|
this.phrase = '';
|
|
492
523
|
/**
|
|
493
524
|
* Get transaction history of a given address with pagination options.
|
|
@@ -1067,6 +1098,8 @@ exports.MsgNativeTx = MsgNativeTx;
|
|
|
1067
1098
|
exports.assetFromDenom = assetFromDenom;
|
|
1068
1099
|
exports.buildDepositTx = buildDepositTx;
|
|
1069
1100
|
exports.getBalance = getBalance;
|
|
1101
|
+
exports.getChainId = getChainId;
|
|
1102
|
+
exports.getChainIds = getChainIds;
|
|
1070
1103
|
exports.getDefaultClientUrl = getDefaultClientUrl;
|
|
1071
1104
|
exports.getDefaultExplorerUrls = getDefaultExplorerUrls;
|
|
1072
1105
|
exports.getDefaultFees = getDefaultFees;
|
|
@@ -16,7 +16,7 @@ export declare type ChainIds = Record<Network, ChainId>;
|
|
|
16
16
|
export declare type ThorchainClientParams = {
|
|
17
17
|
clientUrl?: ClientUrl;
|
|
18
18
|
explorerUrls?: ExplorerUrls;
|
|
19
|
-
chainIds
|
|
19
|
+
chainIds: ChainIds;
|
|
20
20
|
};
|
|
21
21
|
export declare type DepositParam = {
|
|
22
22
|
walletIndex?: number;
|
|
@@ -46,3 +46,12 @@ export declare type ThorchainConstantsResponse = {
|
|
|
46
46
|
NativeTransactionFee: number;
|
|
47
47
|
};
|
|
48
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Response of `/cosmos/base/tendermint/v1beta1/node_info`
|
|
51
|
+
* Note: We are interested in `network` (aka chain id) only
|
|
52
|
+
*/
|
|
53
|
+
export declare type NodeInfoResponse = {
|
|
54
|
+
default_node_info: {
|
|
55
|
+
network: string;
|
|
56
|
+
};
|
|
57
|
+
};
|
package/lib/util.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ 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 { ChainId, ClientUrl, ExplorerUrls, TxData } from './types';
|
|
7
|
+
import { ChainId, ChainIds, ClientUrl, ExplorerUrls, TxData } from './types';
|
|
8
8
|
import { MsgNativeTx } from './types/messages';
|
|
9
9
|
export declare const DECIMAL = 8;
|
|
10
10
|
export declare const DEFAULT_GAS_VALUE = "3000000";
|
|
@@ -88,6 +88,16 @@ export declare const getDefaultFees: () => Fees;
|
|
|
88
88
|
* @returns {string} the transaction type.
|
|
89
89
|
*/
|
|
90
90
|
export declare const getTxType: (txData: string, encoding: 'base64' | 'hex') => string;
|
|
91
|
+
/**
|
|
92
|
+
* Helper to get THORChain's chain id
|
|
93
|
+
* @param {string} nodeUrl THORNode url
|
|
94
|
+
*/
|
|
95
|
+
export declare const getChainId: (nodeUrl: string) => Promise<ChainId>;
|
|
96
|
+
/**
|
|
97
|
+
* Helper to get all THORChain's chain id
|
|
98
|
+
* @param {ClientUrl} client urls (use `getDefaultClientUrl()` if you don't need to use custom urls)
|
|
99
|
+
*/
|
|
100
|
+
export declare const getChainIds: (client: ClientUrl) => Promise<ChainIds>;
|
|
91
101
|
/**
|
|
92
102
|
* Structure StdTx from MsgNativeTx.
|
|
93
103
|
*
|