Overview
The Omnipair program is a Solana smart contract built with Anchor that implements an oracle-less AMM with integrated lending markets.Program ID:
omnixgS8fnqHfCcTGKWj6JtKjzpJZ1Y5y9pyFkQDkYESource Code: github.com/omnipair/omnipair-rsInstructions
Liquidity Management
initialize
initialize
Creates a new trading pair with initial liquidity.Arguments:
Accounts:
| Field | Type | Description |
|---|---|---|
token0 | Pubkey | First token mint (lexicographically smaller) |
token1 | Pubkey | Second token mint |
amount0 | u64 | Initial token0 amount |
amount1 | u64 | Initial token1 amount |
swap_fee_bps | u16 | Swap fee in basis points |
half_life | u64 | EMA half-life in milliseconds |
fixed_cf_bps | Option<u16> | Fixed collateral factor (or None for dynamic) |
pair- The new pair account (PDA)token0_mint- Token0 mint accounttoken1_mint- Token1 mint accountlp_mint- LP token mint (created)rate_model- Interest rate model accountfutarchy_authority- Protocol authority
add_liquidity
add_liquidity
Adds liquidity to an existing pair.Arguments:
Returns: LP tokens minted proportional to liquidity provided.
| Field | Type | Description |
|---|---|---|
amount0_desired | u64 | Desired token0 amount |
amount1_desired | u64 | Desired token1 amount |
amount0_min | u64 | Minimum token0 (slippage) |
amount1_min | u64 | Minimum token1 (slippage) |
remove_liquidity
remove_liquidity
Removes liquidity and burns LP tokens.Arguments:
| Field | Type | Description |
|---|---|---|
liquidity | u64 | LP tokens to burn |
amount0_min | u64 | Minimum token0 out |
amount1_min | u64 | Minimum token1 out |
A 1% withdrawal fee is charged and distributed to remaining LPs.
Spot Trading
swap
swap
Executes a token swap using the constant product formula.Arguments:
Formula:Fee Distribution:
| Field | Type | Description |
|---|---|---|
amount_in | u64 | Input token amount |
min_amount_out | u64 | Minimum output (slippage protection) |
is_token0_in | bool | True if swapping token0 for token1 |
- LP share → Added to reserves
- Protocol share → Accumulated as surplus for Futarchy
Lending Operations
add_collateral
add_collateral
Deposits collateral to enable borrowing.Arguments:
| Field | Type | Description |
|---|---|---|
amount | u64 | Collateral amount to deposit |
token | Pubkey | Token mint of collateral |
remove_collateral
remove_collateral
Withdraws collateral (subject to health check).Requirements:
- Position must remain healthy after withdrawal
- Blocked in reduce-only mode if debt exists
borrow
borrow
Borrows tokens against deposited collateral.Arguments:
Constraints:
| Field | Type | Description |
|---|---|---|
amount | u64 | Amount to borrow |
token | Pubkey | Token mint to borrow |
- Borrow limit = Collateral Value × Collateral Factor × 0.95
- Uses impact-aware valuation at pessimistic EMA price
repay
repay
Repays borrowed tokens.Arguments:
| Field | Type | Description |
|---|---|---|
amount | u64 | Amount to repay |
token | Pubkey | Token mint being repaid |
liquidate
liquidate
Liquidates an undercollateralized position.Liquidation Flow:
- Verify position health:
debt ≥ borrow_limit - Calculate collateral to seize with price impact
- Apply 3% penalty (0.5% to liquidator, 2.5% to LPs)
- Write off debt shares proportionally
flashloan
flashloan
Executes an uncollateralized flash loan.Arguments:
Fee: 0.05% (5 bps)
| Field | Type | Description |
|---|---|---|
amount0 | u64 | Token0 to borrow |
amount1 | u64 | Token1 to borrow |
Governance (Futarchy)
claim_protocol_fees
claim_protocol_fees
Claims accumulated protocol fees (permissionless).Distribution: Fees are split according to
RevenueDistribution:- Futarchy Treasury
- Buybacks Vault
- Team Treasury
set_global_reduce_only
set_global_reduce_only
Enables/disables global reduce-only mode (authority only).When enabled, blocks new borrows and liquidity additions across all pairs.
Accounts
Pair
The core account storing pool state.["gamm_pair", token0, token1, params_hash]
UserPosition
Tracks individual user’s collateral and debt.["gamm_position", pair, owner]
RateModel
Configurable interest rate model parameters.FutarchyAuthority
Protocol-level governance account.Events
The program emits events for indexing and tracking:| Event | Description |
|---|---|
PairCreatedEvent | New pair initialized |
SwapEvent | Swap executed |
AdjustLiquidityEvent | Liquidity added/removed |
AdjustCollateralEvent | Collateral deposited/withdrawn |
AdjustDebtEvent | Borrow/repay executed |
UserPositionLiquidatedEvent | Position liquidated |
FlashloanEvent | Flash loan executed |
ClaimProtocolFeesEvent | Fees distributed |
UpdatePairEvent | Pair state updated (interest accrual) |
Error Codes
Common errors you may encounter:| Error | Description |
|---|---|
BorrowingPowerExceeded | Borrow amount exceeds collateral limit |
Undercollateralized | Position health below threshold |
NotUndercollateralized | Cannot liquidate healthy position |
SlippageExceeded | Output below minimum requested |
InsufficientLiquidity | Not enough reserves for operation |
ReduceOnlyMode | Operation blocked in reduce-only mode |
BorrowExceedsReserve | Cannot borrow more than cash reserves |
Verifiable Builds
All releases use Anchor’s verifiable build system:View on OtterSec Registry
Verified build status and audit submissions