@0xobelisk/sui-client 0.5.18 → 0.5.20

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.
Files changed (36) hide show
  1. package/dist/index.d.ts +15 -0
  2. package/dist/index.js +340 -233
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +337 -230
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/libs/multiSig/client.d.ts +15 -0
  7. package/dist/libs/multiSig/index.d.ts +1 -0
  8. package/dist/libs/multiSig/publickey.d.ts +2 -0
  9. package/dist/libs/suiAccountManager/crypto.d.ts +1 -0
  10. package/dist/libs/suiAccountManager/index.d.ts +39 -0
  11. package/dist/libs/suiAccountManager/keypair.d.ts +21 -0
  12. package/dist/libs/suiAccountManager/util.d.ts +29 -0
  13. package/dist/libs/suiContractFactory/index.d.ts +20 -0
  14. package/dist/libs/suiContractFactory/types.d.ts +49 -0
  15. package/dist/libs/suiInteractor/index.d.ts +1 -0
  16. package/dist/libs/suiInteractor/suiInteractor.d.ts +50 -0
  17. package/dist/libs/suiInteractor/util.d.ts +1 -0
  18. package/dist/libs/suiModel/index.d.ts +2 -0
  19. package/dist/libs/suiModel/suiOwnedObject.d.ts +24 -0
  20. package/dist/libs/suiModel/suiSharedObject.d.ts +11 -0
  21. package/dist/libs/suiTxBuilder/index.d.ts +538 -0
  22. package/dist/libs/suiTxBuilder/util.d.ts +49 -0
  23. package/dist/metadata/index.d.ts +3 -0
  24. package/dist/obelisk.d.ts +140 -0
  25. package/dist/types/index.d.ts +199 -0
  26. package/dist/utils/index.d.ts +3 -0
  27. package/package.json +2 -5
  28. package/src/libs/multiSig/client.ts +1 -1
  29. package/src/libs/suiAccountManager/index.ts +4 -5
  30. package/src/libs/suiInteractor/index.ts +0 -1
  31. package/src/libs/suiModel/suiOwnedObject.ts +2 -2
  32. package/src/libs/suiModel/suiSharedObject.ts +2 -2
  33. package/src/libs/suiTxBuilder/index.ts +43 -49
  34. package/src/libs/suiTxBuilder/util.ts +65 -129
  35. package/src/obelisk.ts +329 -139
  36. package/src/types/index.ts +60 -44
