@injectivelabs/wallet-core 1.15.36 → 1.15.38
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.
|
@@ -112,6 +112,7 @@ export declare class MsgBroadcaster {
|
|
|
112
112
|
* Returns a base64 version of it
|
|
113
113
|
*/
|
|
114
114
|
private fetchFeePayerPubKey;
|
|
115
|
+
private getStdFeeWithDynamicBaseFee;
|
|
115
116
|
/**
|
|
116
117
|
* In case we don't want to simulate the transaction
|
|
117
118
|
* we get the gas limit based on the message type.
|
|
@@ -181,11 +181,14 @@ class MsgBroadcaster {
|
|
|
181
181
|
const gas = (tx.gas?.gas || (0, sdk_ts_1.getGasPriceBasedOnMessage)(msgs)).toString();
|
|
182
182
|
let stdFee = (0, utils_1.getStdFee)({ ...tx.gas, gas });
|
|
183
183
|
/**
|
|
184
|
-
* Account has been created on chain
|
|
185
|
-
* and we
|
|
184
|
+
* Account has not been created on chain
|
|
185
|
+
* and we cannot simulate the transaction
|
|
186
186
|
* to estimate the gas
|
|
187
187
|
**/
|
|
188
|
-
if (baseAccount.pubKey) {
|
|
188
|
+
if (!baseAccount.pubKey) {
|
|
189
|
+
stdFee = await this.getStdFeeWithDynamicBaseFee(stdFee);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
189
192
|
const { stdFee: simulatedStdFee } = await this.getTxWithSignersAndStdFee({
|
|
190
193
|
chainId,
|
|
191
194
|
signMode: sdk_ts_1.SIGN_EIP712,
|
|
@@ -267,11 +270,14 @@ class MsgBroadcaster {
|
|
|
267
270
|
const gas = (tx.gas?.gas || (0, sdk_ts_1.getGasPriceBasedOnMessage)(msgs)).toString();
|
|
268
271
|
let stdFee = (0, utils_1.getStdFee)({ ...tx.gas, gas });
|
|
269
272
|
/**
|
|
270
|
-
* Account has been created on chain
|
|
271
|
-
* and we
|
|
273
|
+
* Account has not been created on chain
|
|
274
|
+
* and we cannot simulate the transaction
|
|
272
275
|
* to estimate the gas
|
|
273
276
|
**/
|
|
274
|
-
if (baseAccount.pubKey) {
|
|
277
|
+
if (!baseAccount.pubKey) {
|
|
278
|
+
stdFee = await this.getStdFeeWithDynamicBaseFee(stdFee);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
275
281
|
const { stdFee: simulatedStdFee } = await this.getTxWithSignersAndStdFee({
|
|
276
282
|
chainId,
|
|
277
283
|
signMode: sdk_ts_1.SIGN_EIP712_V2,
|
|
@@ -280,8 +286,8 @@ class MsgBroadcaster {
|
|
|
280
286
|
timeoutHeight: timeoutHeight.toNumber(),
|
|
281
287
|
signers: {
|
|
282
288
|
pubKey: baseAccount.pubKey.key,
|
|
283
|
-
accountNumber: baseAccount.accountNumber,
|
|
284
289
|
sequence: baseAccount.sequence,
|
|
290
|
+
accountNumber: baseAccount.accountNumber,
|
|
285
291
|
},
|
|
286
292
|
fee: stdFee,
|
|
287
293
|
});
|
|
@@ -529,13 +535,13 @@ class MsgBroadcaster {
|
|
|
529
535
|
/** EIP712 for signing on Ethereum wallets */
|
|
530
536
|
const eip712TypedData = (0, sdk_ts_1.getEip712TypedData)({
|
|
531
537
|
msgs,
|
|
532
|
-
fee:
|
|
538
|
+
fee: await this.getStdFeeWithDynamicBaseFee({ ...tx.gas, gas }),
|
|
533
539
|
tx: {
|
|
540
|
+
chainId,
|
|
534
541
|
memo: tx.memo,
|
|
535
|
-
accountNumber: baseAccount.accountNumber.toString(),
|
|
536
|
-
sequence: baseAccount.sequence.toString(),
|
|
537
542
|
timeoutHeight: timeoutHeight.toFixed(),
|
|
538
|
-
|
|
543
|
+
sequence: baseAccount.sequence.toString(),
|
|
544
|
+
accountNumber: baseAccount.accountNumber.toString(),
|
|
539
545
|
},
|
|
540
546
|
ethereumChainId,
|
|
541
547
|
});
|
|
@@ -713,6 +719,32 @@ class MsgBroadcaster {
|
|
|
713
719
|
}
|
|
714
720
|
return response.feePayerPubKey.key;
|
|
715
721
|
}
|
|
722
|
+
async getStdFeeWithDynamicBaseFee(args) {
|
|
723
|
+
const client = new sdk_ts_1.ChainGrpcTxFeesApi(this.endpoints.grpc);
|
|
724
|
+
let baseFee = utils_1.DEFAULT_GAS_PRICE;
|
|
725
|
+
try {
|
|
726
|
+
const response = await client.fetchEipBaseFee();
|
|
727
|
+
baseFee = Number(response?.baseFee || utils_1.DEFAULT_GAS_PRICE);
|
|
728
|
+
}
|
|
729
|
+
catch { }
|
|
730
|
+
if (!args) {
|
|
731
|
+
return (0, utils_1.getStdFee)(baseFee ? { gasPrice: baseFee } : {});
|
|
732
|
+
}
|
|
733
|
+
if (typeof args === 'string') {
|
|
734
|
+
return (0, utils_1.getStdFee)({
|
|
735
|
+
...(baseFee && {
|
|
736
|
+
gasPrice: new utils_1.BigNumberInBase(baseFee).toFixed(),
|
|
737
|
+
}),
|
|
738
|
+
gas: args,
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
return (0, utils_1.getStdFee)({
|
|
742
|
+
...args,
|
|
743
|
+
...(baseFee && {
|
|
744
|
+
gasPrice: new utils_1.BigNumberInBase(baseFee).toFixed(),
|
|
745
|
+
}),
|
|
746
|
+
});
|
|
747
|
+
}
|
|
716
748
|
/**
|
|
717
749
|
* In case we don't want to simulate the transaction
|
|
718
750
|
* we get the gas limit based on the message type.
|
|
@@ -726,24 +758,21 @@ class MsgBroadcaster {
|
|
|
726
758
|
if (!simulateTx) {
|
|
727
759
|
return {
|
|
728
760
|
...(0, sdk_ts_1.createTransactionWithSigners)(args),
|
|
729
|
-
stdFee:
|
|
761
|
+
stdFee: await this.getStdFeeWithDynamicBaseFee(args.fee),
|
|
730
762
|
};
|
|
731
763
|
}
|
|
732
764
|
const result = await this.simulateTxWithSigners(args);
|
|
733
765
|
if (!result.gasInfo?.gasUsed) {
|
|
734
766
|
return {
|
|
735
767
|
...(0, sdk_ts_1.createTransactionWithSigners)(args),
|
|
736
|
-
stdFee:
|
|
768
|
+
stdFee: await this.getStdFeeWithDynamicBaseFee(args.fee),
|
|
737
769
|
};
|
|
738
770
|
}
|
|
739
|
-
const stdGasFee = {
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
.toFixed(),
|
|
745
|
-
}),
|
|
746
|
-
};
|
|
771
|
+
const stdGasFee = await this.getStdFeeWithDynamicBaseFee({
|
|
772
|
+
gas: new utils_1.BigNumberInBase(result.gasInfo.gasUsed)
|
|
773
|
+
.times(this.gasBufferCoefficient)
|
|
774
|
+
.toFixed(),
|
|
775
|
+
});
|
|
747
776
|
return {
|
|
748
777
|
...(0, sdk_ts_1.createTransactionWithSigners)({
|
|
749
778
|
...args,
|
|
@@ -112,6 +112,7 @@ export declare class MsgBroadcaster {
|
|
|
112
112
|
* Returns a base64 version of it
|
|
113
113
|
*/
|
|
114
114
|
private fetchFeePayerPubKey;
|
|
115
|
+
private getStdFeeWithDynamicBaseFee;
|
|
115
116
|
/**
|
|
116
117
|
* In case we don't want to simulate the transaction
|
|
117
118
|
* we get the gas limit based on the message type.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TxGrpcApi, hexToBuff, PublicKey, SIGN_DIRECT, hexToBase64, ofacWallets,
|
|
2
|
-
import { sleep, getStdFee, BigNumberInBase, DEFAULT_BLOCK_TIMEOUT_HEIGHT, } from '@injectivelabs/utils';
|
|
1
|
+
import { TxGrpcApi, hexToBuff, PublicKey, SIGN_DIRECT, hexToBase64, ofacWallets, SIGN_EIP712, SIGN_EIP712_V2, ChainGrpcAuthApi, createTxRawEIP712, createTransaction, ChainGrpcTxFeesApi, getAminoStdSignDoc, getEip712TypedData, createWeb3Extension, getEip712TypedDataV2, IndexerGrpcWeb3GwApi, ChainGrpcTendermintApi, getGasPriceBasedOnMessage, createTxRawFromSigResponse, recoverTypedSignaturePubKey, createTransactionWithSigners, } from '@injectivelabs/sdk-ts';
|
|
2
|
+
import { sleep, getStdFee, BigNumberInBase, DEFAULT_GAS_PRICE, DEFAULT_BLOCK_TIMEOUT_HEIGHT, } from '@injectivelabs/utils';
|
|
3
3
|
import { GeneralException, isThrownException, UnspecifiedErrorCode, ChainCosmosErrorCode, TransactionException, TransactionChainErrorModule, } from '@injectivelabs/exceptions';
|
|
4
4
|
import { getNetworkInfo, getNetworkEndpoints, } from '@injectivelabs/networks';
|
|
5
5
|
import { WalletStrategyEmitterEventType, } from './types.js';
|
|
@@ -178,11 +178,14 @@ export class MsgBroadcaster {
|
|
|
178
178
|
const gas = (tx.gas?.gas || getGasPriceBasedOnMessage(msgs)).toString();
|
|
179
179
|
let stdFee = getStdFee({ ...tx.gas, gas });
|
|
180
180
|
/**
|
|
181
|
-
* Account has been created on chain
|
|
182
|
-
* and we
|
|
181
|
+
* Account has not been created on chain
|
|
182
|
+
* and we cannot simulate the transaction
|
|
183
183
|
* to estimate the gas
|
|
184
184
|
**/
|
|
185
|
-
if (baseAccount.pubKey) {
|
|
185
|
+
if (!baseAccount.pubKey) {
|
|
186
|
+
stdFee = await this.getStdFeeWithDynamicBaseFee(stdFee);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
186
189
|
const { stdFee: simulatedStdFee } = await this.getTxWithSignersAndStdFee({
|
|
187
190
|
chainId,
|
|
188
191
|
signMode: SIGN_EIP712,
|
|
@@ -264,11 +267,14 @@ export class MsgBroadcaster {
|
|
|
264
267
|
const gas = (tx.gas?.gas || getGasPriceBasedOnMessage(msgs)).toString();
|
|
265
268
|
let stdFee = getStdFee({ ...tx.gas, gas });
|
|
266
269
|
/**
|
|
267
|
-
* Account has been created on chain
|
|
268
|
-
* and we
|
|
270
|
+
* Account has not been created on chain
|
|
271
|
+
* and we cannot simulate the transaction
|
|
269
272
|
* to estimate the gas
|
|
270
273
|
**/
|
|
271
|
-
if (baseAccount.pubKey) {
|
|
274
|
+
if (!baseAccount.pubKey) {
|
|
275
|
+
stdFee = await this.getStdFeeWithDynamicBaseFee(stdFee);
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
272
278
|
const { stdFee: simulatedStdFee } = await this.getTxWithSignersAndStdFee({
|
|
273
279
|
chainId,
|
|
274
280
|
signMode: SIGN_EIP712_V2,
|
|
@@ -277,8 +283,8 @@ export class MsgBroadcaster {
|
|
|
277
283
|
timeoutHeight: timeoutHeight.toNumber(),
|
|
278
284
|
signers: {
|
|
279
285
|
pubKey: baseAccount.pubKey.key,
|
|
280
|
-
accountNumber: baseAccount.accountNumber,
|
|
281
286
|
sequence: baseAccount.sequence,
|
|
287
|
+
accountNumber: baseAccount.accountNumber,
|
|
282
288
|
},
|
|
283
289
|
fee: stdFee,
|
|
284
290
|
});
|
|
@@ -526,13 +532,13 @@ export class MsgBroadcaster {
|
|
|
526
532
|
/** EIP712 for signing on Ethereum wallets */
|
|
527
533
|
const eip712TypedData = getEip712TypedData({
|
|
528
534
|
msgs,
|
|
529
|
-
fee:
|
|
535
|
+
fee: await this.getStdFeeWithDynamicBaseFee({ ...tx.gas, gas }),
|
|
530
536
|
tx: {
|
|
537
|
+
chainId,
|
|
531
538
|
memo: tx.memo,
|
|
532
|
-
accountNumber: baseAccount.accountNumber.toString(),
|
|
533
|
-
sequence: baseAccount.sequence.toString(),
|
|
534
539
|
timeoutHeight: timeoutHeight.toFixed(),
|
|
535
|
-
|
|
540
|
+
sequence: baseAccount.sequence.toString(),
|
|
541
|
+
accountNumber: baseAccount.accountNumber.toString(),
|
|
536
542
|
},
|
|
537
543
|
ethereumChainId,
|
|
538
544
|
});
|
|
@@ -710,6 +716,32 @@ export class MsgBroadcaster {
|
|
|
710
716
|
}
|
|
711
717
|
return response.feePayerPubKey.key;
|
|
712
718
|
}
|
|
719
|
+
async getStdFeeWithDynamicBaseFee(args) {
|
|
720
|
+
const client = new ChainGrpcTxFeesApi(this.endpoints.grpc);
|
|
721
|
+
let baseFee = DEFAULT_GAS_PRICE;
|
|
722
|
+
try {
|
|
723
|
+
const response = await client.fetchEipBaseFee();
|
|
724
|
+
baseFee = Number(response?.baseFee || DEFAULT_GAS_PRICE);
|
|
725
|
+
}
|
|
726
|
+
catch { }
|
|
727
|
+
if (!args) {
|
|
728
|
+
return getStdFee(baseFee ? { gasPrice: baseFee } : {});
|
|
729
|
+
}
|
|
730
|
+
if (typeof args === 'string') {
|
|
731
|
+
return getStdFee({
|
|
732
|
+
...(baseFee && {
|
|
733
|
+
gasPrice: new BigNumberInBase(baseFee).toFixed(),
|
|
734
|
+
}),
|
|
735
|
+
gas: args,
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
return getStdFee({
|
|
739
|
+
...args,
|
|
740
|
+
...(baseFee && {
|
|
741
|
+
gasPrice: new BigNumberInBase(baseFee).toFixed(),
|
|
742
|
+
}),
|
|
743
|
+
});
|
|
744
|
+
}
|
|
713
745
|
/**
|
|
714
746
|
* In case we don't want to simulate the transaction
|
|
715
747
|
* we get the gas limit based on the message type.
|
|
@@ -723,24 +755,21 @@ export class MsgBroadcaster {
|
|
|
723
755
|
if (!simulateTx) {
|
|
724
756
|
return {
|
|
725
757
|
...createTransactionWithSigners(args),
|
|
726
|
-
stdFee:
|
|
758
|
+
stdFee: await this.getStdFeeWithDynamicBaseFee(args.fee),
|
|
727
759
|
};
|
|
728
760
|
}
|
|
729
761
|
const result = await this.simulateTxWithSigners(args);
|
|
730
762
|
if (!result.gasInfo?.gasUsed) {
|
|
731
763
|
return {
|
|
732
764
|
...createTransactionWithSigners(args),
|
|
733
|
-
stdFee:
|
|
765
|
+
stdFee: await this.getStdFeeWithDynamicBaseFee(args.fee),
|
|
734
766
|
};
|
|
735
767
|
}
|
|
736
|
-
const stdGasFee = {
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
.toFixed(),
|
|
742
|
-
}),
|
|
743
|
-
};
|
|
768
|
+
const stdGasFee = await this.getStdFeeWithDynamicBaseFee({
|
|
769
|
+
gas: new BigNumberInBase(result.gasInfo.gasUsed)
|
|
770
|
+
.times(this.gasBufferCoefficient)
|
|
771
|
+
.toFixed(),
|
|
772
|
+
});
|
|
744
773
|
return {
|
|
745
774
|
...createTransactionWithSigners({
|
|
746
775
|
...args,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-core",
|
|
3
3
|
"description": "Core wallet strategy",
|
|
4
|
-
"version": "1.15.
|
|
4
|
+
"version": "1.15.38",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": {
|
|
@@ -56,17 +56,17 @@
|
|
|
56
56
|
"start": "node dist/index.js"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@injectivelabs/exceptions": "^1.15.
|
|
60
|
-
"@injectivelabs/networks": "^1.15.
|
|
61
|
-
"@injectivelabs/sdk-ts": "^1.15.
|
|
62
|
-
"@injectivelabs/ts-types": "^1.15.
|
|
63
|
-
"@injectivelabs/utils": "^1.15.
|
|
64
|
-
"@injectivelabs/wallet-base": "^1.15.
|
|
59
|
+
"@injectivelabs/exceptions": "^1.15.35",
|
|
60
|
+
"@injectivelabs/networks": "^1.15.36",
|
|
61
|
+
"@injectivelabs/sdk-ts": "^1.15.38",
|
|
62
|
+
"@injectivelabs/ts-types": "^1.15.36",
|
|
63
|
+
"@injectivelabs/utils": "^1.15.36",
|
|
64
|
+
"@injectivelabs/wallet-base": "^1.15.38",
|
|
65
65
|
"@keplr-wallet/types": "^0.12.159",
|
|
66
66
|
"eventemitter3": "^5.0.1"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"shx": "^0.3.3"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "2f6b7586dc08c30e83fe780a565571b73af6cacc"
|
|
72
72
|
}
|