create_vault
Record billing terms for a (user, merchant) pair. Moves no funds.
pub fn create_vault(
env: Env,
user: Address,
merchant: Address,
token: Address,
amount_per_interval: i128,
interval_seconds: u64,
)Auth: user.require_auth()
Parameters
The subscriber. Must sign. This is the account tokens are pulled from.
The only address that can call pull_funds on this vault.
SEP-41 token contract, for example the USDC SAC.
Raw units pulled each cycle. 290000000 = 29 USDC. Must be greater than zero.
Minimum ledger-time gap between pulls. Must be greater than zero.
Effects
- Writes
VaultData { token, amount_per_interval, interval_seconds, last_pull_timestamp: 0 }underVaultKey { user, merchant }in persistent storage. - Overwrites any vault that already exists for the same pair.
Errors
Both checks run after user.require_auth() and before anything is written, so a rejected call leaves any existing vault untouched.
| Message | Cause | Fix |
|---|---|---|
amount_per_interval must be positive | amount_per_interval <= 0 | Pass an amount greater than zero, in raw token units |
interval_seconds must be greater than zero | interval_seconds == 0 | Pass an interval of at least 1 second |
See contract errors for the full list and how to catch them in simulation.
Preconditions for later pulls
create_vault does not check the allowance. It succeeds even without an allowance, but every pull will fail until the user calls approve on the token with Orbit as the spender.
Example
stellar contract invoke --id $ORBIT --source subscriber --network testnet -- \
create_vault \
--user $SUBSCRIBER --merchant $MERCHANT --token $TOKEN \
--amount_per_interval 290000000 --interval_seconds 2592000Calling this again for an existing pair resets last_pull_timestamp to 0, which lets the merchant pull again immediately.