@@ -14,6 +14,7 @@ import {
1414 FeeEstimate ,
1515 SimulateTransactionResponse ,
1616 SimulatedTransaction ,
17+ RpcProviderOptions ,
1718} from '../../types/provider' ;
1819import { toBigInt } from '../num' ;
1920import { estimateFeeToBounds , estimatedFeeToMaxFee } from '../stark' ;
@@ -31,6 +32,24 @@ export class RPCResponseParser
3132 | 'parseCallContractResponse'
3233 >
3334{
35+ private margin : RpcProviderOptions [ 'feeMarginPercentage' ] ;
36+
37+ constructor ( margin ?: RpcProviderOptions [ 'feeMarginPercentage' ] ) {
38+ this . margin = margin ;
39+ }
40+
41+ private estimatedFeeToMaxFee ( estimatedFee : Parameters < typeof estimatedFeeToMaxFee > [ 0 ] ) {
42+ return estimatedFeeToMaxFee ( estimatedFee , this . margin ?. maxFee ) ;
43+ }
44+
45+ private estimateFeeToBounds ( estimate : Parameters < typeof estimateFeeToBounds > [ 0 ] ) {
46+ return estimateFeeToBounds (
47+ estimate ,
48+ this . margin ?. l1BoundMaxAmount ,
49+ this . margin ?. l1BoundMaxPricePerUnit
50+ ) ;
51+ }
52+
3453 public parseGetBlockResponse ( res : BlockWithTxHashes ) : GetBlockResponse {
3554 return { status : 'PENDING' , ...res } as GetBlockResponse ;
3655 }
@@ -58,8 +77,8 @@ export class RPCResponseParser
5877 gas_consumed : toBigInt ( val . gas_consumed ) ,
5978 gas_price : toBigInt ( val . gas_price ) ,
6079 unit : val . unit ,
61- suggestedMaxFee : estimatedFeeToMaxFee ( val . overall_fee ) ,
62- resourceBounds : estimateFeeToBounds ( val ) ,
80+ suggestedMaxFee : this . estimatedFeeToMaxFee ( val . overall_fee ) ,
81+ resourceBounds : this . estimateFeeToBounds ( val ) ,
6382 } ;
6483 }
6584
@@ -69,8 +88,8 @@ export class RPCResponseParser
6988 gas_consumed : toBigInt ( val . gas_consumed ) ,
7089 gas_price : toBigInt ( val . gas_price ) ,
7190 unit : val . unit ,
72- suggestedMaxFee : estimatedFeeToMaxFee ( val . overall_fee ) ,
73- resourceBounds : estimateFeeToBounds ( val ) ,
91+ suggestedMaxFee : this . estimatedFeeToMaxFee ( val . overall_fee ) ,
92+ resourceBounds : this . estimateFeeToBounds ( val ) ,
7493 } ) ) ;
7594 }
7695
@@ -85,8 +104,8 @@ export class RPCResponseParser
85104 return res . map ( ( it : SimulatedTransaction ) => {
86105 return {
87106 ...it ,
88- suggestedMaxFee : estimatedFeeToMaxFee ( BigInt ( it . fee_estimation . overall_fee ) ) ,
89- resourceBounds : estimateFeeToBounds ( it . fee_estimation ) ,
107+ suggestedMaxFee : this . estimatedFeeToMaxFee ( it . fee_estimation . overall_fee ) ,
108+ resourceBounds : this . estimateFeeToBounds ( it . fee_estimation ) ,
90109 } ;
91110 } ) ;
92111 }
0 commit comments