@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);
@@ -225,10 +225,10 @@ var require_isMasked = __commonJS({
225
225
  "node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isMasked.js"(exports, module) {
226
226
  "use strict";
227
227
  var coreJsData = require_coreJsData();
228
- var maskSrcKey = function() {
228
+ var maskSrcKey = (function() {
229
229
  var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || "");
230
230
  return uid ? "Symbol(src)_1." + uid : "";
231
- }();
231
+ })();
232
232
  function isMasked(func) {
233
233
  return !!maskSrcKey && maskSrcKey in func;
234
234
  }
@@ -876,11 +876,11 @@ var require_get = __commonJS({
876
876
  "node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/get.js"(exports, module) {
877
877
  "use strict";
878
878
  var baseGet = require_baseGet();
879
- function get9(object, path, defaultValue) {
879
+ function get10(object, path, defaultValue) {
880
880
  var result = object == null ? void 0 : baseGet(object, path);
881
881
  return result === void 0 ? defaultValue : result;
882
882
  }
883
- module.exports = get9;
883
+ module.exports = get10;
884
884
  }
885
885
  });
886
886
 
@@ -1219,7 +1219,7 @@ var require_lodash = __commonJS({
1219
1219
  var freeModule = freeExports && typeof module == "object" && module && !module.nodeType && module;
1220
1220
  var moduleExports = freeModule && freeModule.exports === freeExports;
1221
1221
  var freeProcess = moduleExports && freeGlobal.process;
1222
- var nodeUtil = function() {
1222
+ var nodeUtil = (function() {
1223
1223
  try {
1224
1224
  var types = freeModule && freeModule.require && freeModule.require("util").types;
1225
1225
  if (types) {
@@ -1228,7 +1228,7 @@ var require_lodash = __commonJS({
1228
1228
  return freeProcess && freeProcess.binding && freeProcess.binding("util");
1229
1229
  } catch (e) {
1230
1230
  }
1231
- }();
1231
+ })();
1232
1232
  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;
1233
1233
  function apply(func, thisArg, args) {
1234
1234
  switch (args.length) {
@@ -1574,7 +1574,7 @@ var require_lodash = __commonJS({
1574
1574
  function unicodeWords(string) {
1575
1575
  return string.match(reUnicodeWord) || [];
1576
1576
  }
1577
- var runInContext = function runInContext2(context) {
1577
+ var runInContext = (function runInContext2(context) {
1578
1578
  context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
1579
1579
  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;
1580
1580
  var arrayProto = Array2.prototype, funcProto = Function2.prototype, objectProto = Object2.prototype;
@@ -1582,10 +1582,10 @@ var require_lodash = __commonJS({
1582
1582
  var funcToString = funcProto.toString;
1583
1583
  var hasOwnProperty = objectProto.hasOwnProperty;
1584
1584
  var idCounter = 0;
1585
- var maskSrcKey = function() {
1585
+ var maskSrcKey = (function() {
1586
1586
  var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || "");
1587
1587
  return uid ? "Symbol(src)_1." + uid : "";
1588
- }();
1588
+ })();
1589
1589
  var nativeObjectToString = objectProto.toString;
1590
1590
  var objectCtorString = funcToString.call(Object2);
1591
1591
  var oldDash = root._;
@@ -1593,14 +1593,14 @@ var require_lodash = __commonJS({
1593
1593
  "^" + funcToString.call(hasOwnProperty).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
1594
1594
  );
1595
1595
  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;
1596
- var defineProperty = function() {
1596
+ var defineProperty = (function() {
1597
1597
  try {
1598
1598
  var func = getNative(Object2, "defineProperty");
1599
1599
  func({}, "", {});
1600
1600
  return func;
1601
1601
  } catch (e) {
1602
1602
  }
1603
- }();
1603
+ })();
1604
1604
  var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout, ctxNow = Date2 && Date2.now !== root.Date.now && Date2.now, ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
1605
1605
  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;
1606
1606
  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");
@@ -1619,7 +1619,7 @@ var require_lodash = __commonJS({
1619
1619
  }
1620
1620
  return new LodashWrapper(value);
1621
1621
  }
1622
- var baseCreate = /* @__PURE__ */ function() {
1622
+ var baseCreate = /* @__PURE__ */ (function() {
1623
1623
  function object() {
1624
1624
  }
1625
1625
  return function(proto) {
@@ -1634,7 +1634,7 @@ var require_lodash = __commonJS({
1634
1634
  object.prototype = undefined2;
1635
1635
  return result2;
1636
1636
  };
1637
- }();
1637
+ })();
1638
1638
  function baseLodash() {
1639
1639
  }
1640
1640
  function LodashWrapper(value, chainAll) {
@@ -2002,7 +2002,7 @@ var require_lodash = __commonJS({
2002
2002
  function baseAt(object, paths) {
2003
2003
  var index = -1, length = paths.length, result2 = Array2(length), skip = object == null;
2004
2004
  while (++index < length) {
2005
- result2[index] = skip ? undefined2 : get9(object, paths[index]);
2005
+ result2[index] = skip ? undefined2 : get10(object, paths[index]);
2006
2006
  }
2007
2007
  return result2;
2008
2008
  }
@@ -2447,7 +2447,7 @@ var require_lodash = __commonJS({
2447
2447
  return matchesStrictComparable(toKey(path), srcValue);
2448
2448
  }
2449
2449
  return function(object) {
2450
- var objValue = get9(object, path);
2450
+ var objValue = get10(object, path);
2451
2451
  return objValue === undefined2 && objValue === srcValue ? hasIn(object, path) : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
2452
2452
  };
2453
2453
  }
@@ -4926,9 +4926,9 @@ var require_lodash = __commonJS({
4926
4926
  var gte = createRelationalOperation(function(value, other) {
4927
4927
  return value >= other;
4928
4928
  });
4929
- var isArguments = baseIsArguments(/* @__PURE__ */ function() {
4929
+ var isArguments = baseIsArguments(/* @__PURE__ */ (function() {
4930
4930
  return arguments;
4931
- }()) ? baseIsArguments : function(value) {
4931
+ })()) ? baseIsArguments : function(value) {
4932
4932
  return isObjectLike(value) && hasOwnProperty.call(value, "callee") && !propertyIsEnumerable.call(value, "callee");
4933
4933
  };
4934
4934
  var isArray = Array2.isArray;
@@ -5202,7 +5202,7 @@ var require_lodash = __commonJS({
5202
5202
  function functionsIn(object) {
5203
5203
  return object == null ? [] : baseFunctions(object, keysIn(object));
5204
5204
  }
5205
- function get9(object, path, defaultValue) {
5205
+ function get10(object, path, defaultValue) {
5206
5206
  var result2 = object == null ? undefined2 : baseGet(object, path);
5207
5207
  return result2 === undefined2 ? defaultValue : result2;
5208
5208
  }
@@ -6060,7 +6060,7 @@ var require_lodash = __commonJS({
6060
6060
  lodash.forInRight = forInRight;
6061
6061
  lodash.forOwn = forOwn;
6062
6062
  lodash.forOwnRight = forOwnRight;
6063
- lodash.get = get9;
6063
+ lodash.get = get10;
6064
6064
  lodash.gt = gt;
6065
6065
  lodash.gte = gte;
6066
6066
  lodash.has = has;
@@ -6180,7 +6180,7 @@ var require_lodash = __commonJS({
6180
6180
  lodash.each = forEach;
6181
6181
  lodash.eachRight = forEachRight;
6182
6182
  lodash.first = head;
6183
- mixin(lodash, function() {
6183
+ mixin(lodash, (function() {
6184
6184
  var source = {};
6185
6185
  baseForOwn(lodash, function(func, methodName) {
6186
6186
  if (!hasOwnProperty.call(lodash.prototype, methodName)) {
@@ -6188,7 +6188,7 @@ var require_lodash = __commonJS({
6188
6188
  }
6189
6189
  });
6190
6190
  return source;
6191
- }(), { "chain": false });
6191
+ })(), { "chain": false });
6192
6192
  lodash.VERSION = VERSION;
6193
6193
  arrayEach(["bind", "bindKey", "curry", "curryRight", "partial", "partialRight"], function(methodName) {
6194
6194
  lodash[methodName].placeholder = lodash;
@@ -6348,7 +6348,7 @@ var require_lodash = __commonJS({
6348
6348
  lodash.prototype[symIterator] = wrapperToIterator;
6349
6349
  }
6350
6350
  return lodash;
6351
- };
6351
+ });
6352
6352
  var _ = runInContext();
6353
6353
  if (typeof define == "function" && typeof define.amd == "object" && define.amd) {
6354
6354
  root._ = _;
@@ -6372,6 +6372,7 @@ __export(modules_exports, {
6372
6372
  CredenzaAirdrop: () => CredenzaAirdrop,
6373
6373
  CredenzaAssetCollection: () => CredenzaAssetCollection,
6374
6374
  CredenzaDecom: () => CredenzaDecom,
6375
+ CredenzaDeposit: () => CredenzaDeposit,
6375
6376
  CredenzaLedger: () => CredenzaLedger,
6376
6377
  CredenzaMembership: () => CredenzaMembership,
6377
6378
  Sellable: () => Sellable
@@ -7591,8 +7592,111 @@ var CredenzaAirdrop = class extends CredenzaSuiModule {
7591
7592
  }
7592
7593
  };
7593
7594
 
7594
- // src/client/CredenzaSuiClient.ts
7595
+ // src/client/modules/CredenzaDeposit.ts
7595
7596
  var import_get7 = __toESM(require_get());
7597
+ import { Transaction as Transaction8 } from "@mysten/sui/transactions";
7598
+ var CredenzaDeposit = class extends CredenzaSuiModule {
7599
+ async getCreatedConfigs() {
7600
+ const events = await this.client.suiClient.queryEvents({
7601
+ query: {
7602
+ MoveEventType: `${this.client.getPackageId()}::credenza_asset_deposit::DepositConfigCreatedEvent`
7603
+ }
7604
+ });
7605
+ const res = [];
7606
+ for (const event of events.data) {
7607
+ res.push((0, import_get7.default)(event, "parsedJson.id"));
7608
+ }
7609
+ return res;
7610
+ }
7611
+ async createConfig() {
7612
+ const tx = new Transaction8();
7613
+ tx.moveCall({
7614
+ target: `${this.client.getPackageId()}::credenza_asset_deposit::create_config`,
7615
+ arguments: []
7616
+ });
7617
+ return this.client.signAndExecuteTransaction(tx);
7618
+ }
7619
+ async getDepositedCoinType(configId) {
7620
+ const config = await this.client.suiClient.getObject({ id: configId, options: { showContent: true } });
7621
+ if (parseInt((0, import_get7.default)(config, "data.content.fields.coin.fields.size"))) {
7622
+ const fieldData = await this.client.suiClient.getDynamicFields({
7623
+ parentId: (0, import_get7.default)(config, "data.content.fields.coin.fields.id.id")
7624
+ });
7625
+ for (const item of fieldData.data) {
7626
+ if (item?.name?.type === "0x2::object::ID") {
7627
+ return item.objectType.split("<")[1].split(">")[0] ?? null;
7628
+ }
7629
+ }
7630
+ }
7631
+ return null;
7632
+ }
7633
+ async deposit(configId, coinId) {
7634
+ const coin = await this.client.suiClient.getObject({ id: coinId, options: { showContent: true } });
7635
+ const coinType = (0, import_get7.default)(coin, "data.content.type")?.split("<")[1].split(">")[0];
7636
+ const tx = new Transaction8();
7637
+ tx.moveCall({
7638
+ target: `${this.client.getPackageId()}::credenza_asset_deposit::deposit`,
7639
+ arguments: [tx.object(configId), tx.object(coinId)],
7640
+ typeArguments: [coinType]
7641
+ });
7642
+ return this.client.signAndExecuteTransaction(tx);
7643
+ }
7644
+ async withdraw(configId) {
7645
+ const coinType = await this.getDepositedCoinType(configId);
7646
+ if (!coinType) {
7647
+ throw new Error(`No coin was deposited into ${configId}`);
7648
+ }
7649
+ const tx = new Transaction8();
7650
+ tx.moveCall({
7651
+ target: `${this.client.getPackageId()}::credenza_asset_deposit::withdraw`,
7652
+ arguments: [tx.object(configId)],
7653
+ typeArguments: [coinType]
7654
+ });
7655
+ return this.client.signAndExecuteTransaction(tx);
7656
+ }
7657
+ async setOwner(configId, recipient, isOwner) {
7658
+ const tx = new Transaction8();
7659
+ tx.moveCall({
7660
+ target: `${this.client.getPackageId()}::credenza_asset_deposit::set_owner`,
7661
+ arguments: [tx.object(configId), tx.pure.address(recipient), tx.pure.bool(isOwner)]
7662
+ });
7663
+ return this.client.signAndExecuteTransaction(tx);
7664
+ }
7665
+ async setAuthorizedUser(configId, recipient, isOwner) {
7666
+ const tx = new Transaction8();
7667
+ tx.moveCall({
7668
+ target: `${this.client.getPackageId()}::credenza_asset_deposit::set_authorized_user`,
7669
+ arguments: [tx.object(configId), tx.pure.address(recipient), tx.pure.bool(isOwner)]
7670
+ });
7671
+ return this.client.signAndExecuteTransaction(tx);
7672
+ }
7673
+ async isAuthorizedUser(configId, recipient) {
7674
+ const config = await this.client.suiClient.getObject({ id: configId, options: { showContent: true } });
7675
+ if (parseInt((0, import_get7.default)(config, "data.content.fields.authorized_users.fields.size"))) {
7676
+ const fieldData = await this.client.suiClient.getDynamicFields({
7677
+ parentId: (0, import_get7.default)(config, "data.content.fields.coin.fields.id.id")
7678
+ });
7679
+ return !!fieldData && !!recipient;
7680
+ }
7681
+ return false;
7682
+ }
7683
+ async requestCoin(configId, amount) {
7684
+ const coinType = await this.getDepositedCoinType(configId);
7685
+ if (!coinType) {
7686
+ throw new Error(`This config does not have coin to drop setup`);
7687
+ }
7688
+ const tx = new Transaction8();
7689
+ tx.moveCall({
7690
+ target: `${this.client.getPackageId()}::credenza_asset_deposit::request_funds`,
7691
+ arguments: [tx.object(configId), tx.pure.u64(amount)],
7692
+ typeArguments: [coinType]
7693
+ });
7694
+ return this.client.signAndExecuteTransaction(tx);
7695
+ }
7696
+ };
7697
+
7698
+ // src/client/CredenzaSuiClient.ts
7699
+ var import_get8 = __toESM(require_get());
7596
7700
  import { SuiClient } from "@mysten/sui/client";
7597
7701
  import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
7598
7702
  import { fromB64 } from "@mysten/sui/utils";
@@ -7676,7 +7780,7 @@ var CredenzaSuiClient = class {
7676
7780
  MoveEventType: type
7677
7781
  }
7678
7782
  });
7679
- return (0, import_get7.default)(list, "data.0.parsedJson");
7783
+ return (0, import_get8.default)(list, "data.0.parsedJson");
7680
7784
  }
7681
7785
  };
7682
7786
  export {