@t2000/sdk 0.8.6 → 0.9.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.
@@ -155,7 +155,6 @@ interface SaveResult {
155
155
  success: boolean;
156
156
  tx: string;
157
157
  amount: number;
158
- asset: string;
159
158
  apy: number;
160
159
  fee: number;
161
160
  gasCost: number;
@@ -359,8 +358,6 @@ declare class ProtocolRegistry {
359
358
  getSwap(id: string): SwapAdapter | undefined;
360
359
  listLending(): LendingAdapter[];
361
360
  listSwap(): SwapAdapter[];
362
- isSupportedAsset(asset: string, capability?: AdapterCapability): boolean;
363
- getSupportedAssets(capability?: AdapterCapability): string[];
364
361
  }
365
362
 
366
363
  declare const descriptor$3: ProtocolDescriptor;
@@ -478,4 +475,4 @@ declare function attack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentin
478
475
  /** All registered protocol descriptors — used by the indexer for event classification */
479
476
  declare const allDescriptors: ProtocolDescriptor[];
480
477
 
481
- export { type AdapterCapability as A, type BalanceResponse as B, CetusAdapter as C, type DepositInfo as D, type EarningsResult as E, type FundStatusResult as F, type GasMethod as G, type HealthFactorResult as H, listSentinels as I, descriptor$3 as J, requestAttack as K, type LendingAdapter as L, type MaxWithdrawResult as M, NaviAdapter as N, attack as O, type PositionsResult as P, descriptor as Q, type RepayResult as R, type SendResult as S, type T2000Options as T, settleAttack as U, submitPrompt as V, type WithdrawResult as W, descriptor$1 as X, type TransactionRecord as a, type SwapAdapter as b, type SaveResult as c, type BorrowResult as d, type MaxBorrowResult as e, type SwapResult as f, type RatesResult as g, type LendingRates as h, type RebalanceResult as i, type SentinelAgent as j, type SentinelAttackResult as k, type AdapterPositions as l, type AdapterTxResult as m, type AssetRates as n, type GasReserve as o, type HealthInfo as p, type PositionEntry as q, type ProtocolDescriptor as r, ProtocolRegistry as s, type RebalanceStep as t, type SentinelVerdict as u, SuilendAdapter as v, type SwapQuote as w, allDescriptors as x, descriptor$2 as y, getSentinelInfo as z };
478
+ export { type AdapterCapability as A, type BalanceResponse as B, CetusAdapter as C, type DepositInfo as D, type EarningsResult as E, type FundStatusResult as F, type GasMethod as G, type HealthFactorResult as H, listSentinels as I, descriptor$3 as J, requestAttack as K, type LendingAdapter as L, type MaxWithdrawResult as M, NaviAdapter as N, attack as O, type PositionsResult as P, descriptor as Q, type RepayResult as R, type SendResult as S, type T2000Options as T, settleAttack as U, submitPrompt as V, type WithdrawResult as W, descriptor$1 as X, type TransactionRecord as a, type SwapAdapter as b, type SaveResult as c, type BorrowResult as d, type MaxBorrowResult as e, type RatesResult as f, type LendingRates as g, type RebalanceResult as h, type SentinelAgent as i, type SentinelAttackResult as j, type AdapterPositions as k, type AdapterTxResult as l, type AssetRates as m, type GasReserve as n, type HealthInfo as o, type PositionEntry as p, type ProtocolDescriptor as q, ProtocolRegistry as r, type RebalanceStep as s, type SentinelVerdict as t, SuilendAdapter as u, type SwapQuote as v, type SwapResult as w, allDescriptors as x, descriptor$2 as y, getSentinelInfo as z };
@@ -155,7 +155,6 @@ interface SaveResult {
155
155
  success: boolean;
156
156
  tx: string;
157
157
  amount: number;
158
- asset: string;
159
158
  apy: number;
160
159
  fee: number;
161
160
  gasCost: number;
@@ -359,8 +358,6 @@ declare class ProtocolRegistry {
359
358
  getSwap(id: string): SwapAdapter | undefined;
360
359
  listLending(): LendingAdapter[];
361
360
  listSwap(): SwapAdapter[];
362
- isSupportedAsset(asset: string, capability?: AdapterCapability): boolean;
363
- getSupportedAssets(capability?: AdapterCapability): string[];
364
361
  }
365
362
 
366
363
  declare const descriptor$3: ProtocolDescriptor;
@@ -478,4 +475,4 @@ declare function attack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentin
478
475
  /** All registered protocol descriptors — used by the indexer for event classification */
479
476
  declare const allDescriptors: ProtocolDescriptor[];
480
477
 
481
- export { type AdapterCapability as A, type BalanceResponse as B, CetusAdapter as C, type DepositInfo as D, type EarningsResult as E, type FundStatusResult as F, type GasMethod as G, type HealthFactorResult as H, listSentinels as I, descriptor$3 as J, requestAttack as K, type LendingAdapter as L, type MaxWithdrawResult as M, NaviAdapter as N, attack as O, type PositionsResult as P, descriptor as Q, type RepayResult as R, type SendResult as S, type T2000Options as T, settleAttack as U, submitPrompt as V, type WithdrawResult as W, descriptor$1 as X, type TransactionRecord as a, type SwapAdapter as b, type SaveResult as c, type BorrowResult as d, type MaxBorrowResult as e, type SwapResult as f, type RatesResult as g, type LendingRates as h, type RebalanceResult as i, type SentinelAgent as j, type SentinelAttackResult as k, type AdapterPositions as l, type AdapterTxResult as m, type AssetRates as n, type GasReserve as o, type HealthInfo as p, type PositionEntry as q, type ProtocolDescriptor as r, ProtocolRegistry as s, type RebalanceStep as t, type SentinelVerdict as u, SuilendAdapter as v, type SwapQuote as w, allDescriptors as x, descriptor$2 as y, getSentinelInfo as z };
478
+ export { type AdapterCapability as A, type BalanceResponse as B, CetusAdapter as C, type DepositInfo as D, type EarningsResult as E, type FundStatusResult as F, type GasMethod as G, type HealthFactorResult as H, listSentinels as I, descriptor$3 as J, requestAttack as K, type LendingAdapter as L, type MaxWithdrawResult as M, NaviAdapter as N, attack as O, type PositionsResult as P, descriptor as Q, type RepayResult as R, type SendResult as S, type T2000Options as T, settleAttack as U, submitPrompt as V, type WithdrawResult as W, descriptor$1 as X, type TransactionRecord as a, type SwapAdapter as b, type SaveResult as c, type BorrowResult as d, type MaxBorrowResult as e, type RatesResult as f, type LendingRates as g, type RebalanceResult as h, type SentinelAgent as i, type SentinelAttackResult as j, type AdapterPositions as k, type AdapterTxResult as l, type AssetRates as m, type GasReserve as n, type HealthInfo as o, type PositionEntry as p, type ProtocolDescriptor as q, ProtocolRegistry as r, type RebalanceStep as s, type SentinelVerdict as t, SuilendAdapter as u, type SwapQuote as v, type SwapResult as w, allDescriptors as x, descriptor$2 as y, getSentinelInfo as z };
package/dist/index.cjs CHANGED
@@ -124,10 +124,25 @@ function mapMoveAbortCode(code) {
124
124
  7: "Package version mismatch \u2014 upgrade required",
125
125
  8: "Timelock is active \u2014 wait for expiry",
126
126
  9: "No pending change to execute",
127
- 10: "Already at current version"
127
+ 10: "Already at current version",
128
+ // NAVI Protocol abort codes
129
+ 1502: "Oracle price is stale \u2014 try again in a moment",
130
+ 1600: "Health factor too low \u2014 withdrawal would risk liquidation",
131
+ 1605: "Asset borrowing is disabled or at capacity on this protocol"
128
132
  };
129
133
  return abortMessages[code] ?? `Move abort code: ${code}`;
130
134
  }
135
+ function isMoveAbort(msg) {
136
+ return msg.includes("MoveAbort") || msg.includes("MovePrimitiveRuntimeError");
137
+ }
138
+ function parseMoveAbortMessage(msg) {
139
+ const abortMatch = msg.match(/abort code:\s*(\d+)/i) ?? msg.match(/MoveAbort[^,]*,\s*(\d+)/);
140
+ if (abortMatch) {
141
+ const code = parseInt(abortMatch[1], 10);
142
+ return mapMoveAbortCode(code);
143
+ }
144
+ return msg;
145
+ }
131
146
 
132
147
  // src/utils/sui.ts
133
148
  var cachedClient = null;
@@ -1302,24 +1317,6 @@ var ProtocolRegistry = class {
1302
1317
  listSwap() {
1303
1318
  return [...this.swap.values()];
1304
1319
  }
1305
- isSupportedAsset(asset, capability) {
1306
- for (const adapter of this.lending.values()) {
1307
- if (!adapter.supportedAssets.includes(asset)) continue;
1308
- if (capability && !adapter.capabilities.includes(capability)) continue;
1309
- return true;
1310
- }
1311
- return false;
1312
- }
1313
- getSupportedAssets(capability) {
1314
- const assets = /* @__PURE__ */ new Set();
1315
- for (const adapter of this.lending.values()) {
1316
- if (capability && !adapter.capabilities.includes(capability)) continue;
1317
- for (const a of adapter.supportedAssets) {
1318
- assets.add(a);
1319
- }
1320
- }
1321
- return [...assets];
1322
- }
1323
1320
  };
1324
1321
 
1325
1322
  // src/adapters/navi.ts
@@ -2237,7 +2234,11 @@ async function executeWithGas(client, keypair, buildTx) {
2237
2234
  if (result) return result;
2238
2235
  errors.push("self-funded: SUI below threshold");
2239
2236
  } catch (err) {
2240
- errors.push(`self-funded: ${err instanceof Error ? err.message : String(err)}`);
2237
+ const msg = err instanceof Error ? err.message : String(err);
2238
+ if (isMoveAbort(msg)) {
2239
+ throw new T2000Error("TRANSACTION_FAILED", parseMoveAbortMessage(msg));
2240
+ }
2241
+ errors.push(`self-funded: ${msg}`);
2241
2242
  }
2242
2243
  try {
2243
2244
  const tx = await buildTx();
@@ -2414,43 +2415,34 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
2414
2415
  }
2415
2416
  // -- Savings --
2416
2417
  async save(params) {
2417
- const asset = normalizeAsset(params.asset ?? "USDC");
2418
- if (!this.registry.isSupportedAsset(asset, "save")) {
2419
- const supported = this.registry.getSupportedAssets("save").join(", ");
2420
- throw new T2000Error("ASSET_NOT_SUPPORTED", `${asset} is not supported for save. Supported: ${supported}`);
2421
- }
2418
+ const asset = "USDC";
2422
2419
  let amount;
2423
2420
  if (params.amount === "all") {
2424
2421
  const bal = await queryBalance(this.client, this._address);
2425
- const assetBalance = bal.stables[asset] ?? 0;
2426
- const reserve = asset === "USDC" ? 1 : 0;
2427
- amount = assetBalance - reserve;
2422
+ const assetBalance = bal.stables.USDC ?? 0;
2423
+ amount = assetBalance - 1;
2428
2424
  if (amount <= 0) {
2429
- throw new T2000Error("INSUFFICIENT_BALANCE", `Balance too low to save${asset === "USDC" ? " after $1 gas reserve" : ""}`, {
2430
- reason: asset === "USDC" ? "gas_reserve_required" : "zero_balance",
2425
+ throw new T2000Error("INSUFFICIENT_BALANCE", "Balance too low to save after $1 gas reserve", {
2426
+ reason: "gas_reserve_required",
2431
2427
  available: assetBalance
2432
2428
  });
2433
2429
  }
2434
2430
  } else {
2435
2431
  amount = params.amount;
2436
2432
  const bal = await queryBalance(this.client, this._address);
2437
- const assetBalance = bal.stables[asset] ?? 0;
2438
- if (amount > assetBalance) {
2439
- throw new T2000Error("INSUFFICIENT_BALANCE", `Insufficient ${asset}. Available: $${assetBalance.toFixed(2)}, requested: $${amount.toFixed(2)}`);
2433
+ if (amount > (bal.stables.USDC ?? 0)) {
2434
+ throw new T2000Error("INSUFFICIENT_BALANCE", `Insufficient USDC. Available: $${(bal.stables.USDC ?? 0).toFixed(2)}, requested: $${amount.toFixed(2)}`);
2440
2435
  }
2441
2436
  }
2442
- const shouldCollectFee = asset === "USDC";
2443
- const fee = shouldCollectFee ? calculateFee("save", amount) : { amount: 0, rate: 0};
2437
+ const fee = calculateFee("save", amount);
2444
2438
  const saveAmount = amount;
2445
2439
  const adapter = await this.resolveLending(params.protocol, asset, "save");
2446
2440
  const gasResult = await executeWithGas(this.client, this.keypair, async () => {
2447
- const { tx } = await adapter.buildSaveTx(this._address, saveAmount, asset, { collectFee: shouldCollectFee });
2441
+ const { tx } = await adapter.buildSaveTx(this._address, saveAmount, asset, { collectFee: true });
2448
2442
  return tx;
2449
2443
  });
2450
2444
  const rates = await adapter.getRates(asset);
2451
- if (shouldCollectFee) {
2452
- reportFee(this._address, "save", fee.amount, fee.rate, gasResult.digest);
2453
- }
2445
+ reportFee(this._address, "save", fee.amount, fee.rate, gasResult.digest);
2454
2446
  this.emitBalanceChange(asset, saveAmount, "save", gasResult.digest);
2455
2447
  let savingsBalance = saveAmount;
2456
2448
  try {
@@ -2462,7 +2454,6 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
2462
2454
  success: true,
2463
2455
  tx: gasResult.digest,
2464
2456
  amount: saveAmount,
2465
- asset,
2466
2457
  apy: rates.saveApy,
2467
2458
  fee: fee.amount,
2468
2459
  gasCost: gasResult.gasCostSui,
@@ -2471,14 +2462,27 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
2471
2462
  };
2472
2463
  }
2473
2464
  async withdraw(params) {
2474
- const asset = normalizeAsset(params.asset ?? "USDC");
2475
2465
  if (params.amount === "all" && !params.protocol) {
2476
- return this.withdrawAllProtocols(asset);
2466
+ return this.withdrawAllProtocols();
2467
+ }
2468
+ const allPositions = await this.registry.allPositions(this._address);
2469
+ const supplies = [];
2470
+ for (const pos of allPositions) {
2471
+ if (params.protocol && pos.protocolId !== params.protocol) continue;
2472
+ for (const s of pos.positions.supplies) {
2473
+ if (s.amount > 1e-3) supplies.push({ protocolId: pos.protocolId, asset: s.asset, amount: s.amount, apy: s.apy });
2474
+ }
2477
2475
  }
2478
- const adapter = await this.resolveLending(params.protocol, asset, "withdraw");
2476
+ if (supplies.length === 0) {
2477
+ throw new T2000Error("NO_COLLATERAL", "No savings to withdraw");
2478
+ }
2479
+ supplies.sort((a, b) => a.apy - b.apy);
2480
+ const target = supplies[0];
2481
+ const adapter = this.registry.getLending(target.protocolId);
2482
+ if (!adapter) throw new T2000Error("PROTOCOL_UNAVAILABLE", `Protocol ${target.protocolId} not found`);
2479
2483
  let amount;
2480
2484
  if (params.amount === "all") {
2481
- const maxResult = await adapter.maxWithdraw(this._address, asset);
2485
+ const maxResult = await adapter.maxWithdraw(this._address, target.asset);
2482
2486
  amount = maxResult.maxAmount;
2483
2487
  if (amount <= 0) {
2484
2488
  throw new T2000Error("NO_COLLATERAL", "No savings to withdraw");
@@ -2487,7 +2491,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
2487
2491
  amount = params.amount;
2488
2492
  const hf = await adapter.getHealth(this._address);
2489
2493
  if (hf.borrowed > 0) {
2490
- const maxResult = await adapter.maxWithdraw(this._address, asset);
2494
+ const maxResult = await adapter.maxWithdraw(this._address, target.asset);
2491
2495
  if (amount > maxResult.maxAmount) {
2492
2496
  throw new T2000Error(
2493
2497
  "WITHDRAW_WOULD_LIQUIDATE",
@@ -2504,20 +2508,37 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
2504
2508
  const withdrawAmount = amount;
2505
2509
  let effectiveAmount = withdrawAmount;
2506
2510
  const gasResult = await executeWithGas(this.client, this.keypair, async () => {
2507
- const built = await adapter.buildWithdrawTx(this._address, withdrawAmount, asset);
2511
+ const built = await adapter.buildWithdrawTx(this._address, withdrawAmount, target.asset);
2508
2512
  effectiveAmount = built.effectiveAmount;
2509
2513
  return built.tx;
2510
2514
  });
2511
- this.emitBalanceChange(asset, effectiveAmount, "withdraw", gasResult.digest);
2515
+ let totalGasCost = gasResult.gasCostSui;
2516
+ let finalAmount = effectiveAmount;
2517
+ let lastDigest = gasResult.digest;
2518
+ if (target.asset !== "USDC") {
2519
+ try {
2520
+ const swapResult = await this._swapToUsdc(target.asset, effectiveAmount);
2521
+ finalAmount = swapResult.usdcReceived;
2522
+ lastDigest = swapResult.digest;
2523
+ totalGasCost += swapResult.gasCost;
2524
+ } catch (err) {
2525
+ throw new T2000Error(
2526
+ "SWAP_FAILED",
2527
+ `Withdrew $${effectiveAmount.toFixed(2)} ${target.asset} but swap to USDC failed. Your ${target.asset} is safe in your wallet.`,
2528
+ { withdrawDigest: gasResult.digest, originalError: err instanceof Error ? err.message : String(err) }
2529
+ );
2530
+ }
2531
+ }
2532
+ this.emitBalanceChange("USDC", finalAmount, "withdraw", lastDigest);
2512
2533
  return {
2513
2534
  success: true,
2514
- tx: gasResult.digest,
2515
- amount: effectiveAmount,
2516
- gasCost: gasResult.gasCostSui,
2535
+ tx: lastDigest,
2536
+ amount: finalAmount,
2537
+ gasCost: totalGasCost,
2517
2538
  gasMethod: gasResult.gasMethod
2518
2539
  };
2519
2540
  }
2520
- async withdrawAllProtocols(_asset) {
2541
+ async withdrawAllProtocols() {
2521
2542
  const allPositions = await this.registry.allPositions(this._address);
2522
2543
  const withdrawable = [];
2523
2544
  for (const pos of allPositions) {
@@ -2530,7 +2551,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
2530
2551
  if (withdrawable.length === 0) {
2531
2552
  throw new T2000Error("NO_COLLATERAL", "No savings to withdraw across any protocol");
2532
2553
  }
2533
- let totalWithdrawn = 0;
2554
+ let totalUsdcReceived = 0;
2534
2555
  let lastDigest = "";
2535
2556
  let totalGasCost = 0;
2536
2557
  let lastGasMethod = "self-funded";
@@ -2545,30 +2566,55 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
2545
2566
  effectiveAmount = built.effectiveAmount;
2546
2567
  return built.tx;
2547
2568
  });
2548
- totalWithdrawn += effectiveAmount;
2549
2569
  lastDigest = gasResult.digest;
2550
2570
  totalGasCost += gasResult.gasCostSui;
2551
2571
  lastGasMethod = gasResult.gasMethod;
2552
2572
  this.emitBalanceChange(entry.asset, effectiveAmount, "withdraw", gasResult.digest);
2573
+ if (entry.asset !== "USDC") {
2574
+ try {
2575
+ const swapResult = await this._swapToUsdc(entry.asset, effectiveAmount);
2576
+ totalUsdcReceived += swapResult.usdcReceived;
2577
+ lastDigest = swapResult.digest;
2578
+ totalGasCost += swapResult.gasCost;
2579
+ } catch {
2580
+ totalUsdcReceived += effectiveAmount;
2581
+ }
2582
+ } else {
2583
+ totalUsdcReceived += effectiveAmount;
2584
+ }
2553
2585
  }
2554
- if (totalWithdrawn <= 0) {
2586
+ if (totalUsdcReceived <= 0) {
2555
2587
  throw new T2000Error("NO_COLLATERAL", "No savings to withdraw across any protocol");
2556
2588
  }
2557
2589
  return {
2558
2590
  success: true,
2559
2591
  tx: lastDigest,
2560
- amount: totalWithdrawn,
2592
+ amount: totalUsdcReceived,
2561
2593
  gasCost: totalGasCost,
2562
2594
  gasMethod: lastGasMethod
2563
2595
  };
2564
2596
  }
2597
+ async _swapToUsdc(asset, amount) {
2598
+ const swapAdapter = this.registry.listSwap()[0];
2599
+ if (!swapAdapter) throw new T2000Error("PROTOCOL_UNAVAILABLE", "No swap adapter available");
2600
+ let estimatedOut = 0;
2601
+ let toDecimals = 6;
2602
+ const gasResult = await executeWithGas(this.client, this.keypair, async () => {
2603
+ const built = await swapAdapter.buildSwapTx(this._address, asset, "USDC", amount);
2604
+ estimatedOut = built.estimatedOut;
2605
+ toDecimals = built.toDecimals;
2606
+ return built.tx;
2607
+ });
2608
+ const usdcReceived = estimatedOut / 10 ** toDecimals;
2609
+ return { usdcReceived, digest: gasResult.digest, gasCost: gasResult.gasCostSui };
2610
+ }
2565
2611
  async maxWithdraw() {
2566
2612
  const adapter = await this.resolveLending(void 0, "USDC", "withdraw");
2567
2613
  return adapter.maxWithdraw(this._address, "USDC");
2568
2614
  }
2569
2615
  // -- Borrowing --
2570
2616
  async borrow(params) {
2571
- const asset = normalizeAsset(params.asset ?? "USDC");
2617
+ const asset = "USDC";
2572
2618
  const adapter = await this.resolveLending(params.protocol, asset, "borrow");
2573
2619
  const maxResult = await adapter.maxBorrow(this._address, asset);
2574
2620
  if (maxResult.maxAmount <= 0) {
@@ -2580,17 +2626,14 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
2580
2626
  currentHF: maxResult.currentHF
2581
2627
  });
2582
2628
  }
2583
- const shouldCollectFee = asset === "USDC";
2584
- const fee = shouldCollectFee ? calculateFee("borrow", params.amount) : { amount: 0, rate: 0};
2629
+ const fee = calculateFee("borrow", params.amount);
2585
2630
  const borrowAmount = params.amount;
2586
2631
  const gasResult = await executeWithGas(this.client, this.keypair, async () => {
2587
- const { tx } = await adapter.buildBorrowTx(this._address, borrowAmount, asset, { collectFee: shouldCollectFee });
2632
+ const { tx } = await adapter.buildBorrowTx(this._address, borrowAmount, asset, { collectFee: true });
2588
2633
  return tx;
2589
2634
  });
2590
2635
  const hf = await adapter.getHealth(this._address);
2591
- if (shouldCollectFee) {
2592
- reportFee(this._address, "borrow", fee.amount, fee.rate, gasResult.digest);
2593
- }
2636
+ reportFee(this._address, "borrow", fee.amount, fee.rate, gasResult.digest);
2594
2637
  this.emitBalanceChange(asset, borrowAmount, "borrow", gasResult.digest);
2595
2638
  return {
2596
2639
  success: true,
@@ -2603,7 +2646,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
2603
2646
  };
2604
2647
  }
2605
2648
  async repay(params) {
2606
- const asset = normalizeAsset(params.asset ?? "USDC");
2649
+ const asset = "USDC";
2607
2650
  const adapter = await this.resolveLending(params.protocol, asset, "repay");
2608
2651
  let amount;
2609
2652
  if (params.amount === "all") {
@@ -2645,25 +2688,18 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
2645
2688
  }
2646
2689
  return hf;
2647
2690
  }
2648
- // -- Swap --
2649
- async swap(params) {
2650
- const fromAsset = normalizeAsset(params.from);
2651
- const toAsset = normalizeAsset(params.to);
2691
+ // -- Swap (internal — used by rebalance and withdraw auto-swap) --
2692
+ async _swap(params) {
2693
+ const fromAsset = params.from;
2694
+ const toAsset = params.to;
2652
2695
  if (!(fromAsset in SUPPORTED_ASSETS) || !(toAsset in SUPPORTED_ASSETS)) {
2653
2696
  throw new T2000Error("ASSET_NOT_SUPPORTED", `Swap pair ${fromAsset}/${toAsset} is not supported`);
2654
2697
  }
2655
2698
  if (fromAsset === toAsset) {
2656
2699
  throw new T2000Error("INVALID_AMOUNT", "Cannot swap same asset");
2657
2700
  }
2658
- let adapter;
2659
- if (params.protocol) {
2660
- const found = this.registry.getSwap(params.protocol);
2661
- if (!found) throw new T2000Error("ASSET_NOT_SUPPORTED", `Swap adapter '${params.protocol}' not found`);
2662
- adapter = found;
2663
- } else {
2664
- const best = await this.registry.bestSwapQuote(fromAsset, toAsset, params.amount);
2665
- adapter = best.adapter;
2666
- }
2701
+ const best = await this.registry.bestSwapQuote(fromAsset, toAsset, params.amount);
2702
+ const adapter = best.adapter;
2667
2703
  const fee = calculateFee("swap", params.amount);
2668
2704
  const swapAmount = params.amount;
2669
2705
  const slippageBps = params.maxSlippage ? params.maxSlippage * 100 : void 0;
@@ -2706,9 +2742,9 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
2706
2742
  gasMethod: gasResult.gasMethod
2707
2743
  };
2708
2744
  }
2709
- async swapQuote(params) {
2710
- const fromAsset = normalizeAsset(params.from);
2711
- const toAsset = normalizeAsset(params.to);
2745
+ async _swapQuote(params) {
2746
+ const fromAsset = params.from;
2747
+ const toAsset = params.to;
2712
2748
  const best = await this.registry.bestSwapQuote(fromAsset, toAsset, params.amount);
2713
2749
  const fee = calculateFee("swap", params.amount);
2714
2750
  return { ...best.quote, fee: { amount: fee.amount, rate: fee.rate } };
@@ -3153,7 +3189,6 @@ exports.MIST_PER_SUI = MIST_PER_SUI;
3153
3189
  exports.NaviAdapter = NaviAdapter;
3154
3190
  exports.ProtocolRegistry = ProtocolRegistry;
3155
3191
  exports.SENTINEL = SENTINEL;
3156
- exports.STABLE_ASSETS = STABLE_ASSETS;
3157
3192
  exports.SUI_DECIMALS = SUI_DECIMALS;
3158
3193
  exports.SUPPORTED_ASSETS = SUPPORTED_ASSETS;
3159
3194
  exports.SuilendAdapter = SuilendAdapter;
@@ -3176,7 +3211,6 @@ exports.getGasStatus = getGasStatus;
3176
3211
  exports.getPoolPrice = getPoolPrice;
3177
3212
  exports.getRates = getRates;
3178
3213
  exports.getSentinelInfo = getSentinelInfo;
3179
- exports.getSwapQuote = getSwapQuote;
3180
3214
  exports.keypairFromPrivateKey = keypairFromPrivateKey;
3181
3215
  exports.listSentinels = listSentinels;
3182
3216
  exports.loadKey = loadKey;
@@ -3184,7 +3218,6 @@ exports.mapMoveAbortCode = mapMoveAbortCode;
3184
3218
  exports.mapWalletError = mapWalletError;
3185
3219
  exports.mistToSui = mistToSui;
3186
3220
  exports.naviDescriptor = descriptor2;
3187
- exports.normalizeAsset = normalizeAsset;
3188
3221
  exports.rawToStable = rawToStable;
3189
3222
  exports.rawToUsdc = rawToUsdc;
3190
3223
  exports.requestAttack = requestAttack;