@injectivelabs/wallet-core 1.16.25-alpha.0 → 1.16.25

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 (41) hide show
  1. package/dist/cjs/broadcaster/MsgBroadcaster.d.ts +137 -0
  2. package/dist/cjs/broadcaster/MsgBroadcaster.js +918 -0
  3. package/dist/cjs/broadcaster/Web3Broadcaster.d.ts +30 -0
  4. package/dist/cjs/broadcaster/Web3Broadcaster.js +32 -0
  5. package/dist/cjs/broadcaster/index.d.ts +3 -0
  6. package/dist/cjs/broadcaster/index.js +19 -0
  7. package/dist/cjs/broadcaster/types.d.ts +56 -0
  8. package/dist/cjs/broadcaster/types.js +13 -0
  9. package/dist/cjs/index.d.ts +3 -0
  10. package/dist/cjs/index.js +19 -0
  11. package/dist/cjs/package.json +2 -2
  12. package/dist/cjs/strategy/BaseWalletStrategy.d.ts +58 -0
  13. package/dist/cjs/strategy/BaseWalletStrategy.js +176 -0
  14. package/dist/cjs/strategy/index.d.ts +2 -0
  15. package/dist/cjs/strategy/index.js +8 -0
  16. package/dist/cjs/utils/index.d.ts +1 -0
  17. package/dist/cjs/utils/index.js +17 -0
  18. package/dist/cjs/utils/tx.d.ts +1 -0
  19. package/dist/cjs/utils/tx.js +11 -0
  20. package/dist/esm/broadcaster/MsgBroadcaster.d.ts +137 -0
  21. package/dist/esm/broadcaster/MsgBroadcaster.js +914 -0
  22. package/dist/esm/broadcaster/Web3Broadcaster.d.ts +30 -0
  23. package/dist/esm/broadcaster/Web3Broadcaster.js +28 -0
  24. package/dist/esm/broadcaster/index.d.ts +3 -0
  25. package/dist/esm/broadcaster/index.js +3 -0
  26. package/dist/esm/broadcaster/types.d.ts +56 -0
  27. package/dist/esm/broadcaster/types.js +10 -0
  28. package/dist/esm/index.d.ts +3 -281
  29. package/dist/esm/index.js +3 -1003
  30. package/dist/esm/package.json +2 -2
  31. package/dist/esm/strategy/BaseWalletStrategy.d.ts +58 -0
  32. package/dist/esm/strategy/BaseWalletStrategy.js +173 -0
  33. package/dist/esm/strategy/index.d.ts +2 -0
  34. package/dist/esm/strategy/index.js +2 -0
  35. package/dist/esm/utils/index.d.ts +1 -0
  36. package/dist/esm/utils/index.js +1 -0
  37. package/dist/esm/utils/tx.d.ts +1 -0
  38. package/dist/esm/utils/tx.js +7 -0
  39. package/package.json +19 -19
  40. package/dist/cjs/index.cjs +0 -1007
  41. package/dist/cjs/index.d.cts +0 -281
