Skip to content

Support external-wallet trading with Token Standard V2 - #138

Merged
srikanth-bitdynamics merged 15 commits into
mainfrom
registry-0.14
Sep 10, 2026
Merged

srikanth-bitdynamics merged 15 commits into
mainfrom
registry-0.14

Conversation

@srikanth-bitdynamics

@srikanth-bitdynamics srikanth-bitdynamics commented Sep 10, 2026 •

Copy link
Copy Markdown
Owner

Add external-wallet funding and atomic settlement across token admins in package version 1.3.0. Update allocation recovery, holding selection and wallet approvals for these flows.

Checked package upgrade compatibility, backend typechecking, 346 backend tests, 145 frontend tests and the frontend build.

An Unfunded pool has zero reserves, so matching the pool ratio derived the
paired amount as NaN and left the button disabled. Detect the first deposit,
keep both amounts as independent inputs so the LP sets the opening price,
estimate LP as sqrt(base*quote), and require both sides before enabling add.
Let a connected wallet prove control of its party on-ledger and receive a
scoped, short-lived caller token that authorizes its own trader-flow writes, so
a public user swaps or adds liquidity without ever holding the venue operator
secret.

- Daml SessionAttestation: the party self-authors a single-use proof only it can
  create (sole signatory); the operator observes and consumes it.
- Session service (POST /v1/session/challenge, /v1/session/verify) mints an HS256
  caller token (sub=party) from the on-ledger proof; enabled by
  DEX_CALLER_JWT_SECRET, a 501 no-op otherwise.
- A valid caller token authorizes the seven caller-bound trader routes in place
  of the operator token; the per-caller binding still restricts the subject to
  the caller's own party, and the backend performs the operator/lpRegistrar
  ledger steps with its own server-side credential.
- Frontend establishes a session on connect (the wallet authors the attestation)
  and attaches X-Caller-Token to trader writes.
An env file that parses VITE_CANTON_DEX_PACKAGE_ID=#canton-dex-trading-v2 as
a comment yields an empty string, which the nullish (`??`) default let through
unchanged. Every wallet-authored create then submitted an empty Daml-LF package
id. Use `||` so an empty value also falls back to the package-name reference.
…Message)

Matches the testnet-deployed tree: the wallet authors only Token-Standard
allocations (acceptRequest=false; operator settles via the live-request arm),
SessionAttestation removed, off-ledger signMessage session with a capability
fallback for keyless wallets. Includes a temporary [session:account-debug]
log used to diagnose Loop's empty publicKey (removed in the progressive-auth
work).
…ustody

Wallet connect is sign-in; the Token-Standard allocation validated on-ledger is
the authorization boundary. A one-time operator-signed bootstrap token carries a
nonceHash that the operator stamps into the request's allocation specs; the
settle Daml choices validate the allocations against the live request and return
{authenticatedParty, authBinding}. The backend mints a party JWT only when the
presented bootstrap's nonceHash equals the settle result's authBinding, subject
is the ledger-proven party (never the HTTP body), one-time. signMessage stays a
capability-gated fast path; keyless wallets (Loop) take the ledger path. Request
and settle routes leave the operator-token/caller-binding gates; a rate limiter
covers the new public surface. canton-dex-trading-v2 1.1.0 -> 1.2.0 (additive,
upgrade-check clean). Orders remain on the operator path (still trader-signed).
…1.3.0

SwapAllocationRequest/LiquidityAllocationRequest named the trader as observer,
making the trader's participant a stakeholder on canton-dex-trading-v2 and
forcing it to vet our package (INVALID_PRESCRIBED_SYNCHRONIZER_ID). With
acceptRequest=false the wallet authors from HTTP-returned specs and never
observes the on-ledger request, so the observer is unnecessary. Removing it
keeps the trader off every canton-dex-trading-v2 contract. Additive SCU upgrade
(observer-expression change is a warning, not a break).
…tilityV2

