Allowance vaults
How Orbit bills on a schedule without ever holding the subscriber's funds.
An allowance vault is made of two pieces of onchain state that work together:
| Piece | Lives in | Set by | Controls |
|---|---|---|---|
| Token allowance | The token's SAC | Subscriber, via approve | How much Orbit can move in total, and until which ledger |
VaultData | Orbit contract storage | Subscriber, via create_vault | How often the merchant can pull, and how much per pull |
Tokens only move when both agree.
Lifecycle
Pull eligibility
A pull succeeds only when all of these hold:
now >= last_pull + interval_seconds OR last_pull = 0amount_per_interval <= allowance(user, orbit) AND amount_per_interval <= balance(user)The first condition is checked by Orbit. The second is enforced by the token contract inside transfer_from.
Storage
#[contracttype]
pub struct VaultKey {
pub user: Address,
pub merchant: Address,
}
#[contracttype]
pub struct VaultData {
pub token: Address,
pub amount_per_interval: i128,
pub interval_seconds: u64,
pub last_pull_timestamp: u64,
}- There is one vault per
(user, merchant)pair, stored in persistent storage. - A subscriber can hold vaults with any number of merchants, each with its own terms.
- Calling
create_vaultagain for the same pair overwrites the terms and setslast_pull_timestampback to0.
Sizing the allowance
Approve amount_per_interval x cycles and choose a live_until_ledger that covers them:
cycles = 12
amount = 290000000 # 29 USDC
allowance = 3480000000 # 348 USDC
ledgers per cycle ~ 2592000 / 5 = 518400A short allowance that you top up on renewal gives subscribers more control than one large, long-lived allowance. The dashboard can prompt for re-approval when the allowance is about to run out.
Cancelling
Subscribers have two ways to cancel a subscription, operating at different levels:
-
Revoke the token allowance (on the token): Setting the allowance to
0stops transfers immediately. The vault remains stored in Orbit, but any attempt by the merchant to callpull_fundsfails inside the SAC.stellar contract invoke --id $TOKEN --source subscriber --network testnet -- \ approve --from $SUBSCRIBER --spender $ORBIT --amount 0 --live_until_ledger 0 -
Delete the vault (on Orbit): Calling
cancel_vaultremoves the(user, merchant)record from Orbit's persistent storage and emits avault_cancelledevent. Any subsequentpull_fundscall fails with"Vault does not exist". However, this leaves the token allowance in place.stellar contract invoke --id $ORBIT --source subscriber --network testnet -- \ cancel_vault --user $SUBSCRIBER --merchant $MERCHANT
Recommended: Do both for a clean exit. Call cancel_vault to remove the vault agreement on Orbit, and revoke the allowance (set amount to 0) on the token so Orbit can no longer draw funds.