@xchainjs/xchain-thorchain 0.17.7 → 0.19.2-alpha1
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 +45 -1
- package/lib/client.d.ts +0 -15
- package/lib/index.esm.js +85 -79
- package/lib/index.js +87 -78
- package/lib/types/client-types.d.ts +0 -1
- package/lib/types/messages.d.ts +0 -6
- package/lib/util.d.ts +34 -2
- package/package.json +2 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,14 +1,54 @@
|
|
|
1
|
+
# Pre-release v.0.19.2-alpha1 (2021-09-27)
|
|
2
|
+
|
|
3
|
+
## Fix
|
|
4
|
+
|
|
5
|
+
- Increase `gas` to `500,000,000` (five hundred million)
|
|
6
|
+
|
|
7
|
+
# v.0.19.1 (2021-09-26)
|
|
8
|
+
|
|
9
|
+
## Fix
|
|
10
|
+
|
|
11
|
+
- Increase `gas` to `30,000,000` (thirty million)
|
|
12
|
+
|
|
13
|
+
# v.0.19.0 (2021-09-10)
|
|
14
|
+
|
|
15
|
+
## Breaking change
|
|
16
|
+
|
|
17
|
+
- Extract `buildDepositTx` from `Client` into `utils`
|
|
18
|
+
|
|
19
|
+
## Add
|
|
20
|
+
|
|
21
|
+
- Add `getBalance` to `utils`
|
|
22
|
+
|
|
23
|
+
# v.0.18.0 (2021-09-08)
|
|
24
|
+
|
|
25
|
+
## Add
|
|
26
|
+
|
|
27
|
+
- Make `buildDepositTx` public and overrides its fee
|
|
28
|
+
- Add `DEPOSIT_GAS_VALUE`
|
|
29
|
+
|
|
30
|
+
## Breaking change
|
|
31
|
+
|
|
32
|
+
- Remove `AssetRune` in favour of using `AssetRuneNative` of `xchain-util` only
|
|
33
|
+
- Extract `getChainId` into `util` module
|
|
34
|
+
|
|
1
35
|
# v.0.17.7 (2021-07-20)
|
|
2
36
|
|
|
37
|
+
## Fix
|
|
38
|
+
|
|
3
39
|
- cosmos 0.42.x has too many breaking changes that wren't caught in the last version, downgrade "cosmos-client": "0.39.2"
|
|
4
40
|
|
|
5
41
|
# v.0.17.6 (2021-07-19)
|
|
6
42
|
|
|
43
|
+
## Update
|
|
44
|
+
|
|
7
45
|
- bumping peer dependency "cosmos-client": "0.39.2" -> "cosmos-client": "^0.42.7"
|
|
8
46
|
|
|
9
47
|
# v.0.17.5 (2021-07-18)
|
|
10
48
|
|
|
11
|
-
|
|
49
|
+
## Update
|
|
50
|
+
|
|
51
|
+
- Updated rollupjs to include axios to enlable usage on node
|
|
12
52
|
|
|
13
53
|
# v.0.17.4 (2021-07-14)
|
|
14
54
|
|
|
@@ -18,10 +58,14 @@
|
|
|
18
58
|
|
|
19
59
|
# v.0.17.3 (2021-07-07)
|
|
20
60
|
|
|
61
|
+
## Update
|
|
62
|
+
|
|
21
63
|
- Use latest `xchain-client@0.10.1` + `xchain-util@0.3.0`
|
|
22
64
|
|
|
23
65
|
# v.0.17.2 (2021-07-05)
|
|
24
66
|
|
|
67
|
+
## Fix
|
|
68
|
+
|
|
25
69
|
- refactored client methods to use regular method syntax (not fat arrow) in order for bcall to super.xxx() to work properly
|
|
26
70
|
|
|
27
71
|
# v.0.17.1 (2021-06-29)
|
package/lib/client.d.ts
CHANGED
|
@@ -86,12 +86,6 @@ declare class Client implements ThorchainClient, XChainClient {
|
|
|
86
86
|
* @returns {CosmosSDKClient} current cosmos client
|
|
87
87
|
*/
|
|
88
88
|
getCosmosClient(): CosmosSDKClient;
|
|
89
|
-
/**
|
|
90
|
-
* Get the chain id.
|
|
91
|
-
*
|
|
92
|
-
* @returns {string} The chain id based on the network.
|
|
93
|
-
*/
|
|
94
|
-
getChainId(): string;
|
|
95
89
|
/**
|
|
96
90
|
* Get the explorer url for the given address.
|
|
97
91
|
*
|
|
@@ -182,15 +176,6 @@ declare class Client implements ThorchainClient, XChainClient {
|
|
|
182
176
|
* @returns {Tx} The transaction details of the given transaction id.
|
|
183
177
|
*/
|
|
184
178
|
getDepositTransaction(txId: string): Promise<Omit<Tx, 'date'>>;
|
|
185
|
-
/**
|
|
186
|
-
* Structure StdTx from MsgNativeTx.
|
|
187
|
-
*
|
|
188
|
-
* @param {string} txId The transaction id.
|
|
189
|
-
* @returns {Tx} The transaction details of the given transaction id.
|
|
190
|
-
*
|
|
191
|
-
* @throws {"Invalid client url"} Thrown if the client url is an invalid one.
|
|
192
|
-
*/
|
|
193
|
-
private buildDepositTx;
|
|
194
179
|
/**
|
|
195
180
|
* Transaction with MsgNativeTx.
|
|
196
181
|
*
|
package/lib/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Network, TxType, singleFee, FeeType, FeeOption } from '@xchainjs/xchain-client';
|
|
2
2
|
import { CosmosSDKClient } from '@xchainjs/xchain-cosmos';
|
|
3
3
|
import { validatePhrase } from '@xchainjs/xchain-crypto';
|
|
4
|
-
import {
|
|
4
|
+
import { assetToString, AssetRuneNative, Chain, assetFromString, baseAmount } from '@xchainjs/xchain-util';
|
|
5
5
|
import axios from 'axios';
|
|
6
6
|
import { AccAddress, Msg, codec } from 'cosmos-client';
|
|
7
7
|
import { StdTx } from 'cosmos-client/x/auth';
|
|
@@ -93,16 +93,8 @@ function __spreadArray(to, from) {
|
|
|
93
93
|
return to;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
var AssetRune = { chain: Chain.THORChain, symbol: 'RUNE', ticker: 'RUNE' };
|
|
97
|
-
|
|
98
96
|
var MsgNativeTx = /** @class */ (function (_super) {
|
|
99
97
|
__extends(MsgNativeTx, _super);
|
|
100
|
-
/**
|
|
101
|
-
*
|
|
102
|
-
* @param from_address
|
|
103
|
-
* @param to_address
|
|
104
|
-
* @param amount
|
|
105
|
-
*/
|
|
106
98
|
function MsgNativeTx(coins, memo, signer) {
|
|
107
99
|
var _this = _super.call(this) || this;
|
|
108
100
|
_this.coins = coins;
|
|
@@ -124,6 +116,7 @@ var msgNativeTxFromJson = function (value) {
|
|
|
124
116
|
|
|
125
117
|
var DECIMAL = 8;
|
|
126
118
|
var DEFAULT_GAS_VALUE = '2000000';
|
|
119
|
+
var DEPOSIT_GAS_VALUE = '500000000';
|
|
127
120
|
var MAX_TX_COUNT = 100;
|
|
128
121
|
/**
|
|
129
122
|
* Get denomination from Asset
|
|
@@ -132,7 +125,7 @@ var MAX_TX_COUNT = 100;
|
|
|
132
125
|
* @returns {string} The denomination of the given asset.
|
|
133
126
|
*/
|
|
134
127
|
var getDenom = function (asset) {
|
|
135
|
-
if (assetToString(asset) === assetToString(
|
|
128
|
+
if (assetToString(asset) === assetToString(AssetRuneNative))
|
|
136
129
|
return 'rune';
|
|
137
130
|
return asset.symbol;
|
|
138
131
|
};
|
|
@@ -152,8 +145,8 @@ var getDenomWithChain = function (asset) {
|
|
|
152
145
|
* @returns {Asset|null} The asset of the given denomination.
|
|
153
146
|
*/
|
|
154
147
|
var getAsset = function (denom) {
|
|
155
|
-
if (denom === getDenom(
|
|
156
|
-
return
|
|
148
|
+
if (denom === getDenom(AssetRuneNative))
|
|
149
|
+
return AssetRuneNative;
|
|
157
150
|
return assetFromString(Chain.THORChain + "." + denom.toUpperCase());
|
|
158
151
|
};
|
|
159
152
|
/**
|
|
@@ -202,6 +195,12 @@ var getPrefix = function (network) {
|
|
|
202
195
|
return 'tthor';
|
|
203
196
|
}
|
|
204
197
|
};
|
|
198
|
+
/**
|
|
199
|
+
* Get the chain id.
|
|
200
|
+
*
|
|
201
|
+
* @returns {string} The chain id based on the network.
|
|
202
|
+
*/
|
|
203
|
+
var getChainId = function () { return 'thorchain'; };
|
|
205
204
|
/**
|
|
206
205
|
* Register Codecs based on the prefix.
|
|
207
206
|
*
|
|
@@ -276,6 +275,71 @@ var getDefaultFees = function () {
|
|
|
276
275
|
var getTxType = function (txData, encoding) {
|
|
277
276
|
return Buffer.from(txData, encoding).toString().slice(4);
|
|
278
277
|
};
|
|
278
|
+
/**
|
|
279
|
+
* Structure StdTx from MsgNativeTx.
|
|
280
|
+
*
|
|
281
|
+
* @param {string} txId The transaction id.
|
|
282
|
+
* @returns {Tx} The transaction details of the given transaction id.
|
|
283
|
+
*
|
|
284
|
+
* @throws {"Invalid client url"} Thrown if the client url is an invalid one.
|
|
285
|
+
*/
|
|
286
|
+
var buildDepositTx = function (msgNativeTx, nodeUrl) { return __awaiter(void 0, void 0, void 0, function () {
|
|
287
|
+
var response, fee, unsignedStdTx;
|
|
288
|
+
var _a, _b;
|
|
289
|
+
return __generator(this, function (_c) {
|
|
290
|
+
switch (_c.label) {
|
|
291
|
+
case 0: return [4 /*yield*/, axios.post(nodeUrl + "/thorchain/deposit", {
|
|
292
|
+
coins: msgNativeTx.coins,
|
|
293
|
+
memo: msgNativeTx.memo,
|
|
294
|
+
base_req: {
|
|
295
|
+
chain_id: getChainId(),
|
|
296
|
+
from: msgNativeTx.signer,
|
|
297
|
+
},
|
|
298
|
+
})];
|
|
299
|
+
case 1:
|
|
300
|
+
response = (_c.sent()).data;
|
|
301
|
+
if (!response || !response.value)
|
|
302
|
+
throw new Error('Invalid client url');
|
|
303
|
+
fee = (_b = (_a = response.value) === null || _a === void 0 ? void 0 : _a.fee) !== null && _b !== void 0 ? _b : { amount: [] };
|
|
304
|
+
unsignedStdTx = StdTx.fromJSON({
|
|
305
|
+
msg: response.value.msg,
|
|
306
|
+
// override fee
|
|
307
|
+
fee: __assign(__assign({}, fee), { gas: DEPOSIT_GAS_VALUE }),
|
|
308
|
+
signatures: [],
|
|
309
|
+
memo: '',
|
|
310
|
+
});
|
|
311
|
+
return [2 /*return*/, unsignedStdTx];
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
}); };
|
|
315
|
+
/**
|
|
316
|
+
* Get the balance of a given address.
|
|
317
|
+
*
|
|
318
|
+
* @param {Address} address By default, it will return the balance of the current wallet. (optional)
|
|
319
|
+
* @param {Asset} asset If not set, it will return all assets available. (optional)
|
|
320
|
+
* @param {cosmosClient} CosmosSDKClient
|
|
321
|
+
*
|
|
322
|
+
* @returns {Balance[]} The balance of the address.
|
|
323
|
+
*/
|
|
324
|
+
var getBalance = function (_a) {
|
|
325
|
+
var address = _a.address, assets = _a.assets, cosmosClient = _a.cosmosClient;
|
|
326
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
327
|
+
var balances;
|
|
328
|
+
return __generator(this, function (_b) {
|
|
329
|
+
switch (_b.label) {
|
|
330
|
+
case 0: return [4 /*yield*/, cosmosClient.getBalance(address)];
|
|
331
|
+
case 1:
|
|
332
|
+
balances = _b.sent();
|
|
333
|
+
return [2 /*return*/, balances
|
|
334
|
+
.map(function (balance) { return ({
|
|
335
|
+
asset: (balance.denom && getAsset(balance.denom)) || AssetRuneNative,
|
|
336
|
+
amount: baseAmount(balance.amount, DECIMAL),
|
|
337
|
+
}); })
|
|
338
|
+
.filter(function (balance) { return !assets || assets.filter(function (asset) { return assetToString(balance.asset) === assetToString(asset); }).length; })];
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
};
|
|
279
343
|
/**
|
|
280
344
|
* Get the client url.
|
|
281
345
|
*
|
|
@@ -463,7 +527,7 @@ var Client = /** @class */ (function () {
|
|
|
463
527
|
this.rootDerivationPaths = rootDerivationPaths;
|
|
464
528
|
this.cosmosClient = new CosmosSDKClient({
|
|
465
529
|
server: this.getClientUrl().node,
|
|
466
|
-
chainId:
|
|
530
|
+
chainId: getChainId(),
|
|
467
531
|
prefix: getPrefix(this.network),
|
|
468
532
|
});
|
|
469
533
|
if (phrase)
|
|
@@ -542,14 +606,6 @@ var Client = /** @class */ (function () {
|
|
|
542
606
|
Client.prototype.getCosmosClient = function () {
|
|
543
607
|
return this.cosmosClient;
|
|
544
608
|
};
|
|
545
|
-
/**
|
|
546
|
-
* Get the chain id.
|
|
547
|
-
*
|
|
548
|
-
* @returns {string} The chain id based on the network.
|
|
549
|
-
*/
|
|
550
|
-
Client.prototype.getChainId = function () {
|
|
551
|
-
return 'thorchain';
|
|
552
|
-
};
|
|
553
609
|
/**
|
|
554
610
|
* Get the explorer url for the given address.
|
|
555
611
|
*
|
|
@@ -642,19 +698,8 @@ var Client = /** @class */ (function () {
|
|
|
642
698
|
*/
|
|
643
699
|
Client.prototype.getBalance = function (address, assets) {
|
|
644
700
|
return __awaiter(this, void 0, void 0, function () {
|
|
645
|
-
var balances;
|
|
646
701
|
return __generator(this, function (_a) {
|
|
647
|
-
|
|
648
|
-
case 0: return [4 /*yield*/, this.cosmosClient.getBalance(address)];
|
|
649
|
-
case 1:
|
|
650
|
-
balances = _a.sent();
|
|
651
|
-
return [2 /*return*/, balances
|
|
652
|
-
.map(function (balance) { return ({
|
|
653
|
-
asset: (balance.denom && getAsset(balance.denom)) || AssetRune,
|
|
654
|
-
amount: baseAmount(balance.amount, DECIMAL),
|
|
655
|
-
}); })
|
|
656
|
-
.filter(function (balance) { return !assets || assets.filter(function (asset) { return assetToString(balance.asset) === assetToString(asset); }).length; })];
|
|
657
|
-
}
|
|
702
|
+
return [2 /*return*/, getBalance({ address: address, assets: assets, cosmosClient: this.getCosmosClient() })];
|
|
658
703
|
});
|
|
659
704
|
});
|
|
660
705
|
};
|
|
@@ -678,7 +723,7 @@ var Client = /** @class */ (function () {
|
|
|
678
723
|
from = txData.from, to = txData.to, type = txData.type;
|
|
679
724
|
return [2 /*return*/, {
|
|
680
725
|
hash: txId,
|
|
681
|
-
asset:
|
|
726
|
+
asset: AssetRuneNative,
|
|
682
727
|
from: from,
|
|
683
728
|
to: to,
|
|
684
729
|
date: new Date(txResult.timestamp),
|
|
@@ -720,7 +765,7 @@ var Client = /** @class */ (function () {
|
|
|
720
765
|
asset = assetFromString(coin.asset);
|
|
721
766
|
});
|
|
722
767
|
return [2 /*return*/, {
|
|
723
|
-
asset: asset ||
|
|
768
|
+
asset: asset || AssetRuneNative,
|
|
724
769
|
from: from,
|
|
725
770
|
to: to,
|
|
726
771
|
type: TxType.Transfer,
|
|
@@ -730,42 +775,6 @@ var Client = /** @class */ (function () {
|
|
|
730
775
|
});
|
|
731
776
|
});
|
|
732
777
|
};
|
|
733
|
-
/**
|
|
734
|
-
* Structure StdTx from MsgNativeTx.
|
|
735
|
-
*
|
|
736
|
-
* @param {string} txId The transaction id.
|
|
737
|
-
* @returns {Tx} The transaction details of the given transaction id.
|
|
738
|
-
*
|
|
739
|
-
* @throws {"Invalid client url"} Thrown if the client url is an invalid one.
|
|
740
|
-
*/
|
|
741
|
-
Client.prototype.buildDepositTx = function (msgNativeTx) {
|
|
742
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
743
|
-
var response, unsignedStdTx;
|
|
744
|
-
return __generator(this, function (_a) {
|
|
745
|
-
switch (_a.label) {
|
|
746
|
-
case 0: return [4 /*yield*/, axios.post(this.getClientUrl().node + "/thorchain/deposit", {
|
|
747
|
-
coins: msgNativeTx.coins,
|
|
748
|
-
memo: msgNativeTx.memo,
|
|
749
|
-
base_req: {
|
|
750
|
-
chain_id: 'thorchain',
|
|
751
|
-
from: msgNativeTx.signer,
|
|
752
|
-
},
|
|
753
|
-
})];
|
|
754
|
-
case 1:
|
|
755
|
-
response = (_a.sent()).data;
|
|
756
|
-
if (!response || !response.value)
|
|
757
|
-
throw new Error('Invalid client url');
|
|
758
|
-
unsignedStdTx = StdTx.fromJSON({
|
|
759
|
-
msg: response.value.msg,
|
|
760
|
-
fee: response.value.fee,
|
|
761
|
-
signatures: [],
|
|
762
|
-
memo: '',
|
|
763
|
-
});
|
|
764
|
-
return [2 /*return*/, unsignedStdTx];
|
|
765
|
-
}
|
|
766
|
-
});
|
|
767
|
-
});
|
|
768
|
-
};
|
|
769
778
|
/**
|
|
770
779
|
* Transaction with MsgNativeTx.
|
|
771
780
|
*
|
|
@@ -777,9 +786,9 @@ var Client = /** @class */ (function () {
|
|
|
777
786
|
*/
|
|
778
787
|
Client.prototype.deposit = function (_a) {
|
|
779
788
|
var _b, _c;
|
|
780
|
-
var _d = _a.walletIndex, walletIndex = _d === void 0 ? 0 : _d, _e = _a.asset, asset = _e === void 0 ?
|
|
789
|
+
var _d = _a.walletIndex, walletIndex = _d === void 0 ? 0 : _d, _e = _a.asset, asset = _e === void 0 ? AssetRuneNative : _e, amount = _a.amount, memo = _a.memo;
|
|
781
790
|
return __awaiter(this, void 0, void 0, function () {
|
|
782
|
-
var assetBalance, signer, msgNativeTx, unsignedStdTx, privateKey, accAddress
|
|
791
|
+
var assetBalance, signer, msgNativeTx, unsignedStdTx, privateKey, accAddress;
|
|
783
792
|
return __generator(this, function (_f) {
|
|
784
793
|
switch (_f.label) {
|
|
785
794
|
case 0: return [4 /*yield*/, this.getBalance(this.getAddress(walletIndex), [asset])];
|
|
@@ -799,14 +808,11 @@ var Client = /** @class */ (function () {
|
|
|
799
808
|
memo: memo,
|
|
800
809
|
signer: signer,
|
|
801
810
|
});
|
|
802
|
-
return [4 /*yield*/, this.
|
|
811
|
+
return [4 /*yield*/, buildDepositTx(msgNativeTx, this.getClientUrl().node)];
|
|
803
812
|
case 2:
|
|
804
813
|
unsignedStdTx = _f.sent();
|
|
805
814
|
privateKey = this.getPrivateKey(walletIndex);
|
|
806
815
|
accAddress = AccAddress.fromBech32(signer);
|
|
807
|
-
fee = unsignedStdTx.fee;
|
|
808
|
-
// max. gas
|
|
809
|
-
fee.gas = '25000000';
|
|
810
816
|
return [4 /*yield*/, this.cosmosClient.signAndBroadcast(unsignedStdTx, privateKey, accAddress)];
|
|
811
817
|
case 3: return [2 /*return*/, (_c = (_b = (_f.sent())) === null || _b === void 0 ? void 0 : _b.txhash) !== null && _c !== void 0 ? _c : ''];
|
|
812
818
|
}
|
|
@@ -820,7 +826,7 @@ var Client = /** @class */ (function () {
|
|
|
820
826
|
* @returns {TxHash} The transaction hash.
|
|
821
827
|
*/
|
|
822
828
|
Client.prototype.transfer = function (_a) {
|
|
823
|
-
var _b = _a.walletIndex, walletIndex = _b === void 0 ? 0 : _b, _c = _a.asset, asset = _c === void 0 ?
|
|
829
|
+
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;
|
|
824
830
|
return __awaiter(this, void 0, void 0, function () {
|
|
825
831
|
var assetBalance, fee, transferResult;
|
|
826
832
|
return __generator(this, function (_d) {
|
|
@@ -874,4 +880,4 @@ var Client = /** @class */ (function () {
|
|
|
874
880
|
return Client;
|
|
875
881
|
}());
|
|
876
882
|
|
|
877
|
-
export {
|
|
883
|
+
export { Client, DECIMAL, DEFAULT_GAS_VALUE, DEPOSIT_GAS_VALUE, MAX_TX_COUNT, MsgNativeTx, buildDepositTx, getAsset, getBalance, getChainId, getDefaultClientUrl, getDefaultExplorerUrls, getDefaultFees, getDenom, getDenomWithChain, getDepositTxDataFromLogs, getExplorerAddressUrl, getExplorerTxUrl, getExplorerUrl, getPrefix, getTxType, isBroadcastSuccess, isMsgMultiSend, isMsgSend, msgNativeTxFromJson, registerCodecs };
|
package/lib/index.js
CHANGED
|
@@ -101,16 +101,8 @@ function __spreadArray(to, from) {
|
|
|
101
101
|
return to;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
var AssetRune = { chain: xchainUtil.Chain.THORChain, symbol: 'RUNE', ticker: 'RUNE' };
|
|
105
|
-
|
|
106
104
|
var MsgNativeTx = /** @class */ (function (_super) {
|
|
107
105
|
__extends(MsgNativeTx, _super);
|
|
108
|
-
/**
|
|
109
|
-
*
|
|
110
|
-
* @param from_address
|
|
111
|
-
* @param to_address
|
|
112
|
-
* @param amount
|
|
113
|
-
*/
|
|
114
106
|
function MsgNativeTx(coins, memo, signer) {
|
|
115
107
|
var _this = _super.call(this) || this;
|
|
116
108
|
_this.coins = coins;
|
|
@@ -132,6 +124,7 @@ var msgNativeTxFromJson = function (value) {
|
|
|
132
124
|
|
|
133
125
|
var DECIMAL = 8;
|
|
134
126
|
var DEFAULT_GAS_VALUE = '2000000';
|
|
127
|
+
var DEPOSIT_GAS_VALUE = '500000000';
|
|
135
128
|
var MAX_TX_COUNT = 100;
|
|
136
129
|
/**
|
|
137
130
|
* Get denomination from Asset
|
|
@@ -140,7 +133,7 @@ var MAX_TX_COUNT = 100;
|
|
|
140
133
|
* @returns {string} The denomination of the given asset.
|
|
141
134
|
*/
|
|
142
135
|
var getDenom = function (asset) {
|
|
143
|
-
if (xchainUtil.assetToString(asset) === xchainUtil.assetToString(
|
|
136
|
+
if (xchainUtil.assetToString(asset) === xchainUtil.assetToString(xchainUtil.AssetRuneNative))
|
|
144
137
|
return 'rune';
|
|
145
138
|
return asset.symbol;
|
|
146
139
|
};
|
|
@@ -160,8 +153,8 @@ var getDenomWithChain = function (asset) {
|
|
|
160
153
|
* @returns {Asset|null} The asset of the given denomination.
|
|
161
154
|
*/
|
|
162
155
|
var getAsset = function (denom) {
|
|
163
|
-
if (denom === getDenom(
|
|
164
|
-
return
|
|
156
|
+
if (denom === getDenom(xchainUtil.AssetRuneNative))
|
|
157
|
+
return xchainUtil.AssetRuneNative;
|
|
165
158
|
return xchainUtil.assetFromString(xchainUtil.Chain.THORChain + "." + denom.toUpperCase());
|
|
166
159
|
};
|
|
167
160
|
/**
|
|
@@ -210,6 +203,12 @@ var getPrefix = function (network) {
|
|
|
210
203
|
return 'tthor';
|
|
211
204
|
}
|
|
212
205
|
};
|
|
206
|
+
/**
|
|
207
|
+
* Get the chain id.
|
|
208
|
+
*
|
|
209
|
+
* @returns {string} The chain id based on the network.
|
|
210
|
+
*/
|
|
211
|
+
var getChainId = function () { return 'thorchain'; };
|
|
213
212
|
/**
|
|
214
213
|
* Register Codecs based on the prefix.
|
|
215
214
|
*
|
|
@@ -284,6 +283,71 @@ var getDefaultFees = function () {
|
|
|
284
283
|
var getTxType = function (txData, encoding) {
|
|
285
284
|
return Buffer.from(txData, encoding).toString().slice(4);
|
|
286
285
|
};
|
|
286
|
+
/**
|
|
287
|
+
* Structure StdTx from MsgNativeTx.
|
|
288
|
+
*
|
|
289
|
+
* @param {string} txId The transaction id.
|
|
290
|
+
* @returns {Tx} The transaction details of the given transaction id.
|
|
291
|
+
*
|
|
292
|
+
* @throws {"Invalid client url"} Thrown if the client url is an invalid one.
|
|
293
|
+
*/
|
|
294
|
+
var buildDepositTx = function (msgNativeTx, nodeUrl) { return __awaiter(void 0, void 0, void 0, function () {
|
|
295
|
+
var response, fee, unsignedStdTx;
|
|
296
|
+
var _a, _b;
|
|
297
|
+
return __generator(this, function (_c) {
|
|
298
|
+
switch (_c.label) {
|
|
299
|
+
case 0: return [4 /*yield*/, axios__default['default'].post(nodeUrl + "/thorchain/deposit", {
|
|
300
|
+
coins: msgNativeTx.coins,
|
|
301
|
+
memo: msgNativeTx.memo,
|
|
302
|
+
base_req: {
|
|
303
|
+
chain_id: getChainId(),
|
|
304
|
+
from: msgNativeTx.signer,
|
|
305
|
+
},
|
|
306
|
+
})];
|
|
307
|
+
case 1:
|
|
308
|
+
response = (_c.sent()).data;
|
|
309
|
+
if (!response || !response.value)
|
|
310
|
+
throw new Error('Invalid client url');
|
|
311
|
+
fee = (_b = (_a = response.value) === null || _a === void 0 ? void 0 : _a.fee) !== null && _b !== void 0 ? _b : { amount: [] };
|
|
312
|
+
unsignedStdTx = auth.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
|
+
});
|
|
322
|
+
}); };
|
|
323
|
+
/**
|
|
324
|
+
* Get the balance of a given address.
|
|
325
|
+
*
|
|
326
|
+
* @param {Address} address By default, it will return the balance of the current wallet. (optional)
|
|
327
|
+
* @param {Asset} asset If not set, it will return all assets available. (optional)
|
|
328
|
+
* @param {cosmosClient} CosmosSDKClient
|
|
329
|
+
*
|
|
330
|
+
* @returns {Balance[]} The balance of the address.
|
|
331
|
+
*/
|
|
332
|
+
var getBalance = function (_a) {
|
|
333
|
+
var address = _a.address, assets = _a.assets, cosmosClient = _a.cosmosClient;
|
|
334
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
335
|
+
var balances;
|
|
336
|
+
return __generator(this, function (_b) {
|
|
337
|
+
switch (_b.label) {
|
|
338
|
+
case 0: return [4 /*yield*/, cosmosClient.getBalance(address)];
|
|
339
|
+
case 1:
|
|
340
|
+
balances = _b.sent();
|
|
341
|
+
return [2 /*return*/, balances
|
|
342
|
+
.map(function (balance) { return ({
|
|
343
|
+
asset: (balance.denom && getAsset(balance.denom)) || xchainUtil.AssetRuneNative,
|
|
344
|
+
amount: xchainUtil.baseAmount(balance.amount, DECIMAL),
|
|
345
|
+
}); })
|
|
346
|
+
.filter(function (balance) { return !assets || assets.filter(function (asset) { return xchainUtil.assetToString(balance.asset) === xchainUtil.assetToString(asset); }).length; })];
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
};
|
|
287
351
|
/**
|
|
288
352
|
* Get the client url.
|
|
289
353
|
*
|
|
@@ -471,7 +535,7 @@ var Client = /** @class */ (function () {
|
|
|
471
535
|
this.rootDerivationPaths = rootDerivationPaths;
|
|
472
536
|
this.cosmosClient = new xchainCosmos.CosmosSDKClient({
|
|
473
537
|
server: this.getClientUrl().node,
|
|
474
|
-
chainId:
|
|
538
|
+
chainId: getChainId(),
|
|
475
539
|
prefix: getPrefix(this.network),
|
|
476
540
|
});
|
|
477
541
|
if (phrase)
|
|
@@ -550,14 +614,6 @@ var Client = /** @class */ (function () {
|
|
|
550
614
|
Client.prototype.getCosmosClient = function () {
|
|
551
615
|
return this.cosmosClient;
|
|
552
616
|
};
|
|
553
|
-
/**
|
|
554
|
-
* Get the chain id.
|
|
555
|
-
*
|
|
556
|
-
* @returns {string} The chain id based on the network.
|
|
557
|
-
*/
|
|
558
|
-
Client.prototype.getChainId = function () {
|
|
559
|
-
return 'thorchain';
|
|
560
|
-
};
|
|
561
617
|
/**
|
|
562
618
|
* Get the explorer url for the given address.
|
|
563
619
|
*
|
|
@@ -650,19 +706,8 @@ var Client = /** @class */ (function () {
|
|
|
650
706
|
*/
|
|
651
707
|
Client.prototype.getBalance = function (address, assets) {
|
|
652
708
|
return __awaiter(this, void 0, void 0, function () {
|
|
653
|
-
var balances;
|
|
654
709
|
return __generator(this, function (_a) {
|
|
655
|
-
|
|
656
|
-
case 0: return [4 /*yield*/, this.cosmosClient.getBalance(address)];
|
|
657
|
-
case 1:
|
|
658
|
-
balances = _a.sent();
|
|
659
|
-
return [2 /*return*/, balances
|
|
660
|
-
.map(function (balance) { return ({
|
|
661
|
-
asset: (balance.denom && getAsset(balance.denom)) || AssetRune,
|
|
662
|
-
amount: xchainUtil.baseAmount(balance.amount, DECIMAL),
|
|
663
|
-
}); })
|
|
664
|
-
.filter(function (balance) { return !assets || assets.filter(function (asset) { return xchainUtil.assetToString(balance.asset) === xchainUtil.assetToString(asset); }).length; })];
|
|
665
|
-
}
|
|
710
|
+
return [2 /*return*/, getBalance({ address: address, assets: assets, cosmosClient: this.getCosmosClient() })];
|
|
666
711
|
});
|
|
667
712
|
});
|
|
668
713
|
};
|
|
@@ -686,7 +731,7 @@ var Client = /** @class */ (function () {
|
|
|
686
731
|
from = txData.from, to = txData.to, type = txData.type;
|
|
687
732
|
return [2 /*return*/, {
|
|
688
733
|
hash: txId,
|
|
689
|
-
asset:
|
|
734
|
+
asset: xchainUtil.AssetRuneNative,
|
|
690
735
|
from: from,
|
|
691
736
|
to: to,
|
|
692
737
|
date: new Date(txResult.timestamp),
|
|
@@ -728,7 +773,7 @@ var Client = /** @class */ (function () {
|
|
|
728
773
|
asset = xchainUtil.assetFromString(coin.asset);
|
|
729
774
|
});
|
|
730
775
|
return [2 /*return*/, {
|
|
731
|
-
asset: asset ||
|
|
776
|
+
asset: asset || xchainUtil.AssetRuneNative,
|
|
732
777
|
from: from,
|
|
733
778
|
to: to,
|
|
734
779
|
type: xchainClient.TxType.Transfer,
|
|
@@ -738,42 +783,6 @@ var Client = /** @class */ (function () {
|
|
|
738
783
|
});
|
|
739
784
|
});
|
|
740
785
|
};
|
|
741
|
-
/**
|
|
742
|
-
* Structure StdTx from MsgNativeTx.
|
|
743
|
-
*
|
|
744
|
-
* @param {string} txId The transaction id.
|
|
745
|
-
* @returns {Tx} The transaction details of the given transaction id.
|
|
746
|
-
*
|
|
747
|
-
* @throws {"Invalid client url"} Thrown if the client url is an invalid one.
|
|
748
|
-
*/
|
|
749
|
-
Client.prototype.buildDepositTx = function (msgNativeTx) {
|
|
750
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
751
|
-
var response, unsignedStdTx;
|
|
752
|
-
return __generator(this, function (_a) {
|
|
753
|
-
switch (_a.label) {
|
|
754
|
-
case 0: return [4 /*yield*/, axios__default['default'].post(this.getClientUrl().node + "/thorchain/deposit", {
|
|
755
|
-
coins: msgNativeTx.coins,
|
|
756
|
-
memo: msgNativeTx.memo,
|
|
757
|
-
base_req: {
|
|
758
|
-
chain_id: 'thorchain',
|
|
759
|
-
from: msgNativeTx.signer,
|
|
760
|
-
},
|
|
761
|
-
})];
|
|
762
|
-
case 1:
|
|
763
|
-
response = (_a.sent()).data;
|
|
764
|
-
if (!response || !response.value)
|
|
765
|
-
throw new Error('Invalid client url');
|
|
766
|
-
unsignedStdTx = auth.StdTx.fromJSON({
|
|
767
|
-
msg: response.value.msg,
|
|
768
|
-
fee: response.value.fee,
|
|
769
|
-
signatures: [],
|
|
770
|
-
memo: '',
|
|
771
|
-
});
|
|
772
|
-
return [2 /*return*/, unsignedStdTx];
|
|
773
|
-
}
|
|
774
|
-
});
|
|
775
|
-
});
|
|
776
|
-
};
|
|
777
786
|
/**
|
|
778
787
|
* Transaction with MsgNativeTx.
|
|
779
788
|
*
|
|
@@ -785,9 +794,9 @@ var Client = /** @class */ (function () {
|
|
|
785
794
|
*/
|
|
786
795
|
Client.prototype.deposit = function (_a) {
|
|
787
796
|
var _b, _c;
|
|
788
|
-
var _d = _a.walletIndex, walletIndex = _d === void 0 ? 0 : _d, _e = _a.asset, asset = _e === void 0 ?
|
|
797
|
+
var _d = _a.walletIndex, walletIndex = _d === void 0 ? 0 : _d, _e = _a.asset, asset = _e === void 0 ? xchainUtil.AssetRuneNative : _e, amount = _a.amount, memo = _a.memo;
|
|
789
798
|
return __awaiter(this, void 0, void 0, function () {
|
|
790
|
-
var assetBalance, signer, msgNativeTx, unsignedStdTx, privateKey, accAddress
|
|
799
|
+
var assetBalance, signer, msgNativeTx, unsignedStdTx, privateKey, accAddress;
|
|
791
800
|
return __generator(this, function (_f) {
|
|
792
801
|
switch (_f.label) {
|
|
793
802
|
case 0: return [4 /*yield*/, this.getBalance(this.getAddress(walletIndex), [asset])];
|
|
@@ -807,14 +816,11 @@ var Client = /** @class */ (function () {
|
|
|
807
816
|
memo: memo,
|
|
808
817
|
signer: signer,
|
|
809
818
|
});
|
|
810
|
-
return [4 /*yield*/, this.
|
|
819
|
+
return [4 /*yield*/, buildDepositTx(msgNativeTx, this.getClientUrl().node)];
|
|
811
820
|
case 2:
|
|
812
821
|
unsignedStdTx = _f.sent();
|
|
813
822
|
privateKey = this.getPrivateKey(walletIndex);
|
|
814
823
|
accAddress = cosmosClient.AccAddress.fromBech32(signer);
|
|
815
|
-
fee = unsignedStdTx.fee;
|
|
816
|
-
// max. gas
|
|
817
|
-
fee.gas = '25000000';
|
|
818
824
|
return [4 /*yield*/, this.cosmosClient.signAndBroadcast(unsignedStdTx, privateKey, accAddress)];
|
|
819
825
|
case 3: return [2 /*return*/, (_c = (_b = (_f.sent())) === null || _b === void 0 ? void 0 : _b.txhash) !== null && _c !== void 0 ? _c : ''];
|
|
820
826
|
}
|
|
@@ -828,7 +834,7 @@ var Client = /** @class */ (function () {
|
|
|
828
834
|
* @returns {TxHash} The transaction hash.
|
|
829
835
|
*/
|
|
830
836
|
Client.prototype.transfer = function (_a) {
|
|
831
|
-
var _b = _a.walletIndex, walletIndex = _b === void 0 ? 0 : _b, _c = _a.asset, asset = _c === void 0 ?
|
|
837
|
+
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;
|
|
832
838
|
return __awaiter(this, void 0, void 0, function () {
|
|
833
839
|
var assetBalance, fee, transferResult;
|
|
834
840
|
return __generator(this, function (_d) {
|
|
@@ -882,13 +888,16 @@ var Client = /** @class */ (function () {
|
|
|
882
888
|
return Client;
|
|
883
889
|
}());
|
|
884
890
|
|
|
885
|
-
exports.AssetRune = AssetRune;
|
|
886
891
|
exports.Client = Client;
|
|
887
892
|
exports.DECIMAL = DECIMAL;
|
|
888
893
|
exports.DEFAULT_GAS_VALUE = DEFAULT_GAS_VALUE;
|
|
894
|
+
exports.DEPOSIT_GAS_VALUE = DEPOSIT_GAS_VALUE;
|
|
889
895
|
exports.MAX_TX_COUNT = MAX_TX_COUNT;
|
|
890
896
|
exports.MsgNativeTx = MsgNativeTx;
|
|
897
|
+
exports.buildDepositTx = buildDepositTx;
|
|
891
898
|
exports.getAsset = getAsset;
|
|
899
|
+
exports.getBalance = getBalance;
|
|
900
|
+
exports.getChainId = getChainId;
|
|
892
901
|
exports.getDefaultClientUrl = getDefaultClientUrl;
|
|
893
902
|
exports.getDefaultExplorerUrls = getDefaultExplorerUrls;
|
|
894
903
|
exports.getDefaultFees = getDefaultFees;
|
package/lib/types/messages.d.ts
CHANGED
|
@@ -9,12 +9,6 @@ export declare class MsgNativeTx extends Msg {
|
|
|
9
9
|
coins: MsgCoin[];
|
|
10
10
|
memo: string;
|
|
11
11
|
signer: AccAddress;
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @param from_address
|
|
15
|
-
* @param to_address
|
|
16
|
-
* @param amount
|
|
17
|
-
*/
|
|
18
12
|
constructor(coins: MsgCoin[], memo: string, signer: AccAddress);
|
|
19
13
|
}
|
|
20
14
|
/**
|
package/lib/util.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { Address, Fees, Network, TxHash } from '@xchainjs/xchain-client';
|
|
2
|
-
import { TxLog } from '@xchainjs/xchain-cosmos';
|
|
1
|
+
import { Address, Balance, Fees, Network, TxHash } from '@xchainjs/xchain-client';
|
|
2
|
+
import { CosmosSDKClient, TxLog } from '@xchainjs/xchain-cosmos';
|
|
3
3
|
import { Asset } from '@xchainjs/xchain-util';
|
|
4
4
|
import { Msg } from 'cosmos-client';
|
|
5
|
+
import { StdTx } from 'cosmos-client/x/auth';
|
|
5
6
|
import { MsgMultiSend, MsgSend } from 'cosmos-client/x/bank';
|
|
6
7
|
import { ClientUrl, ExplorerUrls, TxData } from './types';
|
|
8
|
+
import { MsgNativeTx } from './types/messages';
|
|
7
9
|
export declare const DECIMAL = 8;
|
|
8
10
|
export declare const DEFAULT_GAS_VALUE = "2000000";
|
|
11
|
+
export declare const DEPOSIT_GAS_VALUE = "500000000";
|
|
9
12
|
export declare const MAX_TX_COUNT = 100;
|
|
10
13
|
/**
|
|
11
14
|
* Get denomination from Asset
|
|
@@ -57,6 +60,12 @@ export declare const isBroadcastSuccess: (response: unknown) => boolean;
|
|
|
57
60
|
*
|
|
58
61
|
**/
|
|
59
62
|
export declare const getPrefix: (network: Network) => "thor" | "tthor";
|
|
63
|
+
/**
|
|
64
|
+
* Get the chain id.
|
|
65
|
+
*
|
|
66
|
+
* @returns {string} The chain id based on the network.
|
|
67
|
+
*/
|
|
68
|
+
export declare const getChainId: () => string;
|
|
60
69
|
/**
|
|
61
70
|
* Register Codecs based on the prefix.
|
|
62
71
|
*
|
|
@@ -85,6 +94,29 @@ export declare const getDefaultFees: () => Fees;
|
|
|
85
94
|
* @returns {string} the transaction type.
|
|
86
95
|
*/
|
|
87
96
|
export declare const getTxType: (txData: string, encoding: 'base64' | 'hex') => string;
|
|
97
|
+
/**
|
|
98
|
+
* Structure StdTx from MsgNativeTx.
|
|
99
|
+
*
|
|
100
|
+
* @param {string} txId The transaction id.
|
|
101
|
+
* @returns {Tx} The transaction details of the given transaction id.
|
|
102
|
+
*
|
|
103
|
+
* @throws {"Invalid client url"} Thrown if the client url is an invalid one.
|
|
104
|
+
*/
|
|
105
|
+
export declare const buildDepositTx: (msgNativeTx: MsgNativeTx, nodeUrl: string) => Promise<StdTx>;
|
|
106
|
+
/**
|
|
107
|
+
* Get the balance of a given address.
|
|
108
|
+
*
|
|
109
|
+
* @param {Address} address By default, it will return the balance of the current wallet. (optional)
|
|
110
|
+
* @param {Asset} asset If not set, it will return all assets available. (optional)
|
|
111
|
+
* @param {cosmosClient} CosmosSDKClient
|
|
112
|
+
*
|
|
113
|
+
* @returns {Balance[]} The balance of the address.
|
|
114
|
+
*/
|
|
115
|
+
export declare const getBalance: ({ address, assets, cosmosClient, }: {
|
|
116
|
+
address: Address;
|
|
117
|
+
assets?: Asset[] | undefined;
|
|
118
|
+
cosmosClient: CosmosSDKClient;
|
|
119
|
+
}) => Promise<Balance[]>;
|
|
88
120
|
/**
|
|
89
121
|
* Get the client url.
|
|
90
122
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-thorchain",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.2-alpha1",
|
|
4
4
|
"description": "Custom Thorchain client and utilities used by XChainJS clients",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"THORChain",
|
|
@@ -51,6 +51,5 @@
|
|
|
51
51
|
"@xchainjs/xchain-util": "^0.3.0",
|
|
52
52
|
"axios": "^0.21.0",
|
|
53
53
|
"cosmos-client": "0.39.2"
|
|
54
|
-
}
|
|
55
|
-
"gitHead": "6e473642780c4380a7a0774027ac1196e1648a2c"
|
|
54
|
+
}
|
|
56
55
|
}
|