Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions contracts/escrow/src/amount_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
use soroban_sdk::contracterror;

/// Maximum number of decimal places for stroop precision (7 decimal places for Stellar)
#[allow(dead_code)] // available for callers; not used internally
pub const STROOP_PRECISION: u8 = 7;

/// Maximum individual amount allowed per operation to prevent overflow
#[allow(dead_code)] // available for callers; not used internally
pub const MAX_SINGLE_AMOUNT_STROOPS: i128 = 1_000_000_0000000; // 1M tokens

/// Minimum positive amount (1 stroop)
#[allow(dead_code)] // available for callers; not used internally
pub const MIN_POSITIVE_AMOUNT: i128 = 1;

#[contracterror]
Expand All @@ -37,6 +40,7 @@ pub enum AmountValidationError {
///
/// # Returns
/// `Ok(())` if valid, `Err(AmountValidationError)` if invalid
#[allow(dead_code)] // available for callers; not used by the contract directly
pub fn validate_single_amount(amount: i128) -> Result<(), AmountValidationError> {
// Check positivity
if amount <= MIN_POSITIVE_AMOUNT - 1 {
Expand All @@ -62,6 +66,7 @@ pub fn validate_single_amount(amount: i128) -> Result<(), AmountValidationError>
///
/// # Returns
/// `Ok(total)` with sum of all amounts if valid, `Err(AmountValidationError)` if invalid
#[allow(dead_code)] // available for callers; not used by the contract directly
pub fn validate_amount_array(amounts: &[i128]) -> Result<i128, AmountValidationError> {
let mut total: i128 = 0;

Expand All @@ -88,6 +93,7 @@ pub fn validate_amount_array(amounts: &[i128]) -> Result<i128, AmountValidationE
///
/// # Returns
/// `Ok(())` if valid, `Err(AmountValidationError)` if invalid
#[allow(dead_code)] // available for callers; not used by the contract directly
pub fn validate_contract_total(
total_amount: i128,
max_contract_total: i128,
Expand All @@ -106,6 +112,7 @@ pub fn validate_contract_total(
///
/// # Returns
/// `Ok(total)` with sum of all milestones if valid, `Err(AmountValidationError)` if invalid
#[allow(dead_code)] // available for callers; not used by the contract directly
pub fn validate_milestone_amounts(
milestone_amounts: &[i128],
max_contract_total: i128,
Expand All @@ -128,6 +135,7 @@ pub fn validate_milestone_amounts(
///
/// # Returns
/// `Ok(())` if valid, `Err(AmountValidationError)` if invalid
#[allow(dead_code)] // available for callers; not used by the contract directly
pub fn validate_deposit_amount(
deposit_amount: i128,
current_deposited: i128,
Expand Down
8 changes: 4 additions & 4 deletions contracts/escrow/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#![no_std]
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(clippy::derivable_impls)]
#![allow(clippy::manual_range_contains)]
#![allow(clippy::assertions_on_constants)]
Expand Down Expand Up @@ -140,6 +137,7 @@ impl Escrow {
}

/// Panics with `UnauthorizedRole` if `caller` is not the stored admin.
#[allow(dead_code)] // retained for future admin-gated operations
fn require_admin(env: &Env, caller: &Address) {
let admin: Address = env
.storage()
Expand Down Expand Up @@ -178,7 +176,7 @@ impl Escrow {
/// Validate the core accounting invariant:
/// total_deposited == released_amount + refunded_amount + available_balance
/// Panics with `AccountingInvariantViolated` if the invariant is broken.
fn check_accounting_invariant(env: &Env, contract: &EscrowContractData, contract_id: u32) {
fn check_accounting_invariant(env: &Env, contract: &EscrowContractData, _contract_id: u32) {
let available_balance =
contract.total_deposited - contract.released_amount - contract.refunded_amount;
if available_balance < 0 {
Expand Down Expand Up @@ -719,6 +717,8 @@ impl Escrow {
}
}

#[cfg(test)]
mod proptest;
#[cfg(test)]
mod simple_amount_test;

Expand Down
Loading
Loading