LedgerPaymasterFacet
Inherits: IFactoryCMXPaymaster
Paymaster integration facet for ledger factory
Handles CMX token-based fee payments for ledger creation
State Variables
CMX_PAYMASTER_STORAGE_SLOT
bytes32 private constant CMX_PAYMASTER_STORAGE_SLOT = keccak256("capsign.storage.ledger_factory.cmx_paymaster");
Functions
_getCMXPaymasterStorage
function _getCMXPaymasterStorage() internal pure returns (CMXPaymasterLayout storage l);
onlyFactoryAdmin
modifier onlyFactoryAdmin();
updatePaymasterSupport
Update paymaster support
function updatePaymasterSupport(address paymaster, bool supported) external override;
Parameters
paymaster
address
Paymaster address
supported
bool
Whether to support this paymaster
isPaymasterSupported
Check if a paymaster is supported
function isPaymasterSupported(address paymaster) external view override returns (bool supported);
Parameters
paymaster
address
Paymaster address
Returns
supported
bool
Whether the paymaster is supported
getSupportedPaymasters
Get all supported paymasters
function getSupportedPaymasters() external view override returns (address[] memory paymasters);
Returns
paymasters
address[]
Array of supported paymaster addresses
preValidatePayment
Pre-validate payment before operation
function preValidatePayment(address user, address paymaster, PackedUserOperation calldata userOp)
external
view
override
returns (bool validated);
Parameters
user
address
User who will pay
paymaster
address
Paymaster address
userOp
PackedUserOperation
User operation (for gas estimation)
Returns
validated
bool
Whether the payment is pre-validated
updateCMXPaymasterSupport
Update CMX paymaster support
function updateCMXPaymasterSupport(address paymaster, bool supported) external override onlyFactoryAdmin;
Parameters
paymaster
address
CMX paymaster address
supported
bool
Whether to support this paymaster
isCMXPaymasterSupported
Check if a CMX paymaster is supported
function isCMXPaymasterSupported(address paymaster) external view override returns (bool supported);
Parameters
paymaster
address
CMX paymaster address
Returns
supported
bool
Whether the paymaster is supported
getSupportedCMXPaymasters
Get all supported CMX paymasters
function getSupportedCMXPaymasters() external view override returns (address[] memory paymasters);
Returns
paymasters
address[]
Array of supported paymaster addresses
validateCMXPayment
Validate CMX paymaster can handle the fee for an operation
function validateCMXPayment(address user, address paymaster, string calldata operationType)
external
view
override
returns (bool canPay, uint256 cmxRequired, uint256 ethEquivalent);
Parameters
user
address
User who will pay the fee
paymaster
address
CMX paymaster address
operationType
string
Type of operation (for fee calculation)
Returns
canPay
bool
Whether the user can pay via CMX
cmxRequired
uint256
CMX amount required
ethEquivalent
uint256
ETH equivalent amount
preValidateCMXPayment
Pre-validate CMX payment before operation
function preValidateCMXPayment(address user, address paymaster, PackedUserOperation calldata userOp)
external
view
override
returns (bool validated);
Parameters
user
address
User who will pay
paymaster
address
CMX paymaster address
userOp
PackedUserOperation
User operation (for gas estimation)
Returns
validated
bool
Whether the payment is pre-validated
getBaseFee
Get the base creation fee for factory operations
function getBaseFee(string calldata operationType) public view override returns (uint256 fee);
Parameters
operationType
string
Type of operation (always "createLedger" for ledger factory)
Returns
fee
uint256
Base fee in ETH (wei)
calculateTotalFee
Calculate total fee including any factory-specific multipliers
function calculateTotalFee(string calldata operationType, uint256 baseAmount)
public
view
override
returns (uint256 totalFee);
Parameters
operationType
string
Type of operation
baseAmount
uint256
Base amount in ETH
Returns
totalFee
uint256
Total fee including multipliers
validateLedgerCreationPayment
Validate and prepare CMX payment for ledger creation
function validateLedgerCreationPayment(address user, address paymaster, uint8 decimals, string calldata currencyCode)
external
view
returns (bool validated, uint256 cmxAmount);
Parameters
user
address
User creating the ledger
paymaster
address
CMX paymaster to use
decimals
uint8
Decimal precision for the ledger
currencyCode
string
Currency code for the ledger
Returns
validated
bool
Whether the payment is valid
cmxAmount
uint256
CMX amount that will be charged
emitCMXPaymasterUsed
Emit CMX paymaster usage event
function emitCMXPaymasterUsed(
address user,
address paymaster,
uint256 cmxAmount,
uint256 ethEquivalent,
uint8 decimals,
string calldata currencyCode
) external;
Parameters
user
address
User who used the paymaster
paymaster
address
Paymaster address
cmxAmount
uint256
CMX amount charged
ethEquivalent
uint256
ETH equivalent value
decimals
uint8
Decimal precision of the created ledger
currencyCode
string
Currency code of the created ledger
_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
Total 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
Max fee per gas
Structs
CMXPaymasterLayout
struct CMXPaymasterLayout {
mapping(address => bool) supportedCMXPaymasters;
address[] cmxPaymasterList;
}
Last updated
Was this helpful?