@cloakely/sdk 0.2.1 → 0.2.2

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.
@@ -305,8 +305,10 @@ export class CloakPrivate {
305
305
  const fee = (await this.relayFee("placeOrder", poolIn)).fee;
306
306
  if (fee > 0n) {
307
307
  const have = await this.balance(poolIn);
308
- if (sizes.reduce((a, x) => a + x, 0n) + fee * BigInt(sizes.length) > have) {
309
- const budget = have - fee * BigInt(maxOrders);
308
+ // headroom: the fee is re-quoted before every order (gas moves), and combining notes first costs one more fee
309
+ const reserve = (n) => (fee * BigInt(n) * 5n) / 4n + fee;
310
+ if (sizes.reduce((a, x) => a + x, 0n) + reserve(sizes.length) > have) {
311
+ const budget = have - reserve(maxOrders);
310
312
  if (budget <= 0n)
311
313
  throw new Error("insufficient private balance");
312
314
  ({ sizes } = splitStandard(budget < amount ? budget : amount, maxOrders));
@@ -320,7 +322,17 @@ export class CloakPrivate {
320
322
  const size = sizes[i];
321
323
  onStatus(`Order ${i + 1}/${sizes.length}: syncing…`);
322
324
  const q = await this.relayFee("placeOrder", poolIn);
323
- const inputs = await this.inputsFor(poolIn, size + q.fee, onStatus);
325
+ let inputs;
326
+ try {
327
+ inputs = await this.inputsFor(poolIn, size + q.fee, onStatus);
328
+ }
329
+ catch (e) {
330
+ // if fees rose mid-way, keep the orders already placed and leave the rest in the balance
331
+ if (!placed.length || !/insufficient private balance/.test(String(e.message)))
332
+ throw e;
333
+ rest += sizes.slice(i).reduce((a, x) => a + x, 0n);
334
+ break;
335
+ }
324
336
  const keyIndex = randomKeyIndex();
325
337
  const outKey = await this.keys.key(keyIndex);
326
338
  const outBlinding = randomField();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloakely/sdk",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Cloak on Elysium: sealed-bid token launches and private trading (shielded balances, private swaps, batch auctions, private sends) with on-device zero-knowledge proofs.",
5
5
  "keywords": [
6
6
  "cloak",