From f9beee7e7d206a96e4fac86cb854d0e41b8b7e9e Mon Sep 17 00:00:00 2001 From: Oyinkans0la12 <147610565+Oyinkans0la12@users.noreply.github.com> Date: Wed, 16 Sep 2026 11:34:35 +0000 Subject: [PATCH 1/9] ci(workflows): add a manual-only testnet integration check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The gated suite in test/relay.integration.test.ts had no workflow, so it could only be run from a developer's shell with three env vars set by hand — and an unset gate is indistinguishable from a pass, because every test skips. Add a workflow_dispatch-only workflow that runs it against a throwaway vault, with a gate check that fails loudly instead of reporting green on a suite that verified nothing. It is deliberately never scheduled: the submit test is state-changing and the cycle-closing workflow must stay the only thing that touches the treasury vault. Generated with Codebuff 🤖 Co-Authored-By: Codebuff --- .github/workflows/integration-check.yml | 65 +++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .github/workflows/integration-check.yml diff --git a/.github/workflows/integration-check.yml b/.github/workflows/integration-check.yml new file mode 100644 index 0000000..ceb0725 --- /dev/null +++ b/.github/workflows/integration-check.yml @@ -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 From 9eddee994d8f0508b91d4d81251e93ddeb194829 Mon Sep 17 00:00:00 2001 From: Oyinkans0la12 <147610565+Oyinkans0la12@users.noreply.github.com> Date: Wed, 16 Sep 2026 11:34:38 +0000 Subject: [PATCH 2/9] docs(summary): add the docs table of contents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The documentation existed only as a single README; give it an entry point that fixes the reading order before the pages land. Generated with Codebuff 🤖 Co-Authored-By: Codebuff --- docs/SUMMARY.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 docs/SUMMARY.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md new file mode 100644 index 0000000..37b938b --- /dev/null +++ b/docs/SUMMARY.md @@ -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) From b3321f0727129d09af7257858a44e300b80f896f Mon Sep 17 00:00:00 2001 From: Oyinkans0la12 <147610565+Oyinkans0la12@users.noreply.github.com> Date: Wed, 16 Sep 2026 11:34:40 +0000 Subject: [PATCH 3/9] docs(intro): state the shared protocol opening and this repo's role MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Readers arriving at the action repo need the same framing the other two repos use — what the protocol settles and which repo does what — before they meet GitHub-specific mechanics. Name this repo as the authoritative source for the manifest format up front, since that is the part other repos depend on. Generated with Codebuff 🤖 Co-Authored-By: Codebuff --- docs/introduction.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 docs/introduction.md diff --git a/docs/introduction.md b/docs/introduction.md new file mode 100644 index 0000000..debaffb --- /dev/null +++ b/docs/introduction.md @@ -0,0 +1,38 @@ +# Introduction + +SplitStream is a Soroban settlement protocol that lets a Drips Wave team turn +pooled treasury funds into a verifiable, disputable, on-chain distribution to +contributors, instead of calculating payouts by hand off-chain. The pieces are +[splitstream-core] — the vault contract that holds the pool, enforces the cycle +rules, and pays claims — [splitstream-sdk-cli] — the client SDK and CLI +contributors use to read a cycle and claim their share — and this repo, +splitstream-actions. + +splitstream-actions is the bridge between GitHub activity and on-chain +settlement. It never holds funds. On each cycle it reads the contributor +registry, crawls merged PRs across every repo in that registry, counts the +issues each contributor closed, computes each contributor's share with the +frozen payout formula, builds a Merkle root over the payout leaves, writes the +result as a distribution manifest committed to this repo as an audit trail, and +relays the root to splitstream-core with `post_cycle_root`. + +## What this repo owns + +This repo is the **authoritative source for the distribution manifest format**. +[splitstream-sdk-cli] consumes that format; this repo produces it. Both the +manifest shape and the Merkle leaf scheme are cross-repo contracts — a change to +either is a breaking change for the other two repos, not an internal refactor. + +- [How it works](./how-it-works.md) — the pipeline, the payout rule, and the + cross-repo aggregation rules. +- [Manifest reference](./manifest-reference.md) — the JSON shape, the Merkle + leaf and tree format. +- [For maintainers](./for-maintainers.md) — triggering a cycle, the registry, + dry runs. +- [Developer guide](./developer-guide.md) — local setup, the golden fixture + cross-check, the gated integration tests. +- [Contributing](./contributing.md) — where to start, and what breaks other + repos. + +[splitstream-core]: https://github.com/Oyinkans0la12/splitstream-core +[splitstream-sdk-cli]: https://github.com/Oyinkans0la12/splitstream-sdk-cli From 5c52fa17d11552054be8fcf0ea36c5af80676e01 Mon Sep 17 00:00:00 2001 From: Oyinkans0la12 <147610565+Oyinkans0la12@users.noreply.github.com> Date: Wed, 16 Sep 2026 11:34:47 +0000 Subject: [PATCH 4/9] docs(pipeline): state the payout rule once, next to the pipeline it lives in MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The rule that decides who gets paid was spread across the README's numbered stages and its terminology, so a reader had to assemble it. Give it one prominent statement with a worked example that includes a non-zero dust remainder, then document the stages around it: registry load, window, ingest, count, shares, tree, manifest, relay — plus the cross-repo aggregation and the oracle pre-flight that refuse to relay on a mismatch. Generated with Codebuff 🤖 Co-Authored-By: Codebuff --- docs/how-it-works.md | 134 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 docs/how-it-works.md diff --git a/docs/how-it-works.md b/docs/how-it-works.md new file mode 100644 index 0000000..cbccec1 --- /dev/null +++ b/docs/how-it-works.md @@ -0,0 +1,134 @@ +# How it works + +One workflow run closes one cycle. Everything below happens inside +`src/index.ts`'s `main()`, in this order. + +1. **Registry load**. `loadRegistry()` (`src/registry.ts`) reads the file at + `config_path` (default `.github/splitstream.yml`) and validates it against + the strict zod schema in `schemas/splitstream.schema.ts`. Invalid YAML, a + `G...`/`C...` strkey that fails its checksum, a duplicate repo or handle, an + empty `repos`/`contributors` list, or an unknown top-level key aborts the run + via `core.setFailed`. Nothing is skipped or repaired. +2. **Cycle window**. For a real run the boundary comes from this repo's own + committed audit trail: `readLastManifestWindow()` (`src/manifest.ts`) finds + the highest `manifests/cycle-.json`, and the new cycle is that id + 1 + starting at that manifest's `generatedAt`. The deployed contract has no + "latest cycle" call, so it can never define the window; + `get_cycle_info(lastCycleId)` is called only as a sanity check, and a + disagreement only produces a warning. When no manifest exists yet (cycle 0), + the `since` and `cycle_id` inputs supply the boundary instead, and both are + required. +3. **Ingest**. `ingestCycle()` (`src/ingest.ts`) lists closed PRs in every repo + in `repos` (`octokit.paginate(octokit.rest.pulls.list, { state: 'closed', + per_page: 100 })`), keeps those whose `merged_at` is at or after the window + start, and matches GitHub closing keywords in each PR body. A PR closed + without merging, one with an unparseable `merged_at`, or one with no author + is skipped with a warning. +4. **Count**. `countIssuesByContributor()` (`src/counts.ts`) reduces the + (PR, issue) pairs to distinct issues per PR author. Distinctness is per + `owner/repo#issueNumber`, because issue numbers are only unique within a + repo. Counts are summed across every repo. PR authors missing from the + registry are warned about and paid nothing. +5. **Compute shares**. `computePayouts()` (`src/manifest.ts`) applies the payout + rule below. A pool that is not a positive integer, or a cycle in which no + issue was closed, throws instead of producing a distribution. +6. **Build the Merkle tree**. `buildMerkleRoot()` (`src/merkle.ts`) hashes the + `(stellar, amount)` pairs — format in + [Manifest reference](./manifest-reference.md#merkle-leaf-format). +7. **Write the manifest**. `manifests/cycle-.json` (`cycle-.dry-run.json` + in a dry run) is written **before** any relay, so the on-chain root is always + reproducible from a file in git history. +8. **Relay**. Unless `dry_run`, `relayCycleRoot()` (`src/relay.ts`) builds and + signs `post_cycle_root(cycle_id, root, total_amount)`, submits it via Soroban + RPC, polls until the transaction lands, and fails the run if it does not. + `total_amount` is the sum of the manifest's entry amounts — the pool minus + the dust remainder, not the pool. + +## The payout rule + +The single most important fact about this repo, and the rule +[splitstream-sdk-cli] re-simulates when it checks a cycle. + +**An issue counts when it was closed via a merged PR that contains a recognized +GitHub closing keyword in one of the tracked repos, inside the cycle window. +That is the whole rule.** + +- **No label of any kind is read.** Complexity, type, size and `points:*` labels + are informational only and play no part in payout math. +- Recognized keywords are `close`/`closes`/`closed`, `fix`/`fixes`/`fixed`, and + `resolve`/`resolves`/`resolved`, each followed by `#`, matched + case-insensitively (`CLOSING_KEYWORD_RE` in `src/ingest.ts`). References are + only matched inside the PR's own repo — `owner/repo#123` is not a closing + reference, matching GitHub's own behaviour. +- Every qualifying issue counts equally: one issue, one share of the pool + denominator. Nothing weights an issue by difficulty. +- Each distinct issue closed by a contributor's PRs increments their count + exactly once; two PRs from the same author referencing the same issue are one + issue. Counts are summed across every repo in the registry before shares are + computed. +- Credit goes to the **PR author**, not the issue author. PR authors who are + missing from the registry are never paid, and are reported loudly so they can + be added before the next cycle. + +The formula, applied in `BigInt`, never in JS `number`: + +``` +contributor_amount = floor(cycle_pool_amount * contributor_issues_closed / total_issues_closed) +``` + +Worked example — a pool of 5,000,000,000 stroops (500 XLM) with three +contributors closing 3, 2 and 2 issues (7 distinct issues total): + +| Contributor | Issues closed | Amount (stroops) | +|---|---|---| +| alice | 3 | `floor(5000000000 * 3 / 7)` = 2,142,857,142 | +| bob | 2 | `floor(5000000000 * 2 / 7)` = 1,428,571,428 | +| carol | 2 | `floor(5000000000 * 2 / 7)` = 1,428,571,428 | +| **total** | **7** | **4,999,999,998** | + +The undistributed 2 stroops are the **dust remainder**: recorded as +`dustRemainder` in the manifest and left in the vault. It is never silently +dropped and never auto-redistributed. Contributors with no qualifying issues do +not appear in the manifest at all. + +## Cross-repo aggregation + +One cycle covers every repo listed in the registry's `repos` list, not just the +repo the workflow runs in. The window is one shared boundary for the whole org: +a contributor who closed issues in splitstream-core and splitstream-sdk-cli this +cycle gets **one** combined amount and **one** Merkle leaf, not two claims. This +is what makes org-level settlement work — a maintainer's Wave-approved work is +usually spread across several repos under the same owner. + +Set `repos` to exactly the repos whose merged PRs should pay out of this +treasury. A repo left out of the list contributes nothing, and no warning is +emitted for it. + +## Oracle self-verification + +Before any RPC call, `relayCycleRoot()` asserts that the configured +`ORACLE_SECRET_KEY` resolves to the exact `oracleAccount` declared in the +registry, and throws when it does not: + +> oracle identity mismatch: ORACLE_SECRET_KEY resolves to G..., but the +> registry's oracleAccount is G...; refusing to relay + +This matters in both directions. A stale registry means the cycle was computed +under a contributor set that no longer matches the deployed config, and relaying +from the wrong identity means signing a root the contract's oracle gate would +reject — or, worse, signing with a key that was never intended to hold that +authority. There is no override flag: the check runs in `relayCycleRoot` itself, +so every relay path goes through it. See [SECURITY.md](../SECURITY.md) for the +secret-handling rules around this keypair. + +## The window boundary is compared as epochs, not strings + +The `since` value is operator-supplied and only validated through `Date.parse`, +which also accepts shapes GitHub never emits (a `+02:00` offset, a date-only +value) that do not sort lexicographically next to GitHub's canonical +`YYYY-MM-DDTHH:MM:SSZ` `merged_at`. The window is therefore half-open — +`[since, now)` — and every comparison is on parsed epochs. Comparing the raw +strings would silently drop in-window PRs, which understates +`totalIssuesClosed` and so overpays every contributor in the cycle. + +[splitstream-sdk-cli]: https://github.com/Oyinkans0la12/splitstream-sdk-cli From cb1597588415876779876bbe1360e676116fb692 Mon Sep 17 00:00:00 2001 From: Oyinkans0la12 <147610565+Oyinkans0la12@users.noreply.github.com> Date: Wed, 16 Sep 2026 11:34:49 +0000 Subject: [PATCH 5/9] docs(manifest): pin the manifest and Merkle formats as the cross-repo contract MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This repo produces the manifest and every consumer has to decode it exactly, so the field-by-field shape and the leaf/tree construction belong in one reference with the string-vs-number distinction called out. The example root is computed with buildMerkleRoot() rather than hand-written, so the page cannot quietly drift from the implementation. Generated with Codebuff 🤖 Co-Authored-By: Codebuff --- docs/manifest-reference.md | 126 +++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 docs/manifest-reference.md diff --git a/docs/manifest-reference.md b/docs/manifest-reference.md new file mode 100644 index 0000000..19f131a --- /dev/null +++ b/docs/manifest-reference.md @@ -0,0 +1,126 @@ +# Manifest reference + +The distribution manifest is the artifact of a cycle: who gets paid, how much, +and the Merkle root those amounts hash to. This repo is the **authoritative +source for this format** — it is produced by `buildManifest()` in +`src/manifest.ts` and consumed by [splitstream-sdk-cli]. + +The manifest is written to `manifests/cycle-.json` and committed to git +before the relay runs. Treat the committed file, not the chain, as the record of +what was distributed. + +## Fields + +| Field | Type | Meaning | +|---|---|---| +| `cycleId` | integer (JSON number) | Cycle id, taken from the committed audit trail (last cycle + 1) or the `cycle_id` input. Must equal the `` in the filename. | +| `generatedAt` | string, ISO 8601 | `new Date().toISOString()` at build time. This is the next cycle's window start. | +| `poolAmount` | **decimal string** | The `cycle_pool_amount` input in stroops, echoed unchanged. | +| `totalIssuesClosed` | integer (JSON number) | Sum of `entries[].issuesClosed` — the payout denominator. | +| `entries` | array | One entry per contributor with at least one qualifying issue. Contributors with none are absent. | +| `entries[].github` | string | GitHub handle, in the registry's casing. | +| `entries[].stellar` | string | The contributor's `G...` public key. | +| `entries[].issuesClosed` | integer (JSON number) | Distinct issues this contributor closed this cycle. | +| `entries[].amount` | **decimal string** | Payout in stroops, from the floor formula. | +| `dustRemainder` | **decimal string** | `poolAmount - sum(entries[].amount)`. Always present, including `"0"`. | +| `merkleRoot` | string | 64 hex characters — the 32-byte root over the payout leaves. | + +Monetary values are decimal strings, never JSON numbers: a pool or a payout +large enough to exceed `Number.MAX_SAFE_INTEGER` must survive a round trip +through a consumer that parses JSON with floats. + +`entries` is sorted by `issuesClosed` descending, then by handle. That is review +order only — it does not affect the root, because the tree pins leaf order +itself. + +```json +{ + "cycleId": 4, + "generatedAt": "2026-09-10T00:00:00.000Z", + "poolAmount": "5000000000", + "totalIssuesClosed": 7, + "entries": [ + { "github": "alice", "stellar": "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF", "issuesClosed": 3, "amount": "2142857142" }, + { "github": "bob", "stellar": "GC3BLRQMHJGDIBAVHA2WQOY6Q7CBLAZUNZPIR5NYAX6XTQZUSTVRHHPK", "issuesClosed": 2, "amount": "1428571428" }, + { "github": "carol", "stellar": "GCWSW5ZMOHGEBLUFKL7PZGPZKW3OMMDCAT4OMBFKWHXNIUGWGG43HQ7C", "issuesClosed": 2, "amount": "1428571428" } + ], + "dustRemainder": "2", + "merkleRoot": "8b3adf9e99322e6ba79ec199a035e5dbee758160402c4e15ee357b0f445685f2" +} +``` + +That root is the real root of the three entries above, computed with +`buildMerkleRoot()` — not a placeholder. + +## Merkle leaf format + +The leaf is the one thing the contract and every consumer must agree on +byte-for-byte. A leaf hashes exactly two values — the contributor's Stellar +address and their payout amount: + +``` +leaf = sha256( xdr_encode(ScVal(Address(stellar_pubkey))) || xdr_encode(ScVal(i128(amount))) ) + +Address XDR (44 bytes): u32(SCV_ADDRESS=18) | u32(SC_ADDRESS_TYPE_ACCOUNT=0) | u32(publickey ED25519=0) | ed25519(32) +i128 XDR (20 bytes): u32(SCV_I128=10) | int64 hi | uint64 lo +``` + +Both halves are the full ScVal-form XDR that soroban-sdk's `ToXdr` trait +produces — including the ScVal union discriminant, not a bare 32-byte key or a +bare integer. `scvI128()` and `addressScVal()` in `src/merkle.ts` build them; +`test/merkle.test.ts` additionally asserts the i128 encoding against the Rust +SDK's `nativeToScVal` for amounts including `i128::MAX`, `i128::MIN` and +negative values. + +The leaf deliberately does **not** use any Merkle library's default leaf +hashing. It also hashes only `(address, amount)` pairs, which is why the +count-based payout rule needed no contract change: the formula never enters the +leaf. + +## Tree construction + +A sorted-pair Merkle tree: + +- Leaves are ordered by **ascending stellar public key bytes** — deterministic + and independent of handle casing, so the root is reproducible from the + manifest alone, regardless of `entries` order. +- At each level, children are paired left-to-right and concatenated in ascending + byte order before hashing, so a pair `(a, b)` hashes the same as `(b, a)`. +- An odd node is promoted to the next level unchanged. +- A single-leaf tree's root is that leaf. + +`splitstream-core`'s verifier must use the same leaf order and the same pair +sorting; a tree that concats children in insertion order produces a different +root and rejects every claim. + +The golden fixture `test/fixtures/merkle.golden.json` pins the leaf pre-image +bytes, the leaf hash, and a 3-leaf root (odd-node promotion) plus a 4-leaf root. +See the [developer guide](./developer-guide.md#verifying-the-merkle-implementation) +for how to re-verify it against splitstream-core's Rust implementation. + +## Where manifests live, and why the newest one is the source of truth + +Committed manifests are `manifests/cycle-.json`. The workflow's +`wave-cycle-close.yml` commits the generated file as the audit trail. + +`readLastManifestWindow()` (`src/manifest.ts`) scans that directory for files +matching `^cycle-(\d+)\.json$`, takes the highest id, and returns its +`cycleId` and `generatedAt`. The next cycle starts at that timestamp. This is +the only way to answer "what was the last cycle?" — the deployed contract cannot +enumerate its cycles, it only answers `get_cycle_info(cycle_id)` for an id you +already know. + +Two consequences: + +- **Dry-run artifacts never count.** Dry runs write + `cycle-.dry-run.json`, which the regex above does not match, so a dry run + can never advance the window. +- **A corrupt audit trail fails the run rather than guessing.** The scan throws + on an unreadable directory, malformed JSON, a missing or unparseable + `generatedAt`, or a filename whose `` disagrees with the file's `cycleId`. + A missing directory (`ENOENT`) is not an error — it means cycle 0. + +Deleting or rewriting a committed manifest silently rewinds or jumps the next +cycle's window. Don't. + +[splitstream-sdk-cli]: https://github.com/Oyinkans0la12/splitstream-sdk-cli From 123a10f141ca2ad915adee49bb206f6917b26df6 Mon Sep 17 00:00:00 2001 From: Oyinkans0la12 <147610565+Oyinkans0la12@users.noreply.github.com> Date: Wed, 16 Sep 2026 11:34:51 +0000 Subject: [PATCH 6/9] docs(maintainers): cover cycle triggering, the registry, and dry runs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The operational knowledge — which variable the schedule path reads, why the pool guard exists but CYCLE_ID has none, that cycle 0 cannot run on the schedule path, and what a dry run's output should look like — was only discoverable by reading the workflow and src/index.ts. Include the caveat that the manifest commit's push is rejected on a branch whose ruleset requires a PR, since that is where the audit trail can silently stop. Generated with Codebuff 🤖 Co-Authored-By: Codebuff --- docs/for-maintainers.md | 146 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 docs/for-maintainers.md diff --git a/docs/for-maintainers.md b/docs/for-maintainers.md new file mode 100644 index 0000000..1f1896c --- /dev/null +++ b/docs/for-maintainers.md @@ -0,0 +1,146 @@ +# 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 value here must be +the account the deployed vault recognizes as its oracle; 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. 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-.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 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. From 68e49801cdafa3c3db3c200a71e52f270b87f8dd Mon Sep 17 00:00:00 2001 From: Oyinkans0la12 <147610565+Oyinkans0la12@users.noreply.github.com> Date: Wed, 16 Sep 2026 11:34:56 +0000 Subject: [PATCH 7/9] docs(developers): document setup, the golden fixture check, and the gated suite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Merkle cross-check against splitstream-core's Rust implementation is the one procedure that must run before a real relay, and it was only described in CONTRIBUTING.md's golden-fixture section. Point at it from a developer-facing page, record the 2026-09-10 verified values, and explain the gates and the new manual integration workflow — including why it stays separate from the cycle-closing workflow, which cannot be flag-gated because it must always relay. Generated with Codebuff 🤖 Co-Authored-By: Codebuff --- docs/developer-guide.md | 132 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 docs/developer-guide.md diff --git a/docs/developer-guide.md b/docs/developer-guide.md new file mode 100644 index 0000000..78ec6d3 --- /dev/null +++ b/docs/developer-guide.md @@ -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. From 80d843da9ffec910872ac62f1eb78208ec83d9e5 Mon Sep 17 00:00:00 2001 From: Oyinkans0la12 <147610565+Oyinkans0la12@users.noreply.github.com> Date: Wed, 16 Sep 2026 11:34:58 +0000 Subject: [PATCH 8/9] docs(contributing): warn that manifest changes break the other two repos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A contributor reading only this repo's CONTRIBUTING.md will not know that the manifest format and Merkle scheme are consumed byte-for-byte elsewhere, so a "small" format tweak lands as a protocol break. Link the repo's own guide rather than duplicating it, and state who depends on this repo's output. Generated with Codebuff 🤖 Co-Authored-By: Codebuff --- docs/contributing.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 docs/contributing.md diff --git a/docs/contributing.md b/docs/contributing.md new file mode 100644 index 0000000..5efd123 --- /dev/null +++ b/docs/contributing.md @@ -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 From 49d2b9cae93cf4e5be05720daf7a2cced64a950d Mon Sep 17 00:00:00 2001 From: Oyinkans0la12 <147610565+Oyinkans0la12@users.noreply.github.com> Date: Wed, 16 Sep 2026 11:35:26 +0000 Subject: [PATCH 9/9] docs(maintainers): state that the vault's oracle is fixed at initialize() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The page said only that oracleAccount must match the deployment, which reads like a value someone could change later. The vault exposes no setter, so the account stored on-chain is the only one that will ever accept a relayed root — say so, and point at the fix(config) history that already repointed this registry once. Generated with Codebuff 🤖 Co-Authored-By: Codebuff --- docs/for-maintainers.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/for-maintainers.md b/docs/for-maintainers.md index 1f1896c..cec8ec6 100644 --- a/docs/for-maintainers.md +++ b/docs/for-maintainers.md @@ -101,12 +101,15 @@ undetectable until someone fails to claim. ### `oracleAccount` must match what is deployed -This is a property of the deployment, not of this file. The value here must be -the account the deployed vault recognizes as its oracle; 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. Rotating the keypair follows the same rule: new secret, new +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