npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@questionmarket/sdk

v0.3.2

Published

TypeScript SDK for question.market prediction market contracts on Algorand

Readme

@questionmarket/sdk

TypeScript SDK for question.market prediction market contracts on Algorand.

Install

npm install @questionmarket/sdk

What's in the box

Contract clients -- typed wrappers for on-chain operations:

  • market-factory -- create markets atomically (bootstrap + fund + blueprint in one group)
  • question-market -- buy, sell, LP entry, fee claims, residual claims, resolution
  • market-schema -- market state parsing, version checks, status labels
  • protocol-config -- protocol-level configuration reads
  • base -- shared client config and Algorand connection types

LMSR math -- fixed-point arithmetic matching the AVM contract implementation:

  • quoteBuyForBudgetFromState / quoteBuyForSharesFromState -- trade quoting from indexed state
  • calculatePrices -- current price vector from LMSR state
  • calculateSellReturn -- USDC returned when selling shares
  • expFp, lnFp, logSumExpFp -- Taylor-series approximations at SCALE = 10^6

Blueprint toolkit -- resolution blueprint compiler, validator, and presets:

  • compiler -- template token replacement, validation, canonical JSON serialization
  • validate -- DAG structure checks, node type validation, edge consistency
  • presets -- built-in engine-native templates (api_fetch, llm_call, agent_loop, await_signal, etc.)
  • types -- full type definitions for blueprints, nodes, edges, trust classes, and child blueprint policies

Examples

Get prices for a market

import { calculatePrices, SCALE } from '@questionmarket/sdk'

// quantities and b come from on-chain state (all fixed-point at SCALE = 10^6)
const quantities = [5_000_000n, 3_000_000n, 2_000_000n]
const b = 10_000_000n

const prices = calculatePrices(quantities, b)
// prices[i] / SCALE gives the probability for outcome i
// prices always sum to SCALE (1.0)
console.log(prices.map(p => Number(p) / Number(SCALE)))

Quote a buy trade

import { quoteBuyForBudgetFromState } from '@questionmarket/sdk'

const quote = quoteBuyForBudgetFromState(
  {
    quantities: [5_000_000n, 3_000_000n],
    b: 10_000_000n,
    lpFeeBps: 100,      // 1% LP fee
    protocolFeeBps: 25,  // 0.25% protocol fee
  },
  0,                     // buy outcome 0
  500_000n,              // budget: 0.50 USDC (in micro-USDC)
)

console.log({
  shares: quote.shares,         // shares received (fixed-point)
  totalCost: quote.totalCost,   // actual cost in micro-USDC
  beforePrices: quote.beforePrices,
  afterPrices: quote.afterPrices,
})

Compile a resolution blueprint

import { compileResolutionBlueprint } from '@questionmarket/sdk/blueprints'
import type { ResolutionBlueprint } from '@questionmarket/sdk/blueprints'

const blueprint: ResolutionBlueprint = {
  id: 'entropy-reversal',
  version: 1,
  nodes: [
    {
      id: 'judge',
      type: 'llm_call',
      label: 'Evaluate evidence',
      config: {
        provider: 'anthropic',
        model: 'claude-sonnet-4-6',
        prompt:
          'Question: {{market.question}}\n' +
          'Outcomes: {{market.outcomes.indexed}}\n\n' +
          'Evaluate available evidence and return the correct outcome index.',
        allowed_outcomes_key: 'inputs.market.outcomes_json',
        timeout_seconds: 60,
      },
      position: { x: 0, y: 0 },
    },
    {
      id: 'success',
      type: 'return',
      label: 'Return success',
      config: {
        value: {
          status: 'success',
          outcome: '{{results.judge.outcome}}',
          reasoning: '{{results.judge.reasoning}}',
        },
      },
      position: { x: 200, y: 0 },
    },
  ],
  edges: [{ from: 'judge', to: 'success' }],
}

const compiled = compileResolutionBlueprint(blueprint, {
  question: 'Can entropy be reversed?',
  outcomes: ['Yes', 'No', 'Not enough data'],
  deadline: 1797897600,
})

console.log(`Blueprint size: ${compiled.bytes.length} bytes`)

Execute a trade on-chain

import algosdk from 'algosdk'
import { buy, getMarketState } from '@questionmarket/sdk/clients/question-market'

const algodClient = new algosdk.Algodv2('token', 'http://localhost', 4001)
const account = algosdk.mnemonicToSecretKey('your mnemonic here')
const signer = algosdk.makeBasicAccountTransactionSigner(account)
const appId = 1234
const marketState = await getMarketState(algodClient, appId)

await buy(
  {
    algodClient,
    appId,
    sender: account.addr,
    signer,
  },
  0,             // outcome index
  500_000n,      // max 0.50 USDC
  marketState.numOutcomes,
  31_566_704,    // USDC ASA ID
  1_000_000n,    // 1 share
)

Fixed-point conventions

All numeric values use bigint with a scale factor of 10^6 (the SCALE constant):

  • 1 share = 1_000_000n
  • 1 USDC = 1_000_000n (micro-USDC)
  • A price of 0.75 = 750_000n
  • Prices always sum to SCALE

This matches the Algorand contract's uint64 fixed-point arithmetic exactly.

Requirements

  • Node.js 20+

algosdk is shipped as a package dependency.

License

MIT