@@ -0,0 +1,918 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MsgBroadcaster = void 0;
4
+ const ts_types_1 = require("@injectivelabs/ts-types");
5
+ const networks_1 = require("@injectivelabs/networks");
6
+ const utils_1 = require("@injectivelabs/utils");
7
+ const exceptions_1 = require("@injectivelabs/exceptions");
8
+ const wallet_base_1 = require("@injectivelabs/wallet-base");
9
+ const sdk_ts_1 = require("@injectivelabs/sdk-ts");
10
+ const index_js_1 = require("../utils/index.js");
11
+ const types_js_1 = require("./types.js");
12
+ const getEthereumWalletPubKey = async ({ pubKey, eip712TypedData, signature, }) => {
13
+ if (pubKey) {
14
+ return pubKey;
15
+ }
16
+ const recoveredPubKey = await (0, sdk_ts_1.recoverTypedSignaturePubKey)(
17
+ // TODO: fix type
18
+ eip712TypedData, signature);
19
+ return (0, sdk_ts_1.hexToBase64)(recoveredPubKey);
20
+ };
21
+ const defaultRetriesConfig = () => ({
22
+ [`${exceptions_1.TransactionChainErrorModule.CosmosSdk}-${exceptions_1.ChainCosmosErrorCode.ErrMempoolIsFull}`]: {
23
+ retries: 0,
24
+ maxRetries: 10,
25
+ timeout: 1000,
26
+ },
27
+ });
28
+ /**
29
+ * This class is used to broadcast transactions
30
+ * using the WalletStrategy as a handler
31
+ * for the sign/broadcast flow of the transactions
32
+ *
33
+ * Mainly used for building UI products
34
+ */
35
+ class MsgBroadcaster {
36
+ options;
37
+ walletStrategy;
38
+ endpoints;
39
+ chainId;
40
+ txTimeout = utils_1.DEFAULT_BLOCK_TIMEOUT_HEIGHT;
41
+ simulateTx = true;
42
+ txTimeoutOnFeeDelegation = false;
43
+ evmChainId;
44
+ gasBufferCoefficient = 1.2;
45
+ retriesOnError = defaultRetriesConfig();
46
+ httpHeaders;
47
+ constructor(options) {
48
+ const networkInfo = (0, networks_1.getNetworkInfo)(options.network);
49
+ this.options = options;
50
+ this.simulateTx =
51
+ options.simulateTx !== undefined ? options.simulateTx : true;
52
+ this.txTimeout = options.txTimeout || utils_1.DEFAULT_BLOCK_TIMEOUT_HEIGHT;
53
+ this.txTimeoutOnFeeDelegation =
54
+ options.txTimeoutOnFeeDelegation !== undefined
55
+ ? options.txTimeoutOnFeeDelegation
56
+ : true;
57
+ this.gasBufferCoefficient = options.gasBufferCoefficient || 1.2;
58
+ this.chainId = options.chainId || networkInfo.chainId;
59
+ this.evmChainId = options.evmChainId || networkInfo.evmChainId;
60
+ this.endpoints = options.endpoints || (0, networks_1.getNetworkEndpoints)(options.network);
61
+ this.walletStrategy = options.walletStrategy;
62
+ this.httpHeaders = options.httpHeaders;
63
+ }
64
+ setOptions(options) {
65
+ this.simulateTx = options.simulateTx || this.simulateTx;
66
+ this.txTimeout = options.txTimeout || this.txTimeout;
67
+ this.txTimeoutOnFeeDelegation =
68
+ options.txTimeoutOnFeeDelegation || this.txTimeoutOnFeeDelegation;
69
+ }
70
+ async getEvmChainId() {
71
+ const { walletStrategy } = this;
72
+ if (!(0, wallet_base_1.isEvmBrowserWallet)(walletStrategy.wallet)) {
73
+ return this.evmChainId;
74
+ }
75
+ const mainnetEvmIds = [
76
+ ts_types_1.EvmChainId.Mainnet,
77
+ ts_types_1.EvmChainId.MainnetEvm,
78
+ ];
79
+ const testnetEvmIds = [
80
+ ts_types_1.EvmChainId.Sepolia,
81
+ ts_types_1.EvmChainId.TestnetEvm,
82
+ ];
83
+ const devnetEvmIds = [
84
+ ts_types_1.EvmChainId.Sepolia,
85
+ ts_types_1.EvmChainId.DevnetEvm,
86
+ ];
87
+ try {
88
+ const chainId = await walletStrategy.getEthereumChainId();
89
+ if (!chainId) {
90
+ return this.evmChainId;
91
+ }
92
+ const evmChainId = parseInt(chainId, 16);
93
+ if (isNaN(evmChainId)) {
94
+ return this.evmChainId;
95
+ }
96
+ if (((0, networks_1.isMainnet)(this.options.network) &&
97
+ !mainnetEvmIds.includes(evmChainId)) ||
98
+ ((0, networks_1.isTestnet)(this.options.network) &&
99
+ !testnetEvmIds.includes(evmChainId)) ||
100
+ (!(0, networks_1.isMainnet)(this.options.network) &&
101
+ !(0, networks_1.isTestnet)(this.options.network) &&
102
+ !devnetEvmIds.includes(evmChainId))) {
103
+ throw new exceptions_1.WalletException(new Error('Your selected network is incorrect'));
104
+ }
105
+ return evmChainId;
106
+ }
107
+ catch (e) {
108
+ throw new exceptions_1.WalletException(e);
109
+ }
110
+ }
111
+ /**
112
+ * Broadcasting the transaction using the client
113
+ * side approach for both cosmos and ethereum native wallets
114
+ *
115
+ * @param tx
116
+ * @returns {string} transaction hash
117
+ */
118
+ async broadcast(tx) {
119
+ const { walletStrategy } = this;
120
+ const txWithAddresses = {
121
+ ...tx,
122
+ ethereumAddress: (0, wallet_base_1.getEthereumSignerAddress)(tx.injectiveAddress),
123
+ injectiveAddress: (0, wallet_base_1.getInjectiveSignerAddress)(tx.injectiveAddress),
124
+ };
125
+ if (sdk_ts_1.ofacWallets.includes(txWithAddresses.ethereumAddress)) {
126
+ throw new exceptions_1.GeneralException(new Error('You cannot execute this transaction'));
127
+ }
128
+ try {
129
+ return (0, wallet_base_1.isCosmosWallet)(walletStrategy.wallet)
130
+ ? await this.broadcastDirectSign(txWithAddresses)
131
+ : (0, wallet_base_1.isEip712V2OnlyWallet)(walletStrategy.wallet)
132
+ ? await this.broadcastEip712V2(txWithAddresses)
133
+ : await this.broadcastEip712(txWithAddresses);
134
+ }
135
+ catch (e) {
136
+ const error = e;
137
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionFail);
138
+ if ((0, exceptions_1.isThrownException)(error)) {
139
+ throw error;
140
+ }
141
+ throw new exceptions_1.TransactionException(new Error(error));
142
+ }
143
+ }
144
+ /**
145
+ * Broadcasting the transaction using the client
146
+ * side approach for both cosmos and ethereum native wallets
147
+ * Note: using EIP712_V2 for Ethereum wallets
148
+ *
149
+ * @param tx
150
+ * @returns {string} transaction hash
151
+ */
152
+ async broadcastV2(tx) {
153
+ const { walletStrategy } = this;
154
+ const txWithAddresses = {
155
+ ...tx,
156
+ ethereumAddress: (0, wallet_base_1.getEthereumSignerAddress)(tx.injectiveAddress),
157
+ injectiveAddress: (0, wallet_base_1.getInjectiveSignerAddress)(tx.injectiveAddress),
158
+ };
159
+ if (sdk_ts_1.ofacWallets.includes(txWithAddresses.ethereumAddress)) {
160
+ throw new exceptions_1.GeneralException(new Error('You cannot execute this transaction'));
161
+ }
162
+ try {
163
+ return (0, wallet_base_1.isCosmosWallet)(walletStrategy.wallet)
164
+ ? await this.broadcastDirectSign(txWithAddresses)
165
+ : await this.broadcastEip712V2(txWithAddresses);
166
+ }
167
+ catch (e) {
168
+ const error = e;
169
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionFail);
170
+ if ((0, exceptions_1.isThrownException)(error)) {
171
+ throw error;
172
+ }
173
+ throw new exceptions_1.TransactionException(new Error(error));
174
+ }
175
+ }
176
+ /**
177
+ * Broadcasting the transaction using the feeDelegation
178
+ * support approach for both cosmos and ethereum native wallets
179
+ *
180
+ * @param tx
181
+ * @returns {string} transaction hash
182
+ */
183
+ async broadcastWithFeeDelegation(tx) {
184
+ const { walletStrategy } = this;
185
+ const txWithAddresses = {
186
+ ...tx,
187
+ ethereumAddress: (0, wallet_base_1.getEthereumSignerAddress)(tx.injectiveAddress),
188
+ injectiveAddress: (0, wallet_base_1.getInjectiveSignerAddress)(tx.injectiveAddress),
189
+ };
190
+ if (sdk_ts_1.ofacWallets.includes(txWithAddresses.ethereumAddress)) {
191
+ throw new exceptions_1.GeneralException(new Error('You cannot execute this transaction'));
192
+ }
193
+ try {
194
+ return (0, wallet_base_1.isCosmosWallet)(walletStrategy.wallet)
195
+ ? await this.broadcastDirectSignWithFeeDelegation(txWithAddresses)
196
+ : await this.broadcastEip712WithFeeDelegation(txWithAddresses);
197
+ }
198
+ catch (e) {
199
+ const error = e;
200
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionFail);
201
+ if ((0, exceptions_1.isThrownException)(error)) {
202
+ throw error;
203
+ }
204
+ throw new exceptions_1.TransactionException(new Error(error));
205
+ }
206
+ }
207
+ /**
208
+ * Prepare/sign/broadcast transaction using
209
+ * Ethereum native wallets on the client side.
210
+ *
211
+ * Note: Gas estimation not available
212
+ *
213
+ * @param tx The transaction that needs to be broadcasted
214
+ * @returns transaction hash
215
+ */
216
+ async broadcastEip712(tx) {
217
+ const { chainId, endpoints, walletStrategy, txTimeout: txTimeoutInBlocks, } = this;
218
+ const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
219
+ const evmChainId = await this.getEvmChainId();
220
+ if (!evmChainId) {
221
+ throw new exceptions_1.GeneralException(new Error('Please provide evmChainId'));
222
+ }
223
+ /** Account Details * */
224
+ const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
225
+ const timeoutHeight = (0, utils_1.toBigNumber)(latestHeight).plus(txTimeoutInBlocks);
226
+ const txTimeoutTimeInSeconds = txTimeoutInBlocks * utils_1.DEFAULT_BLOCK_TIME_IN_SECONDS;
227
+ const txTimeoutTimeInMilliSeconds = txTimeoutTimeInSeconds * 1000;
228
+ const gas = (tx.gas?.gas || (0, sdk_ts_1.getGasPriceBasedOnMessage)(msgs)).toString();
229
+ let stdFee = (0, utils_1.getStdFee)({ ...tx.gas, gas });
230
+ /**
231
+ * Account has not been created on chain
232
+ * and we cannot simulate the transaction
233
+ * to estimate the gas
234
+ **/
235
+ if (!baseAccount.pubKey) {
236
+ stdFee = await this.getStdFeeWithDynamicBaseFee(stdFee);
237
+ }
238
+ else {
239
+ const { stdFee: simulatedStdFee } = await this.getTxWithSignersAndStdFee({
240
+ chainId,
241
+ signMode: sdk_ts_1.SIGN_EIP712,
242
+ memo: tx.memo,
243
+ message: msgs,
244
+ timeoutHeight: timeoutHeight.toNumber(),
245
+ signers: {
246
+ pubKey: baseAccount.pubKey.key,
247
+ accountNumber: baseAccount.accountNumber,
248
+ sequence: baseAccount.sequence,
249
+ },
250
+ fee: stdFee,
251
+ });
252
+ stdFee = simulatedStdFee;
253
+ }
254
+ /** EIP712 for signing on Ethereum wallets */
255
+ const eip712TypedData = (0, sdk_ts_1.getEip712TypedData)({
256
+ msgs,
257
+ fee: stdFee,
258
+ tx: {
259
+ memo: tx.memo,
260
+ accountNumber: baseAccount.accountNumber.toString(),
261
+ sequence: baseAccount.sequence.toString(),
262
+ timeoutHeight: timeoutHeight.toFixed(),
263
+ chainId,
264
+ },
265
+ evmChainId,
266
+ });
267
+ /** Signing on Ethereum */
268
+ const signature = await walletStrategy.signEip712TypedData(JSON.stringify(eip712TypedData), tx.ethereumAddress, { txTimeout: txTimeoutTimeInSeconds });
269
+ const pubKeyOrSignatureDerivedPubKey = await getEthereumWalletPubKey({
270
+ pubKey: baseAccount.pubKey?.key,
271
+ eip712TypedData,
272
+ signature,
273
+ });
274
+ /** Preparing the transaction for client broadcasting */
275
+ const { txRaw } = (0, sdk_ts_1.createTransaction)({
276
+ message: msgs,
277
+ memo: tx.memo,
278
+ signMode: sdk_ts_1.SIGN_EIP712,
279
+ fee: stdFee,
280
+ pubKey: pubKeyOrSignatureDerivedPubKey,
281
+ sequence: baseAccount.sequence,
282
+ timeoutHeight: timeoutHeight.toNumber(),
283
+ accountNumber: baseAccount.accountNumber,
284
+ chainId,
285
+ });
286
+ const web3Extension = (0, sdk_ts_1.createWeb3Extension)({
287
+ evmChainId,
288
+ });
289
+ const txRawEip712 = (0, sdk_ts_1.createTxRawEIP712)(txRaw, web3Extension);
290
+ /** Append Signatures */
291
+ txRawEip712.signatures = [(0, sdk_ts_1.hexToBuff)(signature)];
292
+ const response = await walletStrategy.sendTransaction(txRawEip712, {
293
+ chainId,
294
+ endpoints,
295
+ txTimeout: txTimeoutInBlocks,
296
+ address: tx.injectiveAddress,
297
+ });
298
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
299
+ return await new sdk_ts_1.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
300
+ }
301
+ /**
302
+ * Prepare/sign/broadcast transaction using
303
+ * Ethereum native wallets on the client side.
304
+ *
305
+ * Note: Gas estimation not available
306
+ *
307
+ * @param tx The transaction that needs to be broadcasted
308
+ * @returns transaction hash
309
+ */
310
+ async broadcastEip712V2(tx) {
311
+ const { chainId, endpoints, walletStrategy, txTimeout: txTimeoutInBlocks, } = this;
312
+ const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
313
+ const evmChainId = await this.getEvmChainId();
314
+ if (!evmChainId) {
315
+ throw new exceptions_1.GeneralException(new Error('Please provide evmChainId'));
316
+ }
317
+ /** Account Details * */
318
+ const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
319
+ const timeoutHeight = (0, utils_1.toBigNumber)(latestHeight).plus(txTimeoutInBlocks);
320
+ const txTimeoutTimeInSeconds = txTimeoutInBlocks * utils_1.DEFAULT_BLOCK_TIME_IN_SECONDS;
321
+ const txTimeoutTimeInMilliSeconds = txTimeoutTimeInSeconds * 1000;
322
+ const gas = (tx.gas?.gas || (0, sdk_ts_1.getGasPriceBasedOnMessage)(msgs)).toString();
323
+ let stdFee = (0, utils_1.getStdFee)({ ...tx.gas, gas });
324
+ /**
325
+ * Account has not been created on chain
326
+ * and we cannot simulate the transaction
327
+ * to estimate the gas
328
+ **/
329
+ if (!baseAccount.pubKey) {
330
+ stdFee = await this.getStdFeeWithDynamicBaseFee(stdFee);
331
+ }
332
+ else {
333
+ const { stdFee: simulatedStdFee } = await this.getTxWithSignersAndStdFee({
334
+ chainId,
335
+ signMode: sdk_ts_1.SIGN_EIP712_V2,
336
+ memo: tx.memo,
337
+ message: msgs,
338
+ timeoutHeight: timeoutHeight.toNumber(),
339
+ signers: {
340
+ pubKey: baseAccount.pubKey.key,
341
+ sequence: baseAccount.sequence,
342
+ accountNumber: baseAccount.accountNumber,
343
+ },
344
+ fee: stdFee,
345
+ });
346
+ stdFee = simulatedStdFee;
347
+ }
348
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionPreparationStart);
349
+ /** EIP712 for signing on Ethereum wallets */
350
+ const eip712TypedData = (0, sdk_ts_1.getEip712TypedDataV2)({
351
+ msgs,
352
+ fee: stdFee,
353
+ tx: {
354
+ memo: tx.memo,
355
+ accountNumber: baseAccount.accountNumber.toString(),
356
+ sequence: baseAccount.sequence.toString(),
357
+ timeoutHeight: timeoutHeight.toFixed(),
358
+ chainId,
359
+ },
360
+ evmChainId,
361
+ });
362
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionPreparationEnd);
363
+ /** Signing on Ethereum */
364
+ const signature = await walletStrategy.signEip712TypedData(JSON.stringify(eip712TypedData), tx.ethereumAddress, { txTimeout: txTimeoutTimeInSeconds });
365
+ const pubKeyOrSignatureDerivedPubKey = await getEthereumWalletPubKey({
366
+ pubKey: baseAccount.pubKey?.key,
367
+ eip712TypedData,
368
+ signature,
369
+ });
370
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionBroadcastStart);
371
+ const { txRaw } = (0, sdk_ts_1.createTransaction)({
372
+ message: msgs,
373
+ memo: tx.memo,
374
+ signMode: sdk_ts_1.SIGN_EIP712_V2,
375
+ fee: stdFee,
376
+ pubKey: pubKeyOrSignatureDerivedPubKey,
377
+ sequence: baseAccount.sequence,
378
+ timeoutHeight: timeoutHeight.toNumber(),
379
+ accountNumber: baseAccount.accountNumber,
380
+ chainId,
381
+ });
382
+ const web3Extension = (0, sdk_ts_1.createWeb3Extension)({
383
+ evmChainId,
384
+ });
385
+ const txRawEip712 = (0, sdk_ts_1.createTxRawEIP712)(txRaw, web3Extension);
386
+ /** Append Signatures */
387
+ txRawEip712.signatures = [(0, sdk_ts_1.hexToBuff)(signature)];
388
+ const response = await walletStrategy.sendTransaction(txRawEip712, {
389
+ chainId,
390
+ endpoints,
391
+ txTimeout: txTimeoutInBlocks,
392
+ address: tx.injectiveAddress,
393
+ });
394
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
395
+ return await new sdk_ts_1.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
396
+ }
397
+ /**
398
+ * Prepare/sign/broadcast transaction using
399
+ * Ethereum native wallets using the Web3Gateway.
400
+ *
401
+ * @param tx The transaction that needs to be broadcasted
402
+ * @returns transaction hash
403
+ */
404
+ async broadcastEip712WithFeeDelegation(tx) {
405
+ const { endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation, txTimeout: txTimeoutInBlocks, } = this;
406
+ const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
407
+ const web3Msgs = msgs.map((msg) => msg.toWeb3());
408
+ const evmChainId = await this.getEvmChainId();
409
+ if (!evmChainId) {
410
+ throw new exceptions_1.GeneralException(new Error('Please provide evmChainId'));
411
+ }
412
+ const transactionApi = new sdk_ts_1.IndexerGrpcWeb3GwApi(endpoints.web3gw || endpoints.indexer);
413
+ if (httpHeaders) {
414
+ transactionApi.setMetadata(httpHeaders);
415
+ }
416
+ const txTimeoutTimeInSeconds = txTimeoutInBlocks * utils_1.DEFAULT_BLOCK_TIME_IN_SECONDS;
417
+ const txTimeoutTimeInMilliSeconds = txTimeoutTimeInSeconds * 1000;
418
+ let timeoutHeight = undefined;
419
+ if (txTimeoutOnFeeDelegation) {
420
+ const latestBlock = await new sdk_ts_1.ChainGrpcTendermintApi(endpoints.grpc).fetchLatestBlock();
421
+ const latestHeight = latestBlock.header.height;
422
+ timeoutHeight = (0, utils_1.toBigNumber)(latestHeight)
423
+ .plus(txTimeoutInBlocks)
424
+ .toNumber();
425
+ }
426
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionPreparationStart);
427
+ const prepareTxResponse = await transactionApi.prepareTxRequest({
428
+ timeoutHeight,
429
+ memo: tx.memo,
430
+ message: web3Msgs,
431
+ address: tx.ethereumAddress,
432
+ chainId: evmChainId,
433
+ gasLimit: (0, sdk_ts_1.getGasPriceBasedOnMessage)(msgs),
434
+ estimateGas: simulateTx,
435
+ });
436
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionPreparationEnd);
437
+ const signature = await walletStrategy.signEip712TypedData(prepareTxResponse.data, tx.ethereumAddress, { txTimeout: txTimeoutTimeInSeconds });
438
+ const broadcast = async () => await transactionApi.broadcastTxRequest({
439
+ signature,
440
+ message: web3Msgs,
441
+ txResponse: prepareTxResponse,
442
+ chainId: evmChainId,
443
+ });
444
+ try {
445
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionBroadcastStart);
446
+ const response = await broadcast();
447
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
448
+ return await new sdk_ts_1.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
449
+ }
450
+ catch (e) {
451
+ const error = e;
452
+ if ((0, exceptions_1.isThrownException)(error)) {
453
+ const exception = error;
454
+ /**
455
+ * First MsgExec transaction with a PrivateKey wallet
456
+ * always runs out of gas for some reason, temporary solution
457
+ * to just broadcast the transaction twice
458
+ **/
459
+ if (walletStrategy.wallet === wallet_base_1.Wallet.PrivateKey &&
460
+ (0, index_js_1.checkIfTxRunOutOfGas)(exception)) {
461
+ /** Account Details * */
462
+ const accountDetails = await new sdk_ts_1.ChainGrpcAuthApi(endpoints.grpc).fetchAccount(tx.injectiveAddress);
463
+ const { baseAccount } = accountDetails;
464
+ /** We only do it on the first account tx fail */
465
+ if (baseAccount.sequence > 1) {
466
+ throw e;
467
+ }
468
+ return await this.broadcastEip712WithFeeDelegation(tx);
469
+ }
470
+ return await this.retryOnException(exception, broadcast);
471
+ }
472
+ throw e;
473
+ }
474
+ }
475
+ /**
476
+ * Prepare/sign/broadcast transaction using
477
+ * Cosmos native wallets on the client side.
478
+ *
479
+ * @param tx The transaction that needs to be broadcasted
480
+ * @returns transaction hash
481
+ */
482
+ async broadcastDirectSign(tx) {
483
+ const { chainId, endpoints, walletStrategy, txTimeout: txTimeoutInBlocks, } = this;
484
+ const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
485
+ /**
486
+ * When using Ledger with Keplr/Leap we have
487
+ * to send EIP712 to sign on Keplr/Leap
488
+ */
489
+ if ([wallet_base_1.Wallet.Keplr, wallet_base_1.Wallet.Leap].includes(walletStrategy.getWallet())) {
490
+ const walletDeviceType = await walletStrategy.getWalletDeviceType();
491
+ const isLedgerConnected = walletDeviceType === wallet_base_1.WalletDeviceType.Hardware;
492
+ if (isLedgerConnected) {
493
+ return this.experimentalBroadcastWalletThroughLedger(tx);
494
+ }
495
+ }
496
+ const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
497
+ const timeoutHeight = (0, utils_1.toBigNumber)(latestHeight).plus(txTimeoutInBlocks);
498
+ const txTimeoutTimeInSeconds = txTimeoutInBlocks * utils_1.DEFAULT_BLOCK_TIME_IN_SECONDS;
499
+ const txTimeoutTimeInMilliSeconds = txTimeoutTimeInSeconds * 1000;
500
+ const signMode = (0, wallet_base_1.isCosmosAminoOnlyWallet)(walletStrategy.wallet)
501
+ ? sdk_ts_1.SIGN_EIP712
502
+ : sdk_ts_1.SIGN_DIRECT;
503
+ const pubKey = await walletStrategy.getPubKey(tx.injectiveAddress);
504
+ const gas = (tx.gas?.gas || (0, sdk_ts_1.getGasPriceBasedOnMessage)(msgs)).toString();
505
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionPreparationStart);
506
+ /** Prepare the Transaction * */
507
+ const { txRaw } = await this.getTxWithSignersAndStdFee({
508
+ chainId,
509
+ signMode,
510
+ memo: tx.memo,
511
+ message: msgs,
512
+ timeoutHeight: timeoutHeight.toNumber(),
513
+ signers: {
514
+ pubKey,
515
+ accountNumber: baseAccount.accountNumber,
516
+ sequence: baseAccount.sequence,
517
+ },
518
+ fee: (0, utils_1.getStdFee)({ ...tx.gas, gas }),
519
+ });
520
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionPreparationEnd);
521
+ /** Ledger using Cosmos app only allows signing amino docs */
522
+ if ((0, wallet_base_1.isCosmosAminoOnlyWallet)(walletStrategy.wallet)) {
523
+ const aminoSignDoc = (0, sdk_ts_1.getAminoStdSignDoc)({
524
+ ...tx,
525
+ ...baseAccount,
526
+ msgs,
527
+ chainId,
528
+ gas: gas || tx.gas?.gas?.toString(),
529
+ timeoutHeight: timeoutHeight.toFixed(),
530
+ });
531
+ const signResponse = await walletStrategy.signAminoCosmosTransaction({
532
+ signDoc: aminoSignDoc,
533
+ address: tx.injectiveAddress,
534
+ });
535
+ txRaw.signatures = [
536
+ Buffer.from(signResponse.signature.signature, 'base64'),
537
+ ];
538
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionBroadcastStart);
539
+ const response = await walletStrategy.sendTransaction(txRaw, {
540
+ chainId,
541
+ endpoints,
542
+ address: tx.injectiveAddress,
543
+ txTimeout: txTimeoutInBlocks,
544
+ });
545
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
546
+ return await new sdk_ts_1.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
547
+ }
548
+ const directSignResponse = (await walletStrategy.signCosmosTransaction({
549
+ txRaw,
550
+ chainId,
551
+ address: tx.injectiveAddress,
552
+ accountNumber: baseAccount.accountNumber,
553
+ }));
554
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionBroadcastStart);
555
+ const response = await walletStrategy.sendTransaction(directSignResponse, {
556
+ chainId,
557
+ endpoints,
558
+ txTimeout: txTimeoutInBlocks,
559
+ address: tx.injectiveAddress,
560
+ });
561
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
562
+ return await new sdk_ts_1.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
563
+ }
564
+ /**
565
+ * We use this method only when we want to broadcast a transaction using Ledger on Keplr/Leap for Injective
566
+ *
567
+ * Note: Gas estimation not available
568
+ * @param tx the transaction that needs to be broadcasted
569
+ */
570
+ async experimentalBroadcastWalletThroughLedger(tx) {
571
+ const { chainId, endpoints, evmChainId, simulateTx, walletStrategy, txTimeout: txTimeoutInBlocks, } = this;
572
+ const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
573
+ /**
574
+ * We can only use this method
575
+ * when Ledger is connected through Keplr
576
+ */
577
+ if ([wallet_base_1.Wallet.Keplr, wallet_base_1.Wallet.Leap].includes(walletStrategy.getWallet())) {
578
+ const walletDeviceType = await walletStrategy.getWalletDeviceType();
579
+ const isLedgerConnected = walletDeviceType === wallet_base_1.WalletDeviceType.Hardware;
580
+ if (!isLedgerConnected) {
581
+ throw new exceptions_1.GeneralException(new Error(`This method can only be used when Ledger is connected through ${walletStrategy.getWallet()}`));
582
+ }
583
+ }
584
+ if (!evmChainId) {
585
+ throw new exceptions_1.GeneralException(new Error('Please provide evmChainId'));
586
+ }
587
+ const cosmosWallet = walletStrategy.getCosmosWallet(chainId);
588
+ const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
589
+ const timeoutHeight = (0, utils_1.toBigNumber)(latestHeight).plus(txTimeoutInBlocks);
590
+ const pubKey = await walletStrategy.getPubKey();
591
+ const gas = (tx.gas?.gas || (0, sdk_ts_1.getGasPriceBasedOnMessage)(msgs)).toString();
592
+ /** EIP712 for signing on Ethereum wallets */
593
+ const eip712TypedData = (0, sdk_ts_1.getEip712TypedData)({
594
+ msgs,
595
+ fee: await this.getStdFeeWithDynamicBaseFee({ ...tx.gas, gas }),
596
+ tx: {
597
+ chainId,
598
+ memo: tx.memo,
599
+ timeoutHeight: timeoutHeight.toFixed(),
600
+ sequence: baseAccount.sequence.toString(),
601
+ accountNumber: baseAccount.accountNumber.toString(),
602
+ },
603
+ evmChainId,
604
+ });
605
+ const aminoSignResponse = await cosmosWallet.signEIP712CosmosTx({
606
+ eip712: eip712TypedData,
607
+ signDoc: (0, wallet_base_1.createEip712StdSignDoc)({
608
+ ...tx,
609
+ ...baseAccount,
610
+ msgs,
611
+ chainId,
612
+ gas: gas || tx.gas?.gas?.toString(),
613
+ timeoutHeight: timeoutHeight.toFixed(),
614
+ }),
615
+ });
616
+ /**
617
+ * Create TxRaw from the signed tx that we
618
+ * get as a response in case the user changed the fee/memo
619
+ * on the Keplr popup
620
+ */
621
+ const { txRaw } = (0, sdk_ts_1.createTransaction)({
622
+ pubKey,
623
+ message: msgs,
624
+ memo: aminoSignResponse.signed.memo,
625
+ signMode: sdk_ts_1.SIGN_EIP712,
626
+ fee: aminoSignResponse.signed.fee,
627
+ sequence: parseInt(aminoSignResponse.signed.sequence, 10),
628
+ timeoutHeight: parseInt(aminoSignResponse.signed.timeout_height, 10),
629
+ accountNumber: parseInt(aminoSignResponse.signed.account_number, 10),
630
+ chainId,
631
+ });
632
+ /** Preparing the transaction for client broadcasting */
633
+ const web3Extension = (0, sdk_ts_1.createWeb3Extension)({
634
+ evmChainId,
635
+ });
636
+ const txRawEip712 = (0, sdk_ts_1.createTxRawEIP712)(txRaw, web3Extension);
637
+ if (simulateTx) {
638
+ await this.simulateTxRaw(txRawEip712);
639
+ }
640
+ /** Append Signatures */
641
+ const signatureBuff = Buffer.from(aminoSignResponse.signature.signature, 'base64');
642
+ txRawEip712.signatures = [signatureBuff];
643
+ /** Broadcast the transaction */
644
+ const response = await new sdk_ts_1.TxGrpcApi(endpoints.grpc).broadcast(txRawEip712, { txTimeout: txTimeoutInBlocks });
645
+ if (response.code !== 0) {
646
+ throw new exceptions_1.TransactionException(new Error(response.rawLog), {
647
+ code: exceptions_1.UnspecifiedErrorCode,
648
+ contextCode: response.code,
649
+ contextModule: response.codespace,
650
+ });
651
+ }
652
+ return response;
653
+ }
654
+ /**
655
+ * Prepare/sign/broadcast transaction using
656
+ * Cosmos native wallets using the Web3Gateway.
657
+ *
658
+ * @param tx The transaction that needs to be broadcasted
659
+ * @returns transaction hash
660
+ */
661
+ async broadcastDirectSignWithFeeDelegation(tx) {
662
+ const { options, chainId, endpoints, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation, txTimeout: txTimeoutInBlocks, } = this;
663
+ const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
664
+ /**
665
+ * We can only use this method when Keplr is connected
666
+ * with ledger
667
+ */
668
+ if (walletStrategy.getWallet() === wallet_base_1.Wallet.Keplr) {
669
+ const walletDeviceType = await walletStrategy.getWalletDeviceType();
670
+ const isLedgerConnectedOnKeplr = walletDeviceType === wallet_base_1.WalletDeviceType.Hardware;
671
+ if (isLedgerConnectedOnKeplr) {
672
+ throw new exceptions_1.GeneralException(new Error('Keplr + Ledger is not available with fee delegation. Connect with Ledger directly.'));
673
+ }
674
+ }
675
+ const cosmosWallet = walletStrategy.getCosmosWallet(chainId);
676
+ const canDisableCosmosGasCheck = [wallet_base_1.Wallet.Keplr, wallet_base_1.Wallet.OWallet].includes(walletStrategy.wallet);
677
+ const feePayerPubKey = await this.fetchFeePayerPubKey(options.feePayerPubKey);
678
+ const feePayerPublicKey = sdk_ts_1.PublicKey.fromBase64(feePayerPubKey);
679
+ const feePayer = feePayerPublicKey.toAddress().address;
680
+ /** Account Details * */
681
+ const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
682
+ const chainGrpcAuthApi = new sdk_ts_1.ChainGrpcAuthApi(endpoints.grpc);
683
+ if (httpHeaders) {
684
+ chainGrpcAuthApi.setMetadata(httpHeaders);
685
+ }
686
+ const feePayerAccountDetails = await chainGrpcAuthApi.fetchAccount(feePayer);
687
+ const { baseAccount: feePayerBaseAccount } = feePayerAccountDetails;
688
+ const timeoutHeight = (0, utils_1.toBigNumber)(latestHeight).plus(txTimeoutOnFeeDelegation
689
+ ? txTimeoutInBlocks
690
+ : utils_1.DEFAULT_BLOCK_TIMEOUT_HEIGHT);
691
+ const txTimeoutTimeInSeconds = txTimeoutInBlocks * utils_1.DEFAULT_BLOCK_TIME_IN_SECONDS;
692
+ const txTimeoutTimeInMilliSeconds = txTimeoutTimeInSeconds * 1000;
693
+ const pubKey = await walletStrategy.getPubKey();
694
+ const gas = (tx.gas?.gas || (0, sdk_ts_1.getGasPriceBasedOnMessage)(msgs)).toString();
695
+ /** Prepare the Transaction * */
696
+ const { txRaw } = await this.getTxWithSignersAndStdFee({
697
+ chainId,
698
+ memo: tx.memo,
699
+ message: msgs,
700
+ timeoutHeight: timeoutHeight.toNumber(),
701
+ signers: [
702
+ {
703
+ pubKey,
704
+ accountNumber: baseAccount.accountNumber,
705
+ sequence: baseAccount.sequence,
706
+ },
707
+ {
708
+ pubKey: feePayerPublicKey.toBase64(),
709
+ accountNumber: feePayerBaseAccount.accountNumber,
710
+ sequence: feePayerBaseAccount.sequence,
711
+ },
712
+ ],
713
+ fee: (0, utils_1.getStdFee)({ ...tx.gas, gas, payer: feePayer }),
714
+ });
715
+ // Temporary remove tx gas check because Keplr doesn't recognize feePayer
716
+ if (canDisableCosmosGasCheck && cosmosWallet.disableGasCheck) {
717
+ cosmosWallet.disableGasCheck(chainId);
718
+ }
719
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionPreparationStart);
720
+ const directSignResponse = (await walletStrategy.signCosmosTransaction({
721
+ txRaw,
722
+ chainId,
723
+ address: tx.injectiveAddress,
724
+ accountNumber: baseAccount.accountNumber,
725
+ }));
726
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionPreparationEnd);
727
+ const transactionApi = new sdk_ts_1.IndexerGrpcWeb3GwApi(endpoints.web3gw || endpoints.indexer);
728
+ if (httpHeaders) {
729
+ transactionApi.setMetadata(httpHeaders);
730
+ }
731
+ const broadcast = async () => await transactionApi.broadcastCosmosTxRequest({
732
+ address: tx.injectiveAddress,
733
+ txRaw: (0, sdk_ts_1.createTxRawFromSigResponse)(directSignResponse),
734
+ signature: directSignResponse.signature.signature,
735
+ pubKey: directSignResponse.signature.pub_key || {
736
+ value: pubKey,
737
+ type: '/injective.crypto.v1beta1.ethsecp256k1.PubKey',
738
+ },
739
+ });
740
+ try {
741
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionBroadcastStart);
742
+ const response = await broadcast();
743
+ walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
744
+ // Re-enable tx gas check removed above
745
+ if (canDisableCosmosGasCheck && cosmosWallet.enableGasCheck) {
746
+ cosmosWallet.enableGasCheck(chainId);
747
+ }
748
+ return await new sdk_ts_1.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
749
+ }
750
+ catch (e) {
751
+ const error = e;
752
+ if ((0, exceptions_1.isThrownException)(error)) {
753
+ const exception = error;
754
+ return await this.retryOnException(exception, broadcast);
755
+ }
756
+ throw e;
757
+ }
758
+ }
759
+ /**
760
+ * Fetch the fee payer's pub key from the web3 gateway
761
+ *
762
+ * Returns a base64 version of it
763
+ */
764
+ async fetchFeePayerPubKey(existingFeePayerPubKey) {
765
+ if (existingFeePayerPubKey) {
766
+ return existingFeePayerPubKey;
767
+ }
768
+ const { endpoints, httpHeaders } = this;
769
+ const transactionApi = new sdk_ts_1.IndexerGrpcWeb3GwApi(endpoints.web3gw || endpoints.indexer);
770
+ if (httpHeaders) {
771
+ transactionApi.setMetadata(httpHeaders);
772
+ }
773
+ const response = await transactionApi.fetchFeePayer();
774
+ if (!response.feePayerPubKey) {
775
+ throw new exceptions_1.GeneralException(new Error('Please provide a feePayerPubKey'));
776
+ }
777
+ if (response.feePayerPubKey.key.startsWith('0x') ||
778
+ response.feePayerPubKey.key.length === 66) {
779
+ return Buffer.from(response.feePayerPubKey.key, 'hex').toString('base64');
780
+ }
781
+ return response.feePayerPubKey.key;
782
+ }
783
+ async getStdFeeWithDynamicBaseFee(args) {
784
+ const client = new sdk_ts_1.ChainGrpcTxFeesApi(this.endpoints.grpc);
785
+ let baseFee = utils_1.DEFAULT_GAS_PRICE;
786
+ try {
787
+ const response = await client.fetchEipBaseFee();
788
+ baseFee = Number(response?.baseFee || utils_1.DEFAULT_GAS_PRICE);
789
+ }
790
+ catch { }
791
+ if (!args) {
792
+ return (0, utils_1.getStdFee)(baseFee ? { gasPrice: baseFee } : {});
793
+ }
794
+ if (typeof args === 'string') {
795
+ return (0, utils_1.getStdFee)({
796
+ ...(baseFee && {
797
+ gasPrice: (0, utils_1.toBigNumber)(baseFee).toFixed(),
798
+ }),
799
+ gas: args,
800
+ });
801
+ }
802
+ return (0, utils_1.getStdFee)({
803
+ ...args,
804
+ ...(baseFee && {
805
+ gasPrice: (0, utils_1.toBigNumber)(baseFee).toFixed(),
806
+ }),
807
+ });
808
+ }
809
+ /**
810
+ * In case we don't want to simulate the transaction
811
+ * we get the gas limit based on the message type.
812
+ *
813
+ * If we want to simulate the transaction we set the
814
+ * gas limit based on the simulation and add a small multiplier
815
+ * to be safe (factor of 1.2 as default)
816
+ */
817
+ async getTxWithSignersAndStdFee(args) {
818
+ const { simulateTx } = this;
819
+ if (!simulateTx) {
820
+ return {
821
+ ...(0, sdk_ts_1.createTransactionWithSigners)(args),
822
+ stdFee: await this.getStdFeeWithDynamicBaseFee(args.fee),
823
+ };
824
+ }
825
+ const result = await this.simulateTxWithSigners(args);
826
+ if (!result.gasInfo?.gasUsed) {
827
+ return {
828
+ ...(0, sdk_ts_1.createTransactionWithSigners)(args),
829
+ stdFee: await this.getStdFeeWithDynamicBaseFee(args.fee),
830
+ };
831
+ }
832
+ const stdGasFee = {
833
+ ...(await this.getStdFeeWithDynamicBaseFee({
834
+ ...(0, utils_1.getStdFee)(args.fee),
835
+ gas: (0, utils_1.toBigNumber)(result.gasInfo.gasUsed)
836
+ .times(this.gasBufferCoefficient)
837
+ .toFixed(),
838
+ })),
839
+ };
840
+ return {
841
+ ...(0, sdk_ts_1.createTransactionWithSigners)({
842
+ ...args,
843
+ fee: stdGasFee,
844
+ }),
845
+ stdFee: stdGasFee,
846
+ };
847
+ }
848
+ /**
849
+ * Create TxRaw and simulate it
850
+ */
851
+ async simulateTxRaw(txRaw) {
852
+ const { endpoints, httpHeaders } = this;
853
+ txRaw.signatures = [new Uint8Array(0)];
854
+ const client = new sdk_ts_1.TxGrpcApi(endpoints.grpc);
855
+ if (httpHeaders) {
856
+ client.setMetadata(httpHeaders);
857
+ }
858
+ const simulationResponse = await client.simulate(txRaw);
859
+ return simulationResponse;
860
+ }
861
+ /**
862
+ * Create TxRaw and simulate it
863
+ */
864
+ async simulateTxWithSigners(args) {
865
+ const { endpoints, httpHeaders } = this;
866
+ const { txRaw } = (0, sdk_ts_1.createTransactionWithSigners)(args);
867
+ txRaw.signatures = Array(Array.isArray(args.signers) ? args.signers.length : 1).fill(new Uint8Array(0));
868
+ const client = new sdk_ts_1.TxGrpcApi(endpoints.grpc);
869
+ if (httpHeaders) {
870
+ client.setMetadata(httpHeaders);
871
+ }
872
+ const simulationResponse = await client.simulate(txRaw);
873
+ return simulationResponse;
874
+ }
875
+ async retryOnException(exception, retryLogic) {
876
+ const errorsToRetry = Object.keys(this.retriesOnError);
877
+ const errorKey = `${exception.contextModule}-${exception.contextCode}`;
878
+ if (!errorsToRetry.includes(errorKey)) {
879
+ throw exception;
880
+ }
881
+ const retryConfig = this.retriesOnError[errorKey];
882
+ if (retryConfig.retries >= retryConfig.maxRetries) {
883
+ this.retriesOnError = defaultRetriesConfig();
884
+ throw exception;
885
+ }
886
+ await (0, utils_1.sleep)(retryConfig.timeout);
887
+ try {
888
+ retryConfig.retries += 1;
889
+ return await retryLogic();
890
+ }
891
+ catch (e) {
892
+ const error = e;
893
+ if ((0, exceptions_1.isThrownException)(error)) {
894
+ return this.retryOnException(error, retryLogic);
895
+ }
896
+ throw e;
897
+ }
898
+ }
899
+ async fetchAccountAndBlockDetails(address) {
900
+ const { endpoints, httpHeaders } = this;
901
+ const chainClient = new sdk_ts_1.ChainGrpcAuthApi(endpoints.grpc);
902
+ const tendermintClient = new sdk_ts_1.ChainGrpcTendermintApi(endpoints.grpc);
903
+ if (httpHeaders) {
904
+ chainClient.setMetadata(httpHeaders);
905
+ tendermintClient.setMetadata(httpHeaders);
906
+ }
907
+ const accountDetails = await chainClient.fetchAccount(address);
908
+ const { baseAccount } = accountDetails;
909
+ const latestBlock = await tendermintClient.fetchLatestBlock();
910
+ const latestHeight = latestBlock.header.height;
911
+ return {
912
+ baseAccount,
913
+ latestHeight,
914
+ accountDetails,
915
+ };
916
+ }
917
+ }
918
+ exports.MsgBroadcaster = MsgBroadcaster;