Skip to content

v2 direct match support#270

Open
weijiekoh wants to merge 2 commits intomainfrom
wj/v2-internal-matches
Open

v2 direct match support#270
weijiekoh wants to merge 2 commits intomainfrom
wj/v2-internal-matches

Conversation

@weijiekoh
Copy link
Copy Markdown

@weijiekoh weijiekoh commented Apr 2, 2026

v2 Typescript SDK (ring0 only)

This PR implements the Typescript SDK for ring0 direct matches.

Note that the Typescript SDK already supports external matches.

It also deletes unused v1 packages, though should still be available via NPM. The price_reporter, token, and core packages remain.

Interface

Users should have this package.json dependency:

"@renegade-fi/renegade-sdk": "^2.0.0",
import { DirectMatchClient } from "@renegade-fi/renegade-sdk";

BTW, @renegade-fi/renegade-sdk also exposes ExternalMatchClient:

import { ExternalMatchClient } from "@renegade-fi/renegade-sdk";

Publishing

Follow these instructions to publish to NPM after this PR is merged:

# 1. Create a changeset (select packages and bump type)
pnpm changeset

# 2. Apply version bumps (converts workspace:^ to real npm versions)
pnpm changeset:version

# 3. Build WASM + TypeScript and publish all packages
pnpm changeset:publish

The changeset:publish script runs ./wasm_v2/build.sh (Schnorr key
derivation WASM), builds all packages, then publishes to npm. The WASM binary
is bundled inside @renegade-fi/direct-match's tarball.

Packages must be published in dependency order (direct-match and
external-match before renegade-sdk). Changesets handles this automatically.

Quick start

In typescript-sdk/, run:

./wasm_v2/build.sh
pnpm build

Next, set private key environment variables which correspond to Base Sepolia
EOAs that should be funded with ETH, dummy WETH
(0x31a5552AF53C35097Fdb20FFf294c56dc66FA04c), and dummy USDC
(0xD9961Bb4Cb27192f8dAd20a662be081f546b0E74).

Not all the tests require these keys.

export PRIVATE_KEY=0x....
export PRIVATE_KEY_2=0x....

For the quoter match test (matchQuoterOrders.test.ts), you also need to be
logged in to the AWS CLI (aws login). The test fetches QUOTERS_API_KEY and
RELAYER_ADMIN_KEY from Secrets Manager. Alternatively, set them as
environment variables:

export QUOTERS_API_KEY=...
export RELAYER_ADMIN_KEY=...

The Base Sepolia v2 WETH quoters must be funded and rebalanced for the quoter
match test to work.

Next, run the tests:

cd packages/direct-match
pnpm run test

DirectMatchClient

The DirectMatchClient class is the starting point to creating, placing,
updating, and cancelling direct match orders to a Renegade relayer. Like the
Rust SDK, the Typescript SDK provides convenience functions to instantiate
DirectMatchClient to specific chains:

const account = privateKeyToAccount(PRIVATE_KEY as Hex);
const client = await DirectMatchClient.newBaseSepoliaClient(account);

Clients can be instantiated via:

  • newArbitrumOneClient()
  • newArbitrumSepoliaClient()
  • newBaseMainnetClient()
  • newBaseSepoliaClient()

Supported client functions

Only ring0-relevant functions are currently supported.

Function Rust SDK equivalent Test Notes
createAccount() create_account() createAndGetAccount.test.ts
getAccount() get_account() createAndGetAccount.test.ts
syncAccount() sync_account() Triggers relayer to re-scan on-chain balances
getBalances() get_balances() getBalances.test.ts
getBalanceByMint(mint) get_balance_by_mint(mint) getBalanceByMint.test.ts
placeOrder(params) place_order(built_order) getOrderAndPlaceOrder.test.ts Ring 0 only
placeOrderInPool(params, pool, adminKey) admin_place_order_in_pool() matchQuoterOrders.test.ts Requires admin HMAC key
getOrder(orderId) get_order(order_id) getOrderAndPlaceOrder.test.ts
getOrders(includeHistoric) get_orders(include_historic) getOrders.test.ts Paginated
cancelOrder(orderId) cancel_order(order_id) cancelOrder.test.ts Ring 0 only
updateOrder(params) update_order(config) updateOrder.test.ts Relayer returns 501

Schnorr public key generation

Although ring0 trades do not rely on the account's Schnorr public key, the
relayer expects a valid curve point during account creation. This PR provides
WASM code to do this. The function to derive this public key is in
wasm_v2/src/lib.rs.

I considered writing a pure-Typescript version of this function but decided to
stick to using WASM because the v1 Typescript SDK already uses WASM for many
cryptographic functions, and it's much more straighforward to follow that
pattern even though we only need one function for now. The WASM integration to
Typescript works just fine. Furthermore, it's safer to rely on existing
cryptographic libraries (i.e. ark-ed-on-bn254) than to write my own.

What's missing

  • updateOrder: implemented client-side but relayer returns 501
  • Tasks: not implemented by the relayer
  • Fill tracking: relayer doesn't record or return fill details (see ticket:
    record-ring0-fill-details)

@weijiekoh weijiekoh requested review from akirillo and sehyunc and removed request for sehyunc April 2, 2026 18:11
@weijiekoh weijiekoh force-pushed the wj/v2-internal-matches branch from 5e4d02c to ea91a14 Compare April 2, 2026 20:55
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