@credenza3/contracts-lib-sui 0.1.11 → 0.1.13

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.
@@ -1,4 +1,4 @@
1
- import type { CRED, CredenzaAssetCollection, CredenzaLedger, Sellable, CredenzaDecom, CredenzaMembership, CredenzaAirdrop } from './modules';
1
+ import type { CRED, CredenzaAssetCollection, CredenzaLedger, Sellable, CredenzaDecom, CredenzaMembership, CredenzaAirdrop, CredenzaDeposit } from './modules';
2
2
  import { SuiClient, SuiObjectData, SuiTransactionBlockResponse } from '@mysten/sui/client';
3
3
  import { Signer, SignatureWithBytes } from '@mysten/sui/cryptography';
4
4
  import { Transaction } from '@mysten/sui/transactions';
@@ -23,6 +23,7 @@ export declare class CredenzaSuiClient {
23
23
  Sellable: Sellable;
24
24
  CredenzaAssetCollection: CredenzaAssetCollection;
25
25
  CredenzaAirdrop: CredenzaAirdrop;
26
+ CredenzaDeposit: CredenzaDeposit;
26
27
  suiClient: SuiClient;
27
28
  static createSigner(pk: string): Signer;
28
29
  constructor(options: CredenzaSuiClientOptions);
@@ -213,10 +213,10 @@ var require_coreJsData = __commonJS({
213
213
  var require_isMasked = __commonJS({
214
214
  "node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isMasked.js"(exports, module2) {
215
215
  var coreJsData = require_coreJsData();
216
- var maskSrcKey = function() {
216
+ var maskSrcKey = (function() {
217
217
  var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || "");
218
218
  return uid ? "Symbol(src)_1." + uid : "";
219
- }();
219
+ })();
220
220
  function isMasked(func) {
221
221
  return !!maskSrcKey && maskSrcKey in func;
222
222
  }
@@ -826,11 +826,11 @@ var require_baseGet = __commonJS({
826
826
  var require_get = __commonJS({
827
827
  "node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/get.js"(exports, module2) {
828
828
  var baseGet = require_baseGet();
829
- function get9(object, path, defaultValue) {
829
+ function get10(object, path, defaultValue) {
830
830
  var result = object == null ? void 0 : baseGet(object, path);
831
831
  return result === void 0 ? defaultValue : result;
832
832
  }
833
- module2.exports = get9;
833
+ module2.exports = get10;
834
834
  }
835
835
  });
836
836
 
@@ -1168,7 +1168,7 @@ var require_lodash = __commonJS({
1168
1168
  var freeModule = freeExports && typeof module2 == "object" && module2 && !module2.nodeType && module2;
1169
1169
  var moduleExports = freeModule && freeModule.exports === freeExports;
1170
1170
  var freeProcess = moduleExports && freeGlobal.process;
1171
- var nodeUtil = function() {
1171
+ var nodeUtil = (function() {
1172
1172
  try {
1173
1173
  var types = freeModule && freeModule.require && freeModule.require("util").types;
1174
1174
  if (types) {
@@ -1177,7 +1177,7 @@ var require_lodash = __commonJS({
1177
1177
  return freeProcess && freeProcess.binding && freeProcess.binding("util");
1178
1178
  } catch (e) {
1179
1179
  }
1180
- }();
1180
+ })();
1181
1181
  var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer, nodeIsDate = nodeUtil && nodeUtil.isDate, nodeIsMap = nodeUtil && nodeUtil.isMap, nodeIsRegExp = nodeUtil && nodeUtil.isRegExp, nodeIsSet = nodeUtil && nodeUtil.isSet, nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
1182
1182
  function apply(func, thisArg, args) {
1183
1183
  switch (args.length) {
@@ -1523,7 +1523,7 @@ var require_lodash = __commonJS({
1523
1523
  function unicodeWords(string) {
1524
1524
  return string.match(reUnicodeWord) || [];
1525
1525
  }
1526
- var runInContext = function runInContext2(context) {
1526
+ var runInContext = (function runInContext2(context) {
1527
1527
  context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
1528
1528
  var Array2 = context.Array, Date2 = context.Date, Error2 = context.Error, Function2 = context.Function, Math2 = context.Math, Object2 = context.Object, RegExp2 = context.RegExp, String = context.String, TypeError2 = context.TypeError;
1529
1529
  var arrayProto = Array2.prototype, funcProto = Function2.prototype, objectProto = Object2.prototype;
@@ -1531,10 +1531,10 @@ var require_lodash = __commonJS({
1531
1531
  var funcToString = funcProto.toString;
1532
1532
  var hasOwnProperty = objectProto.hasOwnProperty;
1533
1533
  var idCounter = 0;
1534
- var maskSrcKey = function() {
1534
+ var maskSrcKey = (function() {
1535
1535
  var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || "");
1536
1536
  return uid ? "Symbol(src)_1." + uid : "";
1537
- }();
1537
+ })();
1538
1538
  var nativeObjectToString = objectProto.toString;
1539
1539
  var objectCtorString = funcToString.call(Object2);
1540
1540
  var oldDash = root._;
@@ -1542,14 +1542,14 @@ var require_lodash = __commonJS({
1542
1542
  "^" + funcToString.call(hasOwnProperty).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
1543
1543
  );
1544
1544
  var Buffer2 = moduleExports ? context.Buffer : undefined2, Symbol2 = context.Symbol, Uint8Array2 = context.Uint8Array, allocUnsafe = Buffer2 ? Buffer2.allocUnsafe : undefined2, getPrototype = overArg(Object2.getPrototypeOf, Object2), objectCreate = Object2.create, propertyIsEnumerable = objectProto.propertyIsEnumerable, splice = arrayProto.splice, spreadableSymbol = Symbol2 ? Symbol2.isConcatSpreadable : undefined2, symIterator = Symbol2 ? Symbol2.iterator : undefined2, symToStringTag = Symbol2 ? Symbol2.toStringTag : undefined2;
1545
- var defineProperty = function() {
1545
+ var defineProperty = (function() {
1546
1546
  try {
1547
1547
  var func = getNative(Object2, "defineProperty");
1548
1548
  func({}, "", {});
1549
1549
  return func;
1550
1550
  } catch (e) {
1551
1551
  }
1552
- }();
1552
+ })();
1553
1553
  var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout, ctxNow = Date2 && Date2.now !== root.Date.now && Date2.now, ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
1554
1554
  var nativeCeil = Math2.ceil, nativeFloor = Math2.floor, nativeGetSymbols = Object2.getOwnPropertySymbols, nativeIsBuffer = Buffer2 ? Buffer2.isBuffer : undefined2, nativeIsFinite = context.isFinite, nativeJoin = arrayProto.join, nativeKeys = overArg(Object2.keys, Object2), nativeMax = Math2.max, nativeMin = Math2.min, nativeNow = Date2.now, nativeParseInt = context.parseInt, nativeRandom = Math2.random, nativeReverse = arrayProto.reverse;
1555
1555
  var DataView = getNative(context, "DataView"), Map = getNative(context, "Map"), Promise2 = getNative(context, "Promise"), Set = getNative(context, "Set"), WeakMap = getNative(context, "WeakMap"), nativeCreate = getNative(Object2, "create");
@@ -1568,7 +1568,7 @@ var require_lodash = __commonJS({
1568
1568
  }
1569
1569
  return new LodashWrapper(value);
1570
1570
  }
1571
- var baseCreate = /* @__PURE__ */ function() {
1571
+ var baseCreate = /* @__PURE__ */ (function() {
1572
1572
  function object() {
1573
1573
  }
1574
1574
  return function(proto) {
@@ -1583,7 +1583,7 @@ var require_lodash = __commonJS({
1583
1583
  object.prototype = undefined2;
1584
1584
  return result2;
1585
1585
  };
1586
- }();
1586
+ })();
1587
1587
  function baseLodash() {
1588
1588
  }
1589
1589
  function LodashWrapper(value, chainAll) {
@@ -1951,7 +1951,7 @@ var require_lodash = __commonJS({
1951
1951
  function baseAt(object, paths) {
1952
1952
  var index = -1, length = paths.length, result2 = Array2(length), skip = object == null;
1953
1953
  while (++index < length) {
1954
- result2[index] = skip ? undefined2 : get9(object, paths[index]);
1954
+ result2[index] = skip ? undefined2 : get10(object, paths[index]);
1955
1955
  }
1956
1956
  return result2;
1957
1957
  }
@@ -2396,7 +2396,7 @@ var require_lodash = __commonJS({
2396
2396
  return matchesStrictComparable(toKey(path), srcValue);
2397
2397
  }
2398
2398
  return function(object) {
2399
- var objValue = get9(object, path);
2399
+ var objValue = get10(object, path);
2400
2400
  return objValue === undefined2 && objValue === srcValue ? hasIn(object, path) : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
2401
2401
  };
2402
2402
  }
@@ -4875,9 +4875,9 @@ var require_lodash = __commonJS({
4875
4875
  var gte = createRelationalOperation(function(value, other) {
4876
4876
  return value >= other;
4877
4877
  });
4878
- var isArguments = baseIsArguments(/* @__PURE__ */ function() {
4878
+ var isArguments = baseIsArguments(/* @__PURE__ */ (function() {
4879
4879
  return arguments;
4880
- }()) ? baseIsArguments : function(value) {
4880
+ })()) ? baseIsArguments : function(value) {
4881
4881
  return isObjectLike(value) && hasOwnProperty.call(value, "callee") && !propertyIsEnumerable.call(value, "callee");
4882
4882
  };
4883
4883
  var isArray = Array2.isArray;
@@ -5151,7 +5151,7 @@ var require_lodash = __commonJS({
5151
5151
  function functionsIn(object) {
5152
5152
  return object == null ? [] : baseFunctions(object, keysIn(object));
5153
5153
  }
5154
- function get9(object, path, defaultValue) {
5154
+ function get10(object, path, defaultValue) {
5155
5155
  var result2 = object == null ? undefined2 : baseGet(object, path);
5156
5156
  return result2 === undefined2 ? defaultValue : result2;
5157
5157
  }
@@ -6009,7 +6009,7 @@ var require_lodash = __commonJS({
6009
6009
  lodash.forInRight = forInRight;
6010
6010
  lodash.forOwn = forOwn;
6011
6011
  lodash.forOwnRight = forOwnRight;
6012
- lodash.get = get9;
6012
+ lodash.get = get10;
6013
6013
  lodash.gt = gt;
6014
6014
  lodash.gte = gte;
6015
6015
  lodash.has = has;
@@ -6129,7 +6129,7 @@ var require_lodash = __commonJS({
6129
6129
  lodash.each = forEach;
6130
6130
  lodash.eachRight = forEachRight;
6131
6131
  lodash.first = head;
6132
- mixin(lodash, function() {
6132
+ mixin(lodash, (function() {
6133
6133
  var source = {};
6134
6134
  baseForOwn(lodash, function(func, methodName) {
6135
6135
  if (!hasOwnProperty.call(lodash.prototype, methodName)) {
@@ -6137,7 +6137,7 @@ var require_lodash = __commonJS({
6137
6137
  }
6138
6138
  });
6139
6139
  return source;
6140
- }(), { "chain": false });
6140
+ })(), { "chain": false });
6141
6141
  lodash.VERSION = VERSION;
6142
6142
  arrayEach(["bind", "bindKey", "curry", "curryRight", "partial", "partialRight"], function(methodName) {
6143
6143
  lodash[methodName].placeholder = lodash;
@@ -6297,7 +6297,7 @@ var require_lodash = __commonJS({
6297
6297
  lodash.prototype[symIterator] = wrapperToIterator;
6298
6298
  }
6299
6299
  return lodash;
6300
- };
6300
+ });
6301
6301
  var _ = runInContext();
6302
6302
  if (typeof define == "function" && typeof define.amd == "object" && define.amd) {
6303
6303
  root._ = _;
@@ -6329,6 +6329,7 @@ __export(modules_exports, {
6329
6329
  CredenzaAirdrop: () => CredenzaAirdrop,
6330
6330
  CredenzaAssetCollection: () => CredenzaAssetCollection,
6331
6331
  CredenzaDecom: () => CredenzaDecom,
6332
+ CredenzaDeposit: () => CredenzaDeposit,
6332
6333
  CredenzaLedger: () => CredenzaLedger,
6333
6334
  CredenzaMembership: () => CredenzaMembership,
6334
6335
  Sellable: () => Sellable
@@ -7548,11 +7549,114 @@ var CredenzaAirdrop = class extends CredenzaSuiModule {
7548
7549
  }
7549
7550
  };
7550
7551
 
7552
+ // src/client/modules/CredenzaDeposit.ts
7553
+ var import_transactions8 = require("@mysten/sui/transactions");
7554
+ var import_get7 = __toESM(require_get());
7555
+ var CredenzaDeposit = class extends CredenzaSuiModule {
7556
+ async getCreatedConfigs() {
7557
+ const events = await this.client.suiClient.queryEvents({
7558
+ query: {
7559
+ MoveEventType: `${this.client.getPackageId()}::credenza_asset_deposit::DepositConfigCreatedEvent`
7560
+ }
7561
+ });
7562
+ const res = [];
7563
+ for (const event of events.data) {
7564
+ res.push((0, import_get7.default)(event, "parsedJson.id"));
7565
+ }
7566
+ return res;
7567
+ }
7568
+ async createConfig() {
7569
+ const tx = new import_transactions8.Transaction();
7570
+ tx.moveCall({
7571
+ target: `${this.client.getPackageId()}::credenza_asset_deposit::create_config`,
7572
+ arguments: []
7573
+ });
7574
+ return this.client.signAndExecuteTransaction(tx);
7575
+ }
7576
+ async getDepositedCoinType(configId) {
7577
+ const config = await this.client.suiClient.getObject({ id: configId, options: { showContent: true } });
7578
+ if (parseInt((0, import_get7.default)(config, "data.content.fields.coin.fields.size"))) {
7579
+ const fieldData = await this.client.suiClient.getDynamicFields({
7580
+ parentId: (0, import_get7.default)(config, "data.content.fields.coin.fields.id.id")
7581
+ });
7582
+ for (const item of fieldData.data) {
7583
+ if (item?.name?.type === "0x2::object::ID") {
7584
+ return item.objectType.split("<")[1].split(">")[0] ?? null;
7585
+ }
7586
+ }
7587
+ }
7588
+ return null;
7589
+ }
7590
+ async deposit(configId, coinId) {
7591
+ const coin = await this.client.suiClient.getObject({ id: coinId, options: { showContent: true } });
7592
+ const coinType = (0, import_get7.default)(coin, "data.content.type")?.split("<")[1].split(">")[0];
7593
+ const tx = new import_transactions8.Transaction();
7594
+ tx.moveCall({
7595
+ target: `${this.client.getPackageId()}::credenza_asset_deposit::deposit`,
7596
+ arguments: [tx.object(configId), tx.object(coinId)],
7597
+ typeArguments: [coinType]
7598
+ });
7599
+ return this.client.signAndExecuteTransaction(tx);
7600
+ }
7601
+ async withdraw(configId) {
7602
+ const coinType = await this.getDepositedCoinType(configId);
7603
+ if (!coinType) {
7604
+ throw new Error(`No coin was deposited into ${configId}`);
7605
+ }
7606
+ const tx = new import_transactions8.Transaction();
7607
+ tx.moveCall({
7608
+ target: `${this.client.getPackageId()}::credenza_asset_deposit::withdraw`,
7609
+ arguments: [tx.object(configId)],
7610
+ typeArguments: [coinType]
7611
+ });
7612
+ return this.client.signAndExecuteTransaction(tx);
7613
+ }
7614
+ async setOwner(configId, recipient, isOwner) {
7615
+ const tx = new import_transactions8.Transaction();
7616
+ tx.moveCall({
7617
+ target: `${this.client.getPackageId()}::credenza_asset_deposit::set_owner`,
7618
+ arguments: [tx.object(configId), tx.pure.address(recipient), tx.pure.bool(isOwner)]
7619
+ });
7620
+ return this.client.signAndExecuteTransaction(tx);
7621
+ }
7622
+ async setAuthorizedUser(configId, recipient, isOwner) {
7623
+ const tx = new import_transactions8.Transaction();
7624
+ tx.moveCall({
7625
+ target: `${this.client.getPackageId()}::credenza_asset_deposit::set_authorized_user`,
7626
+ arguments: [tx.object(configId), tx.pure.address(recipient), tx.pure.bool(isOwner)]
7627
+ });
7628
+ return this.client.signAndExecuteTransaction(tx);
7629
+ }
7630
+ async isAuthorizedUser(configId, recipient) {
7631
+ const config = await this.client.suiClient.getObject({ id: configId, options: { showContent: true } });
7632
+ if (parseInt((0, import_get7.default)(config, "data.content.fields.authorized_users.fields.size"))) {
7633
+ const fieldData = await this.client.suiClient.getDynamicFields({
7634
+ parentId: (0, import_get7.default)(config, "data.content.fields.coin.fields.id.id")
7635
+ });
7636
+ return !!fieldData && !!recipient;
7637
+ }
7638
+ return false;
7639
+ }
7640
+ async requestCoin(configId, amount) {
7641
+ const coinType = await this.getDepositedCoinType(configId);
7642
+ if (!coinType) {
7643
+ throw new Error(`This config does not have coin to drop setup`);
7644
+ }
7645
+ const tx = new import_transactions8.Transaction();
7646
+ tx.moveCall({
7647
+ target: `${this.client.getPackageId()}::credenza_asset_deposit::request_funds`,
7648
+ arguments: [tx.object(configId), tx.pure.u64(amount)],
7649
+ typeArguments: [coinType]
7650
+ });
7651
+ return this.client.signAndExecuteTransaction(tx);
7652
+ }
7653
+ };
7654
+
7551
7655
  // src/client/CredenzaSuiClient.ts
7552
7656
  var import_client = require("@mysten/sui/client");
7553
7657
  var import_ed25519 = require("@mysten/sui/keypairs/ed25519");
7554
7658
  var import_utils = require("@mysten/sui/utils");
7555
- var import_get7 = __toESM(require_get());
7659
+ var import_get8 = __toESM(require_get());
7556
7660
  var ENVIRONMENT_RPC = {
7557
7661
  DEVNET: "https://fullnode.devnet.sui.io:443",
7558
7662
  TESTNET: "https://fullnode.testnet.sui.io:443",
@@ -7633,7 +7737,7 @@ var CredenzaSuiClient = class {
7633
7737
  MoveEventType: type
7634
7738
  }
7635
7739
  });
7636
- return (0, import_get7.default)(list, "data.0.parsedJson");
7740
+ return (0, import_get8.default)(list, "data.0.parsedJson");
7637
7741
  }
7638
7742
  };
7639
7743
  /*! Bundled license information: