Skip to main content

createMarketOfferInstruction

Builds a raw instruction to execute a market order that fills against existing limit orders on the orderbook, allowing users to instantly buy or sell YT tokens at the best available prices.

Usage

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

const ix = createMarketOfferInstruction(
  {
    trader: wallet.publicKey,
    orderbook: orderbookAddress,
    vault: vaultAddress,
    cpiAccountOrderbook: cpiAccountsOrderbook,
    yieldPosition: yieldPositionAddress,
    tokenEscrowYt: orderbookYtEscrow,
    tokenEscrowSy: orderbookSyEscrow,
    tokenEscrowPt: orderbookPtEscrow,
    tokenSyTrader: userSyTokenAccount,
    tokenYtTrader: userYtTokenAccount,
    tokenPtTrader: userPtTokenAccount,
    systemProgram: SYSTEM_PROGRAM_ID,
    syProgram: syProgramId,
    tokenProgram: TOKEN_2022_PROGRAM_ID,
    exponentCore: EXPONENT_CORE_PROGRAM_ID,
    addressLookupTable: vaultLookupTable,
    eventAuthority: eventAuthorityPda,
    program: EXPONENT_ORDERBOOK_PROGRAM_ID,
  },
  {
    maxPriceApy: 7.5,
    amount: BigInt(1_000_000),
    minAmountOut: BigInt(900_000),
    offerType: { buyYt: {} },
    virtualOffer: false,
  }
);

Accounts

NameTypeSignerWritableDescription
traderPublicKeyYesNoThe user executing the market order
orderbookPublicKeyNoYesOrderbook account
vaultPublicKeyNoYesVault account
cpiAccountOrderbookPublicKeyNoNoCPI accounts orderbook
yieldPositionPublicKeyNoYesVault robot yield position
tokenEscrowYtPublicKeyNoYesOrderbook YT escrow account
tokenEscrowSyPublicKeyNoYesOrderbook SY escrow account
tokenEscrowPtPublicKeyNoYesOrderbook PT escrow account
tokenSyTraderPublicKeyNoYesTrader SY token account
tokenYtTraderPublicKeyNoYesTrader YT token account
tokenPtTraderPublicKeyNoYesTrader PT token account
systemProgramPublicKeyNoNoSystem program
syProgramPublicKeyNoNoSY program
tokenProgramPublicKeyNoNoSPL Token 2022 program
exponentCorePublicKeyNoNoExponent Core program
addressLookupTablePublicKeyNoNoVault address lookup table
eventAuthorityPublicKeyNoNoEvent authority PDA
programPublicKeyNoNoExponent Orderbook program

Args

NameTypeDescription
maxPriceApynumberMaximum price in implied APY (f64)
amountbigintAmount of tokens to trade (in base units)
minAmountOutbigintMinimum amount of tokens to receive (slippage protection)
offerTypeOfferTypeType of offer: { sellYt: {} } or { buyYt: {} }
virtualOfferbooleanWhether this is a virtual offer

Returns

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