@@ -19,58 +19,38 @@ mod tiers;
1919mod types;
2020mod upgrade;
2121mod proxy;
22+ mod insurance;
2223
2324use soroban_sdk:: { contract, contractimpl, token:: TokenClient , Address , BytesN , Env } ;
2425
2526pub use errors:: ContractError ;
2627pub use types:: {
27- ArbitrationConfig , DisclosureGrant , DisputeResolution , Proposal , ProposalAction ,
28- ArbitrationConfig , ArbitratorVote , DisclosureGrant , DisputeResolution , MultiSigConfig ,
29- Proposal , ProposalAction , ProposalStatus , Subscription , SubscriptionTier , TierConfig ,
30- TemplateTerms , TemplateVersion , Trade , TradePrivacy , TradeStatus , TradeTemplate ,
31- UserTier , UserTierInfo , VotingSummary ,
32- ArbitratorReputation , DisclosureGrant , DisputeResolution , Proposal , ProposalAction ,
33- ProposalStatus , Subscription , SubscriptionTier , TierConfig , TemplateTerms , TemplateVersion ,
34- Trade , TradePrivacy , TradeStatus , TradeTemplate , UserTier , UserTierInfo ,
28+ ArbitrationConfig , ArbitratorReputation , ArbitratorVote , CrossChainInfo , DisclosureGrant ,
29+ DisputeResolution , InsurancePolicy , MultiSigConfig , Proposal , ProposalAction , ProposalStatus ,
30+ Subscription , SubscriptionTier , TierConfig , TemplateTerms , TemplateVersion , Trade ,
31+ TradePrivacy , TradeStatus , TradeTemplate , UserTier , UserTierInfo , VotingSummary ,
3532} ;
3633pub use queries:: { PageParams , SortDirection , TradeFilter , TradeSortField , TradeStats } ;
3734pub use oracle:: { OracleEntry , PriceData , PriceValidation } ;
3835pub use bridge:: { BridgeProvider , CrossChainTrade , BridgeAttestation , BridgeValidation } ;
3936pub use upgrade:: { RollbackSnapshot , UpgradeProposal } ;
4037pub use proxy:: * ;
4138
42- use storage:: {
43- get_accumulated_fees, get_admin, get_fee_bps, get_trade, get_usdc_token,
44- has_arbitrator, has_initialized, increment_trade_counter, is_initialized, is_paused,
45- remove_arbitrator, save_arbitrator, save_trade, set_accumulated_fees, set_admin, set_fee_bps,
46- ArbitratorReputation , DisputeResolution , TierConfig , TemplateTerms ,
47- TemplateVersion , Trade , TradeStatus , TradeTemplate , UserTier , UserTierInfo ,
48- } ;
49-
50- use storage:: {
51- get_accumulated_fees, get_admin, get_fee_bps, get_trade, get_trade_counter, get_usdc_token,
52- has_arbitrator, has_initialized, has_rated, increment_trade_counter, is_initialized, is_paused,
53- mark_rated, remove_arbitrator, save_arbitrator, save_arbitrator_reputation, save_trade,
54- set_accumulated_fees, set_admin, set_fee_bps, set_initialized, set_paused, set_trade_counter,
55- set_usdc_token,
56- CrossChainInfo , DisputeResolution , InsurancePolicy ,
57- TierConfig , TemplateTerms , TemplateVersion , Trade , TradeStatus ,
58- TradeTemplate , UserTier , UserTierInfo ,
59- } ;
60-
6139use storage:: {
6240 add_accumulated_fees, get_accumulated_fees, get_admin, get_currency_fees, get_fee_bps,
63- get_trade, get_trade_counter, get_usdc_token, has_arbitrator, has_initialized, has_rated,
64- increment_trade_counter, is_initialized, is_paused, mark_rated, remove_arbitrator,
65- save_arbitrator, save_arbitrator_reputation, save_trade, set_accumulated_fees, set_admin,
66- set_currency_fees, set_fee_bps, set_initialized, set_paused, set_trade_counter,
67- set_usdc_token, CrossChainInfo , InsurancePolicy ,
41+ get_insurance_policy, get_trade, get_trade_counter, get_usdc_token, has_arbitrator,
42+ has_initialized, has_insurance_provider, has_rated, increment_trade_counter, is_initialized,
43+ is_paused, mark_rated, remove_arbitrator, remove_insurance_provider, save_arbitrator,
44+ save_arbitrator_reputation, save_insurance_policy, save_insurance_provider, save_trade,
45+ set_accumulated_fees, set_admin, set_currency_fees, set_fee_bps, set_initialized,
46+ set_paused, set_trade_counter, set_usdc_token,
6847} ;
6948
7049fn token_client < ' a > ( env : & ' a Env , token : & Address ) -> token:: Client < ' a > {
7150 token:: Client :: new ( env, token)
7251}
7352
53+
7454/// Maximum length of JSON metadata string
7555pub const MAX_METADATA_SIZE : usize = 1024 ;
7656
@@ -321,6 +301,9 @@ impl StellarEscrowContract {
321301 let resolution = multisig:: resolve_expired_dispute ( & env, trade_id, & admin) ?;
322302 let trade = get_trade ( & env, trade_id) ?;
323303 StellarEscrowContract :: execute_dispute_resolution ( env, trade_id, resolution, trade)
304+ }
305+
306+ // -------------------------------------------------------------------------
324307 // Arbitrator Reputation
325308 // -------------------------------------------------------------------------
326309
@@ -668,6 +651,8 @@ impl StellarEscrowContract {
668651 events:: emit_trade_funded ( & env, trade_id) ;
669652 analytics:: on_trade_funded ( & env) ;
670653 Ok ( ( ) )
654+ }
655+
671656 pub fn complete_trade ( env : Env , trade_id : u64 ) -> Result < ( ) , ContractError > {
672657 require_initialized ( & env) ?;
673658 require_not_paused ( & env) ?;
@@ -712,6 +697,8 @@ impl StellarEscrowContract {
712697 events:: emit_trade_confirmed ( & env, trade_id, payout, trade. fee ) ;
713698 analytics:: on_trade_completed ( & env, trade. fee ) ;
714699 Ok ( ( ) )
700+ }
701+
715702 pub fn raise_dispute ( env : Env , trade_id : u64 , caller : Address ) -> Result < ( ) , ContractError > {
716703 if !is_initialized ( & env) {
717704 return Err ( ContractError :: NotInitialized ) ;
@@ -758,6 +745,8 @@ impl StellarEscrowContract {
758745 events:: emit_dispute_raised ( & env, trade_id, caller) ;
759746 analytics:: on_trade_disputed ( & env) ;
760747 Ok ( ( ) )
748+ }
749+
761750 /// Use `DisputeResolution::Partial { buyer_bps }` for a split:
762751 /// `buyer_bps` is the buyer's share of the net payout in basis points (0–10000).
763752 pub fn resolve_dispute (
@@ -938,7 +927,10 @@ impl StellarEscrowContract {
938927 save_trade ( & env, trade_id, & trade) ;
939928 events:: emit_trade_cancelled ( & env, trade_id) ;
940929 analytics:: on_trade_cancelled ( & env) ;
941- Ok ( ( ) ) : anyone can call this once the expiry has
930+ Ok ( ( ) )
931+ }
932+
933+ /// Claim time release — anyone can call this once the expiry has
942934 /// passed and the trade is Funded or Completed (not Disputed/Cancelled).
943935 /// Funds are released to the seller minus the platform fee.
944936 pub fn claim_time_release ( env : Env , trade_id : u64 ) -> Result < ( ) , ContractError > {
@@ -1119,14 +1111,6 @@ impl StellarEscrowContract {
11191111 }
11201112
11211113 /// Emergency withdrawal of all contract token balance (admin only).
1122- pub fn emergency_withdraw ( env : Env , to : Address ) -> Result < ( ) , ContractError > {
1123- if !is_initialized ( & env) {
1124- return Err ( ContractError :: NotInitialized ) ;
1125- }
1126- let admin = get_admin ( & env) ?;
1127- admin. require_auth ( ) ;
1128- let token = get_usdc_token ( & env) ?;
1129- let token_client = token:: Client :: new ( & env, & token) ;
11301114 /// Allowed even while paused so funds can always be recovered.
11311115 pub fn emergency_withdraw ( env : Env , to : Address ) -> Result < ( ) , ContractError > {
11321116 require_initialized ( & env) ?;
0 commit comments