Skip to content

Commit e5f015c

Browse files
OGPoyrazPatrykLucka
authored andcommitted
feat: Add gasLimitNoBuffer to transactionMeta (#5113)
## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> This PR aims to add `gasLimitNoBuffer` to `transactionMeta` to show minimum value while calculating network fee. ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> * Fixes https://github.com/MetaMask/MetaMask-planning/issues/3773 ## Changelog <!-- If you're making any consumer-facing changes, list those changes here as if you were updating a changelog, using the template below as a guide. (CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or FIXED. For security-related issues, follow the Security Advisory process.) Please take care to name the exact pieces of the API you've added or changed (e.g. types, interfaces, functions, or methods). If there are any breaking changes, make sure to offer a solution for consumers to follow once they upgrade to the changes. Finally, if you're only making changes to development scripts or tests, you may replace the template below with "None". --> ### `@metamask/transaction-controller` - **Added**: Add `gasLimitNoBuffer` to `transactionMeta` - `gasLimitNoBuffer` is the estimated gas (via `eth_estimateGas`) for the transaction without buffer. ## Checklist - [X] I've updated the test suite for new or updated code as appropriate - [X] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [X] I've highlighted breaking changes using the "BREAKING" category above as appropriate - [X] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes
1 parent 079b4cc commit e5f015c

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

packages/transaction-controller/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add `gasLimitNoBuffer` property to `TransactionMeta` type ([#5113](https://github.com/MetaMask/core/pull/5113))
13+
- `gasLimitNoBuffer` is the estimated gas for the transaction without any buffer applied.
14+
1015
## [42.1.0]
1116

1217
### Added

packages/transaction-controller/src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ type TransactionMetaBase = {
184184
/** Whether the gas fee estimates have been checked at least once. */
185185
gasFeeEstimatesLoaded?: boolean;
186186

187+
/**
188+
* The estimated gas for the transaction without any buffer applied.
189+
*/
190+
gasLimitNoBuffer?: string;
191+
187192
/**
188193
* A hex string of the transaction hash, used to identify the transaction on the network.
189194
*/

packages/transaction-controller/src/utils/gas.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ describe('gas', () => {
197197
expect(updateGasRequest.txMeta.originalGasEstimate).toBe(
198198
updateGasRequest.txMeta.txParams.gas,
199199
);
200+
expect(updateGasRequest.txMeta.gasLimitNoBuffer).toBe(
201+
toHex(estimatedGas),
202+
);
200203
});
201204

202205
it('to padded estimate using chain multiplier if padded estimate less than percentage of block gas limit', async () => {
@@ -219,6 +222,9 @@ describe('gas', () => {
219222
expect(updateGasRequest.txMeta.originalGasEstimate).toBe(
220223
updateGasRequest.txMeta.txParams.gas,
221224
);
225+
expect(updateGasRequest.txMeta.gasLimitNoBuffer).toBe(
226+
toHex(estimatedGas),
227+
);
222228
});
223229

224230
it('to percentage of block gas limit if padded estimate only is greater than percentage of block gas limit', async () => {
@@ -241,6 +247,9 @@ describe('gas', () => {
241247
expect(updateGasRequest.txMeta.originalGasEstimate).toBe(
242248
updateGasRequest.txMeta.txParams.gas,
243249
);
250+
expect(updateGasRequest.txMeta.gasLimitNoBuffer).toBe(
251+
toHex(estimatedGas),
252+
);
244253
});
245254

246255
describe('to fixed value', () => {

packages/transaction-controller/src/utils/gas.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ export async function updateGas(request: UpdateGasRequest) {
3232
const { txMeta } = request;
3333
const initialParams = { ...txMeta.txParams };
3434

35-
const [gas, simulationFails] = await getGas(request);
35+
const [gas, simulationFails, gasLimitNoBuffer] = await getGas(request);
3636

3737
txMeta.txParams.gas = gas;
3838
txMeta.simulationFails = simulationFails;
39+
txMeta.gasLimitNoBuffer = gasLimitNoBuffer;
3940

4041
if (!initialParams.gas) {
4142
txMeta.originalGasEstimate = txMeta.txParams.gas;
@@ -132,17 +133,17 @@ export function addGasBuffer(
132133

133134
async function getGas(
134135
request: UpdateGasRequest,
135-
): Promise<[string, TransactionMeta['simulationFails']?]> {
136+
): Promise<[string, TransactionMeta['simulationFails']?, string?]> {
136137
const { isCustomNetwork, chainId, txMeta } = request;
137138

138139
if (txMeta.txParams.gas) {
139140
log('Using value from request', txMeta.txParams.gas);
140-
return [txMeta.txParams.gas];
141+
return [txMeta.txParams.gas, undefined, txMeta.txParams.gas];
141142
}
142143

143144
if (await requiresFixedGas(request)) {
144145
log('Using fixed value', FIXED_GAS);
145-
return [FIXED_GAS];
146+
return [FIXED_GAS, undefined, FIXED_GAS];
146147
}
147148

148149
const { blockGasLimit, estimatedGas, simulationFails } = await estimateGas(
@@ -156,7 +157,7 @@ async function getGas(
156157
? 'Using original estimate as custom network'
157158
: 'Using original fallback estimate as simulation failed',
158159
);
159-
return [estimatedGas, simulationFails];
160+
return [estimatedGas, simulationFails, estimatedGas];
160161
}
161162

162163
const bufferMultiplier =
@@ -170,7 +171,7 @@ async function getGas(
170171
bufferMultiplier,
171172
);
172173

173-
return [bufferedGas, simulationFails];
174+
return [bufferedGas, simulationFails, estimatedGas];
174175
}
175176

176177
async function requiresFixedGas({

0 commit comments

Comments
 (0)