@keplr-wallet/stores 0.9.17 → 0.9.18-rc.2

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.
Files changed (165) hide show
  1. package/build/account/base.d.ts +22 -38
  2. package/build/account/base.js +37 -178
  3. package/build/account/base.js.map +1 -1
  4. package/build/account/base.spec.js +4 -6
  5. package/build/account/base.spec.js.map +1 -1
  6. package/build/account/cosmos.d.ts +59 -28
  7. package/build/account/cosmos.js +267 -130
  8. package/build/account/cosmos.js.map +1 -1
  9. package/build/account/cosmwasm.d.ts +20 -27
  10. package/build/account/cosmwasm.js +39 -39
  11. package/build/account/cosmwasm.js.map +1 -1
  12. package/build/account/index.d.ts +0 -2
  13. package/build/account/index.js +0 -2
  14. package/build/account/index.js.map +1 -1
  15. package/build/account/secret.d.ts +20 -26
  16. package/build/account/secret.js +45 -24
  17. package/build/account/secret.js.map +1 -1
  18. package/build/account/store.d.ts +16 -27
  19. package/build/account/store.js +6 -22
  20. package/build/account/store.js.map +1 -1
  21. package/build/common/index.d.ts +1 -0
  22. package/build/common/index.js +1 -0
  23. package/build/common/index.js.map +1 -1
  24. package/build/common/merge.d.ts +55 -0
  25. package/build/common/merge.js +41 -0
  26. package/build/common/merge.js.map +1 -0
  27. package/build/common/merge.spec.d.ts +1 -0
  28. package/build/common/merge.spec.js +26 -0
  29. package/build/common/merge.spec.js.map +1 -0
  30. package/build/common/query/index.d.ts +10 -0
  31. package/build/common/query/index.js +15 -7
  32. package/build/common/query/index.js.map +1 -1
  33. package/build/common/query/query.spec.d.ts +11 -0
  34. package/build/common/query/query.spec.js +125 -0
  35. package/build/common/query/query.spec.js.map +1 -0
  36. package/build/ibc/currency-registrar.d.ts +8 -16
  37. package/build/ibc/currency-registrar.js.map +1 -1
  38. package/build/price/index.d.ts +1 -2
  39. package/build/price/index.js +2 -3
  40. package/build/price/index.js.map +1 -1
  41. package/build/query/chain-rpc-query.d.ts +18 -0
  42. package/build/query/chain-rpc-query.js +50 -0
  43. package/build/query/chain-rpc-query.js.map +1 -0
  44. package/build/query/cosmos/account/index.js +6 -2
  45. package/build/query/cosmos/account/index.js.map +1 -1
  46. package/build/query/cosmos/account/types.d.ts +9 -4
  47. package/build/query/cosmos/balance/index.js +3 -3
  48. package/build/query/cosmos/balance/index.js.map +1 -1
  49. package/build/query/cosmos/balance/types.d.ts +1 -2
  50. package/build/query/cosmos/distribution/params.js +2 -2
  51. package/build/query/cosmos/distribution/params.js.map +1 -1
  52. package/build/query/cosmos/distribution/types.d.ts +2 -2
  53. package/build/query/cosmos/governance/params.js +3 -3
  54. package/build/query/cosmos/governance/params.js.map +1 -1
  55. package/build/query/cosmos/governance/proposal.d.ts +4 -4
  56. package/build/query/cosmos/governance/proposal.js +16 -37
  57. package/build/query/cosmos/governance/proposal.js.map +1 -1
  58. package/build/query/cosmos/governance/proposals.d.ts +4 -4
  59. package/build/query/cosmos/governance/proposals.js +6 -3
  60. package/build/query/cosmos/governance/proposals.js.map +1 -1
  61. package/build/query/cosmos/governance/types.d.ts +26 -58
  62. package/build/query/cosmos/governance/vote.d.ts +3 -3
  63. package/build/query/cosmos/governance/vote.js +12 -18
  64. package/build/query/cosmos/governance/vote.js.map +1 -1
  65. package/build/query/cosmos/index.d.ts +0 -1
  66. package/build/query/cosmos/index.js +0 -1
  67. package/build/query/cosmos/index.js.map +1 -1
  68. package/build/query/cosmos/queries.d.ts +8 -9
  69. package/build/query/cosmos/queries.js +14 -13
  70. package/build/query/cosmos/queries.js.map +1 -1
  71. package/build/query/cosmos/staking/delegations.d.ts +3 -3
  72. package/build/query/cosmos/staking/delegations.js +9 -36
  73. package/build/query/cosmos/staking/delegations.js.map +1 -1
  74. package/build/query/cosmos/staking/params.d.ts +5 -0
  75. package/build/query/cosmos/staking/params.js +34 -1
  76. package/build/query/cosmos/staking/params.js.map +1 -1
  77. package/build/query/cosmos/staking/pool.d.ts +3 -0
  78. package/build/query/cosmos/staking/pool.js +30 -1
  79. package/build/query/cosmos/staking/pool.js.map +1 -1
  80. package/build/query/cosmos/staking/rewards.js +9 -9
  81. package/build/query/cosmos/staking/rewards.js.map +1 -1
  82. package/build/query/cosmos/staking/types.d.ts +18 -33
  83. package/build/query/cosmos/staking/types.js +1 -0
  84. package/build/query/cosmos/staking/types.js.map +1 -1
  85. package/build/query/cosmos/staking/unbonding-delegations.js +3 -3
  86. package/build/query/cosmos/staking/unbonding-delegations.js.map +1 -1
  87. package/build/query/cosmos/staking/validators.js +14 -20
  88. package/build/query/cosmos/staking/validators.js.map +1 -1
  89. package/build/query/cosmos/status/index.d.ts +50 -0
  90. package/build/query/cosmos/status/index.js +24 -0
  91. package/build/query/cosmos/status/index.js.map +1 -0
  92. package/build/query/cosmos/supply/inflation.d.ts +3 -3
  93. package/build/query/cosmos/supply/inflation.js +5 -11
  94. package/build/query/cosmos/supply/inflation.js.map +1 -1
  95. package/build/query/cosmos/supply/minting.js +1 -1
  96. package/build/query/cosmos/supply/minting.js.map +1 -1
  97. package/build/query/cosmos/supply/supply.d.ts +5 -5
  98. package/build/query/cosmos/supply/supply.js +1 -9
  99. package/build/query/cosmos/supply/supply.js.map +1 -1
  100. package/build/query/cosmos/supply/types.d.ts +2 -8
  101. package/build/query/cosmwasm/queries.d.ts +6 -9
  102. package/build/query/cosmwasm/queries.js +12 -11
  103. package/build/query/cosmwasm/queries.js.map +1 -1
  104. package/build/query/queries.d.ts +20 -11
  105. package/build/query/queries.js +13 -12
  106. package/build/query/queries.js.map +1 -1
  107. package/build/query/secret-wasm/queries.d.ts +8 -8
  108. package/build/query/secret-wasm/queries.js +12 -11
  109. package/build/query/secret-wasm/queries.js.map +1 -1
  110. package/package.json +7 -7
  111. package/src/account/base.spec.ts +5 -7
  112. package/src/account/base.ts +35 -305
  113. package/src/account/cosmos.ts +452 -185
  114. package/src/account/cosmwasm.ts +70 -74
  115. package/src/account/index.ts +0 -2
  116. package/src/account/secret.ts +79 -53
  117. package/src/account/store.ts +43 -57
  118. package/src/common/index.ts +1 -0
  119. package/src/common/merge.spec.ts +47 -0
  120. package/src/common/merge.ts +91 -0
  121. package/src/common/query/index.ts +28 -7
  122. package/src/common/query/query.spec.ts +122 -0
  123. package/src/ibc/currency-registrar.ts +10 -9
  124. package/src/price/index.ts +1 -2
  125. package/src/query/chain-rpc-query.ts +66 -0
  126. package/src/query/cosmos/account/index.ts +12 -2
  127. package/src/query/cosmos/account/types.ts +9 -5
  128. package/src/query/cosmos/balance/index.ts +8 -3
  129. package/src/query/cosmos/balance/types.ts +3 -2
  130. package/src/query/cosmos/distribution/params.ts +2 -2
  131. package/src/query/cosmos/distribution/types.ts +2 -2
  132. package/src/query/cosmos/governance/params.ts +3 -3
  133. package/src/query/cosmos/governance/proposal.ts +25 -51
  134. package/src/query/cosmos/governance/proposals.ts +13 -6
  135. package/src/query/cosmos/governance/types.ts +57 -73
  136. package/src/query/cosmos/governance/vote.ts +16 -26
  137. package/src/query/cosmos/index.ts +0 -1
  138. package/src/query/cosmos/queries.ts +35 -16
  139. package/src/query/cosmos/staking/delegations.ts +15 -48
  140. package/src/query/cosmos/staking/params.ts +29 -1
  141. package/src/query/cosmos/staking/pool.ts +33 -1
  142. package/src/query/cosmos/staking/rewards.ts +9 -9
  143. package/src/query/cosmos/staking/types.ts +30 -45
  144. package/src/query/cosmos/staking/unbonding-delegations.ts +3 -3
  145. package/src/query/cosmos/staking/validators.ts +15 -28
  146. package/src/query/cosmos/status/index.ts +67 -0
  147. package/src/query/cosmos/supply/inflation.ts +8 -13
  148. package/src/query/cosmos/supply/minting.ts +1 -1
  149. package/src/query/cosmos/supply/supply.ts +11 -24
  150. package/src/query/cosmos/supply/types.ts +2 -11
  151. package/src/query/cosmwasm/queries.ts +25 -19
  152. package/src/query/queries.ts +64 -29
  153. package/src/query/secret-wasm/queries.ts +28 -24
  154. package/build/account/all.d.ts +0 -25
  155. package/build/account/all.js +0 -27
  156. package/build/account/all.js.map +0 -1
  157. package/build/account/cosmos-secret.d.ts +0 -23
  158. package/build/account/cosmos-secret.js +0 -25
  159. package/build/account/cosmos-secret.js.map +0 -1
  160. package/build/query/cosmos/block/index.d.ts +0 -25
  161. package/build/query/cosmos/block/index.js +0 -49
  162. package/build/query/cosmos/block/index.js.map +0 -1
  163. package/src/account/all.ts +0 -86
  164. package/src/account/cosmos-secret.ts +0 -65
  165. package/src/query/cosmos/block/index.ts +0 -63
