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

FunctionReturns
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

EventEmitted when
PlanCreatedNew plan created
PlanPaused / PlanUnpausedMerchant pauses/unpauses a plan
SubscriptionCreatedUser subscribes
SubscriptionCancelledUser cancels
SubscriptionExpiredGrace period elapsed with no payment
ChargedSuccessful charge executed
ChargeFailedCharge attempted but failed (low balance etc.)

SubscriptionStatus enum

ValueMeaning
ActiveSubscription is current
PastDueCharge failed, within grace period
CancelledUser cancelled
ExpiredGrace period elapsed, subscription lapsed