@injectivelabs/wallet-core 1.16.25-alpha.1 → 1.16.26

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,30 @@
1
+ import type { Network } from '@injectivelabs/networks';
2
+ import type { EvmChainId } from '@injectivelabs/ts-types';
3
+ import type BaseWalletStrategy from '../strategy/BaseWalletStrategy.js';
4
+ interface SendTransactionOptions {
5
+ tx: {
6
+ from: string;
7
+ to: string;
8
+ gas: string;
9
+ maxFeePerGas: string;
10
+ maxPriorityFeePerGas: string | null;
11
+ data: any;
12
+ };
13
+ address: string;
14
+ evmChainId?: EvmChainId;
15
+ }
16
+ /**
17
+ * Preparing and broadcasting
18
+ * Ethereum transactions
19
+ */
20
+ export declare class Web3Broadcaster {
21
+ private walletStrategy;
22
+ private evmChainId;
23
+ constructor({ walletStrategy, evmChainId, }: {
24
+ walletStrategy: BaseWalletStrategy;
25
+ evmChainId: EvmChainId;
26
+ network: Network;
27
+ });
28
+ sendTransaction(args: SendTransactionOptions): Promise<string>;
29
+ }
30
+ export {};
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Web3Broadcaster = void 0;
4
+ const exceptions_1 = require("@injectivelabs/exceptions");
5
+ /**
6
+ * Preparing and broadcasting
7
+ * Ethereum transactions
8
+ */
9
+ class Web3Broadcaster {
10
+ walletStrategy;
11
+ evmChainId;
12
+ constructor({ walletStrategy, evmChainId, }) {
13
+ this.evmChainId = evmChainId;
14
+ this.walletStrategy = walletStrategy;
15
+ }
16
+ async sendTransaction(args) {
17
+ const { evmChainId, walletStrategy } = this;
18
+ try {
19
+ const chainId = args.evmChainId || evmChainId;
20
+ const txHash = await walletStrategy.sendEvmTransaction(args.tx, {
21
+ evmChainId: chainId,
22
+ address: args.address,
23
+ });
24
+ await walletStrategy.getEvmTransactionReceipt(txHash, chainId);
25
+ return txHash;
26
+ }
27
+ catch (e) {
28
+ throw new exceptions_1.Web3Exception(new Error(e.message));
29
+ }
30
+ }
31
+ }
32
+ exports.Web3Broadcaster = Web3Broadcaster;
@@ -0,0 +1,3 @@
1
+ export * from './MsgBroadcaster.js';
2
+ export * from './Web3Broadcaster.js';
3
+ export * from './types.js';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./MsgBroadcaster.js"), exports);
18
+ __exportStar(require("./Web3Broadcaster.js"), exports);
19
+ __exportStar(require("./types.js"), exports);
@@ -0,0 +1,56 @@
1
+ import type { EventEmitter } from 'eventemitter3';
2
+ import type { Msgs } from '@injectivelabs/sdk-ts';
3
+ import type { ChainId, EvmChainId } from '@injectivelabs/ts-types';
4
+ import type BaseWalletStrategy from '../strategy/BaseWalletStrategy.js';
5
+ import type { Network, NetworkEndpoints } from '@injectivelabs/networks';
6
+ export interface MsgBroadcasterTxOptions {
7
+ memo?: string;
8
+ ethereumAddress?: string;
9
+ injectiveAddress?: string;
10
+ msgs: Msgs | Msgs[];
11
+ gas?: {
12
+ gasPrice?: string;
13
+ gas?: number; /** gas limit */
14
+ feePayer?: string;
15
+ granter?: string;
16
+ };
17
+ }
18
+ export interface MsgBroadcasterTxOptionsWithAddresses extends MsgBroadcasterTxOptions {
19
+ ethereumAddress: string;
20
+ injectiveAddress: string;
21
+ }
22
+ export interface MsgBroadcasterOptions {
23
+ network: Network;
24
+ endpoints?: NetworkEndpoints;
25
+ chainId?: ChainId;
26
+ evmChainId?: EvmChainId;
27
+ feePayerPubKey?: string;
28
+ simulateTx?: boolean;
29
+ txTimeoutOnFeeDelegation?: boolean;
30
+ txTimeout?: number;
31
+ walletStrategy: BaseWalletStrategy;
32
+ gasBufferCoefficient?: number;
33
+ httpHeaders?: Record<string, string>;
34
+ }
35
+ export declare const WalletStrategyEmitterEventType: {
36
+ readonly TransactionFail: "transaction-fail";
37
+ readonly TransactionSigned: "transaction-signed";
38
+ readonly TransactionSignStart: "transaction-sign-start";
39
+ readonly TransactionBroadcastEnd: "transaction-broadcast-end";
40
+ readonly WalletStrategyDisconnect: "wallet-strategy-disconnect";
41
+ readonly TransactionBroadcastStart: "transaction-broadcast-start";
42
+ readonly TransactionPreparationEnd: "transaction-preparation-end";
43
+ readonly TransactionPreparationStart: "transaction-preparation-start";
44
+ };
45
+ export type WalletStrategyEmitterEventType = (typeof WalletStrategyEmitterEventType)[keyof typeof WalletStrategyEmitterEventType];
46
+ export type WalletStrategyEmitterEvents = {
47
+ [WalletStrategyEmitterEventType.TransactionFail]: Record<string, any>;
48
+ [WalletStrategyEmitterEventType.TransactionSigned]: Record<string, any>;
49
+ [WalletStrategyEmitterEventType.TransactionSignStart]: Record<string, any>;
50
+ [WalletStrategyEmitterEventType.TransactionBroadcastEnd]: Record<string, any>;
51
+ [WalletStrategyEmitterEventType.WalletStrategyDisconnect]: Record<string, any>;
52
+ [WalletStrategyEmitterEventType.TransactionBroadcastStart]: Record<string, any>;
53
+ [WalletStrategyEmitterEventType.TransactionPreparationEnd]: Record<string, any>;
54
+ [WalletStrategyEmitterEventType.TransactionPreparationStart]: Record<string, any>;
55
+ };
56
+ export type WalletStrategyEmitter = EventEmitter<WalletStrategyEmitterEvents>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WalletStrategyEmitterEventType = void 0;
4
+ exports.WalletStrategyEmitterEventType = {
5
+ TransactionFail: 'transaction-fail',
6
+ TransactionSigned: 'transaction-signed',
7
+ TransactionSignStart: 'transaction-sign-start',
8
+ TransactionBroadcastEnd: 'transaction-broadcast-end',
9
+ WalletStrategyDisconnect: 'wallet-strategy-disconnect',
10
+ TransactionBroadcastStart: 'transaction-broadcast-start',
11
+ TransactionPreparationEnd: 'transaction-preparation-end',
12
+ TransactionPreparationStart: 'transaction-preparation-start',
13
+ };
@@ -0,0 +1,3 @@
1
+ export * from './broadcaster/index.js';
2
+ export * from './strategy/index.js';
3
+ export * from './utils/index.js';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./broadcaster/index.js"), exports);
18
+ __exportStar(require("./strategy/index.js"), exports);
19
+ __exportStar(require("./utils/index.js"), exports);
@@ -1,3 +1,3 @@
1
1
  {
2
- "type": "commonjs"
3
- }
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,58 @@
1
+ import { Wallet, type WalletMetadata } from '@injectivelabs/wallet-base';
2
+ import type { StdSignDoc } from '@keplr-wallet/types';
3
+ import type { OfflineSigner } from '@cosmjs/proto-signing';
4
+ import type { AccountAddress } from '@injectivelabs/ts-types';
5
+ import type { ChainId, EvmChainId } from '@injectivelabs/ts-types';
6
+ import type { WalletStrategyEmitter } from '../broadcaster/types.js';
7
+ import type { TxRaw, TxResponse, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
8
+ import type { Eip1193Provider, WalletDeviceType, ConcreteStrategiesArg, SendTransactionOptions, ConcreteWalletStrategy, onAccountChangeCallback, onChainIdChangeCallback, WalletStrategyArguments, CosmosWalletAbstraction, WalletStrategy as WalletStrategyInterface } from '@injectivelabs/wallet-base';
9
+ export default class BaseWalletStrategy implements WalletStrategyInterface {
10
+ strategies: ConcreteStrategiesArg;
11
+ wallet: Wallet;
12
+ args: WalletStrategyArguments;
13
+ metadata?: WalletMetadata;
14
+ wallets?: Wallet[];
15
+ private emitter;
16
+ on: WalletStrategyEmitter['on'];
17
+ off: WalletStrategyEmitter['off'];
18
+ emit: WalletStrategyEmitter['emit'];
19
+ constructor(args: WalletStrategyArguments);
20
+ getWallet(): Wallet;
21
+ setWallet(wallet: Wallet): void;
22
+ setMetadata(metadata?: WalletMetadata): void;
23
+ getStrategy(): ConcreteWalletStrategy;
24
+ getAddresses(args?: unknown): Promise<AccountAddress[]>;
25
+ getWalletDeviceType(): Promise<WalletDeviceType>;
26
+ getPubKey(address?: string): Promise<string>;
27
+ enable(args?: unknown): Promise<boolean>;
28
+ enableAndGetAddresses(args?: unknown): Promise<AccountAddress[]>;
29
+ getEthereumChainId(): Promise<string>;
30
+ getEvmTransactionReceipt(txHash: string, evmChainId?: EvmChainId): Promise<void>;
31
+ getSessionOrConfirm(address?: AccountAddress): Promise<string>;
32
+ getWalletClient<T>(): Promise<T>;
33
+ sendTransaction(tx: DirectSignResponse | TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
34
+ sendEvmTransaction(tx: any, options: {
35
+ evmChainId: EvmChainId;
36
+ address: AccountAddress;
37
+ }): Promise<string>;
38
+ signEip712TypedData(eip712TypedData: string, address: AccountAddress, options?: {
39
+ txTimeout?: number;
40
+ }): Promise<string>;
41
+ signAminoCosmosTransaction(transaction: {
42
+ signDoc: StdSignDoc;
43
+ address: string;
44
+ }): Promise<AminoSignResponse>;
45
+ signCosmosTransaction(transaction: {
46
+ txRaw: TxRaw;
47
+ accountNumber: number;
48
+ chainId: string;
49
+ address: string;
50
+ }): Promise<DirectSignResponse>;
51
+ signArbitrary(signer: string, data: string | Uint8Array): Promise<string | void>;
52
+ onAccountChange(callback: onAccountChangeCallback): Promise<void>;
53
+ onChainIdChange(callback: onChainIdChangeCallback): Promise<void>;
54
+ disconnect(): Promise<void>;
55
+ getCosmosWallet(chainId: ChainId): CosmosWalletAbstraction;
56
+ getEip1193Provider(): Promise<Eip1193Provider>;
57
+ getOfflineSigner(chainId: string): Promise<OfflineSigner>;
58
+ }
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const eventemitter3_1 = require("eventemitter3");
4
+ const exceptions_1 = require("@injectivelabs/exceptions");
5
+ const wallet_base_1 = require("@injectivelabs/wallet-base");
6
+ const types_js_1 = require("../broadcaster/types.js");
7
+ const getInitialWallet = (args) => {
8
+ if (args.wallet) {
9
+ return args.wallet;
10
+ }
11
+ const keys = Object.keys(args.strategies || {});
12
+ if (keys.length === 0) {
13
+ return wallet_base_1.Wallet.Metamask;
14
+ }
15
+ if (keys.includes(wallet_base_1.Wallet.Metamask) && args.evmOptions) {
16
+ return wallet_base_1.Wallet.Metamask;
17
+ }
18
+ if (keys.includes(wallet_base_1.Wallet.Keplr) && !args.evmOptions) {
19
+ return wallet_base_1.Wallet.Keplr;
20
+ }
21
+ return keys[0];
22
+ };
23
+ class BaseWalletStrategy {
24
+ strategies;
25
+ wallet;
26
+ args;
27
+ metadata;
28
+ wallets;
29
+ emitter;
30
+ on;
31
+ off;
32
+ emit;
33
+ constructor(args) {
34
+ this.args = args;
35
+ this.strategies = args.strategies;
36
+ this.wallet = getInitialWallet(args);
37
+ this.metadata = args.metadata;
38
+ this.emitter = new eventemitter3_1.EventEmitter();
39
+ this.on = this.emitter.on.bind(this.emitter);
40
+ this.off = this.emitter.off.bind(this.emitter);
41
+ this.emit = this.emitter.emit.bind(this.emitter);
42
+ }
43
+ getWallet() {
44
+ return this.wallet;
45
+ }
46
+ setWallet(wallet) {
47
+ this.wallet = wallet;
48
+ this.getStrategy();
49
+ }
50
+ setMetadata(metadata) {
51
+ console.log('Setting metadata', metadata);
52
+ this.metadata = metadata;
53
+ this.getStrategy().setMetadata?.(metadata);
54
+ }
55
+ getStrategy() {
56
+ if (!this.strategies[this.wallet]) {
57
+ throw new exceptions_1.GeneralException(new Error(`Wallet ${this.wallet} is not enabled/available!`));
58
+ }
59
+ return this.strategies[this.wallet];
60
+ }
61
+ getAddresses(args) {
62
+ return this.getStrategy().getAddresses(args);
63
+ }
64
+ getWalletDeviceType() {
65
+ return this.getStrategy().getWalletDeviceType();
66
+ }
67
+ getPubKey(address) {
68
+ return this.getStrategy().getPubKey(address);
69
+ }
70
+ enable(args) {
71
+ return this.getStrategy().enable(args);
72
+ }
73
+ async enableAndGetAddresses(args) {
74
+ await this.getStrategy().enable(args);
75
+ return this.getStrategy().getAddresses(args);
76
+ }
77
+ getEthereumChainId() {
78
+ return this.getStrategy().getEthereumChainId();
79
+ }
80
+ async getEvmTransactionReceipt(txHash, evmChainId) {
81
+ return this.getStrategy().getEvmTransactionReceipt(txHash, evmChainId);
82
+ }
83
+ async getSessionOrConfirm(address) {
84
+ return this.getStrategy().getSessionOrConfirm(address);
85
+ }
86
+ async getWalletClient() {
87
+ if (this.getStrategy()?.getWalletClient) {
88
+ const result = (this.getStrategy()?.getWalletClient)?.();
89
+ if (result) {
90
+ return result;
91
+ }
92
+ }
93
+ throw new exceptions_1.WalletException(new Error('Wallet client not found. Please check your wallet strategy.'));
94
+ }
95
+ async sendTransaction(tx, options) {
96
+ return this.getStrategy().sendTransaction(tx, options);
97
+ }
98
+ async sendEvmTransaction(tx /* TODO */, options) {
99
+ return this.getStrategy().sendEvmTransaction(tx, options);
100
+ }
101
+ async signEip712TypedData(eip712TypedData, address, options = {}) {
102
+ if ((0, wallet_base_1.isCosmosWallet)(this.wallet)) {
103
+ throw new exceptions_1.WalletException(new Error(`You can't sign Ethereum Transaction using ${this.wallet}`));
104
+ }
105
+ /** Phantom wallet needs enabling before signing */
106
+ if (this.wallet === wallet_base_1.Wallet.Phantom) {
107
+ await this.enable();
108
+ }
109
+ this.emit(types_js_1.WalletStrategyEmitterEventType.TransactionSignStart);
110
+ const response = await this.getStrategy().signEip712TypedData(eip712TypedData, address, options);
111
+ this.emit(types_js_1.WalletStrategyEmitterEventType.TransactionSigned);
112
+ return response;
113
+ }
114
+ async signAminoCosmosTransaction(transaction) {
115
+ if ((0, wallet_base_1.isEvmWallet)(this.wallet)) {
116
+ throw new exceptions_1.WalletException(new Error(`You can't sign Cosmos Transaction using ${this.wallet}`));
117
+ }
118
+ this.emit(types_js_1.WalletStrategyEmitterEventType.TransactionSignStart);
119
+ const response = await this.getStrategy().signAminoCosmosTransaction(transaction);
120
+ this.emit(types_js_1.WalletStrategyEmitterEventType.TransactionSigned);
121
+ return response;
122
+ }
123
+ async signCosmosTransaction(transaction) {
124
+ if ((0, wallet_base_1.isEvmWallet)(this.wallet)) {
125
+ throw new exceptions_1.WalletException(new Error(`You can't sign Cosmos Transaction using ${this.wallet}`));
126
+ }
127
+ this.emit(types_js_1.WalletStrategyEmitterEventType.TransactionSignStart);
128
+ const response = await this.getStrategy().signCosmosTransaction(transaction);
129
+ this.emit(types_js_1.WalletStrategyEmitterEventType.TransactionSigned);
130
+ return response;
131
+ }
132
+ async signArbitrary(signer, data) {
133
+ if (this.getStrategy().signArbitrary) {
134
+ this.emit(types_js_1.WalletStrategyEmitterEventType.TransactionSignStart);
135
+ const response = await this.getStrategy().signArbitrary(signer, data);
136
+ this.emit(types_js_1.WalletStrategyEmitterEventType.TransactionSigned);
137
+ return response;
138
+ }
139
+ }
140
+ async onAccountChange(callback) {
141
+ if (this.getStrategy().onAccountChange) {
142
+ return this.getStrategy().onAccountChange(callback);
143
+ }
144
+ }
145
+ async onChainIdChange(callback) {
146
+ if (this.getStrategy().onChainIdChange) {
147
+ return this.getStrategy().onChainIdChange(callback);
148
+ }
149
+ }
150
+ async disconnect() {
151
+ if (this.getStrategy().disconnect) {
152
+ await this.getStrategy().disconnect();
153
+ this.emit(types_js_1.WalletStrategyEmitterEventType.WalletStrategyDisconnect);
154
+ }
155
+ }
156
+ getCosmosWallet(chainId) {
157
+ const strategy = this.getStrategy();
158
+ if (strategy.getCosmosWallet == undefined) {
159
+ throw new exceptions_1.WalletException(new Error(`This method is not available for ${this.getWallet()} wallet`));
160
+ }
161
+ return strategy.getCosmosWallet(chainId);
162
+ }
163
+ async getEip1193Provider() {
164
+ if (this.getStrategy().getEip1193Provider) {
165
+ return this.getStrategy().getEip1193Provider();
166
+ }
167
+ throw new exceptions_1.WalletException(new Error('EIP1193 provider not found. Please check your wallet strategy.'));
168
+ }
169
+ async getOfflineSigner(chainId) {
170
+ if (this.getStrategy().getOfflineSigner) {
171
+ return this.getStrategy().getOfflineSigner(chainId);
172
+ }
173
+ throw new exceptions_1.WalletException(new Error('Offline signer not found. Please check your wallet strategy.'));
174
+ }
175
+ }
176
+ exports.default = BaseWalletStrategy;
@@ -0,0 +1,2 @@
1
+ import BaseWalletStrategy from './BaseWalletStrategy.js';
2
+ export { BaseWalletStrategy };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.BaseWalletStrategy = void 0;
7
+ const BaseWalletStrategy_js_1 = __importDefault(require("./BaseWalletStrategy.js"));
8
+ exports.BaseWalletStrategy = BaseWalletStrategy_js_1.default;
@@ -0,0 +1 @@
1
+ export * from './tx.js';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./tx.js"), exports);
@@ -0,0 +1 @@
1
+ export declare const checkIfTxRunOutOfGas: (e: unknown) => boolean;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkIfTxRunOutOfGas = void 0;
4
+ const exceptions_1 = require("@injectivelabs/exceptions");
5
+ const checkIfTxRunOutOfGas = (e) => {
6
+ return (e instanceof exceptions_1.TransactionException &&
7
+ e.contextCode === exceptions_1.ChainCosmosErrorCode.ErrOutOfGas &&
8
+ e.contextModule === exceptions_1.TransactionChainErrorModule.CosmosSdk &&
9
+ e.originalMessage.includes('out of gas'));
10
+ };
11
+ exports.checkIfTxRunOutOfGas = checkIfTxRunOutOfGas;
@@ -0,0 +1,137 @@
1
+ import { EvmChainId } from '@injectivelabs/ts-types';
2
+ import type { NetworkEndpoints } from '@injectivelabs/networks';
3
+ import type BaseWalletStrategy from '../strategy/BaseWalletStrategy.js';
4
+ import type { ChainId as ChainIdType, EvmChainId as EvmChainIdType } from '@injectivelabs/ts-types';
5
+ import type { MsgBroadcasterOptions, MsgBroadcasterTxOptions } from './types.js';
6
+ import type { TxResponse } from '@injectivelabs/sdk-ts';
7
+ /**
8
+ * This class is used to broadcast transactions
9
+ * using the WalletStrategy as a handler
10
+ * for the sign/broadcast flow of the transactions
11
+ *
12
+ * Mainly used for building UI products
13
+ */
14
+ export declare class MsgBroadcaster {
15
+ options: MsgBroadcasterOptions;
16
+ walletStrategy: BaseWalletStrategy;
17
+ endpoints: NetworkEndpoints;
18
+ chainId: ChainIdType;
19
+ txTimeout: number;
20
+ simulateTx: boolean;
21
+ txTimeoutOnFeeDelegation: boolean;
22
+ evmChainId?: EvmChainIdType;
23
+ gasBufferCoefficient: number;
24
+ retriesOnError: {
25
+ [x: string]: {
26
+ retries: number;
27
+ maxRetries: number;
28
+ timeout: number;
29
+ };
30
+ };
31
+ httpHeaders?: Record<string, string>;
32
+ constructor(options: MsgBroadcasterOptions);
33
+ setOptions(options: Partial<MsgBroadcasterOptions>): void;
34
+ getEvmChainId(): Promise<EvmChainId | undefined>;
35
+ /**
36
+ * Broadcasting the transaction using the client
37
+ * side approach for both cosmos and ethereum native wallets
38
+ *
39
+ * @param tx
40
+ * @returns {string} transaction hash
41
+ */
42
+ broadcast(tx: MsgBroadcasterTxOptions): Promise<TxResponse>;
43
+ /**
44
+ * Broadcasting the transaction using the client
45
+ * side approach for both cosmos and ethereum native wallets
46
+ * Note: using EIP712_V2 for Ethereum wallets
47
+ *
48
+ * @param tx
49
+ * @returns {string} transaction hash
50
+ */
51
+ broadcastV2(tx: MsgBroadcasterTxOptions): Promise<TxResponse>;
52
+ /**
53
+ * Broadcasting the transaction using the feeDelegation
54
+ * support approach for both cosmos and ethereum native wallets
55
+ *
56
+ * @param tx
57
+ * @returns {string} transaction hash
58
+ */
59
+ broadcastWithFeeDelegation(tx: MsgBroadcasterTxOptions): Promise<TxResponse>;
60
+ /**
61
+ * Prepare/sign/broadcast transaction using
62
+ * Ethereum native wallets on the client side.
63
+ *
64
+ * Note: Gas estimation not available
65
+ *
66
+ * @param tx The transaction that needs to be broadcasted
67
+ * @returns transaction hash
68
+ */
69
+ private broadcastEip712;
70
+ /**
71
+ * Prepare/sign/broadcast transaction using
72
+ * Ethereum native wallets on the client side.
73
+ *
74
+ * Note: Gas estimation not available
75
+ *
76
+ * @param tx The transaction that needs to be broadcasted
77
+ * @returns transaction hash
78
+ */
79
+ private broadcastEip712V2;
80
+ /**
81
+ * Prepare/sign/broadcast transaction using
82
+ * Ethereum native wallets using the Web3Gateway.
83
+ *
84
+ * @param tx The transaction that needs to be broadcasted
85
+ * @returns transaction hash
86
+ */
87
+ private broadcastEip712WithFeeDelegation;
88
+ /**
89
+ * Prepare/sign/broadcast transaction using
90
+ * Cosmos native wallets on the client side.
91
+ *
92
+ * @param tx The transaction that needs to be broadcasted
93
+ * @returns transaction hash
94
+ */
95
+ private broadcastDirectSign;
96
+ /**
97
+ * We use this method only when we want to broadcast a transaction using Ledger on Keplr/Leap for Injective
98
+ *
99
+ * Note: Gas estimation not available
100
+ * @param tx the transaction that needs to be broadcasted
101
+ */
102
+ private experimentalBroadcastWalletThroughLedger;
103
+ /**
104
+ * Prepare/sign/broadcast transaction using
105
+ * Cosmos native wallets using the Web3Gateway.
106
+ *
107
+ * @param tx The transaction that needs to be broadcasted
108
+ * @returns transaction hash
109
+ */
110
+ private broadcastDirectSignWithFeeDelegation;
111
+ /**
112
+ * Fetch the fee payer's pub key from the web3 gateway
113
+ *
114
+ * Returns a base64 version of it
115
+ */
116
+ private fetchFeePayerPubKey;
117
+ private getStdFeeWithDynamicBaseFee;
118
+ /**
119
+ * In case we don't want to simulate the transaction
120
+ * we get the gas limit based on the message type.
121
+ *
122
+ * If we want to simulate the transaction we set the
123
+ * gas limit based on the simulation and add a small multiplier
124
+ * to be safe (factor of 1.2 as default)
125
+ */
126
+ private getTxWithSignersAndStdFee;
127
+ /**
128
+ * Create TxRaw and simulate it
129
+ */
130
+ private simulateTxRaw;
131
+ /**
132
+ * Create TxRaw and simulate it
133
+ */
134
+ private simulateTxWithSigners;
135
+ private retryOnException;
136
+ private fetchAccountAndBlockDetails;
137
+ }