Skip to content

Transactions

The SDK provides helper functions to create transaction payloads for all supported operations.

:::tip High-Level API For most use cases, use the high-level methods on KaizenClient directly:

await client.transfer(to, amount);
await client.withdraw(amount, destination, chainId);
await client.nominateApiWallet(wallet, expiry);
await client.submitRfq(quote);

The payload builders below are useful when you need more control (e.g., custom timestamps) or want to inspect/log payloads before sending. :::

Account Transactions

Transfer

Transfer funds to another account.

import { transfer, parseUSDC, formatUSDC } from "@kaizen-core/sdk";
 
const payload = transfer(
  "0xRecipient...", // to: recipient address
  parseUSDC("100.00") // amount: in smallest unit (6 decimals)
);

Nominate API Wallet

Authorize a hot wallet to sign transactions on your behalf.

API wallets can perform all trading operations but cannot:

  • Withdraw funds (only the main wallet can withdraw)
  • Transfer funds (only the main wallet can transfer)
import { nominateApiWallet } from "@kaizen-core/sdk";
 
const payload = nominateApiWallet(
  "0xApiWallet...", // wallet: address to authorize
  Date.now() + 86400000 // expiry: timestamp in ms (24 hours), 0 = no expiry
);

Revoke API Wallet

Remove authorization from an API wallet.

import { revokeApiWallet } from "@kaizen-core/sdk";
 
const payload = revokeApiWallet("0xApiWallet...");

Withdraw

Withdraw funds to an external address (for bridging out).

import { withdraw, parseUSDC } from "@kaizen-core/sdk";
 
const payload = withdraw(
  parseUSDC("500.00"), // amount
  "0xExternalAddress..." // destination on external chain
);

RFQ Transactions

Submit Thesis

Submit a thesis with a solver's quote.

import { rfqSubmit, parsePrice, parseUSDC } from "@kaizen-core/sdk";
 
const payload = rfqSubmit({
  thesisType: "box", // Only "box" is supported
  oraclePair: {
    base: "0x0000000000000000000000000000000000000001", // BTC
    quote: "0x0000000000000000000000000000000000000002", // USDC
  },
  priceRange: {
    lower: parsePrice("94000.00"),
    upper: parsePrice("96000.00"),
  },
  betAmount: parseUSDC("100.00"),
  payout: parseUSDC("180.00"),
  startTime: Date.now() + 5000,
  endTime: Date.now() + 65000,
  solverQuote: {
    // Quote from solver API
    user: "0x...",
    thesisType: "box",
    oraclePair: { base: "0x...", quote: "0x..." },
    priceRange: { lower: 94000000000n, upper: 96000000000n },
    betAmount: 100000000n,
    payout: 180000000n,
    startTime: Date.now() + 5000,
    endTime: Date.now() + 65000,
    deadline: Date.now() + 30000,
    signature: "0x...",
  },
});

Settle Thesis

Settle a thesis manually after the end time.

import { rfqSettle } from "@kaizen-core/sdk";
 
const payload = rfqSettle(1n); // thesisId

Price Utilities

Parse and Format Prices

import { parsePrice, formatPrice } from "@kaizen-core/sdk";
 
// Parse price string to bigint (6 decimals by default)
const price = parsePrice("95123.456789"); // 95123456789n
 
// Format bigint to string
const formatted = formatPrice(95123456789n); // "95123.456789"
 
// Custom decimals
const btcPrice = parsePrice("95000.00", 8); // 9500000000000n (8 decimals)

Create Price Range

Create a range around a center price.

import { createPriceRange, parsePrice } from "@kaizen-core/sdk";
 
const centerPrice = parsePrice("95000.00");
const range = createPriceRange(centerPrice, 2); // ±1% (2% total width)
 
console.log({
  lower: range.lower, // 94050000000n
  upper: range.upper, // 95950000000n
});

USDC Utilities

import { parseUSDC, formatUSDC } from "@kaizen-core/sdk";
 
// Parse USDC amount (always 6 decimals)
const amount = parseUSDC("100.50"); // 100500000n
 
// Format to string
const formatted = formatUSDC(100500000n); // "100.500000"

Timing Utilities

Create Thesis Timing

import { createThesisTiming } from "@kaizen-core/sdk";
 
const timing = createThesisTiming(
  5, // delaySeconds: thesis starts in 5 seconds
  60, // durationSeconds: thesis lasts 60 seconds
  30 // deadlineSeconds: quote valid for 30 seconds
);
 
console.log({
  startTime: timing.startTime, // now + 5s
  endTime: timing.endTime, // now + 65s
  deadline: timing.deadline, // now + 30s
});

Calculate End Time

import { calculateEndTime } from "@kaizen-core/sdk";
 
const startTime = Date.now();
const endTime = calculateEndTime(startTime, 60); // 60 seconds later

Quote Request Builder

Build a request for the solver API.

import {
  buildQuoteRequest,
  parsePrice,
  parseUSDC,
  createThesisTiming,
} from "@kaizen-core/sdk";
 
const timing = createThesisTiming();
const request = buildQuoteRequest({
  user: "0x...",
  thesisType: "box",
  base: "0x0000000000000000000000000000000000000001",
  quote: "0x0000000000000000000000000000000000000002",
  lowerPrice: parsePrice("94000.00"),
  upperPrice: parsePrice("96000.00"),
  betAmount: parseUSDC("100.00"),
  ...timing,
});
 
// Send to solver API
const response = await fetch("http://solver:4000/quote", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify(request),
});

Complete Thesis Flow Example

import {
  createClient,
  type KaizenClient,
  parsePrice,
  parseUSDC,
  createThesisTiming,
} from "@kaizen-core/sdk";
 
async function submitThesis(client: KaizenClient, solverUrl: string) {
  const timing = createThesisTiming(5, 60, 30);
 
  // 1. Request quote from solver
  const quote = await client.requestQuote(solverUrl, {
    user: client.accountAddress!, // Use accountAddress (works for both owner and API wallet)
    thesisType: "box",
    base: "0x0000000000000000000000000000000000000001",
    quote: "0x0000000000000000000000000000000000000002",
    lowerPrice: parsePrice("94000.00"),
    upperPrice: parsePrice("96000.00"),
    betAmount: parseUSDC("100.00"),
    ...timing,
  });
 
  // 2. Submit thesis with high-level API (handles quote signing automatically)
  const submitReceipt = await client.submitRfq(quote, {
    waitForConfirmation: true,
  });
 
  console.log(`Thesis submitted: ${submitReceipt.hash}`);
 
  // 3. Settlement is automatic via the Settler service
  // Subscribe to thesis updates to track settlement status
  client.subscribeMyTheses((event) => {
    if (event.type === "thesis" && event.thesis.status === "settled") {
      console.log(`Thesis ${event.thesis.id} settled!`);
    }
  });
}