Skip to main content

createCollectInterestInstruction

Builds a raw instruction to collect accrued SY interest earned by a trader’s positions held in the orderbook.

Usage

import { createCollectInterestInstruction, amount } from "@exponent-labs/exponent-sdk/client/orderbook";
import { PublicKey } from "@solana/web3.js";

const ix = createCollectInterestInstruction(
  {
    trader: wallet.publicKey,
    orderbook: orderbookAddress,
    vault: vaultAddress,
    tokenEscrowSy: orderbookSyEscrow,
    tokenSyTrader: userSyTokenAccount,
    systemProgram: SYSTEM_PROGRAM_ID,
    tokenProgram: TOKEN_2022_PROGRAM_ID,
    syProgram: syProgramId,
    exponentCore: EXPONENT_CORE_PROGRAM_ID,
    addressLookupTable: vaultLookupTable,
    cpiAccountOrderbook: cpiAccountsOrderbook,
    eventAuthority: eventAuthorityPda,
    program: EXPONENT_ORDERBOOK_PROGRAM_ID,
  },
  {
    syAmountOptional: amount("All"),
  }
);

Accounts

NameTypeSignerWritableDescription
traderPublicKeyYesNoThe user collecting interest
orderbookPublicKeyNoYesOrderbook account
vaultPublicKeyNoNoVault account
tokenEscrowSyPublicKeyNoYesOrderbook SY escrow account
tokenSyTraderPublicKeyNoYesTrader SY token account
systemProgramPublicKeyNoNoSystem program
tokenProgramPublicKeyNoNoSPL Token 2022 program
syProgramPublicKeyNoNoSY program
exponentCorePublicKeyNoNoExponent Core program
addressLookupTablePublicKeyNoNoVault address lookup table
cpiAccountOrderbookPublicKeyNoNoCPI accounts orderbook
eventAuthorityPublicKeyNoNoEvent authority PDA
programPublicKeyNoNoExponent Orderbook program

Args

NameTypeDescription
syAmountOptionalAmountAmount to collect: amount("All") or amount("Some", [value])

Amount Helper

import { amount } from "@exponent-labs/exponent-sdk/client/orderbook";

amount("All")                // collect everything available
amount("Some", [500_000n])   // collect a specific amount

Returns

TransactionInstruction — a transaction instruction ready to be added to a transaction.