Skip to content

Commit

Permalink
fix: adjust max amount bound calculation for RPC v0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
penovicp committed Mar 14, 2024
1 parent fd206a1 commit dd34cdb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions __tests__/utils/stark.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
6 changes: 5 additions & 1 deletion src/utils/stark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down

0 comments on commit dd34cdb

Please sign in to comment.