For the complete documentation index, see llms.txt. This page is also available as Markdown.

Placing Taker Orders

Fill limit orders as a searcher — instruction layout, accounts, WSOL edge cases, and full execution code.

Searchers fill orders by invoking the TakeOrder instruction (discriminator 2). Orders can be partially or fully fulfilled — in both cases the taker receives their tokens immediately.


Fill behavior

Full fill

When an order is fully filled, the program automatically:

  1. Creates the maker's ATA for the output tokens (if needed).

  2. Refunds the original rent used in the Limit Order back to the maker.

  3. Reimburses any lamports back to the taker if they had to pay for any ATA creation.

  4. For WSOL output — returns funds back to the maker as SOL instead of WSOL.

Partial fill

For partial fills, the taker receives their tokens immediately. The remaining input tokens stay in the program vault. The maker can withdraw filled output tokens at any time.

Example: 100 USDC → 1 SOL with 5 BPS fee

  1. User creates a limit order paying the rent and depositing 100 USDC into the vault. Price is set to 0.01.

  2. Adjusting for fees — when it is favourable to trade 1.0005 SOL → 100 USDC, the taker comes in and takes the full order.

  3. Under the hood, taker deposits 1.0005 SOL into the vault. 100 USDC is moved from the vault to the taker's ATA, 0.0005 WSOL fee is moved to the fee receiver's wallet.

  4. Contract determines the limit order is fulfilled. Since the output is SOL, the special WSOL edge case is handled:

    • The contract expects a taker-owned WSOL (non-ATA) token account is passed into the call.

    • The WSOL vault sends 1 SOL to this token account and closes it out to the maker, crediting their wallet balance with the 1 SOL.

    • The limit order is closed and rent is sent to the taker.

    • The taker sends the rent funds to the maker subtracting any rent they paid for the WSOL token account.

For partial fills, the above example holds — just skip step 4. For non-WSOL trades, only step 4 differs: the program initializes the maker's ATA with the taker as rent payer. When the limit order closes, the taker is rebated accordingly.


WSOL handling

When the output mint is WSOL and the order will close:

  • The taker must pass a seeded (non-ATA) WSOL token account as the maker's output account.

  • The program sends SOL to this account and closes it to the maker, crediting their wallet balance directly.

  • The taker wraps SOL into their ATA before the take, and closes the ATA after.


TakeOrder accounts

  • 0taker — Taker wallet. Writable, signer.

  • 1maker — Maker wallet (receives output tokens on full fill). Writable.

  • 2inputMint — Input token mint. Read-only.

  • 3outputMint — Output token mint. Read-only.

  • 4limitOrder — Limit order PDA. Writable.

  • 5takerInputMintTokenAccount — Taker's input token account (receives input tokens). Writable.

  • 6takerOutputMintTokenAccount — Taker's output token account (sends output tokens + fees). Writable.

  • 7makerOutputMintTokenAccount — Maker's output token account (or seeded account for WSOL). Writable.

  • 8makerInputMintTokenAccount — Maker's input token account (for remaining balance on close). Writable.

  • 9feeReceiverTokenAccount — Fee receiver's output token account. Writable.

  • 10vaultManager — Vault manager PDA (["vault_manager"]). Read-only.

  • 11inputMintVault — Vault's input token account. Writable.

  • 12outputMintVault — Vault's output token account. Writable.

  • 13systemProgram — System program. Read-only.

  • 14inputMintProgram — Token program for input mint (SPL or SPL-2022). Read-only.

  • 15outputMintProgram — Token program for output mint (SPL or SPL-2022). Read-only.

  • 16associatedTokenProgram — Associated Token Program. Read-only.

  • 17instructionsSysvar — Instructions sysvar. Read-only.


Instruction data

  • Byte 0discriminator (u8) — Always 2 (TakeOrder).

  • Bytes 1–8amount (u64, little-endian) — Input token amount to take.

  • Bytes 9–16max_cost_amount (u64, little-endian) — Maximum output tokens the taker will pay. Use u64::MAX for no limit.

  • Byte 17output_mint_token_account_bump (u8) — PDA bump for maker's output token account.

  • Byte 18input_mint_token_account_bump (u8) — PDA bump for maker's input token account.

  • Byte 19fee_receiver_output_mint_bump (u8) — PDA bump for fee receiver's output token account.


Full execution code

The following code shows how to create a complete set of instructions to execute a TakeOrder, including setup (ATA creation, WSOL wrapping) and cleanup (WSOL unwrapping).


Last updated