@ickb/sdk 9000.0.1 → 9001.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -11
- package/dist/constants.d.ts +0 -4
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +6 -24
- package/dist/constants.js.map +1 -1
- package/dist/conversion/estimate.d.ts +0 -6
- package/dist/conversion/estimate.d.ts.map +1 -1
- package/dist/conversion/estimate.js +1 -1
- package/dist/conversion/estimate.js.map +1 -1
- package/dist/conversion/maturity.d.ts +1 -1
- package/dist/conversion/maturity.js +13 -12
- package/dist/conversion/maturity.js.map +1 -1
- package/dist/conversion/plans.d.ts.map +1 -1
- package/dist/conversion/plans.js +6 -6
- package/dist/conversion/plans.js.map +1 -1
- package/dist/conversion/projection.d.ts +5 -6
- package/dist/conversion/projection.d.ts.map +1 -1
- package/dist/conversion/projection.js +11 -8
- package/dist/conversion/projection.js.map +1 -1
- package/dist/conversion/types.d.ts +29 -17
- package/dist/conversion/types.d.ts.map +1 -1
- package/dist/conversion/withdrawal_ring.d.ts +1 -3
- package/dist/conversion/withdrawal_ring.d.ts.map +1 -1
- package/dist/conversion/withdrawal_ring.js +4 -4
- package/dist/conversion/withdrawal_ring.js.map +1 -1
- package/dist/dao.d.ts +19 -5
- package/dist/dao.d.ts.map +1 -1
- package/dist/dao.js +24 -12
- package/dist/dao.js.map +1 -1
- package/dist/index.d.ts +9 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/logic.d.ts +10 -14
- package/dist/logic.d.ts.map +1 -1
- package/dist/logic.js +28 -39
- package/dist/logic.js.map +1 -1
- package/dist/order/cells.d.ts +10 -49
- package/dist/order/cells.d.ts.map +1 -1
- package/dist/order/cells.js +28 -146
- package/dist/order/cells.js.map +1 -1
- package/dist/order/conversion.d.ts +3 -9
- package/dist/order/conversion.d.ts.map +1 -1
- package/dist/order/conversion.js +8 -11
- package/dist/order/conversion.js.map +1 -1
- package/dist/order/fill.d.ts +2 -2
- package/dist/order/fill.js +3 -3
- package/dist/order/fill.js.map +1 -1
- package/dist/order/info.d.ts.map +1 -1
- package/dist/order/info.js +3 -0
- package/dist/order/info.js.map +1 -1
- package/dist/order/matcher.d.ts +1 -1
- package/dist/order/matcher.d.ts.map +1 -1
- package/dist/order/matcher.js +3 -2
- package/dist/order/matcher.js.map +1 -1
- package/dist/order/order.d.ts +6 -2
- package/dist/order/order.d.ts.map +1 -1
- package/dist/order/order.js +32 -37
- package/dist/order/order.js.map +1 -1
- package/dist/order/order_data.d.ts.map +1 -1
- package/dist/order/order_data.js +3 -0
- package/dist/order/order_data.js.map +1 -1
- package/dist/order/ratio.d.ts +0 -2
- package/dist/order/ratio.d.ts.map +1 -1
- package/dist/order/ratio.js +3 -11
- package/dist/order/ratio.js.map +1 -1
- package/dist/order/relative.d.ts.map +1 -1
- package/dist/order/relative.js +3 -0
- package/dist/order/relative.js.map +1 -1
- package/dist/owned_owner.d.ts +10 -15
- package/dist/owned_owner.d.ts.map +1 -1
- package/dist/owned_owner.js +27 -47
- package/dist/owned_owner.js.map +1 -1
- package/dist/sdk.d.ts +74 -31
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +81 -59
- package/dist/sdk.js.map +1 -1
- package/dist/send/sign_and_send_transaction.d.ts +32 -17
- package/dist/send/sign_and_send_transaction.d.ts.map +1 -1
- package/dist/send/sign_and_send_transaction.js +128 -28
- package/dist/send/sign_and_send_transaction.js.map +1 -1
- package/dist/send/wait_transaction.d.ts +7 -6
- package/dist/send/wait_transaction.d.ts.map +1 -1
- package/dist/send/wait_transaction.js +29 -61
- package/dist/send/wait_transaction.js.map +1 -1
- package/dist/udt.d.ts +20 -35
- package/dist/udt.d.ts.map +1 -1
- package/dist/udt.js +39 -103
- package/dist/udt.js.map +1 -1
- package/dist/utils/chain.d.ts +0 -35
- package/dist/utils/chain.d.ts.map +1 -1
- package/dist/utils/chain.js +1 -19
- package/dist/utils/chain.js.map +1 -1
- package/dist/utils/codec.d.ts.map +1 -1
- package/dist/utils/codec.js +3 -0
- package/dist/utils/codec.js.map +1 -1
- package/dist/utils/utils.d.ts +19 -46
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +53 -74
- package/dist/utils/utils.js.map +1 -1
- 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 +2 -2
- package/src/constants.ts +6 -25
- package/src/conversion/estimate.ts +1 -3
- package/src/conversion/maturity.ts +13 -14
- package/src/conversion/plans.ts +6 -6
- package/src/conversion/projection.ts +15 -7
- package/src/conversion/types.ts +32 -17
- package/src/conversion/withdrawal_ring.ts +4 -8
- package/src/dao.ts +38 -14
- package/src/index.ts +8 -8
- package/src/logic.ts +40 -52
- package/src/order/cells.ts +37 -174
- package/src/order/conversion.ts +8 -19
- package/src/order/fill.ts +3 -3
- package/src/order/info.ts +3 -0
- package/src/order/matcher.ts +3 -3
- package/src/order/order.ts +38 -52
- package/src/order/order_data.ts +3 -0
- package/src/order/ratio.ts +3 -20
- package/src/order/relative.ts +3 -0
- package/src/owned_owner.ts +47 -77
- package/src/sdk.ts +95 -108
- package/src/send/sign_and_send_transaction.ts +164 -28
- package/src/send/wait_transaction.ts +44 -88
- package/src/udt.ts +56 -124
- package/src/utils/chain.ts +0 -41
- package/src/utils/codec.ts +4 -0
- package/src/utils/utils.ts +76 -105
- package/src/utils/verified_client.ts +136 -0
- package/dist/utils/transaction_header.d.ts +0 -17
- package/dist/utils/transaction_header.d.ts.map +0 -1
- package/dist/utils/transaction_header.js +0 -44
- package/dist/utils/transaction_header.js.map +0 -1
- package/src/utils/transaction_header.ts +0 -66
package/dist/utils/chain.js
CHANGED
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export const chainIdentities = Object.freeze({
|
|
3
|
-
mainnet: Object.freeze({
|
|
4
|
-
chain: "mainnet",
|
|
5
|
-
networkName: "ckb",
|
|
6
|
-
genesisHash: "0x92b197aa1fba0f63633922c61c92375c9c074a93e85963554f5499fe1450d0e5",
|
|
7
|
-
genesisMessage: "lina 0x18e020f6b1237a3d06b75121f25a7efa0550e4b3f44f974822f471902424c104",
|
|
8
|
-
genesisSource: "https://raw.githubusercontent.com/nervosnetwork/ckb/develop/resource/specs/mainnet.toml",
|
|
9
|
-
addressPrefix: "ckb",
|
|
10
|
-
}),
|
|
11
|
-
testnet: Object.freeze({
|
|
12
|
-
chain: "testnet",
|
|
13
|
-
networkName: "ckb_testnet",
|
|
14
|
-
genesisHash: "0x10639e0895502b5688a6be8cf69460d76541bfa4821629d86d62ba0aae3f9606",
|
|
15
|
-
genesisMessage: "aggron-v4",
|
|
16
|
-
genesisSource: "https://raw.githubusercontent.com/nervosnetwork/ckb/develop/resource/specs/testnet.toml",
|
|
17
|
-
addressPrefix: "ckt",
|
|
18
|
-
}),
|
|
19
|
-
});
|
|
1
|
+
export {};
|
|
20
2
|
//# sourceMappingURL=chain.js.map
|
package/dist/utils/chain.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chain.js","sourceRoot":"","sources":["../../src/utils/chain.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"chain.js","sourceRoot":"","sources":["../../src/utils/chain.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/utils/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,qCAmBzB,CAAC;
|
|
1
|
+
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/utils/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,qCAmBzB,CAAC;AAMH,iDAAiD;AACjD,eAAO,MAAM,YAAY,qCAAmB,CAAC;AAE7C,gEAAgE;AAChE,eAAO,MAAM,eAAe,qCAAmB,CAAC;AAEhD,gEAAgE;AAChE,eAAO,MAAM,eAAe,qCAAmB,CAAC;AAEhD,iEAAiE;AACjE,eAAO,MAAM,gBAAgB,qCAAoB,CAAC"}
|
package/dist/utils/codec.js
CHANGED
|
@@ -24,6 +24,9 @@ export const CheckedInt32LE = ccc.Codec.from({
|
|
|
24
24
|
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getInt32(0, true);
|
|
25
25
|
},
|
|
26
26
|
});
|
|
27
|
+
// CCC's unsigned codecs throw on overflow but encode a negative as its two's complement
|
|
28
|
+
// without a word, and `Ratio.toBytes()` is public and skips `validate`, so these checked
|
|
29
|
+
// codecs keep "never encode a negative" in one place; CCC has no signed Int32 codec at all.
|
|
27
30
|
/** Checked codec for 8-bit unsigned integers. */
|
|
28
31
|
export const CheckedUint8 = checkedUintLE(1);
|
|
29
32
|
/** Checked codec for little-endian 32-bit unsigned integers. */
|
package/dist/utils/codec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../src/utils/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAsB;IAChE,UAAU,EAAE,CAAC;IACb,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE;QAClB,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAC7C,IAAI,UAAU,GAAG,CAAC,WAAW,IAAI,UAAU,GAAG,WAAW,EAAE,CAAC;YAC1D,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,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C,IAAI,CAAC;QACpB,UAAU;QACV,MAAM,EAAE,CAAC,OAAoB,EAAE,EAAE;YAC/B,MAAM,GAAG,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;YACtC,IAAI,GAAG,GAAG,EAAE,IAAI,GAAG,GAAG,GAAG,EAAE,CAAC;gBAC1B,MAAM,IAAI,KAAK,CAAC,sBAAsB,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;YACpE,CAAC;YACD,OAAO,GAAG,CAAC,YAAY,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAC3C,CAAC;QACD,MAAM,EAAE,GAAG,CAAC,YAAY;KACzB,CAAC,CAAC;AACL,CAAC;AAED,SAAS,gBAAgB,CAAC,OAAoB;IAC5C,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;YAC5D,MAAM,IAAI,SAAS,CAAC,kCAAkC,CAAC,CAAC;QAC1D,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,SAAS,CAAC,uCAAuC,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;IACD,IAAI,CAAC;QACH,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,SAAS,CAAC,kCAAkC,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC"}
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -7,28 +7,25 @@ import { ccc } from "@ckb-ccc/core";
|
|
|
7
7
|
*/
|
|
8
8
|
export declare const defaultCellPageSize = 400;
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
* CCC's
|
|
12
|
-
*
|
|
13
|
-
* @remarks A full page must advance the cursor; otherwise the read throws so a faulty
|
|
14
|
-
* endpoint in the app's public node pool cannot keep the scan looping forever.
|
|
15
|
-
* The cursor continues ordering, not a coherent snapshot. There is no aggregate budget:
|
|
16
|
-
* a large book costs a slower read rather than a partial result.
|
|
10
|
+
* A CCC client cache sized for a whole pool: 4096 headers and 4096 transaction bodies,
|
|
11
|
+
* where CCC's defaults keep 128 and 256 (SDK README, Account state). An LRU fills only as
|
|
12
|
+
* far as the book and pool need.
|
|
17
13
|
*/
|
|
18
|
-
export declare function
|
|
14
|
+
export declare function clientCache(): ccc.ClientCacheMemory;
|
|
15
|
+
/** A committed cell and the block the node names for its creating transaction. */
|
|
16
|
+
export interface ScannedCell {
|
|
17
|
+
cell: ccc.Cell;
|
|
18
|
+
blockNumber: ccc.Num;
|
|
19
|
+
}
|
|
19
20
|
/**
|
|
20
|
-
*
|
|
21
|
+
* Reads every committed cell matching the key with the block the node names for it, page
|
|
22
|
+
* by page through the raw requestor (CCC's typed scan drops the block), bypassing CCC's
|
|
23
|
+
* cell cache. A full page whose cursor does not advance throws. Why: SDK README, Account
|
|
24
|
+
* state.
|
|
21
25
|
*/
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*/
|
|
26
|
-
header: ccc.ClientBlockHeader;
|
|
27
|
-
/**
|
|
28
|
-
* The transaction hash when the caller has resolved it for the header.
|
|
29
|
-
*/
|
|
30
|
-
txHash?: ccc.Hex;
|
|
31
|
-
}
|
|
26
|
+
export declare function findCells(client: ccc.Client, keyLike: ccc.ClientIndexerSearchKeyLike): Promise<ScannedCell[]>;
|
|
27
|
+
/** The headers of a batch of block numbers, each read once; every block must exist. */
|
|
28
|
+
export declare function headersByNumber(client: ccc.Client, blockNumbers: Iterable<ccc.Num>): Promise<Map<ccc.Num, ccc.ClientBlockHeader>>;
|
|
32
29
|
/**
|
|
33
30
|
* CKB and UDT amounts carried by a cell, order, or planned value.
|
|
34
31
|
*/
|
|
@@ -73,36 +70,12 @@ export interface ScriptDeps {
|
|
|
73
70
|
*/
|
|
74
71
|
export declare function isPlainCapacityCell(cell: ccc.Cell): boolean;
|
|
75
72
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* [0, n), if `f(i)` is true, then `f(i+1)` is also true. This means that there
|
|
79
|
-
* is a prefix of the input range where `f` is false, followed by a suffix where
|
|
80
|
-
* `f` is true. If no such index exists, the function returns `n`.
|
|
81
|
-
*
|
|
82
|
-
* The function `f` is only called for indices in the range [0, n).
|
|
83
|
-
*
|
|
84
|
-
* @param n - The non-negative integer upper bound of the search range (exclusive).
|
|
85
|
-
* @param f - An async function that takes an index `i` and returns a boolean value.
|
|
86
|
-
* @returns The smallest index `i` such that `f(i)` is true, or `n` if no such index exists.
|
|
87
|
-
*
|
|
88
|
-
* @remarks Adapted from Go's standard library search implementation:
|
|
89
|
-
* {@link https://go.dev/src/sort/search.go}
|
|
90
|
-
*/
|
|
91
|
-
export declare function asyncBinarySearch(n: number, f: (i: number) => Promise<boolean>): Promise<number>;
|
|
92
|
-
/**
|
|
93
|
-
* The client's JSON-RPC requestor, when it has one. The connector hands the interface a
|
|
73
|
+
* The client's JSON-RPC requestor, which the SDK's raw reads need: scans with block
|
|
74
|
+
* numbers, status polls and transaction proofs. The connector hands the interface a
|
|
94
75
|
* composition proxy over the public client (`ClientWithFeeRate`, a `ccc.Client` but not a
|
|
95
76
|
* `ccc.ClientJsonRpc`), so `instanceof` misses it; the proxy forwards the property.
|
|
96
77
|
*/
|
|
97
|
-
export declare function jsonRpcRequestor(client: ccc.Client): ccc.RequestorJsonRpc
|
|
98
|
-
/** A node's raw `get_transaction` status record (verbosity 1), the fields the stack reads. */
|
|
99
|
-
export declare function rawTransactionStatus(response: unknown): {
|
|
100
|
-
status: string | undefined;
|
|
101
|
-
reason: string | undefined;
|
|
102
|
-
blockNumber: ccc.Num | undefined;
|
|
103
|
-
};
|
|
104
|
-
export declare function minBigInt(left: bigint, right: bigint): bigint;
|
|
105
|
-
export declare function maxBigInt(left: bigint, right: bigint): bigint;
|
|
78
|
+
export declare function jsonRpcRequestor(client: ccc.Client): ccc.RequestorJsonRpc;
|
|
106
79
|
/** `numerator / denominator` rounded up; the denominator is positive. */
|
|
107
80
|
export declare function ceilDiv(numerator: bigint, denominator: bigint): bigint;
|
|
108
81
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC;;;;GAIG;AACH,wBAAgB,WAAW,IAAI,GAAG,CAAC,iBAAiB,CAEnD;AAED,kFAAkF;AAClF,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC;IACf,WAAW,EAAE,GAAG,CAAC,GAAG,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAsB,SAAS,CAC7B,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,OAAO,EAAE,GAAG,CAAC,0BAA0B,GACtC,OAAO,CAAC,WAAW,EAAE,CAAC,CA+BxB;AAED,uFAAuF;AACvF,wBAAsB,eAAe,CACnC,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,GAC9B,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAc9C;AAaD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,6CAA6C;IAC7C,QAAQ,EAAE,GAAG,CAAC,UAAU,CAAC;IAEzB,6CAA6C;IAC7C,QAAQ,EAAE,GAAG,CAAC,UAAU,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,2CAA2C;IAC3C,QAAQ,EAAE,GAAG,CAAC,GAAG,CAAC;IAElB,2CAA2C;IAC3C,QAAQ,EAAE,GAAG,CAAC,GAAG,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;IAEnB;;OAEG;IACH,QAAQ,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;CACzB;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,GAAG,OAAO,CAE3D;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,gBAAgB,CAMzE;AAED,yEAAyE;AACzE,wBAAgB,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAUjE;AAED;;;;;;;;;;GAUG;AACH,wBAAiB,MAAM,CAAC,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAS9E"}
|
package/dist/utils/utils.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { cccA } from "@ckb-ccc/core/advanced";
|
|
2
3
|
/**
|
|
3
4
|
* The default page size used when querying cells from the chain.
|
|
4
5
|
*
|
|
@@ -7,30 +8,63 @@ import { ccc } from "@ckb-ccc/core";
|
|
|
7
8
|
*/
|
|
8
9
|
export const defaultCellPageSize = 400;
|
|
9
10
|
/**
|
|
10
|
-
*
|
|
11
|
-
* CCC's
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
* A CCC client cache sized for a whole pool: 4096 headers and 4096 transaction bodies,
|
|
12
|
+
* where CCC's defaults keep 128 and 256 (SDK README, Account state). An LRU fills only as
|
|
13
|
+
* far as the book and pool need.
|
|
14
|
+
*/
|
|
15
|
+
export function clientCache() {
|
|
16
|
+
return new ccc.ClientCacheMemory(512, 4096, 4096);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Reads every committed cell matching the key with the block the node names for it, page
|
|
20
|
+
* by page through the raw requestor (CCC's typed scan drops the block), bypassing CCC's
|
|
21
|
+
* cell cache. A full page whose cursor does not advance throws. Why: SDK README, Account
|
|
22
|
+
* state.
|
|
17
23
|
*/
|
|
18
24
|
export async function findCells(client, keyLike) {
|
|
19
|
-
const
|
|
25
|
+
const requestor = jsonRpcRequestor(client);
|
|
26
|
+
const key = cccA.JsonRpcTransformers.indexerSearchKeyFrom(keyLike);
|
|
20
27
|
const cells = [];
|
|
21
28
|
let after;
|
|
22
29
|
for (;;) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion, no-restricted-syntax -- the node's indexer answer, parsed field by field below as CCC's own transformer does.
|
|
31
|
+
const page = (await requestor.request("get_cells", [
|
|
32
|
+
key,
|
|
33
|
+
"asc",
|
|
34
|
+
ccc.numToHex(defaultCellPageSize),
|
|
35
|
+
after,
|
|
36
|
+
]));
|
|
37
|
+
for (const object of page.objects) {
|
|
38
|
+
cells.push({
|
|
39
|
+
cell: ccc.Cell.from({
|
|
40
|
+
outPoint: cccA.JsonRpcTransformers.outPointTo(object.out_point),
|
|
41
|
+
cellOutput: cccA.JsonRpcTransformers.cellOutputTo(object.output),
|
|
42
|
+
outputData: object.output_data ?? "0x",
|
|
43
|
+
}),
|
|
44
|
+
blockNumber: ccc.numFrom(object.block_number),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (page.objects.length < defaultCellPageSize) {
|
|
26
48
|
return cells;
|
|
27
49
|
}
|
|
28
|
-
if (page.
|
|
50
|
+
if (page.last_cursor === after) {
|
|
29
51
|
throw new Error("Cell scan cursor did not advance");
|
|
30
52
|
}
|
|
31
|
-
after = page.
|
|
53
|
+
after = page.last_cursor;
|
|
32
54
|
}
|
|
33
55
|
}
|
|
56
|
+
/** The headers of a batch of block numbers, each read once; every block must exist. */
|
|
57
|
+
export async function headersByNumber(client, blockNumbers) {
|
|
58
|
+
const distinct = [...new Set(blockNumbers)];
|
|
59
|
+
const headers = await Promise.all(distinct.map(async (blockNumber) => client.getHeaderByNumber(blockNumber)));
|
|
60
|
+
return new Map(distinct.map((blockNumber, index) => {
|
|
61
|
+
const header = headers[index];
|
|
62
|
+
if (header === undefined) {
|
|
63
|
+
throw new Error(`Header not found for block number ${String(blockNumber)}`);
|
|
64
|
+
}
|
|
65
|
+
return [blockNumber, header];
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
34
68
|
/**
|
|
35
69
|
* True when a cell has no type script and no data payload.
|
|
36
70
|
*
|
|
@@ -42,72 +76,17 @@ export function isPlainCapacityCell(cell) {
|
|
|
42
76
|
return cell.cellOutput.type === undefined && cell.outputData === "0x";
|
|
43
77
|
}
|
|
44
78
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* [0, n), if `f(i)` is true, then `f(i+1)` is also true. This means that there
|
|
48
|
-
* is a prefix of the input range where `f` is false, followed by a suffix where
|
|
49
|
-
* `f` is true. If no such index exists, the function returns `n`.
|
|
50
|
-
*
|
|
51
|
-
* The function `f` is only called for indices in the range [0, n).
|
|
52
|
-
*
|
|
53
|
-
* @param n - The non-negative integer upper bound of the search range (exclusive).
|
|
54
|
-
* @param f - An async function that takes an index `i` and returns a boolean value.
|
|
55
|
-
* @returns The smallest index `i` such that `f(i)` is true, or `n` if no such index exists.
|
|
56
|
-
*
|
|
57
|
-
* @remarks Adapted from Go's standard library search implementation:
|
|
58
|
-
* {@link https://go.dev/src/sort/search.go}
|
|
59
|
-
*/
|
|
60
|
-
export async function asyncBinarySearch(n, f) {
|
|
61
|
-
// Define f(-1) == false and f(n) == true.
|
|
62
|
-
// Invariant: f(i-1) == false, f(j) == true.
|
|
63
|
-
let [i, j] = [0, n];
|
|
64
|
-
while (i < j) {
|
|
65
|
-
const h = Math.trunc((i + j) / 2);
|
|
66
|
-
// i ≤ h < j
|
|
67
|
-
if (!(await f(h))) {
|
|
68
|
-
i = h + 1; // preserves f(i-1) == false
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
j = h; // preserves f(j) == true
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// i == j, f(i-1) == false, and f(j) (= f(i)) == true => answer is i.
|
|
75
|
-
return i;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* The client's JSON-RPC requestor, when it has one. The connector hands the interface a
|
|
79
|
+
* The client's JSON-RPC requestor, which the SDK's raw reads need: scans with block
|
|
80
|
+
* numbers, status polls and transaction proofs. The connector hands the interface a
|
|
79
81
|
* composition proxy over the public client (`ClientWithFeeRate`, a `ccc.Client` but not a
|
|
80
82
|
* `ccc.ClientJsonRpc`), so `instanceof` misses it; the proxy forwards the property.
|
|
81
83
|
*/
|
|
82
84
|
export function jsonRpcRequestor(client) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
const requestor = "requestor" in client ? client.requestor : undefined;
|
|
86
|
+
if (!(requestor instanceof ccc.RequestorJsonRpc)) {
|
|
87
|
+
throw new TypeError("The SDK needs a JSON-RPC client");
|
|
85
88
|
}
|
|
86
|
-
|
|
87
|
-
return requestor instanceof ccc.RequestorJsonRpc ? requestor : undefined;
|
|
88
|
-
}
|
|
89
|
-
/** A node's raw `get_transaction` status record (verbosity 1), the fields the stack reads. */
|
|
90
|
-
export function rawTransactionStatus(response) {
|
|
91
|
-
const record = typeof response === "object" &&
|
|
92
|
-
response !== null &&
|
|
93
|
-
"tx_status" in response &&
|
|
94
|
-
typeof response.tx_status === "object" &&
|
|
95
|
-
response.tx_status !== null
|
|
96
|
-
? response.tx_status
|
|
97
|
-
: {};
|
|
98
|
-
return {
|
|
99
|
-
status: "status" in record && typeof record.status === "string" ? record.status : undefined,
|
|
100
|
-
reason: "reason" in record && typeof record.reason === "string" ? record.reason : undefined,
|
|
101
|
-
blockNumber: "block_number" in record && typeof record.block_number === "string"
|
|
102
|
-
? ccc.numFrom(record.block_number)
|
|
103
|
-
: undefined,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
export function minBigInt(left, right) {
|
|
107
|
-
return left < right ? left : right;
|
|
108
|
-
}
|
|
109
|
-
export function maxBigInt(left, right) {
|
|
110
|
-
return left > right ? left : right;
|
|
89
|
+
return requestor;
|
|
111
90
|
}
|
|
112
91
|
/** `numerator / denominator` rounded up; the denominator is positive. */
|
|
113
92
|
export function ceilDiv(numerator, denominator) {
|
package/dist/utils/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEvC;;;;GAIG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,IAAI,GAAG,CAAC,iBAAiB,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACpD,CAAC;AAQD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,MAAkB,E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SAAS,GAAG,WAAW,GAAG,EAAE,CAAC,GAAG,WAAW,CAAC;AACtD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,KAAa;IACvD,IAAI,IAAI,GAAG,KAAK,EAAE,CAAC;QACjB,OAAO,CAAC,CAAC,CAAC;IACZ,CAAC;IAED,IAAI,IAAI,GAAG,KAAK,EAAE,CAAC;QACjB,OAAO,CAAC,CAAC;IACX,CAAC;IAED,OAAO,CAAC,CAAC;AACX,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,SAAS,CAAC,CAAC,MAAM,CAAuB,KAAkB;IAC9D,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9B,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACb,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
/**
|
|
3
|
+
* Wraps `inner` into a client that checks the reads the SDK makes: every header it hands
|
|
4
|
+
* out against the header's own hash, a header read by number against the number asked
|
|
5
|
+
* for, a transaction read by hash against the hash of its body, and a cell against the
|
|
6
|
+
* body of its creating transaction. Other reads pass through unchecked; the cell
|
|
7
|
+
* beside `getCellWithHeader`'s header is one, since the SDK reads only its header.
|
|
8
|
+
*
|
|
9
|
+
* @remarks It wraps the client, not the SDK's readers, because CCC's own DAO valuation
|
|
10
|
+
* (`Cell.getNervosDaoInfo`, in the send) reads headers through the client it is given.
|
|
11
|
+
* Why each check exists: SDK README, Account state.
|
|
12
|
+
*/
|
|
13
|
+
export declare function verifiedClient(inner: ccc.Client): ccc.Client;
|
|
14
|
+
/**
|
|
15
|
+
* The hash of a header as the chain computes it: blake2b over the header struct, each
|
|
16
|
+
* number little-endian, in declaration order, the nonce last.
|
|
17
|
+
*/
|
|
18
|
+
export declare function headerHash(header: ccc.ClientBlockHeader): ccc.Hex;
|
|
19
|
+
//# sourceMappingURL=verified_client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verified_client.d.ts","sourceRoot":"","sources":["../../src/utils/verified_client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAE5D;AAqGD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,iBAAiB,GAAG,GAAG,CAAC,GAAG,CAejE"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
/**
|
|
3
|
+
* Wraps `inner` into a client that checks the reads the SDK makes: every header it hands
|
|
4
|
+
* out against the header's own hash, a header read by number against the number asked
|
|
5
|
+
* for, a transaction read by hash against the hash of its body, and a cell against the
|
|
6
|
+
* body of its creating transaction. Other reads pass through unchecked; the cell
|
|
7
|
+
* beside `getCellWithHeader`'s header is one, since the SDK reads only its header.
|
|
8
|
+
*
|
|
9
|
+
* @remarks It wraps the client, not the SDK's readers, because CCC's own DAO valuation
|
|
10
|
+
* (`Cell.getNervosDaoInfo`, in the send) reads headers through the client it is given.
|
|
11
|
+
* Why each check exists: SDK README, Account state.
|
|
12
|
+
*/
|
|
13
|
+
export function verifiedClient(inner) {
|
|
14
|
+
return new VerifiedClient(inner);
|
|
15
|
+
}
|
|
16
|
+
// @ts-expect-error TS2655: the abstract members are forwarded by the proxy at runtime, as in CCC's own connector.
|
|
17
|
+
class VerifiedClient extends ccc.Proxy.Base(ccc.Client) {
|
|
18
|
+
static [ccc.Proxy.localKeys] = ["bodies"];
|
|
19
|
+
/** Creating transactions `getCell` read, so concurrent reads of one share a request. */
|
|
20
|
+
bodies = new Map();
|
|
21
|
+
async getTipHeader() {
|
|
22
|
+
return verified(await this[ccc.Proxy.inner].getTipHeader());
|
|
23
|
+
}
|
|
24
|
+
async getHeaderByNumber(...args) {
|
|
25
|
+
const header = ccc.apply(verified, await this[ccc.Proxy.inner].getHeaderByNumber(...args));
|
|
26
|
+
const number = ccc.numFrom(args[0]);
|
|
27
|
+
if (header !== undefined && header.number !== number) {
|
|
28
|
+
throw new Error(`Header ${header.hash} answers for block ${number.toString()}`);
|
|
29
|
+
}
|
|
30
|
+
return header;
|
|
31
|
+
}
|
|
32
|
+
async getTransaction(...args) {
|
|
33
|
+
return verifiedBody(await this[ccc.Proxy.inner].getTransaction(...args), args[0]);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The output of the verified creating transaction, cache first: CCC keys cached
|
|
37
|
+
* transactions by their body's hash, and its own `getCell` would build the cell from a
|
|
38
|
+
* read this wrapper never sees, then cache it.
|
|
39
|
+
*/
|
|
40
|
+
async getCell(...args) {
|
|
41
|
+
const outPoint = ccc.OutPoint.from(args[0]);
|
|
42
|
+
const { txHash } = outPoint;
|
|
43
|
+
let body = this.bodies.get(txHash);
|
|
44
|
+
if (body === undefined) {
|
|
45
|
+
body = this.readBody(txHash);
|
|
46
|
+
this.bodies.set(txHash, body);
|
|
47
|
+
}
|
|
48
|
+
const output = (await body)?.transaction.getOutput(outPoint.index);
|
|
49
|
+
return output === undefined
|
|
50
|
+
? undefined
|
|
51
|
+
: ccc.Cell.from({
|
|
52
|
+
outPoint,
|
|
53
|
+
cellOutput: output.cellOutput,
|
|
54
|
+
outputData: output.outputData,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
async readBody(txHash) {
|
|
58
|
+
// CCC's own cache keys bodies by their hash, but a consumer's cache need not.
|
|
59
|
+
return (verifiedBody(await this.cache.getTransactionResponse(txHash), txHash) ??
|
|
60
|
+
(await this.getTransaction(txHash)));
|
|
61
|
+
}
|
|
62
|
+
async getCellWithHeader(...args) {
|
|
63
|
+
const result = await this[ccc.Proxy.inner].getCellWithHeader(...args);
|
|
64
|
+
ccc.apply(verified, result?.header);
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** The response when its body hashes to the hash asked for, else throws. */
|
|
69
|
+
function verifiedBody(response, txHash) {
|
|
70
|
+
const asked = ccc.hexFrom(txHash);
|
|
71
|
+
if (response !== undefined && response.transaction.hash() !== asked) {
|
|
72
|
+
throw new Error(`Transaction ${asked} was answered with a body of another hash`);
|
|
73
|
+
}
|
|
74
|
+
return response;
|
|
75
|
+
}
|
|
76
|
+
/** The header when its fields hash to the hash it carries, else throws. */
|
|
77
|
+
function verified(header) {
|
|
78
|
+
const computed = headerHash(header);
|
|
79
|
+
if (computed !== header.hash) {
|
|
80
|
+
throw new Error(`Header ${header.hash} carries the fields of ${computed}`);
|
|
81
|
+
}
|
|
82
|
+
return header;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The hash of a header as the chain computes it: blake2b over the header struct, each
|
|
86
|
+
* number little-endian, in declaration order, the nonce last.
|
|
87
|
+
*/
|
|
88
|
+
export function headerHash(header) {
|
|
89
|
+
const { dao } = header;
|
|
90
|
+
return ccc.hashCkb(ccc.numLeToBytes(header.version, 4), ccc.numLeToBytes(header.compactTarget, 4), ccc.numLeToBytes(header.timestamp, 8), ccc.numLeToBytes(header.number, 8), ccc.numLeToBytes(header.epoch.toNum(), 8), header.parentHash, header.transactionsRoot, header.proposalsHash, header.extraHash, ...[dao.c, dao.ar, dao.s, dao.u].map((field) => ccc.numLeToBytes(field, 8)), ccc.numLeToBytes(header.nonce, 16));
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=verified_client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verified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AAM,EAAE,CAAC,CAAC,EAClC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EACzC,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,gBAAgB,EACvB,MAAM,CAAC,aAAa,EACpB,MAAM,CAAC,SAAS,EAChB,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAC3E,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,CACnC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ickb/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9001.0.0",
|
|
4
4
|
"description": "iCKB SDK built on top of CCC",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ickb",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@ckb-ccc/core": "^1.23.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@ickb/testkit": "
|
|
45
|
+
"@ickb/testkit": "9001.0.0",
|
|
46
46
|
"@typescript/native-preview": "7.0.0-dev.20260707.2"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
package/src/constants.ts
CHANGED
|
@@ -41,31 +41,18 @@ const ORDER = ccc.Script.from({
|
|
|
41
41
|
args: "0x",
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Each network's iCKB dep group: it carries every iCKB script's code cell, xUDT's and
|
|
46
|
+
* iCKB Logic's included, so one group dep resolves them all.
|
|
47
|
+
*/
|
|
45
48
|
const DEPLOYMENTS = {
|
|
46
49
|
mainnet: {
|
|
47
|
-
udtCode: {
|
|
48
|
-
txHash: "0xc07844ce21b38e4b071dd0e1ee3b0e27afd8d7532491327f39b786343f558ab7",
|
|
49
|
-
index: 0,
|
|
50
|
-
},
|
|
51
|
-
logicCode: {
|
|
52
|
-
txHash: "0xd7309191381f5a8a2904b8a79958a9be2752dbba6871fa193dab6aeb29dc8f44",
|
|
53
|
-
index: 0,
|
|
54
|
-
},
|
|
55
50
|
depGroup: {
|
|
56
51
|
txHash: "0x621a6f38de3b9f453016780edac3b26bfcbfa3e2ecb47c2da275471a5d3ed165",
|
|
57
52
|
index: 0,
|
|
58
53
|
},
|
|
59
54
|
},
|
|
60
55
|
testnet: {
|
|
61
|
-
udtCode: {
|
|
62
|
-
txHash: "0xbf6fb538763efec2a70a6a3dcb7242787087e1030c4e7d86585bc63a9d337f5f",
|
|
63
|
-
index: 0,
|
|
64
|
-
},
|
|
65
|
-
logicCode: {
|
|
66
|
-
txHash: "0x9ac989b3355764f76cdce02c69dedb819fdfbcbda49a7db1a2c9facdfdb9a7fe",
|
|
67
|
-
index: 0,
|
|
68
|
-
},
|
|
69
56
|
depGroup: {
|
|
70
57
|
txHash: "0xf7ece4fb33d8378344cab11fcd6a4c6f382fd4207ac921cf5821f30712dcd311",
|
|
71
58
|
index: 0,
|
|
@@ -73,11 +60,6 @@ const DEPLOYMENTS = {
|
|
|
73
60
|
},
|
|
74
61
|
} as const;
|
|
75
62
|
|
|
76
|
-
/**
|
|
77
|
-
* Plain CKB the bot keeps for its own cells and fees: its sizing line for matches and deposits.
|
|
78
|
-
*/
|
|
79
|
-
export const CKB_RESERVE = ccc.fixedPointFrom(1000);
|
|
80
|
-
|
|
81
63
|
/**
|
|
82
64
|
* The managers of one network's iCKB deployment.
|
|
83
65
|
*
|
|
@@ -89,13 +71,12 @@ export function getConfig(chain: SupportedChain): SdkManagers {
|
|
|
89
71
|
if (!Object.hasOwn(DEPLOYMENTS, chain)) {
|
|
90
72
|
throw new TypeError("unsupported iCKB network");
|
|
91
73
|
}
|
|
92
|
-
const {
|
|
74
|
+
const { depGroup } = DEPLOYMENTS[chain];
|
|
93
75
|
const cellDeps = [ccc.CellDep.from({ outPoint: depGroup, depType: "depGroup" })];
|
|
94
76
|
const dao = { script: DAO, cellDeps };
|
|
95
77
|
const ickbUdt = new IckbUdt({
|
|
96
|
-
code: udtCode,
|
|
97
78
|
script: IckbUdt.typeScriptFrom(UDT, ICKB_LOGIC),
|
|
98
|
-
|
|
79
|
+
cellDeps,
|
|
99
80
|
logicScript: ICKB_LOGIC,
|
|
100
81
|
daoScript: DAO,
|
|
101
82
|
});
|
|
@@ -46,9 +46,7 @@ export function estimateConversionOrder(
|
|
|
46
46
|
* This conservative proxy stays separate from partialOrderFee: the quote has no built
|
|
47
47
|
* order whose serialized size could supply that fee yet.
|
|
48
48
|
*/
|
|
49
|
-
|
|
50
|
-
system: Pick<SystemState, "feeRate">,
|
|
51
|
-
): bigint {
|
|
49
|
+
function estimateMaturityFeeThreshold(system: Pick<SystemState, "feeRate">): bigint {
|
|
52
50
|
return 10n * system.feeRate;
|
|
53
51
|
}
|
|
54
52
|
|
|
@@ -4,12 +4,12 @@ import type { IckbDepositCell } from "../logic.ts";
|
|
|
4
4
|
import type { OrderGroup } from "../order/cells.ts";
|
|
5
5
|
import { fillsWhole } from "../order/fill.ts";
|
|
6
6
|
import type { Info } from "../order/info.ts";
|
|
7
|
-
import {
|
|
8
|
-
import { compareBigInt, type ValueComponents } from "../utils/utils.ts";
|
|
7
|
+
import { ckbFromUdt, ICKB_DEPOSIT_CAP } from "../udt.ts";
|
|
8
|
+
import { ceilDiv, compareBigInt, type ValueComponents } from "../utils/utils.ts";
|
|
9
9
|
import type { MaturityOrderInput, SystemState } from "./types.ts";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Assumed turn duration
|
|
12
|
+
* Assumed turn duration: the bot's turns start ten minutes apart.
|
|
13
13
|
* This is a modeling interval, not a bound on the runtime; see sdk/docs/pool_maturity_estimates.md.
|
|
14
14
|
*/
|
|
15
15
|
export const BOT_TURN_MS = 10n * 60n * 1000n;
|
|
@@ -74,8 +74,8 @@ function ckbToIckbOrderMaturity(
|
|
|
74
74
|
(udt, group) => udt + group.udtValue,
|
|
75
75
|
0n,
|
|
76
76
|
);
|
|
77
|
-
const demand = amount + buyersAhead -
|
|
78
|
-
const capCkb =
|
|
77
|
+
const demand = amount + buyersAhead - ckbFromUdt(sellers, system.exchangeRatio);
|
|
78
|
+
const capCkb = ckbFromUdt(ICKB_DEPOSIT_CAP, system.exchangeRatio);
|
|
79
79
|
const turns = demand > 0n ? 1n + demand / capCkb : 1n;
|
|
80
80
|
return system.tip.timestamp + BOT_TURN_MS * turns;
|
|
81
81
|
}
|
|
@@ -100,14 +100,14 @@ function ickbToCkbOrderMaturity(
|
|
|
100
100
|
// The CKB an order has already received belongs to its earlier fills; what it still
|
|
101
101
|
// needs is the remaining iCKB at its price.
|
|
102
102
|
const needed =
|
|
103
|
-
info.udtToCkb.
|
|
104
|
-
|
|
103
|
+
ceilDiv(amount * info.udtToCkb.udtScale, info.udtToCkb.ckbScale) +
|
|
104
|
+
ckbFromUdt(sellersAhead, system.exchangeRatio);
|
|
105
105
|
const taken = new Set(takenDeposits.map((deposit) => deposit.cell.outPoint.toHex()));
|
|
106
106
|
const steps = [
|
|
107
107
|
{
|
|
108
108
|
ckbValue: sellers.some((group) => sits(group, system))
|
|
109
109
|
? 0n
|
|
110
|
-
:
|
|
110
|
+
: ckbFromUdt(ICKB_DEPOSIT_CAP, system.exchangeRatio),
|
|
111
111
|
at: system.tip.timestamp,
|
|
112
112
|
},
|
|
113
113
|
// A claim the bot can no longer request in time rolls a cycle: the bot's rule, not the
|
|
@@ -148,12 +148,11 @@ function fillableOrders(
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
/**
|
|
151
|
-
* Whether the order has been on the book for more than
|
|
152
|
-
*
|
|
151
|
+
* Whether the order has been on the book for more than an eighth of an epoch in blocks,
|
|
152
|
+
* about three ten-minute turns: the bot has seen it and left it. A turn alone left no
|
|
153
|
+
* margin, since an order placed just after a turn waits a turn to be seen, and a failed
|
|
154
|
+
* turn adds the restart delay.
|
|
153
155
|
*/
|
|
154
156
|
function sits(group: OrderGroup, { tip }: SystemState): boolean {
|
|
155
|
-
return
|
|
156
|
-
group.blockNumber !== undefined &&
|
|
157
|
-
tip.number - group.blockNumber > tip.epoch.denominator / 24n
|
|
158
|
-
);
|
|
157
|
+
return tip.number - group.blockNumber > tip.epoch.denominator / 8n;
|
|
159
158
|
}
|