@ckb-ccc/core 1.10.0 → 1.11.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.
Files changed (71) hide show
  1. package/CHANGELOG.md +36 -4
  2. package/dist/ckb/hash.d.ts +18 -0
  3. package/dist/ckb/hash.d.ts.map +1 -0
  4. package/dist/ckb/hash.js +19 -0
  5. package/dist/ckb/index.d.ts +1 -0
  6. package/dist/ckb/index.d.ts.map +1 -1
  7. package/dist/ckb/index.js +1 -0
  8. package/dist/ckb/transaction.d.ts +179 -11
  9. package/dist/ckb/transaction.d.ts.map +1 -1
  10. package/dist/ckb/transaction.js +197 -59
  11. package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  12. package/dist/client/clientPublicMainnet.advanced.js +0 -60
  13. package/dist/client/clientPublicTestnet.advanced.d.ts +0 -23
  14. package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  15. package/dist/client/clientPublicTestnet.advanced.js +0 -144
  16. package/dist/client/knownScript.d.ts +1 -3
  17. package/dist/client/knownScript.d.ts.map +1 -1
  18. package/dist/client/knownScript.js +0 -4
  19. package/dist/hasher/hasherCkb.d.ts +0 -16
  20. package/dist/hasher/hasherCkb.d.ts.map +1 -1
  21. package/dist/hasher/hasherCkb.js +0 -18
  22. package/dist/molecule/codec.d.ts +30 -10
  23. package/dist/molecule/codec.d.ts.map +1 -1
  24. package/dist/molecule/codec.js +46 -13
  25. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +18 -6
  26. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  27. package/dist/signer/ckb/signerCkbScriptReadonly.js +18 -6
  28. package/dist/signer/signer/index.d.ts +11 -1
  29. package/dist/signer/signer/index.d.ts.map +1 -1
  30. package/dist/signer/signer/index.js +23 -0
  31. package/dist.commonjs/ckb/hash.d.ts +18 -0
  32. package/dist.commonjs/ckb/hash.d.ts.map +1 -0
  33. package/dist.commonjs/ckb/hash.js +22 -0
  34. package/dist.commonjs/ckb/index.d.ts +1 -0
  35. package/dist.commonjs/ckb/index.d.ts.map +1 -1
  36. package/dist.commonjs/ckb/index.js +1 -0
  37. package/dist.commonjs/ckb/transaction.d.ts +179 -11
  38. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  39. package/dist.commonjs/ckb/transaction.js +197 -59
  40. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  41. package/dist.commonjs/client/clientPublicMainnet.advanced.js +0 -60
  42. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +0 -23
  43. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  44. package/dist.commonjs/client/clientPublicTestnet.advanced.js +1 -145
  45. package/dist.commonjs/client/knownScript.d.ts +1 -3
  46. package/dist.commonjs/client/knownScript.d.ts.map +1 -1
  47. package/dist.commonjs/client/knownScript.js +0 -4
  48. package/dist.commonjs/hasher/hasherCkb.d.ts +0 -16
  49. package/dist.commonjs/hasher/hasherCkb.d.ts.map +1 -1
  50. package/dist.commonjs/hasher/hasherCkb.js +2 -21
  51. package/dist.commonjs/molecule/codec.d.ts +30 -10
  52. package/dist.commonjs/molecule/codec.d.ts.map +1 -1
  53. package/dist.commonjs/molecule/codec.js +46 -13
  54. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +18 -6
  55. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  56. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +18 -6
  57. package/dist.commonjs/signer/signer/index.d.ts +11 -1
  58. package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
  59. package/dist.commonjs/signer/signer/index.js +23 -0
  60. package/package.json +1 -1
  61. package/prettier.config.mjs +1 -1
  62. package/src/ckb/hash.ts +28 -0
  63. package/src/ckb/index.ts +1 -0
  64. package/src/ckb/transaction.ts +231 -52
  65. package/src/client/clientPublicMainnet.advanced.ts +0 -68
  66. package/src/client/clientPublicTestnet.advanced.ts +0 -163
  67. package/src/client/knownScript.ts +0 -5
  68. package/src/hasher/hasherCkb.ts +0 -26
  69. package/src/molecule/codec.ts +50 -13
  70. package/src/signer/ckb/signerCkbScriptReadonly.ts +24 -8
  71. package/src/signer/signer/index.ts +34 -0
