@t2000/cli 0.28.9 → 0.31.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/{chunk-2JUMTEBB.js → chunk-IEDON62D.js} +129 -1
- package/dist/{chunk-2JUMTEBB.js.map → chunk-IEDON62D.js.map} +1 -1
- package/dist/{dist-UDCEDQVB.js → dist-UOEUHDJW.js} +2 -2
- package/dist/{dist-F462ZUVT.js → dist-YS7HI7LP.js} +4 -2
- package/dist/index.js +3 -3
- package/package.json +3 -3
- /package/dist/{dist-UDCEDQVB.js.map → dist-UOEUHDJW.js.map} +0 -0
- /package/dist/{dist-F462ZUVT.js.map → dist-YS7HI7LP.js.map} +0 -0
|
@@ -66839,6 +66839,133 @@ var T2000 = class _T2000 extends import_index.default {
|
|
|
66839
66839
|
gasMethod: claimResult.gasMethod
|
|
66840
66840
|
};
|
|
66841
66841
|
}
|
|
66842
|
+
/**
|
|
66843
|
+
* Claim pending rewards, swap non-USDC tokens to USDC via Cetus, and deposit into NAVI.
|
|
66844
|
+
* Multi-step: claim (transfers to wallet) -> swap each reward token to USDC -> deposit USDC.
|
|
66845
|
+
* Minimum threshold: skips if total rewards < $0.10 (gas not worth it).
|
|
66846
|
+
*/
|
|
66847
|
+
async compoundRewards(options = {}) {
|
|
66848
|
+
this.enforcer.assertNotLocked();
|
|
66849
|
+
const minValue = options.minValueUsd ?? 0.1;
|
|
66850
|
+
const USDC_TYPE3 = SUPPORTED_ASSETS.USDC.type;
|
|
66851
|
+
const USDC_DEC = SUPPORTED_ASSETS.USDC.decimals;
|
|
66852
|
+
const pending = await this.getPendingRewards();
|
|
66853
|
+
const nonTrivial = pending.filter((r) => r.amount > 0);
|
|
66854
|
+
if (nonTrivial.length === 0) {
|
|
66855
|
+
return {
|
|
66856
|
+
success: true,
|
|
66857
|
+
claimTx: "",
|
|
66858
|
+
swapTxs: [],
|
|
66859
|
+
depositTx: "",
|
|
66860
|
+
rewards: pending,
|
|
66861
|
+
totalCompoundedUsdc: 0,
|
|
66862
|
+
totalGasCost: 0
|
|
66863
|
+
};
|
|
66864
|
+
}
|
|
66865
|
+
const totalPendingUsd = pending.reduce((s, r) => s + r.estimatedValueUsd, 0);
|
|
66866
|
+
if (totalPendingUsd > 0 && totalPendingUsd < minValue) {
|
|
66867
|
+
return {
|
|
66868
|
+
success: true,
|
|
66869
|
+
claimTx: "",
|
|
66870
|
+
swapTxs: [],
|
|
66871
|
+
depositTx: "",
|
|
66872
|
+
rewards: pending,
|
|
66873
|
+
totalCompoundedUsdc: 0,
|
|
66874
|
+
totalGasCost: 0
|
|
66875
|
+
};
|
|
66876
|
+
}
|
|
66877
|
+
const preUsdcCoins = await this._fetchCoins(USDC_TYPE3);
|
|
66878
|
+
const preUsdcRaw = preUsdcCoins.reduce((s, c) => s + BigInt(c.balance), 0n);
|
|
66879
|
+
const claimResult = await this.claimRewards();
|
|
66880
|
+
if (!claimResult.tx) {
|
|
66881
|
+
return {
|
|
66882
|
+
success: false,
|
|
66883
|
+
claimTx: "",
|
|
66884
|
+
swapTxs: [],
|
|
66885
|
+
depositTx: "",
|
|
66886
|
+
rewards: pending,
|
|
66887
|
+
totalCompoundedUsdc: 0,
|
|
66888
|
+
totalGasCost: 0
|
|
66889
|
+
};
|
|
66890
|
+
}
|
|
66891
|
+
const { findSwapRoute: findSwapRoute2, buildSwapTx: buildSwapTx2 } = await Promise.resolve().then(() => (init_cetus_swap(), cetus_swap_exports));
|
|
66892
|
+
const swapTxs = [];
|
|
66893
|
+
let totalGasCost = claimResult.gasCost;
|
|
66894
|
+
for (const reward of nonTrivial) {
|
|
66895
|
+
if (!reward.coinType) continue;
|
|
66896
|
+
if (reward.coinType === USDC_TYPE3) continue;
|
|
66897
|
+
try {
|
|
66898
|
+
const decimals = getDecimalsForCoinType(reward.coinType) ?? 9;
|
|
66899
|
+
const rawAmount = BigInt(Math.floor(reward.amount * 10 ** decimals));
|
|
66900
|
+
if (rawAmount <= 0n) continue;
|
|
66901
|
+
const coins = await this._fetchCoins(reward.coinType);
|
|
66902
|
+
if (coins.length === 0) continue;
|
|
66903
|
+
const route = await findSwapRoute2({
|
|
66904
|
+
walletAddress: this._address,
|
|
66905
|
+
from: reward.coinType,
|
|
66906
|
+
to: USDC_TYPE3,
|
|
66907
|
+
amount: rawAmount,
|
|
66908
|
+
byAmountIn: true
|
|
66909
|
+
});
|
|
66910
|
+
if (!route || route.insufficientLiquidity) continue;
|
|
66911
|
+
const swapResult = await executeWithGas(this.client, this._signer, async () => {
|
|
66912
|
+
const tx = new Transaction();
|
|
66913
|
+
tx.setSender(this._address);
|
|
66914
|
+
const freshCoins = await this._fetchCoins(reward.coinType);
|
|
66915
|
+
if (freshCoins.length === 0) return tx;
|
|
66916
|
+
const merged = this._mergeCoinsInTx(tx, freshCoins);
|
|
66917
|
+
const [inputCoin] = tx.splitCoins(merged, [rawAmount]);
|
|
66918
|
+
const outputCoin = await buildSwapTx2({
|
|
66919
|
+
walletAddress: this._address,
|
|
66920
|
+
route,
|
|
66921
|
+
tx,
|
|
66922
|
+
inputCoin,
|
|
66923
|
+
slippage: 0.01
|
|
66924
|
+
});
|
|
66925
|
+
tx.transferObjects([outputCoin], this._address);
|
|
66926
|
+
return tx;
|
|
66927
|
+
});
|
|
66928
|
+
swapTxs.push(swapResult.digest);
|
|
66929
|
+
totalGasCost += swapResult.gasCostSui;
|
|
66930
|
+
} catch (err) {
|
|
66931
|
+
console.warn(`[compound] Failed to swap ${reward.symbol}:`, err instanceof Error ? err.message : err);
|
|
66932
|
+
}
|
|
66933
|
+
}
|
|
66934
|
+
const postUsdcCoins = await this._fetchCoins(USDC_TYPE3);
|
|
66935
|
+
const postUsdcRaw = postUsdcCoins.reduce((s, c) => s + BigInt(c.balance), 0n);
|
|
66936
|
+
const gainedRaw = postUsdcRaw > preUsdcRaw ? postUsdcRaw - preUsdcRaw : 0n;
|
|
66937
|
+
const depositUsdc = Number(gainedRaw) / 10 ** USDC_DEC;
|
|
66938
|
+
let depositTx = "";
|
|
66939
|
+
if (gainedRaw > 0n) {
|
|
66940
|
+
try {
|
|
66941
|
+
const adapter2 = await this.resolveLending(void 0, "USDC", "save");
|
|
66942
|
+
const depositResult = await executeWithGas(this.client, this._signer, async () => {
|
|
66943
|
+
const tx = new Transaction();
|
|
66944
|
+
tx.setSender(this._address);
|
|
66945
|
+
const coins = await this._fetchCoins(USDC_TYPE3);
|
|
66946
|
+
if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", "No USDC coins after swap");
|
|
66947
|
+
const merged = this._mergeCoinsInTx(tx, coins);
|
|
66948
|
+
const [inputCoin] = tx.splitCoins(merged, [gainedRaw]);
|
|
66949
|
+
await adapter2.addSaveToTx(tx, this._address, inputCoin, "USDC", { collectFee: false });
|
|
66950
|
+
return tx;
|
|
66951
|
+
});
|
|
66952
|
+
depositTx = depositResult.digest;
|
|
66953
|
+
totalGasCost += depositResult.gasCostSui;
|
|
66954
|
+
} catch (err) {
|
|
66955
|
+
console.warn("[compound] NAVI deposit failed:", err instanceof Error ? err.message : err);
|
|
66956
|
+
}
|
|
66957
|
+
}
|
|
66958
|
+
const hasSubstantiveResult = swapTxs.length > 0 || depositTx !== "";
|
|
66959
|
+
return {
|
|
66960
|
+
success: hasSubstantiveResult,
|
|
66961
|
+
claimTx: claimResult.tx,
|
|
66962
|
+
swapTxs,
|
|
66963
|
+
depositTx,
|
|
66964
|
+
rewards: nonTrivial,
|
|
66965
|
+
totalCompoundedUsdc: depositUsdc,
|
|
66966
|
+
totalGasCost
|
|
66967
|
+
};
|
|
66968
|
+
}
|
|
66842
66969
|
// -- Info --
|
|
66843
66970
|
async positions() {
|
|
66844
66971
|
const allPositions = await this.registry.allPositions(this._address);
|
|
@@ -67408,6 +67535,7 @@ export {
|
|
|
67408
67535
|
calculateFee,
|
|
67409
67536
|
addCollectFeeToTx,
|
|
67410
67537
|
getRates,
|
|
67538
|
+
getPendingRewards,
|
|
67411
67539
|
ProtocolRegistry,
|
|
67412
67540
|
naviDescriptor,
|
|
67413
67541
|
allDescriptors,
|
|
@@ -67488,4 +67616,4 @@ axios/dist/node/axios.cjs:
|
|
|
67488
67616
|
@scure/bip39/index.js:
|
|
67489
67617
|
(*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
|
|
67490
67618
|
*/
|
|
67491
|
-
//# sourceMappingURL=chunk-
|
|
67619
|
+
//# sourceMappingURL=chunk-IEDON62D.js.map
|