Skip to content

fix: correct delegate funding flow in StableFX debug pages - #477

Merged
yitianx00 merged 10 commits into
circlefin:masterfrom
anilgangapersaud-circle:feat/delegate-funding-support
Sep 2, 2026
Merged

yitianx00 merged 10 commits into
circlefin:masterfrom
anilgangapersaud-circle:feat/delegate-funding-support

Conversation

@anilgangapersaud-circle

@anilgangapersaud-circle anilgangapersaud-circle commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes to the delegate funding debug flow in the StableFX pages, plus funder entity credential support in settings.

Detail

stores/main.ts + layouts/default.vue

  • Adds funderWalletApiKey and funderEntitySecret state, getters, actions, and settings fields (masked as password inputs)
  • Supports delegate funding flows where the LLC funder wallet belongs to a separate Circle entity from the trader wallet

pages/debug/stablefx/funding-presign.vue

  • Fixes typed data field mapping: reads batchTraderPermitTypedData / batchFunderPermitTypedData in addition to the single-trade variants, so batch and net delegate presign responses are handled correctly
  • Fixes the "Signed" chip condition: a net_delegate trade has no trader typed data, so the chip now shows when the funder is signed and either there is no trader typed data or the trader is also signed
  • Fixes allDelegateSigned computed to use the same condition
  • Uses the separate funder entity credentials (getFunderWalletApiKey, getFunderEntitySecret) when signing the funder permit, falling back to the trader credentials if not set

pages/debug/stablefx/fund.vue

  • Fixes double-submission: the old delegate path looped once per batch entry and called fund() for each, but the batch permit covers all trades in a single call. Both delegate and net_delegate modes now submit one API call using the data from the first batch entry
  • Fixes hardcoded 'delegate' funding mode: fundingMode is now read from formData.fundingMode so net_delegate passes through correctly

Test plan

  • Verify delegate funding flow works end-to-end on smokebox (single trade, delegate mode)
  • Verify batch delegate funding flow works (makerBatchDelegateDeliver)
  • Verify net delegate funding flow works (makerNetDelegateDeliver)
  • Verify separate funder entity credentials are used when set in settings
  • Verify existing gross/net StableFX fund flow is unaffected

🤖 Generated with Claude Code

@anilgangapersaud-circle
anilgangapersaud-circle force-pushed the feat/delegate-funding-support branch from 63ebaf3 to 8d803f5 Compare September 1, 2026 13:44
For net_delegate, the presign API returns a single funderPermitTypedData
shared across all trades. Previously the signing loop treated it like
delegate mode and tried to sign a funder permit per trade.

- makeApiCall: propagate the shared funderTypedData to all batch entries
- signWithCircle: for net_delegate, sign each trader permit individually
  then sign the shared funder permit once and apply the signature to
  all entries

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…delegate/net_delegate modes

- Read traderPermitTypedData/funderPermitTypedData with batch variants as fallback
- Sign trader and funder typed data once per batch (not per trade) since all
  entries share the same typed data object
- Skip trader signing when traderTypedData is null (auto-confirmation enabled)
- Update allDelegateSigned and Signed chip to handle auto-confirm case where
  traderSignature stays empty

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…gning

The LLC funder wallet is typically under a different Circle entity than the
trader wallet. Using the trader entity secret to sign with the funder wallet ID
causes a 400 from Circle's sign API due to entity mismatch.

Added funderWalletApiKey and funderEntitySecret to the store and settings panel.
signWithCircle now uses funder entity credentials when signing the funder permit,
falling back to trader credentials if the funder fields are not configured.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Circle's sign typed data API rejects typed data that includes EIP712Domain
in the types object. It is a reserved type in EIP-712 — the domain info
is already encoded via the domain field, so EIP712Domain in types is
redundant and causes a 400.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…equest

Circle's sign typed data API expects the data field to be a JSON object.
Sending it as a JSON string caused the KMS to see domain as undefined
when trying to access .domain on a string value.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…g, fix net_delegate funding mode

- Revert circleWalletsApi to pass `data` as JSON string (Circle API requires string, not object)
- Remove stripEip712Domain helper — EIP712Domain must remain in types per contract
- Fix fundDelegateBatch to use formData.fundingMode instead of hardcoded 'delegate'

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…rade

net_delegate issues one batch authorization covering all trade IDs together,
so fundDelegateBatch was incorrectly looping over batch entries and calling
fund() N times with the same payload. Split the handler: net_delegate makes
one fund() call using the first entry's permits (all entries share them) and
marks all entries succeeded/failed together; delegate keeps the per-trade loop.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…modes

funding-presign stores the same shared typed data on every batch entry
regardless of mode. The old delegate path looped once per entry and called
fund N times, duplicating the same request. Both delegate and net_delegate
use a single batch permit that covers all trades, so one fund call is correct.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@anilgangapersaud-circle
anilgangapersaud-circle force-pushed the feat/delegate-funding-support branch from a6b9522 to cdcb217 Compare September 2, 2026 21:31
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@anilgangapersaud-circle
anilgangapersaud-circle marked this pull request as ready for review September 2, 2026 21:50
@anilgangapersaud-circle anilgangapersaud-circle changed the title feat: add delegate funding support to StableFX debug pages fix: correct delegate funding flow in StableFX debug pages Sep 2, 2026
@yitianx00
yitianx00 merged commit 2956e19 into circlefin:master Sep 2, 2026
4 checks passed
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