@t2000/sdk 0.21.15 → 0.22.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 +37 -9
- package/dist/adapters/index.cjs +1 -1
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +89 -4
- package/dist/adapters/index.d.ts +89 -4
- package/dist/adapters/index.js +1 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/browser.cjs +791 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.cts +11 -0
- package/dist/browser.d.ts +11 -0
- package/dist/browser.js +38 -23
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +63 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -339
- package/dist/index.d.ts +7 -339
- package/dist/index.js +60 -58
- package/dist/index.js.map +1 -1
- package/dist/token-registry-BBAPkvGS.d.ts +355 -0
- package/dist/token-registry-abuw6uo0.d.cts +355 -0
- package/dist/{index-BwknZes_.d.ts → types-XWEUAS-X.d.cts} +1 -87
- package/dist/{index-HeR6WZTF.d.cts → types-XWEUAS-X.d.ts} +1 -87
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,171 +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 { T as T2000Error, am as SafeguardEnforcer, w as TransactionSigner, Z as ZkLoginProof, s as SupportedAsset } from './token-registry-BBAPkvGS.js';
|
|
5
|
+
export { A as ALL_NAVI_ASSETS, a as AutoTopUpResult, B as BPS_DENOMINATOR, an as CETUS_USDC_SUI_POOL, C as CLOCK_ID, b as COIN_REGISTRY, c as CoinMeta, D as DEFAULT_NETWORK, d as DEFAULT_SAFEGUARD_CONFIG, E as ETH_TYPE, F as FeeOperation, G as GAS_RESERVE_MIN, e as GasExecutionResult, f as GasRequestType, g as GasSponsorResponse, h as GasStatusResponse, I as IKA_TYPE, K as KeypairSigner, L as LOFI_TYPE, M as MANIFEST_TYPE, i as MIST_PER_SUI, N as NAVX_TYPE, O as OUTBOUND_OPS, P as ProtocolFeeInfo, S as STABLE_ASSETS, j as SUI_DECIMALS, k as SUI_TYPE, l as SUPPORTED_ASSETS, m as SafeguardConfig, n as SafeguardError, o as SafeguardErrorDetails, p as SafeguardRule, q as SimulationResult, r as StableAsset, t as T2000ErrorCode, u as T2000ErrorData, v as TOKEN_MAP, x as TxMetadata, U as USDC_DECIMALS, y as USDC_TYPE, z as USDE_TYPE, H as USDSUI_TYPE, J as USDT_TYPE, W as WAL_TYPE, Q as WBTC_TYPE, R as ZkLoginSigner, V as addCollectFeeToTx, X as calculateFee, Y as executeAutoTopUp, _ as executeWithGas, $ as formatAssetAmount, a0 as formatSui, a1 as formatUsd, a2 as getDecimals, a3 as getDecimalsForCoinType, a4 as getGasStatus, a5 as getTier, a6 as isSupported, a7 as isTier1, a8 as isTier2, a9 as mapMoveAbortCode, aa as mapWalletError, ab as mistToSui, ac as rawToStable, ad as rawToUsdc, ae as resolveSymbol, af as resolveTokenType, ag as shouldAutoTopUp, ao as simulateTransaction, ah as stableToRaw, ai as suiToMist, ap as throwIfSimulationFailed, aj as truncateAddress, ak as usdcToRaw, al as validateAddress } from './token-registry-BBAPkvGS.js';
|
|
4
6
|
import { L as LendingAdapter, a as LendingRates } from './descriptors-Be4FAgN5.js';
|
|
5
7
|
export { A as AdapterCapability, b as AdapterPositions, c as AdapterTxResult, H as HealthInfo, P as ProtocolDescriptor, d as allDescriptors, n as naviDescriptor } from './descriptors-Be4FAgN5.js';
|
|
6
|
-
import {
|
|
7
|
-
export { A as AssetRates,
|
|
8
|
-
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
8
|
+
import { j as T2000Options, P as PayOptions, d as PayResult, k as StakeVSuiResult, U as UnstakeVSuiResult, l as SwapResult, m as SwapQuoteResult, i as SendResult, B as BalanceResponse, T as TransactionRecord, D as DepositInfo, S as SaveResult, W as WithdrawResult, c as MaxWithdrawResult, a as BorrowResult, h as RepayResult, M as MaxBorrowResult, H as HealthFactorResult, e as PendingReward, C as ClaimRewardsResult, g as PositionsResult, R as RatesResult, E as EarningsResult, F as FundStatusResult } from './types-XWEUAS-X.js';
|
|
9
|
+
export { A as AssetRates, G as GasMethod, b as GasReserve, f as PositionEntry } from './types-XWEUAS-X.js';
|
|
9
10
|
import { RouterDataV3 } from '@cetusprotocol/aggregator-sdk';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* Abstract signing interface that decouples the SDK from any specific
|
|
13
|
-
* key management strategy (Ed25519 keypair, zkLogin, multisig, …).
|
|
14
|
-
*/
|
|
15
|
-
interface TransactionSigner {
|
|
16
|
-
getAddress(): string;
|
|
17
|
-
signTransaction(txBytes: Uint8Array): Promise<{
|
|
18
|
-
signature: string;
|
|
19
|
-
}>;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface ZkLoginProof {
|
|
23
|
-
proofPoints: {
|
|
24
|
-
a: string[];
|
|
25
|
-
b: string[][];
|
|
26
|
-
c: string[];
|
|
27
|
-
};
|
|
28
|
-
issBase64Details: {
|
|
29
|
-
indexMod4: number;
|
|
30
|
-
value: string;
|
|
31
|
-
};
|
|
32
|
-
headerBase64: string;
|
|
33
|
-
addressSeed: string;
|
|
34
|
-
}
|
|
35
|
-
declare class ZkLoginSigner implements TransactionSigner {
|
|
36
|
-
private readonly ephemeralKeypair;
|
|
37
|
-
private readonly zkProof;
|
|
38
|
-
private readonly userAddress;
|
|
39
|
-
private readonly maxEpoch;
|
|
40
|
-
constructor(ephemeralKeypair: Ed25519Keypair, zkProof: ZkLoginProof, userAddress: string, maxEpoch: number);
|
|
41
|
-
getAddress(): string;
|
|
42
|
-
signTransaction(txBytes: Uint8Array): Promise<{
|
|
43
|
-
signature: string;
|
|
44
|
-
}>;
|
|
45
|
-
isExpired(currentEpoch: number): boolean;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
type T2000ErrorCode = 'INSUFFICIENT_BALANCE' | 'INSUFFICIENT_GAS' | 'INVALID_ADDRESS' | 'INVALID_AMOUNT' | 'WALLET_NOT_FOUND' | 'WALLET_LOCKED' | 'WALLET_EXISTS' | 'SPONSOR_FAILED' | 'SPONSOR_RATE_LIMITED' | 'USDC_SPONSOR_FAILED' | 'USDC_SPONSOR_RATE_LIMITED' | 'GAS_STATION_UNAVAILABLE' | 'GAS_FEE_EXCEEDED' | 'SIMULATION_FAILED' | 'TRANSACTION_FAILED' | 'ASSET_NOT_SUPPORTED' | 'HEALTH_FACTOR_TOO_LOW' | 'WITHDRAW_WOULD_LIQUIDATE' | 'WITHDRAW_FAILED' | 'NO_COLLATERAL' | 'PROTOCOL_PAUSED' | 'PROTOCOL_UNAVAILABLE' | 'RPC_ERROR' | 'RPC_UNREACHABLE' | 'SPONSOR_UNAVAILABLE' | 'AUTO_TOPUP_FAILED' | 'PRICE_EXCEEDS_LIMIT' | 'UNSUPPORTED_NETWORK' | 'PAYMENT_EXPIRED' | 'DUPLICATE_PAYMENT' | 'FACILITATOR_REJECTION' | 'CONTACT_NOT_FOUND' | 'INVALID_CONTACT_NAME' | 'FACILITATOR_TIMEOUT' | 'SAFEGUARD_BLOCKED' | 'SWAP_NO_ROUTE' | 'SWAP_FAILED' | 'UNKNOWN';
|
|
49
|
-
interface T2000ErrorData {
|
|
50
|
-
reason?: string;
|
|
51
|
-
[key: string]: unknown;
|
|
52
|
-
}
|
|
53
|
-
declare class T2000Error extends Error {
|
|
54
|
-
readonly code: T2000ErrorCode;
|
|
55
|
-
readonly data?: T2000ErrorData;
|
|
56
|
-
readonly retryable: boolean;
|
|
57
|
-
constructor(code: T2000ErrorCode, message: string, data?: T2000ErrorData, retryable?: boolean);
|
|
58
|
-
toJSON(): {
|
|
59
|
-
retryable: boolean;
|
|
60
|
-
data?: T2000ErrorData | undefined;
|
|
61
|
-
error: T2000ErrorCode;
|
|
62
|
-
message: string;
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
declare function mapWalletError(error: unknown): T2000Error;
|
|
66
|
-
declare function mapMoveAbortCode(code: number): string;
|
|
67
|
-
|
|
68
|
-
declare const MIST_PER_SUI = 1000000000n;
|
|
69
|
-
declare const SUI_DECIMALS = 9;
|
|
70
|
-
declare const USDC_DECIMALS = 6;
|
|
71
|
-
declare const BPS_DENOMINATOR = 10000n;
|
|
72
|
-
declare const CLOCK_ID = "0x6";
|
|
73
|
-
declare const SUPPORTED_ASSETS: {
|
|
74
|
-
readonly USDC: {
|
|
75
|
-
readonly type: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
|
|
76
|
-
readonly decimals: 6;
|
|
77
|
-
readonly symbol: "USDC";
|
|
78
|
-
readonly displayName: "USDC";
|
|
79
|
-
};
|
|
80
|
-
readonly USDT: {
|
|
81
|
-
readonly type: "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT";
|
|
82
|
-
readonly decimals: 6;
|
|
83
|
-
readonly symbol: "USDT";
|
|
84
|
-
readonly displayName: "suiUSDT";
|
|
85
|
-
};
|
|
86
|
-
readonly USDe: {
|
|
87
|
-
readonly type: "0x41d587e5336f1c86cad50d38a7136db99333bb9bda91cea4ba69115defeb1402::sui_usde::SUI_USDE";
|
|
88
|
-
readonly decimals: 6;
|
|
89
|
-
readonly symbol: "USDe";
|
|
90
|
-
readonly displayName: "suiUSDe";
|
|
91
|
-
};
|
|
92
|
-
readonly USDsui: {
|
|
93
|
-
readonly type: "0x44f838219cf67b058f3b37907b655f226153c18e33dfcd0da559a844fea9b1c1::usdsui::USDSUI";
|
|
94
|
-
readonly decimals: 6;
|
|
95
|
-
readonly symbol: "USDsui";
|
|
96
|
-
readonly displayName: "USDsui";
|
|
97
|
-
};
|
|
98
|
-
readonly SUI: {
|
|
99
|
-
readonly type: "0x2::sui::SUI";
|
|
100
|
-
readonly decimals: 9;
|
|
101
|
-
readonly symbol: "SUI";
|
|
102
|
-
readonly displayName: "SUI";
|
|
103
|
-
};
|
|
104
|
-
readonly WAL: {
|
|
105
|
-
readonly type: "0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL";
|
|
106
|
-
readonly decimals: 9;
|
|
107
|
-
readonly symbol: "WAL";
|
|
108
|
-
readonly displayName: "WAL";
|
|
109
|
-
};
|
|
110
|
-
readonly ETH: {
|
|
111
|
-
readonly type: "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH";
|
|
112
|
-
readonly decimals: 8;
|
|
113
|
-
readonly symbol: "ETH";
|
|
114
|
-
readonly displayName: "suiETH";
|
|
115
|
-
};
|
|
116
|
-
readonly NAVX: {
|
|
117
|
-
readonly type: "0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX";
|
|
118
|
-
readonly decimals: 9;
|
|
119
|
-
readonly symbol: "NAVX";
|
|
120
|
-
readonly displayName: "NAVX";
|
|
121
|
-
};
|
|
122
|
-
readonly GOLD: {
|
|
123
|
-
readonly type: "0x9d297676e7a4b771ab023291377b2adfaa4938fb9080b8d12430e4b108b836a9::xaum::XAUM";
|
|
124
|
-
readonly decimals: 6;
|
|
125
|
-
readonly symbol: "GOLD";
|
|
126
|
-
readonly displayName: "XAUM";
|
|
127
|
-
};
|
|
128
|
-
};
|
|
129
|
-
type SupportedAsset = keyof typeof SUPPORTED_ASSETS;
|
|
130
|
-
type StableAsset = 'USDC' | 'USDT' | 'USDe' | 'USDsui';
|
|
131
|
-
declare const STABLE_ASSETS: readonly StableAsset[];
|
|
132
|
-
declare const ALL_NAVI_ASSETS: readonly SupportedAsset[];
|
|
133
|
-
declare const DEFAULT_NETWORK: "mainnet";
|
|
134
|
-
declare const CETUS_USDC_SUI_POOL = "0x51e883ba7c0b566a26cbc8a94cd33eb0abd418a77cc1e60ad22fd9b1f29cd2ab";
|
|
135
|
-
declare const GAS_RESERVE_MIN = 0.05;
|
|
136
|
-
|
|
137
|
-
interface SafeguardConfig {
|
|
138
|
-
locked: boolean;
|
|
139
|
-
maxPerTx: number;
|
|
140
|
-
maxDailySend: number;
|
|
141
|
-
dailyUsed: number;
|
|
142
|
-
dailyResetDate: string;
|
|
143
|
-
maxLeverage?: number;
|
|
144
|
-
maxPositionSize?: number;
|
|
145
|
-
}
|
|
146
|
-
interface TxMetadata {
|
|
147
|
-
operation: 'send' | 'save' | 'withdraw' | 'borrow' | 'repay' | 'pay';
|
|
148
|
-
amount?: number;
|
|
149
|
-
}
|
|
150
|
-
declare const OUTBOUND_OPS: Set<"save" | "borrow" | "send" | "withdraw" | "repay" | "pay">;
|
|
151
|
-
declare const DEFAULT_SAFEGUARD_CONFIG: SafeguardConfig;
|
|
152
|
-
|
|
153
|
-
declare class SafeguardEnforcer {
|
|
154
|
-
private config;
|
|
155
|
-
private readonly configPath;
|
|
156
|
-
constructor(configDir?: string);
|
|
157
|
-
load(): void;
|
|
158
|
-
assertNotLocked(): void;
|
|
159
|
-
check(metadata: TxMetadata): void;
|
|
160
|
-
recordUsage(amount: number): void;
|
|
161
|
-
lock(): void;
|
|
162
|
-
unlock(): void;
|
|
163
|
-
set(key: string, value: unknown): void;
|
|
164
|
-
getConfig(): SafeguardConfig;
|
|
165
|
-
isConfigured(): boolean;
|
|
166
|
-
private resetDailyIfNewDay;
|
|
167
|
-
private save;
|
|
168
|
-
}
|
|
11
|
+
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
12
|
+
export { NaviAdapter, ProtocolRegistry } from './adapters/index.js';
|
|
169
13
|
|
|
170
14
|
interface Contact {
|
|
171
15
|
name: string;
|
|
@@ -349,31 +193,6 @@ declare class T2000 extends EventEmitter<T2000Events> {
|
|
|
349
193
|
private emitBalanceChange;
|
|
350
194
|
}
|
|
351
195
|
|
|
352
|
-
declare class KeypairSigner implements TransactionSigner {
|
|
353
|
-
private readonly keypair;
|
|
354
|
-
constructor(keypair: Ed25519Keypair);
|
|
355
|
-
getAddress(): string;
|
|
356
|
-
signTransaction(txBytes: Uint8Array): Promise<{
|
|
357
|
-
signature: string;
|
|
358
|
-
}>;
|
|
359
|
-
/** Access the underlying keypair for APIs that still require it directly. */
|
|
360
|
-
getKeypair(): Ed25519Keypair;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
declare function validateAddress(address: string): string;
|
|
364
|
-
declare function truncateAddress(address: string): string;
|
|
365
|
-
|
|
366
|
-
declare function mistToSui(mist: bigint): number;
|
|
367
|
-
declare function suiToMist(sui: number): bigint;
|
|
368
|
-
declare function usdcToRaw(amount: number): bigint;
|
|
369
|
-
declare function rawToUsdc(raw: bigint): number;
|
|
370
|
-
declare function stableToRaw(amount: number, decimals: number): bigint;
|
|
371
|
-
declare function rawToStable(raw: bigint, decimals: number): number;
|
|
372
|
-
declare function getDecimals(asset: SupportedAsset): number;
|
|
373
|
-
declare function formatUsd(amount: number): string;
|
|
374
|
-
declare function formatSui(amount: number): string;
|
|
375
|
-
declare function formatAssetAmount(amount: number, asset: string): string;
|
|
376
|
-
|
|
377
196
|
declare function generateKeypair(): Ed25519Keypair;
|
|
378
197
|
declare function keypairFromPrivateKey(privateKey: string): Ed25519Keypair;
|
|
379
198
|
declare function saveKey(keypair: Ed25519Keypair, passphrase: string, keyPath?: string): Promise<string>;
|
|
@@ -384,34 +203,6 @@ declare function getAddress(keypair: Ed25519Keypair): string;
|
|
|
384
203
|
|
|
385
204
|
declare function solveHashcash(challenge: string): string;
|
|
386
205
|
|
|
387
|
-
type FeeOperation = 'save' | 'borrow';
|
|
388
|
-
interface ProtocolFeeInfo {
|
|
389
|
-
amount: number;
|
|
390
|
-
asset: string;
|
|
391
|
-
rate: number;
|
|
392
|
-
rawAmount: bigint;
|
|
393
|
-
}
|
|
394
|
-
declare function calculateFee(operation: FeeOperation, amount: number): ProtocolFeeInfo;
|
|
395
|
-
/**
|
|
396
|
-
* Add on-chain fee collection to an existing PTB via t2000::treasury::collect_fee().
|
|
397
|
-
* The Move function splits the fee from the payment coin and stores it in the
|
|
398
|
-
* Treasury's internal Balance<T>. Atomic — reverts with the operation if it fails.
|
|
399
|
-
*/
|
|
400
|
-
declare function addCollectFeeToTx(tx: Transaction, paymentCoin: TransactionObjectArgument, operation: FeeOperation): void;
|
|
401
|
-
|
|
402
|
-
interface SimulationResult {
|
|
403
|
-
success: boolean;
|
|
404
|
-
gasEstimateSui: number;
|
|
405
|
-
error?: {
|
|
406
|
-
moveAbortCode?: number;
|
|
407
|
-
moveModule?: string;
|
|
408
|
-
reason: string;
|
|
409
|
-
rawError: string;
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
declare function simulateTransaction(client: SuiJsonRpcClient, tx: Transaction, sender: string): Promise<SimulationResult>;
|
|
413
|
-
declare function throwIfSimulationFailed(sim: SimulationResult): void;
|
|
414
|
-
|
|
415
206
|
declare function getRates(client: SuiJsonRpcClient): Promise<RatesResult>;
|
|
416
207
|
|
|
417
208
|
declare function getSwapQuote(params: {
|
|
@@ -422,58 +213,6 @@ declare function getSwapQuote(params: {
|
|
|
422
213
|
byAmountIn?: boolean;
|
|
423
214
|
}): Promise<SwapQuoteResult>;
|
|
424
215
|
|
|
425
|
-
/**
|
|
426
|
-
* Unified token registry — single source of truth for coin types, decimals, and symbols.
|
|
427
|
-
*
|
|
428
|
-
* ZERO heavy dependencies. Safe to import from any context (server, browser, Edge).
|
|
429
|
-
* All other token maps (KNOWN_COINS, DEC_MAP, TOKEN_DECIMALS, etc.) should be replaced
|
|
430
|
-
* with imports from this file.
|
|
431
|
-
*
|
|
432
|
-
* To add a new token: add ONE entry to COIN_REGISTRY below. Everything else derives from it.
|
|
433
|
-
*/
|
|
434
|
-
interface CoinMeta {
|
|
435
|
-
type: string;
|
|
436
|
-
decimals: number;
|
|
437
|
-
symbol: string;
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Canonical coin registry. Merges NAVI lending assets + swap-supported tokens.
|
|
441
|
-
* Key = user-friendly name (used in swap_execute, CLI, prompts).
|
|
442
|
-
*/
|
|
443
|
-
declare const COIN_REGISTRY: Record<string, CoinMeta>;
|
|
444
|
-
/**
|
|
445
|
-
* Get decimals for any coin type. Checks full type match, then suffix match, then defaults to 9.
|
|
446
|
-
* Handles address normalization differences (leading zeros, casing).
|
|
447
|
-
*/
|
|
448
|
-
declare function getDecimalsForCoinType(coinType: string): number;
|
|
449
|
-
/**
|
|
450
|
-
* Resolve a full coin type to a user-friendly symbol.
|
|
451
|
-
* Returns the last `::` segment if not in the registry.
|
|
452
|
-
*/
|
|
453
|
-
declare function resolveSymbol(coinType: string): string;
|
|
454
|
-
/**
|
|
455
|
-
* Name → type map for swap resolution. Derived from COIN_REGISTRY.
|
|
456
|
-
* Contains BOTH original-case and UPPERCASE keys for case-insensitive lookup.
|
|
457
|
-
* Backward-compatible with the original TOKEN_MAP in cetus-swap.ts.
|
|
458
|
-
*/
|
|
459
|
-
declare const TOKEN_MAP: Record<string, string>;
|
|
460
|
-
/**
|
|
461
|
-
* Resolve a user-friendly token name to its full coin type.
|
|
462
|
-
* Returns the input unchanged if already a full coin type (contains "::").
|
|
463
|
-
* Case-insensitive: 'usde', 'USDe', 'USDE' all resolve correctly.
|
|
464
|
-
*/
|
|
465
|
-
declare function resolveTokenType(nameOrType: string): string | null;
|
|
466
|
-
/** Common type constants for direct import (avoid hardcoding strings). */
|
|
467
|
-
declare const SUI_TYPE: string;
|
|
468
|
-
declare const USDC_TYPE: string;
|
|
469
|
-
declare const USDT_TYPE: string;
|
|
470
|
-
declare const USDSUI_TYPE: string;
|
|
471
|
-
declare const USDE_TYPE: string;
|
|
472
|
-
declare const ETH_TYPE: string;
|
|
473
|
-
declare const WBTC_TYPE: string;
|
|
474
|
-
declare const WAL_TYPE: string;
|
|
475
|
-
declare const NAVX_TYPE: string;
|
|
476
|
-
|
|
477
216
|
/**
|
|
478
217
|
* Cetus Aggregator V3 SDK wrapper — the ONLY file that imports @cetusprotocol/aggregator-sdk.
|
|
479
218
|
* Documented CLAUDE.md exception: multi-DEX routing cannot be feasibly replaced by thin tx builders.
|
|
@@ -536,75 +275,4 @@ declare function buildStakeVSuiTx(_client: SuiJsonRpcClient, address: string, am
|
|
|
536
275
|
*/
|
|
537
276
|
declare function buildUnstakeVSuiTx(client: SuiJsonRpcClient, address: string, amountMist: bigint | 'all'): Promise<Transaction>;
|
|
538
277
|
|
|
539
|
-
type
|
|
540
|
-
interface SafeguardErrorDetails {
|
|
541
|
-
attempted?: number;
|
|
542
|
-
limit?: number;
|
|
543
|
-
current?: number;
|
|
544
|
-
}
|
|
545
|
-
declare class SafeguardError extends T2000Error {
|
|
546
|
-
readonly rule: SafeguardRule;
|
|
547
|
-
readonly details: SafeguardErrorDetails;
|
|
548
|
-
constructor(rule: SafeguardRule, details: SafeguardErrorDetails, message?: string);
|
|
549
|
-
toJSON(): {
|
|
550
|
-
error: "SAFEGUARD_BLOCKED";
|
|
551
|
-
message: string;
|
|
552
|
-
retryable: boolean;
|
|
553
|
-
data: {
|
|
554
|
-
attempted?: number;
|
|
555
|
-
limit?: number;
|
|
556
|
-
current?: number;
|
|
557
|
-
rule: SafeguardRule;
|
|
558
|
-
};
|
|
559
|
-
};
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
interface GasExecutionResult {
|
|
563
|
-
digest: string;
|
|
564
|
-
effects: unknown;
|
|
565
|
-
balanceChanges?: unknown[];
|
|
566
|
-
gasMethod: GasMethod;
|
|
567
|
-
gasCostSui: number;
|
|
568
|
-
/** Pre-TX SUI balance in MIST — used internally for proactive gas maintenance. */
|
|
569
|
-
preTxSuiMist?: bigint;
|
|
570
|
-
}
|
|
571
|
-
/**
|
|
572
|
-
* Gas resolution chain:
|
|
573
|
-
* 1. Self-funded (agent has enough SUI)
|
|
574
|
-
* 2. Auto-topup (swap USDC→SUI, then self-fund)
|
|
575
|
-
* 3. Gas Station sponsored (fallback)
|
|
576
|
-
* 4. Fail with INSUFFICIENT_GAS
|
|
577
|
-
*
|
|
578
|
-
* After every successful transaction, proactively tops up SUI if it
|
|
579
|
-
* dropped below threshold — so the user never hits a "no gas" wall.
|
|
580
|
-
*/
|
|
581
|
-
declare function executeWithGas(client: SuiJsonRpcClient, signer: TransactionSigner, buildTx: () => Transaction | Promise<Transaction>, options?: {
|
|
582
|
-
metadata?: TxMetadata;
|
|
583
|
-
enforcer?: SafeguardEnforcer;
|
|
584
|
-
}): Promise<GasExecutionResult>;
|
|
585
|
-
|
|
586
|
-
interface AutoTopUpResult {
|
|
587
|
-
success: boolean;
|
|
588
|
-
tx: string;
|
|
589
|
-
usdcSpent: number;
|
|
590
|
-
suiReceived: number;
|
|
591
|
-
}
|
|
592
|
-
declare function shouldAutoTopUp(client: SuiJsonRpcClient, address: string): Promise<boolean>;
|
|
593
|
-
declare function executeAutoTopUp(_client: SuiJsonRpcClient, _signer: TransactionSigner): Promise<AutoTopUpResult>;
|
|
594
|
-
|
|
595
|
-
type GasRequestType = 'bootstrap' | 'auto-topup' | 'fallback';
|
|
596
|
-
interface GasSponsorResponse {
|
|
597
|
-
txBytes: string;
|
|
598
|
-
sponsorSignature: string;
|
|
599
|
-
gasEstimateUsd: number;
|
|
600
|
-
type: GasRequestType;
|
|
601
|
-
}
|
|
602
|
-
interface GasStatusResponse {
|
|
603
|
-
circuitBreaker: boolean;
|
|
604
|
-
suiPrice: number;
|
|
605
|
-
bootstrapUsed?: number;
|
|
606
|
-
bootstrapRemaining?: number;
|
|
607
|
-
}
|
|
608
|
-
declare function getGasStatus(address?: string): Promise<GasStatusResponse>;
|
|
609
|
-
|
|
610
|
-
export { ALL_NAVI_ASSETS, type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CETUS_USDC_SUI_POOL, CLOCK_ID, COIN_REGISTRY, ClaimRewardsResult, type CoinMeta, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DepositInfo, ETH_TYPE, EarningsResult, type FeeOperation, FundStatusResult, GAS_RESERVE_MIN, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, KeypairSigner, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, NAVX_TYPE, OUTBOUND_OPS, PayOptions, PayResult, PendingReward, PositionsResult, type ProtocolFeeInfo, RatesResult, RepayResult, STABLE_ASSETS, SUI_DECIMALS, SUI_TYPE, SUPPORTED_ASSETS, type SafeguardConfig, SafeguardEnforcer, SafeguardError, type SafeguardErrorDetails, type SafeguardRule, SaveResult, SendResult, type SimulationResult, type StableAsset, StakeVSuiResult, type SupportedAsset, SwapQuoteResult, SwapResult, type SwapRouteResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TOKEN_MAP, TransactionRecord, type TransactionSigner, type TxMetadata, USDC_DECIMALS, USDC_TYPE, USDE_TYPE, USDSUI_TYPE, USDT_TYPE, UnstakeVSuiResult, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, type VoloStats, WAL_TYPE, WBTC_TYPE, WithdrawResult, type ZkLoginProof, ZkLoginSigner, addCollectFeeToTx, buildStakeVSuiTx, buildSwapTx, buildUnstakeVSuiTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, findSwapRoute, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getDecimalsForCoinType, getGasStatus, getRates, getSwapQuote, getVoloStats, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, resolveSymbol, resolveTokenType, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
|
278
|
+
export { BalanceResponse, BorrowResult, ClaimRewardsResult, ContactManager, DepositInfo, EarningsResult, FundStatusResult, HealthFactorResult, LendingAdapter, LendingRates, MaxBorrowResult, MaxWithdrawResult, PayOptions, PayResult, PendingReward, PositionsResult, RatesResult, RepayResult, SafeguardEnforcer, SaveResult, SendResult, StakeVSuiResult, SupportedAsset, SwapQuoteResult, SwapResult, type SwapRouteResult, T2000, T2000Error, T2000Options, TransactionRecord, TransactionSigner, UnstakeVSuiResult, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, type VoloStats, WithdrawResult, ZkLoginProof, buildStakeVSuiTx, buildSwapTx, buildUnstakeVSuiTx, exportPrivateKey, findSwapRoute, generateKeypair, getAddress, getRates, getSwapQuote, getVoloStats, keypairFromPrivateKey, loadKey, saveKey, solveHashcash, walletExists };
|
package/dist/index.js
CHANGED
|
@@ -112,6 +112,21 @@ var init_errors = __esm({
|
|
|
112
112
|
});
|
|
113
113
|
|
|
114
114
|
// src/token-registry.ts
|
|
115
|
+
function isTier1(coinType) {
|
|
116
|
+
const meta = BY_TYPE.get(coinType);
|
|
117
|
+
return meta?.tier === 1;
|
|
118
|
+
}
|
|
119
|
+
function isTier2(coinType) {
|
|
120
|
+
const meta = BY_TYPE.get(coinType);
|
|
121
|
+
return meta?.tier === 2;
|
|
122
|
+
}
|
|
123
|
+
function isSupported(coinType) {
|
|
124
|
+
const meta = BY_TYPE.get(coinType);
|
|
125
|
+
return meta?.tier !== void 0;
|
|
126
|
+
}
|
|
127
|
+
function getTier(coinType) {
|
|
128
|
+
return BY_TYPE.get(coinType)?.tier;
|
|
129
|
+
}
|
|
115
130
|
function getDecimalsForCoinType(coinType) {
|
|
116
131
|
const direct = BY_TYPE.get(coinType);
|
|
117
132
|
if (direct) return direct.decimals;
|
|
@@ -140,33 +155,30 @@ function resolveTokenType(nameOrType) {
|
|
|
140
155
|
if (nameOrType.includes("::")) return nameOrType;
|
|
141
156
|
return TOKEN_MAP[nameOrType] ?? TOKEN_MAP[nameOrType.toUpperCase()] ?? null;
|
|
142
157
|
}
|
|
143
|
-
var COIN_REGISTRY, BY_TYPE, TOKEN_MAP, SUI_TYPE, USDC_TYPE, USDT_TYPE, USDSUI_TYPE, USDE_TYPE, ETH_TYPE, WBTC_TYPE, WAL_TYPE, NAVX_TYPE;
|
|
158
|
+
var COIN_REGISTRY, BY_TYPE, TOKEN_MAP, SUI_TYPE, USDC_TYPE, USDT_TYPE, USDSUI_TYPE, USDE_TYPE, ETH_TYPE, WBTC_TYPE, WAL_TYPE, NAVX_TYPE, IKA_TYPE, LOFI_TYPE, MANIFEST_TYPE;
|
|
144
159
|
var init_token_registry = __esm({
|
|
145
160
|
"src/token-registry.ts"() {
|
|
146
161
|
COIN_REGISTRY = {
|
|
147
|
-
|
|
148
|
-
USDC: { type: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC", decimals: 6, symbol: "USDC" },
|
|
162
|
+
// ── Tier 1 — Financial layer ──────────────────────────────────────────
|
|
163
|
+
USDC: { type: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC", decimals: 6, symbol: "USDC", tier: 1 },
|
|
164
|
+
// ── Tier 2 — Swap assets (13 tokens) ──────────────────────────────────
|
|
165
|
+
SUI: { type: "0x2::sui::SUI", decimals: 9, symbol: "SUI", tier: 2 },
|
|
166
|
+
wBTC: { type: "0x0041f9f9344cac094454cd574e333c4fdb132d7bcc9379bcd4aab485b2a63942::wbtc::WBTC", decimals: 8, symbol: "wBTC", tier: 2 },
|
|
167
|
+
ETH: { type: "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH", decimals: 8, symbol: "ETH", tier: 2 },
|
|
168
|
+
GOLD: { type: "0x9d297676e7a4b771ab023291377b2adfaa4938fb9080b8d12430e4b108b836a9::xaum::XAUM", decimals: 6, symbol: "GOLD", tier: 2 },
|
|
169
|
+
DEEP: { type: "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP", decimals: 6, symbol: "DEEP", tier: 2 },
|
|
170
|
+
WAL: { type: "0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL", decimals: 9, symbol: "WAL", tier: 2 },
|
|
171
|
+
NS: { type: "0x5145494a5f5100e645e4b0aa950fa6b68f614e8c59e17bc5ded3495123a79178::ns::NS", decimals: 6, symbol: "NS", tier: 2 },
|
|
172
|
+
IKA: { type: "0x7262fb2f7a3a14c888c438a3cd9b912469a58cf60f367352c46584262e8299aa::ika::IKA", decimals: 9, symbol: "IKA", tier: 2 },
|
|
173
|
+
CETUS: { type: "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS", decimals: 9, symbol: "CETUS", tier: 2 },
|
|
174
|
+
NAVX: { type: "0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX", decimals: 9, symbol: "NAVX", tier: 2 },
|
|
175
|
+
vSUI: { type: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", decimals: 9, symbol: "vSUI", tier: 2 },
|
|
176
|
+
LOFI: { type: "0xf22da9a24ad027cccb5f2d496cbe91de953d363513db08a3a734d361c7c17503::LOFI::LOFI", decimals: 9, symbol: "LOFI", tier: 2 },
|
|
177
|
+
MANIFEST: { type: "0xc466c28d87b3d5cd34f3d5c088751532d71a38d93a8aae4551dd56272cfb4355::manifest::MANIFEST", decimals: 9, symbol: "MANIFEST", tier: 2 },
|
|
178
|
+
// ── Legacy — no tier, kept for display accuracy on existing positions ──
|
|
149
179
|
USDT: { type: "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT", decimals: 6, symbol: "USDT" },
|
|
150
180
|
USDe: { type: "0x41d587e5336f1c86cad50d38a7136db99333bb9bda91cea4ba69115defeb1402::sui_usde::SUI_USDE", decimals: 6, symbol: "USDe" },
|
|
151
|
-
USDSUI: { type: "0x44f838219cf67b058f3b37907b655f226153c18e33dfcd0da559a844fea9b1c1::usdsui::USDSUI", decimals: 6, symbol: "USDsui" }
|
|
152
|
-
WAL: { type: "0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL", decimals: 9, symbol: "WAL" },
|
|
153
|
-
ETH: { type: "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH", decimals: 8, symbol: "ETH" },
|
|
154
|
-
wBTC: { type: "0x0041f9f9344cac094454cd574e333c4fdb132d7bcc9379bcd4aab485b2a63942::wbtc::WBTC", decimals: 8, symbol: "wBTC" },
|
|
155
|
-
NAVX: { type: "0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX", decimals: 9, symbol: "NAVX" },
|
|
156
|
-
CETUS: { type: "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS", decimals: 9, symbol: "CETUS" },
|
|
157
|
-
DEEP: { type: "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP", decimals: 6, symbol: "DEEP" },
|
|
158
|
-
NS: { type: "0x5145494a5f5100e645e4b0aa950fa6b68f614e8c59e17bc5ded3495123a79178::ns::NS", decimals: 6, symbol: "NS" },
|
|
159
|
-
GOLD: { type: "0x9d297676e7a4b771ab023291377b2adfaa4938fb9080b8d12430e4b108b836a9::xaum::XAUM", decimals: 6, symbol: "GOLD" },
|
|
160
|
-
MANIFEST: { type: "0xc466c28d87b3d5cd34f3d5c088751532d71a38d93a8aae4551dd56272cfb4355::manifest::MANIFEST", decimals: 9, symbol: "MANIFEST" },
|
|
161
|
-
vSUI: { type: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", decimals: 9, symbol: "vSUI" },
|
|
162
|
-
haSUI: { type: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e136a8bc::hasui::HASUI", decimals: 9, symbol: "haSUI" },
|
|
163
|
-
afSUI: { type: "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI", decimals: 9, symbol: "afSUI" },
|
|
164
|
-
FDUSD: { type: "0xf16e6b723f242ec745dfd7634ad072c42d5c1d9ac9d62a39c381303eaa57693a::fdusd::FDUSD", decimals: 6, symbol: "FDUSD" },
|
|
165
|
-
AUSD: { type: "0x2053d08c1e2bd02791056171aab0fd12bd7cd7efad2ab8f6b9c8902f14df2ff2::ausd::AUSD", decimals: 6, symbol: "AUSD" },
|
|
166
|
-
BUCK: { type: "0xce7ff77a83ea0cb6fd39bd8748e2ec89a3f41e8efdc3f4eb123e0ca37b184db2::buck::BUCK", decimals: 9, symbol: "BUCK" },
|
|
167
|
-
BLUB: { type: "0xfa7ac3951fdca12c1b6d18eb19e1aa2fbc31e4d45773c8e45b4ded3ef8d83f8a::blub::BLUB", decimals: 9, symbol: "BLUB" },
|
|
168
|
-
SCA: { type: "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA", decimals: 9, symbol: "SCA" },
|
|
169
|
-
TURBOS: { type: "0x5d1f47ea69bb0de31c313d7acf89b890dbb8991ea8e03c6c355171f84bb1ba4a::turbos::TURBOS", decimals: 9, symbol: "TURBOS" }
|
|
181
|
+
USDSUI: { type: "0x44f838219cf67b058f3b37907b655f226153c18e33dfcd0da559a844fea9b1c1::usdsui::USDSUI", decimals: 6, symbol: "USDsui" }
|
|
170
182
|
};
|
|
171
183
|
BY_TYPE = /* @__PURE__ */ new Map();
|
|
172
184
|
for (const meta of Object.values(COIN_REGISTRY)) {
|
|
@@ -189,6 +201,9 @@ var init_token_registry = __esm({
|
|
|
189
201
|
WBTC_TYPE = COIN_REGISTRY.wBTC.type;
|
|
190
202
|
WAL_TYPE = COIN_REGISTRY.WAL.type;
|
|
191
203
|
NAVX_TYPE = COIN_REGISTRY.NAVX.type;
|
|
204
|
+
IKA_TYPE = COIN_REGISTRY.IKA.type;
|
|
205
|
+
LOFI_TYPE = COIN_REGISTRY.LOFI.type;
|
|
206
|
+
MANIFEST_TYPE = COIN_REGISTRY.MANIFEST.type;
|
|
192
207
|
}
|
|
193
208
|
});
|
|
194
209
|
|
|
@@ -310,7 +325,9 @@ function getClient(walletAddress) {
|
|
|
310
325
|
if (clientInstance) return clientInstance;
|
|
311
326
|
clientInstance = new AggregatorClient({
|
|
312
327
|
signer: walletAddress,
|
|
313
|
-
env: Env.Mainnet
|
|
328
|
+
env: Env.Mainnet,
|
|
329
|
+
overlayFeeRate: OVERLAY_FEE_RATE,
|
|
330
|
+
overlayFeeReceiver: OVERLAY_FEE_RECEIVER
|
|
314
331
|
});
|
|
315
332
|
return clientInstance;
|
|
316
333
|
}
|
|
@@ -367,10 +384,12 @@ async function simulateSwap(params) {
|
|
|
367
384
|
return { success: false, error: err instanceof Error ? err.message : String(err) };
|
|
368
385
|
}
|
|
369
386
|
}
|
|
370
|
-
var clientInstance;
|
|
387
|
+
var OVERLAY_FEE_RATE, OVERLAY_FEE_RECEIVER, clientInstance;
|
|
371
388
|
var init_cetus_swap = __esm({
|
|
372
389
|
"src/protocols/cetus-swap.ts"() {
|
|
373
390
|
init_token_registry();
|
|
391
|
+
OVERLAY_FEE_RATE = 1e-3;
|
|
392
|
+
OVERLAY_FEE_RECEIVER = process.env.T2000_TREASURY_ADDRESS ?? "0x3bb501b8300125dca59019247941a42af6b292a150ce3cfcce9449456be2ec91";
|
|
374
393
|
clientInstance = null;
|
|
375
394
|
}
|
|
376
395
|
});
|
|
@@ -442,7 +461,7 @@ var SUPPORTED_ASSETS = {
|
|
|
442
461
|
displayName: "XAUM"
|
|
443
462
|
}
|
|
444
463
|
};
|
|
445
|
-
var STABLE_ASSETS = ["USDC"
|
|
464
|
+
var STABLE_ASSETS = ["USDC"];
|
|
446
465
|
var ALL_NAVI_ASSETS = Object.keys(SUPPORTED_ASSETS);
|
|
447
466
|
var T2000_PACKAGE_ID = process.env.T2000_PACKAGE_ID ?? "0xab92e9f1fe549ad3d6a52924a73181b45791e76120b975138fac9ec9b75db9f3";
|
|
448
467
|
var T2000_CONFIG_ID = process.env.T2000_CONFIG_ID ?? "0x408add9aa9322f93cfd87523d8f603006eb8713894f4c460283c58a6888dae8a";
|
|
@@ -2586,37 +2605,26 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
2586
2605
|
// -- Savings --
|
|
2587
2606
|
async save(params) {
|
|
2588
2607
|
this.enforcer.assertNotLocked();
|
|
2589
|
-
|
|
2608
|
+
if (params.asset && params.asset !== "USDC") {
|
|
2609
|
+
throw new T2000Error("INVALID_ASSET", "Only USDC deposits are supported. Swap to USDC first.");
|
|
2610
|
+
}
|
|
2611
|
+
const asset = "USDC";
|
|
2590
2612
|
const assetInfo = SUPPORTED_ASSETS[asset];
|
|
2591
|
-
if (!assetInfo) throw new T2000Error("ASSET_NOT_SUPPORTED", `Unsupported asset: ${asset}`);
|
|
2592
|
-
const isStable = STABLE_ASSETS.includes(asset);
|
|
2593
2613
|
let amount;
|
|
2594
2614
|
if (params.amount === "all") {
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
amount = (bal.available ?? 0) - 1;
|
|
2598
|
-
} else if (asset === "SUI") {
|
|
2599
|
-
const suiBal = await this.client.getBalance({ owner: this._address, coinType: assetInfo.type });
|
|
2600
|
-
const suiAmount = Number(suiBal.totalBalance) / 10 ** assetInfo.decimals;
|
|
2601
|
-
amount = suiAmount - 0.15;
|
|
2602
|
-
} else {
|
|
2603
|
-
const coins = await this._fetchCoins(assetInfo.type);
|
|
2604
|
-
const totalRaw = coins.reduce((sum, c) => sum + BigInt(c.balance), 0n);
|
|
2605
|
-
amount = Number(totalRaw) / 10 ** assetInfo.decimals;
|
|
2606
|
-
}
|
|
2615
|
+
const bal = await queryBalance(this.client, this._address);
|
|
2616
|
+
amount = (bal.available ?? 0) - 1;
|
|
2607
2617
|
if (amount <= 0) {
|
|
2608
|
-
throw new T2000Error("INSUFFICIENT_BALANCE", `No
|
|
2618
|
+
throw new T2000Error("INSUFFICIENT_BALANCE", `No USDC available to save`, {
|
|
2609
2619
|
reason: "insufficient_balance",
|
|
2610
2620
|
asset
|
|
2611
2621
|
});
|
|
2612
2622
|
}
|
|
2613
2623
|
} else {
|
|
2614
2624
|
amount = params.amount;
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
throw new T2000Error("INSUFFICIENT_BALANCE", `Insufficient balance. Available: $${(bal.available ?? 0).toFixed(2)}, requested: $${amount.toFixed(2)}`);
|
|
2619
|
-
}
|
|
2625
|
+
const bal = await queryBalance(this.client, this._address);
|
|
2626
|
+
if (amount > (bal.available ?? 0)) {
|
|
2627
|
+
throw new T2000Error("INSUFFICIENT_BALANCE", `Insufficient balance. Available: $${(bal.available ?? 0).toFixed(2)}, requested: $${amount.toFixed(2)}`);
|
|
2620
2628
|
}
|
|
2621
2629
|
}
|
|
2622
2630
|
const fee = calculateFee("save", amount);
|
|
@@ -2627,17 +2635,11 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
2627
2635
|
if (canPTB) {
|
|
2628
2636
|
const tx2 = new Transaction();
|
|
2629
2637
|
tx2.setSender(this._address);
|
|
2630
|
-
|
|
2631
|
-
if (
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
const coins = await this._fetchCoins(assetInfo.type);
|
|
2636
|
-
if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", `No ${asset} coins found`);
|
|
2637
|
-
const merged = this._mergeCoinsInTx(tx2, coins);
|
|
2638
|
-
const rawAmount = BigInt(Math.floor(saveAmount * 10 ** assetInfo.decimals));
|
|
2639
|
-
[inputCoin] = tx2.splitCoins(merged, [rawAmount]);
|
|
2640
|
-
}
|
|
2638
|
+
const coins = await this._fetchCoins(assetInfo.type);
|
|
2639
|
+
if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", "No USDC coins found");
|
|
2640
|
+
const merged = this._mergeCoinsInTx(tx2, coins);
|
|
2641
|
+
const rawAmount = BigInt(Math.floor(saveAmount * 10 ** assetInfo.decimals));
|
|
2642
|
+
const [inputCoin] = tx2.splitCoins(merged, [rawAmount]);
|
|
2641
2643
|
await adapter.addSaveToTx(tx2, this._address, inputCoin, asset, { collectFee: true });
|
|
2642
2644
|
return tx2;
|
|
2643
2645
|
}
|
|
@@ -3348,6 +3350,6 @@ init_cetus_swap();
|
|
|
3348
3350
|
init_token_registry();
|
|
3349
3351
|
init_volo();
|
|
3350
3352
|
|
|
3351
|
-
export { ALL_NAVI_ASSETS, BPS_DENOMINATOR, CETUS_USDC_SUI_POOL, CLOCK_ID, COIN_REGISTRY, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, ETH_TYPE, GAS_RESERVE_MIN, KeypairSigner, MIST_PER_SUI, NAVX_TYPE, NaviAdapter, OUTBOUND_OPS, ProtocolRegistry, 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, addCollectFeeToTx, allDescriptors, buildStakeVSuiTx, buildSwapTx, buildUnstakeVSuiTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, findSwapRoute, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getDecimalsForCoinType, getGasStatus, getRates, getSwapQuote, getVoloStats, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, naviDescriptor, rawToStable, rawToUsdc, resolveSymbol, resolveTokenType, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
|
3353
|
+
export { ALL_NAVI_ASSETS, BPS_DENOMINATOR, CETUS_USDC_SUI_POOL, CLOCK_ID, COIN_REGISTRY, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, ETH_TYPE, GAS_RESERVE_MIN, IKA_TYPE, KeypairSigner, LOFI_TYPE, MANIFEST_TYPE, MIST_PER_SUI, NAVX_TYPE, NaviAdapter, OUTBOUND_OPS, ProtocolRegistry, 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, addCollectFeeToTx, allDescriptors, buildStakeVSuiTx, buildSwapTx, buildUnstakeVSuiTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, findSwapRoute, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getDecimalsForCoinType, getGasStatus, getRates, getSwapQuote, getTier, getVoloStats, isSupported, isTier1, isTier2, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, naviDescriptor, rawToStable, rawToUsdc, resolveSymbol, resolveTokenType, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
|
3352
3354
|
//# sourceMappingURL=index.js.map
|
|
3353
3355
|
//# sourceMappingURL=index.js.map
|