Skip to content

Add hook to tempo sessions, triggered on each on-chain tx#667

Open
raubrey-stripe wants to merge 11 commits into
wevm:mainfrom
raubrey-stripe:raubrey/improved-hook-for-each-on-chain-tx
Open

Add hook to tempo sessions, triggered on each on-chain tx#667
raubrey-stripe wants to merge 11 commits into
wevm:mainfrom
raubrey-stripe:raubrey/improved-hook-for-each-on-chain-tx

Conversation

@raubrey-stripe

Copy link
Copy Markdown

Adding an onSessionSettled hook to fire on each on-chain settlement/transaction (I'm not opinionated on the naming here, whatever is best!).

This:

  • Provide visibility into tx's that top-level existing hooks miss (server-driven settlement)
  • Provide visibilitly into tx's that manual instrumentation outside of the SDK cannot provide (namely: clients of the SDK are never notified of transactions triggered as the result of an auto-settlement policy firing an on-chain settlement)
  • Is useful when syncing each on-chain txHash to an external location (like Stripe, where you might want to manage/accumulate your on-chain volume)

Some thoughts

  • While this sits within the tempo method, it attempts to be generic enough to apply across other methods that support sessions (like Solana) without instrumenting those methods.
  • I would have preferred a top level event Mppx.onSessionSettled(...) event like I attempted here, but the code was pretty gnarly and it doesn't feel like I know enough about the ethos of top level events to make that call.

raubrey-stripe and others added 4 commits July 17, 2026 14:15
Adds an `onSettled` callback to `tempo.session()` parameters that fires
after every confirmed on-chain settlement or close transaction. Covers
all three trigger paths: explicit `settle()`, auto-scheduled settlements,
and cooperative `close()`. Errors in handlers are isolated and cannot
break the settlement flow.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
Renames onSettled → onSessionSettlement and promotes it to a first-class
server event ('session.settlement') in the Mppx event map. The hook now
fires for all on-chain transactions from session methods:

- trigger: 'scheduled' — auto-settlement when thresholds are crossed
- trigger: 'settle' — explicit settle() calls
- trigger: 'close' — cooperative channel close

Methods expose _bindSessionSettlementEmitter so Mppx.create() can wire
internal session settlements to the server event dispatcher. Users can
subscribe via mppx.onSessionSettlement() or mppx.on('session.settlement').

Adds tests covering all three trigger paths and error isolation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
Removes the Mppx-level event system wiring (_bindSessionSettlementEmitter,
ServerEventMap addition, onSessionSettlement on Mppx type). Settlement is
session-specific so the hook lives naturally as a tempo.session() parameter
rather than in the generic event map.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
Removes the Tempo-specific `channel: ChannelStore.State` field from
SessionSettlementContext. The remaining fields (txHash, channelId,
trigger, amount) are universal across session implementations and will
work unchanged when Solana sessions land.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
@pkg-pr-new

pkg-pr-new Bot commented Jul 20, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/mppx@667

commit: 3b9b4f0

@brendanjryan brendanjryan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

raubrey-stripe and others added 5 commits July 20, 2026 12:22
The close payload in the onSessionSettlement test was missing the
required descriptor field and had a stray captureAmount field.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
Provides both cumulative amount and incremental delta for each
settlement event, so consumers can distinguish new settlement
value from previously settled amounts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
…tle()

Instead of reading the store after settle() returns, pass the
onSessionSettlement callback through with a trigger override so
delta is computed atomically inside settle().

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
…ement

Verifies that delta correctly reflects only the incremental amount
when the channel already has prior on-chain settlements.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
…ttlement

Verifies that scheduled settlements correctly report delta as the
incremental amount when the channel has prior on-chain settlements.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
@raubrey-stripe

Copy link
Copy Markdown
Author

FYI @brendanjryan could I get another quick look?

  • Added changeset
  • Fixed a gap: in this event we really need the total amount and the delta of this settlement event. The naming here.. I'm not sure about

@brendanjryan

Copy link
Copy Markdown
Collaborator

code LGTM -- some CI issues @raubrey-stripe

raubrey-stripe and others added 2 commits July 20, 2026 21:11
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
Replace invalid '0xclose_sig' with actual Voucher.signVoucher output
so close credential verification passes signature validation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants