Skip to content

feat: Implement core storage data structures for savings contract#19

Merged
Devsol-01 merged 15 commits intoDevsol-01:mainfrom
pope-h:feature/savings-contract-data-structure
Jan 22, 2026
Merged

feat: Implement core storage data structures for savings contract#19
Devsol-01 merged 15 commits intoDevsol-01:mainfrom
pope-h:feature/savings-contract-data-structure

Conversation

@pope-h
Copy link
Copy Markdown
Contributor

@pope-h pope-h commented Jan 21, 2026

Description

This PR implements the core data structures for the Nestera savings contract as defined in the project requirements. These structures support all four savings plan types and are fully compatible with Soroban XDR types.

Changes Made

New Files

  • src/storage_types.rs: Core data structure definitions

Modified Files

  • src/lib.rs: Added storage_types module import
  • src/test.rs: Comprehensive unit tests for all data structures

Data Structures Implemented

1. PlanType Enum

  • Flexi - Instant liquidity savings
  • Lock(u64) - Time-locked savings with unlock timestamp
  • Goal(Symbol, i128, u32) - Goal-based savings with category, target amount, and contribution type
  • Group(u64, bool, u32, i128) - Group savings with ID, visibility, contribution type, and target

2. SavingsPlan Struct

  • Contains: plan_id, plan_type, balance, timestamps, interest_rate, completion status
  • Tracks all savings operations per plan

3. User Struct

  • Aggregates: total_balance, savings_count
  • Provides user-level overview

4. DataKey Enum

  • Admin - Admin address storage
  • User(Address) - User data mapping
  • SavingsPlan(Address, u64) - Plan data mapping

Testing

Test Coverage

  • ✅ 13 unit tests implemented
  • ✅ All tests passing
  • ✅ XDR compatibility verified for all types
  • ✅ Storage operations tested with contract context

Test Results

running 13 tests
test test::test_completed_plan ... ok
test test::test_data_key_admin ... ok
test test::test_data_key_savings_plan ... ok
test test::test_data_key_user ... ok
test test::test_flexi_savings_plan ... ok
test test::test_goal_savings_plan ... ok
test test::test_group_savings_plan ... ok
test test::test_lock_savings_plan ... ok
test test::test_plan_type_patterns ... ok
test test::test_user_instantiation ... ok
test test::test_xdr_compatibility_all_plan_types ... ok
test test::test_xdr_compatibility_savings_plan ... ok
test test::test_xdr_compatibility_user ... ok

test result: ok. 13 passed; 0 failed

Build Status

  • ✅ Contract builds successfully
  • ✅ Wasm output: 1254 bytes
  • ✅ No compilation errors

Technical Decisions

Why u32 instead of u8 for contribution_type?

Soroban XDR only supports u32, u64, u128, i32, i64, and i128. Smaller integer types like u8 are not supported.

Why tuple variants instead of named fields in enums?

Soroban's #[contracttype] macro doesn't support named fields in enum variants. Tuple variants are the standard approach.

Definition of Done

  • ✅ PlanType, SavingsPlan, User, and DataKey defined with #[contracttype]
  • ✅ Structs and enums compile successfully in Soroban
  • ✅ Unit tests instantiate User and SavingsPlan
  • ✅ XDR compatibility verified
  • ✅ Contract builds successfully with make build

Related Issues

Closes #2

Checklist

  • Code follows Rust/Soroban best practices
  • All tests pass locally
  • Contract builds without errors
  • Documentation comments added
  • XDR compatibility verified

Screenshots/Evidence

make build
✅ Build Complete

make test
test result: ok. 13 passed; 0 failed
NesteraSS

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.

# Define Data Structures for Savings Contract

2 participants