Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/integration-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Integration Check (testnet)

# Manual only — never scheduled, never on push. The read-only suite talks to a
# live Soroban RPC endpoint, and the submit suite is state-changing on testnet.
# Point this at a throwaway vault, never the org treasury vault that
# wave-cycle-close.yml relays to.
on:
workflow_dispatch:
inputs:
run_submit:
description: >-
Also run the state-changing submit test. It posts a real
post_cycle_root with the deliberately absurd cycle id 999999, so it
can never collide with a real cycle. Throwaway vaults only.
type: boolean
default: false

permissions:
contents: read

jobs:
integration:
runs-on: ubuntu-latest
steps:
# Fail fast with an actionable message. Without this, the suite's gates
# are simply unmet and every test skips — a green run that verified
# nothing, which is worse than a red one.
- name: Validate integration gates are configured
run: |
missing=""
if [ -z "${{ vars.SOROBAN_RPC_URL }}" ]; then
missing="$missing SOROBAN_RPC_URL"
fi
if [ -z "${{ vars.SPLITSTREAM_VAULT_CONTRACT }}" ]; then
missing="$missing SPLITSTREAM_VAULT_CONTRACT"
fi
if [ -z "${{ secrets.ORACLE_SECRET_KEY }}" ]; then
missing="$missing ORACLE_SECRET_KEY"
fi
if [ -n "$missing" ]; then
echo "::error::gated integration tests would silently skip — unset:$missing. Set SOROBAN_RPC_URL and SPLITSTREAM_VAULT_CONTRACT as repository variables and ORACLE_SECRET_KEY as a repository secret."
exit 1
fi

- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 24
cache: npm

- name: Install dependencies
run: npm ci

- name: Run gated testnet integration tests
env:
RUN_RELAY_INTEGRATION: "1"
RUN_RELAY_SUBMIT: ${{ inputs.run_submit && '1' || '0' }}
SOROBAN_RPC_URL: ${{ vars.SOROBAN_RPC_URL }}
SPLITSTREAM_VAULT_CONTRACT: ${{ vars.SPLITSTREAM_VAULT_CONTRACT }}
# Throwaway relay keypair. Never reuse the production oracle secret here.
ORACLE_SECRET_KEY: ${{ secrets.ORACLE_SECRET_KEY }}
run: npm run test:integration
8 changes: 8 additions & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Summary

- [Introduction](./introduction.md)
- [How it works](./how-it-works.md)
- [Manifest reference](./manifest-reference.md)
- [For maintainers](./for-maintainers.md)
- [Developer guide](./developer-guide.md)
- [Contributing](./contributing.md)
39 changes: 39 additions & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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 skip the Merkle golden test before
a real relay.

## What this repo affects

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

- **splitstream-actions** (this repo) computes what gets settled. It reads
GitHub activity, decides the amounts, and writes the manifest.
- **[splitstream-core]** enforces and pays it. The vault holds the pool, checks
the Merkle proof against the root that was relayed, applies the cycle rules,
and pays claims. Its `merkle::leaf_hash` and `hash_pair` must stay
byte-identical to `src/merkle.ts`.
- **[splitstream-sdk-cli]** is how people check status and claim. It reads the
manifest and the on-chain state, and re-simulates the payout formula to
confirm a cycle it did not compute.

So a change to the **manifest format** or the **Merkle scheme** is a breaking
cross-repo change, not an internal refactor. The manifest format is defined by
this repo and consumed by splitstream-sdk-cli; the leaf format and tree
construction are defined jointly by this repo and splitstream-core. Land either
kind of change in coordination with the other repos, and say so in the PR
description — link to what depends on this repo's output:

- [splitstream-core docs][splitstream-core]
- [splitstream-sdk-cli docs][splitstream-sdk-cli]

Changes to the payout rule fall in the same category: the formula is frozen, and
splitstream-sdk-cli re-simulates it to verify a cycle, so a rule change needs a
coordinated change there.

[splitstream-core]: https://github.com/Oyinkans0la12/splitstream-core
[splitstream-sdk-cli]: https://github.com/Oyinkans0la12/splitstream-sdk-cli
132 changes: 132 additions & 0 deletions docs/developer-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Developer guide

## Local setup

Node 24. `.nvmrc` pins `24` and `package.json` sets `engines.node` to
`>=24.0.0`; CI (`.github/workflows/ci.yml`) uses `node-version: 24`.

```bash
git clone https://github.com/Oyinkans0la12/splitstream-actions
cd splitstream-actions
npm install
```

