@t2000/sdk 0.8.7 → 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.
- package/README.md +22 -24
- package/dist/adapters/index.cjs +0 -18
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.js +0 -18
- package/dist/adapters/index.js.map +1 -1
- package/dist/{index-DNjooNFy.d.cts → index-C7W686z2.d.cts} +1 -4
- package/dist/{index-DNjooNFy.d.ts → index-C7W686z2.d.ts} +1 -4
- package/dist/index.cjs +94 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -41
- package/dist/index.d.ts +7 -41
- package/dist/index.js +95 -78
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -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
|
|
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
|
|
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
|
@@ -1317,24 +1317,6 @@ var ProtocolRegistry = class {
|
|
|
1317
1317
|
listSwap() {
|
|
1318
1318
|
return [...this.swap.values()];
|
|
1319
1319
|
}
|
|
1320
|
-
isSupportedAsset(asset, capability) {
|
|
1321
|
-
for (const adapter of this.lending.values()) {
|
|
1322
|
-
if (!adapter.supportedAssets.includes(asset)) continue;
|
|
1323
|
-
if (capability && !adapter.capabilities.includes(capability)) continue;
|
|
1324
|
-
return true;
|
|
1325
|
-
}
|
|
1326
|
-
return false;
|
|
1327
|
-
}
|
|
1328
|
-
getSupportedAssets(capability) {
|
|
1329
|
-
const assets = /* @__PURE__ */ new Set();
|
|
1330
|
-
for (const adapter of this.lending.values()) {
|
|
1331
|
-
if (capability && !adapter.capabilities.includes(capability)) continue;
|
|
1332
|
-
for (const a of adapter.supportedAssets) {
|
|
1333
|
-
assets.add(a);
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
return [...assets];
|
|
1337
|
-
}
|
|
1338
1320
|
};
|
|
1339
1321
|
|
|
1340
1322
|
// src/adapters/navi.ts
|
|
@@ -2433,43 +2415,34 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2433
2415
|
}
|
|
2434
2416
|
// -- Savings --
|
|
2435
2417
|
async save(params) {
|
|
2436
|
-
const asset =
|
|
2437
|
-
if (!this.registry.isSupportedAsset(asset, "save")) {
|
|
2438
|
-
const supported = this.registry.getSupportedAssets("save").join(", ");
|
|
2439
|
-
throw new T2000Error("ASSET_NOT_SUPPORTED", `${asset} is not supported for save. Supported: ${supported}`);
|
|
2440
|
-
}
|
|
2418
|
+
const asset = "USDC";
|
|
2441
2419
|
let amount;
|
|
2442
2420
|
if (params.amount === "all") {
|
|
2443
2421
|
const bal = await queryBalance(this.client, this._address);
|
|
2444
|
-
const assetBalance = bal.stables
|
|
2445
|
-
|
|
2446
|
-
amount = assetBalance - reserve;
|
|
2422
|
+
const assetBalance = bal.stables.USDC ?? 0;
|
|
2423
|
+
amount = assetBalance - 1;
|
|
2447
2424
|
if (amount <= 0) {
|
|
2448
|
-
throw new T2000Error("INSUFFICIENT_BALANCE",
|
|
2449
|
-
reason:
|
|
2425
|
+
throw new T2000Error("INSUFFICIENT_BALANCE", "Balance too low to save after $1 gas reserve", {
|
|
2426
|
+
reason: "gas_reserve_required",
|
|
2450
2427
|
available: assetBalance
|
|
2451
2428
|
});
|
|
2452
2429
|
}
|
|
2453
2430
|
} else {
|
|
2454
2431
|
amount = params.amount;
|
|
2455
2432
|
const bal = await queryBalance(this.client, this._address);
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
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)}`);
|
|
2459
2435
|
}
|
|
2460
2436
|
}
|
|
2461
|
-
const
|
|
2462
|
-
const fee = shouldCollectFee ? calculateFee("save", amount) : { amount: 0, rate: 0};
|
|
2437
|
+
const fee = calculateFee("save", amount);
|
|
2463
2438
|
const saveAmount = amount;
|
|
2464
2439
|
const adapter = await this.resolveLending(params.protocol, asset, "save");
|
|
2465
2440
|
const gasResult = await executeWithGas(this.client, this.keypair, async () => {
|
|
2466
|
-
const { tx } = await adapter.buildSaveTx(this._address, saveAmount, asset, { collectFee:
|
|
2441
|
+
const { tx } = await adapter.buildSaveTx(this._address, saveAmount, asset, { collectFee: true });
|
|
2467
2442
|
return tx;
|
|
2468
2443
|
});
|
|
2469
2444
|
const rates = await adapter.getRates(asset);
|
|
2470
|
-
|
|
2471
|
-
reportFee(this._address, "save", fee.amount, fee.rate, gasResult.digest);
|
|
2472
|
-
}
|
|
2445
|
+
reportFee(this._address, "save", fee.amount, fee.rate, gasResult.digest);
|
|
2473
2446
|
this.emitBalanceChange(asset, saveAmount, "save", gasResult.digest);
|
|
2474
2447
|
let savingsBalance = saveAmount;
|
|
2475
2448
|
try {
|
|
@@ -2481,7 +2454,6 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2481
2454
|
success: true,
|
|
2482
2455
|
tx: gasResult.digest,
|
|
2483
2456
|
amount: saveAmount,
|
|
2484
|
-
asset,
|
|
2485
2457
|
apy: rates.saveApy,
|
|
2486
2458
|
fee: fee.amount,
|
|
2487
2459
|
gasCost: gasResult.gasCostSui,
|
|
@@ -2490,14 +2462,27 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2490
2462
|
};
|
|
2491
2463
|
}
|
|
2492
2464
|
async withdraw(params) {
|
|
2493
|
-
const asset = normalizeAsset(params.asset ?? "USDC");
|
|
2494
2465
|
if (params.amount === "all" && !params.protocol) {
|
|
2495
|
-
return this.withdrawAllProtocols(
|
|
2466
|
+
return this.withdrawAllProtocols();
|
|
2496
2467
|
}
|
|
2497
|
-
const
|
|
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
|
+
}
|
|
2475
|
+
}
|
|
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`);
|
|
2498
2483
|
let amount;
|
|
2499
2484
|
if (params.amount === "all") {
|
|
2500
|
-
const maxResult = await adapter.maxWithdraw(this._address, asset);
|
|
2485
|
+
const maxResult = await adapter.maxWithdraw(this._address, target.asset);
|
|
2501
2486
|
amount = maxResult.maxAmount;
|
|
2502
2487
|
if (amount <= 0) {
|
|
2503
2488
|
throw new T2000Error("NO_COLLATERAL", "No savings to withdraw");
|
|
@@ -2506,7 +2491,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2506
2491
|
amount = params.amount;
|
|
2507
2492
|
const hf = await adapter.getHealth(this._address);
|
|
2508
2493
|
if (hf.borrowed > 0) {
|
|
2509
|
-
const maxResult = await adapter.maxWithdraw(this._address, asset);
|
|
2494
|
+
const maxResult = await adapter.maxWithdraw(this._address, target.asset);
|
|
2510
2495
|
if (amount > maxResult.maxAmount) {
|
|
2511
2496
|
throw new T2000Error(
|
|
2512
2497
|
"WITHDRAW_WOULD_LIQUIDATE",
|
|
@@ -2523,20 +2508,37 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2523
2508
|
const withdrawAmount = amount;
|
|
2524
2509
|
let effectiveAmount = withdrawAmount;
|
|
2525
2510
|
const gasResult = await executeWithGas(this.client, this.keypair, async () => {
|
|
2526
|
-
const built = await adapter.buildWithdrawTx(this._address, withdrawAmount, asset);
|
|
2511
|
+
const built = await adapter.buildWithdrawTx(this._address, withdrawAmount, target.asset);
|
|
2527
2512
|
effectiveAmount = built.effectiveAmount;
|
|
2528
2513
|
return built.tx;
|
|
2529
2514
|
});
|
|
2530
|
-
|
|
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);
|
|
2531
2533
|
return {
|
|
2532
2534
|
success: true,
|
|
2533
|
-
tx:
|
|
2534
|
-
amount:
|
|
2535
|
-
gasCost:
|
|
2535
|
+
tx: lastDigest,
|
|
2536
|
+
amount: finalAmount,
|
|
2537
|
+
gasCost: totalGasCost,
|
|
2536
2538
|
gasMethod: gasResult.gasMethod
|
|
2537
2539
|
};
|
|
2538
2540
|
}
|
|
2539
|
-
async withdrawAllProtocols(
|
|
2541
|
+
async withdrawAllProtocols() {
|
|
2540
2542
|
const allPositions = await this.registry.allPositions(this._address);
|
|
2541
2543
|
const withdrawable = [];
|
|
2542
2544
|
for (const pos of allPositions) {
|
|
@@ -2549,7 +2551,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2549
2551
|
if (withdrawable.length === 0) {
|
|
2550
2552
|
throw new T2000Error("NO_COLLATERAL", "No savings to withdraw across any protocol");
|
|
2551
2553
|
}
|
|
2552
|
-
let
|
|
2554
|
+
let totalUsdcReceived = 0;
|
|
2553
2555
|
let lastDigest = "";
|
|
2554
2556
|
let totalGasCost = 0;
|
|
2555
2557
|
let lastGasMethod = "self-funded";
|
|
@@ -2564,30 +2566,55 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2564
2566
|
effectiveAmount = built.effectiveAmount;
|
|
2565
2567
|
return built.tx;
|
|
2566
2568
|
});
|
|
2567
|
-
totalWithdrawn += effectiveAmount;
|
|
2568
2569
|
lastDigest = gasResult.digest;
|
|
2569
2570
|
totalGasCost += gasResult.gasCostSui;
|
|
2570
2571
|
lastGasMethod = gasResult.gasMethod;
|
|
2571
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
|
+
}
|
|
2572
2585
|
}
|
|
2573
|
-
if (
|
|
2586
|
+
if (totalUsdcReceived <= 0) {
|
|
2574
2587
|
throw new T2000Error("NO_COLLATERAL", "No savings to withdraw across any protocol");
|
|
2575
2588
|
}
|
|
2576
2589
|
return {
|
|
2577
2590
|
success: true,
|
|
2578
2591
|
tx: lastDigest,
|
|
2579
|
-
amount:
|
|
2592
|
+
amount: totalUsdcReceived,
|
|
2580
2593
|
gasCost: totalGasCost,
|
|
2581
2594
|
gasMethod: lastGasMethod
|
|
2582
2595
|
};
|
|
2583
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
|
+
}
|
|
2584
2611
|
async maxWithdraw() {
|
|
2585
2612
|
const adapter = await this.resolveLending(void 0, "USDC", "withdraw");
|
|
2586
2613
|
return adapter.maxWithdraw(this._address, "USDC");
|
|
2587
2614
|
}
|
|
2588
2615
|
// -- Borrowing --
|
|
2589
2616
|
async borrow(params) {
|
|
2590
|
-
const asset =
|
|
2617
|
+
const asset = "USDC";
|
|
2591
2618
|
const adapter = await this.resolveLending(params.protocol, asset, "borrow");
|
|
2592
2619
|
const maxResult = await adapter.maxBorrow(this._address, asset);
|
|
2593
2620
|
if (maxResult.maxAmount <= 0) {
|
|
@@ -2599,17 +2626,14 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2599
2626
|
currentHF: maxResult.currentHF
|
|
2600
2627
|
});
|
|
2601
2628
|
}
|
|
2602
|
-
const
|
|
2603
|
-
const fee = shouldCollectFee ? calculateFee("borrow", params.amount) : { amount: 0, rate: 0};
|
|
2629
|
+
const fee = calculateFee("borrow", params.amount);
|
|
2604
2630
|
const borrowAmount = params.amount;
|
|
2605
2631
|
const gasResult = await executeWithGas(this.client, this.keypair, async () => {
|
|
2606
|
-
const { tx } = await adapter.buildBorrowTx(this._address, borrowAmount, asset, { collectFee:
|
|
2632
|
+
const { tx } = await adapter.buildBorrowTx(this._address, borrowAmount, asset, { collectFee: true });
|
|
2607
2633
|
return tx;
|
|
2608
2634
|
});
|
|
2609
2635
|
const hf = await adapter.getHealth(this._address);
|
|
2610
|
-
|
|
2611
|
-
reportFee(this._address, "borrow", fee.amount, fee.rate, gasResult.digest);
|
|
2612
|
-
}
|
|
2636
|
+
reportFee(this._address, "borrow", fee.amount, fee.rate, gasResult.digest);
|
|
2613
2637
|
this.emitBalanceChange(asset, borrowAmount, "borrow", gasResult.digest);
|
|
2614
2638
|
return {
|
|
2615
2639
|
success: true,
|
|
@@ -2622,7 +2646,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2622
2646
|
};
|
|
2623
2647
|
}
|
|
2624
2648
|
async repay(params) {
|
|
2625
|
-
const asset =
|
|
2649
|
+
const asset = "USDC";
|
|
2626
2650
|
const adapter = await this.resolveLending(params.protocol, asset, "repay");
|
|
2627
2651
|
let amount;
|
|
2628
2652
|
if (params.amount === "all") {
|
|
@@ -2664,25 +2688,18 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2664
2688
|
}
|
|
2665
2689
|
return hf;
|
|
2666
2690
|
}
|
|
2667
|
-
// -- Swap --
|
|
2668
|
-
async
|
|
2669
|
-
const fromAsset =
|
|
2670
|
-
const toAsset =
|
|
2691
|
+
// -- Swap (internal — used by rebalance and withdraw auto-swap) --
|
|
2692
|
+
async _swap(params) {
|
|
2693
|
+
const fromAsset = params.from;
|
|
2694
|
+
const toAsset = params.to;
|
|
2671
2695
|
if (!(fromAsset in SUPPORTED_ASSETS) || !(toAsset in SUPPORTED_ASSETS)) {
|
|
2672
2696
|
throw new T2000Error("ASSET_NOT_SUPPORTED", `Swap pair ${fromAsset}/${toAsset} is not supported`);
|
|
2673
2697
|
}
|
|
2674
2698
|
if (fromAsset === toAsset) {
|
|
2675
2699
|
throw new T2000Error("INVALID_AMOUNT", "Cannot swap same asset");
|
|
2676
2700
|
}
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
const found = this.registry.getSwap(params.protocol);
|
|
2680
|
-
if (!found) throw new T2000Error("ASSET_NOT_SUPPORTED", `Swap adapter '${params.protocol}' not found`);
|
|
2681
|
-
adapter = found;
|
|
2682
|
-
} else {
|
|
2683
|
-
const best = await this.registry.bestSwapQuote(fromAsset, toAsset, params.amount);
|
|
2684
|
-
adapter = best.adapter;
|
|
2685
|
-
}
|
|
2701
|
+
const best = await this.registry.bestSwapQuote(fromAsset, toAsset, params.amount);
|
|
2702
|
+
const adapter = best.adapter;
|
|
2686
2703
|
const fee = calculateFee("swap", params.amount);
|
|
2687
2704
|
const swapAmount = params.amount;
|
|
2688
2705
|
const slippageBps = params.maxSlippage ? params.maxSlippage * 100 : void 0;
|
|
@@ -2725,9 +2742,9 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2725
2742
|
gasMethod: gasResult.gasMethod
|
|
2726
2743
|
};
|
|
2727
2744
|
}
|
|
2728
|
-
async
|
|
2729
|
-
const fromAsset =
|
|
2730
|
-
const toAsset =
|
|
2745
|
+
async _swapQuote(params) {
|
|
2746
|
+
const fromAsset = params.from;
|
|
2747
|
+
const toAsset = params.to;
|
|
2731
2748
|
const best = await this.registry.bestSwapQuote(fromAsset, toAsset, params.amount);
|
|
2732
2749
|
const fee = calculateFee("swap", params.amount);
|
|
2733
2750
|
return { ...best.quote, fee: { amount: fee.amount, rate: fee.rate } };
|
|
@@ -3172,7 +3189,6 @@ exports.MIST_PER_SUI = MIST_PER_SUI;
|
|
|
3172
3189
|
exports.NaviAdapter = NaviAdapter;
|
|
3173
3190
|
exports.ProtocolRegistry = ProtocolRegistry;
|
|
3174
3191
|
exports.SENTINEL = SENTINEL;
|
|
3175
|
-
exports.STABLE_ASSETS = STABLE_ASSETS;
|
|
3176
3192
|
exports.SUI_DECIMALS = SUI_DECIMALS;
|
|
3177
3193
|
exports.SUPPORTED_ASSETS = SUPPORTED_ASSETS;
|
|
3178
3194
|
exports.SuilendAdapter = SuilendAdapter;
|
|
@@ -3195,7 +3211,6 @@ exports.getGasStatus = getGasStatus;
|
|
|
3195
3211
|
exports.getPoolPrice = getPoolPrice;
|
|
3196
3212
|
exports.getRates = getRates;
|
|
3197
3213
|
exports.getSentinelInfo = getSentinelInfo;
|
|
3198
|
-
exports.getSwapQuote = getSwapQuote;
|
|
3199
3214
|
exports.keypairFromPrivateKey = keypairFromPrivateKey;
|
|
3200
3215
|
exports.listSentinels = listSentinels;
|
|
3201
3216
|
exports.loadKey = loadKey;
|
|
@@ -3203,7 +3218,6 @@ exports.mapMoveAbortCode = mapMoveAbortCode;
|
|
|
3203
3218
|
exports.mapWalletError = mapWalletError;
|
|
3204
3219
|
exports.mistToSui = mistToSui;
|
|
3205
3220
|
exports.naviDescriptor = descriptor2;
|
|
3206
|
-
exports.normalizeAsset = normalizeAsset;
|
|
3207
3221
|
exports.rawToStable = rawToStable;
|
|
3208
3222
|
exports.rawToUsdc = rawToUsdc;
|
|
3209
3223
|
exports.requestAttack = requestAttack;
|