Rivisk

Getting started

Quickstart

Read a wallet's risk, stress it against a BTC drawdown, and receive a signed event. Point it at the hosted beta API or at your own instance.

Install#

bash
npm install @rivisk/sdk

One package, zero runtime dependencies, ESM only, Node 18 or newer. It also runs in browsers, Deno, Bun and edge runtimes.

Five steps#

  1. Create a client

    ts
    import { RiviskClient } from '@rivisk/sdk'; const rivisk = new RiviskClient({  baseUrl: process.env.RIVISK_API_URL ?? 'http://localhost:4000/api/v1',});

    Reads scoped to a public address need no credential at all.

  2. Index a wallet

    A wallet Rivisk has never seen has no snapshot yet. Ask for one. The call returns as soon as the job is queued; indexing takes a few seconds.

    ts
    const address = 'SP10GK6MG2GM7BCVYV7XBHK1JVJDHFDMNBENNBRC3';await rivisk.portfolios.refresh(address);   // 202 Accepted
  3. Read its risk

    import { fromE4, bpsToPercent } from '@rivisk/sdk'; const risk = await rivisk.portfolios.risk(address); risk.riskLevel;                                   // e.g. 'critical'fromE4(risk.healthFactorE4!);                     // e.g. 1.1798bpsToPercent(risk.liquidationDistanceBps!);       // e.g. 15.24 (% from liquidation)risk.sourceBlock;                                 // the Stacks block it describes

    If the wallet has not been indexed yet this returns 404. Refresh, wait a few seconds, and read again.

  4. Stress it

    ts
    const result = await rivisk.simulations.run(address, {  name: 'BTC -20%',  shocks: [{ symbol: 'sBTC', changeBps: -2000 }],}); const newlyLiquidatable = result.positions.filter(  (p) => !p.liquidatableBefore && p.liquidatableAfter,);

    Simulations write nothing, so they are safe to call as often as you like. The SDK treats them as idempotent and retries them through transient failures.

  5. Receive an event

    Register an endpoint with an API key or a wallet session (see Authentication), then verify every delivery:

    app/api/rivisk/route.ts
    import { constructWebhookEvent, SIGNATURE_HEADER } from '@rivisk/sdk'; export async function POST(req: Request) {  const raw = await req.text();   // the raw body, before any parsing  try {    const event = await constructWebhookEvent(      raw,      req.headers.get(SIGNATURE_HEADER),      process.env.RIVISK_WEBHOOK_SECRET!,    );    // event.type: 'risk.updated' | 'alert.triggered' | ...    return new Response('ok');  } catch {    return new Response('bad signature', { status: 400 });  }}

Next#

Read Core concepts before shipping anything that acts on these numbers. The API returns integers in fixed-point units, and a wallet with no debt has no health factor, which the API reports as null.