@t2000/cli 1.22.2 → 1.23.1

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.
@@ -22466,35 +22466,6 @@ async function vt(e, n) {
22466
22466
  );
22467
22467
  return await De(e, t, n);
22468
22468
  }
22469
- function wt(e) {
22470
- const n = /* @__PURE__ */ new Map();
22471
- e.forEach((r) => {
22472
- const t = r.assetId, a = r.option, s = `${t}-${a}-${r.rewardCoinType}-${r.market}`;
22473
- n.has(s) ? n.get(s).total += r.userClaimableReward : n.set(s, {
22474
- assetId: t,
22475
- rewardType: a,
22476
- coinType: r.rewardCoinType,
22477
- total: Number(r.userClaimableReward),
22478
- market: r.market
22479
- });
22480
- });
22481
- const o = /* @__PURE__ */ new Map();
22482
- for (const { assetId: r, rewardType: t, coinType: a, total: s, market: i } of n.values()) {
22483
- const c = `${r}-${t}-${i}`;
22484
- o.has(c) || o.set(c, { assetId: r, rewardType: t, market: i, rewards: /* @__PURE__ */ new Map() });
22485
- const u = o.get(c);
22486
- u.rewards.set(a, (u.rewards.get(a) || 0) + s);
22487
- }
22488
- return Array.from(o.values()).map((r) => ({
22489
- assetId: r.assetId,
22490
- rewardType: r.rewardType,
22491
- market: r.market,
22492
- rewards: Array.from(r.rewards.entries()).map(([t, a]) => ({
22493
- coinType: t,
22494
- available: a.toFixed(6)
22495
- }))
22496
- }));
22497
- }
22498
22469
  async function Ct(e, n, o) {
22499
22470
  const r = await R({
22500
22471
  ...o,
@@ -22670,6 +22641,7 @@ async function Ct(e, n, o) {
22670
22641
  return a;
22671
22642
  }
22672
22643
  init_errors();
22644
+ init_token_registry();
22673
22645
  var MIN_HEALTH_FACTOR = 1.5;
22674
22646
  function sdkOptions(client) {
22675
22647
  return { env: "prod", client, cacheTime: 0, disableCache: true };
@@ -23028,53 +23000,61 @@ async function maxBorrowAmount(client, address) {
23028
23000
  return { maxAmount, healthFactorAfter: MIN_HEALTH_FACTOR, currentHF: hf.healthFactor };
23029
23001
  }
23030
23002
  async function getPendingRewards(client, address) {
23003
+ let rewards;
23031
23004
  try {
23032
- const rewards = await vt(address, {
23005
+ rewards = await vt(address, {
23033
23006
  ...sdkOptions(client),
23034
23007
  markets: ["main"]
23035
23008
  });
23036
- if (!rewards || rewards.length === 0) return [];
23037
- const summary = wt(rewards);
23038
- const result = [];
23039
- for (const s of summary) {
23040
- for (const rw of s.rewards) {
23041
- const available = Number(rw.available);
23042
- if (available <= 0) continue;
23043
- const symbol = rw.coinType.split("::").pop() ?? "UNKNOWN";
23044
- result.push({
23045
- protocol: "navi",
23046
- asset: String(s.assetId),
23047
- coinType: rw.coinType,
23048
- symbol,
23049
- amount: available,
23050
- estimatedValueUsd: 0
23051
- });
23052
- }
23053
- }
23054
- return result;
23055
- } catch {
23056
- return [];
23009
+ } catch (err) {
23010
+ const msg = err instanceof Error ? err.message : String(err);
23011
+ throw new T2000Error(
23012
+ "PROTOCOL_UNAVAILABLE",
23013
+ `NAVI rewards lookup failed: ${msg}`,
23014
+ { source: "navi-rewards-read" },
23015
+ true
23016
+ );
23057
23017
  }
23018
+ if (!rewards || rewards.length === 0) return [];
23019
+ const claimable = rewards.filter((r) => Number(r.userClaimableReward) > 0);
23020
+ return aggregateClaimableRewards(claimable);
23058
23021
  }
23059
23022
  async function addClaimRewardsToTx(tx, client, address) {
23023
+ let rewards;
23060
23024
  try {
23061
- const rewards = await vt(address, {
23025
+ rewards = await vt(address, {
23062
23026
  ...sdkOptions(client),
23063
23027
  markets: ["main"]
23064
23028
  });
23065
- if (!rewards || rewards.length === 0) return [];
23066
- const claimable = rewards.filter(
23067
- (r) => Number(r.userClaimableReward) > 0
23029
+ } catch (err) {
23030
+ const msg = err instanceof Error ? err.message : String(err);
23031
+ throw new T2000Error(
23032
+ "PROTOCOL_UNAVAILABLE",
23033
+ `NAVI rewards lookup failed: ${msg}`,
23034
+ { source: "navi-rewards-claim-prelude" },
23035
+ true
23068
23036
  );
23069
- if (claimable.length === 0) return [];
23037
+ }
23038
+ if (!rewards || rewards.length === 0) return [];
23039
+ const claimable = rewards.filter(
23040
+ (r) => Number(r.userClaimableReward) > 0
23041
+ );
23042
+ if (claimable.length === 0) return [];
23043
+ try {
23070
23044
  await Ct(tx, claimable, {
23071
23045
  env: "prod",
23072
23046
  customCoinReceive: { type: "transfer", transfer: address }
23073
23047
  });
23074
- return aggregateClaimableRewards(claimable);
23075
- } catch {
23076
- return [];
23048
+ } catch (err) {
23049
+ const msg = err instanceof Error ? err.message : String(err);
23050
+ throw new T2000Error(
23051
+ "PROTOCOL_UNAVAILABLE",
23052
+ `NAVI claim PTB build failed: ${msg}`,
23053
+ { source: "navi-rewards-claim-ptb" },
23054
+ true
23055
+ );
23077
23056
  }
23057
+ return aggregateClaimableRewards(claimable);
23078
23058
  }
23079
23059
  async function buildClaimRewardsTx(client, address) {
23080
23060
  const tx = new Transaction();
@@ -23087,7 +23067,8 @@ function aggregateClaimableRewards(claimable) {
23087
23067
  for (const c of claimable) {
23088
23068
  const coinType = c.rewardCoinType;
23089
23069
  if (!coinType) continue;
23090
- const symbol = coinType.split("::").pop() ?? "REWARD";
23070
+ const meta = getCoinMeta(coinType);
23071
+ const symbol = meta?.symbol ?? coinType.split("::").pop() ?? "REWARD";
23091
23072
  const amount = Number(c.userClaimableReward);
23092
23073
  if (!Number.isFinite(amount) || amount <= 0) continue;
23093
23074
  const existing = aggregated.get(coinType);
@@ -24520,13 +24501,20 @@ var T2000 = class _T2000 extends import_index.default {
24520
24501
  }
24521
24502
  // -- Claim Rewards --
24522
24503
  async getPendingRewards() {
24523
- const adapters = this.registry.listLending();
24504
+ const adapters = this.registry.listLending().filter((a) => a.getPendingRewards);
24505
+ if (adapters.length === 0) return [];
24524
24506
  const results = await Promise.allSettled(
24525
- adapters.filter((a) => a.getPendingRewards).map((a) => a.getPendingRewards(this._address))
24507
+ adapters.map((a) => a.getPendingRewards(this._address))
24526
24508
  );
24527
24509
  const all = [];
24510
+ const errors = [];
24528
24511
  for (const r of results) {
24529
24512
  if (r.status === "fulfilled") all.push(...r.value);
24513
+ else errors.push(r.reason);
24514
+ }
24515
+ if (all.length === 0 && errors.length === adapters.length) {
24516
+ const first = errors[0];
24517
+ throw first instanceof Error ? first : new Error(String(first));
24530
24518
  }
24531
24519
  return all;
24532
24520
  }
@@ -24539,13 +24527,19 @@ var T2000 = class _T2000 extends import_index.default {
24539
24527
  const tx = new Transaction();
24540
24528
  tx.setSender(this._address);
24541
24529
  const allRewards = [];
24530
+ const errors = [];
24542
24531
  for (const adapter of adapters) {
24543
24532
  try {
24544
24533
  const claimed = await adapter.addClaimRewardsToTx(tx, this._address);
24545
24534
  allRewards.push(...claimed);
24546
- } catch {
24535
+ } catch (err) {
24536
+ errors.push(err);
24547
24537
  }
24548
24538
  }
24539
+ if (allRewards.length === 0 && errors.length === adapters.length) {
24540
+ const first = errors[0];
24541
+ throw first instanceof Error ? first : new Error(String(first));
24542
+ }
24549
24543
  if (allRewards.length === 0) {
24550
24544
  return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0 };
24551
24545
  }
@@ -25387,6 +25381,10 @@ function buildRevokeLeafTx(suinsClient, { label }) {
25387
25381
  function fullHandle(label) {
25388
25382
  return `${label}.${AUDRIC_PARENT_NAME}`;
25389
25383
  }
25384
+ function displayHandle(label) {
25385
+ const parentDisplay = AUDRIC_PARENT_NAME.replace(/\.sui$/, "");
25386
+ return `${label}@${parentDisplay}`;
25387
+ }
25390
25388
 
25391
25389
  export {
25392
25390
  mapWalletError,
@@ -25488,7 +25486,9 @@ export {
25488
25486
  extractTxCommands,
25489
25487
  getRates,
25490
25488
  getPendingRewards,
25489
+ addClaimRewardsToTx,
25491
25490
  buildClaimRewardsTx,
25491
+ aggregateClaimableRewards,
25492
25492
  ProtocolRegistry,
25493
25493
  naviDescriptor,
25494
25494
  allDescriptors,
@@ -25515,7 +25515,8 @@ export {
25515
25515
  validateLabel,
25516
25516
  buildAddLeafTx,
25517
25517
  buildRevokeLeafTx,
25518
- fullHandle
25518
+ fullHandle,
25519
+ displayHandle
25519
25520
  };
25520
25521
  /*! Bundled license information:
25521
25522
 
@@ -25540,4 +25541,4 @@ axios/dist/node/axios.cjs:
25540
25541
  @scure/bip39/index.js:
25541
25542
  (*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
25542
25543
  */
25543
- //# sourceMappingURL=chunk-COE5RRNH.js.map
25544
+ //# sourceMappingURL=chunk-IR2QGWUU.js.map