Skip to content

Commit d77de25

Browse files
committed
Add overhead calculation
1 parent 0087bb6 commit d77de25

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/MeteePaymaster.sol

+10-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ contract MeteePaymaster is BasePaymaster {
2424

2525
uint256 private constant VALID_TIMESTAMP_OFFSET = 20;
2626
uint256 private constant SIGNATURE_OFFSET = VALID_TIMESTAMP_OFFSET + 64;
27+
uint256 private constant POST_OP_OVERHEAD = 34982;
2728

2829
constructor(IEntryPoint _entryPoint, address _verifyingSigner, MetaPaymaster _metaPaymaster) BasePaymaster(_entryPoint) Ownable() {
2930
verifyingSigner = _verifyingSigner;
@@ -80,15 +81,21 @@ contract MeteePaymaster is BasePaymaster {
8081

8182
// no need for other on-chain validation: entire UserOp should have been checked
8283
// by the external service prior to signing it.
83-
return (" ", _packValidationData(false, validUntil, validAfter));
84+
return (abi.encode(userOp.maxFeePerGas, userOp.maxPriorityFeePerGas), _packValidationData(false, validUntil, validAfter));
8485
}
8586

86-
function _postOp(PostOpMode mode, bytes calldata /*context*/, uint256 actualGasCost) internal override {
87+
function _postOp(PostOpMode mode, bytes calldata context, uint256 actualGasCost) internal override {
8788
if (mode != PostOpMode.postOpReverted) {
88-
metaPaymaster.fund(address(this), actualGasCost + 3453969250695);
89+
(uint256 maxFeePerGas, uint256 maxPriorityFeePerGas) = abi.decode(context, (uint256, uint256));
90+
uint256 gasPrice = min(maxFeePerGas, maxPriorityFeePerGas + block.basefee);
91+
metaPaymaster.fund(address(this), actualGasCost + POST_OP_OVERHEAD*gasPrice);
8992
}
9093
}
9194

95+
function min(uint256 a, uint256 b) internal pure returns (uint256) {
96+
return a < b ? a : b;
97+
}
98+
9299
function parsePaymasterAndData(bytes calldata paymasterAndData)
93100
internal pure returns(uint48 validUntil, uint48 validAfter, bytes calldata signature) {
94101
(validUntil, validAfter) = abi.decode(paymasterAndData[VALID_TIMESTAMP_OFFSET:SIGNATURE_OFFSET],(uint48, uint48));

0 commit comments

Comments
 (0)