@ickb/sdk 1000.0.81 → 9000.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -32
- package/dist/constants.d.ts +13 -22
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +80 -76
- package/dist/constants.js.map +1 -1
- package/dist/conversion/estimate.d.ts +39 -0
- package/dist/conversion/estimate.d.ts.map +1 -0
- package/dist/conversion/estimate.js +117 -0
- package/dist/conversion/estimate.js.map +1 -0
- package/dist/conversion/maturity.d.ts +15 -0
- package/dist/conversion/maturity.d.ts.map +1 -0
- package/dist/conversion/maturity.js +112 -0
- package/dist/conversion/maturity.js.map +1 -0
- package/dist/conversion/plans.d.ts +20 -0
- package/dist/conversion/plans.d.ts.map +1 -0
- package/dist/conversion/plans.js +106 -0
- package/dist/conversion/plans.js.map +1 -0
- package/dist/conversion/projection.d.ts +22 -0
- package/dist/conversion/projection.d.ts.map +1 -0
- package/dist/conversion/projection.js +91 -0
- package/dist/conversion/projection.js.map +1 -0
- package/dist/conversion/types.d.ts +252 -0
- package/dist/conversion/types.d.ts.map +1 -0
- package/dist/conversion/types.js +2 -0
- package/dist/conversion/types.js.map +1 -0
- package/dist/conversion/withdrawal_ring.d.ts +36 -0
- package/dist/conversion/withdrawal_ring.d.ts.map +1 -0
- package/dist/conversion/withdrawal_ring.js +87 -0
- package/dist/conversion/withdrawal_ring.js.map +1 -0
- package/dist/dao.d.ts +86 -0
- package/dist/dao.d.ts.map +1 -0
- package/dist/dao.js +113 -0
- package/dist/dao.js.map +1 -0
- package/dist/index.d.ts +51 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -3
- package/dist/index.js.map +1 -1
- package/dist/logic.d.ts +85 -0
- package/dist/logic.d.ts.map +1 -0
- package/dist/logic.js +184 -0
- package/dist/logic.js.map +1 -0
- package/dist/order/cells.d.ts +207 -0
- package/dist/order/cells.d.ts.map +1 -0
- package/dist/order/cells.js +427 -0
- package/dist/order/cells.js.map +1 -0
- package/dist/order/conversion.d.ts +43 -0
- package/dist/order/conversion.d.ts.map +1 -0
- package/dist/order/conversion.js +123 -0
- package/dist/order/conversion.js.map +1 -0
- package/dist/order/fee.d.ts +9 -0
- package/dist/order/fee.d.ts.map +1 -0
- package/dist/order/fee.js +24 -0
- package/dist/order/fee.js.map +1 -0
- package/dist/order/fill.d.ts +36 -0
- package/dist/order/fill.d.ts.map +1 -0
- package/dist/order/fill.js +53 -0
- package/dist/order/fill.js.map +1 -0
- package/dist/order/info.d.ts +62 -0
- package/dist/order/info.d.ts.map +1 -0
- package/dist/order/info.js +99 -0
- package/dist/order/info.js.map +1 -0
- package/dist/order/master.d.ts +49 -0
- package/dist/order/master.d.ts.map +1 -0
- package/dist/order/master.js +27 -0
- package/dist/order/master.js.map +1 -0
- package/dist/order/matcher.d.ts +43 -0
- package/dist/order/matcher.d.ts.map +1 -0
- package/dist/order/matcher.js +123 -0
- package/dist/order/matcher.js.map +1 -0
- package/dist/order/order.d.ts +59 -0
- package/dist/order/order.d.ts.map +1 -0
- package/dist/order/order.js +239 -0
- package/dist/order/order.js.map +1 -0
- package/dist/order/order_data.d.ts +51 -0
- package/dist/order/order_data.d.ts.map +1 -0
- package/dist/order/order_data.js +64 -0
- package/dist/order/order_data.js.map +1 -0
- package/dist/order/ratio.d.ts +42 -0
- package/dist/order/ratio.d.ts.map +1 -0
- package/dist/order/ratio.js +82 -0
- package/dist/order/ratio.js.map +1 -0
- package/dist/order/relative.d.ts +43 -0
- package/dist/order/relative.d.ts.map +1 -0
- package/dist/order/relative.js +54 -0
- package/dist/order/relative.js.map +1 -0
- package/dist/owned_owner.d.ts +113 -0
- package/dist/owned_owner.d.ts.map +1 -0
- package/dist/owned_owner.js +280 -0
- package/dist/owned_owner.js.map +1 -0
- package/dist/sdk.d.ts +71 -42
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +388 -209
- package/dist/sdk.js.map +1 -1
- package/dist/send/sign_and_send_transaction.d.ts +46 -0
- package/dist/send/sign_and_send_transaction.d.ts.map +1 -0
- package/dist/send/sign_and_send_transaction.js +101 -0
- package/dist/send/sign_and_send_transaction.js.map +1 -0
- package/dist/send/wait_transaction.d.ts +41 -0
- package/dist/send/wait_transaction.d.ts.map +1 -0
- package/dist/send/wait_transaction.js +204 -0
- package/dist/send/wait_transaction.js.map +1 -0
- package/dist/udt.d.ts +123 -0
- package/dist/udt.d.ts.map +1 -0
- package/dist/udt.js +244 -0
- package/dist/udt.js.map +1 -0
- package/dist/utils/chain.d.ts +38 -0
- package/dist/utils/chain.d.ts.map +1 -0
- package/dist/utils/chain.js +20 -0
- package/dist/utils/chain.js.map +1 -0
- package/dist/utils/codec.d.ts +19 -0
- package/dist/utils/codec.d.ts.map +1 -0
- package/dist/utils/codec.js +66 -0
- package/dist/utils/codec.js.map +1 -0
- package/dist/utils/transaction_header.d.ts +17 -0
- package/dist/utils/transaction_header.d.ts.map +1 -0
- package/dist/utils/transaction_header.js +44 -0
- package/dist/utils/transaction_header.js.map +1 -0
- package/dist/utils/utils.d.ts +126 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +151 -0
- package/dist/utils/utils.js.map +1 -0
- package/package.json +19 -26
- package/src/constants.ts +84 -181
- package/src/conversion/estimate.ts +157 -0
- package/src/conversion/maturity.ts +159 -0
- package/src/conversion/plans.ts +144 -0
- package/src/conversion/projection.ts +128 -0
- package/src/conversion/types.ts +287 -0
- package/src/conversion/withdrawal_ring.ts +126 -0
- package/src/dao.ts +172 -0
- package/src/index.ts +89 -3
- package/src/logic.ts +295 -0
- package/src/order/cells.ts +520 -0
- package/src/order/conversion.ts +173 -0
- package/src/order/fee.ts +30 -0
- package/src/order/fill.ts +83 -0
- package/src/order/info.ts +178 -0
- package/src/order/master.ts +42 -0
- package/src/order/matcher.ts +191 -0
- package/src/order/order.ts +302 -0
- package/src/order/order_data.ts +128 -0
- package/src/order/ratio.ts +144 -0
- package/src/order/relative.ts +106 -0
- package/src/owned_owner.ts +394 -0
- package/src/sdk.ts +555 -440
- package/src/send/sign_and_send_transaction.ts +120 -0
- package/src/send/wait_transaction.ts +271 -0
- package/src/udt.ts +317 -0
- package/src/utils/chain.ts +43 -0
- package/src/utils/codec.ts +74 -0
- package/src/utils/transaction_header.ts +66 -0
- package/src/utils/utils.ts +237 -0
- package/dist/codec.d.ts +0 -3
- package/dist/codec.d.ts.map +0 -1
- package/dist/codec.js +0 -58
- package/dist/codec.js.map +0 -1
- package/src/codec.ts +0 -138
package/dist/udt.js
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { ccc, mol } from "@ckb-ccc/core";
|
|
2
|
+
import { isDaoDeposit } from "./dao.js";
|
|
3
|
+
import { CheckedUint128LE, CheckedUint32LE, CheckedUint64LE } from "./utils/codec.js";
|
|
4
|
+
import { transactionHeaders } from "./utils/transaction_header.js";
|
|
5
|
+
const ickbXudtTypeOccupiedSize = 69;
|
|
6
|
+
const udtDataSize = 16;
|
|
7
|
+
const AR_0 = 10000000000000000n; // Base scale for CKB
|
|
8
|
+
const depositUsedCapacity = ccc.fixedPointFrom(82); // 82n CKB
|
|
9
|
+
const depositCapacityDelta = (depositUsedCapacity * AR_0) / ccc.fixedPointFrom(100000);
|
|
10
|
+
const xudtOwnerMode = 0x80000000n;
|
|
11
|
+
// A receipt's fixed prefix: 4 bytes of deposit quantity and 8 of deposit amount.
|
|
12
|
+
export const receiptDataBytes = 12;
|
|
13
|
+
const ReceiptDataCodec = mol.struct({
|
|
14
|
+
depositQuantity: CheckedUint32LE,
|
|
15
|
+
depositAmount: CheckedUint64LE,
|
|
16
|
+
});
|
|
17
|
+
/** Encodes a receipt payload. */
|
|
18
|
+
export function encodeReceiptData(data) {
|
|
19
|
+
return ReceiptDataCodec.encode(data);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Decodes the fixed receipt-data prefix and ignores trailing cell payload bytes.
|
|
23
|
+
*
|
|
24
|
+
* @remarks The receipt data prefix is 12 bytes after the `0x` marker: 4 bytes for deposit
|
|
25
|
+
* quantity and 8 bytes for deposit amount. Later payload bytes belong to other protocol
|
|
26
|
+
* data and are intentionally tolerated here.
|
|
27
|
+
*/
|
|
28
|
+
export function decodeReceiptData(outputData) {
|
|
29
|
+
return ReceiptDataCodec.decode(outputData.slice(0, 2 + 2 * receiptDataBytes));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Soft per-deposit iCKB value cap used before applying the excess discount.
|
|
33
|
+
*/
|
|
34
|
+
export const ICKB_DEPOSIT_CAP = ccc.fixedPointFrom(100000); // 100,000 iCKB
|
|
35
|
+
/**
|
|
36
|
+
* The iCKB xUDT token: its scripts, code cells, and the iCKB accounting of a
|
|
37
|
+
* transaction's inputs. Inputs carry iCKB as xUDT balances, as receipt value,
|
|
38
|
+
* and negatively as the first-phase deposits a transaction re-mints.
|
|
39
|
+
*/
|
|
40
|
+
export class IckbUdt {
|
|
41
|
+
/** The iCKB xUDT type script. */
|
|
42
|
+
script;
|
|
43
|
+
/** Out point of the xUDT code cell used by this iCKB token. */
|
|
44
|
+
udtCode;
|
|
45
|
+
/** Out point of the iCKB Logic code cell required by this token. */
|
|
46
|
+
logicCode;
|
|
47
|
+
/** Logic script whose hash is embedded in this iCKB xUDT type script. */
|
|
48
|
+
logicScript;
|
|
49
|
+
/** The Nervos DAO script, to recognize the first-phase deposits a transaction re-mints. */
|
|
50
|
+
daoScript;
|
|
51
|
+
/** Creates an instance of IckbUdt from its code and script references. */
|
|
52
|
+
constructor({ code, script, logicCode, logicScript, daoScript, }) {
|
|
53
|
+
this.script = ccc.Script.from(script);
|
|
54
|
+
this.udtCode = ccc.OutPoint.from(code);
|
|
55
|
+
this.logicCode = ccc.OutPoint.from(logicCode);
|
|
56
|
+
this.logicScript = ccc.Script.from(logicScript);
|
|
57
|
+
this.daoScript = ccc.Script.from(daoScript);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Computes the iCKB UDT type script from raw UDT and Logic scripts.
|
|
61
|
+
*
|
|
62
|
+
* Concatenates the iCKB logic script hash with the fixed 4-byte little-endian
|
|
63
|
+
* xUDT owner-mode flags postfix ("00000080") to form the UDT type script args.
|
|
64
|
+
*
|
|
65
|
+
* @param udtScript - The raw xUDT script (codeHash and hashType reused).
|
|
66
|
+
* @param ickbLogic - The iCKB logic script (hash used for args).
|
|
67
|
+
* @returns A new Script with the computed args.
|
|
68
|
+
*/
|
|
69
|
+
static typeScriptFrom(udtScript, ickbLogic) {
|
|
70
|
+
const { codeHash, hashType } = udtScript;
|
|
71
|
+
return new ccc.Script(codeHash, hashType, ccc.hexFrom(ccc.bytesConcat(ickbLogic.hash(), CheckedUint32LE.encode(xudtOwnerMode))));
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Minimum capacity for an iCKB xUDT cell locked by the supplied lock script.
|
|
75
|
+
*/
|
|
76
|
+
static minimumXudtCellCapacity(lock) {
|
|
77
|
+
return (BigInt(8 + lock.occupiedSize + ickbXudtTypeOccupiedSize + udtDataSize) * ccc.One);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Returns true when a cell carries this iCKB xUDT type and enough UDT data.
|
|
81
|
+
*/
|
|
82
|
+
isUdt(cellLike) {
|
|
83
|
+
const cell = ccc.CellAny.from(cellLike);
|
|
84
|
+
return (cell.cellOutput.type?.eq(this.script) === true &&
|
|
85
|
+
ccc.bytesFrom(cell.outputData).length >= udtDataSize);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Adds iCKB-specific cell dependencies to a transaction.
|
|
89
|
+
*
|
|
90
|
+
* Adds individual code deps (not dep group) for:
|
|
91
|
+
* - xUDT code cell (this.udtCode)
|
|
92
|
+
* - iCKB Logic code cell (this.logicCode)
|
|
93
|
+
*
|
|
94
|
+
* @param txLike - The transaction to add cell deps to.
|
|
95
|
+
* @returns The transaction with cell deps added.
|
|
96
|
+
*/
|
|
97
|
+
addCellDeps(txLike) {
|
|
98
|
+
const tx = ccc.Transaction.from(txLike);
|
|
99
|
+
addCodeDep(tx, this.udtCode);
|
|
100
|
+
addCodeDep(tx, this.logicCode);
|
|
101
|
+
return tx;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* iCKB carried by the transaction's inputs: xUDT balances plus receipt value,
|
|
105
|
+
* minus the first-phase deposits it re-mints. Final withdrawal inputs carry none.
|
|
106
|
+
* The protocol cells are valued at their deposit headers, each read once.
|
|
107
|
+
*/
|
|
108
|
+
async inputBalance(tx, client) {
|
|
109
|
+
const cells = await Promise.all(tx.inputs.map(async (input) => {
|
|
110
|
+
try {
|
|
111
|
+
return await input.getCell(client);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
throw new Error(`Failed to load input cell ${input.previousOutput.toHex()}`, {
|
|
115
|
+
cause: error,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}));
|
|
119
|
+
const valued = cells.map((cell) => this.protocolValue(cell));
|
|
120
|
+
const headers = await transactionHeaders(client, valued.flatMap((value) => (value === undefined ? [] : [value.txHash])));
|
|
121
|
+
let balance = ccc.Zero;
|
|
122
|
+
for (const [index, cell] of cells.entries()) {
|
|
123
|
+
const value = valued[index];
|
|
124
|
+
if (this.isUdt(cell)) {
|
|
125
|
+
balance += decodeUdtBalance(cell.outputData);
|
|
126
|
+
}
|
|
127
|
+
else if (value !== undefined) {
|
|
128
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- every protocol cell's hash was read above.
|
|
129
|
+
const header = headers.get(value.txHash);
|
|
130
|
+
balance += value.sign * ickbValue(value.amount, header) * value.quantity;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return balance;
|
|
134
|
+
}
|
|
135
|
+
/** What a protocol input (receipt or first-phase deposit) is worth once its header is known. */
|
|
136
|
+
protocolValue(cell) {
|
|
137
|
+
if (this.isUdt(cell) || cell.outPoint === undefined) {
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
const { type, lock } = cell.cellOutput;
|
|
141
|
+
if (type !== undefined && this.logicScript.eq(type)) {
|
|
142
|
+
let receipt;
|
|
143
|
+
try {
|
|
144
|
+
receipt = decodeReceiptData(cell.outputData);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
throw new Error(`Invalid iCKB receipt payload at ${cell.outPoint.toHex()}: ${cell.outputData}`, { cause: error });
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
txHash: cell.outPoint.txHash,
|
|
151
|
+
amount: receipt.depositAmount,
|
|
152
|
+
quantity: receipt.depositQuantity,
|
|
153
|
+
sign: 1n,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
if (this.logicScript.eq(lock) && isDaoDeposit(cell, this.daoScript)) {
|
|
157
|
+
return {
|
|
158
|
+
txHash: cell.outPoint.txHash,
|
|
159
|
+
amount: cell.capacityFree,
|
|
160
|
+
quantity: 1n,
|
|
161
|
+
sign: -1n,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
/** iCKB the transaction's outputs require. */
|
|
167
|
+
outputBalance(tx) {
|
|
168
|
+
return Array.from(tx.outputCells).reduce((required, cell) => {
|
|
169
|
+
return this.isUdt(cell) ? required + decodeUdtBalance(cell.outputData) : required;
|
|
170
|
+
}, ccc.Zero);
|
|
171
|
+
}
|
|
172
|
+
/** Adds the iCKB change output when the surplus is positive; zero needs no output. */
|
|
173
|
+
addChange(tx, lock, balance) {
|
|
174
|
+
if (balance <= ccc.Zero) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
tx.addOutput({ lock, type: this.script }, CheckedUint128LE.encode(balance));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function decodeUdtBalance(data) {
|
|
181
|
+
return CheckedUint128LE.decode(ccc.bytesFrom(data).slice(0, udtDataSize));
|
|
182
|
+
}
|
|
183
|
+
function addCodeDep(tx, outPoint) {
|
|
184
|
+
if (tx.cellDeps.some((dep) => dep.depType === "code" && dep.outPoint.eq(outPoint))) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
tx.addCellDeps({ outPoint, depType: "code" });
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Calculates iCKB value for unoccupied CKB capacity at a deposit header.
|
|
191
|
+
*
|
|
192
|
+
* @remarks
|
|
193
|
+
* Values above {@link ICKB_DEPOSIT_CAP} receive a 10% discount only on the
|
|
194
|
+
* excess amount.
|
|
195
|
+
*/
|
|
196
|
+
export function ickbValue(ckbUnoccupiedCapacity, header) {
|
|
197
|
+
let ickbAmount = convert(true, ckbUnoccupiedCapacity, ickbAccountingRatio(header));
|
|
198
|
+
if (ICKB_DEPOSIT_CAP < ickbAmount) {
|
|
199
|
+
// Apply a 10% discount for the amount exceeding the soft iCKB cap per deposit.
|
|
200
|
+
ickbAmount -= (ickbAmount - ICKB_DEPOSIT_CAP) / 10n;
|
|
201
|
+
}
|
|
202
|
+
return ickbAmount;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Converts between CKB and iCKB based on an explicit ratio.
|
|
206
|
+
*
|
|
207
|
+
* @param isCkb2Udt - A boolean indicating the direction of conversion (CKB to iCKB or vice versa).
|
|
208
|
+
* @param amount - The amount to convert.
|
|
209
|
+
* @param ratio - The CKB and iCKB scales to use.
|
|
210
|
+
* @returns The converted amount in the target unit as a `ccc.FixedPoint`.
|
|
211
|
+
*/
|
|
212
|
+
export function convert(isCkb2Udt, amount, ratio) {
|
|
213
|
+
if (ratio.ckbScale <= 0n || ratio.udtScale <= 0n) {
|
|
214
|
+
throw new Error("Exchange ratio scales must be positive");
|
|
215
|
+
}
|
|
216
|
+
return isCkb2Udt
|
|
217
|
+
? (amount * ratio.ckbScale) / ratio.udtScale
|
|
218
|
+
: (amount * ratio.udtScale) / ratio.ckbScale;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Calculates the free-capacity accounting ratio at a block header.
|
|
222
|
+
*
|
|
223
|
+
* @param header - The block header whose DAO accumulated rate is used.
|
|
224
|
+
* @returns An object containing the CKB and UDT scales.
|
|
225
|
+
*/
|
|
226
|
+
export function ickbAccountingRatio(header) {
|
|
227
|
+
return {
|
|
228
|
+
ckbScale: AR_0,
|
|
229
|
+
udtScale: header.dao.ar,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Calculates the gross iCKB exchange ratio for a recoverable standard deposit.
|
|
234
|
+
*
|
|
235
|
+
* @remarks Includes the standard deposit's 82 CKB occupied capacity spread
|
|
236
|
+
* over the 100,000 iCKB reference amount.
|
|
237
|
+
*/
|
|
238
|
+
export function ickbExchangeRatio(header) {
|
|
239
|
+
return {
|
|
240
|
+
ckbScale: AR_0,
|
|
241
|
+
udtScale: header.dao.ar + depositCapacityDelta,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=udt.js.map
|
package/dist/udt.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"udt.js","sourceRoot":"","sources":["../src/udt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGnE,MAAM,wBAAwB,GAAG,EAAE,CAAC;AACpC,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,MAAM,IAAI,GAAY,kBAAkB,CAAC,CAAC,qBAAqB;AAC/D,MAAM,mBAAmB,GAAG,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU;AAC9D,MAAM,oBAAoB,GAAG,CAAC,mBAAmB,GAAG,IAAI,CAAC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,MAAM,UAAU,iBAAiB,CAAC,MAA6B;IAC7D,OAAO;QACL,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,oBAAoB;KAC/C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ccc } from "@ckb-ccc/core";
|
|
2
|
+
/** Public CKB networks supported by Stack consumers. */
|
|
3
|
+
export type SupportedChain = "mainnet" | "testnet";
|
|
4
|
+
/** Canonical public identity of one supported CKB network. */
|
|
5
|
+
export interface ChainIdentity {
|
|
6
|
+
/** Stack network selector represented by this identity. */
|
|
7
|
+
readonly chain: SupportedChain;
|
|
8
|
+
/** CKB specification network name. */
|
|
9
|
+
readonly networkName: string;
|
|
10
|
+
/** Canonical genesis block hash. */
|
|
11
|
+
readonly genesisHash: ccc.Hex;
|
|
12
|
+
/** Canonical genesis message used by the CKB specification. */
|
|
13
|
+
readonly genesisMessage: string;
|
|
14
|
+
/** Public specification location from which the genesis identity was derived. */
|
|
15
|
+
readonly genesisSource: string;
|
|
16
|
+
/** Canonical address prefix for this network. */
|
|
17
|
+
readonly addressPrefix: "ckb" | "ckt";
|
|
18
|
+
}
|
|
19
|
+
/** The immutable canonical identity of each supported chain. */
|
|
20
|
+
export declare const chainIdentities: Readonly<{
|
|
21
|
+
readonly mainnet: Readonly<{
|
|
22
|
+
chain: "mainnet";
|
|
23
|
+
networkName: "ckb";
|
|
24
|
+
genesisHash: "0x92b197aa1fba0f63633922c61c92375c9c074a93e85963554f5499fe1450d0e5";
|
|
25
|
+
genesisMessage: "lina 0x18e020f6b1237a3d06b75121f25a7efa0550e4b3f44f974822f471902424c104";
|
|
26
|
+
genesisSource: "https://raw.githubusercontent.com/nervosnetwork/ckb/develop/resource/specs/mainnet.toml";
|
|
27
|
+
addressPrefix: "ckb";
|
|
28
|
+
}>;
|
|
29
|
+
readonly testnet: Readonly<{
|
|
30
|
+
chain: "testnet";
|
|
31
|
+
networkName: "ckb_testnet";
|
|
32
|
+
genesisHash: "0x10639e0895502b5688a6be8cf69460d76541bfa4821629d86d62ba0aae3f9606";
|
|
33
|
+
genesisMessage: "aggron-v4";
|
|
34
|
+
genesisSource: "https://raw.githubusercontent.com/nervosnetwork/ckb/develop/resource/specs/testnet.toml";
|
|
35
|
+
addressPrefix: "ckt";
|
|
36
|
+
}>;
|
|
37
|
+
}>;
|
|
38
|
+
//# sourceMappingURL=chain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../src/utils/chain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEzC,wDAAwD;AACxD,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,SAAS,CAAC;AAEnD,8DAA8D;AAC9D,MAAM,WAAW,aAAa;IAC5B,2DAA2D;IAC3D,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,sCAAsC;IACtC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,oCAAoC;IACpC,QAAQ,CAAC,WAAW,EAAE,GAAG,CAAC,GAAG,CAAC;IAC9B,+DAA+D;IAC/D,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,iFAAiF;IACjF,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,iDAAiD;IACjD,QAAQ,CAAC,aAAa,EAAE,KAAK,GAAG,KAAK,CAAC;CACvC;AAED,gEAAgE;AAChE,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;EAoB+B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** The immutable canonical identity of each supported chain. */
|
|
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
|
+
});
|
|
20
|
+
//# sourceMappingURL=chain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.js","sourceRoot":"","sources":["../../src/utils/chain.ts"],"names":[],"mappings":"AAqBA,gEAAgE;AAChE,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3C,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC;QACrB,KAAK,EAAE,SAAS;QAChB,WAAW,EAAE,KAAK;QAClB,WAAW,EAAE,oEAAoE;QACjF,cAAc,EACZ,yEAAyE;QAC3E,aAAa,EACX,yFAAyF;QAC3F,aAAa,EAAE,KAAK;KACrB,CAAC;IACF,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC;QACrB,KAAK,EAAE,SAAS;QAChB,WAAW,EAAE,aAAa;QAC1B,WAAW,EAAE,oEAAoE;QACjF,cAAc,EAAE,WAAW;QAC3B,aAAa,EACX,yFAAyF;QAC3F,aAAa,EAAE,KAAK;KACrB,CAAC;CACsD,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
/**
|
|
3
|
+
* Codec for little-endian 32-bit signed integers.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* The encoder rejects numeric values outside the signed 32-bit range before
|
|
7
|
+
* writing bytes. Decoding reads a signed little-endian integer from the bytes
|
|
8
|
+
* after CCC byte normalization.
|
|
9
|
+
*/
|
|
10
|
+
export declare const CheckedInt32LE: ccc.Codec<ccc.NumLike, number, any>;
|
|
11
|
+
/** Checked codec for 8-bit unsigned integers. */
|
|
12
|
+
export declare const CheckedUint8: ccc.Codec<ccc.NumLike, bigint, any>;
|
|
13
|
+
/** Checked codec for little-endian 32-bit unsigned integers. */
|
|
14
|
+
export declare const CheckedUint32LE: ccc.Codec<ccc.NumLike, bigint, any>;
|
|
15
|
+
/** Checked codec for little-endian 64-bit unsigned integers. */
|
|
16
|
+
export declare const CheckedUint64LE: ccc.Codec<ccc.NumLike, bigint, any>;
|
|
17
|
+
/** Checked codec for little-endian 128-bit unsigned integers. */
|
|
18
|
+
export declare const CheckedUint128LE: ccc.Codec<ccc.NumLike, bigint, any>;
|
|
19
|
+
//# sourceMappingURL=codec.d.ts.map
|
|
@@ -0,0 +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;AAEH,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"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
/**
|
|
3
|
+
* Codec for little-endian 32-bit signed integers.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* The encoder rejects numeric values outside the signed 32-bit range before
|
|
7
|
+
* writing bytes. Decoding reads a signed little-endian integer from the bytes
|
|
8
|
+
* after CCC byte normalization.
|
|
9
|
+
*/
|
|
10
|
+
export const CheckedInt32LE = ccc.Codec.from({
|
|
11
|
+
byteLength: 4,
|
|
12
|
+
encode: (numLike) => {
|
|
13
|
+
const normalized = normalizeInteger(numLike);
|
|
14
|
+
if (normalized < -2147483648n || normalized > 2147483647n) {
|
|
15
|
+
throw new Error("NumLike out of int32 bounds");
|
|
16
|
+
}
|
|
17
|
+
const num = Number(normalized);
|
|
18
|
+
const encoded = new Uint8Array(4);
|
|
19
|
+
new DataView(encoded.buffer).setInt32(0, num, true);
|
|
20
|
+
return encoded;
|
|
21
|
+
},
|
|
22
|
+
decode: (bytesLike) => {
|
|
23
|
+
const bytes = ccc.bytesFrom(bytesLike);
|
|
24
|
+
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getInt32(0, true);
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
/** Checked codec for 8-bit unsigned integers. */
|
|
28
|
+
export const CheckedUint8 = checkedUintLE(1);
|
|
29
|
+
/** Checked codec for little-endian 32-bit unsigned integers. */
|
|
30
|
+
export const CheckedUint32LE = checkedUintLE(4);
|
|
31
|
+
/** Checked codec for little-endian 64-bit unsigned integers. */
|
|
32
|
+
export const CheckedUint64LE = checkedUintLE(8);
|
|
33
|
+
/** Checked codec for little-endian 128-bit unsigned integers. */
|
|
34
|
+
export const CheckedUint128LE = checkedUintLE(16);
|
|
35
|
+
function checkedUintLE(byteLength) {
|
|
36
|
+
const bitLength = BigInt(byteLength * 8);
|
|
37
|
+
const max = (1n << bitLength) - 1n;
|
|
38
|
+
return ccc.Codec.from({
|
|
39
|
+
byteLength,
|
|
40
|
+
encode: (numLike) => {
|
|
41
|
+
const num = normalizeInteger(numLike);
|
|
42
|
+
if (num < 0n || num > max) {
|
|
43
|
+
throw new Error(`NumLike out of uint${String(bitLength)} bounds`);
|
|
44
|
+
}
|
|
45
|
+
return ccc.numLeToBytes(num, byteLength);
|
|
46
|
+
},
|
|
47
|
+
decode: ccc.numFromBytes,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function normalizeInteger(numLike) {
|
|
51
|
+
if (typeof numLike === "number") {
|
|
52
|
+
if (!Number.isFinite(numLike) || !Number.isInteger(numLike)) {
|
|
53
|
+
throw new TypeError("NumLike must be a finite integer");
|
|
54
|
+
}
|
|
55
|
+
if (!Number.isSafeInteger(numLike)) {
|
|
56
|
+
throw new TypeError("NumLike number must be a safe integer");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
return ccc.numFrom(numLike);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
throw new TypeError("NumLike must be a finite integer");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=codec.js.map
|
|
@@ -0,0 +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,CAAC;QACD,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QAC/B,MAAM,OAAO,GAAG,IAAI,UAAU,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AC,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"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ccc } from "@ckb-ccc/core";
|
|
2
|
+
/**
|
|
3
|
+
* The header of the block that committed `txHash`, without the transaction body, which no
|
|
4
|
+
* caller reads. A client with a JSON-RPC requestor, the connector's composed client
|
|
5
|
+
* included, asks the node for the status only (verbosity 1) and then the header by number,
|
|
6
|
+
* which CCC caches once confirmed; a cold read of the pool then moves a few bytes per
|
|
7
|
+
* deposit instead of every deposit transaction. Any other client keeps the typed lookup.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getTransactionHeader(client: ccc.Client, txHash: ccc.Hex): Promise<ccc.ClientBlockHeader | undefined>;
|
|
10
|
+
/**
|
|
11
|
+
* The committing headers of a batch of transactions, each hash read once. A batch is one
|
|
12
|
+
* coherent read: the cells came from one scan, so every header must exist.
|
|
13
|
+
*/
|
|
14
|
+
export declare function transactionHeaders(client: ccc.Client, txHashes: Iterable<ccc.Hex>): Promise<Map<ccc.Hex, ccc.ClientBlockHeader>>;
|
|
15
|
+
/** The headers of a batch of block numbers, each read once; every block must exist. */
|
|
16
|
+
export declare function headersByNumber(client: ccc.Client, blockNumbers: Iterable<ccc.Num>): Promise<Map<ccc.Num, ccc.ClientBlockHeader>>;
|
|
17
|
+
//# sourceMappingURL=transaction_header.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction_header.d.ts","sourceRoot":"","sources":["../../src/utils/transaction_header.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGzC;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,MAAM,EAAE,GAAG,CAAC,GAAG,GACd,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAS5C;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,GAC1B,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAc9C;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"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsonRpcRequestor, rawTransactionStatus } from "./utils.js";
|
|
2
|
+
/**
|
|
3
|
+
* The header of the block that committed `txHash`, without the transaction body, which no
|
|
4
|
+
* caller reads. A client with a JSON-RPC requestor, the connector's composed client
|
|
5
|
+
* included, asks the node for the status only (verbosity 1) and then the header by number,
|
|
6
|
+
* which CCC caches once confirmed; a cold read of the pool then moves a few bytes per
|
|
7
|
+
* deposit instead of every deposit transaction. Any other client keeps the typed lookup.
|
|
8
|
+
*/
|
|
9
|
+
export async function getTransactionHeader(client, txHash) {
|
|
10
|
+
const requestor = jsonRpcRequestor(client);
|
|
11
|
+
if (requestor === undefined) {
|
|
12
|
+
return (await client.getTransactionWithHeader(txHash))?.header;
|
|
13
|
+
}
|
|
14
|
+
const { blockNumber } = rawTransactionStatus(await requestor.request("get_transaction", [txHash, "0x1"]));
|
|
15
|
+
return blockNumber === undefined ? undefined : client.getHeaderByNumber(blockNumber);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The committing headers of a batch of transactions, each hash read once. A batch is one
|
|
19
|
+
* coherent read: the cells came from one scan, so every header must exist.
|
|
20
|
+
*/
|
|
21
|
+
export async function transactionHeaders(client, txHashes) {
|
|
22
|
+
const distinct = [...new Set(txHashes)];
|
|
23
|
+
const headers = await Promise.all(distinct.map(async (txHash) => getTransactionHeader(client, txHash)));
|
|
24
|
+
return new Map(distinct.map((txHash, index) => {
|
|
25
|
+
const header = headers[index];
|
|
26
|
+
if (header === undefined) {
|
|
27
|
+
throw new Error(`Header not found for txHash ${txHash}`);
|
|
28
|
+
}
|
|
29
|
+
return [txHash, header];
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
/** The headers of a batch of block numbers, each read once; every block must exist. */
|
|
33
|
+
export async function headersByNumber(client, blockNumbers) {
|
|
34
|
+
const distinct = [...new Set(blockNumbers)];
|
|
35
|
+
const headers = await Promise.all(distinct.map(async (blockNumber) => client.getHeaderByNumber(blockNumber)));
|
|
36
|
+
return new Map(distinct.map((blockNumber, index) => {
|
|
37
|
+
const header = headers[index];
|
|
38
|
+
if (header === undefined) {
|
|
39
|
+
throw new Error(`Header not found for block number ${String(blockNumber)}`);
|
|
40
|
+
}
|
|
41
|
+
return [blockNumber, header];
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=transaction_header.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction_header.js","sourceRoot":"","sources":["../../src/utils/transaction_header.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEpE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAAkB,EAClB,MAAe;IAEf,MAAM,SAAS,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC3C,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5B,OAAO,CAAC,MAAM,MAAM,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC;IACjE,CAAC;IACD,MAAM,EAAE,WAAW,EAAE,GAAG,oBAAoB,CAC1C,MAAM,SAAS,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAC5D,CAAC;IACF,OAAO,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;AACvF,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAAkB,EAClB,QAA2B;IAE3B,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;IACxC,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CACrE,CAAC;IACF,OAAO,IAAI,GAAG,CACZ,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QAC7B,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QAC9B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,+BAA+B,MAAM,EAAE,CAAC,CAAC;QAC3D,CAAC;QACD,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1B,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AAED,uFAAuF;AACvF,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAAkB,EAClB,YAA+B;IAE/B,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAC3E,CAAC;IACF,OAAO,IAAI,GAAG,CACZ,QAAQ,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE;QAClC,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QAC9B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,qCAAqC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAC9E,CAAC;QACD,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAC/B,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
/**
|
|
3
|
+
* The default page size used when querying cells from the chain.
|
|
4
|
+
*
|
|
5
|
+
* This page size is aligned with Nervos CKB's pull request #4576
|
|
6
|
+
* (https://github.com/nervosnetwork/ckb/pull/4576) to avoid excessive paging.
|
|
7
|
+
*/
|
|
8
|
+
export declare const defaultCellPageSize = 400;
|
|
9
|
+
/**
|
|
10
|
+
* Reads every committed cell matching the key, page by page, without touching
|
|
11
|
+
* CCC's cell cache. The scan ends on the first short page.
|
|
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.
|
|
17
|
+
*/
|
|
18
|
+
export declare function findCells(client: ccc.Client, keyLike: ccc.ClientIndexerSearchKeyLike): Promise<ccc.Cell[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Local transaction inclusion metadata.
|
|
21
|
+
*/
|
|
22
|
+
export interface TransactionHeader {
|
|
23
|
+
/**
|
|
24
|
+
* The block header used for inclusion-dependent calculations.
|
|
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
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* CKB and UDT amounts carried by a cell, order, or planned value.
|
|
34
|
+
*/
|
|
35
|
+
export interface ValueComponents {
|
|
36
|
+
/** CKB-side amount as a `ccc.FixedPoint`. */
|
|
37
|
+
ckbValue: ccc.FixedPoint;
|
|
38
|
+
/** UDT-side amount as a `ccc.FixedPoint`. */
|
|
39
|
+
udtValue: ccc.FixedPoint;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Integer scale pair for comparing or converting CKB-side and UDT-side values.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* CKB-to-UDT conversions multiply by `ckbScale` and divide by `udtScale`.
|
|
46
|
+
* UDT-to-CKB conversions swap the scales. Callers choose the rounding policy.
|
|
47
|
+
*/
|
|
48
|
+
export interface ExchangeRatio {
|
|
49
|
+
/** Numerator scale for CKB-side values. */
|
|
50
|
+
ckbScale: ccc.Num;
|
|
51
|
+
/** Numerator scale for UDT-side values. */
|
|
52
|
+
udtScale: ccc.Num;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Script plus cell dependencies needed to build transactions that use it.
|
|
56
|
+
*/
|
|
57
|
+
export interface ScriptDeps {
|
|
58
|
+
/**
|
|
59
|
+
* The lock or type script.
|
|
60
|
+
*/
|
|
61
|
+
script: ccc.Script;
|
|
62
|
+
/**
|
|
63
|
+
* Cell dependencies required to resolve the script code.
|
|
64
|
+
*/
|
|
65
|
+
cellDeps: ccc.CellDep[];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* True when a cell has no type script and no data payload.
|
|
69
|
+
*
|
|
70
|
+
* @remarks
|
|
71
|
+
* This is a structural filter for plain capacity cells. Spendability still
|
|
72
|
+
* depends on the lock script, live cell state, and transaction context.
|
|
73
|
+
*/
|
|
74
|
+
export declare function isPlainCapacityCell(cell: ccc.Cell): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Performs asynchronously a binary search to find the smallest index `i` in the range [0, n)
|
|
77
|
+
* such that the function `f(i)` returns true. It is assumed that for the range
|
|
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
|
|
94
|
+
* composition proxy over the public client (`ClientWithFeeRate`, a `ccc.Client` but not a
|
|
95
|
+
* `ccc.ClientJsonRpc`), so `instanceof` misses it; the proxy forwards the property.
|
|
96
|
+
*/
|
|
97
|
+
export declare function jsonRpcRequestor(client: ccc.Client): ccc.RequestorJsonRpc | undefined;
|
|
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;
|
|
106
|
+
/** `numerator / denominator` rounded up; the denominator is positive. */
|
|
107
|
+
export declare function ceilDiv(numerator: bigint, denominator: bigint): bigint;
|
|
108
|
+
/**
|
|
109
|
+
* Compares two bigint values using sort-compatible ordering.
|
|
110
|
+
*
|
|
111
|
+
* @returns `-1` when `left` is smaller, `1` when `left` is larger, and `0` when equal.
|
|
112
|
+
*/
|
|
113
|
+
export declare function compareBigInt(left: bigint, right: bigint): number;
|
|
114
|
+
/**
|
|
115
|
+
* Yields unique items from the given iterable based on their hex representation.
|
|
116
|
+
*
|
|
117
|
+
* The function uses a Set to track the hex-string keys of items that have already been yielded.
|
|
118
|
+
* Only the first occurrence of each unique key is yielded.
|
|
119
|
+
*
|
|
120
|
+
* @typeParam T - A type that extends ccc.Entity.
|
|
121
|
+
* @param items - An iterable collection of items of type T.
|
|
122
|
+
* @returns A generator that yields items from the iterable, ensuring that each item's
|
|
123
|
+
* hex representation (via toHex()) is unique.
|
|
124
|
+
*/
|
|
125
|
+
export declare function unique<T extends ccc.Entity>(items: Iterable<T>): Generator<T>;
|
|
126
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAC7B,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,OAAO,EAAE,GAAG,CAAC,0BAA0B,GACtC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAoBrB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,MAAM,EAAE,GAAG,CAAC,iBAAiB,CAAC;IAE9B;;OAEG;IACH,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC;CAClB;AAED;;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;;;;;;;;;;;;;;;GAeG;AACH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