Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.hadron.fi/llms.txt

Use this file to discover all available pages before exploring further.

Install the Hadron package
npm i @hadron-fi/sdk @solana/web3.js

Initializing a pool

Initialising a hadron pool gives you your own propAMM instance.
import { Hadron, Q32_ONE } from "@hadron-fi/sdk";

const { instructions, poolAddress, seed } = Hadron.initialize(payer.publicKey, {
  //Mandatory params
  mintX,
  mintY,
  authority: payer.publicKey,
  initialMidpriceQ32: Q32_ONE, // midprice = 1.0 m
  //Optional params
  seed: "",
  tokenProgramX: "", //pick between token2022 and SPL tokens
  tokenProgramY: "", //SPL 20 Default for X and Y
  maxPrefabSlots: "1-10", // this decides how many strategy presets you store. Cannot be changed
  maxCurvePoints: "", // 16 by default
});

//// Send the instructions (group into transactions as needed)
// ...
With default parameters the CurvePrefabs account is ~15 KB, so two allocate instructions are returned (Solana’s single-instruction realloc limit is 10 KB). Send the allocates first, then the initialize.

setPoolState

Pools are initialised by default as Reject Swaps. This is done to deposit funds to prevent indexing from aggregators
pool.setPoolState(authority, { newState: PoolState.Paused });

//// Send the instructions
ParamDescription
params.InitializedPool is live and will be indexed by aggregators
params.PausedAll operations are paused in the pool
params.RejectSwapsSwaps are rejected, but the user can perform all other actions

Depositing Funds

Build a deposit instruction.

const ix = pool.deposit(user, {
  amountX: 1_000_000n,
  amountY: 2_000_000n,
  expiration: 418052063, //optional parameter
});
ParamTypeDescription
userPublicKeyThe user’s wallet
params.amountXbigintAmount of token X to deposit (in atoms)
params.amountYbigintAmount of token Y to deposit (in atoms)
params.expiration?numberOptional slot expiration

Withdraw

Build a withdraw instruction.
const ix = pool.withdraw(user, {
  amountX: 500_000n,
  amountY: 1_000_000n,
  expiration: 418052063, //optional parameter
});