CronRegistry
Core contract — manages plans, subscriptions, and charge execution.
Key functions
createPlan
function createPlan(
address token,
uint256 amount,
uint256 interval,
uint256 gracePeriod,
bool agentCompatible,
string calldata metadataURI
) external returns (uint256 planId)
Creates a new subscription plan. Returns the plan ID. Only the caller becomes the merchant.
subscribe
function subscribe(uint256 planId, bool mintNFT) external
Subscribes the caller to a plan. If mintNFT is true, mints a CronNFT. Requires the caller to have approved sufficient token allowance to CronRegistry.
charge
function charge(uint256 planId, address subscriber) external
Executes a charge. Can be called by any address (keeper). Reverts if the subscription is not due, inactive, or if the subscriber has insufficient balance/allowance.
cancel
function cancel(uint256 planId) external
Cancels the caller's subscription. No further charges will execute.
pausePlan / unpausePlan
function pausePlan(uint256 planId) external
function unpausePlan(uint256 planId) external
Merchant-only. A paused plan blocks new subscriptions but does not cancel existing ones.
Key view functions
| Function | Returns |
|---|---|
getPlan(planId) | Full plan struct |
getSubscription(planId, subscriber) | Subscription struct |
isChargeDue(planId, subscriber) | bool |
nextChargeAt(planId, subscriber) | Unix timestamp |
subscriptionStatus(planId, subscriber) | SubscriptionStatus enum |
Events
| Event | Emitted when |
|---|---|
PlanCreated | New plan created |
PlanPaused / PlanUnpaused | Merchant pauses/unpauses a plan |
SubscriptionCreated | User subscribes |
SubscriptionCancelled | User cancels |
SubscriptionExpired | Grace period elapsed with no payment |
Charged | Successful charge executed |
ChargeFailed | Charge attempted but failed (low balance etc.) |
SubscriptionStatus enum
| Value | Meaning |
|---|---|
Active | Subscription is current |
PastDue | Charge failed, within grace period |
Cancelled | User cancelled |
Expired | Grace period elapsed, subscription lapsed |