@xchainjs/xchain-thorchain 0.27.5 → 0.27.7
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/README.md +22 -3
- package/lib/client.d.ts +3 -3
- package/lib/const.d.ts +49 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.esm.js +118 -60
- package/lib/index.js +130 -63
- package/lib/types/messages.d.ts +2 -2
- package/lib/{util.d.ts → utils.d.ts} +16 -14
- package/package.json +11 -9
package/README.md
CHANGED
|
@@ -16,14 +16,13 @@ yarn add @xchainjs/xchain-client @xchainjs/xchain-crypto @xchainjs/xchain-util @
|
|
|
16
16
|
|
|
17
17
|
Important note: Make sure to install same version of `@cosmos-client/core` as `xchain-thorchain` is using (currently `@cosmos-client/core@0.45.1` ). In other case things might break.
|
|
18
18
|
|
|
19
|
-
|
|
20
19
|
## Documentation
|
|
21
20
|
|
|
22
21
|
### [`xchain thorchain`](http://docs.xchainjs.org/xchain-client/xchain-thorchain/)
|
|
22
|
+
|
|
23
23
|
[`How xchain-thorchain works`](http://docs.xchainjs.org/xchain-client/xchain-thorchain/how-it-works.html)\
|
|
24
24
|
[`How to use xchain-thorchain`](http://docs.xchainjs.org/xchain-client/xchain-thorchain/how-to-use.html)
|
|
25
25
|
|
|
26
|
-
|
|
27
26
|
For more examples check out tests in `./__tests__/client.test.ts`
|
|
28
27
|
|
|
29
28
|
## Service Providers
|
|
@@ -56,5 +55,25 @@ In order for this library to de/serialize proto3 structures, you can use the fol
|
|
|
56
55
|
yarn run pbts src/types/proto/MsgCompiled.js -o src/types/proto/MsgCompiled.d.ts
|
|
57
56
|
```
|
|
58
57
|
|
|
59
|
-
Alternatively, you can run the convenience script: `genMsgs.sh`, which will overwrite the proto/js files in types/proto. This should only be done and checked in if changes were made to the upstream Msg in the THORNode repo.
|
|
58
|
+
Alternatively, you can run the convenience script: `genMsgs.sh`, which will overwrite the proto/js files in types/proto. This should only be done and checked in if changes were made to the upstream Msg in the THORNode repo.
|
|
59
|
+
|
|
60
|
+
### Setting Headers for Nine Realms endpoints
|
|
61
|
+
|
|
62
|
+
If you plan on using the publically accessible endpoints provided by Nine Realms(listed below), ensure that you add a valid 'x-client-id' to all requests
|
|
63
|
+
|
|
64
|
+
- https://midgard.ninerealms.com
|
|
65
|
+
- https://haskoin.ninerealms.com (BTC/BCH/LTC)
|
|
66
|
+
- https://thornode.ninerealms.com
|
|
67
|
+
|
|
68
|
+
Example
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import cosmosclient from '@cosmos-client/core'
|
|
72
|
+
import axios from 'axios'
|
|
73
|
+
import { register9Rheader } from '@xchainjs/xchain-util'
|
|
74
|
+
|
|
75
|
+
register9Rheader(axios)
|
|
76
|
+
register9Rheader(cosmosclient.config.globalAxios)
|
|
77
|
+
```
|
|
60
78
|
|
|
79
|
+
For a complete example please see this [test](https://github.com/xchainjs/xchainjs-lib/blob/master/packages/xchain-thorchain-amm/__e2e__/wallet.e2e.ts)
|
package/lib/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import cosmosclient from '@cosmos-client/core';
|
|
2
2
|
import { Balance, BaseXChainClient, Fees, Network, Tx, TxHash, TxHistoryParams, TxParams, TxsPage, XChainClient, XChainClientParams } from '@xchainjs/xchain-client';
|
|
3
3
|
import { CosmosSDKClient, RPCTxResult } from '@xchainjs/xchain-cosmos';
|
|
4
4
|
import { Address, Asset } from '@xchainjs/xchain-util';
|
|
@@ -33,7 +33,7 @@ declare class Client extends BaseXChainClient implements ThorchainClient, XChain
|
|
|
33
33
|
*
|
|
34
34
|
* @throws {"Invalid phrase"} Thrown if the given phase is invalid.
|
|
35
35
|
*/
|
|
36
|
-
constructor({ network, phrase, clientUrl, explorerUrls, rootDerivationPaths, chainIds,
|
|
36
|
+
constructor({ network, phrase, clientUrl, explorerUrls, rootDerivationPaths, chainIds, }: XChainClientParams & ThorchainClientParams);
|
|
37
37
|
/**
|
|
38
38
|
* Set/update the current network.
|
|
39
39
|
*
|
|
@@ -115,7 +115,7 @@ declare class Client extends BaseXChainClient implements ThorchainClient, XChain
|
|
|
115
115
|
* @throws {"Phrase not set"}
|
|
116
116
|
* Throws an error if phrase has not been set before
|
|
117
117
|
* */
|
|
118
|
-
getPrivateKey(index?: number): proto.cosmos.crypto.secp256k1.PrivKey;
|
|
118
|
+
getPrivateKey(index?: number): cosmosclient.proto.cosmos.crypto.secp256k1.PrivKey;
|
|
119
119
|
/**
|
|
120
120
|
* Get public key
|
|
121
121
|
*
|
package/lib/const.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Asset, Chain } from '@xchainjs/xchain-util/lib';
|
|
2
|
+
import { ExplorerUrls } from './types';
|
|
3
|
+
export declare const DECIMAL = 8;
|
|
4
|
+
export declare const DEFAULT_GAS_ADJUSTMENT = 2;
|
|
5
|
+
export declare const DEFAULT_GAS_LIMIT_VALUE = "4000000";
|
|
6
|
+
export declare const DEPOSIT_GAS_LIMIT_VALUE = "600000000";
|
|
7
|
+
export declare const MAX_TX_COUNT = 100;
|
|
8
|
+
export declare const RUNE_SYMBOL = "\u16B1";
|
|
9
|
+
export declare const defaultExplorerUrls: ExplorerUrls;
|
|
10
|
+
/**
|
|
11
|
+
* Chain identifier for Thorchain
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
export declare const THORChain: Chain;
|
|
15
|
+
/**
|
|
16
|
+
* Base "chain" asset for RUNE-67C on Binance test net.
|
|
17
|
+
*
|
|
18
|
+
* Based on definition in Thorchain `common`
|
|
19
|
+
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
20
|
+
*/
|
|
21
|
+
export declare const AssetRune67C: Asset;
|
|
22
|
+
/**
|
|
23
|
+
* Base "chain" asset for RUNE-B1A on Binance main net.
|
|
24
|
+
*
|
|
25
|
+
* Based on definition in Thorchain `common`
|
|
26
|
+
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
27
|
+
*/
|
|
28
|
+
export declare const AssetRuneB1A: Asset;
|
|
29
|
+
/**
|
|
30
|
+
* Base "chain" asset on thorchain main net.
|
|
31
|
+
*
|
|
32
|
+
* Based on definition in Thorchain `common`
|
|
33
|
+
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
34
|
+
*/
|
|
35
|
+
export declare const AssetRuneNative: Asset;
|
|
36
|
+
/**
|
|
37
|
+
* Base "chain" asset for RUNE on ethereum main net.
|
|
38
|
+
*
|
|
39
|
+
* Based on definition in Thorchain `common`
|
|
40
|
+
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
41
|
+
*/
|
|
42
|
+
export declare const AssetRuneERC20: Asset;
|
|
43
|
+
/**
|
|
44
|
+
* Base "chain" asset for RUNE on ethereum main net.
|
|
45
|
+
*
|
|
46
|
+
* Based on definition in Thorchain `common`
|
|
47
|
+
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
48
|
+
*/
|
|
49
|
+
export declare const AssetRuneERC20Testnet: Asset;
|
package/lib/index.d.ts
CHANGED
package/lib/index.esm.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Network, TxType, singleFee, FeeType, BaseXChainClient } from '@xchainjs/xchain-client';
|
|
3
|
-
import { CosmosSDKClient } from '@xchainjs/xchain-cosmos';
|
|
4
|
-
import {
|
|
1
|
+
import cosmosclient from '@cosmos-client/core';
|
|
2
|
+
import { Network as Network$1, TxType, singleFee, FeeType, BaseXChainClient } from '@xchainjs/xchain-client';
|
|
3
|
+
import { GAIAChain, CosmosSDKClient } from '@xchainjs/xchain-cosmos';
|
|
4
|
+
import { assetToString, isSynthAsset, assetFromString, baseAmount, assetToBase, assetAmount } from '@xchainjs/xchain-util';
|
|
5
5
|
import axios from 'axios';
|
|
6
|
+
import { Network } from '@xchainjs/xchain-client/lib';
|
|
6
7
|
import { decode } from 'bech32-buffer';
|
|
7
8
|
|
|
8
9
|
/*! *****************************************************************************
|
|
@@ -4260,6 +4261,84 @@ Long.fromBytesBE = function fromBytesBE(bytes, unsigned) {
|
|
|
4260
4261
|
);
|
|
4261
4262
|
};
|
|
4262
4263
|
|
|
4264
|
+
const DEFAULT_EXPLORER_URL = 'https://viewblock.io/thorchain';
|
|
4265
|
+
const txUrl = `${DEFAULT_EXPLORER_URL}/tx`;
|
|
4266
|
+
const addressUrl = `${DEFAULT_EXPLORER_URL}/address`;
|
|
4267
|
+
const RUNE_TICKER = 'RUNE';
|
|
4268
|
+
const DECIMAL = 8;
|
|
4269
|
+
const DEFAULT_GAS_ADJUSTMENT = 2;
|
|
4270
|
+
const DEFAULT_GAS_LIMIT_VALUE = '4000000';
|
|
4271
|
+
const DEPOSIT_GAS_LIMIT_VALUE = '600000000';
|
|
4272
|
+
const MAX_TX_COUNT = 100;
|
|
4273
|
+
const RUNE_SYMBOL = 'ᚱ';
|
|
4274
|
+
const defaultExplorerUrls = {
|
|
4275
|
+
root: {
|
|
4276
|
+
[Network.Testnet]: `${DEFAULT_EXPLORER_URL}?network=testnet`,
|
|
4277
|
+
[Network.Stagenet]: `${DEFAULT_EXPLORER_URL}?network=stagenet`,
|
|
4278
|
+
[Network.Mainnet]: DEFAULT_EXPLORER_URL,
|
|
4279
|
+
},
|
|
4280
|
+
tx: {
|
|
4281
|
+
[Network.Testnet]: txUrl,
|
|
4282
|
+
[Network.Stagenet]: txUrl,
|
|
4283
|
+
[Network.Mainnet]: txUrl,
|
|
4284
|
+
},
|
|
4285
|
+
address: {
|
|
4286
|
+
[Network.Testnet]: addressUrl,
|
|
4287
|
+
[Network.Stagenet]: addressUrl,
|
|
4288
|
+
[Network.Mainnet]: addressUrl,
|
|
4289
|
+
},
|
|
4290
|
+
};
|
|
4291
|
+
/**
|
|
4292
|
+
* Chain identifier for Thorchain
|
|
4293
|
+
*
|
|
4294
|
+
*/
|
|
4295
|
+
const THORChain = 'THOR';
|
|
4296
|
+
/**
|
|
4297
|
+
* Base "chain" asset for RUNE-67C on Binance test net.
|
|
4298
|
+
*
|
|
4299
|
+
* Based on definition in Thorchain `common`
|
|
4300
|
+
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
4301
|
+
*/
|
|
4302
|
+
const AssetRune67C = { chain: 'BNB', symbol: 'RUNE-67C', ticker: RUNE_TICKER, synth: false };
|
|
4303
|
+
/**
|
|
4304
|
+
* Base "chain" asset for RUNE-B1A on Binance main net.
|
|
4305
|
+
*
|
|
4306
|
+
* Based on definition in Thorchain `common`
|
|
4307
|
+
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
4308
|
+
*/
|
|
4309
|
+
const AssetRuneB1A = { chain: 'BNB', symbol: 'RUNE-B1A', ticker: RUNE_TICKER, synth: false };
|
|
4310
|
+
/**
|
|
4311
|
+
* Base "chain" asset on thorchain main net.
|
|
4312
|
+
*
|
|
4313
|
+
* Based on definition in Thorchain `common`
|
|
4314
|
+
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
4315
|
+
*/
|
|
4316
|
+
const AssetRuneNative = { chain: THORChain, symbol: RUNE_TICKER, ticker: RUNE_TICKER, synth: false };
|
|
4317
|
+
/**
|
|
4318
|
+
* Base "chain" asset for RUNE on ethereum main net.
|
|
4319
|
+
*
|
|
4320
|
+
* Based on definition in Thorchain `common`
|
|
4321
|
+
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
4322
|
+
*/
|
|
4323
|
+
const AssetRuneERC20 = {
|
|
4324
|
+
chain: 'ETH',
|
|
4325
|
+
symbol: `${RUNE_TICKER}-0x3155ba85d5f96b2d030a4966af206230e46849cb`,
|
|
4326
|
+
ticker: RUNE_TICKER,
|
|
4327
|
+
synth: false,
|
|
4328
|
+
};
|
|
4329
|
+
/**
|
|
4330
|
+
* Base "chain" asset for RUNE on ethereum main net.
|
|
4331
|
+
*
|
|
4332
|
+
* Based on definition in Thorchain `common`
|
|
4333
|
+
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
4334
|
+
*/
|
|
4335
|
+
const AssetRuneERC20Testnet = {
|
|
4336
|
+
chain: 'ETH',
|
|
4337
|
+
symbol: `${RUNE_TICKER}-0xd601c6A3a36721320573885A8d8420746dA3d7A0`,
|
|
4338
|
+
ticker: RUNE_TICKER,
|
|
4339
|
+
synth: false,
|
|
4340
|
+
};
|
|
4341
|
+
|
|
4263
4342
|
var aspromise = asPromise;
|
|
4264
4343
|
|
|
4265
4344
|
/**
|
|
@@ -9599,33 +9678,16 @@ $root.cosmos = (function() {
|
|
|
9599
9678
|
|
|
9600
9679
|
var MsgCompiled = $root;
|
|
9601
9680
|
|
|
9602
|
-
const DECIMAL = 8;
|
|
9603
|
-
const DEFAULT_GAS_ADJUSTMENT = 2;
|
|
9604
|
-
const DEFAULT_GAS_LIMIT_VALUE = '4000000';
|
|
9605
|
-
const DEPOSIT_GAS_LIMIT_VALUE = '600000000';
|
|
9606
|
-
const MAX_TX_COUNT = 100;
|
|
9607
9681
|
const DENOM_RUNE_NATIVE = 'rune';
|
|
9608
|
-
const DEFAULT_EXPLORER_URL = 'https://viewblock.io/thorchain';
|
|
9609
|
-
const txUrl = `${DEFAULT_EXPLORER_URL}/tx`;
|
|
9610
|
-
const addressUrl = `${DEFAULT_EXPLORER_URL}/address`;
|
|
9611
|
-
const defaultExplorerUrls = {
|
|
9612
|
-
root: {
|
|
9613
|
-
[Network.Testnet]: `${DEFAULT_EXPLORER_URL}?network=testnet`,
|
|
9614
|
-
[Network.Stagenet]: `${DEFAULT_EXPLORER_URL}?network=stagenet`,
|
|
9615
|
-
[Network.Mainnet]: DEFAULT_EXPLORER_URL,
|
|
9616
|
-
},
|
|
9617
|
-
tx: {
|
|
9618
|
-
[Network.Testnet]: txUrl,
|
|
9619
|
-
[Network.Stagenet]: txUrl,
|
|
9620
|
-
[Network.Mainnet]: txUrl,
|
|
9621
|
-
},
|
|
9622
|
-
address: {
|
|
9623
|
-
[Network.Testnet]: addressUrl,
|
|
9624
|
-
[Network.Stagenet]: addressUrl,
|
|
9625
|
-
[Network.Mainnet]: addressUrl,
|
|
9626
|
-
},
|
|
9627
|
-
};
|
|
9628
9682
|
/**
|
|
9683
|
+
* Checks whether an asset is `AssetRuneNative`
|
|
9684
|
+
*
|
|
9685
|
+
* @param {Asset} asset
|
|
9686
|
+
* @returns {boolean} `true` or `false`
|
|
9687
|
+
*/
|
|
9688
|
+
const isAssetRuneNative = (asset) => assetToString(asset) === assetToString(AssetRuneNative);
|
|
9689
|
+
/**
|
|
9690
|
+
|
|
9629
9691
|
* Get denomination from Asset
|
|
9630
9692
|
*
|
|
9631
9693
|
* @param {Asset} asset
|
|
@@ -9668,11 +9730,11 @@ const isBroadcastSuccess = (response) => typeof response === 'object' &&
|
|
|
9668
9730
|
**/
|
|
9669
9731
|
const getPrefix = (network) => {
|
|
9670
9732
|
switch (network) {
|
|
9671
|
-
case Network.Mainnet:
|
|
9733
|
+
case Network$1.Mainnet:
|
|
9672
9734
|
return 'thor';
|
|
9673
|
-
case Network.Stagenet:
|
|
9735
|
+
case Network$1.Stagenet:
|
|
9674
9736
|
return 'sthor';
|
|
9675
|
-
case Network.Testnet:
|
|
9737
|
+
case Network$1.Testnet:
|
|
9676
9738
|
return 'tthor';
|
|
9677
9739
|
}
|
|
9678
9740
|
};
|
|
@@ -9764,13 +9826,13 @@ const getChainId = (nodeUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
9764
9826
|
* @returns
|
|
9765
9827
|
*/
|
|
9766
9828
|
const buildUnsignedTx = ({ cosmosSdk, txBody, signerPubkey, sequence, gasLimit, }) => {
|
|
9767
|
-
const authInfo = new proto.cosmos.tx.v1beta1.AuthInfo({
|
|
9829
|
+
const authInfo = new cosmosclient.proto.cosmos.tx.v1beta1.AuthInfo({
|
|
9768
9830
|
signer_infos: [
|
|
9769
9831
|
{
|
|
9770
9832
|
public_key: signerPubkey,
|
|
9771
9833
|
mode_info: {
|
|
9772
9834
|
single: {
|
|
9773
|
-
mode: proto.cosmos.tx.signing.v1beta1.SignMode.SIGN_MODE_DIRECT,
|
|
9835
|
+
mode: cosmosclient.proto.cosmos.tx.signing.v1beta1.SignMode.SIGN_MODE_DIRECT,
|
|
9774
9836
|
},
|
|
9775
9837
|
},
|
|
9776
9838
|
sequence: sequence,
|
|
@@ -9801,7 +9863,7 @@ const getEstimatedGas = ({ cosmosSDKClient, txBody, privKey, accountNumber, acco
|
|
|
9801
9863
|
});
|
|
9802
9864
|
const signDocBytes = txBuilder.signDocBytes(accountNumber);
|
|
9803
9865
|
txBuilder.addSignature(privKey.sign(signDocBytes));
|
|
9804
|
-
const resp = yield rest.tx.simulate(cosmosSDKClient.sdk, { tx_bytes: txBuilder.txBytes() });
|
|
9866
|
+
const resp = yield cosmosclient.rest.tx.simulate(cosmosSDKClient.sdk, { tx_bytes: txBuilder.txBytes() });
|
|
9805
9867
|
const estimatedGas = (_d = (_c = (_b = resp.data) === null || _b === void 0 ? void 0 : _b.gas_info) === null || _c === void 0 ? void 0 : _c.gas_used) !== null && _d !== void 0 ? _d : null;
|
|
9806
9868
|
if (!estimatedGas) {
|
|
9807
9869
|
throw new Error('Could not get data of estimated gas');
|
|
@@ -9832,7 +9894,7 @@ const buildDepositTx = ({ msgNativeTx, nodeUrl, chainId, }) => __awaiter(void 0,
|
|
|
9832
9894
|
signer: signerDecoded.data,
|
|
9833
9895
|
};
|
|
9834
9896
|
const depositMsg = MsgCompiled.types.MsgDeposit.fromObject(msgDepositObj);
|
|
9835
|
-
return new proto.cosmos.tx.v1beta1.TxBody({
|
|
9897
|
+
return new cosmosclient.proto.cosmos.tx.v1beta1.TxBody({
|
|
9836
9898
|
messages: [cosmosclient.codec.instanceToProtoAny(depositMsg)],
|
|
9837
9899
|
memo: msgNativeTx.memo,
|
|
9838
9900
|
});
|
|
@@ -9866,7 +9928,7 @@ const buildTransferTx = ({ fromAddress, toAddress, assetAmount, assetDenom, memo
|
|
|
9866
9928
|
],
|
|
9867
9929
|
};
|
|
9868
9930
|
const transferMsg = MsgCompiled.types.MsgSend.fromObject(transferObj);
|
|
9869
|
-
return new proto.cosmos.tx.v1beta1.TxBody({
|
|
9931
|
+
return new cosmosclient.proto.cosmos.tx.v1beta1.TxBody({
|
|
9870
9932
|
messages: [cosmosclient.codec.instanceToProtoAny(transferMsg)],
|
|
9871
9933
|
memo,
|
|
9872
9934
|
});
|
|
@@ -9908,11 +9970,11 @@ const getExplorerUrl = ({ root }, network) => root[network];
|
|
|
9908
9970
|
const getExplorerAddressUrl = ({ urls, network, address, }) => {
|
|
9909
9971
|
const url = `${urls.address[network]}/${address}`;
|
|
9910
9972
|
switch (network) {
|
|
9911
|
-
case Network.Mainnet:
|
|
9973
|
+
case Network$1.Mainnet:
|
|
9912
9974
|
return url;
|
|
9913
|
-
case Network.Stagenet:
|
|
9975
|
+
case Network$1.Stagenet:
|
|
9914
9976
|
return `${url}?network=stagenet`;
|
|
9915
|
-
case Network.Testnet:
|
|
9977
|
+
case Network$1.Testnet:
|
|
9916
9978
|
return `${url}?network=testnet`;
|
|
9917
9979
|
}
|
|
9918
9980
|
};
|
|
@@ -9927,11 +9989,11 @@ const getExplorerAddressUrl = ({ urls, network, address, }) => {
|
|
|
9927
9989
|
const getExplorerTxUrl = ({ urls, network, txID, }) => {
|
|
9928
9990
|
const url = `${urls.tx[network]}/${txID}`;
|
|
9929
9991
|
switch (network) {
|
|
9930
|
-
case Network.Mainnet:
|
|
9992
|
+
case Network$1.Mainnet:
|
|
9931
9993
|
return url;
|
|
9932
|
-
case Network.Stagenet:
|
|
9994
|
+
case Network$1.Stagenet:
|
|
9933
9995
|
return `${url}?network=stagenet`;
|
|
9934
|
-
case Network.Testnet:
|
|
9996
|
+
case Network$1.Testnet:
|
|
9935
9997
|
return `${url}?network=testnet`;
|
|
9936
9998
|
}
|
|
9937
9999
|
};
|
|
@@ -9959,29 +10021,29 @@ class Client extends BaseXChainClient {
|
|
|
9959
10021
|
*
|
|
9960
10022
|
* @throws {"Invalid phrase"} Thrown if the given phase is invalid.
|
|
9961
10023
|
*/
|
|
9962
|
-
constructor({ network = Network.Mainnet, phrase, clientUrl = {
|
|
9963
|
-
[Network.Testnet]: {
|
|
10024
|
+
constructor({ network = Network$1.Mainnet, phrase, clientUrl = {
|
|
10025
|
+
[Network$1.Testnet]: {
|
|
9964
10026
|
node: 'deprecated',
|
|
9965
10027
|
rpc: 'deprecated',
|
|
9966
10028
|
},
|
|
9967
|
-
[Network.Stagenet]: {
|
|
10029
|
+
[Network$1.Stagenet]: {
|
|
9968
10030
|
node: 'https://stagenet-thornode.ninerealms.com',
|
|
9969
10031
|
rpc: 'https://stagenet-rpc.ninerealms.com',
|
|
9970
10032
|
},
|
|
9971
|
-
[Network.Mainnet]: {
|
|
10033
|
+
[Network$1.Mainnet]: {
|
|
9972
10034
|
node: 'https://thornode.ninerealms.com',
|
|
9973
10035
|
rpc: 'https://rpc.ninerealms.com',
|
|
9974
10036
|
},
|
|
9975
10037
|
}, explorerUrls = defaultExplorerUrls, rootDerivationPaths = {
|
|
9976
|
-
[Network.Mainnet]: "44'/931'/0'/0/",
|
|
9977
|
-
[Network.Stagenet]: "44'/931'/0'/0/",
|
|
9978
|
-
[Network.Testnet]: "44'/931'/0'/0/",
|
|
10038
|
+
[Network$1.Mainnet]: "44'/931'/0'/0/",
|
|
10039
|
+
[Network$1.Stagenet]: "44'/931'/0'/0/",
|
|
10040
|
+
[Network$1.Testnet]: "44'/931'/0'/0/",
|
|
9979
10041
|
}, chainIds = {
|
|
9980
|
-
[Network.Mainnet]: 'thorchain-mainnet-v1',
|
|
9981
|
-
[Network.Stagenet]: 'thorchain-stagenet-v2',
|
|
9982
|
-
[Network.Testnet]: 'deprecated',
|
|
9983
|
-
},
|
|
9984
|
-
super(
|
|
10042
|
+
[Network$1.Mainnet]: 'thorchain-mainnet-v1',
|
|
10043
|
+
[Network$1.Stagenet]: 'thorchain-stagenet-v2',
|
|
10044
|
+
[Network$1.Testnet]: 'deprecated',
|
|
10045
|
+
}, }) {
|
|
10046
|
+
super(GAIAChain, { network, rootDerivationPaths, phrase });
|
|
9985
10047
|
/**
|
|
9986
10048
|
* Get transaction history of a given address with pagination options.
|
|
9987
10049
|
* By default it will return the transaction history of the current wallet.
|
|
@@ -10038,14 +10100,10 @@ class Client extends BaseXChainClient {
|
|
|
10038
10100
|
this.chainIds = chainIds;
|
|
10039
10101
|
registerSendCodecs();
|
|
10040
10102
|
registerDepositCodecs();
|
|
10041
|
-
if (this.clientUrl[Network.Mainnet].node.includes('ninerealms.com') && !this.customRequestHeaders['x-client-id']) {
|
|
10042
|
-
this.customRequestHeaders['x-client-id'] = 'xchainjs-client';
|
|
10043
|
-
}
|
|
10044
10103
|
this.cosmosClient = new CosmosSDKClient({
|
|
10045
10104
|
server: this.getClientUrl().node,
|
|
10046
10105
|
chainId: this.getChainId(network),
|
|
10047
10106
|
prefix: getPrefix(network),
|
|
10048
|
-
headers: this.customRequestHeaders,
|
|
10049
10107
|
});
|
|
10050
10108
|
}
|
|
10051
10109
|
/**
|
|
@@ -10471,4 +10529,4 @@ const msgNativeTxFromJson = (value) => {
|
|
|
10471
10529
|
return new MsgNativeTx(value.coins, value.memo, cosmosclient.AccAddress.fromString(value.signer));
|
|
10472
10530
|
};
|
|
10473
10531
|
|
|
10474
|
-
export { Client, DECIMAL, DEFAULT_GAS_ADJUSTMENT, DEFAULT_GAS_LIMIT_VALUE, DEPOSIT_GAS_LIMIT_VALUE, MAX_TX_COUNT, MsgNativeTx, assetFromDenom, buildDepositTx, buildTransferTx, buildUnsignedTx, defaultExplorerUrls, getAccount, getBalance, getChainId, getDefaultFees, getDenom, getDepositTxDataFromLogs, getEstimatedGas, getExplorerAddressUrl, getExplorerTxUrl, getExplorerUrl, getPrefix, getSequence, getTxType, isBroadcastSuccess, msgNativeTxFromJson, registerDepositCodecs, registerSendCodecs };
|
|
10532
|
+
export { AssetRune67C, AssetRuneB1A, AssetRuneERC20, AssetRuneERC20Testnet, AssetRuneNative, Client, DECIMAL, DEFAULT_GAS_ADJUSTMENT, DEFAULT_GAS_LIMIT_VALUE, DEPOSIT_GAS_LIMIT_VALUE, MAX_TX_COUNT, MsgNativeTx, RUNE_SYMBOL, THORChain, assetFromDenom, buildDepositTx, buildTransferTx, buildUnsignedTx, defaultExplorerUrls, getAccount, getBalance, getChainId, getDefaultFees, getDenom, getDepositTxDataFromLogs, getEstimatedGas, getExplorerAddressUrl, getExplorerTxUrl, getExplorerUrl, getPrefix, getSequence, getTxType, isAssetRuneNative, isBroadcastSuccess, msgNativeTxFromJson, registerDepositCodecs, registerSendCodecs };
|
package/lib/index.js
CHANGED
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var cosmosclient = require('@cosmos-client/core');
|
|
6
6
|
var xchainClient = require('@xchainjs/xchain-client');
|
|
7
7
|
var xchainCosmos = require('@xchainjs/xchain-cosmos');
|
|
8
8
|
var xchainUtil = require('@xchainjs/xchain-util');
|
|
9
9
|
var axios = require('axios');
|
|
10
|
+
var lib = require('@xchainjs/xchain-client/lib');
|
|
10
11
|
var bech32Buffer = require('bech32-buffer');
|
|
11
12
|
|
|
12
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
14
|
|
|
15
|
+
var cosmosclient__default = /*#__PURE__*/_interopDefaultLegacy(cosmosclient);
|
|
14
16
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
15
17
|
|
|
16
18
|
/*! *****************************************************************************
|
|
@@ -4268,6 +4270,84 @@ Long.fromBytesBE = function fromBytesBE(bytes, unsigned) {
|
|
|
4268
4270
|
);
|
|
4269
4271
|
};
|
|
4270
4272
|
|
|
4273
|
+
const DEFAULT_EXPLORER_URL = 'https://viewblock.io/thorchain';
|
|
4274
|
+
const txUrl = `${DEFAULT_EXPLORER_URL}/tx`;
|
|
4275
|
+
const addressUrl = `${DEFAULT_EXPLORER_URL}/address`;
|
|
4276
|
+
const RUNE_TICKER = 'RUNE';
|
|
4277
|
+
const DECIMAL = 8;
|
|
4278
|
+
const DEFAULT_GAS_ADJUSTMENT = 2;
|
|
4279
|
+
const DEFAULT_GAS_LIMIT_VALUE = '4000000';
|
|
4280
|
+
const DEPOSIT_GAS_LIMIT_VALUE = '600000000';
|
|
4281
|
+
const MAX_TX_COUNT = 100;
|
|
4282
|
+
const RUNE_SYMBOL = 'ᚱ';
|
|
4283
|
+
const defaultExplorerUrls = {
|
|
4284
|
+
root: {
|
|
4285
|
+
[lib.Network.Testnet]: `${DEFAULT_EXPLORER_URL}?network=testnet`,
|
|
4286
|
+
[lib.Network.Stagenet]: `${DEFAULT_EXPLORER_URL}?network=stagenet`,
|
|
4287
|
+
[lib.Network.Mainnet]: DEFAULT_EXPLORER_URL,
|
|
4288
|
+
},
|
|
4289
|
+
tx: {
|
|
4290
|
+
[lib.Network.Testnet]: txUrl,
|
|
4291
|
+
[lib.Network.Stagenet]: txUrl,
|
|
4292
|
+
[lib.Network.Mainnet]: txUrl,
|
|
4293
|
+
},
|
|
4294
|
+
address: {
|
|
4295
|
+
[lib.Network.Testnet]: addressUrl,
|
|
4296
|
+
[lib.Network.Stagenet]: addressUrl,
|
|
4297
|
+
[lib.Network.Mainnet]: addressUrl,
|
|
4298
|
+
},
|
|
4299
|
+
};
|
|
4300
|
+
/**
|
|
4301
|
+
* Chain identifier for Thorchain
|
|
4302
|
+
*
|
|
4303
|
+
*/
|
|
4304
|
+
const THORChain = 'THOR';
|
|
4305
|
+
/**
|
|
4306
|
+
* Base "chain" asset for RUNE-67C on Binance test net.
|
|
4307
|
+
*
|
|
4308
|
+
* Based on definition in Thorchain `common`
|
|
4309
|
+
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
4310
|
+
*/
|
|
4311
|
+
const AssetRune67C = { chain: 'BNB', symbol: 'RUNE-67C', ticker: RUNE_TICKER, synth: false };
|
|
4312
|
+
/**
|
|
4313
|
+
* Base "chain" asset for RUNE-B1A on Binance main net.
|
|
4314
|
+
*
|
|
4315
|
+
* Based on definition in Thorchain `common`
|
|
4316
|
+
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
4317
|
+
*/
|
|
4318
|
+
const AssetRuneB1A = { chain: 'BNB', symbol: 'RUNE-B1A', ticker: RUNE_TICKER, synth: false };
|
|
4319
|
+
/**
|
|
4320
|
+
* Base "chain" asset on thorchain main net.
|
|
4321
|
+
*
|
|
4322
|
+
* Based on definition in Thorchain `common`
|
|
4323
|
+
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
4324
|
+
*/
|
|
4325
|
+
const AssetRuneNative = { chain: THORChain, symbol: RUNE_TICKER, ticker: RUNE_TICKER, synth: false };
|
|
4326
|
+
/**
|
|
4327
|
+
* Base "chain" asset for RUNE on ethereum main net.
|
|
4328
|
+
*
|
|
4329
|
+
* Based on definition in Thorchain `common`
|
|
4330
|
+
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
4331
|
+
*/
|
|
4332
|
+
const AssetRuneERC20 = {
|
|
4333
|
+
chain: 'ETH',
|
|
4334
|
+
symbol: `${RUNE_TICKER}-0x3155ba85d5f96b2d030a4966af206230e46849cb`,
|
|
4335
|
+
ticker: RUNE_TICKER,
|
|
4336
|
+
synth: false,
|
|
4337
|
+
};
|
|
4338
|
+
/**
|
|
4339
|
+
* Base "chain" asset for RUNE on ethereum main net.
|
|
4340
|
+
*
|
|
4341
|
+
* Based on definition in Thorchain `common`
|
|
4342
|
+
* @see https://gitlab.com/thorchain/thornode/-/blob/master/common/asset.go#L12-24
|
|
4343
|
+
*/
|
|
4344
|
+
const AssetRuneERC20Testnet = {
|
|
4345
|
+
chain: 'ETH',
|
|
4346
|
+
symbol: `${RUNE_TICKER}-0xd601c6A3a36721320573885A8d8420746dA3d7A0`,
|
|
4347
|
+
ticker: RUNE_TICKER,
|
|
4348
|
+
synth: false,
|
|
4349
|
+
};
|
|
4350
|
+
|
|
4271
4351
|
var aspromise = asPromise;
|
|
4272
4352
|
|
|
4273
4353
|
/**
|
|
@@ -9607,40 +9687,23 @@ $root.cosmos = (function() {
|
|
|
9607
9687
|
|
|
9608
9688
|
var MsgCompiled = $root;
|
|
9609
9689
|
|
|
9610
|
-
const DECIMAL = 8;
|
|
9611
|
-
const DEFAULT_GAS_ADJUSTMENT = 2;
|
|
9612
|
-
const DEFAULT_GAS_LIMIT_VALUE = '4000000';
|
|
9613
|
-
const DEPOSIT_GAS_LIMIT_VALUE = '600000000';
|
|
9614
|
-
const MAX_TX_COUNT = 100;
|
|
9615
9690
|
const DENOM_RUNE_NATIVE = 'rune';
|
|
9616
|
-
const DEFAULT_EXPLORER_URL = 'https://viewblock.io/thorchain';
|
|
9617
|
-
const txUrl = `${DEFAULT_EXPLORER_URL}/tx`;
|
|
9618
|
-
const addressUrl = `${DEFAULT_EXPLORER_URL}/address`;
|
|
9619
|
-
const defaultExplorerUrls = {
|
|
9620
|
-
root: {
|
|
9621
|
-
[xchainClient.Network.Testnet]: `${DEFAULT_EXPLORER_URL}?network=testnet`,
|
|
9622
|
-
[xchainClient.Network.Stagenet]: `${DEFAULT_EXPLORER_URL}?network=stagenet`,
|
|
9623
|
-
[xchainClient.Network.Mainnet]: DEFAULT_EXPLORER_URL,
|
|
9624
|
-
},
|
|
9625
|
-
tx: {
|
|
9626
|
-
[xchainClient.Network.Testnet]: txUrl,
|
|
9627
|
-
[xchainClient.Network.Stagenet]: txUrl,
|
|
9628
|
-
[xchainClient.Network.Mainnet]: txUrl,
|
|
9629
|
-
},
|
|
9630
|
-
address: {
|
|
9631
|
-
[xchainClient.Network.Testnet]: addressUrl,
|
|
9632
|
-
[xchainClient.Network.Stagenet]: addressUrl,
|
|
9633
|
-
[xchainClient.Network.Mainnet]: addressUrl,
|
|
9634
|
-
},
|
|
9635
|
-
};
|
|
9636
9691
|
/**
|
|
9692
|
+
* Checks whether an asset is `AssetRuneNative`
|
|
9693
|
+
*
|
|
9694
|
+
* @param {Asset} asset
|
|
9695
|
+
* @returns {boolean} `true` or `false`
|
|
9696
|
+
*/
|
|
9697
|
+
const isAssetRuneNative = (asset) => xchainUtil.assetToString(asset) === xchainUtil.assetToString(AssetRuneNative);
|
|
9698
|
+
/**
|
|
9699
|
+
|
|
9637
9700
|
* Get denomination from Asset
|
|
9638
9701
|
*
|
|
9639
9702
|
* @param {Asset} asset
|
|
9640
9703
|
* @returns {string} The denomination of the given asset.
|
|
9641
9704
|
*/
|
|
9642
9705
|
const getDenom = (asset) => {
|
|
9643
|
-
if (
|
|
9706
|
+
if (isAssetRuneNative(asset))
|
|
9644
9707
|
return DENOM_RUNE_NATIVE;
|
|
9645
9708
|
if (xchainUtil.isSynthAsset(asset))
|
|
9646
9709
|
return xchainUtil.assetToString(asset).toLowerCase();
|
|
@@ -9654,7 +9717,7 @@ const getDenom = (asset) => {
|
|
|
9654
9717
|
*/
|
|
9655
9718
|
const assetFromDenom = (denom) => {
|
|
9656
9719
|
if (denom === DENOM_RUNE_NATIVE)
|
|
9657
|
-
return
|
|
9720
|
+
return AssetRuneNative;
|
|
9658
9721
|
return xchainUtil.assetFromString(denom.toUpperCase());
|
|
9659
9722
|
};
|
|
9660
9723
|
/**
|
|
@@ -9688,13 +9751,13 @@ const getPrefix = (network) => {
|
|
|
9688
9751
|
* Register type for encoding `MsgDeposit` messages
|
|
9689
9752
|
*/
|
|
9690
9753
|
const registerDepositCodecs = () => {
|
|
9691
|
-
|
|
9754
|
+
cosmosclient__default['default'].codec.register('/types.MsgDeposit', MsgCompiled.types.MsgDeposit);
|
|
9692
9755
|
};
|
|
9693
9756
|
/**
|
|
9694
9757
|
* Register type for encoding `MsgSend` messages
|
|
9695
9758
|
*/
|
|
9696
9759
|
const registerSendCodecs = () => {
|
|
9697
|
-
|
|
9760
|
+
cosmosclient__default['default'].codec.register('/types.MsgSend', MsgCompiled.types.MsgSend);
|
|
9698
9761
|
};
|
|
9699
9762
|
/**
|
|
9700
9763
|
* Parse transaction data from event logs
|
|
@@ -9772,13 +9835,13 @@ const getChainId = (nodeUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
9772
9835
|
* @returns
|
|
9773
9836
|
*/
|
|
9774
9837
|
const buildUnsignedTx = ({ cosmosSdk, txBody, signerPubkey, sequence, gasLimit, }) => {
|
|
9775
|
-
const authInfo = new
|
|
9838
|
+
const authInfo = new cosmosclient__default['default'].proto.cosmos.tx.v1beta1.AuthInfo({
|
|
9776
9839
|
signer_infos: [
|
|
9777
9840
|
{
|
|
9778
9841
|
public_key: signerPubkey,
|
|
9779
9842
|
mode_info: {
|
|
9780
9843
|
single: {
|
|
9781
|
-
mode:
|
|
9844
|
+
mode: cosmosclient__default['default'].proto.cosmos.tx.signing.v1beta1.SignMode.SIGN_MODE_DIRECT,
|
|
9782
9845
|
},
|
|
9783
9846
|
},
|
|
9784
9847
|
sequence: sequence,
|
|
@@ -9789,7 +9852,7 @@ const buildUnsignedTx = ({ cosmosSdk, txBody, signerPubkey, sequence, gasLimit,
|
|
|
9789
9852
|
gas_limit: gasLimit || null,
|
|
9790
9853
|
},
|
|
9791
9854
|
});
|
|
9792
|
-
return new
|
|
9855
|
+
return new cosmosclient__default['default'].TxBuilder(cosmosSdk, txBody, authInfo);
|
|
9793
9856
|
};
|
|
9794
9857
|
/**
|
|
9795
9858
|
* Estimates usage of gas
|
|
@@ -9804,12 +9867,12 @@ const getEstimatedGas = ({ cosmosSDKClient, txBody, privKey, accountNumber, acco
|
|
|
9804
9867
|
const txBuilder = buildUnsignedTx({
|
|
9805
9868
|
cosmosSdk: cosmosSDKClient.sdk,
|
|
9806
9869
|
txBody: txBody,
|
|
9807
|
-
signerPubkey:
|
|
9870
|
+
signerPubkey: cosmosclient__default['default'].codec.instanceToProtoAny(pubKey),
|
|
9808
9871
|
sequence: accountSequence,
|
|
9809
9872
|
});
|
|
9810
9873
|
const signDocBytes = txBuilder.signDocBytes(accountNumber);
|
|
9811
9874
|
txBuilder.addSignature(privKey.sign(signDocBytes));
|
|
9812
|
-
const resp = yield
|
|
9875
|
+
const resp = yield cosmosclient__default['default'].rest.tx.simulate(cosmosSDKClient.sdk, { tx_bytes: txBuilder.txBytes() });
|
|
9813
9876
|
const estimatedGas = (_d = (_c = (_b = resp.data) === null || _b === void 0 ? void 0 : _b.gas_info) === null || _c === void 0 ? void 0 : _c.gas_used) !== null && _d !== void 0 ? _d : null;
|
|
9814
9877
|
if (!estimatedGas) {
|
|
9815
9878
|
throw new Error('Could not get data of estimated gas');
|
|
@@ -9840,8 +9903,8 @@ const buildDepositTx = ({ msgNativeTx, nodeUrl, chainId, }) => __awaiter(void 0,
|
|
|
9840
9903
|
signer: signerDecoded.data,
|
|
9841
9904
|
};
|
|
9842
9905
|
const depositMsg = MsgCompiled.types.MsgDeposit.fromObject(msgDepositObj);
|
|
9843
|
-
return new
|
|
9844
|
-
messages: [
|
|
9906
|
+
return new cosmosclient__default['default'].proto.cosmos.tx.v1beta1.TxBody({
|
|
9907
|
+
messages: [cosmosclient__default['default'].codec.instanceToProtoAny(depositMsg)],
|
|
9845
9908
|
memo: msgNativeTx.memo,
|
|
9846
9909
|
});
|
|
9847
9910
|
});
|
|
@@ -9874,8 +9937,8 @@ const buildTransferTx = ({ fromAddress, toAddress, assetAmount, assetDenom, memo
|
|
|
9874
9937
|
],
|
|
9875
9938
|
};
|
|
9876
9939
|
const transferMsg = MsgCompiled.types.MsgSend.fromObject(transferObj);
|
|
9877
|
-
return new
|
|
9878
|
-
messages: [
|
|
9940
|
+
return new cosmosclient__default['default'].proto.cosmos.tx.v1beta1.TxBody({
|
|
9941
|
+
messages: [cosmosclient__default['default'].codec.instanceToProtoAny(transferMsg)],
|
|
9879
9942
|
memo,
|
|
9880
9943
|
});
|
|
9881
9944
|
});
|
|
@@ -9892,7 +9955,7 @@ const getBalance = ({ address, assets, cosmosClient, }) => __awaiter(void 0, voi
|
|
|
9892
9955
|
const balances = yield cosmosClient.getBalance(address);
|
|
9893
9956
|
return balances
|
|
9894
9957
|
.map((balance) => ({
|
|
9895
|
-
asset: (balance.denom && assetFromDenom(balance.denom)) ||
|
|
9958
|
+
asset: (balance.denom && assetFromDenom(balance.denom)) || AssetRuneNative,
|
|
9896
9959
|
amount: xchainUtil.baseAmount(balance.amount, DECIMAL),
|
|
9897
9960
|
}))
|
|
9898
9961
|
.filter((balance) => !assets || assets.filter((asset) => xchainUtil.assetToString(balance.asset) === xchainUtil.assetToString(asset)).length);
|
|
@@ -9944,7 +10007,7 @@ const getExplorerTxUrl = ({ urls, network, txID, }) => {
|
|
|
9944
10007
|
}
|
|
9945
10008
|
};
|
|
9946
10009
|
const getAccount = (address, client) => {
|
|
9947
|
-
const accAddress =
|
|
10010
|
+
const accAddress = cosmosclient__default['default'].AccAddress.fromString(address);
|
|
9948
10011
|
return client.getAccount(accAddress);
|
|
9949
10012
|
};
|
|
9950
10013
|
const getSequence = (address, client) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -9988,8 +10051,8 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
9988
10051
|
[xchainClient.Network.Mainnet]: 'thorchain-mainnet-v1',
|
|
9989
10052
|
[xchainClient.Network.Stagenet]: 'thorchain-stagenet-v2',
|
|
9990
10053
|
[xchainClient.Network.Testnet]: 'deprecated',
|
|
9991
|
-
},
|
|
9992
|
-
super(
|
|
10054
|
+
}, }) {
|
|
10055
|
+
super(xchainCosmos.GAIAChain, { network, rootDerivationPaths, phrase });
|
|
9993
10056
|
/**
|
|
9994
10057
|
* Get transaction history of a given address with pagination options.
|
|
9995
10058
|
* By default it will return the transaction history of the current wallet.
|
|
@@ -10046,14 +10109,10 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
10046
10109
|
this.chainIds = chainIds;
|
|
10047
10110
|
registerSendCodecs();
|
|
10048
10111
|
registerDepositCodecs();
|
|
10049
|
-
if (this.clientUrl[xchainClient.Network.Mainnet].node.includes('ninerealms.com') && !this.customRequestHeaders['x-client-id']) {
|
|
10050
|
-
this.customRequestHeaders['x-client-id'] = 'xchainjs-client';
|
|
10051
|
-
}
|
|
10052
10112
|
this.cosmosClient = new xchainCosmos.CosmosSDKClient({
|
|
10053
10113
|
server: this.getClientUrl().node,
|
|
10054
10114
|
chainId: this.getChainId(network),
|
|
10055
10115
|
prefix: getPrefix(network),
|
|
10056
|
-
headers: this.customRequestHeaders,
|
|
10057
10116
|
});
|
|
10058
10117
|
}
|
|
10059
10118
|
/**
|
|
@@ -10232,7 +10291,7 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
10232
10291
|
const { from, to, type } = txData;
|
|
10233
10292
|
return {
|
|
10234
10293
|
hash: txId,
|
|
10235
|
-
asset:
|
|
10294
|
+
asset: AssetRuneNative,
|
|
10236
10295
|
from,
|
|
10237
10296
|
to,
|
|
10238
10297
|
date: new Date(txResult.timestamp),
|
|
@@ -10268,7 +10327,7 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
10268
10327
|
asset = xchainUtil.assetFromString(coin.asset);
|
|
10269
10328
|
});
|
|
10270
10329
|
return {
|
|
10271
|
-
asset: asset ||
|
|
10330
|
+
asset: asset || AssetRuneNative,
|
|
10272
10331
|
from,
|
|
10273
10332
|
to,
|
|
10274
10333
|
type: xchainClient.TxType.Transfer,
|
|
@@ -10285,14 +10344,14 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
10285
10344
|
* @throws {"insufficient funds"} Thrown if the wallet has insufficient funds.
|
|
10286
10345
|
* @throws {"Invalid transaction hash"} Thrown by missing tx hash
|
|
10287
10346
|
*/
|
|
10288
|
-
deposit({ walletIndex = 0, asset =
|
|
10347
|
+
deposit({ walletIndex = 0, asset = AssetRuneNative, amount, memo, gasLimit = new bignumber(DEPOSIT_GAS_LIMIT_VALUE), sequence, }) {
|
|
10289
10348
|
var _a, _b, _c, _d;
|
|
10290
10349
|
return __awaiter(this, void 0, void 0, function* () {
|
|
10291
10350
|
const balances = yield this.getBalance(this.getAddress(walletIndex));
|
|
10292
|
-
const runeBalance = (_b = (_a = balances.filter(({ asset }) =>
|
|
10351
|
+
const runeBalance = (_b = (_a = balances.filter(({ asset }) => isAssetRuneNative(asset))[0]) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : xchainUtil.baseAmount(0, DECIMAL);
|
|
10293
10352
|
const assetBalance = (_d = (_c = balances.filter(({ asset: assetInList }) => xchainUtil.assetToString(assetInList) === xchainUtil.assetToString(asset))[0]) === null || _c === void 0 ? void 0 : _c.amount) !== null && _d !== void 0 ? _d : xchainUtil.baseAmount(0, DECIMAL);
|
|
10294
10353
|
const { average: fee } = yield this.getFees();
|
|
10295
|
-
if (
|
|
10354
|
+
if (isAssetRuneNative(asset)) {
|
|
10296
10355
|
// amount + fee < runeBalance
|
|
10297
10356
|
if (runeBalance.lt(amount.plus(fee))) {
|
|
10298
10357
|
throw new Error('insufficient funds');
|
|
@@ -10307,7 +10366,7 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
10307
10366
|
const privKey = this.getPrivateKey(walletIndex);
|
|
10308
10367
|
const signerPubkey = privKey.pubKey();
|
|
10309
10368
|
const fromAddress = this.getAddress(walletIndex);
|
|
10310
|
-
const fromAddressAcc =
|
|
10369
|
+
const fromAddressAcc = cosmosclient__default['default'].AccAddress.fromString(fromAddress);
|
|
10311
10370
|
const depositTxBody = yield buildDepositTx({
|
|
10312
10371
|
msgNativeTx: {
|
|
10313
10372
|
memo: memo,
|
|
@@ -10329,7 +10388,7 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
10329
10388
|
const txBuilder = buildUnsignedTx({
|
|
10330
10389
|
cosmosSdk: this.getCosmosClient().sdk,
|
|
10331
10390
|
txBody: depositTxBody,
|
|
10332
|
-
signerPubkey:
|
|
10391
|
+
signerPubkey: cosmosclient__default['default'].codec.instanceToProtoAny(signerPubkey),
|
|
10333
10392
|
gasLimit: long_1.fromString(gasLimit.toFixed(0)),
|
|
10334
10393
|
sequence: sequence ? long_1.fromNumber(sequence) : account.sequence || long_1.ZERO,
|
|
10335
10394
|
});
|
|
@@ -10348,14 +10407,14 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
10348
10407
|
* @throws {"insufficient funds"} Thrown if the wallet has insufficient funds.
|
|
10349
10408
|
* @throws {"Invalid transaction hash"} Thrown by missing tx hash
|
|
10350
10409
|
*/
|
|
10351
|
-
transfer({ walletIndex = 0, asset =
|
|
10410
|
+
transfer({ walletIndex = 0, asset = AssetRuneNative, amount, recipient, memo, gasLimit = new bignumber(DEFAULT_GAS_LIMIT_VALUE), sequence, }) {
|
|
10352
10411
|
var _a, _b, _c, _d;
|
|
10353
10412
|
return __awaiter(this, void 0, void 0, function* () {
|
|
10354
10413
|
const balances = yield this.getBalance(this.getAddress(walletIndex));
|
|
10355
|
-
const runeBalance = (_b = (_a = balances.filter(({ asset }) =>
|
|
10414
|
+
const runeBalance = (_b = (_a = balances.filter(({ asset }) => isAssetRuneNative(asset))[0]) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : xchainUtil.baseAmount(0, DECIMAL);
|
|
10356
10415
|
const assetBalance = (_d = (_c = balances.filter(({ asset: assetInList }) => xchainUtil.assetToString(assetInList) === xchainUtil.assetToString(asset))[0]) === null || _c === void 0 ? void 0 : _c.amount) !== null && _d !== void 0 ? _d : xchainUtil.baseAmount(0, DECIMAL);
|
|
10357
10416
|
const fee = (yield this.getFees()).average;
|
|
10358
|
-
if (
|
|
10417
|
+
if (isAssetRuneNative(asset)) {
|
|
10359
10418
|
// amount + fee < runeBalance
|
|
10360
10419
|
if (runeBalance.lt(amount.plus(fee))) {
|
|
10361
10420
|
throw new Error('insufficient funds');
|
|
@@ -10370,7 +10429,7 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
10370
10429
|
const privKey = this.getPrivateKey(walletIndex);
|
|
10371
10430
|
const from = this.getAddress(walletIndex);
|
|
10372
10431
|
const signerPubkey = privKey.pubKey();
|
|
10373
|
-
const accAddress =
|
|
10432
|
+
const accAddress = cosmosclient__default['default'].AccAddress.fromString(from);
|
|
10374
10433
|
const denom = getDenom(asset);
|
|
10375
10434
|
const txBody = yield buildTransferTx({
|
|
10376
10435
|
fromAddress: from,
|
|
@@ -10389,7 +10448,7 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
10389
10448
|
cosmosSdk: this.getCosmosClient().sdk,
|
|
10390
10449
|
txBody: txBody,
|
|
10391
10450
|
gasLimit: long_1.fromString(gasLimit.toString()),
|
|
10392
|
-
signerPubkey:
|
|
10451
|
+
signerPubkey: cosmosclient__default['default'].codec.instanceToProtoAny(signerPubkey),
|
|
10393
10452
|
sequence: sequence ? long_1.fromNumber(sequence) : account.sequence || long_1.ZERO,
|
|
10394
10453
|
});
|
|
10395
10454
|
const txHash = yield this.cosmosClient.signAndBroadcast(txBuilder, privKey, accountNumber);
|
|
@@ -10404,10 +10463,10 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
10404
10463
|
* @param {TxOfflineParams} params The transfer offline options.
|
|
10405
10464
|
* @returns {string} The signed transaction bytes.
|
|
10406
10465
|
*/
|
|
10407
|
-
transferOffline({ walletIndex = 0, asset =
|
|
10466
|
+
transferOffline({ walletIndex = 0, asset = AssetRuneNative, amount, recipient, memo, fromRuneBalance: from_rune_balance, fromAssetBalance: from_asset_balance = xchainUtil.baseAmount(0, DECIMAL), fromAccountNumber = long_1.ZERO, fromSequence = long_1.ZERO, gasLimit = new bignumber(DEFAULT_GAS_LIMIT_VALUE), }) {
|
|
10408
10467
|
return __awaiter(this, void 0, void 0, function* () {
|
|
10409
10468
|
const fee = (yield this.getFees()).average;
|
|
10410
|
-
if (
|
|
10469
|
+
if (isAssetRuneNative(asset)) {
|
|
10411
10470
|
// amount + fee < runeBalance
|
|
10412
10471
|
if (from_rune_balance.lt(amount.plus(fee))) {
|
|
10413
10472
|
throw new Error('insufficient funds');
|
|
@@ -10433,7 +10492,7 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
10433
10492
|
cosmosSdk: this.getCosmosClient().sdk,
|
|
10434
10493
|
txBody: txBody,
|
|
10435
10494
|
gasLimit: long_1.fromString(gasLimit.toFixed(0)),
|
|
10436
|
-
signerPubkey:
|
|
10495
|
+
signerPubkey: cosmosclient__default['default'].codec.instanceToProtoAny(privKey.pubKey()),
|
|
10437
10496
|
sequence: fromSequence,
|
|
10438
10497
|
});
|
|
10439
10498
|
const signDocBytes = txBuilder.signDocBytes(fromAccountNumber);
|
|
@@ -10476,9 +10535,14 @@ class MsgNativeTx {
|
|
|
10476
10535
|
* @returns {MsgNativeTx}
|
|
10477
10536
|
*/
|
|
10478
10537
|
const msgNativeTxFromJson = (value) => {
|
|
10479
|
-
return new MsgNativeTx(value.coins, value.memo,
|
|
10538
|
+
return new MsgNativeTx(value.coins, value.memo, cosmosclient__default['default'].AccAddress.fromString(value.signer));
|
|
10480
10539
|
};
|
|
10481
10540
|
|
|
10541
|
+
exports.AssetRune67C = AssetRune67C;
|
|
10542
|
+
exports.AssetRuneB1A = AssetRuneB1A;
|
|
10543
|
+
exports.AssetRuneERC20 = AssetRuneERC20;
|
|
10544
|
+
exports.AssetRuneERC20Testnet = AssetRuneERC20Testnet;
|
|
10545
|
+
exports.AssetRuneNative = AssetRuneNative;
|
|
10482
10546
|
exports.Client = Client;
|
|
10483
10547
|
exports.DECIMAL = DECIMAL;
|
|
10484
10548
|
exports.DEFAULT_GAS_ADJUSTMENT = DEFAULT_GAS_ADJUSTMENT;
|
|
@@ -10486,6 +10550,8 @@ exports.DEFAULT_GAS_LIMIT_VALUE = DEFAULT_GAS_LIMIT_VALUE;
|
|
|
10486
10550
|
exports.DEPOSIT_GAS_LIMIT_VALUE = DEPOSIT_GAS_LIMIT_VALUE;
|
|
10487
10551
|
exports.MAX_TX_COUNT = MAX_TX_COUNT;
|
|
10488
10552
|
exports.MsgNativeTx = MsgNativeTx;
|
|
10553
|
+
exports.RUNE_SYMBOL = RUNE_SYMBOL;
|
|
10554
|
+
exports.THORChain = THORChain;
|
|
10489
10555
|
exports.assetFromDenom = assetFromDenom;
|
|
10490
10556
|
exports.buildDepositTx = buildDepositTx;
|
|
10491
10557
|
exports.buildTransferTx = buildTransferTx;
|
|
@@ -10504,6 +10570,7 @@ exports.getExplorerUrl = getExplorerUrl;
|
|
|
10504
10570
|
exports.getPrefix = getPrefix;
|
|
10505
10571
|
exports.getSequence = getSequence;
|
|
10506
10572
|
exports.getTxType = getTxType;
|
|
10573
|
+
exports.isAssetRuneNative = isAssetRuneNative;
|
|
10507
10574
|
exports.isBroadcastSuccess = isBroadcastSuccess;
|
|
10508
10575
|
exports.msgNativeTxFromJson = msgNativeTxFromJson;
|
|
10509
10576
|
exports.registerDepositCodecs = registerDepositCodecs;
|
package/lib/types/messages.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import cosmosclient from '@cosmos-client/core';
|
|
2
2
|
import { Asset } from '@xchainjs/xchain-util';
|
|
3
3
|
export declare type MsgCoin = {
|
|
4
4
|
asset: Asset;
|
|
@@ -31,7 +31,7 @@ export declare type ThorchainDepositResponse = AminoWrapping<{
|
|
|
31
31
|
memo: string;
|
|
32
32
|
signer: string;
|
|
33
33
|
}>[];
|
|
34
|
-
fee: proto.cosmos.tx.v1beta1.Fee;
|
|
34
|
+
fee: cosmosclient.proto.cosmos.tx.v1beta1.Fee;
|
|
35
35
|
signatures: string[];
|
|
36
36
|
memo: string;
|
|
37
37
|
timeout_height: string;
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import cosmosclient from '@cosmos-client/core';
|
|
2
2
|
import { Balance, Fees, Network, TxHash } from '@xchainjs/xchain-client';
|
|
3
3
|
import { CosmosSDKClient, TxLog } from '@xchainjs/xchain-cosmos';
|
|
4
4
|
import { Address, Asset, BaseAmount } from '@xchainjs/xchain-util';
|
|
5
5
|
import Long from 'long';
|
|
6
6
|
import { ChainId, ExplorerUrls, TxData } from './types';
|
|
7
7
|
import { MsgNativeTx } from './types/messages';
|
|
8
|
-
export declare const DECIMAL = 8;
|
|
9
|
-
export declare const DEFAULT_GAS_ADJUSTMENT = 2;
|
|
10
|
-
export declare const DEFAULT_GAS_LIMIT_VALUE = "4000000";
|
|
11
|
-
export declare const DEPOSIT_GAS_LIMIT_VALUE = "600000000";
|
|
12
|
-
export declare const MAX_TX_COUNT = 100;
|
|
13
|
-
export declare const defaultExplorerUrls: ExplorerUrls;
|
|
14
8
|
/**
|
|
9
|
+
* Checks whether an asset is `AssetRuneNative`
|
|
10
|
+
*
|
|
11
|
+
* @param {Asset} asset
|
|
12
|
+
* @returns {boolean} `true` or `false`
|
|
13
|
+
*/
|
|
14
|
+
export declare const isAssetRuneNative: (asset: Asset) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
|
|
15
17
|
* Get denomination from Asset
|
|
16
18
|
*
|
|
17
19
|
* @param {Asset} asset
|
|
@@ -87,8 +89,8 @@ export declare const getChainId: (nodeUrl: string) => Promise<ChainId>;
|
|
|
87
89
|
*/
|
|
88
90
|
export declare const buildUnsignedTx: ({ cosmosSdk, txBody, signerPubkey, sequence, gasLimit, }: {
|
|
89
91
|
cosmosSdk: cosmosclient.CosmosSDK;
|
|
90
|
-
txBody: proto.cosmos.tx.v1beta1.TxBody;
|
|
91
|
-
signerPubkey: proto.google.protobuf.Any;
|
|
92
|
+
txBody: cosmosclient.proto.cosmos.tx.v1beta1.TxBody;
|
|
93
|
+
signerPubkey: cosmosclient.proto.google.protobuf.Any;
|
|
92
94
|
sequence: Long;
|
|
93
95
|
gasLimit?: Long.Long | undefined;
|
|
94
96
|
}) => cosmosclient.TxBuilder;
|
|
@@ -101,8 +103,8 @@ export declare const buildUnsignedTx: ({ cosmosSdk, txBody, signerPubkey, sequen
|
|
|
101
103
|
*/
|
|
102
104
|
export declare const getEstimatedGas: ({ cosmosSDKClient, txBody, privKey, accountNumber, accountSequence, multiplier, }: {
|
|
103
105
|
cosmosSDKClient: CosmosSDKClient;
|
|
104
|
-
txBody: proto.cosmos.tx.v1beta1.TxBody;
|
|
105
|
-
privKey: proto.cosmos.crypto.secp256k1.PrivKey;
|
|
106
|
+
txBody: cosmosclient.proto.cosmos.tx.v1beta1.TxBody;
|
|
107
|
+
privKey: cosmosclient.proto.cosmos.crypto.secp256k1.PrivKey;
|
|
106
108
|
accountNumber: Long;
|
|
107
109
|
accountSequence: Long;
|
|
108
110
|
multiplier?: number | undefined;
|
|
@@ -122,7 +124,7 @@ export declare const buildDepositTx: ({ msgNativeTx, nodeUrl, chainId, }: {
|
|
|
122
124
|
msgNativeTx: MsgNativeTx;
|
|
123
125
|
nodeUrl: string;
|
|
124
126
|
chainId: ChainId;
|
|
125
|
-
}) => Promise<proto.cosmos.tx.v1beta1.TxBody>;
|
|
127
|
+
}) => Promise<cosmosclient.proto.cosmos.tx.v1beta1.TxBody>;
|
|
126
128
|
/**
|
|
127
129
|
* Structure a MsgSend
|
|
128
130
|
*
|
|
@@ -142,7 +144,7 @@ export declare const buildTransferTx: ({ fromAddress, toAddress, assetAmount, as
|
|
|
142
144
|
memo?: string | undefined;
|
|
143
145
|
nodeUrl: string;
|
|
144
146
|
chainId: ChainId;
|
|
145
|
-
}) => Promise<proto.cosmos.tx.v1beta1.TxBody>;
|
|
147
|
+
}) => Promise<cosmosclient.proto.cosmos.tx.v1beta1.TxBody>;
|
|
146
148
|
/**
|
|
147
149
|
* Get the balance of a given address.
|
|
148
150
|
*
|
|
@@ -191,5 +193,5 @@ export declare const getExplorerTxUrl: ({ urls, network, txID, }: {
|
|
|
191
193
|
network: Network;
|
|
192
194
|
txID: TxHash;
|
|
193
195
|
}) => string;
|
|
194
|
-
export declare const getAccount: (address: string, client: CosmosSDKClient) => Promise<proto.cosmos.auth.v1beta1.IBaseAccount>;
|
|
196
|
+
export declare const getAccount: (address: string, client: CosmosSDKClient) => Promise<cosmosclient.proto.cosmos.auth.v1beta1.IBaseAccount>;
|
|
195
197
|
export declare const getSequence: (address: string, client: CosmosSDKClient) => Promise<number | null>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-thorchain",
|
|
3
|
-
"version": "0.27.
|
|
3
|
+
"version": "0.27.7",
|
|
4
4
|
"description": "Custom Thorchain client and utilities used by XChainJS clients",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"THORChain",
|
|
@@ -34,12 +34,14 @@
|
|
|
34
34
|
"generate:ThorchainMsgs": "./genMsgs.sh"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@cosmos-client/core": "0.
|
|
37
|
+
"@cosmos-client/core": "0.46.1",
|
|
38
38
|
"@types/big.js": "^6.0.0",
|
|
39
|
-
"@xchainjs/xchain-
|
|
40
|
-
"@xchainjs/xchain-
|
|
39
|
+
"@xchainjs/xchain-binance": "^5.6.6",
|
|
40
|
+
"@xchainjs/xchain-client": "^0.13.5",
|
|
41
|
+
"@xchainjs/xchain-cosmos": "^0.20.6",
|
|
41
42
|
"@xchainjs/xchain-crypto": "^0.2.6",
|
|
42
|
-
"@xchainjs/xchain-
|
|
43
|
+
"@xchainjs/xchain-ethereum": "^0.27.6",
|
|
44
|
+
"@xchainjs/xchain-util": "^0.12.0",
|
|
43
45
|
"axios": "^0.25.0",
|
|
44
46
|
"bech32-buffer": "^0.2.0",
|
|
45
47
|
"nock": "^13.0.5"
|
|
@@ -48,11 +50,11 @@
|
|
|
48
50
|
"access": "public"
|
|
49
51
|
},
|
|
50
52
|
"peerDependencies": {
|
|
51
|
-
"@cosmos-client/core": "0.
|
|
52
|
-
"@xchainjs/xchain-client": "^0.13.
|
|
53
|
-
"@xchainjs/xchain-cosmos": "^0.20.
|
|
53
|
+
"@cosmos-client/core": "0.46.1",
|
|
54
|
+
"@xchainjs/xchain-client": "^0.13.5",
|
|
55
|
+
"@xchainjs/xchain-cosmos": "^0.20.6",
|
|
54
56
|
"@xchainjs/xchain-crypto": "^0.2.6",
|
|
55
|
-
"@xchainjs/xchain-util": "^0.
|
|
57
|
+
"@xchainjs/xchain-util": "^0.12.0",
|
|
56
58
|
"axios": "^0.25.0",
|
|
57
59
|
"bech32-buffer": "^0.2.0"
|
|
58
60
|
}
|