@@ -19,6 +19,9 @@ import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
19
19
contract LimitingPaymaster is BasePaymaster {
20
20
using UserOperationLib for UserOperation;
21
21
22
+ uint256 public constant newSenderPostOpOverhead = 23231 ;
23
+ uint256 public constant oldSenderPostOpOverhead = 6143 ;
24
+
22
25
address public immutable verifyingSigner;
23
26
24
27
mapping (uint32 => uint96 ) public spent;
@@ -89,16 +92,22 @@ contract LimitingPaymaster is BasePaymaster {
89
92
90
93
// no need for other on-chain validation: entire UserOp should have been checked
91
94
// by the external service prior to signing it.
92
- return (abi.encode (spentKey, allowAnyBundler), _packValidationData (false , validUntil, validAfter));
95
+ return (_packContextData (userOp, spentKey, allowAnyBundler), _packValidationData (false , validUntil, validAfter));
96
+ }
97
+
98
+ function _packContextData (UserOperation calldata userOp , uint32 spentKey , bool allowAnyBundler ) internal pure returns (bytes memory ) {
99
+ return abi.encode (userOp.maxFeePerGas, userOp.maxPriorityFeePerGas, spentKey, allowAnyBundler);
93
100
}
94
101
95
102
function _postOp (PostOpMode mode , bytes calldata context , uint256 actualGasCost ) internal override {
96
- (uint32 spentKey , bool allowAnyBundler ) = abi.decode (context, (uint32 , bool ));
103
+ (uint256 maxFeePerGas , uint256 maxPriorityFeePerGas , uint32 spentKey , bool allowAnyBundler ) = abi.decode (context, (uint256 , uint256 , uint32 , bool ));
97
104
// unfortunately tx.origin is not allowed in validation, so we check here
98
105
require (allowAnyBundler || bundlerAllowed[tx .origin ], "Paymaster: bundler not allowed " );
99
106
100
107
if (mode != PostOpMode.postOpReverted) {
101
- spent[spentKey] += uint96 (actualGasCost);
108
+ uint256 overhead = spent[spentKey] == 0 ? newSenderPostOpOverhead : oldSenderPostOpOverhead;
109
+ uint256 gasPrice = min (maxFeePerGas, maxPriorityFeePerGas + block .basefee );
110
+ spent[spentKey] += uint96 (actualGasCost + overhead* gasPrice);
102
111
}
103
112
}
104
113
@@ -130,6 +139,10 @@ contract LimitingPaymaster is BasePaymaster {
130
139
bundlerAllowed[bundler] = false ;
131
140
}
132
141
142
+ function min (uint256 a , uint256 b ) internal pure returns (uint256 ) {
143
+ return a < b ? a : b;
144
+ }
145
+
133
146
receive () external payable {
134
147
// use address(this).balance rather than msg.value in case of force-send
135
148
(bool callSuccess , ) = payable (address (entryPoint)).call {value: address (this ).balance}("" );
0 commit comments