Skip to content

Commit

Permalink
fix: pvg calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewwahid committed May 19, 2023
1 parent f83b579 commit 86c169d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions lib/models/gas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,16 @@ class GasEstimate {
this.l1GasUsed = l1GasUsed ?? BigInt.zero;
this.l1BaseFee = l1BaseFee ?? BigInt.zero;
}

GasEstimate copy() {
return GasEstimate(
callGasLimit: callGasLimit,
preVerificationGas: preVerificationGas,
verificationGasLimit: verificationGasLimit,
maxPriorityFeePerGas: maxPriorityFeePerGas,
maxFeePerGas: maxFeePerGas,
l1GasUsed: l1GasUsed,
l1BaseFee: l1BaseFee,
);
}
}
2 changes: 1 addition & 1 deletion lib/models/gas_estimators/l1_gas_estimator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class L1GasEstimator extends GasEstimator {
gasEstimate.maxFeePerGas = BigInt.from(networkFees[0]);
gasEstimate.maxPriorityFeePerGas = BigInt.from(networkFees[1]);
}else{
gasEstimate = prevEstimate;
gasEstimate = prevEstimate.copy();
}
if (includesPaymaster){
gasEstimate.preVerificationGas += BigInt.from(84); // To accommodate for GnosisTransaction.approveAmount which would be 0 before estimation
Expand Down
2 changes: 1 addition & 1 deletion lib/models/gas_estimators/l2_gas_estimator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class L2GasEstimator extends GasEstimator {
gasEstimate.maxFeePerGas = BigInt.from(networkFees[0]);
gasEstimate.maxPriorityFeePerGas = BigInt.from(networkFees[1]);
}else{
gasEstimate = prevEstimate;
gasEstimate = prevEstimate.copy();
}
//
if (gasEstimate.l1GasUsed == BigInt.zero){
Expand Down
2 changes: 1 addition & 1 deletion lib/models/paymaster/fee_token.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FeeCurrencyUtils {
static final BigInt costOfPost = BigInt.from(45000); // todo shouldn't be hardcoded

static BigInt calculateFee(UserOperation op, BigInt exchangeRate, bool isEther) {
BigInt operationMaxEthCostUsingPaymaster = op.maxFeePerGas * (costOfPost + op.callGasLimit + (op.verificationGasLimit * BigInt.from(isEther ? 1 : 1)) + op.preVerificationGas);
BigInt operationMaxEthCostUsingPaymaster = op.maxFeePerGas * (costOfPost + op.callGasLimit + (op.verificationGasLimit * BigInt.from(isEther ? 1 : 3)) + op.preVerificationGas);
BigInt tokenToEthPrice = (operationMaxEthCostUsingPaymaster * exchangeRate) ~/ BigInt.from(10).pow(18);
return tokenToEthPrice;
}
Expand Down

0 comments on commit 86c169d

Please sign in to comment.