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
56 changes: 56 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Changelog

All notable changes to `@splitstream/sdk` and `splitstream-cli` are recorded here.
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
both packages use [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.0] - 2026-11-28

This release rebases both packages on the currently deployed `splitstream-core`
vault at `CB456KGXH4233BHW5BUEJMN6OJ4ZMWMPP3OXJU5HVQ2T2F7A7XHWLTAT`. The previous
`0.1.x` builds targeted an earlier draft of the contract, so their reads and
claims failed against the live Testnet deployment.

### Fixed

- **Cycles are `u64`.** Every read and transaction builder now encodes the cycle
id as `u64`, so cycle ids are no longer truncated by a `u32` argument.
- **`get_cycle_info` replaces the removed `get_cycle_root`.** The SDK decodes the
full `CycleInfo` record (`root`, `total_amount`, `posted_at`, `claims_started`,
`replaced`) and derives `claimsOpenAt` from the 86,400-second challenge window.
`getCycleRoot` remains as a compatibility alias.
- **Error codes match the deployed contract** (1 `NotInitialized` through
19 `CycleTotalExceeded`), including `ClaimsNotYetOpen`, `InsufficientFreeFunds`
and `CycleTotalExceeded`, so a failed transaction reports its real reason.
- **Liability reads** (`get_total_credited`, `get_vesting_reserved`,
`get_available_funds`) are exposed on the client; `status` now separates the
vault's on-hand token balance from the funds that are actually free to sweep.

### Added

- `claim` verifies the manifest against the vault before signing: it compares the
recomputed root with the manifest root **and** with the on-chain root, and it
refuses to submit while the 24-hour challenge window is still open. `--force`
overrides each check and says so loudly.
- `status` reports cycle state (unposted, in challenge window, claims open,
final/replaced) and surfaces malformed manifests instead of failing silently.
- `report` checks the manifest root against the on-chain root and records a
warning in the generated markdown when they differ or when no root is posted.
- An opt-in live Testnet smoke test: `SPLITSTREAM_TESTNET_E2E=1 npm test -w @splitstream/sdk`.
It only simulates reads, and its token assertions also need
`SPLITSTREAM_TOKEN_CONTRACT_ID`.

### Changed

- README and the reference docs point at the current deployed vault address and
document the `u64`/`get_cycle_info` ABI, the challenge window, and the split
between on-hand and free funds.

### Upgrade notes

- Callers that passed a cycle id as a JS `number` keep working; ids above
`2^32 - 1` are now representable.
- Code that assumed `getCycleRoot` mapped to an on-chain entrypoint should move
to `getCycleInfo`, which surfaces the cycle's state and not just its root.
- Nothing about signing changed: the SDK still never signs, local keys remain
testnet-only, and mainnet claims require a hardware wallet.
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ 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
# Live Testnet smoke test (off by default; free reads only, nothing is signed)
SPLITSTREAM_TESTNET_E2E=1 npm test -w @splitstream/sdk
```

Run the CLI straight from the build output:
Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Client tooling for SplitStream, the pro-rata contributor payout vault on Stellar
![License](https://img.shields.io/github/license/SplitStream-Labs/splitstream-sdk-cli)
[![npm](https://img.shields.io/npm/v/@splitstream/sdk)](https://www.npmjs.com/package/@splitstream/sdk)

[SDK on npm](https://www.npmjs.com/package/@splitstream/sdk) · [Docs](https://splitstream.gitbook.io/splitstream-sdk-cli/) · [Testnet Explorer](https://stellar.expert/explorer/testnet/contract/CCC2LP2LOYZOLA2JW4C4K7JMR3TRJZIKHDSQYSFJ3R3MCDJLVBT3PZOC) · [Contributing](CONTRIBUTING.md) · [Security](SECURITY.md)
[SDK on npm](https://www.npmjs.com/package/@splitstream/sdk) · [Docs](https://splitstream.gitbook.io/splitstream-sdk-cli/) · [Testnet Explorer](https://stellar.expert/explorer/testnet/contract/CB456KGXH4233BHW5BUEJMN6OJ4ZMWMPP3OXJU5HVQ2T2F7A7XHWLTAT) · [Contributing](CONTRIBUTING.md) · [Security](SECURITY.md)

## What it is

Expand Down Expand Up @@ -69,7 +69,9 @@ Claiming is a two-step pull payment:

They are always two separately signed transactions, and `splitstream claim` offers the second one explicitly rather than merging them.

Before signing, the CLI recomputes the Merkle root from the manifest's own rows. If it disagrees with the published `merkleRoot` it refuses to submit (the proof would fail on-chain) unless `--force` is passed, which is reported loudly.
Before signing, the CLI recomputes the Merkle root from the manifest's own rows. If it disagrees with the published `merkleRoot` it refuses to submit (the proof would fail on-chain) unless `--force` is passed, which is reported loudly. It also compares the manifest root with the root the vault actually stored via `get_cycle_info`, and refuses a stale manifest whose root was challenged and replaced.

A posted root is **not immediately claimable**: `splitstream-core` gives maintainers a fixed 24-hour (`86_400s`) challenge window in which a bad root can be replaced once. `credit_claim` rejects early claims with `ClaimsNotYetOpen`; the CLI surfaces the window and refuses to burn a fee inside it unless `--force` is passed.

### Cycles and manifests

Expand Down Expand Up @@ -140,17 +142,20 @@ const client = new SplitStreamClient({
});

const balance = await client.getBalance(address); // bigint, base units
const info = await client.getCycleInfo(3); // CycleInfo, or null if unposted
const root = await client.getCycleRoot(3); // lowercase hex, or null
const claimed = await client.hasClaimed(3, address);
const decimals = await client.getTokenDecimals(); // from the token contract
const free = await client.getAvailableFunds(); // token balance - liabilities

const tx = await client.buildClaimTx(address, 3, amount, proof); // unsigned
const signedXdr = await myWallet.sign(tx); // you sign it
const { hash } = await client.submitSigned(signedXdr);
```

