fixed all issues - #269
Merged
ritaifeoluwa merged 2 commits intoAug 29, 2026
Merged
Conversation
|
@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! 🚀 |
✅ Deploy Preview for sdcontracts ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #251
closes #252
closes #253
closes #254
SUMMARY:
251
Changes Made
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).
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
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
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