Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,705 changes: 1,315 additions & 390 deletions contracts/claims-processor/src/lib.rs

Large diffs are not rendered by default.

1,840 changes: 1,231 additions & 609 deletions contracts/claims-processor/src/test.rs

Large diffs are not rendered by default.

183 changes: 181 additions & 2 deletions contracts/claims-processor/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ pub struct Claim {
/// For PartiallyPaid claims: payout ratio in basis points (0-10000).
/// 10000 = full coverage; lower = proportional partial payment.
pub partial_payout_bps: Option<u32>,
/// Installment payout configuration for large claims.
pub installments: Option<InstallmentSchedule>,
/// Installment payout configuration for large claims. `Vec` instead of
/// `Option<InstallmentSchedule>` because the soroban-sdk XDR (`ScVal`)
/// conversion generated for a contracttype struct does not support
/// `Option<CustomStruct>` fields — only `Vec<T>` round-trips a custom
/// struct through both the WASM `Val` path and the host-side `ScVal`
/// path used by test tooling. Empty = no installment schedule.
pub installments: Vec<InstallmentSchedule>,
/// Whether the claimant's identity was verified (optional, for Sybil protection).
pub identity_verified: bool,
/// Type of identity verification performed (e.g., "kyc", "accreditation").
Expand Down Expand Up @@ -195,3 +200,177 @@ pub struct ContractUpgraded {
pub old_version: u32,
pub new_version: u32,
}

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct GuardiansUpdated {
pub guardians: Vec<Address>,
pub threshold: u32,
}

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct UpgradeApproved {
pub new_wasm_hash: BytesN<32>,
pub approver: Address,
pub approvals: u32,
pub threshold: u32,
}

/// A pending contract-upgrade action awaiting guardian approvals.
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PendingUpgrade {
pub new_wasm_hash: BytesN<32>,
pub new_version: u32,
pub approvals: Vec<Address>,
}

/// A pending admin-transfer proposal awaiting guardian approvals.
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PendingAdminChange {
pub new_admin: Address,
pub approvals: Vec<Address>,
}

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AdminUpdated {
pub new_admin: Address,
}

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct CrossChainAttestation {
/// Which chain this observation came from.
pub chain_id: Symbol,
/// The registered attestor that submitted it.
pub attestor: Address,
/// The observed value, in the same fixed-point units as
/// `Policy.trigger_threshold`.
pub observed_value: i128,
/// Hash of the off-chain proof (light-client proof, relayer message,
/// oracle report) backing `observed_value`. Opaque to the contract —
/// kept for audit/dispute purposes, not verified on-chain.
pub proof_hash: BytesN<32>,
/// Unix timestamp of the observation.
pub timestamp: u64,
}

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct CrossChainAttestorAdded {
pub chain_id: Symbol,
pub attestor: Address,
}

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct CrossChainAttestorRemoved {
pub chain_id: Symbol,
pub attestor: Address,
}

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct CrossChainAttestationSubmitted {
pub policy_id: u128,
pub chain_id: Symbol,
pub attestor: Address,
pub observed_value: i128,
pub timestamp: u64,
}

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct InstallmentPayoutScheduled {
pub claim_id: u128,
pub policy_id: u128,
pub claimant: Address,
pub total_amount: i128,
pub num_installments: u32,
pub interval_seconds: u64,
pub first_installment_at: u64,
}

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct InstallmentPaid {
pub claim_id: u128,
pub claimant: Address,
pub amount: i128,
pub paid_count: u32,
pub total_installments: u32,
}

/// Emitted when the payout delay configuration is updated.
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PayoutDelayUpdated {
pub delay_seconds: u64,
}

/// Supported payout currencies for claim settlements.
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum PayoutCurrency {
/// Default USDC (7-decimal)
USDC,
/// Alternative stablecoin (address stored separately)
Custom(Address),
}

/// Multi-currency payout configuration for a claim.
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PayoutOption {
/// Currency to pay out in.
pub currency: PayoutCurrency,
/// Exchange rate (basis points) relative to USDC. 10000 = 1:1 parity.
/// Used to convert USDC coverage amounts to equivalent other-currency amounts.
pub exchange_rate_bps: u32,
/// Whether this payout option is currently enabled.
pub enabled: bool,
}

/// Record of available payout currencies and their exchange rates.
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PayoutCurrencyRegistry {
/// Address of the USDC token contract (default payout currency).
pub usdc_token: Address,
/// Optional alternative payout currencies with their exchange rates.
pub alt_currencies: Vec<Address>,
/// Exchange rates for alt currencies (index matches alt_currencies).
pub exchange_rates_bps: Vec<u32>,
}

/// Emitted when a new payout currency is registered.
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PayoutCurrencyAdded {
pub token: Address,
pub exchange_rate_bps: u32,
}

/// Emitted when a payout currency's exchange rate is updated.
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PayoutCurrencyRateUpdated {
pub token: Address,
pub old_rate_bps: u32,
pub new_rate_bps: u32,
}

/// Emitted when a claim is paid out in an alternate currency.
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ClaimPaidInAlternativeCurrency {
pub claim_id: u128,
pub claimant: Address,
pub usdc_equivalent: i128,
pub token: Address,
pub actual_amount: i128,
pub exchange_rate_bps: u32,
}
Loading