@ickb/sdk 9000.0.1 → 9001.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.
Files changed (138) hide show
  1. package/README.md +14 -11
  2. package/dist/constants.d.ts +0 -4
  3. package/dist/constants.d.ts.map +1 -1
  4. package/dist/constants.js +6 -24
  5. package/dist/constants.js.map +1 -1
  6. package/dist/conversion/estimate.d.ts +0 -6
  7. package/dist/conversion/estimate.d.ts.map +1 -1
  8. package/dist/conversion/estimate.js +1 -1
  9. package/dist/conversion/estimate.js.map +1 -1
  10. package/dist/conversion/maturity.d.ts +1 -1
  11. package/dist/conversion/maturity.js +13 -12
  12. package/dist/conversion/maturity.js.map +1 -1
  13. package/dist/conversion/plans.d.ts.map +1 -1
  14. package/dist/conversion/plans.js +6 -6
  15. package/dist/conversion/plans.js.map +1 -1
  16. package/dist/conversion/projection.d.ts +5 -6
  17. package/dist/conversion/projection.d.ts.map +1 -1
  18. package/dist/conversion/projection.js +11 -8
  19. package/dist/conversion/projection.js.map +1 -1
  20. package/dist/conversion/types.d.ts +29 -17
  21. package/dist/conversion/types.d.ts.map +1 -1
  22. package/dist/conversion/withdrawal_ring.d.ts +1 -3
  23. package/dist/conversion/withdrawal_ring.d.ts.map +1 -1
  24. package/dist/conversion/withdrawal_ring.js +4 -4
  25. package/dist/conversion/withdrawal_ring.js.map +1 -1
  26. package/dist/dao.d.ts +19 -5
  27. package/dist/dao.d.ts.map +1 -1
  28. package/dist/dao.js +24 -12
  29. package/dist/dao.js.map +1 -1
  30. package/dist/index.d.ts +9 -11
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +2 -2
  33. package/dist/index.js.map +1 -1
  34. package/dist/logic.d.ts +10 -14
  35. package/dist/logic.d.ts.map +1 -1
  36. package/dist/logic.js +28 -39
  37. package/dist/logic.js.map +1 -1
  38. package/dist/order/cells.d.ts +10 -49
  39. package/dist/order/cells.d.ts.map +1 -1
  40. package/dist/order/cells.js +28 -146
  41. package/dist/order/cells.js.map +1 -1
  42. package/dist/order/conversion.d.ts +3 -9
  43. package/dist/order/conversion.d.ts.map +1 -1
  44. package/dist/order/conversion.js +8 -11
  45. package/dist/order/conversion.js.map +1 -1
  46. package/dist/order/fill.d.ts +2 -2
  47. package/dist/order/fill.js +3 -3
  48. package/dist/order/fill.js.map +1 -1
  49. package/dist/order/info.d.ts.map +1 -1
  50. package/dist/order/info.js +3 -0
  51. package/dist/order/info.js.map +1 -1
  52. package/dist/order/matcher.d.ts +1 -1
  53. package/dist/order/matcher.d.ts.map +1 -1
  54. package/dist/order/matcher.js +3 -2
  55. package/dist/order/matcher.js.map +1 -1
  56. package/dist/order/order.d.ts +6 -2
  57. package/dist/order/order.d.ts.map +1 -1
  58. package/dist/order/order.js +32 -37
  59. package/dist/order/order.js.map +1 -1
  60. package/dist/order/order_data.d.ts.map +1 -1
  61. package/dist/order/order_data.js +3 -0
  62. package/dist/order/order_data.js.map +1 -1
  63. package/dist/order/ratio.d.ts +0 -2
  64. package/dist/order/ratio.d.ts.map +1 -1
  65. package/dist/order/ratio.js +3 -11
  66. package/dist/order/ratio.js.map +1 -1
  67. package/dist/order/relative.d.ts.map +1 -1
  68. package/dist/order/relative.js +3 -0
  69. package/dist/order/relative.js.map +1 -1
  70. package/dist/owned_owner.d.ts +10 -15
  71. package/dist/owned_owner.d.ts.map +1 -1
  72. package/dist/owned_owner.js +27 -47
  73. package/dist/owned_owner.js.map +1 -1
  74. package/dist/sdk.d.ts +74 -31
  75. package/dist/sdk.d.ts.map +1 -1
  76. package/dist/sdk.js +81 -59
  77. package/dist/sdk.js.map +1 -1
  78. package/dist/send/sign_and_send_transaction.d.ts +32 -17
  79. package/dist/send/sign_and_send_transaction.d.ts.map +1 -1
  80. package/dist/send/sign_and_send_transaction.js +128 -28
  81. package/dist/send/sign_and_send_transaction.js.map +1 -1
  82. package/dist/send/wait_transaction.d.ts +7 -6
  83. package/dist/send/wait_transaction.d.ts.map +1 -1
  84. package/dist/send/wait_transaction.js +29 -61
  85. package/dist/send/wait_transaction.js.map +1 -1
  86. package/dist/udt.d.ts +20 -35
  87. package/dist/udt.d.ts.map +1 -1
  88. package/dist/udt.js +39 -103
  89. package/dist/udt.js.map +1 -1
  90. package/dist/utils/chain.d.ts +0 -35
  91. package/dist/utils/chain.d.ts.map +1 -1
  92. package/dist/utils/chain.js +1 -19
  93. package/dist/utils/chain.js.map +1 -1
  94. package/dist/utils/codec.d.ts.map +1 -1
  95. package/dist/utils/codec.js +3 -0
  96. package/dist/utils/codec.js.map +1 -1
  97. package/dist/utils/utils.d.ts +19 -46
  98. package/dist/utils/utils.d.ts.map +1 -1
  99. package/dist/utils/utils.js +53 -74
  100. package/dist/utils/utils.js.map +1 -1
  101. package/dist/utils/verified_client.d.ts +19 -0
  102. package/dist/utils/verified_client.d.ts.map +1 -0
  103. package/dist/utils/verified_client.js +92 -0
  104. package/dist/utils/verified_client.js.map +1 -0
  105. package/package.json +2 -2
  106. package/src/constants.ts +6 -25
  107. package/src/conversion/estimate.ts +1 -3
  108. package/src/conversion/maturity.ts +13 -14
  109. package/src/conversion/plans.ts +6 -6
  110. package/src/conversion/projection.ts +15 -7
  111. package/src/conversion/types.ts +32 -17
  112. package/src/conversion/withdrawal_ring.ts +4 -8
  113. package/src/dao.ts +38 -14
  114. package/src/index.ts +8 -8
  115. package/src/logic.ts +40 -52
  116. package/src/order/cells.ts +37 -174
  117. package/src/order/conversion.ts +8 -19
  118. package/src/order/fill.ts +3 -3
  119. package/src/order/info.ts +3 -0
  120. package/src/order/matcher.ts +3 -3
  121. package/src/order/order.ts +38 -52
  122. package/src/order/order_data.ts +3 -0
  123. package/src/order/ratio.ts +3 -20
  124. package/src/order/relative.ts +3 -0
  125. package/src/owned_owner.ts +47 -77
  126. package/src/sdk.ts +95 -108
  127. package/src/send/sign_and_send_transaction.ts +164 -28
  128. package/src/send/wait_transaction.ts +44 -88
  129. package/src/udt.ts +56 -124
  130. package/src/utils/chain.ts +0 -41
  131. package/src/utils/codec.ts +4 -0
  132. package/src/utils/utils.ts +76 -105
  133. package/src/utils/verified_client.ts +136 -0
  134. package/dist/utils/transaction_header.d.ts +0 -17
  135. package/dist/utils/transaction_header.d.ts.map +0 -1
  136. package/dist/utils/transaction_header.js +0 -44
  137. package/dist/utils/transaction_header.js.map +0 -1
  138. package/src/utils/transaction_header.ts +0 -66
