@t2000/sdk 0.6.2 → 0.7.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, f as SwapResult, P as PositionsResult, g as RatesResult, h as LendingRates, E as EarningsResult, F as FundStatusResult, i as SentinelAgent, j as SentinelAttackResult, k as SentinelVerdict, G as GasMethod } from './index-DMDq8uxe.cjs';
5
- export { A as AdapterCapability, l as AdapterPositions, m as AdapterTxResult, C as CetusAdapter, n as GasReserve, o as HealthInfo, N as NaviAdapter, p as PositionEntry, q as ProtocolRegistry, r as SuilendAdapter, s as SwapQuote } from './index-DMDq8uxe.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, E as EarningsResult, F as FundStatusResult, i as SentinelAgent, j as SentinelAttackResult, G as GasMethod } from './index-rT0oHn8M.cjs';
5
+ export { A as AdapterCapability, k as AdapterPositions, l as AdapterTxResult, C as CetusAdapter, m as GasReserve, n as HealthInfo, N as NaviAdapter, o as PositionEntry, p as ProtocolDescriptor, q as ProtocolRegistry, r as SentinelVerdict, s as SuilendAdapter, t as SwapQuote, u as allDescriptors, v as cetusDescriptor, w as getSentinelInfo, x as listSentinels, y as naviDescriptor, z as requestAttack, I as sentinelAttack, J as sentinelDescriptor, K as settleAttack, O as submitPrompt, Q as suilendDescriptor } from './index-rT0oHn8M.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' | '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';
@@ -110,6 +110,7 @@ declare class T2000 extends EventEmitter<T2000Events> {
110
110
  asset?: string;
111
111
  protocol?: string;
112
112
  }): Promise<WithdrawResult>;
113
+ private withdrawAllProtocols;
113
114
  maxWithdraw(): Promise<MaxWithdrawResult>;
114
115
  borrow(params: {
115
116
  amount: number;
@@ -247,19 +248,6 @@ declare function getSwapQuote(client: SuiJsonRpcClient, fromAsset: 'USDC' | 'SUI
247
248
 
248
249
  declare function getRates(client: SuiJsonRpcClient): Promise<RatesResult>;
249
250
 
250
- declare function listSentinels(): Promise<SentinelAgent[]>;
251
- declare function getSentinelInfo(client: SuiJsonRpcClient, sentinelObjectId: string): Promise<SentinelAgent>;
252
- declare function requestAttack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelObjectId: string, feeMist: bigint): Promise<{
253
- attackObjectId: string;
254
- digest: string;
255
- }>;
256
- declare function submitPrompt(agentId: string, attackObjectId: string, prompt: string): Promise<SentinelVerdict>;
257
- declare function settleAttack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelObjectId: string, attackObjectId: string, prompt: string, verdict: SentinelVerdict): Promise<{
258
- digest: string;
259
- success: boolean;
260
- }>;
261
- declare function attack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelId: string, prompt: string, feeMist?: bigint): Promise<SentinelAttackResult>;
262
-
263
251
  interface GasExecutionResult {
264
252
  digest: string;
265
253
  effects: unknown;
@@ -299,4 +287,4 @@ interface GasStatusResponse {
299
287
  }
300
288
  declare function getGasStatus(address?: string): Promise<GasStatusResponse>;
301
289
 
302
- 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, RepayResult, SENTINEL, SUI_DECIMALS, SUPPORTED_ASSETS, SaveResult, SendResult, SentinelAgent, SentinelAttackResult, SentinelVerdict, 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, getGasStatus, getPoolPrice, getRates, getSentinelInfo, getSwapQuote, keypairFromPrivateKey, listSentinels, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToUsdc, requestAttack, saveKey, attack as sentinelAttack, settleAttack, shouldAutoTopUp, simulateTransaction, solveHashcash, submitPrompt, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
290
+ 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, 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, getGasStatus, getPoolPrice, getRates, getSwapQuote, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, 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, f as SwapResult, P as PositionsResult, g as RatesResult, h as LendingRates, E as EarningsResult, F as FundStatusResult, i as SentinelAgent, j as SentinelAttackResult, k as SentinelVerdict, G as GasMethod } from './index-DMDq8uxe.js';
5
- export { A as AdapterCapability, l as AdapterPositions, m as AdapterTxResult, C as CetusAdapter, n as GasReserve, o as HealthInfo, N as NaviAdapter, p as PositionEntry, q as ProtocolRegistry, r as SuilendAdapter, s as SwapQuote } from './index-DMDq8uxe.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, E as EarningsResult, F as FundStatusResult, i as SentinelAgent, j as SentinelAttackResult, G as GasMethod } from './index-rT0oHn8M.js';
5
+ export { A as AdapterCapability, k as AdapterPositions, l as AdapterTxResult, C as CetusAdapter, m as GasReserve, n as HealthInfo, N as NaviAdapter, o as PositionEntry, p as ProtocolDescriptor, q as ProtocolRegistry, r as SentinelVerdict, s as SuilendAdapter, t as SwapQuote, u as allDescriptors, v as cetusDescriptor, w as getSentinelInfo, x as listSentinels, y as naviDescriptor, z as requestAttack, I as sentinelAttack, J as sentinelDescriptor, K as settleAttack, O as submitPrompt, Q as suilendDescriptor } from './index-rT0oHn8M.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' | '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';
@@ -110,6 +110,7 @@ declare class T2000 extends EventEmitter<T2000Events> {
110
110
  asset?: string;
111
111
  protocol?: string;
112
112
  }): Promise<WithdrawResult>;
