Feat/agent subscriptions - #457
Merged
Merged
Conversation
|
@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. |
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.rsSubscriptionstruct:client,agent_id,payment_amount,period_secs,start_time,end_time,periods_paid,total_paid,last_payment_at,auto_renew,statusSubscriptionStatusenum:Active/Cancelled/Expiredsmart-contracts/contracts/agent_registry/src/errors.rsSubscriptionNotFound,SubscriptionAlreadyExists,SubscriptionExpired,SubscriptionActive,InvalidSubscription,SubscriptionAlreadyCancelled(+from_codearms)smart-contracts/contracts/agent_registry/src/events.rsSubscriptionCreatedEvent,SubscriptionRenewedEvent(carries anautoflag),SubscriptionCancelledEvent(carries the refund),PaymentProcessedEventsmart-contracts/contracts/agent_registry/src/lib.rsDataKey::Subscription(Address, Symbol)— one record per (client, agent)DEFAULT_SUBSCRIPTION_PERIOD_SECS(30 days, used when thecaller passes
0) andMIN_SUBSCRIPTION_PERIOD_SECS(1 hour)prorated_refund()helper — payment for the unused remainder of thecurrent 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 fromnowif the term already lapsed), incrementsperiods_paid/total_paid. Cancelled subscriptions cannot be renewed.Emits
pay_proc+sub_renew.cancel_subscription— client-authorised; returns the proratedrefund and marks the subscription
Cancelled. Emitssub_canc.check_subscription—trueiffstatus == Active && now < end_timeget_subscription— full record lookupset_auto_renew— client opt-in / opt-out toggleprocess_auto_renewal— permissionless (agent or keeper bot); onlysucceeds for an opted-in, non-cancelled subscription whose term has
ended. Emits
pay_proc+sub_renewwithauto = true.Payments are modelled as on-chain state (
periods_paid,total_paid) plusPaymentProcessedevents, consistent with how escrow/settlement is handledelsewhere in these contracts.
Build wiring repair (required)
agent_registry/src/lib.rshad lostmod types;,pub use errors::Error;and
pub use types::*;in the merge for #338's upgrade mechanism(commit
38e9f9e), leavingtypes.rsorphaned and the crate uncompilable.Those three lines are restored here.
smart-contracts/contracts/agent_registry/src/test.rs18 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_renewtoggle, event emission across the lifecycle, and a fullcreate → renew → cancel → recreate flow.
Acceptance criteria
create_subscriptionwith duration, payment amount, and agent(
periods_paid/total_paid/last_payment_at)renew_subscriptionextends duration with new paymentcancel_subscriptionwith prorated refundcheck_subscriptionverifies if a subscription is activeauto_renew+process_auto_renewal)SubscriptionCreated,SubscriptionRenewed,SubscriptionCancelled,PaymentProcessedcargo test -p agent-registryandcargo clippycould not be run:agent_registrydepends onupgrade-manager, which is currentlynon-compiling on
main(~25 errors — a#![no_std]crate usingformat!,std::cmp::Ordering,String::to_string(), and moved-value bugs; itsCargo.tomlalso declares onlycdylib, norlib). This breakagepredates 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 thatdependency is repaired. Fixing
upgrade-manageris tracked separately.