@credenza3/contracts-lib-sui 0.1.11 → 0.1.12

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.
@@ -0,0 +1,13 @@
1
+ import { CredenzaSuiModule } from './CredenzaSuiModule';
2
+ import { SuiTransactionResult } from '../CredenzaSuiClient';
3
+ export declare class CredenzaDeposit extends CredenzaSuiModule {
4
+ getCreatedConfigs(): Promise<string[]>;
5
+ createConfig(): Promise<SuiTransactionResult>;
6
+ getDepositedCoinType(configId: string): Promise<string | null>;
7
+ deposit(configId: string, coinId: string): Promise<SuiTransactionResult>;
8
+ withdraw(configId: string): Promise<SuiTransactionResult>;
9
+ setOwner(configId: string, recipient: string, isOwner: boolean): Promise<SuiTransactionResult>;
10
+ setAuthorizedUser(configId: string, recipient: string, isOwner: boolean): Promise<SuiTransactionResult>;
11
+ isAuthorizedUser(configId: string, recipient: string): Promise<boolean>;
12
+ requestCoin(configId: string, amount: number): Promise<SuiTransactionResult>;
13
+ }
@@ -5,4 +5,5 @@ import { CredenzaDecom } from './CredenzaDecom';
5
5
  import { Sellable } from './Sellable';
6
6
  import { CredenzaAssetCollection } from './CredenzaAssetCollection';
7
7
  import { CredenzaAirdrop } from './CredenzaAirdrop';
8
- export { CRED, CredenzaLedger, CredenzaMembership, CredenzaDecom, Sellable, CredenzaAssetCollection, CredenzaAirdrop };
8
+ import { CredenzaDeposit } from './CredenzaDeposit';
9
+ export { CRED, CredenzaLedger, CredenzaMembership, CredenzaDecom, Sellable, CredenzaAssetCollection, CredenzaAirdrop, CredenzaDeposit, };
@@ -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);
@@ -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
 
@@ -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
  }
@@ -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;
@@ -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 {