Skip to content

Commit 66d6d07

Browse files
authored
Merge pull request #36 from usherlabs/feature/routed-withdraw-via-master
Add routed withdraw via master support
2 parents 75310a6 + d02d428 commit 66d6d07

File tree

8 files changed

+826
-96
lines changed

8 files changed

+826
-96
lines changed

README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,110 @@ metadata.set('use-secondary-key', '1'); // Use secondary broker 1
376376
metadata.set('use-secondary-key', '2'); // Use secondary broker 2
377377
```
378378

379+
### Routed Withdraws Via Master
380+
381+
The broker can now orchestrate a routed withdraw for exchanges that require:
382+
383+
1. moving funds from a sub-account to a master account
384+
2. executing the external withdraw from the master account
385+
386+
Current support:
387+
388+
- `binance`: supported
389+
- other exchanges: not yet supported; the broker falls back to a normal direct withdraw
390+
391+
#### Configurer guide
392+
393+
From the operator's perspective, the simplest setup is:
394+
395+
1. configure the master account as the primary account for that exchange
396+
2. configure each sub-account as a numbered secondary account
397+
3. keep using normal withdraw policy rules in `policy.json`
398+
4. set routed-withdraw fields in the request payload when you want this behavior
399+
400+
Minimal Binance example:
401+
402+
```env
403+
# Master account
404+
CEX_BROKER_BINANCE_API_KEY=master_key
405+
CEX_BROKER_BINANCE_API_SECRET=master_secret
406+
407+
# Optional but recommended for clarity
408+
CEX_BROKER_BINANCE_ROLE=master
409+
410+
# Sub-account used as the source of funds
411+
CEX_BROKER_BINANCE_API_KEY_1=subaccount_key_1
412+
CEX_BROKER_BINANCE_API_SECRET_1=subaccount_secret_1
413+
414+
# Optional but recommended for clarity
415+
CEX_BROKER_BINANCE_ROLE_1=subaccount
416+
```
417+
418+
Example withdraw payload:
419+
420+
```json
421+
{
422+
"recipientAddress": "0x1234...",
423+
"amount": "25",
424+
"chain": "ARBITRUM",
425+
"routeViaMaster": "true",
426+
"sourceAccount": "secondary:1",
427+
"masterAccount": "primary"
428+
}
429+
```
430+
431+
Recommended operational model:
432+
433+
- make `primary` the exchange master account
434+
- use `secondary:N` for sub-accounts that hold funds or trade independently
435+
- only set `routeViaMaster=true` when the exchange requires master-executed withdrawals
436+
437+
#### Meaning of `sourceAccount` and `masterAccount`
438+
439+
- `sourceAccount`: the account that currently holds the funds
440+
- `masterAccount`: the account that should perform the final external withdraw
441+
442+
Accepted selector values:
443+
444+
- `primary`
445+
- `secondary:1`, `secondary:2`, ...
446+
- `current` for `sourceAccount`, which means "whatever account was selected by metadata or by default"
447+
448+
#### Purpose of `role`, `uid`, `email`, and `subAccountId`
449+
450+
These fields are **not all required today**, and for the current Binance implementation they are mostly future-proofing rather than something you must configure immediately.
451+
452+
- `role`: broker-level intent. This is the useful one today. It marks an account as `master` or `subaccount` and makes configuration easier to audit.
453+
- `email`: exchange-specific sub-account identifier. Some exchanges identify sub-accounts by email rather than by API key relationship.
454+
- `subAccountId`: exchange-specific sub-account identifier used by APIs that require an explicit account id.
455+
- `uid`: exchange-specific account/user identifier required by some transfer APIs.
456+
457+
If you enforce the convention that **primary is always the master account**, then yes, `uid`, `email`, and `subAccountId` are redundant for the current Binance flow.
458+
459+
They still exist for two reasons:
460+
461+
- to support future exchange adapters where API keys alone are not enough to identify the transfer source or destination
462+
- to make the broker config model stable now instead of redesigning it later per exchange
463+
464+
Practical rule:
465+
466+
- for Binance today, configure `primary` as master and `secondary:N` as sub-accounts; `role` is optional but recommended
467+
- you do not need `uid`, `email`, or `subAccountId` unless a future exchange adapter requires them
468+
469+
#### Does deposit require the same setup?
470+
471+
Usually no.
472+
473+
Deposits are different from withdrawals:
474+
475+
- withdrawals may require a master account to authorize the external transfer
476+
- deposits usually just require fetching the deposit address for the account or sub-account you want to receive funds
477+
478+
So the normal approach is:
479+
480+
- deposit directly to the intended target account or sub-account
481+
- only do an internal transfer afterward if funds landed in the wrong internal account for your workflow
482+
379483
### Zero-Knowledge Proof Integration
380484

381485
**Enable privacy-preserving proof over CEX data** with [Verity zkTLS integration](https://github.com/usherlabs/verity-dp):

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@usherlabs/cex-broker",
3-
"version": "0.2.6",
3+
"version": "0.2.7",
44
"description": "Unified gRPC API to CEXs by Usher Labs.",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)