Skip to content

feat(contracts): implement item durability system with repair and salvage (#400, #401) - #413

Closed
nuvoraxis wants to merge 1 commit into
MindFlowInteractive:mainfrom
nuvoraxis:feat/400-401-item-durability-repair-salvage
Closed

nuvoraxis wants to merge 1 commit into
MindFlowInteractive:mainfrom
nuvoraxis:feat/400-401-item-durability-repair-salvage

Conversation

@nuvoraxis

Copy link
Copy Markdown

Summary of Changes

This Pull Request provides a comprehensive, production-grade Soroban smart contract for the Item Durability lifecycle across Stages 1, 2, and 3, fulfilling all acceptance criteria for both #400 and #401:

  1. Durability Usage & Break State (Stage 1 & 3):

    • Implements Item entity tracking owner, max_durability, current_durability, and is_broken status.
    • use_item: decrements durability by 1 per use with owner authentication.
    • Automatically marks item as broken when durability reaches zero and publishes a (broken, item_id) event.
    • Enforces fail-closed rejection when attempting to use broken or zero-durability items (ZeroDurability error).
  2. Repair with Token Payment Sink (Stage 2 - Item Durability: Repair #400):

    • repair_item: allows item owner to restore missing durability by paying tokens.
    • Repair cost strictly adheres to proportional formula: cost = units_to_repair * cost_per_unit.
    • Durability is capped at max_durability.
    • Payment is routed directly to the designated sink_address via soroban_sdk::token::Client.
    • Rejects repair attempts on broken items (ItemBroken error).
  3. Break & Salvage Material Payout (Stage 3 - Item Durability: Break and Salvage #401):

    • salvage_item: allows owner to salvage broken items for configured material payout tokens.
    • Destroys item persistent storage record upon salvage to prevent double-salvaging.
    • Enforces that non-broken items cannot be salvaged (ItemNotBroken error).
  4. Testing & Tooling:

    • Comprehensive unit test suite in src/test.rs (6/6 passing tests covering usage, breakage, repair calculations, cap enforcement, sink routing, salvage payouts, and authorization).
    • Clean workspace integration in root Cargo.toml.
    • Detailed architectural documentation in contracts/item_durability/README.md.

Closes #400
Closes #401

…vage (MindFlowInteractive#400, MindFlowInteractive#401)

- Add modular Soroban smart contract in contracts/item_durability
- Implement Item structure with owner, max_durability, current_durability, and is_broken state
- Implement use_item function: decrements durability by 1, marks broken and emits broken event upon reaching zero
- Implement repair_item function: allows owner to restore durability via token payment to designated sink address
- Enforce repair cost formula proportional to restored durability and cap at max_durability
- Block repair of broken items to enforce item lifecycle integrity
- Implement salvage_item function: allows owner to salvage broken items for configured material payout tokens
- Destroy item record upon salvage to prevent double-salvaging
- Add full unit test suite in src/test.rs covering usage, breakage, repair calculations, caps, sink routing, and salvage lifecycle
- Add detailed README.md documentation and workspace entry in Cargo.toml

Closes MindFlowInteractive#400
Closes MindFlowInteractive#401
@Mkalbani Mkalbani closed this Nov 22, 2026
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.

Item Durability: Break and Salvage Item Durability: Repair

2 participants