External wallets (Loop) reject the BatchingUtilityV2 CreateAndExercise as an
unsupported command. Emit one direct AllocationFactory_Allocate ExerciseCommand
per leg in a single atomic commands[] instead (composeAllocationCommands), with
real per-leg inputHoldingCids. Removes the splice-util-token-standard-wallet
dependency from the external-wallet path. Invariant test asserts no external
command references canton-dex-trading-v2 / splice-util / CantonDex.*.
PartyLayer/Loop's tx UI refuses a multi-command request (Confirm disabled). The
canonical external-wallet flow is now one AllocationFactory_Allocate per wallet
prompt: capability supportsMultiCommandTransaction (default false) drives a
shared sequential-submit helper that authors each allocation as its own request,
recovers each created cid by updateId, and aggregates them in canonical order —
the operator settle stays the sole atomic point. settleAt ~5min gives locked
funds a liveness escape; partial failure surfaces which leg failed. Backend:
recover-dvp-allocations made public (connected) + rate-limited so the browser
can recover cids before settle. No wallet-name branching.
…), not synthetic

The @partylayer/adapter-loop patch intercepted HoldingV2 ACS queries, called
aggregate getHolding(), and fabricated synthetic loop-holding:* contract ids —
which Canton rejects as unparseable when passed to AllocationFactory_Allocate.
Removed that shim so Holding ACS queries flow through provider.getActiveContracts
(real per-holding cids); getHolding stays display-only. Regenerated the patch.
Added assertRealContractId guard in composeAllocationCommands so a synthetic id
can never reach the wallet again; temporary funding-cid console probe.
…isplay via getHolding

Loop's getActiveContracts(HoldingV2 interface) returns [] despite real CC, so
funding gets a concrete-template fallback: try the HoldingV2 interface first,
then a per-asset concrete Holding template (CC -> #splice-amulet:Splice.Amulet:Amulet)
from an asset-compat descriptor in the wallet layer (never DEX/pool code). USDCx
left unconfigured until its template is known. Balance DISPLAY now uses the
wallet's aggregate getHolding() — a separate path from spendable-holding
resolution (balance != spendable ledger contract). Temporary probe logs on the
concrete-template response. No synthetic cids.
…+ retry on ingestion lag

Recover created allocation cids from each AllocationFactory_Allocate exercise result rather than matching a fixed template name, so deposits minted on external registries (Amulet, USDCx) are recovered. Forward treeAllocationCids through the idempotent ledger wrapper, and retry DvP recovery briefly to absorb cross-participant ingestion lag.
… resolver, committed updateId)

Back off and pace active-contracts reads when a wallet rate-limits them. Resolve spendable holdings via the mapped concrete asset template first, falling back to interface discovery. Submit through submit-and-wait so the receipt carries the real ledger updateId the operator recovers by. Show the aggregate available balance in the pool form.
Remove the [funding]/[holdings] active-contracts probes and the adapter waited-submit diagnostic. The loop-sdk 429 error detail is kept: it surfaces the real status when a wallet rate-limits reads.
… Daml tests

Drop the unused CantonDex.Session.Attestation template and its stale guide (the deployed auth uses the bootstrap-bound session flow, not this proof-of-control contract), and bump canton-dex-trading-v2 to 1.4.0.

The Daml test suite was pinned to the 1.0.0 DAR and had drifted: point trading-tests at the current DAR, add the authBinding field (introduced in 1.2.0) to the request-choice constructions, and read the operator-only request contracts via readAs (the trader observer was removed in 1.3.0). 118 tests pass.
@srikanth-bitdynamics
srikanth-bitdynamics merged commit 50ac0b2 into main Sep 10, 2026
5 checks passed
@srikanth-bitdynamics srikanth-bitdynamics changed the title Self-custodial external-wallet trading (Token Standard V2) — canton-dex-trading-v2 1.3.0 Support external-wallet trading with Token Standard V2 Sep 21, 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

Development

Successfully merging this pull request may close these issues.

1 participant