@deepliquidity/sdk
v0.2.0
Published
TypeScript client for DEEP on Solana: deep-curve (launchpad bonding curve) and DeepSwap (deep-amm) PDAs, instruction builders, account and event decoders, and the programs IDLs.
Maintainers
Readme
@deepliquidity/sdk
TypeScript client for DEEP on Solana: the deep-curve launchpad (bonding curves) and DeepSwap (the deep-amm constant-product AMM that graduated tokens move to). PDAs, instruction functions, account and event decoders, integer quotes that match the programs exactly, and the programs' Anchor IDLs.
Status. The programs are live on Solana mainnet (since 2026-10-08). Not audited. Nothing in this package sends transactions by itself.
The full integration guide (account layouts with offsets, events, fee maths, error codes, compute budgets, differences from pump.fun and Raydium CPMM) is the integration guide and the "Integrate" section of the DEEP docs.
Install
npm install @deepliquidity/sdk @deepliquidity/curve-math @solana/web3.jsESM only, with TypeScript declarations. Works in Node ≥ 22 and in browser bundles: the package
imports Buffer from the buffer package and never relies on a global Buffer.
Program ids
import { DEEP_CURVE_PROGRAM_ID, DEEP_AMM_PROGRAM_ID } from "@deepliquidity/sdk";
// deep-curve 7czURwVLkQpcF1HVhhZU5GGzvPA8YniogZY1BhZHCDtA (mainnet)
// deep-amm HCrCy6bzHhZ1b6bXwQAucEFkKXyzYMh3hgAR8UPrYSEP (mainnet)Quick start: quote and build a curve buy
import { quoteBuyV1 } from "@deepliquidity/curve-math";
import { applySlippage, buyIx, curveFees, curvePda, decodeBondingCurve } from "@deepliquidity/sdk";
import { ComputeBudgetProgram, Connection, PublicKey, Transaction } from "@solana/web3.js";
const conn = new Connection("https://api.mainnet-beta.solana.com", "confirmed"); // or your own RPC;
const mint = new PublicKey("<mint>");
const user = new PublicKey("<wallet>");
const curve = decodeBondingCurve((await conn.getAccountInfo(curvePda(mint)))!.data);
// the token's own terms: DEEP's buy and sell rate, its reward rate and reward model
const fees = curveFees(curve);
const q = quoteBuyV1(curve.state, 100_000_000n, fees); // 0.1 SOL in, fees included
const tx = new Transaction().add(
ComputeBudgetProgram.setComputeUnitLimit({ units: 80_000 }),
buyIx({
user,
mint,
amount: 100_000_000n,
minOut: applySlippage(q.tokensOut, 100), // 1% slippage floor
deadline: BigInt(Math.floor(Date.now() / 1000) + 60),
}),
);
// sign with the user's wallet and sendCharging your own fee
DEEP has no on-chain referral share. To charge an app fee, add a SOL transfer to your own wallet
in the same transaction as the trade: quoteBuyWithIntegratorFee / quoteSellWithIntegratorFee
give the amounts and breakdown, integratorFeeIx builds the transfer (0–10%, rounded up).
Show the fee to the user; DEEP's own fees still apply. See the integration guide, "Charging your
own fee".
Launching from your own launchpad: logo and metadata
Upload the token's logo and details to DEEP first, then launch with the returned uri. The logo
then shows on DEEP right away.
import { uploadTokenMetadata } from "@deepliquidity/sdk";
const { uri } = await uploadTokenMetadata(
{
name: "Sea Bunny",
symbol: "BUNNY",
image: logoBytes,
description: "…",
telegram: "https://t.me/…",
},
{ apiKey: process.env.DEEP_API_KEY }, // optional; uploads then count against your key
);
// pass `uri` to create_tokenThe logo must be PNG, JPEG, GIF or WebP, up to 1 MB. Metadata hosted elsewhere also works: DEEP copies the logo onto its own storage a few minutes after the launch.
Event accounts
Every instruction that emits an event ends with two read-only accounts, event_authority and
program, and the programs require them. The functions of this SDK always add them, so there
is nothing to do. If you build an instruction yourself, append eventCpiMetas(programId) after
its own accounts and before any remaining accounts; the IDLs show which instructions take the
pair.
Quick start: swap on a DeepSwap pool
import {
cpmmDirection,
cpmmReserves,
cpmmSwapBaseInputIx,
decodeCpmmAmmConfig,
decodeCpmmPoolState,
DEEP_AMM_PROGRAM_ID,
graduationPoolPda,
NATIVE_MINT,
quoteCpmmSwapBaseInput,
} from "@deepliquidity/sdk";
const poolId = graduationPoolPda(mint); // the pool a token graduated into
const pool = decodeCpmmPoolState((await conn.getAccountInfo(poolId))!.data);
const amm = decodeCpmmAmmConfig((await conn.getAccountInfo(pool.ammConfig))!.data);
const bal = async (k: PublicKey) => BigInt((await conn.getTokenAccountBalance(k)).value.amount);
const [r0, r1] = cpmmReserves(pool, await bal(pool.token0Vault), await bal(pool.token1Vault));
const { zeroForOne, creatorFeeOnInput } = cpmmDirection(pool, NATIVE_MINT);
const q = quoteCpmmSwapBaseInput({
amountIn: 10_000_000n,
inputReserve: zeroForOne ? r0 : r1,
outputReserve: zeroForOne ? r1 : r0,
config: amm,
creatorFeeEnabled: pool.enableCreatorFee,
creatorFeeOnInput,
});
const ix = cpmmSwapBaseInputIx({
programId: DEEP_AMM_PROGRAM_ID,
payer: user,
poolId,
pool,
inputMint: NATIVE_MINT,
amountIn: 10_000_000n,
minimumAmountOut: (q.amountOut * 99n) / 100n,
}); // wrap SOL into the user's WSOL account first; see examples/deepswap-swap.tsToken pairs: curves quoted in DEEP
A Deep Curve token launches against SOL or against an approved quote asset (DEEP first). Same fees and rules as SOL, taken in that asset; the launch fee stays in SOL.
- Read a token's pair before formatting any amount:
decodeBondingCurve(data).quoteMint(PublicKey.defaultor absent = SOL). On a token-quoted curve the reserve fields and every fee counter are in the quote's base units (DEEP has 6 decimals), not lamports. - A token-quoted curve has its own instructions:
createTokenV2Ix({ ..., quoteMint }),buyV2Ix({ user, mint, quoteMint, amount, minOut, deadline })andsellV2Ix(...)(amounts in quote base units). A SOL curve keepscreateTokenIx,buyIxandsellIx, unchanged; the wrong pair of instructions fails withWrongQuote(6044). - Graduation of a token-quoted curve:
fundGraduationIxs(buys the pool rent in SOL through the quote's route pool, TWAP-bounded) thengraduateV2Ixs; both are permissionless. - Each approved asset has a
QuoteConfigaccount (quoteConfigPda(mint),decodeQuoteConfig(data), 182 bytes): decimals, whether new launches are open, the curve's starting quote reserve, the rent route pool and its slippage cap (MAX_RENT_SLIPPAGE_BPS, 1,000), and the issuer-control level (ISSUER_CONTROL). TradeEvent.solAmountis in quote base units on a token-quoted curve; events carryquoteMint.
Full list in the CHANGELOG; layouts, account lists and errors in docs/INTEGRATORS.md.
Events
Solana keeps about 10 kB of log text per transaction and replaces the rest with Log truncated,
so a transaction with many instructions (a bundled launch: create_token plus several buys)
loses its last events from the log. Read a confirmed transaction with the truncation-safe
readers, not with the log parsers alone:
import { PublicKey } from "@solana/web3.js";
import {
readAmmTransaction,
readCurveTransaction,
rpcTransactionFromResponse,
type ChainReader,
} from "@deepliquidity/sdk";
// asked only when the log was truncated (examples/_shared.ts also implements the optional
// previousTransaction, which a truncated sell or swap may need)
const reader: ChainReader = {
account: async (address) => {
const a = await conn.getAccountInfo(new PublicKey(address));
return a ? { data: a.data, owner: a.owner.toBase58() } : null;
},
};
const res = await conn.getTransaction(signature, { maxSupportedTransactionVersion: 0 });
if (res && !res.meta?.err) {
const tx = rpcTransactionFromResponse(res);
const curve = await readCurveTransaction(tx, signature, reader);
if (curve.status === "unreadable")
// truncated and not rebuildable: NO events; never treat it as "nothing happened"
console.error(`events missing from ${signature}: ${curve.reason}`);
else for (const { index, event, reconstructed } of curve.events) console.log(index, event.name);
const amm = await readAmmTransaction(tx, signature, reader); // DeepSwap swaps, same statuses
}status is complete (the log held everything; nothing else is read), reconstructed (the
missing events were rebuilt from the instructions and balances, proved against the chain, and
marked reconstructed: true, with the indices a complete log would have given) or unreadable
(the result holds no events: report it and store nothing of that transaction). For a live feed,
decode onLogs lines directly while the log is complete, and fetch and read the transaction
when it is not:
import { logsTruncated, parseEventsFromLogs } from "@deepliquidity/sdk";
conn.onLogs(DEEP_CURVE_PROGRAM_ID, (l) => {
if (l.err) return;
if (logsTruncated(l.logs)) return void readFullTransaction(l.signature); // as above
for (const { event } of parseEventsFromLogs(l.logs)) console.log(event.name, event);
});The log parsers (parseEventsFromLogs, parseFeeEventsFromLogs, parseAmmSwapEvents) only
accept Program data: lines emitted by the program itself (they track the invoke stack), so
another program cannot spoof DEEP events. examples/watch-launches.ts puts all of this together.
IDLs
import curveIdl from "@deepliquidity/sdk/idl/deep_curve.json" with { type: "json" };
import ammIdl from "@deepliquidity/sdk/idl/deep_amm.json" with { type: "json" };Anchor IDL spec 0.1.0. The SDK's decoders are tested field by field against these files, and the files against live on-chain accounts.
Examples
examples/ builds real transactions and simulates them on mainnet (sigVerify: false):
nothing is signed or sent, and no keypair is ever read. Pass --payer <public key> to choose
whose account the simulation runs as.
| file | what it does |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| read-curve.ts | Config, curve state, price, progress, completion, graduation pool |
| watch-launches.ts | onLogs on both programs; launches, trades, graduation, swaps; truncated logs read with readCurveTransaction / readAmmTransaction |
| quote-and-buy.ts | quote + buy, checks the TradeEvent against the quote |
| sell.ts | quote + sell |
| deepswap-swap.ts | DeepSwap swap_base_input with wrap/unwrap (buy, or round trip) |
| deepswap-liquidity.ts | deposit and withdraw with exact LP maths |
| claim-creator-fees.ts | curve claim_creator_fees and DeepSwap creator-fee collection |
npx tsx examples/read-curve.ts --rpc <your mainnet RPC URL>Licence
MIT AND Apache-2.0: the cp-swap ports listed in NOTICE are Apache-2.0 (LICENSE-APACHE),
everything else is MIT (LICENSE).
Links
Website and app · Docs · Integration guide · GitHub · Blog · Status · X · Telegram
