@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
package/dist/sdk.d.ts
CHANGED
|
@@ -1,51 +1,123 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
import {
|
|
3
|
-
import { type
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
2
|
+
import type { AccountState, CompleteIckbTransactionOptions, ConversionTransactionContext, ConversionTransactionOptions, ConversionTransactionResult, SdkManagers, SystemState } from "./conversion/types.js";
|
|
3
|
+
import { type LockUpPolicy } from "./dao.js";
|
|
4
|
+
import type { IckbDepositCell } from "./logic.js";
|
|
5
|
+
import type { OrderGroup } from "./order/cells.js";
|
|
6
|
+
import type { SupportedChain } from "./utils/chain.js";
|
|
7
|
+
/**
|
|
8
|
+
* Input count up to which one own transaction sweeps liquid cells.
|
|
9
|
+
*
|
|
10
|
+
* @remarks A compaction target, not a validity bound: required funding and the fee may go
|
|
11
|
+
* past it. Counted rather than measured in bytes because a same-lock input costs a fixed
|
|
12
|
+
* 44 bytes (52 with an extra witness slot), so 1,000 inputs stay near 50 KB, far under the
|
|
13
|
+
* node's 512,000-byte limit, and near the one measured point (1,000 inputs: 44 KB, about
|
|
14
|
+
* 180 ms of local completion). A miner paying the bot adds about forty cellbase cells per
|
|
15
|
+
* turn, which this outpaces; a larger backlog takes several transactions.
|
|
16
|
+
*/
|
|
17
|
+
export declare const SWEEP_INPUT_LIMIT = 1000;
|
|
18
|
+
/** What every own transaction collects along: the context's collectable positions. */
|
|
19
|
+
type CollectSteps = Pick<ConversionTransactionContext, "availableOrders" | "receipts" | "readyWithdrawals">;
|
|
20
|
+
/**
|
|
21
|
+
* The whole SDK, which the Node actors drive by relative import; the package barrel
|
|
22
|
+
* exposes the two conversion-workflow methods, and its assignment checks they agree.
|
|
23
|
+
*/
|
|
6
24
|
export declare class IckbSdk {
|
|
25
|
+
private readonly ickbUdt;
|
|
7
26
|
private readonly ownedOwner;
|
|
8
27
|
private readonly ickbLogic;
|
|
9
28
|
private readonly order;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
info: Info;
|
|
25
|
-
amounts: ValueComponents;
|
|
26
|
-
}, system: SystemState): bigint | undefined;
|
|
27
|
-
request(tx: SmartTransaction, user: ccc.Signer | ccc.Script, info: Info, amounts: ValueComponents): Promise<void>;
|
|
28
|
-
collect(tx: SmartTransaction, groups: OrderGroup[], options?: {
|
|
29
|
-
isFulfilledOnly?: boolean;
|
|
30
|
-
}): void;
|
|
31
|
-
getL1State(client: ccc.Client, locks: ccc.Script[]): Promise<{
|
|
29
|
+
constructor({ ickbUdt, ownedOwner, ickbLogic, order }: SdkManagers);
|
|
30
|
+
/** Creates the SDK for one chain's deployment. */
|
|
31
|
+
static fromChain(chain: SupportedChain): IckbSdk;
|
|
32
|
+
/**
|
|
33
|
+
* Reads system, user-order, and account state at the sampled tip's parent, under the
|
|
34
|
+
* caller's withdrawal timing rules (`BOT_LOCK_UP` or `WALLET_LOCK_UP`) and, when given, a
|
|
35
|
+
* positive fee rate cap that replaces CCC's ceiling; a cap of zero or less throws.
|
|
36
|
+
*
|
|
37
|
+
* @remarks Every read goes through `verifiedClient` and the tip's parent is bounded by the
|
|
38
|
+
* policy's slack, so a caller passes a plain client. Every read is complete and uncapped: a large
|
|
39
|
+
* book or pool costs a slower read, never a partial or failed one. Each account lock is
|
|
40
|
+
* enumerated by one uncached unfiltered exact-lock scan and classified client-side.
|
|
41
|
+
*/
|
|
42
|
+
getL1AccountState(plainClient: ccc.Client, locks: ccc.Script[], lockUp: LockUpPolicy, maxFeeRate?: ccc.NumLike): Promise<{
|
|
32
43
|
system: SystemState;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
44
|
+
userOrders: OrderGroup[];
|
|
45
|
+
account: AccountState;
|
|
36
46
|
}>;
|
|
37
|
-
|
|
47
|
+
/** Every Stack cell one lock owns, classified from a single exact-lock scan. */
|
|
48
|
+
private readLockCells;
|
|
49
|
+
/**
|
|
50
|
+
* Builds and completes one conversion transaction from a conversion context.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* Every branch returns a transaction funded from the signer's committed cells: the
|
|
54
|
+
* candidate plans (deposit counts, or prefixes of the greedy withdrawal selection with
|
|
55
|
+
* their rebuilt remainder order) are completed most direct first and the first fundable one
|
|
56
|
+
* wins, so a wallet short of CKB degrades to fewer direct actions plus a larger standing
|
|
57
|
+
* order rather than failing. Failure results are
|
|
58
|
+
* expected planning outcomes; when no plan can be funded the last completion error throws.
|
|
59
|
+
*/
|
|
60
|
+
buildConversionTransaction(options: ConversionTransactionOptions): Promise<ConversionTransactionResult>;
|
|
61
|
+
private buildCollectOnlyConversion;
|
|
62
|
+
private buildCkbToIckbConversion;
|
|
63
|
+
private buildIckbToCkbConversion;
|
|
64
|
+
private completeConversion;
|
|
65
|
+
/**
|
|
66
|
+
* Adds the context's collect steps to a partial transaction: the withdrawal requests when
|
|
67
|
+
* given, then the collectable orders, the receipts, and the ready withdrawals.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* The result is still partial. Callers should use `completeTransaction` before
|
|
71
|
+
* signing and sending. The withdrawals move their deposit headers to the front of
|
|
72
|
+
* `headerDeps`, so the given transaction must not reference a header by position.
|
|
73
|
+
*/
|
|
74
|
+
buildBaseTransaction(txLike: ccc.TransactionLike, steps: CollectSteps, withdrawalRequest?: {
|
|
75
|
+
deposits: IckbDepositCell[];
|
|
76
|
+
lock: ccc.Script;
|
|
77
|
+
}): ccc.Transaction;
|
|
78
|
+
/**
|
|
79
|
+
* Completes iCKB inputs, iCKB change, plain change, and the fee from the cells it is given.
|
|
80
|
+
*
|
|
81
|
+
* @remarks Completion never scans. `cells` are the signer's known liquid cells, plain
|
|
82
|
+
* CKB and iCKB, from the account state already read: the largest ones fund what the
|
|
83
|
+
* outputs need, the rest ride along as a sweep while the transaction has fewer than
|
|
84
|
+
* {@link SWEEP_INPUT_LIMIT} inputs, so every own transaction compacts the account.
|
|
85
|
+
* Ordinary change is always a plain cell; existing outputs
|
|
86
|
+
* are never reinterpreted or resized as fee change. This does not sign or send.
|
|
87
|
+
*/
|
|
88
|
+
completeTransaction(txLike: ccc.TransactionLike, options: CompleteIckbTransactionOptions): Promise<ccc.Transaction>;
|
|
89
|
+
/** iCKB: what the outputs need first, then the sweep while the limit allows, then change. */
|
|
90
|
+
private completeIckb;
|
|
38
91
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
maturity: ccc.Num;
|
|
92
|
+
/** Stable machine-readable SDK failures. */
|
|
93
|
+
export type IckbErrorCode = "insufficient_capacity" | "insufficient_ickb";
|
|
94
|
+
/** Typed SDK failure with a stable machine-readable code. */
|
|
95
|
+
export declare class IckbError extends Error {
|
|
96
|
+
/** Stable failure code for callers and observability. */
|
|
97
|
+
readonly code: IckbErrorCode;
|
|
98
|
+
/** Creates a typed SDK failure while preserving its cause. */
|
|
99
|
+
constructor(message: string, options: ErrorOptions & {
|
|
100
|
+
code: IckbErrorCode;
|
|
101
|
+
});
|
|
50
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Completes the first candidate that the real completer can fund.
|
|
105
|
+
*
|
|
106
|
+
* @remarks
|
|
107
|
+
* Only completion knows what a transaction costs once markers, remainder orders, change, and
|
|
108
|
+
* fee are in, so no count is computed up front: each candidate is built and completed in turn.
|
|
109
|
+
* Capacity, DAO output-limit and DAO header-index failures advance
|
|
110
|
+
* the walk; transport, scan, signer, and malformed-transaction errors propagate. Exhausting
|
|
111
|
+
* the candidates throws the last advancing failure.
|
|
112
|
+
*/
|
|
113
|
+
export declare function completeFirstFundable<T>(candidates: Iterable<T>, build: (candidate: T) => ccc.Transaction, complete: (tx: ccc.Transaction) => Promise<ccc.Transaction>): Promise<{
|
|
114
|
+
candidate: T;
|
|
115
|
+
tx: ccc.Transaction;
|
|
116
|
+
}>;
|
|
117
|
+
/**
|
|
118
|
+
* A failure the walk advances past: the candidate costs more than the account funds, or
|
|
119
|
+
* needs more DAO outputs or deposit-header slots than one transaction has.
|
|
120
|
+
*/
|
|
121
|
+
export declare function isFundabilityFailure(error: unknown): error is Error;
|
|
122
|
+
export {};
|
|
51
123
|
//# sourceMappingURL=sdk.d.ts.map
|
package/dist/sdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.d.ts","sourceRoot":"
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAOpC,OAAO,KAAK,EACV,YAAY,EACZ,8BAA8B,EAC9B,4BAA4B,EAE5B,4BAA4B,EAC5B,2BAA2B,EAC3B,WAAW,EACX,WAAW,EACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAML,KAAK,YAAY,EAGlB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,eAAe,EAAgB,MAAM,YAAY,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAKnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIvD;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