PaymasterValidationFacet
Inherits: IPaymaster
Main validation facet for CMX paymaster diamond
Implements IPaymaster interface for CMX token-based fee payments
Functions
onlyEntryPoint
modifier onlyEntryPoint();
whenNotPaused
modifier whenNotPaused();
onlyPaymasterManager
modifier onlyPaymasterManager();
validatePaymasterUserOp
Validate a user operation and determine if paymaster will pay for it
function validatePaymasterUserOp(PackedUserOperation calldata userOp, bytes32 userOpHash, uint256 maxCost)
external
override
onlyEntryPoint
whenNotPaused
returns (bytes memory context, uint256 validationData);
Parameters
userOp
PackedUserOperation
The user operation to validate
userOpHash
bytes32
Hash of the user operation
maxCost
uint256
Maximum cost of the operation
Returns
context
bytes
Context data for postOp
validationData
uint256
Validation result (0 = valid)
postOp
Post-operation processing to collect CMX fees
function postOp(
IPaymaster.PostOpMode mode,
bytes calldata context,
uint256 actualGasCost,
uint256 actualUserOpFeePerGas
) external onlyEntryPoint;
Parameters
mode
IPaymaster.PostOpMode
Post-operation mode
context
bytes
Context data from validatePaymasterUserOp
actualGasCost
uint256
Actual gas cost of the operation
actualUserOpFeePerGas
uint256
The gas price this UserOp pays
_extractFactory
Extract factory address from user operation
function _extractFactory(PackedUserOperation calldata userOp) internal pure returns (address factory);
Parameters
userOp
PackedUserOperation
User operation
Returns
factory
address
Factory address
_transferToTreasury
Transfer CMX tokens to protocol treasury
function _transferToTreasury(uint256 amount) internal;
Parameters
amount
uint256
Amount to transfer
calculateOperationFee
Calculate total fee for a user operation
function calculateOperationFee(PackedUserOperation calldata userOp, address factory)
external
view
returns (uint256 cmxAmount, uint256 ethEquivalent);
Parameters
userOp
PackedUserOperation
User operation
factory
address
Target factory contract
Returns
cmxAmount
uint256
CMX amount required
ethEquivalent
uint256
ETH equivalent amount
canPayForOperation
Pre-validate that user can pay for operation
function canPayForOperation(address user, address factory, uint256 maxCost)
external
view
returns (bool canPay, uint256 cmxRequired);
Parameters
user
address
User address
factory
address
Target factory contract
maxCost
uint256
Maximum cost in ETH
Returns
canPay
bool
Whether user can pay
cmxRequired
uint256
CMX amount required
_extractGasLimit
Extract gas limit from user operation
function _extractGasLimit(PackedUserOperation calldata userOp) internal pure returns (uint256 gasLimit);
Parameters
userOp
PackedUserOperation
User operation
Returns
gasLimit
uint256
Gas limit
_extractGasPrice
Extract gas price from user operation
function _extractGasPrice(PackedUserOperation calldata userOp) internal pure returns (uint256 gasPrice);
Parameters
userOp
PackedUserOperation
User operation
Returns
gasPrice
uint256
Gas price
pause
Emergency pause function
Only callable by paymaster manager
function pause() external onlyPaymasterManager;
unpause
Emergency unpause function
Only callable by paymaster manager
function unpause() external onlyPaymasterManager;
isPaused
Check if paymaster is paused
function isPaused() external view returns (bool paused);
Returns
paused
bool
Whether the paymaster is paused
_checkRateLimits
Check rate limits for a user
function _checkRateLimits(address user) internal returns (bool allowed);
Parameters
user
address
User address
Returns
allowed
bool
Whether the operation is allowed
Last updated
Was this helpful?