@@ -12,26 +12,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.CosmosAccount = exports.AccountWithCosmos = void 0;
15
+ exports.CosmosAccountImpl = exports.defaultCosmosMsgOpts = exports.CosmosAccount = void 0;
16
16
  const base_1 = require("./base");
17
+ const launchpad_1 = require("@cosmjs/launchpad");
17
18
  const common_1 = require("@keplr-wallet/common");
18
19
  const unit_1 = require("@keplr-wallet/unit");
19
20
  const cosmos_1 = require("@keplr-wallet/cosmos");
20
21
  const types_1 = require("../query/cosmos/staking/types");
21
22
  const long_1 = __importDefault(require("long"));
22
- class AccountWithCosmos extends base_1.AccountSetBase {
23
- constructor(eventListener, chainGetter, chainId, queriesStore, opts) {
24
- super(eventListener, chainGetter, chainId, queriesStore, opts);
25
- this.eventListener = eventListener;
26
- this.chainGetter = chainGetter;
27
- this.chainId = chainId;
28
- this.queriesStore = queriesStore;
29
- this.opts = opts;
30
- this.cosmos = new CosmosAccount(this, chainGetter, chainId, queriesStore);
31
- }
32
- }
33
- exports.AccountWithCosmos = AccountWithCosmos;
34
- AccountWithCosmos.defaultMsgOpts = {
23
+ const axios_1 = __importDefault(require("axios"));
24
+ var SignMode = cosmos_1.cosmos.tx.signing.v1beta1.SignMode;
25
+ const deepmerge_1 = __importDefault(require("deepmerge"));
26
+ exports.CosmosAccount = {
27
+ use(options) {
28
+ return (base, chainGetter, chainId) => {
29
+ const msgOptsFromCreator = options.msgOptsCreator
30
+ ? options.msgOptsCreator(chainId)
31
+ : undefined;
32
+ return {
33
+ cosmos: new CosmosAccountImpl(base, chainGetter, chainId, options.queriesStore, deepmerge_1.default(exports.defaultCosmosMsgOpts, msgOptsFromCreator ? msgOptsFromCreator : {}), options),
34
+ };
35
+ };
36
+ },
37
+ };
38
+ exports.defaultCosmosMsgOpts = {
35
39
  send: {
36
40
  native: {
37
41
  type: "cosmos-sdk/MsgSend",
@@ -64,14 +68,20 @@ AccountWithCosmos.defaultMsgOpts = {
64
68
  gas: 250000,
65
69
  },
66
70
  };
67
- class CosmosAccount {
68
- constructor(base, chainGetter, chainId, queriesStore) {
71
+ class CosmosAccountImpl {
72
+ constructor(base, chainGetter, chainId, queriesStore, _msgOpts, txOpts) {
69
73
  this.base = base;
70
74
  this.chainGetter = chainGetter;
71
75
  this.chainId = chainId;
72
76
  this.queriesStore = queriesStore;
77
+ this._msgOpts = _msgOpts;
78
+ this.txOpts = txOpts;
79
+ this.broadcastMode = "sync";
73
80
  this.base.registerSendTokenFn(this.processSendToken.bind(this));
74
81
  }
82
+ get msgOpts() {
83
+ return this._msgOpts;
84
+ }
75
85
  processSendToken(amount, currency, recipient, memo, stdFee, signOptions, onTxEvents) {
76
86
  var _a, _b;
77
87
  return __awaiter(this, void 0, void 0, function* () {
@@ -84,7 +94,7 @@ class CosmosAccount {
84
94
  return dec.truncate().toString();
85
95
  })();
86
96
  const msg = {
87
- type: this.base.msgOpts.send.native.type,
97
+ type: this.msgOpts.send.native.type,
88
98
  value: {
89
99
  from_address: this.base.bech32Address,
90
100
  to_address: recipient,
@@ -96,23 +106,21 @@ class CosmosAccount {
96
106
  ],
97
107
  },
98
108
  };
99
- yield this.base.sendMsgs("send", {
109
+ yield this.sendMsgs("send", {
100
110
  aminoMsgs: [msg],
101
- protoMsgs: this.hasNoLegacyStdFeature()
102
- ? [
103
- {
104
- type_url: "/cosmos.bank.v1beta1.MsgSend",
105
- value: cosmos_1.cosmos.bank.v1beta1.MsgSend.encode({
106
- fromAddress: msg.value.from_address,
107
- toAddress: msg.value.to_address,
108
- amount: msg.value.amount,
109
- }).finish(),
110
- },
111
- ]
112
- : undefined,
111
+ protoMsgs: [
112
+ {
113
+ type_url: "/cosmos.bank.v1beta1.MsgSend",
114
+ value: cosmos_1.cosmos.bank.v1beta1.MsgSend.encode({
115
+ fromAddress: msg.value.from_address,
116
+ toAddress: msg.value.to_address,
117
+ amount: msg.value.amount,
118
+ }).finish(),
119
+ },
120
+ ],
113
121
  }, memo, {
114
122
  amount: (_a = stdFee.amount) !== null && _a !== void 0 ? _a : [],
115
- gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.base.msgOpts.send.native.gas.toString(),
123
+ gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.msgOpts.send.native.gas.toString(),
116
124
  }, signOptions, this.txEventsWithPreOnFulfill(onTxEvents, (tx) => {
117
125
  if (tx.code == null || tx.code === 0) {
118
126
  // After succeeding to send token, refresh the balance.
@@ -131,6 +139,142 @@ class CosmosAccount {
131
139
  return false;
132
140
  });
133
141
  }
142
+ sendMsgs(type, msgs, memo = "", fee, signOptions, onTxEvents) {
143
+ var _a, _b;
144
+ return __awaiter(this, void 0, void 0, function* () {
145
+ this.base.setTxTypeInProgress(type);
146
+ let txHash;
147
+ let signDoc;
148
+ try {
149
+ if (typeof msgs === "function") {
150
+ msgs = yield msgs();
151
+ }
152
+ const result = yield this.broadcastMsgs(msgs, fee, memo, signOptions, this.broadcastMode);
153
+ txHash = result.txHash;
154
+ signDoc = result.signDoc;
155
+ }
156
+ catch (e) {
157
+ this.base.setTxTypeInProgress("");
158
+ if ((_a = this.txOpts.preTxEvents) === null || _a === void 0 ? void 0 : _a.onBroadcastFailed) {
159
+ this.txOpts.preTxEvents.onBroadcastFailed(this.chainId, e);
160
+ }
161
+ if (onTxEvents &&
162
+ "onBroadcastFailed" in onTxEvents &&
163
+ onTxEvents.onBroadcastFailed) {
164
+ onTxEvents.onBroadcastFailed(e);
165
+ }
166
+ throw e;
167
+ }
168
+ let onBroadcasted;
169
+ let onFulfill;
170
+ if (onTxEvents) {
171
+ if (typeof onTxEvents === "function") {
172
+ onFulfill = onTxEvents;
173
+ }
174
+ else {
175
+ onBroadcasted = onTxEvents.onBroadcasted;
176
+ onFulfill = onTxEvents.onFulfill;
177
+ }
178
+ }
179
+ if ((_b = this.txOpts.preTxEvents) === null || _b === void 0 ? void 0 : _b.onBroadcasted) {
180
+ this.txOpts.preTxEvents.onBroadcasted(this.chainId, txHash);
181
+ }
182
+ if (onBroadcasted) {
183
+ onBroadcasted(txHash);
184
+ }
185
+ const txTracer = new cosmos_1.TendermintTxTracer(this.chainGetter.getChain(this.chainId).rpc, "/websocket", {
186
+ wsObject: this.txOpts.wsObject,
187
+ });
188
+ txTracer.traceTx(txHash).then((tx) => {
189
+ var _a;
190
+ txTracer.close();
191
+ this.base.setTxTypeInProgress("");
192
+ // After sending tx, the balances is probably changed due to the fee.
193
+ for (const feeAmount of signDoc.fee.amount) {
194
+ const bal = this.queries.queryBalances
195
+ .getQueryBech32Address(this.base.bech32Address)
196
+ .balances.find((bal) => bal.currency.coinMinimalDenom === feeAmount.denom);
197
+ if (bal) {
198
+ bal.fetch();
199
+ }
200
+ }
201
+ // Always add the tx hash data.
202
+ if (tx && !tx.hash) {
203
+ tx.hash = Buffer.from(txHash).toString("hex");
204
+ }
205
+ if ((_a = this.txOpts.preTxEvents) === null || _a === void 0 ? void 0 : _a.onFulfill) {
206
+ this.txOpts.preTxEvents.onFulfill(this.chainId, tx);
207
+ }
208
+ if (onFulfill) {
209
+ onFulfill(tx);
210
+ }
211
+ });
212
+ });
213
+ }
214
+ // Return the tx hash.
215
+ broadcastMsgs(msgs, fee, memo = "", signOptions, mode = "async") {
216
+ return __awaiter(this, void 0, void 0, function* () {
217
+ if (this.base.walletStatus !== base_1.WalletStatus.Loaded) {
218
+ throw new Error(`Wallet is not loaded: ${this.base.walletStatus}`);
219
+ }
220
+ const aminoMsgs = msgs.aminoMsgs;
221
+ const protoMsgs = msgs.protoMsgs;
222
+ // TODO: Make proto sign doc if `aminoMsgs` is empty or null
223
+ if (aminoMsgs.length === 0 || protoMsgs.length === 0) {
224
+ throw new Error("There is no msg to send");
225
+ }
226
+ if (aminoMsgs.length !== protoMsgs.length) {
227
+ throw new Error("The length of aminoMsgs and protoMsgs are different");
228
+ }
229
+ const account = yield cosmos_1.BaseAccount.fetchFromRest(this.instance, this.base.bech32Address, true);
230
+ const coinType = this.chainGetter.getChain(this.chainId).coinType;
231
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
232
+ const keplr = (yield this.base.getKeplr());
233
+ const signDoc = launchpad_1.makeSignDoc(aminoMsgs, fee, this.chainId, memo, account.getAccountNumber().toString(), account.getSequence().toString());
234
+ const signResponse = yield keplr.signAmino(this.chainId, this.base.bech32Address, signDoc, signOptions);
235
+ const signedTx = cosmos_1.cosmos.tx.v1beta1.TxRaw.encode({
236
+ bodyBytes: cosmos_1.cosmos.tx.v1beta1.TxBody.encode({
237
+ messages: protoMsgs,
238
+ memo: signResponse.signed.memo,
239
+ }).finish(),
240
+ authInfoBytes: cosmos_1.cosmos.tx.v1beta1.AuthInfo.encode({
241
+ signerInfos: [
242
+ {
243
+ publicKey: {
244
+ type_url: coinType === 60
245
+ ? "/ethermint.crypto.v1.ethsecp256k1.PubKey"
246
+ : "/cosmos.crypto.secp256k1.PubKey",
247
+ value: cosmos_1.cosmos.crypto.secp256k1.PubKey.encode({
248
+ key: Buffer.from(signResponse.signature.pub_key.value, "base64"),
249
+ }).finish(),
250
+ },
251
+ modeInfo: {
252
+ single: {
253
+ mode: SignMode.SIGN_MODE_LEGACY_AMINO_JSON,
254
+ },
255
+ },
256
+ sequence: long_1.default.fromString(signResponse.signed.sequence),
257
+ },
258
+ ],
259
+ fee: {
260
+ amount: signResponse.signed.fee.amount,
261
+ gasLimit: long_1.default.fromString(signResponse.signed.fee.gas),
262
+ },
263
+ }).finish(),
264
+ signatures: [Buffer.from(signResponse.signature.signature, "base64")],
265
+ }).finish();
266
+ return {
267
+ txHash: yield keplr.sendTx(this.chainId, signedTx, mode),
268
+ signDoc: signResponse.signed,
269
+ };
270
+ });
271
+ }
272
+ get instance() {
273
+ const chainInfo = this.chainGetter.getChain(this.chainId);
274
+ return axios_1.default.create(Object.assign({
275
+ baseURL: chainInfo.rest,
276
+ }, chainInfo.restConfig));
277
+ }
134
278
  sendIBCTransferMsg(channel, amount, currency, recipient, memo = "", stdFee = {}, signOptions, onTxEvents) {
135
279
  var _a, _b;
136
280
  return __awaiter(this, void 0, void 0, function* () {
@@ -142,17 +286,24 @@ class CosmosAccount {
142
286
  dec = dec.mul(unit_1.DecUtils.getPrecisionDec(currency.coinDecimals));
143
287
  return dec.truncate().toString();
144
288
  })();
145
- const destinationBlockHeight = this.queriesStore
146
- .get(channel.counterpartyChainId)
147
- .cosmos.queryBlock.getBlock("latest");
148
- yield this.base.sendMsgs("ibcTransfer", () => __awaiter(this, void 0, void 0, function* () {
289
+ const destinationInfo = this.queriesStore.get(channel.counterpartyChainId)
290
+ .cosmos.queryRPCStatus;
291
+ yield this.sendMsgs("ibcTransfer", () => __awaiter(this, void 0, void 0, function* () {
149
292
  // Wait until fetching complete.
150
- yield destinationBlockHeight.waitFreshResponse();
151
- if (destinationBlockHeight.height.equals(new unit_1.Int("0"))) {
293
+ yield destinationInfo.waitFreshResponse();
294
+ if (!destinationInfo.network) {
295
+ throw new Error(`Failed to fetch the network chain id of ${channel.counterpartyChainId}`);
296
+ }
297
+ if (cosmos_1.ChainIdHelper.parse(destinationInfo.network).identifier !==
298
+ cosmos_1.ChainIdHelper.parse(channel.counterpartyChainId).identifier) {
299
+ throw new Error(`Fetched the network chain id is different with counterparty chain id (${destinationInfo.network}, ${channel.counterpartyChainId})`);
300
+ }
301
+ if (!destinationInfo.latestBlockHeight ||
302
+ destinationInfo.latestBlockHeight.equals(new unit_1.Int("0"))) {
152
303
  throw new Error(`Failed to fetch the latest block of ${channel.counterpartyChainId}`);
153
304
  }
154
305
  const msg = {
155
- type: this.base.msgOpts.ibcTransfer.type,
306
+ type: this.msgOpts.ibcTransfer.type,
156
307
  value: {
157
308
  source_port: channel.portId,
158
309
  source_channel: channel.channelId,
@@ -163,9 +314,9 @@ class CosmosAccount {
163
314
  sender: this.base.bech32Address,
164
315
  receiver: recipient,
165
316
  timeout_height: {
166
- revision_number: cosmos_1.ChainIdHelper.parse(channel.counterpartyChainId).version.toString(),
317
+ revision_number: cosmos_1.ChainIdHelper.parse(destinationInfo.network).version.toString(),
167
318
  // Set the timeout height as the current height + 150.
168
- revision_height: destinationBlockHeight.height
319
+ revision_height: destinationInfo.latestBlockHeight
169
320
  .add(new unit_1.Int("150"))
170
321
  .toString(),
171
322
  },
@@ -197,7 +348,7 @@ class CosmosAccount {
197
348
  };
198
349
  }), memo, {
199
350
  amount: (_a = stdFee.amount) !== null && _a !== void 0 ? _a : [],
200
- gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.base.msgOpts.ibcTransfer.gas.toString(),
351
+ gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.msgOpts.ibcTransfer.gas.toString(),
201
352
  }, signOptions, this.txEventsWithPreOnFulfill(onTxEvents, (tx) => {
202
353
  if (tx.code == null || tx.code === 0) {
203
354
  // After succeeding to send token, refresh the balance.
@@ -228,7 +379,7 @@ class CosmosAccount {
228
379
  let dec = new unit_1.Dec(amount);
229
380
  dec = dec.mulTruncate(unit_1.DecUtils.getPrecisionDec(currency.coinDecimals));
230
381
  const msg = {
231
- type: this.base.msgOpts.delegate.type,
382
+ type: this.msgOpts.delegate.type,
232
383
  value: {
233
384
  delegator_address: this.base.bech32Address,
234
385
  validator_address: validatorAddress,
@@ -238,23 +389,21 @@ class CosmosAccount {
238
389
  },
239
390
  },
240
391
  };
241
- yield this.base.sendMsgs("delegate", {
392
+ yield this.sendMsgs("delegate", {
242
393
  aminoMsgs: [msg],
243
- protoMsgs: this.hasNoLegacyStdFeature()
244
- ? [
245
- {
246
- type_url: "/cosmos.staking.v1beta1.MsgDelegate",
247
- value: cosmos_1.cosmos.staking.v1beta1.MsgDelegate.encode({
248
- delegatorAddress: msg.value.delegator_address,
249
- validatorAddress: msg.value.validator_address,
250
- amount: msg.value.amount,
251
- }).finish(),
252
- },
253
- ]
254
- : undefined,
394
+ protoMsgs: [
395
+ {
396
+ type_url: "/cosmos.staking.v1beta1.MsgDelegate",
397
+ value: cosmos_1.cosmos.staking.v1beta1.MsgDelegate.encode({
398
+ delegatorAddress: msg.value.delegator_address,
399
+ validatorAddress: msg.value.validator_address,
400
+ amount: msg.value.amount,
401
+ }).finish(),
402
+ },
403
+ ],
255
404
  }, memo, {
256
405
  amount: (_a = stdFee.amount) !== null && _a !== void 0 ? _a : [],
257
- gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.base.msgOpts.delegate.gas.toString(),
406
+ gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.msgOpts.delegate.gas.toString(),
258
407
  }, signOptions, this.txEventsWithPreOnFulfill(onTxEvents, (tx) => {
259
408
  if (tx.code == null || tx.code === 0) {
260
409
  // After succeeding to delegate, refresh the validators and delegations, rewards.
@@ -286,7 +435,7 @@ class CosmosAccount {
286
435
  let dec = new unit_1.Dec(amount);
287
436
  dec = dec.mulTruncate(unit_1.DecUtils.getPrecisionDec(currency.coinDecimals));
288
437
  const msg = {
289
- type: this.base.msgOpts.undelegate.type,
438
+ type: this.msgOpts.undelegate.type,
290
439
  value: {
291
440
  delegator_address: this.base.bech32Address,
292
441
  validator_address: validatorAddress,
@@ -296,7 +445,7 @@ class CosmosAccount {
296
445
  },
297
446
  },
298
447
  };
299
- yield this.base.sendMsgs("undelegate", {
448
+ yield this.sendMsgs("undelegate", {
300
449
  aminoMsgs: [msg],
301
450
  protoMsgs: [
302
451
  {
@@ -310,7 +459,7 @@ class CosmosAccount {
310
459
  ],
311
460
  }, memo, {
312
461
  amount: (_a = stdFee.amount) !== null && _a !== void 0 ? _a : [],
313
- gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.base.msgOpts.undelegate.gas.toString(),
462
+ gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.msgOpts.undelegate.gas.toString(),
314
463
  }, signOptions, this.txEventsWithPreOnFulfill(onTxEvents, (tx) => {
315
464
  if (tx.code == null || tx.code === 0) {
316
465
  // After succeeding to unbond, refresh the validators and delegations, unbonding delegations, rewards.
@@ -346,7 +495,7 @@ class CosmosAccount {
346
495
  let dec = new unit_1.Dec(amount);
347
496
  dec = dec.mulTruncate(unit_1.DecUtils.getPrecisionDec(currency.coinDecimals));
348
497
  const msg = {
349
- type: this.base.msgOpts.redelegate.type,
498
+ type: this.msgOpts.redelegate.type,
350
499
  value: {
351
500
  delegator_address: this.base.bech32Address,
352
501
  validator_src_address: srcValidatorAddress,
@@ -357,24 +506,22 @@ class CosmosAccount {
357
506
  },
358
507
  },
359
508
  };
360
- yield this.base.sendMsgs("redelegate", {
509
+ yield this.sendMsgs("redelegate", {
361
510
  aminoMsgs: [msg],
362
- protoMsgs: this.hasNoLegacyStdFeature()
363
- ? [
364
- {
365
- type_url: "/cosmos.staking.v1beta1.MsgBeginRedelegate",
366
- value: cosmos_1.cosmos.staking.v1beta1.MsgBeginRedelegate.encode({
367
- delegatorAddress: msg.value.delegator_address,
368
- validatorSrcAddress: msg.value.validator_src_address,
369
- validatorDstAddress: msg.value.validator_dst_address,
370
- amount: msg.value.amount,
371
- }).finish(),
372
- },
373
- ]
374
- : undefined,
511
+ protoMsgs: [
512
+ {
513
+ type_url: "/cosmos.staking.v1beta1.MsgBeginRedelegate",
514
+ value: cosmos_1.cosmos.staking.v1beta1.MsgBeginRedelegate.encode({
515
+ delegatorAddress: msg.value.delegator_address,
516
+ validatorSrcAddress: msg.value.validator_src_address,
517
+ validatorDstAddress: msg.value.validator_dst_address,
518
+ amount: msg.value.amount,
519
+ }).finish(),
520
+ },
521
+ ],
375
522
  }, memo, {
376
523
  amount: (_a = stdFee.amount) !== null && _a !== void 0 ? _a : [],
377
- gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.base.msgOpts.redelegate.gas.toString(),
524
+ gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.msgOpts.redelegate.gas.toString(),
378
525
  }, signOptions, this.txEventsWithPreOnFulfill(onTxEvents, (tx) => {
379
526
  if (tx.code == null || tx.code === 0) {
380
527
  // After succeeding to redelegate, refresh the validators and delegations, rewards.
@@ -396,29 +543,27 @@ class CosmosAccount {
396
543
  return __awaiter(this, void 0, void 0, function* () {
397
544
  const msgs = validatorAddresses.map((validatorAddress) => {
398
545
  return {
399
- type: this.base.msgOpts.withdrawRewards.type,
546
+ type: this.msgOpts.withdrawRewards.type,
400
547
  value: {
401
548
  delegator_address: this.base.bech32Address,
402
549
  validator_address: validatorAddress,
403
550
  },
404
551
  };
405
552
  });
406
- yield this.base.sendMsgs("withdrawRewards", {
553
+ yield this.sendMsgs("withdrawRewards", {
407
554
  aminoMsgs: msgs,
408
- protoMsgs: this.hasNoLegacyStdFeature()
409
- ? msgs.map((msg) => {
410
- return {
411
- type_url: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
412
- value: cosmos_1.cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward.encode({
413
- delegatorAddress: msg.value.delegator_address,
414
- validatorAddress: msg.value.validator_address,
415
- }).finish(),
416
- };
417
- })
418
- : undefined,
555
+ protoMsgs: msgs.map((msg) => {
556
+ return {
557
+ type_url: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
558
+ value: cosmos_1.cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward.encode({
559
+ delegatorAddress: msg.value.delegator_address,
560
+ validatorAddress: msg.value.validator_address,
561
+ }).finish(),
562
+ };
563
+ }),
419
564
  }, memo, {
420
565
  amount: (_a = stdFee.amount) !== null && _a !== void 0 ? _a : [],
421
- gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : (this.base.msgOpts.withdrawRewards.gas * validatorAddresses.length).toString(),
566
+ gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : (this.msgOpts.withdrawRewards.gas * validatorAddresses.length).toString(),
422
567
  }, signOptions, this.txEventsWithPreOnFulfill(onTxEvents, (tx) => {
423
568
  if (tx.code == null || tx.code === 0) {
424
569
  // After succeeding to withdraw rewards, refresh rewards.
@@ -451,50 +596,47 @@ class CosmosAccount {
451
596
  }
452
597
  })();
453
598
  const msg = {
454
- type: this.base.msgOpts.govVote.type,
599
+ type: this.msgOpts.govVote.type,
455
600
  value: {
456
601
  option: voteOption,
457
602
  proposal_id: proposalId,
458
603
  voter: this.base.bech32Address,
459
604
  },
460
605
  };
461
- yield this.base.sendMsgs("govVote", {
606
+ yield this.sendMsgs("govVote", {
462
607
  aminoMsgs: [msg],
463
- protoMsgs: this.hasNoLegacyStdFeature()
464
- ? [
465
- {
466
- type_url: "/cosmos.gov.v1beta1.MsgVote",
467
- value: cosmos_1.cosmos.gov.v1beta1.MsgVote.encode({
468
- proposalId: long_1.default.fromString(msg.value.proposal_id),
469
- voter: msg.value.voter,
470
- option: (() => {
471
- switch (msg.value.option) {
472
- case "Yes":
473
- case 1:
474
- return cosmos_1.cosmos.gov.v1beta1.VoteOption.VOTE_OPTION_YES;
475
- case "Abstain":
476
- case 2:
477
- return cosmos_1.cosmos.gov.v1beta1.VoteOption
478
- .VOTE_OPTION_ABSTAIN;
479
- case "No":
480
- case 3:
481
- return cosmos_1.cosmos.gov.v1beta1.VoteOption.VOTE_OPTION_NO;
482
- case "NoWithVeto":
483
- case 4:
484
- return cosmos_1.cosmos.gov.v1beta1.VoteOption
485
- .VOTE_OPTION_NO_WITH_VETO;
486
- default:
487
- return cosmos_1.cosmos.gov.v1beta1.VoteOption
488
- .VOTE_OPTION_UNSPECIFIED;
489
- }
490
- })(),
491
- }).finish(),
492
- },
493
- ]
494
- : undefined,
608
+ protoMsgs: [
609
+ {
610
+ type_url: "/cosmos.gov.v1beta1.MsgVote",
611
+ value: cosmos_1.cosmos.gov.v1beta1.MsgVote.encode({
612
+ proposalId: long_1.default.fromString(msg.value.proposal_id),
613
+ voter: msg.value.voter,
614
+ option: (() => {
615
+ switch (msg.value.option) {
616
+ case "Yes":
617
+ case 1:
618
+ return cosmos_1.cosmos.gov.v1beta1.VoteOption.VOTE_OPTION_YES;
619
+ case "Abstain":
620
+ case 2:
621
+ return cosmos_1.cosmos.gov.v1beta1.VoteOption.VOTE_OPTION_ABSTAIN;
622
+ case "No":
623
+ case 3:
624
+ return cosmos_1.cosmos.gov.v1beta1.VoteOption.VOTE_OPTION_NO;
625
+ case "NoWithVeto":
626
+ case 4:
627
+ return cosmos_1.cosmos.gov.v1beta1.VoteOption
628
+ .VOTE_OPTION_NO_WITH_VETO;
629
+ default:
630
+ return cosmos_1.cosmos.gov.v1beta1.VoteOption
631
+ .VOTE_OPTION_UNSPECIFIED;
632
+ }
633
+ })(),
634
+ }).finish(),
635
+ },
636
+ ],
495
637
  }, memo, {
496
638
  amount: (_a = stdFee.amount) !== null && _a !== void 0 ? _a : [],
497
- gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.base.msgOpts.govVote.gas.toString(),
639
+ gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.msgOpts.govVote.gas.toString(),
498
640
  }, signOptions, this.txEventsWithPreOnFulfill(onTxEvents, (tx) => {
499
641
  if (tx.code == null || tx.code === 0) {
500
642
  // After succeeding to vote, refresh the proposal.
@@ -531,11 +673,6 @@ class CosmosAccount {
531
673
  get queries() {
532
674
  return this.queriesStore.get(this.chainId);
533
675
  }
534
- hasNoLegacyStdFeature() {
535
- const chainInfo = this.chainGetter.getChain(this.chainId);
536
- return (chainInfo.features != null &&
537
- chainInfo.features.includes("no-legacy-stdTx"));
538
- }
539
676
  }
540
- exports.CosmosAccount = CosmosAccount;
677
+ exports.CosmosAccountImpl = CosmosAccountImpl;
541
678
  //# sourceMappingURL=cosmos.js.map