Coffer Docs
Technical

Smart Contracts

Program interfaces, account ordering, state, and indexing

Implementation and deployment

Match program, IDL, and SDK versions; unchanged addresses/account sizes do not guarantee compatibility. Verify the executable account and ProgramData upgrade state on your cluster, then quote/simulate against execution state. Mainnet configuration:

ProgramID
Cubic Pool8iQtGj9mcUfFUGaiCpPy89swC3s8YTC8FhVZWfgeZhwu
Protocol Admin3jiojHZbjJQ7QLMGSTjFwxVEmx4NtuRy34nLAmsJME81
Single Token Liquidity7BpdUH1tzTSXLuQNo6YpjJ8Eagw8AkrS6cnkxiJdCFS2

LP token is the ownership token referenced by interface identifiers bpt_mint, bptMint, and minimum_bpt_amount. Preserve these identifiers and seed bytes.

Account derivations

AccountSeeds / derivation
Pool PDA["cubic_pool", config, little-endian u64 pool_id], pool program
LP mint PDA["bpt_mint", pool], pool program; mint authority is the pool PDA
Deposit helper PDA["stld_helper", pool], helper program
Token ATAOwner, token-program ID, mint; associated-token program

Instructions by role

RoleInterface
Trader / LPswap, add_liquidity, remove_liquidity
Readerget_pool_info
Creatorinitialize_cubic_pool, then authorized seed
Pool adminFees, switches, sell-off limits, admin transfer/renunciation, manager/ALT configuration
Configured, enabled managerrange_manager_update
Protocol adminPause, protocol fees, emergency recovery, config authority
Single-token depositorHelper composing swaps/join

Authority follows stored fields and instruction constraints; see Controls.

Swap

pub fn swap<'info>(
    ctx: Context<'_, '_, 'info, 'info, Swap<'info>>,
    amount_in: u64,
    minimum_amount_out: u64,
    token_in_index: u8,
    token_out_index: u8,
) -> Result<()>

Exact input, raw units; indices differ and are below token_count.

Accounts, in orderAccess / validation
poolWritable
token_mint_in, token_mint_outIndexed pool mints
user_token_account_in, user_token_account_outWritable; expected mint, owner user
vault_in, vault_outWritable; pool ATAs under each mint's token program
userSigner
token_program_in, token_program_outStored token programs

Require pool/swaps enabled, input active, and available sell-off capacity. Gross curve output must fit LP-owned and available vault reserves; minimum_amount_out guards received output after surge and any token transfer fee. Base and protocol fees round upward; use exact math. Failure rolls back token movements.

Token programs and extensions

SPL Token/Token-2022 admission checks effective policy, creator overrides, and unconditional mint constraints; see Parameters. The current instruction implementation uses checked transfers and computes epoch-dependent token transfer fees from the mint. Inbound accounting uses the amount received by the vault; outbound minima protect what the user receives. Token-program withheld fees are separate from spendable vault balances and belong to the mint's withheld-fee withdrawal authority, not LPs or Coffer's protocol bucket.

Swaps and liquidity operations accept optional remaining-account tails for transfer hooks and required memos. Hooks needing additional signers are unsupported. Verify the deployed program and SDK support this profile; admission and a matching token-program ID alone do not establish compatibility.

Liquidity instructions

pub fn add_liquidity<'info>(
    ctx: Context<'_, '_, 'info, 'info, ModifyLiquidity<'info>>,
    token_amounts: Vec<u64>,
    minimum_bpt_amount: u64,
) -> Result<()>;

pub fn remove_liquidity<'info>(
    ctx: Context<'_, '_, 'info, 'info, RemoveLiquidity<'info>>,
    bpt_amount: u64,
    minimum_token_amounts: Vec<u64>,
) -> Result<()>;

Named accounts: writable pool with pool_enabled = true; writable derived bpt_mint; writable user_bpt_account with matching mint/user; signer user; LP mint's token_program.

A fixed prefix of 4 × token_count remaining accounts, in pool order:

Deposit: [user_token_0, vault_0, user_token_1, vault_1, ...,
          mint_0, mint_1, ..., token_program_0, token_program_1, ...]
Withdraw: [vault_0, user_token_0, vault_1, user_token_1, ...,
           mint_0, mint_1, ..., token_program_0, token_program_1, ...]

Append any required hook/memo accounts after this prefix. User accounts/vaults are writable; mints/programs read-only. Validate ownership, mints, token programs, and vault derivations.

Subsequent token_amounts are gross spend ceilings: size the proportional basket from net amounts after token transfer fees; zero-actual slots require zero input. Actual reserves already exclude protocol fees. Withdrawals may burn less to preserve 1,000 raw LP units; output minima apply to receipts after that adjustment and any token transfer fee. Only the stored pool admin seeds an empty pool. See join and exit rounding. Suitable ALTs/versioned transactions help larger pools; an ALT does not guarantee fit.

Pool state and discovery

CubicPool: 1,683 bytes, including 8-byte discriminator; ten token slots, first token_count used. Stores authorities, fees, flags, manager settings, reserves, extension policy, and lookup_table. LP mint/vaults are derived; read supply/decimals from mint accounts.

const pools = await program.account.cubicPool.all();
const pool = await program.account.cubicPool.fetch(poolPubkey);
const view = await program.methods.getPoolInfo()
  .accounts({ pool: poolPubkey }).simulate();

Raw getProgramAccounts requires the matching discriminator filter and layout validation. Indexed discovery is a public endpoint.

Indexing and upgrades

Accept logs only from successful transactions at your chosen confirmation level and the expected program. Match event versions; appended fields do not guarantee decoder compatibility.

EventInterpretation
Swapamount_out is post-surge vault debit; received output is amount_out − transfer_fee_out. surge_fee_amount uses output units; fee_amount/protocol_fee_amount use input units
MaxSelloffWindowAdvancedEmitted when an enabled window is checked, not only at a boundary
LiquidityAddedGross amounts debited from the user and LP minted; net reserve credits may be lower due to token transfer fees
LiquidityRemovedGross vault payouts and effective LP burn; user receipts may be lower due to token transfer fees
PoolStateLogVirtual/LP-actual/protocol balances and timestamp after swaps/joins/exits
RangeManagerUpdatedPricing-state changes; refresh quote caches
ProtocolFeesCollectedProtocol-bucket changes
DebugLiquidityWithdrawnEmergency recovery; reconcile separately

PoolStateLog omits LP supply and full configuration. Simulated PoolInfo adds derived addresses, mints, weights, balances, fees, flags, token programs, and timestamp, but omits full authority/manager/sell-off configuration and LP supply. Read accounts/mints at compatible slots.

Consume configuration events/account updates too; fee, flag, and authority changes invalidate caches. Exclude failed transactions, handle reorgs at your commitment level, and periodically reconcile indexed state with accounts.

Migration is layout/deployment-specific: supported migrate_to_v5 requires a compatible starting layout and explicit token-reactivation argument; it is not a generic migration for arbitrary old pools.

On this page