npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@derp-trade/sdk

v0.5.0

Published

An SDK for derp.trade

Readme

@derp-trade/sdk

A TypeScript SDK for derp.trade, a Solana-based derivatives trading platform using abstract futures.

The SDK helps you build derp.trade transactions, resolve market metadata, push prices, route order payments, and read market and position state from Solana.

Installation

npm install @derp-trade/sdk

Quickstart

Initialize the SDK

import { DerpSDK, MAINNET_RPC_URL } from "@derp-trade/sdk";
import { Wallet } from "@coral-xyz/anchor";
import { Connection, Keypair } from "@solana/web3.js";

const connection = new Connection(MAINNET_RPC_URL, "confirmed");
const keypair = Keypair.fromSecretKey(/* your secret key bytes */);
const wallet = new Wallet(keypair);

const sdk = new DerpSDK(connection, wallet);

⚠️ Important: The wallet provided when constructing the SDK should have funds (SOL) on it, otherwise some SDK functions will fail.

Place an Order

import BN from "bn.js";
import { PublicKey, Transaction } from "@solana/web3.js";

const mint = new PublicKey("6ogzHhzdrQr9Pgv6hZ2MNze7UrzBMAFyBBWUYp1Fhitx");

const instructions = await sdk.getOrderInstructions(mint, {
  reduceOnly: false,
  side: "long",
  orderAmount: new BN(1_000_000), // 1 USDT, USDT has 6 decimals
  leverageBps: new BN(20_000), // 2x leverage
});

const tx = new Transaction().add(...instructions);
const signature = await sdk.provider.sendAndConfirm(tx);

getOrderInstructions returns everything needed for a normal order: price update instructions followed by the order instruction.

Core Concepts

Amounts

Use BN for all raw on-chain amounts.

  • orderAmount: input amount for the selected payment route.
  • leverageBps: leverage in basis points, where 10_000 is 1x and 20_000 is 2x.
  • Direct USDT and USDC amounts use 6 decimals.
  • SOL amounts use lamports.
  • Native token amounts use that token's base units.

Sides and Order Modes

await sdk.getOrderInstructions(mint, {
  reduceOnly: false,
  side: "short",
  orderAmount: new BN(5_000_000),
  leverageBps: new BN(15_000),
});

Set reduceOnly: true when the order should only reduce an existing position. Set useSize: true when orderAmount represents position size instead of payment input.

Referrals

const instructions = await sdk.getOrderInstructions(
  mint,
  {
    reduceOnly: false,
    side: "long",
    orderAmount: new BN(1_000_000),
    leverageBps: new BN(20_000),
  },
  {
    referralRecipient: referrerPublicKey,
    referralFeeBps: 25,
  },
);

Routing Payments

Orders can be paid directly with USDT or routed from supported quote assets.

const route = await sdk.buildRoutingContext("USDC", wallet.publicKey, {
  paymentAmountUsd: 25,
});

const instructions = await sdk.getOrderInstructions(mint, {
  reduceOnly: false,
  side: "long",
  orderAmount: route.orderAmount,
  routingContext: route,
  leverageBps: new BN(20_000),
});

Supported route inputs:

| Currency | Use case | Required options | | --- | --- | --- | | USDT | Direct USDT payment | paymentAmountUsd optional | | USDC | Route USDC to USDT | paymentAmountUsd | | SOL | Route SOL to USDT | paymentAmountUsd, solPrice |

Example SOL route:

const route = await sdk.buildRoutingContext("SOL", wallet.publicKey, {
  paymentAmountUsd: 50,
  solPrice: 150,
});

Managing Positions

Close a Position

const closeInstructions = await sdk.getClosePositionInstructions(mint);
await sdk.provider.sendAndConfirm(new Transaction().add(...closeInstructions));

If you already fetched the position, pass it to avoid another RPC read:

const position = await sdk.rawPosition(mint, wallet.publicKey);
const closeInstructions = await sdk.getClosePositionInstructions(mint, position);

Deposit and Withdraw Collateral

const depositIx = await sdk.rawDepositInstruction(
  mint,
  new BN(10_000_000), // 10 USDT
);

const withdrawIx = await sdk.rawWithdrawInstruction(mint);

Market Data

Use converted helpers when you want JavaScript numbers:

const status = await sdk.marketStatus(mint);
const position = await sdk.positionState(mint, wallet.publicKey);

console.log(status.markPrice, status.fundingRate);
console.log(position.side, position.size, position.collateral);

Use raw helpers when you want the Anchor account shape and BN values:

const rawMarket = await sdk.rawMarket(mint);
const rawOracle = await sdk.rawOracle(mint);
const rawPosition = await sdk.rawPosition(mint, wallet.publicKey);
const rawStatus = await sdk.rawMarketStatus(mint);
const config = await sdk.config();

You can also resolve the market type and token standard:

const market = await sdk.resolveMarket(mint);
const launchpad = await sdk.detectMarket(mint);

