Skip to content

Commit 864f26b

Browse files
committed
refactor: migrate from UdtHandler to IckbUdt across packages
- Remove udtHandler parameter from LogicManager and OwnedOwnerManager constructors; callers now manage UDT cellDeps via IckbUdt.addCellDeps() - Replace UdtHandler with plain udtScript in OrderManager - Wire getConfig() to construct IckbUdt with code OutPoints, computing the UDT type script dynamically via IckbUdt.typeScriptFrom() - Delete UDT infrastructure from @ickb/utils (UdtHandler, UdtManager, UdtCell, ErrorTransactionInsufficientCoin) — all superseded by CCC
1 parent 951d938 commit 864f26b

6 files changed

Lines changed: 91 additions & 443 deletions

File tree

packages/core/src/logic.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { DaoManager } from "@ickb/dao";
33
import {
44
defaultFindCellsLimit,
55
type ScriptDeps,
6-
type UdtHandler,
76
unique,
87
} from "@ickb/utils";
98
import {
@@ -25,13 +24,11 @@ export class LogicManager implements ScriptDeps {
2524
* @param script - The script associated with the manager.
2625
* @param cellDeps - The cell dependencies for the manager.
2726
* @param daoManager - The DAO manager for handling deposits and receipts.
28-
* @param udtHandler - The handler for User Defined Tokens (UDTs).
2927
*/
3028
constructor(
3129
public readonly script: ccc.Script,
3230
public readonly cellDeps: ccc.CellDep[],
3331
public readonly daoManager: DaoManager,
34-
public readonly udtHandler: UdtHandler,
3532
) {}
3633

3734
/**
@@ -63,6 +60,9 @@ export class LogicManager implements ScriptDeps {
6360
* @param depositQuantity - The quantity of deposits.
6461
* @param depositAmount - The amount of each deposit.
6562
* @param lock - The lock script for the output receipt cell.
63+
*
64+
* @remarks Caller must ensure UDT cellDeps are added to the transaction
65+
* (e.g., via ickbUdt.addCellDeps(tx)).
6666
*/
6767
async deposit(
6868
txLike: ccc.TransactionLike,
@@ -85,7 +85,6 @@ export class LogicManager implements ScriptDeps {
8585
}
8686

8787
tx.addCellDeps(this.cellDeps);
88-
tx.addCellDeps(this.udtHandler.cellDeps);
8988

9089
const capacities = Array.from(
9190
{ length: depositQuantity },
@@ -111,6 +110,9 @@ export class LogicManager implements ScriptDeps {
111110
*
112111
* @param txLike - The transaction to add the receipts to.
113112
* @param receipts - The receipts to add to the transaction.
113+
*
114+
* @remarks Caller must ensure UDT cellDeps are added to the transaction
115+
* (e.g., via ickbUdt.addCellDeps(tx)).
114116
*/
115117
completeDeposit(
116118
txLike: ccc.TransactionLike,
@@ -122,7 +124,6 @@ export class LogicManager implements ScriptDeps {
122124
}
123125

124126
tx.addCellDeps(this.cellDeps);
125-
tx.addCellDeps(this.udtHandler.cellDeps);
126127

127128
for (const r of receipts) {
128129
const hash = r.header.header.hash;

packages/core/src/owned_owner.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
defaultFindCellsLimit,
44
unique,
55
type ScriptDeps,
6-
type UdtHandler,
76
} from "@ickb/utils";
87
import { daoCellFrom, DaoManager } from "@ickb/dao";
98
import { OwnerData } from "./entities.js";
@@ -20,13 +19,11 @@ export class OwnedOwnerManager implements ScriptDeps {
2019
* @param script - The script associated with the OwnedOwner script.
2120
* @param cellDeps - The cell dependencies for the OwnedOwner script.
2221
* @param daoManager - The DAO manager for handling withdrawal requests.
23-
* @param udtHandler - The handler for User Defined Tokens (UDTs).
2422
*/
2523
constructor(
2624
public readonly script: ccc.Script,
2725
public readonly cellDeps: ccc.CellDep[],
2826
public readonly daoManager: DaoManager,
29-
public readonly udtHandler: UdtHandler,
3027
) {}
3128

3229
/**
@@ -64,6 +61,9 @@ export class OwnedOwnerManager implements ScriptDeps {
6461
* @param options - Optional parameters for the withdrawal request.
6562
* @param options.isReadyOnly - Whether to only process ready deposits (default: false).
6663
* @returns void
64+
*
65+
* @remarks Caller must ensure UDT cellDeps are added to the transaction
66+
* (e.g., via ickbUdt.addCellDeps(tx)).
6767
*/
6868
async requestWithdrawal(
6969
txLike: ccc.TransactionLike,
@@ -92,7 +92,6 @@ export class OwnedOwnerManager implements ScriptDeps {
9292
options,
9393
);
9494
tx.addCellDeps(this.cellDeps);
95-
tx.addCellDeps(this.udtHandler.cellDeps);
9695

9796
const outputData = OwnerData.encode({ ownedDistance: -deposits.length });
9897
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -118,6 +117,9 @@ export class OwnedOwnerManager implements ScriptDeps {
118117
* @param options - Optional parameters for the withdrawal process.
119118
* @param options.isReadyOnly - Whether to only process ready withdrawal groups (default: false).
120119
* @returns void
120+
*
121+
* @remarks Caller must ensure UDT cellDeps are added to the transaction
122+
* (e.g., via ickbUdt.addCellDeps(tx)).
121123
*/
122124
async withdraw(
123125
txLike: ccc.TransactionLike,
@@ -137,7 +139,6 @@ export class OwnedOwnerManager implements ScriptDeps {
137139
}
138140

139141
tx.addCellDeps(this.cellDeps);
140-
tx.addCellDeps(this.udtHandler.cellDeps);
141142

142143
const requests = withdrawalGroups.map((g) => g.owned);
143144
tx = await this.daoManager.withdraw(tx, requests, client);

packages/order/src/order.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
defaultFindCellsLimit,
55
type ExchangeRatio,
66
type ScriptDeps,
7-
type UdtHandler,
87
type ValueComponents,
98
} from "@ickb/utils";
109
import { Info, OrderData, Ratio, Relative, type InfoLike } from "./entities.js";
@@ -19,12 +18,12 @@ export class OrderManager implements ScriptDeps {
1918
*
2019
* @param script - The order script.
2120
* @param cellDeps - The cell dependencies for the order.
22-
* @param udtHandler - The handler for UDT (User Defined Token).
21+
* @param udtScript - The UDT (User Defined Token) type script.
2322
*/
2423
constructor(
2524
public readonly script: ccc.Script,
2625
public readonly cellDeps: ccc.CellDep[],
27-
public readonly udtHandler: UdtHandler,
26+
public readonly udtScript: ccc.Script,
2827
) {}
2928

3029
/**
@@ -39,7 +38,7 @@ export class OrderManager implements ScriptDeps {
3938
isOrder(cell: ccc.Cell): boolean {
4039
return (
4140
cell.cellOutput.lock.eq(this.script) &&
42-
Boolean(cell.cellOutput.type?.eq(this.udtHandler.script))
41+
Boolean(cell.cellOutput.type?.eq(this.udtScript))
4342
);
4443
}
4544

@@ -156,10 +155,12 @@ export class OrderManager implements ScriptDeps {
156155
*
157156
* The method performs the following:
158157
* - Creates order data using the provided amounts and order information.
159-
* - Adds required cell dependencies and UDT handlers to the transaction.
158+
* - Adds required cell dependencies to the transaction.
160159
* - Appends the order cell to the outputs with the UDT data and adjusts the CKB capacity.
161160
* - Appends a corresponding master cell immediately after the order cell.
162161
*
162+
* @remarks Caller must ensure UDT cellDeps are added to the transaction (e.g., via CCC Udt balance completion).
163+
*
163164
* @param txLike - The transaction to which the order will be added.
164165
* @param lock - The lock script for the master cell.
165166
* @param info - The information related to the order, usually calculated using OrderManager.convert.
@@ -187,13 +188,12 @@ export class OrderManager implements ScriptDeps {
187188
});
188189

189190
tx.addCellDeps(this.cellDeps);
190-
tx.addCellDeps(this.udtHandler.cellDeps);
191191

192192
// Append order cell to Outputs
193193
const position = tx.addOutput(
194194
{
195195
lock: this.script,
196-
type: this.udtHandler.script,
196+
type: this.udtScript,
197197
},
198198
data.toBytes(),
199199
);
@@ -215,6 +215,8 @@ export class OrderManager implements ScriptDeps {
215215
* - Adds the original order as an input.
216216
* - Creates an updated output with adjusted CKB capacity and UDT data.
217217
*
218+
* @remarks Caller must ensure UDT cellDeps are added to the transaction (e.g., via CCC Udt balance completion).
219+
*
218220
* @param txLike - The transaction to which the matches will be added.
219221
* @param match - The match object containing partial matches.
220222
*/
@@ -226,14 +228,13 @@ export class OrderManager implements ScriptDeps {
226228
}
227229

228230
tx.addCellDeps(this.cellDeps);
229-
tx.addCellDeps(this.udtHandler.cellDeps);
230231

231232
for (const { order, ckbOut, udtOut } of partials) {
232233
tx.addInput(order.cell);
233234
tx.addOutput(
234235
{
235236
lock: this.script,
236-
type: this.udtHandler.script,
237+
type: this.udtScript,
237238
capacity: ckbOut,
238239
},
239240
OrderData.from({
@@ -495,6 +496,8 @@ export class OrderManager implements ScriptDeps {
495496
*
496497
* @param txLike - The transaction to which the groups will be added.
497498
* @param groups - The array of OrderGroup instances to melt.
499+
* @remarks Caller must ensure UDT cellDeps are added to the transaction (e.g., via CCC Udt balance completion).
500+
*
498501
* @param options - Optional parameters:
499502
* @param options.isFulfilledOnly - If true, only groups with fulfilled orders will be melted.
500503
*
@@ -516,7 +519,6 @@ export class OrderManager implements ScriptDeps {
516519
return tx;
517520
}
518521
tx.addCellDeps(this.cellDeps);
519-
tx.addCellDeps(this.udtHandler.cellDeps);
520522

521523
for (const group of groups) {
522524
tx.addInput(group.order.cell);
@@ -615,7 +617,7 @@ export class OrderManager implements ScriptDeps {
615617
* Finds simple orders on the blockchain.
616618
*
617619
* Queries cells whose lock script equals the order script and whose type script
618-
* matches the UDT handler's script, returning only valid {@link OrderCell} instances.
620+
* matches the UDT type script, returning only valid {@link OrderCell} instances.
619621
*
620622
* @param client – The client used to interact with the blockchain.
621623
* @param limit – Maximum cells to scan per findCells batch.
@@ -632,7 +634,7 @@ export class OrderManager implements ScriptDeps {
632634
script: this.script,
633635
scriptType: "lock",
634636
filter: {
635-
script: this.udtHandler.script,
637+
script: this.udtScript,
636638
},
637639
scriptSearchMode: "exact",
638640
withData: true,

packages/sdk/src/constants.ts

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ccc } from "@ckb-ccc/core";
2-
import { IckbUdtManager, LogicManager, OwnedOwnerManager } from "@ickb/core";
2+
import { IckbUdt, LogicManager, OwnedOwnerManager } from "@ickb/core";
33
import { DaoManager } from "@ickb/dao";
44
import { OrderManager } from "@ickb/order";
55
import { unique, type ScriptDeps } from "@ickb/utils";
@@ -34,13 +34,16 @@ export function getConfig(
3434
): {
3535
managers: {
3636
dao: DaoManager;
37-
ickbUdt: IckbUdtManager;
37+
ickbUdt: IckbUdt;
3838
logic: LogicManager;
3939
ownedOwner: OwnedOwnerManager;
4040
order: OrderManager;
4141
};
4242
bots: ccc.Script[];
4343
} {
44+
// Capture network before d gets reassigned to ScriptDeps.
45+
const network = typeof d === "string" ? d : undefined;
46+
4447
// If deps is provided as a network string, use the pre-defined constants.
4548
if (d === "mainnet" || d === "testnet") {
4649
bots = bots.concat(
@@ -57,25 +60,30 @@ export function getConfig(
5760
}
5861

5962
const dao = new DaoManager(d.dao.script, d.dao.cellDeps);
60-
const ickbUdt = new IckbUdtManager(
61-
d.udt.script,
62-
d.udt.cellDeps,
63-
d.logic.script,
64-
dao,
65-
);
66-
const logic = new LogicManager(
63+
const ickbUdt = new IckbUdt(
64+
// xUDT code cell OutPoint: use known constants for mainnet/testnet,
65+
// fall back to first cellDep's outPoint for devnet.
66+
network
67+
? (network === "mainnet" ? MAINNET_XUDT_CODE : TESTNET_XUDT_CODE)
68+
: d.udt.cellDeps[0]?.outPoint ?? ((): never => { throw new Error("devnet config missing xUDT code cell outPoint in udt.cellDeps"); })(),
69+
IckbUdt.typeScriptFrom(
70+
ccc.Script.from(d.udt.script),
71+
ccc.Script.from(d.logic.script),
72+
),
73+
// iCKB Logic code cell OutPoint: same pattern as above.
74+
network
75+
? (network === "mainnet" ? MAINNET_LOGIC_CODE : TESTNET_LOGIC_CODE)
76+
: d.logic.cellDeps[0]?.outPoint ?? ((): never => { throw new Error("devnet config missing Logic code cell outPoint in logic.cellDeps"); })(),
6777
d.logic.script,
68-
d.logic.cellDeps,
6978
dao,
70-
ickbUdt,
7179
);
80+
const logic = new LogicManager(d.logic.script, d.logic.cellDeps, dao);
7281
const ownedOwner = new OwnedOwnerManager(
7382
d.ownedOwner.script,
7483
d.ownedOwner.cellDeps,
7584
dao,
76-
ickbUdt,
7785
);
78-
const order = new OrderManager(d.order.script, d.order.cellDeps, ickbUdt);
86+
const order = new OrderManager(d.order.script, d.order.cellDeps, ickbUdt.script);
7987

8088
return {
8189
managers: {
@@ -114,13 +122,15 @@ const DAO = {
114122
};
115123

116124
/**
117-
* UDT (User Defined Token) lock script information used for onchain validation.
125+
* Raw xUDT type script (codeHash + hashType only).
126+
* The iCKB UDT type script args are computed dynamically by
127+
* IckbUdt.typeScriptFrom() from ICKB_LOGIC.
118128
*/
119129
const UDT = {
120130
codeHash:
121131
"0x50bd8d6680b8b9cf98b73f3c08faf8b2a21914311954118ad6609be6e78a1b95",
122132
hashType: "data1",
123-
args: "0xb73b6ab39d79390c6de90a09c96b290c331baf1798ed6f97aed02590929734e800000080",
133+
args: "0x",
124134
};
125135

126136
/**
@@ -153,6 +163,46 @@ const ORDER = {
153163
args: "0x",
154164
};
155165

166+
/**
167+
* Mainnet xUDT code cell OutPoint.
168+
* Source: forks/contracts/scripts/deployment/mainnet/deployment.toml
169+
*/
170+
const MAINNET_XUDT_CODE = {
171+
txHash:
172+
"0xc07844ce21b38e4b071dd0e1ee3b0e27afd8d7532491327f39b786343f558ab7",
173+
index: "0x0",
174+
};
175+
176+
/**
177+
* Mainnet iCKB Logic code cell OutPoint.
178+
* Source: forks/contracts/scripts/deployment/mainnet/deployment.toml
179+
*/
180+
const MAINNET_LOGIC_CODE = {
181+
txHash:
182+
"0xd7309191381f5a8a2904b8a79958a9be2752dbba6871fa193dab6aeb29dc8f44",
183+
index: "0x0",
184+
};
185+
186+
/**
187+
* Testnet xUDT code cell OutPoint.
188+
* Source: forks/contracts/scripts/deployment/testnet/deployment.toml
189+
*/
190+
const TESTNET_XUDT_CODE = {
191+
txHash:
192+
"0xbf6fb538763efec2a70a6a3dcb7242787087e1030c4e7d86585bc63a9d337f5f",
193+
index: "0x0",
194+
};
195+
196+
/**
197+
* Testnet iCKB Logic code cell OutPoint.
198+
* Source: forks/contracts/scripts/deployment/testnet/deployment.toml
199+
*/
200+
const TESTNET_LOGIC_CODE = {
201+
txHash:
202+
"0x9ac989b3355764f76cdce02c69dedb819fdfbcbda49a7db1a2c9facdfdb9a7fe",
203+
index: "0x0",
204+
};
205+
156206
/**
157207
* Mainnet dependency group cell dep.
158208
*/

packages/utils/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export * from "./codec.js";
22
export * from "./heap.js";
3-
export * from "./udt.js";
43
export * from "./utils.js";

0 commit comments

Comments
 (0)