Reads: `getBalance`, `getCycleRoot`, `hasClaimed`, `getVesting`, `getTokenDecimals`, `getReserveBalance`.
Reads: `getBalance`, `getCycleInfo`, `getCycleRoot`, `hasClaimed`, `getVesting`, `getTokenDecimals`, `getReserveBalance`, `getTotalCredited`, `getVestingReserved`, `getAvailableFunds`.
Builds: `buildClaimTx`, `buildWithdrawTx`, `buildClaimVestedTx`.
Cycle ids are `u64` on-chain and encoded as such; `getCycleInfo` decodes the vault's `CycleInfo` record (`root`, `totalAmount`, `postedAt`, `claimsStarted`, `replaced`, `claimsOpenAt`), while `getCycleRoot` remains as a convenience alias.
The package also exports the Merkle proof helpers (`buildClaimProof`, `verifyMerkleProof`, `computeMerkleRoot`), amount formatting (`formatTokenAmount`, `parseTokenAmount`), manifest parsing (`parseManifest`) and contract-error decoding (`SplitStreamError`).

## Command reference
Expand Down Expand Up @@ -292,8 +297,8 @@ Tree construction is a **sorted-pair Merkle tree**: at each level, children are

| | |
|---|---|
| Vault contract | `CCC2LP2LOYZOLA2JW4C4K7JMR3TRJZIKHDSQYSFJ3R3MCDJLVBT3PZOC` |
| Explorer | https://stellar.expert/explorer/testnet/contract/CCC2LP2LOYZOLA2JW4C4K7JMR3TRJZIKHDSQYSFJ3R3MCDJLVBT3PZOC |
| Vault contract | `CB456KGXH4233BHW5BUEJMN6OJ4ZMWMPP3OXJU5HVQ2T2F7A7XHWLTAT` |
| Explorer | https://stellar.expert/explorer/testnet/contract/CB456KGXH4233BHW5BUEJMN6OJ4ZMWMPP3OXJU5HVQ2T2F7A7XHWLTAT |
| Network | Test SDF Network ; September 2015 (Testnet) |

## Design decisions & known deviations
Expand All @@ -305,6 +310,7 @@ These are deliberate, documented decisions — each is called out where it bites
- **`credit_claim` and `withdraw` are never merged into one transaction.** They are two separately signed calls, and `claim` offers the second explicitly.
- **`claim` recomputes the Merkle root before signing** and refuses to submit when it disagrees with the published `merkleRoot`, because the proof would fail on-chain. `--force` overrides this and is reported loudly.
- **`merkleRoot` is the canonical field**; `root` is accepted only as a read-compatibility alias.
- **The client follows the deployed vault ABI, not an earlier draft of it.** Cycle ids are encoded as `u64`, the root is read with `get_cycle_info` (the old `get_cycle_root` no longer exists), and the 24-hour challenge window is part of the claim flow.
- **`simulate` never touches the chain** and needs none of the chain variables.

## Contributing
Expand Down
11 changes: 11 additions & 0 deletions change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SplitStream SDK & CLI — Explanation of Changes

