@t2000/sdk 0.17.17 → 0.17.19

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.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { I as InvestmentTrade, S as StrategyDefinition, A as AutoInvestSchedule, a as AutoInvestStatus, T as T2000Options, b as SendResult, B as BalanceResponse, c as TransactionRecord, D as DepositInfo, L as LendingAdapter, d as SwapAdapter, e as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, f as BorrowResult, R as RepayResult, g as MaxBorrowResult, H as HealthFactorResult, h as SwapResult, i as InvestResult, j as InvestEarnResult, P as PendingReward, C as ClaimRewardsResult, k as StrategyBuyResult, l as StrategySellResult, m as StrategyRebalanceResult, n as StrategyStatusResult, o as AutoInvestRunResult, p as PortfolioResult, q as InvestmentPosition, r as PositionsResult, s as RatesResult, t as LendingRates, u as RebalanceResult, E as EarningsResult, F as FundStatusResult, v as SentinelAgent, w as SentinelAttackResult, G as GasMethod } from './index-Dl9CthNB.cjs';
2
- export { x as AdapterCapability, y as AdapterPositions, z as AdapterTxResult, J as AssetRates, K as CetusAdapter, N as GasReserve, O as HealthInfo, Q as NaviAdapter, U as PerpsAdapter, V as PerpsPosition, X as PositionEntry, Y as PositionSide, Z as ProtocolDescriptor, _ as ProtocolRegistry, $ as RebalanceStep, a0 as SentinelVerdict, a1 as SuilendAdapter, a2 as SwapQuote, a3 as TradePositionsResult, a4 as TradeResult, a5 as allDescriptors, a6 as cetusDescriptor, a7 as getSentinelInfo, a8 as listSentinels, a9 as naviDescriptor, aa as requestAttack, ab as sentinelAttack, ac as sentinelDescriptor, ad as settleAttack, ae as submitPrompt, af as suilendDescriptor } from './index-Dl9CthNB.cjs';
1
+ import { I as InvestmentTrade, S as StrategyDefinition, A as AutoInvestSchedule, a as AutoInvestStatus, T as T2000Options, b as SendResult, B as BalanceResponse, c as TransactionRecord, D as DepositInfo, L as LendingAdapter, d as SwapAdapter, e as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, f as BorrowResult, R as RepayResult, g as MaxBorrowResult, H as HealthFactorResult, h as SwapResult, i as InvestResult, j as InvestEarnResult, P as PendingReward, C as ClaimRewardsResult, k as StrategyBuyResult, l as StrategySellResult, m as StrategyRebalanceResult, n as StrategyStatusResult, o as AutoInvestRunResult, p as PortfolioResult, q as InvestmentPosition, r as PositionsResult, s as RatesResult, t as LendingRates, u as RebalanceResult, E as EarningsResult, F as FundStatusResult, v as SentinelAgent, w as SentinelAttackResult, G as GasMethod } from './index-DdtOBw42.cjs';
2
+ export { x as AdapterCapability, y as AdapterPositions, z as AdapterTxResult, J as AssetRates, K as CetusAdapter, N as GasReserve, O as HealthInfo, Q as NaviAdapter, U as PerpsAdapter, V as PerpsPosition, X as PositionEntry, Y as PositionSide, Z as ProtocolDescriptor, _ as ProtocolRegistry, $ as RebalanceStep, a0 as SentinelVerdict, a1 as SuilendAdapter, a2 as SwapQuote, a3 as TradePositionsResult, a4 as TradeResult, a5 as allDescriptors, a6 as cetusDescriptor, a7 as getSentinelInfo, a8 as listSentinels, a9 as naviDescriptor, aa as requestAttack, ab as sentinelAttack, ac as sentinelDescriptor, ad as settleAttack, ae as submitPrompt, af as suilendDescriptor } from './index-DdtOBw42.cjs';
3
3
  import { EventEmitter } from 'eventemitter3';
4
4
  import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
5
5
  import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
@@ -463,6 +463,7 @@ declare class T2000 extends EventEmitter<T2000Events> {
463
463
  }): Promise<InvestEarnResult>;
464
464
  getPendingRewards(): Promise<PendingReward[]>;
465
465
  claimRewards(): Promise<ClaimRewardsResult>;