package/README.md CHANGED
@@ -15,13 +15,15 @@ The top-level script modules are `src/udt.ts` (iCKB), `src/logic.ts` (deposits a
15
15
 
16
16
  ## Account state
17
17
 
18
- `getL1AccountState(client, locks, lockUp)` reads the account, pool and order book. The caller supplies a `LockUpPolicy`, carried on `system.lockUp`; deposits carry a sampled `claimEpoch`, and readers apply the caller's policy to decide readiness. [`src/dao.ts`](src/dao.ts) defines the wallet and bot presets. A human can leave a wallet popup open, so the wallet's selection and broadcast margins are wider than the bot's.
18
+ `getL1AccountState(client, locks, lockUp, maxFeeRate?)` reads the account, pool and order book; `maxFeeRate` caps the node's sampled fee rate through CCC's `getFeeRate` (a cap of zero or less throws `RangeError`), so every consumer of the state (completion, the planned fee, the collect rule, estimates) plans at one rate. The caller supplies a `LockUpPolicy`, carried on `system.lockUp`; deposits carry a sampled `claimEpoch`, and readers apply the caller's policy to decide readiness. [`src/dao.ts`](src/dao.ts) defines the wallet and bot presets. A human can leave a wallet popup open, so the wallet's selection and broadcast margins are wider than the bot's.
19
19
 
20
20
  Each account lock is scanned once, unfiltered, then classified by cell kind. The book is also read once: the market sees orders past par, while the account sees its own orders. An older order from the same wallet legitimately queues ahead of its new one. Dual-ratio orders are valid on chain but excluded by the scan because Stack neither places nor handles them; they are not matched, estimated, displayed or collected here.
21
21
 
22
- Every cell scan uses the uncached [`findCells`](src/utils/utils.ts) loop with pages of 400, ending on the first short page. There is no aggregate scan budget or page-size option: a large account or book costs a slower read rather than a partial result. A full page whose cursor does not advance throws. The cursor is only a continuation key, not a snapshot; one traversal can return a cell and its successor. Planning must tolerate that rather than assume page coherence.
22
+ Every cell scan uses the uncached [`findCells`](src/utils/utils.ts) loop with pages of 400, ending on the first short page. It reads the indexer's raw answer through the client's JSON-RPC requestor, because the answer carries each cell's block number and CCC's typed scan drops it: receipts, deposits and withdrawal requests then read their committing header by number, instead of asking the node for each creating transaction's status first. The number is the node's claim either way. The SDK needs a JSON-RPC client for its raw reads (scans, status polls, transaction proofs); the connector's composition proxy forwards the requestor. It keeps no typed fallback for other clients: none exists in CCC, and two code paths per read had to be kept equivalent. Pages stay at 400 because CKB's sample config recommends that `request_limit`, and a node configured with it refuses a larger page rather than truncating it. There is no aggregate scan budget or page-size option: a large account or book costs a slower read rather than a partial result. A full page whose cursor does not advance throws. The cursor is only a continuation key, not a snapshot; one traversal can return a cell and its successor. Planning must tolerate that rather than assume page coherence.
23
23
 
24
- Transaction and header reads are batched before pure decoding. This replaced promise caches and batch-specific reader wrappers; each deposit carries its value instead of being valued again downstream. CCC's speculative broadcast cache is not authority for committed cells. An origin transaction cached without a block number is refreshed, as the comment at the order reader explains.
24
+ Transaction and header reads are batched before pure decoding. This replaced promise caches and batch-specific reader wrappers; each deposit carries its value instead of being valued again downstream. CCC's speculative broadcast cache is not authority for committed cells. An order is dated by its master's block from the scan: the master is created beside the mint order and never changes until melted, so no status read is needed; its origin transaction is read cache first, a cached body trusted like the scan itself, since the send checks every cell it spends.
25
+
26
+ Every node read in `getL1AccountState` and `signAndSendTransaction` goes through a wrapper the SDK puts on the client it is given, so a consumer passes a plain client and cannot forget. Completion and signing read through the signer's client and `waitTransaction` through the plain one: the send verifies every cell completion valued before signing, witnesses and cell deps are the signer's, and a transaction status has nothing to verify against. The wrapper checks every header against its own hash, a header read by number against the number asked for, and a transaction read by hash against the hash of its body; it serves a cell from that verified body, cache first, re-hashing a cache hit since a consumer's cache need not key bodies by their hash. A header's DAO rate sets the interest a withdrawal collects and the iCKB a deposit is worth. CCC's fee completion values that interest through the signer's client, which the SDK does not wrap, at whatever header the node names; the [send](#signing-and-broadcast) measures the fee from verified values and refuses one above what completion planned. The header beside a transaction or a cell is pinned only to the block the node names for it; the chain values a transaction at the headers it names in its deps, and the [send check](#signing-and-broadcast) refuses an input valued outside them and proves which block committed a withdrawal request. The state read is anchored at the tip's parent, which is bound two ways. Its age against the local clock, the selection margin less the broadcast reserve (five minutes for the bot, thirty for a wallet), catches an honest node that has fallen behind; the bound is on the parent, not the tip, because a fresh tip a node invented can name any old block as its parent. Completion names the parent as a header dep, so a header a node invented prices nothing the chain accepts. The send's deadline check reads the live tip under the same age bound. The bot, the generator and the interface open their clients with `clientCache()`: CCC's default cache keeps 128 blocks and 256 transaction bodies, fewer than a pool's deposits span or a large book's order origins, so every read refetched most of them; the larger cache holds 4096 of each, filling only as far as needed, and a cached header or body is still checked.
25
27
 
26
28
  ## Transaction completion
27
29
 
@@ -41,7 +43,7 @@ The sweep limit does not bound the whole transaction. Receipts and collectable o
41
43
 
42
44
  Plain-cell discovery does not filter mining rewards by cellbase maturity. If the scan returns an immature reward, completion can include it and the node rejects the transaction; rebuilding can select it again until it matures. This limitation is accepted: current use cases do not justify reward-specific discovery checks and their complexity.
43
45
 
44
- CKB capacity and iCKB quantity stay separate, in bigint. An input's full capacity funds the transaction, but the outputs' occupied capacity, a plain change cell, any order master and the fee still have to be paid. Ordinary change remains a plain cell; existing typed outputs are never repurposed as fee change. A duplicate input is a builder defect detected by completion.
46
+ CKB capacity and iCKB quantity stay separate, in bigint. An input's full capacity funds the transaction, but the outputs' occupied capacity, a plain change cell, any order master and the fee still have to be paid. Ordinary change remains a plain cell; existing typed outputs are never repurposed as fee change. A duplicate input is a builder defect detected by completion. Completion names the header the plan was priced at as the last header dep: a parent a node invented passes the hash checks and, dated fresh, the age bound, and its DAO rate sets the exchange ratio fills and orders are priced at, but the chain refuses a transaction whose header deps are off the main chain. Last, because the deployed dao.c reads one byte of a deposit header's index, so the deposit headers lead. That header is the tip's parent, for one more read: a tip can still lose a one-block race, and a transaction naming it is then refused after signing, as a testnet order was on 2026-10-30. Every fork recorded as an uncle in a day of each chain (257 on mainnet, 77 on testnet, to 2026-10-30) was one block deep, so a header further back would only add staleness. Receipts and deposits being withdrawn count at the iCKB value the state read gave them at their deposit headers, passed in as `protocolCells`, rather than each candidate asking the node again which block created them; a wrong value can only get the transaction refused by iCKB Logic's strict equality, and a protocol input without a value is a builder defect that throws.
45
47
 
46
48
  CCC prepares the signer and resolves the witness-aware fee; Stack owns the selected cells and output shape. Calling CCC's input collectors would introduce another discovery path with different cache and filtering rules. All candidate plans use the same sampled state.
47
49
 
@@ -49,19 +51,20 @@ DAO output and deposit-header limits come from the deployed script, not a genera
49
51
 
50
52
  ## Signing and broadcast
51
53
 
52
- `signAndSendTransaction(signer, tx, recordTxHash?, broadcastBefore?)` signs locally, then checks the body, fee rate and optional epoch deadline before sending.
54
+ `signAndSendTransaction(signer, tx, plannedFee, recordTxHash?, broadcastBefore?)` signs locally, then checks the body, the fee and the optional epoch deadline before sending.
53
55
 
54
- - Different ordered inputs, outputs or outputs data are rejected. Witnesses, `cellDeps` and `headerDeps` remain signer-owned. The fee ceiling values inputs from the pre-sign transaction.
55
- - The signed fee rate must not exceed CCC's maximum, which `sendTransactionNoCache` bypasses. There is no operator override that could silently disable this protection.
56
- - A withdrawal plan carries `broadcastBefore`, the earliest selected claim less the policy's reserve. After signing and the fee check, one fresh tip read rejects an expired plan with `TransactionExpiredError`, without broadcasting. Timing uses epochs because CKB has no transaction expiry and a request committed after its claim can lock the deposit for another cycle.
56
+ - Every input is verified before signing: its creating transaction is read from the client cache, else the node, and accepted only when its hash is the one the `OutPoint` names, so the output at the index is the real cell. A planned cell that differs from it in capacity, lock, type or data is rejected; an input without its cell attached is valued from that output. The default lock signs each input as its `OutPoint` only, so without this a node understating a plain cell's capacity or an iCKB amount would turn the difference into fee or a burn on a transaction that passes every other check. One `get_transaction` per distinct creating transaction not already cached.
57
+ - Different ordered inputs, outputs or outputs data are rejected. Witnesses, `cellDeps` and `headerDeps` remain signer-owned. The fee check values the verified inputs, and a phase-2 DAO input's interest at the deposit and request headers the transaction names in its deps: CCC values that interest from headers it reads afresh, which a node can answer with another real block, while the chain reads the deps, so an input valued at a header outside them is refused. The deps alone bind the request header to some block the transaction names, not to the block that committed the input, so in a withdrawal of several requests a node could swap which named request header values which input, paying the rate drift between the two blocks times the capacity imbalance to the miner. The send therefore asks the node for each request transaction's `get_transaction_proof` against the request header it valued, and refuses unless the Merkle path from the transaction's hash reaches that header's transactions root, which the header's own hash binds. That is one call of a few hundred bytes per request transaction per send, through the client's JSON-RPC requestor, which such a send therefore needs. The proven request header is the real request block, so dao.c's rule that it come after the deposit is left to the chain; a send-side copy of that rule, added before the proof, was dropped. A proven pair never changes, but caching it saved nothing: a request is spent once, and proven again only when a failed send is rebuilt. Rejected: reading the whole block, which proves the same at up to hundreds of kilobytes; a second node, which replaces proof with trust; a planner rule valuing every request at the highest-numbered dep, which closes the swap without a call but splits withdrawals by block; an on-chain script recomputing a digest of the inputs and their headers, whose carrier cell a flow's last transaction leaves behind; and accepting the swap, the earlier choice. Deposits, receipts and their headers need no proof: iCKB Logic settles them with strict equality, so a wrong header gets the transaction refused, and a deposit header is matched by the number in the verified cell data.
58
+ - The fee the chain will take must not exceed `plannedFee`, the fee completion priced: `tx.estimateFee(feeRate)`, which CCC's fee completion meets exactly. Completion valued phase-2 interest at whatever header the node named for the request, and a header that hashes correctly can still be one the chain does not use: a lower rate there shortens the change. Checking only CCC's maximum fee rate let that difference go to the miner, up to about 0.1 CKB per kB of transaction. Amounts are compared rather than rates, so the signed size does not matter. Rejected: re-pricing the completed transaction through a verified client, which reads the same node answer CCC read and so catches only a node changing its answer between two reads. The check also replaces CCC's maximum fee rate, which `sendTransactionNoCache` bypasses: CCC caps the rate `getFeeRate` samples at that maximum, so a fee planned from the state read's rate is within it, unless the caller passes its own `maxFeeRate`, which replaces that ceiling on purpose: the caller's cap is the ceiling, and a cap above CCC's lets a node's sample rise to it. That rate is a node statistic with no proof; the bot caps it with `BOT_MAX_FEE_RATE`, and a wallet shows the resulting fee before the user signs.
59
+ - A withdrawal plan carries `broadcastBefore`, the earliest selected claim less the policy's reserve. After signing and the fee check, one fresh tip read rejects an expired plan with `TransactionExpiredError`, without broadcasting. Timing uses epochs because CKB has no transaction expiry and a request committed after its claim can lock the deposit for another cycle. That tip is not a header dep, so a node can show a fresh tip from before the deadline and let an expired plan through; the cost is that extra cycle, time rather than CKB, which is accepted. Checking the priced header, a dep, plus the local clock's elapsed time would close it at the cost of estimating epochs from time.
57
60
 
58
61
  `recordTxHash` receives `signed.hash()` before the send RPC starts. That local hash is authoritative; no hash returned by a node replaces it. Comparing a successful response's hash could only reject after the node had already received the transaction. A duplicate response is accepted only when it names the local hash. Every other send failure is ambiguous and throws `TransactionBroadcastError` carrying `txHash`; callers can observe that hash instead of resending. The client cache is never marked by this helper.
59
62
 
60
63
  ## Confirmation
61
64
 
62
- `waitTransaction(client, txHash, { timeout?, interval?, signal? })` observes one already-broadcast transaction for a bounded window and returns it once the node reports commitment, at depth zero. `timeout` defaults to 60,000 ms and covers the whole wait, including in-flight client operations; it must be a non-negative safe integer no larger than a host timer delay. `interval` defaults to 2,000 ms.
65
+ `waitTransaction(client, txHash, { timeout?, interval?, signal? })` observes one already-broadcast transaction for a bounded window and resolves once the node reports commitment, at depth zero. `timeout` defaults to 60,000 ms and covers the whole wait, including in-flight client operations; it must be a non-negative safe integer no larger than a host timer delay. `interval` defaults to 2,000 ms.
63
66
 
64
- A client exposing a JSON-RPC requestor is polled with `get_transaction` verbosity 1, including the connector's composition proxy. CCC's typed read hides a rejected transaction with a null body, so raw status is needed to preserve rejection evidence. Body reads use `getTransactionNoCache` and are normalized with `ccc.ClientTransactionResponse.from`; a malformed generic-client response is treated as unconfirmed. The typed path remains for clients without a requestor.
67
+ The client is polled with `get_transaction` verbosity 1. CCC's typed read hides a rejected transaction with a null body, so raw status is needed to preserve rejection evidence. The body is never read: no caller uses it, and a second answer from the same node would verify nothing.
65
68
 
66
69
  A terminal rejection throws `TransactionWaitError` with the hash, status and node reason. Timeout uses CCC's `ErrorClientWaitTransactionTimeout`. Aborting or timing out stops the wait, but CCC transports may still finish their in-flight work; late settlement is handled. Nothing clears or marks the cache here.
67
70
 
@@ -77,7 +80,7 @@ CCC caches sufficiently old headers even across `ClientCacheMemory.clear()`. A c
77
80
 
78
81
  The repository follows [Epoch Semantic Versioning](https://antfu.me/posts/epoch-semver). The [release policy](../README.md#releases) explains this rewrite's starting version.
79
82
 
80
- Before this rewritten API is first published, its shape follows actual consumers rather than a committed API report. API Extractor still rejects forgotten exports, so every type reachable from the entry point is importable. A frozen report and release tags would add maintenance without a compatibility promise yet; revisit the report when the new surface has published consumers.
83
+ While the rewritten API has no outside consumers, its shape follows the stack's own rather than a committed API report, and a breaking change takes the next major version. API Extractor still rejects forgotten exports, so every type reachable from the entry point is importable. A frozen report and release tags would add maintenance without a compatibility promise yet; revisit the report when the new surface has published consumers.
81
84
 
82
85
  ## Licensing
83
86
 
@@ -1,9 +1,5 @@
1
1
  import type { SdkManagers } from "./conversion/types.js";
2
2
  import type { SupportedChain } from "./utils/chain.js";
3
- /**
4
- * Plain CKB the bot keeps for its own cells and fees: its sizing line for matches and deposits.
5
- */
6
- export declare const CKB_RESERVE: bigint;
7
3
  /**
8
4
  * The managers of one network's iCKB deployment.
9
5
  *
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAKzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAqEvD;;GAEG;AACH,eAAO,MAAM,WAAW,QAA2B,CAAC;AAEpD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,WAAW,CAqB5D"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAKzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAwDvD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,WAAW,CAoB5D"}
package/dist/constants.js CHANGED
@@ -33,41 +33,24 @@ const ORDER = ccc.Script.from({
33
33
  hashType: "data1",
34
34
  args: "0x",
35
35
  });
36
- /** Each network's code cells, given as direct code deps, and the dep group of the rest. */
36
+ /**
37
+ * Each network's iCKB dep group: it carries every iCKB script's code cell, xUDT's and
38
+ * iCKB Logic's included, so one group dep resolves them all.
39
+ */
37
40
  const DEPLOYMENTS = {
38
41
  mainnet: {
39
- udtCode: {
40
- txHash: "0xc07844ce21b38e4b071dd0e1ee3b0e27afd8d7532491327f39b786343f558ab7",
41
- index: 0,
42
- },
43
- logicCode: {
44
- txHash: "0xd7309191381f5a8a2904b8a79958a9be2752dbba6871fa193dab6aeb29dc8f44",
45
- index: 0,
46
- },
47
42
  depGroup: {
48
43
  txHash: "0x621a6f38de3b9f453016780edac3b26bfcbfa3e2ecb47c2da275471a5d3ed165",
49
44
  index: 0,
50
45
  },
51
46
  },
52
47
  testnet: {
53
- udtCode: {
54
- txHash: "0xbf6fb538763efec2a70a6a3dcb7242787087e1030c4e7d86585bc63a9d337f5f",
55
- index: 0,
56
- },
57
- logicCode: {
58
- txHash: "0x9ac989b3355764f76cdce02c69dedb819fdfbcbda49a7db1a2c9facdfdb9a7fe",
59
- index: 0,
60
- },
61
48
  depGroup: {
62
49
  txHash: "0xf7ece4fb33d8378344cab11fcd6a4c6f382fd4207ac921cf5821f30712dcd311",
63
50
  index: 0,
64
51
  },
65
52
  },
66
53
  };
67
- /**
68
- * Plain CKB the bot keeps for its own cells and fees: its sizing line for matches and deposits.
69
- */
70
- export const CKB_RESERVE = ccc.fixedPointFrom(1000);
71
54
  /**
72
55
  * The managers of one network's iCKB deployment.
73
56
  *
@@ -79,13 +62,12 @@ export function getConfig(chain) {
79
62
  if (!Object.hasOwn(DEPLOYMENTS, chain)) {
80
63
  throw new TypeError("unsupported iCKB network");
81
64
  }
82
- const { udtCode, logicCode, depGroup } = DEPLOYMENTS[chain];
65
+ const { depGroup } = DEPLOYMENTS[chain];
83
66
  const cellDeps = [ccc.CellDep.from({ outPoint: depGroup, depType: "depGroup" })];
84
67
  const dao = { script: DAO, cellDeps };
85
68
  const ickbUdt = new IckbUdt({
86
- code: udtCode,
87
69
  script: IckbUdt.typeScriptFrom(UDT, ICKB_LOGIC),
88
- logicCode,
70
+ cellDeps,
89
71
  logicScript: ICKB_LOGIC,
90
72
  daoScript: DAO,
91
73
  });
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAGnC,8BAA8B;AAC9B,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,QAAQ,EAAE,oEAAoE;IAC9E,QAAQ,EAAE,MAAM;IAChB,IAAI,EAAE,IAAI;CACX,CAAC,CAAC;AAEH,oFAAoF;AACpF,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,QAAQ,EAAE,oEAAoE;IAC9E,QAAQ,EAAE,OAAO;IACjB,IAAI,EAAE,IAAI;CACX,CAAC,CAAC;AAEH,yBAAyB;AACzB,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IACjC,QAAQ,EAAE,oEAAoE;IAC9E,QAAQ,EAAE,OAAO;IACjB,IAAI,EAAE,IAAI;CACX,CAAC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,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;IACjF,MAAM,GAAG,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;IACtC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC;QAC1B,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,EAAE,UAAU,CAAC;QAC/C,QAAQ;QACR,WAAW,EAAE,UAAU;QACvB,SAAS,EAAE,GAAG;KACf,CAAC,CAAC;IACH,OAAO;QACL,OAAO;QACP,UAAU,EAAE,IAAI,iBAAiB,CAAC,WAAW,EAAE,QAAQ,EAAE,GAAG,CAAC;QAC7D,SAAS,EAAE,IAAI,YAAY,CAAC,UAAU,EAAE,QAAQ,EAAE,GAAG,CAAC;QACtD,KAAK,EAAE,IAAI,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC;KACzD,CAAC;AACJ,CAAC"}
@@ -14,12 +14,6 @@ export declare function estimateConversionOrder(isCkb2Udt: boolean, amounts: Val
14
14
  fee: bigint;
15
15
  feeBase: bigint;
16
16
  }, takenDeposits?: readonly IckbDepositCell[]): ConversionOrderEstimate | undefined;
17
- /**
18
- * Returns the CKB fee threshold above which order maturity is worth estimating.
19
- * This conservative proxy stays separate from partialOrderFee: the quote has no built
20
- * order whose serialized size could supply that fee yet.
21
- */
22
- export declare function estimateMaturityFeeThreshold(system: Pick<SystemState, "feeRate">): bigint;
23
17
  /**
24
18
  * The smallest request one direction accepts as an order at the current fee rate. A
25
19
  * CKB-to-iCKB remainder pays the default order fee, which must cover the maturity threshold
@@ -1 +1 @@
1
- {"version":3,"file":"estimate.d.ts","sourceRoot":"","sources":["../../src/conversion/estimate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAKnD,OAAO,EAAW,KAAK,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AAC;AAErC,+EAA+E;AAC/E,eAAO,MAAM,sBAAsB,UAAU,CAAC;AAE9C,6FAA6F;AAC7F,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,OAAO,EAClB,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,WAAW,EACnB,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAClD,aAAa,GAAE,SAAS,eAAe,EAAO,GAC7C,uBAAuB,GAAG,SAAS,CAerC;AAWD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,MAAM,CAOlF;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,WAAW,EACnB,aAAa,EAAE,SAAS,eAAe,EAAE,GACxC,CAAC,uBAAuB,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,SAAS,CAyB9D"}
@@ -31,7 +31,7 @@ export function estimateConversionOrder(isCkb2Udt, amounts, system, { fee, feeBa
31
31
  * This conservative proxy stays separate from partialOrderFee: the quote has no built
32
32
  * order whose serialized size could supply that fee yet.
33
33
  */
34
- export function estimateMaturityFeeThreshold(system) {
34
+ function estimateMaturityFeeThreshold(system) {
35
35
  return 10n * system.feeRate;
36
36
  }
37
37
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"estimate.js","sourceRoot":"","sources":["../../src/conversion/estimate.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oCAAoC,EACpC,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,OAAO,EAAwB,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAErC,+EAA+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M,GAAG,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC9B,MAAM,aAAa,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;QAC3C,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;YAChC,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,IAAI,aAAa,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;YACtC,IAAI,GAAG,GAAG,CAAC;QACb,CAAC;aAAM,CAAC;YACN,GAAG,GAAG,GAAG,GAAG,EAAE,CAAC;QACjB,CAAC;IACH,CAAC;IACD,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,WAAW,CAAC,GAAW;IAC9B,OAAO,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;AAC7B,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import type { IckbDepositCell } from "../logic.js";
2
2
  import type { MaturityOrderInput, SystemState } from "./types.js";
3
3
  /**
4
- * Assumed turn duration, allowing for restart delay, confirmation and slow reads.
4
+ * Assumed turn duration: the bot's turns start ten minutes apart.
5
5
  * This is a modeling interval, not a bound on the runtime; see sdk/docs/pool_maturity_estimates.md.
6
6
  */
7
7
  export declare const BOT_TURN_MS: bigint;
@@ -1,9 +1,9 @@
1
1
  import { BOT_LOCK_UP, depositMaturity } from "../dao.js";
2
2
  import { fillsWhole } from "../order/fill.js";
3
- import { convert, ICKB_DEPOSIT_CAP } from "../udt.js";
4
- import { compareBigInt } from "../utils/utils.js";
3
+ import { ckbFromUdt, ICKB_DEPOSIT_CAP } from "../udt.js";
4
+ import { ceilDiv, compareBigInt } from "../utils/utils.js";
5
5
  /**
6
- * Assumed turn duration, allowing for restart delay, confirmation and slow reads.
6
+ * Assumed turn duration: the bot's turns start ten minutes apart.
7
7
  * This is a modeling interval, not a bound on the runtime; see sdk/docs/pool_maturity_estimates.md.
8
8
  */
9
9
  export const BOT_TURN_MS = 10n * 60n * 1000n;
@@ -47,8 +47,8 @@ function ckbToIckbOrderMaturity(info, amount, system, self) {
47
47
  .filter((group) => group.order.data.info.ckbToUdt.compare(info.ckbToUdt) <= 0)
48
48
  .reduce((ckb, group) => ckb + group.order.ckbUnoccupied, 0n);
49
49
  const sellers = fillableOrders(system, false, self).reduce((udt, group) => udt + group.udtValue, 0n);
50
- const demand = amount + buyersAhead - convert(false, sellers, system.exchangeRatio);
51
- const capCkb = convert(false, ICKB_DEPOSIT_CAP, system.exchangeRatio);
50
+ const demand = amount + buyersAhead - ckbFromUdt(sellers, system.exchangeRatio);
51
+ const capCkb = ckbFromUdt(ICKB_DEPOSIT_CAP, system.exchangeRatio);
52
52
  const turns = demand > 0n ? 1n + demand / capCkb : 1n;
53
53
  return system.tip.timestamp + BOT_TURN_MS * turns;
54
54
  }
@@ -65,14 +65,14 @@ function ickbToCkbOrderMaturity(info, amount, system, takenDeposits, self) {
65
65
  .reduce((udt, group) => udt + group.udtValue, 0n);
66
66
  // The CKB an order has already received belongs to its earlier fills; what it still
67
67
  // needs is the remaining iCKB at its price.
68
- const needed = info.udtToCkb.convert(false, amount, true) +
69
- convert(false, sellersAhead, system.exchangeRatio);
68
+ const needed = ceilDiv(amount * info.udtToCkb.udtScale, info.udtToCkb.ckbScale) +
69
+ ckbFromUdt(sellersAhead, system.exchangeRatio);
70
70
  const taken = new Set(takenDeposits.map((deposit) => deposit.cell.outPoint.toHex()));
71
71
  const steps = [
72
72
  {
73
73
  ckbValue: sellers.some((group) => sits(group, system))
74
74
  ? 0n
75
- : convert(false, ICKB_DEPOSIT_CAP, system.exchangeRatio),
75
+ : ckbFromUdt(ICKB_DEPOSIT_CAP, system.exchangeRatio),
76
76
  at: system.tip.timestamp,
77
77
  },
78
78
  // A claim the bot can no longer request in time rolls a cycle: the bot's rule, not the
@@ -102,11 +102,12 @@ function fillableOrders(system, isCkb2Udt, self) {
102
102
  fillsWhole(group, isCkb2Udt, system.exchangeRatio, system.feeRate));
103
103
  }
104
104
  /**
105
- * Whether the order has been on the book for more than a turn, a twenty-fourth of an
106
- * epoch in blocks: the bot has seen it and left it. An uncommitted origin is fresh.
105
+ * Whether the order has been on the book for more than an eighth of an epoch in blocks,
106
+ * about three ten-minute turns: the bot has seen it and left it. A turn alone left no
107
+ * margin, since an order placed just after a turn waits a turn to be seen, and a failed
108
+ * turn adds the restart delay.
107
109
  */
108
110
  function sits(group, { tip }) {
109
- return (group.blockNumber !== undefined &&
110
- tip.number - group.blockNumber > tip.epoch.denominator / 24n);
111
+ return tip.number - group.blockNumber > tip.epoch.denominator / 8n;
111
112
  }
112
113
  //# sourceMappingURL=maturity.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"maturity.js","sourceRoot":"","sources":["../../src/conversion/maturity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAGzD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,aAAa,EAAwB,MAAM,mBAAmB,CAAC;AAGxE;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,GAAG,GAAG,GAAG,KAAK,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CACtB,CAAqB,EACrB,MAAmB,EACnB,aAAa,GAA+B,EAAE;IAE9C,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC;IACtD,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IACnC,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC/D,IAAI,MAAM,KAAK,EAAE,EAAE,CAAC;QAClB,OAAO,EAAE,CA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AAE,4BAA4B,GACpC,uBAAuB,EAAE,CAgB3B;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,4BAA4B,EACrC,YAAY,EAAE,SAAS,eAAe,EAAE,GACvC,uBAAuB,EAAE,CAc3B"}
1
+ {"version":3,"file":"plans.d.ts","sourceRoot":"","sources":["../../src/conversion/plans.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AASlE,OAAO,KAAK,EACV,uBAAuB,EAEvB,4BAA4B,EAC5B,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAWpB;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,4BAA4B,GACpC,uBAAuB,EAAE,CAgB3B;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,4BAA4B,EACrC,YAAY,EAAE,SAAS,eAAe,EAAE,GACvC,uBAAuB,EAAE,CAc3B"}
@@ -1,7 +1,7 @@
1
+ import { ccc } from "@ckb-ccc/core";
1
2
  import { DAO_OUTPUT_LIMIT } from "../dao.js";
2
3
  import { readyDeposits } from "../logic.js";
3
- import { ICKB_DEPOSIT_CAP, convert } from "../udt.js";
4
- import { maxBigInt } from "../utils/utils.js";
4
+ import { ICKB_DEPOSIT_CAP, ckbFromUdt } from "../udt.js";
5
5
  import { DEFAULT_ORDER_FEE, DEFAULT_ORDER_FEE_BASE, estimateConversionOrder, estimateIckbToCkbOrder, } from "./estimate.js";
6
6
  import { sumUdt } from "./projection.js";
7
7
  import { fitWithdrawalDeposits, ringSurplusDepositFilter, sortByClaim, } from "./withdrawal_ring.js";
@@ -18,7 +18,7 @@ const MAX_PLANNED_DEPOSITS = DAO_OUTPUT_LIMIT - 1;
18
18
  */
19
19
  export function ckbToIckbConversionPlans(options) {
20
20
  const { amount, context } = options;
21
- const depositCapacity = convert(false, ICKB_DEPOSIT_CAP, context.system.exchangeRatio);
21
+ const depositCapacity = ckbFromUdt(ICKB_DEPOSIT_CAP, context.system.exchangeRatio);
22
22
  const depositQuotient = depositCapacity === 0n ? 0n : amount / depositCapacity;
23
23
  const maxDeposits = depositQuotient > BigInt(MAX_PLANNED_DEPOSITS)
24
24
  ? MAX_PLANNED_DEPOSITS
@@ -68,7 +68,7 @@ function ckbToIckbConversionPlan(options, depositCapacity, depositCount) {
68
68
  if (estimate?.maturity === undefined) {
69
69
  return undefined;
70
70
  }
71
- estimatedMaturity = maxBigInt(estimatedMaturity, estimate.maturity);
71
+ estimatedMaturity = ccc.numMax(estimatedMaturity, estimate.maturity);
72
72
  order = { amounts, estimate };
73
73
  }
74
74
  return {
@@ -83,7 +83,7 @@ function ickbToCkbConversionPlan(options, selectedDeposits) {
83
83
  let estimatedMaturity = context.estimatedMaturity;
84
84
  // Selected deposits are ready, so their sampled claim is their date.
85
85
  for (const deposit of selectedDeposits) {
86
- estimatedMaturity = maxBigInt(estimatedMaturity, deposit.claimEpoch.toUnix(context.system.tip));
86
+ estimatedMaturity = ccc.numMax(estimatedMaturity, deposit.claimEpoch.toUnix(context.system.tip));
87
87
  }
88
88
  const remainder = amount - sumUdt(selectedDeposits);
89
89
  let order;
@@ -94,7 +94,7 @@ function ickbToCkbConversionPlan(options, selectedDeposits) {
94
94
  if (estimate === undefined) {
95
95
  return undefined;
96
96
  }
97
- estimatedMaturity = maxBigInt(estimatedMaturity, estimate.maturity);
97
+ estimatedMaturity = ccc.numMax(estimatedMaturity, estimate.maturity);
98
98
  order = { amounts, estimate };
99
99
  }
100
100
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"plans.js","sourceRoot":"","sources":["../../src/conversion/plans.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAwB,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,SAA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CAAC;AAED,SAAS,uBAAuB,CAC9B,OAAqC,EACrC,gBAAmC;IAEnC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IACpC,IAAI,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAClD,qEAAqE;IACrE,KAAK,MAAM,OAAO,IAAI,gBAAgB,EAAE,CAAC;QACvC,iBAAiB,GAAG,GAAG,CAAC,MAAM,CAC5B,iBAAiB,EACjB,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAC9C,CAAC;IACJ,CAAC;IACD,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;IACpD,IAAI,KAAkC,CAAC;IACvC,IAAI,SAAS,GAAG,EAAE,EAAE,CAAC;QACnB,MAAM,OAAO,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;QACtD,2EAA2E;QAC3E,MAAM,QAAQ,GAAG,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;QACnF,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,iBAAiB,GAAG,GAAG,CAAC,MAAM,CAAC,iBAAiB,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACrE,KAAK,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;IAChC,CAAC;IAED,OAAO;QACL,iBAAiB;QACjB,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;QACzC,gBAAgB;KACjB,CAAC;AACJ,CAAC"}
@@ -2,13 +2,12 @@ import type { OrderGroup } from "../order/cells.js";
2
2
  import type { AccountAvailabilityProjection, AccountState, ConversionTransactionContextProjection, SystemState } from "./types.js";
3
3
  /**
4
4
  * Builds the conversion planner context from account state and the caller's own orders,
5
- * split by what it will melt: `available` orders are collected and budgeted as account
6
- * value, `pending` ones stay on the book.
5
+ * split by what it will melt: fulfilled orders, buys the bot's whole-fill rule refuses,
6
+ * and orders past the age cutoff are collected and budgeted as account value; the rest
7
+ * stay on the book. DAO growth can make a waiting sell profitable later, so a sell waits
8
+ * for the age cutoff even when the bot would not fill it today.
7
9
  */
8
- export declare function projectConversionTransactionContext(system: SystemState, account: AccountState, orders: {
9
- available: OrderGroup[];
10
- pending: OrderGroup[];
11
- }): ConversionTransactionContextProjection;
10
+ export declare function projectConversionTransactionContext(system: SystemState, account: AccountState, orders: readonly OrderGroup[]): ConversionTransactionContextProjection;
12
11
  /**
13
12
  * Splits wallet-owned CKB and iCKB into immediately available and pending value.
14
13
  */
@@ -1 +1 @@
1
- {"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../src/conversion/projection.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAIpD,OAAO,KAAK,EACV,6BAA6B,EAC7B,YAAY,EACZ,sCAAsC,EACtC,WAAW,EACZ,MAAM,YAAY,CAAC;AAEpB;;;;GAIG;AACH,wBAAgB,mCAAmC,CACjD,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE;IAAE,SAAS,EAAE,UAAU,EAAE,CAAC;IAAC,OAAO,EAAE,UAAU,EAAE,CAAA;CAAE,GACzD,sCAAsC,CAsBxC;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,YAAY,EACrB,EACE,SAAS,EAAE,eAAe,EAC1B,OAAO,EAAE,aAAa,GACvB,EAAE;IAAE,SAAS,EAAE,UAAU,EAAE,CAAC;IAAC,OAAO,EAAE,UAAU,EAAE,CAAA;CAAE,GACpD,6BAA6B,CAmC/B;AA2BD,wBAAgB,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,MAAM,CAEzE"}
1
+ {"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../src/conversion/projection.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAIpD,OAAO,KAAK,EACV,6BAA6B,EAC7B,YAAY,EACZ,sCAAsC,EACtC,WAAW,EACZ,MAAM,YAAY,CAAC;AAEpB;;;;;;GAMG;AACH,wBAAgB,mCAAmC,CACjD,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,SAAS,UAAU,EAAE,GAC5B,sCAAsC,CA4BxC;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,YAAY,EACrB,EACE,SAAS,EAAE,eAAe,EAC1B,OAAO,EAAE,aAAa,GACvB,EAAE;IAAE,SAAS,EAAE,UAAU,EAAE,CAAC;IAAC,OAAO,EAAE,UAAU,EAAE,CAAA;CAAE,GACpD,6BAA6B,CAmC/B;AA2BD,wBAAgB,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,MAAM,CAEzE"}
@@ -1,18 +1,21 @@
1
1
  import { ccc } from "@ckb-ccc/core";
2
2
  import { DAO_HEADER_INDEX_LIMIT } from "../dao.js";
3
- import { maxBigInt } from "../utils/utils.js";
3
+ import { isRefused, isStale } from "../order/fill.js";
4
4
  import { maturity } from "./maturity.js";
5
5
  /**
6
6
  * Builds the conversion planner context from account state and the caller's own orders,
7
- * split by what it will melt: `available` orders are collected and budgeted as account
8
- * value, `pending` ones stay on the book.
7
+ * split by what it will melt: fulfilled orders, buys the bot's whole-fill rule refuses,
8
+ * and orders past the age cutoff are collected and budgeted as account value; the rest
9
+ * stay on the book. DAO growth can make a waiting sell profitable later, so a sell waits
10
+ * for the age cutoff even when the bot would not fill it today.
9
11
  */
10
12
  export function projectConversionTransactionContext(system, account, orders) {
11
- const projection = projectAccountAvailability(account, orders);
12
- const estimatedMaturity = [
13
- ...projection.pendingWithdrawals.map((group) => group.owned.maturity.toUnix(system.tip)),
14
- ...projection.pendingOrders.map((group) => maturity(group.order, system)),
15
- ].reduce(maxBigInt, system.tip.timestamp);
13
+ const collectable = (group) => group.order.isFulfilled() || isRefused(group, system) || isStale(group, system.tip);
14
+ const projection = projectAccountAvailability(account, {
15
+ available: orders.filter(collectable),
16
+ pending: orders.filter((group) => !collectable(group)),
17
+ });
18
+ const estimatedMaturity = ccc.numMax(system.tip.timestamp, ...projection.pendingWithdrawals.map((group) => group.owned.maturity.toUnix(system.tip)), ...projection.pendingOrders.map((group) => maturity(group.order, system)));
16
19
  return {
17
20
  projection,
18
21
  context: {
@@ -1 +1 @@
1
- {"version":3,"file":"projection.js","sourceRoot":"","sources":["../../src/conversion/projection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAGnD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAQzC;;;;GAIG;AACH,MAAM,UAAU,mCAAmC,CACjD,MAAmB,EACnB,OAAqB,EACrB,MAA0D;IAE1D,MAAM,UAAU,GAAG,0BAA0B,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC/D,MAAM,iBAAiB,GAAG;QACxB,GAAG,UAAU,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAC7C,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CACxC;QACD,GAAG,UAAU,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,EAA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AAI,KAAmB,EAAE,OAA4B;IACrE,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -1,12 +1,12 @@
1
1
  import type { ccc } from "@ckb-ccc/core";
2
- import type { LockUpPolicy } from "../dao.js";
2
+ import type { BroadcastDeadline, LockUpPolicy } from "../dao.js";
3
3
  import type { IckbDepositCell, LogicManager, ReceiptCell } from "../logic.js";
4
4
  import type { OrderCell, OrderGroup } from "../order/cells.js";
5
5
  import type { Info } from "../order/info.js";
6
6
  import type { OrderManager } from "../order/order.js";
7
7
  import type { Ratio } from "../order/ratio.js";
8
8
  import type { OwnedOwnerManager, WithdrawalGroup } from "../owned_owner.js";
9
- import type { IckbUdt } from "../udt.js";
9
+ import type { IckbUdt, ProtocolCell } from "../udt.js";
10
10
  import type { ValueComponents } from "../utils/utils.js";
11
11
  /**
12
12
  * Direction requested by a conversion transaction.
@@ -71,13 +71,8 @@ export interface ConversionNotice {
71
71
  /** CKB incentive associated with the noticed path. */
72
72
  incentiveCkb: bigint;
73
73
  }
74
- /**
75
- * High-level conversion composition used by a built transaction.
76
- */
77
- export interface ConversionMetadata {
78
- /** Composition category selected for the built conversion. */
79
- kind: "direct" | "order" | "direct-plus-order" | "collect-only";
80
- }
74
+ /** Composition category selected for a built conversion. */
75
+ export type ConversionKind = "direct" | "order" | "direct-plus-order" | "collect-only";
81
76
  /**
82
77
  * Result of attempting to build a conversion transaction.
83
78
  */
@@ -88,7 +83,7 @@ export type ConversionTransactionResult = {
88
83
  /** Estimated maturity timestamp for the conversion result. */
89
84
  estimatedMaturity: bigint;
90
85
  /** Composition of the selected conversion path. */
91
- conversion: ConversionMetadata;
86
+ conversionKind: ConversionKind;
92
87
  /** Optional notice about the selected path. */
93
88
  conversionNotice?: ConversionNotice;
94
89
  /**
@@ -100,18 +95,23 @@ export type ConversionTransactionResult = {
100
95
  * The epoch the transaction must be broadcast before for its withdrawal requests to
101
96
  * claim at their sampled dates (`system.lockUp`); absent when it requests none.
102
97
  */
103
- broadcastBefore?: ccc.Epoch;
98
+ broadcastBefore?: BroadcastDeadline;
104
99
  } | {
105
100
  ok: false;
106
- /** Machine-readable failure reason. */
107
- reason: ConversionTransactionFailureReason;
101
+ reason: "amount-too-small";
108
102
  /** Best available maturity estimate from the input context. */
109
103
  estimatedMaturity: bigint;
110
104
  /**
111
- * For `amount-too-small`: the smallest amount this direction accepts at the current fee
112
- * rate, in the request's unit (CKB shannons or iCKB), so a caller can name it.
105
+ * The smallest amount this direction accepts at the current fee rate, in the
106
+ * request's unit (CKB shannons or iCKB), so a caller can name it.
113
107
  */
114
- minimum?: bigint;
108
+ minimum: bigint;
109
+ } | {
110
+ ok: false;
111
+ /** Machine-readable failure reason. */
112
+ reason: Exclude<ConversionTransactionFailureReason, "amount-too-small">;
113
+ /** Best available maturity estimate from the input context. */
114
+ estimatedMaturity: bigint;
115
115
  };
116
116
  /**
117
117
  * Options for completing a partial iCKB transaction before signing and sending.
@@ -125,6 +125,18 @@ export interface CompleteIckbTransactionOptions {
125
125
  feeRate: ccc.Num;
126
126
  /** The signer's known liquid cells, plain CKB and iCKB, from the account state already read. */
127
127
  cells: ccc.Cell[];
128
+ /**
129
+ * The receipts and iCKB deposits the transaction may spend, valued by the state read;
130
+ * any superset works, since only the spent ones are summed.
131
+ */
132
+ protocolCells: readonly ProtocolCell[];
133
+ /**
134
+ * The header the plan was priced at, the state read's `system.tip`, named as a header
135
+ * dep: the chain refuses a transaction whose deps are off the main chain, so a header a
136
+ * node invented, whose DAO rate set the exchange ratio, cannot price an accepted
137
+ * transaction.
138
+ */
139
+ tip: ccc.ClientBlockHeader;
128
140
  }
129
141
  /**
130
142
  * Quote details for one order-based conversion path.
@@ -212,7 +224,7 @@ export interface ConversionTransactionContextProjection {
212
224
  export interface SystemState {
213
225
  /** The fee rate for transactions. */
214
226
  feeRate: ccc.Num;
215
- /** Sampled tip used for this L1 scan. It may be stale after scans complete. */
227
+ /** The sampled tip's parent, this L1 scan's anchor. It may be stale after scans complete. */
216
228
  tip: ccc.ClientBlockHeader;
217
229
  /** The exchange ratio between CKB and UDT. */
218
230
  exchangeRatio: Ratio;