This document explains, in plain prose, what was changed in `SplitStream-Labs/splitstream-sdk-cli` after the repository was rejected from the Stellar Wave program (Drips Wave), and why. The rejection was relayed internally as the instruction to "rebase this project fully on Soroban," so we verified that premise before acting on it. The repository at the rejected baseline was already a native Soroban client: it depended on `@stellar/stellar-sdk` 17, spoke to Soroban RPC, encoded `ScVal` arguments with the SDK's XDR types, read a deployed `C...` vault contract, and reconstructed the same sorted-pair Merkle proofs the Rust contract verifies. There is no EVM contract, no second chain, and no porting layer to migrate away from, so no chain migration was possible or performed. We therefore treated the rejection as a correctness and credibility problem: an SDK is only useful if it matches the contract that is actually deployed, and this one did not.

The substantive defect was ABI drift against the redeployed `splitstream-core` vault. The vault now lives at `CB456KGXH4233BHW5BUEJMN6OJ4ZMWMPP3OXJU5HVQ2T2F7A7XHWLTAT`, declares cycle ids as `u64` rather than `u32`, and exposes `get_cycle_info(cycle_id) -> Option<CycleInfo>` instead of the old `get_cycle_root`. A posted root is also no longer immediately claimable: `CycleInfo` carries `root`, `total_amount`, `posted_at`, `claims_started` and `replaced`, and `credit_claim` rejects any claim made inside the fixed 24-hour (`86_400s`) challenge window with `ClaimsNotYetOpen`. At the rejected baseline this repository encoded every cycle id as `u32` and called `get_cycle_root`, so `status`, `claim` and `report` would fail at simulation time against the live vault, and the README pointed at the superseded address `CCC2LP2...`. We rebuilt the client on the deployed ABI: cycle ids are encoded as `u64`, `getCycleInfo` decodes the real `CycleInfo` record (including the derived `claimsOpenAt`), `getCycleRoot` remains only as a convenience alias, and three new liability views (`getTotalCredited`, `getVestingReserved`, `getAvailableFunds`) expose the vault's solvency position instead of treating its raw token balance as unallocated reserve. The local copy of the contract error enum was replaced wholesale with the current 1–19 discriminants, because the old table would have printed confidently wrong names for `InvalidProof`, `AlreadyClaimed`, `InsufficientFreeFunds` and the challenge-window errors.

The CLI was changed to make that behavior visible rather than merely compile. `splitstream status` now separates the token balance on hand from credited balances, vesting liability and sweepable funds, labels each cycle as not posted, in its challenge window, open for claims, or already started, and splits a contributor's cycles into pending, challenge-window and already-claimed groups; a manifest that exists but does not parse is now reported as malformed instead of being silently presented as "no local manifest found." `splitstream claim` previously checked only that the manifest agreed with its own recomputed tree; it now also reads `get_cycle_info`, refuses a proof against a root the vault does not store (for example a stale manifest after a challenge), reports the on-chain root alongside the manifest root, and refuses to submit during the challenge window unless `--force` is passed. `report` and the unsigned `credit_claim`/`withdraw`/`claim_vested` builders use the same `u64` encoding, and the signer and key-handling model is unchanged: the SDK still never signs, local keys remain testnet-only and environment-only, and mainnet still requires a hardware wallet.

All of this is verified rather than asserted. `npm run typecheck` builds the SDK and type-checks both workspaces cleanly, and `npm test` runs 98 passing tests across the two packages, with a live Testnet smoke test committed behind the `SPLITSTREAM_TESTNET_E2E=1` opt-in so the default suite never needs the network; a `CHANGELOG.md` records the `0.2.0` release and its upgrade notes. New regression coverage pins the parts that were wrong: the `credit_claim` instruction is asserted to carry a `scvU64` cycle id; a real-shaped `CycleInfo` map is decoded into `root`, `totalAmount`, `postedAt`, `claimsStarted`, `replaced` and `claimsOpenAt`; `get_total_credited`, `get_vesting_reserved` and `get_available_funds` are asserted by entrypoint name; the corrected error table is exercised through both simulation and on-chain diagnostics; and the CLI tests cover an unposted cycle, a replaced root, a cycle still inside the challenge window, and a malformed manifest. We also exercised the built SDK against the live Testnet vault at `CB456...` with the native SAC token `CDLZ...`: `getTokenDecimals` returned `7`, cycle 0 correctly returned `null`, and the vault reported an on-hand balance of `10,000,000` stroops with `0` credited, `0` vesting reserved and `10,000,000` available — the same post-deployment state `splitstream-core` recorded after its smoke-test deposit. That is a real read against the deployed contract, not a fixture, and the same reads are now reproducible with `SPLITSTREAM_TESTNET_E2E=1 npm test -w @splitstream/sdk`.

