@0xobelisk/sui-client 0.5.18 → 0.5.19

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 (35) hide show
  1. package/dist/index.d.ts +15 -0
  2. package/dist/index.js +93 -134
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +63 -104
  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 +202 -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/types/index.ts +40 -16
@@ -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 { MapMoudleStruct, NetworkType } 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 struct(): MapMoudleStruct;
42
+ /**
43
+ * if derivePathParams is not provided or mnemonics is empty, it will return the keypair.
44
+ * else:
45
+ * it will generate signer from the mnemonic with the given derivePathParams.
46
+ * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard
47
+ */
48
+ getKeypair(derivePathParams?: DerivePathParams): import("@mysten/sui/dist/cjs/keypairs/ed25519").Ed25519Keypair;
49
+ /**
50
+ * @description Switch the current account with the given derivePathParams
51
+ * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard
52
+ */
53
+ switchAccount(derivePathParams: DerivePathParams): void;
54
+ /**
55
+ * @description Get the address of the account for the given derivePathParams
56
+ * @param derivePathParams, such as { accountIndex: 2, isExternal: false, addressIndex: 10 }, comply with the BIP44 standard
57
+ */
58
+ getAddress(derivePathParams?: DerivePathParams): string;
59
+ currentAddress(): string;
60
+ getPackageId(): string;
61
+ getMetadata(): SuiMoveNormalizedModules | undefined;
62
+ getNetwork(): NetworkType | undefined;
63
+ /**
64
+ * Request some SUI from faucet
65
+ * @Returns {Promise<boolean>}, true if the request is successful, false otherwise.
66
+ */
67
+ requestFaucet(address?: string, network?: FaucetNetworkType, derivePathParams?: DerivePathParams): Promise<void>;
68
+ getBalance(coinType?: string, derivePathParams?: DerivePathParams): Promise<import("@mysten/sui/client").CoinBalance>;
69
+ balanceOf(accountAddress?: string, coinType?: string, derivePathParams?: DerivePathParams): Promise<import("@mysten/sui/client").CoinBalance>;
70
+ client(): import("@mysten/sui/client").SuiClient;
71
+ getObject(objectId: string): Promise<SuiObjectData>;
72
+ getObjects(objectIds: string[]): Promise<SuiObjectData[]>;
73
+ signTxn(tx: Uint8Array | Transaction | SuiTx, derivePathParams?: DerivePathParams): Promise<import("@mysten/sui/dist/cjs/cryptography").SignatureWithBytes>;
74
+ signAndSendTxn(tx: Uint8Array | Transaction | SuiTx, derivePathParams?: DerivePathParams): Promise<SuiTransactionBlockResponse>;
75
+ sendTxn(transactionBlock: Uint8Array | string, signature: string | string[]): Promise<SuiTransactionBlockResponse>;
76
+ /**
77
+ * Transfer the given amount of SUI to the recipient
78
+ * @param recipient
79
+ * @param amount
80
+ * @param derivePathParams
81
+ */
82
+ transferSui(recipient: string, amount: number, derivePathParams?: DerivePathParams): Promise<SuiTransactionBlockResponse>;
83
+ /**
84
+ * Transfer to mutliple recipients
85
+ * @param recipients the recipients addresses
86
+ * @param amounts the amounts of SUI to transfer to each recipient, the length of amounts should be the same as the length of recipients
87
+ * @param derivePathParams
88
+ */
89
+ transferSuiToMany(recipients: string[], amounts: number[], derivePathParams?: DerivePathParams): Promise<SuiTransactionBlockResponse>;
90
+ /**
91
+ * Transfer the given amounts of coin to multiple recipients
92
+ * @param recipients the list of recipient address
93
+ * @param amounts the amounts to transfer for each recipient
94
+ * @param coinType any custom coin type but not SUI
95
+ * @param derivePathParams the derive path params for the current signer
96
+ */
97
+ transferCoinToMany(recipients: string[], amounts: number[], coinType: string, derivePathParams?: DerivePathParams): Promise<SuiTransactionBlockResponse>;
98
+ transferCoin(recipient: string, amount: number, coinType: string, derivePathParams?: DerivePathParams): Promise<SuiTransactionBlockResponse>;
99
+ transferObjects(objects: string[], recipient: string, derivePathParams?: DerivePathParams): Promise<SuiTransactionBlockResponse>;
100
+ moveCall(callParams: {
101
+ target: string;
102
+ arguments?: (SuiTxArg | SuiVecTxArg)[];
103
+ typeArguments?: string[];
104
+ derivePathParams?: DerivePathParams;
105
+ }): Promise<SuiTransactionBlockResponse>;
106
+ /**
107
+ * Select coins with the given amount and coin type, the total amount is greater than or equal to the given amount
108
+ * @param amount
109
+ * @param coinType
110
+ * @param owner
111
+ */
112
+ selectCoinsWithAmount(amount: number, coinType: string, owner?: string): Promise<string[]>;
113
+ selectObjectsWithType(objectType: string, owner?: string): Promise<string[]>;
114
+ /**
115
+ * stake the given amount of SUI to the validator
116
+ * @param amount the amount of SUI to stake
117
+ * @param validatorAddr the validator address
118
+ * @param derivePathParams the derive path params for the current signer
119
+ */
120
+ stakeSui(amount: number, validatorAddr: string, derivePathParams?: DerivePathParams): Promise<SuiTransactionBlockResponse>;
121
+ /**
122
+ * Execute the transaction with on-chain data but without really submitting. Useful for querying the effects of a transaction.
123
+ * Since the transaction is not submitted, its gas cost is not charged.
124
+ * @param tx the transaction to execute
125
+ * @param derivePathParams the derive path params
126
+ * @returns the effects and events of the transaction, such as object changes, gas cost, event emitted.
127
+ */
128
+ inspectTxn(tx: Uint8Array | Transaction | SuiTx, derivePathParams?: DerivePathParams): Promise<DevInspectResults>;
129
+ getWorld(worldObjectId: string): Promise<SuiObjectData>;
130
+ listSchemaNames(worldId: string): Promise<any>;
131
+ getEntity(worldId: string, schemaName: string, entityId?: string): Promise<any[] | undefined>;
132
+ containEntity(worldId: string, schemaName: string, entityId?: string): Promise<boolean | undefined>;
133
+ getOwnedObjects(owner: string, cursor?: string, limit?: number): Promise<SuiObjectData[]>;
134
+ entity_key_from_object(objectId: string): Promise<string | undefined>;
135
+ entity_key_from_bytes(bytes: Uint8Array | Buffer | string): Promise<string>;
136
+ entity_key_from_address_with_seed(objectId: string, seed: string): Promise<string | undefined>;
137
+ entity_key_from_address_with_u256(objectId: string, x: number): Promise<string | undefined>;
138
+ entity_key_from_u256(x: number): Promise<string>;
139
+ autoFormatDryValue(value: DevInspectResults): Promise<(string | number | boolean | number[] | null)[] | undefined>;
140
+ }
@@ -0,0 +1,202 @@
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
+ type MoveStructType = {
72
+ struct: Record<string, {
73
+ fields: {
74
+ type: SuiMoveNormalizedType;
75
+ name: string;
76
+ }[];
77
+ abilities: {
78
+ abilities: string[];
79
+ };
80
+ typeParameters: {
81
+ constraints: {
82
+ abilities: string[];
83
+ };
84
+ isPhantom: boolean;
85
+ }[];
86
+ }>;
87
+ bcs: BcsType<{
88
+ [x: string]: any;
89
+ }, {
90
+ [x: string]: any;
91
+ }>;
92
+ };
93
+ export type MapMoudleStruct = Record<string, MoveStructType>;
94
+ export type MapMoudleFuncTest = Record<string, Record<string, string>>;
95
+ export type MapMoudleFuncQueryTest = Record<string, Record<string, string>>;
96
+ export type AccountMangerParams = {
97
+ mnemonics?: string;
98
+ secretKey?: string;
99
+ };
100
+ export type DerivePathParams = {
101
+ accountIndex?: number;
102
+ isExternal?: boolean;
103
+ addressIndex?: number;
104
+ };
105
+ export type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localnet';
106
+ export type FaucetNetworkType = 'testnet' | 'devnet' | 'localnet';
107
+ export type SuiKitParams = {
108
+ mnemonics?: string;
109
+ secretKey?: string;
110
+ fullnodeUrls?: string[];
111
+ faucetUrl?: string;
112
+ networkType?: NetworkType;
113
+ };
114
+ export type ObjectData = {
115
+ objectId: string;
116
+ objectType: string;
117
+ objectVersion: number;
118
+ objectDigest: string;
119
+ initialSharedVersion?: number;
120
+ objectDisplay: DisplayFieldsResponse;
121
+ objectFields: ObjectContentFields;
122
+ };
123
+ type TransactionBlockType = InstanceType<typeof Transaction>;
124
+ export type PureCallArg = {
125
+ Pure: number[];
126
+ };
127
+ /**
128
+ * An object argument.
129
+ */
130
+ type ObjectArg = {
131
+ ImmOrOwnedObject: SuiObjectRef;
132
+ } | {
133
+ SharedObject: SharedObjectRef;
134
+ } | {
135
+ Receiving: SuiObjectRef;
136
+ };
137
+ export type ObjectCallArg = {
138
+ Object: ObjectArg;
139
+ };
140
+ export type TransactionType = Parameters<TransactionBlockType['add']>;
141
+ export type TransactionPureArgument = Extract<Argument, {
142
+ $kind: 'Input';
143
+ type?: 'pure';
144
+ }>;
145
+ export type ObjectFieldType = {
146
+ id: {
147
+ id: string;
148
+ };
149
+ name: string;
150
+ value: string;
151
+ };
152
+ export type EntityData = {
153
+ objectId: string;
154
+ index: string;
155
+ key: string;
156
+ };
157
+ type SharedObjectRef = {
158
+ /** Hex code as string representing the object id */
159
+ objectId: string;
160
+ /** The version the object was shared at */
161
+ initialSharedVersion: number | string;
162
+ /** Whether reference is mutable */
163
+ mutable: boolean;
164
+ };
165
+ type SuiObjectRef = {
166
+ /** Base64 string representing the object digest */
167
+ objectId: string;
168
+ /** Object version */
169
+ version: number | string;
170
+ /** Hex code as string representing the object id */
171
+ digest: string;
172
+ };
173
+ export type SuiTxArg = TransactionArgument | SerializedBcs<any>;
174
+ export type SuiAddressArg = Argument | SerializedBcs<any> | string;
175
+ export type SuiAmountsArg = SuiTxArg | number | bigint;
176
+ export type SuiObjectArg = TransactionObjectArgument | string | Parameters<typeof Inputs.ObjectRef>[0] | Parameters<typeof Inputs.SharedObjectRef>[0] | ObjectCallArg;
177
+ export type SuiVecTxArg = {
178
+ value: SuiTxArg[];
179
+ vecType: SuiInputTypes;
180
+ } | SuiTxArg[];
181
+ export type DryTxReturnValues = Array<[Uint8Array, string]>;
182
+ /**
183
+ * These are the basics types that can be used in the SUI
184
+ */
185
+ export type SuiBasicTypes = 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256';
186
+ export type SuiInputTypes = 'object' | SuiBasicTypes;
187
+ export type SuiReturnValues = {
188
+ returnValues: [number[], string][];
189
+ }[];
190
+ export type DynamicFieldContentType = {
191
+ type: string;
192
+ fields: Record<string, any>;
193
+ hasPublicTransfer: boolean;
194
+ dataType: string;
195
+ };
196
+ export type ObjectContent = {
197
+ type: string;
198
+ fields: Record<string, any>;
199
+ hasPublicTransfer: boolean;
200
+ dataType: string;
201
+ };
202
+ 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.19",
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
  }