@@ -235,29 +235,58 @@ export class CellOutput extends mol.Entity.Base<CellOutputLike, CellOutput>() {
235
235
 
236
236
  /**
237
237
  * Creates a CellOutput instance from a CellOutputLike object.
238
+ * This method supports automatic capacity calculation when capacity is 0 or omitted.
238
239
  *
239
240
  * @param cellOutput - A CellOutputLike object or an instance of CellOutput.
241
+ * Can also be an object without capacity when outputData is provided.
242
+ * @param outputData - Optional output data used for automatic capacity calculation.
243
+ * When provided and capacity is 0, the capacity will be calculated
244
+ * as occupiedSize + outputData.length.
240
245
  * @returns A CellOutput instance.
241
246
  *
242
247
  * @example
243
248
  * ```typescript
244
- * const cellOutput = CellOutput.from({
249
+ * // Basic usage with explicit capacity
250
+ * const cellOutput1 = CellOutput.from({
245
251
  * capacity: 1000n,
246
252
  * lock: { codeHash: "0x...", hashType: "type", args: "0x..." },
247
253
  * type: { codeHash: "0x...", hashType: "type", args: "0x..." }
248
254
  * });
255
+ *
256
+ * // Automatic capacity calculation
257
+ * const cellOutput2 = CellOutput.from({
258
+ * lock: { codeHash: "0x...", hashType: "type", args: "0x..." }
259
+ * }, "0x1234"); // Capacity will be calculated automatically
249
260
  * ```
250
261
  */
251
- static from(cellOutput: CellOutputLike): CellOutput {
262
+ static from(cellOutput: CellOutputLike, outputData?: HexLike): CellOutput;
263
+ static from(
264
+ cellOutput: Omit<CellOutputLike, "capacity"> &
265
+ Partial<Pick<CellOutputLike, "capacity">>,
266
+ outputData: HexLike,
267
+ ): CellOutput;
268
+ static from(
269
+ cellOutput: Omit<CellOutputLike, "capacity"> &
270
+ Partial<Pick<CellOutputLike, "capacity">>,
271
+ outputData?: HexLike,
272
+ ): CellOutput {
252
273
  if (cellOutput instanceof CellOutput) {
253
274
  return cellOutput;
254
275
  }
255
276
 
256
- return new CellOutput(
257
- numFrom(cellOutput.capacity),
277
+ const output = new CellOutput(
278
+ numFrom(cellOutput.capacity ?? 0),
258
279
  Script.from(cellOutput.lock),
259
280
  apply(Script.from, cellOutput.type),
260
281
  );
282
+
283
+ if (output.capacity === Zero) {
284
+ output.capacity = fixedPointFrom(
285
+ output.occupiedSize + bytesFrom(outputData ?? "0x").length,
286
+ );
287
+ }
288
+
289
+ return output;
261
290
  }
262
291
 
263
292
  /**
@@ -308,9 +337,37 @@ export class Cell {
308
337
 
309
338
  /**
310
339
  * Creates a Cell instance from a CellLike object.
340
+ * This method accepts either `outPoint` or `previousOutput` to specify the cell's location,
341
+ * and supports automatic capacity calculation for the cell output.
311
342
  *
312
- * @param cell - A CellLike object or an instance of Cell.
343
+ * @param cell - A CellLike object or an instance of Cell. The object can use either:
344
+ * - `outPoint`: For referencing a cell output
345
+ * - `previousOutput`: For referencing a cell input (alternative name for outPoint)
346
+ * The cellOutput can omit capacity for automatic calculation.
313
347
  * @returns A Cell instance.
348
+ *
349
+ * @example
350
+ * ```typescript
351
+ * // Using outPoint with explicit capacity
352
+ * const cell1 = Cell.from({
353
+ * outPoint: { txHash: "0x...", index: 0 },
354
+ * cellOutput: {
355
+ * capacity: 1000n,
356
+ * lock: { codeHash: "0x...", hashType: "type", args: "0x..." }
357
+ * },
358
+ * outputData: "0x"
359
+ * });
360
+ *
361
+ * // Using previousOutput with automatic capacity calculation
362
+ * const cell2 = Cell.from({
363
+ * previousOutput: { txHash: "0x...", index: 0 },
364
+ * cellOutput: {
365
+ * lock: { codeHash: "0x...", hashType: "type", args: "0x..." }
366
+ * // capacity will be calculated automatically
367
+ * },
368
+ * outputData: "0x1234"
369
+ * });
370
+ * ```
314
371
  */
315
372
 
316
373
  static from(cell: CellLike): Cell {
@@ -320,7 +377,7 @@ export class Cell {
320
377
 
321
378
  return new Cell(
322
379
  OutPoint.from("outPoint" in cell ? cell.outPoint : cell.previousOutput),
323
- CellOutput.from(cell.cellOutput),
380
+ CellOutput.from(cell.cellOutput, cell.outputData),
324
381
  hexFrom(cell.outputData),
325
382
  );
326
383
  }
@@ -1001,6 +1058,9 @@ export class Transaction extends mol.Entity.Base<
1001
1058
 
1002
1059
  /**
1003
1060
  * Copy every properties from another transaction.
1061
+ * This method replaces all properties of the current transaction with those from the provided transaction.
1062
+ *
1063
+ * @param txLike - The transaction-like object to copy properties from.
1004
1064
  *
1005
1065
  * @example
1006
1066
  * ```typescript
@@ -1092,19 +1152,9 @@ export class Transaction extends mol.Entity.Base<
1092
1152
  return tx;
1093
1153
  }
1094
1154
  const outputs =
1095
- tx.outputs?.map((output, i) => {
1096
- const o = CellOutput.from({
1097
- ...output,
1098
- capacity: output.capacity ?? 0,
1099
- });
1100
- if (o.capacity === Zero) {
1101
- o.capacity = fixedPointFrom(
1102
- o.occupiedSize +
1103
- (apply(bytesFrom, tx.outputsData?.[i])?.length ?? 0),
1104
- );
1105
- }
1106
- return o;
1107
- }) ?? [];
1155
+ tx.outputs?.map((output, i) =>
1156
+ CellOutput.from(output, tx.outputsData?.[i] ?? []),
1157
+ ) ?? [];
1108
1158
  const outputsData = outputs.map((_, i) =>
1109
1159
  hexFrom(tx.outputsData?.[i] ?? "0x"),
1110
1160
  );
@@ -1332,7 +1382,7 @@ export class Transaction extends mol.Entity.Base<
1332
1382
  *
1333
1383
  * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
1334
1384
  * @param client - The client for complete extra infos in the transaction.
1335
- * @returns A promise that resolves to the prepared transaction
1385
+ * @returns A promise that resolves to the found index, or undefined if no matching input is found.
1336
1386
  *
1337
1387
  * @example
1338
1388
  * ```typescript
@@ -1359,7 +1409,7 @@ export class Transaction extends mol.Entity.Base<
1359
1409
  *
1360
1410
  * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
1361
1411
  * @param client - The client for complete extra infos in the transaction.
1362
- * @returns A promise that resolves to the prepared transaction
1412
+ * @returns A promise that resolves to the found index, or undefined if no matching input is found.
1363
1413
  *
1364
1414
  * @example
1365
1415
  * ```typescript
@@ -1472,14 +1522,14 @@ export class Transaction extends mol.Entity.Base<
1472
1522
  * Set output data at index.
1473
1523
  *
1474
1524
  * @param index - The index of the output data.
1475
- * @param witness - The data to set.
1525
+ * @param data - The data to set.
1476
1526
  *
1477
1527
  * @example
1478
1528
  * ```typescript
1479
- * await tx.setOutputDataAt(0, "0x00");
1529
+ * tx.setOutputDataAt(0, "0x00");
1480
1530
  * ```
1481
1531
  */
1482
- setOutputDataAt(index: number, witness: HexLike): void {
1532
+ setOutputDataAt(index: number, data: HexLike): void {
1483
1533
  if (this.outputsData.length < index) {
1484
1534
  this.outputsData.push(
1485
1535
  ...Array.from(
@@ -1489,7 +1539,7 @@ export class Transaction extends mol.Entity.Base<
1489
1539
  );
1490
1540
  }
1491
1541
 
1492
- this.outputsData[index] = hexFrom(witness);
1542
+ this.outputsData[index] = hexFrom(data);
1493
1543
  }
1494
1544
 
1495
1545
  /**
@@ -1564,16 +1614,7 @@ export class Transaction extends mol.Entity.Base<
1564
1614
  Partial<Pick<CellOutputLike, "capacity">>,
1565
1615
  outputData: HexLike = "0x",
1566
1616
  ): number {
1567
- const output = CellOutput.from({
1568
- ...outputLike,
1569
- capacity: outputLike.capacity ?? 0,
1570
- });
1571
- if (output.capacity === Zero) {
1572
- output.capacity = fixedPointFrom(
1573
- output.occupiedSize + bytesFrom(outputData).length,
1574
- );
1575
- }
1576
- const len = this.outputs.push(output);
1617
+ const len = this.outputs.push(CellOutput.from(outputLike, outputData));
1577
1618
  this.setOutputDataAt(len - 1, outputData);
1578
1619
 
1579
1620
  return len;
@@ -1998,21 +2039,22 @@ export class Transaction extends mol.Entity.Base<
1998
2039
 
1999
2040
  let leastFee = Zero;
2000
2041
  let leastExtraCapacity = Zero;
2001
-
2042
+ let collected = 0;
2043
+
2044
+ // ===
2045
+ // Usually, for the worst situation, three iterations are needed
2046
+ // 1. First attempt to complete the transaction.
2047
+ // 2. Not enough capacity for the change cell.
2048
+ // 3. Fee increased by the change cell.
2049
+ // ===
2002
2050
  while (true) {
2003
- const tx = this.clone();
2004
- const collected = await (async () => {
2051
+ collected += await (async () => {
2005
2052
  if (!(options?.shouldAddInputs ?? true)) {
2006
- const fee =
2007
- (await tx.getFee(from.client)) - leastFee - leastExtraCapacity;
2008
- if (fee < Zero) {
2009
- throw new ErrorTransactionInsufficientCapacity(-fee);
2010
- }
2011
2053
  return 0;
2012
2054
  }
2013
2055
 
2014
2056
  try {
2015
- return await tx.completeInputsByCapacity(
2057
+ return await this.completeInputsByCapacity(
2016
2058
  from,
2017
2059
  leastFee + leastExtraCapacity,
2018
2060
  filter,
@@ -2031,21 +2073,33 @@ export class Transaction extends mol.Entity.Base<
2031
2073
  }
2032
2074
  })();
2033
2075
 
2034
- await from.prepareTransaction(tx);
2076
+ const fee = await this.getFee(from.client);
2077
+ if (fee < leastFee + leastExtraCapacity) {
2078
+ // Not enough capacity are collected, it should only happens when shouldAddInputs is false
2079
+ throw new ErrorTransactionInsufficientCapacity(
2080
+ leastFee + leastExtraCapacity - fee,
2081
+ { isForChange: leastExtraCapacity !== Zero },
2082
+ );
2083
+ }
2084
+
2085
+ await from.prepareTransaction(this);
2035
2086
  if (leastFee === Zero) {
2036
2087
  // The initial fee is calculated based on prepared transaction
2037
- leastFee = tx.estimateFee(feeRate);
2088
+ // This should only happens during the first iteration
2089
+ leastFee = this.estimateFee(feeRate);
2038
2090
  }
2039
- const fee = await tx.getFee(from.client);
2040
2091
  // The extra capacity paid the fee without a change
2092
+ // leastExtraCapacity should be 0 here, otherwise we should failed in the previous check
2093
+ // So this only happens in the first iteration
2041
2094
  if (fee === leastFee) {
2042
- this.copy(tx);
2043
2095
  return [collected, false];
2044
2096
  }
2045
2097
 
2098
+ // Invoke the change function on a transaction multiple times may cause problems, so we clone it
2099
+ const tx = this.clone();
2046
2100
  const needed = numFrom(await Promise.resolve(change(tx, fee - leastFee)));
2047
- // No enough extra capacity to create new cells for change
2048
2101
  if (needed > Zero) {
2102
+ // No enough extra capacity to create new cells for change, collect inputs again
2049
2103
  leastExtraCapacity = needed;
2050
2104
  continue;
2051
2105
  }
@@ -2073,6 +2127,38 @@ export class Transaction extends mol.Entity.Base<
2073
2127
  }
2074
2128
  }
2075
2129
 
2130
+ /**
2131
+ * Completes the transaction fee by adding inputs and creating a change output with the specified lock script.
2132
+ * This is a convenience method that automatically creates a change cell with the provided lock script
2133
+ * when there's excess capacity after paying the transaction fee.
2134
+ *
2135
+ * @param from - The signer to complete inputs from and prepare the transaction.
2136
+ * @param change - The lock script for the change output cell.
2137
+ * @param feeRate - Optional fee rate in shannons per 1000 bytes. If not provided, it will be fetched from the client.
2138
+ * @param filter - Optional filter for selecting cells when adding inputs.
2139
+ * @param options - Optional configuration object.
2140
+ * @param options.feeRateBlockRange - Block range for fee rate calculation when feeRate is not provided.
2141
+ * @param options.maxFeeRate - Maximum allowed fee rate.
2142
+ * @param options.shouldAddInputs - Whether to add inputs automatically. Defaults to true.
2143
+ * @returns A promise that resolves to a tuple containing:
2144
+ * - The number of inputs added during the process
2145
+ * - A boolean indicating whether change outputs were created (true) or fee was paid without change (false)
2146
+ *
2147
+ * @example
2148
+ * ```typescript
2149
+ * const changeScript = Script.from({
2150
+ * codeHash: "0x...",
2151
+ * hashType: "type",
2152
+ * args: "0x..."
2153
+ * });
2154
+ *
2155
+ * const [addedInputs, hasChange] = await tx.completeFeeChangeToLock(
2156
+ * signer,
2157
+ * changeScript,
2158
+ * 1000n // 1000 shannons per 1000 bytes
2159
+ * );
2160
+ * ```
2161
+ */
2076
2162
  completeFeeChangeToLock(
2077
2163
  from: Signer,
2078
2164
  change: ScriptLike,
@@ -2104,6 +2190,33 @@ export class Transaction extends mol.Entity.Base<
2104
2190
  );
2105
2191
  }
2106
2192
 
2193
+ /**
2194
+ * Completes the transaction fee using the signer's recommended address for change.
2195
+ * This is a convenience method that automatically uses the signer's recommended
2196
+ * address as the change destination, making it easier to complete transactions
2197
+ * without manually specifying a change address.
2198
+ *
2199
+ * @param from - The signer to complete inputs from and prepare the transaction.
2200
+ * @param feeRate - Optional fee rate in shannons per 1000 bytes. If not provided, it will be fetched from the client.
2201
+ * @param filter - Optional filter for selecting cells when adding inputs.
2202
+ * @param options - Optional configuration object.
2203
+ * @param options.feeRateBlockRange - Block range for fee rate calculation when feeRate is not provided.
2204
+ * @param options.maxFeeRate - Maximum allowed fee rate.
2205
+ * @param options.shouldAddInputs - Whether to add inputs automatically. Defaults to true.
2206
+ * @returns A promise that resolves to a tuple containing:
2207
+ * - The number of inputs added during the process
2208
+ * - A boolean indicating whether change outputs were created (true) or fee was paid without change (false)
2209
+ *
2210
+ * @example
2211
+ * ```typescript
2212
+ * const [addedInputs, hasChange] = await tx.completeFeeBy(
2213
+ * signer,
2214
+ * 1000n // 1000 shannons per 1000 bytes
2215
+ * );
2216
+ *
2217
+ * // Change will automatically go to signer's recommended address
2218
+ * ```
2219
+ */
2107
2220
  async completeFeeBy(
2108
2221
  from: Signer,
2109
2222
  feeRate?: NumLike,
@@ -2119,6 +2232,35 @@ export class Transaction extends mol.Entity.Base<
2119
2232
  return this.completeFeeChangeToLock(from, script, feeRate, filter, options);
2120
2233
  }
2121
2234
 
2235
+ /**
2236
+ * Completes the transaction fee by adding excess capacity to an existing output.
2237
+ * Instead of creating a new change output, this method adds any excess capacity
2238
+ * to the specified existing output in the transaction.
2239
+ *
2240
+ * @param from - The signer to complete inputs from and prepare the transaction.
2241
+ * @param index - The index of the existing output to add excess capacity to.
2242
+ * @param feeRate - Optional fee rate in shannons per 1000 bytes. If not provided, it will be fetched from the client.
2243
+ * @param filter - Optional filter for selecting cells when adding inputs.
2244
+ * @param options - Optional configuration object.
2245
+ * @param options.feeRateBlockRange - Block range for fee rate calculation when feeRate is not provided.
2246
+ * @param options.maxFeeRate - Maximum allowed fee rate.
2247
+ * @param options.shouldAddInputs - Whether to add inputs automatically. Defaults to true.
2248
+ * @returns A promise that resolves to a tuple containing:
2249
+ * - The number of inputs added during the process
2250
+ * - A boolean indicating whether change was applied (true) or fee was paid without change (false)
2251
+ *
2252
+ * @throws {Error} When the specified output index doesn't exist.
2253
+ *
2254
+ * @example
2255
+ * ```typescript
2256
+ * // Add excess capacity to the first output (index 0)
2257
+ * const [addedInputs, hasChange] = await tx.completeFeeChangeToOutput(
2258
+ * signer,
2259
+ * 0, // Output index
2260
+ * 1000n // 1000 shannons per 1000 bytes
2261
+ * );
2262
+ * ```
2263
+ */
2122
2264
  completeFeeChangeToOutput(
2123
2265
  from: Signer,
2124
2266
  index: NumLike,
@@ -2148,7 +2290,26 @@ export class Transaction extends mol.Entity.Base<
2148
2290
  }
2149
2291
 
2150
2292
  /**
2151
- * Calculate Nervos DAO profit between two blocks
2293
+ * Calculate Nervos DAO profit between two blocks.
2294
+ * This function computes the profit earned from a Nervos DAO deposit
2295
+ * based on the capacity and the time period between deposit and withdrawal.
2296
+ *
2297
+ * @param profitableCapacity - The capacity that earns profit (total capacity minus occupied capacity).
2298
+ * @param depositHeaderLike - The block header when the DAO deposit was made.
2299
+ * @param withdrawHeaderLike - The block header when the DAO withdrawal is made.
2300
+ * @returns The profit amount in CKB (capacity units).
2301
+ *
2302
+ * @example
2303
+ * ```typescript
2304
+ * const profit = calcDaoProfit(
2305
+ * ccc.fixedPointFrom(100), // 100 CKB profitable capacity
2306
+ * depositHeader,
2307
+ * withdrawHeader
2308
+ * );
2309
+ * console.log(`Profit: ${profit} shannons`);
2310
+ * ```
2311
+ *
2312
+ * @see {@link https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0023-dao-deposit-withdraw/0023-dao-deposit-withdraw.md | Nervos DAO RFC}
2152
2313
  */
2153
2314
  export function calcDaoProfit(
2154
2315
  profitableCapacity: NumLike,
@@ -2167,8 +2328,26 @@ export function calcDaoProfit(
2167
2328
  }
2168
2329
 
2169
2330
  /**
2170
- * Calculate claimable epoch for Nervos DAO withdrawal
2171
- * See https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0023-dao-deposit-withdraw/0023-dao-deposit-withdraw.md
2331
+ * Calculate claimable epoch for Nervos DAO withdrawal.
2332
+ * This function determines the earliest epoch when a Nervos DAO withdrawal
2333
+ * can be claimed based on the deposit and withdrawal epochs.
2334
+ *
2335
+ * @param depositHeader - The block header when the DAO deposit was made.
2336
+ * @param withdrawHeader - The block header when the DAO withdrawal was initiated.
2337
+ * @returns The epoch when the withdrawal can be claimed, represented as [number, index, length].
2338
+ *
2339
+ * @example
2340
+ * ```typescript
2341
+ * const claimEpoch = calcDaoClaimEpoch(depositHeader, withdrawHeader);
2342
+ * console.log(`Can claim at epoch: ${claimEpoch[0]}, index: ${claimEpoch[1]}, length: ${claimEpoch[2]}`);
2343
+ * ```
2344
+ *
2345
+ * @remarks
2346
+ * The Nervos DAO has a minimum lock period of 180 epochs (~30 days).
2347
+ * This function calculates the exact epoch when the withdrawal becomes claimable
2348
+ * based on the deposit epoch and withdrawal epoch timing.
2349
+ *
2350
+ * @see {@link https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0023-dao-deposit-withdraw/0023-dao-deposit-withdraw.md | Nervos DAO RFC}
2172
2351
  */
2173
2352
  export function calcDaoClaimEpoch(
2174
2353
  depositHeader: ClientBlockHeaderLike,
@@ -387,72 +387,4 @@ export const MAINNET_SCRIPTS: Record<KnownScript, ScriptInfoLike | undefined> =
387
387
  },
388
388
  ],
389
389
  },
390
- [KnownScript.RgbppLock]: {
391
- codeHash:
392
- "0xbc6c568a1a0d0a09f6844dc9d74ddb4343c32143ff25f727c59edf4fb72d6936",
393
- hashType: "type",
394
- cellDeps: [
395
- {
396
- cellDep: {
397
- outPoint: {
398
- txHash:
399
- "0x04c5c3e69f1aa6ee27fb9de3d15a81704e387ab3b453965adbe0b6ca343c6f41",
400
- index: 0,
401
- },
402
- depType: "code",
403
- },
404
- type: {
405
- codeHash:
406
- "0x00000000000000000000000000000000000000000000000000545950455f4944",
407
- hashType: "type",
408
- args: "0x68ad3d9e0bb9ea841a5d1fcd600137bd3f45401e759e353121f26cd0d981452f",
409
- },
410
- },
411
- // Rgbpp lock config cell dep
412
- {
413
- cellDep: {
414
- outPoint: {
415
- txHash:
416
- "0x04c5c3e69f1aa6ee27fb9de3d15a81704e387ab3b453965adbe0b6ca343c6f41",
417
- index: 1,
418
- },
419
- depType: "code",
420
- },
421
- },
422
- ],
423
- },
424
- [KnownScript.BtcTimeLock]: {
425
- codeHash:
426
- "0x70d64497a075bd651e98ac030455ea200637ee325a12ad08aff03f1a117e5a62",
427
- hashType: "type",
428
- cellDeps: [
429
- {
430
- cellDep: {
431
- outPoint: {
432
- txHash:
433
- "0x6257bf4297ee75fcebe2654d8c5f8d93bc9fc1b3dc62b8cef54ffe166162e996",
434
- index: 0,
435
- },
436
- depType: "code",
437
- },
438
- type: {
439
- codeHash:
440
- "0x00000000000000000000000000000000000000000000000000545950455f4944",
441
- hashType: "type",
442
- args: "0x44b8253ae18e913a2845b0d548eaf6b3ba1099ed26835888932a754194028a8a",
443
- },
444
- },
445
- // btc time lock config cell dep
446
- {
447
- cellDep: {
448
- outPoint: {
449
- txHash:
450
- "0x6257bf4297ee75fcebe2654d8c5f8d93bc9fc1b3dc62b8cef54ffe166162e996",
451
- index: 1,
452
- },
453
- depType: "code",
454
- },
455
- },
456
- ],
457
- },
458
390
  });
@@ -399,167 +399,4 @@ export const TESTNET_SCRIPTS: Record<KnownScript, ScriptInfoLike> =
399
399
  },
400
400
  ],
