@ickb/sdk 1000.0.82 → 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.
- package/README.md +84 -32
- package/dist/constants.d.ts +9 -22
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +62 -76
- package/dist/constants.js.map +1 -1
- package/dist/conversion/estimate.d.ts +33 -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 +113 -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 +21 -0
- package/dist/conversion/projection.d.ts.map +1 -0
- package/dist/conversion/projection.js +94 -0
- package/dist/conversion/projection.js.map +1 -0
- package/dist/conversion/types.d.ts +264 -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 +34 -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 +100 -0
- package/dist/dao.d.ts.map +1 -0
- package/dist/dao.js +125 -0
- package/dist/dao.js.map +1 -0
- package/dist/index.d.ts +49 -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 +81 -0
- package/dist/logic.d.ts.map +1 -0
- package/dist/logic.js +173 -0
- package/dist/logic.js.map +1 -0
- package/dist/order/cells.d.ts +168 -0
- package/dist/order/cells.d.ts.map +1 -0
- package/dist/order/cells.js +309 -0
- package/dist/order/cells.js.map +1 -0
- package/dist/order/conversion.d.ts +37 -0
- package/dist/order/conversion.d.ts.map +1 -0
- package/dist/order/conversion.js +120 -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 +102 -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 +124 -0
- package/dist/order/matcher.js.map +1 -0
- package/dist/order/order.d.ts +63 -0
- package/dist/order/order.d.ts.map +1 -0
- package/dist/order/order.js +234 -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 +67 -0
- package/dist/order/order_data.js.map +1 -0
- package/dist/order/ratio.d.ts +40 -0
- package/dist/order/ratio.d.ts.map +1 -0
- package/dist/order/ratio.js +74 -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 +57 -0
- package/dist/order/relative.js.map +1 -0
- package/dist/owned_owner.d.ts +108 -0
- package/dist/owned_owner.d.ts.map +1 -0
- package/dist/owned_owner.js +260 -0
- package/dist/owned_owner.js.map +1 -0
- package/dist/sdk.d.ts +113 -41
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +410 -209
- package/dist/sdk.js.map +1 -1
- package/dist/send/sign_and_send_transaction.d.ts +61 -0
- package/dist/send/sign_and_send_transaction.d.ts.map +1 -0
- package/dist/send/sign_and_send_transaction.js +201 -0
- package/dist/send/sign_and_send_transaction.js.map +1 -0
- package/dist/send/wait_transaction.d.ts +42 -0
- package/dist/send/wait_transaction.d.ts.map +1 -0
- package/dist/send/wait_transaction.js +172 -0
- package/dist/send/wait_transaction.js.map +1 -0
- package/dist/udt.d.ts +108 -0
- package/dist/udt.d.ts.map +1 -0
- package/dist/udt.js +180 -0
- package/dist/udt.js.map +1 -0
- package/dist/utils/chain.d.ts +3 -0
- package/dist/utils/chain.d.ts.map +1 -0
- package/dist/utils/chain.js +2 -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 +69 -0
- package/dist/utils/codec.js.map +1 -0
- package/dist/utils/utils.d.ts +99 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +130 -0
- package/dist/utils/utils.js.map +1 -0
- package/dist/utils/verified_client.d.ts +19 -0
- package/dist/utils/verified_client.d.ts.map +1 -0
- package/dist/utils/verified_client.js +92 -0
- package/dist/utils/verified_client.js.map +1 -0
- package/package.json +19 -26
- package/src/constants.ts +65 -181
- package/src/conversion/estimate.ts +155 -0
- package/src/conversion/maturity.ts +158 -0
- package/src/conversion/plans.ts +144 -0
- package/src/conversion/projection.ts +136 -0
- package/src/conversion/types.ts +302 -0
- package/src/conversion/withdrawal_ring.ts +122 -0
- package/src/dao.ts +196 -0
- package/src/index.ts +89 -3
- package/src/logic.ts +283 -0
- package/src/order/cells.ts +383 -0
- package/src/order/conversion.ts +162 -0
- package/src/order/fee.ts +30 -0
- package/src/order/fill.ts +83 -0
- package/src/order/info.ts +181 -0
- package/src/order/master.ts +42 -0
- package/src/order/matcher.ts +191 -0
- package/src/order/order.ts +288 -0
- package/src/order/order_data.ts +131 -0
- package/src/order/ratio.ts +127 -0
- package/src/order/relative.ts +109 -0
- package/src/owned_owner.ts +364 -0
- package/src/sdk.ts +542 -440
- package/src/send/sign_and_send_transaction.ts +256 -0
- package/src/send/wait_transaction.ts +227 -0
- package/src/udt.ts +249 -0
- package/src/utils/chain.ts +2 -0
- package/src/utils/codec.ts +78 -0
- package/src/utils/utils.ts +208 -0
- package/src/utils/verified_client.ts +136 -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 @@
|
|
|
1
|
+
{"version":3,"file":"cells.js","sourceRoot":"","sources":["../../src/order/cells.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,OAAO,SAAS;IACpB,8DAA8D;IAC9C,IAAI,CAAW;IAC/B,oDAAoD;IACpC,IAAI,CAAY;IAChC,+EAA+E;IAC/D,aAAa,CAAiB;IAC9C,kEAAkE;IAClD,QAAQ,CAAU;IAClC,iEAAiE;IACjD,WAAW,CAAU;IAErC,YAAY,EACV,IAAI,EACJ,IAAI,EACJ,aAAa,EACb,QAAQ,EACR,WAAW,GAOZ;QACC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACH,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;IACvC,CAAC;IAED;;;;OAIG;IACH,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;IAC5B,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,OAAO,CAAC,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angeRatio, type ValueComponents } from "../utils/utils.js";
|
|
3
|
+
import { Info } from "./info.js";
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when an exact quote cannot be represented by the order ratio format.
|
|
6
|
+
*/
|
|
7
|
+
export declare class OrderConversionRepresentabilityError extends Error {
|
|
8
|
+
/** Creates a representability error with the default public conversion message. */
|
|
9
|
+
constructor(message?: string, options?: ErrorOptions);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Quotes a new order: the output-side amount, the CKB fee, and the order info.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* The returned `Info` preserves the quoted amount after fee adjustment so the
|
|
16
|
+
* minted order records the executable limit price.
|
|
17
|
+
*/
|
|
18
|
+
export declare function quoteConversion(isCkb2Udt: boolean, midpoint: ExchangeRatio, amounts: ValueComponents, { fee, feeBase }: {
|
|
19
|
+
fee: ccc.Num;
|
|
20
|
+
feeBase: ccc.Num;
|
|
21
|
+
}): {
|
|
22
|
+
convertedAmount: ccc.FixedPoint;
|
|
23
|
+
ckbFee: ccc.FixedPoint;
|
|
24
|
+
info: Info;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The greatest fraction at most `numerator / denominator` whose terms are at most
|
|
28
|
+
* `maxTerm`, reduced. It walks the continued fraction's convergents while they fit; the
|
|
29
|
+
* first that does not is replaced by the largest semiconvergent the bound allows, which
|
|
30
|
+
* is closer to the target than the last fitting convergent on the same side of it. Every
|
|
31
|
+
* other convergent lands above the target and is skipped.
|
|
32
|
+
*/
|
|
33
|
+
export declare function greatestBoundedFractionAtMost(numerator: bigint, denominator: bigint, maxTerm: bigint): {
|
|
34
|
+
numerator: bigint;
|
|
35
|
+
denominator: bigint;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=conversion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversion.d.ts","sourceRoot":"","sources":["../../src/order/conversion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,EAAW,KAAK,aAAa,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACtF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAKjC;;GAEG;AACH,qBAAa,oCAAqC,SAAQ,KAAK;IAC7D,mFAAmF;IACnF,YACE,OAAO,SAAiE,EACxE,OAAO,CAAC,EAAE,YAAY,EAIvB;CACF;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,OAAO,EAClB,QAAQ,EAAE,aAAa,EACvB,OAAO,EAAE,eAAe,EACxB,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE;IAAE,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC;IAAC,OAAO,EAAE,GAAG,CAAC,GAAG,CAAA;CAAE,GACnD;IAAE,eAAe,EAAE,GAAG,CAAC,UAAU,CAAC;IAAC,MAAM,EAAE,GAAG,CAAC,UAAU,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAoBzE;AAiED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CA+B5C"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { ckbFromUdt } from "../udt.js";
|
|
3
|
+
import { ceilDiv } from "../utils/utils.js";
|
|
4
|
+
import { Info } from "./info.js";
|
|
5
|
+
import { Ratio } from "./ratio.js";
|
|
6
|
+
const maxUint64 = (1n << 64n) - 1n;
|
|
7
|
+
/**
|
|
8
|
+
* Error thrown when an exact quote cannot be represented by the order ratio format.
|
|
9
|
+
*/
|
|
10
|
+
export class OrderConversionRepresentabilityError extends Error {
|
|
11
|
+
/** Creates a representability error with the default public conversion message. */
|
|
12
|
+
constructor(message = "Order conversion quote cannot be represented as Uint64 ratio", options) {
|
|
13
|
+
super(message, options);
|
|
14
|
+
this.name = "OrderConversionRepresentabilityError";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Quotes a new order: the output-side amount, the CKB fee, and the order info.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* The returned `Info` preserves the quoted amount after fee adjustment so the
|
|
22
|
+
* minted order records the executable limit price.
|
|
23
|
+
*/
|
|
24
|
+
export function quoteConversion(isCkb2Udt, midpoint, amounts, { fee, feeBase }) {
|
|
25
|
+
const base = Ratio.from(midpoint);
|
|
26
|
+
const amount = isCkb2Udt ? amounts.ckbValue : amounts.udtValue;
|
|
27
|
+
const { aScale, bScale } = feeAdjustedScales(base, isCkb2Udt, fee, feeBase);
|
|
28
|
+
const convertedAmount = ceilDiv(amount * aScale, bScale);
|
|
29
|
+
let ckbFee = 0n;
|
|
30
|
+
if (amount > 0n && fee !== 0n) {
|
|
31
|
+
ckbFee = isCkb2Udt
|
|
32
|
+
? amount - ckbFromUdt(convertedAmount, base)
|
|
33
|
+
: ckbFromUdt(amount, base) - convertedAmount;
|
|
34
|
+
}
|
|
35
|
+
// Every order this SDK creates carries the default minimum match, the one the bot's
|
|
36
|
+
// remainder rule is sized to.
|
|
37
|
+
const info = Info.create(isCkb2Udt, quotePreservingRatio(amount, convertedAmount, isCkb2Udt));
|
|
38
|
+
return { convertedAmount, ckbFee, info };
|
|
39
|
+
}
|
|
40
|
+
/** The direction's scales with the fee taken out of the output side, reduced. */
|
|
41
|
+
function feeAdjustedScales(ratio, isCkb2Udt, fee, feeBase) {
|
|
42
|
+
if (fee < 0n) {
|
|
43
|
+
throw new Error("Fee cannot be negative");
|
|
44
|
+
}
|
|
45
|
+
if (feeBase <= 0n) {
|
|
46
|
+
throw new Error("Fee base must be positive");
|
|
47
|
+
}
|
|
48
|
+
if (fee >= feeBase) {
|
|
49
|
+
throw new Error("Fee too big relative to feeBase");
|
|
50
|
+
}
|
|
51
|
+
if (!ratio.isPopulated()) {
|
|
52
|
+
throw new Error("Invalid ExchangeRatio");
|
|
53
|
+
}
|
|
54
|
+
let { ckbScale: aScale, udtScale: bScale } = ratio;
|
|
55
|
+
if (!isCkb2Udt) {
|
|
56
|
+
[aScale, bScale] = [bScale, aScale];
|
|
57
|
+
}
|
|
58
|
+
aScale *= feeBase - fee;
|
|
59
|
+
bScale *= feeBase;
|
|
60
|
+
const divisor = ccc.gcd(aScale, bScale);
|
|
61
|
+
return { aScale: aScale / divisor, bScale: bScale / divisor };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The ratio that reproduces the quote exactly: the greatest Uint64 fraction at most
|
|
65
|
+
* `quotedOutput / inputAmount`, which must still round the input up to the quoted output.
|
|
66
|
+
*/
|
|
67
|
+
function quotePreservingRatio(inputAmount, quotedOutput, isCkb2Udt) {
|
|
68
|
+
if (inputAmount < 0n || quotedOutput < 0n) {
|
|
69
|
+
throw new Error("Order conversion amounts cannot be negative");
|
|
70
|
+
}
|
|
71
|
+
if (inputAmount === 0n || quotedOutput === 0n) {
|
|
72
|
+
throw new OrderConversionRepresentabilityError("Order conversion quote must have positive input and output");
|
|
73
|
+
}
|
|
74
|
+
const { numerator, denominator } = greatestBoundedFractionAtMost(quotedOutput, inputAmount, maxUint64);
|
|
75
|
+
if (numerator <= 0n || (quotedOutput - 1n) * denominator >= inputAmount * numerator) {
|
|
76
|
+
throw new OrderConversionRepresentabilityError();
|
|
77
|
+
}
|
|
78
|
+
return Ratio.from({
|
|
79
|
+
ckbScale: isCkb2Udt ? numerator : denominator,
|
|
80
|
+
udtScale: isCkb2Udt ? denominator : numerator,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The greatest fraction at most `numerator / denominator` whose terms are at most
|
|
85
|
+
* `maxTerm`, reduced. It walks the continued fraction's convergents while they fit; the
|
|
86
|
+
* first that does not is replaced by the largest semiconvergent the bound allows, which
|
|
87
|
+
* is closer to the target than the last fitting convergent on the same side of it. Every
|
|
88
|
+
* other convergent lands above the target and is skipped.
|
|
89
|
+
*/
|
|
90
|
+
export function greatestBoundedFractionAtMost(numerator, denominator, maxTerm) {
|
|
91
|
+
let best = { numerator: 0n, denominator: 1n };
|
|
92
|
+
let [previousP, previousQ, p, q] = [0n, 1n, 1n, 0n];
|
|
93
|
+
let [n, d] = [numerator, denominator];
|
|
94
|
+
while (d !== 0n) {
|
|
95
|
+
const quotient = n / d;
|
|
96
|
+
let term = quotient;
|
|
97
|
+
if (p !== 0n) {
|
|
98
|
+
term = ccc.numMin(term, (maxTerm - previousP) / p);
|
|
99
|
+
}
|
|
100
|
+
if (q !== 0n) {
|
|
101
|
+
term = ccc.numMin(term, (maxTerm - previousQ) / q);
|
|
102
|
+
}
|
|
103
|
+
const candidate = {
|
|
104
|
+
numerator: term * p + previousP,
|
|
105
|
+
denominator: term * q + previousQ,
|
|
106
|
+
};
|
|
107
|
+
if (candidate.denominator > 0n &&
|
|
108
|
+
candidate.numerator * denominator <= candidate.denominator * numerator &&
|
|
109
|
+
candidate.numerator * best.denominator > best.numerator * candidate.denominator) {
|
|
110
|
+
best = candidate;
|
|
111
|
+
}
|
|
112
|
+
if (term < quotient) {
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
[previousP, previousQ, p, q] = [p, q, candidate.numerator, candidate.denominator];
|
|
116
|
+
[n, d] = [d, n % d];
|
|
117
|
+
}
|
|
118
|
+
return best;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=conversion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversion.js","sourceRoot":"","sources":["../../src/order/conversion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,O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
+
* The mining fee one more matched order adds to a prepared transaction at the fee rate
|
|
5
|
+
* (shannons per thousand bytes): its input, its replacement output with data, and its
|
|
6
|
+
* empty witness, sized for the largest order of the pool.
|
|
7
|
+
*/
|
|
8
|
+
export declare function partialOrderFee(orderPool: OrderGroup[], feeRate: ccc.Num): bigint;
|
|
9
|
+
//# sourceMappingURL=fee.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fee.d.ts","sourceRoot":"","sources":["../../src/order/fee.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAe7C;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,UAAU,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,GAAG,GAAG,MAAM,CAOjF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { ceilDiv } from "../utils/utils.js";
|
|
3
|
+
const CELL_INPUT_SERIALIZED_SIZE = 44;
|
|
4
|
+
// CellOutput table/script wrappers plus DynVec offset; output data Bytes plus offset.
|
|
5
|
+
const CELL_OUTPUT_SERIALIZATION_OVERHEAD = 60;
|
|
6
|
+
const OUTPUT_DATA_SERIALIZATION_OVERHEAD = 8;
|
|
7
|
+
// The supported SDK completion prepares a later signer witness, inserting one
|
|
8
|
+
// empty witness-vector entry for each preceding order input.
|
|
9
|
+
const EMPTY_WITNESS_SERIALIZATION_SIZE = 8;
|
|
10
|
+
const PREPARED_PARTIAL_SERIALIZATION_OVERHEAD = CELL_INPUT_SERIALIZED_SIZE +
|
|
11
|
+
CELL_OUTPUT_SERIALIZATION_OVERHEAD +
|
|
12
|
+
OUTPUT_DATA_SERIALIZATION_OVERHEAD +
|
|
13
|
+
EMPTY_WITNESS_SERIALIZATION_SIZE;
|
|
14
|
+
/**
|
|
15
|
+
* The mining fee one more matched order adds to a prepared transaction at the fee rate
|
|
16
|
+
* (shannons per thousand bytes): its input, its replacement output with data, and its
|
|
17
|
+
* empty witness, sized for the largest order of the pool.
|
|
18
|
+
*/
|
|
19
|
+
export function partialOrderFee(orderPool, feeRate) {
|
|
20
|
+
const orderSize = orderPool.reduce((largest, group) => Math.max(largest, group.order.cell.occupiedSize), 0);
|
|
21
|
+
const bytes = ccc.numFrom(orderSize + PREPARED_PARTIAL_SERIALIZATION_OVERHEAD);
|
|
22
|
+
return ceilDiv(bytes * feeRate, 1000n);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=fee.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fee.js","sourceRoot":"","sources":["../../src/order/fee.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C,MAAM,0BAA0B,GAAG,EAAE,CAAC;AACtC,sFAAsF;AACtF,MAAM,kCAAkC,GAAG,EAAE,CAAC;AAC9C,MAAM,kCAAkC,GAAG,CAAC,CAAC;AAC7C,8EAA8E;AAC9E,6DAA6D;AAC7D,MAAM,gCAAgC,GAAG,CAAC,CAAC;AAC3C,MAAM,uCAAuC,GAC3C,0BAA0B;IAC1B,kCAAkC;IAClC,kCAAkC;IAClC,gCAAgC,CAAC;AAEnC;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,SAAuB,EAAE,OAAgB;IACvE,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,CAChC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,EACpE,CAAC,CACF,CAAC;IACF,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,uCAAuC,CAAC,CAAC;IAC/E,OAAO,OAAO,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import type { ExchangeRatio } from "../utils/utils.js";
|
|
3
|
+
import type { OrderGroup } from "./cells.js";
|
|
4
|
+
import { type Match, OrderMatcher } from "./matcher.js";
|
|
5
|
+
/** The cost of taking one fill, in the exchange value's unit. */
|
|
6
|
+
export declare function fillCost(fee: bigint, { ckbScale }: ExchangeRatio): bigint;
|
|
7
|
+
/** A fill's exchange value at the DAO ratio, net of the cost of taking it. */
|
|
8
|
+
export declare function netOf(fill: Match, cost: bigint, { ckbScale, udtScale }: ExchangeRatio): bigint;
|
|
9
|
+
/** Whether the matcher's whole fill returns its cost. */
|
|
10
|
+
export declare function returnsCost(matcher: OrderMatcher, cost: bigint, exchangeRatio: ExchangeRatio): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether the bot would take the whole order in the given direction. Judged on the order
|
|
13
|
+
* alone, independently of the bot's current inventory. Price and the sampled fee rate
|
|
14
|
+
* decide profitability; balances decide whether a particular turn can afford it.
|
|
15
|
+
*/
|
|
16
|
+
export declare function fillsWhole(group: OrderGroup, isCkb2Udt: boolean, exchangeRatio: ExchangeRatio, feeRate: ccc.Num): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Whether a buy fails today's whole-fill profitability rule and should be collected.
|
|
19
|
+
* DAO growth makes it less attractive, though a lower fee rate could change this result.
|
|
20
|
+
* Sells are not refused: growth can make them profitable later, so unfilled sells return
|
|
21
|
+
* only through the age cutoff ({@link isStale}).
|
|
22
|
+
*/
|
|
23
|
+
export declare function isRefused(group: OrderGroup, { exchangeRatio, feeRate }: {
|
|
24
|
+
exchangeRatio: ExchangeRatio;
|
|
25
|
+
feeRate: ccc.Num;
|
|
26
|
+
}): boolean;
|
|
27
|
+
/** Thirty days of eight-second blocks. */
|
|
28
|
+
export declare const STALE_ORDER_BLOCKS: bigint;
|
|
29
|
+
/**
|
|
30
|
+
* Whether the order has sat on the book for thirty days: whatever the reason (dust under
|
|
31
|
+
* the fill's cost, a remainder another matcher left, an ask above the market), it is
|
|
32
|
+
* collected and its funds returned. Age from the origin's block. The block count assumes
|
|
33
|
+
* eight-second blocks, not wall time.
|
|
34
|
+
*/
|
|
35
|
+
export declare function isStale(group: OrderGroup, tip: ccc.ClientBlockHeader): boolean;
|
|
36
|
+
//# sourceMappingURL=fill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fill.d.ts","sourceRoot":"","sources":["../../src/order/fill.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EAAE,KAAK,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAUxD,iEAAiE;AACjE,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,EAAE,aAAa,GAAG,MAAM,CAEzE;AAED,8EAA8E;AAC9E,wBAAgB,KAAK,CACnB,IAAI,EAAE,KAAK,EACX,IAAI,EAAE,MAAM,EACZ,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,aAAa,GACpC,MAAM,CAER;AAED,yDAAyD;AACzD,wBAAgB,WAAW,CACzB,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,aAAa,GAC3B,OAAO,CAET;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,UAAU,EACjB,SAAS,EAAE,OAAO,EAClB,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE,GAAG,CAAC,GAAG,GACf,OAAO,CAOT;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,UAAU,EACjB,EAAE,aAAa,EAAE,OAAO,EAAE,EAAE;IAAE,aAAa,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE,GAAG,CAAC,GAAG,CAAA;CAAE,GAC7E,OAAO,CAIT;AAED,0CAA0C;AAC1C,eAAO,MAAM,kBAAkB,QAA+B,CAAC;AAE/D;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,CAAC,iBAAiB,GAAG,OAAO,CAE9E"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { partialOrderFee } from "./fee.js";
|
|
2
|
+
import { OrderMatcher } from "./matcher.js";
|
|
3
|
+
/**
|
|
4
|
+
* What a fill must return before the bot takes it, in mining fees of its own: the buffer
|
|
5
|
+
* for the deposits and withdrawals that rebalance the inventory it moves (user decision
|
|
6
|
+
* 2026-09-10, tuned on testnet). One rule for the bot's fills and the refused-buy
|
|
7
|
+
* classification used by the generator and interface.
|
|
8
|
+
*/
|
|
9
|
+
const FILL_COST_FEES = 10n;
|
|
10
|
+
/** The cost of taking one fill, in the exchange value's unit. */
|
|
11
|
+
export function fillCost(fee, { ckbScale }) {
|
|
12
|
+
return FILL_COST_FEES * fee * ckbScale;
|
|
13
|
+
}
|
|
14
|
+
/** A fill's exchange value at the DAO ratio, net of the cost of taking it. */
|
|
15
|
+
export function netOf(fill, cost, { ckbScale, udtScale }) {
|
|
16
|
+
return fill.ckbDelta * ckbScale + fill.udtDelta * udtScale - cost;
|
|
17
|
+
}
|
|
18
|
+
/** Whether the matcher's whole fill returns its cost. */
|
|
19
|
+
export function returnsCost(matcher, cost, exchangeRatio) {
|
|
20
|
+
return netOf(matcher.match(matcher.bMaxMatch), cost, exchangeRatio) > 0n;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Whether the bot would take the whole order in the given direction. Judged on the order
|
|
24
|
+
* alone, independently of the bot's current inventory. Price and the sampled fee rate
|
|
25
|
+
* decide profitability; balances decide whether a particular turn can afford it.
|
|
26
|
+
*/
|
|
27
|
+
export function fillsWhole(group, isCkb2Udt, exchangeRatio, feeRate) {
|
|
28
|
+
const fee = partialOrderFee([group], feeRate);
|
|
29
|
+
const matcher = OrderMatcher.from(group, isCkb2Udt, fee);
|
|
30
|
+
return (matcher !== undefined &&
|
|
31
|
+
returnsCost(matcher, fillCost(fee, exchangeRatio), exchangeRatio));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Whether a buy fails today's whole-fill profitability rule and should be collected.
|
|
35
|
+
* DAO growth makes it less attractive, though a lower fee rate could change this result.
|
|
36
|
+
* Sells are not refused: growth can make them profitable later, so unfilled sells return
|
|
37
|
+
* only through the age cutoff ({@link isStale}).
|
|
38
|
+
*/
|
|
39
|
+
export function isRefused(group, { exchangeRatio, feeRate }) {
|
|
40
|
+
return (group.order.data.info.isCkb2Udt() && !fillsWhole(group, true, exchangeRatio, feeRate));
|
|
41
|
+
}
|
|
42
|
+
/** Thirty days of eight-second blocks. */
|
|
43
|
+
export const STALE_ORDER_BLOCKS = (30n * 24n * 60n * 60n) / 8n;
|
|
44
|
+
/**
|
|
45
|
+
* Whether the order has sat on the book for thirty days: whatever the reason (dust under
|
|
46
|
+
* the fill's cost, a remainder another matcher left, an ask above the market), it is
|
|
47
|
+
* collected and its funds returned. Age from the origin's block. The block count assumes
|
|
48
|
+
* eight-second blocks, not wall time.
|
|
49
|
+
*/
|
|
50
|
+
export function isStale(group, tip) {
|
|
51
|
+
return group.blockNumber + STALE_ORDER_BLOCKS <= tip.number;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=fill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fill.js","sourceRoot":"","sources":["../../src/order/fill.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAc,YAAY,EAAE,MAAM,cAAc,CAA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AAI,EAAE,aAAa,EAAE,OAAO,CAAC,CACtF,CAAC;AACJ,CAAC;AAED,0CAA0C;AAC1C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC,GAAG,EAAE,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,KAAiB,EAAE,GAA0B;IACnE,OAAO,KAAK,CAAC,WAAW,GAAG,kBAAkB,IAAI,GAAG,CAAC,MAAM,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import type { ExchangeRatio } from "../utils/utils.js";
|
|
3
|
+
import { Ratio } from "./ratio.js";
|
|
4
|
+
/**
|
|
5
|
+
* Wire shape for an order's directional ratios and minimum CKB match.
|
|
6
|
+
*/
|
|
7
|
+
export interface InfoLike {
|
|
8
|
+
/** Populated when the order can trade CKB for UDT; empty otherwise. */
|
|
9
|
+
ckbToUdt: ExchangeRatio;
|
|
10
|
+
/** Populated when the order can trade UDT for CKB; empty otherwise. */
|
|
11
|
+
udtToCkb: ExchangeRatio;
|
|
12
|
+
/** Base-2 exponent for the minimum CKB match amount. */
|
|
13
|
+
ckbMinMatchLog: ccc.FixedPointLike;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Order price and minimum-match metadata.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* Exactly one populated ratio describes a directional order. Two populated
|
|
20
|
+
* ratios describe a dual-ratio order. Validation rejects empty/invalid pairs and
|
|
21
|
+
* ratio pairs that allow value extraction.
|
|
22
|
+
*/
|
|
23
|
+
export interface Info {
|
|
24
|
+
/** Ratio for CKB-to-UDT matching, or empty when unavailable. */
|
|
25
|
+
ckbToUdt: Ratio;
|
|
26
|
+
/** Ratio for UDT-to-CKB matching, or empty when unavailable. */
|
|
27
|
+
udtToCkb: Ratio;
|
|
28
|
+
/** Base-2 exponent for the minimum CKB match amount. */
|
|
29
|
+
ckbMinMatchLog: number;
|
|
30
|
+
/** Creates a copy of this order info. */
|
|
31
|
+
clone(): Info;
|
|
32
|
+
/** Returns whether another value has the same order info. */
|
|
33
|
+
eq(other: InfoLike): boolean;
|
|
34
|
+
/** Returns `2 ** ckbMinMatchLog` as the minimum CKB match amount. */
|
|
35
|
+
getCkbMinMatch(): ccc.FixedPoint;
|
|
36
|
+
/** Returns the CKB hash of the serialized order info. */
|
|
37
|
+
hash(): ccc.Hex;
|
|
38
|
+
/** Returns whether the CKB-to-UDT ratio is populated. */
|
|
39
|
+
isCkb2Udt(): boolean;
|
|
40
|
+
/** Returns whether both directional ratios are populated. */
|
|
41
|
+
isDualRatio(): boolean;
|
|
42
|
+
/** Returns whether the UDT-to-CKB ratio is populated. */
|
|
43
|
+
isUdt2Ckb(): boolean;
|
|
44
|
+
/** Serializes the order info to bytes. */
|
|
45
|
+
toBytes(): ccc.Bytes;
|
|
46
|
+
/** Serializes the order info to full-width hexadecimal. */
|
|
47
|
+
toHex(): ccc.Hex;
|
|
48
|
+
/** Throws if the ratios or minimum-match exponent are invalid. */
|
|
49
|
+
validate(): void;
|
|
50
|
+
}
|
|
51
|
+
export declare const CKB_MIN_MATCH_LOG_DEFAULT = 36;
|
|
52
|
+
/** CCC-backed order-info constructor and codec. */
|
|
53
|
+
export declare const Info: {
|
|
54
|
+
byteLength?: number;
|
|
55
|
+
new (ckbToUdt: Ratio, udtToCkb: Ratio, ckbMinMatchLog: number): Info;
|
|
56
|
+
create: (isCkb2Udt: boolean, ratioLike: ExchangeRatio) => Info;
|
|
57
|
+
decode: (encoded: ccc.BytesLike) => Info;
|
|
58
|
+
encode: (info: InfoLike) => ccc.Bytes;
|
|
59
|
+
from: (info: InfoLike) => Info;
|
|
60
|
+
fromBytes: (encoded: ccc.BytesLike) => Info;
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=info.d.ts.map
|
|
@@ -0,0 +1 @@
|
|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C,EAAE,MAAM,CAAC;IACpB,KAAK,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IACrE,MAAM,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,KAAK,IAAI,CAAC;IAC/D,MAAM,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,SAAS,KAAK,IAAI,CAAC;IACzC,MAAM,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,GAAG,CAAC,KAAK,CAAC;IACtC,IAAI,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;IAC/B,SAAS,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,SAAS,KAAK,IAAI,CAAC;CACxB,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ccc, mol } from "@ckb-ccc/core";
|
|
2
|
+
import { CheckedUint8 } from "../utils/codec.js";
|
|
3
|
+
import { Ratio } from "./ratio.js";
|
|
4
|
+
const InfoCodec = mol.struct({
|
|
5
|
+
ckbToUdt: Ratio,
|
|
6
|
+
udtToCkb: Ratio,
|
|
7
|
+
ckbMinMatchLog: CheckedUint8,
|
|
8
|
+
});
|
|
9
|
+
const InfoBase = ccc.Entity.Base();
|
|
10
|
+
// 2^36 shannons, about 687 CKB, leaves fresh remainders headroom above the fill-cost floor.
|
|
11
|
+
// Orders below twice that minimum are whole-only. Converted to iCKB, this band must stay
|
|
12
|
+
// below `ICKB_REFILL_BELOW` so a buyer too small to split triggers a refill when inventory
|
|
13
|
+
// cannot fill it whole. Fee changes and an aging buy can still make a remainder unprofitable.
|
|
14
|
+
export const CKB_MIN_MATCH_LOG_DEFAULT = 36;
|
|
15
|
+
// An interface, this class expression and a typed const rather than one plain class: a
|
|
16
|
+
// class extending `ccc.Entity.Base<...>()` emits an unexported `*_base` declaration, which
|
|
17
|
+
// API Extractor's ae-forgotten-export rejects (tried 2026-10-30).
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow -- Preserve the runtime constructor name.
|
|
19
|
+
const InfoImplementation = class Info extends InfoBase {
|
|
20
|
+
static {
|
|
21
|
+
ccc.codec(InfoCodec)(this);
|
|
22
|
+
}
|
|
23
|
+
/** Ratio for CKB-to-UDT matching, or empty when unavailable. */
|
|
24
|
+
ckbToUdt;
|
|
25
|
+
/** Ratio for UDT-to-CKB matching, or empty when unavailable. */
|
|
26
|
+
udtToCkb;
|
|
27
|
+
/** Base-2 exponent for the minimum CKB match amount. */
|
|
28
|
+
ckbMinMatchLog;
|
|
29
|
+
/** Creates order info from normalized ratio objects. */
|
|
30
|
+
constructor(ckbToUdt, udtToCkb, ckbMinMatchLog) {
|
|
31
|
+
super();
|
|
32
|
+
this.ckbToUdt = ckbToUdt;
|
|
33
|
+
this.udtToCkb = udtToCkb;
|
|
34
|
+
this.ckbMinMatchLog = ckbMinMatchLog;
|
|
35
|
+
}
|
|
36
|
+
/** Normalizes an `InfoLike` wire object or existing entity into `Info`. */
|
|
37
|
+
static from(info) {
|
|
38
|
+
if (info instanceof Info) {
|
|
39
|
+
return info;
|
|
40
|
+
}
|
|
41
|
+
const { ckbToUdt, udtToCkb, ckbMinMatchLog } = info;
|
|
42
|
+
return new Info(Ratio.from(ckbToUdt), Ratio.from(udtToCkb), Number(ckbMinMatchLog));
|
|
43
|
+
}
|
|
44
|
+
/** Creates directional order info from one ratio, at the default minimum match. */
|
|
45
|
+
static create(isCkb2Udt, ratioLike) {
|
|
46
|
+
return Info.from({
|
|
47
|
+
ckbToUdt: isCkb2Udt ? ratioLike : Ratio.empty(),
|
|
48
|
+
udtToCkb: isCkb2Udt ? Ratio.empty() : ratioLike,
|
|
49
|
+
ckbMinMatchLog: CKB_MIN_MATCH_LOG_DEFAULT,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/** Throws when ratio pairing or minimum-match exponent is invalid. */
|
|
53
|
+
validate() {
|
|
54
|
+
if (!isValidCkbMinMatchLog(this.ckbMinMatchLog)) {
|
|
55
|
+
throw new Error("ckbMinMatchLog invalid");
|
|
56
|
+
}
|
|
57
|
+
this.ckbToUdt.validate();
|
|
58
|
+
this.udtToCkb.validate();
|
|
59
|
+
if (this.ckbToUdt.isEmpty()) {
|
|
60
|
+
if (this.udtToCkb.isPopulated()) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
throw new Error("ckbToUdt is Empty, but udtToCkb is not Populated");
|
|
64
|
+
}
|
|
65
|
+
if (this.udtToCkb.isEmpty()) {
|
|
66
|
+
if (this.ckbToUdt.isPopulated()) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
throw new Error("udtToCkb is Empty, but ckbToUdt is not Populated");
|
|
70
|
+
}
|
|
71
|
+
if (!this.ckbToUdt.isPopulated() || !this.udtToCkb.isPopulated()) {
|
|
72
|
+
throw new Error("One ratio is invalid, so not Empty and not Populated");
|
|
73
|
+
}
|
|
74
|
+
if (this.ckbToUdt.ckbScale * this.udtToCkb.udtScale <
|
|
75
|
+
this.ckbToUdt.udtScale * this.udtToCkb.ckbScale) {
|
|
76
|
+
throw new Error("udtToCkb and ckbToUdt allow order value to be extracted");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** Returns the minimum CKB match amount. */
|
|
80
|
+
getCkbMinMatch() {
|
|
81
|
+
return 1n << BigInt(this.ckbMinMatchLog);
|
|
82
|
+
}
|
|
83
|
+
/** Returns true when CKB-to-UDT matching is enabled. */
|
|
84
|
+
isCkb2Udt() {
|
|
85
|
+
return this.ckbToUdt.isPopulated();
|
|
86
|
+
}
|
|
87
|
+
/** Returns true when UDT-to-CKB matching is enabled. */
|
|
88
|
+
isUdt2Ckb() {
|
|
89
|
+
return this.udtToCkb.isPopulated();
|
|
90
|
+
}
|
|
91
|
+
/** Returns true when both directions are enabled. */
|
|
92
|
+
isDualRatio() {
|
|
93
|
+
return this.isCkb2Udt() && this.isUdt2Ckb();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
/** CCC-backed order-info constructor and codec. */
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare -- The public type and runtime constructor intentionally share a name.
|
|
98
|
+
export const Info = InfoImplementation;
|
|
99
|
+
function isValidCkbMinMatchLog(value) {
|
|
100
|
+
return Number.isInteger(value) && value >= 0 && value <= 64;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"info.js","sourceRoot":"","sources":["../../src/order/info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAcnC,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC;IAC3B,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,KAAK;IACf,cAAc,EAAE,YAAY;CAC7B,CAAC,CAAC;AAEH,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,EAAkB,CAAC;AAuCnD,4FAA4F;AAC5F,yFAAyF;AACzF,2FAA2F;AAC3F,8FAA8F;AAC9F,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAE5C,uFAAuF;AACvF,2FAA2F;AAC3F,kEAAkE;AAClE,kGAAkG;AAClG,MAAM,kBAAkB,GAAG,MAAM,IAAK,SAAQ,QAAQ;IACpD;QACE,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,gEAAgE;IAChD,QAAQ,CAAQ;IAChC,gEAAgE;IAChD,QAAQ,CAAQ;IAChC,wDAAwD;IACxC,cAAc,CAAS;IAEvC,wDAAwD;IACxD,YAAY,QAAe,EAAE,QAAe,EAAE,cAAsB;QAClE,KAAK,EAAE,CAAC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CAAC,KAAa;IAC1C,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { Relative, type RelativeLike } from "./relative.js";
|
|
3
|
+
declare const MasterCodec: ccc.Codec<{
|
|
4
|
+
type: "absolute";
|
|
5
|
+
value: ccc.OutPointLike;
|
|
6
|
+
} | {
|
|
7
|
+
type: "relative";
|
|
8
|
+
value: RelativeLike;
|
|
9
|
+
} | {
|
|
10
|
+
inner: {
|
|
11
|
+
type: "absolute";
|
|
12
|
+
value: ccc.OutPointLike;
|
|
13
|
+
} | {
|
|
14
|
+
type: "relative";
|
|
15
|
+
value: RelativeLike;
|
|
16
|
+
};
|
|
17
|
+
}, {
|
|
18
|
+
type: "absolute";
|
|
19
|
+
value: ccc.OutPoint;
|
|
20
|
+
} | {
|
|
21
|
+
type: "relative";
|
|
22
|
+
value: Relative;
|
|
23
|
+
}, unknown>;
|
|
24
|
+
/**
|
|
25
|
+
* Master pointer before normalization.
|
|
26
|
+
*/
|
|
27
|
+
export type MasterLike = {
|
|
28
|
+
type: "relative";
|
|
29
|
+
value: RelativeLike;
|
|
30
|
+
} | {
|
|
31
|
+
type: "absolute";
|
|
32
|
+
value: ccc.OutPointLike;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Master pointer stored in order data.
|
|
36
|
+
*/
|
|
37
|
+
export type Master = {
|
|
38
|
+
type: "relative";
|
|
39
|
+
value: Relative;
|
|
40
|
+
} | {
|
|
41
|
+
type: "absolute";
|
|
42
|
+
value: ccc.OutPoint;
|
|
43
|
+
};
|
|
44
|
+
/** Normalizes a master pointer into entity values. */
|
|
45
|
+
export declare function masterFrom(master: MasterLike): Master;
|
|
46
|
+
/** Validates a normalized master pointer. */
|
|
47
|
+
export declare function masterValidate(master: Master): void;
|
|
48
|
+
export { MasterCodec };
|
|
49
|
+
//# sourceMappingURL=master.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"master.d.ts","sourceRoot":"","sources":["../../src/order/master.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAO,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAI5D,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;WAGf,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,GAAG,CAAC,YAAY,CAAA;CAAE,CAAC;AAElD;;GAEG;AACH,MAAM,MAAM,MAAM,GAChB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,QAAQ,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,GAAG,CAAC,QAAQ,CAAA;CAAE,CAAC;AAEpF,sDAAsD;AACtD,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAKrD;AAED,6CAA6C;AAC7C,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAOnD;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ccc, mol } from "@ckb-ccc/core";
|
|
2
|
+
import { Relative } from "./relative.js";
|
|
3
|
+
// Both variants are 36 bytes, and OrderData is a struct, so the union must be fixed-size:
|
|
4
|
+
// CCC 1.23+ sizes a plain union dynamically and rejects it as a struct field.
|
|
5
|
+
const MasterCodec = mol.fixedUnion({
|
|
6
|
+
relative: Relative,
|
|
7
|
+
absolute: ccc.OutPoint,
|
|
8
|
+
});
|
|
9
|
+
/** Normalizes a master pointer into entity values. */
|
|
10
|
+
export function masterFrom(master) {
|
|
11
|
+
if (master.type === "relative") {
|
|
12
|
+
return { type: "relative", value: Relative.from(master.value) };
|
|
13
|
+
}
|
|
14
|
+
return { type: "absolute", value: ccc.OutPoint.from(master.value) };
|
|
15
|
+
}
|
|
16
|
+
/** Validates a normalized master pointer. */
|
|
17
|
+
export function masterValidate(master) {
|
|
18
|
+
const { type, value } = master;
|
|
19
|
+
if (type === "relative") {
|
|
20
|
+
value.validate();
|
|
21
|
+
}
|
|
22
|
+
else if (!/^0x[0-9a-f]{64}$/i.test(value.txHash) || value.index < 0) {
|
|
23
|
+
throw new Error("OutPoint invalid");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export { MasterCodec };
|
|
27
|
+
//# sourceMappingURL=master.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"master.js","sourceRoot":"","sources":["../../src/order/master.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAqB,MAAM,eAAe,CAAC;AAE5D,0FAA0F;AAC1F,8EAA8E;AAC9E,MAAM,WAAW,GAAG,GAAG,CAAC,UAAU,CAAC;IACjC,QAAQ,EAAE,QAAQ;IAClB,QAAQ,EAAE,GAAG,CAAC,QAAQ;CACvB,CAAC,CAAC;AAeH,sDAAsD;AACtD,MAAM,UAAU,UAAU,CAAC,MAAkB;IAC3C,IAAI,MAAM,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QAC/B,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IAClE,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AACtE,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IAC/B,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;QACxB,KAAK,CAAC,QAAQ,EAAE,CAAC;IACnB,CAAC;SAAM,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtC,CAAC;AACH,CAAC;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import type { OrderGroup } from "./cells.js";
|
|
3
|
+
/**
|
|
4
|
+
* The fills of one or more orders from the matcher caller's perspective.
|
|
5
|
+
*/
|
|
6
|
+
export interface Match {
|
|
7
|
+
/** Net CKB change from the match. */
|
|
8
|
+
ckbDelta: bigint;
|
|
9
|
+
/** Net UDT change from the match. */
|
|
10
|
+
udtDelta: bigint;
|
|
11
|
+
/** Partial order outputs that must replace matched order inputs. */
|
|
12
|
+
partials: Array<{
|
|
13
|
+
/** Resolved group that proves the matched order's mint origin. */
|
|
14
|
+
group: OrderGroup;
|
|
15
|
+
/** CKB capacity for the replacement partial order output. */
|
|
16
|
+
ckbOut: ccc.FixedPoint;
|
|
17
|
+
/** UDT amount for the replacement partial order output. */
|
|
18
|
+
udtOut: ccc.FixedPoint;
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* One order's fills in one direction, in the contract's terms: `a` is the asset the order
|
|
23
|
+
* gives, `b` the asset the caller pays. A partial pays `b` between `bMinMatch` and
|
|
24
|
+
* `bMaxMatch`; paying `bMaxMatch` completes the order.
|
|
25
|
+
*/
|
|
26
|
+
export declare class OrderMatcher {
|
|
27
|
+
readonly group: OrderGroup;
|
|
28
|
+
readonly isCkb2Udt: boolean;
|
|
29
|
+
readonly aScale: ccc.Num;
|
|
30
|
+
readonly bScale: ccc.Num;
|
|
31
|
+
readonly aIn: ccc.FixedPoint;
|
|
32
|
+
readonly bIn: ccc.FixedPoint;
|
|
33
|
+
readonly aMin: ccc.FixedPoint;
|
|
34
|
+
readonly bMinMatch: ccc.FixedPoint;
|
|
35
|
+
readonly bMaxMatch: ccc.FixedPoint;
|
|
36
|
+
readonly bMaxOut: ccc.FixedPoint;
|
|
37
|
+
private constructor();
|
|
38
|
+
/** The order's matcher in one direction, or `undefined` when nothing gains in it. */
|
|
39
|
+
static from(group: OrderGroup, isCkb2Udt: boolean, ckbMiningFee: ccc.FixedPoint): OrderMatcher | undefined;
|
|
40
|
+
match(bAllowance: ccc.FixedPoint): Match;
|
|
41
|
+
create(aOut: ccc.FixedPoint, bOut: ccc.FixedPoint): Match;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=matcher.d.ts.map
|