ICMXPaymaster
Inherits: IPaymaster
Interface for CMX token-based paymaster diamond
Extends IPaymaster to support CMX token fee payments with configurable exchange rates
Functions
depositCMX
Deposit CMX tokens to the paymaster for fee payments
function depositCMX(uint256 amount) external;
Parameters
amount
uint256
Amount of CMX tokens to deposit
withdrawCMX
Withdraw CMX tokens from the paymaster
function withdrawCMX(uint256 amount, address recipient) external;
Parameters
amount
uint256
Amount of CMX tokens to withdraw
recipient
address
Address to receive the tokens
getCMXBalance
Get CMX token balance of the paymaster
function getCMXBalance() external view returns (uint256 balance);
Returns
balance
uint256
Current CMX token balance
getUserCMXAllowance
Get user's CMX allowance for the paymaster
function getUserCMXAllowance(address user) external view returns (uint256 allowance);
Parameters
user
address
User address
Returns
allowance
uint256
Current CMX allowance
updateExchangeRate
Update CMX/ETH exchange rate
Only callable by authorized rate updaters
function updateExchangeRate(uint256 newRate) external;
Parameters
newRate
uint256
New exchange rate (CMX tokens per 1 ETH, scaled by 1e18)
getExchangeRate
Get current CMX/ETH exchange rate
function getExchangeRate() external view returns (uint256 rate);
Returns
rate
uint256
Current exchange rate (CMX tokens per 1 ETH, scaled by 1e18)
calculateCMXAmount
Calculate CMX amount needed for a given ETH amount
function calculateCMXAmount(uint256 ethAmount) external view returns (uint256 cmxAmount);
Parameters
ethAmount
uint256
ETH amount in wei
Returns
cmxAmount
uint256
Required CMX amount
calculateETHEquivalent
Calculate ETH equivalent for a given CMX amount
function calculateETHEquivalent(uint256 cmxAmount) external view returns (uint256 ethAmount);
Parameters
cmxAmount
uint256
CMX amount
Returns
ethAmount
uint256
Equivalent ETH amount in wei
addSupportedFactory
Add a factory to the supported list
function addSupportedFactory(address factory, uint256 feeMultiplier) external;
Parameters
factory
address
Factory contract address
feeMultiplier
uint256
Fee multiplier for this factory (scaled by 1e18, 1e18 = 1x)
removeSupportedFactory
Remove a factory from the supported list
function removeSupportedFactory(address factory) external;
Parameters
factory
address
Factory contract address
updateFactoryFeeMultiplier
Update fee multiplier for a factory
function updateFactoryFeeMultiplier(address factory, uint256 feeMultiplier) external;
Parameters
factory
address
Factory contract address
feeMultiplier
uint256
New fee multiplier (scaled by 1e18)
isFactorySupported
Check if a factory is supported
function isFactorySupported(address factory) external view returns (bool supported);
Parameters
factory
address
Factory contract address
Returns
supported
bool
Whether the factory is supported
getFactoryFeeMultiplier
Get fee multiplier for a factory
function getFactoryFeeMultiplier(address factory) external view returns (uint256 multiplier);
Parameters
factory
address
Factory contract address
Returns
multiplier
uint256
Fee multiplier (scaled by 1e18)
getSupportedFactories
Get all supported factories
function getSupportedFactories() external view returns (address[] memory factories);
Returns
factories
address[]
Array of supported factory addresses
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
setProtocolTreasury
Set protocol treasury address
function setProtocolTreasury(address treasury) external;
Parameters
treasury
address
New treasury address
getProtocolTreasury
Get protocol treasury address
function getProtocolTreasury() external view returns (address treasury);
Returns
treasury
address
Current treasury address
transferFeesToTreasury
Transfer collected fees to protocol treasury
function transferFeesToTreasury(uint256 amount) external;
Parameters
amount
uint256
Amount of CMX tokens to transfer
getPaymasterStats
Get paymaster statistics
function getPaymasterStats()
external
view
returns (uint256 totalOperationsSponsored, uint256 totalCMXUsed, uint256 totalETHEquivalent);
Returns
totalOperationsSponsored
uint256
Total operations sponsored
totalCMXUsed
uint256
Total CMX tokens used for fees
totalETHEquivalent
uint256
Total ETH equivalent value
getUserStats
Get user-specific statistics
function getUserStats(address user)
external
view
returns (uint256 operationsSponsored, uint256 cmxUsed, uint256 ethEquivalent);
Parameters
user
address
User address
Returns
operationsSponsored
uint256
Operations sponsored for this user
cmxUsed
uint256
CMX tokens used by this user
ethEquivalent
uint256
ETH equivalent value for this user
Events
CMXFeePayment
Emitted when CMX tokens are used to pay for gas
event CMXFeePayment(
address indexed user, address indexed factory, uint256 cmxAmount, uint256 ethEquivalent, uint256 exchangeRate
);
Parameters
user
address
The user whose operation was sponsored
factory
address
The factory contract that received the fee
cmxAmount
uint256
Amount of CMX tokens used
ethEquivalent
uint256
Equivalent ETH value
exchangeRate
uint256
CMX/ETH exchange rate used
ExchangeRateUpdated
Emitted when exchange rate is updated
event ExchangeRateUpdated(uint256 oldRate, uint256 newRate, address indexed updatedBy);
Parameters
oldRate
uint256
Previous CMX/ETH exchange rate
newRate
uint256
New CMX/ETH exchange rate
updatedBy
address
Address that updated the rate
FactoryAdded
Emitted when a factory is added to supported list
event FactoryAdded(address indexed factory, uint256 feeMultiplier);
Parameters
factory
address
Factory contract address
feeMultiplier
uint256
Fee multiplier for this factory
FactoryRemoved
Emitted when a factory is removed from supported list
event FactoryRemoved(address indexed factory);
Parameters
factory
address
Factory contract address
CMXDeposited
Emitted when CMX tokens are deposited to the paymaster
event CMXDeposited(address indexed depositor, uint256 amount);
Parameters
depositor
address
Address that deposited tokens
amount
uint256
Amount of CMX tokens deposited
CMXWithdrawn
Emitted when CMX tokens are withdrawn from the paymaster
event CMXWithdrawn(address indexed recipient, uint256 amount);
Parameters
recipient
address
Address that received tokens
amount
uint256
Amount of CMX tokens withdrawn
Errors
InsufficientCMXBalance
error InsufficientCMXBalance(uint256 required, uint256 available);
UnsupportedFactory
error UnsupportedFactory(address factory);
InvalidExchangeRate
error InvalidExchangeRate(uint256 rate);
InvalidFeeMultiplier
error InvalidFeeMultiplier(uint256 multiplier);
PaymasterDepositFailed
error PaymasterDepositFailed(uint256 amount);
PaymasterWithdrawalFailed
error PaymasterWithdrawalFailed(uint256 amount);
UnauthorizedCaller
error UnauthorizedCaller(address caller);
Last updated
Was this helpful?