Skip to content
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Client tooling for SplitStream, the pro-rata contributor payout vault on Stellar
![Node](https://img.shields.io/badge/node-24-green)
![License](https://img.shields.io/github/license/Oyinkans0la12/splitstream-sdk-cli)

[Testnet Explorer](https://stellar.expert/explorer/testnet/contract/CCC2LP2LOYZOLA2JW4C4K7JMR3TRJZIKHDSQYSFJ3R3MCDJLVBT3PZOC) · [Contributing](CONTRIBUTING.md) · [Security](SECURITY.md)
[Docs](https://splitstream.gitbook.io/splitstream-sdk-cli/) · [Testnet Explorer](https://stellar.expert/explorer/testnet/contract/CCC2LP2LOYZOLA2JW4C4K7JMR3TRJZIKHDSQYSFJ3R3MCDJLVBT3PZOC) · [Contributing](CONTRIBUTING.md) · [Security](SECURITY.md)

## What it is

Expand Down
9 changes: 9 additions & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Summary

- [Introduction](./introduction.md)
- [For contributors](./for-contributors.md)
- [For maintainers](./for-maintainers.md)
- [CLI reference](./cli-reference.md)
- [SDK reference](./sdk-reference.md)
- [Developer guide](./developer-guide.md)
- [Contributing](./contributing.md)
151 changes: 151 additions & 0 deletions docs/cli-reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# CLI reference

The CLI installs as `splitstream` and is built on Commander. Every command ends
up in one place that turns an exception into a single readable line; raw stack
traces appear only with `--verbose`.

```bash
splitstream <command> [options]
splitstream <command> --help
```

## Global options

| Flag | Meaning |
| --- | --- |
| `-v, --verbose` | Print stack traces and raw RPC detail on failure |
| `-V, --version` | Output the version number |
| `-h, --help` | Display help for a command |

`splitstream` with no command lists the commands and examples.

## Commands

| Command | Needs chain config | Purpose |
| --- | --- | --- |
| `simulate` | no | Dry-run payout calculations against merged PRs |
| `status` | yes | Vault reserve, recent cycle distributions, contributor position |
| `claim` | yes | Claim a cycle allocation, and optionally withdraw it |
| `report` | yes | Generate the per-cycle markdown transparency report |

Configuration precedence is flags, then `SPLITSTREAM_*` environment variables,
then a JSON config file. `status`, `claim` and `report` accept
`--rpc-url <url>`, `--network-passphrase <passphrase>`, `--vault <id>` and
`--token <id>` to override the environment for one invocation. `simulate` does
not, because it never touches the chain.

A command that fails prints one line and exits non-zero.

## `splitstream simulate`

Dry run over merged pull requests. Counts the distinct issues each contributor
closed, estimates the pro-rata payout, and estimates the cost of the eventual
`post_cycle_root` call. Never contacts RPC and never signs.

| Flag | Default | Meaning |
| --- | --- | --- |
| `--cycle <id>` | — | Cycle id to simulate |
| `--manifest <path>` | — | Read cycle id and pool from a manifest file |
| `--repo <owner/name...>` | `origin` remote | Repository to read merged PRs from; repeatable |
| `--ref <ref>` | `main` | Git ref to read manifests from when `--repo` is remote |
| `--since <iso>` | previous cycle manifest | Cycle window lower bound, ISO 8601 |
| `--pool <amount>` | manifest | Pool size in whole tokens; overrides the manifest |
| `--decimals <n>` | `7` | Token decimals for display and `--pool` parsing, 0–38 |
| `--map <path>` | — | JSON map of GitHub handle → Stellar address |
| `--max-prs <n>` | `300` | Maximum merged pull requests to consider |
| `--json` | off | Print the result as JSON instead of a table |

`--repo` may be repeated or take several values (`--repo a/b c/d`). With no
`--repo` at all, the `origin` remote of the working directory is used, and the
command fails with a clear message if it cannot determine one.

`--cycle` must be a non-negative integer, `--max-prs` a positive integer, and
`--since` a valid ISO 8601 timestamp; anything else is rejected before any
network call.

## `splitstream status`

Vault reserve, recent cycle distributions, and — with `--contributor` — a single
contributor's balance, vesting and claimed/pending cycles.

| Flag | Default | Meaning |
| --- | --- | --- |
| `--contributor <G...>` | — | Contributor address to report on |
| `--cycle <id>` | — | Show a single cycle instead of a range |
| `--cycles <n>` | `5` | How many recent cycles to show, 1–200 |
| `--manifest <path>` | — | Manifest supplying the last cycle summary |
| `--repo <owner/name>` | — | Repository to fetch the manifest from |
| `--ref <ref>` | `main` | Git ref to read manifests from |
| `--json` | off | Print the result as JSON instead of tables |
| `--rpc-url <url>` | env | Override `SPLITSTREAM_RPC_URL` |
| `--network-passphrase <passphrase>` | env | Override `SPLITSTREAM_NETWORK_PASSPHRASE` |
| `--vault <id>` | env | Override `SPLITSTREAM_VAULT_CONTRACT_ID` |
| `--token <id>` | env | Override `SPLITSTREAM_TOKEN_CONTRACT_ID` |

Cycle ranges are anchored on the highest cycle id that has a manifest in
`manifests/`, so discovering recent cycles needs no extra contract call. A
manifest is optional context here: without one, status still prints chain state
and says so, because contributor-level breakdowns are not available on-chain.

## `splitstream claim`

Claims a cycle allocation and optionally withdraws it, as two separately signed
transactions.

| Flag | Default | Meaning |
| --- | --- | --- |
| `--cycle <id>` | **required** | Cycle to claim |
| `--manifest <path>` | — | Manifest file for the cycle |
| `--repo <owner/name>` | — | Repository to fetch the manifest from |
| `--ref <ref>` | `main` | Git ref to read manifests from |
| `--contributor <address\|handle>` | signing wallet | Who is claiming |
| `--wallet <kind>` | prompt | Signing method: `local` or `hardware` |
| `-y, --yes` | off | Skip the confirmation prompt |
| `--force` | off | Proceed even if the manifest root does not match the recomputed tree |
| `--no-withdraw` | withdraw offered | Stop after `credit_claim` |
| `--rpc-url <url>` | env | Override `SPLITSTREAM_RPC_URL` |
| `--network-passphrase <passphrase>` | env | Override `SPLITSTREAM_NETWORK_PASSPHRASE` |
| `--vault <id>` | env | Override `SPLITSTREAM_VAULT_CONTRACT_ID` |
| `--token <id>` | env | Override `SPLITSTREAM_TOKEN_CONTRACT_ID` |

`--wallet` accepts only `local` or `hardware`. Without it you are prompted.
`--contributor` takes an address or a GitHub handle; without it the claimant is
the local testnet key if one is configured, otherwise the connected Ledger
device, matched against the manifest before anything is signed.

`claim` has no `--json` flag: it is an interactive signing flow, and its output
is the transaction hashes it submitted.

## `splitstream report`

Generates the per-cycle markdown transparency report.

| Flag | Default | Meaning |
| --- | --- | --- |
| `--cycle <id>` | **required** | Cycle to report on |
| `--manifest <path>` | — | Manifest file for the cycle |
| `--repo <owner/name>` | — | Repository to fetch the manifest from |
| `--ref <ref>` | `main` | Git ref to read manifests from |
| `--out <path>` | `SPLITSTREAM_REPORT.md` | Output path |
| `--concurrency <n>` | `5` | Parallel contract reads, 1–20 |
| `--stdout` | off | Print the report instead of writing it to disk |
| `--rpc-url <url>` | env | Override `SPLITSTREAM_RPC_URL` |
| `--network-passphrase <passphrase>` | env | Override `SPLITSTREAM_NETWORK_PASSPHRASE` |
| `--vault <id>` | env | Override `SPLITSTREAM_VAULT_CONTRACT_ID` |
| `--token <id>` | env | Override `SPLITSTREAM_TOKEN_CONTRACT_ID` |

`--concurrency` bounds the in-flight contract reads used to check each
contributor's claim status; a value outside 1–20 is rejected before the run.

## Examples

```bash
splitstream simulate --cycle 3 --pool 100000 --map handles.json
splitstream simulate --repo owner/name --manifest manifests/cycle-3.json --json
splitstream status --contributor GABC...XYZ
splitstream status --cycles 10 --json
splitstream claim --cycle 3 --manifest manifests/cycle-3.json
splitstream claim --cycle 3 --repo owner/name --wallet hardware
splitstream report --cycle 3 --manifest manifests/cycle-3.json
splitstream report --cycle 3 --stdout > report.md
```
58 changes: 58 additions & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Contributing

The build/test workflow, commit conventions and the non-negotiables checklist
for this repo live in [CONTRIBUTING.md](../CONTRIBUTING.md) — that file is the
source of truth for how to land a change here, and this page does not duplicate
it. In short: one commit per logical unit, conventional commit subjects, stage
exactly what belongs to the change, and never "fix" the cross-repo Merkle golden
test by editing its fixture.

Changes reach `main` through a pull request: the branch rules require one, and
they require the CI status check to pass before merge. CI runs the typecheck and
both workspaces' test suites.

## What this repo affects

Three repos split the protocol, and a change here can break the other two:

- **splitstream-sdk-cli** (this repo) is how people check status and claim. It
reads the manifest and the on-chain state, reconstructs Merkle proofs, and
builds the transactions contributors sign.
- **[splitstream-actions]** produces what gets settled. It reads GitHub activity,
decides the amounts, writes the manifest and relays the root. It is the
authoritative source for the manifest format.
- **[splitstream-core]** enforces and pays it. The vault holds the pool, verifies
the proof against the relayed root and pays claims. Its `merkle::leaf_hash` and
`hash_pair` must stay byte-identical to `merkleProof.ts`.

So a change to **manifest parsing** or to the **Merkle scheme** is a
cross-repo change, not an internal refactor. Land it in coordination with the
other repos and say so in the PR description, linking what depends on this
repo's output:

- [splitstream-actions docs][actions-docs]
- [splitstream-core docs][core-docs]

Three areas deserve specific care:

| Area | Why it is cross-repo |
| --- | --- |
| `parseManifest` | Must read the field names the writer actually emits (`entries`, `stellar`, `issuesClosed`, `totalIssuesClosed`, `dustRemainder`, `merkleRoot`), never an invented shape |
| `merkleProof.ts` | Leaves are `sha256(ScVal(Address).toXDR() || ScVal(i128).toXDR())`, ordered by ascending Stellar public-key bytes, internal nodes are `sha256(min||max)`, and an unpaired node is promoted unchanged |
| `errors.ts` | The error table mirrors the vault's enum; a stale table prints a wrong name, which is worse than an unknown code |

Two more rules that are not cross-repo but are not negotiable either: token
decimals are always read from the token contract, never from a manifest; and
monetary amounts are always `bigint` or strings, never JS `number`.

## Where to start

- A claim that fails locally or on-chain: [For contributors](./for-contributors.md).
- A cycle report that looks wrong: [For maintainers](./for-maintainers.md).
- Setup, tests and the golden fixture: [Developer guide](./developer-guide.md).
- The exported API: [SDK reference](./sdk-reference.md).

[splitstream-actions]: https://splitstream.gitbook.io/splitstream-actions/
[splitstream-core]: https://splitstream.gitbook.io/splitstream-core/
[actions-docs]: https://splitstream.gitbook.io/splitstream-actions/
[core-docs]: https://splitstream.gitbook.io/splitstream-core/
103 changes: 103 additions & 0 deletions docs/developer-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Developer guide

## Requirements

Node.js 20 or newer — `package.json` declares `engines.node: ">=20"` in both
workspaces, and CI uses the version pinned in `.nvmrc`. No other toolchain is
required.

## Build, typecheck, test

```bash
npm install
npm run build # builds the SDK, then the CLI
npm run typecheck # type-checks both workspaces without emitting
npm test # runs both workspaces' vitest suites
```

This is an npm workspace with two packages, so the root scripts fan out to each
workspace in order: the CLI depends on the SDK's build output.

Run the CLI straight from the build output:

```bash
node packages/cli/dist/index.js --help
```

`dist/` is build output and is not committed.

## Layout

```
packages/
sdk/ @splitstream/sdk - typed vault client, Merkle proofs, amount math
cli/ splitstream-cli - commander-based terminal app (bin: splitstream)
```

| Path | Responsibility |
| --- | --- |
| `packages/sdk/src/types.ts` | Manifest parsing and domain types |
| `packages/sdk/src/merkleProof.ts` | Frozen leaf hashing and the sorted-pair tree |
| `packages/sdk/src/client.ts` | Typed Soroban client; never signs |
| `packages/sdk/src/errors.ts` | Contract error table and error decoding |
| `packages/sdk/src/amounts.ts` | bigint amount formatting and parsing |
| `packages/sdk/src/bytes.ts`, `xdr.ts` | Byte and ScVal conversion helpers |
| `packages/cli/src/contributions.ts` | Count-based ingest and the payout formula |
| `packages/cli/src/manifest.ts` | Locating and loading a cycle manifest |
| `packages/cli/src/commands/` | `simulate`, `status`, `claim`, `report` |
| `packages/cli/src/wallet.ts` | Signing: local testnet keypair or Ledger |
| `packages/cli/src/report.ts` | Markdown transparency report |

## Tests

- `packages/sdk/test/` covers manifest parsing, amount math, XDR plumbing, the
Merkle scheme, and the RPC client against a stubbed server.
- `packages/cli/test/` covers the commands, configuration precedence, manifest
loading, the wallet paths and the count-based rule.

### The cross-repo golden test

`packages/sdk/test/merkleGolden.test.ts` is not an internal consistency check. It
loads `test/fixtures/merkle.golden.json` — copied verbatim from
[splitstream-actions] — plus a real-shaped manifest fixture, and proves this
repo's proof reconstruction verifies against the *other repo's* committed root.

If it fails, the implementation has diverged from the cross-repo Merkle contract
and real claims would fail `InvalidProof` on-chain. **Never fix it by editing the
fixture.** Fix the implementation, or coordinate the format change across all
three repos.

## Working on the payout path

Two rules matter more than style here:

- **Amounts are `bigint` or strings, never JS `number`.** A rounded payout is a
wrong payout, and the failure is silent.
- **Token decimals come from the token contract at runtime** via
`getTokenDecimals`. They are never read from a manifest, and a manifest that
carries them is out of date.

When you change how a transaction is assembled, exercise it against a stubbed
`rpc.Server` rather than a live network — the client accepts an injected server
precisely so tests stay offline.

## Cross-repo changes

Some changes here cannot land alone:

- **The manifest format** is written by [splitstream-actions] and parsed here.
Do not add fields to the parser that the writer does not produce.
- **The Merkle scheme** is shared byte-for-byte with [splitstream-actions] and
[splitstream-core]. A change to leaf pre-image, leaf order or the odd-node rule
is a breaking change for both.
- **The contract error table** mirrors the vault's enum. Update it in the same
change that renumbers the contract.

The [Contributing](./contributing.md) page says more about what to coordinate;
the sibling sites carry the other side of each contract:
[splitstream-actions docs][actions-docs], [splitstream-core docs][core-docs].

[splitstream-actions]: https://splitstream.gitbook.io/splitstream-actions/
[splitstream-core]: https://splitstream.gitbook.io/splitstream-core/
[actions-docs]: https://splitstream.gitbook.io/splitstream-actions/
[core-docs]: https://splitstream.gitbook.io/splitstream-core/
Loading
Loading