Examples
Three runnable scripts that exercise the SDK against a Solana validator. Use a localnet for fast iteration, or devnet for end-to-end verification.
Run
yarn install
ANCHOR_PROVIDER_URL=http://localhost:8899 \
ANCHOR_WALLET=~/.config/solana/id.json \
yarn ts-node examples/01-create-pool.ts01 · Create pool
Creates two mock SPL mints with 6 decimals and initialises a pool with a 30 bps fee.
const decimals = 6;
const mintA = await createMint(connection, wallet, wallet.publicKey, null, decimals);
let mintB = await createMint(connection, wallet, wallet.publicKey, null, decimals);
if (mintA.toBuffer().compare(mintB.toBuffer()) > 0) {
const tmp = await createMint(connection, wallet, wallet.publicKey, null, decimals);
mintB = tmp;
}
const client = new HanamiClient({ connection, wallet });
const { pool } = await client.initializePool({
tokenAMint: a,
tokenBMint: b,
feeBps: 30,
});02 · Bloom lifecycle
Opens a bloom, waits for maturity, calls settleBloom. Logs the deposited and withdrawn amounts.
const { bloom } = await client.createBloom({
pool,
amountA: new BN(1_000_000),
amountB: new BN(1_000_000),
durationSlots: new BN(40),
});
const blState = await client.getBloom(bloom);
await waitForSlot(connection, blState.endSlot.toNumber() + 1);
const sig = await client.settleBloom({ pool, bloom });03 · Chirigiwa
Opens a long bloom and immediately exits via chirigiwa, paying the 5% principal penalty.
const { bloom } = await client.createBloom({
pool,
amountA: new BN(1_000_000),
amountB: new BN(1_000_000),
durationSlots: new BN(1_000_000),
});
const sig = await client.chirigiwa({ pool, bloom });