Skip to content

Commit dd34cdb

Browse files
committed
fix: adjust max amount bound calculation for RPC v0.7.0
1 parent fd206a1 commit dd34cdb

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

__tests__/utils/stark.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,20 @@ describe('stark', () => {
7979
overall_fee: '1000',
8080
unit: 'FRI',
8181
};
82+
const estimateFeeResponse07: FeeEstimate = {
83+
...estimateFeeResponse,
84+
data_gas_consumed: '100',
85+
data_gas_price: '10',
86+
overall_fee: '2000',
87+
};
8288
expect(stark.estimateFeeToBounds(estimateFeeResponse)).toStrictEqual({
8389
l2_gas: { max_amount: '0x0', max_price_per_unit: '0x0' },
8490
l1_gas: { max_amount: '0x6e', max_price_per_unit: '0xf' },
8591
});
92+
expect(stark.estimateFeeToBounds(estimateFeeResponse07)).toStrictEqual({
93+
l2_gas: { max_amount: '0x0', max_price_per_unit: '0x0' },
94+
l1_gas: { max_amount: '0xdc', max_price_per_unit: '0xf' },
95+
});
8696
});
8797

8898
test('v3Details', () => {

src/utils/stark.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ export function estimateFeeToBounds(
114114
if (typeof estimate.gas_consumed === 'undefined' || typeof estimate.gas_price === 'undefined') {
115115
throw Error('estimateFeeToBounds: estimate is undefined');
116116
}
117-
const maxUnits = toHex(addPercent(estimate.gas_consumed, amountOverhead));
117+
118+
const maxUnits =
119+
estimate.data_gas_consumed !== undefined && estimate.data_gas_price !== undefined // RPC v0.7
120+
? toHex(addPercent(BigInt(estimate.overall_fee) / BigInt(estimate.gas_price), amountOverhead))
121+
: toHex(addPercent(estimate.gas_consumed, amountOverhead));
118122
const maxUnitPrice = toHex(addPercent(estimate.gas_price, priceOverhead));
119123
return {
120124
l2_gas: { max_amount: '0x0', max_price_per_unit: '0x0' },

0 commit comments

Comments
 (0)