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
| Param | Description |
|---|
params.Initialized | Pool is live and will be indexed by aggregators |
params.Paused | All operations are paused in the pool |
params.RejectSwaps | Swaps 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
});
| Param | Type | Description |
|---|
user | PublicKey | The user’s wallet |
params.amountX | bigint | Amount of token X to deposit (in atoms) |
params.amountY | bigint | Amount of token Y to deposit (in atoms) |
params.expiration? | number | Optional slot expiration |
Withdraw
Build a withdraw instruction.
const ix = pool.withdraw(user, {
amountX: 500_000n,
amountY: 1_000_000n,
expiration: 418052063, //optional parameter
});