Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 for the transaction without any buffer applied.

## [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 any buffer applied.
*/
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
13 changes: 7 additions & 6 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,17 +133,17 @@ 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) {
log('Using value from request', txMeta.txParams.gas);
return [txMeta.txParams.gas];
return [txMeta.txParams.gas, undefined, txMeta.txParams.gas];
}

if (await requiresFixedGas(request)) {
log('Using fixed value', FIXED_GAS);
return [FIXED_GAS];
return [FIXED_GAS, undefined, FIXED_GAS];
}

const { blockGasLimit, estimatedGas, simulationFails } = await estimateGas(
Expand All @@ -156,7 +157,7 @@ async function getGas(
? 'Using original estimate as custom network'
: 'Using original fallback estimate as simulation failed',
);
return [estimatedGas, simulationFails];
return [estimatedGas, simulationFails, estimatedGas];
}

const bufferMultiplier =
Expand All @@ -170,7 +171,7 @@ async function getGas(
bufferMultiplier,
);

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

async function requiresFixedGas({
Expand Down
Loading