@0xobelisk/client 0.0.1 → 0.0.3

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/obelisk.d.ts CHANGED
@@ -1,21 +1,27 @@
1
- /**
2
- * @file src.ts
3
- * @description This file is used to aggregate the tools that used to interact with SUI network.
4
- * @author IceFox
5
- * @version 0.1.0
6
- */
7
- import { RawSigner, TransactionBlock, DevInspectResults, SuiTransactionBlockResponse, JsonRpcProvider } from '@mysten/sui.js';
1
+ import { RawSigner, TransactionBlock, DevInspectResults, SuiTransactionBlockResponse, SuiMoveNormalizedModules } from '@mysten/sui.js';
8
2
  import { SuiAccountManager } from './libs/suiAccountManager';
9
3
  import { SuiRpcProvider } from './libs/suiRpcProvider';
10
4
  import { SuiTxBlock } from './libs/suiTxBuilder';
11
- import { SuiKitParams, DerivePathParams, SuiTxArg, SuiVecTxArg } from './types';
5
+ import { SuiContractFactory } from './libs/suiContractFactory';
6
+ import { SuiMoveMoudleFuncType } from './libs/suiContractFactory/types';
7
+ import { ObeliskParams, DerivePathParams, SuiTxArg, SuiVecTxArg, MapMoudleFuncQuery, MapMoudleFuncTx } from './types';
8
+ export declare function isUndefined(value?: unknown): value is undefined;
9
+ export declare function withMeta<T extends {
10
+ meta: SuiMoveMoudleFuncType;
11
+ }>(meta: SuiMoveMoudleFuncType, creator: Omit<T, 'meta'>): T;
12
12
  /**
13
- * @class SuiKit
13
+ * @class Obelisk
14
14
  * @description This class is used to aggregate the tools that used to interact with SUI network.
15
15
  */
