@t2000/sdk 0.51.0 → 0.52.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 +6 -6
- package/dist/adapters/index.d.cts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/browser.d.cts +2 -2
- package/dist/browser.d.ts +2 -2
- package/dist/index.cjs +28 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +28 -15
- package/dist/index.js.map +1 -1
- package/dist/{token-registry-okyiJNWM.d.ts → token-registry-BortlMRr.d.ts} +1 -1
- package/dist/{token-registry-D-j_Rg4S.d.cts → token-registry-DWRdYf6m.d.cts} +1 -1
- package/dist/{types-DlNEW8w1.d.cts → types-DVVns7_w.d.cts} +2 -0
- package/dist/{types-DlNEW8w1.d.ts → types-DVVns7_w.d.ts} +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -92,10 +92,10 @@ const agent = T2000.fromPrivateKey('suiprivkey1q...');
|
|
|
92
92
|
| `agent.balance()` | Available USDC + savings + gas reserve | `BalanceResponse` |
|
|
93
93
|
| `agent.send({ to, amount, asset? })` | Transfer USDC to any Sui address | `SendResult` |
|
|
94
94
|
| `agent.receive({ amount?, currency?, memo?, label? })` | Generate payment request with Payment Kit URI (`sui:pay?...`), nonce for duplicate prevention | `PaymentRequest` |
|
|
95
|
-
| `agent.save({ amount, protocol? })` | Deposit **USDC** to savings (
|
|
96
|
-
| `agent.withdraw({ amount, asset? })` | Withdraw from savings. `amount` can be `'all'`. Optional `asset`
|
|
97
|
-
| `agent.borrow({ amount })` | Borrow USDC against collateral | `BorrowResult` |
|
|
98
|
-
| `agent.repay({ amount })` | Repay outstanding debt
|
|
95
|
+
| `agent.save({ amount, asset?, protocol? })` | Deposit **USDC or USDsui** to NAVI savings (v0.51.0+). `asset` defaults to `'USDC'`. Auto-selects best rate or specify `protocol`. `amount` can be `'all'`. | `SaveResult` |
|
|
96
|
+
| `agent.withdraw({ amount, asset? })` | Withdraw from savings. `amount` can be `'all'`. Optional `asset` (default: USDC; also supports USDsui plus legacy USDe / SUI). | `WithdrawResult` |
|
|
97
|
+
| `agent.borrow({ amount, asset? })` | Borrow **USDC or USDsui** against collateral (v0.51.0+). `asset` defaults to `'USDC'`. | `BorrowResult` |
|
|
98
|
+
| `agent.repay({ amount, asset? })` | Repay outstanding **USDC or USDsui** debt (v0.51.1+). Pass `asset` to target a specific debt; omit for highest-APY repay. **Symmetry enforced:** USDsui debt is repaid with USDsui coins (and USDC with USDC). `amount` can be `'all'`. | `RepayResult` |
|
|
99
99
|
| `agent.swap({ from, to, amount, slippage? })` | Swap tokens via Cetus Aggregator (20+ DEXs). User-friendly names or full coin types. | `SwapResult` |
|
|
100
100
|
| `agent.stakeVSui({ amount })` | Stake SUI for vSUI via VOLO liquid staking (min 1 SUI) | `StakeVSuiResult` |
|
|
101
101
|
| `agent.unstakeVSui({ amount })` | Unstake vSUI back to SUI. `amount` can be `'all'`. | `UnstakeVSuiResult` |
|
|
@@ -263,11 +263,11 @@ Options like `pin`, `keyPath`, and `rpcUrl` are passed directly to `T2000.create
|
|
|
263
263
|
|
|
264
264
|
Token metadata and **tiers** live in `token-registry.ts` (`COIN_REGISTRY`). **17 tokens** total:
|
|
265
265
|
|
|
266
|
-
- **Tier 1:** USDC — save, borrow, send, swap.
|
|
266
|
+
- **Tier 1 (saveable / borrowable):** USDC, USDsui — save, borrow, send, swap. USDsui is a strategic exception (v0.51.0+) because NAVI runs a separate USDsui pool that often quotes a different APY than USDC. Repay symmetry is enforced (USDsui debt → USDsui repay).
|
|
267
267
|
- **Tier 2 (15):** SUI, wBTC, ETH, GOLD, DEEP, WAL, NS, IKA, CETUS, NAVX, vSUI, haSUI, afSUI, LOFI, MANIFEST — send and swap only (not for new save/borrow deposits).
|
|
268
268
|
- **Legacy (no tier):** USDT, USDe, USDSUI — display and withdraw of existing positions; still send/swap where applicable.
|
|
269
269
|
|
|
270
|
-
Six tokens were removed from the registry (FDUSD, AUSD, BUCK, BLUB, SCA, TURBOS).
|
|
270
|
+
Six tokens were removed from the registry (FDUSD, AUSD, BUCK, BLUB, SCA, TURBOS). `STABLE_ASSETS = ['USDC']` (the canonical USD unit for balance aggregation), but **`OPERATION_ASSETS.save` and `OPERATION_ASSETS.borrow` accept both `'USDC'` and `'USDsui'`** (v0.51.0+). Use `isAllowedAsset(op, asset)` / `assertAllowedAsset(op, asset)` to validate.
|
|
271
271
|
|
|
272
272
|
```typescript
|
|
273
273
|
import {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { L as LendingAdapter, a as LendingRates, b as AdapterPositions, A as AdapterCapability, H as HealthInfo, c as AdapterTxResult, P as PendingReward } from '../descriptors-DkKhitk_.cjs';
|
|
2
2
|
export { d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from '../descriptors-DkKhitk_.cjs';
|
|
3
|
-
import { c as MaxWithdrawResult, M as MaxBorrowResult } from '../types-
|
|
3
|
+
import { c as MaxWithdrawResult, M as MaxBorrowResult } from '../types-DVVns7_w.cjs';
|
|
4
4
|
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
5
5
|
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
6
6
|
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { L as LendingAdapter, a as LendingRates, b as AdapterPositions, A as AdapterCapability, H as HealthInfo, c as AdapterTxResult, P as PendingReward } from '../descriptors-DkKhitk_.js';
|
|
2
2
|
export { d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from '../descriptors-DkKhitk_.js';
|
|
3
|
-
import { c as MaxWithdrawResult, M as MaxBorrowResult } from '../types-
|
|
3
|
+
import { c as MaxWithdrawResult, M as MaxBorrowResult } from '../types-DVVns7_w.js';
|
|
4
4
|
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
5
5
|
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
6
6
|
|
package/dist/browser.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { A as ALL_NAVI_ASSETS, a as AutoTopUpResult, B as BPS_DENOMINATOR, C as CLOCK_ID, b as COIN_REGISTRY, c as ClassifyBalanceChange, d as ClassifyResult, e as CoinMeta, D as DEFAULT_NETWORK, f as DEFAULT_SAFEGUARD_CONFIG, E as ETH_TYPE, g as ExtractedTransfer, F as FeeOperation, G as GAS_RESERVE_MIN, h as GasExecutionResult, i as GasRequestType, j as GasSponsorResponse, k as GasStatusResponse, I as IKA_TYPE, K as KNOWN_TARGETS, l as KeypairSigner, L as LABEL_PATTERNS, m as LOFI_TYPE, M as MANIFEST_TYPE, n as MIST_PER_SUI, N as NAVX_TYPE, O as OUTBOUND_OPS, P as ProtocolFeeInfo, S as STABLE_ASSETS, o as SUI_DECIMALS, p as SUI_TYPE, q as SUPPORTED_ASSETS, r as SafeguardConfig, s as SafeguardError, t as SafeguardErrorDetails, u as SafeguardRule, v as SimulationResult, w as StableAsset, x as SuiRpcTxBlock, y as SupportedAsset, T as T2000Error, z as T2000ErrorCode, H as T2000ErrorData, J as TOKEN_MAP, Q as TransactionSigner, R as TxDirection, U as TxMetadata, V as USDC_DECIMALS, W as USDC_TYPE, X as USDE_TYPE, Y as USDSUI_TYPE, Z as USDT_TYPE, _ as WAL_TYPE, $ as WBTC_TYPE, a0 as ZkLoginProof, a1 as ZkLoginSigner, a2 as addCollectFeeToTx, a3 as calculateFee, a4 as classifyAction, a5 as classifyLabel, a6 as classifyTransaction, a7 as executeAutoTopUp, a8 as executeWithGas, a9 as extractTransferDetails, aa as extractTxCommands, ab as extractTxSender, ac as fallbackLabel, ad as formatAssetAmount, ae as formatSui, af as formatUsd, ag as getDecimals, ah as getDecimalsForCoinType, ai as getGasStatus, aj as getTier, ak as isSupported, al as isTier1, am as isTier2, an as mapMoveAbortCode, ao as mapWalletError, ap as mistToSui, aq as parseSuiRpcTx, ar as rawToStable, as as rawToUsdc, at as refineLendingLabel, au as resolveSymbol, av as resolveTokenType, aw as shouldAutoTopUp, ax as stableToRaw, ay as suiToMist, az as truncateAddress, aA as usdcToRaw, aB as validateAddress } from './token-registry-
|
|
2
|
-
export { A as AssetRates, B as BalanceResponse, a as BorrowResult, C as ClaimRewardsResult, D as DepositInfo, E as EarningsResult, F as FundStatusResult, G as GasMethod, b as GasReserve, H as HealthFactorResult, M as MaxBorrowResult, c as MaxWithdrawResult, P as PayOptions, d as PayResult, e as PendingReward, f as PositionEntry, g as PositionsResult, R as RatesResult, h as RepayResult, S as SaveResult, i as SendResult, T as TransactionRecord, W as WithdrawResult } from './types-
|
|
1
|
+
export { A as ALL_NAVI_ASSETS, a as AutoTopUpResult, B as BPS_DENOMINATOR, C as CLOCK_ID, b as COIN_REGISTRY, c as ClassifyBalanceChange, d as ClassifyResult, e as CoinMeta, D as DEFAULT_NETWORK, f as DEFAULT_SAFEGUARD_CONFIG, E as ETH_TYPE, g as ExtractedTransfer, F as FeeOperation, G as GAS_RESERVE_MIN, h as GasExecutionResult, i as GasRequestType, j as GasSponsorResponse, k as GasStatusResponse, I as IKA_TYPE, K as KNOWN_TARGETS, l as KeypairSigner, L as LABEL_PATTERNS, m as LOFI_TYPE, M as MANIFEST_TYPE, n as MIST_PER_SUI, N as NAVX_TYPE, O as OUTBOUND_OPS, P as ProtocolFeeInfo, S as STABLE_ASSETS, o as SUI_DECIMALS, p as SUI_TYPE, q as SUPPORTED_ASSETS, r as SafeguardConfig, s as SafeguardError, t as SafeguardErrorDetails, u as SafeguardRule, v as SimulationResult, w as StableAsset, x as SuiRpcTxBlock, y as SupportedAsset, T as T2000Error, z as T2000ErrorCode, H as T2000ErrorData, J as TOKEN_MAP, Q as TransactionSigner, R as TxDirection, U as TxMetadata, V as USDC_DECIMALS, W as USDC_TYPE, X as USDE_TYPE, Y as USDSUI_TYPE, Z as USDT_TYPE, _ as WAL_TYPE, $ as WBTC_TYPE, a0 as ZkLoginProof, a1 as ZkLoginSigner, a2 as addCollectFeeToTx, a3 as calculateFee, a4 as classifyAction, a5 as classifyLabel, a6 as classifyTransaction, a7 as executeAutoTopUp, a8 as executeWithGas, a9 as extractTransferDetails, aa as extractTxCommands, ab as extractTxSender, ac as fallbackLabel, ad as formatAssetAmount, ae as formatSui, af as formatUsd, ag as getDecimals, ah as getDecimalsForCoinType, ai as getGasStatus, aj as getTier, ak as isSupported, al as isTier1, am as isTier2, an as mapMoveAbortCode, ao as mapWalletError, ap as mistToSui, aq as parseSuiRpcTx, ar as rawToStable, as as rawToUsdc, at as refineLendingLabel, au as resolveSymbol, av as resolveTokenType, aw as shouldAutoTopUp, ax as stableToRaw, ay as suiToMist, az as truncateAddress, aA as usdcToRaw, aB as validateAddress } from './token-registry-DWRdYf6m.cjs';
|
|
2
|
+
export { A as AssetRates, B as BalanceResponse, a as BorrowResult, C as ClaimRewardsResult, D as DepositInfo, E as EarningsResult, F as FundStatusResult, G as GasMethod, b as GasReserve, H as HealthFactorResult, M as MaxBorrowResult, c as MaxWithdrawResult, P as PayOptions, d as PayResult, e as PendingReward, f as PositionEntry, g as PositionsResult, R as RatesResult, h as RepayResult, S as SaveResult, i as SendResult, T as TransactionRecord, W as WithdrawResult } from './types-DVVns7_w.cjs';
|
|
3
3
|
import '@mysten/sui/keypairs/ed25519';
|
|
4
4
|
import '@mysten/sui/jsonRpc';
|
|
5
5
|
import '@mysten/sui/transactions';
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { A as ALL_NAVI_ASSETS, a as AutoTopUpResult, B as BPS_DENOMINATOR, C as CLOCK_ID, b as COIN_REGISTRY, c as ClassifyBalanceChange, d as ClassifyResult, e as CoinMeta, D as DEFAULT_NETWORK, f as DEFAULT_SAFEGUARD_CONFIG, E as ETH_TYPE, g as ExtractedTransfer, F as FeeOperation, G as GAS_RESERVE_MIN, h as GasExecutionResult, i as GasRequestType, j as GasSponsorResponse, k as GasStatusResponse, I as IKA_TYPE, K as KNOWN_TARGETS, l as KeypairSigner, L as LABEL_PATTERNS, m as LOFI_TYPE, M as MANIFEST_TYPE, n as MIST_PER_SUI, N as NAVX_TYPE, O as OUTBOUND_OPS, P as ProtocolFeeInfo, S as STABLE_ASSETS, o as SUI_DECIMALS, p as SUI_TYPE, q as SUPPORTED_ASSETS, r as SafeguardConfig, s as SafeguardError, t as SafeguardErrorDetails, u as SafeguardRule, v as SimulationResult, w as StableAsset, x as SuiRpcTxBlock, y as SupportedAsset, T as T2000Error, z as T2000ErrorCode, H as T2000ErrorData, J as TOKEN_MAP, Q as TransactionSigner, R as TxDirection, U as TxMetadata, V as USDC_DECIMALS, W as USDC_TYPE, X as USDE_TYPE, Y as USDSUI_TYPE, Z as USDT_TYPE, _ as WAL_TYPE, $ as WBTC_TYPE, a0 as ZkLoginProof, a1 as ZkLoginSigner, a2 as addCollectFeeToTx, a3 as calculateFee, a4 as classifyAction, a5 as classifyLabel, a6 as classifyTransaction, a7 as executeAutoTopUp, a8 as executeWithGas, a9 as extractTransferDetails, aa as extractTxCommands, ab as extractTxSender, ac as fallbackLabel, ad as formatAssetAmount, ae as formatSui, af as formatUsd, ag as getDecimals, ah as getDecimalsForCoinType, ai as getGasStatus, aj as getTier, ak as isSupported, al as isTier1, am as isTier2, an as mapMoveAbortCode, ao as mapWalletError, ap as mistToSui, aq as parseSuiRpcTx, ar as rawToStable, as as rawToUsdc, at as refineLendingLabel, au as resolveSymbol, av as resolveTokenType, aw as shouldAutoTopUp, ax as stableToRaw, ay as suiToMist, az as truncateAddress, aA as usdcToRaw, aB as validateAddress } from './token-registry-
|
|
2
|
-
export { A as AssetRates, B as BalanceResponse, a as BorrowResult, C as ClaimRewardsResult, D as DepositInfo, E as EarningsResult, F as FundStatusResult, G as GasMethod, b as GasReserve, H as HealthFactorResult, M as MaxBorrowResult, c as MaxWithdrawResult, P as PayOptions, d as PayResult, e as PendingReward, f as PositionEntry, g as PositionsResult, R as RatesResult, h as RepayResult, S as SaveResult, i as SendResult, T as TransactionRecord, W as WithdrawResult } from './types-
|
|
1
|
+
export { A as ALL_NAVI_ASSETS, a as AutoTopUpResult, B as BPS_DENOMINATOR, C as CLOCK_ID, b as COIN_REGISTRY, c as ClassifyBalanceChange, d as ClassifyResult, e as CoinMeta, D as DEFAULT_NETWORK, f as DEFAULT_SAFEGUARD_CONFIG, E as ETH_TYPE, g as ExtractedTransfer, F as FeeOperation, G as GAS_RESERVE_MIN, h as GasExecutionResult, i as GasRequestType, j as GasSponsorResponse, k as GasStatusResponse, I as IKA_TYPE, K as KNOWN_TARGETS, l as KeypairSigner, L as LABEL_PATTERNS, m as LOFI_TYPE, M as MANIFEST_TYPE, n as MIST_PER_SUI, N as NAVX_TYPE, O as OUTBOUND_OPS, P as ProtocolFeeInfo, S as STABLE_ASSETS, o as SUI_DECIMALS, p as SUI_TYPE, q as SUPPORTED_ASSETS, r as SafeguardConfig, s as SafeguardError, t as SafeguardErrorDetails, u as SafeguardRule, v as SimulationResult, w as StableAsset, x as SuiRpcTxBlock, y as SupportedAsset, T as T2000Error, z as T2000ErrorCode, H as T2000ErrorData, J as TOKEN_MAP, Q as TransactionSigner, R as TxDirection, U as TxMetadata, V as USDC_DECIMALS, W as USDC_TYPE, X as USDE_TYPE, Y as USDSUI_TYPE, Z as USDT_TYPE, _ as WAL_TYPE, $ as WBTC_TYPE, a0 as ZkLoginProof, a1 as ZkLoginSigner, a2 as addCollectFeeToTx, a3 as calculateFee, a4 as classifyAction, a5 as classifyLabel, a6 as classifyTransaction, a7 as executeAutoTopUp, a8 as executeWithGas, a9 as extractTransferDetails, aa as extractTxCommands, ab as extractTxSender, ac as fallbackLabel, ad as formatAssetAmount, ae as formatSui, af as formatUsd, ag as getDecimals, ah as getDecimalsForCoinType, ai as getGasStatus, aj as getTier, ak as isSupported, al as isTier1, am as isTier2, an as mapMoveAbortCode, ao as mapWalletError, ap as mistToSui, aq as parseSuiRpcTx, ar as rawToStable, as as rawToUsdc, at as refineLendingLabel, au as resolveSymbol, av as resolveTokenType, aw as shouldAutoTopUp, ax as stableToRaw, ay as suiToMist, az as truncateAddress, aA as usdcToRaw, aB as validateAddress } from './token-registry-BortlMRr.js';
|
|
2
|
+
export { A as AssetRates, B as BalanceResponse, a as BorrowResult, C as ClaimRewardsResult, D as DepositInfo, E as EarningsResult, F as FundStatusResult, G as GasMethod, b as GasReserve, H as HealthFactorResult, M as MaxBorrowResult, c as MaxWithdrawResult, P as PayOptions, d as PayResult, e as PendingReward, f as PositionEntry, g as PositionsResult, R as RatesResult, h as RepayResult, S as SaveResult, i as SendResult, T as TransactionRecord, W as WithdrawResult } from './types-DVVns7_w.js';
|
|
3
3
|
import '@mysten/sui/keypairs/ed25519';
|
|
4
4
|
import '@mysten/sui/jsonRpc';
|
|
5
5
|
import '@mysten/sui/transactions';
|
package/dist/index.cjs
CHANGED
|
@@ -7180,19 +7180,24 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7180
7180
|
if (params.amount === "all") {
|
|
7181
7181
|
return this._repayAllBorrows(borrows);
|
|
7182
7182
|
}
|
|
7183
|
-
borrows.
|
|
7184
|
-
|
|
7183
|
+
const eligible = params.asset ? borrows.filter((b2) => b2.asset === params.asset) : borrows;
|
|
7184
|
+
if (eligible.length === 0) {
|
|
7185
|
+
throw new exports.T2000Error("NO_COLLATERAL", `No outstanding ${params.asset} borrow to repay`);
|
|
7186
|
+
}
|
|
7187
|
+
eligible.sort((a, b2) => b2.apy - a.apy);
|
|
7188
|
+
const target = eligible[0];
|
|
7185
7189
|
const adapter = this.registry.getLending(target.protocolId);
|
|
7186
7190
|
if (!adapter) throw new exports.T2000Error("PROTOCOL_UNAVAILABLE", `Protocol ${target.protocolId} not found`);
|
|
7187
7191
|
const repayAmount = Math.min(params.amount, target.amount);
|
|
7192
|
+
const targetAssetInfo = SUPPORTED_ASSETS[target.asset] ?? SUPPORTED_ASSETS.USDC;
|
|
7188
7193
|
const gasResult = await executeWithGas(this.client, this._signer, async () => {
|
|
7189
7194
|
if (adapter.addRepayToTx) {
|
|
7190
7195
|
const tx2 = new transactions.Transaction();
|
|
7191
7196
|
tx2.setSender(this._address);
|
|
7192
|
-
const
|
|
7193
|
-
if (
|
|
7194
|
-
const merged = this._mergeCoinsInTx(tx2,
|
|
7195
|
-
const raw = BigInt(Math.floor(repayAmount * 10 **
|
|
7197
|
+
const coins = await this._fetchCoins(targetAssetInfo.type);
|
|
7198
|
+
if (coins.length === 0) throw new exports.T2000Error("INSUFFICIENT_BALANCE", `No ${targetAssetInfo.displayName} coins`);
|
|
7199
|
+
const merged = this._mergeCoinsInTx(tx2, coins);
|
|
7200
|
+
const raw = BigInt(Math.floor(repayAmount * 10 ** targetAssetInfo.decimals));
|
|
7196
7201
|
const [repayCoin] = tx2.splitCoins(merged, [raw]);
|
|
7197
7202
|
await adapter.addRepayToTx(tx2, this._address, repayCoin, target.asset);
|
|
7198
7203
|
return tx2;
|
|
@@ -7201,11 +7206,12 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7201
7206
|
return tx;
|
|
7202
7207
|
});
|
|
7203
7208
|
const hf = await adapter.getHealth(this._address);
|
|
7204
|
-
this.emitBalanceChange(
|
|
7209
|
+
this.emitBalanceChange(target.asset, repayAmount, "repay", gasResult.digest);
|
|
7205
7210
|
return {
|
|
7206
7211
|
success: true,
|
|
7207
7212
|
tx: gasResult.digest,
|
|
7208
7213
|
amount: repayAmount,
|
|
7214
|
+
asset: target.asset,
|
|
7209
7215
|
remainingDebt: hf.borrowed,
|
|
7210
7216
|
gasCost: gasResult.gasCostSui,
|
|
7211
7217
|
gasMethod: gasResult.gasMethod
|
|
@@ -7224,15 +7230,20 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7224
7230
|
if (canPTB) {
|
|
7225
7231
|
const tx = new transactions.Transaction();
|
|
7226
7232
|
tx.setSender(this._address);
|
|
7227
|
-
const
|
|
7228
|
-
|
|
7229
|
-
|
|
7230
|
-
|
|
7233
|
+
const assetMerged = /* @__PURE__ */ new Map();
|
|
7234
|
+
const uniqueAssets = Array.from(new Set(entries.map((e) => e.borrow.asset)));
|
|
7235
|
+
for (const asset of uniqueAssets) {
|
|
7236
|
+
const info = SUPPORTED_ASSETS[asset];
|
|
7237
|
+
if (!info) throw new exports.T2000Error("ASSET_NOT_SUPPORTED", `Cannot repay unknown asset: ${asset}`);
|
|
7238
|
+
const coins = await this._fetchCoins(info.type);
|
|
7239
|
+
if (coins.length === 0) throw new exports.T2000Error("INSUFFICIENT_BALANCE", `No ${info.displayName} coins for repayment`);
|
|
7240
|
+
assetMerged.set(asset, this._mergeCoinsInTx(tx, coins));
|
|
7231
7241
|
}
|
|
7232
7242
|
for (const { borrow, adapter } of entries) {
|
|
7233
|
-
const
|
|
7234
|
-
|
|
7235
|
-
const
|
|
7243
|
+
const info = SUPPORTED_ASSETS[borrow.asset];
|
|
7244
|
+
const merged = assetMerged.get(borrow.asset);
|
|
7245
|
+
const raw = BigInt(Math.floor(borrow.amount * 10 ** info.decimals));
|
|
7246
|
+
const [repayCoin] = tx.splitCoins(merged, [raw]);
|
|
7236
7247
|
await adapter.addRepayToTx(tx, this._address, repayCoin, borrow.asset);
|
|
7237
7248
|
totalRepaid += borrow.amount;
|
|
7238
7249
|
}
|
|
@@ -7248,11 +7259,13 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7248
7259
|
});
|
|
7249
7260
|
const firstAdapter = entries[0]?.adapter;
|
|
7250
7261
|
const hf = firstAdapter ? await firstAdapter.getHealth(this._address) : { borrowed: 0 };
|
|
7251
|
-
|
|
7262
|
+
const dominantAsset = entries.reduce((acc, e) => acc.amount >= e.borrow.amount ? acc : e.borrow, entries[0]?.borrow ?? { asset: "USDC", amount: 0 }).asset;
|
|
7263
|
+
this.emitBalanceChange(dominantAsset, totalRepaid, "repay", gasResult.digest);
|
|
7252
7264
|
return {
|
|
7253
7265
|
success: true,
|
|
7254
7266
|
tx: gasResult.digest,
|
|
7255
7267
|
amount: totalRepaid,
|
|
7268
|
+
asset: dominantAsset,
|
|
7256
7269
|
remainingDebt: hf.borrowed,
|
|
7257
7270
|
gasCost: gasResult.gasCostSui,
|
|
7258
7271
|
gasMethod: gasResult.gasMethod
|