@0xobelisk/sui-client 1.2.0-pre.122 → 1.2.0-pre.124

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/dubhe.d.ts CHANGED
@@ -348,6 +348,22 @@ export declare class Dubhe {
348
348
  *
349
349
  * @param dappStorageId Object ID of the DappStorage to inspect.
350
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
+ }>;
351
367
  getDappStorageFields(dappStorageId: string): Promise<{
352
368
  objectId: string;
353
369
  dapp_key: string;
@@ -365,21 +381,54 @@ export declare class Dubhe {
365
381
  total_settled: bigint;
366
382
  base_fee_per_write: bigint;
367
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;
368
397
  }>;
369
398
  /**
370
- * Settle accumulated write debt for a user.
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).
371
419
  *
372
- * Calls `<frameworkPackageId>::dapp_system::settle_writes<DappKey>` with the
373
- * given DappHub, DappStorage, and UserStorage objects.
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.
374
423
  *
375
- * This is safe to prepend to any PTB — the framework function never aborts
424
+ * This is safe to call at any time — the framework function never aborts
376
425
  * due to insufficient credit; it silently skips or partially settles.
377
426
  *
378
427
  * @param dappHubId Object ID of the DappHub shared object.
379
428
  * @param dappStorageId Object ID of the DApp's DappStorage shared object.
380
429
  * @param userStorageId Object ID of the user's UserStorage shared object.
381
430
  */
382
- settleWrites({ dappHubId, dappStorageId: dappStorageIdParam, userStorageId, derivePathParams, onSuccess, onError }: {
431
+ settleWrites({ dappHubId, dappStorageId, userStorageId, derivePathParams, onSuccess, onError }: {
383
432
  dappHubId: string;
384
433
  dappStorageId?: string;
385
434
  userStorageId: string;
@@ -387,6 +436,192 @@ export declare class Dubhe {
387
436
  onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
388
437
  onError?: (error: Error) => void | Promise<void>;
389
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
+ }>;
390
625
  /**
391
626
  * Return the default network configuration for the given network type.
392
627
  *