Skip to content

feat(contracts): recurring allowance / spending-limit authority (#1041) - #1103

Merged
Calebux merged 1 commit into
Calebux:mainfrom
vibenedict:feat/recurring-allowance-1041
Jul 24, 2026
Merged

feat(contracts): recurring allowance / spending-limit authority (#1041)#1103
Calebux merged 1 commit into
Calebux:mainfrom
vibenedict:feat/recurring-allowance-1041

Conversation

@vibenedict

Copy link
Copy Markdown
Contributor

Summary

Closes #1041.

Adds a standalone Soroban contract — allowance — that lets a user (owner) pre-authorize a merchant for capped recurring pulls, fully decoupled from subscription renewal. It enforces two independent limits:

  • Per-period cap — max pullable within any single rolling period (e.g. "50 USDC / month")
  • Absolute cap — lifetime ceiling across all periods

Funds move via the token's transfer_from with the contract as spender, so the merchant can pull on its own schedule without the owner signing each time (owner grants a matching token approve once).

API

Function Who Purpose
grant_allowance owner Authorize a merchant with per-period cap, absolute cap, period length
revoke_allowance owner Immediately block further pulls
consume merchant Pull funds; auto-resets the period window and enforces both caps
update_caps owner Adjust caps (never below already-spent)
available anyone Amount still pullable right now
pause / unpause / is_paused admin Circuit breaker over all consumption

Design notes

  • Period reset is boundary-aligned: period_start advances by whole periods so caps track fixed cycles rather than drifting per pull.
  • Cap enforcement uses checked arithmetic and runs before any funds move.
  • Validation: merchant ≠ owner, positive caps/period, per-period ≤ absolute, cap adjustments never below spent.

Acceptance criteria

  • Grant / revoke / consume allowance
  • Period reset
  • Cap enforcement (per-period + absolute)
  • Tests

Testing

cargo test -p allowance25 passing (21 unit + 4 property/fuzz), covering the happy path, both cap breaches, period reset & boundary alignment, revoke/pause blocking, cap updates, isolation between allowances, and input validation. Also builds clean for the wasm32v1-none deploy target.

🤖 Generated with Claude Code

…bux#1041)

Add a standalone Soroban contract letting an owner pre-authorize a
merchant for capped recurring pulls, decoupled from subscription renewal.

- grant/revoke allowance with per-period and absolute (lifetime) caps
- consume enforces both caps and auto-resets the period window (boundary
  aligned) before moving funds owner -> merchant via transfer_from
- update_caps (never below already-spent), available() query
- admin pause/unpause circuit breaker
- 21 unit tests + 4 property/fuzz tests; builds for wasm32v1-none

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vibenedict
vibenedict requested a review from Calebux as a code owner July 23, 2026 20:01
@Calebux
Calebux merged commit c8209b4 into Calebux:main Jul 24, 2026
28 of 34 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.

New contract: recurring allowance / spending-limit authority

2 participants