Skip to content

Add collateral_swap() replacing one collateral type with another without unstaking #335

Description

@Rickyy1017

Summary

Builds on Issue #214 (NFT collateral minting). Add a function that allows a staker with an active debt NFT to swap their underlying collateral token for a different token without unstaking — useful when the staker wants to change their exposure while keeping the loan active.

Acceptance Criteria

  • CollateralSwapConfig stored per user: { debt_nft_id: u32, original_token: Address, swap_token: Address }
  • initiate_collateral_swap(user, new_stake_token: Address, min_new_amount: i128) function
  • Validates debt NFT exists and position is collateralized
  • Unstakes current token, swaps via DEX to new_stake_token, re-stakes result
  • min_new_amount is slippage protection — revert with SlippageExceeded if swap output below minimum
  • Position lock maintained throughout — debt NFT remains valid against new token
  • Debt NFT face_value updated to reflect new position amount
  • collateral_swapped event: (user, old_token, new_token, old_amount, new_amount, ledger)
  • Tests: swap executes correctly, slippage protection triggers, non-collateralized position rejected, face value updated correctly

Notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions