Skip to main content

createPostOfferInstruction

Builds a raw instruction to post a limit order on the orderbook, allowing users to place buy or sell offers for YT tokens at a specified price.

Usage

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

const ix = createPostOfferInstruction(
  {
    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,
  },
  {
    priceApy: 5.25,
    amount: BigInt(1_000_000),
    offerTypeFlag: { sellYt: {} },
    virtualOffer: false,
    expirySeconds: 86400,
    options: { fillOrKill: [false] },
  }
);

Accounts

NameTypeSignerWritableDescription
traderPublicKeyYesNoThe user posting the offer
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
priceApynumberPrice in implied APY (f64)
amountbigintAmount of tokens to offer (in base units)
offerTypeFlagOfferTypeType of offer: { sellYt: {} } or { buyYt: {} }
virtualOfferbooleanWhether this is a virtual offer
expirySecondsnumberExpiry time in seconds (u32)
optionsOfferOptionsOffer options: { fillOrKill: [boolean] }

Returns

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