@0xobelisk/sui-client 0.5.17 → 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 (37) hide show
  1. package/dist/index.d.ts +9 -8
  2. package/dist/index.js +309 -208
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +299 -201
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/libs/multiSig/client.d.ts +2 -2
  7. package/dist/libs/multiSig/publickey.d.ts +1 -1
  8. package/dist/libs/suiAccountManager/index.d.ts +1 -1
  9. package/dist/libs/suiAccountManager/keypair.d.ts +1 -1
  10. package/dist/libs/suiContractFactory/index.d.ts +1 -1
  11. package/dist/libs/suiContractFactory/types.d.ts +1 -1
  12. package/dist/libs/suiInteractor/suiInteractor.d.ts +5 -5
  13. package/dist/libs/suiModel/suiOwnedObject.d.ts +2 -2
  14. package/dist/libs/suiModel/suiSharedObject.d.ts +1 -1
  15. package/dist/libs/suiTxBuilder/index.d.ts +365 -160
  16. package/dist/libs/suiTxBuilder/util.d.ts +8 -17
  17. package/dist/metadata/index.d.ts +1 -1
  18. package/dist/obelisk.d.ts +16 -12
  19. package/dist/types/index.d.ts +65 -15
  20. package/package.json +11 -8
  21. package/src/index.ts +9 -8
  22. package/src/libs/multiSig/client.ts +2 -2
  23. package/src/libs/multiSig/publickey.ts +3 -3
  24. package/src/libs/suiAccountManager/index.ts +2 -2
  25. package/src/libs/suiAccountManager/keypair.ts +1 -1
  26. package/src/libs/suiAccountManager/util.ts +1 -1
  27. package/src/libs/suiContractFactory/index.ts +1 -1
  28. package/src/libs/suiContractFactory/types.ts +1 -1
  29. package/src/libs/suiInteractor/index.ts +0 -1
  30. package/src/libs/suiInteractor/suiInteractor.ts +4 -4
  31. package/src/libs/suiModel/suiOwnedObject.ts +5 -3
  32. package/src/libs/suiModel/suiSharedObject.ts +4 -2
  33. package/src/libs/suiTxBuilder/index.ts +120 -108
  34. package/src/libs/suiTxBuilder/util.ts +55 -48
  35. package/src/metadata/index.ts +2 -3
  36. package/src/obelisk.ts +199 -90
  37. package/src/types/index.ts +82 -44
@@ -1,13 +1,13 @@
1
- import { TransactionBlock } from '@mysten/sui.js/transactions';
2
- import { SUI_SYSTEM_STATE_OBJECT_ID } from '@mysten/sui.js/utils';
3
- import { convertArgs, convertAddressArg, convertObjArg } from './util';
4
- import type { SuiClient, SuiObjectRef } from '@mysten/sui.js/client';
5
- import type { TransactionObjectArgument } from '@mysten/sui.js/transactions';
1
+ import { Transaction } from '@mysten/sui/transactions';
2
+ import { SUI_SYSTEM_STATE_OBJECT_ID } from '@mysten/sui/utils';
3
+ import type { SuiClient, SuiObjectRef } from '@mysten/sui/client';
6
4
  import type {
7
- TransactionExpiration,
8
- SharedObjectRef,
9
- } from '@mysten/sui.js/bcs';
10
- import type { Keypair } from '@mysten/sui.js/cryptography';
5
+ TransactionObjectArgument,
6
+ TransactionObjectInput,
7
+ } from '@mysten/sui/transactions';
8
+ import type { Keypair } from '@mysten/sui/cryptography';
9
+ import { SerializedBcs } from '@mysten/bcs';
10
+
11
11
  import type {
12
12
  ObjectCallArg,
13
13
  TransactionType,
@@ -15,68 +15,91 @@ import type {
15
15
  SuiAddressArg,
16
16
  SuiObjectArg,
17
17
  SuiVecTxArg,
18
+ SuiAmountsArg,
18
19
  } from '../../types';
19
20
 
20
- export class SuiTxBlock {
21
- public txBlock: TransactionBlock;
21
+ import type { bcs } from '@mysten/sui/bcs';
22
+ import {
23
+ convertArgs,
24
+ convertAddressArg,
25
+ convertObjArg,
26
+ convertAmounts,
27
+ } from './util';
28
+ export class SuiTx {
29
+ public tx: Transaction;
22
30
 
23
- constructor(transaction?: TransactionBlock) {
24
- this.txBlock = new TransactionBlock(transaction);
31
+ constructor(transaction?: Transaction) {
32
+ if (transaction !== undefined) {
33
+ this.tx = Transaction.from(transaction);
34
+ } else {
35
+ this.tx = new Transaction();
36
+ }
25
37
  }
26
38
 
27
39
  /* Directly wrap methods and properties of TransactionBlock */
28
40
  get gas() {
29
- return this.txBlock.gas;
41
+ return this.tx.gas;
30
42
  }
31
43
  get blockData() {
32
- return this.txBlock.blockData;
44
+ return this.tx.blockData;
45
+ }
46
+
47
+ autoPure(value: SuiTxArg, type?: string) {
48
+ if (type === undefined) {
49
+ return convertArgs(this.tx, [value]);
50
+ }
51
+
52
+ return;
33
53
  }
34
54
 
35
55
  address(value: string) {
36
- return this.txBlock.pure(value, 'address');
56
+ return this.tx.pure.address(value);
37
57
  }
38
- pure(value: unknown, type?: string) {
39
- return this.txBlock.pure(value, type);
58
+ get pure() {
59
+ return this.tx.pure.bind(this.tx);
40
60
  }
41
- object(value: string | ObjectCallArg) {
42
- return this.txBlock.object(value);
61
+ object(value: string | TransactionObjectInput) {
62
+ return this.tx.object(value);
43
63
  }
44
64
  objectRef(ref: SuiObjectRef) {
45
- return this.txBlock.objectRef(ref);
65
+ return this.tx.objectRef(ref);
46
66
  }
47
- sharedObjectRef(ref: SharedObjectRef) {
48
- return this.txBlock.sharedObjectRef(ref);
67
+ sharedObjectRef(ref: typeof bcs.SharedObjectRef.$inferType) {
68
+ return this.tx.sharedObjectRef(ref);
49
69
  }
50
70
  setSender(sender: string) {
51
- return this.txBlock.setSender(sender);
71
+ return this.tx.setSender(sender);
52
72
  }
53
73
  setSenderIfNotSet(sender: string) {
54
- return this.txBlock.setSenderIfNotSet(sender);
74
+ return this.tx.setSenderIfNotSet(sender);
55
75
  }
56
- setExpiration(expiration?: TransactionExpiration) {
57
- return this.txBlock.setExpiration(expiration);
76
+ setExpiration(expiration?: Parameters<typeof this.tx.setExpiration>[0]) {
77
+ return this.tx.setExpiration(expiration);
58
78
  }
59
79
  setGasPrice(price: number | bigint) {
60
- return this.txBlock.setGasPrice(price);
80
+ return this.tx.setGasPrice(price);
61
81
  }
62
82
  setGasBudget(budget: number | bigint) {
63
- return this.txBlock.setGasBudget(budget);
83
+ return this.tx.setGasBudget(budget);
64
84
  }
65
85
  setGasOwner(owner: string) {
66
- return this.txBlock.setGasOwner(owner);
86
+ return this.tx.setGasOwner(owner);
67
87
  }
68
88
  setGasPayment(payments: SuiObjectRef[]) {
69
- return this.txBlock.setGasPayment(payments);
89
+ return this.tx.setGasPayment(payments);
70
90
  }
71
91
  serialize() {
72
- return this.txBlock.serialize();
92
+ return this.tx.serialize();
93
+ }
94
+ toJSON() {
95
+ return this.tx.toJSON();
73
96
  }
74
97
  sign(params: {
75
98
  signer: Keypair;
76
99
  client?: SuiClient;
77
100
  onlyTransactionKind?: boolean;
78
101
  }) {
79
- return this.txBlock.sign(params);
102
+ return this.tx.sign(params);
80
103
  }
81
104
  build(
82
105
  params: {
@@ -84,13 +107,13 @@ export class SuiTxBlock {
84
107
  onlyTransactionKind?: boolean;
85
108
  } = {}
86
109
  ) {
87
- return this.txBlock.build(params);
110
+ return this.tx.build(params);
88
111
  }
89
112
  getDigest(params: { client?: SuiClient } = {}) {
90
- return this.txBlock.getDigest(params);
113
+ return this.tx.getDigest(params);
91
114
  }
92
- add(...args: TransactionType) {
93
- return this.txBlock.add(...args);
115
+ add(...args: Parameters<typeof this.tx.add>) {
116
+ return this.tx.add(...args);
94
117
  }
95
118
  publish({
96
119
  modules,
@@ -99,54 +122,38 @@ export class SuiTxBlock {
99
122
  modules: number[][] | string[];
100
123
  dependencies: string[];
101
124
  }) {
102
- return this.txBlock.publish({ modules, dependencies });
125
+ return this.tx.publish({ modules, dependencies });
103
126
  }
104
- upgrade({
105
- modules,
106
- dependencies,
107
- packageId,
108
- ticket,
109
- }: {
110
- modules: number[][] | string[];
111
- dependencies: string[];
112
- packageId: string;
113
- ticket: TransactionObjectArgument | string;
114
- }) {
115
- return this.txBlock.upgrade({ modules, dependencies, packageId, ticket });
127
+ upgrade(...args: Parameters<typeof this.tx.upgrade>) {
128
+ return this.tx.upgrade(...args);
116
129
  }
117
- makeMoveVec({
118
- objects,
119
- type,
120
- }: {
121
- objects: (TransactionObjectArgument | string)[];
122
- type?: string;
123
- }) {
124
- return this.txBlock.makeMoveVec({ objects, type });
130
+ makeMoveVec(...args: Parameters<typeof this.tx.makeMoveVec>) {
131
+ return this.tx.makeMoveVec(...args);
125
132
  }
126
133
 
127
134
  /* Override methods of TransactionBlock */
128
135
 
129
136
  transferObjects(objects: SuiObjectArg[], address: SuiAddressArg) {
130
- return this.txBlock.transferObjects(
131
- objects.map((object) => convertObjArg(this.txBlock, object)),
132
- convertAddressArg(this.txBlock, address)
137
+ return this.tx.transferObjects(
138
+ objects.map((object) => convertObjArg(this.tx, object)),
139
+ convertAddressArg(this.tx, address)
133
140
  );
134
141
  }
135
142
 
136
143
  splitCoins(coin: SuiObjectArg, amounts: SuiTxArg[]) {
137
- const res = this.txBlock.splitCoins(
138
- convertObjArg(this.txBlock, coin),
139
- convertArgs(this.txBlock, amounts)
144
+ const res = this.tx.splitCoins(
145
+ convertObjArg(this.tx, coin),
146
+ convertArgs(this.tx, amounts)
140
147
  );
141
148
  return amounts.map((_, i) => res[i]);
142
149
  }
143
150
 
144
151
  mergeCoins(destination: SuiObjectArg, sources: SuiObjectArg[]) {
145
- const destinationObject = convertObjArg(this.txBlock, destination);
152
+ const destinationObject = convertObjArg(this.tx, destination);
146
153
  const sourceObjects = sources.map((source) =>
147
- convertObjArg(this.txBlock, source)
154
+ convertObjArg(this.tx, source)
148
155
  );
149
- return this.txBlock.mergeCoins(destinationObject, sourceObjects);
156
+ return this.tx.mergeCoins(destinationObject, sourceObjects);
150
157
  }
151
158
 
152
159
  /**
@@ -168,8 +175,8 @@ export class SuiTxBlock {
168
175
  throw new Error(
169
176
  'Invalid target format. Expected `${string}::${string}::${string}`'
170
177
  );
171
- const convertedArgs = convertArgs(this.txBlock, args);
172
- return this.txBlock.moveCall({
178
+ const convertedArgs = convertArgs(this.tx, args);
179
+ return this.tx.moveCall({
173
180
  target: target as `${string}::${string}::${string}`,
174
181
  arguments: convertedArgs,
175
182
  typeArguments: typeArgs,
@@ -178,59 +185,67 @@ export class SuiTxBlock {
178
185
 
179
186
  /* Enhance methods of TransactionBlock */
180
187
 
181
- transferSuiToMany(recipients: SuiAddressArg[], amounts: SuiTxArg[]) {
188
+ transferSuiToMany(
189
+ recipients: SuiAddressArg[],
190
+ amounts: (SuiTxArg | number | bigint)[]
191
+ ) {
182
192
  // require recipients.length === amounts.length
183
193
  if (recipients.length !== amounts.length) {
184
194
  throw new Error(
185
195
  'transferSuiToMany: recipients.length !== amounts.length'
186
196
  );
187
197
  }
188
- const coins = this.txBlock.splitCoins(
189
- this.txBlock.gas,
190
- convertArgs(this.txBlock, amounts)
198
+ const coins = this.tx.splitCoins(
199
+ this.tx.gas,
200
+ amounts.map((amount) =>
201
+ typeof amount === 'number' || typeof amount === 'bigint'
202
+ ? amount
203
+ : convertArgs(this.tx, [amount])[0]
204
+ )
191
205
  );
192
206
  const recipientObjects = recipients.map((recipient) =>
193
- convertAddressArg(this.txBlock, recipient)
207
+ convertAddressArg(this.tx, recipient)
194
208
  );
195
209
  recipientObjects.forEach((address, index) => {
196
- this.txBlock.transferObjects([coins[index]], address);
210
+ this.tx.transferObjects([coins[index]], address);
197
211
  });
198
212
  return this;
199
213
  }
200
214
 
201
- transferSui(address: SuiAddressArg, amount: SuiTxArg) {
215
+ transferSui(address: SuiAddressArg, amount: SuiTxArg | number | bigint) {
202
216
  return this.transferSuiToMany([address], [amount]);
203
217
  }
204
218
 
205
- takeAmountFromCoins(coins: SuiObjectArg[], amount: SuiTxArg) {
206
- const coinObjects = coins.map((coin) => convertObjArg(this.txBlock, coin));
219
+ takeAmountFromCoins(
220
+ coins: SuiObjectArg[],
221
+ amount: SuiTxArg | number | bigint
222
+ ) {
223
+ const coinObjects = coins.map((coin) => convertObjArg(this.tx, coin));
207
224
  const mergedCoin = coinObjects[0];
208
225
  if (coins.length > 1) {
209
- this.txBlock.mergeCoins(mergedCoin, coinObjects.slice(1));
226
+ this.tx.mergeCoins(mergedCoin, coinObjects.slice(1));
210
227
  }
211
- const [sendCoin] = this.txBlock.splitCoins(
212
- mergedCoin,
213
- convertArgs(this.txBlock, [amount])
214
- );
228
+ const [sendCoin] = this.tx.splitCoins(mergedCoin, [
229
+ typeof amount === 'number' || typeof amount === 'bigint'
230
+ ? amount
231
+ : convertArgs(this.tx, [amount])[0],
232
+ ]);
215
233
  return [sendCoin, mergedCoin];
216
234
  }
217
235
 
218
236
  splitSUIFromGas(amounts: SuiTxArg[]) {
219
- return this.txBlock.splitCoins(
220
- this.txBlock.gas,
221
- convertArgs(this.txBlock, amounts)
222
- );
237
+ return this.tx.splitCoins(this.tx.gas, convertArgs(this.tx, amounts));
223
238
  }
224
239
 
225
- splitMultiCoins(coins: SuiObjectArg[], amounts: SuiTxArg[]) {
226
- const coinObjects = coins.map((coin) => convertObjArg(this.txBlock, coin));
240
+ splitMultiCoins(coins: SuiObjectArg[], amounts: SuiAmountsArg[]) {
241
+ const coinObjects = coins.map((coin) => convertObjArg(this.tx, coin));
227
242
  const mergedCoin = coinObjects[0];
228
243
  if (coins.length > 1) {
229
- this.txBlock.mergeCoins(mergedCoin, coinObjects.slice(1));
244
+ this.tx.mergeCoins(mergedCoin, coinObjects.slice(1));
230
245
  }
231
- const splitedCoins = this.txBlock.splitCoins(
246
+ const splitedCoins = this.tx.splitCoins(
232
247
  mergedCoin,
233
- convertArgs(this.txBlock, amounts)
248
+ convertAmounts(this.tx, amounts)
234
249
  );
235
250
  return { splitedCoins, mergedCoin };
236
251
  }
@@ -239,7 +254,7 @@ export class SuiTxBlock {
239
254
  coins: SuiObjectArg[],
240
255
  sender: SuiAddressArg,
241
256
  recipients: SuiAddressArg[],
242
- amounts: SuiTxArg[]
257
+ amounts: SuiAmountsArg[]
243
258
  ) {
244
259
  // require recipients.length === amounts.length
245
260
  if (recipients.length !== amounts.length) {
@@ -247,21 +262,18 @@ export class SuiTxBlock {
247
262
  'transferSuiToMany: recipients.length !== amounts.length'
248
263
  );
249
264
  }
250
- const coinObjects = coins.map((coin) => convertObjArg(this.txBlock, coin));
265
+ const coinObjects = coins.map((coin) => convertObjArg(this.tx, coin));
251
266
  const { splitedCoins, mergedCoin } = this.splitMultiCoins(
252
267
  coinObjects,
253
268
  amounts
254
269
  );
255
270
  const recipientObjects = recipients.map((recipient) =>
256
- convertAddressArg(this.txBlock, recipient)
271
+ convertAddressArg(this.tx, recipient)
257
272
  );
258
273
  recipientObjects.forEach((address, index) => {
259
- this.txBlock.transferObjects([splitedCoins[index]], address);
274
+ this.tx.transferObjects([splitedCoins[index]], address);
260
275
  });
261
- this.txBlock.transferObjects(
262
- [mergedCoin],
263
- convertAddressArg(this.txBlock, sender)
264
- );
276
+ this.tx.transferObjects([mergedCoin], convertAddressArg(this.tx, sender));
265
277
  return this;
266
278
  }
267
279
 
@@ -274,17 +286,17 @@ export class SuiTxBlock {
274
286
  return this.transferCoinToMany(coins, sender, [recipient], [amount]);
275
287
  }
276
288
 
277
- stakeSui(amount: SuiTxArg, validatorAddr: SuiAddressArg) {
278
- const [stakeCoin] = this.txBlock.splitCoins(
279
- this.txBlock.gas,
280
- convertArgs(this.txBlock, [amount])
289
+ stakeSui(amount: SuiTxArg | number | bigint, validatorAddr: SuiAddressArg) {
290
+ const [stakeCoin] = this.tx.splitCoins(
291
+ this.tx.gas,
292
+ convertAmounts(this.tx, [amount])
281
293
  );
282
- return this.txBlock.moveCall({
294
+ return this.tx.moveCall({
283
295
  target: '0x3::sui_system::request_add_stake',
284
- arguments: convertArgs(this.txBlock, [
285
- SUI_SYSTEM_STATE_OBJECT_ID,
296
+ arguments: convertArgs(this.tx, [
297
+ this.tx.object(SUI_SYSTEM_STATE_OBJECT_ID),
286
298
  stakeCoin,
287
- this.txBlock.pure(validatorAddr),
299
+ convertAddressArg(this.tx, validatorAddr),
288
300
  ]),
289
301
  });
290
302
  }
@@ -3,26 +3,25 @@ import {
3
3
  normalizeSuiAddress,
4
4
  isValidSuiObjectId,
5
5
  isValidSuiAddress,
6
- } from '@mysten/sui.js/utils';
7
- import { Inputs } from '@mysten/sui.js/transactions';
8
- import { isPureArg } from '@mysten/sui.js/bcs';
9
- import { isSerializedBcs } from '@mysten/bcs';
6
+ } from '@mysten/sui/utils';
7
+ import { Inputs, getPureBcsSchema } from '@mysten/sui/transactions';
8
+ import { SerializedBcs, bcs, isSerializedBcs } from '@mysten/bcs';
10
9
  import type {
11
10
  TransactionArgument,
12
- TransactionBlock,
11
+ Transaction,
13
12
  TransactionObjectArgument,
14
- } from '@mysten/sui.js/transactions';
13
+ } from '@mysten/sui/transactions';
15
14
  import type {
16
- SuiInputTypes,
17
15
  SuiObjectArg,
18
16
  SuiAddressArg,
19
17
  SuiTxArg,
20
18
  SuiVecTxArg,
21
- } from '../../types';
19
+ SuiInputTypes,
20
+ } from 'src/types';
22
21
 
23
22
  export const getDefaultSuiInputType = (
24
23
  value: SuiTxArg
25
- ): SuiInputTypes | undefined => {
24
+ ): 'u64' | 'bool' | 'object' | undefined => {
26
25
  if (typeof value === 'string' && isValidSuiObjectId(value)) {
27
26
  return 'object';
28
27
  } else if (typeof value === 'number' || typeof value === 'bigint') {
@@ -48,7 +47,7 @@ export const getDefaultSuiInputType = (
48
47
  * @param type 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256' | 'signer' | 'object' | string
49
48
  */
50
49
  export function makeVecParam(
51
- txBlock: TransactionBlock,
50
+ txBlock: Transaction,
52
51
  args: SuiTxArg[],
53
52
  type?: SuiInputTypes
54
53
  ): TransactionArgument {
@@ -62,23 +61,24 @@ export function makeVecParam(
62
61
  type = type || defaultSuiType;
63
62
 
64
63
  if (type === 'object') {
65
- const objects = args.map((arg) =>
64
+ const elements = args.map((arg) =>
66
65
  typeof arg === 'string' && isValidSuiObjectId(arg)
67
66
  ? txBlock.object(normalizeSuiObjectId(arg))
68
67
  : convertObjArg(txBlock, arg as SuiObjectArg)
69
68
  );
70
- return txBlock.makeMoveVec({ objects });
69
+ return txBlock.makeMoveVec({ elements });
71
70
  } else if (
72
71
  typeof type === 'string' &&
73
72
  !VECTOR_REGEX.test(type) &&
74
73
  !STRUCT_REGEX.test(type)
75
74
  ) {
76
- return txBlock.pure(args, `vector<${type}>`);
75
+ const bcsSchema = getPureBcsSchema(type)!;
76
+ return txBlock.pure(bcs.vector(bcsSchema).serialize(args));
77
77
  } else {
78
- const objects = args.map((arg) =>
78
+ const elements = args.map((arg) =>
79
79
  convertObjArg(txBlock, arg as SuiObjectArg)
80
80
  );
81
- return txBlock.makeMoveVec({ objects, type });
81
+ return txBlock.makeMoveVec({ elements, type });
82
82
  }
83
83
  }
84
84
 
@@ -105,29 +105,22 @@ export function isMoveVecArg(arg: SuiTxArg | SuiVecTxArg): arg is SuiVecTxArg {
105
105
  * @returns The converted array of TransactionArgument.
106
106
  */
107
107
  export function convertArgs(
108
- txBlock: TransactionBlock,
108
+ txBlock: Transaction,
109
109
  args: (SuiTxArg | SuiVecTxArg)[]
110
- ) {
110
+ ): TransactionArgument[] {
111
111
  return args.map((arg) => {
112
- if (typeof arg === 'string' && isValidSuiObjectId(arg)) {
113
- return txBlock.object(normalizeSuiObjectId(arg));
114
- } else if (
115
- typeof arg == 'object' &&
116
- !isSerializedBcs(arg) &&
117
- !isPureArg(arg) &&
118
- !isMoveVecArg(arg)
119
- ) {
120
- return convertObjArg(txBlock, arg as SuiObjectArg);
121
- } else if (isMoveVecArg(arg)) {
112
+ if (arg instanceof SerializedBcs || isSerializedBcs(arg)) {
113
+ return txBlock.pure(arg);
114
+ }
115
+
116
+ if (isMoveVecArg(arg)) {
122
117
  const vecType = 'vecType' in arg;
123
118
  return vecType
124
119
  ? makeVecParam(txBlock, arg.value, arg.vecType)
125
120
  : makeVecParam(txBlock, arg);
126
- } else if (isSerializedBcs(arg)) {
127
- return arg;
128
- } else {
129
- return txBlock.pure(arg);
130
121
  }
122
+
123
+ return arg;
131
124
  });
132
125
  }
133
126
 
@@ -139,21 +132,13 @@ export function convertArgs(
139
132
  * @returns The converted TransactionArgument.
140
133
  */
141
134
  export function convertAddressArg(
142
- txBlock: TransactionBlock,
135
+ txBlock: Transaction,
143
136
  arg: SuiAddressArg
144
- ) {
137
+ ): TransactionArgument {
145
138
  if (typeof arg === 'string' && isValidSuiAddress(arg)) {
146
139
  return txBlock.pure.address(normalizeSuiAddress(arg));
147
- } else if (
148
- typeof arg == 'object' &&
149
- !isSerializedBcs(arg) &&
150
- !isPureArg(arg)
151
- ) {
152
- return convertObjArg(txBlock, arg as SuiObjectArg);
153
- } else if (isPureArg(arg)) {
154
- return txBlock.pure(arg);
155
140
  } else {
156
- return arg;
141
+ return convertArgs(txBlock, [arg])[0];
157
142
  }
158
143
  }
159
144
 
@@ -165,7 +150,7 @@ export function convertAddressArg(
165
150
  * @returns The converted TransactionArgument.
166
151
  */
167
152
  export function convertObjArg(
168
- txb: TransactionBlock,
153
+ txb: Transaction,
169
154
  arg: SuiObjectArg
170
155
  ): TransactionObjectArgument {
171
156
  if (typeof arg === 'string') {
@@ -181,18 +166,40 @@ export function convertObjArg(
181
166
  }
182
167
 
183
168
  if ('Object' in arg) {
184
- if ('ImmOrOwned' in arg.Object) {
185
- return txb.object(Inputs.ObjectRef(arg.Object.ImmOrOwned));
186
- } else if ('Shared' in arg.Object) {
187
- return txb.object(Inputs.SharedObjectRef(arg.Object.Shared));
169
+ if ('ImmOrOwnedObject' in arg.Object) {
170
+ return txb.object(Inputs.ObjectRef(arg.Object.ImmOrOwnedObject));
171
+ } else if ('SharedObject' in arg.Object) {
172
+ return txb.object(Inputs.SharedObjectRef(arg.Object.SharedObject));
188
173
  } else {
189
174
  throw new Error('Invalid argument type');
190
175
  }
191
176
  }
192
177
 
193
- if ('kind' in arg) {
178
+ if (typeof arg === 'function') {
179
+ return arg;
180
+ }
181
+
182
+ if (
183
+ 'GasCoin' in arg ||
184
+ 'Input' in arg ||
185
+ 'Result' in arg ||
186
+ 'NestedResult' in arg
187
+ ) {
194
188
  return arg;
195
189
  }
196
190
 
197
191
  throw new Error('Invalid argument type');
198
192
  }
193
+
194
+ export function convertAmounts(
195
+ txBlock: Transaction,
196
+ amounts: (SuiTxArg | number | bigint)[]
197
+ ): (TransactionArgument | number | bigint)[] {
198
+ return amounts.map((amount) => {
199
+ if (typeof amount === 'number' || typeof amount === 'bigint') {
200
+ return amount;
201
+ } else {
202
+ return convertArgs(txBlock, [amount])[0];
203
+ }
204
+ });
205
+ }
@@ -1,8 +1,7 @@
1
- import { SuiMoveNormalizedModules } from '@mysten/sui.js/client';
2
- import { getFullnodeUrl } from '@mysten/sui.js/client';
1
+ import { SuiMoveNormalizedModules } from '@mysten/sui/client';
2
+ import { getFullnodeUrl } from '@mysten/sui/client';
3
3
 
4
4
  import { SuiInteractor } from '../libs/suiInteractor';
5
-
6
5
  import { NetworkType } from '../types';
7
6
 
8
7
  export async function loadMetadata(