Skip to content
Open
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/sentinel-api-service/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]

### Changed

- **BREAKING:** `SentinelSimulationResponseTransaction.gasCost` is now typed `string` instead of `number`, matching the value the Sentinel API actually returns on the wire (a quoted decimal string, not a JSON number) ([#10050](https://github.com/MetaMask/core/pull/10050))
- Consumers reading `gasCost` and treating it as a `number` (e.g. doing arithmetic directly on it) must parse it first, e.g. via `new BN(gasCost)` or `BigInt(gasCost)`.

## [1.0.1]

### Changed
Expand Down
4 changes: 2 additions & 2 deletions packages/sentinel-api-service/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,10 @@ export type SentinelSimulationResponseTransaction = {
fees?: SentinelSimulationFeeLevel[];

/**
* Estimated total gas cost of the transaction, in wei as a decimal number.
* Estimated total gas cost of the transaction, in wei as a decimal string.
* Included in the `stateDiff` when `withGas` is true.
*/
gasCost?: number;
gasCost?: string;

/** Required `gasLimit` for the transaction. */
gasLimit?: Hex;
Expand Down
4 changes: 2 additions & 2 deletions packages/transaction-controller/src/api/simulation-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ export type SimulationResponseTransaction = {
}[];

/**
* Estimated total gas cost of the transaction.
* Estimated total gas cost of the transaction, in wei as a decimal string.
* Included in the stateDiff if `withGas` is true.
*/
gasCost?: number;
gasCost?: string;

/** Required `gasLimit` for the transaction. */
gasLimit?: Hex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function createEventResponseMock(
function createNativeBalanceResponse(
previousBalance: string,
newBalance: string,
gasCost: number = 0,
gasCost: string = '0',
): SimulationResponse {
return {
transactions: [
Expand Down Expand Up @@ -343,7 +343,7 @@ describe('Balance Change Utils', () => {

it('ignoring gas cost', async () => {
simulateTransactionsMock.mockResolvedValueOnce(
createNativeBalanceResponse('0x3', '0x8', 2),
createNativeBalanceResponse('0x3', '0x8', '2'),
);

const result = await getBalanceChanges(REQUEST_MOCK);
Expand All @@ -363,6 +363,33 @@ describe('Balance Change Utils', () => {
simulationRevert: undefined,
});
});

it('supports a gas cost above Number.MAX_SAFE_INTEGER', async () => {
// A wei-scale gas cost this large is realistic on chains such as
// Polygon, and would previously throw when the wire value was
// mistakenly parsed as a JS `number` via `new BN(offset)`.
const largeGasCost = '10500000000000000'; // 2^53 (9007199254740992) < this
simulateTransactionsMock.mockResolvedValueOnce(
createNativeBalanceResponse('0x0', '0x0', largeGasCost),
);

const result = await getBalanceChanges(REQUEST_MOCK);

expect(result).toStrictEqual({
simulationData: {
callTraceErrors: [],
nativeBalanceChange: {
difference: '0x254db1c2244000',
isDecrease: false,
newBalance: '0x254db1c2244000',
previousBalance: '0x0',
},
tokenBalanceChanges: [],
},
gasUsed: undefined,
simulationRevert: undefined,
});
});
});

describe('returns token balance changes', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ function extractRootRevert(
function getSimulationBalanceChange(
previousBalance: Hex,
newBalance: Hex,
offset: number = 0,
offset: string = '0',
): SimulationBalanceChange | undefined {
const newBalanceBN = hexToBN(newBalance).add(new BN(offset));
const previousBalanceBN = hexToBN(previousBalance);
Expand Down