OrbitDocs

batch_disburse

Pay many recipients from one sender in a single atomic invocation.

Edit this page on GitHub
pub fn batch_disburse(env: Env, sender: Address, token: Address, splits: Vec<PaymentSplit>)

Auth: sender.require_auth()

Parameters

senderAddressrequired

The treasury paying out. Must sign and must have approved Orbit for at least the sum of all splits.

tokenAddressrequired

SEP-41 token to pay in.

splitsVec<PaymentSplit>required

Ordered list of { recipient: Address, amount: i128 }. Amounts are raw units.

Execution

sender.require_auth();

assert!(!splits.is_empty(), "splits must not be empty");

for split in splits.iter() {
    assert!(split.amount > 0, "split amount must be positive");
}

let token_client = token::Client::new(&env, &token);
let recipient_count = splits.len();
let mut total_amount: i128 = 0;

for split in splits.into_iter() {
    total_amount = total_amount
        .checked_add(split.amount)
        .expect("Total amount overflow");

    token_client.transfer_from(
        &env.current_contract_address(),
        &sender,
        &split.recipient,
        &split.amount,
    );
}

env.events().publish(
    (Symbol::new(&env, "batch_disbursed"), sender),
    (token, recipient_count, total_amount),
);

Validation

Input validation runs before any transfer is executed. Every split amount is checked upfront, so an invalid split anywhere in the list causes the entire transaction to revert before any tokens move:

MessageCauseFix
splits must not be emptysplits has no entriesProvide at least one recipient and amount
split amount must be positiveAny split has amount <= 0Pass an amount greater than zero, in raw token units
Total amount overflowThe sum of split amounts overflows i128Keep the total batch payout within i128::MAX

See contract errors for the full list of errors and simulation instructions.

Properties

  • Atomic: a failure on split k reverts splits 0..k.
  • Stateless: writes nothing to Orbit storage.
  • Bounded by resources, not by a constant: large batches can go over the transaction's CPU or ledger-write budget. Simulate first, and split the batch if needed.

Example

stellar contract invoke --id $ORBIT --source treasury --network testnet -- \
  batch_disburse --sender $TREASURY --token $TOKEN \
  --splits '[{"recipient":"'$A'","amount":"100000000"},{"recipient":"'$B'","amount":"50000000"}]'

On this page