@ickb/sdk 1000.0.82 → 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.
- package/README.md +81 -32
- package/dist/constants.d.ts +13 -22
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +80 -76
- package/dist/constants.js.map +1 -1
- package/dist/conversion/estimate.d.ts +39 -0
- package/dist/conversion/estimate.d.ts.map +1 -0
- package/dist/conversion/estimate.js +117 -0
- package/dist/conversion/estimate.js.map +1 -0
- package/dist/conversion/maturity.d.ts +15 -0
- package/dist/conversion/maturity.d.ts.map +1 -0
- package/dist/conversion/maturity.js +112 -0
- package/dist/conversion/maturity.js.map +1 -0
- package/dist/conversion/plans.d.ts +20 -0
- package/dist/conversion/plans.d.ts.map +1 -0
- package/dist/conversion/plans.js +106 -0
- package/dist/conversion/plans.js.map +1 -0
- package/dist/conversion/projection.d.ts +22 -0
- package/dist/conversion/projection.d.ts.map +1 -0
- package/dist/conversion/projection.js +91 -0
- package/dist/conversion/projection.js.map +1 -0
- package/dist/conversion/types.d.ts +252 -0
- package/dist/conversion/types.d.ts.map +1 -0
- package/dist/conversion/types.js +2 -0
- package/dist/conversion/types.js.map +1 -0
- package/dist/conversion/withdrawal_ring.d.ts +36 -0
- package/dist/conversion/withdrawal_ring.d.ts.map +1 -0
- package/dist/conversion/withdrawal_ring.js +87 -0
- package/dist/conversion/withdrawal_ring.js.map +1 -0
- package/dist/dao.d.ts +86 -0
- package/dist/dao.d.ts.map +1 -0
- package/dist/dao.js +113 -0
- package/dist/dao.js.map +1 -0
- package/dist/index.d.ts +51 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -3
- package/dist/index.js.map +1 -1
- package/dist/logic.d.ts +85 -0
- package/dist/logic.d.ts.map +1 -0
- package/dist/logic.js +184 -0
- package/dist/logic.js.map +1 -0
- package/dist/order/cells.d.ts +207 -0
- package/dist/order/cells.d.ts.map +1 -0
- package/dist/order/cells.js +427 -0
- package/dist/order/cells.js.map +1 -0
- package/dist/order/conversion.d.ts +43 -0
- package/dist/order/conversion.d.ts.map +1 -0
- package/dist/order/conversion.js +123 -0
- package/dist/order/conversion.js.map +1 -0
- package/dist/order/fee.d.ts +9 -0
- package/dist/order/fee.d.ts.map +1 -0
- package/dist/order/fee.js +24 -0
- package/dist/order/fee.js.map +1 -0
- package/dist/order/fill.d.ts +36 -0
- package/dist/order/fill.d.ts.map +1 -0
- package/dist/order/fill.js +53 -0
- package/dist/order/fill.js.map +1 -0
- package/dist/order/info.d.ts +62 -0
- package/dist/order/info.d.ts.map +1 -0
- package/dist/order/info.js +99 -0
- package/dist/order/info.js.map +1 -0
- package/dist/order/master.d.ts +49 -0
- package/dist/order/master.d.ts.map +1 -0
- package/dist/order/master.js +27 -0
- package/dist/order/master.js.map +1 -0
- package/dist/order/matcher.d.ts +43 -0
- package/dist/order/matcher.d.ts.map +1 -0
- package/dist/order/matcher.js +123 -0
- package/dist/order/matcher.js.map +1 -0
- package/dist/order/order.d.ts +59 -0
- package/dist/order/order.d.ts.map +1 -0
- package/dist/order/order.js +239 -0
- package/dist/order/order.js.map +1 -0
- package/dist/order/order_data.d.ts +51 -0
- package/dist/order/order_data.d.ts.map +1 -0
- package/dist/order/order_data.js +64 -0
- package/dist/order/order_data.js.map +1 -0
- package/dist/order/ratio.d.ts +42 -0
- package/dist/order/ratio.d.ts.map +1 -0
- package/dist/order/ratio.js +82 -0
- package/dist/order/ratio.js.map +1 -0
- package/dist/order/relative.d.ts +43 -0
- package/dist/order/relative.d.ts.map +1 -0
- package/dist/order/relative.js +54 -0
- package/dist/order/relative.js.map +1 -0
- package/dist/owned_owner.d.ts +113 -0
- package/dist/owned_owner.d.ts.map +1 -0
- package/dist/owned_owner.js +280 -0
- package/dist/owned_owner.js.map +1 -0
- package/dist/sdk.d.ts +71 -42
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +388 -209
- package/dist/sdk.js.map +1 -1
- package/dist/send/sign_and_send_transaction.d.ts +46 -0
- package/dist/send/sign_and_send_transaction.d.ts.map +1 -0
- package/dist/send/sign_and_send_transaction.js +101 -0
- package/dist/send/sign_and_send_transaction.js.map +1 -0
- package/dist/send/wait_transaction.d.ts +41 -0
- package/dist/send/wait_transaction.d.ts.map +1 -0
- package/dist/send/wait_transaction.js +204 -0
- package/dist/send/wait_transaction.js.map +1 -0
- package/dist/udt.d.ts +123 -0
- package/dist/udt.d.ts.map +1 -0
- package/dist/udt.js +244 -0
- package/dist/udt.js.map +1 -0
- package/dist/utils/chain.d.ts +38 -0
- package/dist/utils/chain.d.ts.map +1 -0
- package/dist/utils/chain.js +20 -0
- package/dist/utils/chain.js.map +1 -0
- package/dist/utils/codec.d.ts +19 -0
- package/dist/utils/codec.d.ts.map +1 -0
- package/dist/utils/codec.js +66 -0
- package/dist/utils/codec.js.map +1 -0
- package/dist/utils/transaction_header.d.ts +17 -0
- package/dist/utils/transaction_header.d.ts.map +1 -0
- package/dist/utils/transaction_header.js +44 -0
- package/dist/utils/transaction_header.js.map +1 -0
- package/dist/utils/utils.d.ts +126 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +151 -0
- package/dist/utils/utils.js.map +1 -0
- package/package.json +19 -26
- package/src/constants.ts +84 -181
- package/src/conversion/estimate.ts +157 -0
- package/src/conversion/maturity.ts +159 -0
- package/src/conversion/plans.ts +144 -0
- package/src/conversion/projection.ts +128 -0
- package/src/conversion/types.ts +287 -0
- package/src/conversion/withdrawal_ring.ts +126 -0
- package/src/dao.ts +172 -0
- package/src/index.ts +89 -3
- package/src/logic.ts +295 -0
- package/src/order/cells.ts +520 -0
- package/src/order/conversion.ts +173 -0
- package/src/order/fee.ts +30 -0
- package/src/order/fill.ts +83 -0
- package/src/order/info.ts +178 -0
- package/src/order/master.ts +42 -0
- package/src/order/matcher.ts +191 -0
- package/src/order/order.ts +302 -0
- package/src/order/order_data.ts +128 -0
- package/src/order/ratio.ts +144 -0
- package/src/order/relative.ts +106 -0
- package/src/owned_owner.ts +394 -0
- package/src/sdk.ts +555 -440
- package/src/send/sign_and_send_transaction.ts +120 -0
- package/src/send/wait_transaction.ts +271 -0
- package/src/udt.ts +317 -0
- package/src/utils/chain.ts +43 -0
- package/src/utils/codec.ts +74 -0
- package/src/utils/transaction_header.ts +66 -0
- package/src/utils/utils.ts +237 -0
- package/dist/codec.d.ts +0 -3
- package/dist/codec.d.ts.map +0 -1
- package/dist/codec.js +0 -58
- package/dist/codec.js.map +0 -1
- package/src/codec.ts +0 -138
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { BOT_LOCK_UP, depositMaturity } from "../dao.js";
|
|
2
|
+
import { fillsWhole } from "../order/fill.js";
|
|
3
|
+
import { convert, ICKB_DEPOSIT_CAP } from "../udt.js";
|
|
4
|
+
import { compareBigInt } from "../utils/utils.js";
|
|
5
|
+
/**
|
|
6
|
+
* Assumed turn duration, allowing for restart delay, confirmation and slow reads.
|
|
7
|
+
* This is a modeling interval, not a bound on the runtime; see sdk/docs/pool_maturity_estimates.md.
|
|
8
|
+
*/
|
|
9
|
+
export const BOT_TURN_MS = 10n * 60n * 1000n;
|
|
10
|
+
/**
|
|
11
|
+
* The estimated fill time of an order on the book or about to be placed, zero when it is
|
|
12
|
+
* already fulfilled. `takenDeposits` are the pool deposits the same plan withdraws
|
|
13
|
+
* directly, which cannot fill its order leg too. Dual-ratio orders never reach here: the
|
|
14
|
+
* scan drops them.
|
|
15
|
+
*/
|
|
16
|
+
export function maturity(o, system, takenDeposits = []) {
|
|
17
|
+
const { info, amounts, self } = maturityOrderParts(o);
|
|
18
|
+
const isCkb2Udt = info.isCkb2Udt();
|
|
19
|
+
const amount = isCkb2Udt ? amounts.ckbValue : amounts.udtValue;
|
|
20
|
+
if (amount === 0n) {
|
|
21
|
+
return 0n;
|
|
22
|
+
}
|
|
23
|
+
return isCkb2Udt
|
|
24
|
+
? ckbToIckbOrderMaturity(info, amount, system, self)
|
|
25
|
+
: ickbToCkbOrderMaturity(info, amount, system, takenDeposits, self);
|
|
26
|
+
}
|
|
27
|
+
/** The order's terms, and its own out point when it is already on the book. */
|
|
28
|
+
function maturityOrderParts(o) {
|
|
29
|
+
if ("info" in o) {
|
|
30
|
+
return { ...o, self: undefined };
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
info: o.data.info,
|
|
34
|
+
amounts: { ckbValue: o.ckbUnoccupied, udtValue: o.udtValue },
|
|
35
|
+
self: o.cell.outPoint,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A buyer waits for the bot to mint: the bot mints one cap-sized deposit per turn once its
|
|
40
|
+
* iCKB inventory is spent, and the inventory is unknown here, so the wait is one turn plus
|
|
41
|
+
* one per whole cap of positive net CKB demand (this request and buyers priced at least
|
|
42
|
+
* as well, less the iCKB sellers bring in). The model does not measure the bot's funds.
|
|
43
|
+
*/
|
|
44
|
+
function ckbToIckbOrderMaturity(info, amount, system, self) {
|
|
45
|
+
// An equal price counts as ahead: the bot fills ties in an order of its own choosing.
|
|
46
|
+
const buyersAhead = fillableOrders(system, true, self)
|
|
47
|
+
.filter((group) => group.order.data.info.ckbToUdt.compare(info.ckbToUdt) <= 0)
|
|
48
|
+
.reduce((ckb, group) => ckb + group.order.ckbUnoccupied, 0n);
|
|
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);
|
|
52
|
+
const turns = demand > 0n ? 1n + demand / capCkb : 1n;
|
|
53
|
+
return system.tip.timestamp + BOT_TURN_MS * turns;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A seller waits for CKB: one deposit's worth of assumed working capital, zeroed when
|
|
57
|
+
* another fillable seller has sat beyond the threshold, plus dated pool supply. Return
|
|
58
|
+
* the first date covering demand, plus a turn. Insufficient supply falls back to the last
|
|
59
|
+
* date; this can understate an above-par ask's wait for further DAO growth.
|
|
60
|
+
*/
|
|
61
|
+
function ickbToCkbOrderMaturity(info, amount, system, takenDeposits, self) {
|
|
62
|
+
const sellers = fillableOrders(system, false, self);
|
|
63
|
+
const sellersAhead = sellers
|
|
64
|
+
.filter((group) => info.udtToCkb.compare(group.order.data.info.udtToCkb) <= 0)
|
|
65
|
+
.reduce((udt, group) => udt + group.udtValue, 0n);
|
|
66
|
+
// The CKB an order has already received belongs to its earlier fills; what it still
|
|
67
|
+
// needs is the remaining iCKB at its price.
|
|
68
|
+
const needed = info.udtToCkb.convert(false, amount, true) +
|
|
69
|
+
convert(false, sellersAhead, system.exchangeRatio);
|
|
70
|
+
const taken = new Set(takenDeposits.map((deposit) => deposit.cell.outPoint.toHex()));
|
|
71
|
+
const steps = [
|
|
72
|
+
{
|
|
73
|
+
ckbValue: sellers.some((group) => sits(group, system))
|
|
74
|
+
? 0n
|
|
75
|
+
: convert(false, ICKB_DEPOSIT_CAP, system.exchangeRatio),
|
|
76
|
+
at: system.tip.timestamp,
|
|
77
|
+
},
|
|
78
|
+
// A claim the bot can no longer request in time rolls a cycle: the bot's rule, not the
|
|
79
|
+
// caller's, since the bot is the one making the requests.
|
|
80
|
+
...system.poolDeposits
|
|
81
|
+
.filter((deposit) => !taken.has(deposit.cell.outPoint.toHex()))
|
|
82
|
+
.map((deposit) => ({
|
|
83
|
+
ckbValue: deposit.ckbValue,
|
|
84
|
+
at: depositMaturity(deposit.claimEpoch, system.tip, BOT_LOCK_UP).maturity.toUnix(system.tip),
|
|
85
|
+
}))
|
|
86
|
+
.toSorted((left, right) => compareBigInt(left.at, right.at)),
|
|
87
|
+
];
|
|
88
|
+
let supply = 0n;
|
|
89
|
+
let at = system.tip.timestamp;
|
|
90
|
+
for (const step of steps) {
|
|
91
|
+
supply += step.ckbValue;
|
|
92
|
+
at = step.at;
|
|
93
|
+
if (supply >= needed) {
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return at + BOT_TURN_MS;
|
|
98
|
+
}
|
|
99
|
+
/** The book orders the bot would take whole in the given direction, this one aside. */
|
|
100
|
+
function fillableOrders(system, isCkb2Udt, self) {
|
|
101
|
+
return system.orderPool.filter((group) => (self === undefined || !group.order.cell.outPoint.eq(self)) &&
|
|
102
|
+
fillsWhole(group, isCkb2Udt, system.exchangeRatio, system.feeRate));
|
|
103
|
+
}
|
|
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.
|
|
107
|
+
*/
|
|
108
|
+
function sits(group, { tip }) {
|
|
109
|
+
return (group.blockNumber !== undefined &&
|
|
110
|
+
tip.number - group.blockNumber > tip.epoch.denominator / 24n);
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=maturity.js.map
|
|
@@ -0,0 +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;I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,SAAS,CAAC;IAC9B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC;QACxB,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QACb,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;YACrB,MAAM;QACR,CAAC;IACH,CAAC;IACD,OAAO,EAAE,GAAG,WAAW,CAAC;AAC1B,CAAC;AAED,uFAAuF;AACvF,SAAS,cAAc,CACrB,MAAmB,EACnB,SAAkB,EAClB,IAA8B;IAE9B,OAAO,MAAM,CAAC,SAAS,CAAC,MAAM,CAC5B,CAAC,KAAK,EAAE,EAAE,CACR,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;QAC3D,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,OAAO,CAAC,CACrE,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,IAAI,CAAC,KAAiB,EAAE,EAAE,GAAG,EAAe;IACnD,OAAO,CACL,KAAK,CAAC,WAAW,KAAK,SAAS;QAC/B,GAAG,CAAC,MAAM,GAAG,KAAK,CAAC,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,WAAW,GAAG,GAAG,CAC7D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type IckbDepositCell } from "../logic.js";
|
|
2
|
+
import type { CkbToIckbConversionPlan, ConversionTransactionOptions, IckbToCkbConversionPlan } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Plans every deposit count from the most the amount covers down to zero, skipping
|
|
5
|
+
* unrepresentable remainders. Cap-sized deposits plus an order for the rest is the cheapest
|
|
6
|
+
* shape at every amount: a deposit's 82 CKB of occupied capacity goes to its withdrawer
|
|
7
|
+
* (0.082% at the cap, 8.2% at the contract's 1,000 CKB minimum), the excess above the cap
|
|
8
|
+
* is discounted 10%, and an order costs 0.01% at any size; the cap's CKB value grows with
|
|
9
|
+
* the DAO rate, so the order stays cheaper until the cap is worth 820,000 CKB.
|
|
10
|
+
*/
|
|
11
|
+
export declare function ckbToIckbConversionPlans(options: ConversionTransactionOptions): CkbToIckbConversionPlan[];
|
|
12
|
+
/**
|
|
13
|
+
* Plans every prefix of the greedy ready-deposit selection, longest first, the remainder as
|
|
14
|
+
* an order: direct withdrawals are free and their claim date certain, an order pays a fee
|
|
15
|
+
* and waits for the bot, so the completion walk takes the most direct plan it can fund.
|
|
16
|
+
* The prefix shape keeps ring classification frozen: a prefix of surplus deposits stays
|
|
17
|
+
* surplus with the same anchors pinned.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ickbToCkbConversionPlans(options: ConversionTransactionOptions, poolDeposits: readonly IckbDepositCell[]): IckbToCkbConversionPlan[];
|
|
20
|
+
//# sourceMappingURL=plans.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plans.d.ts","sourceRoot":"","sources":["../../src/conversion/plans.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAUlE,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"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { DAO_OUTPUT_LIMIT } from "../dao.js";
|
|
2
|
+
import { readyDeposits } from "../logic.js";
|
|
3
|
+
import { ICKB_DEPOSIT_CAP, convert } from "../udt.js";
|
|
4
|
+
import { maxBigInt } from "../utils/utils.js";
|
|
5
|
+
import { DEFAULT_ORDER_FEE, DEFAULT_ORDER_FEE_BASE, estimateConversionOrder, estimateIckbToCkbOrder, } from "./estimate.js";
|
|
6
|
+
import { sumUdt } from "./projection.js";
|
|
7
|
+
import { fitWithdrawalDeposits, ringSurplusDepositFilter, sortByClaim, } from "./withdrawal_ring.js";
|
|
8
|
+
// The planner starts at the most `DAO_OUTPUT_LIMIT` can hold, one change output beside the
|
|
9
|
+
// deposits, and the completion walk steps down from there when change and fees need more room.
|
|
10
|
+
const MAX_PLANNED_DEPOSITS = DAO_OUTPUT_LIMIT - 1;
|
|
11
|
+
/**
|
|
12
|
+
* Plans every deposit count from the most the amount covers down to zero, skipping
|
|
13
|
+
* unrepresentable remainders. Cap-sized deposits plus an order for the rest is the cheapest
|
|
14
|
+
* shape at every amount: a deposit's 82 CKB of occupied capacity goes to its withdrawer
|
|
15
|
+
* (0.082% at the cap, 8.2% at the contract's 1,000 CKB minimum), the excess above the cap
|
|
16
|
+
* is discounted 10%, and an order costs 0.01% at any size; the cap's CKB value grows with
|
|
17
|
+
* the DAO rate, so the order stays cheaper until the cap is worth 820,000 CKB.
|
|
18
|
+
*/
|
|
19
|
+
export function ckbToIckbConversionPlans(options) {
|
|
20
|
+
const { amount, context } = options;
|
|
21
|
+
const depositCapacity = convert(false, ICKB_DEPOSIT_CAP, context.system.exchangeRatio);
|
|
22
|
+
const depositQuotient = depositCapacity === 0n ? 0n : amount / depositCapacity;
|
|
23
|
+
const maxDeposits = depositQuotient > BigInt(MAX_PLANNED_DEPOSITS)
|
|
24
|
+
? MAX_PLANNED_DEPOSITS
|
|
25
|
+
: Number(depositQuotient);
|
|
26
|
+
const plans = [];
|
|
27
|
+
for (let depositCount = maxDeposits; depositCount >= 0; depositCount -= 1) {
|
|
28
|
+
const plan = ckbToIckbConversionPlan(options, depositCapacity, depositCount);
|
|
29
|
+
if (plan !== undefined) {
|
|
30
|
+
plans.push(plan);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return plans;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Plans every prefix of the greedy ready-deposit selection, longest first, the remainder as
|
|
37
|
+
* an order: direct withdrawals are free and their claim date certain, an order pays a fee
|
|
38
|
+
* and waits for the bot, so the completion walk takes the most direct plan it can fund.
|
|
39
|
+
* The prefix shape keeps ring classification frozen: a prefix of surplus deposits stays
|
|
40
|
+
* surplus with the same anchors pinned.
|
|
41
|
+
*/
|
|
42
|
+
export function ickbToCkbConversionPlans(options, poolDeposits) {
|
|
43
|
+
const { amount, context } = options;
|
|
44
|
+
const { tip, lockUp } = context.system;
|
|
45
|
+
const ready = readyDeposits(poolDeposits, tip, lockUp);
|
|
46
|
+
const isSurplus = ringSurplusDepositFilter(poolDeposits, ready);
|
|
47
|
+
const deposits = fitWithdrawalDeposits(sortByClaim(ready.filter(isSurplus)), amount);
|
|
48
|
+
const plans = [];
|
|
49
|
+
for (let count = deposits.length; count >= 0; count -= 1) {
|
|
50
|
+
const plan = ickbToCkbConversionPlan(options, deposits.slice(0, count));
|
|
51
|
+
if (plan !== undefined) {
|
|
52
|
+
plans.push(plan);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return plans;
|
|
56
|
+
}
|
|
57
|
+
function ckbToIckbConversionPlan(options, depositCapacity, depositCount) {
|
|
58
|
+
const { amount, context } = options;
|
|
59
|
+
const remainder = amount - depositCapacity * BigInt(depositCount);
|
|
60
|
+
let estimatedMaturity = context.estimatedMaturity;
|
|
61
|
+
let order;
|
|
62
|
+
if (remainder > 0n) {
|
|
63
|
+
const amounts = { ckbValue: remainder, udtValue: 0n };
|
|
64
|
+
const estimate = estimateConversionOrder(true, amounts, context.system, {
|
|
65
|
+
fee: DEFAULT_ORDER_FEE,
|
|
66
|
+
feeBase: DEFAULT_ORDER_FEE_BASE,
|
|
67
|
+
});
|
|
68
|
+
if (estimate?.maturity === undefined) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
estimatedMaturity = maxBigInt(estimatedMaturity, estimate.maturity);
|
|
72
|
+
order = { amounts, estimate };
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
depositCapacity,
|
|
76
|
+
depositCount,
|
|
77
|
+
estimatedMaturity,
|
|
78
|
+
...(order === undefined ? {} : { order }),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function ickbToCkbConversionPlan(options, selectedDeposits) {
|
|
82
|
+
const { amount, context } = options;
|
|
83
|
+
let estimatedMaturity = context.estimatedMaturity;
|
|
84
|
+
// Selected deposits are ready, so their sampled claim is their date.
|
|
85
|
+
for (const deposit of selectedDeposits) {
|
|
86
|
+
estimatedMaturity = maxBigInt(estimatedMaturity, deposit.claimEpoch.toUnix(context.system.tip));
|
|
87
|
+
}
|
|
88
|
+
const remainder = amount - sumUdt(selectedDeposits);
|
|
89
|
+
let order;
|
|
90
|
+
if (remainder > 0n) {
|
|
91
|
+
const amounts = { ckbValue: 0n, udtValue: remainder };
|
|
92
|
+
// The deposits this plan withdraws directly cannot fill its order leg too.
|
|
93
|
+
const estimate = estimateIckbToCkbOrder(amounts, context.system, selectedDeposits);
|
|
94
|
+
if (estimate === undefined) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
estimatedMaturity = maxBigInt(estimatedMaturity, estimate.maturity);
|
|
98
|
+
order = { amounts, estimate };
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
estimatedMaturity,
|
|
102
|
+
...(order === undefined ? {} : { order }),
|
|
103
|
+
selectedDeposits,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=plans.js.map
|
|
@@ -0,0 +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,aA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AE,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,SAAS,CAAC,iBAAiB,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACpE,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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { OrderGroup } from "../order/cells.js";
|
|
2
|
+
import type { AccountAvailabilityProjection, AccountState, ConversionTransactionContextProjection, SystemState } from "./types.js";
|
|
3
|
+
/**
|
|
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.
|
|
7
|
+
*/
|
|
8
|
+
export declare function projectConversionTransactionContext(system: SystemState, account: AccountState, orders: {
|
|
9
|
+
available: OrderGroup[];
|
|
10
|
+
pending: OrderGroup[];
|
|
11
|
+
}): ConversionTransactionContextProjection;
|
|
12
|
+
/**
|
|
13
|
+
* Splits wallet-owned CKB and iCKB into immediately available and pending value.
|
|
14
|
+
*/
|
|
15
|
+
export declare function projectAccountAvailability(account: AccountState, { available: availableOrders, pending: pendingOrders, }: {
|
|
16
|
+
available: OrderGroup[];
|
|
17
|
+
pending: OrderGroup[];
|
|
18
|
+
}): AccountAvailabilityProjection;
|
|
19
|
+
export declare function sumUdt(items: ReadonlyArray<{
|
|
20
|
+
udtValue: bigint;
|
|
21
|
+
}>): bigint;
|
|
22
|
+
//# sourceMappingURL=projection.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { DAO_HEADER_INDEX_LIMIT } from "../dao.js";
|
|
3
|
+
import { maxBigInt } from "../utils/utils.js";
|
|
4
|
+
import { maturity } from "./maturity.js";
|
|
5
|
+
/**
|
|
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.
|
|
9
|
+
*/
|
|
10
|
+
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);
|
|
16
|
+
return {
|
|
17
|
+
projection,
|
|
18
|
+
context: {
|
|
19
|
+
system,
|
|
20
|
+
receipts: account.receipts,
|
|
21
|
+
readyWithdrawals: projection.readyWithdrawals,
|
|
22
|
+
availableOrders: projection.availableOrders,
|
|
23
|
+
cells: [...account.capacityCells, ...account.nativeUdtCells],
|
|
24
|
+
ckbAvailable: projection.ckbAvailable,
|
|
25
|
+
ickbAvailable: projection.ickbAvailable,
|
|
26
|
+
estimatedMaturity,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Splits wallet-owned CKB and iCKB into immediately available and pending value.
|
|
32
|
+
*/
|
|
33
|
+
export function projectAccountAvailability(account, { available: availableOrders, pending: pendingOrders, }) {
|
|
34
|
+
const { readyWithdrawals, pendingWithdrawals } = splitWithdrawals(account.withdrawalGroups);
|
|
35
|
+
// An iCKB cell's capacity is the owner's CKB too: completion spends it like a plain cell.
|
|
36
|
+
const ckbNative = sumValues([...account.capacityCells, ...account.nativeUdtCells], (cell) => cell.cellOutput.capacity);
|
|
37
|
+
const ickbNative = sumValues(account.nativeUdtCells, (cell) => ccc.udtBalanceFrom(cell.outputData));
|
|
38
|
+
const ckbAvailable = ckbNative +
|
|
39
|
+
sumCkb(account.receipts) +
|
|
40
|
+
sumCkb(readyWithdrawals) +
|
|
41
|
+
sumCkb(availableOrders);
|
|
42
|
+
const ickbAvailable = ickbNative + sumUdt(account.receipts) + sumUdt(availableOrders);
|
|
43
|
+
const ckbPending = sumCkb(pendingWithdrawals) + sumCkb(pendingOrders);
|
|
44
|
+
const ickbPending = sumUdt(pendingOrders);
|
|
45
|
+
return {
|
|
46
|
+
ckbNative,
|
|
47
|
+
ickbNative,
|
|
48
|
+
ckbAvailable,
|
|
49
|
+
ickbAvailable,
|
|
50
|
+
ckbPending,
|
|
51
|
+
ickbPending,
|
|
52
|
+
ckbBalance: ckbAvailable + ckbPending,
|
|
53
|
+
ickbBalance: ickbAvailable + ickbPending,
|
|
54
|
+
readyWithdrawals,
|
|
55
|
+
pendingWithdrawals,
|
|
56
|
+
availableOrders,
|
|
57
|
+
pendingOrders,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* `ready` is the batch one transaction can complete: the deployed DAO script addresses a
|
|
62
|
+
* withdrawal's deposit header only below `DAO_HEADER_INDEX_LIMIT`, and the builder puts
|
|
63
|
+
* those headers first, so matured withdrawals past that count wait a turn.
|
|
64
|
+
*/
|
|
65
|
+
function splitWithdrawals(withdrawalGroups) {
|
|
66
|
+
const readyWithdrawals = [];
|
|
67
|
+
const pendingWithdrawals = [];
|
|
68
|
+
for (const group of withdrawalGroups) {
|
|
69
|
+
if (group.owned.isReady && readyWithdrawals.length < DAO_HEADER_INDEX_LIMIT) {
|
|
70
|
+
readyWithdrawals.push(group);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
pendingWithdrawals.push(group);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return { readyWithdrawals, pendingWithdrawals };
|
|
77
|
+
}
|
|
78
|
+
function sumCkb(items) {
|
|
79
|
+
return sumValues(items, (item) => item.ckbValue);
|
|
80
|
+
}
|
|
81
|
+
export function sumUdt(items) {
|
|
82
|
+
return sumValues(items, (item) => item.udtValue);
|
|
83
|
+
}
|
|
84
|
+
function sumValues(items, project) {
|
|
85
|
+
let total = 0n;
|
|
86
|
+
for (const item of items) {
|
|
87
|
+
total += project(item);
|
|
88
|
+
}
|
|
89
|
+
return total;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=projection.js.map
|
|
@@ -0,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,EAAE,CAAC;IAC/C,MAAM,kBAAkB,GAAsB,EAAE,CAAC;IACjD,KAAK,MAAM,KAAK,IAAI,gBAAgB,EAAE,CAAC;QACrC,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,gBAAgB,CAAC,MAAM,GAAG,sBAAsB,EAAE,CAAC;YAC5E,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;aAAM,CAAC;YACN,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IACD,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,CAAC;AAClD,CAAC;AAED,SAAS,MAAM,CAAC,KAA0C;IACxD,OAAO,SAAS,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,KAA0C;IAC/D,OAAO,SAAS,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,SAAS,CAAI,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"}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import type { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import type { LockUpPolicy } from "../dao.js";
|
|
3
|
+
import type { IckbDepositCell, LogicManager, ReceiptCell } from "../logic.js";
|
|
4
|
+
import type { OrderCell, OrderGroup } from "../order/cells.js";
|
|
5
|
+
import type { Info } from "../order/info.js";
|
|
6
|
+
import type { OrderManager } from "../order/order.js";
|
|
7
|
+
import type { Ratio } from "../order/ratio.js";
|
|
8
|
+
import type { OwnedOwnerManager, WithdrawalGroup } from "../owned_owner.js";
|
|
9
|
+
import type { IckbUdt } from "../udt.js";
|
|
10
|
+
import type { ValueComponents } from "../utils/utils.js";
|
|
11
|
+
/**
|
|
12
|
+
* Direction requested by a conversion transaction.
|
|
13
|
+
*/
|
|
14
|
+
export type ConversionDirection = "ckb-to-ickb" | "ickb-to-ckb";
|
|
15
|
+
/**
|
|
16
|
+
* Snapshot used to plan one wallet conversion transaction.
|
|
17
|
+
*/
|
|
18
|
+
export interface ConversionTransactionContext {
|
|
19
|
+
/** Public system state sampled for conversion planning. */
|
|
20
|
+
system: SystemState;
|
|
21
|
+
/** User receipt cells available for deposit completion. */
|
|
22
|
+
receipts: ReceiptCell[];
|
|
23
|
+
/** User withdrawal groups ready to complete. */
|
|
24
|
+
readyWithdrawals: WithdrawalGroup[];
|
|
25
|
+
/** Order groups available for collection or budgeting as account value. */
|
|
26
|
+
availableOrders: OrderGroup[];
|
|
27
|
+
/** The wallet's liquid cells, plain CKB and iCKB, that completion funds from and sweeps. */
|
|
28
|
+
cells: ccc.Cell[];
|
|
29
|
+
/** Projected CKB available to the wallet after pending state is considered. */
|
|
30
|
+
ckbAvailable: bigint;
|
|
31
|
+
/** Projected iCKB available to the wallet after pending state is considered. */
|
|
32
|
+
ickbAvailable: bigint;
|
|
33
|
+
/**
|
|
34
|
+
* The latest date at which everything the wallet has converting, plus this request, is
|
|
35
|
+
* collectable; an amount of zero is the collection itself.
|
|
36
|
+
*/
|
|
37
|
+
estimatedMaturity: bigint;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Inputs and policy limits for building one conversion transaction.
|
|
41
|
+
*/
|
|
42
|
+
export interface ConversionTransactionOptions {
|
|
43
|
+
/** Conversion direction to build. */
|
|
44
|
+
direction: ConversionDirection;
|
|
45
|
+
/** Requested input amount in the source asset. */
|
|
46
|
+
amount: bigint;
|
|
47
|
+
/**
|
|
48
|
+
* Lock that owns every cell the transaction creates for the user, the conversion outputs
|
|
49
|
+
* and the change; the signer's recommended lock by default. Completion sweeps the liquid
|
|
50
|
+
* cells along within its input limit, so a foreign lock redirects those funds too.
|
|
51
|
+
*/
|
|
52
|
+
lock?: ccc.Script;
|
|
53
|
+
/** Signer whose committed cells fund the completed transaction. */
|
|
54
|
+
signer: ccc.Signer;
|
|
55
|
+
/** Sampled state used to plan this conversion. */
|
|
56
|
+
context: ConversionTransactionContext;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Reason a conversion transaction could not be built without throwing.
|
|
60
|
+
*/
|
|
61
|
+
export type ConversionTransactionFailureReason = "amount-negative" | "insufficient-ckb" | "insufficient-ickb" | "amount-too-small" | "nothing-to-do";
|
|
62
|
+
/**
|
|
63
|
+
* A dust iCKB-to-CKB order: too small for the default fee to clear the estimate threshold,
|
|
64
|
+
* so it pays the smallest fee that does. For callers to surface in UI or logs.
|
|
65
|
+
*/
|
|
66
|
+
export interface ConversionNotice {
|
|
67
|
+
/** iCKB input amount that triggered the notice. */
|
|
68
|
+
inputIckb: bigint;
|
|
69
|
+
/** CKB output estimate for the noticed path. */
|
|
70
|
+
outputCkb: bigint;
|
|
71
|
+
/** CKB incentive associated with the noticed path. */
|
|
72
|
+
incentiveCkb: bigint;
|
|
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
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Result of attempting to build a conversion transaction.
|
|
83
|
+
*/
|
|
84
|
+
export type ConversionTransactionResult = {
|
|
85
|
+
ok: true;
|
|
86
|
+
/** Completed transaction, funded from the signer's committed cells. Callers own signing and send. */
|
|
87
|
+
tx: ccc.Transaction;
|
|
88
|
+
/** Estimated maturity timestamp for the conversion result. */
|
|
89
|
+
estimatedMaturity: bigint;
|
|
90
|
+
/** Composition of the selected conversion path. */
|
|
91
|
+
conversion: ConversionMetadata;
|
|
92
|
+
/** Optional notice about the selected path. */
|
|
93
|
+
conversionNotice?: ConversionNotice;
|
|
94
|
+
/**
|
|
95
|
+
* True when every liquid cell of the context is an input. False when the input limit
|
|
96
|
+
* left some behind: a move to another lock then needs another transaction.
|
|
97
|
+
*/
|
|
98
|
+
isSweepComplete: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* The epoch the transaction must be broadcast before for its withdrawal requests to
|
|
101
|
+
* claim at their sampled dates (`system.lockUp`); absent when it requests none.
|
|
102
|
+
*/
|
|
103
|
+
broadcastBefore?: ccc.Epoch;
|
|
104
|
+
} | {
|
|
105
|
+
ok: false;
|
|
106
|
+
/** Machine-readable failure reason. */
|
|
107
|
+
reason: ConversionTransactionFailureReason;
|
|
108
|
+
/** Best available maturity estimate from the input context. */
|
|
109
|
+
estimatedMaturity: bigint;
|
|
110
|
+
/**
|
|
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.
|
|
113
|
+
*/
|
|
114
|
+
minimum?: bigint;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Options for completing a partial iCKB transaction before signing and sending.
|
|
118
|
+
*/
|
|
119
|
+
export interface CompleteIckbTransactionOptions {
|
|
120
|
+
/** Signer that prepares the transaction; its recommended lock owns the change by default. */
|
|
121
|
+
signer: ccc.Signer;
|
|
122
|
+
/** Lock that owns the change, iCKB and plain, when not the signer's recommended lock. */
|
|
123
|
+
lock?: ccc.Script;
|
|
124
|
+
/** Fee rate passed to CCC fee completion. */
|
|
125
|
+
feeRate: ccc.Num;
|
|
126
|
+
/** The signer's known liquid cells, plain CKB and iCKB, from the account state already read. */
|
|
127
|
+
cells: ccc.Cell[];
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Quote details for one order-based conversion path.
|
|
131
|
+
*/
|
|
132
|
+
export interface ConversionOrderEstimate {
|
|
133
|
+
/** Output amount after applying the order ratio and fee. */
|
|
134
|
+
convertedAmount: ccc.FixedPoint;
|
|
135
|
+
/** CKB fee component embedded in the order conversion. */
|
|
136
|
+
ckbFee: ccc.FixedPoint;
|
|
137
|
+
/** Order info that should be encoded into a created order. */
|
|
138
|
+
info: Info;
|
|
139
|
+
/** Estimated maturity timestamp, or `undefined` when it cannot be estimated. */
|
|
140
|
+
maturity: ccc.Num | undefined;
|
|
141
|
+
/** A non-fatal notice about the path this estimate took, for the caller to surface. */
|
|
142
|
+
notice?: ConversionNotice;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Input accepted by maturity estimation, either a live order cell or raw order data plus values.
|
|
146
|
+
*/
|
|
147
|
+
export type MaturityOrderInput = OrderCell | {
|
|
148
|
+
info: Info;
|
|
149
|
+
amounts: ValueComponents;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Raw wallet-owned cells and grouped iCKB state sampled from L1.
|
|
153
|
+
*/
|
|
154
|
+
export interface AccountState {
|
|
155
|
+
/** Plain capacity cells owned by the account locks. */
|
|
156
|
+
capacityCells: ccc.Cell[];
|
|
157
|
+
/** Native iCKB xUDT cells owned by the account locks. */
|
|
158
|
+
nativeUdtCells: ccc.Cell[];
|
|
159
|
+
/** Receipt cells owned by the account. */
|
|
160
|
+
receipts: ReceiptCell[];
|
|
161
|
+
/** Withdrawal groups owned by the account. */
|
|
162
|
+
withdrawalGroups: WithdrawalGroup[];
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Account balances split into available, pending, and order/withdrawal buckets.
|
|
166
|
+
*/
|
|
167
|
+
export interface AccountAvailabilityProjection {
|
|
168
|
+
/**
|
|
169
|
+
* CKB in the account's liquid cells, plain and iCKB alike: what the wallet shows and what
|
|
170
|
+
* the next transaction spends, before the change cells, an order's master cell and the
|
|
171
|
+
* fee it must fund on top.
|
|
172
|
+
*/
|
|
173
|
+
ckbNative: bigint;
|
|
174
|
+
/** iCKB in the account's native iCKB cells. */
|
|
175
|
+
ickbNative: bigint;
|
|
176
|
+
/** `ckbNative` plus the CKB the receipts, ready withdrawals and collectable orders return. */
|
|
177
|
+
ckbAvailable: bigint;
|
|
178
|
+
/** `ickbNative` plus the iCKB the receipts and collectable orders return. */
|
|
179
|
+
ickbAvailable: bigint;
|
|
180
|
+
/** CKB pending in withdrawals or orders. */
|
|
181
|
+
ckbPending: bigint;
|
|
182
|
+
/** iCKB pending in withdrawals or orders. */
|
|
183
|
+
ickbPending: bigint;
|
|
184
|
+
/** Total CKB balance including pending positions. */
|
|
185
|
+
ckbBalance: bigint;
|
|
186
|
+
/** Total iCKB balance including pending positions. */
|
|
187
|
+
ickbBalance: bigint;
|
|
188
|
+
/**
|
|
189
|
+
* Matured withdrawal groups one transaction can complete: at most the deposit-header slots
|
|
190
|
+
* the DAO script addresses (`DAO_HEADER_INDEX_LIMIT`), which the deposit headers hold alone.
|
|
191
|
+
*/
|
|
192
|
+
readyWithdrawals: WithdrawalGroup[];
|
|
193
|
+
/** Withdrawal groups still waiting for DAO maturity or for a header slot in a later turn. */
|
|
194
|
+
pendingWithdrawals: WithdrawalGroup[];
|
|
195
|
+
/** Order groups available for collection or budgeting as account value. */
|
|
196
|
+
availableOrders: OrderGroup[];
|
|
197
|
+
/** Order groups that are owned but unavailable or unresolved. */
|
|
198
|
+
pendingOrders: OrderGroup[];
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Combined projection and transaction-planning context for one sampled account state.
|
|
202
|
+
*/
|
|
203
|
+
export interface ConversionTransactionContextProjection {
|
|
204
|
+
/** User-facing availability projection. */
|
|
205
|
+
projection: AccountAvailabilityProjection;
|
|
206
|
+
/** Builder-facing transaction context derived from the same sampled state. */
|
|
207
|
+
context: ConversionTransactionContext;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Public sampled system state used for quotes, maturity, and conversion planning.
|
|
211
|
+
*/
|
|
212
|
+
export interface SystemState {
|
|
213
|
+
/** The fee rate for transactions. */
|
|
214
|
+
feeRate: ccc.Num;
|
|
215
|
+
/** Sampled tip used for this L1 scan. It may be stale after scans complete. */
|
|
216
|
+
tip: ccc.ClientBlockHeader;
|
|
217
|
+
/** The exchange ratio between CKB and UDT. */
|
|
218
|
+
exchangeRatio: Ratio;
|
|
219
|
+
/** Every order past par on the book, the wallet's own included: what the bot can fill. */
|
|
220
|
+
orderPool: OrderGroup[];
|
|
221
|
+
/** Every iCKB pool deposit with its claim epoch at this tip: the CKB supply. */
|
|
222
|
+
poolDeposits: IckbDepositCell[];
|
|
223
|
+
/** The caller's withdrawal timing rules, which every builder and the sender follow. */
|
|
224
|
+
lockUp: LockUpPolicy;
|
|
225
|
+
}
|
|
226
|
+
/** Manager set that builds one iCKB SDK instance. */
|
|
227
|
+
export interface SdkManagers {
|
|
228
|
+
/** iCKB xUDT manager with receipt and DAO deposit aware completion. */
|
|
229
|
+
ickbUdt: IckbUdt;
|
|
230
|
+
/** Owned-owner manager for withdrawal request and claim cells. */
|
|
231
|
+
ownedOwner: OwnedOwnerManager;
|
|
232
|
+
/** iCKB Logic manager for deposits and receipts. */
|
|
233
|
+
ickbLogic: LogicManager;
|
|
234
|
+
/** Limit order manager. */
|
|
235
|
+
order: OrderManager;
|
|
236
|
+
}
|
|
237
|
+
export interface ConversionOrder {
|
|
238
|
+
amounts: ValueComponents;
|
|
239
|
+
estimate: ConversionOrderEstimate;
|
|
240
|
+
}
|
|
241
|
+
export interface CkbToIckbConversionPlan {
|
|
242
|
+
depositCapacity: bigint;
|
|
243
|
+
depositCount: number;
|
|
244
|
+
estimatedMaturity: bigint;
|
|
245
|
+
order?: ConversionOrder;
|
|
246
|
+
}
|
|
247
|
+
export interface IckbToCkbConversionPlan {
|
|
248
|
+
estimatedMaturity: bigint;
|
|
249
|
+
order?: ConversionOrder;
|
|
250
|
+
selectedDeposits: IckbDepositCell[];
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL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