@t2000/cli 0.22.24 → 0.22.25

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.
@@ -71889,6 +71889,8 @@ function mapMoveAbortCode(code) {
71889
71889
  1503: 'Withdrawal amount is invalid (zero or dust) \u2014 try a specific amount instead of "all"',
71890
71890
  1600: "Health factor too low \u2014 withdrawal would risk liquidation",
71891
71891
  1605: "Asset borrowing is disabled or at capacity on this protocol",
71892
+ // NAVI utils abort codes
71893
+ 46e3: "Insufficient balance to repay \u2014 withdraw some savings first to get cash",
71892
71894
  // Cetus DEX abort codes
71893
71895
  46001: "Swap failed \u2014 the DEX pool rejected the trade (liquidity or routing issue). Try again."
71894
71896
  };
@@ -72687,12 +72689,16 @@ async function buildRepayTx(client, address, amount, options = {}) {
72687
72689
  const asset = options.asset ?? "USDC";
72688
72690
  const assetInfo = resolveAssetInfo(asset);
72689
72691
  const coins = await fetchCoins(client, address, assetInfo.type);
72690
- if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", `No ${assetInfo.displayName} coins to repay with`);
72692
+ if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", `No ${assetInfo.displayName} coins to repay with. Withdraw some savings first to get cash.`);
72691
72693
  const totalBalance = coins.reduce((sum2, c) => sum2 + BigInt(c.balance), 0n);
72694
+ const rawRequested = Number(stableToRaw(amount, assetInfo.decimals));
72695
+ if (Number(totalBalance) < rawRequested && Number(totalBalance) < 1e3) {
72696
+ 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.`);
72697
+ }
72692
72698
  const tx = new Transaction();
72693
72699
  tx.setSender(address);
72694
72700
  const coinObj = mergeCoins(tx, coins);
72695
- const rawAmount = Math.min(Number(stableToRaw(amount, assetInfo.decimals)), Number(totalBalance));
72701
+ const rawAmount = Math.min(rawRequested, Number(totalBalance));
72696
72702
  const [repayCoin] = tx.splitCoins(coinObj, [rawAmount]);
72697
72703
  await refreshOracle(tx, client, address, {
72698
72704
  skipPythUpdate: options.sponsored,
@@ -74947,14 +74953,20 @@ var T2000 = class _T2000 extends import_index.default {
74947
74953
  const agent = new _T2000(keypair, client, void 0, DEFAULT_CONFIG_DIR);
74948
74954
  const address = agent.address();
74949
74955
  let sponsored = false;
74956
+ let usdcSponsored = false;
74950
74957
  if (options.sponsored !== false) {
74951
74958
  try {
74952
74959
  await callSponsorApi(address, options.name);
74953
74960
  sponsored = true;
74954
74961
  } catch {
74955
74962
  }
74963
+ try {
74964
+ await callUsdcSponsorApi(address);
74965
+ usdcSponsored = true;
74966
+ } catch {
74967
+ }
74956
74968
  }
74957
- return { agent, address, sponsored };
74969
+ return { agent, address, sponsored, usdcSponsored };
74958
74970
  }
74959
74971
  // -- Gas --
74960
74972
  /** SuiJsonRpcClient used by this agent — exposed for integrations. */
@@ -77496,6 +77508,30 @@ async function callSponsorApi(address, name) {
77496
77508
  throw new T2000Error("SPONSOR_FAILED", "Sponsor API unavailable");
77497
77509
  }
77498
77510
  }
77511
+ async function callUsdcSponsorApi(address) {
77512
+ const res = await fetch(`${API_BASE_URL}/api/sponsor/usdc`, {
77513
+ method: "POST",
77514
+ headers: { "Content-Type": "application/json" },
77515
+ body: JSON.stringify({ address, source: "cli" })
77516
+ });
77517
+ if (res.status === 429) {
77518
+ const data = await res.json();
77519
+ if (data.challenge) {
77520
+ const proof = solveHashcash(data.challenge);
77521
+ const retry = await fetch(`${API_BASE_URL}/api/sponsor/usdc`, {
77522
+ method: "POST",
77523
+ headers: { "Content-Type": "application/json" },
77524
+ body: JSON.stringify({ address, source: "cli", proof })
77525
+ });
77526
+ if (!retry.ok) throw new T2000Error("USDC_SPONSOR_RATE_LIMITED", "USDC sponsor rate limited");
77527
+ return;
77528
+ }
77529
+ }
77530
+ if (res.status === 409) return;
77531
+ if (!res.ok) {
77532
+ throw new T2000Error("USDC_SPONSOR_FAILED", "USDC sponsor unavailable");
77533
+ }
77534
+ }
77499
77535
  async function simulateTransaction(client, tx, sender) {
77500
77536
  tx.setSender(sender);
77501
77537
  try {
@@ -77694,4 +77730,4 @@ lodash/lodash.js:
77694
77730
  *)
77695
77731
  *)
77696
77732
  */
77697
- //# sourceMappingURL=chunk-BPTNEFB5.js.map
77733
+ //# sourceMappingURL=chunk-FM4762OE.js.map