@t2000/sdk 0.11.2 → 0.14.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/dist/index.d.cts CHANGED
@@ -1,11 +1,11 @@
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 T2000Options, S as SendResult, B as BalanceResponse, a as TransactionRecord, D as DepositInfo, L as LendingAdapter, b as SwapAdapter, c as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, d as BorrowResult, R as RepayResult, e as MaxBorrowResult, H as HealthFactorResult, f as SwapResult, P as PositionsResult, g as RatesResult, h as LendingRates, i as RebalanceResult, E as EarningsResult, F as FundStatusResult, j as SentinelAgent, k as SentinelAttackResult, G as GasMethod } from './index-BwHcYli9.cjs';
5
- export { A as AdapterCapability, l as AdapterPositions, m as AdapterTxResult, n as AssetRates, C as CetusAdapter, o as GasReserve, p as HealthInfo, N as NaviAdapter, q as PositionEntry, r as ProtocolDescriptor, s as ProtocolRegistry, t as RebalanceStep, u as SentinelVerdict, v as SuilendAdapter, w as SwapQuote, x as allDescriptors, y as cetusDescriptor, z as getSentinelInfo, I as listSentinels, J as naviDescriptor, K as requestAttack, O as sentinelAttack, Q as sentinelDescriptor, U as settleAttack, V as submitPrompt, X as suilendDescriptor } from './index-BwHcYli9.cjs';
4
+ import { I as InvestmentTrade, T as T2000Options, S as SendResult, B as BalanceResponse, a as TransactionRecord, D as DepositInfo, L as LendingAdapter, b as SwapAdapter, c as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, d as BorrowResult, R as RepayResult, e as MaxBorrowResult, H as HealthFactorResult, f as SwapResult, g as InvestResult, P as PortfolioResult, h as PositionsResult, i as RatesResult, j as LendingRates, k as RebalanceResult, E as EarningsResult, F as FundStatusResult, l as SentinelAgent, m as SentinelAttackResult, G as GasMethod } from './index-B14ZyQZt.cjs';
5
+ export { A as AdapterCapability, n as AdapterPositions, o as AdapterTxResult, p as AssetRates, C as CetusAdapter, q as GasReserve, r as HealthInfo, s as InvestmentPosition, N as NaviAdapter, t as PerpsAdapter, u as PerpsPosition, v as PositionEntry, w as PositionSide, x as ProtocolDescriptor, y as ProtocolRegistry, z as RebalanceStep, J as SentinelVerdict, K as SuilendAdapter, O as SwapQuote, Q as TradePositionsResult, U as TradeResult, V as allDescriptors, X as cetusDescriptor, Y as getSentinelInfo, Z as listSentinels, _ as naviDescriptor, $ as requestAttack, a0 as sentinelAttack, a1 as sentinelDescriptor, a2 as settleAttack, a3 as submitPrompt, a4 as suilendDescriptor } from './index-B14ZyQZt.cjs';
6
6
  import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
7
7
 