113
+ private withdrawAllProtocols;
113
114
  maxWithdraw(): Promise<MaxWithdrawResult>;
114
115
  borrow(params: {
115
116
  amount: number;
@@ -247,19 +248,6 @@ declare function getSwapQuote(client: SuiJsonRpcClient, fromAsset: 'USDC' | 'SUI
247
248
 
248
249
  declare function getRates(client: SuiJsonRpcClient): Promise<RatesResult>;
249
250
 
250
- declare function listSentinels(): Promise<SentinelAgent[]>;
251
- declare function getSentinelInfo(client: SuiJsonRpcClient, sentinelObjectId: string): Promise<SentinelAgent>;
252
- declare function requestAttack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelObjectId: string, feeMist: bigint): Promise<{
253
- attackObjectId: string;
254
- digest: string;
255
- }>;
256
- declare function submitPrompt(agentId: string, attackObjectId: string, prompt: string): Promise<SentinelVerdict>;
257
- declare function settleAttack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelObjectId: string, attackObjectId: string, prompt: string, verdict: SentinelVerdict): Promise<{
258
- digest: string;
259
- success: boolean;
260
- }>;
261
- declare function attack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelId: string, prompt: string, feeMist?: bigint): Promise<SentinelAttackResult>;
262
-
263
251
  interface GasExecutionResult {
264
252
  digest: string;
265
253
  effects: unknown;
@@ -299,4 +287,4 @@ interface GasStatusResponse {
299
287
  }
300
288
  declare function getGasStatus(address?: string): Promise<GasStatusResponse>;
301
289
 
302
- 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, RepayResult, SENTINEL, SUI_DECIMALS, SUPPORTED_ASSETS, SaveResult, SendResult, SentinelAgent, SentinelAttackResult, SentinelVerdict, 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, getGasStatus, getPoolPrice, getRates, getSentinelInfo, getSwapQuote, keypairFromPrivateKey, listSentinels, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToUsdc, requestAttack, saveKey, attack as sentinelAttack, settleAttack, shouldAutoTopUp, simulateTransaction, solveHashcash, submitPrompt, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
290
+ 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, 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, getGasStatus, getPoolPrice, getRates, getSwapQuote, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
package/dist/index.js CHANGED
@@ -45,6 +45,7 @@ var DEFAULT_RPC_URL = "https://fullnode.mainnet.sui.io:443";
45
45
  var DEFAULT_KEY_PATH = "~/.t2000/wallet.key";
46
46
  var API_BASE_URL = process.env.T2000_API_URL ?? "https://api.t2000.ai";
47
47
  var CETUS_USDC_SUI_POOL = "0x51e883ba7c0b566a26cbc8a94cd33eb0abd418a77cc1e60ad22fd9b1f29cd2ab";
48
+ var CETUS_PACKAGE = "0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb";
48
49
  var SENTINEL = {
49
50
  PACKAGE: "0x88b83f36dafcd5f6dcdcf1d2cb5889b03f61264ab3cee9cae35db7aa940a21b7",
50
51
  AGENT_REGISTRY: "0xc47564f5f14c12b31e0dfa1a3dc99a6380a1edf8929c28cb0eaa3359c8db36ac",
@@ -852,6 +853,15 @@ async function getFundStatus(client, keypair) {
852
853
  projectedMonthly: earnings.dailyEarning * 30
853
854
  };
854
855
  }
856
+ var descriptor = {
857
+ id: "sentinel",
858
+ name: "Sui Sentinel",
859
+ packages: [SENTINEL.PACKAGE],
860
+ actionMap: {
861
+ "sentinel::request_attack": "sentinel_attack",
862
+ "sentinel::consume_prompt": "sentinel_settle"
863
+ }
864
+ };
855
865
  function mapAgent(raw) {
856
866
  return {
857
867
  id: raw.agent_id,
@@ -1139,6 +1149,22 @@ var ProtocolRegistry = class {
1139
1149
  };
1140
1150
 
1141
1151
  // src/adapters/navi.ts
1152
+ var descriptor2 = {
1153
+ id: "navi",
1154
+ name: "NAVI Protocol",
1155
+ packages: [],
1156
+ dynamicPackageId: true,
1157
+ actionMap: {
1158
+ "incentive_v3::entry_deposit": "save",
1159
+ "incentive_v3::deposit": "save",
1160
+ "incentive_v3::withdraw_v2": "withdraw",
1161
+ "incentive_v3::entry_withdraw": "withdraw",
1162
+ "incentive_v3::borrow_v2": "borrow",
1163
+ "incentive_v3::entry_borrow": "borrow",
1164
+ "incentive_v3::entry_repay": "repay",
1165
+ "incentive_v3::repay": "repay"
1166
+ }
1167
+ };
1142
1168
  var NaviAdapter = class {
1143
1169
  id = "navi";
1144
1170
  name = "NAVI Protocol";
@@ -1283,6 +1309,18 @@ function fallbackQuote(fromAsset, amount, poolPrice) {
1283
1309
  }
1284
1310
 
1285
1311
  // src/adapters/cetus.ts
1312
+ var descriptor3 = {
1313
+ id: "cetus",
1314
+ name: "Cetus DEX",
1315
+ packages: [CETUS_PACKAGE],
1316
+ actionMap: {
1317
+ "router::swap": "swap",
1318
+ "router::swap_ab_bc": "swap",
1319
+ "router::swap_ab_cb": "swap",
1320
+ "router::swap_ba_bc": "swap",
1321
+ "router::swap_ba_cb": "swap"
1322
+ }
1323
+ };
1286
1324
  var CetusAdapter = class {
1287
1325
  id = "cetus";
1288
1326
  name = "Cetus";
@@ -1336,7 +1374,21 @@ var LENDING_MARKET_ID = "0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc
1336
1374
  var LENDING_MARKET_TYPE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL";
1337
1375
  var SUILEND_PACKAGE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf";
1338
1376
  var UPGRADE_CAP_ID = "0x3d4ef1859c3ee9fc72858f588b56a09da5466e64f8cc4e90a7b3b909fba8a7ae";
1339
- var FALLBACK_PUBLISHED_AT = "0xd2a67633ccb8de063163e25bcfca242929caf5cf1a26c2929dab519ee0b8f331";
1377
+ var FALLBACK_PUBLISHED_AT = "0x3d4353f3bd3565329655e6b77bc2abfd31e558b86662ebd078ae453d416bc10f";
1378
+ var descriptor4 = {
1379
+ id: "suilend",
1380
+ name: "Suilend",
1381
+ packages: [SUILEND_PACKAGE],
1382
+ actionMap: {
1383
+ "lending_market::deposit_liquidity_and_mint_ctokens": "save",
1384
+ "lending_market::deposit_ctokens_into_obligation": "save",
1385
+ "lending_market::create_obligation": "save",
1386
+ "lending_market::withdraw_ctokens": "withdraw",
1387
+ "lending_market::redeem_ctokens_and_withdraw_liquidity": "withdraw",
1388
+ "lending_market::borrow": "borrow",
1389
+ "lending_market::repay": "repay"
1390
+ }
1391
+ };
1340
1392
  function interpolateRate(utilBreakpoints, aprBreakpoints, utilizationPct) {
1341
1393
  if (utilBreakpoints.length === 0) return 0;
1342
1394
  if (utilizationPct <= utilBreakpoints[0]) return aprBreakpoints[0];
@@ -2110,6 +2162,10 @@ var T2000 = class _T2000 extends EventEmitter {
2110
2162
  }
2111
2163
  } else {
2112
2164
  amount = params.amount;
2165
+ const bal = await queryBalance(this.client, this._address);
2166
+ if (amount > bal.available) {
2167
+ throw new T2000Error("INSUFFICIENT_BALANCE", `Insufficient USDC. Available: $${bal.available.toFixed(2)}, requested: $${amount.toFixed(2)}`);
2168
+ }
2113
2169
  }
2114
2170
  const fee = calculateFee("save", amount);
2115
2171
  const saveAmount = amount;
@@ -2143,6 +2199,9 @@ var T2000 = class _T2000 extends EventEmitter {
2143
2199
  if (asset !== "USDC") {
2144
2200
  throw new T2000Error("ASSET_NOT_SUPPORTED", `Only USDC is supported for withdraw. Got: ${asset}`);
2145
2201
  }
2202
+ if (params.amount === "all" && !params.protocol) {
2203
+ return this.withdrawAllProtocols(asset);
2204
+ }
2146
2205
  const adapter = await this.resolveLending(params.protocol, asset, "withdraw");
2147
2206
  let amount;
2148
2207
  if (params.amount === "all") {
@@ -2185,6 +2244,46 @@ var T2000 = class _T2000 extends EventEmitter {
2185
2244
  gasMethod: gasResult.gasMethod
2186
2245
  };
2187
2246
  }
2247
+ async withdrawAllProtocols(asset) {
2248
+ const allPositions = await this.registry.allPositions(this._address);
2249
+ const withSupply = allPositions.filter(
2250
+ (p) => p.positions.supplies.some((s) => s.asset === asset && s.amount > 1e-3)
2251
+ );
2252
+ if (withSupply.length === 0) {
2253
+ throw new T2000Error("NO_COLLATERAL", "No savings to withdraw across any protocol");
2254
+ }
2255
+ let totalWithdrawn = 0;
2256
+ let lastDigest = "";
2257
+ let totalGasCost = 0;
2258
+ let lastGasMethod = "self-funded";
2259
+ for (const pos of withSupply) {
2260
+ const adapter = this.registry.getLending(pos.protocolId);
2261
+ if (!adapter) continue;
2262
+ const maxResult = await adapter.maxWithdraw(this._address, asset);
2263
+ if (maxResult.maxAmount <= 1e-3) continue;
2264
+ let effectiveAmount = maxResult.maxAmount;
2265
+ const gasResult = await executeWithGas(this.client, this.keypair, async () => {
2266
+ const built = await adapter.buildWithdrawTx(this._address, maxResult.maxAmount, asset);
2267
+ effectiveAmount = built.effectiveAmount;
2268
+ return built.tx;
2269
+ });
2270
+ totalWithdrawn += effectiveAmount;
2271
+ lastDigest = gasResult.digest;
2272
+ totalGasCost += gasResult.gasCostSui;
2273
+ lastGasMethod = gasResult.gasMethod;
2274
+ this.emitBalanceChange("USDC", effectiveAmount, "withdraw", gasResult.digest);
2275
+ }
2276
+ if (totalWithdrawn <= 0) {
2277
+ throw new T2000Error("NO_COLLATERAL", "No savings to withdraw across any protocol");
2278
+ }
2279
+ return {
2280
+ success: true,
2281
+ tx: lastDigest,
2282
+ amount: totalWithdrawn,
2283
+ gasCost: totalGasCost,
2284
+ gasMethod: lastGasMethod
2285
+ };
2286
+ }
2188
2287
  async maxWithdraw() {
2189
2288
  const adapter = await this.resolveLending(void 0, "USDC", "withdraw");
2190
2289
  return adapter.maxWithdraw(this._address, "USDC");
@@ -2515,6 +2614,14 @@ function parseMoveAbort(errorStr) {
2515
2614
  return { reason: errorStr };
2516
2615
  }
2517
2616
 
2518
- export { BPS_DENOMINATOR, CLOCK_ID, CetusAdapter, DEFAULT_NETWORK, MIST_PER_SUI, NaviAdapter, ProtocolRegistry, SENTINEL, SUI_DECIMALS, SUPPORTED_ASSETS, SuilendAdapter, T2000, T2000Error, USDC_DECIMALS, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatSui, formatUsd, generateKeypair, getAddress, getGasStatus, getPoolPrice, getRates, getSentinelInfo, getSwapQuote, keypairFromPrivateKey, listSentinels, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToUsdc, requestAttack, saveKey, attack as sentinelAttack, settleAttack, shouldAutoTopUp, simulateTransaction, solveHashcash, submitPrompt, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
2617
+ // src/adapters/index.ts
2618
+ var allDescriptors = [
2619
+ descriptor2,
2620
+ descriptor4,
2621
+ descriptor3,
2622
+ descriptor
2623
+ ];
2624
+
2625
+ export { BPS_DENOMINATOR, CLOCK_ID, CetusAdapter, DEFAULT_NETWORK, MIST_PER_SUI, NaviAdapter, ProtocolRegistry, SENTINEL, SUI_DECIMALS, SUPPORTED_ASSETS, SuilendAdapter, T2000, T2000Error, USDC_DECIMALS, addCollectFeeToTx, allDescriptors, calculateFee, descriptor3 as cetusDescriptor, executeAutoTopUp, executeWithGas, exportPrivateKey, formatSui, formatUsd, generateKeypair, getAddress, getGasStatus, getPoolPrice, getRates, getSentinelInfo, getSwapQuote, keypairFromPrivateKey, listSentinels, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, descriptor2 as naviDescriptor, rawToUsdc, requestAttack, saveKey, attack as sentinelAttack, descriptor as sentinelDescriptor, settleAttack, shouldAutoTopUp, simulateTransaction, solveHashcash, submitPrompt, suiToMist, descriptor4 as suilendDescriptor, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
2519
2626
  //# sourceMappingURL=index.js.map
2520
2627
  //# sourceMappingURL=index.js.map