@t2000/sdk 10.38.0 → 10.38.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.
package/dist/browser.cjs CHANGED
@@ -237,6 +237,14 @@ __export(coinSelection_exports, {
237
237
  selectAndSplitCoin: () => selectAndSplitCoin,
238
238
  selectSuiCoin: () => selectSuiCoin
239
239
  });
240
+ function formatRawAmount(raw, coinType) {
241
+ const decimals = getDecimalsForCoinType(coinType);
242
+ const dp = Math.min(decimals, 8);
243
+ const s = raw.toString().padStart(decimals + 1, "0");
244
+ const whole = s.slice(0, s.length - decimals);
245
+ const frac = s.slice(s.length - decimals).slice(0, dp).replace(/0+$/, "");
246
+ return frac ? `${whole}.${frac}` : whole;
247
+ }
240
248
  async function fetchAllCoins(client, owner, coinType) {
241
249
  const [balance, ids] = await Promise.all([
242
250
  client.core.getBalance({ owner, coinType }),
@@ -269,15 +277,25 @@ async function selectAndSplitCoin(tx, client, owner, coinType, amount, options =
269
277
  }
270
278
  const balanceResp = await client.core.getBalance({ owner, coinType });
271
279
  const totalBalance = BigInt(balanceResp.balance.balance);
280
+ const symbol = resolveSymbol(coinType);
272
281
  if (totalBalance === 0n) {
273
- throw new exports.T2000Error("INSUFFICIENT_BALANCE", `No balance found for ${coinType}`);
282
+ throw new exports.T2000Error(
283
+ "INSUFFICIENT_BALANCE",
284
+ amount === "all" ? `No ${symbol} in this wallet.` : `Insufficient ${symbol}: need ${formatRawAmount(amount, coinType)}, the wallet holds 0.`,
285
+ { available: "0", required: amount === "all" ? "0" : amount.toString(), coinType }
286
+ );
274
287
  }
275
288
  const allowSwapAll = options.allowSwapAll ?? true;
276
289
  if (amount !== "all" && amount > totalBalance && !allowSwapAll) {
277
- throw new exports.T2000Error("INSUFFICIENT_BALANCE", `Insufficient balance for ${coinType}`, {
278
- available: totalBalance.toString(),
279
- required: amount.toString()
280
- });
290
+ throw new exports.T2000Error(
291
+ "INSUFFICIENT_BALANCE",
292
+ `Insufficient ${symbol}: need ${formatRawAmount(amount, coinType)}, the wallet holds ${formatRawAmount(totalBalance, coinType)}.`,
293
+ {
294
+ available: totalBalance.toString(),
295
+ required: amount.toString(),
296
+ coinType
297
+ }
298
+ );
281
299
  }
282
300
  const requested = amount === "all" ? totalBalance : amount;
283
301
  const swapAll = amount === "all" || requested >= totalBalance;
@@ -292,7 +310,7 @@ async function selectCoinObjectsOnly(tx, client, owner, coinType, amount, allowS
292
310
  if (cached.remaining === 0n || requested2 > cached.remaining) {
293
311
  throw new exports.T2000Error(
294
312
  "ADDRESS_BALANCE_UNSPONSORABLE",
295
- `Not enough ${coinType} in coin objects to cover all legs of this sponsored bundle. The remaining funds are in your address balance, which sponsored transactions can't access yet.`,
313
+ `Not enough ${resolveSymbol(coinType)} in coin objects to cover all legs of this sponsored bundle. The remaining funds are in your address balance, which sponsored transactions can't access yet.`,
296
314
  { remaining: cached.remaining.toString(), requested: requested2.toString(), coinType }
297
315
  );
298
316
  }
@@ -357,7 +375,7 @@ function buildCoinToAddressBalanceMigration(args) {
357
375
  migratedRaw += c.balance;
358
376
  }
359
377
  if (migratedRaw < minAmount) {
360
- throw new exports.T2000Error("INSUFFICIENT_BALANCE", `Insufficient ${coinType} coin objects to migrate`, {
378
+ throw new exports.T2000Error("INSUFFICIENT_BALANCE", `Insufficient ${resolveSymbol(coinType)} coin objects to migrate`, {
361
379
  available: migratedRaw.toString(),
362
380
  required: minAmount.toString()
363
381
  });
@@ -383,6 +401,7 @@ async function selectSuiCoin(tx, client, owner, amountMist, sponsoredContext, me
383
401
  var init_coinSelection = __esm({
384
402
  "src/wallet/coinSelection.ts"() {
385
403
  init_errors();
404
+ init_token_registry();
386
405
  }
387
406
  });
388
407
 
package/dist/browser.js CHANGED
@@ -235,6 +235,14 @@ __export(coinSelection_exports, {
235
235
  selectAndSplitCoin: () => selectAndSplitCoin,
236
236
  selectSuiCoin: () => selectSuiCoin
237
237
  });
238
+ function formatRawAmount(raw, coinType) {
239
+ const decimals = getDecimalsForCoinType(coinType);
240
+ const dp = Math.min(decimals, 8);
241
+ const s = raw.toString().padStart(decimals + 1, "0");
242
+ const whole = s.slice(0, s.length - decimals);
243
+ const frac = s.slice(s.length - decimals).slice(0, dp).replace(/0+$/, "");
244
+ return frac ? `${whole}.${frac}` : whole;
245
+ }
238
246
  async function fetchAllCoins(client, owner, coinType) {
239
247
  const [balance, ids] = await Promise.all([
240
248
  client.core.getBalance({ owner, coinType }),
@@ -267,15 +275,25 @@ async function selectAndSplitCoin(tx, client, owner, coinType, amount, options =
267
275
  }
268
276
  const balanceResp = await client.core.getBalance({ owner, coinType });
269
277
  const totalBalance = BigInt(balanceResp.balance.balance);
278
+ const symbol = resolveSymbol(coinType);
270
279
  if (totalBalance === 0n) {
271
- throw new T2000Error("INSUFFICIENT_BALANCE", `No balance found for ${coinType}`);
280
+ throw new T2000Error(
281
+ "INSUFFICIENT_BALANCE",
282
+ amount === "all" ? `No ${symbol} in this wallet.` : `Insufficient ${symbol}: need ${formatRawAmount(amount, coinType)}, the wallet holds 0.`,
283
+ { available: "0", required: amount === "all" ? "0" : amount.toString(), coinType }
284
+ );
272
285
  }
273
286
  const allowSwapAll = options.allowSwapAll ?? true;
274
287
  if (amount !== "all" && amount > totalBalance && !allowSwapAll) {
275
- throw new T2000Error("INSUFFICIENT_BALANCE", `Insufficient balance for ${coinType}`, {
276
- available: totalBalance.toString(),
277
- required: amount.toString()
278
- });
288
+ throw new T2000Error(
289
+ "INSUFFICIENT_BALANCE",
290
+ `Insufficient ${symbol}: need ${formatRawAmount(amount, coinType)}, the wallet holds ${formatRawAmount(totalBalance, coinType)}.`,
291
+ {
292
+ available: totalBalance.toString(),
293
+ required: amount.toString(),
294
+ coinType
295
+ }
296
+ );
279
297
  }
280
298
  const requested = amount === "all" ? totalBalance : amount;
281
299
  const swapAll = amount === "all" || requested >= totalBalance;
@@ -290,7 +308,7 @@ async function selectCoinObjectsOnly(tx, client, owner, coinType, amount, allowS
290
308
  if (cached.remaining === 0n || requested2 > cached.remaining) {
291
309
  throw new T2000Error(
292
310
  "ADDRESS_BALANCE_UNSPONSORABLE",
293
- `Not enough ${coinType} in coin objects to cover all legs of this sponsored bundle. The remaining funds are in your address balance, which sponsored transactions can't access yet.`,
311
+ `Not enough ${resolveSymbol(coinType)} in coin objects to cover all legs of this sponsored bundle. The remaining funds are in your address balance, which sponsored transactions can't access yet.`,
294
312
  { remaining: cached.remaining.toString(), requested: requested2.toString(), coinType }
295
313
  );
296
314
  }
@@ -355,7 +373,7 @@ function buildCoinToAddressBalanceMigration(args) {
355
373
  migratedRaw += c.balance;
356
374
  }
357
375
  if (migratedRaw < minAmount) {
358
- throw new T2000Error("INSUFFICIENT_BALANCE", `Insufficient ${coinType} coin objects to migrate`, {
376
+ throw new T2000Error("INSUFFICIENT_BALANCE", `Insufficient ${resolveSymbol(coinType)} coin objects to migrate`, {
359
377
  available: migratedRaw.toString(),
360
378
  required: minAmount.toString()
361
379
  });
@@ -381,6 +399,7 @@ async function selectSuiCoin(tx, client, owner, amountMist, sponsoredContext, me
381
399
  var init_coinSelection = __esm({
382
400
  "src/wallet/coinSelection.ts"() {
383
401
  init_errors();
402
+ init_token_registry();
384
403
  }
385
404
  });
386
405
 
package/dist/index.cjs CHANGED
@@ -281,6 +281,14 @@ __export(coinSelection_exports, {
281
281
  selectAndSplitCoin: () => selectAndSplitCoin,
282
282
  selectSuiCoin: () => selectSuiCoin
283
283
  });
284
+ function formatRawAmount(raw, coinType) {
285
+ const decimals = getDecimalsForCoinType(coinType);
286
+ const dp = Math.min(decimals, 8);
287
+ const s = raw.toString().padStart(decimals + 1, "0");
288
+ const whole = s.slice(0, s.length - decimals);
289
+ const frac = s.slice(s.length - decimals).slice(0, dp).replace(/0+$/, "");
290
+ return frac ? `${whole}.${frac}` : whole;
291
+ }
284
292
  async function fetchAllCoins(client, owner, coinType) {
285
293
  const [balance, ids] = await Promise.all([
286
294
  client.core.getBalance({ owner, coinType }),
@@ -313,15 +321,25 @@ async function selectAndSplitCoin(tx, client, owner, coinType, amount, options =
313
321
  }
314
322
  const balanceResp = await client.core.getBalance({ owner, coinType });
315
323
  const totalBalance = BigInt(balanceResp.balance.balance);
324
+ const symbol = resolveSymbol(coinType);
316
325
  if (totalBalance === 0n) {
317
- throw new exports.T2000Error("INSUFFICIENT_BALANCE", `No balance found for ${coinType}`);
326
+ throw new exports.T2000Error(
327
+ "INSUFFICIENT_BALANCE",
328
+ amount === "all" ? `No ${symbol} in this wallet.` : `Insufficient ${symbol}: need ${formatRawAmount(amount, coinType)}, the wallet holds 0.`,
329
+ { available: "0", required: amount === "all" ? "0" : amount.toString(), coinType }
330
+ );
318
331
  }
319
332
  const allowSwapAll = options.allowSwapAll ?? true;
320
333
  if (amount !== "all" && amount > totalBalance && !allowSwapAll) {
321
- throw new exports.T2000Error("INSUFFICIENT_BALANCE", `Insufficient balance for ${coinType}`, {
322
- available: totalBalance.toString(),
323
- required: amount.toString()
324
- });
334
+ throw new exports.T2000Error(
335
+ "INSUFFICIENT_BALANCE",
336
+ `Insufficient ${symbol}: need ${formatRawAmount(amount, coinType)}, the wallet holds ${formatRawAmount(totalBalance, coinType)}.`,
337
+ {
338
+ available: totalBalance.toString(),
339
+ required: amount.toString(),
340
+ coinType
341
+ }
342
+ );
325
343
  }
326
344
  const requested = amount === "all" ? totalBalance : amount;
327
345
  const swapAll = amount === "all" || requested >= totalBalance;
@@ -336,7 +354,7 @@ async function selectCoinObjectsOnly(tx, client, owner, coinType, amount, allowS
336
354
  if (cached.remaining === 0n || requested2 > cached.remaining) {
337
355
  throw new exports.T2000Error(
338
356
  "ADDRESS_BALANCE_UNSPONSORABLE",
339
- `Not enough ${coinType} in coin objects to cover all legs of this sponsored bundle. The remaining funds are in your address balance, which sponsored transactions can't access yet.`,
357
+ `Not enough ${resolveSymbol(coinType)} in coin objects to cover all legs of this sponsored bundle. The remaining funds are in your address balance, which sponsored transactions can't access yet.`,
340
358
  { remaining: cached.remaining.toString(), requested: requested2.toString(), coinType }
341
359
  );
342
360
  }
@@ -401,7 +419,7 @@ function buildCoinToAddressBalanceMigration(args) {
401
419
  migratedRaw += c.balance;
402
420
  }
403
421
  if (migratedRaw < minAmount) {
404
- throw new exports.T2000Error("INSUFFICIENT_BALANCE", `Insufficient ${coinType} coin objects to migrate`, {
422
+ throw new exports.T2000Error("INSUFFICIENT_BALANCE", `Insufficient ${resolveSymbol(coinType)} coin objects to migrate`, {
405
423
  available: migratedRaw.toString(),
406
424
  required: minAmount.toString()
407
425
  });
@@ -427,6 +445,7 @@ async function selectSuiCoin(tx, client, owner, amountMist, sponsoredContext, me
427
445
  var init_coinSelection = __esm({
428
446
  "src/wallet/coinSelection.ts"() {
429
447
  init_errors();
448
+ init_token_registry();
430
449
  }
431
450
  });
432
451
 
package/dist/index.js CHANGED
@@ -275,6 +275,14 @@ __export(coinSelection_exports, {
275
275
  selectAndSplitCoin: () => selectAndSplitCoin,
276
276
  selectSuiCoin: () => selectSuiCoin
277
277
  });
278
+ function formatRawAmount(raw, coinType) {
279
+ const decimals = getDecimalsForCoinType(coinType);
280
+ const dp = Math.min(decimals, 8);
281
+ const s = raw.toString().padStart(decimals + 1, "0");
282
+ const whole = s.slice(0, s.length - decimals);
283
+ const frac = s.slice(s.length - decimals).slice(0, dp).replace(/0+$/, "");
284
+ return frac ? `${whole}.${frac}` : whole;
285
+ }
278
286
  async function fetchAllCoins(client, owner, coinType) {
279
287
  const [balance, ids] = await Promise.all([
280
288
  client.core.getBalance({ owner, coinType }),
@@ -307,15 +315,25 @@ async function selectAndSplitCoin(tx, client, owner, coinType, amount, options =
307
315
  }
308
316
  const balanceResp = await client.core.getBalance({ owner, coinType });
309
317
  const totalBalance = BigInt(balanceResp.balance.balance);
318
+ const symbol = resolveSymbol(coinType);
310
319
  if (totalBalance === 0n) {
311
- throw new T2000Error("INSUFFICIENT_BALANCE", `No balance found for ${coinType}`);
320
+ throw new T2000Error(
321
+ "INSUFFICIENT_BALANCE",
322
+ amount === "all" ? `No ${symbol} in this wallet.` : `Insufficient ${symbol}: need ${formatRawAmount(amount, coinType)}, the wallet holds 0.`,
323
+ { available: "0", required: amount === "all" ? "0" : amount.toString(), coinType }
324
+ );
312
325
  }
313
326
  const allowSwapAll = options.allowSwapAll ?? true;
314
327
  if (amount !== "all" && amount > totalBalance && !allowSwapAll) {
315
- throw new T2000Error("INSUFFICIENT_BALANCE", `Insufficient balance for ${coinType}`, {
316
- available: totalBalance.toString(),
317
- required: amount.toString()
318
- });
328
+ throw new T2000Error(
329
+ "INSUFFICIENT_BALANCE",
330
+ `Insufficient ${symbol}: need ${formatRawAmount(amount, coinType)}, the wallet holds ${formatRawAmount(totalBalance, coinType)}.`,
331
+ {
332
+ available: totalBalance.toString(),
333
+ required: amount.toString(),
334
+ coinType
335
+ }
336
+ );
319
337
  }
320
338
  const requested = amount === "all" ? totalBalance : amount;
321
339
  const swapAll = amount === "all" || requested >= totalBalance;
@@ -330,7 +348,7 @@ async function selectCoinObjectsOnly(tx, client, owner, coinType, amount, allowS
330
348
  if (cached.remaining === 0n || requested2 > cached.remaining) {
331
349
  throw new T2000Error(
332
350
  "ADDRESS_BALANCE_UNSPONSORABLE",
333
- `Not enough ${coinType} in coin objects to cover all legs of this sponsored bundle. The remaining funds are in your address balance, which sponsored transactions can't access yet.`,
351
+ `Not enough ${resolveSymbol(coinType)} in coin objects to cover all legs of this sponsored bundle. The remaining funds are in your address balance, which sponsored transactions can't access yet.`,
334
352
  { remaining: cached.remaining.toString(), requested: requested2.toString(), coinType }
335
353
  );
336
354
  }
@@ -395,7 +413,7 @@ function buildCoinToAddressBalanceMigration(args) {
395
413
  migratedRaw += c.balance;
396
414
  }
397
415
  if (migratedRaw < minAmount) {
398
- throw new T2000Error("INSUFFICIENT_BALANCE", `Insufficient ${coinType} coin objects to migrate`, {
416
+ throw new T2000Error("INSUFFICIENT_BALANCE", `Insufficient ${resolveSymbol(coinType)} coin objects to migrate`, {
399
417
  available: migratedRaw.toString(),
400
418
  required: minAmount.toString()
401
419
  });
@@ -421,6 +439,7 @@ async function selectSuiCoin(tx, client, owner, amountMist, sponsoredContext, me
421
439
  var init_coinSelection = __esm({
422
440
  "src/wallet/coinSelection.ts"() {
423
441
  init_errors();
442
+ init_token_registry();
424
443
  }
425
444
  });
426
445
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t2000/sdk",
3
- "version": "10.38.0",
3
+ "version": "10.38.2",
4
4
  "engines": {
5
5
  "node": ">=20"
6
6
  },
@@ -17,7 +17,8 @@
17
17
  },
18
18
  "./browser": {
19
19
  "types": "./dist/browser.d.ts",
20
- "import": "./dist/browser.js"
20
+ "import": "./dist/browser.js",
21
+ "require": "./dist/browser.cjs"
21
22
  }
22
23
  },
23
24
  "files": [
@@ -55,7 +56,7 @@
55
56
  "@phala/dcap-qvl": "^0.5.2",
56
57
  "bn.js": "^5.2.1",
57
58
  "eventemitter3": "^5",
58
- "@t2000/sui-x402": "10.38.0"
59
+ "@t2000/sui-x402": "10.38.2"
59
60
  },
60
61
  "devDependencies": {
61
62
  "@types/bn.js": "^5.1.5",