8
- type T2000ErrorCode = 'INSUFFICIENT_BALANCE' | 'INSUFFICIENT_GAS' | 'INVALID_ADDRESS' | 'INVALID_AMOUNT' | 'WALLET_NOT_FOUND' | 'WALLET_LOCKED' | 'WALLET_EXISTS' | 'SPONSOR_FAILED' | 'SPONSOR_RATE_LIMITED' | 'GAS_STATION_UNAVAILABLE' | 'GAS_FEE_EXCEEDED' | 'SIMULATION_FAILED' | 'TRANSACTION_FAILED' | 'ASSET_NOT_SUPPORTED' | 'SWAP_FAILED' | 'SLIPPAGE_EXCEEDED' | 'HEALTH_FACTOR_TOO_LOW' | 'WITHDRAW_WOULD_LIQUIDATE' | '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' | 'FACILITATOR_TIMEOUT' | 'SENTINEL_API_ERROR' | 'SENTINEL_NOT_FOUND' | 'SENTINEL_TX_FAILED' | 'SENTINEL_TEE_ERROR' | 'SAFEGUARD_BLOCKED' | 'UNKNOWN';
8
+ type T2000ErrorCode = 'INSUFFICIENT_BALANCE' | 'INSUFFICIENT_GAS' | 'INVALID_ADDRESS' | 'INVALID_AMOUNT' | 'WALLET_NOT_FOUND' | 'WALLET_LOCKED' | 'WALLET_EXISTS' | 'SPONSOR_FAILED' | 'SPONSOR_RATE_LIMITED' | 'GAS_STATION_UNAVAILABLE' | 'GAS_FEE_EXCEEDED' | 'SIMULATION_FAILED' | 'TRANSACTION_FAILED' | 'ASSET_NOT_SUPPORTED' | 'SWAP_FAILED' | 'SLIPPAGE_EXCEEDED' | 'HEALTH_FACTOR_TOO_LOW' | 'WITHDRAW_WOULD_LIQUIDATE' | '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' | 'SENTINEL_API_ERROR' | 'SENTINEL_NOT_FOUND' | 'SENTINEL_TX_FAILED' | 'SENTINEL_TEE_ERROR' | 'SAFEGUARD_BLOCKED' | 'INSUFFICIENT_INVESTMENT' | 'INVESTMENT_LOCKED' | 'MARKET_NOT_SUPPORTED' | 'LEVERAGE_EXCEEDED' | 'POSITION_SIZE_EXCEEDED' | 'BLUEFIN_AUTH_FAILED' | 'BLUEFIN_API_ERROR' | 'POSITION_NOT_FOUND' | 'UNKNOWN';
9
9
  interface T2000ErrorData {
10
10
  reason?: string;
11
11
  [key: string]: unknown;
@@ -25,18 +25,109 @@ declare class T2000Error extends Error {
25
25
  declare function mapWalletError(error: unknown): T2000Error;
26
26
  declare function mapMoveAbortCode(code: number): string;
27
27
 
28
+ declare const MIST_PER_SUI = 1000000000n;
29
+ declare const SUI_DECIMALS = 9;
30
+ declare const USDC_DECIMALS = 6;
31
+ declare const BPS_DENOMINATOR = 10000n;
32
+ declare const CLOCK_ID = "0x6";
33
+ declare const SUPPORTED_ASSETS: {
34
+ readonly USDC: {
35
+ readonly type: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
36
+ readonly decimals: 6;
37
+ readonly symbol: "USDC";
38
+ readonly displayName: "USDC";
39
+ };
40
+ readonly USDT: {
41
+ readonly type: "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT";
42
+ readonly decimals: 6;
43
+ readonly symbol: "USDT";
44
+ readonly displayName: "suiUSDT";
45
+ };
46
+ readonly USDe: {
47
+ readonly type: "0x41d587e5336f1c86cad50d38a7136db99333bb9bda91cea4ba69115defeb1402::sui_usde::SUI_USDE";
48
+ readonly decimals: 6;
49
+ readonly symbol: "USDe";
50
+ readonly displayName: "suiUSDe";
51
+ };
52
+ readonly USDsui: {
53
+ readonly type: "0x44f838219cf67b058f3b37907b655f226153c18e33dfcd0da559a844fea9b1c1::usdsui::USDSUI";
54
+ readonly decimals: 6;
55
+ readonly symbol: "USDsui";
56
+ readonly displayName: "USDsui";
57
+ };
58
+ readonly SUI: {
59
+ readonly type: "0x2::sui::SUI";
60
+ readonly decimals: 9;
61
+ readonly symbol: "SUI";
62
+ readonly displayName: "SUI";
63
+ };
64
+ readonly BTC: {
65
+ readonly type: "0xaafb102dd0902f5055cadecd687fb5b71ca82ef0e0285d90afde828ec58ca96b::btc::BTC";
66
+ readonly decimals: 8;
67
+ readonly symbol: "BTC";
68
+ readonly displayName: "Bitcoin";
69
+ };
70
+ readonly ETH: {
71
+ readonly type: "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH";
72
+ readonly decimals: 8;
73
+ readonly symbol: "ETH";
74
+ readonly displayName: "Ethereum";
75
+ };
76
+ };
77
+ type SupportedAsset = keyof typeof SUPPORTED_ASSETS;
78
+ declare const DEFAULT_NETWORK: "mainnet";
79
+ declare const INVESTMENT_ASSETS: {
80
+ readonly SUI: {
81
+ readonly type: "0x2::sui::SUI";
82
+ readonly decimals: 9;
83
+ readonly symbol: "SUI";
84
+ readonly displayName: "SUI";
85
+ };
86
+ readonly BTC: {
87
+ readonly type: "0xaafb102dd0902f5055cadecd687fb5b71ca82ef0e0285d90afde828ec58ca96b::btc::BTC";
88
+ readonly decimals: 8;
89
+ readonly symbol: "BTC";
90
+ readonly displayName: "Bitcoin";
91
+ };
92
+ readonly ETH: {
93
+ readonly type: "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH";
94
+ readonly decimals: 8;
95
+ readonly symbol: "ETH";
96
+ readonly displayName: "Ethereum";
97
+ };
98
+ };
99
+ type InvestmentAsset = keyof typeof INVESTMENT_ASSETS;
100
+ declare const PERPS_MARKETS: readonly ["SUI-PERP"];
101
+ type PerpsMarket = (typeof PERPS_MARKETS)[number];
102
+ declare const DEFAULT_MAX_LEVERAGE = 5;
103
+ declare const DEFAULT_MAX_POSITION_SIZE = 1000;
104
+ declare const GAS_RESERVE_MIN = 0.05;
105
+ declare const SENTINEL: {
106
+ readonly PACKAGE: "0x88b83f36dafcd5f6dcdcf1d2cb5889b03f61264ab3cee9cae35db7aa940a21b7";
107
+ readonly AGENT_REGISTRY: "0xc47564f5f14c12b31e0dfa1a3dc99a6380a1edf8929c28cb0eaa3359c8db36ac";
108
+ readonly ENCLAVE: "0xfb1261aeb9583514cb1341a548a5ec12d1231bd96af22215f1792617a93e1213";
109
+ readonly PROTOCOL_CONFIG: "0x2fa4fa4a1dd0498612304635ff9334e1b922e78af325000e9d9c0e88adea459f";
110
+ readonly TEE_API: "https://app.suisentinel.xyz/api/consume-prompt";
111
+ readonly SENTINELS_API: "https://api.suisentinel.xyz/agents/mainnet";
112
+ readonly RANDOM: "0x8";
113
+ readonly MIN_FEE_MIST: 100000000n;
114
+ readonly MAX_PROMPT_TOKENS: 600;
115
+ };
116
+
28
117
  interface SafeguardConfig {
29
118
  locked: boolean;
30
119
  maxPerTx: number;
31
120
  maxDailySend: number;
32
121
  dailyUsed: number;
33
122
  dailyResetDate: string;
123
+ maxLeverage?: number;
124
+ maxPositionSize?: number;
34
125
  }
35
126
  interface TxMetadata {
36
- operation: 'send' | 'save' | 'withdraw' | 'borrow' | 'repay' | 'exchange' | 'rebalance' | 'pay' | 'sentinel';
127
+ operation: 'send' | 'save' | 'withdraw' | 'borrow' | 'repay' | 'exchange' | 'rebalance' | 'pay' | 'sentinel' | 'invest' | 'trade';
37
128
  amount?: number;
38
129
  }
39
- declare const OUTBOUND_OPS: Set<"save" | "borrow" | "withdraw" | "repay" | "sentinel" | "send" | "exchange" | "rebalance" | "pay">;
130
+ declare const OUTBOUND_OPS: Set<"save" | "borrow" | "withdraw" | "repay" | "sentinel" | "send" | "exchange" | "rebalance" | "pay" | "invest" | "trade">;
40
131
  declare const DEFAULT_SAFEGUARD_CONFIG: SafeguardConfig;
41
132
 
42
133
  declare class SafeguardEnforcer {
@@ -56,6 +147,53 @@ declare class SafeguardEnforcer {
56
147
  private save;
57
148
  }
58
149
 
150
+ interface Contact {
151
+ name: string;
152
+ address: string;
153
+ }
154
+ type ContactMap = Record<string, Contact>;
155
+ declare class ContactManager {
156
+ private contacts;
157
+ private readonly filePath;
158
+ private readonly dir;
159
+ constructor(configDir?: string);
160
+ private load;
161
+ private save;
162
+ add(name: string, address: string): {
163
+ action: 'added' | 'updated';
164
+ };
165
+ remove(name: string): boolean;
166
+ get(name: string): Contact | undefined;
167
+ list(): Contact[];
168
+ resolve(nameOrAddress: string): {
169
+ address: string;
170
+ contactName?: string;
171
+ };
172
+ private validateName;
173
+ }
174
+
175
+ interface StoredPosition {
176
+ totalAmount: number;
177
+ costBasis: number;
178
+ avgPrice: number;
179
+ trades: InvestmentTrade[];
180
+ }
181
+ declare class PortfolioManager {
182
+ private data;
183
+ private readonly filePath;
184
+ private readonly dir;
185
+ constructor(configDir?: string);
186
+ private load;
187
+ private save;
188
+ recordBuy(trade: InvestmentTrade): void;
189
+ recordSell(trade: InvestmentTrade): number;
190
+ getPosition(asset: string): StoredPosition | undefined;
191
+ getPositions(): Array<{
192
+ asset: string;
193
+ } & StoredPosition>;
194
+ getRealizedPnL(): number;
195
+ }
196
+
59
197
  interface T2000Events {
60
198
  balanceChange: (event: {
61
199
  asset: string;
@@ -97,6 +235,8 @@ declare class T2000 extends EventEmitter<T2000Events> {
97
235
  private readonly _address;
98
236
  private readonly registry;
99
237
  readonly enforcer: SafeguardEnforcer;
238
+ readonly contacts: ContactManager;
239
+ readonly portfolio: PortfolioManager;
100
240
  private constructor();
101
241
  private static createDefaultRegistry;
102
242
  static create(options?: T2000Options): Promise<T2000>;
@@ -163,6 +303,7 @@ declare class T2000 extends EventEmitter<T2000Events> {
163
303
  to: string;
164
304
  amount: number;
165
305
  maxSlippage?: number;
306
+ _bypassInvestmentGuard?: boolean;
166
307
  }): Promise<SwapResult>;
167
308
  exchangeQuote(params: {
168
309
  from: string;
@@ -177,6 +318,17 @@ declare class T2000 extends EventEmitter<T2000Events> {
177
318
  rate: number;
178
319
  };
179
320
  }>;
321
+ investBuy(params: {
322
+ asset: InvestmentAsset;
323
+ usdAmount: number;
324
+ maxSlippage?: number;
325
+ }): Promise<InvestResult>;
326
+ investSell(params: {
327
+ asset: InvestmentAsset;
328
+ usdAmount: number | 'all';
329
+ maxSlippage?: number;
330
+ }): Promise<InvestResult>;
331
+ getPortfolio(): Promise<PortfolioResult>;
180
332
  positions(): Promise<PositionsResult>;
181
333
  rates(): Promise<RatesResult>;
182
334
  allRates(asset?: string): Promise<{
@@ -200,61 +352,11 @@ declare class T2000 extends EventEmitter<T2000Events> {
200
352
  sentinelList(): Promise<SentinelAgent[]>;
201
353
  sentinelInfo(id: string): Promise<SentinelAgent>;
202
354
  sentinelAttack(id: string, prompt: string, fee?: bigint): Promise<SentinelAttackResult>;
355
+ private getFreeBalance;
203
356
  private resolveLending;
204
357
  private emitBalanceChange;
205
358
  }
206
359
 
207
- declare const MIST_PER_SUI = 1000000000n;
208
- declare const SUI_DECIMALS = 9;
209
- declare const USDC_DECIMALS = 6;
210
- declare const BPS_DENOMINATOR = 10000n;
211
- declare const CLOCK_ID = "0x6";
212
- declare const SUPPORTED_ASSETS: {
213
- readonly USDC: {
214
- readonly type: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
215
- readonly decimals: 6;
216
- readonly symbol: "USDC";
217
- readonly displayName: "USDC";
218
- };
219
- readonly USDT: {
220
- readonly type: "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT";
221
- readonly decimals: 6;
222
- readonly symbol: "USDT";
223
- readonly displayName: "suiUSDT";
224
- };
225
- readonly USDe: {
226
- readonly type: "0x41d587e5336f1c86cad50d38a7136db99333bb9bda91cea4ba69115defeb1402::sui_usde::SUI_USDE";
227
- readonly decimals: 6;
228
- readonly symbol: "USDe";
229
- readonly displayName: "suiUSDe";
230
- };
231
- readonly USDsui: {
232
- readonly type: "0x44f838219cf67b058f3b37907b655f226153c18e33dfcd0da559a844fea9b1c1::usdsui::USDSUI";
233
- readonly decimals: 6;
234
- readonly symbol: "USDsui";
235
- readonly displayName: "USDsui";
236
- };
237
- readonly SUI: {
238
- readonly type: "0x2::sui::SUI";
239
- readonly decimals: 9;
240
- readonly symbol: "SUI";
241
- readonly displayName: "SUI";
242
- };
243
- };
244
- type SupportedAsset = keyof typeof SUPPORTED_ASSETS;
245
- declare const DEFAULT_NETWORK: "mainnet";
246
- declare const SENTINEL: {
247
- readonly PACKAGE: "0x88b83f36dafcd5f6dcdcf1d2cb5889b03f61264ab3cee9cae35db7aa940a21b7";
248
- readonly AGENT_REGISTRY: "0xc47564f5f14c12b31e0dfa1a3dc99a6380a1edf8929c28cb0eaa3359c8db36ac";
249
- readonly ENCLAVE: "0xfb1261aeb9583514cb1341a548a5ec12d1231bd96af22215f1792617a93e1213";
250
- readonly PROTOCOL_CONFIG: "0x2fa4fa4a1dd0498612304635ff9334e1b922e78af325000e9d9c0e88adea459f";
251
- readonly TEE_API: "https://app.suisentinel.xyz/api/consume-prompt";
252
- readonly SENTINELS_API: "https://api.suisentinel.xyz/agents/mainnet";
253
- readonly RANDOM: "0x8";
254
- readonly MIN_FEE_MIST: 100000000n;
255
- readonly MAX_PROMPT_TOKENS: 600;
256
- };
257
-
258
360
  declare function validateAddress(address: string): string;
259
361
  declare function truncateAddress(address: string): string;
260
362
 
@@ -375,4 +477,4 @@ interface GasStatusResponse {
375
477
  }
376
478
  declare function getGasStatus(address?: string): Promise<GasStatusResponse>;
377
479
 
378
- export { type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CLOCK_ID, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, OUTBOUND_OPS, PositionsResult, type ProtocolFeeInfo, RatesResult, RebalanceResult, RepayResult, SENTINEL, SUI_DECIMALS, SUPPORTED_ASSETS, type SafeguardConfig, SafeguardEnforcer, SafeguardError, type SafeguardErrorDetails, type SafeguardRule, SaveResult, SendResult, SentinelAgent, SentinelAttackResult, type SimulationResult, type SupportedAsset, SwapAdapter, SwapResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TransactionRecord, type TxMetadata, USDC_DECIMALS, WithdrawResult, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getPoolPrice, getRates, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
480
+ export { type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CLOCK_ID, type Contact, ContactManager, type ContactMap, DEFAULT_MAX_LEVERAGE, DEFAULT_MAX_POSITION_SIZE, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, GAS_RESERVE_MIN, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, INVESTMENT_ASSETS, InvestResult, type InvestmentAsset, InvestmentTrade, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, OUTBOUND_OPS, PERPS_MARKETS, type PerpsMarket, PortfolioManager, PortfolioResult, PositionsResult, type ProtocolFeeInfo, RatesResult, RebalanceResult, RepayResult, SENTINEL, SUI_DECIMALS, SUPPORTED_ASSETS, type SafeguardConfig, SafeguardEnforcer, SafeguardError, type SafeguardErrorDetails, type SafeguardRule, SaveResult, SendResult, SentinelAgent, SentinelAttackResult, type SimulationResult, type SupportedAsset, SwapAdapter, SwapResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TransactionRecord, type TxMetadata, USDC_DECIMALS, WithdrawResult, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getPoolPrice, getRates, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
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 T2000Options, S as SendResult, B as BalanceResponse, a as TransactionRecord, D as DepositInfo, L as LendingAdapter, b as SwapAdapter, c as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, d as BorrowResult, R as RepayResult, e as MaxBorrowResult, H as HealthFactorResult, f as SwapResult, P as PositionsResult, g as RatesResult, h as LendingRates, i as RebalanceResult, E as EarningsResult, F as FundStatusResult, j as SentinelAgent, k as SentinelAttackResult, G as GasMethod } from './index-BwHcYli9.js';
5
- export { A as AdapterCapability, l as AdapterPositions, m as AdapterTxResult, n as AssetRates, C as CetusAdapter, o as GasReserve, p as HealthInfo, N as NaviAdapter, q as PositionEntry, r as ProtocolDescriptor, s as ProtocolRegistry, t as RebalanceStep, u as SentinelVerdict, v as SuilendAdapter, w as SwapQuote, x as allDescriptors, y as cetusDescriptor, z as getSentinelInfo, I as listSentinels, J as naviDescriptor, K as requestAttack, O as sentinelAttack, Q as sentinelDescriptor, U as settleAttack, V as submitPrompt, X as suilendDescriptor } from './index-BwHcYli9.js';
4
+ import { I as InvestmentTrade, T as T2000Options, S as SendResult, B as BalanceResponse, a as TransactionRecord, D as DepositInfo, L as LendingAdapter, b as SwapAdapter, c as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, d as BorrowResult, R as RepayResult, e as MaxBorrowResult, H as HealthFactorResult, f as SwapResult, g as InvestResult, P as PortfolioResult, h as PositionsResult, i as RatesResult, j as LendingRates, k as RebalanceResult, E as EarningsResult, F as FundStatusResult, l as SentinelAgent, m as SentinelAttackResult, G as GasMethod } from './index-B14ZyQZt.js';
5
+ export { A as AdapterCapability, n as AdapterPositions, o as AdapterTxResult, p as AssetRates, C as CetusAdapter, q as GasReserve, r as HealthInfo, s as InvestmentPosition, N as NaviAdapter, t as PerpsAdapter, u as PerpsPosition, v as PositionEntry, w as PositionSide, x as ProtocolDescriptor, y as ProtocolRegistry, z as RebalanceStep, J as SentinelVerdict, K as SuilendAdapter, O as SwapQuote, Q as TradePositionsResult, U as TradeResult, V as allDescriptors, X as cetusDescriptor, Y as getSentinelInfo, Z as listSentinels, _ as naviDescriptor, $ as requestAttack, a0 as sentinelAttack, a1 as sentinelDescriptor, a2 as settleAttack, a3 as submitPrompt, a4 as suilendDescriptor } from './index-B14ZyQZt.js';
6
6
  import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
7
7
 
8
- type T2000ErrorCode = 'INSUFFICIENT_BALANCE' | 'INSUFFICIENT_GAS' | 'INVALID_ADDRESS' | 'INVALID_AMOUNT' | 'WALLET_NOT_FOUND' | 'WALLET_LOCKED' | 'WALLET_EXISTS' | 'SPONSOR_FAILED' | 'SPONSOR_RATE_LIMITED' | 'GAS_STATION_UNAVAILABLE' | 'GAS_FEE_EXCEEDED' | 'SIMULATION_FAILED' | 'TRANSACTION_FAILED' | 'ASSET_NOT_SUPPORTED' | 'SWAP_FAILED' | 'SLIPPAGE_EXCEEDED' | 'HEALTH_FACTOR_TOO_LOW' | 'WITHDRAW_WOULD_LIQUIDATE' | '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' | 'FACILITATOR_TIMEOUT' | 'SENTINEL_API_ERROR' | 'SENTINEL_NOT_FOUND' | 'SENTINEL_TX_FAILED' | 'SENTINEL_TEE_ERROR' | 'SAFEGUARD_BLOCKED' | 'UNKNOWN';
8
+ type T2000ErrorCode = 'INSUFFICIENT_BALANCE' | 'INSUFFICIENT_GAS' | 'INVALID_ADDRESS' | 'INVALID_AMOUNT' | 'WALLET_NOT_FOUND' | 'WALLET_LOCKED' | 'WALLET_EXISTS' | 'SPONSOR_FAILED' | 'SPONSOR_RATE_LIMITED' | 'GAS_STATION_UNAVAILABLE' | 'GAS_FEE_EXCEEDED' | 'SIMULATION_FAILED' | 'TRANSACTION_FAILED' | 'ASSET_NOT_SUPPORTED' | 'SWAP_FAILED' | 'SLIPPAGE_EXCEEDED' | 'HEALTH_FACTOR_TOO_LOW' | 'WITHDRAW_WOULD_LIQUIDATE' | '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' | 'SENTINEL_API_ERROR' | 'SENTINEL_NOT_FOUND' | 'SENTINEL_TX_FAILED' | 'SENTINEL_TEE_ERROR' | 'SAFEGUARD_BLOCKED' | 'INSUFFICIENT_INVESTMENT' | 'INVESTMENT_LOCKED' | 'MARKET_NOT_SUPPORTED' | 'LEVERAGE_EXCEEDED' | 'POSITION_SIZE_EXCEEDED' | 'BLUEFIN_AUTH_FAILED' | 'BLUEFIN_API_ERROR' | 'POSITION_NOT_FOUND' | 'UNKNOWN';
9
9
  interface T2000ErrorData {
10
10
  reason?: string;
11
11
  [key: string]: unknown;
@@ -25,18 +25,109 @@ declare class T2000Error extends Error {
25
25
  declare function mapWalletError(error: unknown): T2000Error;
26
26
  declare function mapMoveAbortCode(code: number): string;
27
27
 
28
+ declare const MIST_PER_SUI = 1000000000n;
29
+ declare const SUI_DECIMALS = 9;
30
+ declare const USDC_DECIMALS = 6;
31
+ declare const BPS_DENOMINATOR = 10000n;
32
+ declare const CLOCK_ID = "0x6";
33
+ declare const SUPPORTED_ASSETS: {
34
+ readonly USDC: {
35
+ readonly type: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
36
+ readonly decimals: 6;
37
+ readonly symbol: "USDC";
38
+ readonly displayName: "USDC";
39
+ };
40
+ readonly USDT: {
41
+ readonly type: "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT";
42
+ readonly decimals: 6;
43
+ readonly symbol: "USDT";
44
+ readonly displayName: "suiUSDT";
45
+ };
46
+ readonly USDe: {
47
+ readonly type: "0x41d587e5336f1c86cad50d38a7136db99333bb9bda91cea4ba69115defeb1402::sui_usde::SUI_USDE";
48
+ readonly decimals: 6;
49
+ readonly symbol: "USDe";
50
+ readonly displayName: "suiUSDe";
51
+ };
52
+ readonly USDsui: {
53
+ readonly type: "0x44f838219cf67b058f3b37907b655f226153c18e33dfcd0da559a844fea9b1c1::usdsui::USDSUI";
54
+ readonly decimals: 6;
55
+ readonly symbol: "USDsui";
56
+ readonly displayName: "USDsui";
57
+ };
58
+ readonly SUI: {
59
+ readonly type: "0x2::sui::SUI";
60
+ readonly decimals: 9;
61
+ readonly symbol: "SUI";
62
+ readonly displayName: "SUI";
63
+ };
64
+ readonly BTC: {
65
+ readonly type: "0xaafb102dd0902f5055cadecd687fb5b71ca82ef0e0285d90afde828ec58ca96b::btc::BTC";
66
+ readonly decimals: 8;
67
+ readonly symbol: "BTC";
68
+ readonly displayName: "Bitcoin";
69
+ };
70
+ readonly ETH: {
71
+ readonly type: "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH";
72
+ readonly decimals: 8;
73
+ readonly symbol: "ETH";
74
+ readonly displayName: "Ethereum";
75
+ };
76
+ };
77
+ type SupportedAsset = keyof typeof SUPPORTED_ASSETS;
78
+ declare const DEFAULT_NETWORK: "mainnet";
79
+ declare const INVESTMENT_ASSETS: {
80
+ readonly SUI: {
81
+ readonly type: "0x2::sui::SUI";
82
+ readonly decimals: 9;
83
+ readonly symbol: "SUI";
84
+ readonly displayName: "SUI";
85
+ };
86
+ readonly BTC: {
87
+ readonly type: "0xaafb102dd0902f5055cadecd687fb5b71ca82ef0e0285d90afde828ec58ca96b::btc::BTC";
88
+ readonly decimals: 8;
89
+ readonly symbol: "BTC";
90
+ readonly displayName: "Bitcoin";
91
+ };
92
+ readonly ETH: {
93
+ readonly type: "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH";
94
+ readonly decimals: 8;
95
+ readonly symbol: "ETH";
96
+ readonly displayName: "Ethereum";
97
+ };
98
+ };
99
+ type InvestmentAsset = keyof typeof INVESTMENT_ASSETS;
100
+ declare const PERPS_MARKETS: readonly ["SUI-PERP"];
101
+ type PerpsMarket = (typeof PERPS_MARKETS)[number];
102
+ declare const DEFAULT_MAX_LEVERAGE = 5;
103
+ declare const DEFAULT_MAX_POSITION_SIZE = 1000;
104
+ declare const GAS_RESERVE_MIN = 0.05;
105
+ declare const SENTINEL: {
106
+ readonly PACKAGE: "0x88b83f36dafcd5f6dcdcf1d2cb5889b03f61264ab3cee9cae35db7aa940a21b7";
107
+ readonly AGENT_REGISTRY: "0xc47564f5f14c12b31e0dfa1a3dc99a6380a1edf8929c28cb0eaa3359c8db36ac";
108
+ readonly ENCLAVE: "0xfb1261aeb9583514cb1341a548a5ec12d1231bd96af22215f1792617a93e1213";
109
+ readonly PROTOCOL_CONFIG: "0x2fa4fa4a1dd0498612304635ff9334e1b922e78af325000e9d9c0e88adea459f";
110
+ readonly TEE_API: "https://app.suisentinel.xyz/api/consume-prompt";
111
+ readonly SENTINELS_API: "https://api.suisentinel.xyz/agents/mainnet";
112
+ readonly RANDOM: "0x8";
113
+ readonly MIN_FEE_MIST: 100000000n;
114
+ readonly MAX_PROMPT_TOKENS: 600;
115
+ };
116
+
28
117
  interface SafeguardConfig {
29
118
  locked: boolean;
30
119
  maxPerTx: number;
31
120
  maxDailySend: number;
32
121
  dailyUsed: number;
33
122
  dailyResetDate: string;
123
+ maxLeverage?: number;
124
+ maxPositionSize?: number;
34
125
  }
35
126
  interface TxMetadata {
36
- operation: 'send' | 'save' | 'withdraw' | 'borrow' | 'repay' | 'exchange' | 'rebalance' | 'pay' | 'sentinel';
127
+ operation: 'send' | 'save' | 'withdraw' | 'borrow' | 'repay' | 'exchange' | 'rebalance' | 'pay' | 'sentinel' | 'invest' | 'trade';
37
128
  amount?: number;
38
129
  }
39
- declare const OUTBOUND_OPS: Set<"save" | "borrow" | "withdraw" | "repay" | "sentinel" | "send" | "exchange" | "rebalance" | "pay">;
130
+ declare const OUTBOUND_OPS: Set<"save" | "borrow" | "withdraw" | "repay" | "sentinel" | "send" | "exchange" | "rebalance" | "pay" | "invest" | "trade">;
40
131
  declare const DEFAULT_SAFEGUARD_CONFIG: SafeguardConfig;
41
132
 
42
133
  declare class SafeguardEnforcer {
@@ -56,6 +147,53 @@ declare class SafeguardEnforcer {
56
147
  private save;
57
148
  }
58
149
 
150
+ interface Contact {
151
+ name: string;
152
+ address: string;
153
+ }
154
+ type ContactMap = Record<string, Contact>;
155
+ declare class ContactManager {
156
+ private contacts;
157
+ private readonly filePath;
158
+ private readonly dir;
159
+ constructor(configDir?: string);
160
+ private load;
161
+ private save;
162
+ add(name: string, address: string): {
163
+ action: 'added' | 'updated';
164
+ };
165
+ remove(name: string): boolean;
166
+ get(name: string): Contact | undefined;
167
+ list(): Contact[];
168
+ resolve(nameOrAddress: string): {
169
+ address: string;
170
+ contactName?: string;
171
+ };
172
+ private validateName;
173
+ }
174
+
175
+ interface StoredPosition {
176
+ totalAmount: number;
177
+ costBasis: number;
178
+ avgPrice: number;
179
+ trades: InvestmentTrade[];
180
+ }
181
+ declare class PortfolioManager {
182
+ private data;
183
+ private readonly filePath;
184
+ private readonly dir;
185
+ constructor(configDir?: string);
186
+ private load;
187
+ private save;
188
+ recordBuy(trade: InvestmentTrade): void;
189
+ recordSell(trade: InvestmentTrade): number;
190
+ getPosition(asset: string): StoredPosition | undefined;
191
+ getPositions(): Array<{
192
+ asset: string;
193
+ } & StoredPosition>;
194
+ getRealizedPnL(): number;
195
+ }
196
+
59
197
  interface T2000Events {
60
198
  balanceChange: (event: {
61
199
  asset: string;
@@ -97,6 +235,8 @@ declare class T2000 extends EventEmitter<T2000Events> {
97
235
  private readonly _address;
98
236
  private readonly registry;
99
237
  readonly enforcer: SafeguardEnforcer;
238
+ readonly contacts: ContactManager;
239
+ readonly portfolio: PortfolioManager;
100
240
  private constructor();
101
241
  private static createDefaultRegistry;
102
242
  static create(options?: T2000Options): Promise<T2000>;
@@ -163,6 +303,7 @@ declare class T2000 extends EventEmitter<T2000Events> {
163
303
  to: string;
164
304
  amount: number;
165
305
  maxSlippage?: number;
306
+ _bypassInvestmentGuard?: boolean;
166
307
  }): Promise<SwapResult>;
167
308
  exchangeQuote(params: {
168
309
  from: string;
@@ -177,6 +318,17 @@ declare class T2000 extends EventEmitter<T2000Events> {
177
318
  rate: number;
178
319
  };
179
320
  }>;
321
+ investBuy(params: {
322
+ asset: InvestmentAsset;
323
+ usdAmount: number;
324
+ maxSlippage?: number;
325
+ }): Promise<InvestResult>;
326
+ investSell(params: {
327
+ asset: InvestmentAsset;
328
+ usdAmount: number | 'all';
329
+ maxSlippage?: number;
330
+ }): Promise<InvestResult>;
331
+ getPortfolio(): Promise<PortfolioResult>;
180
332
  positions(): Promise<PositionsResult>;
181
333
  rates(): Promise<RatesResult>;
182
334
  allRates(asset?: string): Promise<{
@@ -200,61 +352,11 @@ declare class T2000 extends EventEmitter<T2000Events> {
200
352
  sentinelList(): Promise<SentinelAgent[]>;
201
353
  sentinelInfo(id: string): Promise<SentinelAgent>;
202
354
  sentinelAttack(id: string, prompt: string, fee?: bigint): Promise<SentinelAttackResult>;
355
+ private getFreeBalance;
203
356
  private resolveLending;
204
357
  private emitBalanceChange;
205
358
  }
206
359
 
207
- declare const MIST_PER_SUI = 1000000000n;
208
- declare const SUI_DECIMALS = 9;
209
- declare const USDC_DECIMALS = 6;
210
- declare const BPS_DENOMINATOR = 10000n;
211
- declare const CLOCK_ID = "0x6";
212
- declare const SUPPORTED_ASSETS: {
213
- readonly USDC: {
214
- readonly type: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
215
- readonly decimals: 6;
216
- readonly symbol: "USDC";
217
- readonly displayName: "USDC";
218
- };
219
- readonly USDT: {
220
- readonly type: "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT";
221
- readonly decimals: 6;
222
- readonly symbol: "USDT";
223
- readonly displayName: "suiUSDT";
224
- };
225
- readonly USDe: {
226
- readonly type: "0x41d587e5336f1c86cad50d38a7136db99333bb9bda91cea4ba69115defeb1402::sui_usde::SUI_USDE";
227
- readonly decimals: 6;
228
- readonly symbol: "USDe";
229
- readonly displayName: "suiUSDe";
230
- };
231
- readonly USDsui: {
232
- readonly type: "0x44f838219cf67b058f3b37907b655f226153c18e33dfcd0da559a844fea9b1c1::usdsui::USDSUI";
233
- readonly decimals: 6;
234
- readonly symbol: "USDsui";
235
- readonly displayName: "USDsui";
236
- };
237
- readonly SUI: {
238
- readonly type: "0x2::sui::SUI";
239
- readonly decimals: 9;
240
- readonly symbol: "SUI";
241
- readonly displayName: "SUI";
242
- };
243
- };
244
- type SupportedAsset = keyof typeof SUPPORTED_ASSETS;
245
- declare const DEFAULT_NETWORK: "mainnet";
246
- declare const SENTINEL: {
247
- readonly PACKAGE: "0x88b83f36dafcd5f6dcdcf1d2cb5889b03f61264ab3cee9cae35db7aa940a21b7";
248
- readonly AGENT_REGISTRY: "0xc47564f5f14c12b31e0dfa1a3dc99a6380a1edf8929c28cb0eaa3359c8db36ac";
249
- readonly ENCLAVE: "0xfb1261aeb9583514cb1341a548a5ec12d1231bd96af22215f1792617a93e1213";
250
- readonly PROTOCOL_CONFIG: "0x2fa4fa4a1dd0498612304635ff9334e1b922e78af325000e9d9c0e88adea459f";
251
- readonly TEE_API: "https://app.suisentinel.xyz/api/consume-prompt";
252
- readonly SENTINELS_API: "https://api.suisentinel.xyz/agents/mainnet";
253
- readonly RANDOM: "0x8";
254
- readonly MIN_FEE_MIST: 100000000n;
255
- readonly MAX_PROMPT_TOKENS: 600;
256
- };
257
-
258
360
  declare function validateAddress(address: string): string;
259
361
  declare function truncateAddress(address: string): string;
260
362
 
@@ -375,4 +477,4 @@ interface GasStatusResponse {
375
477
  }
376
478
  declare function getGasStatus(address?: string): Promise<GasStatusResponse>;
377
479
 
378
- export { type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CLOCK_ID, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, OUTBOUND_OPS, PositionsResult, type ProtocolFeeInfo, RatesResult, RebalanceResult, RepayResult, SENTINEL, SUI_DECIMALS, SUPPORTED_ASSETS, type SafeguardConfig, SafeguardEnforcer, SafeguardError, type SafeguardErrorDetails, type SafeguardRule, SaveResult, SendResult, SentinelAgent, SentinelAttackResult, type SimulationResult, type SupportedAsset, SwapAdapter, SwapResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TransactionRecord, type TxMetadata, USDC_DECIMALS, WithdrawResult, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getPoolPrice, getRates, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
480
+ export { type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CLOCK_ID, type Contact, ContactManager, type ContactMap, DEFAULT_MAX_LEVERAGE, DEFAULT_MAX_POSITION_SIZE, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, GAS_RESERVE_MIN, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, INVESTMENT_ASSETS, InvestResult, type InvestmentAsset, InvestmentTrade, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, OUTBOUND_OPS, PERPS_MARKETS, type PerpsMarket, PortfolioManager, PortfolioResult, PositionsResult, type ProtocolFeeInfo, RatesResult, RebalanceResult, RepayResult, SENTINEL, SUI_DECIMALS, SUPPORTED_ASSETS, type SafeguardConfig, SafeguardEnforcer, SafeguardError, type SafeguardErrorDetails, type SafeguardRule, SaveResult, SendResult, SentinelAgent, SentinelAttackResult, type SimulationResult, type SupportedAsset, SwapAdapter, SwapResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TransactionRecord, type TxMetadata, USDC_DECIMALS, WithdrawResult, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getPoolPrice, getRates, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };