@t2000/sdk 1.0.1 → 1.1.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 +15 -15
- package/dist/adapters/descriptors.d.cts +1 -1
- package/dist/adapters/descriptors.d.ts +1 -1
- package/dist/adapters/index.cjs +30 -42
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +7 -9
- package/dist/adapters/index.d.ts +7 -9
- package/dist/adapters/index.js +30 -42
- package/dist/adapters/index.js.map +1 -1
- package/dist/browser.cjs +194 -77
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +2 -1
- package/dist/browser.d.ts +2 -1
- package/dist/browser.js +186 -74
- package/dist/browser.js.map +1 -1
- package/dist/{descriptors-CDVXo3BM.d.cts → descriptors-BnbL3xN8.d.cts} +11 -7
- package/dist/{descriptors-CDVXo3BM.d.ts → descriptors-BnbL3xN8.d.ts} +11 -7
- package/dist/index.cjs +85 -91
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -50
- package/dist/index.d.ts +7 -50
- package/dist/index.js +84 -91
- package/dist/index.js.map +1 -1
- package/dist/{token-registry-DAHghHh2.d.cts → types-Bx0uh6g9.d.cts} +154 -45
- package/dist/{token-registry-CoTPqCbS.d.ts → types-CWnyOY9f.d.ts} +154 -45
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
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 {
|
|
5
|
-
export { A as ALL_NAVI_ASSETS,
|
|
6
|
-
import { L as LendingAdapter, a as LendingRates, P as PendingReward$1 } from './descriptors-
|
|
7
|
-
export { A as AdapterCapability, b as AdapterPositions, c as AdapterTxResult, H as HealthInfo, d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from './descriptors-
|
|
4
|
+
import { V as TxMetadata, q as SafeguardConfig, T as T2000Error, R as TransactionSigner, a1 as ZkLoginProof, x as SupportedAsset } from './types-Bx0uh6g9.cjs';
|
|
5
|
+
export { A as ALL_NAVI_ASSETS, B as BORROW_FEE_BPS, a as BPS_DENOMINATOR, aB as CETUS_USDC_SUI_POOL, 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, I as IKA_TYPE, K as KNOWN_TARGETS, h as KeypairSigner, L as LABEL_PATTERNS, i as LOFI_TYPE, M as MANIFEST_TYPE, j as MIST_PER_SUI, N as NAVX_TYPE, aC as OPERATION_ASSETS, O as OUTBOUND_OPS, k as OVERLAY_FEE_RATE, aD as Operation, l as OverlayFeeConfig, P as ProtocolFeeInfo, S as SAVE_FEE_BPS, m as STABLE_ASSETS, n as SUI_DECIMALS, o as SUI_TYPE, p as SUPPORTED_ASSETS, r as SafeguardError, s as SafeguardErrorDetails, t as SafeguardRule, u as SimulationResult, v as StableAsset, w as SuiRpcTxBlock, y as SwapRouteResult, z as T2000ErrorCode, H as T2000ErrorData, J as T2000_OVERLAY_FEE_WALLET, Q as TOKEN_MAP, U as TxDirection, W as USDC_DECIMALS, X as USDC_TYPE, Y as USDE_TYPE, Z as USDSUI_TYPE, _ as USDT_TYPE, $ as WAL_TYPE, a0 as WBTC_TYPE, a2 as ZkLoginSigner, a3 as addFeeTransfer, aE as assertAllowedAsset, a4 as buildSwapTx, a5 as calculateFee, a6 as classifyAction, a7 as classifyLabel, a8 as classifyTransaction, a9 as extractTransferDetails, aa as extractTxCommands, ab as extractTxSender, ac as fallbackLabel, ad as findSwapRoute, ae as formatAssetAmount, af as formatSui, ag as formatUsd, ah as getDecimals, ai as getDecimalsForCoinType, aj as getTier, aF as isAllowedAsset, ak as isSupported, al as isTier1, am as isTier2, an as mapMoveAbortCode, ao as mapWalletError, ap as mistToSui, aG as normalizeCoinType, aq as parseSuiRpcTx, aH as queryHistory, aI as queryTransaction, ar as rawToStable, as as rawToUsdc, at as refineLendingLabel, au as resolveSymbol, av as resolveTokenType, aJ as simulateTransaction, aw as stableToRaw, ax as suiToMist, aK as throwIfSimulationFailed, ay as truncateAddress, az as usdcToRaw, aA as validateAddress } from './types-Bx0uh6g9.cjs';
|
|
6
|
+
import { L as LendingAdapter, a as LendingRates, P as PendingReward$1 } from './descriptors-BnbL3xN8.cjs';
|
|
7
|
+
export { A as AdapterCapability, b as AdapterPositions, c as AdapterTxResult, H as HealthInfo, d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from './descriptors-BnbL3xN8.cjs';
|
|
8
8
|
import { i as T2000Options, P as PayOptions, c as PayResult, j as StakeVSuiResult, U as UnstakeVSuiResult, k as SwapResult, l as SwapQuoteResult, h as SendResult, B as BalanceResponse, T as TransactionRecord, D as DepositInfo, m as PaymentRequest, S as SaveResult, W as WithdrawResult, b as MaxWithdrawResult, a as BorrowResult, g as RepayResult, M as MaxBorrowResult, H as HealthFactorResult, d as PendingReward, C as ClaimRewardsResult, n as CompoundRewardsResult, f as PositionsResult, R as RatesResult, E as EarningsResult, F as FundStatusResult, o as FinancialSummary } from './types-jAD-e7Pq.cjs';
|
|
9
9
|
export { A as AssetRates, G as GasReserve, p as HFAlertLevel, e as PositionEntry } from './types-jAD-e7Pq.cjs';
|
|
10
|
-
import {
|
|
11
|
-
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
10
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
12
11
|
export { NaviAdapter, ProtocolRegistry } from './adapters/index.cjs';
|
|
12
|
+
import '@cetusprotocol/aggregator-sdk';
|
|
13
13
|
|
|
14
14
|
declare class SafeguardEnforcer {
|
|
15
15
|
private config;
|
|
@@ -258,49 +258,6 @@ declare function getSwapQuote(params: {
|
|
|
258
258
|
byAmountIn?: boolean;
|
|
259
259
|
}): Promise<SwapQuoteResult>;
|
|
260
260
|
|
|
261
|
-
/**
|
|
262
|
-
* Cetus Aggregator V3 SDK wrapper — the ONLY file that imports @cetusprotocol/aggregator-sdk.
|
|
263
|
-
* Documented CLAUDE.md exception: multi-DEX routing cannot be feasibly replaced by thin tx builders.
|
|
264
|
-
*/
|
|
265
|
-
|
|
266
|
-
interface SwapRouteResult {
|
|
267
|
-
routerData: RouterDataV3;
|
|
268
|
-
amountIn: string;
|
|
269
|
-
amountOut: string;
|
|
270
|
-
byAmountIn: boolean;
|
|
271
|
-
priceImpact: number;
|
|
272
|
-
insufficientLiquidity: boolean;
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* [v1.4 Item 5] T2000 swap overlay fee — 0.1% taken on top of Cetus's
|
|
276
|
-
* own fee. Exported so consumers (web app, spec-consistency assertions)
|
|
277
|
-
* can compare against a single source of truth instead of hard-coding
|
|
278
|
-
* the value. Changing this rate requires a coordinated SDK + audric
|
|
279
|
-
* release.
|
|
280
|
-
*/
|
|
281
|
-
declare const OVERLAY_FEE_RATE = 0.001;
|
|
282
|
-
/**
|
|
283
|
-
* Find the optimal swap route via Cetus Aggregator REST API.
|
|
284
|
-
*/
|
|
285
|
-
declare function findSwapRoute(params: {
|
|
286
|
-
walletAddress: string;
|
|
287
|
-
from: string;
|
|
288
|
-
to: string;
|
|
289
|
-
amount: bigint;
|
|
290
|
-
byAmountIn: boolean;
|
|
291
|
-
}): Promise<SwapRouteResult | null>;
|
|
292
|
-
/**
|
|
293
|
-
* Build a swap PTB from a route result. The caller must provide an input coin
|
|
294
|
-
* obtained by splitting/merging wallet coins.
|
|
295
|
-
*/
|
|
296
|
-
declare function buildSwapTx(params: {
|
|
297
|
-
walletAddress: string;
|
|
298
|
-
route: SwapRouteResult;
|
|
299
|
-
tx: Transaction;
|
|
300
|
-
inputCoin: TransactionObjectArgument;
|
|
301
|
-
slippage: number;
|
|
302
|
-
}): Promise<TransactionObjectArgument>;
|
|
303
|
-
|
|
304
261
|
/**
|
|
305
262
|
* VOLO vSUI liquid staking — thin transaction builders.
|
|
306
263
|
* No SDK dependency. Two Move calls, immutable contract addresses.
|
|
@@ -328,4 +285,4 @@ declare function buildStakeVSuiTx(_client: SuiJsonRpcClient, address: string, am
|
|
|
328
285
|
*/
|
|
329
286
|
declare function buildUnstakeVSuiTx(client: SuiJsonRpcClient, address: string, amountMist: bigint | 'all'): Promise<Transaction>;
|
|
330
287
|
|
|
331
|
-
export { BalanceResponse, BorrowResult, ClaimRewardsResult, CompoundRewardsResult, ContactManager, DepositInfo, EarningsResult, FinancialSummary, type FinancialSummaryOptions, FundStatusResult, HF_CRITICAL_THRESHOLD, HF_WARN_THRESHOLD, HealthFactorResult, LendingAdapter, LendingRates, MaxBorrowResult, MaxWithdrawResult,
|
|
288
|
+
export { BalanceResponse, BorrowResult, ClaimRewardsResult, CompoundRewardsResult, ContactManager, DepositInfo, EarningsResult, FinancialSummary, type FinancialSummaryOptions, FundStatusResult, HF_CRITICAL_THRESHOLD, HF_WARN_THRESHOLD, HealthFactorResult, LendingAdapter, LendingRates, MaxBorrowResult, MaxWithdrawResult, PayOptions, PayResult, PaymentRequest, PendingReward, PositionsResult, RatesResult, RepayResult, SafeguardConfig, SafeguardEnforcer, SaveResult, SendResult, StakeVSuiResult, SupportedAsset, SwapQuoteResult, SwapResult, T2000, T2000Error, T2000Options, TransactionRecord, TransactionSigner, TxMetadata, UnstakeVSuiResult, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, type VoloStats, WithdrawResult, ZkLoginProof, buildStakeVSuiTx, buildUnstakeVSuiTx, exportPrivateKey, generateKeypair, getAddress, getFinancialSummary, getPendingRewards, getRates, getSwapQuote, getVoloStats, keypairFromPrivateKey, loadKey, saveKey, walletExists };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
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 {
|
|
5
|
-
export { A as ALL_NAVI_ASSETS,
|
|
6
|
-
import { L as LendingAdapter, a as LendingRates, P as PendingReward$1 } from './descriptors-
|
|
7
|
-
export { A as AdapterCapability, b as AdapterPositions, c as AdapterTxResult, H as HealthInfo, d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from './descriptors-
|
|
4
|
+
import { V as TxMetadata, q as SafeguardConfig, T as T2000Error, R as TransactionSigner, a1 as ZkLoginProof, x as SupportedAsset } from './types-CWnyOY9f.js';
|
|
5
|
+
export { A as ALL_NAVI_ASSETS, B as BORROW_FEE_BPS, a as BPS_DENOMINATOR, aB as CETUS_USDC_SUI_POOL, 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, I as IKA_TYPE, K as KNOWN_TARGETS, h as KeypairSigner, L as LABEL_PATTERNS, i as LOFI_TYPE, M as MANIFEST_TYPE, j as MIST_PER_SUI, N as NAVX_TYPE, aC as OPERATION_ASSETS, O as OUTBOUND_OPS, k as OVERLAY_FEE_RATE, aD as Operation, l as OverlayFeeConfig, P as ProtocolFeeInfo, S as SAVE_FEE_BPS, m as STABLE_ASSETS, n as SUI_DECIMALS, o as SUI_TYPE, p as SUPPORTED_ASSETS, r as SafeguardError, s as SafeguardErrorDetails, t as SafeguardRule, u as SimulationResult, v as StableAsset, w as SuiRpcTxBlock, y as SwapRouteResult, z as T2000ErrorCode, H as T2000ErrorData, J as T2000_OVERLAY_FEE_WALLET, Q as TOKEN_MAP, U as TxDirection, W as USDC_DECIMALS, X as USDC_TYPE, Y as USDE_TYPE, Z as USDSUI_TYPE, _ as USDT_TYPE, $ as WAL_TYPE, a0 as WBTC_TYPE, a2 as ZkLoginSigner, a3 as addFeeTransfer, aE as assertAllowedAsset, a4 as buildSwapTx, a5 as calculateFee, a6 as classifyAction, a7 as classifyLabel, a8 as classifyTransaction, a9 as extractTransferDetails, aa as extractTxCommands, ab as extractTxSender, ac as fallbackLabel, ad as findSwapRoute, ae as formatAssetAmount, af as formatSui, ag as formatUsd, ah as getDecimals, ai as getDecimalsForCoinType, aj as getTier, aF as isAllowedAsset, ak as isSupported, al as isTier1, am as isTier2, an as mapMoveAbortCode, ao as mapWalletError, ap as mistToSui, aG as normalizeCoinType, aq as parseSuiRpcTx, aH as queryHistory, aI as queryTransaction, ar as rawToStable, as as rawToUsdc, at as refineLendingLabel, au as resolveSymbol, av as resolveTokenType, aJ as simulateTransaction, aw as stableToRaw, ax as suiToMist, aK as throwIfSimulationFailed, ay as truncateAddress, az as usdcToRaw, aA as validateAddress } from './types-CWnyOY9f.js';
|
|
6
|
+
import { L as LendingAdapter, a as LendingRates, P as PendingReward$1 } from './descriptors-BnbL3xN8.js';
|
|
7
|
+
export { A as AdapterCapability, b as AdapterPositions, c as AdapterTxResult, H as HealthInfo, d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from './descriptors-BnbL3xN8.js';
|
|
8
8
|
import { i as T2000Options, P as PayOptions, c as PayResult, j as StakeVSuiResult, U as UnstakeVSuiResult, k as SwapResult, l as SwapQuoteResult, h as SendResult, B as BalanceResponse, T as TransactionRecord, D as DepositInfo, m as PaymentRequest, S as SaveResult, W as WithdrawResult, b as MaxWithdrawResult, a as BorrowResult, g as RepayResult, M as MaxBorrowResult, H as HealthFactorResult, d as PendingReward, C as ClaimRewardsResult, n as CompoundRewardsResult, f as PositionsResult, R as RatesResult, E as EarningsResult, F as FundStatusResult, o as FinancialSummary } from './types-jAD-e7Pq.js';
|
|
9
9
|
export { A as AssetRates, G as GasReserve, p as HFAlertLevel, e as PositionEntry } from './types-jAD-e7Pq.js';
|
|
10
|
-
import {
|
|
11
|
-
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
10
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
12
11
|
export { NaviAdapter, ProtocolRegistry } from './adapters/index.js';
|
|
12
|
+
import '@cetusprotocol/aggregator-sdk';
|
|
13
13
|
|
|
14
14
|
declare class SafeguardEnforcer {
|
|
15
15
|
private config;
|
|
@@ -258,49 +258,6 @@ declare function getSwapQuote(params: {
|
|
|
258
258
|
byAmountIn?: boolean;
|
|
259
259
|
}): Promise<SwapQuoteResult>;
|
|
260
260
|
|
|
261
|
-
/**
|
|
262
|
-
* Cetus Aggregator V3 SDK wrapper — the ONLY file that imports @cetusprotocol/aggregator-sdk.
|
|
263
|
-
* Documented CLAUDE.md exception: multi-DEX routing cannot be feasibly replaced by thin tx builders.
|
|
264
|
-
*/
|
|
265
|
-
|
|
266
|
-
interface SwapRouteResult {
|
|
267
|
-
routerData: RouterDataV3;
|
|
268
|
-
amountIn: string;
|
|
269
|
-
amountOut: string;
|
|
270
|
-
byAmountIn: boolean;
|
|
271
|
-
priceImpact: number;
|
|
272
|
-
insufficientLiquidity: boolean;
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* [v1.4 Item 5] T2000 swap overlay fee — 0.1% taken on top of Cetus's
|
|
276
|
-
* own fee. Exported so consumers (web app, spec-consistency assertions)
|
|
277
|
-
* can compare against a single source of truth instead of hard-coding
|
|
278
|
-
* the value. Changing this rate requires a coordinated SDK + audric
|
|
279
|
-
* release.
|
|
280
|
-
*/
|
|
281
|
-
declare const OVERLAY_FEE_RATE = 0.001;
|
|
282
|
-
/**
|
|
283
|
-
* Find the optimal swap route via Cetus Aggregator REST API.
|
|
284
|
-
*/
|
|
285
|
-
declare function findSwapRoute(params: {
|
|
286
|
-
walletAddress: string;
|
|
287
|
-
from: string;
|
|
288
|
-
to: string;
|
|
289
|
-
amount: bigint;
|
|
290
|
-
byAmountIn: boolean;
|
|
291
|
-
}): Promise<SwapRouteResult | null>;
|
|
292
|
-
/**
|
|
293
|
-
* Build a swap PTB from a route result. The caller must provide an input coin
|
|
294
|
-
* obtained by splitting/merging wallet coins.
|
|
295
|
-
*/
|
|
296
|
-
declare function buildSwapTx(params: {
|
|
297
|
-
walletAddress: string;
|
|
298
|
-
route: SwapRouteResult;
|
|
299
|
-
tx: Transaction;
|
|
300
|
-
inputCoin: TransactionObjectArgument;
|
|
301
|
-
slippage: number;
|
|
302
|
-
}): Promise<TransactionObjectArgument>;
|
|
303
|
-
|
|
304
261
|
/**
|
|
305
262
|
* VOLO vSUI liquid staking — thin transaction builders.
|
|
306
263
|
* No SDK dependency. Two Move calls, immutable contract addresses.
|
|
@@ -328,4 +285,4 @@ declare function buildStakeVSuiTx(_client: SuiJsonRpcClient, address: string, am
|
|
|
328
285
|
*/
|
|
329
286
|
declare function buildUnstakeVSuiTx(client: SuiJsonRpcClient, address: string, amountMist: bigint | 'all'): Promise<Transaction>;
|
|
330
287
|
|
|
331
|
-
export { BalanceResponse, BorrowResult, ClaimRewardsResult, CompoundRewardsResult, ContactManager, DepositInfo, EarningsResult, FinancialSummary, type FinancialSummaryOptions, FundStatusResult, HF_CRITICAL_THRESHOLD, HF_WARN_THRESHOLD, HealthFactorResult, LendingAdapter, LendingRates, MaxBorrowResult, MaxWithdrawResult,
|
|
288
|
+
export { BalanceResponse, BorrowResult, ClaimRewardsResult, CompoundRewardsResult, ContactManager, DepositInfo, EarningsResult, FinancialSummary, type FinancialSummaryOptions, FundStatusResult, HF_CRITICAL_THRESHOLD, HF_WARN_THRESHOLD, HealthFactorResult, LendingAdapter, LendingRates, MaxBorrowResult, MaxWithdrawResult, PayOptions, PayResult, PaymentRequest, PendingReward, PositionsResult, RatesResult, RepayResult, SafeguardConfig, SafeguardEnforcer, SaveResult, SendResult, StakeVSuiResult, SupportedAsset, SwapQuoteResult, SwapResult, T2000, T2000Error, T2000Options, TransactionRecord, TransactionSigner, TxMetadata, UnstakeVSuiResult, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, type VoloStats, WithdrawResult, ZkLoginProof, buildStakeVSuiTx, buildUnstakeVSuiTx, exportPrivateKey, generateKeypair, getAddress, getFinancialSummary, getPendingRewards, getRates, getSwapQuote, getVoloStats, keypairFromPrivateKey, loadKey, saveKey, walletExists };
|
package/dist/index.js
CHANGED
|
@@ -726,18 +726,22 @@ __export(cetus_swap_exports, {
|
|
|
726
726
|
resolveTokenType: () => resolveTokenType,
|
|
727
727
|
simulateSwap: () => simulateSwap
|
|
728
728
|
});
|
|
729
|
-
function getClient(walletAddress) {
|
|
730
|
-
|
|
731
|
-
|
|
729
|
+
function getClient(walletAddress, overlayFee) {
|
|
730
|
+
const rate = overlayFee?.rate ?? 0;
|
|
731
|
+
const receiver = overlayFee?.receiver ?? "";
|
|
732
|
+
const key = `${walletAddress}|${rate}|${receiver}`;
|
|
733
|
+
const cached = clientCache.get(key);
|
|
734
|
+
if (cached) return cached;
|
|
735
|
+
const client = new AggregatorClient({
|
|
732
736
|
signer: walletAddress,
|
|
733
737
|
env: Env.Mainnet,
|
|
734
|
-
overlayFeeRate:
|
|
735
|
-
overlayFeeReceiver: OVERLAY_FEE_RECEIVER
|
|
738
|
+
...rate > 0 && receiver ? { overlayFeeRate: rate, overlayFeeReceiver: receiver } : {}
|
|
736
739
|
});
|
|
737
|
-
|
|
740
|
+
clientCache.set(key, client);
|
|
741
|
+
return client;
|
|
738
742
|
}
|
|
739
743
|
async function findSwapRoute(params) {
|
|
740
|
-
const client = getClient(params.walletAddress);
|
|
744
|
+
const client = getClient(params.walletAddress, params.overlayFee);
|
|
741
745
|
const findParams = {
|
|
742
746
|
from: params.from,
|
|
743
747
|
target: params.to,
|
|
@@ -774,7 +778,7 @@ function normalizePriceImpact(value) {
|
|
|
774
778
|
return Number.isFinite(n) ? n : 0;
|
|
775
779
|
}
|
|
776
780
|
async function buildSwapTx(params) {
|
|
777
|
-
const client = getClient(params.walletAddress);
|
|
781
|
+
const client = getClient(params.walletAddress, params.overlayFee);
|
|
778
782
|
const clampedSlippage = Math.max(1e-3, Math.min(params.slippage, 0.05));
|
|
779
783
|
const outputCoin = await client.routerSwap({
|
|
780
784
|
router: params.route.routerData,
|
|
@@ -785,7 +789,7 @@ async function buildSwapTx(params) {
|
|
|
785
789
|
return outputCoin;
|
|
786
790
|
}
|
|
787
791
|
async function simulateSwap(params) {
|
|
788
|
-
const client = getClient(params.walletAddress);
|
|
792
|
+
const client = getClient(params.walletAddress, params.overlayFee);
|
|
789
793
|
try {
|
|
790
794
|
await client.devInspectTransactionBlock(params.tx);
|
|
791
795
|
return { success: true };
|
|
@@ -793,13 +797,12 @@ async function simulateSwap(params) {
|
|
|
793
797
|
return { success: false, error: err instanceof Error ? err.message : String(err) };
|
|
794
798
|
}
|
|
795
799
|
}
|
|
796
|
-
var OVERLAY_FEE_RATE,
|
|
800
|
+
var OVERLAY_FEE_RATE, clientCache;
|
|
797
801
|
var init_cetus_swap = __esm({
|
|
798
802
|
"src/protocols/cetus-swap.ts"() {
|
|
799
803
|
init_token_registry();
|
|
800
804
|
OVERLAY_FEE_RATE = 1e-3;
|
|
801
|
-
|
|
802
|
-
clientInstance = null;
|
|
805
|
+
clientCache = /* @__PURE__ */ new Map();
|
|
803
806
|
}
|
|
804
807
|
});
|
|
805
808
|
|
|
@@ -895,13 +898,13 @@ function assertAllowedAsset(op, asset) {
|
|
|
895
898
|
);
|
|
896
899
|
}
|
|
897
900
|
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
var
|
|
901
|
+
process.env.T2000_PACKAGE_ID ?? "0xd775fcc66eae26797654d435d751dea56b82eeb999de51fd285348e573b968ad";
|
|
902
|
+
process.env.T2000_CONFIG_ID ?? "0x08ba26f0d260b5edf6a19c71492b3eb914906a7419baf2df1426765157e5862a";
|
|
903
|
+
var T2000_OVERLAY_FEE_WALLET = process.env.T2000_OVERLAY_FEE_WALLET ?? "0x5366efbf2b4fe5767fe2e78eb197aa5f5d138d88ac3333fbf3f80a1927da473a";
|
|
901
904
|
var DEFAULT_NETWORK = "mainnet";
|
|
902
905
|
var DEFAULT_RPC_URL = "https://fullnode.mainnet.sui.io:443";
|
|
903
906
|
var DEFAULT_KEY_PATH = "~/.t2000/wallet.key";
|
|
904
|
-
|
|
907
|
+
process.env.T2000_API_URL ?? "https://api.t2000.ai";
|
|
905
908
|
var CETUS_USDC_SUI_POOL = "0x51e883ba7c0b566a26cbc8a94cd33eb0abd418a77cc1e60ad22fd9b1f29cd2ab";
|
|
906
909
|
var GAS_RESERVE_MIN = 0.05;
|
|
907
910
|
|
|
@@ -1443,57 +1446,6 @@ function extractCommands(txBlock) {
|
|
|
1443
1446
|
// src/t2000.ts
|
|
1444
1447
|
init_token_registry();
|
|
1445
1448
|
|
|
1446
|
-
// src/protocols/protocolFee.ts
|
|
1447
|
-
var FEE_RATES = {
|
|
1448
|
-
save: SAVE_FEE_BPS,
|
|
1449
|
-
borrow: BORROW_FEE_BPS
|
|
1450
|
-
};
|
|
1451
|
-
var OP_CODES = {
|
|
1452
|
-
save: 0,
|
|
1453
|
-
borrow: 2
|
|
1454
|
-
};
|
|
1455
|
-
function calculateFee(operation, amount) {
|
|
1456
|
-
const bps = FEE_RATES[operation];
|
|
1457
|
-
const feeAmount = amount * Number(bps) / Number(BPS_DENOMINATOR);
|
|
1458
|
-
const rawAmount = usdcToRaw(feeAmount);
|
|
1459
|
-
return {
|
|
1460
|
-
amount: feeAmount,
|
|
1461
|
-
asset: "USDC",
|
|
1462
|
-
rate: Number(bps) / Number(BPS_DENOMINATOR),
|
|
1463
|
-
rawAmount
|
|
1464
|
-
};
|
|
1465
|
-
}
|
|
1466
|
-
function addCollectFeeToTx(tx, paymentCoin, operation) {
|
|
1467
|
-
const bps = FEE_RATES[operation];
|
|
1468
|
-
if (bps <= 0n) return;
|
|
1469
|
-
tx.moveCall({
|
|
1470
|
-
target: `${T2000_PACKAGE_ID}::treasury::collect_fee`,
|
|
1471
|
-
typeArguments: [SUPPORTED_ASSETS.USDC.type],
|
|
1472
|
-
arguments: [
|
|
1473
|
-
tx.object(T2000_TREASURY_ID),
|
|
1474
|
-
tx.object(T2000_CONFIG_ID),
|
|
1475
|
-
paymentCoin,
|
|
1476
|
-
tx.pure.u8(OP_CODES[operation])
|
|
1477
|
-
]
|
|
1478
|
-
});
|
|
1479
|
-
}
|
|
1480
|
-
async function reportFee(agentAddress, operation, feeAmount, feeRate, txDigest) {
|
|
1481
|
-
try {
|
|
1482
|
-
await fetch(`${API_BASE_URL}/api/fees`, {
|
|
1483
|
-
method: "POST",
|
|
1484
|
-
headers: { "Content-Type": "application/json" },
|
|
1485
|
-
body: JSON.stringify({
|
|
1486
|
-
agentAddress,
|
|
1487
|
-
operation,
|
|
1488
|
-
feeAmount: feeAmount.toString(),
|
|
1489
|
-
feeRate: feeRate.toString(),
|
|
1490
|
-
txDigest
|
|
1491
|
-
})
|
|
1492
|
-
});
|
|
1493
|
-
} catch {
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1496
|
-
|
|
1497
1449
|
// ../../node_modules/.pnpm/@mysten+bcs@2.0.2/node_modules/@mysten/bcs/dist/uleb.mjs
|
|
1498
1450
|
function ulebEncode(num) {
|
|
1499
1451
|
let bigNum = BigInt(num);
|
|
@@ -5277,9 +5229,6 @@ async function buildSaveTx(client, address, amount, options = {}) {
|
|
|
5277
5229
|
const tx = new Transaction();
|
|
5278
5230
|
tx.setSender(address);
|
|
5279
5231
|
const coinObj = mergeCoins(tx, coins);
|
|
5280
|
-
if (options.collectFee) {
|
|
5281
|
-
addCollectFeeToTx(tx, coinObj, "save");
|
|
5282
|
-
}
|
|
5283
5232
|
const rawAmount = Math.min(Number(stableToRaw(amount, assetInfo.decimals)), Number(totalBalance));
|
|
5284
5233
|
try {
|
|
5285
5234
|
await Ce(tx, assetInfo.type, coinObj, {
|
|
@@ -5350,9 +5299,6 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
|
5350
5299
|
async function addSaveToTx(tx, _client, _address, coin, options = {}) {
|
|
5351
5300
|
const asset = options.asset ?? "USDC";
|
|
5352
5301
|
const assetInfo = resolveAssetInfo(asset);
|
|
5353
|
-
if (options.collectFee) {
|
|
5354
|
-
addCollectFeeToTx(tx, coin, "save");
|
|
5355
|
-
}
|
|
5356
5302
|
try {
|
|
5357
5303
|
await Ce(tx, assetInfo.type, coin, { env: "prod" });
|
|
5358
5304
|
} catch (err) {
|
|
@@ -5383,9 +5329,6 @@ async function buildBorrowTx(client, address, amount, options = {}) {
|
|
|
5383
5329
|
await refreshOracle(tx, client, address, { skipPythUpdate: options.skipPythUpdate });
|
|
5384
5330
|
try {
|
|
5385
5331
|
const borrowedCoin = await Xe(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
5386
|
-
if (options.collectFee) {
|
|
5387
|
-
addCollectFeeToTx(tx, borrowedCoin, "borrow");
|
|
5388
|
-
}
|
|
5389
5332
|
tx.transferObjects([borrowedCoin], address);
|
|
5390
5333
|
} catch (err) {
|
|
5391
5334
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -5393,6 +5336,22 @@ async function buildBorrowTx(client, address, amount, options = {}) {
|
|
|
5393
5336
|
}
|
|
5394
5337
|
return tx;
|
|
5395
5338
|
}
|
|
5339
|
+
async function addBorrowToTx(tx, client, address, amount, options = {}) {
|
|
5340
|
+
if (!amount || amount <= 0 || !Number.isFinite(amount)) {
|
|
5341
|
+
throw new T2000Error("INVALID_AMOUNT", "Borrow amount must be a positive number");
|
|
5342
|
+
}
|
|
5343
|
+
const asset = options.asset ?? "USDC";
|
|
5344
|
+
const assetInfo = resolveAssetInfo(asset);
|
|
5345
|
+
const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
|
|
5346
|
+
await refreshOracle(tx, client, address, { skipPythUpdate: options.skipPythUpdate });
|
|
5347
|
+
try {
|
|
5348
|
+
const borrowedCoin = await Xe(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
5349
|
+
return borrowedCoin;
|
|
5350
|
+
} catch (err) {
|
|
5351
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
5352
|
+
throw new T2000Error("PROTOCOL_UNAVAILABLE", `NAVI borrow failed: ${msg}`);
|
|
5353
|
+
}
|
|
5354
|
+
}
|
|
5396
5355
|
async function buildRepayTx(client, address, amount, options = {}) {
|
|
5397
5356
|
if (!amount || amount <= 0 || !Number.isFinite(amount)) {
|
|
5398
5357
|
throw new T2000Error("INVALID_AMOUNT", "Repay amount must be a positive number");
|
|
@@ -5720,9 +5679,9 @@ var NaviAdapter = class {
|
|
|
5720
5679
|
async getHealth(address) {
|
|
5721
5680
|
return getHealthFactor(this.client, address);
|
|
5722
5681
|
}
|
|
5723
|
-
async buildSaveTx(address, amount, asset
|
|
5682
|
+
async buildSaveTx(address, amount, asset) {
|
|
5724
5683
|
const normalized = normalizeAsset(asset);
|
|
5725
|
-
const tx = await buildSaveTx(this.client, address, amount, {
|
|
5684
|
+
const tx = await buildSaveTx(this.client, address, amount, { asset: normalized });
|
|
5726
5685
|
return { tx };
|
|
5727
5686
|
}
|
|
5728
5687
|
async buildWithdrawTx(address, amount, asset, options) {
|
|
@@ -5760,9 +5719,16 @@ var NaviAdapter = class {
|
|
|
5760
5719
|
skipPythUpdate: options?.skipPythUpdate
|
|
5761
5720
|
});
|
|
5762
5721
|
}
|
|
5763
|
-
async addSaveToTx(tx, address, coin, asset
|
|
5722
|
+
async addSaveToTx(tx, address, coin, asset) {
|
|
5723
|
+
const normalized = normalizeAsset(asset);
|
|
5724
|
+
return addSaveToTx(tx, this.client, address, coin, { asset: normalized });
|
|
5725
|
+
}
|
|
5726
|
+
async addBorrowToTx(tx, address, amount, asset, options) {
|
|
5764
5727
|
const normalized = normalizeAsset(asset);
|
|
5765
|
-
return
|
|
5728
|
+
return addBorrowToTx(tx, this.client, address, amount, {
|
|
5729
|
+
asset: normalized,
|
|
5730
|
+
skipPythUpdate: options?.skipPythUpdate
|
|
5731
|
+
});
|
|
5766
5732
|
}
|
|
5767
5733
|
async addRepayToTx(tx, address, coin, asset, options) {
|
|
5768
5734
|
const normalized = normalizeAsset(asset);
|
|
@@ -6504,7 +6470,6 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
6504
6470
|
);
|
|
6505
6471
|
}
|
|
6506
6472
|
}
|
|
6507
|
-
const fee = calculateFee("save", amount);
|
|
6508
6473
|
const saveAmount = amount;
|
|
6509
6474
|
const adapter = await this.resolveLending(params.protocol, asset, "save");
|
|
6510
6475
|
const canPTB = !!adapter.addSaveToTx;
|
|
@@ -6517,14 +6482,13 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
6517
6482
|
const merged = this._mergeCoinsInTx(tx2, coins);
|
|
6518
6483
|
const rawAmount = BigInt(Math.floor(saveAmount * 10 ** assetInfo.decimals));
|
|
6519
6484
|
const [inputCoin] = tx2.splitCoins(merged, [rawAmount]);
|
|
6520
|
-
await adapter.addSaveToTx(tx2, this._address, inputCoin, asset
|
|
6485
|
+
await adapter.addSaveToTx(tx2, this._address, inputCoin, asset);
|
|
6521
6486
|
return tx2;
|
|
6522
6487
|
}
|
|
6523
|
-
const { tx } = await adapter.buildSaveTx(this._address, saveAmount, asset
|
|
6488
|
+
const { tx } = await adapter.buildSaveTx(this._address, saveAmount, asset);
|
|
6524
6489
|
return tx;
|
|
6525
6490
|
});
|
|
6526
6491
|
const rates = await adapter.getRates(asset);
|
|
6527
|
-
reportFee(this._address, "save", fee.amount, fee.rate, gasResult.digest);
|
|
6528
6492
|
this.emitBalanceChange(asset, saveAmount, "save", gasResult.digest);
|
|
6529
6493
|
let savingsBalance = saveAmount;
|
|
6530
6494
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
@@ -6544,7 +6508,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
6544
6508
|
tx: gasResult.digest,
|
|
6545
6509
|
amount: saveAmount,
|
|
6546
6510
|
apy: rates.saveApy,
|
|
6547
|
-
fee:
|
|
6511
|
+
fee: 0,
|
|
6548
6512
|
gasCost: gasResult.gasCostSui,
|
|
6549
6513
|
savingsBalance
|
|
6550
6514
|
};
|
|
@@ -6807,21 +6771,19 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
6807
6771
|
currentHF: maxResult.currentHF
|
|
6808
6772
|
});
|
|
6809
6773
|
}
|
|
6810
|
-
const fee = calculateFee("borrow", params.amount);
|
|
6811
6774
|
const borrowAmount = params.amount;
|
|
6812
6775
|
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
6813
|
-
const { tx } = await adapter.buildBorrowTx(this._address, borrowAmount, asset
|
|
6776
|
+
const { tx } = await adapter.buildBorrowTx(this._address, borrowAmount, asset);
|
|
6814
6777
|
return tx;
|
|
6815
6778
|
});
|
|
6816
6779
|
const hf = await adapter.getHealth(this._address);
|
|
6817
|
-
reportFee(this._address, "borrow", fee.amount, fee.rate, gasResult.digest);
|
|
6818
6780
|
this.emitBalanceChange(asset, borrowAmount, "borrow", gasResult.digest);
|
|
6819
6781
|
return {
|
|
6820
6782
|
success: true,
|
|
6821
6783
|
tx: gasResult.digest,
|
|
6822
6784
|
amount: borrowAmount,
|
|
6823
6785
|
asset,
|
|
6824
|
-
fee:
|
|
6786
|
+
fee: 0,
|
|
6825
6787
|
healthFactor: hf.healthFactor,
|
|
6826
6788
|
gasCost: gasResult.gasCostSui
|
|
6827
6789
|
};
|
|
@@ -7094,7 +7056,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
7094
7056
|
if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", "No USDC coins after swap");
|
|
7095
7057
|
const merged = this._mergeCoinsInTx(tx, coins);
|
|
7096
7058
|
const [inputCoin] = tx.splitCoins(merged, [gainedRaw]);
|
|
7097
|
-
await adapter.addSaveToTx(tx, this._address, inputCoin, "USDC"
|
|
7059
|
+
await adapter.addSaveToTx(tx, this._address, inputCoin, "USDC");
|
|
7098
7060
|
return tx;
|
|
7099
7061
|
});
|
|
7100
7062
|
depositTx = depositResult.digest;
|
|
@@ -7222,6 +7184,37 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
7222
7184
|
// src/index.ts
|
|
7223
7185
|
init_errors();
|
|
7224
7186
|
|
|
7187
|
+
// src/protocols/protocolFee.ts
|
|
7188
|
+
var FEE_RATES = {
|
|
7189
|
+
save: SAVE_FEE_BPS,
|
|
7190
|
+
borrow: BORROW_FEE_BPS,
|
|
7191
|
+
// Swap uses Cetus's overlay-fee mechanism (taken from output by the aggregator
|
|
7192
|
+
// and transferred to `overlayFee.receiver`). We list the rate here for display
|
|
7193
|
+
// / quote calculations only — `addFeeTransfer` is NOT called for swaps.
|
|
7194
|
+
swap: 10n
|
|
7195
|
+
// 0.1%
|
|
7196
|
+
};
|
|
7197
|
+
function calculateFee(operation, amount) {
|
|
7198
|
+
const bps = FEE_RATES[operation];
|
|
7199
|
+
const feeAmount = amount * Number(bps) / Number(BPS_DENOMINATOR);
|
|
7200
|
+
const rawAmount = usdcToRaw(feeAmount);
|
|
7201
|
+
return {
|
|
7202
|
+
amount: feeAmount,
|
|
7203
|
+
asset: "USDC",
|
|
7204
|
+
rate: Number(bps) / Number(BPS_DENOMINATOR),
|
|
7205
|
+
rawAmount
|
|
7206
|
+
};
|
|
7207
|
+
}
|
|
7208
|
+
function addFeeTransfer(tx, paymentCoin, feeBps, receiver, amount) {
|
|
7209
|
+
if (feeBps <= 0n) return;
|
|
7210
|
+
if (amount <= 0) return;
|
|
7211
|
+
const feeAmount = amount * Number(feeBps) / Number(BPS_DENOMINATOR);
|
|
7212
|
+
const rawFee = usdcToRaw(feeAmount);
|
|
7213
|
+
if (rawFee <= 0n) return;
|
|
7214
|
+
const [feeCoin] = tx.splitCoins(paymentCoin, [tx.pure.u64(rawFee)]);
|
|
7215
|
+
tx.transferObjects([feeCoin], tx.pure.address(receiver));
|
|
7216
|
+
}
|
|
7217
|
+
|
|
7225
7218
|
// src/protocols/financialSummary.ts
|
|
7226
7219
|
var HF_WARN_THRESHOLD = 1.8;
|
|
7227
7220
|
var HF_CRITICAL_THRESHOLD = 1.3;
|
|
@@ -7404,6 +7397,6 @@ init_volo();
|
|
|
7404
7397
|
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
7405
7398
|
*/
|
|
7406
7399
|
|
|
7407
|
-
export { ALL_NAVI_ASSETS, BORROW_FEE_BPS, BPS_DENOMINATOR, CETUS_USDC_SUI_POOL, CLOCK_ID, COIN_REGISTRY, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, ETH_TYPE, GAS_RESERVE_MIN, HF_CRITICAL_THRESHOLD, HF_WARN_THRESHOLD, IKA_TYPE, KNOWN_TARGETS, KeypairSigner, LABEL_PATTERNS, LOFI_TYPE, MANIFEST_TYPE, MIST_PER_SUI, NAVX_TYPE, NaviAdapter, OPERATION_ASSETS, OUTBOUND_OPS, OVERLAY_FEE_RATE, ProtocolRegistry, SAVE_FEE_BPS, STABLE_ASSETS, SUI_DECIMALS, SUI_TYPE, SUPPORTED_ASSETS, SafeguardEnforcer, SafeguardError, T2000, T2000Error, TOKEN_MAP, USDC_DECIMALS, USDC_TYPE, USDE_TYPE, USDSUI_TYPE, USDT_TYPE, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, WAL_TYPE, WBTC_TYPE, ZkLoginSigner,
|
|
7400
|
+
export { ALL_NAVI_ASSETS, BORROW_FEE_BPS, BPS_DENOMINATOR, CETUS_USDC_SUI_POOL, CLOCK_ID, COIN_REGISTRY, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, ETH_TYPE, GAS_RESERVE_MIN, HF_CRITICAL_THRESHOLD, HF_WARN_THRESHOLD, IKA_TYPE, KNOWN_TARGETS, KeypairSigner, LABEL_PATTERNS, LOFI_TYPE, MANIFEST_TYPE, MIST_PER_SUI, NAVX_TYPE, NaviAdapter, OPERATION_ASSETS, OUTBOUND_OPS, OVERLAY_FEE_RATE, ProtocolRegistry, SAVE_FEE_BPS, STABLE_ASSETS, SUI_DECIMALS, SUI_TYPE, SUPPORTED_ASSETS, SafeguardEnforcer, SafeguardError, T2000, T2000Error, T2000_OVERLAY_FEE_WALLET, TOKEN_MAP, USDC_DECIMALS, USDC_TYPE, USDE_TYPE, USDSUI_TYPE, USDT_TYPE, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, WAL_TYPE, WBTC_TYPE, ZkLoginSigner, addFeeTransfer, allDescriptors, assertAllowedAsset, buildStakeVSuiTx, buildSwapTx, buildUnstakeVSuiTx, calculateFee, classifyAction, classifyLabel, classifyTransaction, exportPrivateKey, extractTransferDetails, extractTxCommands, extractTxSender, fallbackLabel, findSwapRoute, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getDecimalsForCoinType, getFinancialSummary, getPendingRewards, getRates, getSwapQuote, getTier, getVoloStats, isAllowedAsset, isSupported, isTier1, isTier2, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, naviDescriptor, normalizeCoinType, parseSuiRpcTx, queryHistory, queryTransaction, rawToStable, rawToUsdc, refineLendingLabel, resolveSymbol, resolveTokenType, saveKey, simulateTransaction, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
|
7408
7401
|
//# sourceMappingURL=index.js.map
|
|
7409
7402
|
//# sourceMappingURL=index.js.map
|