Skip to content

Add Subscription example: pull payments without escrow lock - #74

Draft
tiero wants to merge 3 commits into
masterfrom
claude/subscriptions-pull-payment-design-6fj9vv
Draft

Add Subscription example: pull payments without escrow lock#74
tiero wants to merge 3 commits into
masterfrom
claude/subscriptions-pull-payment-design-6fj9vv

Conversation

@tiero

@tiero tiero commented Aug 1, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds examples/subscription/subscription.ark: a pull-payment alternative to payment_auth's authorize/capture escrow. Instead of locking the customer's funds until the merchant captures or a timelock refunds, the coin stays customer-spendable at all times; the covenant carves out a bounded merchant allowance of exactly pullAmount once per interval.
  • pull(merchantSig): merchant collects one period once it's due (tx.offchainTime >= nextPullTime); the remainder recreates the contract with the schedule advanced by interval (missed periods accrue rather than resetting to "now", so billing dates never drift).
  • cancel(customerSig): customer exits anytime, but any already-due periods are settled to the merchant first (billed-in-advance, so pull and cancel always agree on what's currently owed). Debt is capped against the coin's balance before multiplying, to avoid overflow on a long-neglected subscription; sub-dust debt is forgiven.
  • unilateral(customerSig) tapscript CSV exit, matching the project's standard L1 fallback pattern.
  • Wires the new example into tests/examples/compilation_roundtrip.rs and adds a dedicated tests/examples/subscription.rs with structural assertions on spend-group count, witness/signature shape per function, the overflow-safe debt-cap ordering, and the recursive renewal output.

Test plan

  • cargo test --test examples subscription — 11/11 new tests pass
  • cargo test --workspace — full suite passes
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo fmt --check — clean
  • cargo run -- examples/subscription/subscription.ark -o /tmp/contract.json — compiles

Generated by Claude Code

Alternative to PaymentAuthorization's lock-then-capture escrow. The coin
stays customer-spendable at all times; the merchant gets a covenant-bound
allowance to pull exactly pullAmount once per interval. Cancel settles any
already-due periods to the merchant before releasing the rest.
@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 50f09210-e088-43e1-88cc-01abf8fd7012

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Playground Preview

A live preview of this PR's playground is available at:
https://arkade-os.github.io/compiler/pr-previews/pr-74/

Built from commit c694308eb3b6bac8d25d19a4c6eda2c787fe5760 · Workflow run

claude added 2 commits August 1, 2026 23:16
- cancel now computes elapsed = tx.offchainTime - nextPullTime once and
  guards on its sign, instead of re-deriving the same subtraction from
  tx.offchainTime/nextPullTime separately for the gate and for elapsed
  (matches the elapsed-time idiom used elsewhere, e.g. stability_vault.ark).
- Test file reuses the shared leaf_asm/witness_names helpers instead of
  hand-rolling leaf/witness extraction.
- Strengthened the pull output-0 assertion to check the exact merchant-pin
  token sequence, since pull pins two structurally similar outputs
  (merchant payout at 0, renewal VTXO at 1) and a presence-only check
  couldn't tell them apart.
Fresh environments have neither the wasm32 target nor wasm-pack installed.
Also note wasm-pack's binaryen download can fail in restricted sandboxes
(use --no-opt, not a Cargo.toml change), and that examples/ files auto-join
the WASM build via contracts.js but need a manual main.js entry to appear
in the playground's file-tree UI.
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.

2 participants