401
401
  },
402
- [KnownScript.RgbppLock]: {
403
- codeHash:
404
- "0x61ca7a4796a4eb19ca4f0d065cb9b10ddcf002f10f7cbb810c706cb6bb5c3248",
405
- hashType: "type",
406
- cellDeps: [
407
- {
408
- cellDep: {
409
- outPoint: {
410
- txHash:
411
- "0xf1de59e973b85791ec32debbba08dff80c63197e895eb95d67fc1e9f6b413e00",
412
- index: 0,
413
- },
414
- depType: "code",
415
- },
416
- type: {
417
- codeHash:
418
- "0x00000000000000000000000000000000000000000000000000545950455f4944",
419
- hashType: "type",
420
- args: "0xa3bc8441df149def76cfe15fec7b1e51d949548bc27fb7a75e9d4b3ef1c12c7f",
421
- },
422
- },
423
- // Rgbpp lock config cell dep for Bitcoin Testnet3
424
- {
425
- cellDep: {
426
- outPoint: {
427
- txHash:
428
- "0xf1de59e973b85791ec32debbba08dff80c63197e895eb95d67fc1e9f6b413e00",
429
- index: 1,
430
- },
431
- depType: "code",
432
- },
433
- },
434
- ],
435
- },
436
- [KnownScript.BtcTimeLock]: {
437
- codeHash:
438
- "0x00cdf8fab0f8ac638758ebf5ea5e4052b1d71e8a77b9f43139718621f6849326",
439
- hashType: "type",
440
- cellDeps: [
441
- {
442
- cellDep: {
443
- outPoint: {
444
- txHash:
445
- "0xde0f87878a97500f549418e5d46d2f7704c565a262aa17036c9c1c13ad638529",
446
- index: 0,
447
- },
448
- depType: "code",
449
- },
450
- type: {
451
- codeHash:
452
- "0x00000000000000000000000000000000000000000000000000545950455f4944",
453
- hashType: "type",
454
- args: "0xc9828585e6dd2afacb9e6e8ca7deb0975121aabee5c7983178a45509ffaec984",
455
- },
456
- },
457
- // btc time lock config cell dep for Bitcoin Testnet3
458
- {
459
- cellDep: {
460
- outPoint: {
461
- txHash:
462
- "0xde0f87878a97500f549418e5d46d2f7704c565a262aa17036c9c1c13ad638529",
463
- index: 1,
464
- },
465
- depType: "code",
466
- },
467
- },
468
- ],
469
- },
470
402
  });