@@ -0,0 +1,140 @@
1
+ /// <reference types="node" />
2
+ import { Transaction } from '@mysten/sui/transactions';
3
+ import type { SuiTransactionBlockResponse, DevInspectResults, SuiMoveNormalizedModules, SuiObjectData } from '@mysten/sui/client';
4
+ import { SuiAccountManager } from './libs/suiAccountManager';
5
+ import { SuiTx } from './libs/suiTxBuilder';
6
+ import { SuiInteractor } from './libs/suiInteractor';
7
+ import { MapObjectStruct } from './types';
8
+ import { SuiContractFactory } from './libs/suiContractFactory';
9
+ import { SuiMoveMoudleFuncType } from './libs/suiContractFactory/types';
10
+ import { DerivePathParams, FaucetNetworkType, MapMoudleFuncQuery, MapMoudleFuncTx, ObeliskParams, SuiTxArg, SuiVecTxArg } from './types';
11
+ export declare function isUndefined(value?: unknown): value is undefined;
12
+ export declare function withMeta<T extends {
13
+ meta: SuiMoveMoudleFuncType;
14
+ }>(meta: SuiMoveMoudleFuncType, creator: Omit<T, 'meta'>): T;
15
+ /**
16
+ * @class Obelisk
17
+ * @description This class is used to aggregate the tools that used to interact with SUI network.
18
+ */
19
+ export declare class Obelisk {
20
+ #private;
21
+ accountManager: SuiAccountManager;
22
+ suiInteractor: SuiInteractor;
23
+ contractFactory: SuiContractFactory;
24
+ packageId: string | undefined;
25
+ metadata: SuiMoveNormalizedModules | undefined;
26
+ /**
27
+ * Support the following ways to init the ObeliskClient:
28
+ * 1. mnemonics
29
+ * 2. secretKey (base64 or hex)
30
+ * If none of them is provided, will generate a random mnemonics with 24 words.
31
+ *
32
+ * @param mnemonics, 12 or 24 mnemonics words, separated by space
33
+ * @param secretKey, base64 or hex string or bech32, when mnemonics is provided, secretKey will be ignored
34
+ * @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
35
+ * @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type
36
+ * @param packageId
37
+ */
38
+ constructor({ mnemonics, secretKey, networkType, fullnodeUrls, packageId, metadata, }?: ObeliskParams);
39
+ get query(): MapMoudleFuncQuery;
40
+ get tx(): MapMoudleFuncTx;
41
+ get object(): MapObjectStruct;
42
+ view(dryResult: DevInspectResults): any[] | undefined;
43
+ /**
44
+ * if derivePathParams is not provided or mnemonics is empty, it will return the keypair.
45
+ * else:
46
+ * it will generate signer from the mnemonic with the given derivePathParams.
47
+ * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard
48
+ */
49
+ getKeypair(derivePathParams?: DerivePathParams): import("@mysten/sui/dist/cjs/keypairs/ed25519").Ed25519Keypair;
50
+ /**
51
+ * @description Switch the current account with the given derivePathParams
52
+ * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard
53
+ */
54
+ switchAccount(derivePathParams: DerivePathParams): void;
55
+ /**
56
+ * @description Get the address of the account for the given derivePathParams
57
+ * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard
58
+ */
59
+ getAddress(derivePathParams?: DerivePathParams): string;
60
+ currentAddress(): string;
61
+ getPackageId(): string;
62
+ getMetadata(): SuiMoveNormalizedModules | undefined;
63
+ getNetwork(): import("./types").NetworkType | undefined;
64
+ /**
65
+ * Request some SUI from faucet
66
+ * @Returns {Promise<boolean>}, true if the request is successful, false otherwise.
67
+ */
68
+ requestFaucet(address?: string, network?: FaucetNetworkType, derivePathParams?: DerivePathParams): Promise<void>;
69
+ getBalance(coinType?: string, derivePathParams?: DerivePathParams): Promise<import("@mysten/sui/client").CoinBalance>;
70
+ balanceOf(accountAddress?: string, coinType?: string, derivePathParams?: DerivePathParams): Promise<import("@mysten/sui/client").CoinBalance>;
71
+ client(): import("@mysten/sui/client").SuiClient;
72
+ getObject(objectId: string): Promise<SuiObjectData>;
73
+ getObjects(objectIds: string[]): Promise<SuiObjectData[]>;
74
+ signTxn(tx: Uint8Array | Transaction | SuiTx, derivePathParams?: DerivePathParams): Promise<import("@mysten/sui/dist/cjs/cryptography").SignatureWithBytes>;
75
+ signAndSendTxn(tx: Uint8Array | Transaction | SuiTx, derivePathParams?: DerivePathParams): Promise<SuiTransactionBlockResponse>;
76
+ sendTxn(transactionBlock: Uint8Array | string, signature: string | string[]): Promise<SuiTransactionBlockResponse>;
77
+ /**
78
+ * Transfer the given amount of SUI to the recipient
79
+ * @param recipient
80
+ * @param amount
81
+ * @param derivePathParams
82
+ */
83
+ transferSui(recipient: string, amount: number, derivePathParams?: DerivePathParams): Promise<SuiTransactionBlockResponse>;
84
+ /**
85
+ * Transfer to mutliple recipients
86
+ * @param recipients the recipients addresses
87
+ * @param amounts the amounts of SUI to transfer to each recipient, the length of amounts should be the same as the length of recipients
88
+ * @param derivePathParams
89
+ */
90
+ transferSuiToMany(recipients: string[], amounts: number[], derivePathParams?: DerivePathParams): Promise<SuiTransactionBlockResponse>;
91
+ /**
92
+ * Transfer the given amounts of coin to multiple recipients
93
+ * @param recipients the list of recipient address
94
+ * @param amounts the amounts to transfer for each recipient
95
+ * @param coinType any custom coin type but not SUI
96
+ * @param derivePathParams the derive path params for the current signer
97
+ */
98
+ transferCoinToMany(recipients: string[], amounts: number[], coinType: string, derivePathParams?: DerivePathParams): Promise<SuiTransactionBlockResponse>;
99
+ transferCoin(recipient: string, amount: number, coinType: string, derivePathParams?: DerivePathParams): Promise<SuiTransactionBlockResponse>;
100
+ transferObjects(objects: string[], recipient: string, derivePathParams?: DerivePathParams): Promise<SuiTransactionBlockResponse>;
101
+ moveCall(callParams: {
102
+ target: string;
103
+ arguments?: (SuiTxArg | SuiVecTxArg)[];
104
+ typeArguments?: string[];
105
+ derivePathParams?: DerivePathParams;
106
+ }): Promise<SuiTransactionBlockResponse>;
107
+ /**
108
+ * Select coins with the given amount and coin type, the total amount is greater than or equal to the given amount
109
+ * @param amount
110
+ * @param coinType
111
+ * @param owner
112
+ */
113
+ selectCoinsWithAmount(amount: number, coinType: string, owner?: string): Promise<string[]>;
114
+ selectObjectsWithType(objectType: string, owner?: string): Promise<string[]>;
115
+ /**
116
+ * stake the given amount of SUI to the validator
117
+ * @param amount the amount of SUI to stake
118
+ * @param validatorAddr the validator address
119
+ * @param derivePathParams the derive path params for the current signer
120
+ */
121
+ stakeSui(amount: number, validatorAddr: string, derivePathParams?: DerivePathParams): Promise<SuiTransactionBlockResponse>;
122
+ /**
123
+ * Execute the transaction with on-chain data but without really submitting. Useful for querying the effects of a transaction.
124
+ * Since the transaction is not submitted, its gas cost is not charged.
125
+ * @param tx the transaction to execute
126
+ * @param derivePathParams the derive path params
127
+ * @returns the effects and events of the transaction, such as object changes, gas cost, event emitted.
128
+ */
129
+ inspectTxn(tx: Uint8Array | Transaction | SuiTx, derivePathParams?: DerivePathParams): Promise<DevInspectResults>;
130
+ getWorld(worldObjectId: string): Promise<SuiObjectData>;
131
+ listSchemaNames(worldId: string): Promise<any>;
132
+ getEntity(worldId: string, schemaName: string, entityId?: string): Promise<any[] | undefined>;
133
+ containEntity(worldId: string, schemaName: string, entityId?: string): Promise<boolean | undefined>;
134
+ getOwnedObjects(owner: string, cursor?: string, limit?: number): Promise<SuiObjectData[]>;
135
+ entity_key_from_object(objectId: string): Promise<string | undefined>;
136
+ entity_key_from_bytes(bytes: Uint8Array | Buffer | string): Promise<string>;
137
+ entity_key_from_address_with_seed(objectId: string, seed: string): Promise<string | undefined>;
138
+ entity_key_from_address_with_u256(objectId: string, x: number): Promise<string | undefined>;
139
+ entity_key_from_u256(x: number): Promise<string>;
140
+ }
@@ -0,0 +1,199 @@
1
+ import type { Infer } from 'superstruct';
2
+ import type { BcsType, SerializedBcs } from '@mysten/bcs';
3
+ import type { TransactionArgument } from '@mysten/sui/transactions';
4
+ import type { Transaction, TransactionObjectArgument, TransactionResult, Argument, Inputs } from '@mysten/sui/transactions';
5
+ import type { SuiMoveNormalizedModules, DevInspectResults, SuiTransactionBlockResponse, DisplayFieldsResponse, SuiMoveNormalizedType, MoveStruct } from '@mysten/sui/client';
6
+ import { SuiMoveMoudleFuncType } from '../libs/suiContractFactory/types';
7
+ export declare const ObjectContentFields: import("superstruct").Struct<Record<string, any>, null>;
8
+ export type ObjectContentFields = Infer<typeof ObjectContentFields>;
9
+ export type ObeliskObjectData = {
10
+ objectId: string;
11
+ objectType: string;
12
+ objectVersion: number;
13
+ objectDisplay: DisplayFieldsResponse;
14
+ objectFields: ObjectContentFields;
15
+ };
16
+ export type ObeliskObjectContent = {
17
+ dataType: 'moveObject';
18
+ fields: MoveStruct;
19
+ hasPublicTransfer: boolean;
20
+ type: string;
21
+ };
22
+ export type ObeliskParams = {
23
+ mnemonics?: string;
24
+ secretKey?: string;
25
+ fullnodeUrls?: string[];
26
+ faucetUrl?: string;
27
+ networkType?: NetworkType;
28
+ packageId?: string;
29
+ metadata?: SuiMoveNormalizedModules;
30
+ };
31
+ export type SchemaFieldType = {
32
+ schemas: {
33
+ type: string;
34
+ fields: {
35
+ id: {
36
+ id: string;
37
+ };
38
+ size: string;
39
+ };
40
+ };
41
+ };
42
+ export type SchemaValueType = {
43
+ id: {
44
+ id: string;
45
+ };
46
+ name: string;
47
+ value: {
48
+ type: string;
49
+ fields: SchemaFieldType;
50
+ };
51
+ };
52
+ export type SchemaContentType = {
53
+ type: string;
54
+ fields: SchemaValueType;
55
+ hasPublicTransfer: boolean;
56
+ dataType: 'moveObject';
57
+ };
58
+ export interface MessageMeta {
59
+ readonly meta: SuiMoveMoudleFuncType;
60
+ }
61
+ export interface ContractQuery extends MessageMeta {
62
+ (tx: Transaction, params: (TransactionArgument | SerializedBcs<any>)[], typeArguments?: string[], isRaw?: boolean): Promise<DevInspectResults | TransactionResult>;
63
+ }
64
+ export interface ContractTx extends MessageMeta {
65
+ (tx: Transaction, params: (TransactionArgument | SerializedBcs<any>)[], typeArguments?: string[], isRaw?: boolean): Promise<SuiTransactionBlockResponse | TransactionResult>;
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 MoveStructValueType = {
72
+ fields: {
73
+ type: SuiMoveNormalizedType;
74
+ name: string;
75
+ }[];
76
+ abilities: {
77
+ abilities: string[];
78
+ };
79
+ typeParameters: {
80
+ constraints: {
81
+ abilities: string[];
82
+ };
83
+ isPhantom: boolean;
84
+ }[];
85
+ };
86
+ export type MoveStructType = {
87
+ objectType: MoveStructValueType;
88
+ objectName: string;
89
+ };
90
+ export type MapObjectStruct = Record<string, BcsType<any, any>>;
91
+ export type MapMoudleFuncTest = Record<string, Record<string, string>>;
92
+ export type MapMoudleFuncQueryTest = Record<string, Record<string, string>>;
93
+ export type AccountMangerParams = {
94
+ mnemonics?: string;
95
+ secretKey?: string;
96
+ };
97
+ export type DerivePathParams = {
98
+ accountIndex?: number;
99
+ isExternal?: boolean;
100
+ addressIndex?: number;
101
+ };
102
+ export type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localnet';
103
+ export type FaucetNetworkType = 'testnet' | 'devnet' | 'localnet';
104
+ export type SuiKitParams = {
105
+ mnemonics?: string;
106
+ secretKey?: string;
107
+ fullnodeUrls?: string[];
108
+ faucetUrl?: string;
109
+ networkType?: NetworkType;
110
+ };
111
+ export type ObjectData = {
112
+ objectId: string;
113
+ objectType: string;
114
+ objectVersion: number;
115
+ objectDigest: string;
116
+ initialSharedVersion?: number;
117
+ objectDisplay: DisplayFieldsResponse;
118
+ objectFields: ObjectContentFields;
119
+ };
120
+ type TransactionBlockType = InstanceType<typeof Transaction>;
121
+ export type PureCallArg = {
122
+ Pure: number[];
123
+ };
124
+ /**
125
+ * An object argument.
126
+ */
127
+ type ObjectArg = {
128
+ ImmOrOwnedObject: SuiObjectRef;
129
+ } | {
130
+ SharedObject: SharedObjectRef;
131
+ } | {
132
+ Receiving: SuiObjectRef;
133
+ };
134
+ export type ObjectCallArg = {
135
+ Object: ObjectArg;
136
+ };
137
+ export type TransactionType = Parameters<TransactionBlockType['add']>;
138
+ export type TransactionPureArgument = Extract<Argument, {
139
+ $kind: 'Input';
140
+ type?: 'pure';
141
+ }>;
142
+ export type ObjectFieldType = {
143
+ id: {
144
+ id: string;
145
+ };
146
+ name: string;
147
+ value: string;
148
+ };
149
+ export type EntityData = {
150
+ objectId: string;
151
+ index: string;
152
+ key: string;
153
+ };
154
+ type SharedObjectRef = {
155
+ /** Hex code as string representing the object id */
156
+ objectId: string;
157
+ /** The version the object was shared at */
158
+ initialSharedVersion: number | string;
159
+ /** Whether reference is mutable */
160
+ mutable: boolean;
161
+ };
162
+ type SuiObjectRef = {
163
+ /** Base64 string representing the object digest */
164
+ objectId: string;
165
+ /** Object version */
166
+ version: number | string;
167
+ /** Hex code as string representing the object id */
168
+ digest: string;
169
+ };
170
+ export type SuiTxArg = TransactionArgument | SerializedBcs<any>;
171
+ export type SuiAddressArg = Argument | SerializedBcs<any> | string;
172
+ export type SuiAmountsArg = SuiTxArg | number | bigint;
173
+ export type SuiObjectArg = TransactionObjectArgument | string | Parameters<typeof Inputs.ObjectRef>[0] | Parameters<typeof Inputs.SharedObjectRef>[0] | ObjectCallArg;
174
+ export type SuiVecTxArg = {
175
+ value: SuiTxArg[];
176
+ vecType: SuiInputTypes;
177
+ } | SuiTxArg[];
178
+ export type DryTxReturnValues = Array<[Uint8Array, string]>;
179
+ /**
180
+ * These are the basics types that can be used in the SUI
181
+ */
182
+ export type SuiBasicTypes = 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256';
183
+ export type SuiInputTypes = 'object' | SuiBasicTypes;
184
+ export type SuiReturnValues = {
185
+ returnValues: [number[], string][];
186
+ }[];
187
+ export type DynamicFieldContentType = {
188
+ type: string;
189
+ fields: Record<string, any>;
190
+ hasPublicTransfer: boolean;
191
+ dataType: string;
192
+ };
193
+ export type ObjectContent = {
194
+ type: string;
195
+ fields: Record<string, any>;
196
+ hasPublicTransfer: boolean;
197
+ dataType: string;
198
+ };
199
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare function capitalizeFirstLetter(input: string): string;
2
+ export declare function normalizeHexAddress(input: string): string | null;
3
+ export declare function numberToAddressHex(num: number): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xobelisk/sui-client",
3
- "version": "0.5.18",
3
+ "version": "0.5.20",
4
4
  "description": "Tookit for interacting with move eps framework",
5
5
  "keywords": [
6
6
  "sui",
@@ -59,9 +59,6 @@
59
59
  "tmp": "^0.2.1",
60
60
  "valibot": "^0.25.0"
61
61
  },
62
- "peerDependencies": {
63
- "@mysten/sui": "^1.1.2"
64
- },
65
62
  "devDependencies": {
66
63
  "@commitlint/cli": "^18.0.0",
67
64
  "@commitlint/config-conventional": "^18.0.0",
@@ -80,7 +77,7 @@
80
77
  "tsconfig-paths": "^4.2.0",
81
78
  "tsup": "^7.1.0",
82
79
  "typedoc": "^0.25.2",
83
- "typescript": "^5.0.4"
80
+ "typescript": "^5.2.2"
84
81
  },
85
82
  "lint-staged": {
86
83
  "**/*.ts": [
@@ -1,5 +1,5 @@
1
1
  import { MultiSigPublicKey } from '@mysten/sui/multisig';
2
- import type { PublicKey } from '@mysten/sui/src/cryptography';
2
+ import type { PublicKey } from '@mysten/sui/cryptography';
3
3
  import { ed25519PublicKeyFromBase64 } from './publickey';
4
4
 
5
5
  export type PublicKeyWeightPair = {
@@ -1,13 +1,12 @@
1
1
  import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
2
- import {
3
- SUI_PRIVATE_KEY_PREFIX,
4
- decodeSuiPrivateKey,
5
- } from '@mysten/sui/cryptography';
6
-
7
2
  import { getKeyPair } from './keypair';
8
3
  import { hexOrBase64ToUint8Array, normalizePrivateKey } from './util';
9
4
  import { generateMnemonic } from './crypto';
10
5
  import type { AccountMangerParams, DerivePathParams } from 'src/types';
6
+ import {
7
+ SUI_PRIVATE_KEY_PREFIX,
8
+ decodeSuiPrivateKey,
9
+ } from '@mysten/sui/cryptography';
11
10
 
12
11
  export class SuiAccountManager {
13
12
  private mnemonics: string;
@@ -1,2 +1 @@
1
1
  export { SuiInteractor } from './suiInteractor';
2
- // export { getDefaultConnection } from './defaultConfig';
@@ -1,5 +1,5 @@
1
1
  import type { SuiTransactionBlockResponse } from '@mysten/sui/client';
2
- import { bcs } from '@mysten/sui/bcs';
2
+ import type { CallArg } from '@mysten/sui/transactions';
3
3
 
4
4
  export class SuiOwnedObject {
5
5
  public readonly objectId: string;
@@ -21,7 +21,7 @@ export class SuiOwnedObject {
21
21
  return !!this.version && !!this.digest;
22
22
  }
23
23
 
24
- asCallArg(): typeof bcs.CallArg.$inferType | string {
24
+ asCallArg(): CallArg | string {
25
25
  if (!this.version || !this.digest) {
26
26
  return this.objectId;
27
27
  }
@@ -1,4 +1,4 @@
1
- import { bcs } from '@mysten/sui/bcs';
1
+ import type { CallArg } from '@mysten/sui/transactions';
2
2
 
3
3
  export class SuiSharedObject {
4
4
  public readonly objectId: string;
@@ -13,7 +13,7 @@ export class SuiSharedObject {
13
13
  this.initialSharedVersion = param.initialSharedVersion;
14
14
  }
15
15
 
16
- asCallArg(mutable: boolean = false): typeof bcs.CallArg.$inferType | string {
16
+ asCallArg(mutable: boolean = false): CallArg | string {
17
17
  if (!this.initialSharedVersion) {
18
18
  return this.objectId;
19
19
  }
@@ -5,7 +5,6 @@ import type {
5
5
  TransactionObjectArgument,
6
6
  TransactionObjectInput,
7
7
  } from '@mysten/sui/transactions';
8
- import { bcs } from '@mysten/sui/bcs';
9
8
  import type { Keypair } from '@mysten/sui/cryptography';
10
9
  import { SerializedBcs } from '@mysten/bcs';
11
10
 
@@ -16,14 +15,16 @@ import type {
16
15
  SuiAddressArg,
17
16
  SuiObjectArg,
18
17
  SuiVecTxArg,
18
+ SuiAmountsArg,
19
19
  } from '../../types';
20
+
21
+ import type { bcs } from '@mysten/sui/bcs';
20
22
  import {
21
23
  convertArgs,
22
24
  convertAddressArg,
23
25
  convertObjArg,
24
- getDefaultSuiInputType,
26
+ convertAmounts,
25
27
  } from './util';
26
-
27
28
  export class SuiTx {
28
29
  public tx: Transaction;
29
30
 
@@ -43,7 +44,7 @@ export class SuiTx {
43
44
  return this.tx.blockData;
44
45
  }
45
46
 
46
- autoPure(value: string, type?: string) {
47
+ autoPure(value: SuiTxArg, type?: string) {
47
48
  if (type === undefined) {
48
49
  return convertArgs(this.tx, [value]);
49
50
  }
@@ -54,10 +55,10 @@ export class SuiTx {
54
55
  address(value: string) {
55
56
  return this.tx.pure.address(value);
56
57
  }
57
- pure(value: SerializedBcs<any, any> | Uint8Array) {
58
- return this.tx.pure(value);
58
+ get pure() {
59
+ return this.tx.pure.bind(this.tx);
59
60
  }
60
- object(value: TransactionObjectInput) {
61
+ object(value: string | TransactionObjectInput) {
61
62
  return this.tx.object(value);
62
63
  }
63
64
  objectRef(ref: SuiObjectRef) {
@@ -72,7 +73,7 @@ export class SuiTx {
72
73
  setSenderIfNotSet(sender: string) {
73
74
  return this.tx.setSenderIfNotSet(sender);
74
75
  }
75
- setExpiration(expiration?: typeof bcs.TransactionExpiration.$inferType) {
76
+ setExpiration(expiration?: Parameters<typeof this.tx.setExpiration>[0]) {
76
77
  return this.tx.setExpiration(expiration);
77
78
  }
78
79
  setGasPrice(price: number | bigint) {
@@ -90,6 +91,9 @@ export class SuiTx {
90
91
  serialize() {
91
92
  return this.tx.serialize();
92
93
  }
94
+ toJSON() {
95
+ return this.tx.toJSON();
96
+ }
93
97
  sign(params: {
94
98
  signer: Keypair;
95
99
  client?: SuiClient;
@@ -108,7 +112,7 @@ export class SuiTx {
108
112
  getDigest(params: { client?: SuiClient } = {}) {
109
113
  return this.tx.getDigest(params);
110
114
  }
111
- add(...args: TransactionType) {
115
+ add(...args: Parameters<typeof this.tx.add>) {
112
116
  return this.tx.add(...args);
113
117
  }
114
118
  publish({
@@ -120,32 +124,11 @@ export class SuiTx {
120
124
  }) {
121
125
  return this.tx.publish({ modules, dependencies });
122
126
  }
123
- upgrade({
124
- modules,
125
- dependencies,
126
- package: packageId,
127
- ticket,
128
- }: {
129
- modules: number[][] | string[];
130
- dependencies: string[];
131
- package: string;
132
- ticket: TransactionObjectArgument | string;
133
- }) {
134
- return this.tx.upgrade({
135
- modules,
136
- dependencies,
137
- package: packageId,
138
- ticket,
139
- });
127
+ upgrade(...args: Parameters<typeof this.tx.upgrade>) {
128
+ return this.tx.upgrade(...args);
140
129
  }
141
- makeMoveVec({
142
- elements,
143
- type,
144
- }: {
145
- elements: (TransactionObjectArgument | string)[];
146
- type?: string;
147
- }) {
148
- return this.tx.makeMoveVec({ elements, type });
130
+ makeMoveVec(...args: Parameters<typeof this.tx.makeMoveVec>) {
131
+ return this.tx.makeMoveVec(...args);
149
132
  }
150
133
 
151
134
  /* Override methods of TransactionBlock */
@@ -202,7 +185,10 @@ export class SuiTx {
202
185
 
203
186
  /* Enhance methods of TransactionBlock */
204
187
 
205
- transferSuiToMany(recipients: SuiAddressArg[], amounts: SuiTxArg[]) {
188
+ transferSuiToMany(
189
+ recipients: SuiAddressArg[],
190
+ amounts: (SuiTxArg | number | bigint)[]
191
+ ) {
206
192
  // require recipients.length === amounts.length
207
193
  if (recipients.length !== amounts.length) {
208
194
  throw new Error(
@@ -211,7 +197,11 @@ export class SuiTx {
211
197
  }
212
198
  const coins = this.tx.splitCoins(
213
199
  this.tx.gas,
214
- convertArgs(this.tx, amounts)
200
+ amounts.map((amount) =>
201
+ typeof amount === 'number' || typeof amount === 'bigint'
202
+ ? amount
203
+ : convertArgs(this.tx, [amount])[0]
204
+ )
215
205
  );
216
206
  const recipientObjects = recipients.map((recipient) =>
217
207
  convertAddressArg(this.tx, recipient)
@@ -222,20 +212,24 @@ export class SuiTx {
222
212
  return this;
223
213
  }
224
214
 
225
- transferSui(address: SuiAddressArg, amount: SuiTxArg) {
215
+ transferSui(address: SuiAddressArg, amount: SuiTxArg | number | bigint) {
226
216
  return this.transferSuiToMany([address], [amount]);
227
217
  }
228
218
 
229
- takeAmountFromCoins(coins: SuiObjectArg[], amount: SuiTxArg) {
219
+ takeAmountFromCoins(
220
+ coins: SuiObjectArg[],
221
+ amount: SuiTxArg | number | bigint
222
+ ) {
230
223
  const coinObjects = coins.map((coin) => convertObjArg(this.tx, coin));
231
224
  const mergedCoin = coinObjects[0];
232
225
  if (coins.length > 1) {
233
226
  this.tx.mergeCoins(mergedCoin, coinObjects.slice(1));
234
227
  }
235
- const [sendCoin] = this.tx.splitCoins(
236
- mergedCoin,
237
- convertArgs(this.tx, [amount])
238
- );
228
+ const [sendCoin] = this.tx.splitCoins(mergedCoin, [
229
+ typeof amount === 'number' || typeof amount === 'bigint'
230
+ ? amount
231
+ : convertArgs(this.tx, [amount])[0],
232
+ ]);
239
233
  return [sendCoin, mergedCoin];
240
234
  }
241
235
 
@@ -243,7 +237,7 @@ export class SuiTx {
243
237
  return this.tx.splitCoins(this.tx.gas, convertArgs(this.tx, amounts));
244
238
  }
245
239
 
246
- splitMultiCoins(coins: SuiObjectArg[], amounts: SuiTxArg[]) {
240
+ splitMultiCoins(coins: SuiObjectArg[], amounts: SuiAmountsArg[]) {
247
241
  const coinObjects = coins.map((coin) => convertObjArg(this.tx, coin));
248
242
  const mergedCoin = coinObjects[0];
249
243
  if (coins.length > 1) {
@@ -251,7 +245,7 @@ export class SuiTx {
251
245
  }
252
246
  const splitedCoins = this.tx.splitCoins(
253
247
  mergedCoin,
254
- convertArgs(this.tx, amounts)
248
+ convertAmounts(this.tx, amounts)
255
249
  );
256
250
  return { splitedCoins, mergedCoin };
257
251
  }
@@ -260,7 +254,7 @@ export class SuiTx {
260
254
  coins: SuiObjectArg[],
261
255
  sender: SuiAddressArg,
262
256
  recipients: SuiAddressArg[],
263
- amounts: SuiTxArg[]
257
+ amounts: SuiAmountsArg[]
264
258
  ) {
265
259
  // require recipients.length === amounts.length
266
260
  if (recipients.length !== amounts.length) {
@@ -292,17 +286,17 @@ export class SuiTx {
292
286
  return this.transferCoinToMany(coins, sender, [recipient], [amount]);
293
287
  }
294
288
 
295
- stakeSui(amount: SuiTxArg, validatorAddr: SuiAddressArg) {
289
+ stakeSui(amount: SuiTxArg | number | bigint, validatorAddr: SuiAddressArg) {
296
290
  const [stakeCoin] = this.tx.splitCoins(
297
291
  this.tx.gas,
298
- convertArgs(this.tx, [amount])
292
+ convertAmounts(this.tx, [amount])
299
293
  );
300
294
  return this.tx.moveCall({
301
295
  target: '0x3::sui_system::request_add_stake',
302
296
  arguments: convertArgs(this.tx, [
303
- SUI_SYSTEM_STATE_OBJECT_ID,
297
+ this.tx.object(SUI_SYSTEM_STATE_OBJECT_ID),
304
298
  stakeCoin,
305
- this.tx.pure.address(validatorAddr.toString()),
299
+ convertAddressArg(this.tx, validatorAddr),
306
300
  ]),
307
301
  });
308
302
  }