@t2000/sdk 0.13.0 → 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.
@@ -2,134 +2,6 @@ import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions
2
2
  import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
3
3
  import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
4
4
 
5
- type AdapterCapability = 'save' | 'withdraw' | 'borrow' | 'repay' | 'swap';
6
- /**
7
- * Describes a protocol for indexer event classification.
8
- * Each adapter exports one of these so the server can auto-build
9
- * detection rules without manual sync.
10
- *
11
- * To add a new protocol: export a `descriptor` from your adapter file.
12
- */
13
- interface ProtocolDescriptor {
14
- /** Unique protocol ID — must match the adapter's `id` field */
15
- id: string;
16
- /** Human-readable name */
17
- name: string;
18
- /**
19
- * On-chain package IDs that identify this protocol's transactions.
20
- * For protocols with upgradeable packages, list the original/base package.
21
- */
22
- packages: string[];
23
- /**
24
- * Maps `module::function` patterns to action types.
25
- * The indexer matches Move call targets against these patterns.
26
- * For dynamic package IDs (e.g. NAVI), matching is done on module::function only.
27
- */
28
- actionMap: Record<string, string>;
29
- /**
30
- * If true, the indexer matches by module::function suffix only,
31
- * ignoring the package ID prefix. Use for protocols with frequently
32
- * upgraded (dynamic) package IDs.
33
- */
34
- dynamicPackageId?: boolean;
35
- }
36
- interface AdapterTxResult {
37
- tx: Transaction;
38
- feeCoin?: TransactionObjectArgument;
39
- meta?: Record<string, unknown>;
40
- }
41
- interface LendingRates {
42
- asset: string;
43
- saveApy: number;
44
- borrowApy: number;
45
- }
46
- interface AdapterPositions {
47
- supplies: Array<{
48
- asset: string;
49
- amount: number;
50
- apy: number;
51
- }>;
52
- borrows: Array<{
53
- asset: string;
54
- amount: number;
55
- apy: number;
56
- }>;
57
- }
58
- interface HealthInfo {
59
- healthFactor: number;
60
- supplied: number;
61
- borrowed: number;
62
- maxBorrow: number;
63
- liquidationThreshold: number;
64
- }
65
- interface SwapQuote {
66
- expectedOutput: number;
67
- priceImpact: number;
68
- poolPrice: number;
69
- }
70
- interface LendingAdapter {
71
- readonly id: string;
72
- readonly name: string;
73
- readonly version: string;
74
- readonly capabilities: readonly AdapterCapability[];
75
- readonly supportedAssets: readonly string[];
76
- readonly supportsSameAssetBorrow: boolean;
77
- init(client: SuiJsonRpcClient): Promise<void>;
78
- getRates(asset: string): Promise<LendingRates>;
79
- getPositions(address: string): Promise<AdapterPositions>;
80
- getHealth(address: string): Promise<HealthInfo>;
81
- buildSaveTx(address: string, amount: number, asset: string, options?: {
82
- collectFee?: boolean;
83
- }): Promise<AdapterTxResult>;
84
- buildWithdrawTx(address: string, amount: number, asset: string): Promise<AdapterTxResult & {
85
- effectiveAmount: number;
86
- }>;
87
- buildBorrowTx(address: string, amount: number, asset: string, options?: {
88
- collectFee?: boolean;
89
- }): Promise<AdapterTxResult>;
90
- buildRepayTx(address: string, amount: number, asset: string): Promise<AdapterTxResult>;
91
- maxWithdraw(address: string, asset: string): Promise<{
92
- maxAmount: number;
93
- healthFactorAfter: number;
94
- currentHF: number;
95
- }>;
96
- maxBorrow(address: string, asset: string): Promise<{
97
- maxAmount: number;
98
- healthFactorAfter: number;
99
- currentHF: number;
100
- }>;
101
- addWithdrawToTx?(tx: Transaction, address: string, amount: number, asset: string): Promise<{
102
- coin: TransactionObjectArgument;
103
- effectiveAmount: number;
104
- }>;
105
- addSaveToTx?(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string, options?: {
106
- collectFee?: boolean;
107
- }): Promise<void>;
108
- addRepayToTx?(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string): Promise<void>;
109
- }
110
- interface SwapAdapter {
111
- readonly id: string;
112
- readonly name: string;
113
- readonly version: string;
114
- readonly capabilities: readonly AdapterCapability[];
115
- init(client: SuiJsonRpcClient): Promise<void>;
116
- getQuote(from: string, to: string, amount: number): Promise<SwapQuote>;
117
- buildSwapTx(address: string, from: string, to: string, amount: number, maxSlippageBps?: number): Promise<AdapterTxResult & {
118
- estimatedOut: number;
119
- toDecimals: number;
120
- }>;
121
- getSupportedPairs(): Array<{
122
- from: string;
123
- to: string;
124
- }>;
125
- getPoolPrice(): Promise<number>;
126
- addSwapToTx?(tx: Transaction, address: string, inputCoin: TransactionObjectArgument, from: string, to: string, amount: number, maxSlippageBps?: number): Promise<{
127
- outputCoin: TransactionObjectArgument;
128
- estimatedOut: number;
129
- toDecimals: number;
130
- }>;
131
- }
132
-
133
5
  interface T2000Options {
134
6
  keyPath?: string;
135
7
  /** PIN to decrypt the key file. Accepts any string (4+ chars). */
@@ -149,6 +21,8 @@ interface BalanceResponse {
149
21
  available: number;
150
22
  savings: number;
151
23
  debt: number;
24
+ investment: number;
25
+ investmentPnL: number;
152
26
  gasReserve: GasReserve;
153
27
  total: number;
154
28
  assets: Record<string, number>;
@@ -328,6 +202,229 @@ interface SentinelAttackResult {
328
202
  won: boolean;
329
203
  feePaid: number;
330
204
  }
205
+ interface InvestmentTrade {
206
+ id: string;
207
+ type: 'buy' | 'sell';
208
+ asset: string;
209
+ amount: number;
210
+ price: number;
211
+ usdValue: number;
212
+ fee: number;
213
+ tx: string;
214
+ timestamp: string;
215
+ }
216
+ interface InvestmentPosition {
217
+ asset: string;
218
+ totalAmount: number;
219
+ costBasis: number;
220
+ avgPrice: number;
221
+ currentPrice: number;
222
+ currentValue: number;
223
+ unrealizedPnL: number;
224
+ unrealizedPnLPct: number;
225
+ trades: InvestmentTrade[];
226
+ }
227
+ interface PortfolioResult {
228
+ positions: InvestmentPosition[];
229
+ totalInvested: number;
230
+ totalValue: number;
231
+ unrealizedPnL: number;
232
+ unrealizedPnLPct: number;
233
+ realizedPnL: number;
234
+ }
235
+ interface InvestResult {
236
+ success: boolean;
237
+ tx: string;
238
+ type: 'buy' | 'sell';
239
+ asset: string;
240
+ amount: number;
241
+ price: number;
242
+ usdValue: number;
243
+ fee: number;
244
+ gasCost: number;
245
+ gasMethod: GasMethod;
246
+ realizedPnL?: number;
247
+ position: InvestmentPosition;
248
+ }
249
+ type PositionSide = 'long' | 'short';
250
+ interface PerpsPosition {
251
+ market: string;
252
+ side: PositionSide;
253
+ margin: number;
254
+ leverage: number;
255
+ size: number;
256
+ entryPrice: number;
257
+ markPrice: number;
258
+ liquidationPrice: number;
259
+ unrealizedPnL: number;
260
+ unrealizedPnLPct: number;
261
+ }
262
+ interface TradeResult {
263
+ success: boolean;
264
+ action: 'open' | 'close';
265
+ market: string;
266
+ side: PositionSide;
267
+ margin: number;
268
+ leverage: number;
269
+ size: number;
270
+ entryPrice: number;
271
+ liquidationPrice?: number;
272
+ realizedPnL?: number;
273
+ tx?: string;
274
+ }
275
+ interface TradePositionsResult {
276
+ positions: PerpsPosition[];
277
+ totalMargin: number;
278
+ totalUnrealizedPnL: number;
279
+ }
280
+
281
+ type AdapterCapability = 'save' | 'withdraw' | 'borrow' | 'repay' | 'swap' | 'perps';
282
+ /**
283
+ * Describes a protocol for indexer event classification.
284
+ * Each adapter exports one of these so the server can auto-build
285
+ * detection rules without manual sync.
286
+ *
287
+ * To add a new protocol: export a `descriptor` from your adapter file.
288
+ */
289
+ interface ProtocolDescriptor {
290
+ /** Unique protocol ID — must match the adapter's `id` field */
291
+ id: string;
292
+ /** Human-readable name */
293
+ name: string;
294
+ /**
295
+ * On-chain package IDs that identify this protocol's transactions.
296
+ * For protocols with upgradeable packages, list the original/base package.
297
+ */
298
+ packages: string[];
299
+ /**
300
+ * Maps `module::function` patterns to action types.
301
+ * The indexer matches Move call targets against these patterns.
302
+ * For dynamic package IDs (e.g. NAVI), matching is done on module::function only.
303
+ */
304
+ actionMap: Record<string, string>;
305
+ /**
306
+ * If true, the indexer matches by module::function suffix only,
307
+ * ignoring the package ID prefix. Use for protocols with frequently
308
+ * upgraded (dynamic) package IDs.
309
+ */
310
+ dynamicPackageId?: boolean;
311
+ }
312
+ interface AdapterTxResult {
313
+ tx: Transaction;
314
+ feeCoin?: TransactionObjectArgument;
315
+ meta?: Record<string, unknown>;
316
+ }
317
+ interface LendingRates {
318
+ asset: string;
319
+ saveApy: number;
320
+ borrowApy: number;
321
+ }
322
+ interface AdapterPositions {
323
+ supplies: Array<{
324
+ asset: string;
325
+ amount: number;
326
+ apy: number;
327
+ }>;
328
+ borrows: Array<{
329
+ asset: string;
330
+ amount: number;
331
+ apy: number;
332
+ }>;
333
+ }
334
+ interface HealthInfo {
335
+ healthFactor: number;
336
+ supplied: number;
337
+ borrowed: number;
338
+ maxBorrow: number;
339
+ liquidationThreshold: number;
340
+ }
341
+ interface SwapQuote {
342
+ expectedOutput: number;
343
+ priceImpact: number;
344
+ poolPrice: number;
345
+ }
346
+ interface LendingAdapter {
347
+ readonly id: string;
348
+ readonly name: string;
349
+ readonly version: string;
350
+ readonly capabilities: readonly AdapterCapability[];
351
+ readonly supportedAssets: readonly string[];
352
+ readonly supportsSameAssetBorrow: boolean;
353
+ init(client: SuiJsonRpcClient): Promise<void>;
354
+ getRates(asset: string): Promise<LendingRates>;
355
+ getPositions(address: string): Promise<AdapterPositions>;
356
+ getHealth(address: string): Promise<HealthInfo>;
357
+ buildSaveTx(address: string, amount: number, asset: string, options?: {
358
+ collectFee?: boolean;
359
+ }): Promise<AdapterTxResult>;
360
+ buildWithdrawTx(address: string, amount: number, asset: string): Promise<AdapterTxResult & {
361
+ effectiveAmount: number;
362
+ }>;
363
+ buildBorrowTx(address: string, amount: number, asset: string, options?: {
364
+ collectFee?: boolean;
365
+ }): Promise<AdapterTxResult>;
366
+ buildRepayTx(address: string, amount: number, asset: string): Promise<AdapterTxResult>;
367
+ maxWithdraw(address: string, asset: string): Promise<{
368
+ maxAmount: number;
369
+ healthFactorAfter: number;
370
+ currentHF: number;
371
+ }>;
372
+ maxBorrow(address: string, asset: string): Promise<{
373
+ maxAmount: number;
374
+ healthFactorAfter: number;
375
+ currentHF: number;
376
+ }>;
377
+ addWithdrawToTx?(tx: Transaction, address: string, amount: number, asset: string): Promise<{
378
+ coin: TransactionObjectArgument;
379
+ effectiveAmount: number;
380
+ }>;
381
+ addSaveToTx?(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string, options?: {
382
+ collectFee?: boolean;
383
+ }): Promise<void>;
384
+ addRepayToTx?(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string): Promise<void>;
385
+ }
386
+ interface SwapAdapter {
387
+ readonly id: string;
388
+ readonly name: string;
389
+ readonly version: string;
390
+ readonly capabilities: readonly AdapterCapability[];
391
+ init(client: SuiJsonRpcClient): Promise<void>;
392
+ getQuote(from: string, to: string, amount: number): Promise<SwapQuote>;
393
+ buildSwapTx(address: string, from: string, to: string, amount: number, maxSlippageBps?: number): Promise<AdapterTxResult & {
394
+ estimatedOut: number;
395
+ toDecimals: number;
396
+ }>;
397
+ getSupportedPairs(): Array<{
398
+ from: string;
399
+ to: string;
400
+ }>;
401
+ getPoolPrice(): Promise<number>;
402
+ addSwapToTx?(tx: Transaction, address: string, inputCoin: TransactionObjectArgument, from: string, to: string, amount: number, maxSlippageBps?: number): Promise<{
403
+ outputCoin: TransactionObjectArgument;
404
+ estimatedOut: number;
405
+ toDecimals: number;
406
+ }>;
407
+ }
408
+ interface PerpsAdapter {
409
+ readonly id: string;
410
+ readonly name: string;
411
+ readonly version: string;
412
+ readonly capabilities: readonly AdapterCapability[];
413
+ readonly supportedMarkets: readonly string[];
414
+ init(keypair: unknown, network: 'mainnet' | 'testnet'): Promise<void>;
415
+ getAccountBalance(address: string): Promise<number>;
416
+ getPositions(address: string): Promise<PerpsPosition[]>;
417
+ getMarketPrice(market: string): Promise<number>;
418
+ deposit(amount: number): Promise<string>;
419
+ withdraw(amount: number): Promise<string>;
420
+ openPosition(params: {
421
+ market: string;
422
+ side: PositionSide;
423
+ margin: number;
424
+ leverage: number;
425
+ }): Promise<TradeResult>;
426
+ closePosition(market: string): Promise<TradeResult>;
427
+ }
331
428
 
332
429
  declare class ProtocolRegistry {
333
430
  private lending;
@@ -511,4 +608,4 @@ declare function attack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentin
511
608
  /** All registered protocol descriptors — used by the indexer for event classification */
512
609
  declare const allDescriptors: ProtocolDescriptor[];
513
610
 
514
- export { type AdapterCapability as A, type BalanceResponse as B, CetusAdapter as C, type DepositInfo as D, type EarningsResult as E, type FundStatusResult as F, type GasMethod as G, type HealthFactorResult as H, listSentinels as I, descriptor$3 as J, requestAttack as K, type LendingAdapter as L, type MaxWithdrawResult as M, NaviAdapter as N, attack as O, type PositionsResult as P, descriptor as Q, type RepayResult as R, type SendResult as S, type T2000Options as T, settleAttack as U, submitPrompt as V, type WithdrawResult as W, descriptor$1 as X, type TransactionRecord as a, type SwapAdapter as b, type SaveResult as c, type BorrowResult as d, type MaxBorrowResult as e, type SwapResult as f, type RatesResult as g, type LendingRates as h, type RebalanceResult as i, type SentinelAgent as j, type SentinelAttackResult as k, type AdapterPositions as l, type AdapterTxResult as m, type AssetRates as n, type GasReserve as o, type HealthInfo as p, type PositionEntry as q, type ProtocolDescriptor as r, ProtocolRegistry as s, type RebalanceStep as t, type SentinelVerdict as u, SuilendAdapter as v, type SwapQuote as w, allDescriptors as x, descriptor$2 as y, getSentinelInfo as z };
611
+ export { requestAttack as $, type AdapterCapability as A, type BalanceResponse as B, CetusAdapter as C, type DepositInfo as D, type EarningsResult as E, type FundStatusResult as F, type GasMethod as G, type HealthFactorResult as H, type InvestmentTrade as I, type SentinelVerdict as J, SuilendAdapter as K, type LendingAdapter as L, type MaxWithdrawResult as M, NaviAdapter as N, type SwapQuote as O, type PortfolioResult as P, type TradePositionsResult as Q, type RepayResult as R, type SendResult as S, type T2000Options as T, type TradeResult as U, allDescriptors as V, type WithdrawResult as W, descriptor$2 as X, getSentinelInfo as Y, listSentinels as Z, descriptor$3 as _, type TransactionRecord as a, attack as a0, descriptor as a1, settleAttack as a2, submitPrompt as a3, descriptor$1 as a4, type SwapAdapter as b, type SaveResult as c, type BorrowResult as d, type MaxBorrowResult as e, type SwapResult as f, type InvestResult as g, type PositionsResult as h, type RatesResult as i, type LendingRates as j, type RebalanceResult as k, type SentinelAgent as l, type SentinelAttackResult as m, type AdapterPositions as n, type AdapterTxResult as o, type AssetRates as p, type GasReserve as q, type HealthInfo as r, type InvestmentPosition as s, type PerpsAdapter as t, type PerpsPosition as u, type PositionEntry as v, type PositionSide as w, type ProtocolDescriptor as x, ProtocolRegistry as y, type RebalanceStep as z };