@t2000/sdk 0.6.2 → 0.7.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.
@@ -1,7 +1,38 @@
1
1
  import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
2
2
  import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
3
+ import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
3
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
+ }
5
36
  interface AdapterTxResult {
6
37
  tx: Transaction;
7
38
  feeCoin?: TransactionObjectArgument;
@@ -292,6 +323,7 @@ declare class ProtocolRegistry {
292
323
  listSwap(): SwapAdapter[];
293
324
  }
294
325
 
326
+ declare const descriptor$3: ProtocolDescriptor;
295
327
  declare class NaviAdapter implements LendingAdapter {
296
328
  readonly id = "navi";
297
329
  readonly name = "NAVI Protocol";
@@ -319,6 +351,7 @@ declare class NaviAdapter implements LendingAdapter {
319
351
  maxBorrow(address: string, _asset: string): Promise<MaxBorrowResult>;
320
352
  }
321
353
 
354
+ declare const descriptor$2: ProtocolDescriptor;
322
355
  declare class CetusAdapter implements SwapAdapter {
323
356
  readonly id = "cetus";
324
357
  readonly name = "Cetus";
@@ -339,6 +372,7 @@ declare class CetusAdapter implements SwapAdapter {
339
372
  getPoolPrice(): Promise<number>;
340
373
  }
341
374
 
375
+ declare const descriptor$1: ProtocolDescriptor;
342
376
  /**
343
377
  * Suilend adapter — contract-first, no SDK dependency.
344
378
  * Interacts directly with Suilend Move contracts via RPC + PTB moveCall.
@@ -387,4 +421,21 @@ declare class SuilendAdapter implements LendingAdapter {
387
421
  private fetchAllCoins;
388
422
  }
389
423
 
390
- 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, type LendingAdapter as L, type MaxWithdrawResult as M, NaviAdapter as N, type PositionsResult as P, type RepayResult as R, type SendResult as S, type T2000Options as T, type WithdrawResult as W, 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 SentinelAgent as i, type SentinelAttackResult as j, type SentinelVerdict as k, type AdapterPositions as l, type AdapterTxResult as m, type GasReserve as n, type HealthInfo as o, type PositionEntry as p, ProtocolRegistry as q, SuilendAdapter as r, type SwapQuote as s };
424
+ declare const descriptor: ProtocolDescriptor;
425
+ declare function listSentinels(): Promise<SentinelAgent[]>;
426
+ declare function getSentinelInfo(client: SuiJsonRpcClient, sentinelObjectId: string): Promise<SentinelAgent>;
427
+ declare function requestAttack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelObjectId: string, feeMist: bigint): Promise<{
428
+ attackObjectId: string;
429
+ digest: string;
430
+ }>;
431
+ declare function submitPrompt(agentId: string, attackObjectId: string, prompt: string): Promise<SentinelVerdict>;
432
+ declare function settleAttack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelObjectId: string, attackObjectId: string, prompt: string, verdict: SentinelVerdict): Promise<{
433
+ digest: string;
434
+ success: boolean;
435
+ }>;
436
+ declare function attack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelId: string, prompt: string, feeMist?: bigint): Promise<SentinelAttackResult>;
437
+
438
+ /** All registered protocol descriptors — used by the indexer for event classification */
439
+ declare const allDescriptors: ProtocolDescriptor[];
440
+
441
+ 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, attack as I, descriptor as J, settleAttack as K, type LendingAdapter as L, type MaxWithdrawResult as M, NaviAdapter as N, submitPrompt as O, type PositionsResult as P, descriptor$1 as Q, type RepayResult as R, type SendResult as S, type T2000Options as T, type WithdrawResult as W, 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 SentinelAgent as i, type SentinelAttackResult as j, type AdapterPositions as k, type AdapterTxResult as l, type GasReserve as m, type HealthInfo as n, type PositionEntry as o, type ProtocolDescriptor as p, ProtocolRegistry as q, type SentinelVerdict as r, SuilendAdapter as s, type SwapQuote as t, allDescriptors as u, descriptor$2 as v, getSentinelInfo as w, listSentinels as x, descriptor$3 as y, requestAttack as z };
@@ -1,7 +1,38 @@
1
1
  import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
2
2
  import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
3
+ import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
3
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
+ }
5
36
  interface AdapterTxResult {
6
37
  tx: Transaction;
7
38
  feeCoin?: TransactionObjectArgument;
@@ -292,6 +323,7 @@ declare class ProtocolRegistry {
292
323
  listSwap(): SwapAdapter[];
293
324
  }
294
325
 
326
+ declare const descriptor$3: ProtocolDescriptor;
295
327
  declare class NaviAdapter implements LendingAdapter {
296
328
  readonly id = "navi";
297
329
  readonly name = "NAVI Protocol";
@@ -319,6 +351,7 @@ declare class NaviAdapter implements LendingAdapter {
319
351
  maxBorrow(address: string, _asset: string): Promise<MaxBorrowResult>;
320
352
  }
321
353
 
354
+ declare const descriptor$2: ProtocolDescriptor;
322
355
  declare class CetusAdapter implements SwapAdapter {
323
356
  readonly id = "cetus";
324
357
  readonly name = "Cetus";
@@ -339,6 +372,7 @@ declare class CetusAdapter implements SwapAdapter {
339
372
  getPoolPrice(): Promise<number>;
340
373
  }
341
374
 
375
+ declare const descriptor$1: ProtocolDescriptor;
342
376
  /**
343
377
  * Suilend adapter — contract-first, no SDK dependency.
344
378
  * Interacts directly with Suilend Move contracts via RPC + PTB moveCall.
@@ -387,4 +421,21 @@ declare class SuilendAdapter implements LendingAdapter {
387
421
  private fetchAllCoins;
388
422
  }
389
423
 
390
- 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, type LendingAdapter as L, type MaxWithdrawResult as M, NaviAdapter as N, type PositionsResult as P, type RepayResult as R, type SendResult as S, type T2000Options as T, type WithdrawResult as W, 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 SentinelAgent as i, type SentinelAttackResult as j, type SentinelVerdict as k, type AdapterPositions as l, type AdapterTxResult as m, type GasReserve as n, type HealthInfo as o, type PositionEntry as p, ProtocolRegistry as q, SuilendAdapter as r, type SwapQuote as s };
424
+ declare const descriptor: ProtocolDescriptor;
425
+ declare function listSentinels(): Promise<SentinelAgent[]>;
426
+ declare function getSentinelInfo(client: SuiJsonRpcClient, sentinelObjectId: string): Promise<SentinelAgent>;
427
+ declare function requestAttack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelObjectId: string, feeMist: bigint): Promise<{
428
+ attackObjectId: string;
429
+ digest: string;
430
+ }>;
431
+ declare function submitPrompt(agentId: string, attackObjectId: string, prompt: string): Promise<SentinelVerdict>;
432
+ declare function settleAttack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelObjectId: string, attackObjectId: string, prompt: string, verdict: SentinelVerdict): Promise<{
433
+ digest: string;
434
+ success: boolean;
435
+ }>;
436
+ declare function attack(client: SuiJsonRpcClient, signer: Ed25519Keypair, sentinelId: string, prompt: string, feeMist?: bigint): Promise<SentinelAttackResult>;
437
+
438
+ /** All registered protocol descriptors — used by the indexer for event classification */
439
+ declare const allDescriptors: ProtocolDescriptor[];
440
+
441
+ 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, attack as I, descriptor as J, settleAttack as K, type LendingAdapter as L, type MaxWithdrawResult as M, NaviAdapter as N, submitPrompt as O, type PositionsResult as P, descriptor$1 as Q, type RepayResult as R, type SendResult as S, type T2000Options as T, type WithdrawResult as W, 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 SentinelAgent as i, type SentinelAttackResult as j, type AdapterPositions as k, type AdapterTxResult as l, type GasReserve as m, type HealthInfo as n, type PositionEntry as o, type ProtocolDescriptor as p, ProtocolRegistry as q, type SentinelVerdict as r, SuilendAdapter as s, type SwapQuote as t, allDescriptors as u, descriptor$2 as v, getSentinelInfo as w, listSentinels as x, descriptor$3 as y, requestAttack as z };
package/dist/index.cjs CHANGED
@@ -47,6 +47,7 @@ var DEFAULT_RPC_URL = "https://fullnode.mainnet.sui.io:443";
47
47
  var DEFAULT_KEY_PATH = "~/.t2000/wallet.key";
48
48
  var API_BASE_URL = process.env.T2000_API_URL ?? "https://api.t2000.ai";
49
49
  var CETUS_USDC_SUI_POOL = "0x51e883ba7c0b566a26cbc8a94cd33eb0abd418a77cc1e60ad22fd9b1f29cd2ab";
50
+ var CETUS_PACKAGE = "0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb";
50
51
  var SENTINEL = {
51
52
  PACKAGE: "0x88b83f36dafcd5f6dcdcf1d2cb5889b03f61264ab3cee9cae35db7aa940a21b7",
52
53
  AGENT_REGISTRY: "0xc47564f5f14c12b31e0dfa1a3dc99a6380a1edf8929c28cb0eaa3359c8db36ac",
@@ -854,6 +855,15 @@ async function getFundStatus(client, keypair) {
854
855
  projectedMonthly: earnings.dailyEarning * 30
855
856
  };
856
857
  }
858
+ var descriptor = {
859
+ id: "sentinel",
860
+ name: "Sui Sentinel",
861
+ packages: [SENTINEL.PACKAGE],
862
+ actionMap: {
863
+ "sentinel::request_attack": "sentinel_attack",
864
+ "sentinel::consume_prompt": "sentinel_settle"
865
+ }
866
+ };
857
867
  function mapAgent(raw) {
858
868
  return {
859
869
  id: raw.agent_id,
@@ -1141,6 +1151,22 @@ var ProtocolRegistry = class {
1141
1151
  };
1142
1152
 
1143
1153
  // src/adapters/navi.ts
1154
+ var descriptor2 = {
1155
+ id: "navi",
1156
+ name: "NAVI Protocol",
1157
+ packages: [],
1158
+ dynamicPackageId: true,
1159
+ actionMap: {
1160
+ "incentive_v3::entry_deposit": "save",
1161
+ "incentive_v3::deposit": "save",
1162
+ "incentive_v3::withdraw_v2": "withdraw",
1163
+ "incentive_v3::entry_withdraw": "withdraw",
1164
+ "incentive_v3::borrow_v2": "borrow",
1165
+ "incentive_v3::entry_borrow": "borrow",
1166
+ "incentive_v3::entry_repay": "repay",
1167
+ "incentive_v3::repay": "repay"
1168
+ }
1169
+ };
1144
1170
  var NaviAdapter = class {
1145
1171
  id = "navi";
1146
1172
  name = "NAVI Protocol";
@@ -1285,6 +1311,18 @@ function fallbackQuote(fromAsset, amount, poolPrice) {
1285
1311
  }
1286
1312
 
1287
1313
  // src/adapters/cetus.ts
1314
+ var descriptor3 = {
1315
+ id: "cetus",
1316
+ name: "Cetus DEX",
1317
+ packages: [CETUS_PACKAGE],
1318
+ actionMap: {
1319
+ "router::swap": "swap",
1320
+ "router::swap_ab_bc": "swap",
1321
+ "router::swap_ab_cb": "swap",
1322
+ "router::swap_ba_bc": "swap",
1323
+ "router::swap_ba_cb": "swap"
1324
+ }
1325
+ };
1288
1326
  var CetusAdapter = class {
1289
1327
  id = "cetus";
1290
1328
  name = "Cetus";
@@ -1339,6 +1377,20 @@ var LENDING_MARKET_TYPE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea3
1339
1377
  var SUILEND_PACKAGE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf";
1340
1378
  var UPGRADE_CAP_ID = "0x3d4ef1859c3ee9fc72858f588b56a09da5466e64f8cc4e90a7b3b909fba8a7ae";
1341
1379
  var FALLBACK_PUBLISHED_AT = "0xd2a67633ccb8de063163e25bcfca242929caf5cf1a26c2929dab519ee0b8f331";
1380
+ var descriptor4 = {
1381
+ id: "suilend",
1382
+ name: "Suilend",
1383
+ packages: [SUILEND_PACKAGE],
1384
+ actionMap: {
1385
+ "lending_market::deposit_liquidity_and_mint_ctokens": "save",
1386
+ "lending_market::deposit_ctokens_into_obligation": "save",
1387
+ "lending_market::create_obligation": "save",
1388
+ "lending_market::withdraw_ctokens": "withdraw",
1389
+ "lending_market::redeem_ctokens_and_withdraw_liquidity": "withdraw",
1390
+ "lending_market::borrow": "borrow",
1391
+ "lending_market::repay": "repay"
1392
+ }
1393
+ };
1342
1394
  function interpolateRate(utilBreakpoints, aprBreakpoints, utilizationPct) {
1343
1395
  if (utilBreakpoints.length === 0) return 0;
1344
1396
  if (utilizationPct <= utilBreakpoints[0]) return aprBreakpoints[0];
@@ -2517,6 +2569,14 @@ function parseMoveAbort(errorStr) {
2517
2569
  return { reason: errorStr };
2518
2570
  }
2519
2571
 
2572
+ // src/adapters/index.ts
2573
+ var allDescriptors = [
2574
+ descriptor2,
2575
+ descriptor4,
2576
+ descriptor3,
2577
+ descriptor
2578
+ ];
2579
+
2520
2580
  exports.BPS_DENOMINATOR = BPS_DENOMINATOR;
2521
2581
  exports.CLOCK_ID = CLOCK_ID;
2522
2582
  exports.CetusAdapter = CetusAdapter;
@@ -2532,7 +2592,9 @@ exports.T2000 = T2000;
2532
2592
  exports.T2000Error = T2000Error;
2533
2593
  exports.USDC_DECIMALS = USDC_DECIMALS;
2534
2594
  exports.addCollectFeeToTx = addCollectFeeToTx;
2595
+ exports.allDescriptors = allDescriptors;
2535
2596
  exports.calculateFee = calculateFee;
2597
+ exports.cetusDescriptor = descriptor3;
2536
2598
  exports.executeAutoTopUp = executeAutoTopUp;
2537
2599
  exports.executeWithGas = executeWithGas;
2538
2600
  exports.exportPrivateKey = exportPrivateKey;
@@ -2551,16 +2613,19 @@ exports.loadKey = loadKey;
2551
2613
  exports.mapMoveAbortCode = mapMoveAbortCode;
2552
2614
  exports.mapWalletError = mapWalletError;
2553
2615
  exports.mistToSui = mistToSui;
2616
+ exports.naviDescriptor = descriptor2;
2554
2617
  exports.rawToUsdc = rawToUsdc;
2555
2618
  exports.requestAttack = requestAttack;
2556
2619
  exports.saveKey = saveKey;
2557
2620
  exports.sentinelAttack = attack;
2621
+ exports.sentinelDescriptor = descriptor;
2558
2622
  exports.settleAttack = settleAttack;
2559
2623
  exports.shouldAutoTopUp = shouldAutoTopUp;
2560
2624
  exports.simulateTransaction = simulateTransaction;
2561
2625
  exports.solveHashcash = solveHashcash;
2562
2626
  exports.submitPrompt = submitPrompt;
2563
2627
  exports.suiToMist = suiToMist;
2628
+ exports.suilendDescriptor = descriptor4;
2564
2629
  exports.throwIfSimulationFailed = throwIfSimulationFailed;
2565
2630
  exports.truncateAddress = truncateAddress;
2566
2631
  exports.usdcToRaw = usdcToRaw;