@ickb/sdk 1000.0.52 → 1000.0.71
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/dist/cjs/codec.d.ts +14 -0
- package/dist/cjs/codec.d.ts.map +1 -0
- package/dist/cjs/codec.js +125 -0
- package/dist/cjs/codec.js.map +1 -0
- package/dist/cjs/constants.d.ts +49 -0
- package/dist/cjs/constants.d.ts.map +1 -0
- package/dist/cjs/constants.js +156 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/index.d.ts +3 -189
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +17 -338
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/sdk.d.ts +178 -0
- package/dist/cjs/sdk.d.ts.map +1 -0
- package/dist/cjs/sdk.js +362 -0
- package/dist/cjs/sdk.js.map +1 -0
- package/dist/esm/codec.d.ts +14 -0
- package/dist/esm/codec.d.ts.map +1 -0
- package/dist/esm/codec.js +122 -0
- package/dist/esm/codec.js.map +1 -0
- package/dist/esm/constants.d.ts +49 -0
- package/dist/esm/constants.d.ts.map +1 -0
- package/dist/esm/constants.js +152 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/index.d.ts +3 -189
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +3 -336
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/sdk.d.ts +178 -0
- package/dist/esm/sdk.d.ts.map +1 -0
- package/dist/esm/sdk.js +358 -0
- package/dist/esm/sdk.js.map +1 -0
- package/package.json +8 -8
- package/src/codec.ts +138 -0
- package/src/constants.ts +200 -0
- package/src/index.ts +3 -573
- package/src/sdk.ts +513 -0
package/dist/esm/index.js
CHANGED
|
@@ -1,337 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { DaoManager } from "@ickb/dao";
|
|
5
|
-
import { Info, OrderManager, } from "@ickb/order";
|
|
6
|
-
/**
|
|
7
|
-
* Controller for managing iCKB operations.
|
|
8
|
-
*/
|
|
9
|
-
export class IckbController {
|
|
10
|
-
/**
|
|
11
|
-
* Creates an instance of IckbController.
|
|
12
|
-
* @param ickbUdtManager - The manager for iCKB UDT operations.
|
|
13
|
-
* @param logicManager - The logic manager for handling business logic.
|
|
14
|
-
* @param ownedOwnerManager - The manager for owned owner operations.
|
|
15
|
-
* @param orderManager - The manager for order operations.
|
|
16
|
-
* @param daoManager - The manager for DAO operations.
|
|
17
|
-
*/
|
|
18
|
-
constructor(ickbUdtManager, logicManager, ownedOwnerManager, orderManager, daoManager, bots) {
|
|
19
|
-
this.ickbUdtManager = ickbUdtManager;
|
|
20
|
-
this.logicManager = logicManager;
|
|
21
|
-
this.ownedOwnerManager = ownedOwnerManager;
|
|
22
|
-
this.orderManager = orderManager;
|
|
23
|
-
this.daoManager = daoManager;
|
|
24
|
-
this.bots = bots;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Creates an instance of IckbController from script dependencies.
|
|
28
|
-
* @param deps - The script dependencies.
|
|
29
|
-
* @param deps.udt - The script dependencies for UDT.
|
|
30
|
-
* @param deps.dao - The script dependencies for DAO.
|
|
31
|
-
* @param deps.ickbLogic - The script dependencies for iCKB logic.
|
|
32
|
-
* @param deps.ownedOwner - The script dependencies for owned owner.
|
|
33
|
-
* @param deps.order - The script dependencies for order.
|
|
34
|
-
* @returns An instance of IckbController.
|
|
35
|
-
*/
|
|
36
|
-
static fromDeps(deps, bots) {
|
|
37
|
-
const { udt: { script: { codeHash, hashType }, cellDeps, }, ickbLogic: { script: ickbLogicScript }, } = deps;
|
|
38
|
-
const daoManager = DaoManager.fromDeps(deps);
|
|
39
|
-
const udt = {
|
|
40
|
-
script: new ccc.Script(codeHash, hashType, [ickbLogicScript.hash(), "00000080"].join("")),
|
|
41
|
-
cellDeps,
|
|
42
|
-
};
|
|
43
|
-
const ickbUdtManager = IckbUdtManager.fromDeps({ udt }, daoManager);
|
|
44
|
-
return new IckbController(ickbUdtManager, LogicManager.fromDeps(deps, daoManager, ickbUdtManager), OwnedOwnerManager.fromDeps(deps, daoManager, ickbUdtManager), OrderManager.fromDeps(deps, ickbUdtManager), daoManager, bots);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Previews the conversion between CKB and UDT.
|
|
48
|
-
* @param conversion - The conversion parameters.
|
|
49
|
-
* @param conversion.isCkb2Udt - Indicates if the conversion is from CKB to UDT.
|
|
50
|
-
* @param conversion.amount - The amount to convert.
|
|
51
|
-
* @param conversion.rate - The exchange rate for conversion.
|
|
52
|
-
* @param conversion.fee - The fee for the conversion.
|
|
53
|
-
* @returns The rate and converted amount.
|
|
54
|
-
*
|
|
55
|
-
* Fee meaning examples:
|
|
56
|
-
* - 100000n => 0.001%
|
|
57
|
-
* - 10000n => 0.01%
|
|
58
|
-
* - 1000n => 0.1%
|
|
59
|
-
* - 100n => 1%
|
|
60
|
-
* - 10n => 10%
|
|
61
|
-
* - 1n => 100%
|
|
62
|
-
* - less than 1n => 0%
|
|
63
|
-
*/
|
|
64
|
-
static previewConversion(conversion) {
|
|
65
|
-
const { isCkb2Udt, amount, fee } = conversion;
|
|
66
|
-
let rate = conversion.rate;
|
|
67
|
-
rate = "dao" in rate ? ickbExchangeRatio(rate) : rate;
|
|
68
|
-
if (fee > ccc.Zero) {
|
|
69
|
-
const { ckbScale, udtScale } = rate;
|
|
70
|
-
rate = {
|
|
71
|
-
ckbScale,
|
|
72
|
-
// Worst case scenario where fee applies to the full amount
|
|
73
|
-
udtScale: udtScale + (isCkb2Udt ? 1n : -1n) * (udtScale / fee),
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
const convertedAmount = amount > ccc.Zero ? convert(isCkb2Udt, amount, rate) : ccc.Zero;
|
|
77
|
-
return { rate, convertedAmount };
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Converts between CKB and UDT based on the provided options.
|
|
81
|
-
* @param options - The conversion options.
|
|
82
|
-
* @param options.conversion - The conversion parameters.
|
|
83
|
-
* @param options.conversion.isCkb2Udt - Indicates if the conversion is from CKB to UDT.
|
|
84
|
-
* @param options.conversion.amount - The amount to convert.
|
|
85
|
-
* @param options.conversion.rate - The exchange rate for conversion.
|
|
86
|
-
* @param options.conversion.ckbMinMatchLog - Minimum CKB match log (optional).
|
|
87
|
-
* @param options.conversion.ckbMinFee - Minimum CKB fee (optional).
|
|
88
|
-
* @param options.signer - The signer for the transaction.
|
|
89
|
-
* @param options.userCells - The user's cells.
|
|
90
|
-
* @param options.system - The current system state.
|
|
91
|
-
* @param options.filters - The filters for the conversion.
|
|
92
|
-
* @param options.filters.isReadyOnly - Indicates if only ready conversions should be considered.
|
|
93
|
-
* @param options.filters.isFulfilledOnly - Indicates if only fulfilled conversions should be considered.
|
|
94
|
-
* @returns A promise that resolves to the conversion result or undefined.
|
|
95
|
-
*/
|
|
96
|
-
async convert(options) {
|
|
97
|
-
// Get user lock
|
|
98
|
-
const { system, signer } = options;
|
|
99
|
-
const lock = (await signer.getRecommendedAddressObj()).script;
|
|
100
|
-
// Normalize rate
|
|
101
|
-
const { rate } = IckbController.previewConversion({
|
|
102
|
-
...options.conversion,
|
|
103
|
-
amount: ccc.Zero,
|
|
104
|
-
});
|
|
105
|
-
const { isCkb2Udt, amount, ckbMinMatchLog } = options.conversion;
|
|
106
|
-
const info = Info.create(isCkb2Udt, rate, ckbMinMatchLog);
|
|
107
|
-
// feeRate is a good approximation of the bot tx size matching the order
|
|
108
|
-
const ckbMinFee = options.conversion.ckbMinFee ?? 10n * system.feeRate;
|
|
109
|
-
const conversion = {
|
|
110
|
-
isCkb2Udt,
|
|
111
|
-
amount,
|
|
112
|
-
rate,
|
|
113
|
-
info,
|
|
114
|
-
ckbMinFee,
|
|
115
|
-
lock,
|
|
116
|
-
};
|
|
117
|
-
const N = isCkb2Udt
|
|
118
|
-
? Number(amount / system.ckbDepositCap)
|
|
119
|
-
: system.depositPool.slice(0, 30).length;
|
|
120
|
-
const cache = Array(N);
|
|
121
|
-
const cachedAttempt = (n) => {
|
|
122
|
-
n = N - n;
|
|
123
|
-
return (cache[n] = cache[n] ?? this.attempt(n, conversion, options));
|
|
124
|
-
};
|
|
125
|
-
return cachedAttempt(await asyncBinarySearch(N, async (n) => (await cachedAttempt(n)) !== undefined));
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Attempts to perform a conversion based on the provided parameters.
|
|
129
|
-
* @param n - The size of deposit to make or withdraw from.
|
|
130
|
-
* @param conversion - The conversion parameters.
|
|
131
|
-
* @param conversion.isCkb2Udt - Indicates if the conversion is from CKB to UDT.
|
|
132
|
-
* @param conversion.amount - The amount to convert.
|
|
133
|
-
* @param conversion.rate - The exchange rate for conversion.
|
|
134
|
-
* @param conversion.info - Additional information for the conversion.
|
|
135
|
-
* @param conversion.ckbMinFee - Minimum CKB fee.
|
|
136
|
-
* @param conversion.lock - The script lock for the transaction.
|
|
137
|
-
* @param options - Additional options for the conversion.
|
|
138
|
-
* @returns A promise that resolves to the conversion result or undefined.
|
|
139
|
-
*/
|
|
140
|
-
async attempt(n, conversion, options) {
|
|
141
|
-
try {
|
|
142
|
-
const { isCkb2Udt, rate, info, ckbMinFee, lock } = conversion;
|
|
143
|
-
const { signer, userCells, filters, system } = options;
|
|
144
|
-
const { feeRate, ckbDepositCap, exchangeRatio, depositPool } = system;
|
|
145
|
-
const tx = SmartTransaction.default();
|
|
146
|
-
const maturities = [[0n, 1n, 80n]]; // 3 minutes minimum
|
|
147
|
-
let ckbFee = ccc.Zero;
|
|
148
|
-
let amount = conversion.amount;
|
|
149
|
-
let udtWithdrawed = ccc.Zero;
|
|
150
|
-
// Core protocol
|
|
151
|
-
if (n > 0) {
|
|
152
|
-
if (isCkb2Udt) {
|
|
153
|
-
amount -= ckbDepositCap * BigInt(n);
|
|
154
|
-
if (amount < ccc.Zero) {
|
|
155
|
-
// Too many Deposits respectfully to the amount
|
|
156
|
-
return undefined;
|
|
157
|
-
}
|
|
158
|
-
this.logicManager.deposit(tx, n, ckbDepositCap, lock);
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
const myDeposits = depositPool.slice(0, n);
|
|
162
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
163
|
-
udtWithdrawed = myDeposits.slice(-1)[0].udtCumulative;
|
|
164
|
-
amount -= udtWithdrawed;
|
|
165
|
-
if (amount < ccc.Zero) {
|
|
166
|
-
// Too many Withdrawal Requests respectfully to the amount
|
|
167
|
-
return undefined;
|
|
168
|
-
}
|
|
169
|
-
this.ownedOwnerManager.requestWithdrawal(tx, myDeposits, lock);
|
|
170
|
-
maturities.push(...myDeposits.map((d) => d.maturity));
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
// Order protocol
|
|
174
|
-
if (amount > ccc.Zero) {
|
|
175
|
-
this.orderManager.mint(tx, lock, info, {
|
|
176
|
-
ckbValue: isCkb2Udt ? amount : ccc.Zero,
|
|
177
|
-
udtValue: isCkb2Udt ? ccc.Zero : amount,
|
|
178
|
-
});
|
|
179
|
-
const convertedAmount = convert(isCkb2Udt, amount, rate);
|
|
180
|
-
ckbFee = isCkb2Udt
|
|
181
|
-
? amount - convert(false, convertedAmount, exchangeRatio)
|
|
182
|
-
: convert(true, amount, exchangeRatio) - convertedAmount;
|
|
183
|
-
maturities.push(orderMaturityEstimate(isCkb2Udt, amount, udtWithdrawed, system));
|
|
184
|
-
// Check that order provides enough fee to the bot for being matched
|
|
185
|
-
if (ckbFee < ckbMinFee) {
|
|
186
|
-
return undefined;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
const { receipts, withdrawalGroups, orders, udts, capacities } = userCells;
|
|
190
|
-
this.logicManager.completeDeposit(tx, receipts);
|
|
191
|
-
this.ownedOwnerManager.withdraw(tx, withdrawalGroups, filters);
|
|
192
|
-
this.orderManager.melt(tx, orders, filters);
|
|
193
|
-
this.ickbUdtManager.addUdts(tx, udts);
|
|
194
|
-
CapacityManager.addCapacities(tx, capacities);
|
|
195
|
-
// Throw an error if inputs do not cover for outputs
|
|
196
|
-
await new RestrictedTransaction(tx).completeFeeBy(signer, feeRate);
|
|
197
|
-
// Find the maturity most distant in the future
|
|
198
|
-
const maturity = maturities.reduce((a, b) => epochCompare(a, b) === -1 ? b : a);
|
|
199
|
-
return {
|
|
200
|
-
tx,
|
|
201
|
-
ckbFee,
|
|
202
|
-
maturity,
|
|
203
|
-
};
|
|
204
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
205
|
-
}
|
|
206
|
-
catch (_) {
|
|
207
|
-
return undefined;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Retrieves the L1 state based on the provided parameters.
|
|
212
|
-
* @param client - The client to interact with the blockchain.
|
|
213
|
-
* @param filter - The set of filters to apply.
|
|
214
|
-
* @param locks - The script locks to filter the user cells.
|
|
215
|
-
* @param options - Optional parameters for the state retrieval.
|
|
216
|
-
* @param options.minLockUp - The minimum lock-up period (optional).
|
|
217
|
-
* @param options.maxLockUp - The maximum lock-up period (optional).
|
|
218
|
-
* @returns A promise that resolves to an object containing the system state and user cells.
|
|
219
|
-
*/
|
|
220
|
-
async getL1State(client, filter, locks, options) {
|
|
221
|
-
const tip = await client.getTipHeader();
|
|
222
|
-
const onChain = true;
|
|
223
|
-
const opts = { ...options, tip, onChain };
|
|
224
|
-
const [feeRate, depositPool, capacities, udts, receipts, withdrawalGroups, orders, deposits, withdrawalRequests, botCapacities,] = await Promise.all([
|
|
225
|
-
client.getFeeRate(),
|
|
226
|
-
filter.has("depositPool")
|
|
227
|
-
? collect(this.logicManager.findDeposits(client, opts))
|
|
228
|
-
: [],
|
|
229
|
-
filter.has("capacities")
|
|
230
|
-
? collect(CapacityManager.findCapacities(client, locks, opts))
|
|
231
|
-
: [],
|
|
232
|
-
filter.has("udts")
|
|
233
|
-
? collect(this.ickbUdtManager.findUdts(client, locks, opts))
|
|
234
|
-
: [],
|
|
235
|
-
filter.has("receipts")
|
|
236
|
-
? collect(this.logicManager.findReceipts(client, locks, opts))
|
|
237
|
-
: [],
|
|
238
|
-
filter.has("withdrawalGroups")
|
|
239
|
-
? collect(this.ownedOwnerManager.findWithdrawalGroups(client, locks, opts))
|
|
240
|
-
: [],
|
|
241
|
-
filter.has("orders") ? collect(this.orderManager.findOrders(client)) : [],
|
|
242
|
-
filter.has("deposits")
|
|
243
|
-
? collect(this.daoManager.findDeposits(client, locks, opts))
|
|
244
|
-
: [],
|
|
245
|
-
filter.has("withdrawalRequests")
|
|
246
|
-
? collect(this.daoManager.findWithdrawalRequests(client, locks, opts))
|
|
247
|
-
: [],
|
|
248
|
-
filter.has("ckbBots")
|
|
249
|
-
? collect(CapacityManager.findCapacities(client, locks, opts))
|
|
250
|
-
: [],
|
|
251
|
-
]);
|
|
252
|
-
// Sort depositPool by maturity
|
|
253
|
-
depositPool.sort((a, b) => epochCompare(a.maturity, b.maturity));
|
|
254
|
-
// Calculate cumulative value of deposits in the pool
|
|
255
|
-
let udtCumulative = 0n;
|
|
256
|
-
const cumulativeDepositPool = [];
|
|
257
|
-
for (const deposit of depositPool) {
|
|
258
|
-
udtCumulative += deposit.udtValue;
|
|
259
|
-
cumulativeDepositPool.push({ ...deposit, udtCumulative });
|
|
260
|
-
}
|
|
261
|
-
const userOrders = [];
|
|
262
|
-
const nonUserOrders = [];
|
|
263
|
-
for (const group of orders) {
|
|
264
|
-
if (group.isOwner(...locks)) {
|
|
265
|
-
userOrders.push(group);
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
nonUserOrders.push(group.order);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
const exchangeRatio = ickbExchangeRatio(tip);
|
|
272
|
-
const ckbDepositCap = convert(false, ICKB_DEPOSIT_CAP, exchangeRatio);
|
|
273
|
-
// Calculate the ckb ready to match incoming transactions
|
|
274
|
-
let ckbBots = botCapacities.reduce((acc, c) => acc + c.ckbValue, ccc.Zero);
|
|
275
|
-
// Each bot keeps a reserve of CKB for operations
|
|
276
|
-
ckbBots -= ccc.numFrom(this.bots.length) * ccc.fixedPointFrom("2000");
|
|
277
|
-
ckbBots = ckbBots > ccc.Zero ? ckbBots : ccc.Zero;
|
|
278
|
-
return {
|
|
279
|
-
system: {
|
|
280
|
-
feeRate,
|
|
281
|
-
tip,
|
|
282
|
-
exchangeRatio,
|
|
283
|
-
ckbDepositCap,
|
|
284
|
-
udtDepositCap: ICKB_DEPOSIT_CAP,
|
|
285
|
-
depositPool: cumulativeDepositPool,
|
|
286
|
-
orderPool: nonUserOrders,
|
|
287
|
-
ckbBots,
|
|
288
|
-
},
|
|
289
|
-
user: {
|
|
290
|
-
capacities,
|
|
291
|
-
udts,
|
|
292
|
-
receipts,
|
|
293
|
-
withdrawalGroups,
|
|
294
|
-
orders: userOrders,
|
|
295
|
-
deposits,
|
|
296
|
-
withdrawalRequests,
|
|
297
|
-
},
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Estimates the maturity of an order based on the type of conversion and amount.
|
|
303
|
-
*
|
|
304
|
-
* @param isCkb2Udt - A boolean indicating if the order is from CKB to UDT.
|
|
305
|
-
* @param amount - The amount of CKB or UDT involved in the order.
|
|
306
|
-
* @param udtWithdrawed - The amount of UDT that has been withdrawn by the current conversion via core.
|
|
307
|
-
* @param system - The current system state, which includes the block header tip, order pool, deposit pool, CKB bots, and exchange ratio.
|
|
308
|
-
*
|
|
309
|
-
* @returns The estimated maturity epoch for the order.
|
|
310
|
-
*/
|
|
311
|
-
function orderMaturityEstimate(isCkb2Udt, amount, udtWithdrawed, system) {
|
|
312
|
-
const { tip, orderPool, depositPool, ckbBots, exchangeRatio } = system;
|
|
313
|
-
// Maturity estimate a priori, the estimation is based on:
|
|
314
|
-
// - CKB to iCKB orders at 100k CKB every minute
|
|
315
|
-
// - iCKB to CKB orders at 200 CKB every minute
|
|
316
|
-
let maturity = epochAdd(tip.epoch, [
|
|
317
|
-
0n,
|
|
318
|
-
1n + amount / ccc.fixedPointFrom(isCkb2Udt ? 100000 : 200),
|
|
319
|
-
4n * 60n,
|
|
320
|
-
]);
|
|
321
|
-
if (isCkb2Udt) {
|
|
322
|
-
return maturity;
|
|
323
|
-
}
|
|
324
|
-
if (depositPool.length > 0) {
|
|
325
|
-
const udtWaiting = orderPool
|
|
326
|
-
.filter((o) => o.isUdt2CkbMatchable())
|
|
327
|
-
.reduce((acc, o) => acc + o.udtValue, ccc.Zero);
|
|
328
|
-
const udtAvailable = convert(isCkb2Udt, ckbBots, exchangeRatio);
|
|
329
|
-
const udtToConvert = amount + udtWithdrawed + udtWaiting - udtAvailable;
|
|
330
|
-
const i = binarySearch(depositPool.length,
|
|
331
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
332
|
-
(n) => depositPool[n].udtCumulative >= udtToConvert);
|
|
333
|
-
maturity = depositPool[i]?.maturity ?? maturity;
|
|
334
|
-
}
|
|
335
|
-
return maturity;
|
|
336
|
-
}
|
|
1
|
+
export * from "./sdk.js";
|
|
2
|
+
export * from "./codec.js";
|
|
3
|
+
export * from "./constants.js";
|
|
337
4
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EACL,OAAO,EACP,YAAY,EACZ,eAAe,EACf,gBAAgB,EAIhB,QAAQ,EACR,iBAAiB,EACjB,qBAAqB,EAErB,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,OAAO,EACP,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,iBAAiB,GAIlB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,UAAU,EAAgB,MAAM,WAAW,CAAC;AACrD,OAAO,EACL,IAAI,EACJ,YAAY,GAGb,MAA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AAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC;QAC1D,EAAE,GAAG,GAAG;KACT,CAAC,CAAC;IAEH,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,UAAU,GAAG,SAAS;aACzB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,kBAAkB,EAAE,CAAC;aACrC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;QAClD,MAAM,YAAY,GAAG,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;QAEhE,MAAM,YAAY,GAAG,MAAM,GAAG,aAAa,GAAG,UAAU,GAAG,YAAY,CAAC;QACxE,MAAM,CAAC,GAAG,YAAY,CACpB,WAAW,CAAC,MAAM;QAClB,oEAAoE;QACpE,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC,aAAa,IAAI,YAAY,CACrD,CAAC;QAEF,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,QAAQ,IAAI,QAAQ,CAAC;IAClD,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { CapacityManager, SmartTransaction, type ValueComponents } from "@ickb/utils";
|
|
3
|
+
import { type LogicManager, type OwnedOwnerManager } from "@ickb/core";
|
|
4
|
+
import { Info, OrderManager, Ratio, type OrderCell, type OrderGroup } from "@ickb/order";
|
|
5
|
+
import { getConfig } from "./constants.js";
|
|
6
|
+
/**
|
|
7
|
+
* SDK for managing iCKB operations.
|
|
8
|
+
*/
|
|
9
|
+
export declare class IckbSdk {
|
|
10
|
+
private readonly ownedOwner;
|
|
11
|
+
private readonly ickbLogic;
|
|
12
|
+
private readonly order;
|
|
13
|
+
private readonly capacity;
|
|
14
|
+
private readonly bots;
|
|
15
|
+
/**
|
|
16
|
+
* Creates an instance of IckbSdk.
|
|
17
|
+
*
|
|
18
|
+
* @param ownedOwner - The manager for owned owner operations.
|
|
19
|
+
* @param ickbLogic - The manager for iCKB logic operations.
|
|
20
|
+
* @param order - The manager for order operations.
|
|
21
|
+
* @param capacity - The capacity manager instance.
|
|
22
|
+
* @param bots - An array of bot lock scripts.
|
|
23
|
+
*/
|
|
24
|
+
constructor(ownedOwner: OwnedOwnerManager, ickbLogic: LogicManager, order: OrderManager, capacity: CapacityManager, bots: ccc.Script[]);
|
|
25
|
+
/**
|
|
26
|
+
* Creates an instance of IckbSdk from script dependencies.
|
|
27
|
+
*
|
|
28
|
+
* @param args - Parameters matching those of getConfig.
|
|
29
|
+
* @returns A new instance of IckbSdk.
|
|
30
|
+
*/
|
|
31
|
+
static from(...args: Parameters<typeof getConfig>): IckbSdk;
|
|
32
|
+
/**
|
|
33
|
+
* Previews the conversion between CKB and UDT.
|
|
34
|
+
*
|
|
35
|
+
* This method calculates a conversion preview using an exchange ratio midpoint.
|
|
36
|
+
* Optionally, a fee may be applied that influences the effective conversion rate,
|
|
37
|
+
* scaling the converted amount by (feeBase - fee) / feeBase.
|
|
38
|
+
*
|
|
39
|
+
* @param isCkb2Udt - Indicates the conversion direction:
|
|
40
|
+
* - true: Convert CKB to UDT.
|
|
41
|
+
* - false: Convert UDT to CKB.
|
|
42
|
+
* @param amounts - An object containing value components (amounts for CKB and UDT).
|
|
43
|
+
* @param system - The current system state containing exchange ratio, fee rate, tip, and order-related information.
|
|
44
|
+
* @param options - Optional parameters for fee and matching:
|
|
45
|
+
* - fee: The fee to apply in integer terms (defaults to 1n for 0.001% fee).
|
|
46
|
+
* - feeBase: The base used for fee scaling (defaults to 100000n).
|
|
47
|
+
*
|
|
48
|
+
* @returns An object with:
|
|
49
|
+
* - convertedAmount: The estimated converted amount as a FixedPoint.
|
|
50
|
+
* - ckbFee: The fee (or gain) in CKB, as a FixedPoint.
|
|
51
|
+
* - info: Additional conversion metadata.
|
|
52
|
+
* - maturity: Optional maturity information (as ccc.Num) if meets criteria.
|
|
53
|
+
*/
|
|
54
|
+
static estimate(isCkb2Udt: boolean, amounts: ValueComponents, system: SystemState, options?: {
|
|
55
|
+
fee?: ccc.Num;
|
|
56
|
+
feeBase?: ccc.Num;
|
|
57
|
+
}): {
|
|
58
|
+
convertedAmount: ccc.FixedPoint;
|
|
59
|
+
ckbFee: ccc.FixedPoint;
|
|
60
|
+
info: Info;
|
|
61
|
+
maturity: ccc.Num | undefined;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Estimates the maturity for an order formatted as a Unix timestamp.
|
|
65
|
+
*
|
|
66
|
+
* Depending on the order type and amount remaining, the method calculates an estimated timestamp
|
|
67
|
+
* when the order (or part thereof) might be fulfilled.
|
|
68
|
+
*
|
|
69
|
+
* @param o - Either an OrderCell or an object containing order Info and value components.
|
|
70
|
+
* @param system - The current system state.
|
|
71
|
+
* @returns The Unix timestamp of estimated maturity as a bigint (in milliseconds) or undefined if not applicable.
|
|
72
|
+
*/
|
|
73
|
+
static maturity(o: OrderCell | {
|
|
74
|
+
info: Info;
|
|
75
|
+
amounts: ValueComponents;
|
|
76
|
+
}, system: SystemState): bigint | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Mints a new order cell and appends it to the transaction.
|
|
79
|
+
*
|
|
80
|
+
* The method performs the following operations:
|
|
81
|
+
* - Creates order cell data using provided amounts and order information.
|
|
82
|
+
* - Adds required cell dependencies and UDT handlers to the transaction.
|
|
83
|
+
* - Appends the order cell to the transaction outputs.
|
|
84
|
+
*
|
|
85
|
+
* @param tx - The smart transaction to which the order cell is added.
|
|
86
|
+
* @param user - The user, represented either as a Signer or a Script.
|
|
87
|
+
* @param info - The order information meta data (usually computed via OrderManager.convert).
|
|
88
|
+
* @param amounts - The value components for the order, including:
|
|
89
|
+
* - ckbValue: The CKB amount (may include an internal surplus).
|
|
90
|
+
* - udtValue: The UDT amount.
|
|
91
|
+
*
|
|
92
|
+
* @returns A Promise resolving to void.
|
|
93
|
+
*/
|
|
94
|
+
request(tx: SmartTransaction, user: ccc.Signer | ccc.Script, info: Info, amounts: ValueComponents): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Melts (cancels) the specified order groups.
|
|
97
|
+
*
|
|
98
|
+
* For each order group, if the option is set to process fulfilled orders only,
|
|
99
|
+
* it filters accordingly. Then, for every valid group, the master and order cells are added
|
|
100
|
+
* as inputs to the transaction.
|
|
101
|
+
*
|
|
102
|
+
* @param tx - The smart transaction to which the inputs are added.
|
|
103
|
+
* @param groups - An array of order groups to be melted.
|
|
104
|
+
* @param options - Optional parameters:
|
|
105
|
+
* - isFulfilledOnly: If true, only order groups with fully or partially fulfilled orders are processed.
|
|
106
|
+
*
|
|
107
|
+
* @returns void
|
|
108
|
+
*/
|
|
109
|
+
collect(tx: SmartTransaction, groups: OrderGroup[], options?: {
|
|
110
|
+
isFulfilledOnly?: boolean;
|
|
111
|
+
}): void;
|
|
112
|
+
/**
|
|
113
|
+
* Retrieves the L1 state from the blockchain.
|
|
114
|
+
*
|
|
115
|
+
* The method performs the following:
|
|
116
|
+
* - Obtains the current block tip and calculates the exchange ratio.
|
|
117
|
+
* - Fetches available CKB and the maturing CKB based on bot capacities and deposit snapshots.
|
|
118
|
+
* - Filters orders into user-owned and system orders based on the provided locks.
|
|
119
|
+
* - Estimates user-owned orders maturity.
|
|
120
|
+
*
|
|
121
|
+
* @param client - The blockchain client interface.
|
|
122
|
+
* @param locks - An array of lock scripts used to filter user cells.
|
|
123
|
+
* @returns A promise that resolves to an object containing:
|
|
124
|
+
* - system: The system state (fee rate, tip header, exchange ratio, order pool, etc.).
|
|
125
|
+
* - user: The user's orders grouped as an array of OrderGroup.
|
|
126
|
+
*/
|
|
127
|
+
getL1State(client: ccc.Client, locks: ccc.Script[]): Promise<{
|
|
128
|
+
system: SystemState;
|
|
129
|
+
user: {
|
|
130
|
+
orders: OrderGroup[];
|
|
131
|
+
};
|
|
132
|
+
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Retrieves available CKB and maturing CKB values from the blockchain.
|
|
135
|
+
*
|
|
136
|
+
* This method:
|
|
137
|
+
* - Fetches bot withdrawal requests and deposit snapshots.
|
|
138
|
+
* - Aggregates available CKB balances from bot capacities.
|
|
139
|
+
* - Calculates maturing CKB values (with their expected maturity timestamps)
|
|
140
|
+
* based on deposit pool snapshots or via direct deposit cell lookups.
|
|
141
|
+
* - Sorts and cumulatively sums the maturing values for later lookup.
|
|
142
|
+
*
|
|
143
|
+
* @param client - The blockchain client used for fetching data.
|
|
144
|
+
* @param tip - The current block tip header.
|
|
145
|
+
* @returns A Promise that resolves with:
|
|
146
|
+
* - ckbAvailable: The total available CKB (as a FixedPoint).
|
|
147
|
+
* - ckbMaturing: An array of maturing CKB objects containing the cumulative CKB
|
|
148
|
+
* and the associated maturity timestamp.
|
|
149
|
+
*/
|
|
150
|
+
private getCkb;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Represents the state of the system.
|
|
154
|
+
*/
|
|
155
|
+
export interface SystemState {
|
|
156
|
+
/** The fee rate for transactions. */
|
|
157
|
+
feeRate: ccc.Num;
|
|
158
|
+
/** The tip for the current block header. */
|
|
159
|
+
tip: ccc.ClientBlockHeader;
|
|
160
|
+
/** The exchange ratio between CKB and UDT. */
|
|
161
|
+
exchangeRatio: Ratio;
|
|
162
|
+
/** The order pool containing order cells matching system criteria. */
|
|
163
|
+
orderPool: OrderCell[];
|
|
164
|
+
/** The total available CKB (as FixedPoint). */
|
|
165
|
+
ckbAvailable: ccc.FixedPoint;
|
|
166
|
+
/** Array of CKB maturing entries with cumulative amounts and maturity timestamps. */
|
|
167
|
+
ckbMaturing: CkbCumulative[];
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Represents a cumulative CKB maturing entry.
|
|
171
|
+
*/
|
|
172
|
+
export interface CkbCumulative {
|
|
173
|
+
/** The cumulative CKB value (as FixedPoint) up to this maturity. */
|
|
174
|
+
ckbCumulative: ccc.FixedPoint;
|
|
175
|
+
/** The maturity timestamp (as ccc.Num). */
|
|
176
|
+
maturity: ccc.Num;
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=sdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAEL,eAAe,EACf,gBAAgB,EAEhB,KAAK,eAAe,EAIrB,MAAM,aAAa,CAAC;AACrB,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACvB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,IAAI,EACJ,YAAY,EACZ,KAAK,EACL,KAAK,SAAS,EACd,KAAK,UAAU,EAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C;;GAEG;AACH,qBAAa,OAAO;IAWhB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAdvB;;;;;;;;OAQG;gBAEgB,UAAU,EAAE,iBAAiB,EAC7B,SAAS,EAAE,YAAY,EACvB,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,eAA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