@t2000/sdk 0.9.9 → 0.10.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.d.cts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { EventEmitter } from 'eventemitter3';
2
2
  import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
3
3
  import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
4
- import { T as T2000Options, S as SendResult, B as BalanceResponse, a as TransactionRecord, D as DepositInfo, L as LendingAdapter, b as SwapAdapter, c as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, d as BorrowResult, R as RepayResult, e as MaxBorrowResult, H as HealthFactorResult, P as PositionsResult, f as RatesResult, g as LendingRates, h as RebalanceResult, E as EarningsResult, F as FundStatusResult, i as SentinelAgent, j as SentinelAttackResult, G as GasMethod } from './index-CrLRqDFL.cjs';
5
- export { A as AdapterCapability, k as AdapterPositions, l as AdapterTxResult, m as AssetRates, C as CetusAdapter, n as GasReserve, o as HealthInfo, N as NaviAdapter, p as PositionEntry, q as ProtocolDescriptor, r as ProtocolRegistry, s as RebalanceStep, t as SentinelVerdict, u as SuilendAdapter, v as SwapQuote, w as SwapResult, x as allDescriptors, y as cetusDescriptor, z as getSentinelInfo, I as listSentinels, J as naviDescriptor, K as requestAttack, O as sentinelAttack, Q as sentinelDescriptor, U as settleAttack, V as submitPrompt, X as suilendDescriptor } from './index-CrLRqDFL.cjs';
4
+ import { T as T2000Options, S as SendResult, B as BalanceResponse, a as TransactionRecord, D as DepositInfo, L as LendingAdapter, b as SwapAdapter, c as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, d as BorrowResult, R as RepayResult, e as MaxBorrowResult, H as HealthFactorResult, f as SwapResult, P as PositionsResult, g as RatesResult, h as LendingRates, i as RebalanceResult, E as EarningsResult, F as FundStatusResult, j as SentinelAgent, k as SentinelAttackResult, G as GasMethod } from './index-UOQejD-B.cjs';
5
+ export { A as AdapterCapability, l as AdapterPositions, m as AdapterTxResult, n as AssetRates, C as CetusAdapter, o as GasReserve, p as HealthInfo, N as NaviAdapter, q as PositionEntry, r as ProtocolDescriptor, s as ProtocolRegistry, t as RebalanceStep, u as SentinelVerdict, v as SuilendAdapter, w as SwapQuote, x as allDescriptors, y as cetusDescriptor, z as getSentinelInfo, I as listSentinels, J as naviDescriptor, K as requestAttack, O as sentinelAttack, Q as sentinelDescriptor, U as settleAttack, V as submitPrompt, X as suilendDescriptor } from './index-UOQejD-B.cjs';
6
6
  import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
7
7
 
8
8
  type T2000ErrorCode = 'INSUFFICIENT_BALANCE' | 'INSUFFICIENT_GAS' | 'INVALID_ADDRESS' | 'INVALID_AMOUNT' | 'WALLET_NOT_FOUND' | 'WALLET_LOCKED' | 'WALLET_EXISTS' | 'SPONSOR_FAILED' | 'SPONSOR_RATE_LIMITED' | 'GAS_STATION_UNAVAILABLE' | 'GAS_FEE_EXCEEDED' | 'SIMULATION_FAILED' | 'TRANSACTION_FAILED' | 'ASSET_NOT_SUPPORTED' | 'SWAP_FAILED' | 'SLIPPAGE_EXCEEDED' | 'HEALTH_FACTOR_TOO_LOW' | 'WITHDRAW_WOULD_LIQUIDATE' | 'NO_COLLATERAL' | 'PROTOCOL_PAUSED' | 'PROTOCOL_UNAVAILABLE' | 'RPC_ERROR' | 'RPC_UNREACHABLE' | 'SPONSOR_UNAVAILABLE' | 'AUTO_TOPUP_FAILED' | 'PRICE_EXCEEDS_LIMIT' | 'UNSUPPORTED_NETWORK' | 'PAYMENT_EXPIRED' | 'DUPLICATE_PAYMENT' | 'FACILITATOR_REJECTION' | 'FACILITATOR_TIMEOUT' | 'SENTINEL_API_ERROR' | 'SENTINEL_NOT_FOUND' | 'SENTINEL_TX_FAILED' | 'SENTINEL_TEE_ERROR' | 'UNKNOWN';
