@hanami/sdk

TypeScript SDK

Typed client, PDA helpers, error mirror, math utilities. Ships as ESM + CJS with declaration files.

Install

bash
git clone https://github.com/REVY2026/hanami-engine.git
cd hanami-engine/sdk
yarn install
yarn build

Open a bloom

ts
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
import { HanamiClient, derivePoolPda } from "@hanami/sdk";
import BN from "bn.js";

const connection = new Connection(process.env.HANAMI_RPC_URL!);
const wallet = Keypair.fromSecretKey(/* ... */);
const client = new HanamiClient({ connection, wallet });

const tokenA = new PublicKey("So11111111111111111111111111111111111111112");
const tokenB = new PublicKey("EPjFWdd5AufqSSqeM2qN1XzybapC8G4wEGGkZwyTDt1v");
const [pool] = derivePoolPda(tokenA, tokenB);

const { bloom } = await client.createBloom({
  pool,
  amountA: new BN(1_000_000),
  amountB: new BN(1_000_000),
  durationSlots: new BN(2_400),
});

API surface

MethodDescription
initializePoolCreate a new pool PDA + vaults
createBloomOpen a time-bounded LP position
swapConstant-product swap with basis-point fee
settleBloomPermissionless settle after end_slot
chirigiwaEarly exit with 5% principal penalty
getPoolFetch pool state
getBloomFetch bloom state
ensureUserAtasIdempotent ATA creation for both pool tokens

PDA helpers

ts
import {
  derivePoolPda,
  deriveVaultAPda,
  deriveVaultBPda,
  deriveBloomPda,
  sortMintPair,
} from "@hanami/sdk";

const [pool] = derivePoolPda(mintA, mintB);
const [vaultA] = deriveVaultAPda(pool);
const [vaultB] = deriveVaultBPda(pool);
const [bloom] = deriveBloomPda(pool, owner.publicKey, new BN(1));

Typed errors

Anchor error codes are mirrored as a TypeScript enum so you can pattern-match on them without parsing strings.

ts
import { HanamiError, HanamiErrorCode } from "@hanami/sdk";

try {
  await client.settleBloom({ pool, bloom });
} catch (e) {
  if (e instanceof HanamiError && e.code === HanamiErrorCode.BloomNotMatured) {
    console.warn("not yet matured, try again after end_slot");
  } else {
    throw e;
  }
}

Utilities

ts
import { formatLamports, slotsToDuration, applyChirigiwaPenalty } from "@hanami/sdk";

formatLamports(new BN(1_500_000), 6);   // "1.5"
slotsToDuration(2_400).minutes;          // ~16
applyChirigiwaPenalty(new BN(10_000));   // 9500
edit on github ↗