@@ -150,6 +150,22 @@ struct ClaimFiled {
150150 pub evidence_hashes : Vec < BytesN < 32 > > ,
151151}
152152
153+ /// Emitted when a claim filing fee is collected from the claimant.
154+ ///
155+ /// Topic layout: ["niffyinsure", "claim_fee_collected", claim_id]
156+ /// Data: { fee_amount, payer, at_ledger }
157+ #[ contractevent( topics = [ "niffyinsure" , "claim_fee_collected" ] ) ]
158+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
159+ pub struct ClaimFeeCollected {
160+ #[ topic]
161+ pub claim_id : u64 ,
162+ /// Fee amount collected (stroops).
163+ pub fee_amount : i128 ,
164+ /// Address that paid the fee (the claimant).
165+ pub payer : Address ,
166+ pub at_ledger : u32 ,
167+ }
168+
153169/// Emitted when the claimant withdraws before any vote is cast.
154170///
155171/// Topic layout: ["niffyinsure", "claim_withdrawn", claim_id]
@@ -326,6 +342,33 @@ pub fn file_claim(
326342 let voting_deadline_ledger = now. checked_add ( duration) . ok_or ( Error :: Overflow ) ?;
327343
328344 let claim_id = storage:: next_claim_id ( env) ?;
345+
346+ // ── Claim filing fee ─────────────────────────────────────────────────────
347+ //
348+ // If a non-zero filing fee is configured, collect it from the claimant
349+ // before creating (persisting) the claim. The fee is transferred to the
350+ // treasury. If allowance is insufficient, the claim is rejected and
351+ // claim_id is NOT consumed (next_claim_id already bumped; this is
352+ // acceptable for auditability — gap claim_ids are harmless).
353+ let filing_fee = storage:: get_claim_filing_fee ( env) ;
354+ if filing_fee > 0 {
355+ let token_client = soroban_sdk:: token:: TokenClient :: new ( env, & policy. asset ) ;
356+ let allowance = token_client. allowance ( holder, & env. current_contract_address ( ) ) ;
357+ if allowance < filing_fee {
358+ return Err ( Error :: InsufficientAllowanceForFee ) ;
359+ }
360+
361+ crate :: token:: collect_premium ( env, holder, & policy. asset , filing_fee) ;
362+
363+ ClaimFeeCollected {
364+ claim_id,
365+ fee_amount : filing_fee,
366+ payer : holder. clone ( ) ,
367+ at_ledger : now,
368+ }
369+ . publish ( env) ;
370+ }
371+
329372 let mut status_history: Vec < ClaimStatusHistoryEntry > = Vec :: new ( env) ;
330373 push_status_transition ( & mut status_history, ClaimStatus :: Processing , now) ;
331374 storage:: snapshot_claim_voters ( env, claim_id) ;
0 commit comments