CoreExecution
CoreExecution is an abstract contract that provides a convenient interface for services to process payments through Core.sol. It handles both user-initiated payments (via signatures) and contract-authorized payments.
Overview
Contract Type: Abstract Contract
License: EVVM-NONCOMMERCIAL-1.0
Import Path: @evvm/testnet-contracts/library/utils/service/CoreExecution.sol
Key Features
- Direct integration with Core.sol for payment processing
- Support for both signed and contract-authorized payments
- Batch payment capabilities
- Governance-controlled Core.sol address updates
State Variables
Core public core;
Reference to the EVVM Core.sol contract for balance operations.
Functions
requestPay
function requestPay(
address from,
address token,
uint256 amount,
uint256 priorityFee,
uint256 nonce,
bool isAsyncExec,
bytes memory signature
) internal
Requests payment from a user via Core.sol with signature validation.
Parameters:
from- User address making the paymenttoken- Token address (oraddress(0)for native token)amount- Payment amountpriorityFee- Optional MATE priority feenonce- User's nonce for Core.solisAsyncExec- Whether to use async (true) or sync (false) nonce systemsignature- User's EIP-191 signature authorizing the payment
Implementation: Calls core.pay(from, address(this), "", token, amount, priorityFee, address(this), nonce, isAsyncExec, signature)
Executor: Always address(this) (the service contract itself)
Usage: Call this from your service function when a user needs to pay.
makeCaPay
function makeCaPay(
address to,
address token,
uint256 amount
) internal
Sends tokens from service's balance to recipient via contract authorization (no signature required).
Parameters:
to- Recipient addresstoken- Token address (oraddress(0)for native token)amount- Amount to send
Usage: Use this when your service needs to pay users from its own balance (e.g., rewards, refunds).
makeCaBatchPay
function makeCaBatchPay(
address[] memory to,
address token,
uint256[] memory amounts
) internal
Sends tokens to multiple recipients via contract authorization (batch version).
Parameters:
to- Array of recipient addressestoken- Token address (oraddress(0)for native token)amounts- Array of amounts corresponding to each recipient
Usage: Efficient way to distribute payments to multiple users in a single transaction.
updateCoreAddress (Admin only)
function updateCoreAddress(address newCoreAddress) external virtual
Updates the Core.sol contract address. Must be overridden with proper access control (e.g., onlyAdmin modifier).
Parameters:
newCoreAddress- New Core.sol contract address
Security: Always restrict this function to admin-only access in your implementation.
Usage Example
import {CoreExecution} from "@evvm/testnet-contracts/library/utils/service/CoreExecution.sol";
import {Admin} from "@evvm/testnet-contracts/library/utils/governance/Admin.sol";
contract CoffeeShop is CoreExecution, Admin {
uint256 public constant COFFEE_PRICE = 0.001 ether;
constructor(address coreAddress, address initialAdmin)
CoreExecution(coreAddress)
Admin(initialAdmin)
{}
function buyCoffee(
address buyer,
uint256 priorityFee,
uint256 nonce,
bool isAsyncExec,
bytes memory signature
) external {
// Request payment from buyer
requestPay(
buyer,
address(0), // ETH payment
COFFEE_PRICE,
priorityFee,
nonce,
isAsyncExec,
signature
);
// Process coffee order...
}
function refundCustomer(address customer, uint256 amount) external onlyAdmin {
// Send refund from service balance
makeCaPay(customer, address(0), amount);
}
function distributeRewards(
address[] memory winners,
uint256[] memory amounts
) external onlyAdmin {
// Batch payment to multiple users
makeCaBatchPay(winners, address(0), amounts);
}
// Override with admin protection
function updateCoreAddress(address newCoreAddress) external override onlyAdmin {
core = Core(newCoreAddress);
}
}
Integration with EvvmService
EvvmService internally inherits from CoreExecution, providing these payment functions automatically:
import {EvvmService} from "@evvm/testnet-contracts/library/EvvmService.sol";
contract MyService is EvvmService {
// Inherits requestPay, makeCaPay, makeCaBatchPay automatically
}
Payment Flow
User-to-Service Payment (requestPay)
- User signs payment authorization with Core.sol nonce
- Service calls
requestPay()with signature - Core.sol validates signature and nonce
- Core.sol transfers tokens from user to service
- Nonce is marked as consumed
Service-to-User Payment (makeCaPay)
- Service calls
makeCaPay()(no signature needed) - Core.sol transfers from service balance to user
- Uses contract address authorization (msg.sender)
Security Considerations
- Nonce Management: Always use correct nonce from
core.getNonce(user, serviceAddress) - Signature Validation: Core.sol validates signatures - don't bypass this
- Origin Executor: Set
originExecutorto actual EOA calling the transaction - Balance Checks: Ensure service has sufficient balance before
makeCaPay() - Admin Protection: Always override
updateCoreAddress()with access control
Related Components
- Core.sol - Main payment contract
- EvvmService - Includes CoreExecution functionality
- SignatureUtil - For manual signature verification
- CoreHashUtils - For generating payment hashes
Recommendation: Use CoreExecution when building services that need Core.sol payment integration without the full EvvmService stack.