Skip to content

core: socialize default losses to pool share price on liquidation #59

Description

@EmeditWeb

Problem

When a loan defaults, mark_defaulted() (lib.rs:486-558) forwards only the
forfeited guarantee_amount to the pool via receive_guarantee(). The
unrecovered shortfall (remaining_balance - guarantee_amount) is never
written down
from the pool. locked_liquidity and total_liquidity still
reflect the full outstanding principal, so get_share_price() reports a
value the pool cannot actually pay out. LPs who withdraw first are made
whole at the expense of those who withdraw last — the loss is not socialized.

Before Starting

Read ALL of these before writing any code:

  • context/architecture-context.md
  • context/code-standards.md
  • context/progress-tracker.md

What To Build

Loss socialization on default so share price honestly reflects realized losses:

  1. Add a pool entrypoint (e.g. absorb_loss(creditline, principal_shortfall))
    callable only by the registered CreditLine, that reduces both
    locked_liquidity and total_liquidity by the unrecovered principal.
  2. In mark_defaulted(), after applying the guarantee, compute the shortfall
    and call the new entrypoint so the write-down hits share price immediately.
  3. Guard against negative liquidity and double-application; keep CEI ordering
    and the non-reentrant guard.

Files To Touch

  • contracts/liquidity-pool-contract/src/lib.rs (new loss-absorption fn)
  • contracts/liquidity-pool-contract/src/events.rs
  • contracts/creditline-contract/src/lib.rs (mark_defaulted)
  • both contracts' tests.rs

Acceptance Criteria

  • Default reduces pool total_liquidity by the unrecovered principal
  • get_share_price() drops to a value the pool can actually pay
  • Guarantee recovery still applied and nets against the shortfall
  • New entrypoint restricted to the registered CreditLine contract
  • Loss-socialization event emitted; tests assert share price before/after

Mandatory Checks Before Opening PR

  • All context/ files read and understood
  • context/progress-tracker.md updated
  • cargo build passes with zero errors
  • cargo test passes — test count not decreased
  • require_auth() first in every mutating function
  • extend_ttl() after every persistent storage write
  • No .unwrap()/.expect() in user-facing paths
  • PR references this issue number

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions