@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.
- package/dist/cjs/client/CredenzaSuiClient.d.ts +2 -1
- package/dist/cjs/client/index.cjs +112 -8
- package/dist/cjs/client/index.cjs.map +4 -4
- package/dist/cjs/client/modules/CredenzaDeposit.d.ts +13 -0
- package/dist/cjs/client/modules/index.d.ts +2 -1
- package/dist/esm/client/CredenzaSuiClient.d.ts +2 -1
- package/dist/esm/client/index.mjs +112 -8
- package/dist/esm/client/index.mjs.map +4 -4
- package/dist/esm/client/modules/CredenzaDeposit.d.ts +13 -0
- package/dist/esm/client/modules/index.d.ts +2 -1
- package/dist/umd/client/index.js +6 -6
- package/dist/umd/client/index.js.map +4 -4
- package/package.json +1 -1
|
@@ -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);
|
|
@@ -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
|
|
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 =
|
|
833
|
+
module2.exports = get10;
|
|
834
834
|
}
|
|
835
835
|
});
|
|
836
836
|
|
|
@@ -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 :
|
|
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 =
|
|
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
|
}
|
|
@@ -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
|
|
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 =
|
|
6012
|
+
lodash.get = get10;
|
|
6013
6013
|
lodash.gt = gt;
|
|
6014
6014
|
lodash.gte = gte;
|
|
6015
6015
|
lodash.has = has;
|
|
@@ -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
|
|
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,
|
|
7740
|
+
return (0, import_get8.default)(list, "data.0.parsedJson");
|
|
7637
7741
|
}
|
|
7638
7742
|
};
|
|
7639
7743
|
/*! Bundled license information:
|