471
-
472
- /**
473
- * Bitcoin Signet specific script overrides for testnet
474
- *
475
- * Contains script configurations that differ when using Bitcoin Signet
476
- * instead of Bitcoin Testnet3. Only RgbppLock and BtcTimeLock are affected.
477
- *
478
- * @example
479
- * ```typescript
480
- * import { ClientPublicTestnet } from "@ckb-ccc/core";
481
- * import { TESTNET_SCRIPTS, TESTNET_SCRIPTS_BTC_SIGNET_OVERRIDES } from "@ckb-ccc/core/advanced";
482
- *
483
- * // Use Bitcoin Testnet3 scripts (default)
484
- * const testnet3Client = new ClientPublicTestnet();
485
- *
486
- * // Use Bitcoin Signet scripts by merging overrides
487
- * const signetClient = new ClientPublicTestnet({
488
- * scripts: {
489
- * ...TESTNET_SCRIPTS,
490
- * ...TESTNET_SCRIPTS_BTC_SIGNET_OVERRIDES
491
- * }
492
- * });
493
- */
494
- export const TESTNET_SCRIPTS_BTC_SIGNET_OVERRIDES: Partial<
495
- Record<KnownScript, ScriptInfoLike>
496
- > = Object.freeze({
497
- [KnownScript.RgbppLock]: {
498
- codeHash:
499
- "0xd07598deec7ce7b5665310386b4abd06a6d48843e953c5cc2112ad0d5a220364",
500
- hashType: "type",
501
- cellDeps: [
502
- {
503
- cellDep: {
504
- outPoint: {
505
- txHash:
506
- "0x61efdeddbaa0bb4132c0eb174b3e8002ff5ec430f61ba46f30768d683c516eec",
507
- index: 0,
508
- },
509
- depType: "code",
510
- },
511
- type: {
512
- codeHash:
513
- "0x00000000000000000000000000000000000000000000000000545950455f4944",
514
- hashType: "type",
515
- args: "0xb69fe766ce3b7014a2a78ad1fe688d82f1679325805371d2856c3b8d18ebfa5a",
516
- },
517
- },
518
- // Rgbpp lock config cell dep for Bitcoin Signet
519
- {
520
- cellDep: {
521
- outPoint: {
522
- txHash:
523
- "0x61efdeddbaa0bb4132c0eb174b3e8002ff5ec430f61ba46f30768d683c516eec",
524
- index: 1,
525
- },
526
- depType: "code",
527
- },
528
- },
529
- ],
530
- },
531
- [KnownScript.BtcTimeLock]: {
532
- codeHash:
533
- "0x80a09eca26d77cea1f5a69471c59481be7404febf40ee90f886c36a948385b55",
534
- hashType: "type",
535
- cellDeps: [
536
- {
537
- cellDep: {
538
- outPoint: {
539
- txHash:
540
- "0x5364b3535965e9eac9a35dd7af8e9e45a61d30a16e115923c032f80b28783e21",
541
- index: 0,
542
- },
543
- depType: "code",
544
- },
545
- type: {
546
- codeHash:
547
- "0x00000000000000000000000000000000000000000000000000545950455f4944",
548
- hashType: "type",
549
- args: "0x32fc8c70a6451a1439fd91e214bba093f9cdd9276bc4ab223430dab5940aff92",
550
- },
551
- },
552
- // btc time lock config cell dep for Bitcoin Signet
553
- {
554
- cellDep: {
555
- outPoint: {
556
- txHash:
557
- "0x5364b3535965e9eac9a35dd7af8e9e45a61d30a16e115923c032f80b28783e21",
558
- index: 1,
559
- },
560
- depType: "code",
561
- },
562
- },
563
- ],
564
- },
565
- });
@@ -25,9 +25,4 @@ export enum KnownScript {
25
25
  TypeBurnLock = "TypeBurnLock",
26
26
  EasyToDiscoverType = "EasyToDiscoverType",
27
27
  TimeLock = "TimeLock",
28
-
29
- // RGB++ related scripts (default using Bitcoin Testnet3)
30
- // For Bitcoin Signet, use TESTNET_SCRIPTS_BTC_SIGNET_OVERRIDES from @ckb-ccc/core/advanced
31
- RgbppLock = "RgbppLock",
32
- BtcTimeLock = "BtcTimeLock",
33
28
  }