466
+ private swapRewardTokensToUsdc;
466
467
  investStrategy(params: {
467
468
  strategy: string;
468
469
  usdAmount: number;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { I as InvestmentTrade, S as StrategyDefinition, A as AutoInvestSchedule, a as AutoInvestStatus, T as T2000Options, b as SendResult, B as BalanceResponse, c as TransactionRecord, D as DepositInfo, L as LendingAdapter, d as SwapAdapter, e as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, f as BorrowResult, R as RepayResult, g as MaxBorrowResult, H as HealthFactorResult, h as SwapResult, i as InvestResult, j as InvestEarnResult, P as PendingReward, C as ClaimRewardsResult, k as StrategyBuyResult, l as StrategySellResult, m as StrategyRebalanceResult, n as StrategyStatusResult, o as AutoInvestRunResult, p as PortfolioResult, q as InvestmentPosition, r as PositionsResult, s as RatesResult, t as LendingRates, u as RebalanceResult, E as EarningsResult, F as FundStatusResult, v as SentinelAgent, w as SentinelAttackResult, G as GasMethod } from './index-Dl9CthNB.js';
2
- export { x as AdapterCapability, y as AdapterPositions, z as AdapterTxResult, J as AssetRates, K as CetusAdapter, N as GasReserve, O as HealthInfo, Q as NaviAdapter, U as PerpsAdapter, V as PerpsPosition, X as PositionEntry, Y as PositionSide, Z as ProtocolDescriptor, _ as ProtocolRegistry, $ as RebalanceStep, a0 as SentinelVerdict, a1 as SuilendAdapter, a2 as SwapQuote, a3 as TradePositionsResult, a4 as TradeResult, a5 as allDescriptors, a6 as cetusDescriptor, a7 as getSentinelInfo, a8 as listSentinels, a9 as naviDescriptor, aa as requestAttack, ab as sentinelAttack, ac as sentinelDescriptor, ad as settleAttack, ae as submitPrompt, af as suilendDescriptor } from './index-Dl9CthNB.js';
1
+ import { I as InvestmentTrade, S as StrategyDefinition, A as AutoInvestSchedule, a as AutoInvestStatus, T as T2000Options, b as SendResult, B as BalanceResponse, c as TransactionRecord, D as DepositInfo, L as LendingAdapter, d as SwapAdapter, e as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, f as BorrowResult, R as RepayResult, g as MaxBorrowResult, H as HealthFactorResult, h as SwapResult, i as InvestResult, j as InvestEarnResult, P as PendingReward, C as ClaimRewardsResult, k as StrategyBuyResult, l as StrategySellResult, m as StrategyRebalanceResult, n as StrategyStatusResult, o as AutoInvestRunResult, p as PortfolioResult, q as InvestmentPosition, r as PositionsResult, s as RatesResult, t as LendingRates, u as RebalanceResult, E as EarningsResult, F as FundStatusResult, v as SentinelAgent, w as SentinelAttackResult, G as GasMethod } from './index-DdtOBw42.js';
2
+ export { x as AdapterCapability, y as AdapterPositions, z as AdapterTxResult, J as AssetRates, K as CetusAdapter, N as GasReserve, O as HealthInfo, Q as NaviAdapter, U as PerpsAdapter, V as PerpsPosition, X as PositionEntry, Y as PositionSide, Z as ProtocolDescriptor, _ as ProtocolRegistry, $ as RebalanceStep, a0 as SentinelVerdict, a1 as SuilendAdapter, a2 as SwapQuote, a3 as TradePositionsResult, a4 as TradeResult, a5 as allDescriptors, a6 as cetusDescriptor, a7 as getSentinelInfo, a8 as listSentinels, a9 as naviDescriptor, aa as requestAttack, ab as sentinelAttack, ac as sentinelDescriptor, ad as settleAttack, ae as submitPrompt, af as suilendDescriptor } from './index-DdtOBw42.js';
3
3
  import { EventEmitter } from 'eventemitter3';
4
4
  import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
5
5
  import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
@@ -463,6 +463,7 @@ declare class T2000 extends EventEmitter<T2000Events> {
463
463
  }): Promise<InvestEarnResult>;
464
464
  getPendingRewards(): Promise<PendingReward[]>;
465
465
  claimRewards(): Promise<ClaimRewardsResult>;
466
+ private swapRewardTokensToUsdc;
466
467
  investStrategy(params: {
467
468
  strategy: string;
468
469
  usdAmount: number;
package/dist/index.js CHANGED
@@ -1897,6 +1897,45 @@ async function addSwapToTx(params) {
1897
1897
  toDecimals: toInfo.decimals
1898
1898
  };
1899
1899
  }
1900
+ async function buildRawSwapTx(params) {
1901
+ const { client, address, fromCoinType, toCoinType, amount, toDecimals, maxSlippageBps = 500 } = params;
1902
+ const aggClient = createAggregatorClient(client, address);
1903
+ const _origLog = console.log;
1904
+ console.log = () => {
1905
+ };
1906
+ let result;
1907
+ try {
1908
+ result = await aggClient.findRouters({
1909
+ from: fromCoinType,
1910
+ target: toCoinType,
1911
+ amount,
1912
+ byAmountIn: true
1913
+ });
1914
+ } finally {
1915
+ console.log = _origLog;
1916
+ }
1917
+ if (!result || result.insufficientLiquidity) {
1918
+ throw new T2000Error("ASSET_NOT_SUPPORTED", `No swap route for reward token \u2192 USDC`);
1919
+ }
1920
+ const tx = new Transaction();
1921
+ const slippage = maxSlippageBps / 1e4;
1922
+ console.log = () => {
1923
+ };
1924
+ try {
1925
+ await aggClient.fastRouterSwap({
1926
+ router: result,
1927
+ txb: tx,
1928
+ slippage
1929
+ });
1930
+ } finally {
1931
+ console.log = _origLog;
1932
+ }
1933
+ return {
1934
+ tx,
1935
+ estimatedOut: Number(result.amountOut.toString()),
1936
+ toDecimals
1937
+ };
1938
+ }
1900
1939
  async function getPoolPrice(client) {
1901
1940
  try {
1902
1941
  const pool = await client.getObject({
@@ -3652,6 +3691,11 @@ var AutoInvestManager = class {
3652
3691
  }
3653
3692
  };
3654
3693
  var LOW_LIQUIDITY_ASSETS = /* @__PURE__ */ new Set(["GOLD"]);
3694
+ var REWARD_TOKEN_DECIMALS = {
3695
+ "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT": 9,
3696
+ "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP": 6,
3697
+ "0x83556891f4a0f233ce7b05cfe7f957d4020492a34f5405b2cb9377d060bef4bf::spring_sui::SPRING_SUI": 9
3698
+ };
3655
3699
  function defaultSlippage(asset) {
3656
3700
  return LOW_LIQUIDITY_ASSETS.has(asset) ? 0.05 : 0.03;
3657
3701
  }
@@ -4853,7 +4897,7 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
4853
4897
  this.enforcer.assertNotLocked();
4854
4898
  const adapters = this.registry.listLending().filter((a) => a.addClaimRewardsToTx);
4855
4899
  if (adapters.length === 0) {
4856
- return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0, gasMethod: "none" };
4900
+ return { success: true, tx: "", rewards: [], totalValueUsd: 0, usdcReceived: 0, gasCost: 0, gasMethod: "none" };
4857
4901
  }
4858
4902
  const tx = new Transaction();
4859
4903
  tx.setSender(this._address);
@@ -4866,18 +4910,52 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
4866
4910
  }
4867
4911
  }
4868
4912
  if (allRewards.length === 0) {
4869
- return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0, gasMethod: "none" };
4913
+ return { success: true, tx: "", rewards: [], totalValueUsd: 0, usdcReceived: 0, gasCost: 0, gasMethod: "none" };
4870
4914
  }
4871
- const gasResult = await executeWithGas(this.client, this.keypair, async () => tx);
4915
+ const claimResult = await executeWithGas(this.client, this.keypair, async () => tx);
4916
+ await this.client.waitForTransaction({ digest: claimResult.digest });
4917
+ const usdcReceived = await this.swapRewardTokensToUsdc(allRewards);
4872
4918
  return {
4873
4919
  success: true,
4874
- tx: gasResult.digest,
4920
+ tx: claimResult.digest,
4875
4921
  rewards: allRewards,
4876
- totalValueUsd: allRewards.reduce((s, r) => s + r.estimatedValueUsd, 0),
4877
- gasCost: gasResult.gasCostSui,
4878
- gasMethod: gasResult.gasMethod
4922
+ totalValueUsd: usdcReceived,
4923
+ usdcReceived,
4924
+ gasCost: claimResult.gasCostSui,
4925
+ gasMethod: claimResult.gasMethod
4879
4926
  };
4880
4927
  }
