@injectivelabs/wallet-core 1.15.0 → 1.15.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.
- package/dist/cjs/broadcaster/MsgBroadcaster.d.ts +132 -0
- package/dist/cjs/broadcaster/MsgBroadcaster.js +782 -0
- package/dist/cjs/broadcaster/Web3Broadcaster.d.ts +29 -0
- package/dist/cjs/broadcaster/Web3Broadcaster.js +31 -0
- package/dist/cjs/broadcaster/index.d.ts +3 -0
- package/dist/cjs/broadcaster/index.js +19 -0
- package/dist/cjs/broadcaster/types.d.ts +32 -0
- package/dist/cjs/broadcaster/types.js +2 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/strategy/BaseWalletStrategy.d.ts +44 -0
- package/dist/cjs/strategy/BaseWalletStrategy.js +127 -0
- package/dist/cjs/strategy/index.d.ts +2 -0
- package/dist/cjs/strategy/index.js +8 -0
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.js +17 -0
- package/dist/cjs/utils/tx.d.ts +1 -0
- package/dist/cjs/utils/tx.js +11 -0
- package/dist/esm/broadcaster/MsgBroadcaster.d.ts +132 -0
- package/dist/esm/broadcaster/MsgBroadcaster.js +778 -0
- package/dist/esm/broadcaster/Web3Broadcaster.d.ts +29 -0
- package/dist/esm/broadcaster/Web3Broadcaster.js +27 -0
- package/dist/esm/broadcaster/index.d.ts +3 -0
- package/dist/esm/broadcaster/index.js +3 -0
- package/dist/esm/broadcaster/types.d.ts +32 -0
- package/dist/esm/broadcaster/types.js +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/strategy/BaseWalletStrategy.d.ts +44 -0
- package/dist/esm/strategy/BaseWalletStrategy.js +124 -0
- package/dist/esm/strategy/index.d.ts +2 -0
- package/dist/esm/strategy/index.js +2 -0
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/tx.d.ts +1 -0
- package/dist/esm/utils/tx.js +7 -0
- package/package.json +8 -8
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { EthereumChainId } from '@injectivelabs/ts-types';
|
|
2
|
+
import { Network } from '@injectivelabs/networks';
|
|
3
|
+
import 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
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Preparing and broadcasting
|
|
17
|
+
* Ethereum transactions
|
|
18
|
+
*/
|
|
19
|
+
export declare class Web3Broadcaster {
|
|
20
|
+
private walletStrategy;
|
|
21
|
+
private ethereumChainId;
|
|
22
|
+
constructor({ walletStrategy, ethereumChainId, }: {
|
|
23
|
+
walletStrategy: BaseWalletStrategy;
|
|
24
|
+
ethereumChainId: EthereumChainId;
|
|
25
|
+
network: Network;
|
|
26
|
+
});
|
|
27
|
+
sendTransaction(args: SendTransactionOptions): Promise<string>;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
ethereumChainId;
|
|
12
|
+
constructor({ walletStrategy, ethereumChainId, }) {
|
|
13
|
+
this.walletStrategy = walletStrategy;
|
|
14
|
+
this.ethereumChainId = ethereumChainId;
|
|
15
|
+
}
|
|
16
|
+
async sendTransaction(args) {
|
|
17
|
+
const { walletStrategy, ethereumChainId } = this;
|
|
18
|
+
try {
|
|
19
|
+
const txHash = await walletStrategy.sendEthereumTransaction(args.tx, {
|
|
20
|
+
ethereumChainId,
|
|
21
|
+
address: args.address,
|
|
22
|
+
});
|
|
23
|
+
await walletStrategy.getEthereumTransactionReceipt(txHash);
|
|
24
|
+
return txHash;
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
throw new exceptions_1.Web3Exception(new Error(e.message));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.Web3Broadcaster = Web3Broadcaster;
|
|
@@ -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,32 @@
|
|
|
1
|
+
import { Msgs } from '@injectivelabs/sdk-ts';
|
|
2
|
+
import { ChainId, EthereumChainId } from '@injectivelabs/ts-types';
|
|
3
|
+
import { Network, NetworkEndpoints } from '@injectivelabs/networks';
|
|
4
|
+
import BaseWalletStrategy from '../strategy/BaseWalletStrategy.js';
|
|
5
|
+
export interface MsgBroadcasterTxOptions {
|
|
6
|
+
memo?: string;
|
|
7
|
+
ethereumAddress?: string;
|
|
8
|
+
injectiveAddress?: string;
|
|
9
|
+
msgs: Msgs | Msgs[];
|
|
10
|
+
gas?: {
|
|
11
|
+
gasPrice?: string;
|
|
12
|
+
gas?: number; /** gas limit */
|
|
13
|
+
feePayer?: string;
|
|
14
|
+
granter?: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export interface MsgBroadcasterTxOptionsWithAddresses extends MsgBroadcasterTxOptions {
|
|
18
|
+
ethereumAddress: string;
|
|
19
|
+
injectiveAddress: string;
|
|
20
|
+
}
|
|
21
|
+
export interface MsgBroadcasterOptions {
|
|
22
|
+
network: Network;
|
|
23
|
+
endpoints?: NetworkEndpoints;
|
|
24
|
+
chainId?: ChainId;
|
|
25
|
+
ethereumChainId?: EthereumChainId;
|
|
26
|
+
feePayerPubKey?: string;
|
|
27
|
+
simulateTx?: boolean;
|
|
28
|
+
txTimeoutOnFeeDelegation?: boolean;
|
|
29
|
+
txTimeout?: number;
|
|
30
|
+
walletStrategy: BaseWalletStrategy;
|
|
31
|
+
gasBufferCoefficient?: number;
|
|
32
|
+
}
|
|
@@ -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);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { TxRaw, TxResponse, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
|
|
2
|
+
import { ChainId, AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
|
|
3
|
+
import { Wallet, WalletDeviceType, ConcreteStrategiesArg, SendTransactionOptions, ConcreteWalletStrategy, onAccountChangeCallback, onChainIdChangeCallback, WalletStrategyArguments, CosmosWalletAbstraction, ConcreteWalletStrategyOptions, WalletStrategy as WalletStrategyInterface } from '@injectivelabs/wallet-base';
|
|
4
|
+
import { StdSignDoc } from '@keplr-wallet/types';
|
|
5
|
+
export default class BaseWalletStrategy implements WalletStrategyInterface {
|
|
6
|
+
strategies: ConcreteStrategiesArg;
|
|
7
|
+
wallet: Wallet;
|
|
8
|
+
args: WalletStrategyArguments;
|
|
9
|
+
wallets?: Wallet[];
|
|
10
|
+
constructor(args: WalletStrategyArguments);
|
|
11
|
+
getWallet(): Wallet;
|
|
12
|
+
setWallet(wallet: Wallet): void;
|
|
13
|
+
setOptions(_options?: ConcreteWalletStrategyOptions): void;
|
|
14
|
+
getStrategy(): ConcreteWalletStrategy;
|
|
15
|
+
getAddresses(args?: unknown): Promise<AccountAddress[]>;
|
|
16
|
+
getWalletDeviceType(): Promise<WalletDeviceType>;
|
|
17
|
+
getPubKey(address?: string): Promise<string>;
|
|
18
|
+
enable(args?: unknown): Promise<boolean>;
|
|
19
|
+
enableAndGetAddresses(args?: unknown): Promise<AccountAddress[]>;
|
|
20
|
+
getEthereumChainId(): Promise<string>;
|
|
21
|
+
getEthereumTransactionReceipt(txHash: string): Promise<void>;
|
|
22
|
+
getSessionOrConfirm(address?: AccountAddress): Promise<string>;
|
|
23
|
+
sendTransaction(tx: DirectSignResponse | TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
|
|
24
|
+
sendEthereumTransaction(tx: any, options: {
|
|
25
|
+
address: AccountAddress;
|
|
26
|
+
ethereumChainId: EthereumChainId;
|
|
27
|
+
}): Promise<string>;
|
|
28
|
+
signEip712TypedData(eip712TypedData: string, address: AccountAddress): Promise<string>;
|
|
29
|
+
signAminoCosmosTransaction(transaction: {
|
|
30
|
+
signDoc: StdSignDoc;
|
|
31
|
+
address: string;
|
|
32
|
+
}): Promise<AminoSignResponse>;
|
|
33
|
+
signCosmosTransaction(transaction: {
|
|
34
|
+
txRaw: TxRaw;
|
|
35
|
+
accountNumber: number;
|
|
36
|
+
chainId: string;
|
|
37
|
+
address: string;
|
|
38
|
+
}): Promise<DirectSignResponse>;
|
|
39
|
+
signArbitrary(signer: string, data: string | Uint8Array): Promise<string | void>;
|
|
40
|
+
onAccountChange(callback: onAccountChangeCallback): Promise<void>;
|
|
41
|
+
onChainIdChange(callback: onChainIdChangeCallback): Promise<void>;
|
|
42
|
+
disconnect(): Promise<void>;
|
|
43
|
+
getCosmosWallet(chainId: ChainId): CosmosWalletAbstraction;
|
|
44
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
4
|
+
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
5
|
+
const getInitialWallet = (args) => {
|
|
6
|
+
if (args.wallet) {
|
|
7
|
+
return args.wallet;
|
|
8
|
+
}
|
|
9
|
+
const keys = Object.keys(args.strategies || {});
|
|
10
|
+
if (keys.length === 0) {
|
|
11
|
+
throw new exceptions_1.GeneralException(new Error('No strategies provided to BaseWalletStrategy'));
|
|
12
|
+
}
|
|
13
|
+
if (keys.includes(wallet_base_1.Wallet.Metamask) && args.ethereumOptions) {
|
|
14
|
+
return wallet_base_1.Wallet.Metamask;
|
|
15
|
+
}
|
|
16
|
+
if (keys.includes(wallet_base_1.Wallet.Keplr) && !args.ethereumOptions) {
|
|
17
|
+
return wallet_base_1.Wallet.Keplr;
|
|
18
|
+
}
|
|
19
|
+
return keys[0];
|
|
20
|
+
};
|
|
21
|
+
class BaseWalletStrategy {
|
|
22
|
+
strategies;
|
|
23
|
+
wallet;
|
|
24
|
+
args;
|
|
25
|
+
wallets;
|
|
26
|
+
constructor(args) {
|
|
27
|
+
this.args = args;
|
|
28
|
+
this.strategies = args.strategies;
|
|
29
|
+
this.wallet = getInitialWallet(args);
|
|
30
|
+
}
|
|
31
|
+
getWallet() {
|
|
32
|
+
return this.wallet;
|
|
33
|
+
}
|
|
34
|
+
setWallet(wallet) {
|
|
35
|
+
this.wallet = wallet;
|
|
36
|
+
}
|
|
37
|
+
setOptions(_options) {
|
|
38
|
+
//
|
|
39
|
+
}
|
|
40
|
+
getStrategy() {
|
|
41
|
+
if (!this.strategies[this.wallet]) {
|
|
42
|
+
throw new exceptions_1.GeneralException(new Error(`Wallet ${this.wallet} is not enabled/available!`));
|
|
43
|
+
}
|
|
44
|
+
return this.strategies[this.wallet];
|
|
45
|
+
}
|
|
46
|
+
getAddresses(args) {
|
|
47
|
+
return this.getStrategy().getAddresses(args);
|
|
48
|
+
}
|
|
49
|
+
getWalletDeviceType() {
|
|
50
|
+
return this.getStrategy().getWalletDeviceType();
|
|
51
|
+
}
|
|
52
|
+
getPubKey(address) {
|
|
53
|
+
return this.getStrategy().getPubKey(address);
|
|
54
|
+
}
|
|
55
|
+
enable(args) {
|
|
56
|
+
return this.getStrategy().enable(args);
|
|
57
|
+
}
|
|
58
|
+
async enableAndGetAddresses(args) {
|
|
59
|
+
await this.getStrategy().enable(args);
|
|
60
|
+
return this.getStrategy().getAddresses(args);
|
|
61
|
+
}
|
|
62
|
+
getEthereumChainId() {
|
|
63
|
+
return this.getStrategy().getEthereumChainId();
|
|
64
|
+
}
|
|
65
|
+
async getEthereumTransactionReceipt(txHash) {
|
|
66
|
+
return this.getStrategy().getEthereumTransactionReceipt(txHash);
|
|
67
|
+
}
|
|
68
|
+
async getSessionOrConfirm(address) {
|
|
69
|
+
return this.getStrategy().getSessionOrConfirm(address);
|
|
70
|
+
}
|
|
71
|
+
async sendTransaction(tx, options) {
|
|
72
|
+
return this.getStrategy().sendTransaction(tx, options);
|
|
73
|
+
}
|
|
74
|
+
async sendEthereumTransaction(tx /* TODO */, options) {
|
|
75
|
+
return this.getStrategy().sendEthereumTransaction(tx, options);
|
|
76
|
+
}
|
|
77
|
+
async signEip712TypedData(eip712TypedData, address) {
|
|
78
|
+
if ((0, wallet_base_1.isCosmosWallet)(this.wallet)) {
|
|
79
|
+
throw new exceptions_1.WalletException(new Error(`You can't sign Ethereum Transaction using ${this.wallet}`));
|
|
80
|
+
}
|
|
81
|
+
/** Phantom wallet needs enabling before signing */
|
|
82
|
+
if (this.wallet === wallet_base_1.Wallet.Phantom) {
|
|
83
|
+
await this.enable();
|
|
84
|
+
}
|
|
85
|
+
return this.getStrategy().signEip712TypedData(eip712TypedData, address);
|
|
86
|
+
}
|
|
87
|
+
async signAminoCosmosTransaction(transaction) {
|
|
88
|
+
if ((0, wallet_base_1.isEvmWallet)(this.wallet)) {
|
|
89
|
+
throw new exceptions_1.WalletException(new Error(`You can't sign Cosmos Transaction using ${this.wallet}`));
|
|
90
|
+
}
|
|
91
|
+
return this.getStrategy().signAminoCosmosTransaction(transaction);
|
|
92
|
+
}
|
|
93
|
+
async signCosmosTransaction(transaction) {
|
|
94
|
+
if ((0, wallet_base_1.isEvmWallet)(this.wallet)) {
|
|
95
|
+
throw new exceptions_1.WalletException(new Error(`You can't sign Cosmos Transaction using ${this.wallet}`));
|
|
96
|
+
}
|
|
97
|
+
return this.getStrategy().signCosmosTransaction(transaction);
|
|
98
|
+
}
|
|
99
|
+
async signArbitrary(signer, data) {
|
|
100
|
+
if (this.getStrategy().signArbitrary) {
|
|
101
|
+
return this.getStrategy().signArbitrary(signer, data);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async onAccountChange(callback) {
|
|
105
|
+
if (this.getStrategy().onAccountChange) {
|
|
106
|
+
return this.getStrategy().onAccountChange(callback);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async onChainIdChange(callback) {
|
|
110
|
+
if (this.getStrategy().onChainIdChange) {
|
|
111
|
+
return this.getStrategy().onChainIdChange(callback);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async disconnect() {
|
|
115
|
+
if (this.getStrategy().disconnect) {
|
|
116
|
+
await this.getStrategy().disconnect();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
getCosmosWallet(chainId) {
|
|
120
|
+
const strategy = this.getStrategy();
|
|
121
|
+
if (strategy.getCosmosWallet == undefined) {
|
|
122
|
+
throw new exceptions_1.WalletException(new Error(`This method is not available for ${this.getWallet()} wallet`));
|
|
123
|
+
}
|
|
124
|
+
return strategy.getCosmosWallet(chainId);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.default = 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,132 @@
|
|
|
1
|
+
import { TxResponse } from '@injectivelabs/sdk-ts';
|
|
2
|
+
import { NetworkEndpoints } from '@injectivelabs/networks';
|
|
3
|
+
import { ChainId, EthereumChainId } from '@injectivelabs/ts-types';
|
|
4
|
+
import { MsgBroadcasterOptions, MsgBroadcasterTxOptions } from './types.js';
|
|
5
|
+
import BaseWalletStrategy from '../strategy/BaseWalletStrategy.js';
|
|
6
|
+
/**
|
|
7
|
+
* This class is used to broadcast transactions
|
|
8
|
+
* using the WalletStrategy as a handler
|
|
9
|
+
* for the sign/broadcast flow of the transactions
|
|
10
|
+
*
|
|
11
|
+
* Mainly used for building UI products
|
|
12
|
+
*/
|
|
13
|
+
export declare class MsgBroadcaster {
|
|
14
|
+
options: MsgBroadcasterOptions;
|
|
15
|
+
walletStrategy: BaseWalletStrategy;
|
|
16
|
+
endpoints: NetworkEndpoints;
|
|
17
|
+
chainId: ChainId;
|
|
18
|
+
txTimeout: number;
|
|
19
|
+
simulateTx: boolean;
|
|
20
|
+
txTimeoutOnFeeDelegation: boolean;
|
|
21
|
+
ethereumChainId?: EthereumChainId;
|
|
22
|
+
gasBufferCoefficient: number;
|
|
23
|
+
retriesOnError: {
|
|
24
|
+
"sdk-20": {
|
|
25
|
+
retries: number;
|
|
26
|
+
maxRetries: number;
|
|
27
|
+
timeout: number;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
constructor(options: MsgBroadcasterOptions);
|
|
31
|
+
setOptions(options: Partial<MsgBroadcasterOptions>): void;
|
|
32
|
+
/**
|
|
33
|
+
* Broadcasting the transaction using the client
|
|
34
|
+
* side approach for both cosmos and ethereum native wallets
|
|
35
|
+
*
|
|
36
|
+
* @param tx
|
|
37
|
+
* @returns {string} transaction hash
|
|
38
|
+
*/
|
|
39
|
+
broadcast(tx: MsgBroadcasterTxOptions): Promise<TxResponse>;
|
|
40
|
+
/**
|
|
41
|
+
* Broadcasting the transaction using the client
|
|
42
|
+
* side approach for both cosmos and ethereum native wallets
|
|
43
|
+
* Note: using EIP712_V2 for Ethereum wallets
|
|
44
|
+
*
|
|
45
|
+
* @param tx
|
|
46
|
+
* @returns {string} transaction hash
|
|
47
|
+
*/
|
|
48
|
+
broadcastV2(tx: MsgBroadcasterTxOptions): Promise<TxResponse>;
|
|
49
|
+
/**
|
|
50
|
+
* Broadcasting the transaction using the feeDelegation
|
|
51
|
+
* support approach for both cosmos and ethereum native wallets
|
|
52
|
+
*
|
|
53
|
+
* @param tx
|
|
54
|
+
* @returns {string} transaction hash
|
|
55
|
+
*/
|
|
56
|
+
broadcastWithFeeDelegation(tx: MsgBroadcasterTxOptions): Promise<TxResponse>;
|
|
57
|
+
/**
|
|
58
|
+
* Prepare/sign/broadcast transaction using
|
|
59
|
+
* Ethereum native wallets on the client side.
|
|
60
|
+
*
|
|
61
|
+
* Note: Gas estimation not available
|
|
62
|
+
*
|
|
63
|
+
* @param tx The transaction that needs to be broadcasted
|
|
64
|
+
* @returns transaction hash
|
|
65
|
+
*/
|
|
66
|
+
private broadcastEip712;
|
|
67
|
+
/**
|
|
68
|
+
* Prepare/sign/broadcast transaction using
|
|
69
|
+
* Ethereum native wallets on the client side.
|
|
70
|
+
*
|
|
71
|
+
* Note: Gas estimation not available
|
|
72
|
+
*
|
|
73
|
+
* @param tx The transaction that needs to be broadcasted
|
|
74
|
+
* @returns transaction hash
|
|
75
|
+
*/
|
|
76
|
+
private broadcastEip712V2;
|
|
77
|
+
/**
|
|
78
|
+
* Prepare/sign/broadcast transaction using
|
|
79
|
+
* Ethereum native wallets using the Web3Gateway.
|
|
80
|
+
*
|
|
81
|
+
* @param tx The transaction that needs to be broadcasted
|
|
82
|
+
* @returns transaction hash
|
|
83
|
+
*/
|
|
84
|
+
private broadcastEip712WithFeeDelegation;
|
|
85
|
+
/**
|
|
86
|
+
* Prepare/sign/broadcast transaction using
|
|
87
|
+
* Cosmos native wallets on the client side.
|
|
88
|
+
*
|
|
89
|
+
* @param tx The transaction that needs to be broadcasted
|
|
90
|
+
* @returns transaction hash
|
|
91
|
+
*/
|
|
92
|
+
private broadcastDirectSign;
|
|
93
|
+
/**
|
|
94
|
+
* We use this method only when we want to broadcast a transaction using Ledger on Keplr/Leap for Injective
|
|
95
|
+
*
|
|
96
|
+
* Note: Gas estimation not available
|
|
97
|
+
* @param tx the transaction that needs to be broadcasted
|
|
98
|
+
*/
|
|
99
|
+
private experimentalBroadcastWalletThroughLedger;
|
|
100
|
+
/**
|
|
101
|
+
* Prepare/sign/broadcast transaction using
|
|
102
|
+
* Cosmos native wallets using the Web3Gateway.
|
|
103
|
+
*
|
|
104
|
+
* @param tx The transaction that needs to be broadcasted
|
|
105
|
+
* @returns transaction hash
|
|
106
|
+
*/
|
|
107
|
+
private broadcastDirectSignWithFeeDelegation;
|
|
108
|
+
/**
|
|
109
|
+
* Fetch the fee payer's pub key from the web3 gateway
|
|
110
|
+
*
|
|
111
|
+
* Returns a base64 version of it
|
|
112
|
+
*/
|
|
113
|
+
private fetchFeePayerPubKey;
|
|
114
|
+
/**
|
|
115
|
+
* In case we don't want to simulate the transaction
|
|
116
|
+
* we get the gas limit based on the message type.
|
|
117
|
+
*
|
|
118
|
+
* If we want to simulate the transaction we set the
|
|
119
|
+
* gas limit based on the simulation and add a small multiplier
|
|
120
|
+
* to be safe (factor of 1.2 as default)
|
|
121
|
+
*/
|
|
122
|
+
private getTxWithSignersAndStdFee;
|
|
123
|
+
/**
|
|
124
|
+
* Create TxRaw and simulate it
|
|
125
|
+
*/
|
|
126
|
+
private simulateTxRaw;
|
|
127
|
+
/**
|
|
128
|
+
* Create TxRaw and simulate it
|
|
129
|
+
*/
|
|
130
|
+
private simulateTxWithSigners;
|
|
131
|
+
private retryOnException;
|
|
132
|
+
}
|