Skip to content

Commit

Permalink
add maxPenalty and emit A + U from Paymaster
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipp Makarov authored and Filipp Makarov committed Oct 15, 2024
1 parent 061b152 commit cdfa3d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions contracts/interfaces/IBiconomySponsorshipPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface IBiconomySponsorshipPaymaster {
event PriceMarkupCollected(address indexed paymasterId, uint256 indexed priceMarkup);
event Received(address indexed sender, uint256 value);
event TokensWithdrawn(address indexed token, address indexed to, uint256 indexed amount, address actor);
event ActualGasCostBeforePaymasterPremium(uint256 actualGasCost);

function depositFor(address paymasterId) external payable;

Expand Down
9 changes: 8 additions & 1 deletion contracts/sponsorship/BiconomySponsorshipPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ contract BiconomySponsorshipPaymaster is
// Include unaccountedGas since EP doesn't include this in actualGasCost
// unaccountedGas = postOpGas + EP overhead gas + estimated penalty
actualGasCost = actualGasCost + (unaccountedGas * actualUserOpFeePerGas);
emit ActualGasCostBeforePaymasterPremium(actualGasCost);
// Apply the price markup
uint256 adjustedGasCost = (actualGasCost * priceMarkup) / _PRICE_DENOMINATOR;

Expand Down Expand Up @@ -337,9 +338,15 @@ contract BiconomySponsorshipPaymaster is
revert InvalidPriceMarkup();
}

// callGasLimit + paymasterPostOpGas
uint256 maxPenalty = (
uint128(uint256(userOp.accountGasLimits)) +
uint128(bytes16(userOp.paymasterAndData[_PAYMASTER_POSTOP_GAS_OFFSET : _PAYMASTER_DATA_OFFSET]))
) * 10 / 100 * userOp.unpackMaxFeePerGas();

// Deduct the max gas cost.
uint256 effectiveCost =
((requiredPreFund + unaccountedGas * userOp.unpackMaxFeePerGas()) * priceMarkup) / _PRICE_DENOMINATOR;
((requiredPreFund + unaccountedGas * userOp.unpackMaxFeePerGas()) * priceMarkup / _PRICE_DENOMINATOR) + maxPenalty;

if (effectiveCost > paymasterIdBalances[paymasterId]) {
revert InsufficientFundsForPaymasterId();
Expand Down

0 comments on commit cdfa3d1

Please sign in to comment.