The documentation was corrected rather than appended to: the README and package README now show `getCycleInfo`, the new read methods and the `u64` cycle-id rule, describe the 24-hour challenge window in the claim flow, and point at the current Testnet deployment; the SDK reference has the new read table and the exact 1–19 error table; and the contributor, maintainer and CLI pages describe challenge-window states and the new pre-signing checks. We would rather state the limits than have them found in review: this repository is client tooling and does not deploy the vault, so the changes target the existing `CB456...` deployment and cannot redeploy it; the previous address `CCC2LP2...` is superseded rather than migrated; the challenge-window check in the CLI compares ledger timestamps to the local clock as a convenience, while the contract remains the authority; everything here is Testnet-only; and the code remains unaudited.
8 changes: 5 additions & 3 deletions docs/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ network call.
## `splitstream status`

Vault reserve, recent cycle distributions, and — with `--contributor` — a single
contributor's balance, vesting and claimed/pending cycles.
contributor's balance, vesting and claimed/pending/challenge-window cycles. The
reserve block separates the token balance on hand from credited and vesting
liabilities, and shows `get_available_funds` (the sweepable surplus).

| Flag | Default | Meaning |
| --- | --- | --- |
Expand Down Expand Up @@ -94,14 +96,14 @@ transactions.

| Flag | Default | Meaning |
| --- | --- | --- |
| `--cycle <id>` | **required** | Cycle to claim |
| `--cycle <id>` | **required** | Cycle to claim (`u64` on-chain) |
| `--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 |
| `--force` | off | Proceed despite a root mismatch or an open challenge window |
| `--no-withdraw` | withdraw offered | Stop after `credit_claim` |
| `--rpc-url <url>` | env | Override `SPLITSTREAM_RPC_URL` |
| `--network-passphrase <passphrase>` | env | Override `SPLITSTREAM_NETWORK_PASSPHRASE` |
Expand Down
16 changes: 12 additions & 4 deletions docs/for-contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ With `--contributor`, status reads the vault and reports:

- **claimable in vault** — your credit balance, from `get_balance`.
- **vesting** — the schedule from `get_vesting`, or `none`.
- **pending claimable cycles** — cycles whose root is posted and which you have
not claimed yet.
- **pending claimable cycles** — cycles whose root is posted, whose 24-hour
challenge window has elapsed, and which you have not claimed yet.
- **cycles in challenge window** — posted cycles that are not claimable yet.
- **already claimed cycles** — cycles where `has_claimed` is already true.

Add `--json` for machine-readable output, or `--cycles <n>` to widen the range.
Expand Down Expand Up @@ -52,9 +53,16 @@ merged into one transaction. Pass `--no-withdraw` to stop after `credit_claim`.
to the published `merkleRoot`. If they disagree it refuses to submit, because
the proof would burn a fee and fail on-chain. `--force` overrides that, prints
a warning, and should only be used when you are certain.
3. It checks `has_claimed` for your cycle and address, and stops before signing
3. It reads `get_cycle_info` and compares the manifest root with the root the
vault actually stored. A stale manifest (for example one whose root was
challenged and replaced) is refused before signing.
4. It checks the **24-hour challenge window**. A posted root is not claimable
until 24 hours after it was posted, so the command reports when claims open
and refuses to submit early instead of paying a fee for a guaranteed
`ClaimsNotYetOpen` failure. `--force` overrides this too.
5. It checks `has_claimed` for your cycle and address, and stops before signing
if you have already claimed.
4. It asks you to confirm, unless you pass `-y, --yes`.
6. It asks you to confirm, unless you pass `-y, --yes`.

## Signing

Expand Down
7 changes: 4 additions & 3 deletions docs/for-maintainers.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ issues closed, the dust note when the pool does not divide evenly, and a

## Inspect the vault

Without `--contributor`, `status` is the maintainer view: the vault's unallocated
reserve, recent cycle roots, and — when a manifest is available locally — the
last cycle's distribution summary.
Without `--contributor`, `status` is the maintainer view: the vault's token
balance split into credited, vesting and sweepable funds, recent cycle records
(including whether each root is still in its 24-hour challenge window), and —
when a manifest is available locally — the last cycle's distribution summary.

```bash
splitstream status --cycles 10
Expand Down
Loading
Loading