OrbitDocs

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

userAddressrequired

The subscriber. Must sign. This is the account tokens are pulled from.

merchantAddressrequired

The only address that can call pull_funds on this vault.

tokenAddressrequired

SEP-41 token contract, for example the USDC SAC.

amount_per_intervali128required

Raw units pulled each cycle. 290000000 = 29 USDC. Must be greater than zero.

interval_secondsu64required

Minimum ledger-time gap between pulls. Must be greater than zero.

Effects

  1. Writes VaultData { token, amount_per_interval, interval_seconds, last_pull_timestamp: 0 } under VaultKey { user, merchant } in persistent storage.
  2. 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.

MessageCauseFix
amount_per_interval must be positiveamount_per_interval <= 0Pass an amount greater than zero, in raw token units
interval_seconds must be greater than zerointerval_seconds == 0Pass 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 2592000

Calling this again for an existing pair resets last_pull_timestamp to 0, which lets the merchant pull again immediately.

On this page