@t2000/sdk 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.
- package/dist/index.cjs +201 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +170 -4
- package/dist/index.d.ts +170 -4
- package/dist/index.js +201 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7442,6 +7442,183 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
7442
7442
|
// src/index.ts
|
|
7443
7443
|
init_errors();
|
|
7444
7444
|
init_coinSelection();
|
|
7445
|
+
init_errors();
|
|
7446
|
+
init_token_registry();
|
|
7447
|
+
init_cetus_swap();
|
|
7448
|
+
async function addHarvestToTx(tx, client, address, options = {}) {
|
|
7449
|
+
const slippage = options.slippage ?? 0.01;
|
|
7450
|
+
const minRewardUsd = options.minRewardUsd ?? 0.01;
|
|
7451
|
+
const priceCache = options.priceCache;
|
|
7452
|
+
let rawRewards;
|
|
7453
|
+
try {
|
|
7454
|
+
rawRewards = await vt(address, {
|
|
7455
|
+
env: "prod",
|
|
7456
|
+
client,
|
|
7457
|
+
markets: ["main"]
|
|
7458
|
+
});
|
|
7459
|
+
} catch (err) {
|
|
7460
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
7461
|
+
throw new T2000Error(
|
|
7462
|
+
"PROTOCOL_UNAVAILABLE",
|
|
7463
|
+
`NAVI rewards lookup failed: ${msg}`,
|
|
7464
|
+
{ source: "navi-harvest-read" },
|
|
7465
|
+
true
|
|
7466
|
+
);
|
|
7467
|
+
}
|
|
7468
|
+
const claimable = (rawRewards ?? []).filter((r) => Number(r.userClaimableReward) > 0);
|
|
7469
|
+
if (claimable.length === 0) {
|
|
7470
|
+
throw new T2000Error(
|
|
7471
|
+
"INVALID_AMOUNT",
|
|
7472
|
+
"No pending rewards to harvest.",
|
|
7473
|
+
{ source: "navi-harvest" }
|
|
7474
|
+
);
|
|
7475
|
+
}
|
|
7476
|
+
const aggregated = aggregateClaimableRewards(claimable);
|
|
7477
|
+
let claimed;
|
|
7478
|
+
try {
|
|
7479
|
+
const claimResult = await Ct(tx, claimable, {
|
|
7480
|
+
env: "prod",
|
|
7481
|
+
// 'skip' = NAVI doesn't auto-transfer; coin handles stay in the PTB
|
|
7482
|
+
// for downstream consumption. Verified against NAVI lending source
|
|
7483
|
+
// (index.esm.js@1828–1911) — when type !== 'transfer' && type !==
|
|
7484
|
+
// 'depositNAVI', the `else` branch pushes `{ coin, identifier, ... }`
|
|
7485
|
+
// to the return without consuming the handle.
|
|
7486
|
+
customCoinReceive: { type: "skip" }
|
|
7487
|
+
});
|
|
7488
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
7489
|
+
for (const c of claimResult) {
|
|
7490
|
+
const ct2 = c.identifier.suiCoinType ?? "";
|
|
7491
|
+
if (!ct2) continue;
|
|
7492
|
+
const list = grouped.get(ct2) ?? [];
|
|
7493
|
+
list.push(c.coin);
|
|
7494
|
+
grouped.set(ct2, list);
|
|
7495
|
+
}
|
|
7496
|
+
claimed = [];
|
|
7497
|
+
for (const [coinType, handles] of grouped.entries()) {
|
|
7498
|
+
if (handles.length === 1) {
|
|
7499
|
+
claimed.push({ coin: handles[0], coinType });
|
|
7500
|
+
} else {
|
|
7501
|
+
const [dest, ...rest] = handles;
|
|
7502
|
+
tx.mergeCoins(dest, rest);
|
|
7503
|
+
claimed.push({ coin: dest, coinType });
|
|
7504
|
+
}
|
|
7505
|
+
}
|
|
7506
|
+
} catch (err) {
|
|
7507
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
7508
|
+
throw new T2000Error(
|
|
7509
|
+
"PROTOCOL_UNAVAILABLE",
|
|
7510
|
+
`NAVI claim PTB build failed: ${msg}`,
|
|
7511
|
+
{ source: "navi-harvest-claim-ptb" },
|
|
7512
|
+
true
|
|
7513
|
+
);
|
|
7514
|
+
}
|
|
7515
|
+
const usdcHandles = [];
|
|
7516
|
+
const swaps = [];
|
|
7517
|
+
const skipped = [];
|
|
7518
|
+
let expectedUsdcDeposited = 0;
|
|
7519
|
+
for (const { coin, coinType } of claimed) {
|
|
7520
|
+
const aggRow = aggregated.find((r) => r.coinType === coinType);
|
|
7521
|
+
if (!aggRow) {
|
|
7522
|
+
continue;
|
|
7523
|
+
}
|
|
7524
|
+
if (coinType === USDC_TYPE) {
|
|
7525
|
+
usdcHandles.push(coin);
|
|
7526
|
+
expectedUsdcDeposited += aggRow.amount;
|
|
7527
|
+
continue;
|
|
7528
|
+
}
|
|
7529
|
+
const meta = getCoinMeta(coinType);
|
|
7530
|
+
const isTradeable = meta && (meta.tier === 1 || meta.tier === 2);
|
|
7531
|
+
if (!isTradeable) {
|
|
7532
|
+
tx.transferObjects([coin], address);
|
|
7533
|
+
skipped.push({
|
|
7534
|
+
symbol: aggRow.symbol,
|
|
7535
|
+
coinType,
|
|
7536
|
+
amount: aggRow.amount,
|
|
7537
|
+
reason: "untradeable"
|
|
7538
|
+
});
|
|
7539
|
+
continue;
|
|
7540
|
+
}
|
|
7541
|
+
if (priceCache && minRewardUsd > 0) {
|
|
7542
|
+
const px = priceCache.get(aggRow.symbol.toUpperCase());
|
|
7543
|
+
if (px && px > 0 && aggRow.amount * px < minRewardUsd) {
|
|
7544
|
+
tx.transferObjects([coin], address);
|
|
7545
|
+
skipped.push({
|
|
7546
|
+
symbol: aggRow.symbol,
|
|
7547
|
+
coinType,
|
|
7548
|
+
amount: aggRow.amount,
|
|
7549
|
+
reason: "dust"
|
|
7550
|
+
});
|
|
7551
|
+
continue;
|
|
7552
|
+
}
|
|
7553
|
+
}
|
|
7554
|
+
try {
|
|
7555
|
+
const swapResult = await addSwapToTx(tx, client, address, {
|
|
7556
|
+
from: aggRow.symbol,
|
|
7557
|
+
to: "USDC",
|
|
7558
|
+
amount: aggRow.amount,
|
|
7559
|
+
slippage,
|
|
7560
|
+
inputCoin: coin,
|
|
7561
|
+
providers: options.providers
|
|
7562
|
+
});
|
|
7563
|
+
usdcHandles.push(swapResult.coin);
|
|
7564
|
+
expectedUsdcDeposited += swapResult.expectedAmountOut;
|
|
7565
|
+
swaps.push({
|
|
7566
|
+
fromSymbol: aggRow.symbol,
|
|
7567
|
+
fromCoinType: coinType,
|
|
7568
|
+
toSymbol: "USDC",
|
|
7569
|
+
inputAmount: swapResult.effectiveAmountIn,
|
|
7570
|
+
expectedOutputUsdc: swapResult.expectedAmountOut
|
|
7571
|
+
});
|
|
7572
|
+
} catch (err) {
|
|
7573
|
+
const code = err instanceof T2000Error ? err.code : "UNKNOWN";
|
|
7574
|
+
if (code !== "SWAP_NO_ROUTE" && code !== "SWAP_FAILED") {
|
|
7575
|
+
throw err;
|
|
7576
|
+
}
|
|
7577
|
+
tx.transferObjects([coin], address);
|
|
7578
|
+
skipped.push({
|
|
7579
|
+
symbol: aggRow.symbol,
|
|
7580
|
+
coinType,
|
|
7581
|
+
amount: aggRow.amount,
|
|
7582
|
+
reason: "no-route"
|
|
7583
|
+
});
|
|
7584
|
+
}
|
|
7585
|
+
}
|
|
7586
|
+
if (usdcHandles.length > 0) {
|
|
7587
|
+
let depositCoin;
|
|
7588
|
+
if (usdcHandles.length === 1) {
|
|
7589
|
+
depositCoin = usdcHandles[0];
|
|
7590
|
+
} else {
|
|
7591
|
+
const [primary, ...rest] = usdcHandles;
|
|
7592
|
+
tx.mergeCoins(primary, rest);
|
|
7593
|
+
depositCoin = primary;
|
|
7594
|
+
}
|
|
7595
|
+
try {
|
|
7596
|
+
await addSaveToTx(tx, client, address, depositCoin, { asset: "USDC" });
|
|
7597
|
+
} catch (err) {
|
|
7598
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
7599
|
+
throw new T2000Error(
|
|
7600
|
+
"PROTOCOL_UNAVAILABLE",
|
|
7601
|
+
`NAVI deposit failed during harvest: ${msg}`,
|
|
7602
|
+
{ source: "navi-harvest-deposit" },
|
|
7603
|
+
true
|
|
7604
|
+
);
|
|
7605
|
+
}
|
|
7606
|
+
}
|
|
7607
|
+
return {
|
|
7608
|
+
claimed: aggregated,
|
|
7609
|
+
swaps,
|
|
7610
|
+
skipped,
|
|
7611
|
+
expectedUsdcDeposited
|
|
7612
|
+
};
|
|
7613
|
+
}
|
|
7614
|
+
async function buildHarvestRewardsTx(client, address, options = {}) {
|
|
7615
|
+
const tx = new Transaction();
|
|
7616
|
+
tx.setSender(address);
|
|
7617
|
+
const plan = await addHarvestToTx(tx, client, address, options);
|
|
7618
|
+
return { tx, plan };
|
|
7619
|
+
}
|
|
7620
|
+
|
|
7621
|
+
// src/composeTx.ts
|
|
7445
7622
|
init_cetus_swap();
|
|
7446
7623
|
init_volo();
|
|
7447
7624
|
init_coinSelection();
|
|
@@ -7641,6 +7818,29 @@ var WRITE_APPENDER_REGISTRY = {
|
|
|
7641
7818
|
const rewards = await addClaimRewardsToTx(tx, ctx.client, ctx.sender);
|
|
7642
7819
|
return { preview: { toolName: "claim_rewards", rewards } };
|
|
7643
7820
|
},
|
|
7821
|
+
// [Track B / 2026-05-08] Macro appender — assembles claim → swap(s) →
|
|
7822
|
+
// save inline. The audric host wires `getSponsoredSwapProviders()` into
|
|
7823
|
+
// `options.providers` automatically when `ctx.sponsoredContext === true`
|
|
7824
|
+
// (parity with `swap_execute` below). Slippage + dust-floor pulled from
|
|
7825
|
+
// the input; price cache is forwarded from the host so the dust filter
|
|
7826
|
+
// can compare claimed amounts to USD.
|
|
7827
|
+
harvest_rewards: async (tx, input, ctx) => {
|
|
7828
|
+
const providers = ctx.sponsoredContext ? await getSponsoredSwapProviders() : void 0;
|
|
7829
|
+
const plan = await addHarvestToTx(tx, ctx.client, ctx.sender, {
|
|
7830
|
+
slippage: input.slippage,
|
|
7831
|
+
minRewardUsd: input.minRewardUsd,
|
|
7832
|
+
providers
|
|
7833
|
+
});
|
|
7834
|
+
return {
|
|
7835
|
+
preview: {
|
|
7836
|
+
toolName: "harvest_rewards",
|
|
7837
|
+
claimed: plan.claimed,
|
|
7838
|
+
swaps: plan.swaps,
|
|
7839
|
+
skipped: plan.skipped,
|
|
7840
|
+
expectedUsdcDeposited: plan.expectedUsdcDeposited
|
|
7841
|
+
}
|
|
7842
|
+
};
|
|
7843
|
+
},
|
|
7644
7844
|
volo_stake: async (tx, input, ctx) => {
|
|
7645
7845
|
if (input.amountSui <= 0) {
|
|
7646
7846
|
throw new T2000Error("INVALID_AMOUNT", "Stake amount must be greater than zero");
|
|
@@ -8056,6 +8256,6 @@ function displayHandle(label) {
|
|
|
8056
8256
|
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
8057
8257
|
*/
|
|
8058
8258
|
|
|
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 };
|
|
8259
|
+
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, 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
8260
|
//# sourceMappingURL=index.js.map
|
|
8061
8261
|
//# sourceMappingURL=index.js.map
|