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

@protocolwealthos/onchain-accounting-contract

v0.2.1

Published

PII-free TypeScript ABI for nexus-core accounting 0.2.0: strict runtime invariants, structural schema hints, and read-only tool definitions.

Readme

@protocolwealthos/onchain-accounting-contract

Strict, PII-free TypeScript ABI for nexus-core onchain accounting contract 0.2.0.

The math and methodology live in the sibling Python engine. This package ships the reusable cross-language boundary: TypeScript types inferred from strict Zod schemas, runtime request/response validation, generated Draft 2020-12 JSON Schema hints, version/tool constants, fail-closed response-correlation assessments, and read-only MCP tool declarations.

npm install @protocolwealthos/onchain-accounting-contract

What It Covers

  • price_history: historical USD prices with explicit unpriced gaps.
  • decode_onchain_events: public-chain movements to a de-identified event ledger.
  • compute_cost_basis: account-scoped FIFO lots, transfers, fees, replay, lineage, coverage, and completeness.
  • onchain_pnl_report: realized-PnL and tax-year rollups with methodology provenance and a tax-awareness disclaimer.
  • describe: REST gateway introspection schema and all gateway/tool constants.

Every request object is strict. Unknown fields fail validation. The generic parser recursively rejects identity-shaped keys, and every account_ref must be opaque: raw EVM, Bitcoin, or supported-chain base58 wallet shapes are rejected. Consumers remain responsible for a stronger value-level PII/canary boundary before network egress because only the private application knows whether an otherwise opaque string is reversible or client-derived.

Version Axes

These versions are intentionally distinct:

| Constant | Current | Meaning | |---|---:|---| | VERSION | 0.2.0 | npm package version; Changesets owns releases | | ACCOUNTING_CONTRACT_VERSION | 0.2.0 | Nexus request/response wire ABI | | ACCOUNTING_METHOD_VERSION | 2.0.0 | FIFO calculation methodology | | ACCOUNTING_REPLAY_VERSION | 1.0.0 | Report-window replay protocol |

A consumer must validate the response body against the tool-specific schema; that validation includes the exact contractVersion handshake. A contract change is a cross-repo event: update Nexus, this package, fixtures, and every consumer together.

0.2.0 is versioned and prepared as the first public npm release, promoted from the pre-release 0.1.0 source baseline. Maintainer-local npm publication and registry verification remain pending. The package version is independent of the Nexus wire version; both currently read 0.2.0 and may diverge later. VERSION is checked against the package manifest in CI and is updated by the Changesets version workflow.

The runtime Zod schemas are authoritative. ACCOUNTING_MODEL_INPUT_SCHEMA_HINTS and ACCOUNTING_RESPONSE_STRUCTURE_SCHEMA_HINTS are generated with explicit input/output modes for model discovery and structural documentation. They do not represent custom Zod refinements such as exact accounting arithmetic, partition counts, or opaque-reference checks; always call the runtime parsers.

Runtime response validation mirrors Nexus calendar and aggregate semantics. holding_days is the difference between UTC calendar dates, and a disposition is long term only after its one-year calendar anniversary (February 29 rolls to February 28 in a non-leap anniversary year). Known serialized totals are required and exact, and a disposal's acquisition-fee component cannot exceed its matched cost basis. Open-lot totals are null only when a serialized component is unknown or an unmatched_transfer_out gap means inventory is hidden. Incomplete dispositions must enumerate the exact semantic missing_fields implied by their values and provenance. A complete result cannot report unknown-basis open lots, and an opening-state replay cannot also claim pre-period events.

Exact Decimals

Accounting amounts are strings, never JavaScript numbers. Runtime schemas enforce the same bounded decimal envelopes as Nexus:

| Value | Fractional digits | Integer digits | |---|---:|---:| | Direct quantities and unit prices | 36 | 42 | | Explicit monetary totals | 72 | 84 | | Authoritative replay/result values | 256 | 128 |

Scientific notation is accepted only when its represented value fits the applicable envelope. NaN, infinity, oversized coefficients, and extreme exponents fail before arithmetic. Exact comparison and correlation helpers use integer coefficients rather than binary floating point.

Usage

import {
  ACCOUNTING_CONTRACT_VERSION,
  assessAccountingResponseCorrelation,
  isAccountingResponseCorrelationVerified,
  isNexusAccountingResultEligibleForComposition,
  parseAccountingRequest,
  parseAccountingResponse,
} from "@protocolwealthos/onchain-accounting-contract";

const request = parseAccountingRequest("compute_cost_basis", {
  events: [],
  report_window: {
    start_at: 1_704_067_200,
    end_at: 1_735_689_600,
    full_history: true,
  },
  method: "fifo",
});

// `wireBody` is unknown JSON returned by the versioned engine gateway.
declare const wireBody: unknown;
const response = parseAccountingResponse("compute_cost_basis", wireBody);

console.log(ACCOUNTING_CONTRACT_VERSION); // "0.2.0"
const correlation = assessAccountingResponseCorrelation(
  "compute_cost_basis",
  request,
  response,
);
console.log(correlation.status); // "unverifiable" in wire contract 0.2.0
console.log(
  isAccountingResponseCorrelationVerified("compute_cost_basis", request, response),
); // false
console.log(isNexusAccountingResultEligibleForComposition(response));

Correlation is intentionally tri-state: verified, partial, or unverifiable. Every price override must uniquely identify a requested coin/timestamp coordinate and verifies only when its exact value and override provenance are echoed. Duplicate query coordinates are allowed; one unique override applies deterministically to each matching ordered response slot. Hintless decoder classifications can verify; decoder requests carrying protocol_hint, method, movement counterparty, or transfer metadata dropped by a non-transfer classification are only partial because contract 0.2.0 does not echo those inputs. Cost-basis and PnL responses are always unverifiable because they do not carry a canonical request digest. The boolean helper returns true only for verified.

Private consumers must bind each response to its originating in-flight request, request identifier, authenticated transport context, and immutable audit record before accepting it. A future canonical request digest requires a coordinated wire-contract version bump across Nexus, this package, fixtures, and consumers.

isNexusAccountingResultEligibleForComposition is deliberately engine-scoped and fail-closed. It requires a strictly valid result, approved methodology, bounded replay, complete partitions, no gaps or unresolved coverage, and complete dispositions. It does not authorize client delivery, approve a statement, satisfy books-and-records retention, or replace advisor/CCO review. Contract 0.2.0 currently reports pending_governance_review, so composition eligibility remains false. Passing CI or code review is not methodology approval.

Tool Declarations

ACCOUNTING_TOOL_DEFINITIONS and registerAccountingTools(registry) declare the four calculation tools as advisor-tier, read-only, idempotent tools. They do not implement math or transport. The describe handler is REST introspection and is therefore represented in gateway constants/schemas, not registered as a global model-visible tool with a collision-prone generic name.

isAccountingGatewayCompatible accepts discovery only when the contract is exactly 0.2.0 and the duplicate-free handler set contains all five handlers (describe plus the four calculations), regardless of order.

Contract Boundary

This package contains generic, public-safe shapes only. It does not ingest client data, map wallets to clients, retain records, prepare or release statements, render reports, provide tax advice, or implement a tax return. Those responsibilities belong to the consumer application. Do not commit client or advisor data, reversible private identifiers, credentials, API keys, production endpoint URLs, or firm-specific policy values here.

The contract mirrors the Apache-2.0 Nexus implementation and public accounting methodology. Golden fixtures are synthetic and de-identified. No AGPL source was copied.

Apache-2.0. Educational accounting/tax-awareness substrate only, not tax, investment, or legal advice.