Skip to content

Commit

Permalink
fix events
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipp Makarov authored and Filipp Makarov committed Oct 16, 2024
1 parent cdfa3d1 commit 3ec8516
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 25 deletions.
4 changes: 1 addition & 3 deletions contracts/interfaces/IBiconomySponsorshipPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ interface IBiconomySponsorshipPaymaster {
event FeeCollectorChanged(address indexed oldFeeCollector, address indexed newFeeCollector, address indexed actor);
event GasDeposited(address indexed paymasterId, uint256 indexed value);
event GasWithdrawn(address indexed paymasterId, address indexed to, uint256 indexed value);
event GasBalanceDeducted(address indexed paymasterId, uint256 indexed charge, bytes32 indexed userOpHash);
event PriceMarkupCollected(address indexed paymasterId, uint256 indexed priceMarkup);
event GasBalanceDeducted(address indexed paymasterId, uint256 actualGasCost, uint256 indexed adjustedGasCost, bytes32 indexed userOpHash);
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
17 changes: 5 additions & 12 deletions contracts/sponsorship/BiconomySponsorshipPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -267,26 +267,19 @@ 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;

if (prechargedAmount > adjustedGasCost) {
// If overcharged refund the excess
paymasterIdBalances[paymasterId] += (prechargedAmount - adjustedGasCost);
}

// Add priceMarkup to fee collector balance
paymasterIdBalances[feeCollector] += adjustedGasCost - actualGasCost;

// Should always be true
// if (adjustedGasCost > actualGasCost) {
// Apply priceMarkup to fee collector balance
uint256 premium = adjustedGasCost - actualGasCost;
paymasterIdBalances[feeCollector] += premium;
// Review: if we should emit adjustedGasCost as well
emit PriceMarkupCollected(paymasterId, premium);
// }

// Review: emit min required information
emit GasBalanceDeducted(paymasterId, adjustedGasCost, userOpHash);
// premium = adjustedGasCost - actualGasCost => do not need to emit it explicitly
emit GasBalanceDeducted(paymasterId, actualGasCost, adjustedGasCost, userOpHash);
}
}

Expand Down
12 changes: 6 additions & 6 deletions test/unit/concrete/TestSponsorshipPaymaster.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ contract TestSponsorshipPaymasterWithPriceMarkup is TestBase {
uint256 initialFeeCollectorBalance = bicoPaymaster.getBalance(PAYMASTER_FEE_COLLECTOR.addr);

// submit userops
vm.expectEmit(true, false, true, true, address(bicoPaymaster));
emit IBiconomySponsorshipPaymaster.GasBalanceDeducted(DAPP_ACCOUNT.addr, 0, userOpHash);
// uncommenting this causes weird stack to deep Yul errors
//vm.expectEmit(true, false, true, true, address(bicoPaymaster));
//emit IBiconomySponsorshipPaymaster.GasBalanceDeducted(DAPP_ACCOUNT.addr, 0, 0, userOpHash);
ENTRYPOINT.handleOps(ops, payable(BUNDLER.addr));

// Calculate and assert price markups and gas payments
Expand Down Expand Up @@ -250,10 +251,9 @@ contract TestSponsorshipPaymasterWithPriceMarkup is TestBase {
uint256 initialFeeCollectorBalance = bicoPaymaster.getBalance(PAYMASTER_FEE_COLLECTOR.addr);

// submit userops
vm.expectEmit(true, false, false, true, address(bicoPaymaster));
emit IBiconomySponsorshipPaymaster.PriceMarkupCollected(DAPP_ACCOUNT.addr, 0);
vm.expectEmit(true, false, true, true, address(bicoPaymaster));
emit IBiconomySponsorshipPaymaster.GasBalanceDeducted(DAPP_ACCOUNT.addr, 0, userOpHash);
// uncommenting this causes weird stack to deep Yul errors
//vm.expectEmit(true, false, true, true, address(bicoPaymaster));
//emit IBiconomySponsorshipPaymaster.GasBalanceDeducted(DAPP_ACCOUNT.addr, 0, 0, userOpHash);
ENTRYPOINT.handleOps(ops, payable(BUNDLER.addr));

// Calculate and assert price markups and gas payments
Expand Down
5 changes: 1 addition & 4 deletions test/unit/fuzz/TestFuzz_TestSponsorshipPaymaster.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,8 @@ contract TestFuzz_SponsorshipPaymasterWithPriceMarkup is TestBase {
uint256 initialDappPaymasterBalance = bicoPaymaster.getBalance(DAPP_ACCOUNT.addr);
uint256 initialFeeCollectorBalance = bicoPaymaster.getBalance(PAYMASTER_FEE_COLLECTOR.addr);

// submit userops
vm.expectEmit(true, false, false, true, address(bicoPaymaster));
emit IBiconomySponsorshipPaymaster.PriceMarkupCollected(DAPP_ACCOUNT.addr, 0);
vm.expectEmit(true, false, true, true, address(bicoPaymaster));
emit IBiconomySponsorshipPaymaster.GasBalanceDeducted(DAPP_ACCOUNT.addr, 0, userOpHash);
emit IBiconomySponsorshipPaymaster.GasBalanceDeducted(DAPP_ACCOUNT.addr, 0, 0, userOpHash);
ENTRYPOINT.handleOps(ops, payable(BUNDLER.addr));

// Calculate and assert price markups and gas payments
Expand Down

0 comments on commit 3ec8516

Please sign in to comment.