TypeScript SDK
Typed client, PDA helpers, error mirror, math utilities. Ships as ESM + CJS with declaration files.
Install
git clone https://github.com/REVY2026/hanami-engine.git
cd hanami-engine/sdk
yarn install
yarn buildOpen a bloom
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
| Method | Description |
|---|---|
initializePool | Create a new pool PDA + vaults |
createBloom | Open a time-bounded LP position |
swap | Constant-product swap with basis-point fee |
settleBloom | Permissionless settle after end_slot |
chirigiwa | Early exit with 5% principal penalty |
getPool | Fetch pool state |
getBloom | Fetch bloom state |
ensureUserAtas | Idempotent ATA creation for both pool tokens |
PDA helpers
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.
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
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