Skip to content

Commit d53a3c2

Browse files
authored
Merge pull request #1266 from Sundayabel222/main
newchange
2 parents 68d4eac + 0a9cb2e commit d53a3c2

3 files changed

Lines changed: 78 additions & 0 deletions

File tree

contracts/niffyinsure/src/claim.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

contracts/niffyinsure/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ impl NiffyInsure {
209209
storage::set_protocol_fee_bps(&env, 0);
210210
storage::set_fee_recipient(&env, &env.current_contract_address());
211211
storage::set_min_solvency_ratio_bps(&env, 0);
212+
storage::set_claim_filing_fee(&env, 0);
212213
storage::set_voting_duration_ledgers(&env, ledger::VOTE_WINDOW_LEDGERS);
213214
storage::set_quorum_bps(&env, types::DEFAULT_QUORUM_BPS);
214215
admin::emit_admin_action(&env, &admin, "initialize");
@@ -863,6 +864,19 @@ impl NiffyInsure {
863864
results
864865
}
865866

867+
/// Admin-only: set the flat fee (stroops) charged to the claimant at file_claim.
868+
/// 0 = disabled. Fee is transferred to the treasury before claim creation.
869+
pub fn admin_set_claim_filing_fee(env: Env, fee: i128) {
870+
let _admin = admin::require_admin(&env);
871+
storage::bump_instance(&env);
872+
storage::set_claim_filing_fee(&env, fee);
873+
}
874+
875+
/// Read-only: the current claim filing fee. 0 = disabled.
876+
pub fn get_claim_filing_fee(env: Env) -> i128 {
877+
storage::get_claim_filing_fee(&env)
878+
}
879+
866880
pub fn get_policy_counter(env: Env, holder: Address) -> u32 {
867881
storage::get_policy_counter(&env, &holder)
868882
}

contracts/niffyinsure/src/storage.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ pub enum DataKey {
205205
WhitelistEnabled,
206206
/// Per-address whitelist entry for KYC compliance gating.
207207
Whitelisted(Address),
208+
/// Optional flat fee (stroops) charged to the claimant at file_claim.
209+
/// 0 = disabled. Transferred directly to the treasury before claim creation.
210+
ClaimFilingFee,
208211
// ── Appeal mechanism (Issue #1) ───────────────────────────────────────────
209212
/// Voter snapshot for an appeal round (separate from the base-claim snapshot).
210213
AppealVoters(u64),
@@ -1171,6 +1174,24 @@ pub fn get_max_weight_cap(env: &Env) -> i128 {
11711174
.unwrap_or(i128::MAX)
11721175
}
11731176

1177+
// ── Claim filing fee (instance) ────────────────────────────────────────────
1178+
1179+
/// Set the flat fee (stroops) charged to the claimant at file_claim.
1180+
/// 0 = disabled. Fee is transferred to the treasury before claim creation.
1181+
pub fn set_claim_filing_fee(env: &Env, fee: i128) {
1182+
env.storage()
1183+
.instance()
1184+
.set(&DataKey::ClaimFilingFee, &fee);
1185+
}
1186+
1187+
/// Get the current claim filing fee. Defaults to 0 (disabled) when unset.
1188+
pub fn get_claim_filing_fee(env: &Env) -> i128 {
1189+
env.storage()
1190+
.instance()
1191+
.get(&DataKey::ClaimFilingFee)
1192+
.unwrap_or(0)
1193+
}
1194+
11741195
// ── Per-policy cooldown (persistent) ─────────────────────────────────────────
11751196

11761197
/// Record the ledger at which the last claim for `(holder, policy_id)` was resolved.

0 commit comments

Comments
 (0)