Skip to content

Add minimum stake amount validation to prevent dust positions #36

Description

@prodbycorne

Overview

lock_assets and stake only validate amount > 0. A user can stake 1 stroop (the minimum Stellar token unit) and create a storage entry with negligible economic value. Dust positions:

  1. Waste on-chain storage (each position costs ledger entry fees)
  2. Clutter off-chain indexer queries
  3. Enable griefing attacks where many accounts create 1-unit stakes to bloat factory pool records

Fix

Add a min_stake_amount parameter to initialize and enforce it in lock_assets and stake:

// types.rs — add to DataKey
MinStakeAmount,

// initialize signature change
pub fn initialize(
    env: Env,
    admin: Address,
    stake_token: Address,
    global_multiplier: u32,
    credit_rate: i128,
    min_lock_period: u32,
    min_stake_amount: i128,   // new parameter
) -> Result<(), PoolError>
// lock_assets and stake — add guard
let min = env.storage().instance()
    .get::<DataKey, i128>(&DataKey::MinStakeAmount)
    .unwrap_or(1);
if amount < min {
    return Err(PoolError::BelowMinimumStake);
}

Add BelowMinimumStake = 14 to PoolError.

Also add an admin function to update the minimum:

pub fn set_min_stake_amount(env: Env, amount: i128) -> Result<(), PoolError>

Acceptance Criteria

  • min_stake_amount parameter added to initialize
  • DataKey::MinStakeAmount added to storage schema
  • lock_assets and stake reject amounts below minimum with BelowMinimumStake
  • set_min_stake_amount admin function added
  • Default minimum of 1 (preserve backward compatibility if not set)
  • get_min_stake_amount public getter added
  • Tests: amount = min-1 rejected, amount = min accepted

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official CampaigncorrectnessLogic correctness and invariant enforcementfarming-poolFarmingPool contract

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions