Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/onchain/contracts/aid_escrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ pub struct Config {
pub min_amount: i128,
pub max_expires_in: u64,
pub allowed_tokens: Vec<Address>,
/// Maximum number of packages allowed in a single batch_create_packages call.
/// 0 means unlimited.
pub max_batch_size: u32,
}

#[contracttype]
Expand Down Expand Up @@ -108,6 +111,9 @@ pub enum Error {
TokenTransferFailed = 18,
// Merkle allowlist root has expired (merkle_root_expires_at <= now)
AllowlistExpired = 19,
/// Batch request exceeds the configured per-call ceiling.
/// Carries (requested, max).
BatchTooLarge = 20,
}

// --- Contract Events (indexer-friendly; stable topics & payloads) ---
Expand Down Expand Up @@ -235,6 +241,7 @@ impl AidEscrow {
min_amount: 1,
max_expires_in: 0,
allowed_tokens: Vec::new(&env),
max_batch_size: 0,
};
env.storage().instance().set(&KEY_CONFIG, &config);
Ok(())
Expand Down Expand Up @@ -642,6 +649,11 @@ impl AidEscrow {
return Err(Error::MismatchedArrays);
}

// Guard against oversized batches
if config.max_batch_size > 0 && recipients.len() > config.max_batch_size {
return Err(Error::BatchTooLarge);
}

if !config.allowed_tokens.is_empty() && !config.allowed_tokens.contains(token.clone()) {
return Err(Error::InvalidState);
}
Expand Down