@0xobelisk/sui-client 1.2.0-pre.98 → 2.0.0

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/LICENSE ADDED
@@ -0,0 +1,92 @@
1
+ Business Source License 1.1
2
+
3
+ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.
4
+ "Business Source License" is a trademark of MariaDB Corporation Ab.
5
+
6
+ -----------------------------------------------------------------------------
7
+
8
+ Parameters
9
+
10
+ Licensor: Obelisk Labs
11
+
12
+ Licensed Work: Dubhe
13
+ The Licensed Work is (c) 2023 Obelisk Labs
14
+
15
+ -----------------------------------------------------------------------------
16
+
17
+ Terms
18
+
19
+ The Licensor hereby grants you the right to copy, modify, create derivative
20
+ works, redistribute, and make non-production use of the Licensed Work. The
21
+ Licensor may make an Additional Use Grant, above, permitting limited
22
+ production use.
23
+
24
+ Effective on the Change Date, or the fourth anniversary of the first publicly
25
+ available distribution of a specific version of the Licensed Work under this
26
+ License, whichever comes first, the Licensor hereby grants you rights under
27
+ the terms of the Change License, and the rights granted in the paragraph
28
+ above terminate.
29
+
30
+ If your use of the Licensed Work does not comply with the requirements
31
+ currently in effect as described in this License, you must purchase a
32
+ commercial license from the Licensor, its affiliated entities, or authorized
33
+ resellers, or you must refrain from using the Licensed Work.
34
+
35
+ All copies of the original and modified Licensed Work, and derivative works
36
+ of the Licensed Work, are subject to this License. This License applies
37
+ separately for each version of the Licensed Work and the Change Date may vary
38
+ for each version of the Licensed Work released by Licensor.
39
+
40
+ You must conspicuously display this License on each original or modified copy
41
+ of the Licensed Work. If you receive the Licensed Work in original or
42
+ modified form from a third party, the terms and conditions set forth in this
43
+ License apply to your use of that work.
44
+
45
+ Any use of the Licensed Work in violation of this License will automatically
46
+ terminate your rights under this License for the current and all other
47
+ versions of the Licensed Work.
48
+
49
+ This License does not grant you any right in any trademark or logo of
50
+ Licensor or its affiliates (provided that you may use a trademark or logo of
51
+ Licensor as expressly required by this License).
52
+
53
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
54
+ AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
55
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
56
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
57
+ TITLE.
58
+
59
+ MariaDB hereby grants you permission to use this License’s text to license
60
+ your works, and to refer to it using the trademark "Business Source License",
61
+ as long as you comply with the Covenants of Licensor below.
62
+
63
+ -----------------------------------------------------------------------------
64
+
65
+ Covenants of Licensor
66
+
67
+ In consideration of the right to use this License’s text and the "Business
68
+ Source License" name and trademark, Licensor covenants to MariaDB, and to all
69
+ other recipients of the licensed work to be provided by Licensor:
70
+
71
+ 1. To specify as the Change License the GPL Version 2.0 or any later version,
72
+ or a license that is compatible with GPL Version 2.0 or a later version,
73
+ where "compatible" means that software provided under the Change License can
74
+ be included in a program with software provided under GPL Version 2.0 or a
75
+ later version. Licensor may specify additional Change Licenses without
76
+ limitation.
77
+
78
+ 2. To either: (a) specify an additional grant of rights to use that does not
79
+ impose any additional restriction on the right granted in this License, as
80
+ the Additional Use Grant; or (b) insert the text "None".
81
+
82
+ 3. To specify a Change Date.
83
+
84
+ 4. Not to modify this License in any other way.
85
+
86
+ -----------------------------------------------------------------------------
87
+
88
+ Notice
89
+
90
+ The Business Source License (this document, or the "License") is not an Open
91
+ Source license. However, the Licensed Work will eventually be made available
92
+ under an Open Source License, as stated in this License.
package/dist/dubhe.d.ts CHANGED
@@ -7,7 +7,7 @@ import { MapObjectStruct } from './types';
7
7
  import { SuiContractFactory } from './libs/suiContractFactory';
