@t2000/cli 1.23.1 → 1.24.0

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.
@@ -24787,6 +24787,181 @@ var T2000 = class _T2000 extends import_index.default {
24787
24787
  };
24788
24788
  init_errors();
24789
24789
  init_coinSelection();
24790
+ init_errors();
24791
+ init_token_registry();
24792
+ init_cetus_swap();
24793
+ async function addHarvestToTx(tx, client, address, options = {}) {
24794
+ const slippage = options.slippage ?? 0.01;
24795
+ const minRewardUsd = options.minRewardUsd ?? 0.01;
24796
+ const priceCache = options.priceCache;
24797
+ let rawRewards;
24798
+ try {
24799
+ rawRewards = await vt(address, {
24800
+ env: "prod",
24801
+ client,
24802
+ markets: ["main"]
24803
+ });
24804
+ } catch (err) {
24805
+ const msg = err instanceof Error ? err.message : String(err);
24806
+ throw new T2000Error(
24807
+ "PROTOCOL_UNAVAILABLE",
24808
+ `NAVI rewards lookup failed: ${msg}`,
24809
+ { source: "navi-harvest-read" },
24810
+ true
24811
+ );
24812
+ }
24813
+ const claimable = (rawRewards ?? []).filter((r) => Number(r.userClaimableReward) > 0);
24814
+ if (claimable.length === 0) {
24815
+ throw new T2000Error(
24816
+ "INVALID_AMOUNT",
24817
+ "No pending rewards to harvest.",
24818
+ { source: "navi-harvest" }
24819
+ );
24820
+ }
24821
+ const aggregated = aggregateClaimableRewards(claimable);
24822
+ let claimed;
24823
+ try {
24824
+ const claimResult = await Ct(tx, claimable, {
24825
+ env: "prod",
24826
+ // 'skip' = NAVI doesn't auto-transfer; coin handles stay in the PTB
24827
+ // for downstream consumption. Verified against NAVI lending source
24828
+ // (index.esm.js@1828–1911) — when type !== 'transfer' && type !==
24829
+ // 'depositNAVI', the `else` branch pushes `{ coin, identifier, ... }`
24830
+ // to the return without consuming the handle.
24831
+ customCoinReceive: { type: "skip" }
24832
+ });
24833
+ const grouped = /* @__PURE__ */ new Map();
24834
+ for (const c of claimResult) {
24835
+ const ct2 = c.identifier.suiCoinType ?? "";
24836
+ if (!ct2) continue;
24837
+ const list = grouped.get(ct2) ?? [];
24838
+ list.push(c.coin);
24839
+ grouped.set(ct2, list);
24840
+ }
24841
+ claimed = [];
24842
+ for (const [coinType, handles] of grouped.entries()) {
24843
+ if (handles.length === 1) {
24844
+ claimed.push({ coin: handles[0], coinType });
24845
+ } else {
24846
+ const [dest, ...rest] = handles;
24847
+ tx.mergeCoins(dest, rest);
24848
+ claimed.push({ coin: dest, coinType });
24849
+ }
24850
+ }
24851
+ } catch (err) {
24852
+ const msg = err instanceof Error ? err.message : String(err);
24853
+ throw new T2000Error(
24854
+ "PROTOCOL_UNAVAILABLE",
24855
+ `NAVI claim PTB build failed: ${msg}`,
24856
+ { source: "navi-harvest-claim-ptb" },
24857
+ true
24858
+ );
24859
+ }
24860
+ const usdcHandles = [];
24861
+ const swaps = [];
24862
+ const skipped = [];
24863
+ let expectedUsdcDeposited = 0;
24864
+ for (const { coin, coinType } of claimed) {
24865
+ const aggRow = aggregated.find((r) => r.coinType === coinType);
24866
+ if (!aggRow) {
24867
+ continue;
24868
+ }
24869
+ if (coinType === USDC_TYPE) {
24870
+ usdcHandles.push(coin);
24871
+ expectedUsdcDeposited += aggRow.amount;
24872
+ continue;
24873
+ }
24874
+ const meta = getCoinMeta(coinType);
24875
+ const isTradeable = meta && (meta.tier === 1 || meta.tier === 2);
24876
+ if (!isTradeable) {
24877
+ tx.transferObjects([coin], address);
24878
+ skipped.push({
24879
+ symbol: aggRow.symbol,
24880
+ coinType,
24881
+ amount: aggRow.amount,
24882
+ reason: "untradeable"
24883
+ });
24884
+ continue;
24885
+ }
24886
+ if (priceCache && minRewardUsd > 0) {
24887
+ const px = priceCache.get(aggRow.symbol.toUpperCase());
24888
+ if (px && px > 0 && aggRow.amount * px < minRewardUsd) {
24889
+ tx.transferObjects([coin], address);
24890
+ skipped.push({
24891
+ symbol: aggRow.symbol,
24892
+ coinType,
24893
+ amount: aggRow.amount,
24894
+ reason: "dust"
24895
+ });
24896
+ continue;
24897
+ }
24898
+ }
24899
+ try {
24900
+ const swapResult = await addSwapToTx(tx, client, address, {
24901
+ from: aggRow.symbol,
24902
+ to: "USDC",
24903
+ amount: aggRow.amount,
24904
+ slippage,
24905
+ inputCoin: coin,
24906
+ providers: options.providers
24907
+ });
24908
+ usdcHandles.push(swapResult.coin);
24909
+ expectedUsdcDeposited += swapResult.expectedAmountOut;
24910
+ swaps.push({
24911
+ fromSymbol: aggRow.symbol,
24912
+ fromCoinType: coinType,
24913
+ toSymbol: "USDC",
24914
+ inputAmount: swapResult.effectiveAmountIn,
24915
+ expectedOutputUsdc: swapResult.expectedAmountOut
24916
+ });
24917
+ } catch (err) {
24918
+ const code = err instanceof T2000Error ? err.code : "UNKNOWN";
24919
+ if (code !== "SWAP_NO_ROUTE" && code !== "SWAP_FAILED") {
24920
+ throw err;
24921
+ }
24922
+ tx.transferObjects([coin], address);
24923
+ skipped.push({
24924
+ symbol: aggRow.symbol,
24925
+ coinType,
24926
+ amount: aggRow.amount,
24927
+ reason: "no-route"
24928
+ });
24929
+ }
24930
+ }
24931
+ if (usdcHandles.length > 0) {
24932
+ let depositCoin;
24933
+ if (usdcHandles.length === 1) {
24934
+ depositCoin = usdcHandles[0];
24935
+ } else {
24936
+ const [primary, ...rest] = usdcHandles;
24937
+ tx.mergeCoins(primary, rest);
24938
+ depositCoin = primary;
24939
+ }
24940
+ try {
24941
+ await addSaveToTx(tx, client, address, depositCoin, { asset: "USDC" });
24942
+ } catch (err) {
24943
+ const msg = err instanceof Error ? err.message : String(err);
24944
+ throw new T2000Error(
24945
+ "PROTOCOL_UNAVAILABLE",
24946
+ `NAVI deposit failed during harvest: ${msg}`,
24947
+ { source: "navi-harvest-deposit" },
24948
+ true
24949
+ );
24950
+ }
24951
+ }
24952
+ return {
24953
+ claimed: aggregated,
24954
+ swaps,
24955
+ skipped,
24956
+ expectedUsdcDeposited
24957
+ };
24958
+ }
24959
+ async function buildHarvestRewardsTx(client, address, options = {}) {
24960
+ const tx = new Transaction();
24961
+ tx.setSender(address);
24962
+ const plan = await addHarvestToTx(tx, client, address, options);
24963
+ return { tx, plan };
24964
+ }
24790
24965
  init_cetus_swap();
24791
24966
  init_volo();
24792
24967
  init_coinSelection();
@@ -24986,6 +25161,29 @@ var WRITE_APPENDER_REGISTRY = {
24986
25161
  const rewards = await addClaimRewardsToTx(tx, ctx.client, ctx.sender);
24987
25162
  return { preview: { toolName: "claim_rewards", rewards } };
24988
25163
  },
25164
+ // [Track B / 2026-05-08] Macro appender — assembles claim → swap(s) →
25165
+ // save inline. The audric host wires `getSponsoredSwapProviders()` into
25166
+ // `options.providers` automatically when `ctx.sponsoredContext === true`
25167
+ // (parity with `swap_execute` below). Slippage + dust-floor pulled from
25168
+ // the input; price cache is forwarded from the host so the dust filter
25169
+ // can compare claimed amounts to USD.
25170
+ harvest_rewards: async (tx, input, ctx) => {
25171
+ const providers = ctx.sponsoredContext ? await getSponsoredSwapProviders() : void 0;
25172
+ const plan = await addHarvestToTx(tx, ctx.client, ctx.sender, {
25173
+ slippage: input.slippage,
25174
+ minRewardUsd: input.minRewardUsd,
25175
+ providers
25176
+ });
25177
+ return {
25178
+ preview: {
25179
+ toolName: "harvest_rewards",
25180
+ claimed: plan.claimed,
25181
+ swaps: plan.swaps,
25182
+ skipped: plan.skipped,
25183
+ expectedUsdcDeposited: plan.expectedUsdcDeposited
25184
+ }
25185
+ };
25186
+ },
24989
25187
  volo_stake: async (tx, input, ctx) => {
24990
25188
  if (input.amountSui <= 0) {
24991
25189
  throw new T2000Error("INVALID_AMOUNT", "Stake amount must be greater than zero");
@@ -25499,6 +25697,7 @@ export {
25499
25697
  SafeguardEnforcer,
25500
25698
  ContactManager,
25501
25699
  T2000,
25700
+ buildHarvestRewardsTx,
25502
25701
  WRITE_APPENDER_REGISTRY,
25503
25702
  deriveAllowedAddressesFromPtb,
25504
25703
  composeTx,
@@ -25541,4 +25740,4 @@ axios/dist/node/axios.cjs:
25541
25740
  @scure/bip39/index.js:
25542
25741
  (*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
25543
25742
  */
25544
- //# sourceMappingURL=chunk-IR2QGWUU.js.map
25743
+ //# sourceMappingURL=chunk-JDOIQPNR.js.map