@t2000/sdk 0.19.22 → 0.19.24

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