Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion soroban/contracts/factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
mod types;

use soroban_sdk::{
contract, contractimpl, symbol_short, vec, Address, BytesN, Env, IntoVal, Symbol, Val, Vec,
contract, contractimpl, symbol_short, vec, Address, BytesN, Env, IntoVal, String, Symbol, Val,
Vec,
};
use types::{DataKey, FactoryError, ListPoolsResponse, PoolRecord, PoolSort};

Expand Down
17 changes: 17 additions & 0 deletions soroban/contracts/factory/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,23 @@ fn test_double_initialize_returns_error() {
);
}

#[test]
fn test_initialize_rejects_zero_address_admin() {
let env = Env::default();
env.mock_all_auths();
let wasm_hash = upload_farming_pool_wasm(&env);
let factory_addr = env.register(Factory, ());
let client = FactoryClient::new(&env, &factory_addr);
let zero_admin = Address::from_string(&soroban_sdk::String::from_str(
&env,
"GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF",
));
assert_eq!(
client.try_initialize(&zero_admin, &wasm_hash),
Err(Ok(FactoryError::InvalidAdmin))
);
}

// ── NotInitialized guard ──────────────────────────────────────────────────────

#[test]
Expand Down

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions soroban/contracts/farming-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,17 @@ impl FarmingPool {
Ok(Some(position))
}

/// Lightweight check for whether `user` has an active locked position.
///
/// Returns `true` if the user has a non-zero locked position, `false`
/// otherwise. This is cheaper than `get_user_position` as it avoids
/// computing uncommitted credit accrual.
pub fn has_position(env: Env, user: Address) -> Result<bool, PoolError> {
require_initialized(&env)?;
bump_instance(&env);
Ok(get_position(&env, &user).is_some())
}

pub fn pause(env: Env) -> Result<(), PoolError> {
require_initialized(&env)?;
get_admin(&env)?.require_auth();
Expand Down Expand Up @@ -1360,6 +1371,14 @@ impl FarmingPool {

/// Set the credit accrual rate. Rejects non-positive values and anything
/// above `MAX_CREDIT_RATE` — see #89 for the overflow-safety derivation.
///
/// The new rate takes effect immediately for *new* checkpoints. Existing
/// staked or locked users retain their previous rate snapshot until they
/// interact (e.g. `stake`/`unstake` or `lock_assets`/`unlock_assets`),
/// at which point `checkpoint` records the new rate. This is by design:
/// iterating all on-chain user entries would be prohibitively expensive.
/// Off-chain indexers should apply the rate from the `rate_set` event
/// when computing credits for users who have not yet checkpointed.
pub fn set_credit_rate(env: Env, new_rate: i128) -> Result<(), PoolError> {
require_initialized(&env)?;
get_admin(&env)?.require_auth();
Expand Down
22 changes: 22 additions & 0 deletions soroban/contracts/farming-pool/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,28 @@ fn test_lock_assets_creates_position() {
assert_eq!(t.token.balance(&t.contract_id), 500);
}

#[test]
fn test_has_position_returns_false_without_position() {
let t = setup(1, 1);
assert!(!t.client.has_position(&t.user));
}

#[test]
fn test_has_position_returns_true_after_lock() {
let t = setup(1, 1);
t.client.lock_assets(&t.user, &500);
assert!(t.client.has_position(&t.user));
}

#[test]
fn test_has_position_returns_false_after_full_unlock() {
let t = setup(1, 1);
t.client.lock_assets(&t.user, &500);
advance_ledgers(&t.env, 100);
t.client.unlock_assets(&t.user, &500);
assert!(!t.client.has_position(&t.user));
}

#[test]
fn test_lock_assets_additional_lock_checkpoints_credits() {
// Lock 1000, advance 10 ledgers (10000 credits), then lock 500 more.
Expand Down
Loading