Skip to content

Commit

Permalink
👷🏻 🧹 Add onlyEntryPoint modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyrharper committed Jul 10, 2024
1 parent da7622a commit 51c9fe0
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/MarginPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,20 @@ contract MarginPaymaster is IPaymaster, Zap {
_USDC.approve(_uniV3Router, type(uint256).max);
}

modifier onlyEntryPoint() {
if (msg.sender != entryPoint) revert InvalidEntryPoint();
_;
}

function validatePaymasterUserOp(
UserOperation calldata userOp,
bytes32,
uint256
) external returns (bytes memory context, uint256 validationData) {
if (msg.sender != entryPoint) revert InvalidEntryPoint();
)
external
onlyEntryPoint
returns (bytes memory context, uint256 validationData)
{
context = abi.encode(userOp.sender); // passed to the postOp method
validationData = 0; // 0 means accept sponsorship, 1 means reject
}
Expand All @@ -62,17 +70,15 @@ contract MarginPaymaster is IPaymaster, Zap {
PostOpMode,
bytes calldata context,
uint256 actualGasCostInWei
) external {
if (msg.sender != entryPoint) revert InvalidEntryPoint();

) external onlyEntryPoint {
(, int24 tick, , , , , ) = pool.slot0();

uint256 costOfGasInUSDC = OracleLibrary.getQuoteAtTick(
uint256 costOfGasInUSDC = (OracleLibrary.getQuoteAtTick(
tick,
uint128(actualGasCostInWei), // TODO: account for gas costs of postOp func
uint128(actualGasCostInWei),
address(weth),
address(_USDC)
) * 110 / 100;
) * 110) / 100; // TODO: account for gas costs of postOp func
uint256 costOfGasInsUSD = costOfGasInUSDC * 1e12;

address sender = abi.decode(context, (address));
Expand Down

0 comments on commit 51c9fe0

Please sign in to comment.