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
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
src/lock.rs(orlib.rsif centralized)storage_types.rsfor Lock Save:LockSave(u64)→ maps lock plan ID to LockSave structUserLockSaves(Address)→ maps user to a list of their LockSave IDsNextLockId→ stores the next auto-incrementing LockSave IDLockSavestruct with#[contracttype]:id: u64owner: Addressamount: i128interest_rate: u32start_time: u64maturity_time: u64is_withdrawn: boolcreate_lock_save(env: &Env, user: Address, amount: i128, duration: u64) -> Result<u64, SavingsError>:amount > 0andduration > 0lock_idusingNextLockIdstart_timeto current ledger timestampmaturity_time = start_time + durationlock_idtoUserLockSavescheck_matured_lock(env: &Env, lock_id: u64) -> bool:maturity_timecheck_matured_lockreturns correct booleanAcceptance Criteria
make build