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
63 changes: 62 additions & 1 deletion contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub use crate::liquidity::{calculate_lp_tokens, calculate_liquidity_value, calcu
pub use crate::market::CreateMarketParams;
pub use crate::storage_types::{
CreatorStats, DataKey, InviteCode, LeaderboardEntry, LeaderboardSnapshot, Market, MarketStats,
PlatformStats, Prediction, Season, UserProfile,
PlatformStats, Prediction, Season, UserProfile, LiquidityPool, LPPosition, SwapRecord,
};

use soroban_sdk::{contract, contractimpl, Address, Env, Symbol, Vec};
Expand Down Expand Up @@ -446,6 +446,67 @@ impl InsightArenaContract {
pub fn get_platform_stats(env: Env) -> PlatformStats {
analytics::get_platform_stats(env)
}

// ── Liquidity Pool / AMM ──────────────────────────────────────────────────

/// Add liquidity to a market pool and receive LP tokens
pub fn add_liquidity(
env: Env,
provider: Address,
market_id: u64,
amount: i128,
) -> Result<i128, InsightArenaError> {
liquidity::add_liquidity(&env, provider, market_id, amount)
}

/// Remove liquidity from a pool by burning LP tokens
pub fn remove_liquidity(
env: Env,
provider: Address,
market_id: u64,
lp_tokens: i128,
) -> Result<i128, InsightArenaError> {
liquidity::remove_liquidity(&env, provider, market_id, lp_tokens)
}

/// Swap from one outcome position to another
pub fn swap_outcome(
env: Env,
trader: Address,
market_id: u64,
from_outcome: Symbol,
to_outcome: Symbol,
amount_in: i128,
min_amount_out: i128,
) -> Result<i128, InsightArenaError> {
liquidity::swap_outcome(
&env,
trader,
market_id,
from_outcome,
to_outcome,
amount_in,
min_amount_out,
)
}

/// Get current price of an outcome in the pool
pub fn get_outcome_price(
env: Env,
market_id: u64,
outcome: Symbol,
) -> Result<i128, InsightArenaError> {
liquidity::get_outcome_price(&env, market_id, outcome)
}

/// Get LP position for a provider
pub fn get_lp_position(
env: Env,
provider: Address,
market_id: u64,
) -> Result<crate::storage_types::LPPosition, InsightArenaError> {
liquidity::get_lp_position_public(&env, provider, market_id)
}
}

// ── Tests ─────────────────────────────────────────────────────────────────────
Expand Down
Loading
Loading