Skip to content
2 changes: 1 addition & 1 deletion contract/src/leaderboard.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::errors::InsightArenaError;
use crate::storage_types::{DataKey, LeaderboardSnapshot, Season, UserProfile};
use soroban_sdk::{Address, Env, Vec};
use soroban_sdk::{Address, Env};

/// `stake_bonus = floor(stake_xlm / 10)` → `floor(stake_stroops / 10^8 stroops)`.
const STROOPS_PER_STAKE_POINT: i128 = 100_000_000;
Expand Down
1 change: 1 addition & 0 deletions contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub mod ttl;
pub use crate::config::Config;
pub use crate::errors::InsightArenaError;
pub use crate::governance::{Proposal, ProposalType};
pub use crate::liquidity::{calculate_lp_tokens, calculate_liquidity_value, calculate_swap_output};
pub use crate::market::CreateMarketParams;
pub use crate::storage_types::{
CreatorStats, DataKey, InviteCode, LeaderboardEntry, LeaderboardSnapshot, Market, MarketStats,
Expand Down
24 changes: 23 additions & 1 deletion contract/src/liquidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,29 @@ pub fn calculate_swap_output(

// ── Helper Functions ──────────────────────────────────────────────────────────

// TODO: Add helper functions
/// Calculate liquidity value for LP tokens (for withdrawal)
#[allow(dead_code)]
pub fn calculate_liquidity_value(
lp_tokens: i128,
total_liquidity: i128,
total_lp_supply: i128,
) -> Result<i128, InsightArenaError> {
if lp_tokens <= 0 || total_lp_supply <= 0 {
return Err(InsightArenaError::InvalidInput);
}

if lp_tokens > total_lp_supply {
return Err(InsightArenaError::InsufficientFunds);
}

let value = lp_tokens
.checked_mul(total_liquidity)
.ok_or(InsightArenaError::Overflow)?
.checked_div(total_lp_supply)
.ok_or(InsightArenaError::Overflow)?;

Ok(value)
}

// ── Liquidity Management ──────────────────────────────────────────────────────

Expand Down
Loading