@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.mjs CHANGED
@@ -29,10 +29,6 @@ import { Transaction as Transaction2 } from "@mysten/sui/transactions";
29
29
 
30
30
  // src/libs/suiAccountManager/index.ts
31
31
  import { Ed25519Keypair as Ed25519Keypair2 } from "@mysten/sui/keypairs/ed25519";
32
- import {
33
- SUI_PRIVATE_KEY_PREFIX,
34
- decodeSuiPrivateKey
35
- } from "@mysten/sui/cryptography";
36
32
 
37
33
  // src/libs/suiAccountManager/keypair.ts
38
34
  import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
@@ -94,6 +90,10 @@ var generateMnemonic = (numberOfWords = 24) => {
94
90
  };
95
91
 
96
92
  // src/libs/suiAccountManager/index.ts
93
+ import {
94
+ SUI_PRIVATE_KEY_PREFIX,
95
+ decodeSuiPrivateKey
96
+ } from "@mysten/sui/cryptography";
97
97
  var SuiAccountManager = class {
98
98
  /**
99
99
  * Support the following ways to init the SuiToolkit:
@@ -170,9 +170,8 @@ import {
170
170
  isValidSuiObjectId,
171
171
  isValidSuiAddress
172
172
  } from "@mysten/sui/utils";
173
- import { Inputs } from "@mysten/sui/transactions";
174
- import { isSerializedBcs } from "@mysten/bcs";
175
- import { bcs } from "@mysten/sui/bcs";
173
+ import { Inputs, getPureBcsSchema } from "@mysten/sui/transactions";
174
+ import { SerializedBcs, bcs, isSerializedBcs } from "@mysten/bcs";
176
175
  var getDefaultSuiInputType = (value) => {
177
176
  if (typeof value === "string" && isValidSuiObjectId(value)) {
178
177
  return "object";
@@ -184,10 +183,7 @@ var getDefaultSuiInputType = (value) => {
184
183
  return void 0;
185
184
  }
186
185
  };
187
- function isPureArg(arg) {
188
- return arg.Pure !== void 0;
189
- }
190
- function makeVecParam(tx, args, type) {
186
+ function makeVecParam(txBlock, args, type) {
191
187
  if (args.length === 0)
192
188
  throw new Error("Transaction builder error: Empty array is not allowed");
193
189
  const defaultSuiType = getDefaultSuiInputType(args[0]);
@@ -196,32 +192,17 @@ function makeVecParam(tx, args, type) {
196
192
  type = type || defaultSuiType;
197
193
  if (type === "object") {
198
194
  const elements = args.map(
199
- (arg) => typeof arg === "string" && isValidSuiObjectId(arg) ? tx.object(normalizeSuiObjectId(arg)) : convertObjArg(tx, arg)
195
+ (arg) => typeof arg === "string" && isValidSuiObjectId(arg) ? txBlock.object(normalizeSuiObjectId(arg)) : convertObjArg(txBlock, arg)
200
196
  );
201
- return tx.makeMoveVec({ elements });
197
+ return txBlock.makeMoveVec({ elements });
202
198
  } else if (typeof type === "string" && !VECTOR_REGEX.test(type) && !STRUCT_REGEX.test(type)) {
203
- if (type === "address") {
204
- return tx.pure(bcs.vector(bcs.Address).serialize(args));
205
- } else if (type === "bool") {
206
- return tx.pure(bcs.vector(bcs.Bool).serialize(args));
207
- } else if (type === "u8") {
208
- return tx.pure(bcs.vector(bcs.U8).serialize(args));
209
- } else if (type === "u16") {
210
- return tx.pure(bcs.vector(bcs.U16).serialize(args));
211
- } else if (type === "u32") {
212
- return tx.pure(bcs.vector(bcs.U32).serialize(args));
213
- } else if (type === "u64") {
214
- return tx.pure(bcs.vector(bcs.U64).serialize(args));
215
- } else if (type === "u128") {
216
- return tx.pure(bcs.vector(bcs.U128).serialize(args));
217
- } else if (type === "u256") {
218
- return tx.pure(bcs.vector(bcs.U256).serialize(args));
219
- } else {
220
- return tx.pure(bcs.vector(bcs.U8).serialize(args));
221
- }
199
+ const bcsSchema = getPureBcsSchema(type);
200
+ return txBlock.pure(bcs.vector(bcsSchema).serialize(args));
222
201
  } else {
223
- const elements = args.map((arg) => convertObjArg(tx, arg));
224
- return tx.makeMoveVec({ elements, type });
202
+ const elements = args.map(
203
+ (arg) => convertObjArg(txBlock, arg)
204
+ );
205
+ return txBlock.makeMoveVec({ elements, type });
225
206
  }
226
207
  }
227
208
  function isMoveVecArg(arg) {
@@ -232,74 +213,61 @@ function isMoveVecArg(arg) {
232
213
  }
233
214
  return false;
234
215
  }
235
- function convertArgs(tx, args) {
216
+ function convertArgs(txBlock, args) {
236
217
  return args.map((arg) => {
237
- if (typeof arg === "string" && isValidSuiObjectId(arg)) {
238
- return tx.object(normalizeSuiObjectId(arg));
239
- } else if (typeof arg == "object" && !isSerializedBcs(arg) && !isPureArg(arg) && !isMoveVecArg(arg)) {
240
- return convertObjArg(tx, arg);
241
- } else if (isMoveVecArg(arg)) {
218
+ if (arg instanceof SerializedBcs || isSerializedBcs(arg)) {
219
+ return txBlock.pure(arg);
220
+ }
221
+ if (isMoveVecArg(arg)) {
242
222
  const vecType = "vecType" in arg;
243
- return vecType ? makeVecParam(tx, arg.value, arg.vecType) : makeVecParam(tx, arg);
244
- } else if (isSerializedBcs(arg)) {
245
- return arg;
246
- } else {
247
- let argType = getDefaultSuiInputType(arg);
248
- if (argType === "address") {
249
- return tx.pure.address(arg);
250
- } else if (argType === "u64") {
251
- return tx.pure.u64(arg);
252
- } else if (argType === "bool") {
253
- return tx.pure.bool(arg);
254
- } else {
255
- return tx.pure.u64(arg);
256
- }
223
+ return vecType ? makeVecParam(txBlock, arg.value, arg.vecType) : makeVecParam(txBlock, arg);
257
224
  }
225
+ return arg;
258
226
  });
259
227
  }
260
- function convertAddressArg(tx, arg) {
228
+ function convertAddressArg(txBlock, arg) {
261
229
  if (typeof arg === "string" && isValidSuiAddress(arg)) {
262
- return tx.pure.address(normalizeSuiAddress(arg));
263
- } else if (typeof arg == "object" && !isSerializedBcs(arg) && !isPureArg(arg)) {
264
- return convertObjArg(tx, arg);
265
- } else if (isPureArg(arg)) {
266
- return tx.pure(Uint8Array.from(arg.Pure));
230
+ return txBlock.pure.address(normalizeSuiAddress(arg));
267
231
  } else {
268
- return arg;
232
+ return convertArgs(txBlock, [arg])[0];
269
233
  }
270
234
  }
271
- function convertObjArg(tx, arg) {
235
+ function convertObjArg(txb, arg) {
272
236
  if (typeof arg === "string") {
273
- return tx.object(arg);
237
+ return txb.object(arg);
274
238
  }
275
239
  if ("digest" in arg && "version" in arg && "objectId" in arg) {
276
- return tx.objectRef(arg);
240
+ return txb.objectRef(arg);
277
241
  }
278
242
  if ("objectId" in arg && "initialSharedVersion" in arg && "mutable" in arg) {
279
- return tx.sharedObjectRef(arg);
243
+ return txb.sharedObjectRef(arg);
280
244
  }
281
245
  if ("Object" in arg) {
282
246
  if ("ImmOrOwnedObject" in arg.Object) {
283
- return tx.object(
284
- Inputs.ObjectRef(arg.Object.ImmOrOwnedObject)
285
- );
247
+ return txb.object(Inputs.ObjectRef(arg.Object.ImmOrOwnedObject));
286
248
  } else if ("SharedObject" in arg.Object) {
287
- return tx.object(
288
- Inputs.SharedObjectRef(
289
- arg.Object.SharedObject
290
- )
291
- );
292
- } else if ("Receiving" in arg.Object) {
293
- return tx.object(Inputs.ReceivingRef(arg.Object.Receiving));
249
+ return txb.object(Inputs.SharedObjectRef(arg.Object.SharedObject));
294
250
  } else {
295
251
  throw new Error("Invalid argument type");
296
252
  }
297
253
  }
298
- if ("kind" in arg) {
254
+ if (typeof arg === "function") {
255
+ return arg;
256
+ }
257
+ if ("GasCoin" in arg || "Input" in arg || "Result" in arg || "NestedResult" in arg) {
299
258
  return arg;
300
259
  }
301
260
  throw new Error("Invalid argument type");
302
261
  }
262
+ function convertAmounts(txBlock, amounts) {
263
+ return amounts.map((amount) => {
264
+ if (typeof amount === "number" || typeof amount === "bigint") {
265
+ return amount;
266
+ } else {
267
+ return convertArgs(txBlock, [amount])[0];
268
+ }
269
+ });
270
+ }
303
271
 
304
272
  // src/libs/suiTxBuilder/index.ts
305
273
  var SuiTx = class {
@@ -326,8 +294,8 @@ var SuiTx = class {
326
294
  address(value) {
327
295
  return this.tx.pure.address(value);
328
296
  }
329
- pure(value) {
330
- return this.tx.pure(value);
297
+ get pure() {
298
+ return this.tx.pure.bind(this.tx);
331
299
  }
332
300
  object(value) {
333
301
  return this.tx.object(value);
@@ -362,6 +330,9 @@ var SuiTx = class {
362
330
  serialize() {
363
331
  return this.tx.serialize();
364
332
  }
333
+ toJSON() {
334
+ return this.tx.toJSON();
335
+ }
365
336
  sign(params) {
366
337
  return this.tx.sign(params);
367
338
  }
@@ -380,24 +351,11 @@ var SuiTx = class {
380
351
  }) {
381
352
  return this.tx.publish({ modules, dependencies });
382
353
  }
383
- upgrade({
384
- modules,
385
- dependencies,
386
- package: packageId,
387
- ticket
388
- }) {
389
- return this.tx.upgrade({
390
- modules,
391
- dependencies,
392
- package: packageId,
393
- ticket
394
- });
354
+ upgrade(...args) {
355
+ return this.tx.upgrade(...args);
395
356
  }
396
- makeMoveVec({
397
- elements,
398
- type
399
- }) {
400
- return this.tx.makeMoveVec({ elements, type });
357
+ makeMoveVec(...args) {
358
+ return this.tx.makeMoveVec(...args);
401
359
  }
402
360
  /* Override methods of TransactionBlock */
403
361
  transferObjects(objects, address) {
@@ -449,7 +407,9 @@ var SuiTx = class {
449
407
  }
450
408
  const coins = this.tx.splitCoins(
451
409
  this.tx.gas,
452
- convertArgs(this.tx, amounts)
410
+ amounts.map(
411
+ (amount) => typeof amount === "number" || typeof amount === "bigint" ? amount : convertArgs(this.tx, [amount])[0]
412
+ )
453
413
  );
454
414
  const recipientObjects = recipients.map(
455
415
  (recipient) => convertAddressArg(this.tx, recipient)
@@ -468,10 +428,9 @@ var SuiTx = class {
468
428
  if (coins.length > 1) {
469
429
  this.tx.mergeCoins(mergedCoin, coinObjects.slice(1));
470
430
  }
471
- const [sendCoin] = this.tx.splitCoins(
472
- mergedCoin,
473
- convertArgs(this.tx, [amount])
474
- );
431
+ const [sendCoin] = this.tx.splitCoins(mergedCoin, [
432
+ typeof amount === "number" || typeof amount === "bigint" ? amount : convertArgs(this.tx, [amount])[0]
433
+ ]);
475
434
  return [sendCoin, mergedCoin];
476
435
  }
477
436
  splitSUIFromGas(amounts) {
@@ -485,7 +444,7 @@ var SuiTx = class {
485
444
  }
486
445
  const splitedCoins = this.tx.splitCoins(
487
446
  mergedCoin,
488
- convertArgs(this.tx, amounts)
447
+ convertAmounts(this.tx, amounts)
489
448
  );
490
449
  return { splitedCoins, mergedCoin };
491
450
  }
@@ -515,14 +474,14 @@ var SuiTx = class {
515
474
  stakeSui(amount, validatorAddr) {
516
475
  const [stakeCoin] = this.tx.splitCoins(
517
476
  this.tx.gas,
518
- convertArgs(this.tx, [amount])
477
+ convertAmounts(this.tx, [amount])
519
478
  );
520
479
  return this.tx.moveCall({
521
480
  target: "0x3::sui_system::request_add_stake",
522
481
  arguments: convertArgs(this.tx, [
523
- SUI_SYSTEM_STATE_OBJECT_ID,
482
+ this.tx.object(SUI_SYSTEM_STATE_OBJECT_ID),
524
483
  stakeCoin,
525
- this.tx.pure.address(validatorAddr.toString())
484
+ convertAddressArg(this.tx, validatorAddr)
526
485
  ])
527
486
  });
528
487
  }
@@ -982,7 +941,7 @@ function createTx(meta, fn) {
982
941
  }
983
942
  );
984
943
  }
985
- var _query, _tx, _struct, _exec, _read;
944
+ var _query, _tx, _object, _exec, _read, _bcs;
986
945
  var Obelisk = class {
987
946
  /**
988
947
  * Support the following ways to init the ObeliskClient:
@@ -1006,7 +965,49 @@ var Obelisk = class {
1006
965
  } = {}) {
1007
966
  __privateAdd(this, _query, {});
1008
967
  __privateAdd(this, _tx, {});
1009
- __privateAdd(this, _struct, {});
968
+ __privateAdd(this, _object, {
969
+ address: bcs2.bytes(32).transform({
970
+ // To change the input type, you need to provide a type definition for the input
971
+ input: (val) => fromHEX2(val),
972
+ output: (val) => toHEX(val)
973
+ }),
974
+ u8: bcs2.u8(),
975
+ u16: bcs2.u16(),
976
+ u32: bcs2.u32(),
977
+ u64: bcs2.u64(),
978
+ u128: bcs2.u128(),
979
+ u256: bcs2.u256(),
980
+ bool: bcs2.bool(),
981
+ "0x1::ascii::String": bcs2.string(),
982
+ "0x1::option::Option<address>": bcs2.option(
983
+ bcs2.bytes(32).transform({
984
+ // To change the input type, you need to provide a type definition for the input
985
+ input: (val) => fromHEX2(val),
986
+ output: (val) => toHEX(val)
987
+ })
988
+ ),
989
+ "0x1::option::Option<u8>": bcs2.option(bcs2.u8()),
990
+ "0x1::option::Option<u16>": bcs2.option(bcs2.u16()),
991
+ "0x1::option::Option<u32>": bcs2.option(bcs2.u32()),
992
+ "0x1::option::Option<u64>": bcs2.option(bcs2.u64()),
993
+ "0x1::option::Option<u128>": bcs2.option(bcs2.u128()),
994
+ "0x1::option::Option<u256>": bcs2.option(bcs2.u256()),
995
+ "0x1::option::Option<bool>": bcs2.option(bcs2.bool()),
996
+ "vector<address>": bcs2.vector(
997
+ bcs2.bytes(32).transform({
998
+ // To change the input type, you need to provide a type definition for the input
999
+ input: (val) => fromHEX2(val),
1000
+ output: (val) => toHEX(val)
1001
+ })
1002
+ ),
1003
+ "vector<u8>": bcs2.vector(bcs2.u8()),
1004
+ "vector<u16>": bcs2.vector(bcs2.u16()),
1005
+ "vector<u32>": bcs2.vector(bcs2.u32()),
1006
+ "vector<u64>": bcs2.vector(bcs2.u64()),
1007
+ "vector<u128>": bcs2.vector(bcs2.u128()),
1008
+ "vector<u256>": bcs2.vector(bcs2.u256()),
1009
+ "vector<bool>": bcs2.vector(bcs2.bool())
1010
+ });
1010
1011
  __privateAdd(this, _exec, async (meta, tx, params, typeArguments, isRaw) => {
1011
1012
  if (isRaw === true) {
1012
1013
  return tx.moveCall({
@@ -1037,43 +1038,221 @@ var Obelisk = class {
1037
1038
  });
1038
1039
  return await this.inspectTxn(tx);
1039
1040
  });
1041
+ __privateAdd(this, _bcs, (bcsmeta) => {
1042
+ let loopFlag = false;
1043
+ const bcsJson = {};
1044
+ Object.entries(bcsmeta.objectType.fields).forEach(([index, type]) => {
1045
+ const objName = type.name;
1046
+ const objType = type.type;
1047
+ switch (typeof objType) {
1048
+ case "object":
1049
+ for (const [key, value] of Object.entries(objType)) {
1050
+ switch (key) {
1051
+ case "Struct":
1052
+ const structType = value;
1053
+ if (structType.address === "0x1" && structType.module === "ascii" && structType.name === "String") {
1054
+ bcsJson[objName] = bcs2.string();
1055
+ return;
1056
+ } else if (structType.address === "0x2" && structType.module === "object" && structType.name === "UID") {
1057
+ bcsJson[objName] = bcs2.fixedArray(32, bcs2.u8()).transform({
1058
+ input: (id) => fromHEX2(id),
1059
+ output: (id) => toHEX(Uint8Array.from(id))
1060
+ });
1061
+ return;
1062
+ } else if (structType.address === "0x2" && structType.module === "object" && structType.name === "ID") {
1063
+ bcsJson[objName] = bcs2.fixedArray(32, bcs2.u8()).transform({
1064
+ input: (id) => fromHEX2(id),
1065
+ output: (id) => toHEX(Uint8Array.from(id))
1066
+ });
1067
+ return;
1068
+ } else if (structType.address === "0x2" && structType.module === "bag" && structType.name === "Bag") {
1069
+ bcsJson[objName] = bcs2.fixedArray(32, bcs2.u8()).transform({
1070
+ input: (id) => fromHEX2(id),
1071
+ output: (id) => toHEX(Uint8Array.from(id))
1072
+ });
1073
+ return;
1074
+ } else if (structType.address === "0x1" && structType.module === "option" && structType.name === "Option") {
1075
+ switch (structType.typeArguments[0]) {
1076
+ case "U8":
1077
+ bcsJson[objName] = bcs2.option(bcs2.u8());
1078
+ return;
1079
+ case "U16":
1080
+ bcsJson[objName] = bcs2.option(bcs2.u16());
1081
+ return;
1082
+ case "U32":
1083
+ bcsJson[objName] = bcs2.option(bcs2.u32());
1084
+ return;
1085
+ case "U64":
1086
+ bcsJson[objName] = bcs2.option(bcs2.u64());
1087
+ return;
1088
+ case "U128":
1089
+ bcsJson[objName] = bcs2.option(bcs2.u128());
1090
+ return;
1091
+ case "U256":
1092
+ bcsJson[objName] = bcs2.option(bcs2.u256());
1093
+ return;
1094
+ case "Bool":
1095
+ bcsJson[objName] = bcs2.option(bcs2.bool());
1096
+ return;
1097
+ case "Address":
1098
+ bcsJson[objName] = bcs2.option(
1099
+ bcs2.bytes(32).transform({
1100
+ // To change the input type, you need to provide a type definition for the input
1101
+ input: (val) => fromHEX2(val),
1102
+ output: (val) => toHEX(val)
1103
+ })
1104
+ );
1105
+ return;
1106
+ default:
1107
+ }
1108
+ } else {
1109
+ if (this.object[`${structType.address}::${structType.module}::${structType.name}`] === void 0) {
1110
+ loopFlag = true;
1111
+ } else {
1112
+ bcsJson[objName] = this.object[`${structType.address}::${structType.module}::${structType.name}`];
1113
+ return;
1114
+ }
1115
+ }
1116
+ return;
1117
+ case "Vector":
1118
+ switch (value) {
1119
+ case "U8":
1120
+ bcsJson[objName] = bcs2.vector(bcs2.u8());
1121
+ return;
1122
+ case "U16":
1123
+ bcsJson[objName] = bcs2.vector(bcs2.u16());
1124
+ return;
1125
+ case "U32":
1126
+ bcsJson[objName] = bcs2.vector(bcs2.u32());
1127
+ return;
1128
+ case "U64":
1129
+ bcsJson[objName] = bcs2.vector(bcs2.u64());
1130
+ return;
1131
+ case "U128":
1132
+ bcsJson[objName] = bcs2.vector(bcs2.u128());
1133
+ return;
1134
+ case "U256":
1135
+ bcsJson[objName] = bcs2.vector(bcs2.u256());
1136
+ return;
1137
+ case "Bool":
1138
+ bcsJson[objName] = bcs2.vector(bcs2.bool());
1139
+ return;
1140
+ case "Address":
1141
+ bcsJson[objName] = bcs2.vector(
1142
+ bcs2.bytes(32).transform({
1143
+ // To change the input type, you need to provide a type definition for the input
1144
+ input: (val) => fromHEX2(val),
1145
+ output: (val) => toHEX(val)
1146
+ })
1147
+ );
1148
+ return;
1149
+ default:
1150
+ }
1151
+ case "TypeParameter":
1152
+ bcsJson[objName] = bcs2.u128();
1153
+ return;
1154
+ default:
1155
+ throw new Error("Unsupported type");
1156
+ }
1157
+ }
1158
+ return;
1159
+ case "string":
1160
+ switch (objType) {
1161
+ case "U8":
1162
+ bcsJson[objName] = bcs2.u8();
1163
+ return;
1164
+ case "U16":
1165
+ bcsJson[objName] = bcs2.u16();
1166
+ return;
1167
+ case "U32":
1168
+ bcsJson[objName] = bcs2.u32();
1169
+ return;
1170
+ case "U64":
1171
+ bcsJson[objName] = bcs2.u64();
1172
+ return;
1173
+ case "U128":
1174
+ bcsJson[objName] = bcs2.u128();
1175
+ return;
1176
+ case "U256":
1177
+ bcsJson[objName] = bcs2.u256();
1178
+ return;
1179
+ case "Bool":
1180
+ bcsJson[objName] = bcs2.bool();
1181
+ return;
1182
+ case "Address":
1183
+ bcsJson[objName] = bcs2.bytes(32).transform({
1184
+ // To change the input type, you need to provide a type definition for the input
1185
+ input: (val) => fromHEX2(val),
1186
+ output: (val) => toHEX(val)
1187
+ });
1188
+ return;
1189
+ default:
1190
+ return;
1191
+ }
1192
+ default:
1193
+ throw new Error("Unsupported type");
1194
+ }
1195
+ });
1196
+ return {
1197
+ bcs: bcs2.struct(bcsmeta.objectName, bcsJson),
1198
+ loopFlag
1199
+ };
1200
+ });
1040
1201
  this.accountManager = new SuiAccountManager({ mnemonics, secretKey });
1041
1202
  fullnodeUrls = fullnodeUrls || [getFullnodeUrl(networkType ?? "mainnet")];
1042
1203
  this.suiInteractor = new SuiInteractor(fullnodeUrls, networkType);
1043
1204
  this.packageId = packageId;
1044
1205
  if (metadata !== void 0) {
1045
1206
  this.metadata = metadata;
1046
- Object.values(metadata).forEach(
1047
- (moudlevalue) => {
1048
- const data = moudlevalue;
1049
- const moduleName = data.name;
1050
- Object.entries(data.exposedFunctions).forEach(
1051
- ([funcName, funcvalue]) => {
1052
- const meta = funcvalue;
1053
- meta.moduleName = moduleName;
1054
- meta.funcName = funcName;
1055
- if (isUndefined(__privateGet(this, _query)[moduleName])) {
1056
- __privateGet(this, _query)[moduleName] = {};
1057
- }
1058
- if (isUndefined(__privateGet(this, _query)[moduleName][funcName])) {
1059
- __privateGet(this, _query)[moduleName][funcName] = createQuery(
1060
- meta,
1061
- (tx, p, typeArguments, isRaw) => __privateGet(this, _read).call(this, meta, tx, p, typeArguments, isRaw)
1062
- );
1207
+ let stillNeedFormat = true;
1208
+ while (stillNeedFormat === true) {
1209
+ let loopFlag = false;
1210
+ Object.values(metadata).forEach(
1211
+ (moudlevalue) => {
1212
+ const data = moudlevalue;
1213
+ const moduleName = data.name;
1214
+ const objMoudleId = `${packageId}::${moduleName}`;
1215
+ Object.entries(data.structs).forEach(([objectName, objectType]) => {
1216
+ const objId = `${objMoudleId}::${objectName}`;
1217
+ const bcsmeta = {
1218
+ objectName,
1219
+ objectType
1220
+ };
1221
+ let bcsObj = __privateGet(this, _bcs).call(this, bcsmeta);
1222
+ if (bcsObj.loopFlag === true) {
1223
+ loopFlag = bcsObj.loopFlag;
1063
1224
  }
1064
- if (isUndefined(__privateGet(this, _tx)[moduleName])) {
1065
- __privateGet(this, _tx)[moduleName] = {};
1225
+ __privateGet(this, _object)[objId] = bcsObj.bcs;
1226
+ });
1227
+ Object.entries(data.exposedFunctions).forEach(
1228
+ ([funcName, funcvalue]) => {
1229
+ const meta = funcvalue;
1230
+ meta.moduleName = moduleName;
1231
+ meta.funcName = funcName;
1232
+ if (isUndefined(__privateGet(this, _query)[moduleName])) {
1233
+ __privateGet(this, _query)[moduleName] = {};
1234
+ }
1235
+ if (isUndefined(__privateGet(this, _query)[moduleName][funcName])) {
1236
+ __privateGet(this, _query)[moduleName][funcName] = createQuery(
1237
+ meta,
1238
+ (tx, p, typeArguments, isRaw) => __privateGet(this, _read).call(this, meta, tx, p, typeArguments, isRaw)
1239
+ );
1240
+ }
1241
+ if (isUndefined(__privateGet(this, _tx)[moduleName])) {
1242
+ __privateGet(this, _tx)[moduleName] = {};
1243
+ }
1244
+ if (isUndefined(__privateGet(this, _tx)[moduleName][funcName])) {
1245
+ __privateGet(this, _tx)[moduleName][funcName] = createTx(
1246
+ meta,
1247
+ (tx, p, typeArguments, isRaw) => __privateGet(this, _exec).call(this, meta, tx, p, typeArguments, isRaw)
1248
+ );
1249
+ }
1066
1250
  }
1067
- if (isUndefined(__privateGet(this, _tx)[moduleName][funcName])) {
1068
- __privateGet(this, _tx)[moduleName][funcName] = createTx(
1069
- meta,
1070
- (tx, p, typeArguments, isRaw) => __privateGet(this, _exec).call(this, meta, tx, p, typeArguments, isRaw)
1071
- );
1072
- }
1073
- }
1074
- );
1075
- }
1076
- );
1251
+ );
1252
+ }
1253
+ );
1254
+ stillNeedFormat = loopFlag;
1255
+ }
1077
1256
  }
1078
1257
  this.contractFactory = new SuiContractFactory({
1079
1258
  packageId,
@@ -1086,8 +1265,23 @@ var Obelisk = class {
1086
1265
  get tx() {
1087
1266
  return __privateGet(this, _tx);
1088
1267
  }
1089
- get struct() {
1090
- return __privateGet(this, _struct);
1268
+ get object() {
1269
+ return __privateGet(this, _object);
1270
+ }
1271
+ view(dryResult) {
1272
+ let returnValues = [];
1273
+ if (dryResult.effects.status.status === "success") {
1274
+ const resultList = dryResult.results[0].returnValues;
1275
+ for (const res of resultList) {
1276
+ let baseValue = res[0];
1277
+ let baseType = res[1];
1278
+ const value = Uint8Array.from(baseValue);
1279
+ returnValues.push(this.object[baseType].parse(value));
1280
+ }
1281
+ return returnValues;
1282
+ } else {
1283
+ return void 0;
1284
+ }
1091
1285
  }
1092
1286
  /**
1093
1287
  * if derivePathParams is not provided or mnemonics is empty, it will return the keypair.
@@ -1305,50 +1499,11 @@ var Obelisk = class {
1305
1499
  if (entityId !== void 0) {
1306
1500
  params.push(tx.pure.address(entityId));
1307
1501
  }
1308
- const getResult = await this.query[schemaModuleName].get(
1502
+ const dryResult = await this.query[schemaModuleName].get(
1309
1503
  tx,
1310
1504
  params
1311
1505
  );
1312
- let returnValues = [];
1313
- if (getResult.effects.status.status === "success") {
1314
- const resultList = getResult.results[0].returnValues;
1315
- for (const res of resultList) {
1316
- let baseValue = res[0];
1317
- let baseType = res[1];
1318
- const value = Uint8Array.from(baseValue);
1319
- if (baseType === "address") {
1320
- const Address = bcs2.bytes(32).transform({
1321
- // To change the input type, you need to provide a type definition for the input
1322
- input: (val) => fromHEX2(val),
1323
- output: (val) => toHEX(val)
1324
- });
1325
- returnValues.push(Address.parse(value));
1326
- } else if (baseType === "u8") {
1327
- returnValues.push(bcs2.u8().parse(value));
1328
- } else if (baseType === "u16") {
1329
- returnValues.push(bcs2.u16().parse(value));
1330
- } else if (baseType === "u32") {
1331
- returnValues.push(bcs2.u32().parse(value));
1332
- } else if (baseType === "u64") {
1333
- returnValues.push(bcs2.u64().parse(value));
1334
- } else if (baseType === "u128") {
1335
- returnValues.push(bcs2.u128().parse(value));
1336
- } else if (baseType === "u256") {
1337
- returnValues.push(bcs2.u256().parse(value));
1338
- } else if (baseType === "bool") {
1339
- returnValues.push(bcs2.bool().parse(value));
1340
- } else if (baseType === "0x1::ascii::String") {
1341
- returnValues.push(bcs2.string().parse(value));
1342
- } else if (baseType === "vector<u8>") {
1343
- returnValues.push(bcs2.vector(bcs2.u8()).parse(value));
1344
- } else if (baseType === "0x1::option::Option<u8>") {
1345
- returnValues.push(bcs2.option(bcs2.u8()).parse(value));
1346
- }
1347
- }
1348
- return returnValues;
1349
- } else {
1350
- return void 0;
1351
- }
1506
+ return this.view(dryResult);
1352
1507
  }
1353
1508
  async containEntity(worldId, schemaName, entityId) {
1354
1509
  const schemaModuleName = `${schemaName}_schema`;
@@ -1357,18 +1512,11 @@ var Obelisk = class {
1357
1512
  if (entityId !== void 0) {
1358
1513
  params.push(tx.pure.address(entityId));
1359
1514
  }
1360
- const getResult = await this.query[schemaModuleName].contains(
1515
+ const dryResult = await this.query[schemaModuleName].contains(
1361
1516
  tx,
1362
1517
  params
1363
1518
  );
1364
- if (getResult.effects.status.status === "success") {
1365
- const res = getResult.results[0].returnValues[0];
1366
- let baseValue = res[0];
1367
- const value = Uint8Array.from(baseValue);
1368
- return bcs2.bool().parse(value);
1369
- } else {
1370
- return void 0;
1371
- }
1519
+ return this.view(dryResult);
1372
1520
  }
1373
1521
  // async getEntities(
1374
1522
  // worldId: string,
@@ -1465,54 +1613,13 @@ var Obelisk = class {
1465
1613
  // const u8Value = Uint8Array.from(value);
1466
1614
  // return bcs.de(type, u8Value);
1467
1615
  // }
1468
- async autoFormatDryValue(value) {
1469
- let returnValues = [];
1470
- if (value.effects.status.status === "success") {
1471
- const resultList = value.results[0].returnValues;
1472
- for (const res of resultList) {
1473
- let baseValue = res[0];
1474
- let baseType = res[1];
1475
- const value2 = Uint8Array.from(baseValue);
1476
- if (baseType === "address") {
1477
- const Address = bcs2.bytes(32).transform({
1478
- // To change the input type, you need to provide a type definition for the input
1479
- input: (val) => fromHEX2(val),
1480
- output: (val) => toHEX(val)
1481
- });
1482
- returnValues.push(Address.parse(value2));
1483
- } else if (baseType === "u8") {
1484
- returnValues.push(bcs2.u8().parse(value2));
1485
- } else if (baseType === "u16") {
1486
- returnValues.push(bcs2.u16().parse(value2));
1487
- } else if (baseType === "u32") {
1488
- returnValues.push(bcs2.u32().parse(value2));
1489
- } else if (baseType === "u64") {
1490
- returnValues.push(bcs2.u64().parse(value2));
1491
- } else if (baseType === "u128") {
1492
- returnValues.push(bcs2.u128().parse(value2));
1493
- } else if (baseType === "u256") {
1494
- returnValues.push(bcs2.u256().parse(value2));
1495
- } else if (baseType === "bool") {
1496
- returnValues.push(bcs2.bool().parse(value2));
1497
- } else if (baseType === "0x1::ascii::String") {
1498
- returnValues.push(bcs2.string().parse(value2));
1499
- } else if (baseType === "vector<u8>") {
1500
- returnValues.push(bcs2.vector(bcs2.u8()).parse(value2));
1501
- } else if (baseType === "0x1::option::Option<u8>") {
1502
- returnValues.push(bcs2.option(bcs2.u8()).parse(value2));
1503
- }
1504
- }
1505
- return returnValues;
1506
- } else {
1507
- return void 0;
1508
- }
1509
- }
1510
1616
  };
1511
1617
  _query = new WeakMap();
1512
1618
  _tx = new WeakMap();
1513
- _struct = new WeakMap();
1619
+ _object = new WeakMap();
1514
1620
  _exec = new WeakMap();
1515
1621
  _read = new WeakMap();
1622
+ _bcs = new WeakMap();
1516
1623
 
1517
1624
  // src/libs/multiSig/client.ts
1518
1625
  import { MultiSigPublicKey } from "@mysten/sui/multisig";