@usherlabs/cex-broker 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -0
- package/dist/commands/cli.js +7250 -7059
- package/dist/helpers/index.d.ts +38 -13
- package/dist/index.js +6994 -6803
- package/dist/index.js.map +47 -47
- package/dist/schemas/action-payloads.d.ts +3 -0
- package/dist/server.d.ts +2 -5
- package/dist/types.d.ts +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -376,6 +376,110 @@ metadata.set('use-secondary-key', '1'); // Use secondary broker 1
|
|
|
376
376
|
metadata.set('use-secondary-key', '2'); // Use secondary broker 2
|
|
377
377
|
```
|
|
378
378
|
|
|
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
|
+
|
|
379
483
|
### Zero-Knowledge Proof Integration
|
|
380
484
|
|
|
381
485
|
**Enable privacy-preserving proof over CEX data** with [Verity zkTLS integration](https://github.com/usherlabs/verity-dp):
|