diff --git a/__tests__/utils/stark.test.ts b/__tests__/utils/stark.test.ts index 66257c698..de4dc3c49 100644 --- a/__tests__/utils/stark.test.ts +++ b/__tests__/utils/stark.test.ts @@ -79,10 +79,20 @@ describe('stark', () => { overall_fee: '1000', unit: 'FRI', }; + const estimateFeeResponse07: FeeEstimate = { + ...estimateFeeResponse, + data_gas_consumed: '100', + data_gas_price: '10', + overall_fee: '2000', + }; expect(stark.estimateFeeToBounds(estimateFeeResponse)).toStrictEqual({ l2_gas: { max_amount: '0x0', max_price_per_unit: '0x0' }, l1_gas: { max_amount: '0x6e', max_price_per_unit: '0xf' }, }); + expect(stark.estimateFeeToBounds(estimateFeeResponse07)).toStrictEqual({ + l2_gas: { max_amount: '0x0', max_price_per_unit: '0x0' }, + l1_gas: { max_amount: '0xdc', max_price_per_unit: '0xf' }, + }); }); test('v3Details', () => { diff --git a/src/utils/stark.ts b/src/utils/stark.ts index 374ce91a4..a83ba9820 100644 --- a/src/utils/stark.ts +++ b/src/utils/stark.ts @@ -114,7 +114,11 @@ export function estimateFeeToBounds( if (typeof estimate.gas_consumed === 'undefined' || typeof estimate.gas_price === 'undefined') { throw Error('estimateFeeToBounds: estimate is undefined'); } - const maxUnits = toHex(addPercent(estimate.gas_consumed, amountOverhead)); + + const maxUnits = + estimate.data_gas_consumed !== undefined && estimate.data_gas_price !== undefined // RPC v0.7 + ? toHex(addPercent(BigInt(estimate.overall_fee) / BigInt(estimate.gas_price), amountOverhead)) + : toHex(addPercent(estimate.gas_consumed, amountOverhead)); const maxUnitPrice = toHex(addPercent(estimate.gas_price, priceOverhead)); return { l2_gas: { max_amount: '0x0', max_price_per_unit: '0x0' },