@otcdex/sdk
v0.9.0
Published
TypeScript SDK for the OTC escrow marketplace Solana program
Maintainers
Readme
@otcdex/sdk
TypeScript client for the OTC escrow marketplace Solana program.
npm i @otcdex/sdk @solana/web3.jsThree things to know
maxPricePerTokenis an all-in bound — it includes the buyer-side protocol fee. Passing a listing's raw price always reverts. UsequoteFill().- All money is
bigint. A u64 of 6-decimal quote units exceedsNumber.MAX_SAFE_INTEGERaround 9 billion units. - Reads should come from the indexer API, not
getProgramAccounts— public RPCs throttle it.OtcClientis for spot checks and tests.
Quote and fill
import { quoteFill, fillListing, OtcClient } from '@otcdex/sdk';
const client = new OtcClient(connection);
const listing = await client.getListing(listingAddress);
const { feeBps } = (await client.getConfig())!;
// Pure math, no RPC. 50 = 0.5% slippage headroom.
const q = quoteFill(listing!, amount, feeBps, 50);
// q.buyerPays, q.sellerReceives, q.protocolFee, q.maxPricePerToken
const ix = fillListing({
buyer, listing: listing!.address,
tokenMint: listing!.tokenMint, quoteMint: listing!.quoteMint,
tokenProgram: listing!.tokenProgram, quoteTokenProgram: listing!.quoteProgram,
buyerTokenAccount, buyerQuoteAccount, sellerQuoteAccount,
amount, maxPricePerToken: q.maxPricePerToken,
});Sweep several listings
import { buildBasket, planSweep } from '@otcdex/sdk';
const plan = planSweep(listings, targetAmount, feeBps, 50);
const { transactions, dropped } = await buildBasket(connection, ctx, plan.legs);
// `dropped` legs did NOT execute - surface them to the user.Batches are capped at 10 fills per transaction. The binding limit is Solana's
64-account-lock budget, not transaction size or compute — measured, see
basket.ts.
Also exported
createListing, updatePrice, cancelListing, admin instructions,
decodeListing / decodeConfig, parseProgramEvents (rejects log lines forged
by other programs), and all PDA helpers.