16
16
  export declare class Obelisk {
17
+ #private;
17
18
  accountManager: SuiAccountManager;
18
19
  rpcProvider: SuiRpcProvider;
20
+ contractFactory: SuiContractFactory;
21
+ packageId: string | undefined;
22
+ metadata: SuiMoveNormalizedModules;
23
+ epsId: string;
24
+ componentsId: string;
19
25
  /**
20
26
  * Support the following ways to init the SuiToolkit:
21
27
  * 1. mnemonics
@@ -27,8 +33,11 @@ export declare class Obelisk {
27
33
  * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
28
34
  * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type
29
35
  * @param faucetUrl, the faucet url, default is the preconfig faucet url for the given network type
36
+ * @param packageId
30
37
  */
31
- constructor({ mnemonics, secretKey, networkType, fullnodeUrl, faucetUrl, }?: SuiKitParams);
38
+ constructor({ mnemonics, secretKey, networkType, fullnodeUrl, faucetUrl, packageId, metadata }?: ObeliskParams);
39
+ get query(): MapMoudleFuncQuery;
40
+ get tx(): MapMoudleFuncTx;
32
41
  /**
33
42
  * if derivePathParams is not provided or mnemonics is empty, it will return the currentSigner.
34
43
  * else:
@@ -47,7 +56,41 @@ export declare class Obelisk {
47
56
  */
48
57
  getAddress(derivePathParams?: DerivePathParams): string;
49
58
  currentAddress(): string;
50
- provider(): JsonRpcProvider;
59
+ provider(): import("@mysten/sui.js").JsonRpcProvider;
60
+ getPackageId(): string;
61
+ getMetadata(): Record<string, {
62
+ address: string;
63
+ name: string;
64
+ fileFormatVersion: number;
65
+ friends: {
66
+ address: string;
67
+ name: string;
68
+ }[];
69
+ structs: Record<string, {
70
+ fields: {
71
+ type: import("@mysten/sui.js").SuiMoveNormalizedType;
72
+ name: string;
73
+ }[];
74
+ abilities: {
75
+ abilities: string[];
76
+ };
77
+ typeParameters: {
78
+ constraints: {
79
+ abilities: string[];
80
+ };
81
+ isPhantom: boolean;
82
+ }[];
83
+ }>;
84
+ exposedFunctions: Record<string, {
85
+ visibility: "Private" | "Public" | "Friend";
86
+ isEntry: boolean;
87
+ typeParameters: {
88
+ abilities: string[];
89
+ }[];
90
+ parameters: import("@mysten/sui.js").SuiMoveNormalizedType[];
91
+ return: import("@mysten/sui.js").SuiMoveNormalizedType[];
92
+ }>;
93
+ }> | undefined;
51
94
  /**
52
95
  * Request some SUI from faucet
53
96
  * @Returns {Promise<boolean>}, true if the request is successful, false otherwise.
@@ -62,6 +105,7 @@ export declare class Obelisk {
62
105
  epochId?: number | undefined;
63
106
  };
64
107
  }>;
108
+ getObject(objectId: string): Promise<import("./libs/suiRpcProvider/types").ObjectData>;
65
109
  getObjects(objectIds: string[]): Promise<import("./libs/suiRpcProvider/types").ObjectData[]>;
66
110
  signTxn(tx: Uint8Array | TransactionBlock | SuiTxBlock, derivePathParams?: DerivePathParams): Promise<import("@mysten/sui.js").SignedTransaction>;
67
111
  signAndSendTxn(tx: Uint8Array | TransactionBlock | SuiTxBlock, derivePathParams?: DerivePathParams): Promise<SuiTransactionBlockResponse>;
@@ -2511,147 +2555,8 @@ export declare class Obelisk {
2511
2555
  * @returns the effects and events of the transaction, such as object changes, gas cost, event emitted.
2512
2556
  */
2513
2557
  inspectTxn(tx: Uint8Array | TransactionBlock | SuiTxBlock, derivePathParams?: DerivePathParams): Promise<DevInspectResults>;
2514
- call(world_id: string, system_name: string, counter: any, derivePathParams?: DerivePathParams): Promise<{
2515
- digest: string;
2516
- timestampMs?: string | undefined;
2517
- transaction?: {
2518
- data: {
2519
- sender: string;
2520
- messageVersion: "v1";
2521
- transaction: {
2522
- epoch: string;
2523
- storage_charge: string;
2524
- computation_charge: string;
2525
- storage_rebate: string;
2526
- kind: "ChangeEpoch";
2527
- epoch_start_timestamp_ms?: string | undefined;
2528
- } | {
2529
- epoch: string;
2530
- round: string;
2531
- commit_timestamp_ms: string;
2532
- kind: "ConsensusCommitPrologue";
2533
- } | {
2534
- objects: string[];
2535
- kind: "Genesis";
2536
- } | {
2537
- transactions: ({
2538
- MoveCall: {
2539
- function: string;
2540
- package: string;
2541
- module: string;
2542
- arguments?: ("GasCoin" | {
2543
- Input: number;
2544
- } | {
2545
- Result: number;
2546
- } | {
2547
- NestedResult: [number, number];
2548
- })[] | undefined;
2549
- type_arguments?: string[] | undefined;
2550
- };
2551
- } | {
2552
- TransferObjects: [("GasCoin" | {
2553
- Input: number;
2554
- } | {
2555
- Result: number;
2556
- } | {
2557
- NestedResult: [number, number];
2558
- })[], "GasCoin" | {
2559
- Input: number;
2560
- } | {
2561
- Result: number;
2562
- } | {
2563
- NestedResult: [number, number];
2564
- }];
2565
- } | {
2566
- SplitCoins: ["GasCoin" | {
2567
- Input: number;
2568
- } | {
2569
- Result: number;
2570
- } | {
2571
- NestedResult: [number, number];
2572
- }, ("GasCoin" | {
2573
- Input: number;
2574
- } | {
2575
- Result: number;
2576
- } | {
2577
- NestedResult: [number, number];
2578
- })[]];
2579
- } | {
2580
- MergeCoins: ["GasCoin" | {
2581
- Input: number;
2582
- } | {
2583
- Result: number;
2584
- } | {
2585
- NestedResult: [number, number];
2586
- }, ("GasCoin" | {
2587
- Input: number;
2588
- } | {
2589
- Result: number;
2590
- } | {
2591
- NestedResult: [number, number];
2592
- })[]];
2593
- } | {
2594
- Publish: string[] | [{
2595
- disassembled: Record<string, string>;
2596
- }, string[]];
2597
- } | {
2598
- Upgrade: [string[], string, "GasCoin" | {
2599
- Input: number;
2600
- } | {
2601
- Result: number;
2602
- } | {
2603
- NestedResult: [number, number];
2604
- }] | [{
2605
- disassembled: Record<string, string>;
2606
- }, string[], string, "GasCoin" | {
2607
- Input: number;
2608
- } | {
2609
- Result: number;
2610
- } | {
2611
- NestedResult: [number, number];
2612
- }];
2613
- } | {
2614
- MakeMoveVec: [string | null, ("GasCoin" | {
2615
- Input: number;
2616
- } | {
2617
- Result: number;
2618
- } | {
2619
- NestedResult: [number, number];
2620
- })[]];
2621
- })[];
2622
- inputs: ({
2623
- type: "pure";
2624
- valueType: string | null;
2625
- value: import("@mysten/sui.js").SuiJsonValue;
2626
- } | {
2627
- type: "object";
2628
- objectType: "immOrOwnedObject";
2629
- objectId: string;
2630
- version: string;
2631
- digest: string;
2632
- } | {
2633
- type: "object";
2634
- objectType: "sharedObject";
2635
- objectId: string;
2636
- initialSharedVersion: string;
2637
- mutable: boolean;
2638
- })[];
2639
- kind: "ProgrammableTransaction";
2640
- };
2641
- gasData: {
2642
- payment: {
2643
- objectId: string;
2644
- version: string | number;
2645
- digest: string;
2646
- }[];
2647
- owner: string;
2648
- price: string;
2649
- budget: string;
2650
- };
2651
- };
2652
- txSignatures: string[];
2653
- } | undefined;
2654
- effects?: {
2558
+ getBirthTime(objectId: string, derivePathParams?: DerivePathParams): Promise<{
2559
+ effects: {
2655
2560
  messageVersion: "v1";
2656
2561
  status: {
2657
2562
  status: "success" | "failure";
@@ -2755,8 +2660,8 @@ export declare class Obelisk {
2755
2660
  }[] | undefined;
2756
2661
  eventsDigest?: string | undefined;
2757
2662
  dependencies?: string[] | undefined;
2758
- } | undefined;
2759
- events?: {
2663
+ };
2664
+ events: {
2760
2665
  id: {
2761
2666
  txDigest: string;
2762
2667
  eventSeq: string;
@@ -2768,39 +2673,54 @@ export declare class Obelisk {
2768
2673
  parsedJson?: Record<string, any> | undefined;
2769
2674
  bcs?: string | undefined;
2770
2675
  timestampMs?: string | undefined;
2676
+ }[];
2677
+ error?: string | undefined;
2678
+ results?: {
2679
+ mutableReferenceOutputs?: ["GasCoin" | {
2680
+ Input: number;
2681
+ } | {
2682
+ Result: number;
2683
+ } | {
2684
+ NestedResult: [number, number];
2685
+ }, number[], string][] | undefined;
2686
+ returnValues?: [number[], string][] | undefined;
2771
2687
  }[] | undefined;
2772
- checkpoint?: string | undefined;
2773
- confirmedLocalExecution?: boolean | undefined;
2774
- objectChanges?: ({
2775
- packageId: string;
2776
- type: "published";
2777
- version: string;
2778
- digest: string;
2779
- modules: string[];
2780
- } | {
2781
- sender: string;
2782
- type: "transferred";
2688
+ }>;
2689
+ getWorld(worldObjectId: string): Promise<import("./libs/suiRpcProvider/types").ObjectData>;
2690
+ getAllEntities(worldId: string, cursor?: string, limit?: number): Promise<{
2691
+ data: {
2692
+ type: "DynamicField" | "DynamicObject";
2783
2693
  objectType: string;
2784
2694
  objectId: string;
2785
- version: string;
2695
+ version: number;
2786
2696
  digest: string;
2787
- recipient: "Immutable" | {
2788
- AddressOwner: string;
2789
- } | {
2790
- ObjectOwner: string;
2791
- } | {
2792
- Shared: {
2793
- initial_shared_version: number;
2794
- };
2795
- };
2796
- } | {
2797
- sender: string;
2798
- type: "mutated";
2799
- objectType: string;
2697
+ name: {
2698
+ type: string;
2699
+ value?: any;
2700
+ };
2701
+ bcsName: string;
2702
+ }[];
2703
+ nextCursor: string | null;
2704
+ hasNextPage: boolean;
2705
+ }>;
2706
+ getEntity(worldId: string, entityId: string): Promise<{
2707
+ data?: {
2800
2708
  objectId: string;
2801
2709
  version: string;
2802
2710
  digest: string;
2803
- owner: "Immutable" | {
2711
+ type?: string | undefined;
2712
+ bcs?: {
2713
+ type: string;
2714
+ version: number;
2715
+ hasPublicTransfer: boolean;
2716
+ dataType: "moveObject";
2717
+ bcsBytes: string;
2718
+ } | {
2719
+ id: string;
2720
+ dataType: "package";
2721
+ moduleMap: Record<string, string>;
2722
+ } | undefined;
2723
+ owner?: {
2804
2724
  AddressOwner: string;
2805
2725
  } | {
2806
2726
  ObjectOwner: string;
@@ -2808,39 +2728,73 @@ export declare class Obelisk {
2808
2728
  Shared: {
2809
2729
  initial_shared_version: number;
2810
2730
  };
2811
- };
2812
- previousVersion: string;
2813
- } | {
2814
- sender: string;
2815
- type: "deleted";
2816
- objectType: string;
2817
- objectId: string;
2818
- version: string;
2819
- } | {
2820
- sender: string;
2821
- type: "wrapped";
2731
+ } | "Immutable" | undefined;
2732
+ storageRebate?: string | undefined;
2733
+ previousTransaction?: string | undefined;
2734
+ content?: {
2735
+ type: string;
2736
+ fields: Record<string, any>;
2737
+ hasPublicTransfer: boolean;
2738
+ dataType: "moveObject";
2739
+ } | {
2740
+ disassembled: Record<string, string>;
2741
+ dataType: "package";
2742
+ } | undefined;
2743
+ display?: Record<string, string> | {
2744
+ data: Record<string, string> | null;
2745
+ error: {
2746
+ code: string;
2747
+ version?: number | undefined;
2748
+ digest?: string | undefined;
2749
+ error?: string | undefined;
2750
+ object_id?: string | undefined;
2751
+ parent_object_id?: string | undefined;
2752
+ } | null;
2753
+ } | undefined;
2754
+ } | undefined;
2755
+ error?: {
2756
+ code: string;
2757
+ version?: number | undefined;
2758
+ digest?: string | undefined;
2759
+ error?: string | undefined;
2760
+ object_id?: string | undefined;
2761
+ parent_object_id?: string | undefined;
2762
+ } | undefined;
2763
+ }>;
2764
+ getEntityComponents(worldId: string, entityId: string, cursor?: string, limit?: number): Promise<{
2765
+ data: {
2766
+ type: "DynamicField" | "DynamicObject";
2822
2767
  objectType: string;
2823
2768
  objectId: string;
2824
- version: string;
2825
- } | {
2826
- sender: string;
2827
- type: "created";
2828
- objectType: string;
2769
+ version: number;
2770
+ digest: string;
2771
+ name: {
2772
+ type: string;
2773
+ value?: any;
2774
+ };
2775
+ bcsName: string;
2776
+ }[];
2777
+ nextCursor: string | null;
2778
+ hasNextPage: boolean;
2779
+ }>;
2780
+ getEntityComponent(entityId: string, componentId: string): Promise<{
2781
+ data?: {
2829
2782
  objectId: string;
2830
2783
  version: string;
2831
2784
  digest: string;
2832
- owner: "Immutable" | {
2833
- AddressOwner: string;
2834
- } | {
2835
- ObjectOwner: string;
2836
- } | {
2837
- Shared: {
2838
- initial_shared_version: number;
2839
- };
2840
- };
2841
- })[] | undefined;
2842
- balanceChanges?: {
2843
- owner: "Immutable" | {
2785
+ type?: string | undefined;
2786
+ bcs?: {
2787
+ type: string;
2788
+ version: number;
2789
+ hasPublicTransfer: boolean;
2790
+ dataType: "moveObject";
2791
+ bcsBytes: string;
2792
+ } | {
2793
+ id: string;
2794
+ dataType: "package";
2795
+ moduleMap: Record<string, string>;
2796
+ } | undefined;
2797
+ owner?: {
2844
2798
  AddressOwner: string;
2845
2799
  } | {
2846
2800
  ObjectOwner: string;
@@ -2848,10 +2802,37 @@ export declare class Obelisk {
2848
2802
  Shared: {
2849
2803
  initial_shared_version: number;
2850
2804
  };
2851
- };
2852
- coinType: string;
2853
- amount: string;
2854
- }[] | undefined;
2855
- errors?: string[] | undefined;
2805
+ } | "Immutable" | undefined;
2806
+ storageRebate?: string | undefined;
2807
+ previousTransaction?: string | undefined;
2808
+ content?: {
2809
+ type: string;
2810
+ fields: Record<string, any>;
2811
+ hasPublicTransfer: boolean;
2812
+ dataType: "moveObject";
2813
+ } | {
2814
+ disassembled: Record<string, string>;
2815
+ dataType: "package";
2816
+ } | undefined;
2817
+ display?: Record<string, string> | {
2818
+ data: Record<string, string> | null;
2819
+ error: {
2820
+ code: string;
2821
+ version?: number | undefined;
2822
+ digest?: string | undefined;
2823
+ error?: string | undefined;
2824
+ object_id?: string | undefined;
2825
+ parent_object_id?: string | undefined;
2826
+ } | null;
2827
+ } | undefined;
2828
+ } | undefined;
2829
+ error?: {
2830
+ code: string;
2831
+ version?: number | undefined;
2832
+ digest?: string | undefined;
2833
+ error?: string | undefined;
2834
+ object_id?: string | undefined;
2835
+ parent_object_id?: string | undefined;
2836
+ } | undefined;
2856
2837
  }>;
2857
2838
  }
@@ -1,11 +1,72 @@
1
+ import { SuiMoveNormalizedModules, DevInspectResults, SuiTransactionBlockResponse, TransactionBlock } from "@mysten/sui.js";
1
2
  import type { NetworkType as SuiNetworkType } from '../libs/suiRpcProvider/types';
2
3
  export type { DerivePathParams } from '../libs/suiAccountManager/types';
4
+ import { SuiMoveMoudleFuncType } from '../libs/suiContractFactory/types';
3
5
  export type { SuiTxArg, SuiVecTxArg, SuiObjectArg, } from '../libs/suiTxBuilder/types';
4
6
  export type NetworkType = SuiNetworkType;
5
- export type SuiKitParams = {
7
+ export type ObeliskParams = {
6
8
  mnemonics?: string;
7
9
  secretKey?: string;
8
10
  fullnodeUrl?: string;
9
11
  faucetUrl?: string;
10
12
  networkType?: NetworkType;
13
+ packageId?: string;
14
+ metadata?: SuiMoveNormalizedModules;
11
15
  };
16
+ export type ComponentFieldType = {
17
+ components: {
18
+ type: string;
19
+ fields: {
20
+ id: {
21
+ id: string;
22
+ };
23
+ size: string;
24
+ };
25
+ };
26
+ };
27
+ export type ComponentValueType = {
28
+ id: {
29
+ id: string;
30
+ };
31
+ name: string;
32
+ value: {
33
+ type: string;
34
+ fields: ComponentFieldType;
35
+ };
36
+ };
37
+ export type SuiTxArgument = {
38
+ kind: "Input";
39
+ index: number;
40
+ type?: "object" | "pure" | undefined;
41
+ value?: any;
42
+ } | {
43
+ kind: "GasCoin";
44
+ } | {
45
+ kind: "Result";
46
+ index: number;
47
+ } | {
48
+ kind: "NestedResult";
49
+ index: number;
50
+ resultIndex: number;
51
+ };
52
+ export type ComponentContentType = {
53
+ type: string;
54
+ fields: ComponentValueType;
55
+ hasPublicTransfer: boolean;
56
+ dataType: "moveObject";
57
+ };
58
+ export interface MessageMeta {
59
+ readonly meta: SuiMoveMoudleFuncType;
60
+ }
61
+ export interface ContractQuery extends MessageMeta {
62
+ (tx: TransactionBlock, params: SuiTxArgument[]): Promise<DevInspectResults>;
63
+ }
64
+ export interface ContractTx extends MessageMeta {
65
+ (tx: TransactionBlock, params: SuiTxArgument[], isRaw: boolean): SuiTransactionBlockResponse | TransactionBlock;
66
+ }
67
+ export type MapMessageTx = Record<string, ContractTx>;
68
+ export type MapMessageQuery = Record<string, ContractQuery>;
69
+ export type MapMoudleFuncTx = Record<string, MapMessageTx>;
70
+ export type MapMoudleFuncQuery = Record<string, MapMessageQuery>;
71
+ export type MapMoudleFuncTest = Record<string, Record<string, string>>;
72
+ export type MapMoudleFuncQueryTest = Record<string, Record<string, string>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xobelisk/client",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Tookit for interacting with move eps framework",
5
5
  "keywords": [
6
6
  "sui",
@@ -50,15 +50,18 @@
50
50
  "test:watch": "vitest",
51
51
  "format:fix": "prettier --ignore-path 'dist/* docs/*' --write '**/*.{ts,json,md}'",
52
52
  "lint:fix": "eslint . --ignore-pattern dist --ext .ts --fix",
53
- "prepare": "husky install",
54
53
  "commit": "commit",
55
54
  "doc": "typedoc --out docs src/index.ts"
56
55
  },
57
56
  "dependencies": {
57
+ "@mysten/bcs": "^0.7.3",
58
58
  "@mysten/sui.js": "^0.37.1",
59
59
  "@scure/bip39": "^1.2.1",
60
60
  "assert": "^2.0.0",
61
61
  "colorts": "^0.1.63",
62
+ "fs": "^0.0.1-security",
63
+ "husky": "^8.0.3",
64
+ "process": "^0.11.10",
62
65
  "superstruct": "^1.0.3",
63
66
  "tmp": "^0.2.1",
64
67
  "ts-retry-promise": "^0.7.0"
@@ -70,19 +73,18 @@
70
73
  "@commitlint/cli": "^17.6.6",
71
74
  "@commitlint/config-conventional": "^17.6.6",
72
75
  "@commitlint/prompt-cli": "^17.6.6",
73
- "@types/node": "^20.3.2",
76
+ "@types/node": "^20.5.0",
77
+ "@types/tmp": "^0.2.3",
74
78
  "@typescript-eslint/eslint-plugin": "^5.60.1",
75
79
  "@typescript-eslint/parser": "^5.60.1",
76
- "@types/tmp": "^0.2.3",
77
80
  "dotenv": "^16.3.1",
78
81
  "eslint": "^8.43.0",
79
82
  "eslint-config-prettier": "^8.8.0",
80
83
  "eslint-plugin-prettier": "^4.2.1",
81
- "husky": "^8.0.3",
82
84
  "lint-staged": "^13.2.3",
83
85
  "prettier": "^2.8.8",
84
- "tsconfig-paths": "^4.2.0",
85
86
  "ts-node": "^10.9.1",
87
+ "tsconfig-paths": "^4.2.0",
86
88
  "tsup": "^7.1.0",
87
89
  "typedoc": "^0.24.8",
88
90
  "typescript": "^5.0.4",
@@ -97,11 +99,6 @@
97
99
  "pnpm run format:fix"
98
100
  ]
99
101
  },
100
- "husky": {
101
- "hooks": {
102
- "pre-commit": "lint-staged"
103
- }
104
- },
105
102
  "commitlint": {
106
103
  "extends": [
107
104
  "@commitlint/config-conventional"
@@ -0,0 +1,6 @@
1
+
2
+ import { BCS, getSuiMoveConfig } from '@mysten/bcs'
3
+
4
+ export const bcsSource = new BCS(getSuiMoveConfig())
5
+ export const bcsOnchain = new BCS(getSuiMoveConfig())
6
+