Skip to content

feat(sdk): memo payload, 502 failover, abortable confirmation, vested amount (#1170, #1171, #1172, #1173) - #1207

Merged
Jaydbrown merged 7 commits into
conduit-protocol:mainfrom
gbemisola299:feat/1170-1171-1172-1173-sdk-issues
Nov 26, 2026
Merged

Jaydbrown merged 7 commits into
conduit-protocol:mainfrom
gbemisola299:feat/1170-1171-1172-1173-sdk-issues

Conversation

@gbemisola299

@gbemisola299 gbemisola299 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1170
Closes #1171
Closes #1172
Closes #1173

Summary

Four SDK enhancements on one branch, each in its own area of the code. Before implementing, I checked what already existed on main, since some of the requested behaviour was partly there. The gaps I found and closed are listed per issue below.

#1170: memo in the stream-creation payload

Already on main: StreamBuilder.withMemo() stored the memo and applied it to buildTransaction() / simulate().

Gap: build() (the off-chain payload) never included it, so a backend reconciling streams had nothing to match on.

Change: build() now adds memo as base64 Memo XDR when withMemo() was called. The field is omitted when unset. Decode with xdr.Memo.fromXDR(memo, 'base64'). Text, hash, id and return memos all work.

#1171: RPC failover on 502 / 503

Already on main: endpoint groups (ConduitConfig.rpcUrls), rotation on 429/503, timeouts and open circuits, with tests.

Gap: HTTP 502 was never classified as a service-unavailable error, so a bad gateway retried the same dead endpoint instead of rotating.

Change: 502 maps to RpcServiceUnavailableError, same as 503. Tests confirm a 502 rotates to the next endpoint and a 400 does not.

Not done: 504 is not included. I kept the change to the two statuses the issue names. It's a one-line addition if you want it.

#1172: AbortSignal on confirmation watchers

Already on main: waitForConfirmation(), builder.submit() and pollForConfirmation() accepted a signal.

Gaps:

  1. clawback() accepted a signal and then dropped it before the confirmation poll.
  2. Abort was only checked after each poll sleep, so cancelling waited out the full poll interval (1 s by default, longer when confirmationPollIntervalMs is set).

Change: the poll sleep is now abortable (sleepOrAbort), so an abort rejects with AbortError immediately. clawback() forwards its signal.

Not done: createBatchStreams() and the deprecated create() still take no signal. Adding one is a public signature change, so I left it for a follow-up.

#1173: sub-second vested amount

Added: calculateVestedAmount(stream, currentTimestampMs = Date.now()), exported from the package root.

  • Accrual is ratePerSecond × elapsedMs / 1000, computed in bigint (no float rounding; tested at 10¹⁸).
  • The fraction is floored, so the counter never shows more than has accrued.
  • It follows the same pause, endTime and cancellation rules as calculateWithdrawableAmount. It does not subtract withdrawn, because it reports total vested.

Note on "matching on-chain": the contract records accrual in whole seconds. At whole-second timestamps this matches calculateWithdrawableAmount + withdrawn exactly (tested). Between seconds, the value is a client-side estimate for display, not a value the contract has recorded yet.

Other fixes needed to build and test

These were blocking npm ci / npm run build on main, so they are included in this PR:

  • src/signer.ts: a broken string literal (a stray line break inside `navigator.credentials`) that stopped the file from parsing.
  • src/events.ts: a cliff-reached event was attributed to an undefined sender, so the recipient was silently dropped from history actors. Now it's attributed to recipient. This is a behaviour change, so it has a CHANGELOG entry.
  • src/token.ts: window is read via globalThis. Browser behaviour is unchanged.
  • src/tests/mock-event-stream.test.ts: narrowed a union type that broke typecheck.

Commits

Follows the CONTRIBUTING 5-commit convention. The signer fix comes first, since nothing else builds without it.

  1. fix(signer): restore the broken literal
  2. test(sdk): failing tests for all four issues (verified to fail on main)
  3. feat(sdk): implementation
  4. test(sdk): edge cases and error paths
  5. docs(sdk): docs/api.md and CHANGELOG.md
  6. chore(sdk): typecheck and build pass

Testing

  • npm run typecheck: passes
  • npm run build: passes (previously failed on main)
  • npm run lint: 0 errors. The warnings in touched files are pre-existing (SorobanRpc import, Number() calls in older code). None are new.
  • npx vitest run: 1875 passed, 2 failed. Both failures also occur on main:
    • custom-fetch.test.ts > keeps non-2xx status visible so 429s still map to RateLimitError times out at 10 s.
    • builder-create-stream-args.test.ts > rejects a startTime in the past expects the old message startTime cannot be in the past. main now says cannot be more than 30 days in the past. The assertion is stale; I did not change it, since it is outside these issues.

Review notes

  • This adds a new public export (calculateVestedAmount). Per CONTRIBUTING, it needs the mandatory owner review plus one more maintainer approval, and the CHANGELOG entry is included.
  • The commit-level Closes lines are in the feature commit as well, as CONTRIBUTING asks.

A stray line break split the 'navigator.credentials' literal in
WebAuthnSigner.defaultCredentialsContainer, so src/signer.ts failed to
parse. That stopped 'npm ci' (which runs the build via 'prepare') and any
test importing the signer module from working.

Restores the literal to a single line with the original message text.
…col#1171, conduit-protocol#1172, conduit-protocol#1173

Describe the behaviour the four issues ask for. These are expected to fail
on main:

- conduit-protocol#1170: StreamBuilder.build() does not emit the memo set via withMemo().
  The payload should carry it as base64 Memo XDR.
- conduit-protocol#1171: an HTTP 502 from the primary RPC should rotate to the next
  endpoint in the group. Only 503 currently does.
- conduit-protocol#1172: clawback() accepts an AbortSignal but drops it before the
  confirmation poll, so aborting it does not stop polling.
- conduit-protocol#1173: calculateVestedAmount() does not exist. It should interpolate
  vested stroops from millisecond timestamps.

Refs conduit-protocol#1170 Refs conduit-protocol#1171 Refs conduit-protocol#1172 Refs conduit-protocol#1173
… amount

conduit-protocol#1170: StreamBuilder.build() now emits the memo set via withMemo() as
base64 Memo XDR under 'memo', so off-chain systems can reconcile a stream
against an invoice or employee reference. The memo is omitted when unset.

conduit-protocol#1171: an HTTP 502 from an RPC endpoint is classified as
RpcServiceUnavailableError, the same as 503. The endpoint group then
rotates to the next URL instead of retrying the failing one.

conduit-protocol#1172: pollForConfirmation waits through a sleepOrAbort helper that
rejects with AbortError as soon as the signal aborts, not after the full
poll interval. clawback() now forwards its signal to the confirmation
poll, where it was previously dropped.

conduit-protocol#1173: new calculateVestedAmount(stream, currentTimestampMs) returns
vested stroops with millisecond interpolation for live counters. It is
exported from the package entry point.

Closes conduit-protocol#1170
Closes conduit-protocol#1171
Closes conduit-protocol#1172
Closes conduit-protocol#1173
…it-protocol#1173

Covers the boundaries the feature commit could still get wrong:

- conduit-protocol#1170: an over-long text memo still throws and leaves no memo in the
  payload; an id memo keeps its full 64-bit value; replacing the memo
  replaces the payload field.
- conduit-protocol#1171: an HTTP 400 must not trigger failover (only server-side gateway
  errors should rotate endpoints); 502 maps to RpcServiceUnavailableError.
