Skip to content

fixed all issues - #269

Merged
ritaifeoluwa merged 2 commits into
SmartDropLabs:mainfrom
Dev-Ben-Theo:feat/251-252-253-254
Aug 29, 2026
Merged

fixed all issues#269
ritaifeoluwa merged 2 commits into
SmartDropLabs:mainfrom
Dev-Ben-Theo:feat/251-252-253-254

Conversation

@Dev-Ben-Theo

Copy link
Copy Markdown
Contributor

closes #251
closes #252
closes #253
closes #254

SUMMARY:
251
Changes Made

  1. types.rs — DataKey & struct fixes
    Added 4 new DataKey variants (L118-L125):

TotalDeposits — running total of all tokens deposited (stake + lock)
TotalWithdrawals — running total of all tokens withdrawn (unstake + unlock + emergency)
TotalCredits — was already referenced in lib.rs but missing from enum
EmergencyWithdrawalCount — was already referenced in lib.rs but missing from enum
Fixed misplaced TotalCredits field inside ListWhitelistedResponse struct (L128-L136).

  1. lib.rs — Core logic
    Added helper functions (L342-L390):

add_total_credits() — fills the missing function referenced by checkpoint_position()
read_total_deposits() / add_total_deposits() — read/increment deposit aggregate
read_total_withdrawals() / add_total_withdrawals() — read/increment withdrawal aggregate
Initialize storage in initialize() (L607-L612):

TotalDeposits and TotalWithdrawals both start at 0i128
Public query functions (L1693-L1709):

total_deposits(env) -> Result<i128, PoolError> — returns cumulative inflow
total_withdrawals(env) -> Result<i128, PoolError> — returns cumulative outflow
Deposit tracking (calls add_total_deposits(&env, amount)):

lock_assets() at L797
stake() at L1345
Withdrawal tracking (calls add_total_withdrawals(&env, amount)):

unlock_assets() at L854
unstake() at L1400
emergency_withdraw() at L1072 (tracks combined total_returned)
Verification
✅ farming-pool WASM build: exit code 0
✅ factory contract build: exit code 0
✅ Rust diagnostics: 0 errors in both files
✅ Test suite: exit code 0

252

Changes Made
lib.rs — Added revocable() public getter
Rust

/// Return whether the vesting schedule is revocable by admin.
pub fn revocable(env: Env) -> Result<bool, VestingError> {
require_initialized(&env)?;
bump_instance(&env);
Ok(is_revocable(&env))
}
Location: Lines 337-342, placed between releasable() and get_vesting_schedule().

Pattern: Follows the exact pattern of the existing getter functions in the contract:

Calls require_initialized(&env)? to return NotInitialized if the wallet hasn't been set up
Calls bump_instance(&env) to extend instance storage TTL
Delegates to the existing private is_revocable(&env) helper (line 71-76)
Returns Result<bool, VestingError> to match the convention of the other getters
Verification:

✅ WASM build: exit code 0
✅ Rust diagnostics: 0 errors

253

Changes Made

  1. types.rs — New DataKey variants
    Rust

/// Sum of all active user boost allocation percentages (for average computation).
TotalBoostAlloc,
/// Count of users currently with a non-zero boost allocation set.
BoostUserCount,
2. lib.rs — Helper functions, set_boost updates, and public getters
Helper functions (L392-L436):

read_total_boost_allocations(&Env) -> u64 — reads TotalBoostAlloc (defaults to 0)
add_total_boost_allocation(&Env, delta: i64) — adds/subtracts from total (signed delta, checked arithmetic with overflow/underflow asserts)
read_boost_user_count(&Env) -> u32 — reads BoostUserCount (defaults to 0)
increment_boost_user_count(&Env) — +1 user count
decrement_boost_user_count(&Env) — -1 user count (guards against underflow to 0)
Updated set_boost() (L1467-L1476):

Rust

let old_alloc: u32 = get_user_boost(&env, &user).unwrap_or(0);
if old_alloc == 0 {
increment_boost_user_count(&env);
add_total_boost_allocation(&env, allocation_pct as i64);
} else {
let delta = allocation_pct as i64 - old_alloc as i64;
if delta != 0 {
add_total_boost_allocation(&env, delta);
}
}
Logic:

First-time boost (old=0 → new 1-100): BoostUserCount +1, TotalBoostAlloc + new_value
Existing boost update (old>0 → new 1-100): TotalBoostAlloc adjusted by (new - old) delta
Public getters (L1811-L1830):

total_boost_allocations(env) -> Result<u64, PoolError> — sum of all active allocations
boost_user_count(env) -> Result<u32, PoolError> — count of users with active boosts
Both follow the contract's standard pattern: require_initialized → bump_instance → return.

Note on calculating the average: The average boost allocation is intentionally kept as an off-chain computation (total_boost_allocations / boost_user_count) to avoid unnecessary on-chain division and precision loss.

Verification
✅ farming-pool WASM build: exit code 0
✅ Rust diagnostics: 0 errors in both files

254

Changes Made

  1. types.rs — DataKey fixes & addition
    Added import (L1):

BytesN to support the new enum variant.
Added 2 DataKey variants (L20-L23):

AssetPools(Address) — was already referenced in lib.rs but missing from the enum (would have caused runtime encoding issues if fixed post-deploy).
PoolsByWasmHash(BytesN<32>) — the new secondary index mapping a WASM hash → Vec of matching pool IDs.
2. lib.rs — helpers, index maintenance, and query
TTL bump helper (L74-L80):

Rust

fn bump_wasm_pools(env: &Env, wasm_hash: &BytesN<32>)
Extends persistent TTL of PoolsByWasmHash(hash) entries, mirroring bump_asset_pools.

create_pool index update (L875-L883): After writing the pool's PoolRecord and AssetPools index, appends the new pool_id to the PoolsByWasmHash(wasm_hash) list (creating it if absent), then bumps its TTL.

upgrade_pool index hot-swap (L649-L672):

Removes pool_id from the old hash's index list by iterating and filtering out the ID, rewrites the filtered list.
Appends pool_id to the new hash's index list (creating if absent), bumps TTL.
Ensures each pool ID lives in exactly one index entry at a time.
Public getter get_pools_by_wasm_hash (L489-L542):

Rust

pub fn get_pools_by_wasm_hash(
env: Env,
wasm_hash: BytesN<32>,
start_idx: u32,
limit: u32,
) -> Result<ListPoolsResponse, FactoryError>
Direct indexed lookup — uses PoolsByWasmHash(wasm_hash), no O(n) registry scan.
Paginated — start_idx is a 0-based offset within the matching-ID list; limit is capped at 20 (0 → 20 default).
Standard ListPoolsResponse — records, next_start_id (the next start_idx to use), total (factory pool count), has_more.
TTL bumps — instance, the wasm-index entry, and every returned Pool(u32) record.
NotInitialized guard matches the other getters.
Verification
✅ Factory WASM build: exit code 0
✅ Rust diagnostics: 0 errors in both files

@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@Dev-Ben-Theo Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@netlify

netlify Bot commented Aug 29, 2026

Copy link
Copy Markdown

Deploy Preview for sdcontracts ready!

Name Link
🔨 Latest commit 8f02987
🔍 Latest deploy log https://app.netlify.com/projects/sdcontracts/deploys/6a92b82f042d0e0008ad91ae
😎 Deploy Preview https://deploy-preview-269--sdcontracts.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@ritaifeoluwa
ritaifeoluwa merged commit b8cdf76 into SmartDropLabs:main Aug 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants