Hanzo
Hanzo Skills Reference

Hanzo Treasury

Hanzo Treasury is a programmable financial infrastructure stack providing a double-entry ledger, payment connectors, virtual wallets, reconciliation, and workflow orchestration. Go monorepo (forked...

Overview

Hanzo Treasury is a programmable financial infrastructure stack providing a double-entry ledger, payment connectors, virtual wallets, reconciliation, and workflow orchestration. Go monorepo (forked from Formance Stack). Uses Earthly for builds. License: MIT.

Why Hanzo Treasury?

  • Double-entry ledger: Immutable, programmable source of truth for all financial transactions
  • Numscript DSL: Domain-specific language for modeling complex monetary flows
  • 50+ payment connectors: Unified API for payment processing across providers
  • Virtual wallets: Multi-currency with hold/release mechanics
  • Reconciliation: Auto-match ledger entries against payment provider data
  • Workflow orchestration: Composable payment and treasury operation flows
  • Event-driven: JSON Schema-validated events across all services

Tech Stack

  • Language: Go (module: github.com/formancehq/stack, Go 1.22)
  • Build: Earthly (v0.8)
  • Events: Go + Node.js (JSON Schema validation with gojsonschema)
  • API: OpenAPI 3.0.3 (merged spec from all sub-services)

OSS Base

Repo: hanzoai/treasury (Formance Stack fork). Default branch: main.

When to use

  • Recording financial transactions with double-entry accounting
  • Payment routing across multiple providers
  • Multi-currency virtual wallet management
  • Reconciling ledger data against external payment sources
  • Orchestrating multi-step payment workflows
  • Modeling complex fee splits and fund distributions with Numscript

Hard requirements

  1. Go 1.22+ for building
  2. Earthly for the build system
  3. PostgreSQL for ledger and payment data storage
  4. Docker for running the full stack locally

Quick reference

ItemValue
Ledger APIPOST /v2/ledger/{name}/transactions
Accounts APIGET /v2/ledger/{name}/accounts
Payments APIPOST /v2/payments
Wallets APIPOST /v2/wallets
Reconciliation APIPOST /v2/reconciliation/policies
Local Port3068 (ledger)
LicenseMIT
Repogithub.com/hanzoai/treasury

One-file quickstart

Start local stack

docker compose up -d

Create a ledger transaction

curl -X POST http://localhost:3068/v2/ledger/demo/transactions \
  -H "Content-Type: application/json" \
  -d '{
    "postings": [{
      "source": "world",
      "destination": "users:001",
      "amount": 10000,
      "asset": "USD/2"
    }]
  }'

Numscript example

// Transfer with multi-party fee split
send [USD/2 10000] (
  source = @users:001
  destination = {
    90% to @merchants:042
    10% to {
      50% to @platform:fees
      50% to @platform:reserve
    }
  }
)

Core Concepts

Architecture

hanzo/commerce    Storefront, catalog, orders
       |
hanzo/payments    Payment routing (50+ processors)
       |
hanzo/treasury    Ledger, reconciliation, wallets, flows   <-- this repo
       |
lux/treasury      On-chain treasury, MPC/KMS wallets

Components

ComponentDescription
LedgerProgrammable double-entry, immutable source of truth
PaymentsUnified API and data layer for payment processing
NumscriptDSL for modeling monetary computations and flows
WalletsMulti-currency virtual wallets with hold/release
ReconciliationAuto-match ledger vs. payment provider data
FlowsWorkflow orchestration (via orchestration service)
WebhooksEvent delivery for financial state changes
AuthAuthentication and authorization for treasury APIs
SearchFull-text search across treasury data
GatewayAPI gateway for all treasury services

Service Versions (from Earthfile)

ServiceVersion
Ledgerv2.3.1
Paymentsv3.0.18
Walletsv2.1.5
Webhooksv2.2.0
Authv2.4.0
Searchv2.1.0
Orchestrationv2.4.0
Reconciliationv2.2.1
Gatewayv2.1.0

Event System

Events are JSON Schema-validated. The events/ directory contains:

  • base.yaml - Common event envelope (type, app, payload)
  • services/ledger/ - Ledger events (e.g., SAVED_TRANSACTION)
  • services/payments/ - Payment events (e.g., SAVED_PAYMENT)
  • services/orchestration/ - Workflow events

Event validation in Go:

import "github.com/formancehq/stack/events"

err := events.Check(data, "payments", "SAVED_PAYMENT")

OpenAPI Specification

The releases/ directory merges OpenAPI specs from all sub-services into a unified API spec:

  • Auth: /api/auth/*
  • Ledger: /api/ledger/*
  • Payments: /api/payments/*
  • Wallets: /api/wallets/*
  • Webhooks: /api/webhooks/*
  • Search: /api/search/*
  • Orchestration: /api/orchestration/*
  • Reconciliation: /api/reconciliation/*
  • Gateway: top-level

Authentication: OAuth2 client credentials (/api/auth/oauth/token).

Directory Structure

treasury/
  README.md              # Project overview
  LLM.md                 # AI agent documentation
  LICENSE                # MIT
  go.mod                 # Root Go module (github.com/formancehq/stack)
  Earthfile              # Earthly build (downloads + merges OpenAPI specs)
  base.Dockerfile        # Base Docker image
  events/
    base.yaml            # Common event envelope schema
    events.go            # Go event validation library
    services/
      ledger/            # Ledger event schemas
      payments/          # Payment event schemas
      orchestration/     # Orchestration event schemas
    generated/           # Auto-generated event code
  libs/
    events/
      generated/         # Generated event library
  releases/
    base.yaml            # OpenAPI 3.0.3 base spec
    openapi-merge.json   # Config for merging all service specs
    openapi-overlay.json # Spec overlays

Integration with Hanzo Stack

  • hanzo/payments - Payment routing layer (upstream source of payment connectors)
  • hanzo/commerce - Order settlement and storefront
  • lux/treasury - On-chain treasury operations, MPC wallet management
  • hanzo/kms - Secrets and key management

Building

# Build all (OpenAPI spec + events)
earthly +build

# Build just the merged OpenAPI spec
earthly +build-final-spec

# Go tests
go test ./...

Troubleshooting

IssueCauseSolution
Earthly build failsMissing Earthly CLIInstall with brew install earthly
Event validation failsSchema version mismatchCheck events/services/ for latest version dir
API 401Missing OAuth tokenGet token from /api/auth/oauth/token
Ledger balance errorInsufficient funds in sourceCheck account balances via GET /v2/ledger/{name}/accounts
  • hanzo/hanzo-payments.md - Payment routing
  • hanzo/hanzo-commerce.md - E-commerce platform
  • hanzo/hanzo-ledger.md - Ledger details
  • hanzo/hanzo-kms.md - Secret management
  • hanzo/hanzo-sql.md - PostgreSQL backend

How is this guide?

Last updated on

On this page