- conduit-protocol#1172: waitForConfirmation rejects at abort time rather than after the
  poll interval, does not poll when already aborted, and keeps polling
  normally when not aborted.
- conduit-protocol#1173: endTime boundary returns the full deposit; withdrawn does not
  reduce the vested total; a future pausedAt is ignored; very large rates
  keep full bigint precision; a paused stream at its start returns 0.
- docs/api.md: new calculateVestedAmount entry (units, interpolation,
  whole-second agreement with calculateWithdrawableAmount); build() memo
  field; clawback(streamId, signal?); waitForConfirmation abort timing;
  HTTP 502 in the failover list.
- CHANGELOG.md: Added and Fixed entries under [Unreleased] for conduit-protocol#1170,
  conduit-protocol#1171, conduit-protocol#1172 and conduit-protocol#1173.
Fixes the TypeScript errors that stopped 'npm run build' and
'npm run typecheck' on main. None of them changed the public API:

- src/events.ts: a cliff-reached event is attributed to its recipient.
  The old code read a 'sender' field that event does not have, so the
  recipient was silently dropped from the history actor list.
- src/token.ts: 'window' is read through globalThis so the file compiles
  without the DOM lib. Browser behaviour is unchanged.
- src/tests/mock-event-stream.test.ts: narrow the union before reading
  'sequence', which cliff-reached events do not carry.

Lint reports no errors on the touched files.
@drips-wave

drips-wave Bot commented Nov 22, 2026

Copy link
Copy Markdown

@gbemisola299 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Jaydbrown
Jaydbrown merged commit 0617ad7 into conduit-protocol:main Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants