Skip to content

Implement CollateralValuation trait for multi-asset solver bonds#16

Open
zmanian wants to merge 5 commits into
mainfrom
collateral-valuation-trait
Open

Implement CollateralValuation trait for multi-asset solver bonds#16
zmanian wants to merge 5 commits into
mainfrom
collateral-valuation-trait

Conversation

@zmanian
Copy link
Copy Markdown
Contributor

@zmanian zmanian commented Jan 5, 2026

Summary

This PR implements the CollateralValuation trait system that unifies support for multiple collateral types as solver bonds:

  • Native tokens (ATOM) - 0% haircut, direct valuation
  • LSM shares - 10% haircut, covers slashing risk with 1:1 valuation
  • Hydro vault shares - 20% haircut, ratio-based valuation via pool info queries

Key features:

  • Unified trait interface for all collateral types
  • Fixed haircuts per asset class (configurable constants)
  • Cross-chain valuation support with ICQ caching and 1-hour staleness limit
  • Intent-based liquidation flow for converting seized collateral to ATOM
  • Bond pool management with per-settlement 1.5x locking

Changes

Core Types (crates/types/)

  • collateral.rs - Core collateral types, bond pools, liquidation intents
  • valuation.rs - CollateralValuation trait and implementations

Settlement Contract (contracts/settlement/)

  • Integrated bond pool storage and management
  • Per-settlement 1.5x collateral locking
  • Collateral deposit/withdraw handlers
  • Slashing with intent-based liquidation for non-ATOM collateral
  • Pool info caching for Hydro vault valuations
  • Liquidation auction handlers (bid, execute, cancel)

Related

Test plan

  • All 86 core contract tests passing
  • 30 new collateral integration tests
  • Tests for collateral types, haircuts, and valuations
  • Tests for settlement flow with collateral locking/unlocking
  • Tests for slashing and liquidation creation

🤖 Generated with Claude Code

zmanian and others added 5 commits January 5, 2026 10:34
Adds a unified system for accepting multiple collateral types as solver bonds:

## New Types (collateral.rs)
- CollateralAsset enum: Native, LsmShare, HydroVault
- AssetClass with fixed haircuts: Native 0%, LSM 10%, Hydro 20%
- SolverBondPool with multi-asset deposit support
- CollateralDeposit with lock/unlock for per-settlement locking
- LiquidationIntent and LiquidationBid for intent-based liquidation
- Helper functions: apply_haircut, reverse_haircut, calculate_lock_requirement

## Valuation Trait (valuation.rs)
- CollateralValuation trait with get_raw_value, get_collateral_value, haircut_bps
- NativeValuation: 1:1 for uatom, rejects other denoms
- LsmShareValuation: 1:1 with 10% haircut covering slashing risk
- HydroVaultValuation: ratio-based using ControlCenterPoolInfo
  - Same-chain: direct contract query
  - Cross-chain: cached ICQ with staleness check (1 hour max)
- create_valuation factory function
- Bond pool valuation helpers

## Tests
- 19 new unit tests covering all collateral types
- Haircut calculations, staleness checks, lock/unlock operations
- All 88 tests pass

Implements design from docs/plans/2026-01-05-collateral-valuation-trait.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This integrates the CollateralValuation trait and bond pool management into the settlement contract:

Execute handlers:
- DepositCollateral: Deposit collateral to solver's bond pool
- WithdrawCollateral: Withdraw unlocked collateral from bond pool
- UpdatePoolInfo: Cache pool info for cross-chain Hydro vaults (via ICQ)
- BidOnLiquidation: Submit bid on a liquidation intent
- ExecuteLiquidation: Settle winning bid and transfer collateral
- CancelLiquidation: Cancel expired liquidation (admin only)

Settlement flow integration:
- CreateSettlement now locks 1.5x collateral from solver's bond pool
- MarkCompleted now unlocks the collateral
- SlashSolver now seizes collateral and creates liquidation intent for
  non-native assets (LSM shares, Hydro vault shares)

Query handlers:
- BondPool: Query solver's bond pool deposits
- CollateralValue: Query total value after haircuts
- AvailableCollateral: Query unlocked collateral value
- Liquidation: Query liquidation intent details
- PendingLiquidations: List active liquidations
- CachedPoolInfo: Query Hydro vault pool info

Key features:
- Per-settlement 1.5x collateral locking (vs old fixed bond system)
- Multi-asset support (Native ATOM, LSM shares, Hydro vault shares)
- Fixed haircuts per asset class (0% native, 10% LSM, 20% Hydro)
- Intent-based liquidation for non-liquid collateral
- Backwards compatibility with legacy fixed bond system

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add comprehensive collateral_tests.rs with 30 tests covering:
  - Collateral deposits (native, LSM, multiple types)
  - Withdrawal permissions and limits
  - Per-settlement collateral locking
  - Settlement completion unlocking
  - Slashing and liquidation creation
  - Pool info caching and staleness
  - Liquidation auctions (bid, execute, cancel)

- Update existing tests to work with new per-settlement locking:
  - Add deposit_collateral helper function
  - Modify register_solver to also deposit collateral
  - Update test_slash_solver_success to verify bond pool behavior

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- cancellation.rs: Remove empty line between doc comments
- handlers.rs: Allow too_many_arguments for execute_create_settlement
- helpers.rs: Combine identical if blocks in speed_score calculation
- adversarial_settlement_tests.rs:
  - Convert outer doc comments to inner doc comments
  - Remove unused imports (from_json, query, QueryMsg, SettlementResponse)
  - Prefix unused result variables with underscore
  - Add #[allow(dead_code)] to fake_solver field
  - Add collateral deposit to register_solver helper

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant