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:
- 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.
- In
mark_defaulted(), after applying the guarantee, compute the shortfall
and call the new entrypoint so the write-down hits share price immediately.
- 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
Mandatory Checks Before Opening PR
Problem
When a loan defaults,
mark_defaulted()(lib.rs:486-558) forwards only theforfeited
guarantee_amountto the pool viareceive_guarantee(). Theunrecovered shortfall (
remaining_balance - guarantee_amount) is neverwritten down from the pool.
locked_liquidityandtotal_liquiditystillreflect the full outstanding principal, so
get_share_price()reports avalue 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:
What To Build
Loss socialization on default so share price honestly reflects realized losses:
absorb_loss(creditline, principal_shortfall))callable only by the registered CreditLine, that reduces both
locked_liquidityandtotal_liquidityby the unrecovered principal.mark_defaulted(), after applying the guarantee, compute the shortfalland call the new entrypoint so the write-down hits share price immediately.
and the non-reentrant guard.
Files To Touch
mark_defaulted)Acceptance Criteria
total_liquidityby the unrecovered principalget_share_price()drops to a value the pool can actually payMandatory Checks Before Opening PR