@t2000/sdk 1.23.0 → 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/adapters/index.cjs +45 -48
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.js +45 -48
- package/dist/adapters/index.js.map +1 -1
- package/dist/index.cjs +208 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +191 -4
- package/dist/index.d.ts +191 -4
- package/dist/index.js +206 -49
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5099,35 +5099,6 @@ async function vt(e, n) {
|
|
|
5099
5099
|
);
|
|
5100
5100
|
return await De(e, t, n);
|
|
5101
5101
|
}
|
|
5102
|
-
function wt(e) {
|
|
5103
|
-
const n = /* @__PURE__ */ new Map();
|
|
5104
|
-
e.forEach((r) => {
|
|
5105
|
-
const t = r.assetId, a = r.option, s = `${t}-${a}-${r.rewardCoinType}-${r.market}`;
|
|
5106
|
-
n.has(s) ? n.get(s).total += r.userClaimableReward : n.set(s, {
|
|
5107
|
-
assetId: t,
|
|
5108
|
-
rewardType: a,
|
|
5109
|
-
coinType: r.rewardCoinType,
|
|
5110
|
-
total: Number(r.userClaimableReward),
|
|
5111
|
-
market: r.market
|
|
5112
|
-
});
|
|
5113
|
-
});
|
|
5114
|
-
const o = /* @__PURE__ */ new Map();
|
|
5115
|
-
for (const { assetId: r, rewardType: t, coinType: a, total: s, market: i } of n.values()) {
|
|
5116
|
-
const c = `${r}-${t}-${i}`;
|
|
5117
|
-
o.has(c) || o.set(c, { assetId: r, rewardType: t, market: i, rewards: /* @__PURE__ */ new Map() });
|
|
5118
|
-
const u = o.get(c);
|
|
5119
|
-
u.rewards.set(a, (u.rewards.get(a) || 0) + s);
|
|
5120
|
-
}
|
|
5121
|
-
return Array.from(o.values()).map((r) => ({
|
|
5122
|
-
assetId: r.assetId,
|
|
5123
|
-
rewardType: r.rewardType,
|
|
5124
|
-
market: r.market,
|
|
5125
|
-
rewards: Array.from(r.rewards.entries()).map(([t, a]) => ({
|
|
5126
|
-
coinType: t,
|
|
5127
|
-
available: a.toFixed(6)
|
|
5128
|
-
}))
|
|
5129
|
-
}));
|
|
5130
|
-
}
|
|
5131
5102
|
async function Ct(e, n, o) {
|
|
5132
5103
|
const r = await R({
|
|
5133
5104
|
...o,
|
|
@@ -5305,6 +5276,7 @@ async function Ct(e, n, o) {
|
|
|
5305
5276
|
|
|
5306
5277
|
// src/protocols/navi.ts
|
|
5307
5278
|
init_errors();
|
|
5279
|
+
init_token_registry();
|
|
5308
5280
|
var MIN_HEALTH_FACTOR = 1.5;
|
|
5309
5281
|
function sdkOptions(client) {
|
|
5310
5282
|
return { env: "prod", client, cacheTime: 0, disableCache: true };
|
|
@@ -5679,24 +5651,8 @@ async function getPendingRewards(client, address) {
|
|
|
5679
5651
|
);
|
|
5680
5652
|
}
|
|
5681
5653
|
if (!rewards || rewards.length === 0) return [];
|
|
5682
|
-
const
|
|
5683
|
-
|
|
5684
|
-
for (const s of summary) {
|
|
5685
|
-
for (const rw of s.rewards) {
|
|
5686
|
-
const available = Number(rw.available);
|
|
5687
|
-
if (available <= 0) continue;
|
|
5688
|
-
const symbol = rw.coinType.split("::").pop() ?? "UNKNOWN";
|
|
5689
|
-
result.push({
|
|
5690
|
-
protocol: "navi",
|
|
5691
|
-
asset: String(s.assetId),
|
|
5692
|
-
coinType: rw.coinType,
|
|
5693
|
-
symbol,
|
|
5694
|
-
amount: available,
|
|
5695
|
-
estimatedValueUsd: 0
|
|
5696
|
-
});
|
|
5697
|
-
}
|
|
5698
|
-
}
|
|
5699
|
-
return result;
|
|
5654
|
+
const claimable = rewards.filter((r) => Number(r.userClaimableReward) > 0);
|
|
5655
|
+
return aggregateClaimableRewards(claimable);
|
|
5700
5656
|
}
|
|
5701
5657
|
async function addClaimRewardsToTx(tx, client, address) {
|
|
5702
5658
|
let rewards;
|
|
@@ -5746,7 +5702,8 @@ function aggregateClaimableRewards(claimable) {
|
|
|
5746
5702
|
for (const c of claimable) {
|
|
5747
5703
|
const coinType = c.rewardCoinType;
|
|
5748
5704
|
if (!coinType) continue;
|
|
5749
|
-
const
|
|
5705
|
+
const meta = getCoinMeta(coinType);
|
|
5706
|
+
const symbol = meta?.symbol ?? coinType.split("::").pop() ?? "REWARD";
|
|
5750
5707
|
const amount = Number(c.userClaimableReward);
|
|
5751
5708
|
if (!Number.isFinite(amount) || amount <= 0) continue;
|
|
5752
5709
|
const existing = aggregated.get(coinType);
|
|
@@ -7485,6 +7442,183 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
7485
7442
|
// src/index.ts
|
|
7486
7443
|
init_errors();
|
|
7487
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
|
|
7488
7622
|
init_cetus_swap();
|
|
7489
7623
|
init_volo();
|
|
7490
7624
|
init_coinSelection();
|
|
@@ -7684,6 +7818,29 @@ var WRITE_APPENDER_REGISTRY = {
|
|
|
7684
7818
|
const rewards = await addClaimRewardsToTx(tx, ctx.client, ctx.sender);
|
|
7685
7819
|
return { preview: { toolName: "claim_rewards", rewards } };
|
|
7686
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
|
+
},
|
|
7687
7844
|
volo_stake: async (tx, input, ctx) => {
|
|
7688
7845
|
if (input.amountSui <= 0) {
|
|
7689
7846
|
throw new T2000Error("INVALID_AMOUNT", "Stake amount must be greater than zero");
|
|
@@ -8099,6 +8256,6 @@ function displayHandle(label) {
|
|
|
8099
8256
|
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
8100
8257
|
*/
|
|
8101
8258
|
|
|
8102
|
-
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, addFeeTransfer, addSendToTx, addStakeVSuiToTx, addSwapToTx, addUnstakeVSuiToTx, 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 };
|
|
8103
8260
|
//# sourceMappingURL=index.js.map
|
|
8104
8261
|
//# sourceMappingURL=index.js.map
|