Skip to main content

Install

npm i @hadron-so/sdk @solana/web3.js

Create a pool client

import { Connection, PublicKey } from "@solana/web3.js";
import { Hadron } from "@hadron-so/sdk";

const connection = new Connection("https://api.mainnet-beta.solana.com");
const poolAddress = new PublicKey("REPLACE_WITH_POOL_ADDRESS");

const pool = await Hadron.load(connection, poolAddress);

Read core state

const midprice = pool.getMidprice();
const spread = pool.getSpreadFactor();
const active = pool.getActiveCurveSlots();

console.log({ midprice, spread, active });

Build a swap instruction

import { PublicKey } from "@solana/web3.js";

const user = new PublicKey("REPLACE_WITH_USER_PUBKEY");
const feeRecipient = new PublicKey("REPLACE_WITH_FEE_RECIPIENT");

const swapIx = pool.swap(user, {
  isX: true,               // true = sell X for Y, false = sell Y for X
  amountIn: 1_000_000n,
  minOut: 0n,              // set > 0 for slippage protection
  feeRecipient,
});

Next steps

  • Read SDK Reference for a curated map of the APIs you will use most.
  • Use Reference -> API for full autogenerated docs.
  • Use the instruction builders for deposit, withdraw, curve updates, and authority management.
  • Pin and document your network/program IDs in your app configuration.