8
8
  import { SuiMoveMoudleFuncType } from './libs/suiContractFactory/types';
9
9
  import { NetworkConfig } from './libs/suiInteractor';
10
- import { DerivePathParams, FaucetNetworkType, MapMoudleFuncQuery, MapMoudleFuncTx, DubheParams, SuiTxArg, SuiObjectArg, SuiVecTxArg } from './types';
10
+ import { DerivePathParams, FaucetNetworkType, MapMoudleFuncQuery, MapMoudleFuncTx, DubheParams, SuiTxArg, SuiObjectArg, SuiVecTxArg, NetworkType } from './types';
11
11
  import { DubheChannelClient } from './libs/dubheChannel';
12
12
  export declare function isUndefined(value?: unknown): value is undefined;
13
13
  export declare function withMeta<T extends {
@@ -24,8 +24,13 @@ export declare class Dubhe {
24
24
  contractFactory: SuiContractFactory;
25
25
  dubheChannelClient: DubheChannelClient;
26
26
  packageId: string | undefined;
27
+ /** Fully-qualified Move type string for this DApp's DappKey, e.g. `<64-hex>::dapp_key::DappKey`. */
28
+ dappKey: string | undefined;
27
29
  metadata: SuiMoveNormalizedModules | undefined;
28
30
  projectName: string | undefined;
31
+ frameworkPackageId: string | undefined;
32
+ dappStorageId: string | undefined;
33
+ dappHubId: string | undefined;
29
34
  /**
30
35
  * Support the following ways to init the DubheClient:
31
36
  * 1. mnemonics
@@ -39,8 +44,9 @@ export declare class Dubhe {
39
44
  * @param packageId
40
45
  * @param metadata
41
46
  * @param channelUrl, the base URL for Dubhe Channel API, optional
47
+ * @param frameworkPackageId, the published package ID of the dubhe framework, required for proxy operations
42
48
  */
43
- constructor({ mnemonics, secretKey, networkType, fullnodeUrls, packageId, metadata, channelUrl }?: DubheParams);
49
+ constructor({ mnemonics, secretKey, networkType, fullnodeUrls, packageId, dappKey: dappKeyParam, metadata, channelUrl, frameworkPackageId, dappStorageId, dappHubId }?: DubheParams);
44
50
  get query(): MapMoudleFuncQuery;
45
51
  get tx(): MapMoudleFuncTx;
46
52
  get object(): MapObjectStruct;
@@ -76,8 +82,27 @@ export declare class Dubhe {
76
82
  getAddress(derivePathParams?: DerivePathParams): string;
77
83
  currentAddress(): string;
78
84
  getPackageId(): string;
85
+ /**
86
+ * Return the fully-qualified Move type string for this DApp's `DappKey`.
87
+ *
88
+ * The format matches what `std::type_name::get<DappKey>()` returns on-chain:
89
+ * `<64-char-zero-padded-address>::dapp_key::DappKey`
90
+ *
91
+ * Use this whenever you need to pass a type argument or build a `target`
92
+ * string that references the DApp's DappKey type.
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * tx.moveCall({
97
+ * target: `${frameworkPackageId}::dapp_system::settle_writes`,
98
+ * typeArguments: [contract.getDappKey()],
99
+ * arguments: [...],
100
+ * });
101
+ * ```
102
+ */
103
+ getDappKey(): string | undefined;
79
104
  getMetadata(): SuiMoveNormalizedModules | undefined;
80
- getNetwork(): import("./types").NetworkType | undefined;
105
+ getNetwork(): NetworkType | undefined;
81
106
  getNetworkConfig(): NetworkConfig;
82
107
  getTxExplorerUrl(txHash: string): string;
83
108
  getAccountExplorerUrl(address: string): string;
@@ -148,7 +173,7 @@ export declare class Dubhe {
148
173
  * { onMessage: (data) => console.log(data) }
149
174
  * );
150
175
  */
151
- subscribeChannelTable({ packageId, account, table, key }?: {
176
+ subscribeChannelTable({ packageId: _packageId, account, table, key }?: {
152
177
  packageId?: string;
153
178
  account?: string;
154
179
  table?: string;
@@ -221,4 +246,392 @@ export declare class Dubhe {
221
246
  entity_key_from_address_with_seed(objectId: string, seed: string): Promise<string | undefined>;
222
247
  entity_key_from_address_with_u256(objectId: string, x: number): Promise<string | undefined>;
223
248
  entity_key_from_u256(x: number): Promise<string>;
249
+ /**
250
+ * Call the DApp's generated `user_storage_init::init_user_storage` entry function,
251
+ * which creates and shares a `UserStorage` object for the signer.
252
+ *
253
+ * Each DApp exposes this entry point under its own package ID.
254
+ * On Sui, the `UserStorage` object is shared immediately so all transactions
255
+ * can reference it without knowing the object ID in advance.
256
+ *
257
+ * @param dappHubId Object ID of the DappHub shared object
258
+ * @param dappStorageId Object ID of the DApp's DappStorage shared object
259
+ */
260
+ initUserStorage({ dappHubId, dappStorageId: dappStorageIdParam, derivePathParams, onSuccess, onError }: {
261
+ dappHubId: string;
262
+ dappStorageId?: string;
263
+ derivePathParams?: DerivePathParams;
264
+ onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
265
+ onError?: (error: Error) => void | Promise<void>;
266
+ }): Promise<SuiTransactionBlockResponse>;
267
+ /**
268
+ * Activate a session key for the signer's `UserStorage`.
269
+ *
270
+ * The signer must be the `canonical_owner` of the `UserStorage` object.
271
+ * Calls `<frameworkPackageId>::dapp_system::activate_session<DappKey>`.
272
+ *
273
+ * @param userStorageId Object ID of the UserStorage to activate a session for
274
+ * @param sessionWallet Sui address of the session wallet
275
+ * @param durationMs Session duration in milliseconds ([60_000, 604_800_000])
276
+ * @param clockObjectId Object ID of the Sui Clock (default: 0x6)
277
+ */
278
+ activateSession({ userStorageId, sessionWallet, durationMs, dappHubId: dappHubIdParam, clockObjectId, derivePathParams, onSuccess, onError }: {
279
+ userStorageId: string;
280
+ sessionWallet: string;
281
+ durationMs: number;
282
+ dappHubId?: string;
283
+ clockObjectId?: string;
284
+ derivePathParams?: DerivePathParams;
285
+ onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
286
+ onError?: (error: Error) => void | Promise<void>;
287
+ }): Promise<SuiTransactionBlockResponse>;
288
+ /**
289
+ * Deactivate the current session key on a `UserStorage`.
290
+ *
291
+ * Allowed callers:
292
+ * - The `canonical_owner` (revoke at any time).
293
+ * - The session key itself (voluntary sign-out).
294
+ * - Anyone, once the session has expired.
295
+ *
296
+ * Calls `<frameworkPackageId>::dapp_system::deactivate_session<DappKey>`.
297
+ *
298
+ * @param userStorageId Object ID of the UserStorage to deactivate the session on
299
+ */
300
+ deactivateSession({ userStorageId, dappHubId: dappHubIdParam, derivePathParams, onSuccess, onError }: {
301
+ userStorageId: string;
302
+ dappHubId?: string;
303
+ derivePathParams?: DerivePathParams;
304
+ onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
305
+ onError?: (error: Error) => void | Promise<void>;
306
+ }): Promise<SuiTransactionBlockResponse>;
307
+ /**
308
+ * Look up the `UserStorage` object ID for the given address in this DApp.
309
+ *
310
+ * Scans the transaction history for `user_storage_init::init_user_storage`
311
+ * calls from the given address and extracts the created `UserStorage` object
312
+ * ID from the transaction's object changes.
313
+ *
314
+ * Returns the object ID on success, or `null` when:
315
+ * - `packageId` or `frameworkPackageId` is not set.
316
+ * - The user has not yet called `initUserStorage`.
317
+ *
318
+ * @param userAddress Sui address to look up (with or without 0x prefix).
319
+ */
320
+ getUserStorageId(userAddress: string): Promise<string | null>;
321
+ /**
322
+ * Fetch and return the on-chain fields of a `UserStorage` shared object.
323
+ *
324
+ * The returned object mirrors Move's `UserStorage` struct plus two
325
+ * convenience fields computed from the raw counters:
326
+ * - `unsettled_count` = write_count − settled_count
327
+ * - `unsettled_bytes` = write_bytes − settled_bytes
328
+ *
329
+ * @param userStorageId Object ID of the UserStorage to inspect.
330
+ */
331
+ getUserStorageFields(userStorageId: string): Promise<{
332
+ objectId: string;
333
+ dapp_key: string;
334
+ canonical_owner: string;
335
+ session_key: string;
336
+ session_expires_at: bigint;
337
+ write_count: bigint;
338
+ settled_count: bigint;
339
+ write_bytes: bigint;
340
+ settled_bytes: bigint;
341
+ unsettled_count: bigint;
342
+ unsettled_bytes: bigint;
343
+ }>;
344
+ /**
345
+ * Fetch and return the on-chain fields of a `DappStorage` shared object.
346
+ *
347
+ * Covers the full metadata + fee/credit subset of the Move struct.
348
+ *
349
+ * @param dappStorageId Object ID of the DappStorage to inspect.
350
+ */
351
+ /**
352
+ * Read the framework-level fields from the DappHub shared object.
353
+ *
354
+ * Key fields:
355
+ * - `treasury` — address that directly receives framework fee income
356
+ * - `pending_treasury` — queued treasury address during two-step rotation
357
+ * - `framework_admin` — address that can update framework configuration
358
+ * - `version` — current framework version
359
+ */
360
+ getDappHubFields(dappHubId: string): Promise<{
361
+ objectId: string;
362
+ version: number;
363
+ framework_admin: string;
364
+ treasury: string;
365
+ pending_treasury: string;
366
+ }>;
367
+ getDappStorageFields(dappStorageId: string): Promise<{
368
+ objectId: string;
369
+ dapp_key: string;
370
+ name: string;
371
+ description: string;
372
+ website_url: string;
373
+ admin: string;
374
+ version: number;
375
+ paused: boolean;
376
+ free_credit: bigint;
377
+ free_credit_expires_at: bigint;
378
+ credit_pool: bigint;
379
+ min_credit_to_unsuspend: bigint;
380
+ suspended: boolean;
381
+ total_settled: bigint;
382
+ base_fee_per_write: bigint;
383
+ bytes_fee_per_byte: bigint;
384
+ /**
385
+ * Settlement mode: 0 = DAPP_SUBSIDIZES (operator pays from credit_pool),
386
+ * 1 = USER_PAYS (user provides Coin via settle_writes_user_pays).
387
+ * Only `settle_writes` (no-coin variant) is safe to auto-call in mode 0.
388
+ */
389
+ settlement_mode: number;
390
+ /**
391
+ * BPS (0-10000) of each write-fee payment that flows into the DApp's
392
+ * revenue pool. The remainder goes to the framework treasury.
393
+ * Set exclusively by the framework admin via set_dapp_write_fee_share.
394
+ * Default: 0 (100% to framework treasury).
395
+ */
396
+ write_fee_dapp_share_bps: number;
397
+ }>;
398
+ /**
399
+ * Append a `dapp_system::settle_writes` moveCall to an existing PTB.
400
+ *
401
+ * Does NOT send the transaction — call this before your own moveCall(s) to
402
+ * settle any accumulated write debt within the same PTB at no extra round-trip.
403
+ *
404
+ * The framework function never aborts due to insufficient credit (it silently
405
+ * skips or partially settles), so prepending this to any PTB is always safe.
406
+ *
407
+ * @param tx The Transaction object to append the moveCall to.
408
+ * @param dappHubId Object ID of the DappHub shared object.
409
+ * @param dappStorageId Object ID of the DApp's DappStorage (falls back to constructor value).
410
+ * @param userStorageId Object ID of the user's UserStorage shared object.
411
+ */
412
+ buildSettleWritesTx(tx: Transaction, { dappHubId, dappStorageId: dappStorageIdParam, userStorageId }: {
413
+ dappHubId: string;
414
+ dappStorageId?: string;
415
+ userStorageId: string;
416
+ }): void;
417
+ /**
418
+ * Settle accumulated write debt for a user (standalone transaction).
419
+ *
420
+ * Builds a PTB containing a single `dapp_system::settle_writes` call and
421
+ * sends it. For embedding settlement into an existing PTB, use
422
+ * `buildSettleWritesTx` instead.
423
+ *
424
+ * This is safe to call at any time — the framework function never aborts
425
+ * due to insufficient credit; it silently skips or partially settles.
426
+ *
427
+ * @param dappHubId Object ID of the DappHub shared object.
428
+ * @param dappStorageId Object ID of the DApp's DappStorage shared object.
429
+ * @param userStorageId Object ID of the user's UserStorage shared object.
430
+ */
431
+ settleWrites({ dappHubId, dappStorageId, userStorageId, derivePathParams, onSuccess, onError }: {
432
+ dappHubId: string;
433
+ dappStorageId?: string;
434
+ userStorageId: string;
435
+ derivePathParams?: DerivePathParams;
436
+ onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
437
+ onError?: (error: Error) => void | Promise<void>;
438
+ }): Promise<SuiTransactionBlockResponse>;
439
+ /**
440
+ * Recharge a DApp's credit pool by paying with the framework's accepted coin type.
441
+ *
442
+ * Wraps `dapp_system::recharge_credit<DappKey, CoinType>`. Any account may call
443
+ * this — no admin restriction. Payment is forwarded to the framework treasury and
444
+ * the DApp's `credit_pool` is increased by the coin value.
445
+ *
446
+ * Only valid in DAPP_SUBSIDIZES settlement mode. Aborts with
447
+ * `wrong_settlement_mode` if the DApp is in USER_PAYS mode.
448
+ *
449
+ * @param dappHubId Object ID of the DappHub shared object.
450
+ * @param dappStorageId Object ID of the DApp's DappStorage shared object.
451
+ * @param coinObjectId Object ID of the Coin to use as payment.
452
+ * @param coinType Move type of the coin (default: "0x2::sui::SUI").
453
+ */
454
+ rechargeCredit({ dappHubId, dappStorageId: dappStorageIdParam, coinObjectId, coinType, derivePathParams, onSuccess, onError }: {
455
+ dappHubId: string;
456
+ dappStorageId?: string;
457
+ coinObjectId: string;
458
+ coinType?: string;
459
+ derivePathParams?: DerivePathParams;
460
+ onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
461
+ onError?: (error: Error) => void | Promise<void>;
462
+ }): Promise<SuiTransactionBlockResponse>;
463
+ /**
464
+ * Append a `dapp_system::settle_writes_user_pays` moveCall to an existing PTB.
465
+ *
466
+ * Splits `maxPaymentMist` MIST from `tx.gas` as the payment coin, then calls
467
+ * `settle_writes_user_pays`. The framework returns any overpayment automatically,
468
+ * so it is safe to over-estimate. This lets a session key pay for settlement
469
+ * inline without requiring a separate owned Coin object.
470
+ *
471
+ * @param tx The Transaction object to append the moveCall to.
472
+ * @param dappHubId Object ID of the DappHub shared object.
473
+ * @param dappStorageId Object ID of the DApp's DappStorage (falls back to constructor value).
474
+ * @param userStorageId Object ID of the user's UserStorage shared object.
475
+ * @param maxPaymentMist Upper bound for the payment in MIST (default: 50_000_000 = 0.05 SUI).
476
+ * @param coinType Move type of the payment coin (default: "0x2::sui::SUI").
477
+ */
478
+ buildSettleWritesUserPaysTx(tx: Transaction, { dappHubId, dappStorageId: dappStorageIdParam, userStorageId, maxPaymentMist, coinType }: {
479
+ dappHubId: string;
480
+ dappStorageId?: string;
481
+ userStorageId: string;
482
+ maxPaymentMist?: bigint;
483
+ coinType?: string;
484
+ }): void;
485
+ /**
486
+ * Settle accumulated write debt where the user pays directly (USER_PAYS mode).
487
+ *
488
+ * Wraps `dapp_system::settle_writes_user_pays<DappKey, CoinType>`. The exact
489
+ * cost is computed on-chain; any overpayment from the coin is returned to the
490
+ * sender after settlement.
491
+ *
492
+ * Aborts if:
493
+ * - The DApp is not in USER_PAYS mode (`wrong_settlement_mode`)
494
+ * - The coin type does not match the accepted type (`wrong_payment_coin_type`)
495
+ * - The coin value is less than the total cost (`insufficient_credit`)
496
+ *
497
+ * @param dappHubId Object ID of the DappHub shared object.
498
+ * @param dappStorageId Object ID of the DApp's DappStorage shared object.
499
+ * @param userStorageId Object ID of the user's UserStorage shared object.
500
+ * @param coinObjectId Object ID of the Coin to use as payment.
501
+ * @param coinType Move type of the coin (default: "0x2::sui::SUI").
502
+ */
503
+ settleWritesUserPays({ dappHubId, dappStorageId: dappStorageIdParam, userStorageId, coinObjectId, coinType, derivePathParams, onSuccess, onError }: {
504
+ dappHubId: string;
505
+ dappStorageId?: string;
506
+ userStorageId: string;
507
+ coinObjectId: string;
508
+ coinType?: string;
509
+ derivePathParams?: DerivePathParams;
510
+ onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
511
+ onError?: (error: Error) => void | Promise<void>;
512
+ }): Promise<SuiTransactionBlockResponse>;
513
+ /**
514
+ * Query `WritesSettled` events from the Sui full node.
515
+ *
516
+ * Returns the most recent settlement events across ALL users of this DApp.
517
+ * Each event captures one user's write debt settlement: number of writes,
518
+ * bytes, and the amount charged (`paid_cost`).
519
+ *
520
+ * Note: Sui full nodes may prune old events. For long-term history use a
521
+ * dedicated indexer table (`writes_settled_history`).
522
+ *
523
+ * @param limit Max events to return (default: 30, max: 50).
524
+ * @param cursor Pagination cursor from a previous response.
525
+ */
526
+ queryWritesSettledEvents(limit?: number, cursor?: {
527
+ txDigest: string;
528
+ eventSeq: string;
529
+ }): Promise<Array<{
530
+ txDigest: string;
531
+ eventSeq: string;
532
+ timestampMs: number;
533
+ dappKey: string;
534
+ account: string;
535
+ writes: number;
536
+ bytes: string;
537
+ freeCost: string;
538
+ paidCost: string;
539
+ }>>;
540
+ /**
541
+ * Query `MarketplaceFeeSettled` events from the Sui full node.
542
+ *
543
+ * Each event records the fee split for a completed marketplace purchase:
544
+ * total fee, framework treasury share, and DApp revenue share.
545
+ *
546
+ * @param limit Max events to return (default: 30, max: 50).
547
+ * @param cursor Pagination cursor from a previous response.
548
+ */
549
+ queryMarketplaceFeeSettledEvents(limit?: number, cursor?: {
550
+ txDigest: string;
551
+ eventSeq: string;
552
+ }): Promise<Array<{
553
+ txDigest: string;
554
+ eventSeq: string;
555
+ timestampMs: number;
556
+ dappKey: string;
557
+ listingId: string;
558
+ coinType: string;
559
+ totalFee: string;
560
+ treasuryAmount: string;
561
+ dappAmount: string;
562
+ }>>;
563
+ /**
564
+ * Read the DApp's accumulated revenue balance directly from the chain.
565
+ *
566
+ * `dapp_revenue` is stored as a dynamic field (`DappRevenueKey<CoinType>`)
567
+ * on the DappStorage object — it is NOT a top-level field, so `getObject`
568
+ * alone cannot return it. This method calls `getDynamicFields` to locate
569
+ * the correct child object and returns its balance.
570
+ *
571
+ * Returns 0n when the dynamic field has never been created (no revenue yet).
572
+ *
573
+ * @param dappStorageId Object ID of the DApp's DappStorage shared object.
574
+ * @param coinType Move type of the revenue coin (default: "0x2::sui::SUI").
575
+ */
576
+ getDappRevenueBalance(dappStorageId: string, coinType?: string): Promise<bigint>;
577
+ /**
578
+ * Withdraw all accumulated DApp revenue to the DApp admin address.
579
+ *
580
+ * Wraps `dapp_system::withdraw_dapp_revenue<DappKey, CoinType>`.
581
+ * The entire revenue balance is transferred to the DApp admin on-chain.
582
+ * Aborts if the balance is zero (`no_revenue_to_withdraw`).
583
+ *
584
+ * @param dappHubId Object ID of the DappHub shared object.
585
+ * @param dappStorageId Object ID of the DApp's DappStorage shared object.
586
+ * @param coinType Move type of the revenue coin (default: "0x2::sui::SUI").
587
+ */
588
+ withdrawDappRevenue({ dappHubId, dappStorageId: dappStorageIdParam, coinType, derivePathParams, onSuccess, onError }: {
589
+ dappHubId: string;
590
+ dappStorageId?: string;
591
+ coinType?: string;
592
+ derivePathParams?: DerivePathParams;
593
+ onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
594
+ onError?: (error: Error) => void | Promise<void>;
595
+ }): Promise<SuiTransactionBlockResponse>;
596
+ /**
597
+ * Return a combined settlement health snapshot for a user.
598
+ *
599
+ * Fetches `UserStorage` fields (always) and optionally `DappStorage` fields
600
+ * (when `dappStorageId` is supplied) to produce high-level diagnostic values:
601
+ *
602
+ * - `utilizationPct` — how close the user is to the 2 000-write hard limit
603
+ * - `isAtRisk` — utilization >= 80 % (settlement recommended soon)
604
+ * - `isBlocked` — utilization >= 100 % (writes will be rejected)
605
+ * - `estimatedWritesAffordable` — writes the credit pool can still cover
606
+ * - `creditAtRisk` — fewer than 500 writes of credit remaining
607
+ *
608
+ * @param userStorageId Object ID of the user's UserStorage shared object.
609
+ * @param dappStorageId Object ID of the DApp's DappStorage (optional).
610
+ */
611
+ getSettlementHealth({ userStorageId, dappStorageId }: {
612
+ userStorageId: string;
613
+ dappStorageId?: string;
614
+ }): Promise<{
615
+ unsettledCount: bigint;
616
+ writeLimit: bigint;
617
+ utilizationPct: number;
618
+ isAtRisk: boolean;
619
+ isBlocked: boolean;
620
+ creditPool?: bigint;
621
+ baseFeePerWrite?: bigint;
622
+ estimatedWritesAffordable?: bigint;
623
+ creditAtRisk?: boolean;
624
+ }>;
625
+ /**
626
+ * Return the default network configuration for the given network type.
627
+ *
628
+ * Useful for reading `frameworkPackageId` without instantiating a full client:
629
+ *
630
+ * ```ts
631
+ * const { frameworkPackageId } = Dubhe.getDefaultConfig('testnet');
632
+ * // → '0x8817b...' (known constant for testnet/mainnet)
633
+ * // → undefined (for localnet/devnet — supply after local deployment)
634
+ * ```
635
+ */
636
+ static getDefaultConfig(networkType: NetworkType): NetworkConfig;
224
637
  }
package/dist/index.d.ts CHANGED
@@ -14,3 +14,5 @@ export { MultiSigClient } from './libs/multiSig';
14
14
  export { SuiContractFactory } from './libs/suiContractFactory';
15
15
  export { loadMetadata } from './metadata';
16
16
  export type * from './types';
17
+ export { getDefaultConfig, getDefaultURL, TESTNET_DUBHE_FRAMEWORK_PACKAGE_ID, TESTNET_DUBHE_HUB_OBJECT_ID, MAINNET_DUBHE_FRAMEWORK_PACKAGE_ID, MAINNET_DUBHE_HUB_OBJECT_ID } from './libs/suiInteractor/defaultConfig';
18
+ export type { NetworkConfig } from './libs/suiInteractor/defaultConfig';