Pull-based recurring payments for Stellar.
Soroban contracts that let a merchant charge a subscriber on a schedule,
without the subscriber signing every payment.
Live demo: https://mmm-pay.github.io/payflow-frontend/ · Docs: https://mmm-pay.github.io/payflow-docs/
Stellar payments are push-only. The account holding the funds must sign every transfer. That is correct for a one-off payment and useless for a subscription: a merchant cannot bill a customer monthly without the customer signing a transaction every month, and no consumer does that.
Every subscription business on Stellar today solves this by holding customer funds off-chain or by asking for a custodial key. Both re-introduce exactly the trust the chain was supposed to remove.
Payflow supplies the missing primitive: a mandate. A subscriber authorizes a bounded, revocable standing charge once. After that, anyone can settle the payment when it comes due — and nobody can take more than the mandate allows.
merchant subscriber keeper (anyone)
│ │ │
│ create_plan │ deposit │
▼ ▼ │
┌──────────────┐ ┌──────────────┐ │
│ plan-registry│ │ vault │ │
│ │ │ holds funds │ │
│ price/period │ └──────┬───────┘ │
└──────┬───────┘ │ debit (only) │
│ get_plan │ │
▼ │ │
┌──────────────────────────────┴───────┐ │
│ subscription │◄──── charge ──────┘
│ mandates · schedule · fee split │
└──────────────────────────────────────┘
Three contracts, one direction of dependency:
| Contract | Owns | Depends on |
|---|---|---|
plan-registry |
Merchant plans: price, period, accepted tokens | — |
vault |
Custody of subscriber funds | token (SEP-41) |
subscription |
Mandates, scheduling, fee split | plan-registry, vault |
Why the vault exists. A pull payment fails the moment a subscriber's wallet is empty at charge time. Separating custody from billing means subscribers fund ahead, and the biller debits a balance that is already committed. It also means custody logic can be audited on its own.
Why charge is open to anyone. The mandate is the authorization, so it
does not matter who triggers settlement. If the project's keeper goes offline,
the merchant — or the subscriber, or a stranger — can still settle. Billing does
not depend on us staying online. The caller signs only to receive the plan's
keeper tip, if it sets one; that signature gives it no power over the mandate.
A tip is paid out of the merchant's share, so it never raises what the
subscriber pays.
- The price is copied into the mandate at subscribe time. A merchant editing a plan later cannot reprice an open mandate.
- The subscriber selects one of the plan's accepted SEP-41 tokens when opening a mandate. That token is frozen into the mandate and used for every charge.
max_chargescaps total collections.0means open-ended.cancelis unilateral and immediate; the merchant is not consulted.- A merchant can end a mandate (
end_mandate) when it stops offering the service. Ending can only stop future charges; it never takes anything. - Withdrawing from the vault starves any mandate. Funds are never locked.
- A keeper outage delays billing; it never accumulates a backlog that drains a
vault in one burst.
next_chargeadvances tonow + period, notnext_charge + period. - The protocol fee is capped at 10% (
MAX_FEE_BPS = 1000) and is integer basis points, frozen into each mandate when it is opened. An admin fee change only applies to new mandates. There is no floating point anywhere in the contracts. - A keeper tip is capped at 5% of the merchant's share (
MAX_KEEPER_BPS = 500) and comes out of that share, never out of the subscriber's payment. It is frozen into the mandate when it is opened. upgrademoves a mandate onto another plan of the same merchant that accepts the mandate's frozen token. A more expensive plan collects the price difference for the part of the current period that is still ahead, prorated and rounded in the subscriber's favour; a cheaper plan takes effect at the next charge and never refunds anything. See Plan Upgrade and Downgrade Semantics and ADR 0006. anything. See ADR 0006.- A subscriber can authorize one separate additional charge with
set_extra_charge_cap. Anyone may settle an amount up to that cap once; it counts toward the mandate's charge and spend limits but does not move the next recurring due date. - A merchant can pause charging for one plan without ending its mandates or closing it to new subscribers. Pausing only blocks settlement; resuming restores the same mandates.
- A plan's grace window is copied into each mandate at sign-up.
is_in_grace_periodlets a wallet warn the subscriber between the due time and the end of that window. The view never changes or cancels the mandate. - Vault deposits and withdrawals are limited to 8 operations per
(user, token)in each 60-second window. Charges are not affected, and the window resets on a fixed epoch-aligned boundary.
Constructors, not initialize. Every contract receives its admin and
wiring as constructor arguments, so it is configured in the same transaction
that deploys it. A separate initialize call leaves a window in which anyone
can call it first and become admin.
Indexes that cannot be griefed. The lists of a merchant's plans, a
merchant's mandates and a subscriber's mandates are stored one ledger entry per
position plus a count, not as a single growing Vec. Opening a subscription
costs the same whether the merchant has one subscriber or a million, and nobody
can block a merchant by opening throwaway mandates until a list outgrows the
ledger's entry size limit.
Paged reads. merchant_plans, token_plans, merchant_mandates and subscriber_mandates
take start and limit and return at most 50 ids (MAX_PAGE), because one
transaction may touch at most 100 ledger entries. Each has a matching
*_count function, and next_plan_id tells a client how many plans exist.
mandate_terms returns a mandate's price, period, fee, charge/spend/pause
caps, one-off cap, current pause state and next due time in one read.
docs/sequence-diagrams.md shows the
cross-contract calls (Subscription → PlanRegistry → Vault → token) for
subscribe, charge and cancel, the errors each step can stop on, the
events each flow emits, and what the protocol pause blocks.
docs/settlement-threat-model.md explains
the trust assumptions and attack surface for charge, vault debit and refund.
See the event contribution guide to add or change a typed contract event, test its wire layout and regenerate bindings.
The complete numeric error reference is in docs/ERRORS.md, including the trigger condition for every contract error.
Detailed lifecycle guides:
docs/plan-changes.md— plan upgrade proration, downgrade behaviour, and state transitions forSubscription::upgradedocs/vault-reserves.md— per-mandate vault reserve lifecycle, reserve delta table, and expired vs. cancelled mandate behaviourdocs/storage-ttl.md— storage TTLs, archival, which entries can expire, and how callers keep a mandate alive
Settled design choices are written up as short ADRs (context, decision,
consequences) in docs/adr/:
- 0001: Vault separate from billing
- 0002:
now + periodscheduling - 0003: Constructors instead of
initialize - 0004: Per-position indexes
- 0005: Permissionless
charge - 0006: Prorated upgrade charging
- 0007: TTL refresh on access for hot keys
Add a new ADR whenever a design choice changes.
docs/glossary.md maps the terms on the
docs site glossary
(mandate, plan, vault, charge, keeper, …) to the contract, type, function and
storage key that implement each one, and lists where the two have drifted.
You need Freighter (or another wallet supported by Stellar Wallets Kit) set to Testnet.
- Get test XLM. Copy your address from the wallet and open
https://friendbot.stellar.org/?addr=<your address>. - Fund your vault. In the demo, connect your wallet, open Account and deposit 5 XLM. The vault is the only balance a mandate can draw from, and you can withdraw it at any time.
- Subscribe. Open Subscribe, pick Demo Monthly (1 XLM every minute; the name predates the period), set a charge limit of 3 and confirm.
- Watch it bill. The first charge is due at once. A scheduled keeper settles due mandates about every 15 minutes, and Account shows the charges. Anyone can settle a due mandate, so a merchant does not have to wait for the keeper.
- Stay in control. Pause, resume or cancel from Account. Withdrawing your vault balance also stops further charges.
- Be the merchant. On Merchant, publish your own plan, charge due mandates yourself, or end a subscriber's mandate.
| Contract | ID |
|---|---|
plan-registry |
CDQ5EJTVXXX2CBMHWP3BGGUDHSK6D4I25IF5XXH3QGL2TNTBMJUOFKDB |
vault |
CBNQEWSYYQOKNX5KB62OFT6ID5TCVSWN4PS4AXAJK6IWUEXOLVN6DXII |
subscription |
CD5YZUJU6WLFIHGAV4J2BV42GCVZE5ZGDUGSW5CBRIA47TQHSZZW3XMM |
Settlement token: the native XLM Stellar Asset Contract
(CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC). The same ids, the admin and the ledger the suite was
deployed at are in deployments/testnet.env.
# prerequisites: Rust 1.96+, stellar-cli 27+
rustup target add wasm32v1-none
cargo test --all # 250 tests
stellar contract build # wasm -> target/wasm32v1-none/releaseDeploy your own suite:
stellar keys generate payflow-deployer --network testnet --fund
./scripts/deploy.sh testnet payflow-deployerThe script deploys in dependency order, passing each contract its configuration
as constructor arguments, grants the subscription contract debit rights on the
vault, and writes the ids to deployments/<network>.env.
Upgrade a deployed suite to new wasm (admin-signed; storage is preserved):
./scripts/upgrade.sh subscription testnet payflow-deployerFor a full step-by-step walkthrough including prerequisites, smoke-testing, and troubleshooting, see docs/testnet-quickstart.md.
Smoke-test a live deployment end to end:
./scripts/demo.sh testnet # reads deployments/testnet.envInstall the generated clients from npm:
npm install @mmm-pay/contracts @stellar/stellar-sdkUse the generated client with the testnet RPC to read contract state:
import { Networks } from "@stellar/stellar-sdk";
import { PlanRegistryClient } from "@mmm-pay/contracts";
const registry = new PlanRegistryClient({
contractId: "YOUR_PLAN_REGISTRY_ID",
networkPassphrase: Networks.TESTNET,
rpcUrl: "https://soroban-testnet.stellar.org",
});
const transaction = await registry.next_plan_id();
await transaction.simulate();
const nextPlanId = transaction.result.unwrap();The package also exports VaultClient and SubscriptionClient, with
contract-specific types under PlanRegistryTypes, VaultTypes and
SubscriptionTypes. Mutating methods return transactions that integrators
must authorize and submit with the Stellar SDK.
CI builds and verifies the bindings on contract changes. Publishing a GitHub
release publishes the matching version to npm; the repository needs an
NPM_TOKEN secret. The manual TypeScript bindings testnet smoke workflow
checks the live registry's next_plan_id read without a signing key.
To regenerate and check the package locally after changing a contract:
stellar contract build
./scripts/generate-bindings.sh
npm ci --prefix bindings
npm test --prefix bindingsVerify that a deployment runs the WASM built from this source:
./scripts/verify.sh testnet # fetches IDs from deployments/testnet.envThe verifier builds the contracts, fetches each deployed WASM, and compares SHA-256 hashes. It exits non-zero if any deployed contract differs.
contracts/
plan-registry/ merchant plan catalogue
vault/ subscriber custody
subscription/ mandates, scheduling, fee split
test-token/ test-only SEP-41 fixture (never deploy as a real asset)
shared/ types shared across contract boundaries
scripts/
deploy.sh ordered deploy + wiring
demo.sh end-to-end smoke test
upgrade.sh admin-gated in-place wasm upgrade
verify.sh compare deployed WASMs with source
deployments/
testnet.env ids of the live testnet suite
Each contract follows the same file split: lib.rs (entry points), types.rs
(storage types), error.rs (contracterror), events.rs (contractevent),
test.rs.
The extra contracts/test-token crate is not part of the deployed suite: it is
a test-only token fixture with minting and failure injection, documented in
docs/test-token.md. Never deploy it as a real asset.
| Repo | Role |
|---|---|
| payflow-contract | Soroban contracts (this repo) |
| payflow-backend | Event indexer + keeper that settles due mandates |
| payflow-frontend | Merchant dashboard and subscriber portal |
| payflow-docs | Protocol documentation |
Install just, the Rust toolchain specified in
rust-toolchain.toml (including rustfmt, clippy
and the wasm32v1-none target), and the Stellar CLI
used by CI (stellar/[email protected]). The auth-coverage script
requires a POSIX-compatible shell.
From the repository root, run:
just check
# or: just ciThis runs the core CI checks sequentially, stopping on the first failure:
cargo fmt --all -- --checkcargo clippy --all-targets -- -D warningscargo test --alland./scripts/check_auth_tests.shstellar contract build(Wasm artifacts intarget/wasm32v1-none/release/)
You can run an individual stage with just fmt, just clippy,
just test, or just build. These recipes match CI's core fmt,
clippy, test and Wasm build jobs. The separate CI coverage, dependency-audit,
minimum-supported-Rust-version, and reproducible-Wasm-build jobs are not
part of this local command; the pull-request workflow remains authoritative.
Read CONTRIBUTING.md. Good first issues are labelled
good-first-issue. Changes are recorded in CHANGELOG.md. Every PR must pass cargo fmt --check, cargo clippy -D warnings, and cargo test --all.
Unaudited. Testnet only. Do not use with real funds. See SECURITY.md.
| Name | Role | Contact |
|---|---|---|
| Victor Adeleke | Lead maintainer | @titilope12 |
Apache-2.0. See LICENSE.