n3-sdk 0.1.0 → 0.1.1

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/dist/index.d.ts CHANGED
@@ -2,24 +2,20 @@ import * as viem from 'viem';
2
2
  import { PublicClient, WalletClient, Account } from 'viem';
3
3
 
4
4
  type N3Env = {
5
- /** GraphQL HTTP endpoint, e.g. https://api.example.com/graphql */
5
+ /** GraphQL HTTP endpoint (for info/state). */
6
6
  gqlUrl: string;
7
- /** WS endpoint, e.g. wss://api.example.com/ws */
7
+ /** WebSocket endpoint (for live fanout). */
8
8
  wsUrl: string;
9
- /** Hex ed25519 public key used by the gateway allowlist (lower/upper, 0x ok) */
10
- pubkeyHex?: string;
11
- /** Optional signer for nonces; if omitted, provide secretKey instead. */
12
- signer?: (msg: Uint8Array) => Promise<Uint8Array>;
13
- /** Optional ed25519 secret key (32 or 64 bytes). */
14
- secretKey?: Uint8Array;
15
- /** Custom fetch (Node <18 or special envs). Defaults to global fetch. */
16
- fetchFn?: typeof fetch;
17
- /** Optional nonce factory; defaults to ISO timestamp with random suffix. */
18
- makeNonce?: () => string;
19
- /** OPTIONAL OVERRIDES (if you don’t use default /exchange and /info): */
20
- baseUrl?: string;
21
- exchangePath?: string;
22
- infoPath?: string;
9
+ /** Private pool contract on your chain. */
10
+ pool: `0x${string}`;
11
+ /** Domain params used by your circuits. */
12
+ chainIdDec: number;
13
+ domainDec: number;
14
+ /** Indexer + (optional) proof server. */
15
+ indexerUrl: string;
16
+ proofUrl?: string;
17
+ rpcUrl?: string;
18
+ treeDepth?: number;
23
19
  };
24
20
 
25
21
  /** GraphQL types aligned with your gateway schema */
@@ -560,7 +556,29 @@ declare class NoteStore {
560
556
  private withTxn;
561
557
  }
562
558
 
563
- declare function submitOrder(params: SubmitOrderIntentParams): Promise<string | null>;
559
+ /** Optional extra behavior for order publishing */
560
+ type SubmitOrderOptions = {
561
+ /**
562
+ * If true, the SDK will:
563
+ * - pin the head/root from the indexer
564
+ * - recompute each note commit
565
+ * - fetch Merkle proofs
566
+ * - fold back to root (sanity)
567
+ * - attach `pathElements` / `pathIndex` to spendNotes
568
+ *
569
+ * Defaults to false (for backwards compat).
570
+ */
571
+ attachProofs?: boolean;
572
+ };
573
+ /**
574
+ * Core order publisher.
575
+ * If `opts.attachProofs` is true, will enrich spendNotes with Merkle membership proofs.
576
+ */
577
+ declare function submitOrder(params: SubmitOrderIntentParams, opts?: SubmitOrderOptions): Promise<string | null>;
578
+ /**
579
+ * Convenience: build spend notes from a NoteStore (with optional partials), then publish.
580
+ * If `opts.attachProofs` is true, will enrich the *selected* spend notes with proofs.
581
+ */
564
582
  declare function submitOrderAuto(params: SubmitOrderIntentParams & {
565
583
  store: NoteStore;
566
584
  spend: {
@@ -568,7 +586,7 @@ declare function submitOrderAuto(params: SubmitOrderIntentParams & {
568
586
  amount: bigint;
569
587
  };
570
588
  allowPartial?: boolean;
571
- }): Promise<string | null>;
589
+ }, opts?: SubmitOrderOptions): Promise<string | null>;
572
590
 
573
591
  type WDOut = {
574
592
  assetId: bigint;
@@ -655,6 +673,7 @@ type index_CancelTarget = CancelTarget;
655
673
  type index_ModifyOrder = ModifyOrder;
656
674
  type index_ModifyOrderIntentParams = ModifyOrderIntentParams;
657
675
  type index_ModifyTarget = ModifyTarget;
676
+ type index_SubmitOrderOptions = SubmitOrderOptions;
658
677
  declare const index_batchCancel: typeof batchCancel;
659
678
  declare const index_batchModify: typeof batchModify;
660
679
  declare const index_batchOrders: typeof batchOrders;
@@ -667,7 +686,7 @@ declare const index_submitOrderAuto: typeof submitOrderAuto;
667
686
  declare const index_withdraw: typeof withdraw;
668
687
  declare const index_withdrawAuto: typeof withdrawAuto;
669
688
  declare namespace index {
670
- export { type index_BatchCancelOrderIntentParams as BatchCancelOrderIntentParams, type index_BatchModifyItem as BatchModifyItem, type index_BatchModifyOrderIntentParams as BatchModifyOrderIntentParams, type index_CancelOrderIntentParams as CancelOrderIntentParams, type index_CancelTarget as CancelTarget, type index_ModifyOrder as ModifyOrder, type index_ModifyOrderIntentParams as ModifyOrderIntentParams, type index_ModifyTarget as ModifyTarget, index_batchCancel as batchCancel, index_batchModify as batchModify, index_batchOrders as batchOrders, index_cancel as cancel, index_depositERC20 as depositERC20, index_depositHYPE as depositHYPE, index_modify as modify, index_submitOrder as submitOrder, index_submitOrderAuto as submitOrderAuto, index_withdraw as withdraw, index_withdrawAuto as withdrawAuto };
689
+ export { type index_BatchCancelOrderIntentParams as BatchCancelOrderIntentParams, type index_BatchModifyItem as BatchModifyItem, type index_BatchModifyOrderIntentParams as BatchModifyOrderIntentParams, type index_CancelOrderIntentParams as CancelOrderIntentParams, type index_CancelTarget as CancelTarget, type index_ModifyOrder as ModifyOrder, type index_ModifyOrderIntentParams as ModifyOrderIntentParams, type index_ModifyTarget as ModifyTarget, type index_SubmitOrderOptions as SubmitOrderOptions, index_batchCancel as batchCancel, index_batchModify as batchModify, index_batchOrders as batchOrders, index_cancel as cancel, index_depositERC20 as depositERC20, index_depositHYPE as depositHYPE, index_modify as modify, index_submitOrder as submitOrder, index_submitOrderAuto as submitOrderAuto, index_withdraw as withdraw, index_withdrawAuto as withdrawAuto };
671
690
  }
672
691
 
673
692
  type Chain = {
@@ -718,18 +737,30 @@ type SubsAPI = {
718
737
  trades: ReturnType<typeof makeTrades>;
719
738
  batches: ReturnType<typeof makeBatches>;
720
739
  };
740
+ /**
741
+ * Exchange facade: we pre-bind env and auto-inject default clients if caller
742
+ * doesn't pass them. Callers can still override by passing { clients }.
743
+ */
721
744
  type ExAPI = {
722
- order: typeof submitOrder;
723
- orderAuto: typeof submitOrderAuto;
745
+ order: (p: Parameters<typeof submitOrder>[0]) => ReturnType<typeof submitOrder>;
746
+ orderAuto: (p: Parameters<typeof submitOrderAuto>[0]) => ReturnType<typeof submitOrderAuto>;
724
747
  modify: typeof modify;
725
748
  cancel: typeof cancel;
726
749
  batchOrder: typeof batchOrders;
727
750
  batchModify: typeof batchModify;
728
751
  batchCancel: typeof batchCancel;
729
- withdraw: typeof withdraw;
730
- withdrawAuto: typeof withdrawAuto;
731
- depositHYPE: typeof depositHYPE;
732
- depositERC20: typeof depositERC20;
752
+ withdraw: (p: Parameters<typeof withdraw>[0] & {
753
+ clients?: N3Clients;
754
+ }) => ReturnType<typeof withdraw>;
755
+ withdrawAuto: (p: Parameters<typeof withdrawAuto>[0] & {
756
+ clients?: N3Clients;
757
+ }) => ReturnType<typeof withdrawAuto>;
758
+ depositHYPE: (p: Parameters<typeof depositHYPE>[0] & {
759
+ clients?: N3Clients;
760
+ }) => ReturnType<typeof depositHYPE>;
761
+ depositERC20: (p: Parameters<typeof depositERC20>[0] & {
762
+ clients?: N3Clients;
763
+ }) => ReturnType<typeof depositERC20>;
733
764
  };
734
765
  declare class N3SDK {
735
766
  readonly env: N3Env;
@@ -737,10 +768,26 @@ declare class N3SDK {
737
768
  readonly info: InfoAPI;
738
769
  /** WebSocket fanout (live streams) */
739
770
  readonly subscriptions: SubsAPI;
740
- /** Hyperliquid-aligned exchange actions */
771
+ /** Exchange actions (env-bound; auto inject default clients if missing) */
741
772
  readonly exchange: ExAPI;
742
- constructor(env: N3Env);
743
- startReceiverSync(store: NoteStore, clients: N3Clients, fromBlock?: number | bigint): () => void;
773
+ /** Optional default clients (set at construction or via setter). */
774
+ private _defaultClients;
775
+ /** Optional server-only public client if env.rpcUrl is provided. */
776
+ private _serverPublicClient;
777
+ constructor(env: N3Env, opts?: {
778
+ defaultClients?: N3Clients | null;
779
+ });
780
+ /** Prefer this instead of touching private fields. */
781
+ setDefaultClients(c: N3Clients | null): void;
782
+ /** Retrieve default clients (throws if not set). */
783
+ getClientsOrThrow(): N3Clients;
784
+ /**
785
+ * Optional: start background receiver sync (Merkle confirmations & NF tracking).
786
+ * If `clients` not passed, it will try server public client from `env.rpcUrl`,
787
+ * but you should usually pass a full N3Clients bundle (with account/wallet)
788
+ * when you also need to mark nullifiers, etc.
789
+ */
790
+ startReceiverSync(store: NoteStore, clients?: N3Clients, fromBlock?: number | bigint): () => void;
744
791
  }
745
792
 
746
793
  export { type AssetId, index as Exchange, index$2 as Info, type N3Clients, type N3Env, N3SDK, NoteStore, NoteStore as NoteStoreT, Receiver, index$1 as Subscription, type TopicName, Topics, N3SDK as default, toReceiverFromBlock, toViemFromBlock };