Data Structure
1. Pool
/// Main pool structure managing liquidity and operations for a token pair.
///
/// This struct represents a liquidity pool for two token types. It manages
/// liquidity across multiple bins, handles swaps, and tracks positions and rewards.
///
/// ## Type Parameters
/// - `CoinTypeA`: First token type in the pool
/// - `CoinTypeB`: Second token type in the pool
///
/// ## Fields
/// - `id`: Unique identifier for the pool
/// - `index`: Pool index for identification
/// - `v_parameters`: Variable parameters for dynamic fee calculation
/// - `active_id`: Current active bin ID representing market price
/// - `base_fee_rate`: Base fee rate for swaps
/// - `balance_a`: Balance of token A in the pool
/// - `balance_b`: Balance of token B in the pool
/// - `protocol_fee_a`: Accumulated protocol fees for token A
/// - `protocol_fee_b`: Accumulated protocol fees for token B
/// - `reward_manager`: Manager for reward distribution
/// - `bin_manager`: Manager for liquidity bins
/// - `position_manager`: Manager for liquidity positions
/// - `url`: Pool metadata URL
/// - `permissions`: Pool operation permissions
/// - `active_open_positions`: Number of open position operation, forbid swap when open position is not 0
public struct Pool<phantom CoinTypeA, phantom CoinTypeB> has key, store {
id: UID,
index: u64,
v_parameters: VariableParameters,
active_id: I32,
base_fee_rate: u64,
balance_a: Balance<CoinTypeA>,
balance_b: Balance<CoinTypeB>,
protocol_fee_a: u64,
protocol_fee_b: u64,
reward_manager: RewardManager,
bin_manager: BinManager,
position_manager: PositionManager,
url: String,
permissions: Permissions,
active_open_positions: u64,
}
2. Position
/// Individual liquidity position with metadata and liquidity shares.
///
/// This struct represents a liquidity position that spans multiple bins,
/// with metadata for display and tracking of liquidity shares across bins.
///
/// ## Fields
/// - `id`: Unique identifier for the position
/// - `pool_id`: ID of the pool this position belongs to
/// - `index`: Position index within the pool
/// - `coin_type_a`: Name of token A in the position
/// - `coin_type_b`: Name of token B in the position
/// - `description`: Description of the position
/// - `name`: Display name for the position
/// - `uri`: URI for position metadata
/// - `lower_bin_id`: Lower bound bin ID of the position
/// - `upper_bin_id`: Upper bound bin ID of the position
/// - `liquidity_shares`: Vector of liquidity shares for each bin
/// - `flash_count`: Number of flash swaps for the position
public struct Position has key, store {
id: UID,
pool_id: ID,
index: u64,
coin_type_a: String,
coin_type_b: String,
description: String,
name: String,
uri: String,
lower_bin_id: I32,
upper_bin_id: I32,
liquidity_shares: vector<u128>,
flash_count: u64,
}
3. Bin
/// Represents a single liquidity bin at a specific price point.
///
/// Each bin contains liquidity in the form of token amounts and tracks
/// accumulated fees and rewards for liquidity providers.
///
/// ## Fields
/// - `id`: Unique identifier for the bin (I32)
/// - `amount_a`, `amount_b`: Token amounts in the bin
/// - `price`: Price at this bin's price point (u128)
/// - `liquidity_share`: Total liquidity share in the bin
/// - `rewards_growth_global`: Accumulated rewards growth per liquidity share
/// - `fee_a_growth_global`, `fee_b_growth_global`: Accumulated fees growth per liquidity share
public struct Bin has store {
id: I32,
amount_a: u64,
amount_b: u64,
price: u128,
liquidity_share: u128,
rewards_growth_global: vector<u128>,
fee_a_growth_global: u128,
fee_b_growth_global: u128,
}
4. Partner
/// Individual partner account with balances and settings.
///
/// This struct represents a single partner with their referral fee rate,
/// time range, and accumulated balances across different token types.
///
/// ## Fields
/// - `id`: Unique identifier for the partner
/// - `name`: Name of the partner
/// - `ref_fee_rate`: Referral fee rate in basis points
/// - `start_time`: Start time when partner becomes active (Unix timestamp)
/// - `end_time`: End time when partner becomes inactive (Unix timestamp)
/// - `balances`: Bag containing balances for different token types
public struct Partner has key, store {
id: UID,
name: String,
ref_fee_rate: u64,
start_time: u64,
end_time: u64,
balances: Bag,
}
Last updated