@t2000/sdk 0.19.22 → 0.19.23

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.
@@ -588,12 +588,16 @@ async function buildRepayTx(client, address, amount, options = {}) {
588
588
  const asset = options.asset ?? "USDC";
589
589
  const assetInfo = resolveAssetInfo(asset);
590
590
  const coins = await fetchCoins(client, address, assetInfo.type);
591
- if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", `No ${assetInfo.displayName} coins to repay with`);
591
+ if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", `No ${assetInfo.displayName} coins to repay with. Withdraw some savings first to get cash.`);
592
592
  const totalBalance = coins.reduce((sum, c) => sum + BigInt(c.balance), 0n);
593
+ const rawRequested = Number(stableToRaw(amount, assetInfo.decimals));
594
+ if (Number(totalBalance) < rawRequested && Number(totalBalance) < 1e3) {
595
+ throw new T2000Error("INSUFFICIENT_BALANCE", `Not enough ${assetInfo.displayName} to repay (need $${amount.toFixed(2)}, wallet has ~$${(Number(totalBalance) / 10 ** assetInfo.decimals).toFixed(4)}). Withdraw some savings first.`);
596
+ }
593
597
  const tx = new transactions.Transaction();
594
598
  tx.setSender(address);
595
599
  const coinObj = mergeCoins(tx, coins);
596
- const rawAmount = Math.min(Number(stableToRaw(amount, assetInfo.decimals)), Number(totalBalance));
600
+ const rawAmount = Math.min(rawRequested, Number(totalBalance));
597
601
  const [repayCoin] = tx.splitCoins(coinObj, [rawAmount]);
598
602
  await refreshOracle(tx, client, address, {
599
603
  skipPythUpdate: options.sponsored,