Skip to content
markpaper

src/account/fixtures.ts

v0.2.0 · 2.3 KB

Download file
// Test fixtures for account reads: response shapes from the knowledge base; every number (prices, sizes,
// times, nonces) is synthetic and round. Not built.

import { BTC_RAW, PONS_RAW, symbolsPayload, XRP_RAW } from '../markets/fixtures.js';
import { parseSymbols } from '../markets/parse.js';
import { decimalToX18, X18 } from '../numbers/x18.js';
import { buildNonce } from '../signing/nonce.js';

export const UNIVERSE = parseSymbols(
  symbolsPayload({ 'BTC-PERP': BTC_RAW, 'XRP-PERP': XRP_RAW, 'PONS-PERP': PONS_RAW }),
);

/** `subaccount_info` with a 0.5 BTC long (entry ~66 000, oracle 66 120) and a flat XRP entry. */
export function subaccountInfoPayload(overrides: Record<string, unknown> = {}): Record<string, unknown> {
  return {
    exists: true,
    healths: [
      { health: (1000n * X18).toString() },
      { health: (1100n * X18).toString() },
      { health: (1234n * X18 + X18 / 2n).toString() },
    ],
    perp_balances: [
      {
        product_id: 2,
        balance: { amount: decimalToX18('0.5').toString(), v_quote_balance: (-33000n * X18).toString() },
      },
      { product_id: 8, balance: { amount: '0', v_quote_balance: '0' } },
    ],
    perp_products: [
      {
        product_id: 2,
        oracle_price_x18: (66120n * X18).toString(),
        risk: { long_weight_initial_x18: '950000000000000000' },
      },
      {
        product_id: 8,
        oracle_price_x18: decimalToX18('1.1281').toString(),
        risk: { long_weight_initial_x18: '900000000000000000' },
      },
    ],
    ...overrides,
  };
}

/** Synthetic round clock (ms). */
export const NOW_MS = 1_780_000_000_000;

/** One raw resting order in the live `orders` shape (synthetic values). */
export function rawOrder(over: Partial<Record<string, unknown>> = {}): Record<string, unknown> {
  const amount = (-decimalToX18('0.25')).toString();
  return {
    product_id: 2,
    sender: `0x${'0'.repeat(64)}`,
    price_x18: (67000n * X18).toString(),
    amount,
    expiration: '18446744073709551615',
    order_type: 'default',
    nonce: buildNonce({ recvTimeMs: NOW_MS + 60_000, random: 3 }).toString(),
    appendix: '1',
    unfilled_amount: amount,
    digest: `0x${'ab'.repeat(32)}`,
    placed_at: NOW_MS / 1000,
    ...over,
  };
}

export function ordersData(orders: unknown[]): { product_orders: Array<{ orders: unknown[] }> } {
  return { product_orders: [{ orders }] };
}
All files