CometDocs
Open app
Contents

Protocol

Program reference

Comet is one Solana program. This page lists its accounts and instructions for integrators and liquidators.

Accounts

AccountOne perHolds
MarketDeploymentThe lists of reserves and pools, and the protocol’s parameters
ReserveAssetThe token vault, borrow and supply indexes, rate curve, collateral weights, backstop balance, oracle feed
MarginAccountAccount a wallet opensDeposit shares and borrows per reserve
PoolPair and fee tierCurrent price and tick, liquidity in range, fee growth, the price average
TickArraySpan of ticks in a poolLiquidity and fee growth at each initialized tick
RangeLiquidity positionOwner account, ticks, liquidity, margin, debt per token
PerpPerp positionOwner account, side, held shares, debt, entry price

Instructions

Accounts and Lend

InstructionArgumentsDoes
create_account—Opens a margin account for the signer
depositamountSupplies tokens to a reserve
withdrawamountWithdraws a deposit, within the borrow limit
borrowamountBorrows from a reserve to the signer’s wallet
repayamountRepays a borrow

Pools

InstructionArgumentsDoes
swapamount_in, min_out, base_to_quoteSwaps against a pool
open_rangeOpenRangeArgsMints a range, with or without borrowed tokens
collect_fees—Moves a range’s fees into the account’s deposits
close_rangefraction, min_base, min_quoteRemoves liquidity, repays debt, returns the rest

Perps

InstructionArgumentsDoes
open_perpOpenPerpArgsOpens a long or short
close_perpfraction, min_outCloses all or part of a position
add_marginamountMoves deposits into a range or perp
remove_marginamountMoves margin back, down to the opening requirement

Liquidation

InstructionArgumentsDoes
liquidate_accountrepay_amountRepays a borrow and receives collateral with the bonus
liquidate_position—Closes a range or perp at maintenance and pays the caller’s fee

Argument structs

open_perp
pub struct OpenPerpArgs {
    /// Long or Short.
    pub side: Side,
    /// Taken from the account's deposits, in the pool's quote token.
    pub margin: u64,
    /// Drawn from Lend: the quote token for a long, the base token for a short.
    pub borrow: u64,
    /// The least the opening swap must return.
    pub min_out: u64,
}
open_range
pub struct OpenRangeArgs {
    pub tick_lower: i32,
    pub tick_upper: i32,
    /// Margin taken from the account's deposits, per pool token.
    pub margin_base: u64,
    pub margin_quote: u64,
    /// Borrowed from Lend, per pool token. Zero for an unleveraged range.
    pub borrow_base: u64,
    pub borrow_quote: u64,
    /// The least liquidity the range must mint.
    pub min_liquidity: u128,
}

Units and precision

ValueTypeUnit
Token amountsu64The mint’s smallest unit
Rates and indexesu128Fixed point, 18 decimals
Pool priceu128Square root of the price, Q64.64
Ticksi32Price = 1.0001^tick
Fractions (close_perp, close_range)u16Basis points; 10,000 closes the whole position

Interest inside instructions

Every instruction that reads a reserve first brings its indexes up to the current slot, so a transaction never needs a separate refresh step and always sees current debt.