Skip to content

# Implement Lock save function #9

@Devsol-01

Description

@Devsol-01

Description

Implement the core Lock Save functionality. Lock Save allows users to deposit funds for a fixed duration. Users can only withdraw after the lock period has matured. This issue focuses on creating, tracking, and maturing Lock Save plans.

Tasks

  • Create or edit src/lock.rs (or lib.rs if centralized)
  • Define storage keys in storage_types.rs for Lock Save:
    • LockSave(u64) → maps lock plan ID to LockSave struct
    • UserLockSaves(Address) → maps user to a list of their LockSave IDs
    • NextLockId → stores the next auto-incrementing LockSave ID
  • Define LockSave struct with #[contracttype]:
    • id: u64
    • owner: Address
    • amount: i128
    • interest_rate: u32
    • start_time: u64
    • maturity_time: u64
    • is_withdrawn: bool
  • Implement create_lock_save(env: &Env, user: Address, amount: i128, duration: u64) -> Result<u64, SavingsError>:
    • Validate amount > 0 and duration > 0
    • Ensure user exists
    • Assign unique lock_id using NextLockId
    • Set start_time to current ledger timestamp
    • Set maturity_time = start_time + duration
    • Store the LockSave in storage
    • Add lock_id to UserLockSaves
  • Implement check_matured_lock(env: &Env, lock_id: u64) -> bool:
    • Returns true if current timestamp >= maturity_time
  • Add unit tests to verify:
    • Users can create Lock Save plans
    • LockSave stores correct start and maturity times
    • check_matured_lock returns correct boolean

Acceptance Criteria

  • Lock Save creation stores plans correctly in blockchain storage
  • Auto-generated LockSave IDs are unique
  • LockSave maturation is correctly calculated
  • Unit tests cover creation and maturation logic
  • Contract builds successfully with make build

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions