@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
package/dist/index.js CHANGED
@@ -44,13 +44,13 @@ var __privateAdd = (obj, member, value) => {
44
44
  // src/index.ts
45
45
  var src_exports = {};
46
46
  __export(src_exports, {
47
- BcsType: () => import_bcs4.BcsType,
47
+ BcsType: () => import_bcs3.BcsType,
48
48
  MultiSigClient: () => MultiSigClient,
49
49
  Obelisk: () => Obelisk,
50
50
  SuiAccountManager: () => SuiAccountManager,
51
51
  SuiContractFactory: () => SuiContractFactory,
52
52
  SuiTx: () => SuiTx,
53
- bcs: () => import_bcs4.bcs,
53
+ bcs: () => import_bcs3.bcs,
54
54
  loadMetadata: () => loadMetadata
55
55
  });
56
56
  module.exports = __toCommonJS(src_exports);
@@ -61,7 +61,7 @@ __reExport(src_exports, require("@mysten/sui/bcs"), module.exports);
61
61
  __reExport(src_exports, require("@mysten/sui/keypairs/ed25519"), module.exports);
62
62
  __reExport(src_exports, require("@mysten/sui/keypairs/secp256k1"), module.exports);
63
63
  __reExport(src_exports, require("@mysten/sui/keypairs/secp256r1"), module.exports);
64
- var import_bcs4 = require("@mysten/bcs");
64
+ var import_bcs3 = require("@mysten/bcs");
65
65
 
66
66
  // src/obelisk.ts
67
67
  var import_keccak256 = __toESM(require("keccak256"));
@@ -70,7 +70,6 @@ var import_transactions3 = require("@mysten/sui/transactions");
70
70
 
71
71
  // src/libs/suiAccountManager/index.ts
72
72
  var import_ed255192 = require("@mysten/sui/keypairs/ed25519");
73
- var import_cryptography = require("@mysten/sui/cryptography");
74
73
 
75
74
  // src/libs/suiAccountManager/keypair.ts
76
75
  var import_ed25519 = require("@mysten/sui/keypairs/ed25519");
@@ -132,6 +131,7 @@ var generateMnemonic = (numberOfWords = 24) => {
132
131
  };
133
132
 
134
133
  // src/libs/suiAccountManager/index.ts
134
+ var import_cryptography = require("@mysten/sui/cryptography");
135
135
  var SuiAccountManager = class {
136
136
  /**
137
137
  * Support the following ways to init the SuiToolkit:
@@ -205,7 +205,6 @@ var import_utils3 = require("@mysten/sui/utils");
205
205
  var import_utils2 = require("@mysten/sui/utils");
206
206
  var import_transactions = require("@mysten/sui/transactions");
207
207
  var import_bcs = require("@mysten/bcs");
208
- var import_bcs2 = require("@mysten/sui/bcs");
209
208
  var getDefaultSuiInputType = (value) => {
210
209
  if (typeof value === "string" && (0, import_utils2.isValidSuiObjectId)(value)) {
211
210
  return "object";
@@ -217,10 +216,7 @@ var getDefaultSuiInputType = (value) => {
217
216
  return void 0;
218
217
  }
219
218
  };
220
- function isPureArg(arg) {
221
- return arg.Pure !== void 0;
222
- }
223
- function makeVecParam(tx, args, type) {
219
+ function makeVecParam(txBlock, args, type) {
224
220
  if (args.length === 0)
225
221
  throw new Error("Transaction builder error: Empty array is not allowed");
226
222
  const defaultSuiType = getDefaultSuiInputType(args[0]);
@@ -229,32 +225,17 @@ function makeVecParam(tx, args, type) {
229
225
  type = type || defaultSuiType;
230
226
  if (type === "object") {
231
227
  const elements = args.map(
232
- (arg) => typeof arg === "string" && (0, import_utils2.isValidSuiObjectId)(arg) ? tx.object((0, import_utils2.normalizeSuiObjectId)(arg)) : convertObjArg(tx, arg)
228
+ (arg) => typeof arg === "string" && (0, import_utils2.isValidSuiObjectId)(arg) ? txBlock.object((0, import_utils2.normalizeSuiObjectId)(arg)) : convertObjArg(txBlock, arg)
233
229
  );
234
- return tx.makeMoveVec({ elements });
230
+ return txBlock.makeMoveVec({ elements });
235
231
  } else if (typeof type === "string" && !VECTOR_REGEX.test(type) && !STRUCT_REGEX.test(type)) {
236
- if (type === "address") {
237
- return tx.pure(import_bcs2.bcs.vector(import_bcs2.bcs.Address).serialize(args));
238
- } else if (type === "bool") {
239
- return tx.pure(import_bcs2.bcs.vector(import_bcs2.bcs.Bool).serialize(args));
240
- } else if (type === "u8") {
241
- return tx.pure(import_bcs2.bcs.vector(import_bcs2.bcs.U8).serialize(args));
242
- } else if (type === "u16") {
243
- return tx.pure(import_bcs2.bcs.vector(import_bcs2.bcs.U16).serialize(args));
244
- } else if (type === "u32") {
245
- return tx.pure(import_bcs2.bcs.vector(import_bcs2.bcs.U32).serialize(args));
246
- } else if (type === "u64") {
247
- return tx.pure(import_bcs2.bcs.vector(import_bcs2.bcs.U64).serialize(args));
248
- } else if (type === "u128") {
249
- return tx.pure(import_bcs2.bcs.vector(import_bcs2.bcs.U128).serialize(args));
250
- } else if (type === "u256") {
251
- return tx.pure(import_bcs2.bcs.vector(import_bcs2.bcs.U256).serialize(args));
252
- } else {
253
- return tx.pure(import_bcs2.bcs.vector(import_bcs2.bcs.U8).serialize(args));
254
- }
232
+ const bcsSchema = (0, import_transactions.getPureBcsSchema)(type);
233
+ return txBlock.pure(import_bcs.bcs.vector(bcsSchema).serialize(args));
255
234
  } else {
256
- const elements = args.map((arg) => convertObjArg(tx, arg));
257
- return tx.makeMoveVec({ elements, type });
235
+ const elements = args.map(
236
+ (arg) => convertObjArg(txBlock, arg)
237
+ );
238
+ return txBlock.makeMoveVec({ elements, type });
258
239
  }
259
240
  }
260
241
  function isMoveVecArg(arg) {
@@ -265,74 +246,61 @@ function isMoveVecArg(arg) {
265
246
  }
266
247
  return false;
267
248
  }
268
- function convertArgs(tx, args) {
249
+ function convertArgs(txBlock, args) {
269
250
  return args.map((arg) => {
270
- if (typeof arg === "string" && (0, import_utils2.isValidSuiObjectId)(arg)) {
271
- return tx.object((0, import_utils2.normalizeSuiObjectId)(arg));
272
- } else if (typeof arg == "object" && !(0, import_bcs.isSerializedBcs)(arg) && !isPureArg(arg) && !isMoveVecArg(arg)) {
273
- return convertObjArg(tx, arg);
274
- } else if (isMoveVecArg(arg)) {
251
+ if (arg instanceof import_bcs.SerializedBcs || (0, import_bcs.isSerializedBcs)(arg)) {
252
+ return txBlock.pure(arg);
253
+ }
254
+ if (isMoveVecArg(arg)) {
275
255
  const vecType = "vecType" in arg;
276
- return vecType ? makeVecParam(tx, arg.value, arg.vecType) : makeVecParam(tx, arg);
277
- } else if ((0, import_bcs.isSerializedBcs)(arg)) {
278
- return arg;
279
- } else {
280
- let argType = getDefaultSuiInputType(arg);
281
- if (argType === "address") {
282
- return tx.pure.address(arg);
283
- } else if (argType === "u64") {
284
- return tx.pure.u64(arg);
285
- } else if (argType === "bool") {
286
- return tx.pure.bool(arg);
287
- } else {
288
- return tx.pure.u64(arg);
289
- }
256
+ return vecType ? makeVecParam(txBlock, arg.value, arg.vecType) : makeVecParam(txBlock, arg);
290
257
  }
258
+ return arg;
291
259
  });
292
260
  }
293
- function convertAddressArg(tx, arg) {
261
+ function convertAddressArg(txBlock, arg) {
294
262
  if (typeof arg === "string" && (0, import_utils2.isValidSuiAddress)(arg)) {
295
- return tx.pure.address((0, import_utils2.normalizeSuiAddress)(arg));
296
- } else if (typeof arg == "object" && !(0, import_bcs.isSerializedBcs)(arg) && !isPureArg(arg)) {
297
- return convertObjArg(tx, arg);
298
- } else if (isPureArg(arg)) {
299
- return tx.pure(Uint8Array.from(arg.Pure));
263
+ return txBlock.pure.address((0, import_utils2.normalizeSuiAddress)(arg));
300
264
  } else {
301
- return arg;
265
+ return convertArgs(txBlock, [arg])[0];
302
266
  }
303
267
  }
304
- function convertObjArg(tx, arg) {
268
+ function convertObjArg(txb, arg) {
305
269
  if (typeof arg === "string") {
306
- return tx.object(arg);
270
+ return txb.object(arg);
307
271
  }
308
272
  if ("digest" in arg && "version" in arg && "objectId" in arg) {
309
- return tx.objectRef(arg);
273
+ return txb.objectRef(arg);
310
274
  }
311
275
  if ("objectId" in arg && "initialSharedVersion" in arg && "mutable" in arg) {
312
- return tx.sharedObjectRef(arg);
276
+ return txb.sharedObjectRef(arg);
313
277
  }
314
278
  if ("Object" in arg) {
315
279
  if ("ImmOrOwnedObject" in arg.Object) {
316
- return tx.object(
317
- import_transactions.Inputs.ObjectRef(arg.Object.ImmOrOwnedObject)
318
- );
280
+ return txb.object(import_transactions.Inputs.ObjectRef(arg.Object.ImmOrOwnedObject));
319
281
  } else if ("SharedObject" in arg.Object) {
320
- return tx.object(
321
- import_transactions.Inputs.SharedObjectRef(
322
- arg.Object.SharedObject
323
- )
324
- );
325
- } else if ("Receiving" in arg.Object) {
326
- return tx.object(import_transactions.Inputs.ReceivingRef(arg.Object.Receiving));
282
+ return txb.object(import_transactions.Inputs.SharedObjectRef(arg.Object.SharedObject));
327
283
  } else {
328
284
  throw new Error("Invalid argument type");
329
285
  }
330
286
  }
331
- if ("kind" in arg) {
287
+ if (typeof arg === "function") {
288
+ return arg;
289
+ }
290
+ if ("GasCoin" in arg || "Input" in arg || "Result" in arg || "NestedResult" in arg) {
332
291
  return arg;
333
292
  }
334
293
  throw new Error("Invalid argument type");
335
294
  }
295
+ function convertAmounts(txBlock, amounts) {
296
+ return amounts.map((amount) => {
297
+ if (typeof amount === "number" || typeof amount === "bigint") {
298
+ return amount;
299
+ } else {
300
+ return convertArgs(txBlock, [amount])[0];
301
+ }
302
+ });
303
+ }
336
304
 
337
305
  // src/libs/suiTxBuilder/index.ts
338
306
  var SuiTx = class {
@@ -359,8 +327,8 @@ var SuiTx = class {
359
327
  address(value) {
360
328
  return this.tx.pure.address(value);
361
329
  }
362
- pure(value) {
363
- return this.tx.pure(value);
330
+ get pure() {
331
+ return this.tx.pure.bind(this.tx);
364
332
  }
365
333
  object(value) {
366
334
  return this.tx.object(value);
@@ -395,6 +363,9 @@ var SuiTx = class {
395
363
  serialize() {
396
364
  return this.tx.serialize();
397
365
  }
366
+ toJSON() {
367
+ return this.tx.toJSON();
368
+ }
398
369
  sign(params) {
399
370
  return this.tx.sign(params);
400
371
  }
@@ -413,24 +384,11 @@ var SuiTx = class {
413
384
  }) {
414
385
  return this.tx.publish({ modules, dependencies });
415
386
  }
416
- upgrade({
417
- modules,
418
- dependencies,
419
- package: packageId,
420
- ticket
421
- }) {
422
- return this.tx.upgrade({
423
- modules,
424
- dependencies,
425
- package: packageId,
426
- ticket
427
- });
387
+ upgrade(...args) {
388
+ return this.tx.upgrade(...args);
428
389
  }
429
- makeMoveVec({
430
- elements,
431
- type
432
- }) {
433
- return this.tx.makeMoveVec({ elements, type });
390
+ makeMoveVec(...args) {
391
+ return this.tx.makeMoveVec(...args);
434
392
  }
435
393
  /* Override methods of TransactionBlock */
436
394
  transferObjects(objects, address) {
@@ -482,7 +440,9 @@ var SuiTx = class {
482
440
  }
483
441
  const coins = this.tx.splitCoins(
484
442
  this.tx.gas,
485
- convertArgs(this.tx, amounts)
443
+ amounts.map(
444
+ (amount) => typeof amount === "number" || typeof amount === "bigint" ? amount : convertArgs(this.tx, [amount])[0]
445
+ )
486
446
  );
487
447
  const recipientObjects = recipients.map(
488
448
  (recipient) => convertAddressArg(this.tx, recipient)
@@ -501,10 +461,9 @@ var SuiTx = class {
501
461
  if (coins.length > 1) {
502
462
  this.tx.mergeCoins(mergedCoin, coinObjects.slice(1));
503
463
  }
504
- const [sendCoin] = this.tx.splitCoins(
505
- mergedCoin,
506
- convertArgs(this.tx, [amount])
507
- );
464
+ const [sendCoin] = this.tx.splitCoins(mergedCoin, [
465
+ typeof amount === "number" || typeof amount === "bigint" ? amount : convertArgs(this.tx, [amount])[0]
466
+ ]);
508
467
  return [sendCoin, mergedCoin];
509
468
  }
510
469
  splitSUIFromGas(amounts) {
@@ -518,7 +477,7 @@ var SuiTx = class {
518
477
  }
519
478
  const splitedCoins = this.tx.splitCoins(
520
479
  mergedCoin,
521
- convertArgs(this.tx, amounts)
480
+ convertAmounts(this.tx, amounts)
522
481
  );
523
482
  return { splitedCoins, mergedCoin };
524
483
  }
@@ -548,14 +507,14 @@ var SuiTx = class {
548
507
  stakeSui(amount, validatorAddr) {
549
508
  const [stakeCoin] = this.tx.splitCoins(
550
509
  this.tx.gas,
551
- convertArgs(this.tx, [amount])
510
+ convertAmounts(this.tx, [amount])
552
511
  );
553
512
  return this.tx.moveCall({
554
513
  target: "0x3::sui_system::request_add_stake",
555
514
  arguments: convertArgs(this.tx, [
556
- import_utils3.SUI_SYSTEM_STATE_OBJECT_ID,
515
+ this.tx.object(import_utils3.SUI_SYSTEM_STATE_OBJECT_ID),
557
516
  stakeCoin,
558
- this.tx.pure.address(validatorAddr.toString())
517
+ convertAddressArg(this.tx, validatorAddr)
559
518
  ])
560
519
  });
561
520
  }
@@ -990,7 +949,7 @@ function numberToAddressHex(num) {
990
949
  }
991
950
 
992
951
  // src/obelisk.ts
993
- var import_bcs3 = require("@mysten/bcs");
952
+ var import_bcs2 = require("@mysten/bcs");
994
953
  function isUndefined(value) {
995
954
  return value === void 0;
996
955
  }
@@ -1015,7 +974,7 @@ function createTx(meta, fn) {
1015
974
  }
1016
975
  );
1017
976
  }
1018
- var _query, _tx, _struct, _exec, _read;
977
+ var _query, _tx, _object, _exec, _read, _bcs;
1019
978
  var Obelisk = class {
1020
979
  /**
1021
980
  * Support the following ways to init the ObeliskClient:
@@ -1039,7 +998,49 @@ var Obelisk = class {
1039
998
  } = {}) {
1040
999
  __privateAdd(this, _query, {});
1041
1000
  __privateAdd(this, _tx, {});
1042
- __privateAdd(this, _struct, {});
1001
+ __privateAdd(this, _object, {
1002
+ address: import_bcs2.bcs.bytes(32).transform({
1003
+ // To change the input type, you need to provide a type definition for the input
1004
+ input: (val) => (0, import_bcs2.fromHEX)(val),
1005
+ output: (val) => (0, import_bcs2.toHEX)(val)
1006
+ }),
1007
+ u8: import_bcs2.bcs.u8(),
1008
+ u16: import_bcs2.bcs.u16(),
1009
+ u32: import_bcs2.bcs.u32(),
1010
+ u64: import_bcs2.bcs.u64(),
1011
+ u128: import_bcs2.bcs.u128(),
1012
+ u256: import_bcs2.bcs.u256(),
1013
+ bool: import_bcs2.bcs.bool(),
1014
+ "0x1::ascii::String": import_bcs2.bcs.string(),
1015
+ "0x1::option::Option<address>": import_bcs2.bcs.option(
1016
+ import_bcs2.bcs.bytes(32).transform({
1017
+ // To change the input type, you need to provide a type definition for the input
1018
+ input: (val) => (0, import_bcs2.fromHEX)(val),
1019
+ output: (val) => (0, import_bcs2.toHEX)(val)
1020
+ })
1021
+ ),
1022
+ "0x1::option::Option<u8>": import_bcs2.bcs.option(import_bcs2.bcs.u8()),
1023
+ "0x1::option::Option<u16>": import_bcs2.bcs.option(import_bcs2.bcs.u16()),
1024
+ "0x1::option::Option<u32>": import_bcs2.bcs.option(import_bcs2.bcs.u32()),
1025
+ "0x1::option::Option<u64>": import_bcs2.bcs.option(import_bcs2.bcs.u64()),
1026
+ "0x1::option::Option<u128>": import_bcs2.bcs.option(import_bcs2.bcs.u128()),
1027
+ "0x1::option::Option<u256>": import_bcs2.bcs.option(import_bcs2.bcs.u256()),
1028
+ "0x1::option::Option<bool>": import_bcs2.bcs.option(import_bcs2.bcs.bool()),
1029
+ "vector<address>": import_bcs2.bcs.vector(
1030
+ import_bcs2.bcs.bytes(32).transform({
1031
+ // To change the input type, you need to provide a type definition for the input
1032
+ input: (val) => (0, import_bcs2.fromHEX)(val),
1033
+ output: (val) => (0, import_bcs2.toHEX)(val)
1034
+ })
1035
+ ),
1036
+ "vector<u8>": import_bcs2.bcs.vector(import_bcs2.bcs.u8()),
1037
+ "vector<u16>": import_bcs2.bcs.vector(import_bcs2.bcs.u16()),
1038
+ "vector<u32>": import_bcs2.bcs.vector(import_bcs2.bcs.u32()),
1039
+ "vector<u64>": import_bcs2.bcs.vector(import_bcs2.bcs.u64()),
1040
+ "vector<u128>": import_bcs2.bcs.vector(import_bcs2.bcs.u128()),
1041
+ "vector<u256>": import_bcs2.bcs.vector(import_bcs2.bcs.u256()),
1042
+ "vector<bool>": import_bcs2.bcs.vector(import_bcs2.bcs.bool())
1043
+ });
1043
1044
  __privateAdd(this, _exec, async (meta, tx, params, typeArguments, isRaw) => {
1044
1045
  if (isRaw === true) {
1045
1046
  return tx.moveCall({
@@ -1070,43 +1071,221 @@ var Obelisk = class {
1070
1071
  });
1071
1072
  return await this.inspectTxn(tx);
1072
1073
  });
1074
+ __privateAdd(this, _bcs, (bcsmeta) => {
1075
+ let loopFlag = false;
1076
+ const bcsJson = {};
1077
+ Object.entries(bcsmeta.objectType.fields).forEach(([index, type]) => {
1078
+ const objName = type.name;
1079
+ const objType = type.type;
1080
+ switch (typeof objType) {
1081
+ case "object":
1082
+ for (const [key, value] of Object.entries(objType)) {
1083
+ switch (key) {
1084
+ case "Struct":
1085
+ const structType = value;
1086
+ if (structType.address === "0x1" && structType.module === "ascii" && structType.name === "String") {
1087
+ bcsJson[objName] = import_bcs2.bcs.string();
1088
+ return;
1089
+ } else if (structType.address === "0x2" && structType.module === "object" && structType.name === "UID") {
1090
+ bcsJson[objName] = import_bcs2.bcs.fixedArray(32, import_bcs2.bcs.u8()).transform({
1091
+ input: (id) => (0, import_bcs2.fromHEX)(id),
1092
+ output: (id) => (0, import_bcs2.toHEX)(Uint8Array.from(id))
1093
+ });
1094
+ return;
1095
+ } else if (structType.address === "0x2" && structType.module === "object" && structType.name === "ID") {
1096
+ bcsJson[objName] = import_bcs2.bcs.fixedArray(32, import_bcs2.bcs.u8()).transform({
1097
+ input: (id) => (0, import_bcs2.fromHEX)(id),
1098
+ output: (id) => (0, import_bcs2.toHEX)(Uint8Array.from(id))
1099
+ });
1100
+ return;
1101
+ } else if (structType.address === "0x2" && structType.module === "bag" && structType.name === "Bag") {
1102
+ bcsJson[objName] = import_bcs2.bcs.fixedArray(32, import_bcs2.bcs.u8()).transform({
1103
+ input: (id) => (0, import_bcs2.fromHEX)(id),
1104
+ output: (id) => (0, import_bcs2.toHEX)(Uint8Array.from(id))
1105
+ });
1106
+ return;
1107
+ } else if (structType.address === "0x1" && structType.module === "option" && structType.name === "Option") {
1108
+ switch (structType.typeArguments[0]) {
1109
+ case "U8":
1110
+ bcsJson[objName] = import_bcs2.bcs.option(import_bcs2.bcs.u8());
1111
+ return;
1112
+ case "U16":
1113
+ bcsJson[objName] = import_bcs2.bcs.option(import_bcs2.bcs.u16());
1114
+ return;
1115
+ case "U32":
1116
+ bcsJson[objName] = import_bcs2.bcs.option(import_bcs2.bcs.u32());
1117
+ return;
1118
+ case "U64":
1119
+ bcsJson[objName] = import_bcs2.bcs.option(import_bcs2.bcs.u64());
1120
+ return;
1121
+ case "U128":
1122
+ bcsJson[objName] = import_bcs2.bcs.option(import_bcs2.bcs.u128());
1123
+ return;
1124
+ case "U256":
1125
+ bcsJson[objName] = import_bcs2.bcs.option(import_bcs2.bcs.u256());
1126
+ return;
1127
+ case "Bool":
1128
+ bcsJson[objName] = import_bcs2.bcs.option(import_bcs2.bcs.bool());
1129
+ return;
1130
+ case "Address":
1131
+ bcsJson[objName] = import_bcs2.bcs.option(
1132
+ import_bcs2.bcs.bytes(32).transform({
1133
+ // To change the input type, you need to provide a type definition for the input
1134
+ input: (val) => (0, import_bcs2.fromHEX)(val),
1135
+ output: (val) => (0, import_bcs2.toHEX)(val)
1136
+ })
1137
+ );
1138
+ return;
1139
+ default:
1140
+ }
1141
+ } else {
1142
+ if (this.object[`${structType.address}::${structType.module}::${structType.name}`] === void 0) {
1143
+ loopFlag = true;
1144
+ } else {
1145
+ bcsJson[objName] = this.object[`${structType.address}::${structType.module}::${structType.name}`];
1146
+ return;
1147
+ }
1148
+ }
1149
+ return;
1150
+ case "Vector":
1151
+ switch (value) {
1152
+ case "U8":
1153
+ bcsJson[objName] = import_bcs2.bcs.vector(import_bcs2.bcs.u8());
1154
+ return;
1155
+ case "U16":
1156
+ bcsJson[objName] = import_bcs2.bcs.vector(import_bcs2.bcs.u16());
1157
+ return;
1158
+ case "U32":
1159
+ bcsJson[objName] = import_bcs2.bcs.vector(import_bcs2.bcs.u32());
1160
+ return;
1161
+ case "U64":
1162
+ bcsJson[objName] = import_bcs2.bcs.vector(import_bcs2.bcs.u64());
1163
+ return;
1164
+ case "U128":
1165
+ bcsJson[objName] = import_bcs2.bcs.vector(import_bcs2.bcs.u128());
1166
+ return;
1167
+ case "U256":
1168
+ bcsJson[objName] = import_bcs2.bcs.vector(import_bcs2.bcs.u256());
1169
+ return;
1170
+ case "Bool":
1171
+ bcsJson[objName] = import_bcs2.bcs.vector(import_bcs2.bcs.bool());
1172
+ return;
1173
+ case "Address":
1174
+ bcsJson[objName] = import_bcs2.bcs.vector(
1175
+ import_bcs2.bcs.bytes(32).transform({
1176
+ // To change the input type, you need to provide a type definition for the input
1177
+ input: (val) => (0, import_bcs2.fromHEX)(val),
1178
+ output: (val) => (0, import_bcs2.toHEX)(val)
1179
+ })
1180
+ );
1181
+ return;
1182
+ default:
1183
+ }
1184
+ case "TypeParameter":
1185
+ bcsJson[objName] = import_bcs2.bcs.u128();
1186
+ return;
1187
+ default:
1188
+ throw new Error("Unsupported type");
1189
+ }
1190
+ }
1191
+ return;
1192
+ case "string":
1193
+ switch (objType) {
1194
+ case "U8":
1195
+ bcsJson[objName] = import_bcs2.bcs.u8();
1196
+ return;
1197
+ case "U16":
1198
+ bcsJson[objName] = import_bcs2.bcs.u16();
1199
+ return;
1200
+ case "U32":
1201
+ bcsJson[objName] = import_bcs2.bcs.u32();
1202
+ return;
1203
+ case "U64":
1204
+ bcsJson[objName] = import_bcs2.bcs.u64();
1205
+ return;
1206
+ case "U128":
1207
+ bcsJson[objName] = import_bcs2.bcs.u128();
1208
+ return;
1209
+ case "U256":
1210
+ bcsJson[objName] = import_bcs2.bcs.u256();
1211
+ return;
1212
+ case "Bool":
1213
+ bcsJson[objName] = import_bcs2.bcs.bool();
1214
+ return;
1215
+ case "Address":
1216
+ bcsJson[objName] = import_bcs2.bcs.bytes(32).transform({
1217
+ // To change the input type, you need to provide a type definition for the input
1218
+ input: (val) => (0, import_bcs2.fromHEX)(val),
1219
+ output: (val) => (0, import_bcs2.toHEX)(val)
1220
+ });
1221
+ return;
1222
+ default:
1223
+ return;
1224
+ }
1225
+ default:
1226
+ throw new Error("Unsupported type");
1227
+ }
1228
+ });
1229
+ return {
1230
+ bcs: import_bcs2.bcs.struct(bcsmeta.objectName, bcsJson),
1231
+ loopFlag
1232
+ };
1233
+ });
1073
1234
  this.accountManager = new SuiAccountManager({ mnemonics, secretKey });
1074
1235
  fullnodeUrls = fullnodeUrls || [(0, import_client2.getFullnodeUrl)(networkType ?? "mainnet")];
1075
1236
  this.suiInteractor = new SuiInteractor(fullnodeUrls, networkType);
1076
1237
  this.packageId = packageId;
1077
1238
  if (metadata !== void 0) {
1078
1239
  this.metadata = metadata;
1079
- Object.values(metadata).forEach(
1080
- (moudlevalue) => {
1081
- const data = moudlevalue;
1082
- const moduleName = data.name;
1083
- Object.entries(data.exposedFunctions).forEach(
1084
- ([funcName, funcvalue]) => {
1085
- const meta = funcvalue;
1086
- meta.moduleName = moduleName;
1087
- meta.funcName = funcName;
1088
- if (isUndefined(__privateGet(this, _query)[moduleName])) {
1089
- __privateGet(this, _query)[moduleName] = {};
1090
- }
1091
- if (isUndefined(__privateGet(this, _query)[moduleName][funcName])) {
1092
- __privateGet(this, _query)[moduleName][funcName] = createQuery(
1093
- meta,
1094
- (tx, p, typeArguments, isRaw) => __privateGet(this, _read).call(this, meta, tx, p, typeArguments, isRaw)
1095
- );
1240
+ let stillNeedFormat = true;
1241
+ while (stillNeedFormat === true) {
1242
+ let loopFlag = false;
1243
+ Object.values(metadata).forEach(
1244
+ (moudlevalue) => {
1245
+ const data = moudlevalue;
1246
+ const moduleName = data.name;
1247
+ const objMoudleId = `${packageId}::${moduleName}`;
1248
+ Object.entries(data.structs).forEach(([objectName, objectType]) => {
1249
+ const objId = `${objMoudleId}::${objectName}`;
1250
+ const bcsmeta = {
1251
+ objectName,
1252
+ objectType
1253
+ };
1254
+ let bcsObj = __privateGet(this, _bcs).call(this, bcsmeta);
1255
+ if (bcsObj.loopFlag === true) {
1256
+ loopFlag = bcsObj.loopFlag;
1096
1257
  }
1097
- if (isUndefined(__privateGet(this, _tx)[moduleName])) {
1098
- __privateGet(this, _tx)[moduleName] = {};
1258
+ __privateGet(this, _object)[objId] = bcsObj.bcs;
1259
+ });
1260
+ Object.entries(data.exposedFunctions).forEach(
1261
+ ([funcName, funcvalue]) => {
1262
+ const meta = funcvalue;
1263
+ meta.moduleName = moduleName;
1264
+ meta.funcName = funcName;
1265
+ if (isUndefined(__privateGet(this, _query)[moduleName])) {
1266
+ __privateGet(this, _query)[moduleName] = {};
1267
+ }
1268
+ if (isUndefined(__privateGet(this, _query)[moduleName][funcName])) {
1269
+ __privateGet(this, _query)[moduleName][funcName] = createQuery(
1270
+ meta,
1271
+ (tx, p, typeArguments, isRaw) => __privateGet(this, _read).call(this, meta, tx, p, typeArguments, isRaw)
1272
+ );
1273
+ }
1274
+ if (isUndefined(__privateGet(this, _tx)[moduleName])) {
1275
+ __privateGet(this, _tx)[moduleName] = {};
1276
+ }
1277
+ if (isUndefined(__privateGet(this, _tx)[moduleName][funcName])) {
1278
+ __privateGet(this, _tx)[moduleName][funcName] = createTx(
1279
+ meta,
1280
+ (tx, p, typeArguments, isRaw) => __privateGet(this, _exec).call(this, meta, tx, p, typeArguments, isRaw)
1281
+ );
1282
+ }
1099
1283
  }
1100
- if (isUndefined(__privateGet(this, _tx)[moduleName][funcName])) {
1101
- __privateGet(this, _tx)[moduleName][funcName] = createTx(
1102
- meta,
1103
- (tx, p, typeArguments, isRaw) => __privateGet(this, _exec).call(this, meta, tx, p, typeArguments, isRaw)
1104
- );
1105
- }
1106
- }
1107
- );
1108
- }
1109
- );
1284
+ );
1285
+ }
1286
+ );
1287
+ stillNeedFormat = loopFlag;
1288
+ }
1110
1289
  }
1111
1290
  this.contractFactory = new SuiContractFactory({
1112
1291
  packageId,
@@ -1119,8 +1298,23 @@ var Obelisk = class {
1119
1298
  get tx() {
1120
1299
  return __privateGet(this, _tx);
1121
1300
  }
1122
- get struct() {
1123
- return __privateGet(this, _struct);
1301
+ get object() {
1302
+ return __privateGet(this, _object);
1303
+ }
1304
+ view(dryResult) {
1305
+ let returnValues = [];
1306
+ if (dryResult.effects.status.status === "success") {
1307
+ const resultList = dryResult.results[0].returnValues;
1308
+ for (const res of resultList) {
1309
+ let baseValue = res[0];
1310
+ let baseType = res[1];
1311
+ const value = Uint8Array.from(baseValue);
1312
+ returnValues.push(this.object[baseType].parse(value));
1313
+ }
1314
+ return returnValues;
1315
+ } else {
1316
+ return void 0;
1317
+ }
1124
1318
  }
1125
1319
  /**
1126
1320
  * if derivePathParams is not provided or mnemonics is empty, it will return the keypair.
@@ -1338,50 +1532,11 @@ var Obelisk = class {
1338
1532
  if (entityId !== void 0) {
1339
1533
  params.push(tx.pure.address(entityId));
1340
1534
  }
1341
- const getResult = await this.query[schemaModuleName].get(
1535
+ const dryResult = await this.query[schemaModuleName].get(
1342
1536
  tx,
1343
1537
  params
1344
1538
  );
1345
- let returnValues = [];
1346
- if (getResult.effects.status.status === "success") {
1347
- const resultList = getResult.results[0].returnValues;
1348
- for (const res of resultList) {
1349
- let baseValue = res[0];
1350
- let baseType = res[1];
1351
- const value = Uint8Array.from(baseValue);
1352
- if (baseType === "address") {
1353
- const Address = import_bcs3.bcs.bytes(32).transform({
1354
- // To change the input type, you need to provide a type definition for the input
1355
- input: (val) => (0, import_bcs3.fromHEX)(val),
1356
- output: (val) => (0, import_bcs3.toHEX)(val)
1357
- });
1358
- returnValues.push(Address.parse(value));
1359
- } else if (baseType === "u8") {
1360
- returnValues.push(import_bcs3.bcs.u8().parse(value));
1361
- } else if (baseType === "u16") {
1362
- returnValues.push(import_bcs3.bcs.u16().parse(value));
1363
- } else if (baseType === "u32") {
1364
- returnValues.push(import_bcs3.bcs.u32().parse(value));
1365
- } else if (baseType === "u64") {
1366
- returnValues.push(import_bcs3.bcs.u64().parse(value));
1367
- } else if (baseType === "u128") {
1368
- returnValues.push(import_bcs3.bcs.u128().parse(value));
1369
- } else if (baseType === "u256") {
1370
- returnValues.push(import_bcs3.bcs.u256().parse(value));
1371
- } else if (baseType === "bool") {
1372
- returnValues.push(import_bcs3.bcs.bool().parse(value));
1373
- } else if (baseType === "0x1::ascii::String") {
1374
- returnValues.push(import_bcs3.bcs.string().parse(value));
1375
- } else if (baseType === "vector<u8>") {
1376
- returnValues.push(import_bcs3.bcs.vector(import_bcs3.bcs.u8()).parse(value));
1377
- } else if (baseType === "0x1::option::Option<u8>") {
1378
- returnValues.push(import_bcs3.bcs.option(import_bcs3.bcs.u8()).parse(value));
1379
- }
1380
- }
1381
- return returnValues;
1382
- } else {
1383
- return void 0;
1384
- }
1539
+ return this.view(dryResult);
1385
1540
  }
1386
1541
  async containEntity(worldId, schemaName, entityId) {
1387
1542
  const schemaModuleName = `${schemaName}_schema`;
@@ -1390,18 +1545,11 @@ var Obelisk = class {
1390
1545
  if (entityId !== void 0) {
1391
1546
  params.push(tx.pure.address(entityId));
1392
1547
  }
1393
- const getResult = await this.query[schemaModuleName].contains(
1548
+ const dryResult = await this.query[schemaModuleName].contains(
1394
1549
  tx,
1395
1550
  params
1396
1551
  );
1397
- if (getResult.effects.status.status === "success") {
1398
- const res = getResult.results[0].returnValues[0];
1399
- let baseValue = res[0];
1400
- const value = Uint8Array.from(baseValue);
1401
- return import_bcs3.bcs.bool().parse(value);
1402
- } else {
1403
- return void 0;
1404
- }
1552
+ return this.view(dryResult);
1405
1553
  }
1406
1554
  // async getEntities(
1407
1555
  // worldId: string,
@@ -1461,10 +1609,10 @@ var Obelisk = class {
1461
1609
  const hashBytes = (0, import_keccak256.default)(bytes);
1462
1610
  const hashU8Array = Array.from(hashBytes);
1463
1611
  const value = Uint8Array.from(hashU8Array);
1464
- const Address = import_bcs3.bcs.bytes(32).transform({
1612
+ const Address = import_bcs2.bcs.bytes(32).transform({
1465
1613
  // To change the input type, you need to provide a type definition for the input
1466
- input: (val) => (0, import_bcs3.fromHEX)(val),
1467
- output: (val) => (0, import_bcs3.toHEX)(val)
1614
+ input: (val) => (0, import_bcs2.fromHEX)(val),
1615
+ output: (val) => (0, import_bcs2.toHEX)(val)
1468
1616
  });
1469
1617
  const data = Address.parse(value);
1470
1618
  return "0x" + data;
@@ -1485,7 +1633,7 @@ var Obelisk = class {
1485
1633
  if (checkObjectId !== null) {
1486
1634
  objectId = checkObjectId;
1487
1635
  const bytes = Buffer.from(objectId.slice(2), "hex");
1488
- const numberBytes = import_bcs3.bcs.u256().serialize(x).toBytes();
1636
+ const numberBytes = import_bcs2.bcs.u256().serialize(x).toBytes();
1489
1637
  return this.entity_key_from_bytes(Buffer.concat([bytes, numberBytes]));
1490
1638
  } else {
1491
1639
  return void 0;
@@ -1498,54 +1646,13 @@ var Obelisk = class {
1498
1646
  // const u8Value = Uint8Array.from(value);
1499
1647
  // return bcs.de(type, u8Value);
1500
1648
  // }
1501
- async autoFormatDryValue(value) {
1502
- let returnValues = [];
1503
- if (value.effects.status.status === "success") {
1504
- const resultList = value.results[0].returnValues;
1505
- for (const res of resultList) {
1506
- let baseValue = res[0];
1507
- let baseType = res[1];
1508
- const value2 = Uint8Array.from(baseValue);
1509
- if (baseType === "address") {
1510
- const Address = import_bcs3.bcs.bytes(32).transform({
1511
- // To change the input type, you need to provide a type definition for the input
1512
- input: (val) => (0, import_bcs3.fromHEX)(val),
1513
- output: (val) => (0, import_bcs3.toHEX)(val)
1514
- });
1515
- returnValues.push(Address.parse(value2));
1516
- } else if (baseType === "u8") {
1517
- returnValues.push(import_bcs3.bcs.u8().parse(value2));
1518
- } else if (baseType === "u16") {
1519
- returnValues.push(import_bcs3.bcs.u16().parse(value2));
1520
- } else if (baseType === "u32") {
1521
- returnValues.push(import_bcs3.bcs.u32().parse(value2));
1522
- } else if (baseType === "u64") {
1523
- returnValues.push(import_bcs3.bcs.u64().parse(value2));
1524
- } else if (baseType === "u128") {
1525
- returnValues.push(import_bcs3.bcs.u128().parse(value2));
1526
- } else if (baseType === "u256") {
1527
- returnValues.push(import_bcs3.bcs.u256().parse(value2));
1528
- } else if (baseType === "bool") {
1529
- returnValues.push(import_bcs3.bcs.bool().parse(value2));
1530
- } else if (baseType === "0x1::ascii::String") {
1531
- returnValues.push(import_bcs3.bcs.string().parse(value2));
1532
- } else if (baseType === "vector<u8>") {
1533
- returnValues.push(import_bcs3.bcs.vector(import_bcs3.bcs.u8()).parse(value2));
1534
- } else if (baseType === "0x1::option::Option<u8>") {
1535
- returnValues.push(import_bcs3.bcs.option(import_bcs3.bcs.u8()).parse(value2));
1536
- }
1537
- }
1538
- return returnValues;
1539
- } else {
1540
- return void 0;
1541
- }
1542
- }
1543
1649
  };
1544
1650
  _query = new WeakMap();
1545
1651
  _tx = new WeakMap();
1546
- _struct = new WeakMap();
1652
+ _object = new WeakMap();
1547
1653
  _exec = new WeakMap();
1548
1654
  _read = new WeakMap();
1655
+ _bcs = new WeakMap();
1549
1656
 
1550
1657
  // src/libs/multiSig/client.ts
1551
1658
  var import_multisig = require("@mysten/sui/multisig");