4928
+ async swapRewardTokensToUsdc(rewards) {
4929
+ const uniqueTokens = [...new Set(rewards.map((r) => r.coinType))];
4930
+ const usdcType = SUPPORTED_ASSETS.USDC.type;
4931
+ const usdcDecimals = SUPPORTED_ASSETS.USDC.decimals;
4932
+ let totalUsdc = 0;
4933
+ for (const coinType of uniqueTokens) {
4934
+ try {
4935
+ const balResult = await this.client.getBalance({
4936
+ owner: this._address,
4937
+ coinType
4938
+ });
4939
+ const rawBalance = BigInt(balResult.totalBalance);
4940
+ if (rawBalance <= 0n) continue;
4941
+ const decimals = REWARD_TOKEN_DECIMALS[coinType] ?? 9;
4942
+ const swapResult = await buildRawSwapTx({
4943
+ client: this.client,
4944
+ address: this._address,
4945
+ fromCoinType: coinType,
4946
+ fromDecimals: decimals,
4947
+ toCoinType: usdcType,
4948
+ toDecimals: usdcDecimals,
4949
+ amount: rawBalance
4950
+ });
4951
+ const gasResult = await executeWithGas(this.client, this.keypair, async () => swapResult.tx);
4952
+ await this.client.waitForTransaction({ digest: gasResult.digest });
4953
+ totalUsdc += swapResult.estimatedOut / 10 ** usdcDecimals;
4954
+ } catch {
4955
+ }
4956
+ }
4957
+ return totalUsdc;
4958
+ }
4881
4959
  // -- Strategies --
4882
4960
  async investStrategy(params) {
4883
4961
  this.enforcer.assertNotLocked();