Skip to content

feat: batch settlement go sdk#2212

Closed
CarsonRoscoe wants to merge 4 commits intox402-foundation:mainfrom
coinbase:feat/batch-settlement-go-sdk
Closed

feat: batch settlement go sdk#2212
CarsonRoscoe wants to merge 4 commits intox402-foundation:mainfrom
coinbase:feat/batch-settlement-go-sdk

Conversation

@CarsonRoscoe
Copy link
Copy Markdown
Contributor

Follow up of PR #2164, which was automatically closed when the Typescript SDK merged to main

Description

Adds the batch-settlement EVM scheme to the Go SDK at parity with the TypeScript reference implementation, plus the
resource-server architectural changes from #2109 that batch-settlement depends on.

New: batch-settlement scheme (go/mechanisms/evm/batch-settlement/)

  • Client: BatchSettlementEvmScheme with deposit (ERC-3009 + Permit2 transports), voucher signing, channel-state recovery, corrective
    402 resync, cooperative refund (scheme.Refund(url)).
  • Facilitator: simulate-then-execute for deposit/claim/refund/settle; multicall(claim+refund) on cooperative refund; ECDSA + ERC-1271
    voucher verification.
  • Server: atomic per-channel UpdateChannel storage + PendingRequest reservations; voucher local-commit short-circuit (no on-chain
    settle for vouchers); local voucher verification when on-chain state is fresh (OnchainStateTtlMs); InMemory + File channel storage
    backends; BatchSettlementChannelManager claim/settle/refund tick loop.
  • Wire format matches TS byte-for-byte (nested extra.channelState, chargedAmount, etc.); error codes consolidated under the
    invalid_batch_settlement_evm_* prefix.

Resource-server hook architecture (go/server.go, go/server_hooks.go, go/server_hook_policy.go) — port of TS PR #2109:

  • Per-(network, scheme) hook isolation: scheme-provided hooks no longer leak into the global hook list and only fire for the matched
    scheme.
  • Hook execution order: manual → matched scheme → declared extensions (mirrors TS getLabeledHooks).
  • Extension hook adapters: extensions can declare ResourceServerExtensionHooks{...}; each hook is gated on
    ctx.DeclaredExtensions[key] being set on the route.
  • Scheme-level EnrichSettlementPayload / EnrichSettlementResponse providers, called around facilitator settle.
  • Additive-policy guards (AssertAcceptsAllowlistedAfterExtensionEnrich, AssertAdditivePayloadEnrichment,
    AssertAdditiveSettlementExtra, MergeAdditiveSettlementExtra, etc.) — full port of TS hookPolicy.ts. Replaces TS's compile-time
    DeepReadonly enforcement with runtime additive-policy enforcement.
  • New VerifyPaymentWithExtensions / SettlePaymentWithExtensions / ProcessSettlementWithExtensions /
    CreatePaymentCancellationDispatcherWithExtensions methods thread declared extensions through verify → settle → cancellation.
    Existing API methods delegate with nil for backward compat.
  • HTTP middlewares (nethttp, gin, echo) all forward result.DeclaredExtensions and honor the SkipHandler directive
    (previously only nethttp did).

Examples (examples/go/{clients,servers,facilitator}/batch-settlement/): drop-in client, server, and facilitator examples with .env-example files mirroring the TS examples.

E2E (e2e/clients/go-http, e2e/facilitators/go, e2e/servers/{gin,nethttp}): batch-settlement scenarios wired into the cross-SDK harness, exercising deposit + voucher + cooperative-refund phases across go-http × {gin, nethttp} × go-facilitator on Base Sepolia.

Tests

make test and make test-integration from /go both pass:

Cross-SDK e2e testing between Typescript and Go for batch-settlement

Checklist

  • I have formatted and linted my code
  • All new and existing tests pass
  • My commits are signed (required for merge) -- you may need to rebase if you initially pushed unsigned commits
  • I added a changelog fragment for user-facing changes (docs-only changes can skip)

@CarsonRoscoe CarsonRoscoe marked this pull request as ready for review May 6, 2026 18:43
@vercel
Copy link
Copy Markdown

vercel Bot commented May 6, 2026

@CarsonRoscoe is attempting to deploy a commit to the Coinbase Team on Vercel.

A member of the Team first needs to authorize it.

@CarsonRoscoe CarsonRoscoe requested a review from phdargen May 6, 2026 18:43
@github-actions github-actions Bot added go sdk Changes to core v2 packages examples Changes to examples labels May 6, 2026
@CarsonRoscoe CarsonRoscoe force-pushed the feat/batch-settlement-go-sdk branch from 073b8b3 to f2d2dcc Compare May 6, 2026 21:43
@phdargen phdargen self-assigned this May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

examples Changes to examples go sdk Changes to core v2 packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants