dipcoin-cli 0.6.0 → 0.8.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/cli.cjs CHANGED
@@ -9,7 +9,6 @@ var path = require('path');
9
9
  var os = require('os');
10
10
  var fs = require('fs');
11
11
  var ed25519 = require('@mysten/sui/keypairs/ed25519');
12
- var perpTsLibrary = require('@dipcoinlab/perp-ts-library');
13
12
  var transactions = require('@mysten/sui/transactions');
14
13
  var BigNumber = require('bignumber.js');
15
14
  var pythSuiJs = require('@pythnetwork/pyth-sui-js');
@@ -49,8 +48,8 @@ function initSDKOptions(options) {
49
48
  };
50
49
  }
51
50
 
52
- const PACKAGE_VERSION = "1.45.0";
53
- const TARGETED_RPC_VERSION = "1.61.0";
51
+ const PACKAGE_VERSION = "1.45.2";
52
+ const TARGETED_RPC_VERSION = "1.62.0";
54
53
 
55
54
  const CODE_TO_ERROR_TYPE = {
56
55
  "-32700": "ParseError",
@@ -2504,773 +2503,902 @@ class Experimental_BaseClient {
2504
2503
  }
2505
2504
  }
2506
2505
 
2507
- // src/actions/await/awaitAsync.ts
2508
-
2509
- // src/storages/globalConfig/globalConfig.ts
2510
- var store;
2511
- function getGlobalConfig(config2) {
2512
- return {
2513
- lang: config2?.lang ?? store?.lang,
2514
- message: config2?.message,
2515
- abortEarly: config2?.abortEarly ?? store?.abortEarly,
2516
- abortPipeEarly: config2?.abortPipeEarly ?? store?.abortPipeEarly
2517
- };
2506
+ //#region src/storages/globalConfig/globalConfig.ts
2507
+ let store$4;
2508
+ /**
2509
+ * Returns the global configuration.
2510
+ *
2511
+ * @param config The config to merge.
2512
+ *
2513
+ * @returns The configuration.
2514
+ */
2515
+ /* @__NO_SIDE_EFFECTS__ */
2516
+ function getGlobalConfig(config$1) {
2517
+ return {
2518
+ lang: config$1?.lang ?? store$4?.lang,
2519
+ message: config$1?.message,
2520
+ abortEarly: config$1?.abortEarly ?? store$4?.abortEarly,
2521
+ abortPipeEarly: config$1?.abortPipeEarly ?? store$4?.abortPipeEarly
2522
+ };
2518
2523
  }
2519
2524
 
2520
- // src/storages/globalMessage/globalMessage.ts
2521
- var store2;
2525
+ //#endregion
2526
+ //#region src/storages/globalMessage/globalMessage.ts
2527
+ let store$3;
2528
+ /**
2529
+ * Returns a global error message.
2530
+ *
2531
+ * @param lang The language of the message.
2532
+ *
2533
+ * @returns The error message.
2534
+ */
2535
+ /* @__NO_SIDE_EFFECTS__ */
2522
2536
  function getGlobalMessage(lang) {
2523
- return store2?.get(lang);
2537
+ return store$3?.get(lang);
2524
2538
  }
2525
2539
 
2526
- // src/storages/schemaMessage/schemaMessage.ts
2527
- var store3;
2540
+ //#endregion
2541
+ //#region src/storages/schemaMessage/schemaMessage.ts
2542
+ let store$2;
2543
+ /**
2544
+ * Returns a schema error message.
2545
+ *
2546
+ * @param lang The language of the message.
2547
+ *
2548
+ * @returns The error message.
2549
+ */
2550
+ /* @__NO_SIDE_EFFECTS__ */
2528
2551
  function getSchemaMessage(lang) {
2529
- return store3?.get(lang);
2552
+ return store$2?.get(lang);
2530
2553
  }
2531
2554
 
2532
- // src/storages/specificMessage/specificMessage.ts
2533
- var store4;
2555
+ //#endregion
2556
+ //#region src/storages/specificMessage/specificMessage.ts
2557
+ let store$1;
2558
+ /**
2559
+ * Returns a specific error message.
2560
+ *
2561
+ * @param reference The identifier reference.
2562
+ * @param lang The language of the message.
2563
+ *
2564
+ * @returns The error message.
2565
+ */
2566
+ /* @__NO_SIDE_EFFECTS__ */
2534
2567
  function getSpecificMessage(reference, lang) {
2535
- return store4?.get(reference)?.get(lang);
2568
+ return store$1?.get(reference)?.get(lang);
2536
2569
  }
2537
2570
 
2538
- // src/utils/_stringify/_stringify.ts
2571
+ //#endregion
2572
+ //#region src/utils/_stringify/_stringify.ts
2573
+ /**
2574
+ * Stringifies an unknown input to a literal or type string.
2575
+ *
2576
+ * @param input The unknown input.
2577
+ *
2578
+ * @returns A literal or type string.
2579
+ *
2580
+ * @internal
2581
+ */
2582
+ /* @__NO_SIDE_EFFECTS__ */
2539
2583
  function _stringify(input) {
2540
- const type = typeof input;
2541
- if (type === "string") {
2542
- return `"${input}"`;
2543
- }
2544
- if (type === "number" || type === "bigint" || type === "boolean") {
2545
- return `${input}`;
2546
- }
2547
- if (type === "object" || type === "function") {
2548
- return (input && Object.getPrototypeOf(input)?.constructor?.name) ?? "null";
2549
- }
2550
- return type;
2584
+ const type = typeof input;
2585
+ if (type === "string") return `"${input}"`;
2586
+ if (type === "number" || type === "bigint" || type === "boolean") return `${input}`;
2587
+ if (type === "object" || type === "function") return (input && Object.getPrototypeOf(input)?.constructor?.name) ?? "null";
2588
+ return type;
2551
2589
  }
2552
2590
 
2553
- // src/utils/_addIssue/_addIssue.ts
2554
- function _addIssue(context, label, dataset, config2, other) {
2555
- const input = other && "input" in other ? other.input : dataset.value;
2556
- const expected = other?.expected ?? context.expects ?? null;
2557
- const received = other?.received ?? _stringify(input);
2558
- const issue = {
2559
- kind: context.kind,
2560
- type: context.type,
2561
- input,
2562
- expected,
2563
- received,
2564
- message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
2565
- // @ts-expect-error
2566
- requirement: context.requirement,
2567
- path: other?.path,
2568
- issues: other?.issues,
2569
- lang: config2.lang,
2570
- abortEarly: config2.abortEarly,
2571
- abortPipeEarly: config2.abortPipeEarly
2572
- };
2573
- const isSchema = context.kind === "schema";
2574
- const message = other?.message ?? // @ts-expect-error
2575
- context.message ?? getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? getSchemaMessage(issue.lang) : null) ?? config2.message ?? getGlobalMessage(issue.lang);
2576
- if (message) {
2577
- issue.message = typeof message === "function" ? message(issue) : message;
2578
- }
2579
- if (isSchema) {
2580
- dataset.typed = false;
2581
- }
2582
- if (dataset.issues) {
2583
- dataset.issues.push(issue);
2584
- } else {
2585
- dataset.issues = [issue];
2586
- }
2591
+ //#endregion
2592
+ //#region src/utils/_addIssue/_addIssue.ts
2593
+ /**
2594
+ * Adds an issue to the dataset.
2595
+ *
2596
+ * @param context The issue context.
2597
+ * @param label The issue label.
2598
+ * @param dataset The input dataset.
2599
+ * @param config The configuration.
2600
+ * @param other The optional props.
2601
+ *
2602
+ * @internal
2603
+ */
2604
+ function _addIssue(context, label, dataset, config$1, other) {
2605
+ const input = other && "input" in other ? other.input : dataset.value;
2606
+ const expected = other?.expected ?? context.expects ?? null;
2607
+ const received = other?.received ?? /* @__PURE__ */ _stringify(input);
2608
+ const issue = {
2609
+ kind: context.kind,
2610
+ type: context.type,
2611
+ input,
2612
+ expected,
2613
+ received,
2614
+ message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
2615
+ requirement: context.requirement,
2616
+ path: other?.path,
2617
+ issues: other?.issues,
2618
+ lang: config$1.lang,
2619
+ abortEarly: config$1.abortEarly,
2620
+ abortPipeEarly: config$1.abortPipeEarly
2621
+ };
2622
+ const isSchema = context.kind === "schema";
2623
+ const message$1 = other?.message ?? context.message ?? /* @__PURE__ */ getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? /* @__PURE__ */ getSchemaMessage(issue.lang) : null) ?? config$1.message ?? /* @__PURE__ */ getGlobalMessage(issue.lang);
2624
+ if (message$1 !== void 0) issue.message = typeof message$1 === "function" ? message$1(issue) : message$1;
2625
+ if (isSchema) dataset.typed = false;
2626
+ if (dataset.issues) dataset.issues.push(issue);
2627
+ else dataset.issues = [issue];
2628
+ }
2629
+
2630
+ //#endregion
2631
+ //#region src/utils/_getStandardProps/_getStandardProps.ts
2632
+ /**
2633
+ * Returns the Standard Schema properties.
2634
+ *
2635
+ * @param context The schema context.
2636
+ *
2637
+ * @returns The Standard Schema properties.
2638
+ */
2639
+ /* @__NO_SIDE_EFFECTS__ */
2640
+ function _getStandardProps(context) {
2641
+ return {
2642
+ version: 1,
2643
+ vendor: "valibot",
2644
+ validate(value$1) {
2645
+ return context["~run"]({ value: value$1 }, /* @__PURE__ */ getGlobalConfig());
2646
+ }
2647
+ };
2648
+ }
2649
+
2650
+ //#endregion
2651
+ //#region src/utils/_isValidObjectKey/_isValidObjectKey.ts
2652
+ /**
2653
+ * Disallows inherited object properties and prevents object prototype
2654
+ * pollution by disallowing certain keys.
2655
+ *
2656
+ * @param object The object to check.
2657
+ * @param key The key to check.
2658
+ *
2659
+ * @returns Whether the key is allowed.
2660
+ *
2661
+ * @internal
2662
+ */
2663
+ /* @__NO_SIDE_EFFECTS__ */
2664
+ function _isValidObjectKey(object$1, key) {
2665
+ return Object.hasOwn(object$1, key) && key !== "__proto__" && key !== "prototype" && key !== "constructor";
2587
2666
  }
2588
2667
 
2589
- // src/utils/_isValidObjectKey/_isValidObjectKey.ts
2590
- function _isValidObjectKey(object2, key) {
2591
- return Object.hasOwn(object2, key) && key !== "__proto__" && key !== "prototype" && key !== "constructor";
2668
+ //#endregion
2669
+ //#region src/utils/_joinExpects/_joinExpects.ts
2670
+ /**
2671
+ * Joins multiple `expects` values with the given separator.
2672
+ *
2673
+ * @param values The `expects` values.
2674
+ * @param separator The separator.
2675
+ *
2676
+ * @returns The joined `expects` property.
2677
+ *
2678
+ * @internal
2679
+ */
2680
+ /* @__NO_SIDE_EFFECTS__ */
2681
+ function _joinExpects(values$1, separator) {
2682
+ const list = [...new Set(values$1)];
2683
+ if (list.length > 1) return `(${list.join(` ${separator} `)})`;
2684
+ return list[0] ?? "never";
2592
2685
  }
2593
2686
 
2594
- // src/utils/ValiError/ValiError.ts
2687
+ //#endregion
2688
+ //#region src/utils/ValiError/ValiError.ts
2689
+ /**
2690
+ * A Valibot error with useful information.
2691
+ */
2595
2692
  var ValiError = class extends Error {
2596
- /**
2597
- * The error issues.
2598
- */
2599
- issues;
2600
- /**
2601
- * Creates a Valibot error with useful information.
2602
- *
2603
- * @param issues The error issues.
2604
- */
2605
- constructor(issues) {
2606
- super(issues[0].message);
2607
- this.name = "ValiError";
2608
- this.issues = issues;
2609
- }
2693
+ /**
2694
+ * Creates a Valibot error with useful information.
2695
+ *
2696
+ * @param issues The error issues.
2697
+ */
2698
+ constructor(issues) {
2699
+ super(issues[0].message);
2700
+ this.name = "ValiError";
2701
+ this.issues = issues;
2702
+ }
2610
2703
  };
2611
2704
 
2612
- // src/actions/check/check.ts
2613
- function check(requirement, message) {
2614
- return {
2615
- kind: "validation",
2616
- type: "check",
2617
- reference: check,
2618
- async: false,
2619
- expects: null,
2620
- requirement,
2621
- message,
2622
- _run(dataset, config2) {
2623
- if (dataset.typed && !this.requirement(dataset.value)) {
2624
- _addIssue(this, "input", dataset, config2);
2625
- }
2626
- return dataset;
2627
- }
2628
- };
2705
+ //#endregion
2706
+ //#region src/actions/check/check.ts
2707
+ /* @__NO_SIDE_EFFECTS__ */
2708
+ function check(requirement, message$1) {
2709
+ return {
2710
+ kind: "validation",
2711
+ type: "check",
2712
+ reference: check,
2713
+ async: false,
2714
+ expects: null,
2715
+ requirement,
2716
+ message: message$1,
2717
+ "~run"(dataset, config$1) {
2718
+ if (dataset.typed && !this.requirement(dataset.value)) _addIssue(this, "input", dataset, config$1);
2719
+ return dataset;
2720
+ }
2721
+ };
2629
2722
  }
2630
2723
 
2631
- // src/actions/integer/integer.ts
2632
- function integer(message) {
2633
- return {
2634
- kind: "validation",
2635
- type: "integer",
2636
- reference: integer,
2637
- async: false,
2638
- expects: null,
2639
- requirement: Number.isInteger,
2640
- message,
2641
- _run(dataset, config2) {
2642
- if (dataset.typed && !this.requirement(dataset.value)) {
2643
- _addIssue(this, "integer", dataset, config2);
2644
- }
2645
- return dataset;
2646
- }
2647
- };
2724
+ //#endregion
2725
+ //#region src/actions/integer/integer.ts
2726
+ /* @__NO_SIDE_EFFECTS__ */
2727
+ function integer(message$1) {
2728
+ return {
2729
+ kind: "validation",
2730
+ type: "integer",
2731
+ reference: integer,
2732
+ async: false,
2733
+ expects: null,
2734
+ requirement: Number.isInteger,
2735
+ message: message$1,
2736
+ "~run"(dataset, config$1) {
2737
+ if (dataset.typed && !this.requirement(dataset.value)) _addIssue(this, "integer", dataset, config$1);
2738
+ return dataset;
2739
+ }
2740
+ };
2648
2741
  }
2649
2742
 
2650
- // src/actions/transform/transform.ts
2743
+ //#endregion
2744
+ //#region src/actions/transform/transform.ts
2745
+ /**
2746
+ * Creates a custom transformation action.
2747
+ *
2748
+ * @param operation The transformation operation.
2749
+ *
2750
+ * @returns A transform action.
2751
+ */
2752
+ /* @__NO_SIDE_EFFECTS__ */
2651
2753
  function transform(operation) {
2652
- return {
2653
- kind: "transformation",
2654
- type: "transform",
2655
- reference: transform,
2656
- async: false,
2657
- operation,
2658
- _run(dataset) {
2659
- dataset.value = this.operation(dataset.value);
2660
- return dataset;
2661
- }
2662
- };
2754
+ return {
2755
+ kind: "transformation",
2756
+ type: "transform",
2757
+ reference: transform,
2758
+ async: false,
2759
+ operation,
2760
+ "~run"(dataset) {
2761
+ dataset.value = this.operation(dataset.value);
2762
+ return dataset;
2763
+ }
2764
+ };
2663
2765
  }
2664
2766
 
2665
- // src/methods/getDefault/getDefault.ts
2666
- function getDefault(schema, dataset, config2) {
2667
- return typeof schema.default === "function" ? (
2668
- // @ts-expect-error
2669
- schema.default(dataset, config2)
2670
- ) : (
2671
- // @ts-expect-error
2672
- schema.default
2673
- );
2767
+ //#endregion
2768
+ //#region src/methods/getFallback/getFallback.ts
2769
+ /**
2770
+ * Returns the fallback value of the schema.
2771
+ *
2772
+ * @param schema The schema to get it from.
2773
+ * @param dataset The output dataset if available.
2774
+ * @param config The config if available.
2775
+ *
2776
+ * @returns The fallback value.
2777
+ */
2778
+ /* @__NO_SIDE_EFFECTS__ */
2779
+ function getFallback(schema, dataset, config$1) {
2780
+ return typeof schema.fallback === "function" ? schema.fallback(dataset, config$1) : schema.fallback;
2781
+ }
2782
+
2783
+ //#endregion
2784
+ //#region src/methods/getDefault/getDefault.ts
2785
+ /**
2786
+ * Returns the default value of the schema.
2787
+ *
2788
+ * @param schema The schema to get it from.
2789
+ * @param dataset The input dataset if available.
2790
+ * @param config The config if available.
2791
+ *
2792
+ * @returns The default value.
2793
+ */
2794
+ /* @__NO_SIDE_EFFECTS__ */
2795
+ function getDefault(schema, dataset, config$1) {
2796
+ return typeof schema.default === "function" ? schema.default(dataset, config$1) : schema.default;
2674
2797
  }
2675
2798
 
2676
- // src/methods/is/is.ts
2799
+ //#endregion
2800
+ //#region src/methods/is/is.ts
2801
+ /**
2802
+ * Checks if the input matches the schema. By using a type predicate, this
2803
+ * function can be used as a type guard.
2804
+ *
2805
+ * @param schema The schema to be used.
2806
+ * @param input The input to be tested.
2807
+ *
2808
+ * @returns Whether the input matches the schema.
2809
+ */
2810
+ /* @__NO_SIDE_EFFECTS__ */
2677
2811
  function is(schema, input) {
2678
- return !schema._run({ typed: false, value: input }, { abortEarly: true }).issues;
2812
+ return !schema["~run"]({ value: input }, { abortEarly: true }).issues;
2679
2813
  }
2680
2814
 
2681
- // src/schemas/array/array.ts
2682
- function array(item, message) {
2683
- return {
2684
- kind: "schema",
2685
- type: "array",
2686
- reference: array,
2687
- expects: "Array",
2688
- async: false,
2689
- item,
2690
- message,
2691
- _run(dataset, config2) {
2692
- const input = dataset.value;
2693
- if (Array.isArray(input)) {
2694
- dataset.typed = true;
2695
- dataset.value = [];
2696
- for (let key = 0; key < input.length; key++) {
2697
- const value2 = input[key];
2698
- const itemDataset = this.item._run({ typed: false, value: value2 }, config2);
2699
- if (itemDataset.issues) {
2700
- const pathItem = {
2701
- type: "array",
2702
- origin: "value",
2703
- input,
2704
- key,
2705
- value: value2
2706
- };
2707
- for (const issue of itemDataset.issues) {
2708
- if (issue.path) {
2709
- issue.path.unshift(pathItem);
2710
- } else {
2711
- issue.path = [pathItem];
2712
- }
2713
- dataset.issues?.push(issue);
2714
- }
2715
- if (!dataset.issues) {
2716
- dataset.issues = itemDataset.issues;
2717
- }
2718
- if (config2.abortEarly) {
2719
- dataset.typed = false;
2720
- break;
2721
- }
2722
- }
2723
- if (!itemDataset.typed) {
2724
- dataset.typed = false;
2725
- }
2726
- dataset.value.push(itemDataset.value);
2727
- }
2728
- } else {
2729
- _addIssue(this, "type", dataset, config2);
2730
- }
2731
- return dataset;
2732
- }
2733
- };
2815
+ //#endregion
2816
+ //#region src/schemas/array/array.ts
2817
+ /* @__NO_SIDE_EFFECTS__ */
2818
+ function array(item, message$1) {
2819
+ return {
2820
+ kind: "schema",
2821
+ type: "array",
2822
+ reference: array,
2823
+ expects: "Array",
2824
+ async: false,
2825
+ item,
2826
+ message: message$1,
2827
+ get "~standard"() {
2828
+ return /* @__PURE__ */ _getStandardProps(this);
2829
+ },
2830
+ "~run"(dataset, config$1) {
2831
+ const input = dataset.value;
2832
+ if (Array.isArray(input)) {
2833
+ dataset.typed = true;
2834
+ dataset.value = [];
2835
+ for (let key = 0; key < input.length; key++) {
2836
+ const value$1 = input[key];
2837
+ const itemDataset = this.item["~run"]({ value: value$1 }, config$1);
2838
+ if (itemDataset.issues) {
2839
+ const pathItem = {
2840
+ type: "array",
2841
+ origin: "value",
2842
+ input,
2843
+ key,
2844
+ value: value$1
2845
+ };
2846
+ for (const issue of itemDataset.issues) {
2847
+ if (issue.path) issue.path.unshift(pathItem);
2848
+ else issue.path = [pathItem];
2849
+ dataset.issues?.push(issue);
2850
+ }
2851
+ if (!dataset.issues) dataset.issues = itemDataset.issues;
2852
+ if (config$1.abortEarly) {
2853
+ dataset.typed = false;
2854
+ break;
2855
+ }
2856
+ }
2857
+ if (!itemDataset.typed) dataset.typed = false;
2858
+ dataset.value.push(itemDataset.value);
2859
+ }
2860
+ } else _addIssue(this, "type", dataset, config$1);
2861
+ return dataset;
2862
+ }
2863
+ };
2734
2864
  }
2735
2865
 
2736
- // src/schemas/bigint/bigint.ts
2737
- function bigint(message) {
2738
- return {
2739
- kind: "schema",
2740
- type: "bigint",
2741
- reference: bigint,
2742
- expects: "bigint",
2743
- async: false,
2744
- message,
2745
- _run(dataset, config2) {
2746
- if (typeof dataset.value === "bigint") {
2747
- dataset.typed = true;
2748
- } else {
2749
- _addIssue(this, "type", dataset, config2);
2750
- }
2751
- return dataset;
2752
- }
2753
- };
2866
+ //#endregion
2867
+ //#region src/schemas/bigint/bigint.ts
2868
+ /* @__NO_SIDE_EFFECTS__ */
2869
+ function bigint(message$1) {
2870
+ return {
2871
+ kind: "schema",
2872
+ type: "bigint",
2873
+ reference: bigint,
2874
+ expects: "bigint",
2875
+ async: false,
2876
+ message: message$1,
2877
+ get "~standard"() {
2878
+ return /* @__PURE__ */ _getStandardProps(this);
2879
+ },
2880
+ "~run"(dataset, config$1) {
2881
+ if (typeof dataset.value === "bigint") dataset.typed = true;
2882
+ else _addIssue(this, "type", dataset, config$1);
2883
+ return dataset;
2884
+ }
2885
+ };
2754
2886
  }
2755
2887
 
2756
- // src/schemas/boolean/boolean.ts
2757
- function boolean(message) {
2758
- return {
2759
- kind: "schema",
2760
- type: "boolean",
2761
- reference: boolean,
2762
- expects: "boolean",
2763
- async: false,
2764
- message,
2765
- _run(dataset, config2) {
2766
- if (typeof dataset.value === "boolean") {
2767
- dataset.typed = true;
2768
- } else {
2769
- _addIssue(this, "type", dataset, config2);
2770
- }
2771
- return dataset;
2772
- }
2773
- };
2888
+ //#endregion
2889
+ //#region src/schemas/boolean/boolean.ts
2890
+ /* @__NO_SIDE_EFFECTS__ */
2891
+ function boolean(message$1) {
2892
+ return {
2893
+ kind: "schema",
2894
+ type: "boolean",
2895
+ reference: boolean,
2896
+ expects: "boolean",
2897
+ async: false,
2898
+ message: message$1,
2899
+ get "~standard"() {
2900
+ return /* @__PURE__ */ _getStandardProps(this);
2901
+ },
2902
+ "~run"(dataset, config$1) {
2903
+ if (typeof dataset.value === "boolean") dataset.typed = true;
2904
+ else _addIssue(this, "type", dataset, config$1);
2905
+ return dataset;
2906
+ }
2907
+ };
2774
2908
  }
2775
2909
 
2776
- // src/schemas/lazy/lazy.ts
2910
+ //#endregion
2911
+ //#region src/schemas/lazy/lazy.ts
2912
+ /**
2913
+ * Creates a lazy schema.
2914
+ *
2915
+ * @param getter The schema getter.
2916
+ *
2917
+ * @returns A lazy schema.
2918
+ */
2919
+ /* @__NO_SIDE_EFFECTS__ */
2777
2920
  function lazy(getter) {
2778
- return {
2779
- kind: "schema",
2780
- type: "lazy",
2781
- reference: lazy,
2782
- expects: "unknown",
2783
- async: false,
2784
- getter,
2785
- _run(dataset, config2) {
2786
- return this.getter(dataset.value)._run(dataset, config2);
2787
- }
2788
- };
2921
+ return {
2922
+ kind: "schema",
2923
+ type: "lazy",
2924
+ reference: lazy,
2925
+ expects: "unknown",
2926
+ async: false,
2927
+ getter,
2928
+ get "~standard"() {
2929
+ return /* @__PURE__ */ _getStandardProps(this);
2930
+ },
2931
+ "~run"(dataset, config$1) {
2932
+ return this.getter(dataset.value)["~run"](dataset, config$1);
2933
+ }
2934
+ };
2789
2935
  }
2790
2936
 
2791
- // src/schemas/literal/literal.ts
2792
- function literal(literal_, message) {
2793
- return {
2794
- kind: "schema",
2795
- type: "literal",
2796
- reference: literal,
2797
- expects: _stringify(literal_),
2798
- async: false,
2799
- literal: literal_,
2800
- message,
2801
- _run(dataset, config2) {
2802
- if (dataset.value === this.literal) {
2803
- dataset.typed = true;
2804
- } else {
2805
- _addIssue(this, "type", dataset, config2);
2806
- }
2807
- return dataset;
2808
- }
2809
- };
2937
+ //#endregion
2938
+ //#region src/schemas/literal/literal.ts
2939
+ /* @__NO_SIDE_EFFECTS__ */
2940
+ function literal(literal_, message$1) {
2941
+ return {
2942
+ kind: "schema",
2943
+ type: "literal",
2944
+ reference: literal,
2945
+ expects: /* @__PURE__ */ _stringify(literal_),
2946
+ async: false,
2947
+ literal: literal_,
2948
+ message: message$1,
2949
+ get "~standard"() {
2950
+ return /* @__PURE__ */ _getStandardProps(this);
2951
+ },
2952
+ "~run"(dataset, config$1) {
2953
+ if (dataset.value === this.literal) dataset.typed = true;
2954
+ else _addIssue(this, "type", dataset, config$1);
2955
+ return dataset;
2956
+ }
2957
+ };
2810
2958
  }
2811
2959
 
2812
- // src/schemas/nullable/nullable.ts
2813
- function nullable(wrapped, ...args) {
2814
- const schema = {
2815
- kind: "schema",
2816
- type: "nullable",
2817
- reference: nullable,
2818
- expects: `${wrapped.expects} | null`,
2819
- async: false,
2820
- wrapped,
2821
- _run(dataset, config2) {
2822
- if (dataset.value === null) {
2823
- if ("default" in this) {
2824
- dataset.value = getDefault(
2825
- this,
2826
- dataset,
2827
- config2
2828
- );
2829
- }
2830
- if (dataset.value === null) {
2831
- dataset.typed = true;
2832
- return dataset;
2833
- }
2834
- }
2835
- return this.wrapped._run(dataset, config2);
2836
- }
2837
- };
2838
- if (0 in args) {
2839
- schema.default = args[0];
2840
- }
2841
- return schema;
2960
+ //#endregion
2961
+ //#region src/schemas/nullable/nullable.ts
2962
+ /* @__NO_SIDE_EFFECTS__ */
2963
+ function nullable(wrapped, default_) {
2964
+ return {
2965
+ kind: "schema",
2966
+ type: "nullable",
2967
+ reference: nullable,
2968
+ expects: `(${wrapped.expects} | null)`,
2969
+ async: false,
2970
+ wrapped,
2971
+ default: default_,
2972
+ get "~standard"() {
2973
+ return /* @__PURE__ */ _getStandardProps(this);
2974
+ },
2975
+ "~run"(dataset, config$1) {
2976
+ if (dataset.value === null) {
2977
+ if (this.default !== void 0) dataset.value = /* @__PURE__ */ getDefault(this, dataset, config$1);
2978
+ if (dataset.value === null) {
2979
+ dataset.typed = true;
2980
+ return dataset;
2981
+ }
2982
+ }
2983
+ return this.wrapped["~run"](dataset, config$1);
2984
+ }
2985
+ };
2842
2986
  }
2843
2987
 
2844
- // src/schemas/nullish/nullish.ts
2845
- function nullish(wrapped, ...args) {
2846
- const schema = {
2847
- kind: "schema",
2848
- type: "nullish",
2849
- reference: nullish,
2850
- expects: `${wrapped.expects} | null | undefined`,
2851
- async: false,
2852
- wrapped,
2853
- _run(dataset, config2) {
2854
- if (dataset.value === null || dataset.value === void 0) {
2855
- if ("default" in this) {
2856
- dataset.value = getDefault(
2857
- this,
2858
- dataset,
2859
- config2
2860
- );
2861
- }
2862
- if (dataset.value === null || dataset.value === void 0) {
2863
- dataset.typed = true;
2864
- return dataset;
2865
- }
2866
- }
2867
- return this.wrapped._run(dataset, config2);
2868
- }
2869
- };
2870
- if (0 in args) {
2871
- schema.default = args[0];
2872
- }
2873
- return schema;
2988
+ //#endregion
2989
+ //#region src/schemas/nullish/nullish.ts
2990
+ /* @__NO_SIDE_EFFECTS__ */
2991
+ function nullish(wrapped, default_) {
2992
+ return {
2993
+ kind: "schema",
2994
+ type: "nullish",
2995
+ reference: nullish,
2996
+ expects: `(${wrapped.expects} | null | undefined)`,
2997
+ async: false,
2998
+ wrapped,
2999
+ default: default_,
3000
+ get "~standard"() {
3001
+ return /* @__PURE__ */ _getStandardProps(this);
3002
+ },
3003
+ "~run"(dataset, config$1) {
3004
+ if (dataset.value === null || dataset.value === void 0) {
3005
+ if (this.default !== void 0) dataset.value = /* @__PURE__ */ getDefault(this, dataset, config$1);
3006
+ if (dataset.value === null || dataset.value === void 0) {
3007
+ dataset.typed = true;
3008
+ return dataset;
3009
+ }
3010
+ }
3011
+ return this.wrapped["~run"](dataset, config$1);
3012
+ }
3013
+ };
2874
3014
  }
2875
3015
 
2876
- // src/schemas/number/number.ts
2877
- function number(message) {
2878
- return {
2879
- kind: "schema",
2880
- type: "number",
2881
- reference: number,
2882
- expects: "number",
2883
- async: false,
2884
- message,
2885
- _run(dataset, config2) {
2886
- if (typeof dataset.value === "number" && !isNaN(dataset.value)) {
2887
- dataset.typed = true;
2888
- } else {
2889
- _addIssue(this, "type", dataset, config2);
2890
- }
2891
- return dataset;
2892
- }
2893
- };
3016
+ //#endregion
3017
+ //#region src/schemas/number/number.ts
3018
+ /* @__NO_SIDE_EFFECTS__ */
3019
+ function number(message$1) {
3020
+ return {
3021
+ kind: "schema",
3022
+ type: "number",
3023
+ reference: number,
3024
+ expects: "number",
3025
+ async: false,
3026
+ message: message$1,
3027
+ get "~standard"() {
3028
+ return /* @__PURE__ */ _getStandardProps(this);
3029
+ },
3030
+ "~run"(dataset, config$1) {
3031
+ if (typeof dataset.value === "number" && !isNaN(dataset.value)) dataset.typed = true;
3032
+ else _addIssue(this, "type", dataset, config$1);
3033
+ return dataset;
3034
+ }
3035
+ };
2894
3036
  }
2895
3037
 
2896
- // src/schemas/object/object.ts
2897
- function object(entries, message) {
2898
- return {
2899
- kind: "schema",
2900
- type: "object",
2901
- reference: object,
2902
- expects: "Object",
2903
- async: false,
2904
- entries,
2905
- message,
2906
- _run(dataset, config2) {
2907
- const input = dataset.value;
2908
- if (input && typeof input === "object") {
2909
- dataset.typed = true;
2910
- dataset.value = {};
2911
- for (const key in this.entries) {
2912
- const value2 = input[key];
2913
- const valueDataset = this.entries[key]._run(
2914
- { typed: false, value: value2 },
2915
- config2
2916
- );
2917
- if (valueDataset.issues) {
2918
- const pathItem = {
2919
- type: "object",
2920
- origin: "value",
2921
- input,
2922
- key,
2923
- value: value2
2924
- };
2925
- for (const issue of valueDataset.issues) {
2926
- if (issue.path) {
2927
- issue.path.unshift(pathItem);
2928
- } else {
2929
- issue.path = [pathItem];
2930
- }
2931
- dataset.issues?.push(issue);
2932
- }
2933
- if (!dataset.issues) {
2934
- dataset.issues = valueDataset.issues;
2935
- }
2936
- if (config2.abortEarly) {
2937
- dataset.typed = false;
2938
- break;
2939
- }
2940
- }
2941
- if (!valueDataset.typed) {
2942
- dataset.typed = false;
2943
- }
2944
- if (valueDataset.value !== void 0 || key in input) {
2945
- dataset.value[key] = valueDataset.value;
2946
- }
2947
- }
2948
- } else {
2949
- _addIssue(this, "type", dataset, config2);
2950
- }
2951
- return dataset;
2952
- }
2953
- };
3038
+ //#endregion
3039
+ //#region src/schemas/object/object.ts
3040
+ /* @__NO_SIDE_EFFECTS__ */
3041
+ function object(entries$1, message$1) {
3042
+ return {
3043
+ kind: "schema",
3044
+ type: "object",
3045
+ reference: object,
3046
+ expects: "Object",
3047
+ async: false,
3048
+ entries: entries$1,
3049
+ message: message$1,
3050
+ get "~standard"() {
3051
+ return /* @__PURE__ */ _getStandardProps(this);
3052
+ },
3053
+ "~run"(dataset, config$1) {
3054
+ const input = dataset.value;
3055
+ if (input && typeof input === "object") {
3056
+ dataset.typed = true;
3057
+ dataset.value = {};
3058
+ for (const key in this.entries) {
3059
+ const valueSchema = this.entries[key];
3060
+ if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) {
3061
+ const value$1 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);
3062
+ const valueDataset = valueSchema["~run"]({ value: value$1 }, config$1);
3063
+ if (valueDataset.issues) {
3064
+ const pathItem = {
3065
+ type: "object",
3066
+ origin: "value",
3067
+ input,
3068
+ key,
3069
+ value: value$1
3070
+ };
3071
+ for (const issue of valueDataset.issues) {
3072
+ if (issue.path) issue.path.unshift(pathItem);
3073
+ else issue.path = [pathItem];
3074
+ dataset.issues?.push(issue);
3075
+ }
3076
+ if (!dataset.issues) dataset.issues = valueDataset.issues;
3077
+ if (config$1.abortEarly) {
3078
+ dataset.typed = false;
3079
+ break;
3080
+ }
3081
+ }
3082
+ if (!valueDataset.typed) dataset.typed = false;
3083
+ dataset.value[key] = valueDataset.value;
3084
+ } else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
3085
+ else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
3086
+ _addIssue(this, "key", dataset, config$1, {
3087
+ input: void 0,
3088
+ expected: `"${key}"`,
3089
+ path: [{
3090
+ type: "object",
3091
+ origin: "key",
3092
+ input,
3093
+ key,
3094
+ value: input[key]
3095
+ }]
3096
+ });
3097
+ if (config$1.abortEarly) break;
3098
+ }
3099
+ }
3100
+ } else _addIssue(this, "type", dataset, config$1);
3101
+ return dataset;
3102
+ }
3103
+ };
2954
3104
  }
2955
3105
 
2956
- // src/schemas/optional/optional.ts
2957
- function optional(wrapped, ...args) {
2958
- const schema = {
2959
- kind: "schema",
2960
- type: "optional",
2961
- reference: optional,
2962
- expects: `${wrapped.expects} | undefined`,
2963
- async: false,
2964
- wrapped,
2965
- _run(dataset, config2) {
2966
- if (dataset.value === void 0) {
2967
- if ("default" in this) {
2968
- dataset.value = getDefault(
2969
- this,
2970
- dataset,
2971
- config2
2972
- );
2973
- }
2974
- if (dataset.value === void 0) {
2975
- dataset.typed = true;
2976
- return dataset;
2977
- }
2978
- }
2979
- return this.wrapped._run(dataset, config2);
2980
- }
2981
- };
2982
- if (0 in args) {
2983
- schema.default = args[0];
2984
- }
2985
- return schema;
3106
+ //#endregion
3107
+ //#region src/schemas/optional/optional.ts
3108
+ /* @__NO_SIDE_EFFECTS__ */
3109
+ function optional(wrapped, default_) {
3110
+ return {
3111
+ kind: "schema",
3112
+ type: "optional",
3113
+ reference: optional,
3114
+ expects: `(${wrapped.expects} | undefined)`,
3115
+ async: false,
3116
+ wrapped,
3117
+ default: default_,
3118
+ get "~standard"() {
3119
+ return /* @__PURE__ */ _getStandardProps(this);
3120
+ },
3121
+ "~run"(dataset, config$1) {
3122
+ if (dataset.value === void 0) {
3123
+ if (this.default !== void 0) dataset.value = /* @__PURE__ */ getDefault(this, dataset, config$1);
3124
+ if (dataset.value === void 0) {
3125
+ dataset.typed = true;
3126
+ return dataset;
3127
+ }
3128
+ }
3129
+ return this.wrapped["~run"](dataset, config$1);
3130
+ }
3131
+ };
2986
3132
  }
2987
3133
 
2988
- // src/schemas/record/record.ts
2989
- function record(key, value2, message) {
2990
- return {
2991
- kind: "schema",
2992
- type: "record",
2993
- reference: record,
2994
- expects: "Object",
2995
- async: false,
2996
- key,
2997
- value: value2,
2998
- message,
2999
- _run(dataset, config2) {
3000
- const input = dataset.value;
3001
- if (input && typeof input === "object") {
3002
- dataset.typed = true;
3003
- dataset.value = {};
3004
- for (const entryKey in input) {
3005
- if (_isValidObjectKey(input, entryKey)) {
3006
- const entryValue = input[entryKey];
3007
- const keyDataset = this.key._run(
3008
- { typed: false, value: entryKey },
3009
- config2
3010
- );
3011
- if (keyDataset.issues) {
3012
- const pathItem = {
3013
- type: "object",
3014
- origin: "key",
3015
- input,
3016
- key: entryKey,
3017
- value: entryValue
3018
- };
3019
- for (const issue of keyDataset.issues) {
3020
- issue.path = [pathItem];
3021
- dataset.issues?.push(issue);
3022
- }
3023
- if (!dataset.issues) {
3024
- dataset.issues = keyDataset.issues;
3025
- }
3026
- if (config2.abortEarly) {
3027
- dataset.typed = false;
3028
- break;
3029
- }
3030
- }
3031
- const valueDataset = this.value._run(
3032
- { typed: false, value: entryValue },
3033
- config2
3034
- );
3035
- if (valueDataset.issues) {
3036
- const pathItem = {
3037
- type: "object",
3038
- origin: "value",
3039
- input,
3040
- key: entryKey,
3041
- value: entryValue
3042
- };
3043
- for (const issue of valueDataset.issues) {
3044
- if (issue.path) {
3045
- issue.path.unshift(pathItem);
3046
- } else {
3047
- issue.path = [pathItem];
3048
- }
3049
- dataset.issues?.push(issue);
3050
- }
3051
- if (!dataset.issues) {
3052
- dataset.issues = valueDataset.issues;
3053
- }
3054
- if (config2.abortEarly) {
3055
- dataset.typed = false;
3056
- break;
3057
- }
3058
- }
3059
- if (!keyDataset.typed || !valueDataset.typed) {
3060
- dataset.typed = false;
3061
- }
3062
- if (keyDataset.typed) {
3063
- dataset.value[keyDataset.value] = valueDataset.value;
3064
- }
3065
- }
3066
- }
3067
- } else {
3068
- _addIssue(this, "type", dataset, config2);
3069
- }
3070
- return dataset;
3071
- }
3072
- };
3134
+ //#endregion
3135
+ //#region src/schemas/record/record.ts
3136
+ /* @__NO_SIDE_EFFECTS__ */
3137
+ function record(key, value$1, message$1) {
3138
+ return {
3139
+ kind: "schema",
3140
+ type: "record",
3141
+ reference: record,
3142
+ expects: "Object",
3143
+ async: false,
3144
+ key,
3145
+ value: value$1,
3146
+ message: message$1,
3147
+ get "~standard"() {
3148
+ return /* @__PURE__ */ _getStandardProps(this);
3149
+ },
3150
+ "~run"(dataset, config$1) {
3151
+ const input = dataset.value;
3152
+ if (input && typeof input === "object") {
3153
+ dataset.typed = true;
3154
+ dataset.value = {};
3155
+ for (const entryKey in input) if (/* @__PURE__ */ _isValidObjectKey(input, entryKey)) {
3156
+ const entryValue = input[entryKey];
3157
+ const keyDataset = this.key["~run"]({ value: entryKey }, config$1);
3158
+ if (keyDataset.issues) {
3159
+ const pathItem = {
3160
+ type: "object",
3161
+ origin: "key",
3162
+ input,
3163
+ key: entryKey,
3164
+ value: entryValue
3165
+ };
3166
+ for (const issue of keyDataset.issues) {
3167
+ issue.path = [pathItem];
3168
+ dataset.issues?.push(issue);
3169
+ }
3170
+ if (!dataset.issues) dataset.issues = keyDataset.issues;
3171
+ if (config$1.abortEarly) {
3172
+ dataset.typed = false;
3173
+ break;
3174
+ }
3175
+ }
3176
+ const valueDataset = this.value["~run"]({ value: entryValue }, config$1);
3177
+ if (valueDataset.issues) {
3178
+ const pathItem = {
3179
+ type: "object",
3180
+ origin: "value",
3181
+ input,
3182
+ key: entryKey,
3183
+ value: entryValue
3184
+ };
3185
+ for (const issue of valueDataset.issues) {
3186
+ if (issue.path) issue.path.unshift(pathItem);
3187
+ else issue.path = [pathItem];
3188
+ dataset.issues?.push(issue);
3189
+ }
3190
+ if (!dataset.issues) dataset.issues = valueDataset.issues;
3191
+ if (config$1.abortEarly) {
3192
+ dataset.typed = false;
3193
+ break;
3194
+ }
3195
+ }
3196
+ if (!keyDataset.typed || !valueDataset.typed) dataset.typed = false;
3197
+ if (keyDataset.typed) dataset.value[keyDataset.value] = valueDataset.value;
3198
+ }
3199
+ } else _addIssue(this, "type", dataset, config$1);
3200
+ return dataset;
3201
+ }
3202
+ };
3073
3203
  }
3074
3204
 
3075
- // src/schemas/string/string.ts
3076
- function string(message) {
3077
- return {
3078
- kind: "schema",
3079
- type: "string",
3080
- reference: string,
3081
- expects: "string",
3082
- async: false,
3083
- message,
3084
- _run(dataset, config2) {
3085
- if (typeof dataset.value === "string") {
3086
- dataset.typed = true;
3087
- } else {
3088
- _addIssue(this, "type", dataset, config2);
3089
- }
3090
- return dataset;
3091
- }
3092
- };
3205
+ //#endregion
3206
+ //#region src/schemas/string/string.ts
3207
+ /* @__NO_SIDE_EFFECTS__ */
3208
+ function string(message$1) {
3209
+ return {
3210
+ kind: "schema",
3211
+ type: "string",
3212
+ reference: string,
3213
+ expects: "string",
3214
+ async: false,
3215
+ message: message$1,
3216
+ get "~standard"() {
3217
+ return /* @__PURE__ */ _getStandardProps(this);
3218
+ },
3219
+ "~run"(dataset, config$1) {
3220
+ if (typeof dataset.value === "string") dataset.typed = true;
3221
+ else _addIssue(this, "type", dataset, config$1);
3222
+ return dataset;
3223
+ }
3224
+ };
3093
3225
  }
3094
3226
 
3095
- // src/schemas/tuple/tuple.ts
3096
- function tuple(items, message) {
3097
- return {
3098
- kind: "schema",
3099
- type: "tuple",
3100
- reference: tuple,
3101
- expects: "Array",
3102
- async: false,
3103
- items,
3104
- message,
3105
- _run(dataset, config2) {
3106
- const input = dataset.value;
3107
- if (Array.isArray(input)) {
3108
- dataset.typed = true;
3109
- dataset.value = [];
3110
- for (let key = 0; key < this.items.length; key++) {
3111
- const value2 = input[key];
3112
- const itemDataset = this.items[key]._run(
3113
- { typed: false, value: value2 },
3114
- config2
3115
- );
3116
- if (itemDataset.issues) {
3117
- const pathItem = {
3118
- type: "array",
3119
- origin: "value",
3120
- input,
3121
- key,
3122
- value: value2
3123
- };
3124
- for (const issue of itemDataset.issues) {
3125
- if (issue.path) {
3126
- issue.path.unshift(pathItem);
3127
- } else {
3128
- issue.path = [pathItem];
3129
- }
3130
- dataset.issues?.push(issue);
3131
- }
3132
- if (!dataset.issues) {
3133
- dataset.issues = itemDataset.issues;
3134
- }
3135
- if (config2.abortEarly) {
3136
- dataset.typed = false;
3137
- break;
3138
- }
3139
- }
3140
- if (!itemDataset.typed) {
3141
- dataset.typed = false;
3142
- }
3143
- dataset.value.push(itemDataset.value);
3144
- }
3145
- } else {
3146
- _addIssue(this, "type", dataset, config2);
3147
- }
3148
- return dataset;
3149
- }
3150
- };
3227
+ //#endregion
3228
+ //#region src/schemas/tuple/tuple.ts
3229
+ /* @__NO_SIDE_EFFECTS__ */
3230
+ function tuple(items, message$1) {
3231
+ return {
3232
+ kind: "schema",
3233
+ type: "tuple",
3234
+ reference: tuple,
3235
+ expects: "Array",
3236
+ async: false,
3237
+ items,
3238
+ message: message$1,
3239
+ get "~standard"() {
3240
+ return /* @__PURE__ */ _getStandardProps(this);
3241
+ },
3242
+ "~run"(dataset, config$1) {
3243
+ const input = dataset.value;
3244
+ if (Array.isArray(input)) {
3245
+ dataset.typed = true;
3246
+ dataset.value = [];
3247
+ for (let key = 0; key < this.items.length; key++) {
3248
+ const value$1 = input[key];
3249
+ const itemDataset = this.items[key]["~run"]({ value: value$1 }, config$1);
3250
+ if (itemDataset.issues) {
3251
+ const pathItem = {
3252
+ type: "array",
3253
+ origin: "value",
3254
+ input,
3255
+ key,
3256
+ value: value$1
3257
+ };
3258
+ for (const issue of itemDataset.issues) {
3259
+ if (issue.path) issue.path.unshift(pathItem);
3260
+ else issue.path = [pathItem];
3261
+ dataset.issues?.push(issue);
3262
+ }
3263
+ if (!dataset.issues) dataset.issues = itemDataset.issues;
3264
+ if (config$1.abortEarly) {
3265
+ dataset.typed = false;
3266
+ break;
3267
+ }
3268
+ }
3269
+ if (!itemDataset.typed) dataset.typed = false;
3270
+ dataset.value.push(itemDataset.value);
3271
+ }
3272
+ } else _addIssue(this, "type", dataset, config$1);
3273
+ return dataset;
3274
+ }
3275
+ };
3151
3276
  }
3152
3277
 
3153
- // src/schemas/union/utils/_subIssues/_subIssues.ts
3278
+ //#endregion
3279
+ //#region src/schemas/union/utils/_subIssues/_subIssues.ts
3280
+ /**
3281
+ * Returns the sub issues of the provided datasets for the union issue.
3282
+ *
3283
+ * @param datasets The datasets.
3284
+ *
3285
+ * @returns The sub issues.
3286
+ *
3287
+ * @internal
3288
+ */
3289
+ /* @__NO_SIDE_EFFECTS__ */
3154
3290
  function _subIssues(datasets) {
3155
- let issues;
3156
- if (datasets) {
3157
- for (const dataset of datasets) {
3158
- if (issues) {
3159
- issues.push(...dataset.issues);
3160
- } else {
3161
- issues = dataset.issues;
3162
- }
3163
- }
3164
- }
3165
- return issues;
3291
+ let issues;
3292
+ if (datasets) for (const dataset of datasets) if (issues) issues.push(...dataset.issues);
3293
+ else issues = dataset.issues;
3294
+ return issues;
3166
3295
  }
3167
3296
 
3168
- // src/schemas/union/union.ts
3169
- function union(options, message) {
3170
- return {
3171
- kind: "schema",
3172
- type: "union",
3173
- reference: union,
3174
- expects: [...new Set(options.map((option) => option.expects))].join(" | ") || "never",
3175
- async: false,
3176
- options,
3177
- message,
3178
- _run(dataset, config2) {
3179
- let validDataset;
3180
- let typedDatasets;
3181
- let untypedDatasets;
3182
- for (const schema of this.options) {
3183
- const optionDataset = schema._run(
3184
- { typed: false, value: dataset.value },
3185
- config2
3186
- );
3187
- if (optionDataset.typed) {
3188
- if (optionDataset.issues) {
3189
- if (typedDatasets) {
3190
- typedDatasets.push(optionDataset);
3191
- } else {
3192
- typedDatasets = [optionDataset];
3193
- }
3194
- } else {
3195
- validDataset = optionDataset;
3196
- break;
3197
- }
3198
- } else {
3199
- if (untypedDatasets) {
3200
- untypedDatasets.push(optionDataset);
3201
- } else {
3202
- untypedDatasets = [optionDataset];
3203
- }
3204
- }
3205
- }
3206
- if (validDataset) {
3207
- return validDataset;
3208
- }
3209
- if (typedDatasets) {
3210
- if (typedDatasets.length === 1) {
3211
- return typedDatasets[0];
3212
- }
3213
- _addIssue(this, "type", dataset, config2, {
3214
- issues: _subIssues(typedDatasets)
3215
- });
3216
- dataset.typed = true;
3217
- } else if (untypedDatasets?.length === 1) {
3218
- return untypedDatasets[0];
3219
- } else {
3220
- _addIssue(this, "type", dataset, config2, {
3221
- issues: _subIssues(untypedDatasets)
3222
- });
3223
- }
3224
- return dataset;
3225
- }
3226
- };
3297
+ //#endregion
3298
+ //#region src/schemas/union/union.ts
3299
+ /* @__NO_SIDE_EFFECTS__ */
3300
+ function union(options, message$1) {
3301
+ return {
3302
+ kind: "schema",
3303
+ type: "union",
3304
+ reference: union,
3305
+ expects: /* @__PURE__ */ _joinExpects(options.map((option) => option.expects), "|"),
3306
+ async: false,
3307
+ options,
3308
+ message: message$1,
3309
+ get "~standard"() {
3310
+ return /* @__PURE__ */ _getStandardProps(this);
3311
+ },
3312
+ "~run"(dataset, config$1) {
3313
+ let validDataset;
3314
+ let typedDatasets;
3315
+ let untypedDatasets;
3316
+ for (const schema of this.options) {
3317
+ const optionDataset = schema["~run"]({ value: dataset.value }, config$1);
3318
+ if (optionDataset.typed) if (optionDataset.issues) if (typedDatasets) typedDatasets.push(optionDataset);
3319
+ else typedDatasets = [optionDataset];
3320
+ else {
3321
+ validDataset = optionDataset;
3322
+ break;
3323
+ }
3324
+ else if (untypedDatasets) untypedDatasets.push(optionDataset);
3325
+ else untypedDatasets = [optionDataset];
3326
+ }
3327
+ if (validDataset) return validDataset;
3328
+ if (typedDatasets) {
3329
+ if (typedDatasets.length === 1) return typedDatasets[0];
3330
+ _addIssue(this, "type", dataset, config$1, { issues: /* @__PURE__ */ _subIssues(typedDatasets) });
3331
+ dataset.typed = true;
3332
+ } else if (untypedDatasets?.length === 1) return untypedDatasets[0];
3333
+ else _addIssue(this, "type", dataset, config$1, { issues: /* @__PURE__ */ _subIssues(untypedDatasets) });
3334
+ return dataset;
3335
+ }
3336
+ };
3227
3337
  }
3228
3338
 
3229
- // src/schemas/unknown/unknown.ts
3339
+ //#endregion
3340
+ //#region src/schemas/unknown/unknown.ts
3341
+ /**
3342
+ * Creates a unknown schema.
3343
+ *
3344
+ * @returns A unknown schema.
3345
+ */
3346
+ /* @__NO_SIDE_EFFECTS__ */
3230
3347
  function unknown() {
3231
- return {
3232
- kind: "schema",
3233
- type: "unknown",
3234
- reference: unknown,
3235
- expects: "unknown",
3236
- async: false,
3237
- _run(dataset) {
3238
- dataset.typed = true;
3239
- return dataset;
3240
- }
3241
- };
3348
+ return {
3349
+ kind: "schema",
3350
+ type: "unknown",
3351
+ reference: unknown,
3352
+ expects: "unknown",
3353
+ async: false,
3354
+ get "~standard"() {
3355
+ return /* @__PURE__ */ _getStandardProps(this);
3356
+ },
3357
+ "~run"(dataset) {
3358
+ dataset.typed = true;
3359
+ return dataset;
3360
+ }
3361
+ };
3242
3362
  }
3243
3363
 
3244
- // src/methods/parse/parse.ts
3245
- function parse(schema, input, config2) {
3246
- const dataset = schema._run(
3247
- { typed: false, value: input },
3248
- getGlobalConfig(config2)
3249
- );
3250
- if (dataset.issues) {
3251
- throw new ValiError(dataset.issues);
3252
- }
3253
- return dataset.value;
3364
+ //#endregion
3365
+ //#region src/methods/parse/parse.ts
3366
+ /**
3367
+ * Parses an unknown input based on a schema.
3368
+ *
3369
+ * @param schema The schema to be used.
3370
+ * @param input The input to be parsed.
3371
+ * @param config The parse configuration.
3372
+ *
3373
+ * @returns The parsed input.
3374
+ */
3375
+ function parse(schema, input, config$1) {
3376
+ const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config$1));
3377
+ if (dataset.issues) throw new ValiError(dataset.issues);
3378
+ return dataset.value;
3254
3379
  }
3255
3380
 
3256
- // src/methods/pipe/pipe.ts
3257
- function pipe(...pipe2) {
3258
- return {
3259
- ...pipe2[0],
3260
- pipe: pipe2,
3261
- _run(dataset, config2) {
3262
- for (let index = 0; index < pipe2.length; index++) {
3263
- if (dataset.issues && (pipe2[index].kind === "schema" || pipe2[index].kind === "transformation")) {
3264
- dataset.typed = false;
3265
- break;
3266
- }
3267
- if (!dataset.issues || !config2.abortEarly && !config2.abortPipeEarly) {
3268
- dataset = pipe2[index]._run(dataset, config2);
3269
- }
3270
- }
3271
- return dataset;
3272
- }
3273
- };
3381
+ //#endregion
3382
+ //#region src/methods/pipe/pipe.ts
3383
+ /* @__NO_SIDE_EFFECTS__ */
3384
+ function pipe(...pipe$1) {
3385
+ return {
3386
+ ...pipe$1[0],
3387
+ pipe: pipe$1,
3388
+ get "~standard"() {
3389
+ return /* @__PURE__ */ _getStandardProps(this);
3390
+ },
3391
+ "~run"(dataset, config$1) {
3392
+ for (const item of pipe$1) if (item.kind !== "metadata") {
3393
+ if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) {
3394
+ dataset.typed = false;
3395
+ break;
3396
+ }
3397
+ if (!dataset.issues || !config$1.abortEarly && !config$1.abortPipeEarly) dataset = item["~run"](dataset, config$1);
3398
+ }
3399
+ return dataset;
3400
+ }
3401
+ };
3274
3402
  }
3275
3403
 
3276
3404
  const SUI_NS_NAME_REGEX = /^(?!.*(^(?!@)|[-.@])($|[-.@]))(?:[a-z0-9-]{0,63}(?:\.[a-z0-9-]{0,63})*)?@[a-z0-9-]{0,63}$/i;
@@ -3389,10 +3517,12 @@ function safeEnum(options) {
3389
3517
  const unionOptions = Object.entries(options).map(([key, value]) => object({ [key]: value }));
3390
3518
  return pipe(
3391
3519
  union(unionOptions),
3392
- transform((value) => ({
3393
- ...value,
3394
- $kind: Object.keys(value)[0]
3395
- }))
3520
+ transform(
3521
+ (value) => ({
3522
+ ...value,
3523
+ $kind: Object.keys(value)[0]
3524
+ })
3525
+ )
3396
3526
  );
3397
3527
  }
3398
3528
  const SuiAddress = pipe(
@@ -5017,7 +5147,7 @@ function asciiToBase16(ch) {
5017
5147
  * Convert hex string to byte array. Uses built-in function, when available.
5018
5148
  * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
5019
5149
  */
5020
- function hexToBytes(hex) {
5150
+ function hexToBytes$1(hex) {
5021
5151
  if (typeof hex !== 'string')
5022
5152
  throw new Error('hex string expected, got ' + typeof hex);
5023
5153
  // @ts-ignore
@@ -7678,6 +7808,7 @@ runPlugins_fn = async function(plugins, options) {
7678
7808
  } finally {
7679
7809
  __privateSet$4(this, _inputSection, __privateGet$4(this, _data$1).inputs.slice());
7680
7810
  __privateSet$4(this, _commandSection, __privateGet$4(this, _data$1).commands.slice());
7811
+ __privateSet$4(this, _availableResults, new Set(__privateGet$4(this, _commandSection).map((_, i) => i)));
7681
7812
  }
7682
7813
  };
7683
7814
  waitForPendingTasks_fn = async function() {
@@ -9498,6 +9629,322 @@ class HttpClient {
9498
9629
  }
9499
9630
  }
9500
9631
 
9632
+ // Copyright (c) 2025 Dipcoin LLC
9633
+ // SPDX-License-Identifier: Apache-2.0
9634
+ function computeOrderFlag(order) {
9635
+ let flag = 0;
9636
+ if (order.ioc)
9637
+ flag += 1;
9638
+ if (order.postOnly)
9639
+ flag += 2;
9640
+ if (order.reduceOnly)
9641
+ flag += 4;
9642
+ if (order.isLong)
9643
+ flag += 8;
9644
+ if (order.orderbookOnly)
9645
+ flag += 16;
9646
+ return flag;
9647
+ }
9648
+ function packPayload(fields) {
9649
+ let result = "{\n";
9650
+ for (const [key, value] of fields) {
9651
+ result += `"${key}":"${value}",\n`;
9652
+ }
9653
+ result += '"domain":"dipcoin.io"\n';
9654
+ result += "}";
9655
+ return result;
9656
+ }
9657
+ function getOrderMessageForUIWallet(order) {
9658
+ const flag = computeOrderFlag(order);
9659
+ const fields = [
9660
+ ["market", `${order.market}`],
9661
+ ["creator", `${order.creator}`],
9662
+ ["isLong", `${order.isLong}`],
9663
+ ["reduceOnly", `${order.reduceOnly}`],
9664
+ ["postOnly", `${order.postOnly}`],
9665
+ ["orderbookOnly", `${order.orderbookOnly}`],
9666
+ ["ioc", `${order.ioc || false}`],
9667
+ ["quantity", `${order.quantity.toFixed(0)}`],
9668
+ ["price", `${order.price.toFixed(0)}`],
9669
+ ["leverage", `${order.leverage.toFixed(0)}`],
9670
+ ["expiration", `${order.expiration.toFixed(0)}`],
9671
+ ["salt", `${order.salt.toFixed(0)}`],
9672
+ ["orderFlag", `${flag}`],
9673
+ ];
9674
+ return packPayload(fields);
9675
+ }
9676
+
9677
+ // Copyright (c) 2025 Dipcoin LLC
9678
+ const CLOCK_OBJECT_ID = "0x6";
9679
+ // ---------------------------------------------------------------------------
9680
+ // Deployment config helpers
9681
+ // ---------------------------------------------------------------------------
9682
+ function getPackageId(deployment) {
9683
+ const pkgs = deployment?.packages;
9684
+ if (!pkgs || !pkgs.length)
9685
+ throw new Error("Deployment config missing packages array");
9686
+ return pkgs[pkgs.length - 1];
9687
+ }
9688
+ function getProtocolConfigId(deployment) {
9689
+ const id = deployment?.objects?.ProtocolConfig?.id;
9690
+ if (!id)
9691
+ throw new Error("Deployment config missing ProtocolConfig id");
9692
+ return id;
9693
+ }
9694
+ function getBankId(deployment) {
9695
+ const id = deployment?.objects?.Bank?.id;
9696
+ if (!id)
9697
+ throw new Error("Deployment config missing Bank id");
9698
+ return id;
9699
+ }
9700
+ function getSubAccountsId(deployment) {
9701
+ const id = deployment?.objects?.SubAccounts?.id;
9702
+ if (!id)
9703
+ throw new Error("Deployment config missing SubAccounts id");
9704
+ return id;
9705
+ }
9706
+ function getTxIndexerId(deployment) {
9707
+ const id = deployment?.objects?.TxIndexer?.id;
9708
+ if (!id)
9709
+ throw new Error("Deployment config missing TxIndexer id");
9710
+ return id;
9711
+ }
9712
+ function getCurrencyType(deployment) {
9713
+ const dt = deployment?.objects?.Currency?.dataType;
9714
+ if (!dt)
9715
+ throw new Error("Deployment config missing Currency dataType");
9716
+ return dt;
9717
+ }
9718
+ function getPerpetualId(deployment, market) {
9719
+ const m = market?.toUpperCase();
9720
+ const id = deployment?.markets?.[m]?.Objects?.Perpetual?.id;
9721
+ if (!id)
9722
+ throw new Error(`Deployment config missing Perpetual id for ${m}`);
9723
+ return id;
9724
+ }
9725
+ function getPriceOracleObjectId(deployment, market) {
9726
+ const m = market?.toUpperCase() || "ETH-PERP";
9727
+ const id = deployment?.markets?.[m]?.Objects?.PriceInfoObject?.id;
9728
+ if (!id)
9729
+ throw new Error(`Deployment config missing PriceInfoObject id for ${m}`);
9730
+ return id;
9731
+ }
9732
+ function getPriceOracleFeedId(deployment, market) {
9733
+ const m = market?.toUpperCase() || "ETH-PERP";
9734
+ const feedId = deployment?.markets?.[m]?.Config?.priceInfoFeedId;
9735
+ if (!feedId)
9736
+ throw new Error(`Deployment config missing priceInfoFeedId for ${m}`);
9737
+ return feedId;
9738
+ }
9739
+ function getPythPkgId(deployment, market) {
9740
+ const m = market?.toUpperCase() || "ETH-PERP";
9741
+ const dataType = deployment?.markets?.[m]?.Objects?.PriceInfoObject?.dataType;
9742
+ if (!dataType)
9743
+ throw new Error(`Deployment config missing PriceInfoObject dataType for ${m}`);
9744
+ return dataType.split("::")[0];
9745
+ }
9746
+ function hexToBytes(hex) {
9747
+ const h = hex.startsWith("0x") ? hex.slice(2) : hex;
9748
+ const bytes = [];
9749
+ for (let i = 0; i < h.length; i += 2) {
9750
+ bytes.push(parseInt(h.substr(i, 2), 16));
9751
+ }
9752
+ return bytes;
9753
+ }
9754
+ function toBigIntStr(value, decimals) {
9755
+ // Equivalent to library's J(value, decimals) → multiply by 10^decimals and return integer string
9756
+ const factor = Math.pow(10, decimals);
9757
+ return Math.round(value * factor).toString();
9758
+ }
9759
+ // ---------------------------------------------------------------------------
9760
+ // Transaction builders
9761
+ // ---------------------------------------------------------------------------
9762
+ function buildAddMarginTx(deployment, args, tx, gasBudget, sender) {
9763
+ const t = tx || new transactions.Transaction();
9764
+ if (gasBudget)
9765
+ t.setGasBudget(gasBudget);
9766
+ if (sender)
9767
+ t.setSender(sender);
9768
+ const packageId = getPackageId(deployment);
9769
+ t.moveCall({
9770
+ target: `${packageId}::exchange::add_margin_v2`,
9771
+ arguments: [
9772
+ t.object(getProtocolConfigId(deployment)),
9773
+ t.object(CLOCK_OBJECT_ID),
9774
+ t.object(args.perpID || getPerpetualId(deployment, args.market)),
9775
+ t.object(getBankId(deployment)),
9776
+ t.object(args.subAccountsMapID || getSubAccountsId(deployment)),
9777
+ t.object(getTxIndexerId(deployment)),
9778
+ t.object(getPriceOracleObjectId(deployment, args.market)),
9779
+ t.pure.address(args.account || sender || ""),
9780
+ t.pure.u128(args.amount.toString()),
9781
+ ],
9782
+ typeArguments: [getCurrencyType(deployment)],
9783
+ });
9784
+ return t;
9785
+ }
9786
+ function buildRemoveMarginTx(deployment, args, tx, gasBudget, sender) {
9787
+ const t = tx || new transactions.Transaction();
9788
+ if (gasBudget)
9789
+ t.setGasBudget(gasBudget);
9790
+ if (sender)
9791
+ t.setSender(sender);
9792
+ const packageId = getPackageId(deployment);
9793
+ t.moveCall({
9794
+ target: `${packageId}::exchange::remove_margin_v2`,
9795
+ arguments: [
9796
+ t.object(getProtocolConfigId(deployment)),
9797
+ t.object(CLOCK_OBJECT_ID),
9798
+ t.object(args.perpID || getPerpetualId(deployment, args.market)),
9799
+ t.object(getBankId(deployment)),
9800
+ t.object(args.subAccountsMapID || getSubAccountsId(deployment)),
9801
+ t.object(getTxIndexerId(deployment)),
9802
+ t.object(getPriceOracleObjectId(deployment, args.market)),
9803
+ t.pure.address(args.account || sender || ""),
9804
+ t.pure.u128(args.amount.toString()),
9805
+ ],
9806
+ typeArguments: [getCurrencyType(deployment)],
9807
+ });
9808
+ return t;
9809
+ }
9810
+ function buildDepositTx(deployment, args, tx, gasBudget, sender) {
9811
+ const t = tx || new transactions.Transaction();
9812
+ if (gasBudget)
9813
+ t.setGasBudget(gasBudget);
9814
+ if (sender)
9815
+ t.setSender(sender);
9816
+ // The library uses a coin-splitting intent for deposit.
9817
+ // We replicate the same Move call structure: bank::deposit_v2
9818
+ // with a SplitCoins + the amount.
9819
+ const coinType = getCurrencyType(deployment);
9820
+ const coin = t.splitCoins(t.gas, [BigInt(args.amount)]);
9821
+ const packageId = getPackageId(deployment);
9822
+ t.moveCall({
9823
+ target: `${packageId}::bank::deposit_v2`,
9824
+ arguments: [
9825
+ t.object(getProtocolConfigId(deployment)),
9826
+ t.object(args.bankID || getBankId(deployment)),
9827
+ t.object(getTxIndexerId(deployment)),
9828
+ t.pure.address(args.accountAddress || sender || ""),
9829
+ t.pure.u64(args.amount),
9830
+ coin,
9831
+ ],
9832
+ typeArguments: [coinType],
9833
+ });
9834
+ return t;
9835
+ }
9836
+ function buildWithdrawTx(deployment, args, tx, gasBudget, sender) {
9837
+ const t = tx || new transactions.Transaction();
9838
+ if (gasBudget)
9839
+ t.setGasBudget(gasBudget);
9840
+ if (sender)
9841
+ t.setSender(sender);
9842
+ const packageId = getPackageId(deployment);
9843
+ t.moveCall({
9844
+ target: `${packageId}::bank::withdraw_v2`,
9845
+ arguments: [
9846
+ t.object(getProtocolConfigId(deployment)),
9847
+ t.object(args.bankID || getBankId(deployment)),
9848
+ t.object(getTxIndexerId(deployment)),
9849
+ t.pure.address(args.accountAddress || sender || ""),
9850
+ t.pure.u128(args.amount),
9851
+ ],
9852
+ typeArguments: [getCurrencyType(deployment)],
9853
+ });
9854
+ return t;
9855
+ }
9856
+ function buildSetSubAccountTx(deployment, args, tx, gasBudget, sender) {
9857
+ const t = tx || new transactions.Transaction();
9858
+ if (gasBudget)
9859
+ t.setGasBudget(gasBudget);
9860
+ if (sender)
9861
+ t.setSender(sender);
9862
+ const packageId = getPackageId(deployment);
9863
+ t.moveCall({
9864
+ target: `${packageId}::sub_accounts::set_sub_account`,
9865
+ arguments: [
9866
+ t.object(getProtocolConfigId(deployment)),
9867
+ t.object(args.subAccountsMapID || getSubAccountsId(deployment)),
9868
+ t.pure.address(args.account),
9869
+ t.pure.bool(args.status),
9870
+ ],
9871
+ typeArguments: [],
9872
+ });
9873
+ return t;
9874
+ }
9875
+ function buildSetOraclePriceTx(deployment, args, tx, gasBudget, sender) {
9876
+ const t = tx || new transactions.Transaction();
9877
+ if (gasBudget)
9878
+ t.setGasBudget(gasBudget);
9879
+ if (sender)
9880
+ t.setSender(sender);
9881
+ const pythPkgId = getPythPkgId(deployment, args.market);
9882
+ const oracleObjId = getPriceOracleObjectId(deployment, args.market);
9883
+ const feedIdHex = getPriceOracleFeedId(deployment, args.market);
9884
+ const feedIdBytes = hexToBytes(feedIdHex);
9885
+ const priceU64 = toBigIntStr(args.price, 6);
9886
+ t.moveCall({
9887
+ target: `${pythPkgId}::price_info::update_price_info_object_for_test`,
9888
+ arguments: [
9889
+ t.object(oracleObjId),
9890
+ t.object(CLOCK_OBJECT_ID),
9891
+ t.pure.u64(priceU64),
9892
+ t.pure.u64(args.confidence || "10"),
9893
+ t.pure(suiBcs.vector(suiBcs.u8()).serialize(new Uint8Array(feedIdBytes))),
9894
+ ],
9895
+ typeArguments: [],
9896
+ });
9897
+ return t;
9898
+ }
9899
+ function buildBatchSetOraclePriceTx(deployment, args, tx, gasBudget, sender) {
9900
+ let t = tx || new transactions.Transaction();
9901
+ for (const priceArgs of args.prices) {
9902
+ t = buildSetOraclePriceTx(deployment, priceArgs, t, undefined, undefined);
9903
+ }
9904
+ if (gasBudget)
9905
+ t.setGasBudget(gasBudget);
9906
+ if (sender)
9907
+ t.setSender(sender);
9908
+ return t;
9909
+ }
9910
+
9911
+ // Copyright (c) 2025 Dipcoin LLC
9912
+ async function executeTxBlock(suiClient, tx, signer) {
9913
+ return suiClient.signAndExecuteTransaction({
9914
+ signer,
9915
+ transaction: tx,
9916
+ options: {
9917
+ showObjectChanges: true,
9918
+ showEffects: true,
9919
+ showEvents: true,
9920
+ showInput: true,
9921
+ },
9922
+ });
9923
+ }
9924
+ function getDeploymentPerpetualID(deployment, market) {
9925
+ return getPerpetualId(deployment, market);
9926
+ }
9927
+ async function getOraclePrice(suiClient, deployment, market) {
9928
+ const objId = getPriceOracleObjectId(deployment, market);
9929
+ const obj = await suiClient.getObject({ id: objId, options: { showContent: true } });
9930
+ const fields = obj.data?.content?.fields?.price_info?.fields?.price_feed?.fields?.price?.fields;
9931
+ if (!fields)
9932
+ throw new Error(`Failed to read oracle price for ${market}`);
9933
+ return Number(fields.price.fields.magnitude) / Math.pow(10, Number(fields.expo.fields.magnitude));
9934
+ }
9935
+ async function depositToBank(suiClient, deployment, args, signer) {
9936
+ const tx = buildDepositTx(deployment, args, undefined, args.gasBudget, signer.getPublicKey().toSuiAddress());
9937
+ return executeTxBlock(suiClient, tx, signer);
9938
+ }
9939
+ async function withdrawFromBank(suiClient, deployment, args, signer) {
9940
+ const tx = buildWithdrawTx(deployment, args, undefined, args.gasBudget, signer.getPublicKey().toSuiAddress());
9941
+ return executeTxBlock(suiClient, tx, signer);
9942
+ }
9943
+ async function setSubAccount(suiClient, deployment, args, signer) {
9944
+ const tx = buildSetSubAccountTx(deployment, args, undefined, args.gasBudget, signer.getPublicKey().toSuiAddress());
9945
+ return executeTxBlock(suiClient, tx, signer);
9946
+ }
9947
+
9501
9948
  // Copyright (c) 2025 Dipcoin LLC
9502
9949
  // SPDX-License-Identifier: Apache-2.0
9503
9950
  /**
@@ -9935,7 +10382,7 @@ function bytesToNumberLE(bytes) {
9935
10382
  return hexToNumber(bytesToHex(Uint8Array.from(bytes).reverse()));
9936
10383
  }
9937
10384
  function numberToBytesBE(n, len) {
9938
- return hexToBytes(n.toString(16).padStart(len * 2, '0'));
10385
+ return hexToBytes$1(n.toString(16).padStart(len * 2, '0'));
9939
10386
  }
9940
10387
  function numberToBytesLE(n, len) {
9941
10388
  return numberToBytesBE(n, len).reverse();
@@ -9953,7 +10400,7 @@ function ensureBytes(title, hex, expectedLength) {
9953
10400
  let res;
9954
10401
  if (typeof hex === 'string') {
9955
10402
  try {
9956
- res = hexToBytes(hex);
10403
+ res = hexToBytes$1(hex);
9957
10404
  }
9958
10405
  catch (e) {
9959
10406
  throw new Error(title + ' must be hex string or Uint8Array, cause: ' + e);
@@ -11699,7 +12146,7 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
11699
12146
  throw new Error('invalid format');
11700
12147
  }
11701
12148
  static fromHex(hex, format) {
11702
- return this.fromBytes(hexToBytes(hex), format);
12149
+ return this.fromBytes(hexToBytes$1(hex), format);
11703
12150
  }
11704
12151
  addRecoveryBit(recovery) {
11705
12152
  return new Signature(this.r, this.s, recovery);
@@ -11748,7 +12195,7 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
11748
12195
  if (format === 'compact')
11749
12196
  return concatBytes(Fn.toBytes(this.r), Fn.toBytes(this.s));
11750
12197
  if (format === 'der')
11751
- return hexToBytes(DER.hexFromSig(this));
12198
+ return hexToBytes$1(DER.hexFromSig(this));
11752
12199
  throw new Error('invalid format');
11753
12200
  }
11754
12201
  toHex(format) {
@@ -12381,7 +12828,7 @@ function bytesToNumber(bytes) {
12381
12828
  function numberToBytes(num) {
12382
12829
  if (typeof num !== 'bigint')
12383
12830
  throw new Error('bigint expected');
12384
- return hexToBytes(num.toString(16).padStart(64, '0'));
12831
+ return hexToBytes$1(num.toString(16).padStart(64, '0'));
12385
12832
  }
12386
12833
  const MASTER_SECRET = utf8ToBytes('Bitcoin seed');
12387
12834
  // Bitcoin hardcoded by default
@@ -15324,7 +15771,7 @@ function findFirstNonZeroIndex(bytes) {
15324
15771
  }
15325
15772
  function toPaddedBigEndianBytes(num, width) {
15326
15773
  const hex = num.toString(16);
15327
- return hexToBytes(hex.padStart(width * 2, "0").slice(-width * 2));
15774
+ return hexToBytes$1(hex.padStart(width * 2, "0").slice(-width * 2));
15328
15775
  }
15329
15776
  function toBigEndianBytes(num, width) {
15330
15777
  const bytes = toPaddedBigEndianBytes(num, width);
@@ -16607,10 +17054,8 @@ class DipCoinPerpSDK {
16607
17054
  subJwtToken;
16608
17055
  isAuthenticating = false;
16609
17056
  isSubAuthenticating = false;
16610
- exchangeOnChain;
16611
17057
  deploymentConfig;
16612
17058
  suiClient;
16613
- transactionBuilder;
16614
17059
  priceServiceConnection;
16615
17060
  pythClient;
16616
17061
  tradingPairsCache;
@@ -16646,10 +17091,6 @@ class DipCoinPerpSDK {
16646
17091
  this.deploymentConfig = readFile(`config/deployed/${options.network}/main_contract.json`);
16647
17092
  const rpcUrl = options.customRpc || getFullnodeUrl(options.network);
16648
17093
  this.suiClient = new SuiJsonRpcClient({ url: rpcUrl });
16649
- this.exchangeOnChain = new perpTsLibrary.ExchangeOnChain(this.deploymentConfig, this.suiClient, this.keypair);
16650
- const packageId = this.getDeploymentPackageId();
16651
- const protocolConfigId = this.getDeploymentProtocolConfigId();
16652
- this.transactionBuilder = new perpTsLibrary.TransactionBuilder(packageId, protocolConfigId, this.deploymentConfig, this.suiClient);
16653
17094
  }
16654
17095
  /**
16655
17096
  * Get wallet address
@@ -16923,21 +17364,21 @@ class DipCoinPerpSDK {
16923
17364
  };
16924
17365
  }
16925
17366
  // Generate order message for signing
16926
- const orderMsg = perpTsLibrary.OrderSigner.getOrderMessageForUIWallet(order);
17367
+ const orderMsg = getOrderMessageForUIWallet(order);
16927
17368
  const orderHashBytes = new TextEncoder().encode(orderMsg);
16928
17369
  // Sign main order
16929
17370
  const orderSignature = await signMessage(signingKeypair, orderHashBytes);
16930
17371
  // Sign TP order if exists
16931
17372
  let tpOrderSignature;
16932
17373
  if (tpOrder) {
16933
- const tpOrderMsg = perpTsLibrary.OrderSigner.getOrderMessageForUIWallet(tpOrder);
17374
+ const tpOrderMsg = getOrderMessageForUIWallet(tpOrder);
16934
17375
  const tpOrderHashBytes = new TextEncoder().encode(tpOrderMsg);
16935
17376
  tpOrderSignature = await signMessage(signingKeypair, tpOrderHashBytes);
16936
17377
  }
16937
17378
  // Sign SL order if exists
16938
17379
  let slOrderSignature;
16939
17380
  if (slOrder) {
16940
- const slOrderMsg = perpTsLibrary.OrderSigner.getOrderMessageForUIWallet(slOrder);
17381
+ const slOrderMsg = getOrderMessageForUIWallet(slOrder);
16941
17382
  const slOrderHashBytes = new TextEncoder().encode(slOrderMsg);
16942
17383
  slOrderSignature = await signMessage(signingKeypair, slOrderHashBytes);
16943
17384
  }
@@ -17325,7 +17766,7 @@ class DipCoinPerpSDK {
17325
17766
  expiration: expirationBN,
17326
17767
  salt: tpSaltValue,
17327
17768
  };
17328
- const tpOrderMsg = perpTsLibrary.OrderSigner.getOrderMessageForUIWallet(tpOrder);
17769
+ const tpOrderMsg = getOrderMessageForUIWallet(tpOrder);
17329
17770
  const tpOrderSignature = await signMessage(signingKeypair, new TextEncoder().encode(tpOrderMsg));
17330
17771
  tpPayload = {
17331
17772
  ...planPayloadBase,
@@ -17370,7 +17811,7 @@ class DipCoinPerpSDK {
17370
17811
  expiration: expirationBN,
17371
17812
  salt: slSaltValue,
17372
17813
  };
17373
- const slOrderMsg = perpTsLibrary.OrderSigner.getOrderMessageForUIWallet(slOrder);
17814
+ const slOrderMsg = getOrderMessageForUIWallet(slOrder);
17374
17815
  const slOrderSignature = await signMessage(signingKeypair, new TextEncoder().encode(slOrderMsg));
17375
17816
  slPayload = {
17376
17817
  ...planPayloadBase,
@@ -18251,10 +18692,11 @@ class DipCoinPerpSDK {
18251
18692
  async addMargin(params) {
18252
18693
  const transaction = await this.buildMarginTransaction(params, "add");
18253
18694
  if (transaction) {
18254
- return this.exchangeOnChain.executeTxBlock(transaction, this.keypair);
18695
+ return executeTxBlock(this.suiClient, transaction, this.keypair);
18255
18696
  }
18256
18697
  const fallbackPayload = this.buildMarginCallArgs(params, "add");
18257
- return this.exchangeOnChain.addMargin(fallbackPayload);
18698
+ const tx = buildAddMarginTx(this.deploymentConfig, fallbackPayload, undefined, fallbackPayload.gasBudget, this.keypair.getPublicKey().toSuiAddress());
18699
+ return executeTxBlock(this.suiClient, tx, this.keypair);
18258
18700
  }
18259
18701
  /**
18260
18702
  * Remove isolated margin from an existing position (on-chain)
@@ -18263,10 +18705,11 @@ class DipCoinPerpSDK {
18263
18705
  async removeMargin(params) {
18264
18706
  const transaction = await this.buildMarginTransaction(params, "remove");
18265
18707
  if (transaction) {
18266
- return this.exchangeOnChain.executeTxBlock(transaction, this.keypair);
18708
+ return executeTxBlock(this.suiClient, transaction, this.keypair);
18267
18709
  }
18268
18710
  const fallbackPayload = this.buildMarginCallArgs(params, "remove");
18269
- return this.exchangeOnChain.removeMargin(fallbackPayload);
18711
+ const tx = buildRemoveMarginTx(this.deploymentConfig, fallbackPayload, undefined, fallbackPayload.gasBudget, this.keypair.getPublicKey().toSuiAddress());
18712
+ return executeTxBlock(this.suiClient, tx, this.keypair);
18270
18713
  }
18271
18714
  /**
18272
18715
  * Build ExchangeOnChain call args for margin adjustments
@@ -18296,13 +18739,6 @@ class DipCoinPerpSDK {
18296
18739
  txHash,
18297
18740
  };
18298
18741
  }
18299
- getDeploymentPackageId() {
18300
- const packages = this.deploymentConfig?.packages;
18301
- if (!packages || !packages.length) {
18302
- throw new Error("Deployment config missing packages array");
18303
- }
18304
- return packages[packages.length - 1];
18305
- }
18306
18742
  getDeploymentProtocolConfigId() {
18307
18743
  const protocolId = this.deploymentConfig?.objects?.ProtocolConfig?.id;
18308
18744
  if (!protocolId) {
@@ -18311,18 +18747,15 @@ class DipCoinPerpSDK {
18311
18747
  return protocolId;
18312
18748
  }
18313
18749
  async buildMarginTransaction(params, action) {
18314
- if (!this.transactionBuilder) {
18315
- return undefined;
18316
- }
18317
18750
  const payload = this.buildMarginCallArgs(params, action);
18318
18751
  const updatePriceTx = payload.market
18319
18752
  ? await this.buildUpdatePriceTransaction(payload.market)
18320
18753
  : undefined;
18321
18754
  const baseTx = updatePriceTx || new transactions.Transaction();
18322
18755
  if (action === "add") {
18323
- return this.transactionBuilder.exchange_addMarginTx(payload, baseTx, params.gasBudget);
18756
+ return buildAddMarginTx(this.deploymentConfig, payload, baseTx, params.gasBudget);
18324
18757
  }
18325
- return this.transactionBuilder.exchange_removeMarginTx(payload, baseTx, params.gasBudget);
18758
+ return buildRemoveMarginTx(this.deploymentConfig, payload, baseTx, params.gasBudget);
18326
18759
  }
18327
18760
  async buildUpdatePriceTransaction(symbol) {
18328
18761
  if (!symbol) {
@@ -18365,11 +18798,11 @@ class DipCoinPerpSDK {
18365
18798
  }
18366
18799
  async buildTestnetPriceUpdateTransaction(symbol) {
18367
18800
  try {
18368
- const oraclePrice = await this.exchangeOnChain.getOraclePrice(symbol);
18801
+ const oraclePrice = await getOraclePrice(this.suiClient, this.deploymentConfig, symbol);
18369
18802
  if (oraclePrice === undefined || oraclePrice === null) {
18370
18803
  return undefined;
18371
18804
  }
18372
- return this.transactionBuilder.price_info_setOraclePriceTx({
18805
+ return buildSetOraclePriceTx(this.deploymentConfig, {
18373
18806
  price: Number(oraclePrice),
18374
18807
  market: symbol,
18375
18808
  });
@@ -18464,7 +18897,7 @@ class DipCoinPerpSDK {
18464
18897
  */
18465
18898
  resolvePerpIdFromDeployment(market) {
18466
18899
  try {
18467
- const perpId = this.exchangeOnChain.getPerpetualID(market);
18900
+ const perpId = getDeploymentPerpetualID(this.deploymentConfig, market);
18468
18901
  return perpId || undefined;
18469
18902
  }
18470
18903
  catch (error) {
@@ -18478,7 +18911,7 @@ class DipCoinPerpSDK {
18478
18911
  * @returns On-chain transaction result
18479
18912
  */
18480
18913
  async setSubAccount(subAddress) {
18481
- return await this.exchangeOnChain.setSubAccount({
18914
+ return await setSubAccount(this.suiClient, this.deploymentConfig, {
18482
18915
  account: subAddress,
18483
18916
  status: true,
18484
18917
  }, this.keypair);
@@ -18494,7 +18927,7 @@ class DipCoinPerpSDK {
18494
18927
  * ```
18495
18928
  */
18496
18929
  async depositToBank(amount) {
18497
- return await this.exchangeOnChain.depositToBank({
18930
+ return await depositToBank(this.suiClient, this.deploymentConfig, {
18498
18931
  amount: formatNormalToWei(amount, DECIMALS.USDC),
18499
18932
  accountAddress: this.address,
18500
18933
  }, this.keypair);
@@ -18510,7 +18943,7 @@ class DipCoinPerpSDK {
18510
18943
  * ```
18511
18944
  */
18512
18945
  async withdrawFromBank(amount) {
18513
- return await this.exchangeOnChain.withdrawFromBank({
18946
+ return await withdrawFromBank(this.suiClient, this.deploymentConfig, {
18514
18947
  amount: formatNormalToWei(amount, DECIMALS.USDC),
18515
18948
  accountAddress: this.address,
18516
18949
  }, this.keypair);
@@ -18610,11 +19043,11 @@ class DipCoinPerpSDK {
18610
19043
  const currencyType = this.getCurrencyType();
18611
19044
  const symbols = markets && markets.length > 0 ? markets : this.getMarketSymbols();
18612
19045
  // On testnet, prepend price oracle updates so PriceInfoObjects are fresh
18613
- if (this.options.network === "testnet" && this.transactionBuilder) {
19046
+ if (this.options.network === "testnet") {
18614
19047
  const prices = [];
18615
19048
  for (const sym of symbols) {
18616
19049
  try {
18617
- const oraclePrice = await this.exchangeOnChain.getOraclePrice(sym);
19050
+ const oraclePrice = await getOraclePrice(this.suiClient, this.deploymentConfig, sym);
18618
19051
  if (oraclePrice !== undefined && oraclePrice !== null) {
18619
19052
  prices.push({ price: Number(oraclePrice), market: sym });
18620
19053
  }
@@ -18624,7 +19057,7 @@ class DipCoinPerpSDK {
18624
19057
  }
18625
19058
  }
18626
19059
  if (prices.length > 0) {
18627
- this.transactionBuilder.price_info_batchSetOraclePriceTx({ prices }, t);
19060
+ buildBatchSetOraclePriceTx(this.deploymentConfig, { prices }, t);
18628
19061
  }
18629
19062
  }
18630
19063
  const [nav] = t.moveCall({
@@ -20189,11 +20622,27 @@ function registerBalanceCommand(program) {
20189
20622
  });
20190
20623
  }
20191
20624
 
20625
+ function getPackageVersion() {
20626
+ try {
20627
+ // Works in both ESM and CJS after bundling
20628
+ const pkgPath = path.resolve(path.dirname(url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT' && document.currentScript.src || new URL('cli.cjs', document.baseURI).href)))), "../package.json");
20629
+ return JSON.parse(fs.readFileSync(pkgPath, "utf-8")).version;
20630
+ }
20631
+ catch {
20632
+ try {
20633
+ // Fallback: resolve from cwd
20634
+ return JSON.parse(fs.readFileSync(path.resolve(process.cwd(), "package.json"), "utf-8")).version;
20635
+ }
20636
+ catch {
20637
+ return "0.0.0";
20638
+ }
20639
+ }
20640
+ }
20192
20641
  const program = new commander.Command();
20193
20642
  program
20194
20643
  .name("dipcoin-cli")
20195
20644
  .description("DipCoin Perpetual Trading CLI")
20196
- .version("0.5.0")
20645
+ .version(getPackageVersion())
20197
20646
  .option("--json", "Output in JSON format")
20198
20647
  .option("--vault-index <n>", "Vault index (1+ for HD-derived sub-accounts)");
20199
20648
  registerAccountCommands(program);