console.log(market.launchpad.launchpad, market.tokenStandard);
console.log(launchpad);

Supported Markets

The SDK supports the market sources used by derp.trade:

| Launchpad | Identifier | Notes | | --- | --- | --- | | Pump.fun | pump | Pump.fun and PumpSwap markets | | LetsBonk / Raydium LaunchLab | bonk | LaunchLab tokens with Raydium CPMM liquidity | | Meteora | meteora | Meteora DBC and DAMM v2 markets | | Raydium AMM v4 | raydiumAmmV4 | Raydium AMM v4 markets | | derp.trade feed | derpFeed | Signed derp.trade price feeds | | External | external | Supported external pool markets |

Market metadata is usually resolved automatically. If you already know the launchpad, or if you are building instructions before metadata is available, pass it explicitly:

await sdk.getOrderInstructions(
  mint,
  {
    reduceOnly: false,
    side: "long",
    orderAmount: new BN(1_000_000),
    leverageBps: new BN(20_000),
  },
  undefined,
  undefined,
  "pump",
);

For launchpads that need extra accounts, pass a LaunchpadData object:

await sdk.getPricePushInstructions(mint, {
  launchpadData: {
    launchpad: "meteora",
    meteoraDbcConfig,
    quoteMint,
  },
});

await sdk.getPricePushInstructions(mint, {
  launchpadData: {
    launchpad: "raydiumAmmV4",
    openbookMarket,
  },
});

Price Push Instructions

Most SDK methods that need fresh prices build the price push instructions for you. You can also build them directly:

const pushInstructions = await sdk.getPricePushInstructions(mint);
const pushInstruction = await sdk.getPricePushInstruction(mint);

Convenience helpers are also available:

const pumpPush = await sdk.rawPricePushPumpInstruction(mint);
const bonkPush = await sdk.rawPricePushBonkInstruction(mint);
const externalPush = await sdk.rawPricePushExternalInstruction(mint);

When market metadata is resolved through the Derp API, pump.fun quote mints and token standards are applied automatically. For explicit pump pushes, pass the quote mint and token standard:

import { USDC_ID } from "@derp-trade/sdk";

const pumpPush = await sdk.getPricePushInstruction(
  mint,
  { launchpad: "pump", quoteMint: USDC_ID, tokenStandard: "token2022" },
  wallet.publicKey,
);

const rawPumpPush = await sdk.rawPricePushPumpInstruction(mint, {
  user: wallet.publicKey,
  quoteMint: USDC_ID,
  tokenStandard: "token2022",
});

Creating Markets

const createInstructions = await sdk.getCreateMarketInstructions(mint, "pump");
await sdk.provider.sendAndConfirm(new Transaction().add(...createInstructions));

Pass tokenStandard for Token-2022 mints:

await sdk.getCreateMarketInstructions(mint, "pump", wallet.publicKey, "token2022");

Low-Level Access

The SDK exposes the underlying typed Anchor program for advanced integrations:

import { getMarketStatePda } from "@derp-trade/sdk";

const program = sdk.program;
const marketPda = getMarketStatePda(mint);

const marketAccount = await program.account.marketState.fetch(marketPda);

Useful exports include:

import {
  DERP_PROGRAM_ID,
  GLOBAL_CONFIG_PDA,
  MAINNET_RPC_URL,
  getMarketStatePda,
  getOracleStatePda,
  getPositionStatePda,
  getAtaAddress,
} from "@derp-trade/sdk";

API Overview

Constructor

new DerpSDK(connection, wallet);

Trading

sdk.getOrderInstructions(mint, params, referralParams?);
sdk.getOrderInstructions(mint, params, referralParams?, undefined, launchpadData?, user?);
sdk.rawOrderRoutedInstruction(mint, params, referralParams?, options?);
sdk.getClosePositionInstructions(mint, positionState?, referralParams?);
sdk.getClosePositionInstructions(mint, positionState?, referralParams?, undefined, launchpadData?, user?, routingContext?);
sdk.rawDepositInstruction(mint, amount, user?);
sdk.rawWithdrawInstruction(mint, user?);

Market and Account Reads

sdk.marketStatus(mint, launchpadData?, user?);
sdk.rawMarketStatus(mint, launchpadData?, user?);
sdk.positionState(mint, user?);
sdk.rawPosition(mint, user?);
sdk.rawMarket(mint);
sdk.rawOracle(mint);
sdk.config();
sdk.resolveMarket(mint, options?);
sdk.detectMarket(mint);

Price Pushes and Market Creation

sdk.getPricePushInstructions(mint, options?);
sdk.getPricePushInstruction(mint, launchpadData?, user?);
sdk.getCreateMarketInstructions(mint, launchpadData, user?, tokenStandard?);

Routing

sdk.buildRoutingContext("USDT" | "USDC" | "SOL", user, options?);

License

MIT