@xchainjs/xchain-thorchain 0.22.1 → 0.24.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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?: ChainIds;
19
+ chainIds: ChainIds;
20
20
  };
21
21
  export declare type DepositParam = {
22
22
  walletIndex?: number;
@@ -38,3 +38,20 @@ export declare type TxOfflineParams = TxParams & {
38
38
  from_account_number: string;
39
39
  from_sequence: string;
40
40
  };
41
+ /**
42
+ * Response from `thorchain/constants` endpoint
43
+ */
44
+ export declare type ThorchainConstantsResponse = {
45
+ int_64_values: {
46
+ NativeTransactionFee: number;
47
+ };
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
+ };
@@ -1,15 +1,14 @@
1
- import { AccAddress, Msg } from 'cosmos-client';
2
- import { StdTxFee } from 'cosmos-client/api';
3
- import { StdSignature } from 'cosmos-client/x/auth';
1
+ import { cosmosclient, proto } from '@cosmos-client/core';
2
+ import { Asset } from '@xchainjs/xchain-util';
4
3
  export declare type MsgCoin = {
5
- asset: string;
4
+ asset: Asset;
6
5
  amount: string;
7
6
  };
8
- export declare class MsgNativeTx extends Msg {
7
+ export declare class MsgNativeTx {
9
8
  coins: MsgCoin[];
10
9
  memo: string;
11
- signer: AccAddress;
12
- constructor(coins: MsgCoin[], memo: string, signer: AccAddress);
10
+ signer: cosmosclient.AccAddress;
11
+ constructor(coins: MsgCoin[], memo: string, signer: cosmosclient.AccAddress);
13
12
  }
14
13
  /**
15
14
  * This creates MsgNativeTx from json.
@@ -32,8 +31,8 @@ export declare type ThorchainDepositResponse = AminoWrapping<{
32
31
  memo: string;
33
32
  signer: string;
34
33
  }>[];
35
- fee: StdTxFee;
36
- signatures: StdSignature[];
34
+ fee: proto.cosmos.tx.v1beta1.Fee;
35
+ signatures: string[];
37
36
  memo: string;
38
37
  timeout_height: string;
39
38
  }>;
package/lib/util.d.ts CHANGED
@@ -1,10 +1,8 @@
1
+ import { cosmosclient, proto } from '@cosmos-client/core';
1
2
  import { Address, Balance, Fees, Network, TxHash } from '@xchainjs/xchain-client';
2
3
  import { CosmosSDKClient, TxLog } from '@xchainjs/xchain-cosmos';
3
- import { Asset } from '@xchainjs/xchain-util';
4
- import { Msg } from 'cosmos-client';
5
- import { StdTx } from 'cosmos-client/x/auth';
6
- import { MsgMultiSend, MsgSend } from 'cosmos-client/x/bank';
7
- import { ChainId, ClientUrl, ExplorerUrls, TxData } from './types';
4
+ import { Asset, BaseAmount } from '@xchainjs/xchain-util';
5
+ import { ChainId, ChainIds, ClientUrl, ExplorerUrls, TxData } from './types';
8
6
  import { MsgNativeTx } from './types/messages';
9
7
  export declare const DECIMAL = 8;
10
8
  export declare const DEFAULT_GAS_VALUE = "3000000";
@@ -31,20 +29,6 @@ export declare const getDenom: (asset: Asset) => string;
31
29
  * @returns {Asset|null} The asset of the given denomination.
32
30
  */
33
31
  export declare const assetFromDenom: (denom: string) => Asset | null;
34
- /**
35
- * Type guard for MsgSend
36
- *
37
- * @param {Msg} msg
38
- * @returns {boolean} `true` or `false`.
39
- */
40
- export declare const isMsgSend: (msg: Msg) => msg is MsgSend;
41
- /**
42
- * Type guard for MsgMultiSend
43
- *
44
- * @param {Msg} msg
45
- * @returns {boolean} `true` or `false`.
46
- */
47
- export declare const isMsgMultiSend: (msg: Msg) => msg is MsgMultiSend;
48
32
  /**
49
33
  * Response guard for transaction broadcast
50
34
  *
@@ -65,7 +49,13 @@ export declare const getPrefix: (network: Network) => "thor" | "sthor" | "tthor"
65
49
  *
66
50
  * @param {string} prefix
67
51
  */
68
- export declare const registerCodecs: (prefix: string) => void;
52
+ export declare const registerDespositCodecs: () => Promise<void>;
53
+ /**
54
+ * Register Codecs based on the prefix.
55
+ *
56
+ * @param {string} prefix
57
+ */
58
+ export declare const registerSendCodecs: () => Promise<void>;
69
59
  /**
70
60
  * Parse transaction data from event logs
71
61
  *
@@ -89,7 +79,34 @@ export declare const getDefaultFees: () => Fees;
89
79
  */
90
80
  export declare const getTxType: (txData: string, encoding: 'base64' | 'hex') => string;
91
81
  /**
92
- * Structure StdTx from MsgNativeTx.
82
+ * Helper to get THORChain's chain id
83
+ * @param {string} nodeUrl THORNode url
84
+ */
85
+ export declare const getChainId: (nodeUrl: string) => Promise<ChainId>;
86
+ /**
87
+ * Helper to get all THORChain's chain id
88
+ * @param {ClientUrl} client urls (use `getDefaultClientUrl()` if you don't need to use custom urls)
89
+ */
90
+ export declare const getChainIds: (client: ClientUrl) => Promise<ChainIds>;
91
+ /**
92
+ * Builds final unsigned TX
93
+ *
94
+ * @param cosmosSdk - CosmosSDK
95
+ * @param txBody - txBody with encoded Msgs
96
+ * @param signerPubkey - signerPubkey string
97
+ * @param sequence - account sequence
98
+ * @param gasLimit - transaction gas limit
99
+ * @returns
100
+ */
101
+ export declare const buildUnsignedTx: ({ cosmosSdk, txBody, signerPubkey, sequence, gasLimit, }: {
102
+ cosmosSdk: cosmosclient.CosmosSDK;
103
+ txBody: proto.cosmos.tx.v1beta1.TxBody;
104
+ signerPubkey: proto.google.protobuf.Any;
105
+ sequence: cosmosclient.Long;
106
+ gasLimit: string;
107
+ }) => cosmosclient.TxBuilder;
108
+ /**
109
+ * Structure a MsgDeposit
93
110
  *
94
111
  * @param {MsgNativeTx} msgNativeTx Msg of type `MsgNativeTx`.
95
112
  * @param {string} nodeUrl Node url
@@ -103,7 +120,27 @@ export declare const buildDepositTx: ({ msgNativeTx, nodeUrl, chainId, }: {
103
120
  msgNativeTx: MsgNativeTx;
104
121
  nodeUrl: string;
105
122
  chainId: ChainId;
106
- }) => Promise<StdTx>;
123
+ }) => Promise<proto.cosmos.tx.v1beta1.TxBody>;
124
+ /**
125
+ * Structure a MsgSend
126
+ *
127
+ * @param fromAddress - required, from address string
128
+ * @param toAddress - required, to address string
129
+ * @param assetAmount - required, asset amount string (e.g. "10000")
130
+ * @param assetDenom - required, asset denom string (e.g. "rune")
131
+ * @param memo - optional, memo string
132
+ *
133
+ * @returns
134
+ */
135
+ export declare const buildTransferTx: ({ fromAddress, toAddress, assetAmount, assetDenom, memo, nodeUrl, chainId, }: {
136
+ fromAddress: Address;
137
+ toAddress: Address;
138
+ assetAmount: BaseAmount;
139
+ assetDenom: string;
140
+ memo?: string | undefined;
141
+ nodeUrl: string;
142
+ chainId: ChainId;
143
+ }) => Promise<proto.cosmos.tx.v1beta1.TxBody>;
107
144
  /**
108
145
  * Get the balance of a given address.
109
146
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xchainjs/xchain-thorchain",
3
- "version": "0.22.1",
3
+ "version": "0.24.0-alpha.1",
4
4
  "description": "Custom Thorchain client and utilities used by XChainJS clients",
5
5
  "keywords": [
6
6
  "THORChain",
@@ -27,29 +27,33 @@
27
27
  "clean": "rimraf lib/**",
28
28
  "build": "yarn clean && rollup -c",
29
29
  "test": "jest",
30
+ "e2e": "jest --config jest.config.e2e.js",
30
31
  "lint": "eslint \"{src,__tests__}/**/*.ts\" --fix --max-warnings 0",
31
32
  "prepublishOnly": "yarn build",
32
- "start:example": "ts-node example/index.ts"
33
+ "start:example": "ts-node example/index.ts",
34
+ "generate:ThorchainMsgs": "./genMsgs.sh"
33
35
  },
34
36
  "devDependencies": {
37
+ "@cosmos-client/core": "^0.45.1",
35
38
  "@types/big.js": "^6.0.0",
36
39
  "@xchainjs/xchain-client": "^0.11.1",
37
- "@xchainjs/xchain-cosmos": "^0.16.1",
40
+ "@xchainjs/xchain-cosmos": "^0.17.0-alpha.1",
38
41
  "@xchainjs/xchain-crypto": "^0.2.4",
39
42
  "@xchainjs/xchain-util": "^0.5.1",
40
43
  "axios": "^0.25.0",
41
- "cosmos-client": "0.39.2",
44
+ "bech32-buffer": "^0.2.0",
42
45
  "nock": "^13.0.5"
43
46
  },
44
47
  "publishConfig": {
45
48
  "access": "public"
46
49
  },
47
50
  "peerDependencies": {
51
+ "@cosmos-client/core": "^0.45.1",
48
52
  "@xchainjs/xchain-client": "^0.11.1",
49
- "@xchainjs/xchain-cosmos": "^0.16.1",
53
+ "@xchainjs/xchain-cosmos": "^0.17.0",
50
54
  "@xchainjs/xchain-crypto": "^0.2.4",
51
55
  "@xchainjs/xchain-util": "^0.5.1",
52
56
  "axios": "^0.25.0",
53
- "cosmos-client": "0.39.2"
57
+ "bech32-buffer": "^0.2.0"
54
58
  }
55
- }
59
+ }