@t2000/sdk 0.21.14 → 0.21.16

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.
@@ -0,0 +1,341 @@
1
+ import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
2
+ import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
3
+ import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
4
+ import { G as GasMethod } from './types-XWEUAS-X.js';
5
+
6
+ /**
7
+ * Abstract signing interface that decouples the SDK from any specific
8
+ * key management strategy (Ed25519 keypair, zkLogin, multisig, …).
9
+ */
10
+ interface TransactionSigner {
11
+ getAddress(): string;
12
+ signTransaction(txBytes: Uint8Array): Promise<{
13
+ signature: string;
14
+ }>;
15
+ }
16
+
17
+ declare class KeypairSigner implements TransactionSigner {
18
+ private readonly keypair;
19
+ constructor(keypair: Ed25519Keypair);
20
+ getAddress(): string;
21
+ signTransaction(txBytes: Uint8Array): Promise<{
22
+ signature: string;
23
+ }>;
24
+ /** Access the underlying keypair for APIs that still require it directly. */
25
+ getKeypair(): Ed25519Keypair;
26
+ }
27
+
28
+ interface ZkLoginProof {
29
+ proofPoints: {
30
+ a: string[];
31
+ b: string[][];
32
+ c: string[];
33
+ };
34
+ issBase64Details: {
35
+ indexMod4: number;
36
+ value: string;
37
+ };
38
+ headerBase64: string;
39
+ addressSeed: string;
40
+ }
41
+ declare class ZkLoginSigner implements TransactionSigner {
42
+ private readonly ephemeralKeypair;
43
+ private readonly zkProof;
44
+ private readonly userAddress;
45
+ private readonly maxEpoch;
46
+ constructor(ephemeralKeypair: Ed25519Keypair, zkProof: ZkLoginProof, userAddress: string, maxEpoch: number);
47
+ getAddress(): string;
48
+ signTransaction(txBytes: Uint8Array): Promise<{
49
+ signature: string;
50
+ }>;
51
+ isExpired(currentEpoch: number): boolean;
52
+ }
53
+
54
+ 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';
55
+ interface T2000ErrorData {
56
+ reason?: string;
57
+ [key: string]: unknown;
58
+ }
59
+ declare class T2000Error extends Error {
60
+ readonly code: T2000ErrorCode;
61
+ readonly data?: T2000ErrorData;
62
+ readonly retryable: boolean;
63
+ constructor(code: T2000ErrorCode, message: string, data?: T2000ErrorData, retryable?: boolean);
64
+ toJSON(): {
65
+ retryable: boolean;
66
+ data?: T2000ErrorData | undefined;
67
+ error: T2000ErrorCode;
68
+ message: string;
69
+ };
70
+ }
71
+ declare function mapWalletError(error: unknown): T2000Error;
72
+ declare function mapMoveAbortCode(code: number): string;
73
+
74
+ interface SafeguardConfig {
75
+ locked: boolean;
76
+ maxPerTx: number;
77
+ maxDailySend: number;
78
+ dailyUsed: number;
79
+ dailyResetDate: string;
80
+ maxLeverage?: number;
81
+ maxPositionSize?: number;
82
+ }
83
+ interface TxMetadata {
84
+ operation: 'send' | 'save' | 'withdraw' | 'borrow' | 'repay' | 'pay';
85
+ amount?: number;
86
+ }
87
+ declare const OUTBOUND_OPS: Set<"save" | "borrow" | "send" | "withdraw" | "repay" | "pay">;
88
+ declare const DEFAULT_SAFEGUARD_CONFIG: SafeguardConfig;
89
+
90
+ declare class SafeguardEnforcer {
91
+ private config;
92
+ private readonly configPath;
93
+ constructor(configDir?: string);
94
+ load(): void;
95
+ assertNotLocked(): void;
96
+ check(metadata: TxMetadata): void;
97
+ recordUsage(amount: number): void;
98
+ lock(): void;
99
+ unlock(): void;
100
+ set(key: string, value: unknown): void;
101
+ getConfig(): SafeguardConfig;
102
+ isConfigured(): boolean;
103
+ private resetDailyIfNewDay;
104
+ private save;
105
+ }
106
+
107
+ interface GasExecutionResult {
108
+ digest: string;
109
+ effects: unknown;
110
+ balanceChanges?: unknown[];
111
+ gasMethod: GasMethod;
112
+ gasCostSui: number;
113
+ /** Pre-TX SUI balance in MIST — used internally for proactive gas maintenance. */
114
+ preTxSuiMist?: bigint;
115
+ }
116
+ /**
117
+ * Gas resolution chain:
118
+ * 1. Self-funded (agent has enough SUI)
119
+ * 2. Auto-topup (swap USDC→SUI, then self-fund)
120
+ * 3. Gas Station sponsored (fallback)
121
+ * 4. Fail with INSUFFICIENT_GAS
122
+ *
123
+ * After every successful transaction, proactively tops up SUI if it
124
+ * dropped below threshold — so the user never hits a "no gas" wall.
125
+ */
126
+ declare function executeWithGas(client: SuiJsonRpcClient, signer: TransactionSigner, buildTx: () => Transaction | Promise<Transaction>, options?: {
127
+ metadata?: TxMetadata;
128
+ enforcer?: SafeguardEnforcer;
129
+ }): Promise<GasExecutionResult>;
130
+
131
+ interface AutoTopUpResult {
132
+ success: boolean;
133
+ tx: string;
134
+ usdcSpent: number;
135
+ suiReceived: number;
136
+ }
137
+ declare function shouldAutoTopUp(client: SuiJsonRpcClient, address: string): Promise<boolean>;
138
+ declare function executeAutoTopUp(_client: SuiJsonRpcClient, _signer: TransactionSigner): Promise<AutoTopUpResult>;
139
+
140
+ type GasRequestType = 'bootstrap' | 'auto-topup' | 'fallback';
141
+ interface GasSponsorResponse {
142
+ txBytes: string;
143
+ sponsorSignature: string;
144
+ gasEstimateUsd: number;
145
+ type: GasRequestType;
146
+ }
147
+ interface GasStatusResponse {
148
+ circuitBreaker: boolean;
149
+ suiPrice: number;
150
+ bootstrapUsed?: number;
151
+ bootstrapRemaining?: number;
152
+ }
153
+ declare function getGasStatus(address?: string): Promise<GasStatusResponse>;
154
+
155
+ declare const MIST_PER_SUI = 1000000000n;
156
+ declare const SUI_DECIMALS = 9;
157
+ declare const USDC_DECIMALS = 6;
158
+ declare const BPS_DENOMINATOR = 10000n;
159
+ declare const CLOCK_ID = "0x6";
160
+ declare const SUPPORTED_ASSETS: {
161
+ readonly USDC: {
162
+ readonly type: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
163
+ readonly decimals: 6;
164
+ readonly symbol: "USDC";
165
+ readonly displayName: "USDC";
166
+ };
167
+ readonly USDT: {
168
+ readonly type: "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT";
169
+ readonly decimals: 6;
170
+ readonly symbol: "USDT";
171
+ readonly displayName: "suiUSDT";
172
+ };
173
+ readonly USDe: {
174
+ readonly type: "0x41d587e5336f1c86cad50d38a7136db99333bb9bda91cea4ba69115defeb1402::sui_usde::SUI_USDE";
175
+ readonly decimals: 6;
176
+ readonly symbol: "USDe";
177
+ readonly displayName: "suiUSDe";
178
+ };
179
+ readonly USDsui: {
180
+ readonly type: "0x44f838219cf67b058f3b37907b655f226153c18e33dfcd0da559a844fea9b1c1::usdsui::USDSUI";
181
+ readonly decimals: 6;
182
+ readonly symbol: "USDsui";
183
+ readonly displayName: "USDsui";
184
+ };
185
+ readonly SUI: {
186
+ readonly type: "0x2::sui::SUI";
187
+ readonly decimals: 9;
188
+ readonly symbol: "SUI";
189
+ readonly displayName: "SUI";
190
+ };
191
+ readonly WAL: {
192
+ readonly type: "0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL";
193
+ readonly decimals: 9;
194
+ readonly symbol: "WAL";
195
+ readonly displayName: "WAL";
196
+ };
197
+ readonly ETH: {
198
+ readonly type: "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH";
199
+ readonly decimals: 8;
200
+ readonly symbol: "ETH";
201
+ readonly displayName: "suiETH";
202
+ };
203
+ readonly NAVX: {
204
+ readonly type: "0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX";
205
+ readonly decimals: 9;
206
+ readonly symbol: "NAVX";
207
+ readonly displayName: "NAVX";
208
+ };
209
+ readonly GOLD: {
210
+ readonly type: "0x9d297676e7a4b771ab023291377b2adfaa4938fb9080b8d12430e4b108b836a9::xaum::XAUM";
211
+ readonly decimals: 6;
212
+ readonly symbol: "GOLD";
213
+ readonly displayName: "XAUM";
214
+ };
215
+ };
216
+ type SupportedAsset = keyof typeof SUPPORTED_ASSETS;
217
+ type StableAsset = 'USDC' | 'USDT' | 'USDe' | 'USDsui';
218
+ declare const STABLE_ASSETS: readonly StableAsset[];
219
+ declare const ALL_NAVI_ASSETS: readonly SupportedAsset[];
220
+ declare const DEFAULT_NETWORK: "mainnet";
221
+ declare const CETUS_USDC_SUI_POOL = "0x51e883ba7c0b566a26cbc8a94cd33eb0abd418a77cc1e60ad22fd9b1f29cd2ab";
222
+ declare const GAS_RESERVE_MIN = 0.05;
223
+
224
+ declare function validateAddress(address: string): string;
225
+ declare function truncateAddress(address: string): string;
226
+
227
+ declare function mistToSui(mist: bigint): number;
228
+ declare function suiToMist(sui: number): bigint;
229
+ declare function usdcToRaw(amount: number): bigint;
230
+ declare function rawToUsdc(raw: bigint): number;
231
+ declare function stableToRaw(amount: number, decimals: number): bigint;
232
+ declare function rawToStable(raw: bigint, decimals: number): number;
233
+ declare function getDecimals(asset: SupportedAsset): number;
234
+ declare function formatUsd(amount: number): string;
235
+ declare function formatSui(amount: number): string;
236
+ declare function formatAssetAmount(amount: number, asset: string): string;
237
+
238
+ interface SimulationResult {
239
+ success: boolean;
240
+ gasEstimateSui: number;
241
+ error?: {
242
+ moveAbortCode?: number;
243
+ moveModule?: string;
244
+ reason: string;
245
+ rawError: string;
246
+ };
247
+ }
248
+ declare function simulateTransaction(client: SuiJsonRpcClient, tx: Transaction, sender: string): Promise<SimulationResult>;
249
+ declare function throwIfSimulationFailed(sim: SimulationResult): void;
250
+
251
+ type FeeOperation = 'save' | 'borrow';
252
+ interface ProtocolFeeInfo {
253
+ amount: number;
254
+ asset: string;
255
+ rate: number;
256
+ rawAmount: bigint;
257
+ }
258
+ declare function calculateFee(operation: FeeOperation, amount: number): ProtocolFeeInfo;
259
+ /**
260
+ * Add on-chain fee collection to an existing PTB via t2000::treasury::collect_fee().
261
+ * The Move function splits the fee from the payment coin and stores it in the
262
+ * Treasury's internal Balance<T>. Atomic — reverts with the operation if it fails.
263
+ */
264
+ declare function addCollectFeeToTx(tx: Transaction, paymentCoin: TransactionObjectArgument, operation: FeeOperation): void;
265
+
266
+ type SafeguardRule = 'locked' | 'maxPerTx' | 'maxDailySend';
267
+ interface SafeguardErrorDetails {
268
+ attempted?: number;
269
+ limit?: number;
270
+ current?: number;
271
+ }
272
+ declare class SafeguardError extends T2000Error {
273
+ readonly rule: SafeguardRule;
274
+ readonly details: SafeguardErrorDetails;
275
+ constructor(rule: SafeguardRule, details: SafeguardErrorDetails, message?: string);
276
+ toJSON(): {
277
+ error: "SAFEGUARD_BLOCKED";
278
+ message: string;
279
+ retryable: boolean;
280
+ data: {
281
+ attempted?: number;
282
+ limit?: number;
283
+ current?: number;
284
+ rule: SafeguardRule;
285
+ };
286
+ };
287
+ }
288
+
289
+ /**
290
+ * Unified token registry — single source of truth for coin types, decimals, and symbols.
291
+ *
292
+ * ZERO heavy dependencies. Safe to import from any context (server, browser, Edge).
293
+ * All other token maps (KNOWN_COINS, DEC_MAP, TOKEN_DECIMALS, etc.) should be replaced
294
+ * with imports from this file.
295
+ *
296
+ * To add a new token: add ONE entry to COIN_REGISTRY below. Everything else derives from it.
297
+ */
298
+ interface CoinMeta {
299
+ type: string;
300
+ decimals: number;
301
+ symbol: string;
302
+ }
303
+ /**
304
+ * Canonical coin registry. Merges NAVI lending assets + swap-supported tokens.
305
+ * Key = user-friendly name (used in swap_execute, CLI, prompts).
306
+ */
307
+ declare const COIN_REGISTRY: Record<string, CoinMeta>;
308
+ /**
309
+ * Get decimals for any coin type. Checks full type match, then suffix match, then defaults to 9.
310
+ * Handles address normalization differences (leading zeros, casing).
311
+ */
312
+ declare function getDecimalsForCoinType(coinType: string): number;
313
+ /**
314
+ * Resolve a full coin type to a user-friendly symbol.
315
+ * Returns the last `::` segment if not in the registry.
316
+ */
317
+ declare function resolveSymbol(coinType: string): string;
318
+ /**
319
+ * Name → type map for swap resolution. Derived from COIN_REGISTRY.
320
+ * Contains BOTH original-case and UPPERCASE keys for case-insensitive lookup.
321
+ * Backward-compatible with the original TOKEN_MAP in cetus-swap.ts.
322
+ */
323
+ declare const TOKEN_MAP: Record<string, string>;
324
+ /**
325
+ * Resolve a user-friendly token name to its full coin type.
326
+ * Returns the input unchanged if already a full coin type (contains "::").
327
+ * Case-insensitive: 'usde', 'USDe', 'USDE' all resolve correctly.
328
+ */
329
+ declare function resolveTokenType(nameOrType: string): string | null;
330
+ /** Common type constants for direct import (avoid hardcoding strings). */
331
+ declare const SUI_TYPE: string;
332
+ declare const USDC_TYPE: string;
333
+ declare const USDT_TYPE: string;
334
+ declare const USDSUI_TYPE: string;
335
+ declare const USDE_TYPE: string;
336
+ declare const ETH_TYPE: string;
337
+ declare const WBTC_TYPE: string;
338
+ declare const WAL_TYPE: string;
339
+ declare const NAVX_TYPE: string;
340
+
341
+ export { getDecimals as $, ALL_NAVI_ASSETS as A, BPS_DENOMINATOR as B, CLOCK_ID as C, DEFAULT_NETWORK as D, ETH_TYPE as E, type FeeOperation as F, GAS_RESERVE_MIN as G, USDT_TYPE as H, WBTC_TYPE as I, ZkLoginSigner as J, KeypairSigner as K, addCollectFeeToTx as L, MIST_PER_SUI as M, NAVX_TYPE as N, OUTBOUND_OPS as O, type ProtocolFeeInfo as P, calculateFee as Q, executeAutoTopUp as R, STABLE_ASSETS as S, T2000Error as T, USDC_DECIMALS as U, executeWithGas as V, WAL_TYPE as W, formatAssetAmount as X, formatSui as Y, type ZkLoginProof as Z, formatUsd as _, type AutoTopUpResult as a, getDecimalsForCoinType as a0, getGasStatus as a1, mapMoveAbortCode as a2, mapWalletError as a3, mistToSui as a4, rawToStable as a5, rawToUsdc as a6, resolveSymbol as a7, resolveTokenType as a8, shouldAutoTopUp as a9, stableToRaw as aa, suiToMist as ab, truncateAddress as ac, usdcToRaw as ad, validateAddress as ae, SafeguardEnforcer as af, CETUS_USDC_SUI_POOL as ag, simulateTransaction as ah, throwIfSimulationFailed as ai, COIN_REGISTRY as b, type CoinMeta as c, DEFAULT_SAFEGUARD_CONFIG as d, type GasExecutionResult as e, type GasRequestType as f, type GasSponsorResponse as g, type GasStatusResponse as h, SUI_DECIMALS as i, SUI_TYPE as j, SUPPORTED_ASSETS as k, type SafeguardConfig as l, SafeguardError as m, type SafeguardErrorDetails as n, type SafeguardRule as o, type SimulationResult as p, type StableAsset as q, type SupportedAsset as r, type T2000ErrorCode as s, type T2000ErrorData as t, TOKEN_MAP as u, type TransactionSigner as v, type TxMetadata as w, USDC_TYPE as x, USDE_TYPE as y, USDSUI_TYPE as z };
@@ -0,0 +1,341 @@
1
+ import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
2
+ import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
3
+ import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
4
+ import { G as GasMethod } from './types-XWEUAS-X.cjs';
5
+
6
+ /**
7
+ * Abstract signing interface that decouples the SDK from any specific
8
+ * key management strategy (Ed25519 keypair, zkLogin, multisig, …).
9
+ */
10
+ interface TransactionSigner {
11
+ getAddress(): string;
12
+ signTransaction(txBytes: Uint8Array): Promise<{
13
+ signature: string;
14
+ }>;
15
+ }
16
+
17
+ declare class KeypairSigner implements TransactionSigner {
18
+ private readonly keypair;
19
+ constructor(keypair: Ed25519Keypair);
20
+ getAddress(): string;
21
+ signTransaction(txBytes: Uint8Array): Promise<{
22
+ signature: string;
23
+ }>;
24
+ /** Access the underlying keypair for APIs that still require it directly. */
25
+ getKeypair(): Ed25519Keypair;
26
+ }
27
+
28
+ interface ZkLoginProof {
29
+ proofPoints: {
30
+ a: string[];
31
+ b: string[][];
32
+ c: string[];
33
+ };
34
+ issBase64Details: {
35
+ indexMod4: number;
36
+ value: string;
37
+ };
38
+ headerBase64: string;
39
+ addressSeed: string;
40
+ }
41
+ declare class ZkLoginSigner implements TransactionSigner {
42
+ private readonly ephemeralKeypair;
43
+ private readonly zkProof;
44
+ private readonly userAddress;
45
+ private readonly maxEpoch;
46
+ constructor(ephemeralKeypair: Ed25519Keypair, zkProof: ZkLoginProof, userAddress: string, maxEpoch: number);
47
+ getAddress(): string;
48
+ signTransaction(txBytes: Uint8Array): Promise<{
49
+ signature: string;
50
+ }>;
51
+ isExpired(currentEpoch: number): boolean;
52
+ }
53
+
54
+ 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';
55
+ interface T2000ErrorData {
56
+ reason?: string;
57
+ [key: string]: unknown;
58
+ }
59
+ declare class T2000Error extends Error {
60
+ readonly code: T2000ErrorCode;
61
+ readonly data?: T2000ErrorData;
62
+ readonly retryable: boolean;
63
+ constructor(code: T2000ErrorCode, message: string, data?: T2000ErrorData, retryable?: boolean);
64
+ toJSON(): {
65
+ retryable: boolean;
66
+ data?: T2000ErrorData | undefined;
67
+ error: T2000ErrorCode;
68
+ message: string;
69
+ };
70
+ }
71
+ declare function mapWalletError(error: unknown): T2000Error;
72
+ declare function mapMoveAbortCode(code: number): string;
73
+
74
+ interface SafeguardConfig {
75
+ locked: boolean;
76
+ maxPerTx: number;
77
+ maxDailySend: number;
78
+ dailyUsed: number;
79
+ dailyResetDate: string;
80
+ maxLeverage?: number;
81
+ maxPositionSize?: number;
82
+ }
83
+ interface TxMetadata {
84
+ operation: 'send' | 'save' | 'withdraw' | 'borrow' | 'repay' | 'pay';
85
+ amount?: number;
86
+ }
87
+ declare const OUTBOUND_OPS: Set<"save" | "borrow" | "send" | "withdraw" | "repay" | "pay">;
88
+ declare const DEFAULT_SAFEGUARD_CONFIG: SafeguardConfig;
89
+
90
+ declare class SafeguardEnforcer {
91
+ private config;
92
+ private readonly configPath;
93
+ constructor(configDir?: string);
94
+ load(): void;
95
+ assertNotLocked(): void;
96
+ check(metadata: TxMetadata): void;
97
+ recordUsage(amount: number): void;
98
+ lock(): void;
99
+ unlock(): void;
100
+ set(key: string, value: unknown): void;
101
+ getConfig(): SafeguardConfig;
102
+ isConfigured(): boolean;
103
+ private resetDailyIfNewDay;
104
+ private save;
105
+ }
106
+
107
+ interface GasExecutionResult {
108
+ digest: string;
109
+ effects: unknown;
110
+ balanceChanges?: unknown[];
111
+ gasMethod: GasMethod;
112
+ gasCostSui: number;
113
+ /** Pre-TX SUI balance in MIST — used internally for proactive gas maintenance. */
114
+ preTxSuiMist?: bigint;
115
+ }
116
+ /**
117
+ * Gas resolution chain:
118
+ * 1. Self-funded (agent has enough SUI)
119
+ * 2. Auto-topup (swap USDC→SUI, then self-fund)
120
+ * 3. Gas Station sponsored (fallback)
121
+ * 4. Fail with INSUFFICIENT_GAS
122
+ *
123
+ * After every successful transaction, proactively tops up SUI if it
124
+ * dropped below threshold — so the user never hits a "no gas" wall.
125
+ */
126
+ declare function executeWithGas(client: SuiJsonRpcClient, signer: TransactionSigner, buildTx: () => Transaction | Promise<Transaction>, options?: {
127
+ metadata?: TxMetadata;
128
+ enforcer?: SafeguardEnforcer;
129
+ }): Promise<GasExecutionResult>;
130
+
131
+ interface AutoTopUpResult {
132
+ success: boolean;
133
+ tx: string;
134
+ usdcSpent: number;
135
+ suiReceived: number;
136
+ }
137
+ declare function shouldAutoTopUp(client: SuiJsonRpcClient, address: string): Promise<boolean>;
138
+ declare function executeAutoTopUp(_client: SuiJsonRpcClient, _signer: TransactionSigner): Promise<AutoTopUpResult>;
139
+
140
+ type GasRequestType = 'bootstrap' | 'auto-topup' | 'fallback';
141
+ interface GasSponsorResponse {
142
+ txBytes: string;
143
+ sponsorSignature: string;
144
+ gasEstimateUsd: number;
145
+ type: GasRequestType;
146
+ }
147
+ interface GasStatusResponse {
148
+ circuitBreaker: boolean;
149
+ suiPrice: number;
150
+ bootstrapUsed?: number;
151
+ bootstrapRemaining?: number;
152
+ }
153
+ declare function getGasStatus(address?: string): Promise<GasStatusResponse>;
154
+
155
+ declare const MIST_PER_SUI = 1000000000n;
156
+ declare const SUI_DECIMALS = 9;
157
+ declare const USDC_DECIMALS = 6;
158
+ declare const BPS_DENOMINATOR = 10000n;
159
+ declare const CLOCK_ID = "0x6";
160
+ declare const SUPPORTED_ASSETS: {
161
+ readonly USDC: {
162
+ readonly type: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
163
+ readonly decimals: 6;
164
+ readonly symbol: "USDC";
165
+ readonly displayName: "USDC";
166
+ };
167
+ readonly USDT: {
168
+ readonly type: "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT";
169
+ readonly decimals: 6;
170
+ readonly symbol: "USDT";
171
+ readonly displayName: "suiUSDT";
172
+ };
173
+ readonly USDe: {
174
+ readonly type: "0x41d587e5336f1c86cad50d38a7136db99333bb9bda91cea4ba69115defeb1402::sui_usde::SUI_USDE";
175
+ readonly decimals: 6;
176
+ readonly symbol: "USDe";
177
+ readonly displayName: "suiUSDe";
178
+ };
179
+ readonly USDsui: {
180
+ readonly type: "0x44f838219cf67b058f3b37907b655f226153c18e33dfcd0da559a844fea9b1c1::usdsui::USDSUI";
181
+ readonly decimals: 6;
182
+ readonly symbol: "USDsui";
183
+ readonly displayName: "USDsui";
184
+ };
185
+ readonly SUI: {
186
+ readonly type: "0x2::sui::SUI";
187
+ readonly decimals: 9;
188
+ readonly symbol: "SUI";
189
+ readonly displayName: "SUI";
190
+ };
191
+ readonly WAL: {
192
+ readonly type: "0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL";
193
+ readonly decimals: 9;
194
+ readonly symbol: "WAL";
195
+ readonly displayName: "WAL";
196
+ };
197
+ readonly ETH: {
198
+ readonly type: "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH";
199
+ readonly decimals: 8;
200
+ readonly symbol: "ETH";
201
+ readonly displayName: "suiETH";
202
+ };
203
+ readonly NAVX: {
204
+ readonly type: "0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX";
205
+ readonly decimals: 9;
206
+ readonly symbol: "NAVX";
207
+ readonly displayName: "NAVX";
208
+ };
209
+ readonly GOLD: {
210
+ readonly type: "0x9d297676e7a4b771ab023291377b2adfaa4938fb9080b8d12430e4b108b836a9::xaum::XAUM";
211
+ readonly decimals: 6;
212
+ readonly symbol: "GOLD";
213
+ readonly displayName: "XAUM";
214
+ };
215
+ };
216
+ type SupportedAsset = keyof typeof SUPPORTED_ASSETS;
217
+ type StableAsset = 'USDC' | 'USDT' | 'USDe' | 'USDsui';
218
+ declare const STABLE_ASSETS: readonly StableAsset[];
219
+ declare const ALL_NAVI_ASSETS: readonly SupportedAsset[];
220
+ declare const DEFAULT_NETWORK: "mainnet";
221
+ declare const CETUS_USDC_SUI_POOL = "0x51e883ba7c0b566a26cbc8a94cd33eb0abd418a77cc1e60ad22fd9b1f29cd2ab";
222
+ declare const GAS_RESERVE_MIN = 0.05;
223
+
224
+ declare function validateAddress(address: string): string;
225
+ declare function truncateAddress(address: string): string;
226
+
227
+ declare function mistToSui(mist: bigint): number;
228
+ declare function suiToMist(sui: number): bigint;
229
+ declare function usdcToRaw(amount: number): bigint;
230
+ declare function rawToUsdc(raw: bigint): number;
231
+ declare function stableToRaw(amount: number, decimals: number): bigint;
232
+ declare function rawToStable(raw: bigint, decimals: number): number;
233
+ declare function getDecimals(asset: SupportedAsset): number;
234
+ declare function formatUsd(amount: number): string;
235
+ declare function formatSui(amount: number): string;
236
+ declare function formatAssetAmount(amount: number, asset: string): string;
237
+
238
+ interface SimulationResult {
239
+ success: boolean;
240
+ gasEstimateSui: number;
241
+ error?: {
242
+ moveAbortCode?: number;
243
+ moveModule?: string;
244
+ reason: string;
245
+ rawError: string;
246
+ };
247
+ }
248
+ declare function simulateTransaction(client: SuiJsonRpcClient, tx: Transaction, sender: string): Promise<SimulationResult>;
249
+ declare function throwIfSimulationFailed(sim: SimulationResult): void;
250
+
251
+ type FeeOperation = 'save' | 'borrow';
252
+ interface ProtocolFeeInfo {
253
+ amount: number;
254
+ asset: string;
255
+ rate: number;
256
+ rawAmount: bigint;
257
+ }
258
+ declare function calculateFee(operation: FeeOperation, amount: number): ProtocolFeeInfo;
259
+ /**
260
+ * Add on-chain fee collection to an existing PTB via t2000::treasury::collect_fee().
261
+ * The Move function splits the fee from the payment coin and stores it in the
262
+ * Treasury's internal Balance<T>. Atomic — reverts with the operation if it fails.
263
+ */
264
+ declare function addCollectFeeToTx(tx: Transaction, paymentCoin: TransactionObjectArgument, operation: FeeOperation): void;
265
+
266
+ type SafeguardRule = 'locked' | 'maxPerTx' | 'maxDailySend';
267
+ interface SafeguardErrorDetails {
268
+ attempted?: number;
269
+ limit?: number;
270
+ current?: number;
271
+ }
272
+ declare class SafeguardError extends T2000Error {
273
+ readonly rule: SafeguardRule;
274
+ readonly details: SafeguardErrorDetails;
275
+ constructor(rule: SafeguardRule, details: SafeguardErrorDetails, message?: string);
276
+ toJSON(): {
277
+ error: "SAFEGUARD_BLOCKED";
278
+ message: string;
279
+ retryable: boolean;
280
+ data: {
281
+ attempted?: number;
282
+ limit?: number;
283
+ current?: number;
284
+ rule: SafeguardRule;
285
+ };
286
+ };
287
+ }
288
+
289
+ /**
290
+ * Unified token registry — single source of truth for coin types, decimals, and symbols.
291
+ *
292
+ * ZERO heavy dependencies. Safe to import from any context (server, browser, Edge).
293
+ * All other token maps (KNOWN_COINS, DEC_MAP, TOKEN_DECIMALS, etc.) should be replaced
294
+ * with imports from this file.
295
+ *
296
+ * To add a new token: add ONE entry to COIN_REGISTRY below. Everything else derives from it.
297
+ */
298
+ interface CoinMeta {
299
+ type: string;
300
+ decimals: number;
301
+ symbol: string;
302
+ }
303
+ /**
304
+ * Canonical coin registry. Merges NAVI lending assets + swap-supported tokens.
305
+ * Key = user-friendly name (used in swap_execute, CLI, prompts).
306
+ */
307
+ declare const COIN_REGISTRY: Record<string, CoinMeta>;
308
+ /**
309
+ * Get decimals for any coin type. Checks full type match, then suffix match, then defaults to 9.
310
+ * Handles address normalization differences (leading zeros, casing).
311
+ */
312
+ declare function getDecimalsForCoinType(coinType: string): number;
313
+ /**
314
+ * Resolve a full coin type to a user-friendly symbol.
315
+ * Returns the last `::` segment if not in the registry.
316
+ */
317
+ declare function resolveSymbol(coinType: string): string;
318
+ /**
319
+ * Name → type map for swap resolution. Derived from COIN_REGISTRY.
320
+ * Contains BOTH original-case and UPPERCASE keys for case-insensitive lookup.
321
+ * Backward-compatible with the original TOKEN_MAP in cetus-swap.ts.
322
+ */
323
+ declare const TOKEN_MAP: Record<string, string>;
324
+ /**
325
+ * Resolve a user-friendly token name to its full coin type.
326
+ * Returns the input unchanged if already a full coin type (contains "::").
327
+ * Case-insensitive: 'usde', 'USDe', 'USDE' all resolve correctly.
328
+ */
329
+ declare function resolveTokenType(nameOrType: string): string | null;
330
+ /** Common type constants for direct import (avoid hardcoding strings). */
331
+ declare const SUI_TYPE: string;
332
+ declare const USDC_TYPE: string;
333
+ declare const USDT_TYPE: string;
334
+ declare const USDSUI_TYPE: string;
335
+ declare const USDE_TYPE: string;
336
+ declare const ETH_TYPE: string;
337
+ declare const WBTC_TYPE: string;
338
+ declare const WAL_TYPE: string;
339
+ declare const NAVX_TYPE: string;
340
+
341
+ export { getDecimals as $, ALL_NAVI_ASSETS as A, BPS_DENOMINATOR as B, CLOCK_ID as C, DEFAULT_NETWORK as D, ETH_TYPE as E, type FeeOperation as F, GAS_RESERVE_MIN as G, USDT_TYPE as H, WBTC_TYPE as I, ZkLoginSigner as J, KeypairSigner as K, addCollectFeeToTx as L, MIST_PER_SUI as M, NAVX_TYPE as N, OUTBOUND_OPS as O, type ProtocolFeeInfo as P, calculateFee as Q, executeAutoTopUp as R, STABLE_ASSETS as S, T2000Error as T, USDC_DECIMALS as U, executeWithGas as V, WAL_TYPE as W, formatAssetAmount as X, formatSui as Y, type ZkLoginProof as Z, formatUsd as _, type AutoTopUpResult as a, getDecimalsForCoinType as a0, getGasStatus as a1, mapMoveAbortCode as a2, mapWalletError as a3, mistToSui as a4, rawToStable as a5, rawToUsdc as a6, resolveSymbol as a7, resolveTokenType as a8, shouldAutoTopUp as a9, stableToRaw as aa, suiToMist as ab, truncateAddress as ac, usdcToRaw as ad, validateAddress as ae, SafeguardEnforcer as af, CETUS_USDC_SUI_POOL as ag, simulateTransaction as ah, throwIfSimulationFailed as ai, COIN_REGISTRY as b, type CoinMeta as c, DEFAULT_SAFEGUARD_CONFIG as d, type GasExecutionResult as e, type GasRequestType as f, type GasSponsorResponse as g, type GasStatusResponse as h, SUI_DECIMALS as i, SUI_TYPE as j, SUPPORTED_ASSETS as k, type SafeguardConfig as l, SafeguardError as m, type SafeguardErrorDetails as n, type SafeguardRule as o, type SimulationResult as p, type StableAsset as q, type SupportedAsset as r, type T2000ErrorCode as s, type T2000ErrorData as t, TOKEN_MAP as u, type TransactionSigner as v, type TxMetadata as w, USDC_TYPE as x, USDE_TYPE as y, USDSUI_TYPE as z };