Overview
Both contracts extend TTL on every read and write, including read-only query functions. This is unnecessarily expensive in terms of Soroban resource fees:
// farming-pool/src/lib.rs — called on EVERY public function, including pure reads
fn bump_instance(env: &Env) {
env.storage().instance().extend_ttl(TTL_THRESHOLD, TTL_EXTEND_TO);
}
// Also called on every get_user_stake, get_position read
fn bump_user(env: &Env, key: &DataKey) {
env.storage().persistent().extend_ttl(key, USER_TTL_THRESHOLD, USER_TTL_EXTEND_TO);
}
Problems:
extend_ttl costs fees even when current TTL is already maxed out (well above TTL_THRESHOLD)
- Read-only functions (
get_credits, calculate_credits, get_stake, get_user_position) should not modify state — bumping TTL makes them state-modifying
- In Soroban v22+,
extend_ttl below threshold is a no-op at the host level, but the instruction cost is still charged
Fix
- Conditional bump — only extend if current TTL is actually below threshold:
fn bump_instance(env: &Env) {
let ttl = env.storage().instance().get_ttl();
if ttl < TTL_THRESHOLD {
env.storage().instance().extend_ttl(TTL_THRESHOLD, TTL_EXTEND_TO);
}
}
-
Skip bump in read-only paths — calculate_credits, get_user_position, get_boost_config, get_stake, get_credits, is_paused, pool_count, get_pool, admin, pool_wasm_hash should NOT bump TTL
-
Batch user bumps — when both UserStake and UserBoost are read in the same call, batch the extends
Acceptance Criteria
Overview
Both contracts extend TTL on every read and write, including read-only query functions. This is unnecessarily expensive in terms of Soroban resource fees:
Problems:
extend_ttlcosts fees even when current TTL is already maxed out (well aboveTTL_THRESHOLD)get_credits,calculate_credits,get_stake,get_user_position) should not modify state — bumping TTL makes them state-modifyingextend_ttlbelow threshold is a no-op at the host level, but the instruction cost is still chargedFix
Skip bump in read-only paths —
calculate_credits,get_user_position,get_boost_config,get_stake,get_credits,is_paused,pool_count,get_pool,admin,pool_wasm_hashshould NOT bump TTLBatch user bumps — when both
UserStakeandUserBoostare read in the same call, batch the extendsAcceptance Criteria
bump_instancechecks current TTL before extendingbump_instanceorbump_usercalculate_credits