@t2000/sdk 1.23.1 → 1.24.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.
package/dist/index.js CHANGED
@@ -5634,6 +5634,14 @@ async function maxBorrowAmount(client, address) {
5634
5634
  const maxAmount = Math.max(0, hf.supplied * ltv / MIN_HEALTH_FACTOR - hf.borrowed);
5635
5635
  return { maxAmount, healthFactorAfter: MIN_HEALTH_FACTOR, currentHF: hf.healthFactor };
5636
5636
  }
5637
+ async function getPendingRewardsByAddress(address, suiRpcUrl) {
5638
+ const { SuiJsonRpcClient: SuiJsonRpcClient2, getJsonRpcFullnodeUrl: getJsonRpcFullnodeUrl2 } = await import('@mysten/sui/jsonRpc');
5639
+ const client = new SuiJsonRpcClient2({
5640
+ url: suiRpcUrl ?? getJsonRpcFullnodeUrl2("mainnet"),
5641
+ network: "mainnet"
5642
+ });
5643
+ return getPendingRewards(client, address);
5644
+ }
5637
5645
  async function getPendingRewards(client, address) {
5638
5646
  let rewards;
5639
5647
  try {
@@ -7442,6 +7450,183 @@ var T2000 = class _T2000 extends EventEmitter {
7442
7450
  // src/index.ts
7443
7451
  init_errors();
7444
7452
  init_coinSelection();
7453
+ init_errors();
7454
+ init_token_registry();
7455
+ init_cetus_swap();
7456
+ async function addHarvestToTx(tx, client, address, options = {}) {
7457
+ const slippage = options.slippage ?? 0.01;
7458
+ const minRewardUsd = options.minRewardUsd ?? 0.01;
7459
+ const priceCache = options.priceCache;
7460
+ let rawRewards;
7461
+ try {
7462
+ rawRewards = await vt(address, {
7463
+ env: "prod",
7464
+ client,
7465
+ markets: ["main"]
7466
+ });
7467
+ } catch (err) {
7468
+ const msg = err instanceof Error ? err.message : String(err);
7469
+ throw new T2000Error(
7470
+ "PROTOCOL_UNAVAILABLE",
7471
+ `NAVI rewards lookup failed: ${msg}`,
7472
+ { source: "navi-harvest-read" },
7473
+ true
7474
+ );
7475
+ }
7476
+ const claimable = (rawRewards ?? []).filter((r) => Number(r.userClaimableReward) > 0);
7477
+ if (claimable.length === 0) {
7478
+ throw new T2000Error(
7479
+ "INVALID_AMOUNT",
7480
+ "No pending rewards to harvest.",
7481
+ { source: "navi-harvest" }
7482
+ );
7483
+ }
7484
+ const aggregated = aggregateClaimableRewards(claimable);
7485
+ let claimed;
7486
+ try {
7487
+ const claimResult = await Ct(tx, claimable, {
7488
+ env: "prod",
7489
+ // 'skip' = NAVI doesn't auto-transfer; coin handles stay in the PTB
7490
+ // for downstream consumption. Verified against NAVI lending source
7491
+ // (index.esm.js@1828–1911) — when type !== 'transfer' && type !==
7492
+ // 'depositNAVI', the `else` branch pushes `{ coin, identifier, ... }`
7493
+ // to the return without consuming the handle.
7494
+ customCoinReceive: { type: "skip" }
7495
+ });
7496
+ const grouped = /* @__PURE__ */ new Map();
7497
+ for (const c of claimResult) {
7498
+ const ct2 = c.identifier.suiCoinType ?? "";
7499
+ if (!ct2) continue;
7500
+ const list = grouped.get(ct2) ?? [];
7501
+ list.push(c.coin);
7502
+ grouped.set(ct2, list);
7503
+ }
7504
+ claimed = [];
7505
+ for (const [coinType, handles] of grouped.entries()) {
7506
+ if (handles.length === 1) {
7507
+ claimed.push({ coin: handles[0], coinType });
7508
+ } else {
7509
+ const [dest, ...rest] = handles;
7510
+ tx.mergeCoins(dest, rest);
7511
+ claimed.push({ coin: dest, coinType });
7512
+ }
7513
+ }
7514
+ } catch (err) {
7515
+ const msg = err instanceof Error ? err.message : String(err);
7516
+ throw new T2000Error(
7517
+ "PROTOCOL_UNAVAILABLE",
7518
+ `NAVI claim PTB build failed: ${msg}`,
7519
+ { source: "navi-harvest-claim-ptb" },
7520
+ true
7521
+ );
7522
+ }
7523
+ const usdcHandles = [];
7524
+ const swaps = [];
7525
+ const skipped = [];
7526
+ let expectedUsdcDeposited = 0;
7527
+ for (const { coin, coinType } of claimed) {
7528
+ const aggRow = aggregated.find((r) => r.coinType === coinType);
7529
+ if (!aggRow) {
7530
+ continue;
7531
+ }
7532
+ if (coinType === USDC_TYPE) {
7533
+ usdcHandles.push(coin);
7534
+ expectedUsdcDeposited += aggRow.amount;
7535
+ continue;
7536
+ }
7537
+ const meta = getCoinMeta(coinType);
7538
+ const isTradeable = meta && (meta.tier === 1 || meta.tier === 2);
7539
+ if (!isTradeable) {
7540
+ tx.transferObjects([coin], address);
7541
+ skipped.push({
7542
+ symbol: aggRow.symbol,
7543
+ coinType,
7544
+ amount: aggRow.amount,
7545
+ reason: "untradeable"
7546
+ });
7547
+ continue;
7548
+ }
7549
+ if (priceCache && minRewardUsd > 0) {
7550
+ const px = priceCache.get(aggRow.symbol.toUpperCase());
7551
+ if (px && px > 0 && aggRow.amount * px < minRewardUsd) {
7552
+ tx.transferObjects([coin], address);
7553
+ skipped.push({
7554
+ symbol: aggRow.symbol,
7555
+ coinType,
7556
+ amount: aggRow.amount,
7557
+ reason: "dust"
7558
+ });
7559
+ continue;
7560
+ }
7561
+ }
7562
+ try {
7563
+ const swapResult = await addSwapToTx(tx, client, address, {
7564
+ from: aggRow.symbol,
7565
+ to: "USDC",
7566
+ amount: aggRow.amount,
7567
+ slippage,
7568
+ inputCoin: coin,
7569
+ providers: options.providers
7570
+ });
7571
+ usdcHandles.push(swapResult.coin);
7572
+ expectedUsdcDeposited += swapResult.expectedAmountOut;
7573
+ swaps.push({
7574
+ fromSymbol: aggRow.symbol,
7575
+ fromCoinType: coinType,
7576
+ toSymbol: "USDC",
7577
+ inputAmount: swapResult.effectiveAmountIn,
7578
+ expectedOutputUsdc: swapResult.expectedAmountOut
7579
+ });
7580
+ } catch (err) {
7581
+ const code = err instanceof T2000Error ? err.code : "UNKNOWN";
7582
+ if (code !== "SWAP_NO_ROUTE" && code !== "SWAP_FAILED") {
7583
+ throw err;
7584
+ }
7585
+ tx.transferObjects([coin], address);
7586
+ skipped.push({
7587
+ symbol: aggRow.symbol,
7588
+ coinType,
7589
+ amount: aggRow.amount,
7590
+ reason: "no-route"
7591
+ });
7592
+ }
7593
+ }
7594
+ if (usdcHandles.length > 0) {
7595
+ let depositCoin;
7596
+ if (usdcHandles.length === 1) {
7597
+ depositCoin = usdcHandles[0];
7598
+ } else {
7599
+ const [primary, ...rest] = usdcHandles;
7600
+ tx.mergeCoins(primary, rest);
7601
+ depositCoin = primary;
7602
+ }
7603
+ try {
7604
+ await addSaveToTx(tx, client, address, depositCoin, { asset: "USDC" });
7605
+ } catch (err) {
7606
+ const msg = err instanceof Error ? err.message : String(err);
7607
+ throw new T2000Error(
7608
+ "PROTOCOL_UNAVAILABLE",
7609
+ `NAVI deposit failed during harvest: ${msg}`,
7610
+ { source: "navi-harvest-deposit" },
7611
+ true
7612
+ );
7613
+ }
7614
+ }
7615
+ return {
7616
+ claimed: aggregated,
7617
+ swaps,
7618
+ skipped,
7619
+ expectedUsdcDeposited
7620
+ };
7621
+ }
7622
+ async function buildHarvestRewardsTx(client, address, options = {}) {
7623
+ const tx = new Transaction();
7624
+ tx.setSender(address);
7625
+ const plan = await addHarvestToTx(tx, client, address, options);
7626
+ return { tx, plan };
7627
+ }
7628
+
7629
+ // src/composeTx.ts
7445
7630
  init_cetus_swap();
7446
7631
  init_volo();
7447
7632
  init_coinSelection();
@@ -7641,6 +7826,29 @@ var WRITE_APPENDER_REGISTRY = {
7641
7826
  const rewards = await addClaimRewardsToTx(tx, ctx.client, ctx.sender);
7642
7827
  return { preview: { toolName: "claim_rewards", rewards } };
7643
7828
  },
7829
+ // [Track B / 2026-05-08] Macro appender — assembles claim → swap(s) →
7830
+ // save inline. The audric host wires `getSponsoredSwapProviders()` into
7831
+ // `options.providers` automatically when `ctx.sponsoredContext === true`
7832
+ // (parity with `swap_execute` below). Slippage + dust-floor pulled from
7833
+ // the input; price cache is forwarded from the host so the dust filter
7834
+ // can compare claimed amounts to USD.
7835
+ harvest_rewards: async (tx, input, ctx) => {
7836
+ const providers = ctx.sponsoredContext ? await getSponsoredSwapProviders() : void 0;
7837
+ const plan = await addHarvestToTx(tx, ctx.client, ctx.sender, {
7838
+ slippage: input.slippage,
7839
+ minRewardUsd: input.minRewardUsd,
7840
+ providers
7841
+ });
7842
+ return {
7843
+ preview: {
7844
+ toolName: "harvest_rewards",
7845
+ claimed: plan.claimed,
7846
+ swaps: plan.swaps,
7847
+ skipped: plan.skipped,
7848
+ expectedUsdcDeposited: plan.expectedUsdcDeposited
7849
+ }
7850
+ };
7851
+ },
7644
7852
  volo_stake: async (tx, input, ctx) => {
7645
7853
  if (input.amountSui <= 0) {
7646
7854
  throw new T2000Error("INVALID_AMOUNT", "Stake amount must be greater than zero");
@@ -8056,6 +8264,6 @@ function displayHandle(label) {
8056
8264
  (*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
8057
8265
  */
8058
8266
 
8059
- export { ALL_NAVI_ASSETS, AUDRIC_PARENT_NAME, AUDRIC_PARENT_NFT_ID, BORROW_FEE_BPS, BPS_DENOMINATOR, CETUS_USDC_SUI_POOL, CLOCK_ID, COIN_REGISTRY, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, ETH_TYPE, GAS_RESERVE_MIN, HF_CRITICAL_THRESHOLD, HF_WARN_THRESHOLD, IKA_TYPE, KNOWN_TARGETS, KeypairSigner, LABEL_PATTERNS, LOFI_TYPE, MANIFEST_TYPE, MIST_PER_SUI, NAVX_TYPE, NaviAdapter, OPERATION_ASSETS, OUTBOUND_OPS, OVERLAY_FEE_RATE, ProtocolRegistry, SAVE_FEE_BPS, STABLE_ASSETS, SUI_DECIMALS, SUI_TYPE, SUPPORTED_ASSETS, SafeguardEnforcer, SafeguardError, T2000, T2000Error, T2000_OVERLAY_FEE_WALLET, TOKEN_MAP, USDC_DECIMALS, USDC_TYPE, USDE_TYPE, USDSUI_TYPE, USDT_TYPE, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, WAL_TYPE, WBTC_TYPE, WRITE_APPENDER_REGISTRY, ZkLoginSigner, addClaimRewardsToTx, addFeeTransfer, addSendToTx, addStakeVSuiToTx, addSwapToTx, addUnstakeVSuiToTx, aggregateClaimableRewards, allDescriptors, assertAllowedAsset, buildAddLeafTx, buildClaimRewardsTx, buildRevokeLeafTx, buildSendTx, buildStakeVSuiTx, buildSwapTx, buildUnstakeVSuiTx, calculateFee, classifyAction, classifyLabel, classifyTransaction, composeTx, deriveAllowedAddressesFromPtb, displayHandle, exportPrivateKey, extractTransferDetails, extractTxCommands, extractTxSender, fallbackLabel, fetchAllCoins, findSwapRoute, formatAssetAmount, formatSui, formatUsd, fullHandle, generateKeypair, getAddress, getCoinMeta, getDecimals, getDecimalsForCoinType, getFinancialSummary, getPendingRewards, getRates, getSwapQuote, getTier, getVoloStats, isAllowedAsset, isInRegistry, isSupported, isTier1, isTier2, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, naviDescriptor, normalizeAsset, normalizeCoinType, parseSuiRpcTx, queryHistory, queryTransaction, rawToStable, rawToUsdc, refineLendingLabel, resolveSymbol, resolveTokenType, saveKey, selectAndSplitCoin, selectSuiCoin, simulateTransaction, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, validateLabel, walletExists };
8267
+ export { ALL_NAVI_ASSETS, AUDRIC_PARENT_NAME, AUDRIC_PARENT_NFT_ID, BORROW_FEE_BPS, BPS_DENOMINATOR, CETUS_USDC_SUI_POOL, CLOCK_ID, COIN_REGISTRY, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, ETH_TYPE, GAS_RESERVE_MIN, HF_CRITICAL_THRESHOLD, HF_WARN_THRESHOLD, IKA_TYPE, KNOWN_TARGETS, KeypairSigner, LABEL_PATTERNS, LOFI_TYPE, MANIFEST_TYPE, MIST_PER_SUI, NAVX_TYPE, NaviAdapter, OPERATION_ASSETS, OUTBOUND_OPS, OVERLAY_FEE_RATE, ProtocolRegistry, SAVE_FEE_BPS, STABLE_ASSETS, SUI_DECIMALS, SUI_TYPE, SUPPORTED_ASSETS, SafeguardEnforcer, SafeguardError, T2000, T2000Error, T2000_OVERLAY_FEE_WALLET, TOKEN_MAP, USDC_DECIMALS, USDC_TYPE, USDE_TYPE, USDSUI_TYPE, USDT_TYPE, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, WAL_TYPE, WBTC_TYPE, WRITE_APPENDER_REGISTRY, ZkLoginSigner, addClaimRewardsToTx, addFeeTransfer, addSendToTx, addStakeVSuiToTx, addSwapToTx, addUnstakeVSuiToTx, aggregateClaimableRewards, allDescriptors, assertAllowedAsset, buildAddLeafTx, buildClaimRewardsTx, buildHarvestRewardsTx, buildRevokeLeafTx, buildSendTx, buildStakeVSuiTx, buildSwapTx, buildUnstakeVSuiTx, calculateFee, classifyAction, classifyLabel, classifyTransaction, composeTx, deriveAllowedAddressesFromPtb, displayHandle, exportPrivateKey, extractTransferDetails, extractTxCommands, extractTxSender, fallbackLabel, fetchAllCoins, findSwapRoute, formatAssetAmount, formatSui, formatUsd, fullHandle, generateKeypair, getAddress, getCoinMeta, getDecimals, getDecimalsForCoinType, getFinancialSummary, getPendingRewards, getPendingRewardsByAddress, getRates, getSwapQuote, getTier, getVoloStats, isAllowedAsset, isInRegistry, isSupported, isTier1, isTier2, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, naviDescriptor, normalizeAsset, normalizeCoinType, parseSuiRpcTx, queryHistory, queryTransaction, rawToStable, rawToUsdc, refineLendingLabel, resolveSymbol, resolveTokenType, saveKey, selectAndSplitCoin, selectSuiCoin, simulateTransaction, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, validateLabel, walletExists };
8060
8268
  //# sourceMappingURL=index.js.map
8061
8269
  //# sourceMappingURL=index.js.map