| Command | Does |
|---|---|
| `npm run typecheck` | `tsc --noEmit`. |
| `npm test` | `vitest run` — all unit tests. |
| `npm run test:watch` | vitest in watch mode. |
| `npm run test:integration` | `vitest run test/relay.integration.test.ts` — gated, see below. |
| `npm run build` | `ncc build src/index.ts -o dist` — the action bundle. |
| `npm run check` | `typecheck` + `test` + `build`. This is exactly what CI runs on every push and PR to `main`. |

`dist/` is deliberately not gitignored, because `action.yml` runs `dist/index.js`
(`using: node24`, `main: dist/index.js`) and `uses: ./` resolves there. **Any
change under `src/` needs a rebuilt bundle committed with it** — run
`npm run build` (or `npm run check`) and commit `dist/` in the same commit.

Layout:

```
src/index.ts orchestrator (inputs -> pipeline -> relay)
src/registry.ts loads + validates splitstream.yml
src/ingest.ts Octokit: merged PRs + closing refs (no label reading)
src/counts.ts distinct closed issues per contributor
src/manifest.ts floor payout formula + dust remainder + manifest format
src/merkle.ts leaf XDR hashing + sorted-pair tree
src/relay.ts Soroban RPC: cycle query, build/sign/submit/confirm
schemas/splitstream.schema.ts the zod registry schema
```

Unit suites cover `registry`, `counts`, `manifest`, `merkle` (golden), and
`ingest`. `test/relay.integration.test.ts` also holds two always-on unit blocks —
the oracle self-verification check and `parseCycleInfo` — which run under plain
`npm test` against stubbed RPC servers; only the testnet blocks in that file are
gated.

## Verifying the Merkle implementation

This is the check that matters most: `src/merkle.ts` must produce the same bytes
as splitstream-core's Rust `merkle::leaf_hash` and `hash_pair`. If it drifts,
every root this repo relays is unclaimable.

`test/fixtures/merkle.golden.json` pins:

- the 64-byte leaf pre-image (`leaf.leafPayloadHex`) and the leaf hash
(`leaf.leafHex`) for one `(address, amount)` pair;
- a 3-leaf root (`tree3.rootHex`, exercises odd-node promotion) and a 4-leaf
root (`tree4.rootHex`).

`test/merkle.test.ts` asserts all of these, plus that the i128 encoding matches
the Rust SDK's `nativeToScVal` for amounts up to `2^127 - 1` and down to
`-2^127`.

Procedure after any change to `src/merkle.ts`, or to splitstream-core's
`merkle.rs`:

