Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/transaction-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `gasLimitNoBuffer` property to `TransactionMeta` type ([#5113](https://github.com/MetaMask/core/pull/5113))
- `gasLimitNoBuffer` is the estimated gas (via `eth_estimateGas`) for the transaction without buffer.

## [42.1.0]

### Added
Expand Down
5 changes: 5 additions & 0 deletions packages/transaction-controller/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ type TransactionMetaBase = {
/** Whether the gas fee estimates have been checked at least once. */
gasFeeEstimatesLoaded?: boolean;

/**
* The estimated gas for the transaction without buffer.
*/
gasLimitNoBuffer?: string;

/**
* A hex string of the transaction hash, used to identify the transaction on the network.
*/
Expand Down
9 changes: 9 additions & 0 deletions packages/transaction-controller/src/utils/gas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ describe('gas', () => {
expect(updateGasRequest.txMeta.originalGasEstimate).toBe(
updateGasRequest.txMeta.txParams.gas,
);
expect(updateGasRequest.txMeta.gasLimitNoBuffer).toBe(
toHex(estimatedGas),
);
});

it('to padded estimate using chain multiplier if padded estimate less than percentage of block gas limit', async () => {
Expand All @@ -219,6 +222,9 @@ describe('gas', () => {
expect(updateGasRequest.txMeta.originalGasEstimate).toBe(
updateGasRequest.txMeta.txParams.gas,
);
expect(updateGasRequest.txMeta.gasLimitNoBuffer).toBe(
toHex(estimatedGas),
);
});

it('to percentage of block gas limit if padded estimate only is greater than percentage of block gas limit', async () => {
Expand All @@ -241,6 +247,9 @@ describe('gas', () => {
expect(updateGasRequest.txMeta.originalGasEstimate).toBe(
updateGasRequest.txMeta.txParams.gas,
);
expect(updateGasRequest.txMeta.gasLimitNoBuffer).toBe(
toHex(estimatedGas),
);
});

describe('to fixed value', () => {
Expand Down
7 changes: 4 additions & 3 deletions packages/transaction-controller/src/utils/gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ export async function updateGas(request: UpdateGasRequest) {
const { txMeta } = request;
const initialParams = { ...txMeta.txParams };

const [gas, simulationFails] = await getGas(request);
const [gas, simulationFails, gasLimitNoBuffer] = await getGas(request);

txMeta.txParams.gas = gas;
txMeta.simulationFails = simulationFails;
txMeta.gasLimitNoBuffer = gasLimitNoBuffer;

if (!initialParams.gas) {
txMeta.originalGasEstimate = txMeta.txParams.gas;
Expand Down Expand Up @@ -132,7 +133,7 @@ export function addGasBuffer(

async function getGas(
request: UpdateGasRequest,
): Promise<[string, TransactionMeta['simulationFails']?]> {
): Promise<[string, TransactionMeta['simulationFails']?, string?]> {
const { isCustomNetwork, chainId, txMeta } = request;

if (txMeta.txParams.gas) {
Expand Down Expand Up @@ -170,7 +171,7 @@ async function getGas(
bufferMultiplier,
);

return [bufferedGas, simulationFails];
return [bufferedGas, simulationFails, estimatedGas];
}

async function requiresFixedGas({
Expand Down
Loading