Skip to content

Feat/agent subscriptions - #457

Merged
devJaja merged 2 commits into
Epta-Node:mainfrom
nasarajoe:feat/agent-subscriptions
Aug 31, 2026
Merged

Feat/agent subscriptions#457
devJaja merged 2 commits into
Epta-Node:mainfrom
nasarajoe:feat/agent-subscriptions

Conversation

@nasarajoe

Copy link
Copy Markdown
Contributor

Summary

Adds a subscription-based payment model to the agent registry: clients
subscribe to an agent's service with recurring, period-based XLM payments,
can renew or cancel (with a prorated refund), and can opt into automatic
renewal.

Closes #258

What's implemented

smart-contracts/contracts/agent_registry/src/types.rs

  • Subscription struct: client, agent_id, payment_amount,
    period_secs, start_time, end_time, periods_paid, total_paid,
    last_payment_at, auto_renew, status
  • SubscriptionStatus enum: Active / Cancelled / Expired

smart-contracts/contracts/agent_registry/src/errors.rs

  • Error codes 27–32: SubscriptionNotFound, SubscriptionAlreadyExists,
    SubscriptionExpired, SubscriptionActive, InvalidSubscription,
    SubscriptionAlreadyCancelled (+ from_code arms)

smart-contracts/contracts/agent_registry/src/events.rs

  • SubscriptionCreatedEvent, SubscriptionRenewedEvent (carries an
    auto flag), SubscriptionCancelledEvent (carries the refund),
    PaymentProcessedEvent

smart-contracts/contracts/agent_registry/src/lib.rs

  • DataKey::Subscription(Address, Symbol) — one record per (client, agent)
  • Constants DEFAULT_SUBSCRIPTION_PERIOD_SECS (30 days, used when the
    caller passes 0) and MIN_SUBSCRIPTION_PERIOD_SECS (1 hour)
  • prorated_refund() helper — payment for the unused remainder of the
    current billing period, capped at one full period
  • create_subscription — client-authorised; validates amount/period,
    requires the agent to be registered, rejects a duplicate active
    subscription, pays for period 1. Emits sub_creat + pay_proc.
  • renew_subscription — client-authorised; appends one billing period
    (from end_time, or from now if the term already lapsed), increments
    periods_paid/total_paid. Cancelled subscriptions cannot be renewed.
    Emits pay_proc + sub_renew.
  • cancel_subscription — client-authorised; returns the prorated
    refund and marks the subscription Cancelled. Emits sub_canc.
  • check_subscriptiontrue iff status == Active && now < end_time
  • get_subscription — full record lookup
  • set_auto_renew — client opt-in / opt-out toggle
  • process_auto_renewal — permissionless (agent or keeper bot); only
    succeeds for an opted-in, non-cancelled subscription whose term has
    ended. Emits pay_proc + sub_renew with auto = true.

Payments are modelled as on-chain state (periods_paid, total_paid) plus
PaymentProcessed events, consistent with how escrow/settlement is handled
elsewhere in these contracts.

Build wiring repair (required)

agent_registry/src/lib.rs had lost mod types;, pub use errors::Error;
and pub use types::*; in the merge for #338's upgrade mechanism
(commit 38e9f9e), leaving types.rs orphaned and the crate uncompilable.
Those three lines are restored here.

smart-contracts/contracts/agent_registry/src/test.rs

18 unit tests: create/store, default-period fallback, unknown agent,
invalid params, duplicate active, time-based expiry, renew (extend and
post-expiry restart), prorated refund (60% mid-period) and zero refund
after expiry, cancel-twice, renew-after-cancel, unknown subscription,
auto-renewal (opt-in extends, requires opt-in, rejected before term end),
set_auto_renew toggle, event emission across the lifecycle, and a full
create → renew → cancel → recreate flow.

Acceptance criteria

  • create_subscription with duration, payment amount, and agent
  • Subscription stored with start time, end time, and payment schedule
    (periods_paid / total_paid / last_payment_at)
  • renew_subscription extends duration with new payment
  • cancel_subscription with prorated refund
  • check_subscription verifies if a subscription is active
  • Auto-renewal support (opt-in via auto_renew + process_auto_renewal)
  • Events: SubscriptionCreated, SubscriptionRenewed,
    SubscriptionCancelled, PaymentProcessed
  • Unit tests for create, renew, cancel, and expiry

⚠️ Verification status

cargo test -p agent-registry and cargo clippy could not be run:
agent_registry depends on upgrade-manager, which is currently
non-compiling on main (~25 errors — a #![no_std] crate using format!,
std::cmp::Ordering, String::to_string(), and moved-value bugs; its
Cargo.toml also declares only cdylib, no rlib). This breakage
predates and is unrelated to this change (introduced by commit 38e9f9e).

The subscription code follows the crate's established patterns (persistent
storage + TTL extension, (registry, <action>) event topics,
Result<_, Error> signatures) and is written to compile and pass once that
dependency is repaired. Fixing upgrade-manager is tracked separately.

@vercel

vercel Bot commented Aug 29, 2026

Copy link
Copy Markdown

@nasarajoe is attempting to deploy a commit to the Jaja's projects Team on Vercel.

A member of the Team first needs to authorize it.

@devJaja
devJaja merged commit 070a1fb into Epta-Node:main Aug 31, 2026
3 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(smart-contract): Implement Agent Subscription and Recurring Payment Model

2 participants