@ickb/sdk 1000.0.81 → 9000.0.1

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.
Files changed (157) hide show
  1. package/README.md +81 -32
  2. package/dist/constants.d.ts +13 -22
  3. package/dist/constants.d.ts.map +1 -1
  4. package/dist/constants.js +80 -76
  5. package/dist/constants.js.map +1 -1
  6. package/dist/conversion/estimate.d.ts +39 -0
  7. package/dist/conversion/estimate.d.ts.map +1 -0
  8. package/dist/conversion/estimate.js +117 -0
  9. package/dist/conversion/estimate.js.map +1 -0
  10. package/dist/conversion/maturity.d.ts +15 -0
  11. package/dist/conversion/maturity.d.ts.map +1 -0
  12. package/dist/conversion/maturity.js +112 -0
  13. package/dist/conversion/maturity.js.map +1 -0
  14. package/dist/conversion/plans.d.ts +20 -0
  15. package/dist/conversion/plans.d.ts.map +1 -0
  16. package/dist/conversion/plans.js +106 -0
  17. package/dist/conversion/plans.js.map +1 -0
  18. package/dist/conversion/projection.d.ts +22 -0
  19. package/dist/conversion/projection.d.ts.map +1 -0
  20. package/dist/conversion/projection.js +91 -0
  21. package/dist/conversion/projection.js.map +1 -0
  22. package/dist/conversion/types.d.ts +252 -0
  23. package/dist/conversion/types.d.ts.map +1 -0
  24. package/dist/conversion/types.js +2 -0
  25. package/dist/conversion/types.js.map +1 -0
  26. package/dist/conversion/withdrawal_ring.d.ts +36 -0
  27. package/dist/conversion/withdrawal_ring.d.ts.map +1 -0
  28. package/dist/conversion/withdrawal_ring.js +87 -0
  29. package/dist/conversion/withdrawal_ring.js.map +1 -0
  30. package/dist/dao.d.ts +86 -0
  31. package/dist/dao.d.ts.map +1 -0
  32. package/dist/dao.js +113 -0
  33. package/dist/dao.js.map +1 -0
  34. package/dist/index.d.ts +51 -3
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +20 -3
  37. package/dist/index.js.map +1 -1
  38. package/dist/logic.d.ts +85 -0
  39. package/dist/logic.d.ts.map +1 -0
  40. package/dist/logic.js +184 -0
  41. package/dist/logic.js.map +1 -0
  42. package/dist/order/cells.d.ts +207 -0
  43. package/dist/order/cells.d.ts.map +1 -0
  44. package/dist/order/cells.js +427 -0
  45. package/dist/order/cells.js.map +1 -0
  46. package/dist/order/conversion.d.ts +43 -0
  47. package/dist/order/conversion.d.ts.map +1 -0
  48. package/dist/order/conversion.js +123 -0
  49. package/dist/order/conversion.js.map +1 -0
  50. package/dist/order/fee.d.ts +9 -0
  51. package/dist/order/fee.d.ts.map +1 -0
  52. package/dist/order/fee.js +24 -0
  53. package/dist/order/fee.js.map +1 -0
  54. package/dist/order/fill.d.ts +36 -0
  55. package/dist/order/fill.d.ts.map +1 -0
  56. package/dist/order/fill.js +53 -0
  57. package/dist/order/fill.js.map +1 -0
  58. package/dist/order/info.d.ts +62 -0
  59. package/dist/order/info.d.ts.map +1 -0
  60. package/dist/order/info.js +99 -0
  61. package/dist/order/info.js.map +1 -0
  62. package/dist/order/master.d.ts +49 -0
  63. package/dist/order/master.d.ts.map +1 -0
  64. package/dist/order/master.js +27 -0
  65. package/dist/order/master.js.map +1 -0
  66. package/dist/order/matcher.d.ts +43 -0
  67. package/dist/order/matcher.d.ts.map +1 -0
  68. package/dist/order/matcher.js +123 -0
  69. package/dist/order/matcher.js.map +1 -0
  70. package/dist/order/order.d.ts +59 -0
  71. package/dist/order/order.d.ts.map +1 -0
  72. package/dist/order/order.js +239 -0
  73. package/dist/order/order.js.map +1 -0
  74. package/dist/order/order_data.d.ts +51 -0
  75. package/dist/order/order_data.d.ts.map +1 -0
  76. package/dist/order/order_data.js +64 -0
  77. package/dist/order/order_data.js.map +1 -0
  78. package/dist/order/ratio.d.ts +42 -0
  79. package/dist/order/ratio.d.ts.map +1 -0
  80. package/dist/order/ratio.js +82 -0
  81. package/dist/order/ratio.js.map +1 -0
  82. package/dist/order/relative.d.ts +43 -0
  83. package/dist/order/relative.d.ts.map +1 -0
  84. package/dist/order/relative.js +54 -0
  85. package/dist/order/relative.js.map +1 -0
  86. package/dist/owned_owner.d.ts +113 -0
  87. package/dist/owned_owner.d.ts.map +1 -0
  88. package/dist/owned_owner.js +280 -0
  89. package/dist/owned_owner.js.map +1 -0
  90. package/dist/sdk.d.ts +71 -42
  91. package/dist/sdk.d.ts.map +1 -1
  92. package/dist/sdk.js +388 -209
  93. package/dist/sdk.js.map +1 -1
  94. package/dist/send/sign_and_send_transaction.d.ts +46 -0
  95. package/dist/send/sign_and_send_transaction.d.ts.map +1 -0
  96. package/dist/send/sign_and_send_transaction.js +101 -0
  97. package/dist/send/sign_and_send_transaction.js.map +1 -0
  98. package/dist/send/wait_transaction.d.ts +41 -0
  99. package/dist/send/wait_transaction.d.ts.map +1 -0
  100. package/dist/send/wait_transaction.js +204 -0
  101. package/dist/send/wait_transaction.js.map +1 -0
  102. package/dist/udt.d.ts +123 -0
  103. package/dist/udt.d.ts.map +1 -0
  104. package/dist/udt.js +244 -0
  105. package/dist/udt.js.map +1 -0
  106. package/dist/utils/chain.d.ts +38 -0
  107. package/dist/utils/chain.d.ts.map +1 -0
  108. package/dist/utils/chain.js +20 -0
  109. package/dist/utils/chain.js.map +1 -0
  110. package/dist/utils/codec.d.ts +19 -0
  111. package/dist/utils/codec.d.ts.map +1 -0
  112. package/dist/utils/codec.js +66 -0
  113. package/dist/utils/codec.js.map +1 -0
  114. package/dist/utils/transaction_header.d.ts +17 -0
  115. package/dist/utils/transaction_header.d.ts.map +1 -0
  116. package/dist/utils/transaction_header.js +44 -0
  117. package/dist/utils/transaction_header.js.map +1 -0
  118. package/dist/utils/utils.d.ts +126 -0
  119. package/dist/utils/utils.d.ts.map +1 -0
  120. package/dist/utils/utils.js +151 -0
  121. package/dist/utils/utils.js.map +1 -0
  122. package/package.json +19 -26
  123. package/src/constants.ts +84 -181
  124. package/src/conversion/estimate.ts +157 -0
  125. package/src/conversion/maturity.ts +159 -0
  126. package/src/conversion/plans.ts +144 -0
  127. package/src/conversion/projection.ts +128 -0
  128. package/src/conversion/types.ts +287 -0
  129. package/src/conversion/withdrawal_ring.ts +126 -0
  130. package/src/dao.ts +172 -0
  131. package/src/index.ts +89 -3
  132. package/src/logic.ts +295 -0
  133. package/src/order/cells.ts +520 -0
  134. package/src/order/conversion.ts +173 -0
  135. package/src/order/fee.ts +30 -0
  136. package/src/order/fill.ts +83 -0
  137. package/src/order/info.ts +178 -0
  138. package/src/order/master.ts +42 -0
  139. package/src/order/matcher.ts +191 -0
  140. package/src/order/order.ts +302 -0
  141. package/src/order/order_data.ts +128 -0
  142. package/src/order/ratio.ts +144 -0
  143. package/src/order/relative.ts +106 -0
  144. package/src/owned_owner.ts +394 -0
  145. package/src/sdk.ts +555 -440
  146. package/src/send/sign_and_send_transaction.ts +120 -0
  147. package/src/send/wait_transaction.ts +271 -0
  148. package/src/udt.ts +317 -0
  149. package/src/utils/chain.ts +43 -0
  150. package/src/utils/codec.ts +74 -0
  151. package/src/utils/transaction_header.ts +66 -0
  152. package/src/utils/utils.ts +237 -0
  153. package/dist/codec.d.ts +0 -3
  154. package/dist/codec.d.ts.map +0 -1
  155. package/dist/codec.js +0 -58
  156. package/dist/codec.js.map +0 -1
  157. package/src/codec.ts +0 -138
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/conversion/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,36 @@
1
+ import type { ccc } from "@ckb-ccc/core";
2
+ import type { IckbDepositCell } from "../logic.js";
3
+ /**
4
+ * Ring segment of pool deposits grouped by maturity around the DAO cycle.
5
+ */
6
+ export interface RingSegment {
7
+ /** Segment index in the ring. */
8
+ index: number;
9
+ /** Deposits assigned to this segment. */
10
+ deposits: IckbDepositCell[];
11
+ /** Total iCKB value of deposits in this segment. */
12
+ udtValue: bigint;
13
+ }
14
+ /**
15
+ * Splits pool deposits into power-of-two maturity ring segments, one segment per two
16
+ * deposit caps of pool iCKB.
17
+ */
18
+ export declare function ringSegments(poolDeposits: readonly IckbDepositCell[]): RingSegment[];
19
+ /** The segment index an epoch falls in, for a deposit's claim or the tip. */
20
+ export declare function ringSegmentIndex(epoch: ccc.Epoch, segmentCount: number): number;
21
+ /**
22
+ * Returns a filter that excludes the ring anchor deposits from surplus selection: each
23
+ * segment keeps its anchor, the largest deposit not in `ready`, else the largest one.
24
+ */
25
+ export declare function ringSurplusDepositFilter(poolDeposits: readonly IckbDepositCell[], ready: readonly IckbDepositCell[]): (deposit: IckbDepositCell) => boolean;
26
+ /**
27
+ * Walks the candidates in the given order and takes each one that still fits under
28
+ * `maxAmount`; the caller chooses the order, earliest claim first
29
+ * for a user (the wait they feel), surplus before anchors for the bot. The chain stops at
30
+ * the most requests one transaction can carry, a request and its owner marker per deposit;
31
+ * completion steps down from there when change and fees need more room.
32
+ */
33
+ export declare function fitWithdrawalDeposits(candidates: readonly IckbDepositCell[], maxAmount: bigint): IckbDepositCell[];
34
+ /** Earliest claim first: the deposit that turns into CKB soonest. */
35
+ export declare function sortByClaim(deposits: readonly IckbDepositCell[]): IckbDepositCell[];
36
+ //# sourceMappingURL=withdrawal_ring.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withdrawal_ring.d.ts","sourceRoot":"","sources":["../../src/conversion/withdrawal_ring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGnD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAC;IAEd,yCAAyC;IACzC,QAAQ,EAAE,eAAe,EAAE,CAAC;IAE5B,oDAAoD;IACpD,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,YAAY,EAAE,SAAS,eAAe,EAAE,GAAG,WAAW,EAAE,CAuBpF;AAED,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAS/E;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,YAAY,EAAE,SAAS,eAAe,EAAE,EACxC,KAAK,EAAE,SAAS,eAAe,EAAE,GAChC,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAevC;AAcD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,SAAS,eAAe,EAAE,EACtC,SAAS,EAAE,MAAM,GAChB,eAAe,EAAE,CAcnB;AAED,qEAAqE;AACrE,wBAAgB,WAAW,CAAC,QAAQ,EAAE,SAAS,eAAe,EAAE,GAAG,eAAe,EAAE,CAEnF"}
@@ -0,0 +1,87 @@
1
+ import { DAO_CYCLE_EPOCHS, DAO_OUTPUT_LIMIT } from "../dao.js";
2
+ import { ICKB_DEPOSIT_CAP } from "../udt.js";
3
+ /**
4
+ * Splits pool deposits into power-of-two maturity ring segments, one segment per two
5
+ * deposit caps of pool iCKB.
6
+ */
7
+ export function ringSegments(poolDeposits) {
8
+ // Value, not count: zero-value deposits, made without iCKB Logic running, must not add segments.
9
+ // Two caps per segment, not one: the room the bot's own fills need, see node/docs/policy.md.
10
+ const totalUdt = poolDeposits.reduce((sum, deposit) => sum + deposit.udtValue, 0n);
11
+ let segmentCount = 1;
12
+ while (BigInt(segmentCount) * 2n * ICKB_DEPOSIT_CAP < totalUdt) {
13
+ segmentCount *= 2;
14
+ }
15
+ const segments = Array.from({ length: segmentCount }, (_, index) => ({
16
+ index,
17
+ deposits: [],
18
+ udtValue: 0n,
19
+ }));
20
+ // The ring is one DAO cycle round, so a claim rolled a cycle lands in the same segment.
21
+ for (const deposit of poolDeposits) {
22
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- ringSegmentIndex returns 0 <= index < segmentCount.
23
+ const segment = segments[ringSegmentIndex(deposit.claimEpoch, segmentCount)];
24
+ segment.deposits.push(deposit);
25
+ segment.udtValue += deposit.udtValue;
26
+ }
27
+ return segments;
28
+ }
29
+ /** The segment index an epoch falls in, for a deposit's claim or the tip. */
30
+ export function ringSegmentIndex(epoch, segmentCount) {
31
+ const { denominator } = epoch;
32
+ if (denominator <= 0n) {
33
+ throw new Error("Epoch denominator must be positive");
34
+ }
35
+ const scaled = epoch.integer * denominator + epoch.numerator;
36
+ const ring = DAO_CYCLE_EPOCHS * denominator;
37
+ const wrapped = ((scaled % ring) + ring) % ring;
38
+ return Number((wrapped * BigInt(segmentCount)) / ring);
39
+ }
40
+ /**
41
+ * Returns a filter that excludes the ring anchor deposits from surplus selection: each
42
+ * segment keeps its anchor, the largest deposit not in `ready`, else the largest one.
43
+ */
44
+ export function ringSurplusDepositFilter(poolDeposits, ready) {
45
+ const isReady = new Set(ready.map((deposit) => deposit.cell.outPoint.toHex()));
46
+ const anchors = new Set(ringSegments(poolDeposits).flatMap((segment) => {
47
+ const anchor = segment.deposits.reduce((best, deposit) => best === undefined || isBetterRingAnchor(deposit, best, isReady)
48
+ ? deposit
49
+ : best, undefined);
50
+ return anchor === undefined ? [] : [anchor.cell.outPoint.toHex()];
51
+ }));
52
+ return (deposit) => !anchors.has(deposit.cell.outPoint.toHex());
53
+ }
54
+ function isBetterRingAnchor(candidate, current, isReady) {
55
+ const candidateReady = isReady.has(candidate.cell.outPoint.toHex());
56
+ if (candidateReady !== isReady.has(current.cell.outPoint.toHex())) {
57
+ return !candidateReady;
58
+ }
59
+ return candidate.udtValue > current.udtValue;
60
+ }
61
+ /**
62
+ * Walks the candidates in the given order and takes each one that still fits under
63
+ * `maxAmount`; the caller chooses the order, earliest claim first
64
+ * for a user (the wait they feel), surplus before anchors for the bot. The chain stops at
65
+ * the most requests one transaction can carry, a request and its owner marker per deposit;
66
+ * completion steps down from there when change and fees need more room.
67
+ */
68
+ export function fitWithdrawalDeposits(candidates, maxAmount) {
69
+ const deposits = [];
70
+ let total = 0n;
71
+ for (const deposit of candidates) {
72
+ if (deposits.length === DAO_OUTPUT_LIMIT / 2) {
73
+ break;
74
+ }
75
+ if (total + deposit.udtValue > maxAmount) {
76
+ continue;
77
+ }
78
+ total += deposit.udtValue;
79
+ deposits.push(deposit);
80
+ }
81
+ return deposits;
82
+ }
83
+ /** Earliest claim first: the deposit that turns into CKB soonest. */
84
+ export function sortByClaim(deposits) {
85
+ return deposits.toSorted((left, right) => left.claimEpoch.compare(right.claimEpoch));
86
+ }
87
+ //# sourceMappingURL=withdrawal_ring.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withdrawal_ring.js","sourceRoot":"","sources":["../../src/conversion/withdrawal_ring.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAgB7C;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,YAAwC;IACnE,iGAAiG;IACjG,6FAA6F;IAC7F,MAAM,QAAQ,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,GAAG,GAAG,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACnF,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,OAAO,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,gBAAgB,GAAG,QAAQ,EAAE,CAAC;QAC/D,YAAY,IAAI,CAAC,CAAC;IACpB,CAAC;IACD,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAe,EAAE,CAAC,CAAC;QAChF,KAAK;QACL,QAAQ,EAAE,EAAE;QACZ,QAAQ,EAAE,EAAE;KACb,CAAC,CAAC,CAAC;IAEJ,wFAAwF;IACxF,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE,CAAC;QACnC,2HAA2H;QAC3H,MAAM,OAAO,GAAG,QAAQ,CAAC,gBAAgB,CAAC,OAAO,CAAC,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O,CAAC,QAAQ,CAAC;QAC1B,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,WAAW,CAAC,QAAoC;IAC9D,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;AACvF,CAAC"}
package/dist/dao.d.ts ADDED
@@ -0,0 +1,86 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ /**
3
+ * Maximum outputs accepted by deployed dao.c, not a general CKB consensus cap.
4
+ * A node upgrade cannot lift a limit in that deployed script.
5
+ */
6
+ export declare const DAO_OUTPUT_LIMIT = 64;
7
+ /**
8
+ * Deposit-header indices the deployed DAO script can address in a phase-2 witness.
9
+ *
10
+ * @remarks The script reads one byte of the u64 field (RFC 0023 erratum,
11
+ * nervosnetwork/rfcs pull 456).
12
+ */
13
+ export declare const DAO_HEADER_INDEX_LIMIT = 256;
14
+ /** One DAO cycle, the lock-up a deposit renews by when it is not withdrawn. */
15
+ export declare const DAO_CYCLE_EPOCHS = 180n;
16
+ /**
17
+ * Error thrown when a transaction exceeds the deployed DAO script's output limit.
18
+ */
19
+ export declare class DaoOutputLimitError extends Error {
20
+ /**
21
+ * Creates an output-limit error for a transaction with too many outputs.
22
+ */
23
+ constructor(outputCount: number, options?: ErrorOptions);
24
+ }
25
+ /**
26
+ * Error thrown when a phase-2 withdrawal would reference a deposit header the
27
+ * deployed DAO script cannot address.
28
+ */
29
+ export declare class DaoHeaderIndexError extends Error {
30
+ /**
31
+ * Creates a header-index error for one unrepresentable index.
32
+ */
33
+ constructor(headerIndex: number, options?: ErrorOptions);
34
+ }
35
+ /**
36
+ * Throws when a transaction using the DAO script exceeds the Nervos DAO output limit. An
37
+ * oversized transaction with an unresolved input is refused too: whether it uses the DAO
38
+ * cannot be known, and the completion walk steps a plan down on this error either way.
39
+ */
40
+ export declare function assertDaoOutputLimit(txLike: ccc.TransactionLike, daoScriptLike: ccc.ScriptLike): void;
41
+ /** The canonical DAO deposit data payload. */
42
+ export declare function depositData(): ccc.Hex;
43
+ /** Whether the cell is a DAO deposit of the given DAO script. */
44
+ export declare function isDaoDeposit(cell: ccc.CellAny, daoScript: ccc.Script): boolean;
45
+ /**
46
+ * Whether the cell uses the DAO script and is not deposit-shaped. This structural check
47
+ * does not decode the withdrawal request's deposit block number payload.
48
+ */
49
+ export declare function isDaoWithdrawalRequest(cell: ccc.CellAny, daoScript: ccc.Script): boolean;
50
+ /**
51
+ * A caller's timing rules for withdrawal requests, in epochs (the chain's clock, so no
52
+ * wall-clock drift). Selection: a deposit may be requested when its claim epoch is past
53
+ * `tip + minLockUp` (closer, the request would commit after the claim and lock for another
54
+ * cycle, so the deposit is judged on its next cycle) and before `tip + maxLockUp`.
55
+ * Broadcast: the signed request is sent only while the tip is before the earliest selected
56
+ * claim less `broadcastReserve`, else it is refused before broadcast.
57
+ */
58
+ export interface LockUpPolicy {
59
+ minLockUp: ccc.Epoch;
60
+ maxLockUp: ccc.Epoch;
61
+ broadcastReserve: ccc.Epoch;
62
+ }
63
+ /**
64
+ * The bot's rules on the nominal four-hour epoch: claims twenty minutes to an hour out,
65
+ * sent while fifteen minutes remain. The bot signs at once, so a short window suffices, and
66
+ * the estimate models the pool's supply on it (`sdk/docs/pool_maturity_estimates.md`).
67
+ */
68
+ export declare const BOT_LOCK_UP: LockUpPolicy;
69
+ /**
70
+ * A wallet's rules on the nominal four-hour epoch: claims two hours to three days out,
71
+ * sent while ninety minutes remain. A user may leave the request in a wallet popup.
72
+ */
73
+ export declare const WALLET_LOCK_UP: LockUpPolicy;
74
+ /** A deposit's maturity, rolled a cycle when its claim is too close, and whether it is ready. */
75
+ export declare function depositMaturity(claim: ccc.Epoch, tip: ccc.ClientBlockHeader, { minLockUp, maxLockUp }: LockUpPolicy): {
76
+ maturity: ccc.Epoch;
77
+ isReady: boolean;
78
+ };
79
+ /**
80
+ * The epoch a transaction requesting these deposits must be broadcast before: the earliest
81
+ * claim less the reserve; undefined when it requests none.
82
+ */
83
+ export declare function broadcastDeadline(claims: readonly ccc.Epoch[], { broadcastReserve }: LockUpPolicy): ccc.Epoch | undefined;
84
+ /** Adds the header dep once. */
85
+ export declare function pushHeaderDep(tx: ccc.Transaction, hash: ccc.Hex): void;
86
+ //# sourceMappingURL=dao.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dao.d.ts","sourceRoot":"","sources":["../src/dao.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC;;;GAGG;AACH,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C,+EAA+E;AAC/E,eAAO,MAAM,gBAAgB,OAAO,CAAC;AAErC;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C;;OAEG;IACH,YAAY,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,EAMtD;CACF;AAED;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C;;OAEG;IACH,YAAY,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,EAMtD;CACF;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,GAAG,CAAC,eAAe,EAC3B,aAAa,EAAE,GAAG,CAAC,UAAU,GAC5B,IAAI,CAeN;AAED,8CAA8C;AAC9C,wBAAgB,WAAW,IAAI,GAAG,CAAC,GAAG,CAErC;AAED,iEAAiE;AACjE,wBAAgB,YAAY,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAI9E;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,GAAG,CAAC,OAAO,EACjB,SAAS,EAAE,GAAG,CAAC,MAAM,GACpB,OAAO,CAIT;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC;IACrB,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC;IACrB,gBAAgB,EAAE,GAAG,CAAC,KAAK,CAAC;CAC7B;AAED;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,YAIzB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,YAI5B,CAAC;AAEF,iGAAiG;AACjG,wBAAgB,eAAe,CAC7B,KAAK,EAAE,GAAG,CAAC,KAAK,EAChB,GAAG,EAAE,GAAG,CAAC,iBAAiB,EAC1B,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,YAAY,GACrC;IAAE,QAAQ,EAAE,GAAG,CAAC,KAAK,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAM3C;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,SAAS,GAAG,CAAC,KAAK,EAAE,EAC5B,EAAE,gBAAgB,EAAE,EAAE,YAAY,GACjC,GAAG,CAAC,KAAK,GAAG,SAAS,CAMvB;AAED,gCAAgC;AAChC,wBAAgB,aAAa,CAAC,EAAE,EAAE,GAAG,CAAC,WAAW,EAAE,IAAI,EAAE,GAAG,CAAC,GAAG,GAAG,IAAI,CAItE"}
package/dist/dao.js ADDED
@@ -0,0 +1,113 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { CheckedUint64LE } from "./utils/codec.js";
3
+ /**
4
+ * Maximum outputs accepted by deployed dao.c, not a general CKB consensus cap.
5
+ * A node upgrade cannot lift a limit in that deployed script.
6
+ */
7
+ export const DAO_OUTPUT_LIMIT = 64;
8
+ /**
9
+ * Deposit-header indices the deployed DAO script can address in a phase-2 witness.
10
+ *
11
+ * @remarks The script reads one byte of the u64 field (RFC 0023 erratum,
12
+ * nervosnetwork/rfcs pull 456).
13
+ */
14
+ export const DAO_HEADER_INDEX_LIMIT = 256;
15
+ /** One DAO cycle, the lock-up a deposit renews by when it is not withdrawn. */
16
+ export const DAO_CYCLE_EPOCHS = 180n;
17
+ /**
18
+ * Error thrown when a transaction exceeds the deployed DAO script's output limit.
19
+ */
20
+ export class DaoOutputLimitError extends Error {
21
+ /**
22
+ * Creates an output-limit error for a transaction with too many outputs.
23
+ */
24
+ constructor(outputCount, options) {
25
+ super(`NervosDAO transaction has ${String(outputCount)} output cells, exceeding the limit of ${String(DAO_OUTPUT_LIMIT)}`, options);
26
+ this.name = "DaoOutputLimitError";
27
+ }
28
+ }
29
+ /**
30
+ * Error thrown when a phase-2 withdrawal would reference a deposit header the
31
+ * deployed DAO script cannot address.
32
+ */
33
+ export class DaoHeaderIndexError extends Error {
34
+ /**
35
+ * Creates a header-index error for one unrepresentable index.
36
+ */
37
+ constructor(headerIndex, options) {
38
+ super(`NervosDAO deposit header index ${String(headerIndex)} is not below ${String(DAO_HEADER_INDEX_LIMIT)}`, options);
39
+ this.name = "DaoHeaderIndexError";
40
+ }
41
+ }
42
+ /**
43
+ * Throws when a transaction using the DAO script exceeds the Nervos DAO output limit. An
44
+ * oversized transaction with an unresolved input is refused too: whether it uses the DAO
45
+ * cannot be known, and the completion walk steps a plan down on this error either way.
46
+ */
47
+ export function assertDaoOutputLimit(txLike, daoScriptLike) {
48
+ const tx = ccc.Transaction.from(txLike);
49
+ if (tx.outputs.length <= DAO_OUTPUT_LIMIT) {
50
+ return;
51
+ }
52
+ const daoScript = ccc.Script.from(daoScriptLike);
53
+ if (tx.inputs.some((input) => input.cellOutput === undefined || input.cellOutput.type?.eq(daoScript) === true) ||
54
+ tx.outputs.some((output) => output.type?.eq(daoScript) === true)) {
55
+ throw new DaoOutputLimitError(tx.outputs.length);
56
+ }
57
+ }
58
+ /** The canonical DAO deposit data payload. */
59
+ export function depositData() {
60
+ return ccc.hexFrom(CheckedUint64LE.encode(0n));
61
+ }
62
+ /** Whether the cell is a DAO deposit of the given DAO script. */
63
+ export function isDaoDeposit(cell, daoScript) {
64
+ return (cell.outputData === depositData() && cell.cellOutput.type?.eq(daoScript) === true);
65
+ }
66
+ /**
67
+ * Whether the cell uses the DAO script and is not deposit-shaped. This structural check
68
+ * does not decode the withdrawal request's deposit block number payload.
69
+ */
70
+ export function isDaoWithdrawalRequest(cell, daoScript) {
71
+ return (cell.outputData !== depositData() && cell.cellOutput.type?.eq(daoScript) === true);
72
+ }
73
+ /**
74
+ * The bot's rules on the nominal four-hour epoch: claims twenty minutes to an hour out,
75
+ * sent while fifteen minutes remain. The bot signs at once, so a short window suffices, and
76
+ * the estimate models the pool's supply on it (`sdk/docs/pool_maturity_estimates.md`).
77
+ */
78
+ export const BOT_LOCK_UP = {
79
+ minLockUp: ccc.Epoch.from([0n, 1n, 12n]),
80
+ maxLockUp: ccc.Epoch.from([0n, 4n, 16n]),
81
+ broadcastReserve: ccc.Epoch.from([0n, 1n, 16n]),
82
+ };
83
+ /**
84
+ * A wallet's rules on the nominal four-hour epoch: claims two hours to three days out,
85
+ * sent while ninety minutes remain. A user may leave the request in a wallet popup.
86
+ */
87
+ export const WALLET_LOCK_UP = {
88
+ minLockUp: ccc.Epoch.from([0n, 1n, 2n]),
89
+ maxLockUp: ccc.Epoch.from([18n, 0n, 1n]),
90
+ broadcastReserve: ccc.Epoch.from([0n, 3n, 8n]),
91
+ };
92
+ /** A deposit's maturity, rolled a cycle when its claim is too close, and whether it is ready. */
93
+ export function depositMaturity(claim, tip, { minLockUp, maxLockUp }) {
94
+ const maturity = claim.compare(minLockUp.add(tip.epoch)) <= 0
95
+ ? claim.add([DAO_CYCLE_EPOCHS, 0n, 1n])
96
+ : claim;
97
+ return { maturity, isReady: maxLockUp.add(tip.epoch).compare(maturity) > 0 };
98
+ }
99
+ /**
100
+ * The epoch a transaction requesting these deposits must be broadcast before: the earliest
101
+ * claim less the reserve; undefined when it requests none.
102
+ */
103
+ export function broadcastDeadline(claims, { broadcastReserve }) {
104
+ const earliest = claims.reduce((best, claim) => (best === undefined || claim.compare(best) < 0 ? claim : best), undefined);
105
+ return earliest?.sub(broadcastReserve);
106
+ }
107
+ /** Adds the header dep once. */
108
+ export function pushHeaderDep(tx, hash) {
109
+ if (!tx.headerDeps.includes(hash)) {
110
+ tx.headerDeps.push(hash);
111
+ }
112
+ }
113
+ //# sourceMappingURL=dao.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dao.js","sourceRoot":"","sources":["../src/dao.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAE1C,+EAA+E;AAC/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAErC;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C;;OAEG;IACH,YAAY,WAAmB,EAAE,OAAsB;QACrD,KAAK,CACH,6BAA6B,MAAM,CAAC,WAAW,CAAC,yCAAyC,MAAM,CAAC,gBAAgB,CAAC,EAAE,EACnH,OAAO,CACR,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C;;OAEG;IACH,YAAY,WAAmB,EAAE,OAAsB;QACrD,KAAK,CACH,kCAAkC,MAAM,CAAC,WAAW,CAAC,iBAAiB,MAAM,CAAC,sBAAsB,CAAC,EAAE,EACtG,OAAO,CACR,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED;;;;GAIG;AACH,MA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,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;AAC/E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAC/B,MAA4B,EAC5B,EAAE,gBAAgB,EAAgB;IAElC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAC5B,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,EAC/E,SAAS,CACV,CAAC;IACF,OAAO,QAAQ,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;AACzC,CAAC;AAED,gCAAgC;AAChC,MAAM,UAAU,aAAa,CAAC,EAAmB,EAAE,IAAa;IAC9D,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAClC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,52 @@
1
- export * from "./sdk.js";
2
- export * from "./codec.js";
3
- export * from "./constants.js";
1
+ /**
2
+ * Public SDK for one iCKB conversion workflow: read the sampled state, quote, build and
3
+ * complete a conversion, sign, send, and wait.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ import type { ccc } from "@ckb-ccc/core";
8
+ import type { AccountState, ConversionTransactionOptions, ConversionTransactionResult, SystemState } from "./conversion/types.js";
9
+ import type { LockUpPolicy } from "./dao.js";
10
+ import type { OrderGroup } from "./order/cells.js";
11
+ import type { SupportedChain } from "./utils/chain.js";
12
+ /** The SDK an integrator drives: the state read and the conversion builder. */
13
+ export interface IckbSdk {
14
+ /** Builds and completes a conversion, or returns a typed planning failure. */
15
+ buildConversionTransaction: (txLike: ccc.TransactionLike, options: ConversionTransactionOptions) => Promise<ConversionTransactionResult>;
16
+ /** Reads system, user-order, and account state against one sampled tip, under one timing policy. */
17
+ getL1AccountState: (client: ccc.Client, locks: ccc.Script[], lockUp: LockUpPolicy) => Promise<{
18
+ system: SystemState;
19
+ user: {
20
+ orders: OrderGroup[];
21
+ };
22
+ account: AccountState;
23
+ }>;
24
+ }
25
+ /** Creates the SDK for one chain's deployment. */
26
+ export declare const IckbSdk: {
27
+ fromChain: (chain: SupportedChain) => IckbSdk;
28
+ };
29
+ export { DEFAULT_ORDER_FEE, DEFAULT_ORDER_FEE_BASE } from "./conversion/estimate.js";
30
+ export { projectConversionTransactionContext } from "./conversion/projection.js";
31
+ export type { AccountAvailabilityProjection, AccountState, ConversionDirection, ConversionMetadata, ConversionNotice, ConversionTransactionContext, ConversionTransactionContextProjection, ConversionTransactionFailureReason, ConversionTransactionOptions, ConversionTransactionResult, SystemState, } from "./conversion/types.js";
32
+ export { WALLET_LOCK_UP } from "./dao.js";
33
+ export type { LockUpPolicy } from "./dao.js";
34
+ export type { IckbDepositCell, ReceiptCell } from "./logic.js";
35
+ export type { MasterCell, OrderCell, OrderGroup } from "./order/cells.js";
36
+ export { OrderConversionRepresentabilityError, quoteConversion, } from "./order/conversion.js";
37
+ export { isRefused, isStale } from "./order/fill.js";
38
+ export type { Info, InfoLike } from "./order/info.js";
39
+ export type { Master, MasterLike } from "./order/master.js";
40
+ export type { OrderData, OrderDataLike } from "./order/order_data.js";
41
+ export { Ratio } from "./order/ratio.js";
42
+ export type { Relative, RelativeLike } from "./order/relative.js";
43
+ export type { DaoWithdrawalRequestCell, OwnerCell, WithdrawalGroup, } from "./owned_owner.js";
44
+ export { hasTransactionActivity, IckbError } from "./sdk.js";
45
+ export type { IckbErrorCode } from "./sdk.js";
46
+ export { signAndSendTransaction, signerAccountLocks, TransactionBroadcastError, TransactionExpiredError, } from "./send/sign_and_send_transaction.js";
47
+ export { TransactionWaitError, waitTransaction } from "./send/wait_transaction.js";
48
+ export type { WaitTransactionOptions } from "./send/wait_transaction.js";
49
+ export { ickbExchangeRatio } from "./udt.js";
50
+ export type { SupportedChain } from "./utils/chain.js";
51
+ export type { ExchangeRatio, TransactionHeader, ValueComponents } from "./utils/utils.js";
4
52
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"../src/","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EACV,YAAY,EACZ,4BAA4B,EAC5B,2BAA2B,EAC3B,WAAW,EACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,+EAA+E;AAC/E,MAAM,WAAW,OAAO;IACtB,8EAA8E;IAC9E,0BAA0B,EAAE,CAC1B,MAAM,EAAE,GAAG,CAAC,eAAe,EAC3B,OAAO,EAAE,4BAA4B,KAClC,OAAO,CAAC,2BAA2B,CAAC,CAAC;IAC1C,oGAAoG;IACpG,iBAAiB,EAAE,CACjB,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,EACnB,MAAM,EAAE,YAAY,KACjB,OAAO,CAAC;QACX,MAAM,EAAE,WAAW,CAAC;QACpB,IAAI,EAAE;YAAE,MAAM,EAAE,UAAU,EAAE,CAAA;SAAE,CAAC;QAC/B,OAAO,EAAE,YAAY,CAAC;KACvB,CAAC,CAAC;CACJ;A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U,CAAC;AAC7D,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AACnF,YAAY,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,21 @@
1
- export * from "./sdk.js";
2
- export * from "./codec.js";
3
- export * from "./constants.js";
1
+ /**
2
+ * Public SDK for one iCKB conversion workflow: read the sampled state, quote, build and
3
+ * complete a conversion, sign, send, and wait.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ import { IckbSdk as IckbSdkClass } from "./sdk.js";
8
+ /** Creates the SDK for one chain's deployment. */
9
+ // eslint-disable-next-line @typescript-eslint/no-redeclare -- The public type and the constructor namespace intentionally share a name.
10
+ export const IckbSdk = IckbSdkClass;
11
+ export { DEFAULT_ORDER_FEE, DEFAULT_ORDER_FEE_BASE } from "./conversion/estimate.js";
12
+ export { projectConversionTransactionContext } from "./conversion/projection.js";
13
+ export { WALLET_LOCK_UP } from "./dao.js";
14
+ export { OrderConversionRepresentabilityError, quoteConversion, } from "./order/conversion.js";
15
+ export { isRefused, isStale } from "./order/fill.js";
16
+ export { Ratio } from "./order/ratio.js";
17
+ export { hasTransactionActivity, IckbError } from "./sdk.js";
18
+ export { signAndSendTransaction, signerAccountLocks, TransactionBroadcastError, TransactionExpiredError, } from "./send/sign_and_send_transaction.js";
19
+ export { TransactionWaitError, waitTransaction } from "./send/wait_transaction.js";
20
+ export { ickbExchangeRatio } from "./udt.js";
4
21
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,UAAU,CAAC;AAsBnD,kDAAkD;AAClD,wIAAwI;AACxI,MAAM,CAAC,MAAM,OAAO,GAAsD,YAAY,CAAC;AAEvF,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,mCAAmC,EAAE,MAAM,4BAA4B,CAAC;AAcjF,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAI1C,OAAO,EACL,oCAAoC,EACpC,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAIrD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAOzC,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE7D,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAEnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,85 @@
1
+ import { ccc } from "@ckb-ccc/core";
2
+ import { type LockUpPolicy } from "./dao.js";
3
+ import { type ScriptDeps, type TransactionHeader, type ValueComponents } from "./utils/utils.js";
4
+ /**
5
+ * A live iCKB deposit: a DAO deposit cell locked by the iCKB Logic script, valued at its
6
+ * deposit header.
7
+ */
8
+ export interface IckbDepositCell extends ValueComponents {
9
+ /** The DAO deposit cell. */
10
+ cell: ccc.Cell;
11
+ /** The deposit header and the tip the readiness was judged against. */
12
+ headers: [TransactionHeader, TransactionHeader];
13
+ /** The DAO interest accrued between the two headers. */
14
+ interests: ccc.Num;
15
+ /**
16
+ * The DAO claim epoch as sampled at the tip, not rolled: each reader judges it against
17
+ * its own {@link LockUpPolicy} with `depositMaturity`.
18
+ */
19
+ claimEpoch: ccc.Epoch;
20
+ }
21
+ /**
22
+ * Represents a receipt cell containing the receipt for iCKB Deposits.
23
+ */
24
+ export interface ReceiptCell extends ValueComponents {
25
+ /** The cell associated with the receipt. */
26
+ cell: ccc.Cell;
27
+ /** The header of the transaction that made the deposits. */
28
+ header: TransactionHeader;
29
+ }
30
+ /**
31
+ * Manages logic related to deposits and receipts in the blockchain.
32
+ */
33
+ export declare class LogicManager implements ScriptDeps {
34
+ /** The iCKB Logic script used as receipt type and DAO deposit lock. */
35
+ readonly script: ccc.Script;
36
+ /** Cell dependencies required to execute the iCKB Logic script. */
37
+ readonly cellDeps: ccc.CellDep[];
38
+ /** The Nervos DAO script the deposits carry, with its cell deps. */
39
+ readonly dao: ScriptDeps;
40
+ /** Creates the manager for one iCKB Logic deployment over one DAO deployment. */
41
+ constructor(script: ccc.Script, cellDeps: ccc.CellDep[], dao: ScriptDeps);
42
+ /** Whether the cell is an iCKB receipt: typed by the logic script with a decodable prefix. */
43
+ isReceipt(cell: ccc.Cell): boolean;
44
+ /** Whether the cell is a DAO deposit locked by the logic script. */
45
+ isDeposit(cell: ccc.Cell): boolean;
46
+ /**
47
+ * Adds `depositQuantity` DAO deposits of `depositCapacity` locked by the logic script,
48
+ * then the receipt that mints their iCKB in phase 2, locked by `lock`.
49
+ *
50
+ * @remarks Caller must ensure UDT cellDeps are added to the transaction
51
+ * (e.g., via ickbUdt.addCellDeps(tx)).
52
+ */
53
+ deposit(txLike: ccc.TransactionLike, depositQuantity: number, depositCapacity: ccc.FixedPoint, lock: ccc.Script): ccc.Transaction;
54
+ /**
55
+ * Adds receipt inputs and their deposit header deps for iCKB deposit completion.
56
+ *
57
+ * @remarks This prepares the phase-2 inputs; the iCKB they mint is completed by
58
+ * `IckbSdk.completeTransaction`.
59
+ */
60
+ completeDeposit(txLike: ccc.TransactionLike, receipts: ReceiptCell[]): ccc.Transaction;
61
+ /**
62
+ * The receipts among `cells`, valued at their deposit headers, each header read once.
63
+ */
64
+ receiptsFrom(client: ccc.Client, cells: readonly ccc.Cell[]): Promise<ReceiptCell[]>;
65
+ /**
66
+ * Every live iCKB deposit, valued at its deposit header, with its claim epoch at the tip;
67
+ * each deposit transaction's header is read once.
68
+ */
69
+ findDeposits(client: ccc.Client, tip: ccc.ClientBlockHeader): Promise<IckbDepositCell[]>;
70
+ }
71
+ /** Values a DAO deposit cell at its deposit header and samples its claim epoch at the tip. */
72
+ export declare function ickbDepositCell(cell: ccc.Cell, depositHeader: TransactionHeader, tip: ccc.ClientBlockHeader): IckbDepositCell;
73
+ /** The deposits a withdrawal request made now may claim at their sampled dates under the policy. */
74
+ export declare function readyDeposits(deposits: readonly IckbDepositCell[], tip: ccc.ClientBlockHeader, policy: LockUpPolicy): IckbDepositCell[];
75
+ /** Decodes a receipt cell and values it at its deposit header. */
76
+ export declare function receiptCell(cell: ccc.Cell, header: TransactionHeader): ReceiptCell;
77
+ /**
78
+ * Returns the CKB needed for the two phase-2 outputs created by one receipt.
79
+ *
80
+ * @remarks The value is sized with the actual user lock because lock args affect
81
+ * occupied capacity. It includes one plain output, one xUDT output, and the
82
+ * phase-2 fee reserve.
83
+ */
84
+ export declare function receiptPhase2Capacity(lock: ccc.Script): ccc.FixedPoint;
85
+ //# sourceMappingURL=logic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logic.d.ts","sourceRoot":"","sources":["../src/logic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM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