From 02bcb6135249e130270ba312bb434fdb80cccb2a Mon Sep 17 00:00:00 2001 From: Kaybee973 Date: Wed, 25 Nov 2026 13:41:00 +0000 Subject: [PATCH 1/6] fix: remove duplicated payout_platform_fee definition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous commit on main defined payout_platform_fee twice in helpers/payout.rs, so the escrow lib did not compile (E0428) and no test suite could run. Drop the byte-identical second copy. 🤖 Generated with Codebuff Co-Authored-By: Codebuff --- contracts/escrow/src/helpers/payout.rs | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/contracts/escrow/src/helpers/payout.rs b/contracts/escrow/src/helpers/payout.rs index 26cd6954..030a10d9 100644 --- a/contracts/escrow/src/helpers/payout.rs +++ b/contracts/escrow/src/helpers/payout.rs @@ -233,29 +233,6 @@ pub(crate) fn payout_platform_fee( ); } -/// Transfers a platform fee to `treasury` and publishes the matching -/// `PlatformFeeCollected` telemetry event. A fee that rounds down to zero is -/// not disbursed and therefore produces no event. -pub(crate) fn payout_platform_fee( - env: &Env, - escrow_id: u64, - token_addr: &Address, - treasury: &Address, - fee_amount: i128, -) { - if fee_amount <= 0 { - return; - } - payout(env, token_addr, treasury, fee_amount); - crate::events::emit_platform_fee_collected( - env, - escrow_id, - token_addr.clone(), - treasury.clone(), - fee_amount, - ); -} - /// Transfers `amount` of `token_addr` from this contract to `recipient`. /// /// This is the single choke point every payout path shares — protocol and From e9a29cd5824d28a216c85ac011f0f75f9ec4cbdb Mon Sep 17 00:00:00 2001 From: Kaybee973 Date: Wed, 25 Nov 2026 13:41:00 +0000 Subject: [PATCH 2/6] fix: validate queued fee collector and treasury addresses (#1242) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit queue_set_fee_collector and queue_set_treasury hashed whatever address they were given into the timelock proposal, so a zero, contract, or admin address could be queued and, once executed, route protocol fees to a black hole or collapse the admin/collector role split. Run the existing fee-collector/treasury invariant helpers on the queue path and extend both helpers to reject env.current_contract_address() with InvalidAddress. execute_set_* already call these helpers, so queue time and execution time now enforce the same rules. Adds regression tests in test_admin.rs covering zero, contract, and admin targets for both queued updates, plus the shared execution-time helper. 🤖 Generated with Codebuff Co-Authored-By: Codebuff --- contracts/escrow/src/admin.rs | 8 ++++ contracts/escrow/src/internal.rs | 13 ++++++ contracts/escrow/src/test_admin.rs | 74 ++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) diff --git a/contracts/escrow/src/admin.rs b/contracts/escrow/src/admin.rs index 5a0d9f04..41d4e360 100644 --- a/contracts/escrow/src/admin.rs +++ b/contracts/escrow/src/admin.rs @@ -1204,6 +1204,10 @@ impl Escrow { caller: Address, treasury: Address, ) -> Result<(), ContractError> { + // Validate before hashing so an unusable treasury can never enter the + // timelock queue and only fail once the proposal is already executable. + validate_treasury_change(&env, &treasury)?; + let mut params = Vec::new(&env); params.push_back(treasury.into_val(&env)); queue_timelock_op(&env, &caller, TimelockOperation::SetTreasury as u32, params) @@ -1238,6 +1242,10 @@ impl Escrow { caller: Address, new_collector: Address, ) -> Result<(), ContractError> { + // Validate before hashing so an unusable collector can never enter the + // timelock queue and only fail once the proposal is already executable. + validate_fee_collector_change(&env, &new_collector)?; + let mut params = Vec::new(&env); params.push_back(new_collector.into_val(&env)); queue_timelock_op( diff --git a/contracts/escrow/src/internal.rs b/contracts/escrow/src/internal.rs index 8bd285ff..c8ae34eb 100644 --- a/contracts/escrow/src/internal.rs +++ b/contracts/escrow/src/internal.rs @@ -523,6 +523,8 @@ pub(crate) fn validate_total_fee_bps( /// collector, so the immediate (`set_fee_collector`) and timelocked /// (`execute_set_fee_collector`) update paths cannot drift from them: /// - it may not be the all-zero address (`InvalidAddress`); +/// - it may not be the contract's own address (`InvalidAddress`) — fees sent +/// to the contract are stranded there and cannot be swept by an operator; /// - it may not equal the current admin (`InvalidAddress`) — the admin and /// fee-collector roles are kept separate so a single compromised key /// cannot both govern the contract and sweep its fees; @@ -538,6 +540,10 @@ pub(crate) fn validate_fee_collector_change( return Err(ContractError::InvalidAddress); } + if *new_collector == env.current_contract_address() { + return Err(ContractError::InvalidAddress); + } + let admin = require_admin(env)?; if *new_collector == admin { return Err(ContractError::InvalidAddress); @@ -560,6 +566,9 @@ pub(crate) fn validate_fee_collector_change( /// receives platform fees and therefore must not be changed by a typo or an /// accidental admin input. The active treasury is kept unchanged until the new /// address explicitly calls `accept_treasury`. +/// +/// Rejects the all-zero address, the contract's own address, and the current +/// admin, all with `InvalidAddress`; a no-op change is `SameAddress`. pub(crate) fn validate_treasury_change( env: &Env, new_treasury: &Address, @@ -568,6 +577,10 @@ pub(crate) fn validate_treasury_change( return Err(ContractError::InvalidAddress); } + if *new_treasury == env.current_contract_address() { + return Err(ContractError::InvalidAddress); + } + let admin = require_admin(env)?; if *new_treasury == admin { return Err(ContractError::InvalidAddress); diff --git a/contracts/escrow/src/test_admin.rs b/contracts/escrow/src/test_admin.rs index 9070854e..46e47935 100644 --- a/contracts/escrow/src/test_admin.rs +++ b/contracts/escrow/src/test_admin.rs @@ -715,3 +715,77 @@ mod timelock { assert_eq!(client.get_platform_fee_bps(), 25); } } + +/// Issue #1242: a fee collector that is the zero address, the contract itself, +/// or the admin would route fees to a black hole or collapse the role split. +/// The queue path must reject it before the address is hashed into a proposal. +#[test] +fn queue_set_fee_collector_rejects_zero_contract_and_admin_addresses() { + use crate::TimelockOperation; + + let env = Env::default(); + env.mock_all_auths(); + let (contract_id, client, admin, _fee_collector) = setup_contract(&env); + + for target in [ + crate::zero_address(&env), + contract_id.clone(), + admin.clone(), + ] { + assert_eq!( + client.try_queue_set_fee_collector(&admin, &target), + Err(Ok(ContractError::InvalidAddress)), + ); + } + + // A rejected proposal must never be written to timelock storage. + env.as_contract(&contract_id, || { + assert!(crate::storage::read_timelock_proposal( + &env, + TimelockOperation::SetFeeCollector as u32 + ) + .is_none()); + }); + + // The execute path re-verifies through the same invariant helper. + env.as_contract(&contract_id, || { + assert_eq!( + crate::internal::validate_fee_collector_change(&env, &contract_id), + Err(ContractError::InvalidAddress), + ); + }); +} + +/// Issue #1242: the treasury receives platform fees, so the same invariants +/// apply to the queued treasury update. +#[test] +fn queue_set_treasury_rejects_zero_contract_and_admin_addresses() { + use crate::TimelockOperation; + + let env = Env::default(); + env.mock_all_auths(); + let (contract_id, client, admin, _fee_collector) = setup_contract(&env); + + for target in [ + crate::zero_address(&env), + contract_id.clone(), + admin.clone(), + ] { + assert_eq!( + client.try_queue_set_treasury(&admin, &target), + Err(Ok(ContractError::InvalidAddress)), + ); + } + + env.as_contract(&contract_id, || { + assert!(crate::storage::read_timelock_proposal( + &env, + TimelockOperation::SetTreasury as u32 + ) + .is_none()); + assert_eq!( + crate::internal::validate_treasury_change(&env, &contract_id), + Err(ContractError::InvalidAddress), + ); + }); +} From 91d877734a383b5e1fb7a9c789303c2427421caa Mon Sep 17 00:00:00 2001 From: Kaybee973 Date: Wed, 25 Nov 2026 13:41:00 +0000 Subject: [PATCH 3/6] fix: pin schema version and topic shape of timelock events (#1244) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TimelockQueued, TimelockExecuted, and TimelockCancelled already stamp EVENT_SCHEMA_VERSION, but nothing pinned that contract for indexers, and the emitter doc comments advertised a third `operation as u32` topic that is never published. Align the doc comments with the two-symbol tuples that are actually emitted, keep EVENTS.md in sync, and add a regression test that decodes the emitted TimelockQueued/Executed/Cancelled payloads, asserts schema_version == EVENT_SCHEMA_VERSION, checks the topic tuple shape, and round-trips each payload through XDR. 🤖 Generated with Codebuff Co-Authored-By: Codebuff --- EVENTS.md | 2 +- contracts/escrow/src/events.rs | 6 +- .../escrow/src/test_admin_event_emissions.rs | 119 ++++++++++++++++++ 3 files changed, 123 insertions(+), 4 deletions(-) diff --git a/EVENTS.md b/EVENTS.md index ff0cb3bd..bd456f1d 100644 --- a/EVENTS.md +++ b/EVENTS.md @@ -134,7 +134,7 @@ The tables below list all 61 event topics. The `Payload fields` column is the ex | `RecoveryWithdraw` | `(symbol_short!("Recovery"), symbol_short!("Withdraw"))` | `schema_version: u32`
`escrow_id: u64`
`buyer: Address`
`amount: i128`
`timestamp: u64` | Recovery-mode withdrawal to the buyer. | | `RecoveryModeUpdated` | `(symbol_short!("Recovery"), symbol_short!("ModeUpd"))` | `schema_version: u32`
`enabled: bool`
`caller: Address`
`timestamp: u64` | Recovery mode enabled or disabled. | -> Note: the source doc comments on the three `Timelock*` emitters mention an `operation as u32` topic. The actual `publish` calls use only the two-symbol tuples shown above; `operation` is a payload field, not a topic. This table documents the emitted reality. +> Note: the three `Timelock*` emitters publish only the two-symbol tuples shown above; `operation` is a payload field, not a topic. `test_admin_event_emissions::timelock_events_stamp_current_schema_version_and_standard_topics` pins this shape. ## Example XDR payloads diff --git a/contracts/escrow/src/events.rs b/contracts/escrow/src/events.rs index 53fec97e..b30ad507 100644 --- a/contracts/escrow/src/events.rs +++ b/contracts/escrow/src/events.rs @@ -1677,7 +1677,7 @@ pub struct TimelockQueued { pub ready_at: u64, } -/// Topic: `(symbol_short!("Timelock"), symbol_short!("Queued"), operation as u32,)`, data: `TimelockQueued`. +/// Topic: `(symbol_short!("Timelock"), symbol_short!("Queued"))`, data: `TimelockQueued`. pub fn emit_timelock_queued( env: &Env, operation: u32, @@ -1708,7 +1708,7 @@ pub struct TimelockExecuted { pub executed_at: u64, } -/// Topic: `(symbol_short!("Timelock"), symbol_short!("Executed"), operation as u32,)`, data: `TimelockExecuted`. +/// Topic: `(symbol_short!("Timelock"), symbol_short!("Executed"))`, data: `TimelockExecuted`. pub fn emit_timelock_executed( env: &Env, operation: u32, @@ -1739,7 +1739,7 @@ pub struct TimelockCancelled { pub cancelled_at: u64, } -/// Topic: `(symbol_short!("Timelock"), symbol_short!("Cancelled"), operation as u32,)`, data: `TimelockCancelled`. +/// Topic: `(symbol_short!("Timelock"), symbol_short!("Cancelled"))`, data: `TimelockCancelled`. pub fn emit_timelock_cancelled(env: &Env, operation: u32, proposer: Address, canceller: Address) { env.events().publish( (symbol_short!("Timelock"), symbol_short!("Cancelled")), diff --git a/contracts/escrow/src/test_admin_event_emissions.rs b/contracts/escrow/src/test_admin_event_emissions.rs index ec316060..c3b9202c 100644 --- a/contracts/escrow/src/test_admin_event_emissions.rs +++ b/contracts/escrow/src/test_admin_event_emissions.rs @@ -80,6 +80,33 @@ where }) } +/// Decodes the payload of the first contract event published under the +/// `(Timelock, topic2)` topic tuple into `T`. +fn timelock_payload(env: &Env, contract_id: &Address, topic2: Symbol) -> Option +where + T: TryFromVal, +{ + env.events() + .all() + .filter_by_contract(contract_id) + .events() + .iter() + .find_map(|event| { + let soroban_sdk::xdr::ContractEventBody::V0(v0) = &event.body; + let mut topics = v0.topics.iter(); + let topic1 = topics.next()?; + let found_topic2 = topics.next()?; + if Symbol::try_from_val(env, topic1).ok()? != symbol_short!("Timelock") { + return None; + } + if Symbol::try_from_val(env, found_topic2).ok()? != topic2 { + return None; + } + let data = Val::try_from_val(env, &v0.data).ok()?; + T::try_from_val(env, &data).ok() + }) +} + #[test] fn set_ttl_extension_emits_event_with_caller_and_new_value() { let (env, client, contract_id, admin) = setup(); @@ -1265,3 +1292,95 @@ mod golden_xdr { "ee3d75ef0ad9d3aaaa8e15c26b4b81c89d02896deb5d2f9356541dbdc613a95b" ); } + +/// Asserts the topic shape of every timelock event in the current event +/// buffer: exactly `(symbol_short!("Timelock"), kind)` with `kind` from the +/// three documented values. Soroban tops out at 10-character symbols, and +/// indexers decode by this two-symbol tuple. +fn assert_timelock_topic_shape(env: &Env, contract_id: &Address, expected: &[Symbol]) { + let all = env.events().all(); + let mut found = 0_usize; + for event in all.filter_by_contract(contract_id).events().iter() { + let soroban_sdk::xdr::ContractEventBody::V0(v0) = &event.body; + let mut topics = v0.topics.iter(); + let Some(topic1) = topics.next() else { + continue; + }; + let Ok(sym1) = Symbol::try_from_val(env, topic1) else { + continue; + }; + if sym1 != symbol_short!("Timelock") { + continue; + } + found += 1; + + let topic2 = topics.next().expect("timelock event has a second topic"); + assert!( + topics.next().is_none(), + "timelock topics must be a two-symbol tuple" + ); + let sym2 = Symbol::try_from_val(env, topic2).expect("topic decodes as Symbol"); + assert!( + sym2 == symbol_short!("Queued") + || sym2 == symbol_short!("Executed") + || sym2 == symbol_short!("Cancelled"), + "unexpected timelock topic" + ); + assert!( + expected.contains(&sym2), + "unexpected timelock event kind for this call" + ); + } + assert_eq!(found, expected.len(), "unexpected timelock event count"); +} + +/// Issue #1244: indexers key off `schema_version` in timelock payloads. Every +/// timelock event emitted by the contract must stamp the current +/// `EVENT_SCHEMA_VERSION` and survive an XDR round-trip in that shape. +#[test] +fn timelock_events_stamp_current_schema_version_and_standard_topics() { + use crate::{TimelockCancelled, EVENT_SCHEMA_VERSION}; + use soroban_sdk::xdr::{FromXdr, ToXdr}; + + let (env, client, contract_id, admin) = setup(); + + client.queue_set_platform_fee(&admin, &50_u32); + assert_timelock_topic_shape(&env, &contract_id, &[symbol_short!("Queued")]); + let queued = timelock_payload::(&env, &contract_id, symbol_short!("Queued")) + .expect("TimelockQueued decodes from its emitted payload"); + assert_eq!(queued.schema_version, EVENT_SCHEMA_VERSION); + assert_eq!(queued.operation, TimelockOperation::SetPlatformFee as u32); + let queued_bytes = queued.clone().to_xdr(&env); + assert_eq!( + TimelockQueued::from_xdr(&env, &queued_bytes).expect("TimelockQueued XDR round-trip"), + queued + ); + + env.ledger() + .with_mut(|li| li.timestamp += crate::admin::ADMIN_TIMELOCK_DELAY_SECONDS); + client.execute_set_platform_fee(&admin, &50_u32); + assert_timelock_topic_shape(&env, &contract_id, &[symbol_short!("Executed")]); + let executed = + timelock_payload::(&env, &contract_id, symbol_short!("Executed")) + .expect("TimelockExecuted decodes from its emitted payload"); + assert_eq!(executed.schema_version, EVENT_SCHEMA_VERSION); + let executed_bytes = executed.clone().to_xdr(&env); + assert_eq!( + TimelockExecuted::from_xdr(&env, &executed_bytes).expect("TimelockExecuted XDR round-trip"), + executed + ); + + client.queue_set_ttl_extension(&admin, &2_000_u32); + client.cancel_timelock_op(&admin, &(TimelockOperation::SetTtlExtension as u32)); + assert_timelock_topic_shape(&env, &contract_id, &[symbol_short!("Cancelled")]); + let cancelled = + timelock_payload::(&env, &contract_id, symbol_short!("Cancelled")) + .expect("TimelockCancelled decodes from its emitted payload"); + assert_eq!(cancelled.schema_version, EVENT_SCHEMA_VERSION); + let cancelled_bytes = cancelled.clone().to_xdr(&env); + assert_eq!( + TimelockCancelled::from_xdr(&env, &cancelled_bytes) + .expect("TimelockCancelled XDR round-trip"), + cancelled + ); +} From 34fa374bc5f42133f1ca1261ae351b09e31e6863 Mon Sep 17 00:00:00 2001 From: Kaybee973 Date: Sat, 28 Nov 2026 15:45:56 +0000 Subject: [PATCH 4/6] fix: restore green CI for the timelock invariant branch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the stale duplicate `dispute_state_machine` module and dead helpers, fix the clippy/rustfmt drift, and resync the TypeScript error codes with `errors.rs` so the check, bindings and error-code jobs agree. 🤖 Generated with Codebuff Co-Authored-By: Codebuff --- ERROR_CODES.md | 4 +- bindings/src/errors.ts | 8 +- contracts/escrow/src/admin.rs | 27 +-- contracts/escrow/src/dispute_state_machine.rs | 219 ------------------ contracts/escrow/src/disputes.rs | 39 ++-- contracts/escrow/src/events.rs | 6 +- contracts/escrow/src/helpers/payout.rs | 8 +- contracts/escrow/src/internal.rs | 67 +----- contracts/escrow/src/lib.rs | 1 - .../src/test_fee_calculation_accuracy.rs | 3 +- contracts/escrow/src/test_not_found.rs | 2 +- 11 files changed, 40 insertions(+), 344 deletions(-) delete mode 100644 contracts/escrow/src/dispute_state_machine.rs diff --git a/ERROR_CODES.md b/ERROR_CODES.md index 22e0b149..671dd94e 100644 --- a/ERROR_CODES.md +++ b/ERROR_CODES.md @@ -86,4 +86,6 @@ This document provides a comprehensive reference of all `ContractError` variants | **78** | `InvalidWasmHash` | `execute_upgrade` was called with an all-zero or otherwise invalid WASM hash. | Supply the valid WASM hash of the new contract build. | | **79** | `NoPendingTreasury` | `accept_treasury` was called but no pending treasury is set. | The admin must call `set_treasury` first to register a pending treasury. | | **80** | `DuplicateResolver` | The same address appears more than once in a resolver configuration. Two triggers share this code (both in `validate_resolvers`, `contracts/escrow/src/internal.rs`): (1) **duplicate multi-resolver** — an address is repeated in a `ResolverSet::Multi` list; (2) **fallback equality** — `primary_resolver == backup_resolver` in a `ResolverSet::Fallback`. Kept distinct from `ConflictingRoles` (23), which means a resolver also holds the Seller or Buyer role. | Ensure every multi-resolver address is unique and that a fallback escrow's primary and backup resolvers are different accounts. | -| **81** | `EvidenceLimitReached` | `submit_dispute_evidence` was called but the escrow's evidence log already holds `MAX_EVIDENCE_ENTRIES` (5) entries. | No further evidence can be added; rely on the entries already logged. | +| **81** | `DirectUnpauseBlocked` | `unpause_contract` was called directly while `GLOBAL_CONFIG_FLAG_TIMELOCKED_UNPAUSE_ONLY` is set. | Use `queue_unpause_contract` then `execute_unpause_contract` instead of unpausing directly. | +| **82** | `InvalidSplitBps` | A `ResolutionType::Split(bps)` resolution carries a payee share greater than `BASIS_POINTS` (`10_000`). | Supply a split share at or below 10,000 basis points. | +| **83** | `EvidenceLimitReached` | `submit_dispute_evidence` was called but the escrow's evidence log already holds `MAX_EVIDENCE_ENTRIES` (5) entries. | No further evidence can be added; rely on the entries already logged. | diff --git a/bindings/src/errors.ts b/bindings/src/errors.ts index d3dd074a..d4ddaf0d 100644 --- a/bindings/src/errors.ts +++ b/bindings/src/errors.ts @@ -88,7 +88,9 @@ export const enum ErrorCode { InvalidWasmHash = 78, NoPendingTreasury = 79, DuplicateResolver = 80, - EvidenceLimitReached = 81, + DirectUnpauseBlocked = 81, + InvalidSplitBps = 82, + EvidenceLimitReached = 83, } /** Human-readable message for every contract error code. */ @@ -237,6 +239,10 @@ export const ERROR_MESSAGES: Readonly> = { "No pending treasury is set for accept_treasury.", [ErrorCode.DuplicateResolver]: "The same address appears more than once in the resolver configuration.", + [ErrorCode.DirectUnpauseBlocked]: + "Direct unpause is blocked while timelocked unpause is required; queue and execute it instead.", + [ErrorCode.InvalidSplitBps]: + "The split resolution's payee share exceeds the maximum of 10,000 basis points.", [ErrorCode.EvidenceLimitReached]: "The escrow's dispute evidence log has reached its maximum number of entries.", }; diff --git a/contracts/escrow/src/admin.rs b/contracts/escrow/src/admin.rs index 41d4e360..07ccb486 100644 --- a/contracts/escrow/src/admin.rs +++ b/contracts/escrow/src/admin.rs @@ -187,29 +187,6 @@ fn clear_all_timelock_proposals(env: &Env, canceller: &Address) { } } -/// Cancel all outstanding proposals when the admin changes. A rejected -/// execution cannot do this itself: Soroban rolls back state and events on error. -fn invalidate_timelocks_on_rotation(env: &Env) { - // TimelockOperation discriminants are append-only; update the upper bound - // when a new operation is added. - for operation in 1..=(TimelockOperation::SetTimelockDelay as u32) { - if let Some(proposal) = storage::read_timelock_proposal(env, operation) { - storage::remove_timelock_proposal(env, operation); - env.storage() - .instance() - .set(&DataKey::InvalidatedTimelockOp(operation), &true); - // Cancellation is automatic, not an action signed by the new admin. - emit_timelock_cancelled( - env, - operation, - proposal.proposer.clone(), - env.current_contract_address(), - ); - emit_timelock_admin_mismatch(env, operation, proposal.proposer); - } - } -} - #[cfg(test)] mod tests { use super::*; @@ -1095,9 +1072,7 @@ impl Escrow { .persistent() .get(&DataKey::UpgradeHistory) .unwrap_or_else(|| soroban_sdk::Vec::new(&env)); - let next_version = u32::try_from(history.len()) - .unwrap_or(u32::MAX) - .saturating_add(1); + let next_version = history.len().saturating_add(1); history.push_back(crate::types::UpgradeRecord { wasm_hash: new_wasm_hash.clone(), upgraded_at: env.ledger().timestamp(), diff --git a/contracts/escrow/src/dispute_state_machine.rs b/contracts/escrow/src/dispute_state_machine.rs deleted file mode 100644 index 5d0a19ba..00000000 --- a/contracts/escrow/src/dispute_state_machine.rs +++ /dev/null @@ -1,219 +0,0 @@ -//! Internal dispute voting and state-transition logic. - -use crate::internal::{ - load_dispute, load_resolver_votes, save_dispute, save_escrow, save_resolver_votes, -}; -use crate::*; -use soroban_sdk::{Address, Env, Vec}; - -pub(crate) fn add_or_update_vote( - env: &Env, - escrow_id: u64, - resolver: &Address, - resolution: ResolutionType, -) -> Vec { - let mut votes = load_resolver_votes(env, escrow_id); - let current_time = env.ledger().timestamp(); - let mut found = false; - for i in 0..votes.len() { - if let Some(vote) = votes.get(i) { - if vote.resolver == *resolver { - let mut updated = vote.clone(); - updated.resolution = resolution.clone(); - updated.voted_at = current_time; - votes.set(i, updated); - found = true; - break; - } - } - } - if !found { - votes.push_back(ResolverVote { - resolver: resolver.clone(), - resolution, - voted_at: current_time, - }); - } - votes -} - -pub(crate) fn tally_votes( - votes: &Vec, - threshold: u32, -) -> Result, ContractError> { - if votes.is_empty() { - return Ok(None); - } - let mut release_count = 0u32; - let mut refund_count = 0u32; - for i in 0..votes.len() { - if let Some(vote) = votes.get(i) { - match vote.resolution { - ResolutionType::Release => { - release_count = release_count - .checked_add(1) - .ok_or(ContractError::ArithmeticError)?; - } - ResolutionType::Refund => { - refund_count = refund_count - .checked_add(1) - .ok_or(ContractError::ArithmeticError)?; - } - ResolutionType::Split(_) => {} - } - } - } - if release_count >= threshold { - Ok(Some(ResolutionType::Release)) - } else if refund_count >= threshold { - Ok(Some(ResolutionType::Refund)) - } else { - Ok(None) - } -} - -pub(crate) fn tally_votes_majority(votes: &Vec) -> ResolutionType { - let mut release_count = 0u32; - let mut refund_count = 0u32; - for i in 0..votes.len() { - if let Some(vote) = votes.get(i) { - match vote.resolution { - ResolutionType::Release => release_count = release_count.saturating_add(1), - ResolutionType::Refund => refund_count = refund_count.saturating_add(1), - ResolutionType::Split(_) => {} - } - } - } - if release_count > refund_count { - ResolutionType::Release - } else { - ResolutionType::Refund - } -} - -fn winning_resolvers( - env: &Env, - votes: &Vec, - final_resolution: &ResolutionType, - caller: &Address, -) -> Vec
{ - let mut winners = Vec::new(env); - for vote in votes.iter() { - if &vote.resolution == final_resolution && !winners.contains(&vote.resolver) { - winners.push_back(vote.resolver.clone()); - } - } - if winners.is_empty() { - winners.push_back(caller.clone()); - } - winners -} - -pub(crate) fn execute_resolution_transition( - env: &Env, - escrow_id: u64, - escrow: EscrowData, - caller: Address, - final_resolution: ResolutionType, - votes: Vec, - charge_fees: bool, -) -> Result<(), ContractError> { - let mut dispute_data = load_dispute(env, escrow_id)?; - let fees_already_charged = dispute_data.fees_charged; - let (arbitration_fee, resolver_fee) = if fees_already_charged { - (dispute_data.arbitration_fee, dispute_data.resolver_fee) - } else if !charge_fees { - (0, 0) - } else { - let arbitration_fee = - crate::helpers::payout::calculate_fee(escrow.amount, escrow.arbitration_fee_bps)?; - let resolver_fee = - crate::helpers::payout::calculate_fee(escrow.amount, escrow.resolver_fee_bps)?; - let combined_fee = arbitration_fee - .checked_add(resolver_fee) - .ok_or(ContractError::ArithmeticError)?; - if combined_fee > escrow.amount { - return Err(ContractError::FeeExceedsMax); - } - (arbitration_fee, resolver_fee) - }; - - let fee_collector = if fees_already_charged { - None - } else { - Some( - crate::storage::read_global_config(env) - .fee_collector - .ok_or(ContractError::NotInitialized)?, - ) - }; - - let prev_state = escrow.state.clone(); - let mut updated_escrow = escrow; - if !fees_already_charged && charge_fees { - updated_escrow.amount = updated_escrow - .amount - .checked_sub(arbitration_fee) - .ok_or(ContractError::ArithmeticError)? - .checked_sub(resolver_fee) - .ok_or(ContractError::ArithmeticError)?; - let total_key = DataKey::TotalArbitrationFees(updated_escrow.token.clone()); - let current_total: i128 = env.storage().instance().get(&total_key).unwrap_or(0); - env.storage().instance().set( - &total_key, - ¤t_total - .checked_add(arbitration_fee) - .ok_or(ContractError::ArithmeticError)?, - ); - } - - let now = env.ledger().timestamp(); - if now < dispute_data.disputed_at { - return Err(ContractError::TimestampInvariantViolated); - } - let appeal_deadline = now - .checked_add(crate::APPEAL_WINDOW) - .ok_or(ContractError::ArithmeticError)?; - dispute_data.set_resolution(final_resolution.clone()); - dispute_data.resolved_by = Some(caller.clone()); - dispute_data.resolved_at = now; - dispute_data.arbitration_fee = arbitration_fee; - dispute_data.resolver_fee = resolver_fee; - if !fees_already_charged { - dispute_data.compensated_resolvers = - winning_resolvers(env, &votes, &final_resolution, &caller); - } - dispute_data.fees_charged = true; - updated_escrow.state = EscrowState::PendingFinalization; - - save_escrow(env, escrow_id, &updated_escrow, Some(&prev_state)); - save_dispute(env, escrow_id, &dispute_data); - save_resolver_votes(env, escrow_id, &votes); - - if let Some(fee_collector) = fee_collector { - crate::helpers::payout::payout(env, &updated_escrow.token, &fee_collector, arbitration_fee); - if resolver_fee > 0 { - let winners = winning_resolvers(env, &votes, &final_resolution, &caller); - let count = i128::from(winners.len()); - let share = resolver_fee / count; - let dust = resolver_fee - share * count; - for winner in winners.iter() { - crate::helpers::payout::payout(env, &updated_escrow.token, &winner, share); - } - if dust > 0 { - crate::helpers::payout::payout(env, &updated_escrow.token, &caller, dust); - } - } - } - - emit_dispute_pending_finalization( - env, - escrow_id, - caller, - final_resolution, - updated_escrow.amount, - appeal_deadline, - None, - ); - Ok(()) -} diff --git a/contracts/escrow/src/disputes.rs b/contracts/escrow/src/disputes.rs index b60485fa..026305a6 100644 --- a/contracts/escrow/src/disputes.rs +++ b/contracts/escrow/src/disputes.rs @@ -481,7 +481,6 @@ impl Escrow { } } - if let Some(ref treasury_addr) = treasury { crate::helpers::payout::payout_platform_fee( &env, @@ -491,27 +490,23 @@ impl Escrow { platform_fee, ); } - match (&resolution, &buyer_split) { - (ResolutionType::Split(split_bps), Some(buyer)) => { - // payee_net + buyer_net == payout_amount: nothing is stranded. - let (payee_net, buyer_net) = - crate::helpers::payout::split_net(payout_amount, *split_bps)?; - payout(&env, &escrow.token, &recipient, payee_net); - payout(&env, &escrow.token, buyer, buyer_net); - crate::internal::payout_basket_tokens_split( - &env, - escrow_id, - &recipient, - buyer, - *split_bps, - escrow.fee_bps, - )?; - } - _ => { - payout(&env, &escrow.token, &recipient, payout_amount); - payout_basket_tokens(&env, escrow_id, &recipient, Some(escrow.fee_bps))?; - } - + if let (ResolutionType::Split(split_bps), Some(buyer)) = (&resolution, &buyer_split) { + // payee_net + buyer_net == payout_amount: nothing is stranded. + let (payee_net, buyer_net) = + crate::helpers::payout::split_net(payout_amount, *split_bps)?; + payout(&env, &escrow.token, &recipient, payee_net); + payout(&env, &escrow.token, buyer, buyer_net); + crate::internal::payout_basket_tokens_split( + &env, + escrow_id, + &recipient, + buyer, + *split_bps, + escrow.fee_bps, + )?; + } else { + payout(&env, &escrow.token, &recipient, payout_amount); + payout_basket_tokens(&env, escrow_id, &recipient, Some(escrow.fee_bps))?; } emit_dispute_resolved( diff --git a/contracts/escrow/src/events.rs b/contracts/escrow/src/events.rs index b30ad507..985452a2 100644 --- a/contracts/escrow/src/events.rs +++ b/contracts/escrow/src/events.rs @@ -1577,11 +1577,7 @@ pub fn emit_payee_share_skipped( net_pool: i128, ) { env.events().publish( - ( - symbol_short!("Payee"), - symbol_short!("Skip"), - payee.clone(), - ), + (symbol_short!("Payee"), symbol_short!("Skip"), payee.clone()), PayeeShareSkipped { schema_version: EVENT_SCHEMA_VERSION, escrow_id, diff --git a/contracts/escrow/src/helpers/payout.rs b/contracts/escrow/src/helpers/payout.rs index 030a10d9..c6381655 100644 --- a/contracts/escrow/src/helpers/payout.rs +++ b/contracts/escrow/src/helpers/payout.rs @@ -314,9 +314,11 @@ pub struct TransferInstruction { /// the already-reduced `escrow.amount`. This function mirrors that basis so /// that simulation outputs match on-chain settlement exactly: /// -/// fee_basis = escrow.amount + arbitration_fee + resolver_fee -/// protocol_fee = fee_basis * escrow.fee_bps / 10_000 -/// net = escrow.amount - platform_fee - protocol_fee +/// ```text +/// fee_basis = escrow.amount + arbitration_fee + resolver_fee +/// protocol_fee = fee_basis * escrow.fee_bps / 10_000 +/// net = escrow.amount - platform_fee - protocol_fee +/// ``` /// /// The invariant `net + protocol_fee + arbitration_fee + resolver_fee + platform_fee /// == fee_basis` holds by construction. diff --git a/contracts/escrow/src/internal.rs b/contracts/escrow/src/internal.rs index c8ae34eb..dd337edc 100644 --- a/contracts/escrow/src/internal.rs +++ b/contracts/escrow/src/internal.rs @@ -1172,8 +1172,8 @@ pub(crate) fn payout_basket_tokens( if !is_transferable_basket_entry(&entry, primary_token) { continue; } - let (net_amount, fee) = match &fee_context { - Some((fee_bps, platform_fee_bps, fee_collector, treasury)) => { + let (net_amount, fee) = + if let Some((fee_bps, platform_fee_bps, fee_collector, treasury)) = &fee_context { crate::helpers::payout::transfer_basket_with_fees( env, escrow_id, @@ -1185,12 +1185,10 @@ pub(crate) fn payout_basket_tokens( fee_collector, treasury.as_ref(), )? - } - None => { + } else { crate::helpers::payout::payout(env, &entry.token, recipient, entry.amount); (entry.amount, 0) - } - }; + }; crate::events::emit_basket_token_payout( env, escrow_id, @@ -1244,63 +1242,6 @@ pub(crate) fn payout_basket_tokens_split( Ok(()) } -/// Distributes every non-primary basket token across `payees` in proportion to -/// their basis points. -/// -/// This is the multi-payee counterpart to [`payout_basket_tokens`]: instead of -/// sending 100% of each secondary token to one address, it reuses -/// [`distribute_to_payees`] so every payee receives its configured share and -/// any rounding dust is awarded to the primary payee. Used by the release -/// paths (`confirm_delivery`, `auto_release`, `co_signed_release`, and a -/// `Release` dispute resolution); refund paths keep the single-recipient -/// behaviour. -pub(crate) fn distribute_basket_tokens( - env: &Env, - escrow_id: u64, - payees: &BoundedPayees, - fee_bps: u32, -) -> Result<(), ContractError> { - let escrow = load_escrow(env, escrow_id)?; - let primary_token = &escrow.token; - let basket_tokens = load_basket_tokens(env, escrow_id); - - let config = crate::storage::read_global_config(env); - - for i in 0..basket_tokens.len() { - let entry = basket_tokens - .get(i) - .ok_or(ContractError::BasketIndexOutOfBounds)?; - if !is_transferable_basket_entry(&entry, primary_token) { - continue; - } - let protocol_fee = crate::helpers::payout::calculate_fee(entry.amount, fee_bps)?; - let platform_fee = match config.treasury.as_ref() { - Some(_) => { - crate::helpers::payout::calculate_fee(entry.amount, escrow.platform_fee_bps)? - } - None => 0, - }; - let net_amount = entry - .amount - .checked_sub(protocol_fee) - .ok_or(ContractError::AmountCalculationOverflow)? - .checked_sub(platform_fee) - .ok_or(ContractError::AmountCalculationOverflow)?; - distribute_to_payees(env, &entry.token, payees, net_amount, Some(escrow_id))?; - crate::storage::add_accumulated_fee(env, &entry.token, protocol_fee)?; - if let Some(treasury_addr) = config.treasury.as_ref() { - crate::helpers::payout::payout_platform_fee( - env, - escrow_id, - &entry.token, - treasury_addr, - platform_fee, - ); - } - } - Ok(()) -} - /// State and timing gate for [`Escrow::auto_release`](crate::Escrow::auto_release). /// /// `auto_release` is permissionless — anyone may call it — so the safety of the diff --git a/contracts/escrow/src/lib.rs b/contracts/escrow/src/lib.rs index edd97568..d9200409 100644 --- a/contracts/escrow/src/lib.rs +++ b/contracts/escrow/src/lib.rs @@ -17,7 +17,6 @@ pub mod storage; pub mod types; mod admin; -mod dispute_state_machine; mod disputes; pub use crate::disputes::DISPUTE_REASONS; mod instructions; diff --git a/contracts/escrow/src/test_fee_calculation_accuracy.rs b/contracts/escrow/src/test_fee_calculation_accuracy.rs index 58f5445d..7805b84b 100644 --- a/contracts/escrow/src/test_fee_calculation_accuracy.rs +++ b/contracts/escrow/src/test_fee_calculation_accuracy.rs @@ -693,8 +693,7 @@ fn test_multi_payee_zero_share_rounded_down() { token::StellarAssetClient::new(&env, &token).mint(&contract_id, &net); env.as_contract(&contract_id, || { - crate::internal::distribute_to_payees(&env, &token, &payees, net, Some(1)) - .unwrap(); + crate::internal::distribute_to_payees(&env, &token, &payees, net, Some(1)).unwrap(); }); let token_client = token::Client::new(&env, &token); diff --git a/contracts/escrow/src/test_not_found.rs b/contracts/escrow/src/test_not_found.rs index 2f424d95..baad264d 100644 --- a/contracts/escrow/src/test_not_found.rs +++ b/contracts/escrow/src/test_not_found.rs @@ -155,4 +155,4 @@ fn settlement_without_fee_collector_returns_not_initialized() { matches!(res, Err(Ok(ContractError::NotInitialized))), "confirm_delivery must return NotInitialized when fee collector is unset, got {res:?}", ); -} \ No newline at end of file +} From 33bd5758e3f6b439f9ce9fef0906b5cd939e3693 Mon Sep 17 00:00:00 2001 From: Kaybee973 Date: Sat, 28 Nov 2026 16:01:37 +0000 Subject: [PATCH 5/6] test: align legacy fee assertions with the accrued-fee model MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Settlement accrues protocol fees in the contract for the collector to pull instead of transferring them immediately, fees are snapshotted at escrow creation, and an admin rotation invalidates queued timelock slots. Update the affected unit and integration tests, the fallback-deadline fixtures, and the regenerated Soroban snapshots so `make test` and `make test-all` pass again. 🤖 Generated with Codebuff Co-Authored-By: Codebuff --- contracts/escrow/src/internal.rs | 1 - contracts/escrow/src/test.rs | 16 +++ contracts/escrow/src/test_admin.rs | 6 +- contracts/escrow/src/test_appeal.rs | 19 ++-- contracts/escrow/src/test_basket_escrow.rs | 7 +- contracts/escrow/src/test_dispute.rs | 5 + contracts/escrow/src/test_edge_cases.rs | 3 + .../escrow/src/test_fallback_resolver.rs | 4 +- .../test_finalize_dispute_appeal_boundary.rs | 16 +-- contracts/escrow/src/test_overflow.rs | 3 + .../buyer_funded_cancel_emits_event.1.json | 16 +++ .../seller_pending_cancel_emits_event.1.json | 16 +++ .../test/test_auto_release.1.json | 99 ++++++++++++++++++- ...auto_release_after_dispute_deadline.1.json | 98 +++++++++++++++++- .../test/test_confirm_delivery.1.json | 99 ++++++++++++++++++- ...onfirm_delivery_with_non_usdc_token.1.json | 99 ++++++++++++++++++- ...se_and_resolve_dispute_refund_buyer.1.json | 99 ++++++++++++++++++- ...d_resolve_dispute_release_to_seller.1.json | 99 ++++++++++++++++++- ...ease_before_record_delivery_reverts.1.json | 16 +++ ...s_no_dust_for_non_divisible_amounts.1.json | 96 +++++++++++++++++- ...s_no_dust_for_non_divisible_amounts.2.json | 73 ++++++++++++++ ...s_no_dust_for_non_divisible_amounts.3.json | 73 ++++++++++++++ ...s_no_dust_for_non_divisible_amounts.4.json | 73 ++++++++++++++ ...s_no_dust_for_non_divisible_amounts.5.json | 73 ++++++++++++++ ...s_no_dust_for_non_divisible_amounts.6.json | 73 ++++++++++++++ ...s_no_dust_for_non_divisible_amounts.7.json | 73 ++++++++++++++ ...s_no_dust_for_non_divisible_amounts.8.json | 73 ++++++++++++++ .../test_happy_path_escrow_lifecycle.1.json | 73 ++++++++++++++ ...t_fee_calculation_max_escrow_amount.1.json | 99 ++++++++++++++++++- ...horized_attacker_cannot_fund_escrow.1.json | 16 +++ contracts/escrow/tests/happy_path.rs | 5 +- 31 files changed, 1480 insertions(+), 41 deletions(-) diff --git a/contracts/escrow/src/internal.rs b/contracts/escrow/src/internal.rs index dd337edc..8c9fc785 100644 --- a/contracts/escrow/src/internal.rs +++ b/contracts/escrow/src/internal.rs @@ -1843,7 +1843,6 @@ pub(crate) fn execute_resolution_transition( let prev_state = escrow.state.clone(); let mut updated_escrow = escrow; - updated_escrow.amount = updated_escrow .amount .checked_sub(arbitration_fee) diff --git a/contracts/escrow/src/test.rs b/contracts/escrow/src/test.rs index d9c2d140..1a303679 100644 --- a/contracts/escrow/src/test.rs +++ b/contracts/escrow/src/test.rs @@ -193,6 +193,8 @@ fn test_confirm_delivery() { let escrow = client.get_escrow(&id); assert_eq!(escrow.state, EscrowState::Completed); assert_eq!(get_balance(&env, &token, &seller), 980); + // Protocol fees accrue in the contract for the collector to pull. + client.claim_accumulated_fees(&fee_collector, &token); assert_eq!(get_balance(&env, &token, &fee_collector), 20); assert_eq!(get_balance(&env, &token, &contract_id), 0); } @@ -239,6 +241,8 @@ fn test_raise_and_resolve_dispute_release_to_seller() { let escrow = client.get_escrow(&id); assert_eq!(escrow.state, EscrowState::Completed); assert_eq!(get_balance(&env, &token, &seller), 980); + // Protocol fees accrue in the contract for the collector to pull. + client.claim_accumulated_fees(&fee_collector, &token); assert_eq!(get_balance(&env, &token, &contract_id), 0); assert_eq!(get_balance(&env, &token, &fee_collector), 20); } @@ -285,6 +289,8 @@ fn test_raise_and_resolve_dispute_refund_buyer() { let escrow = client.get_escrow(&id); assert_eq!(escrow.state, EscrowState::Refunded); assert_eq!(get_balance(&env, &token, &buyer), 980); + // Protocol fees accrue in the contract for the collector to pull. + client.claim_accumulated_fees(&fee_collector, &token); assert_eq!(get_balance(&env, &token, &contract_id), 0); assert_eq!(get_balance(&env, &token, &fee_collector), 20); } @@ -328,6 +334,8 @@ fn test_auto_release() { let escrow = client.get_escrow(&id); assert_eq!(escrow.state, EscrowState::Completed); assert_eq!(get_balance(&env, &token, &seller), 980); + // Protocol fees accrue in the contract for the collector to pull. + client.claim_accumulated_fees(&fee_collector, &token); assert_eq!(get_balance(&env, &token, &fee_collector), 20); assert_eq!(get_balance(&env, &token, &contract_id), 0); } @@ -555,6 +563,8 @@ fn test_fund_and_confirm_delivery_with_non_usdc_token() { env.ledger().set_timestamp(escrow.dispute_deadline() + 1); client.confirm_delivery(&buyer, &id, &false); assert_eq!(get_balance(&env, &alt_token, &seller), 297); + // Protocol fees accrue in the contract for the collector to pull. + client.claim_accumulated_fees(&fee_collector, &alt_token); assert_eq!(get_balance(&env, &alt_token, &fee_collector), 3); assert_eq!(get_balance(&env, &alt_token, &contract_id), 0); } @@ -1057,6 +1067,8 @@ fn test_auto_release_after_dispute_deadline() { let escrow = client.get_escrow(&id); assert_eq!(escrow.state, EscrowState::Completed); assert_eq!(get_balance(&env, &token, &seller), 980); + // Protocol fees accrue in the contract for the collector to pull. + client.claim_accumulated_fees(&fee_collector, &token); assert_eq!(get_balance(&env, &token, &fee_collector), 20); } @@ -1284,6 +1296,8 @@ fn test_escrow_completed_event_amount_is_gross_of_protocol_fee() { )); assert_eq!(get_balance(&env, &token, &seller), net); + // Protocol fees accrue in the contract for the collector to pull. + client.claim_accumulated_fees(&fee_collector, &token); assert_eq!(get_balance(&env, &token, &fee_collector), fee); } @@ -1350,6 +1364,8 @@ fn test_dispute_resolved_event_amount_is_gross_of_final_fees() { // Recipient receives 950 - 20 protocol fee; the collector receives the // 50 arbitration fee plus the 20 protocol fee. assert_eq!(get_balance(&env, &token, &seller), 930); + // Protocol fees accrue in the contract for the collector to pull. + client.claim_accumulated_fees(&fee_collector, &token); assert_eq!(get_balance(&env, &token, &fee_collector), 70); } diff --git a/contracts/escrow/src/test_admin.rs b/contracts/escrow/src/test_admin.rs index 46e47935..33bbd13a 100644 --- a/contracts/escrow/src/test_admin.rs +++ b/contracts/escrow/src/test_admin.rs @@ -424,7 +424,7 @@ mod timelock { /// A proposal queued by an admin who has since been rotated out is purged /// by the rotation (#1234): nobody (keeper, new admin, or old admin) can - /// execute it, and the now-empty slot returns `InvalidState`. + /// execute it, and the invalidated slot returns `NotAuthorized`. #[test] fn proposal_from_rotated_out_admin_cannot_be_executed() { let env = Env::default(); @@ -437,10 +437,12 @@ mod timelock { client.set_admin(&new_admin); advance(&env, ADMIN_TIMELOCK_DELAY_SECONDS); + // The rotation marks the slot invalidated, so execution reports the + // canceled proposal as NotAuthorized for every caller. for executor in [&keeper, &new_admin, &admin] { assert_eq!( client.try_execute_set_platform_fee(executor, &150_u32), - Err(Ok(ContractError::InvalidState)) + Err(Ok(ContractError::NotAuthorized)) ); } assert_eq!(client.get_platform_fee_bps(), 0); diff --git a/contracts/escrow/src/test_appeal.rs b/contracts/escrow/src/test_appeal.rs index 57e4a5c7..532807d0 100644 --- a/contracts/escrow/src/test_appeal.rs +++ b/contracts/escrow/src/test_appeal.rs @@ -201,9 +201,10 @@ fn appeal_fails_after_finalization_completed() { EscrowState::Completed, ); - // Appeal is no longer possible once finalization has completed. + // Appeal is no longer possible once finalization has completed, and the + // terminal state is reported precisely rather than as NotPendingFinalization. let res = client.try_appeal_dispute(&setup.buyer, &setup.escrow_id); - assert_eq!(res, Err(Ok(ContractError::NotPendingFinalization))); + assert_eq!(res, Err(Ok(ContractError::EscrowAlreadyCompleted))); assert_eq!( client.get_dispute(&setup.escrow_id).unwrap().status, DisputeStatus::Resolved, @@ -421,10 +422,12 @@ fn appeal_fee_is_charged_on_reconstructed_principal() { client.set_appeal_fee(&setup.admin, &500_u32); // 5% raise_and_resolve(&setup); - // 1_000 principal - 50 arbitration - 20 resolver = 930 remaining. - assert_eq!(client.get_escrow(&setup.escrow_id).amount, 930); + // Fees are snapshotted at escrow creation, so this escrow keeps the 50 bps + // arbitration fee configured by `initialize` (5 stroops), not the later + // 500 bps: 1_000 principal - 5 arbitration - 20 resolver = 975 remaining. + assert_eq!(client.get_escrow(&setup.escrow_id).amount, 975); let dispute = client.get_dispute(&setup.escrow_id).unwrap(); - assert_eq!(dispute.arbitration_fee, 50); + assert_eq!(dispute.arbitration_fee, 5); assert_eq!(dispute.resolver_fee, 20); let collector_before = token_client.balance(&setup.fee_collector); @@ -502,7 +505,7 @@ fn resolve_appeal_reresolve_with_new_resolver_defers_and_pays_final_resolver() { assert_eq!(token_client.balance(&setup.contract_id), AMOUNT); let dispute = client.get_dispute(&setup.escrow_id).unwrap(); assert_eq!(dispute.resolved_by, Some(new_resolver.clone())); - assert_eq!(dispute.arbitration_fee, 50); + assert_eq!(dispute.arbitration_fee, 5); assert_eq!(dispute.resolver_fee, 20); setup @@ -515,8 +518,8 @@ fn resolve_appeal_reresolve_with_new_resolver_defers_and_pays_final_resolver() { // protocol fee) are all settled together at finalization. assert_eq!(token_client.balance(&new_resolver), 20); assert_eq!(token_client.balance(&setup.resolver), 0); - assert_eq!(token_client.balance(&setup.fee_collector), 50); - assert_eq!(token_client.balance(&setup.seller), 1_000 - 50 - 20); + assert_eq!(token_client.balance(&setup.fee_collector), 5); + assert_eq!(token_client.balance(&setup.seller), 1_000 - 5 - 20); assert_eq!(token_client.balance(&setup.contract_id), 0); assert!(client.get_dispute(&setup.escrow_id).unwrap().fees_charged); } diff --git a/contracts/escrow/src/test_basket_escrow.rs b/contracts/escrow/src/test_basket_escrow.rs index 6b1f5d7e..524f993f 100644 --- a/contracts/escrow/src/test_basket_escrow.rs +++ b/contracts/escrow/src/test_basket_escrow.rs @@ -1539,7 +1539,7 @@ fn create_basket_escrow_fallback_settles_basket_on_backup_refund() { let backup = Address::generate(&fx.env); let now = fx.env.ledger().timestamp(); - let dispute_deadline = now + 100; + let dispute_deadline = now + crate::MIN_FALLBACK_DEADLINE_OFFSET; let escrow_id = client.create_basket_escrow_fallback( &fx.seller, @@ -1785,6 +1785,11 @@ fn confirm_delivery_collects_protocol_and_platform_fees_on_basket_tokens() { ); client.confirm_delivery(&fx.buyer, &escrow_id, &true); + // Protocol fees accrue in the contract for the collector to pull. + client.claim_accumulated_fees(&fx.fee_collector, &a.address); + client.claim_accumulated_fees(&fx.fee_collector, &b.address); + client.claim_accumulated_fees(&fx.fee_collector, &c.address); + // Primary token keeps its existing treatment: only the protocol fee is // taken (no platform fee is charged on the primary on this path). assert_eq!( diff --git a/contracts/escrow/src/test_dispute.rs b/contracts/escrow/src/test_dispute.rs index 5a8f6f27..7cc48269 100644 --- a/contracts/escrow/src/test_dispute.rs +++ b/contracts/escrow/src/test_dispute.rs @@ -901,6 +901,9 @@ fn test_split_resolution_50_50_pays_both_sides_with_no_stranded_funds() { assert_eq!(client.get_escrow(&id).state, crate::EscrowState::Completed); + // Protocol fees accrue in the contract for the collector to pull. + client.claim_accumulated_fees(&fee_collector, &token); + let tc = token::Client::new(&env, &token); let seller_bal = tc.balance(&seller); let buyer_bal = tc.balance(&buyer); @@ -932,6 +935,8 @@ fn test_split_resolution_extremes_match_release_and_refund() { env.ledger() .set_timestamp(env.ledger().timestamp() + crate::APPEAL_WINDOW + 1); client.finalize_dispute(&resolver, &id); + // Protocol fees accrue in the contract for the collector to pull. + client.claim_accumulated_fees(&fee_collector, &token); let tc = token::Client::new(&env, &token); if payee_gets_all { diff --git a/contracts/escrow/src/test_edge_cases.rs b/contracts/escrow/src/test_edge_cases.rs index 647caa44..99de017d 100644 --- a/contracts/escrow/src/test_edge_cases.rs +++ b/contracts/escrow/src/test_edge_cases.rs @@ -247,6 +247,9 @@ fn test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts() { let expected_fee = (amount * fee_bps as i128) / 10_000; let expected_net = amount - expected_fee; + // Protocol fees accrue in the contract for the collector to pull. + client.claim_accumulated_fees(&fee_collector, &token); + let tc = soroban_sdk::token::Client::new(&env, &token); let seller_payout = tc.balance(&seller); let fee_collector_balance = tc.balance(&fee_collector); diff --git a/contracts/escrow/src/test_fallback_resolver.rs b/contracts/escrow/src/test_fallback_resolver.rs index 9cea0b80..52bf76db 100644 --- a/contracts/escrow/src/test_fallback_resolver.rs +++ b/contracts/escrow/src/test_fallback_resolver.rs @@ -782,7 +782,7 @@ fn test_fallback_backup_resolves_appeal_clears_votes_primary_reresolves() { // Move past the fallback deadline so the backup is authorized. let now = setup.env.ledger().timestamp(); - setup.env.ledger().set_timestamp(now + 200); + setup.env.ledger().set_timestamp(now + OFFSET); // Round 1: backup resolves Refund. client.resolve_dispute(&setup.backup, &escrow_id, &ResolutionType::Refund); @@ -843,7 +843,7 @@ fn test_fallback_round1_resolver_can_reresolve_after_appeal() { let escrow_id = create_funded_shipped_disputed(&setup); let now = setup.env.ledger().timestamp(); - setup.env.ledger().set_timestamp(now + 200); + setup.env.ledger().set_timestamp(now + OFFSET); client.resolve_dispute(&setup.backup, &escrow_id, &ResolutionType::Refund); client.appeal_dispute(&setup.buyer, &escrow_id); diff --git a/contracts/escrow/src/test_finalize_dispute_appeal_boundary.rs b/contracts/escrow/src/test_finalize_dispute_appeal_boundary.rs index 8737e1cd..1862b62d 100644 --- a/contracts/escrow/src/test_finalize_dispute_appeal_boundary.rs +++ b/contracts/escrow/src/test_finalize_dispute_appeal_boundary.rs @@ -132,7 +132,7 @@ fn finalize_succeeds_one_tick_after_deadline() { } #[test] -fn finalize_dispute_without_treasury_returns_not_initialized() { +fn finalize_dispute_without_treasury_skips_platform_fee() { let env = Env::default(); env.mock_all_auths(); @@ -188,15 +188,9 @@ fn finalize_dispute_without_treasury_returns_not_initialized() { let appeal_deadline = dispute.resolved_at + crate::APPEAL_WINDOW; env.ledger().set_timestamp(appeal_deadline + 1); - // Note: treasury was never set via set_treasury, so read_treasury should - // return NotInitialized (35) instead of NotAuthorized (5). - // Since platform_fee > 0, treasury will be read and should fail with NotInitialized. + // No treasury was set, so the platform fee is skipped (#1258) and + // finalization succeeds rather than failing with NotInitialized. let res = client.try_finalize_dispute(&resolver, &escrow_id); - assert_eq!(res, Err(Ok(ContractError::NotInitialized))); - - // Escrow should still be in PendingFinalization (no state change on error) - assert_eq!( - client.get_escrow(&escrow_id).state, - EscrowState::PendingFinalization, - ); + assert_eq!(res, Ok(Ok(()))); + assert_eq!(client.get_escrow(&escrow_id).state, EscrowState::Completed); } diff --git a/contracts/escrow/src/test_overflow.rs b/contracts/escrow/src/test_overflow.rs index 85df1864..84bd4d32 100644 --- a/contracts/escrow/src/test_overflow.rs +++ b/contracts/escrow/src/test_overflow.rs @@ -88,6 +88,9 @@ fn test_fee_calculation_max_escrow_amount() { (MAX_ESCROW_AMOUNT / 10_000) * 300 + (MAX_ESCROW_AMOUNT % 10_000) * 300 / 10_000; let expected_net = MAX_ESCROW_AMOUNT - expected_fee; + // Protocol fees accrue in the contract for the collector to pull. + client.claim_accumulated_fees(&fee_collector, &token); + let tc = soroban_sdk::token::Client::new(&env, &token); assert_eq!(tc.balance(&seller), expected_net); assert_eq!(tc.balance(&fee_collector), expected_fee); diff --git a/contracts/escrow/test_snapshots/buyer_funded_cancel_emits_event.1.json b/contracts/escrow/test_snapshots/buyer_funded_cancel_emits_event.1.json index 650a66f4..89c4e8e3 100644 --- a/contracts/escrow/test_snapshots/buyer_funded_cancel_emits_event.1.json +++ b/contracts/escrow/test_snapshots/buyer_funded_cancel_emits_event.1.json @@ -321,6 +321,14 @@ "i128": "1000" } }, + { + "key": { + "symbol": "arbitration_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "buyer" @@ -411,6 +419,14 @@ ] } }, + { + "key": { + "symbol": "platform_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "resolver_fee_bps" diff --git a/contracts/escrow/test_snapshots/seller_pending_cancel_emits_event.1.json b/contracts/escrow/test_snapshots/seller_pending_cancel_emits_event.1.json index ca1407f8..e8cf7b13 100644 --- a/contracts/escrow/test_snapshots/seller_pending_cancel_emits_event.1.json +++ b/contracts/escrow/test_snapshots/seller_pending_cancel_emits_event.1.json @@ -230,6 +230,14 @@ "i128": "1000" } }, + { + "key": { + "symbol": "arbitration_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "buyer" @@ -318,6 +326,14 @@ ] } }, + { + "key": { + "symbol": "platform_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "resolver_fee_bps" diff --git a/contracts/escrow/test_snapshots/test/test_auto_release.1.json b/contracts/escrow/test_snapshots/test/test_auto_release.1.json index 183477b4..f35cb96e 100644 --- a/contracts/escrow/test_snapshots/test/test_auto_release.1.json +++ b/contracts/escrow/test_snapshots/test/test_auto_release.1.json @@ -247,6 +247,29 @@ [], [], [], + [ + [ + "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4", + { + "function": { + "contract_fn": { + "contract_address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5", + "function_name": "claim_accumulated_fees", + "args": [ + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4" + }, + { + "address": "CDS3FDGQ4JA2V3F26Y4BMWWJEC5TT26RJBN7KIQKUMVO2MAOCMDTSZ7A" + } + ] + } + }, + "sub_invocations": [] + } + ] + ], + [], [] ], "ledger": { @@ -440,6 +463,26 @@ }, "live_until": 6311999 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4", + "key": { + "ledger_key_nonce": { + "nonce": "5806905060045992000" + } + }, + "durability": "temporary", + "val": "void" + } + }, + "ext": "v0" + }, + "live_until": 6311999 + }, { "entry": { "last_modified_ledger_seq": 0, @@ -900,7 +943,7 @@ ] }, "val": { - "i128": "20" + "i128": "0" } }, { @@ -1164,7 +1207,7 @@ "symbol": "Balance" }, { - "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5" + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4" } ] }, @@ -1203,6 +1246,58 @@ }, "live_until": 518400 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CDS3FDGQ4JA2V3F26Y4BMWWJEC5TT26RJBN7KIQKUMVO2MAOCMDTSZ7A", + "key": { + "vec": [ + { + "symbol": "Balance" + }, + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5" + } + ] + }, + "durability": "persistent", + "val": { + "map": [ + { + "key": { + "symbol": "amount" + }, + "val": { + "i128": "0" + } + }, + { + "key": { + "symbol": "authorized" + }, + "val": { + "bool": true + } + }, + { + "key": { + "symbol": "clawback" + }, + "val": { + "bool": false + } + } + ] + } + } + }, + "ext": "v0" + }, + "live_until": 518400 + }, { "entry": { "last_modified_ledger_seq": 0, diff --git a/contracts/escrow/test_snapshots/test/test_auto_release_after_dispute_deadline.1.json b/contracts/escrow/test_snapshots/test/test_auto_release_after_dispute_deadline.1.json index 9a9e099d..ae6e36f0 100644 --- a/contracts/escrow/test_snapshots/test/test_auto_release_after_dispute_deadline.1.json +++ b/contracts/escrow/test_snapshots/test/test_auto_release_after_dispute_deadline.1.json @@ -247,6 +247,28 @@ [], [], [], + [ + [ + "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4", + { + "function": { + "contract_fn": { + "contract_address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5", + "function_name": "claim_accumulated_fees", + "args": [ + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4" + }, + { + "address": "CDS3FDGQ4JA2V3F26Y4BMWWJEC5TT26RJBN7KIQKUMVO2MAOCMDTSZ7A" + } + ] + } + }, + "sub_invocations": [] + } + ] + ], [] ], "ledger": { @@ -440,6 +462,26 @@ }, "live_until": 6311999 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4", + "key": { + "ledger_key_nonce": { + "nonce": "5806905060045992000" + } + }, + "durability": "temporary", + "val": "void" + } + }, + "ext": "v0" + }, + "live_until": 6311999 + }, { "entry": { "last_modified_ledger_seq": 0, @@ -900,7 +942,7 @@ ] }, "val": { - "i128": "20" + "i128": "0" } }, { @@ -1164,7 +1206,7 @@ "symbol": "Balance" }, { - "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5" + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4" } ] }, @@ -1203,6 +1245,58 @@ }, "live_until": 518400 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CDS3FDGQ4JA2V3F26Y4BMWWJEC5TT26RJBN7KIQKUMVO2MAOCMDTSZ7A", + "key": { + "vec": [ + { + "symbol": "Balance" + }, + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5" + } + ] + }, + "durability": "persistent", + "val": { + "map": [ + { + "key": { + "symbol": "amount" + }, + "val": { + "i128": "0" + } + }, + { + "key": { + "symbol": "authorized" + }, + "val": { + "bool": true + } + }, + { + "key": { + "symbol": "clawback" + }, + "val": { + "bool": false + } + } + ] + } + } + }, + "ext": "v0" + }, + "live_until": 518400 + }, { "entry": { "last_modified_ledger_seq": 0, diff --git a/contracts/escrow/test_snapshots/test/test_confirm_delivery.1.json b/contracts/escrow/test_snapshots/test/test_confirm_delivery.1.json index 4e167a8a..324ead66 100644 --- a/contracts/escrow/test_snapshots/test/test_confirm_delivery.1.json +++ b/contracts/escrow/test_snapshots/test/test_confirm_delivery.1.json @@ -205,6 +205,29 @@ ], [], [], + [ + [ + "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4", + { + "function": { + "contract_fn": { + "contract_address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5", + "function_name": "claim_accumulated_fees", + "args": [ + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4" + }, + { + "address": "CDS3FDGQ4JA2V3F26Y4BMWWJEC5TT26RJBN7KIQKUMVO2MAOCMDTSZ7A" + } + ] + } + }, + "sub_invocations": [] + } + ] + ], + [], [] ], "ledger": { @@ -358,6 +381,26 @@ }, "live_until": 6311999 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4", + "key": { + "ledger_key_nonce": { + "nonce": "8370022561469687789" + } + }, + "durability": "temporary", + "val": "void" + } + }, + "ext": "v0" + }, + "live_until": 6311999 + }, { "entry": { "last_modified_ledger_seq": 0, @@ -816,7 +859,7 @@ ] }, "val": { - "i128": "20" + "i128": "0" } }, { @@ -1080,7 +1123,7 @@ "symbol": "Balance" }, { - "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5" + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4" } ] }, @@ -1119,6 +1162,58 @@ }, "live_until": 518400 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CDS3FDGQ4JA2V3F26Y4BMWWJEC5TT26RJBN7KIQKUMVO2MAOCMDTSZ7A", + "key": { + "vec": [ + { + "symbol": "Balance" + }, + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5" + } + ] + }, + "durability": "persistent", + "val": { + "map": [ + { + "key": { + "symbol": "amount" + }, + "val": { + "i128": "0" + } + }, + { + "key": { + "symbol": "authorized" + }, + "val": { + "bool": true + } + }, + { + "key": { + "symbol": "clawback" + }, + "val": { + "bool": false + } + } + ] + } + } + }, + "ext": "v0" + }, + "live_until": 518400 + }, { "entry": { "last_modified_ledger_seq": 0, diff --git a/contracts/escrow/test_snapshots/test/test_fund_and_confirm_delivery_with_non_usdc_token.1.json b/contracts/escrow/test_snapshots/test/test_fund_and_confirm_delivery_with_non_usdc_token.1.json index dbef2553..c3fc6653 100644 --- a/contracts/escrow/test_snapshots/test/test_fund_and_confirm_delivery_with_non_usdc_token.1.json +++ b/contracts/escrow/test_snapshots/test/test_fund_and_confirm_delivery_with_non_usdc_token.1.json @@ -224,6 +224,29 @@ ] ], [], + [ + [ + "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4", + { + "function": { + "contract_fn": { + "contract_address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVAX5", + "function_name": "claim_accumulated_fees", + "args": [ + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4" + }, + { + "address": "CCFPZOCU33AWX2NKX47XD6W5JNYFP7MU57DTQFB5XOOQSJLSSC4PMX25" + } + ] + } + }, + "sub_invocations": [] + } + ] + ], + [], [] ], "ledger": { @@ -398,6 +421,26 @@ }, "live_until": 6311999 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4", + "key": { + "ledger_key_nonce": { + "nonce": "6277191135259896685" + } + }, + "durability": "temporary", + "val": "void" + } + }, + "ext": "v0" + }, + "live_until": 6311999 + }, { "entry": { "last_modified_ledger_seq": 0, @@ -876,7 +919,7 @@ ] }, "val": { - "i128": "3" + "i128": "0" } }, { @@ -1140,7 +1183,7 @@ "symbol": "Balance" }, { - "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVAX5" + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4" } ] }, @@ -1179,6 +1222,58 @@ }, "live_until": 518400 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CCFPZOCU33AWX2NKX47XD6W5JNYFP7MU57DTQFB5XOOQSJLSSC4PMX25", + "key": { + "vec": [ + { + "symbol": "Balance" + }, + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVAX5" + } + ] + }, + "durability": "persistent", + "val": { + "map": [ + { + "key": { + "symbol": "amount" + }, + "val": { + "i128": "0" + } + }, + { + "key": { + "symbol": "authorized" + }, + "val": { + "bool": true + } + }, + { + "key": { + "symbol": "clawback" + }, + "val": { + "bool": false + } + } + ] + } + } + }, + "ext": "v0" + }, + "live_until": 518400 + }, { "entry": { "last_modified_ledger_seq": 0, diff --git a/contracts/escrow/test_snapshots/test/test_raise_and_resolve_dispute_refund_buyer.1.json b/contracts/escrow/test_snapshots/test/test_raise_and_resolve_dispute_refund_buyer.1.json index 29b97613..e4c5e970 100644 --- a/contracts/escrow/test_snapshots/test/test_raise_and_resolve_dispute_refund_buyer.1.json +++ b/contracts/escrow/test_snapshots/test/test_raise_and_resolve_dispute_refund_buyer.1.json @@ -261,6 +261,29 @@ ], [], [], + [ + [ + "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4", + { + "function": { + "contract_fn": { + "contract_address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5", + "function_name": "claim_accumulated_fees", + "args": [ + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4" + }, + { + "address": "CDS3FDGQ4JA2V3F26Y4BMWWJEC5TT26RJBN7KIQKUMVO2MAOCMDTSZ7A" + } + ] + } + }, + "sub_invocations": [] + } + ] + ], + [], [] ], "ledger": { @@ -454,6 +477,26 @@ }, "live_until": 6311999 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4", + "key": { + "ledger_key_nonce": { + "nonce": "5806905060045992000" + } + }, + "durability": "temporary", + "val": "void" + } + }, + "ext": "v0" + }, + "live_until": 6311999 + }, { "entry": { "last_modified_ledger_seq": 0, @@ -1178,7 +1221,7 @@ ] }, "val": { - "i128": "20" + "i128": "0" } }, { @@ -1390,7 +1433,7 @@ "symbol": "Balance" }, { - "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5" + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4" } ] }, @@ -1429,6 +1472,58 @@ }, "live_until": 518400 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CDS3FDGQ4JA2V3F26Y4BMWWJEC5TT26RJBN7KIQKUMVO2MAOCMDTSZ7A", + "key": { + "vec": [ + { + "symbol": "Balance" + }, + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5" + } + ] + }, + "durability": "persistent", + "val": { + "map": [ + { + "key": { + "symbol": "amount" + }, + "val": { + "i128": "0" + } + }, + { + "key": { + "symbol": "authorized" + }, + "val": { + "bool": true + } + }, + { + "key": { + "symbol": "clawback" + }, + "val": { + "bool": false + } + } + ] + } + } + }, + "ext": "v0" + }, + "live_until": 518400 + }, { "entry": { "last_modified_ledger_seq": 0, diff --git a/contracts/escrow/test_snapshots/test/test_raise_and_resolve_dispute_release_to_seller.1.json b/contracts/escrow/test_snapshots/test/test_raise_and_resolve_dispute_release_to_seller.1.json index 13305530..eeee865e 100644 --- a/contracts/escrow/test_snapshots/test/test_raise_and_resolve_dispute_release_to_seller.1.json +++ b/contracts/escrow/test_snapshots/test/test_raise_and_resolve_dispute_release_to_seller.1.json @@ -261,6 +261,29 @@ ], [], [], + [ + [ + "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4", + { + "function": { + "contract_fn": { + "contract_address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5", + "function_name": "claim_accumulated_fees", + "args": [ + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4" + }, + { + "address": "CDS3FDGQ4JA2V3F26Y4BMWWJEC5TT26RJBN7KIQKUMVO2MAOCMDTSZ7A" + } + ] + } + }, + "sub_invocations": [] + } + ] + ], + [], [] ], "ledger": { @@ -454,6 +477,26 @@ }, "live_until": 6311999 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4", + "key": { + "ledger_key_nonce": { + "nonce": "5806905060045992000" + } + }, + "durability": "temporary", + "val": "void" + } + }, + "ext": "v0" + }, + "live_until": 6311999 + }, { "entry": { "last_modified_ledger_seq": 0, @@ -1178,7 +1221,7 @@ ] }, "val": { - "i128": "20" + "i128": "0" } }, { @@ -1442,7 +1485,7 @@ "symbol": "Balance" }, { - "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5" + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4" } ] }, @@ -1481,6 +1524,58 @@ }, "live_until": 518400 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CDS3FDGQ4JA2V3F26Y4BMWWJEC5TT26RJBN7KIQKUMVO2MAOCMDTSZ7A", + "key": { + "vec": [ + { + "symbol": "Balance" + }, + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5" + } + ] + }, + "durability": "persistent", + "val": { + "map": [ + { + "key": { + "symbol": "amount" + }, + "val": { + "i128": "0" + } + }, + { + "key": { + "symbol": "authorized" + }, + "val": { + "bool": true + } + }, + { + "key": { + "symbol": "clawback" + }, + "val": { + "bool": false + } + } + ] + } + } + }, + "ext": "v0" + }, + "live_until": 518400 + }, { "entry": { "last_modified_ledger_seq": 0, diff --git a/contracts/escrow/test_snapshots/test_auto_release_before_record_delivery_reverts.1.json b/contracts/escrow/test_snapshots/test_auto_release_before_record_delivery_reverts.1.json index a0342a47..3ace870f 100644 --- a/contracts/escrow/test_snapshots/test_auto_release_before_record_delivery_reverts.1.json +++ b/contracts/escrow/test_snapshots/test_auto_release_before_record_delivery_reverts.1.json @@ -400,6 +400,14 @@ "i128": "1000" } }, + { + "key": { + "symbol": "arbitration_fee_bps" + }, + "val": { + "u32": 100 + } + }, { "key": { "symbol": "buyer" @@ -490,6 +498,14 @@ ] } }, + { + "key": { + "symbol": "platform_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "resolver_fee_bps" diff --git a/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.1.json b/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.1.json index e40fada0..d26dfb8d 100644 --- a/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.1.json +++ b/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.1.json @@ -220,6 +220,28 @@ } ] ], + [ + [ + "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M", + { + "function": { + "contract_fn": { + "contract_address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM", + "function_name": "claim_accumulated_fees", + "args": [ + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M" + }, + { + "address": "CD3FXVGYSLQFFTW3UH6WFF2OKZH7VERGZJZAMJHTGHBWO4F6URWEJL23" + } + ] + } + }, + "sub_invocations": [] + } + ] + ], [], [] ], @@ -732,7 +754,7 @@ ] }, "val": { - "i128": "10000" + "i128": "0" } }, { @@ -899,6 +921,26 @@ }, "live_until": 6311999 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M", + "key": { + "ledger_key_nonce": { + "nonce": "6277191135259896685" + } + }, + "durability": "temporary", + "val": "void" + } + }, + "ext": "v0" + }, + "live_until": 6311999 + }, { "entry": { "last_modified_ledger_seq": 0, @@ -1017,6 +1059,58 @@ ] }, "durability": "persistent", + "val": { + "map": [ + { + "key": { + "symbol": "amount" + }, + "val": { + "i128": "0" + } + }, + { + "key": { + "symbol": "authorized" + }, + "val": { + "bool": true + } + }, + { + "key": { + "symbol": "clawback" + }, + "val": { + "bool": false + } + } + ] + } + } + }, + "ext": "v0" + }, + "live_until": 518400 + }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CD3FXVGYSLQFFTW3UH6WFF2OKZH7VERGZJZAMJHTGHBWO4F6URWEJL23", + "key": { + "vec": [ + { + "symbol": "Balance" + }, + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M" + } + ] + }, + "durability": "persistent", "val": { "map": [ { diff --git a/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.2.json b/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.2.json index 61efb7cd..af16a827 100644 --- a/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.2.json +++ b/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.2.json @@ -220,6 +220,28 @@ } ] ], + [ + [ + "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M", + { + "function": { + "contract_fn": { + "contract_address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM", + "function_name": "claim_accumulated_fees", + "args": [ + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M" + }, + { + "address": "CD3FXVGYSLQFFTW3UH6WFF2OKZH7VERGZJZAMJHTGHBWO4F6URWEJL23" + } + ] + } + }, + "sub_invocations": [] + } + ] + ], [], [] ], @@ -363,6 +385,14 @@ "i128": "1000099" } }, + { + "key": { + "symbol": "arbitration_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "buyer" @@ -453,6 +483,14 @@ ] } }, + { + "key": { + "symbol": "platform_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "resolver_fee_bps" @@ -704,6 +742,21 @@ "wasm": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }, "storage": [ + { + "key": { + "vec": [ + { + "symbol": "AccumulatedFees" + }, + { + "address": "CD3FXVGYSLQFFTW3UH6WFF2OKZH7VERGZJZAMJHTGHBWO4F6URWEJL23" + } + ] + }, + "val": { + "i128": "0" + } + }, { "key": { "vec": [ @@ -868,6 +921,26 @@ }, "live_until": 6311999 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M", + "key": { + "ledger_key_nonce": { + "nonce": "6277191135259896685" + } + }, + "durability": "temporary", + "val": "void" + } + }, + "ext": "v0" + }, + "live_until": 6311999 + }, { "entry": { "last_modified_ledger_seq": 0, diff --git a/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.3.json b/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.3.json index 51265947..6c79d560 100644 --- a/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.3.json +++ b/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.3.json @@ -220,6 +220,28 @@ } ] ], + [ + [ + "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M", + { + "function": { + "contract_fn": { + "contract_address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM", + "function_name": "claim_accumulated_fees", + "args": [ + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M" + }, + { + "address": "CD3FXVGYSLQFFTW3UH6WFF2OKZH7VERGZJZAMJHTGHBWO4F6URWEJL23" + } + ] + } + }, + "sub_invocations": [] + } + ] + ], [], [] ], @@ -363,6 +385,14 @@ "i128": "1234567" } }, + { + "key": { + "symbol": "arbitration_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "buyer" @@ -453,6 +483,14 @@ ] } }, + { + "key": { + "symbol": "platform_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "resolver_fee_bps" @@ -704,6 +742,21 @@ "wasm": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }, "storage": [ + { + "key": { + "vec": [ + { + "symbol": "AccumulatedFees" + }, + { + "address": "CD3FXVGYSLQFFTW3UH6WFF2OKZH7VERGZJZAMJHTGHBWO4F6URWEJL23" + } + ] + }, + "val": { + "i128": "0" + } + }, { "key": { "vec": [ @@ -868,6 +921,26 @@ }, "live_until": 6311999 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M", + "key": { + "ledger_key_nonce": { + "nonce": "6277191135259896685" + } + }, + "durability": "temporary", + "val": "void" + } + }, + "ext": "v0" + }, + "live_until": 6311999 + }, { "entry": { "last_modified_ledger_seq": 0, diff --git a/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.4.json b/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.4.json index d688f45a..2bfce240 100644 --- a/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.4.json +++ b/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.4.json @@ -220,6 +220,28 @@ } ] ], + [ + [ + "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M", + { + "function": { + "contract_fn": { + "contract_address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM", + "function_name": "claim_accumulated_fees", + "args": [ + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M" + }, + { + "address": "CD3FXVGYSLQFFTW3UH6WFF2OKZH7VERGZJZAMJHTGHBWO4F6URWEJL23" + } + ] + } + }, + "sub_invocations": [] + } + ] + ], [], [] ], @@ -363,6 +385,14 @@ "i128": "1000001" } }, + { + "key": { + "symbol": "arbitration_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "buyer" @@ -453,6 +483,14 @@ ] } }, + { + "key": { + "symbol": "platform_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "resolver_fee_bps" @@ -704,6 +742,21 @@ "wasm": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }, "storage": [ + { + "key": { + "vec": [ + { + "symbol": "AccumulatedFees" + }, + { + "address": "CD3FXVGYSLQFFTW3UH6WFF2OKZH7VERGZJZAMJHTGHBWO4F6URWEJL23" + } + ] + }, + "val": { + "i128": "0" + } + }, { "key": { "vec": [ @@ -868,6 +921,26 @@ }, "live_until": 6311999 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M", + "key": { + "ledger_key_nonce": { + "nonce": "6277191135259896685" + } + }, + "durability": "temporary", + "val": "void" + } + }, + "ext": "v0" + }, + "live_until": 6311999 + }, { "entry": { "last_modified_ledger_seq": 0, diff --git a/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.5.json b/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.5.json index 658ddb2a..dbd38bea 100644 --- a/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.5.json +++ b/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.5.json @@ -220,6 +220,28 @@ } ] ], + [ + [ + "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M", + { + "function": { + "contract_fn": { + "contract_address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM", + "function_name": "claim_accumulated_fees", + "args": [ + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M" + }, + { + "address": "CD3FXVGYSLQFFTW3UH6WFF2OKZH7VERGZJZAMJHTGHBWO4F6URWEJL23" + } + ] + } + }, + "sub_invocations": [] + } + ] + ], [], [] ], @@ -363,6 +385,14 @@ "i128": "1000003" } }, + { + "key": { + "symbol": "arbitration_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "buyer" @@ -453,6 +483,14 @@ ] } }, + { + "key": { + "symbol": "platform_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "resolver_fee_bps" @@ -704,6 +742,21 @@ "wasm": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }, "storage": [ + { + "key": { + "vec": [ + { + "symbol": "AccumulatedFees" + }, + { + "address": "CD3FXVGYSLQFFTW3UH6WFF2OKZH7VERGZJZAMJHTGHBWO4F6URWEJL23" + } + ] + }, + "val": { + "i128": "0" + } + }, { "key": { "vec": [ @@ -868,6 +921,26 @@ }, "live_until": 6311999 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M", + "key": { + "ledger_key_nonce": { + "nonce": "6277191135259896685" + } + }, + "durability": "temporary", + "val": "void" + } + }, + "ext": "v0" + }, + "live_until": 6311999 + }, { "entry": { "last_modified_ledger_seq": 0, diff --git a/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.6.json b/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.6.json index 1b3fac55..02cd8e84 100644 --- a/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.6.json +++ b/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.6.json @@ -220,6 +220,28 @@ } ] ], + [ + [ + "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M", + { + "function": { + "contract_fn": { + "contract_address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM", + "function_name": "claim_accumulated_fees", + "args": [ + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M" + }, + { + "address": "CD3FXVGYSLQFFTW3UH6WFF2OKZH7VERGZJZAMJHTGHBWO4F6URWEJL23" + } + ] + } + }, + "sub_invocations": [] + } + ] + ], [], [] ], @@ -363,6 +385,14 @@ "i128": "9999999" } }, + { + "key": { + "symbol": "arbitration_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "buyer" @@ -453,6 +483,14 @@ ] } }, + { + "key": { + "symbol": "platform_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "resolver_fee_bps" @@ -704,6 +742,21 @@ "wasm": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }, "storage": [ + { + "key": { + "vec": [ + { + "symbol": "AccumulatedFees" + }, + { + "address": "CD3FXVGYSLQFFTW3UH6WFF2OKZH7VERGZJZAMJHTGHBWO4F6URWEJL23" + } + ] + }, + "val": { + "i128": "0" + } + }, { "key": { "vec": [ @@ -868,6 +921,26 @@ }, "live_until": 6311999 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M", + "key": { + "ledger_key_nonce": { + "nonce": "6277191135259896685" + } + }, + "durability": "temporary", + "val": "void" + } + }, + "ext": "v0" + }, + "live_until": 6311999 + }, { "entry": { "last_modified_ledger_seq": 0, diff --git a/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.7.json b/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.7.json index f36f5410..5e0a9845 100644 --- a/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.7.json +++ b/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.7.json @@ -220,6 +220,28 @@ } ] ], + [ + [ + "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M", + { + "function": { + "contract_fn": { + "contract_address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM", + "function_name": "claim_accumulated_fees", + "args": [ + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M" + }, + { + "address": "CD3FXVGYSLQFFTW3UH6WFF2OKZH7VERGZJZAMJHTGHBWO4F6URWEJL23" + } + ] + } + }, + "sub_invocations": [] + } + ] + ], [], [] ], @@ -363,6 +385,14 @@ "i128": "1000001" } }, + { + "key": { + "symbol": "arbitration_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "buyer" @@ -453,6 +483,14 @@ ] } }, + { + "key": { + "symbol": "platform_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "resolver_fee_bps" @@ -704,6 +742,21 @@ "wasm": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }, "storage": [ + { + "key": { + "vec": [ + { + "symbol": "AccumulatedFees" + }, + { + "address": "CD3FXVGYSLQFFTW3UH6WFF2OKZH7VERGZJZAMJHTGHBWO4F6URWEJL23" + } + ] + }, + "val": { + "i128": "0" + } + }, { "key": { "vec": [ @@ -868,6 +921,26 @@ }, "live_until": 6311999 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M", + "key": { + "ledger_key_nonce": { + "nonce": "6277191135259896685" + } + }, + "durability": "temporary", + "val": "void" + } + }, + "ext": "v0" + }, + "live_until": 6311999 + }, { "entry": { "last_modified_ledger_seq": 0, diff --git a/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.8.json b/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.8.json index acdd87b6..527295cd 100644 --- a/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.8.json +++ b/contracts/escrow/test_snapshots/test_edge_cases/test_confirm_delivery_leaves_no_dust_for_non_divisible_amounts.8.json @@ -220,6 +220,28 @@ } ] ], + [ + [ + "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M", + { + "function": { + "contract_fn": { + "contract_address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM", + "function_name": "claim_accumulated_fees", + "args": [ + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M" + }, + { + "address": "CD3FXVGYSLQFFTW3UH6WFF2OKZH7VERGZJZAMJHTGHBWO4F6URWEJL23" + } + ] + } + }, + "sub_invocations": [] + } + ] + ], [], [] ], @@ -363,6 +385,14 @@ "i128": "7777777" } }, + { + "key": { + "symbol": "arbitration_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "buyer" @@ -453,6 +483,14 @@ ] } }, + { + "key": { + "symbol": "platform_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "resolver_fee_bps" @@ -704,6 +742,21 @@ "wasm": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }, "storage": [ + { + "key": { + "vec": [ + { + "symbol": "AccumulatedFees" + }, + { + "address": "CD3FXVGYSLQFFTW3UH6WFF2OKZH7VERGZJZAMJHTGHBWO4F6URWEJL23" + } + ] + }, + "val": { + "i128": "0" + } + }, { "key": { "vec": [ @@ -868,6 +921,26 @@ }, "live_until": 6311999 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M", + "key": { + "ledger_key_nonce": { + "nonce": "6277191135259896685" + } + }, + "durability": "temporary", + "val": "void" + } + }, + "ext": "v0" + }, + "live_until": 6311999 + }, { "entry": { "last_modified_ledger_seq": 0, diff --git a/contracts/escrow/test_snapshots/test_happy_path_escrow_lifecycle.1.json b/contracts/escrow/test_snapshots/test_happy_path_escrow_lifecycle.1.json index 673f3e70..3ca63708 100644 --- a/contracts/escrow/test_snapshots/test_happy_path_escrow_lifecycle.1.json +++ b/contracts/escrow/test_snapshots/test_happy_path_escrow_lifecycle.1.json @@ -209,6 +209,28 @@ ] ], [], + [ + [ + "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK3IM", + { + "function": { + "contract_fn": { + "contract_address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5", + "function_name": "claim_accumulated_fees", + "args": [ + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK3IM" + }, + { + "address": "CDS3FDGQ4JA2V3F26Y4BMWWJEC5TT26RJBN7KIQKUMVO2MAOCMDTSZ7A" + } + ] + } + }, + "sub_invocations": [] + } + ] + ], [], [], [] @@ -344,6 +366,26 @@ }, "live_until": 6311999 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK3IM", + "key": { + "ledger_key_nonce": { + "nonce": "8370022561469687789" + } + }, + "durability": "temporary", + "val": "void" + } + }, + "ext": "v0" + }, + "live_until": 6311999 + }, { "entry": { "last_modified_ledger_seq": 0, @@ -453,6 +495,14 @@ "i128": "10000" } }, + { + "key": { + "symbol": "arbitration_fee_bps" + }, + "val": { + "u32": 100 + } + }, { "key": { "symbol": "buyer" @@ -543,6 +593,14 @@ ] } }, + { + "key": { + "symbol": "platform_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "resolver_fee_bps" @@ -794,6 +852,21 @@ "wasm": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }, "storage": [ + { + "key": { + "vec": [ + { + "symbol": "AccumulatedFees" + }, + { + "address": "CDS3FDGQ4JA2V3F26Y4BMWWJEC5TT26RJBN7KIQKUMVO2MAOCMDTSZ7A" + } + ] + }, + "val": { + "i128": "0" + } + }, { "key": { "vec": [ diff --git a/contracts/escrow/test_snapshots/test_overflow/test_fee_calculation_max_escrow_amount.1.json b/contracts/escrow/test_snapshots/test_overflow/test_fee_calculation_max_escrow_amount.1.json index df3cccdc..8e228fa0 100644 --- a/contracts/escrow/test_snapshots/test_overflow/test_fee_calculation_max_escrow_amount.1.json +++ b/contracts/escrow/test_snapshots/test_overflow/test_fee_calculation_max_escrow_amount.1.json @@ -226,6 +226,29 @@ ] ], [], + [ + [ + "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK3IM", + { + "function": { + "contract_fn": { + "contract_address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM", + "function_name": "claim_accumulated_fees", + "args": [ + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK3IM" + }, + { + "address": "CACMVW2KK4H5FZDFF2AUCAKQTEJMZZWJUIZF23XMRVYQBSXYLHZ6BKWN" + } + ] + } + }, + "sub_invocations": [] + } + ] + ], + [], [], [] ], @@ -380,6 +403,26 @@ }, "live_until": 6311999 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK3IM", + "key": { + "ledger_key_nonce": { + "nonce": "6277191135259896685" + } + }, + "durability": "temporary", + "val": "void" + } + }, + "ext": "v0" + }, + "live_until": 6311999 + }, { "entry": { "last_modified_ledger_seq": 0, @@ -838,7 +881,7 @@ ] }, "val": { - "i128": "510423550381407695195061911147652" + "i128": "0" } }, { @@ -1122,7 +1165,7 @@ "symbol": "Balance" }, { - "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM" + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK3IM" } ] }, @@ -1161,6 +1204,58 @@ }, "live_until": 518400 }, + { + "entry": { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CACMVW2KK4H5FZDFF2AUCAKQTEJMZZWJUIZF23XMRVYQBSXYLHZ6BKWN", + "key": { + "vec": [ + { + "symbol": "Balance" + }, + { + "address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOLZM" + } + ] + }, + "durability": "persistent", + "val": { + "map": [ + { + "key": { + "symbol": "amount" + }, + "val": { + "i128": "0" + } + }, + { + "key": { + "symbol": "authorized" + }, + "val": { + "bool": true + } + }, + { + "key": { + "symbol": "clawback" + }, + "val": { + "bool": false + } + } + ] + } + } + }, + "ext": "v0" + }, + "live_until": 518400 + }, { "entry": { "last_modified_ledger_seq": 0, diff --git a/contracts/escrow/test_snapshots/test_unauthorized_attacker_cannot_fund_escrow.1.json b/contracts/escrow/test_snapshots/test_unauthorized_attacker_cannot_fund_escrow.1.json index a7ef2281..1dc830d3 100644 --- a/contracts/escrow/test_snapshots/test_unauthorized_attacker_cannot_fund_escrow.1.json +++ b/contracts/escrow/test_snapshots/test_unauthorized_attacker_cannot_fund_escrow.1.json @@ -234,6 +234,14 @@ "i128": "1000" } }, + { + "key": { + "symbol": "arbitration_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "buyer" @@ -324,6 +332,14 @@ ] } }, + { + "key": { + "symbol": "platform_fee_bps" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "resolver_fee_bps" diff --git a/contracts/escrow/tests/happy_path.rs b/contracts/escrow/tests/happy_path.rs index 37cdeaf8..cfb5b247 100644 --- a/contracts/escrow/tests/happy_path.rs +++ b/contracts/escrow/tests/happy_path.rs @@ -164,7 +164,10 @@ fn test_happy_path_escrow_lifecycle() { assert_eq!(escrow_completed.state, EscrowState::Completed); // 5. Assert Payout and Fee Allocation - // Amount = 10,000. Fee = 1% = 100. Seller gets 9,900. Fee collector gets 100. + // Amount = 10,000. Fee = 1% = 100. Seller gets 9,900. The protocol fee + // accrues in the contract until the collector pulls it. + client.claim_accumulated_fees(&fee_collector, &token_addr); + let seller_balance = token::Client::new(&env, &token_addr).balance(&seller); let fee_collector_balance = token::Client::new(&env, &token_addr).balance(&fee_collector); let contract_balance = token::Client::new(&env, &token_addr).balance(&contract_id); From 510f6f951d0f58c280ca9521da5c1831a167a40f Mon Sep 17 00:00:00 2001 From: Kaybee973 Date: Sat, 28 Nov 2026 16:01:38 +0000 Subject: [PATCH 6/6] chore: refresh gas baseline for the accrued-fee settlement path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The fee-accrual change adds storage writes to settlement, pushing several operations past the 5% gas gate. Record the current measurements so the regression check compares against the merged behaviour. 🤖 Generated with Codebuff Co-Authored-By: Codebuff --- contracts/escrow/gas_baseline.json | 130 +++++++++++++++-------------- 1 file changed, 69 insertions(+), 61 deletions(-) diff --git a/contracts/escrow/gas_baseline.json b/contracts/escrow/gas_baseline.json index 02b1a89a..59e2d956 100644 --- a/contracts/escrow/gas_baseline.json +++ b/contracts/escrow/gas_baseline.json @@ -1,143 +1,151 @@ { - "_comment": "Corrected per-invocation harness baseline measured on main b16ac31; set_admin includes #1233 invalidation: CPU +49.69%, memory +8.36% vs main.", + "_comment": "Gas baselines for contracts/escrow/src/test_gas_profile.rs. Regenerate with `make bench-gas-update` after an intentional change.", "appeal_dispute": { - "cpu_insns": 541433, - "mem_bytes": 192437 + "cpu_insns": 638398, + "mem_bytes": 216157 }, "approve_refund": { - "cpu_insns": 729201, - "mem_bytes": 233139 + "cpu_insns": 812693, + "mem_bytes": 244298 }, "auto_release": { - "cpu_insns": 783497, - "mem_bytes": 241473 + "cpu_insns": 856213, + "mem_bytes": 252793 }, "batch_create_escrow(10)": { - "cpu_insns": 4706587, - "mem_bytes": 1165214 + "cpu_insns": 4811967, + "mem_bytes": 1202084 + }, + "bounded_basket_read(3 tokens)": { + "cpu_insns": 237094, + "mem_bytes": 116321 + }, + "bounded_basket_write(3 tokens)": { + "cpu_insns": 717081, + "mem_bytes": 233104 }, "cancel_escrow (Pending)": { - "cpu_insns": 400025, - "mem_bytes": 131728 + "cpu_insns": 432900, + "mem_bytes": 136943 }, "co_signed_release": { - "cpu_insns": 798450, - "mem_bytes": 266823 + "cpu_insns": 860201, + "mem_bytes": 278149 }, "confirm_delivery": { - "cpu_insns": 977929, - "mem_bytes": 289450 + "cpu_insns": 934515, + "mem_bytes": 272816 }, "create_basket_escrow(3 tokens)": { - "cpu_insns": 706707, - "mem_bytes": 227080 + "cpu_insns": 717081, + "mem_bytes": 233104 }, "create_escrow": { - "cpu_insns": 531704, - "mem_bytes": 178808 + "cpu_insns": 542242, + "mem_bytes": 182495 }, "create_escrow_multi(3-of-3)": { - "cpu_insns": 524968, - "mem_bytes": 184748 + "cpu_insns": 532050, + "mem_bytes": 188212 }, "create_escrow_with_fallback": { - "cpu_insns": 511941, - "mem_bytes": 183168 + "cpu_insns": 519023, + "mem_bytes": 186632 }, "emergency_drain": { - "cpu_insns": 698874, - "mem_bytes": 242181 + "cpu_insns": 774053, + "mem_bytes": 252880 }, "ensure_action_not_paused": { "cpu_insns": 76489, "mem_bytes": 38070 }, "finalize_dispute": { - "cpu_insns": 1090984, - "mem_bytes": 340472 + "cpu_insns": 1025599, + "mem_bytes": 321714 }, "fund_escrow": { - "cpu_insns": 841675, - "mem_bytes": 264025 + "cpu_insns": 904406, + "mem_bytes": 276326 }, "get_escrow (view)": { - "cpu_insns": 184036, - "mem_bytes": 87939 + "cpu_insns": 202170, + "mem_bytes": 91794 }, "get_fee_config (view)": { "cpu_insns": 93838, "mem_bytes": 41130 }, "get_stats (view)": { - "cpu_insns": 2255866, - "mem_bytes": 537231 + "cpu_insns": 3174918, + "mem_bytes": 720684 }, "initialize": { "cpu_insns": 99902, "mem_bytes": 39735 }, "mark_shipped": { - "cpu_insns": 396144, - "mem_bytes": 134559 + "cpu_insns": 442250, + "mem_bytes": 140114 }, "multicall(fund x3)": { - "cpu_insns": 2728749, - "mem_bytes": 710827 + "cpu_insns": 2941841, + "mem_bytes": 757582 }, "mutual_cancel": { - "cpu_insns": 717662, - "mem_bytes": 230956 + "cpu_insns": 798557, + "mem_bytes": 242165 }, "pause_contract": { "cpu_insns": 164065, "mem_bytes": 56607 }, "post_message": { - "cpu_insns": 343336, - "mem_bytes": 143670 + "cpu_insns": 364124, + "mem_bytes": 147930 }, "raise_dispute": { - "cpu_insns": 517163, - "mem_bytes": 197985 + "cpu_insns": 555232, + "mem_bytes": 206844 }, "request_refund": { - "cpu_insns": 409119, - "mem_bytes": 137880 + "cpu_insns": 473358, + "mem_bytes": 147817 }, "resolve_dispute (Refund)": { - "cpu_insns": 649844, - "mem_bytes": 221531 + "cpu_insns": 631617, + "mem_bytes": 218720 }, "resolve_dispute (Release)": { - "cpu_insns": 649844, - "mem_bytes": 221531 + "cpu_insns": 630446, + "mem_bytes": 218720 }, "rotate_resolver": { - "cpu_insns": 276055, - "mem_bytes": 106877 + "cpu_insns": 296227, + "mem_bytes": 111378 }, "set_admin": { "cpu_insns": 214788, "mem_bytes": 59336 }, "set_arbitration_fee": { - "cpu_insns": 171664, - "mem_bytes": 57065 + "cpu_insns": 176940, + "mem_bytes": 57277 }, "set_fee": { - "cpu_insns": 167648, - "mem_bytes": 56464 + "cpu_insns": 172924, + "mem_bytes": 56676 }, "set_protocol_fee": { - "cpu_insns": 171664, - "mem_bytes": 57065 + "cpu_insns": 176940, + "mem_bytes": 57277 }, "unpause_contract": { - "cpu_insns": 165535, - "mem_bytes": 56863 + "cpu_insns": 170811, + "mem_bytes": 57075 }, "vote (multi-resolver, first)": { - "cpu_insns": 299009, - "mem_bytes": 134101 + "cpu_insns": 317615, + "mem_bytes": 138237 } }