@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.
@@ -52,11 +52,13 @@ import {
52
52
  WBTC_TYPE,
53
53
  WRITE_APPENDER_REGISTRY,
54
54
  ZkLoginSigner,
55
+ addClaimRewardsToTx,
55
56
  addFeeTransfer,
56
57
  addSendToTx,
57
58
  addStakeVSuiToTx,
58
59
  addSwapToTx,
59
60
  addUnstakeVSuiToTx,
61
+ aggregateClaimableRewards,
60
62
  allDescriptors,
61
63
  assertAllowedAsset,
62
64
  buildAddLeafTx,
@@ -72,6 +74,7 @@ import {
72
74
  classifyTransaction,
73
75
  composeTx,
74
76
  deriveAllowedAddressesFromPtb,
77
+ displayHandle,
75
78
  exportPrivateKey,
76
79
  extractTransferDetails,
77
80
  extractTxCommands,
@@ -127,7 +130,7 @@ import {
127
130
  validateAddress,
128
131
  validateLabel,
129
132
  walletExists
130
- } from "./chunk-COE5RRNH.js";
133
+ } from "./chunk-IR2QGWUU.js";
131
134
  import "./chunk-Z74HUTKM.js";
132
135
  import "./chunk-V7PXDEKG.js";
133
136
  import "./chunk-UY3WLP52.js";
@@ -186,11 +189,13 @@ export {
186
189
  WBTC_TYPE,
187
190
  WRITE_APPENDER_REGISTRY,
188
191
  ZkLoginSigner,
192
+ addClaimRewardsToTx,
189
193
  addFeeTransfer,
190
194
  addSendToTx,
191
195
  addStakeVSuiToTx,
192
196
  addSwapToTx,
193
197
  addUnstakeVSuiToTx,
198
+ aggregateClaimableRewards,
194
199
  allDescriptors,
195
200
  assertAllowedAsset,
196
201
  buildAddLeafTx,
@@ -206,6 +211,7 @@ export {
206
211
  classifyTransaction,
207
212
  composeTx,
208
213
  deriveAllowedAddressesFromPtb,
214
+ displayHandle,
209
215
  exportPrivateKey,
210
216
  extractTransferDetails,
211
217
  extractTxCommands,
@@ -262,4 +268,4 @@ export {
262
268
  validateLabel,
263
269
  walletExists
264
270
  };
265
- //# sourceMappingURL=dist-XSJQIU5E.js.map
271
+ //# sourceMappingURL=dist-K2TQP3EL.js.map
@@ -136083,35 +136083,6 @@ async function vt(e, n) {
136083
136083
  );
136084
136084
  return await De(e, t, n);
136085
136085
  }
136086
- function wt(e) {
136087
- const n = /* @__PURE__ */ new Map();
136088
- e.forEach((r) => {
136089
- const t = r.assetId, a = r.option, s = `${t}-${a}-${r.rewardCoinType}-${r.market}`;
136090
- n.has(s) ? n.get(s).total += r.userClaimableReward : n.set(s, {
136091
- assetId: t,
136092
- rewardType: a,
136093
- coinType: r.rewardCoinType,
136094
- total: Number(r.userClaimableReward),
136095
- market: r.market
136096
- });
136097
- });
136098
- const o = /* @__PURE__ */ new Map();
136099
- for (const { assetId: r, rewardType: t, coinType: a, total: s, market: i } of n.values()) {
136100
- const c = `${r}-${t}-${i}`;
136101
- o.has(c) || o.set(c, { assetId: r, rewardType: t, market: i, rewards: /* @__PURE__ */ new Map() });
136102
- const u2 = o.get(c);
136103
- u2.rewards.set(a, (u2.rewards.get(a) || 0) + s);
136104
- }
136105
- return Array.from(o.values()).map((r) => ({
136106
- assetId: r.assetId,
136107
- rewardType: r.rewardType,
136108
- market: r.market,
136109
- rewards: Array.from(r.rewards.entries()).map(([t, a]) => ({
136110
- coinType: t,
136111
- available: a.toFixed(6)
136112
- }))
136113
- }));
136114
- }
136115
136086
  async function Ct(e, n, o) {
136116
136087
  const r = await R2({
136117
136088
  ...o,
@@ -136287,6 +136258,7 @@ async function Ct(e, n, o) {
136287
136258
  return a;
136288
136259
  }
136289
136260
  init_errors7();
136261
+ init_token_registry();
136290
136262
  var MIN_HEALTH_FACTOR = 1.5;
136291
136263
  function sdkOptions(client) {
136292
136264
  return { env: "prod", client, cacheTime: 0, disableCache: true };
@@ -136645,60 +136617,69 @@ async function maxBorrowAmount(client, address2) {
136645
136617
  return { maxAmount, healthFactorAfter: MIN_HEALTH_FACTOR, currentHF: hf.healthFactor };
136646
136618
  }
136647
136619
  async function getPendingRewards2(client, address2) {
136620
+ let rewards;
136648
136621
  try {
136649
- const rewards = await vt(address2, {
136622
+ rewards = await vt(address2, {
136650
136623
  ...sdkOptions(client),
136651
136624
  markets: ["main"]
136652
136625
  });
136653
- if (!rewards || rewards.length === 0) return [];
136654
- const summary = wt(rewards);
136655
- const result = [];
136656
- for (const s of summary) {
136657
- for (const rw of s.rewards) {
136658
- const available = Number(rw.available);
136659
- if (available <= 0) continue;
136660
- const symbol2 = rw.coinType.split("::").pop() ?? "UNKNOWN";
136661
- result.push({
136662
- protocol: "navi",
136663
- asset: String(s.assetId),
136664
- coinType: rw.coinType,
136665
- symbol: symbol2,
136666
- amount: available,
136667
- estimatedValueUsd: 0
136668
- });
136669
- }
136670
- }
136671
- return result;
136672
- } catch {
136673
- return [];
136626
+ } catch (err) {
136627
+ const msg = err instanceof Error ? err.message : String(err);
136628
+ throw new T2000Error(
136629
+ "PROTOCOL_UNAVAILABLE",
136630
+ `NAVI rewards lookup failed: ${msg}`,
136631
+ { source: "navi-rewards-read" },
136632
+ true
136633
+ );
136674
136634
  }
136635
+ if (!rewards || rewards.length === 0) return [];
136636
+ const claimable = rewards.filter((r) => Number(r.userClaimableReward) > 0);
136637
+ return aggregateClaimableRewards(claimable);
136675
136638
  }
136676
136639
  async function addClaimRewardsToTx(tx, client, address2) {
136640
+ let rewards;
136677
136641
  try {
136678
- const rewards = await vt(address2, {
136642
+ rewards = await vt(address2, {
136679
136643
  ...sdkOptions(client),
136680
136644
  markets: ["main"]
136681
136645
  });
136682
- if (!rewards || rewards.length === 0) return [];
136683
- const claimable = rewards.filter(
136684
- (r) => Number(r.userClaimableReward) > 0
136646
+ } catch (err) {
136647
+ const msg = err instanceof Error ? err.message : String(err);
136648
+ throw new T2000Error(
136649
+ "PROTOCOL_UNAVAILABLE",
136650
+ `NAVI rewards lookup failed: ${msg}`,
136651
+ { source: "navi-rewards-claim-prelude" },
136652
+ true
136685
136653
  );
136686
- if (claimable.length === 0) return [];
136654
+ }
136655
+ if (!rewards || rewards.length === 0) return [];
136656
+ const claimable = rewards.filter(
136657
+ (r) => Number(r.userClaimableReward) > 0
136658
+ );
136659
+ if (claimable.length === 0) return [];
136660
+ try {
136687
136661
  await Ct(tx, claimable, {
136688
136662
  env: "prod",
136689
136663
  customCoinReceive: { type: "transfer", transfer: address2 }
136690
136664
  });
136691
- return aggregateClaimableRewards(claimable);
136692
- } catch {
136693
- return [];
136665
+ } catch (err) {
136666
+ const msg = err instanceof Error ? err.message : String(err);
136667
+ throw new T2000Error(
136668
+ "PROTOCOL_UNAVAILABLE",
136669
+ `NAVI claim PTB build failed: ${msg}`,
136670
+ { source: "navi-rewards-claim-ptb" },
136671
+ true
136672
+ );
136694
136673
  }
136674
+ return aggregateClaimableRewards(claimable);
136695
136675
  }
136696
136676
  function aggregateClaimableRewards(claimable) {
136697
136677
  const aggregated = /* @__PURE__ */ new Map();
136698
136678
  for (const c of claimable) {
136699
136679
  const coinType = c.rewardCoinType;
136700
136680
  if (!coinType) continue;
136701
- const symbol2 = coinType.split("::").pop() ?? "REWARD";
136681
+ const meta3 = getCoinMeta(coinType);
136682
+ const symbol2 = meta3?.symbol ?? coinType.split("::").pop() ?? "REWARD";
136702
136683
  const amount2 = Number(c.userClaimableReward);
136703
136684
  if (!Number.isFinite(amount2) || amount2 <= 0) continue;
136704
136685
  const existing = aggregated.get(coinType);
@@ -138112,13 +138093,20 @@ var T2000 = class _T2000 extends import_index2.default {
138112
138093
  }
138113
138094
  // -- Claim Rewards --
138114
138095
  async getPendingRewards() {
138115
- const adapters = this.registry.listLending();
138096
+ const adapters = this.registry.listLending().filter((a) => a.getPendingRewards);
138097
+ if (adapters.length === 0) return [];
138116
138098
  const results = await Promise.allSettled(
138117
- adapters.filter((a) => a.getPendingRewards).map((a) => a.getPendingRewards(this._address))
138099
+ adapters.map((a) => a.getPendingRewards(this._address))
138118
138100
  );
138119
138101
  const all3 = [];
138102
+ const errors = [];
138120
138103
  for (const r of results) {
138121
138104
  if (r.status === "fulfilled") all3.push(...r.value);
138105
+ else errors.push(r.reason);
138106
+ }
138107
+ if (all3.length === 0 && errors.length === adapters.length) {
138108
+ const first = errors[0];
138109
+ throw first instanceof Error ? first : new Error(String(first));
138122
138110
  }
138123
138111
  return all3;
138124
138112
  }
@@ -138131,13 +138119,19 @@ var T2000 = class _T2000 extends import_index2.default {
138131
138119
  const tx = new Transaction();
138132
138120
  tx.setSender(this._address);
138133
138121
  const allRewards = [];
138122
+ const errors = [];
138134
138123
  for (const adapter2 of adapters) {
138135
138124
  try {
138136
138125
  const claimed = await adapter2.addClaimRewardsToTx(tx, this._address);
138137
138126
  allRewards.push(...claimed);
138138
- } catch {
138127
+ } catch (err) {
138128
+ errors.push(err);
138139
138129
  }
138140
138130
  }
138131
+ if (allRewards.length === 0 && errors.length === adapters.length) {
138132
+ const first = errors[0];
138133
+ throw first instanceof Error ? first : new Error(String(first));
138134
+ }
138141
138135
  if (allRewards.length === 0) {
138142
138136
  return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0 };
138143
138137
  }
@@ -139672,7 +139666,7 @@ ${context}
139672
139666
  })
139673
139667
  );
139674
139668
  }
139675
- var PKG_VERSION = "1.22.2";
139669
+ var PKG_VERSION = "1.23.1";
139676
139670
  console.log = (...args) => console.error("[log]", ...args);
139677
139671
  console.warn = (...args) => console.error("[warn]", ...args);
139678
139672
  async function startMcpServer(opts) {
@@ -139762,4 +139756,4 @@ axios/dist/node/axios.cjs:
139762
139756
  @scure/bip39/index.js:
139763
139757
  (*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
139764
139758
  */
139765
- //# sourceMappingURL=dist-7TDENFJA.js.map
139759
+ //# sourceMappingURL=dist-K4ONVV5A.js.map