@@ -126,8 +126,25 @@ declare class T2000 extends EventEmitter<T2000Events> {
126
126
  private _repayAllBorrows;
127
127
  maxBorrow(): Promise<MaxBorrowResult>;
128
128
  healthFactor(): Promise<HealthFactorResult>;
129
- private _swap;
130
- private _swapQuote;
129
+ exchange(params: {
130
+ from: string;
131
+ to: string;
132
+ amount: number;
133
+ maxSlippage?: number;
134
+ }): Promise<SwapResult>;
135
+ exchangeQuote(params: {
136
+ from: string;
137
+ to: string;
138
+ amount: number;
139
+ }): Promise<{
140
+ expectedOutput: number;
141
+ priceImpact: number;
142
+ poolPrice: number;
143
+ fee: {
144
+ amount: number;
145
+ rate: number;
146
+ };
147
+ }>;
131
148
  positions(): Promise<PositionsResult>;
132
149
  rates(): Promise<RatesResult>;
133
150
  allRates(asset?: string): Promise<{
@@ -300,4 +317,4 @@ interface GasStatusResponse {
300
317
  }
301
318
  declare function getGasStatus(address?: string): Promise<GasStatusResponse>;
302
319
 
303
- export { type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CLOCK_ID, DEFAULT_NETWORK, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, PositionsResult, type ProtocolFeeInfo, RatesResult, RebalanceResult, RepayResult, SENTINEL, SUI_DECIMALS, SUPPORTED_ASSETS, SaveResult, SendResult, SentinelAgent, SentinelAttackResult, type SimulationResult, type SupportedAsset, SwapAdapter, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TransactionRecord, USDC_DECIMALS, WithdrawResult, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getPoolPrice, getRates, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
320
+ export { type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CLOCK_ID, DEFAULT_NETWORK, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, PositionsResult, type ProtocolFeeInfo, RatesResult, RebalanceResult, RepayResult, SENTINEL, SUI_DECIMALS, SUPPORTED_ASSETS, SaveResult, SendResult, SentinelAgent, SentinelAttackResult, type SimulationResult, type SupportedAsset, SwapAdapter, SwapResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TransactionRecord, USDC_DECIMALS, WithdrawResult, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getPoolPrice, getRates, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { EventEmitter } from 'eventemitter3';
2
2
  import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
3
3
  import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
4
- import { T as T2000Options, S as SendResult, B as BalanceResponse, a as TransactionRecord, D as DepositInfo, L as LendingAdapter, b as SwapAdapter, c as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, d as BorrowResult, R as RepayResult, e as MaxBorrowResult, H as HealthFactorResult, P as PositionsResult, f as RatesResult, g as LendingRates, h as RebalanceResult, E as EarningsResult, F as FundStatusResult, i as SentinelAgent, j as SentinelAttackResult, G as GasMethod } from './index-CrLRqDFL.js';
5
- export { A as AdapterCapability, k as AdapterPositions, l as AdapterTxResult, m as AssetRates, C as CetusAdapter, n as GasReserve, o as HealthInfo, N as NaviAdapter, p as PositionEntry, q as ProtocolDescriptor, r as ProtocolRegistry, s as RebalanceStep, t as SentinelVerdict, u as SuilendAdapter, v as SwapQuote, w as SwapResult, x as allDescriptors, y as cetusDescriptor, z as getSentinelInfo, I as listSentinels, J as naviDescriptor, K as requestAttack, O as sentinelAttack, Q as sentinelDescriptor, U as settleAttack, V as submitPrompt, X as suilendDescriptor } from './index-CrLRqDFL.js';
4
+ import { T as T2000Options, S as SendResult, B as BalanceResponse, a as TransactionRecord, D as DepositInfo, L as LendingAdapter, b as SwapAdapter, c as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, d as BorrowResult, R as RepayResult, e as MaxBorrowResult, H as HealthFactorResult, f as SwapResult, P as PositionsResult, g as RatesResult, h as LendingRates, i as RebalanceResult, E as EarningsResult, F as FundStatusResult, j as SentinelAgent, k as SentinelAttackResult, G as GasMethod } from './index-UOQejD-B.js';
5
+ export { A as AdapterCapability, l as AdapterPositions, m as AdapterTxResult, n as AssetRates, C as CetusAdapter, o as GasReserve, p as HealthInfo, N as NaviAdapter, q as PositionEntry, r as ProtocolDescriptor, s as ProtocolRegistry, t as RebalanceStep, u as SentinelVerdict, v as SuilendAdapter, w as SwapQuote, x as allDescriptors, y as cetusDescriptor, z as getSentinelInfo, I as listSentinels, J as naviDescriptor, K as requestAttack, O as sentinelAttack, Q as sentinelDescriptor, U as settleAttack, V as submitPrompt, X as suilendDescriptor } from './index-UOQejD-B.js';
6
6
  import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
7
7
 
8
8
  type T2000ErrorCode = 'INSUFFICIENT_BALANCE' | 'INSUFFICIENT_GAS' | 'INVALID_ADDRESS' | 'INVALID_AMOUNT' | 'WALLET_NOT_FOUND' | 'WALLET_LOCKED' | 'WALLET_EXISTS' | 'SPONSOR_FAILED' | 'SPONSOR_RATE_LIMITED' | 'GAS_STATION_UNAVAILABLE' | 'GAS_FEE_EXCEEDED' | 'SIMULATION_FAILED' | 'TRANSACTION_FAILED' | 'ASSET_NOT_SUPPORTED' | 'SWAP_FAILED' | 'SLIPPAGE_EXCEEDED' | 'HEALTH_FACTOR_TOO_LOW' | 'WITHDRAW_WOULD_LIQUIDATE' | 'NO_COLLATERAL' | 'PROTOCOL_PAUSED' | 'PROTOCOL_UNAVAILABLE' | 'RPC_ERROR' | 'RPC_UNREACHABLE' | 'SPONSOR_UNAVAILABLE' | 'AUTO_TOPUP_FAILED' | 'PRICE_EXCEEDS_LIMIT' | 'UNSUPPORTED_NETWORK' | 'PAYMENT_EXPIRED' | 'DUPLICATE_PAYMENT' | 'FACILITATOR_REJECTION' | 'FACILITATOR_TIMEOUT' | 'SENTINEL_API_ERROR' | 'SENTINEL_NOT_FOUND' | 'SENTINEL_TX_FAILED' | 'SENTINEL_TEE_ERROR' | 'UNKNOWN';
@@ -126,8 +126,25 @@ declare class T2000 extends EventEmitter<T2000Events> {
126
126
  private _repayAllBorrows;
127
127
  maxBorrow(): Promise<MaxBorrowResult>;
128
128
  healthFactor(): Promise<HealthFactorResult>;
129
- private _swap;
130
- private _swapQuote;
129
+ exchange(params: {
130
+ from: string;
131
+ to: string;
132
+ amount: number;
133
+ maxSlippage?: number;
134
+ }): Promise<SwapResult>;
135
+ exchangeQuote(params: {
136
+ from: string;
137
+ to: string;
138
+ amount: number;
139
+ }): Promise<{
140
+ expectedOutput: number;
141
+ priceImpact: number;
142
+ poolPrice: number;
143
+ fee: {
144
+ amount: number;
145
+ rate: number;
146
+ };
147
+ }>;
131
148
  positions(): Promise<PositionsResult>;
132
149
  rates(): Promise<RatesResult>;
133
150
  allRates(asset?: string): Promise<{
@@ -300,4 +317,4 @@ interface GasStatusResponse {
300
317
  }
301
318
  declare function getGasStatus(address?: string): Promise<GasStatusResponse>;
302
319
 
303
- export { type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CLOCK_ID, DEFAULT_NETWORK, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, PositionsResult, type ProtocolFeeInfo, RatesResult, RebalanceResult, RepayResult, SENTINEL, SUI_DECIMALS, SUPPORTED_ASSETS, SaveResult, SendResult, SentinelAgent, SentinelAttackResult, type SimulationResult, type SupportedAsset, SwapAdapter, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TransactionRecord, USDC_DECIMALS, WithdrawResult, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getPoolPrice, getRates, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
320
+ export { type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CLOCK_ID, DEFAULT_NETWORK, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, PositionsResult, type ProtocolFeeInfo, RatesResult, RebalanceResult, RepayResult, SENTINEL, SUI_DECIMALS, SUPPORTED_ASSETS, SaveResult, SendResult, SentinelAgent, SentinelAttackResult, type SimulationResult, type SupportedAsset, SwapAdapter, SwapResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TransactionRecord, USDC_DECIMALS, WithdrawResult, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getPoolPrice, getRates, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
package/dist/index.js CHANGED
@@ -9,7 +9,6 @@ import { access, mkdir, writeFile, readFile } from 'fs/promises';
9
9
  import { dirname, resolve } from 'path';
10
10
  import { homedir } from 'os';
11
11
  import { bcs } from '@mysten/sui/bcs';
12
- import { SuiPriceServiceConnection, SuiPythClient } from '@pythnetwork/pyth-sui-js';
13
12
  import { AggregatorClient, Env } from '@cetusprotocol/aggregator-sdk';
14
13
 
15
14
  // src/t2000.ts
@@ -509,7 +508,6 @@ var NAVI_BALANCE_DECIMALS = 9;
509
508
  var CONFIG_API = "https://open-api.naviprotocol.io/api/navi/config?env=prod";
510
509
  var POOLS_API = "https://open-api.naviprotocol.io/api/navi/pools?env=prod";
511
510
  var PACKAGE_API = "https://open-api.naviprotocol.io/api/package";
512
- var PYTH_HERMES_URL = "https://hermes.pyth.network/";
513
511
  var packageCache = null;
514
512
  function toBigInt(v) {
515
513
  if (typeof v === "bigint") return v;
@@ -604,31 +602,12 @@ function addOracleUpdate(tx, config, pool) {
604
602
  ]
605
603
  });
606
604
  }
607
- async function refreshStableOracles(tx, client, config, pools) {
605
+ function refreshStableOracles(tx, config, pools) {
608
606
  const stableTypes = STABLE_ASSETS.map((a) => SUPPORTED_ASSETS[a].type);
609
607
  const stablePools = pools.filter((p) => {
610
608
  const ct = p.suiCoinType || p.coinType || "";
611
609
  return stableTypes.some((t) => matchesCoinType(ct, t));
612
610
  });
613
- const feeds = (config.oracle.feeds ?? []).filter(
614
- (f2) => stablePools.some((p) => p.id === f2.assetId)
615
- );
616
- if (feeds.length === 0) return;
617
- const pythFeedIds = feeds.map((f2) => f2.pythPriceFeedId).filter(Boolean);
618
- if (pythFeedIds.length > 0 && config.oracle.pythStateId && config.oracle.wormholeStateId) {
619
- try {
620
- const connection = new SuiPriceServiceConnection(PYTH_HERMES_URL);
621
- const priceUpdateData = await connection.getPriceFeedsUpdateData(pythFeedIds);
622
- const pythClient = new SuiPythClient(
623
- client,
624
- config.oracle.pythStateId,
625
- config.oracle.wormholeStateId
626
- );
627
- await pythClient.updatePriceFeeds(tx, priceUpdateData, pythFeedIds);
628
- } catch (err) {
629
- console.error("[t2000] Pyth oracle push failed, falling back to cached prices:", err.message ?? err);
630
- }
631
- }
632
611
  for (const pool of stablePools) {
633
612
  addOracleUpdate(tx, config, pool);
634
613
  }
@@ -749,7 +728,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
749
728
  }
750
729
  const tx = new Transaction();
751
730
  tx.setSender(address);
752
- await refreshStableOracles(tx, client, config, pools);
731
+ refreshStableOracles(tx, config, pools);
753
732
  const [balance] = tx.moveCall({
754
733
  target: `${config.package}::incentive_v3::withdraw_v2`,
755
734
  arguments: [
@@ -794,7 +773,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
794
773
  });
795
774
  return { coin: coin2, effectiveAmount: 0 };
796
775
  }
797
- await refreshStableOracles(tx, client, config, pools);
776
+ refreshStableOracles(tx, config, pools);
798
777
  const [balance] = tx.moveCall({
799
778
  target: `${config.package}::incentive_v3::withdraw_v2`,
800
779
  arguments: [
@@ -882,7 +861,7 @@ async function buildBorrowTx(client, address, amount, options = {}) {
882
861
  ]);
883
862
  const tx = new Transaction();
884
863
  tx.setSender(address);
885
- await refreshStableOracles(tx, client, config, pools);
864
+ refreshStableOracles(tx, config, pools);
886
865
  const [balance] = tx.moveCall({
887
866
  target: `${config.package}::incentive_v3::borrow_v2`,
888
867
  arguments: [
@@ -3218,8 +3197,8 @@ var T2000 = class _T2000 extends EventEmitter {
3218
3197
  }
3219
3198
  return hf;
3220
3199
  }
3221
- // -- Swap (internal — used by rebalance and withdraw auto-swap) --
3222
- async _swap(params) {
3200
+ // -- Exchange --
3201
+ async exchange(params) {
3223
3202
  const fromAsset = params.from;
3224
3203
  const toAsset = params.to;
3225
3204
  if (!(fromAsset in SUPPORTED_ASSETS) || !(toAsset in SUPPORTED_ASSETS)) {
@@ -3272,7 +3251,7 @@ var T2000 = class _T2000 extends EventEmitter {
3272
3251
  gasMethod: gasResult.gasMethod
3273
3252
  };
3274
3253
  }
3275
- async _swapQuote(params) {
3254
+ async exchangeQuote(params) {
3276
3255
  const fromAsset = params.from;
3277
3256
  const toAsset = params.to;
3278
3257
  const best = await this.registry.bestSwapQuote(fromAsset, toAsset, params.amount);