1. In a checkout of `splitstream-core`, regenerate the same three values from
Rust (`Address::to_xdr` + `i128::to_xdr` concatenated, then `sha256`, and the
same pair/tree construction). [CONTRIBUTING.md](../CONTRIBUTING.md#merkle-golden-fixture)
carries a runnable `cargo test` snippet and the expected hex.
2. Compare against the fixture. The last recorded cross-check, on **2026-09-10**
against `Oyinkans0la12/splitstream-core@main` (soroban-sdk 27.0.6), matched
all three: leaf `e89c8b63…33c206`, `tree3` `42cb7efa…0663f94f`, `tree4`
`b9f5a8ae…36197b24`.
3. If the Rust value differs, **fix `src/merkle.ts` first.** Update the fixture
only once both implementations agree, in the same commit, and record the new
values there too. Never re-pin the fixture to make a failing test pass — the
fixture is pinned to the contract's implementation, not this repo's.

`splitstream-core`'s `merkle.rs` is frozen; treat any change to it as a breaking
protocol change and re-run this cross-check before trusting a relayed root.

## Gated integration tests (testnet)

`test/relay.integration.test.ts` runs its testnet blocks only when every gate is
set:

| Env var | Value |
|---|---|
| `RUN_RELAY_INTEGRATION` | `1` — required for the read-only suite |
| `SOROBAN_RPC_URL` | e.g. `https://soroban-testnet.stellar.org` |
| `SPLITSTREAM_VAULT_CONTRACT` | a deployed `C...` vault contract |
| `ORACLE_SECRET_KEY` | a funded `S...` relay keypair |
| `RUN_RELAY_SUBMIT` | `1` — additionally required for the state-changing submit test |

```bash
RUN_RELAY_INTEGRATION=1 \
SOROBAN_RPC_URL=https://soroban-testnet.stellar.org \
SPLITSTREAM_VAULT_CONTRACT=C... \
ORACLE_SECRET_KEY=S... \
npm run test:integration
```

- **Read-only** (`RUN_RELAY_INTEGRATION=1`): `queryCycleInfo` against cycle 0
(a `None` reply for a never-posted cycle is a valid result and passes) and
`ledgerCloseTime` against the latest ledger.
- **Submit** (`RUN_RELAY_SUBMIT=1`): posts a real `post_cycle_root` with cycle id
`999999`, a 32-byte root of `0xab`, and `totalAmount = 1`. The absurd cycle id
keeps it from colliding with a real cycle, but it is still a real state change
— run it only against a throwaway vault and a throwaway keypair, never the
treasury vault or the production oracle secret.

### The manual `integration-check.yml` workflow

`.github/workflows/integration-check.yml` runs the gated suite on demand:
**`workflow_dispatch` only**, never on a schedule and never on push. It takes
one input, `run_submit` (boolean, default `false`), sets
`RUN_RELAY_INTEGRATION=1`, passes `run_submit` through as `RUN_RELAY_SUBMIT`,
supplies `SOROBAN_RPC_URL` and `SPLITSTREAM_VAULT_CONTRACT` from repository
variables and `ORACLE_SECRET_KEY` from a repository secret, and runs
`npm run test:integration`.

It starts with a gate check that fails the run when any of those three is unset.
Without it, unmet gates mean every test skips and the job reports green having
verified nothing.

It is separate from `wave-cycle-close.yml` on purpose. That workflow is the real
cycle close: it runs on the sprint boundary, relays to the production vault, and
cannot be made conditional on a flag, because closing the cycle is the whole
point of the schedule. The integration check is never scheduled, is read-only
unless `run_submit` is set, and is pointed at a throwaway vault — so running it
costs nothing and cannot move treasury funds.
149 changes: 149 additions & 0 deletions docs/for-maintainers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# For maintainers

## Before the first cycle

Three things must exist in the repo that runs the cycle, and **only** that repo
— the registry is read from the job's working directory, never from the repos it
lists.

| What | Where | Required for |
|---|---|---|
| `.github/splitstream.yml` | the repo running the workflow | every run |
| `ORACLE_SECRET_KEY` | repository **secret** | every run except `dry_run=true` |
| `CYCLE_POOL_AMOUNT` | repository **variable** | every scheduled run |
| `CYCLE_ID` | repository **variable** | cycle 0 only |
| `GITHUB_TOKEN` | supplied by the workflow as `secrets.GITHUB_TOKEN` | every run |
| `FEE_BUMP_SECRET_KEY` | repository **secret** | optional |

Set `CYCLE_POOL_AMOUNT` under **Settings → Secrets and variables → Actions →
Variables** before the first scheduled run, or that run has no pool to
distribute.

## Triggering a cycle

`.github/workflows/wave-cycle-close.yml` has two entry points.

**`schedule`** — `cron: "0 0 * * 1"`, Monday 00:00 UTC. Adjust it to your org's
sprint day. Per-cycle values come from variables: `cycle_pool_amount` from
`vars.CYCLE_POOL_AMOUNT`, `cycle_id` from `vars.CYCLE_ID`, and `dry_run` is
forced to `false`. `since` is not settable on this path.

**`workflow_dispatch`** — run it from the Actions tab:

| Input | Default | Meaning |
|---|---|---|
| `cycle_pool_amount` | — | Pool in stroops (string). Ignored on the schedule path. |
| `cycle_id` | — | Required for cycle 0 and dry runs; otherwise inferred from the committed `manifests/` trail. |
| `since` | — | Cycle start boundary (ISO 8601). Required for cycle 0 and dry runs; otherwise the last committed manifest's `generatedAt`. |
| `dry_run` | `false` | Compute the manifest and root only; skips queries, relay, and the manifest commit. |
| `commit_manifest` | `true` | Commit the generated manifest as the audit trail. |

The workflow requests `contents: write`, `issues: read`, `pull-requests: read`.

### The unset-variable guard

A schedule-only step fails the run when `vars.CYCLE_POOL_AMOUNT` is empty,
because otherwise the failure surfaces as the opaque platform error
`Input required and not supplied: cycle_pool_amount`. The guard's message points
at the setting to fix.

There is no equivalent guard for `CYCLE_ID`. It is only needed for cycle 0, and
by design the run fails with a clear action-level error
(`cycle_id input is required when no previous cycle manifest exists`) if it is
missing when there is nothing in `manifests/` yet. Note that a cycle-0 run
cannot use the schedule path at all: `since` is required in that case and the
schedule path never supplies it. Run cycle 0 manually.

## The registry — `.github/splitstream.yml`

```yaml
version: 1
repos:
- owner: your-org
name: splitstream-core
- owner: your-org
name: splitstream-actions
- owner: your-org
name: splitstream-sdk-cli
contributors:
- github: octocat
stellar: GABCD1234... # G... public key, 56 chars, checksum verified
- github: some-dev
stellar: GXYZ9876...
oracleAccount: GORACLE... # the relay's own public key
tokenContract: CABCDEF... # deployed SEP-41 token contract id
vaultContract: CVAULT... # the deployed splitstream-core contract for this treasury
network: testnet # testnet | mainnet
```

| Field | Rules |
|---|---|
| `version` | must be `1`. |
| `repos` | non-empty. Each entry is `{ owner, name }`. Duplicate `(owner, name)` pairs are rejected, compared case-insensitively. Every repo listed is crawled; repos left out contribute nothing. |
| `contributors` | non-empty. `github` is validated against GitHub's handle shape (1–39 characters, alphanumeric or hyphen, no leading or trailing hyphen). `stellar` must be a checksum-verified `G...` ed25519 public key. Duplicate handles are rejected, compared case-insensitively. |
| `oracleAccount` | checksum-verified `G...` key. Must be the public key that `ORACLE_SECRET_KEY` signs for. |
| `tokenContract` | checksum-verified `C...` contract id. |
| `vaultContract` | checksum-verified `C...` contract id. Required. |
| `network` | `testnet` or `mainnet`. Selects the default RPC endpoint: `https://soroban-testnet.stellar.org` or `https://soroban-rpc.mainnet.stellar.gateway.fm`. Override with the `rpc_url` input. |

Unknown top-level keys are rejected, so a typo like `vaultContractt` fails the
run instead of being ignored. Nothing is skipped, repaired, or defaulted: any
validation failure aborts the cycle with a non-zero exit.

### Adding a contributor

Append `{ github, stellar }` to `contributors` and merge it before the cycle
that should pay them. A PR author who is not in the registry is never paid — the
run warns loudly with their handle, issue count, and the repos involved, and
carries on, so the fix always lands in the *next* cycle. Get both values right:
the `stellar` key is where the money goes, and a wrong-but-valid key is
undetectable until someone fails to claim.

### `oracleAccount` must match what is deployed

This is a property of the deployment, not of this file. The vault fixes its
oracle at `initialize()` and exposes no setter, so the account in instance
storage is the only one `post_cycle_root` will accept; this repo can only report
a mismatch (it refuses to relay), never resolve one. Changing the vault's oracle
means changing it on splitstream-core's side first — see that repo's contract
reference for how the oracle is configured — and updating this registry in the
same change. This repo has already been burned by getting it wrong once; see the
`fix(config)` commit that repointed `oracleAccount` at the deployed vault's
on-chain oracle. Rotating the keypair follows the same rule: new secret, new
`oracleAccount`, one change, never a half-applied rotation.

## Running a dry run first

Dispatch the workflow with `dry_run: true`. Dry-run mode still requires
`cycle_id` and `since` (there is no window to infer and no chain to query), still
requires `GITHUB_TOKEN`, and does **not** require `ORACLE_SECRET_KEY`. It writes
`manifests/cycle-<id>.dry-run.json`, skips every RPC call and the manifest
commit, and never advances the next cycle's window.

What to check in the log:

- `registry OK: N contributor(s), M repo(s), network=...` — the registry parsed,
with the counts you expect.
- `ingested N merged PR(s) in window; M (PR, issue) contribution(s) with closing
references` — N is PR volume, M is how many closing references were found.
- `issues counted: handle=N, ...` — the denominator. Confirm nobody is missing.
- Warnings for unregistered authors, each with their handle and issue count. Add
them to the registry before the real cycle; they are paid nothing this cycle.
- The summary line `pool=... totalIssuesClosed=... dustRemainder=... (left in
vault), merkleRoot=...`. `dustRemainder` is expected to be small; a large one
means the pool barely divides among the counts.
- The manifest filename uses the `cycle_id` you passed, and for a real run the
window log line reads `last committed cycle manifest: #N ...; new cycle #N+1
window starts ...`.

## What the run commits

After a successful non-dry run, the workflow commits the generated manifest:
`git add manifests/`, commit `chore(manifest): record cycle <id> distribution
manifest` (or a "no manifest changes to commit" notice), then `git push`.

That push targets the branch the workflow runs on. If `main` is protected by a
ruleset requiring a pull request, the push is rejected unless the ruleset exempts
the workflow's token — exempt it, or change that step to open a PR instead. The
manifest commit is not optional housekeeping: it is what defines the next
cycle's window.
Loading
Loading