Skip to content

feat(contracts): implement item durability module (#399) - #407

Open
nuvoraxis wants to merge 1 commit into
MindFlowInteractive:mainfrom
nuvoraxis:feat/399-item-durability-module
Open

nuvoraxis wants to merge 1 commit into
MindFlowInteractive:mainfrom
nuvoraxis:feat/399-item-durability-module

Conversation

@nuvoraxis

Copy link
Copy Markdown
Contributor

Summary of Changes

This pull request implements the Item Durability Module (Stage 1 of the Durability chain) for the Quest Contract ecosystem as requested in #399.

Key Features & Architecture

  • Location: contracts/item_durability
  • Item Data Model: Item struct tracks item owner, max_durability, and current_durability.
  • Item Registration: Admin-gated register_item(item_id, owner, max_durability) ensures items start initialized at full durability.
  • Gameplay Degradation: use_item(user, item_id) authenticates the owner and decrements durability by exactly 1 per use.
  • Zero-Durability Rejection: Rejects usage with ZeroDurability once an item is depleted.
  • Event Emission: Emits standard Soroban events on every use: topic: (use, item_id), data: (user, current_durability).
  • Query APIs: Zero-cost read functions get_item(item_id) and get_durability(item_id).
  • Admin Governance: Allows transferring the admin role via two-way authorized transfer_admin.
  • Unit Test Suite: Thorough test coverage in contracts/item_durability/src/test.rs verifying registration, sequential decrement by 1, zero-durability rejection, unauthorized user rejection, non-existent item handling, and admin transfers.
  • Documentation: Complete README.md detailing storage schema, error codes, events, and integration examples.

Verification

  • cargo check --package item_durability passed with 0 errors.
  • Added to root Cargo.toml workspace members.

Closes #399

…e#399)

- Add reusable Soroban smart contract in contracts/item_durability
- Implement Item structure with owner, max_durability, and current_durability
- Support admin-gated register_item function with max durability validation
- Implement use_item function: decrements durability by 1 per use
- Enforce fail-closed rejection when item durability reaches zero (ZeroDurability error)
- Verify caller authorization to ensure only the authenticated owner can use items
- Emit Soroban events on durability change: (use, item_id) -> (user, current_durability)
- Expose read functions for get_item and get_durability
- Support secure admin transfer via transfer_admin
- Add comprehensive unit test suite in src/test.rs
- Add detailed README.md documentation and workspace entry in Cargo.toml

Closes MindFlowInteractive#399
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

1 participant