@t2000/sdk 0.19.21 → 0.19.22

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.cjs CHANGED
@@ -11,7 +11,6 @@ var promises = require('fs/promises');
11
11
  var path = require('path');
12
12
  var os = require('os');
13
13
  var lending = require('@naviprotocol/lending');
14
- var bcs = require('@mysten/sui/bcs');
15
14
  var aggregatorSdk = require('@cetusprotocol/aggregator-sdk');
16
15
  var client = require('@suilend/sdk/client');
17
16
  var initialize = require('@suilend/sdk/lib/initialize');
@@ -135,18 +134,6 @@ var PERPS_MARKETS = ["SUI-PERP"];
135
134
  var DEFAULT_MAX_LEVERAGE = 5;
136
135
  var DEFAULT_MAX_POSITION_SIZE = 1e3;
137
136
  var GAS_RESERVE_MIN = 0.05;
138
- var SENTINEL = {
139
- PACKAGE: "0x88b83f36dafcd5f6dcdcf1d2cb5889b03f61264ab3cee9cae35db7aa940a21b7",
140
- AGENT_REGISTRY: "0xc47564f5f14c12b31e0dfa1a3dc99a6380a1edf8929c28cb0eaa3359c8db36ac",
141
- ENCLAVE: "0xfb1261aeb9583514cb1341a548a5ec12d1231bd96af22215f1792617a93e1213",
142
- PROTOCOL_CONFIG: "0x2fa4fa4a1dd0498612304635ff9334e1b922e78af325000e9d9c0e88adea459f",
143
- TEE_API: "https://app.suisentinel.xyz/api/consume-prompt",
144
- SENTINELS_API: "https://api.suisentinel.xyz/agents/mainnet",
145
- RANDOM: "0x8",
146
- MIN_FEE_MIST: 100000000n,
147
- // 0.1 SUI
148
- MAX_PROMPT_TOKENS: 600
149
- };
150
137
 
151
138
  // src/errors.ts
152
139
  var T2000Error = class extends Error {
@@ -929,6 +916,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
929
916
  }
930
917
  async function addWithdrawToTx(tx, client, address, amount, options = {}) {
931
918
  const asset = options.asset ?? "USDC";
919
+ const sponsored = options.sponsored ?? true;
932
920
  const assetInfo = resolveAssetInfo(asset);
933
921
  const posResult = await getPositions(client, address);
934
922
  const supply = posResult.positions.find(
@@ -946,7 +934,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
946
934
  });
947
935
  return { coin, effectiveAmount: 0 };
948
936
  }
949
- await refreshOracle(tx, client, address);
937
+ await refreshOracle(tx, client, address, { skipPythUpdate: sponsored });
950
938
  try {
951
939
  const coin = await lending.withdrawCoinPTB(tx, assetInfo.type, rawAmount, sdkOptions(client));
952
940
  return { coin, effectiveAmount };
@@ -970,8 +958,9 @@ async function addSaveToTx(tx, _client, _address, coin, options = {}) {
970
958
  }
971
959
  async function addRepayToTx(tx, client, address, coin, options = {}) {
972
960
  const asset = options.asset ?? "USDC";
961
+ const sponsored = options.sponsored ?? true;
973
962
  const assetInfo = resolveAssetInfo(asset);
974
- await refreshOracle(tx, client, address);
963
+ await refreshOracle(tx, client, address, { skipPythUpdate: sponsored });
975
964
  try {
976
965
  await lending.repayCoinPTB(tx, assetInfo.type, coin, { env: "prod" });
977
966
  } catch (err) {
@@ -1132,206 +1121,6 @@ async function getFundStatus(client, address) {
1132
1121
  projectedMonthly: earnings.dailyEarning * 30
1133
1122
  };
1134
1123
  }
1135
- var descriptor = {
1136
- id: "sentinel",
1137
- name: "Sui Sentinel",
1138
- packages: [SENTINEL.PACKAGE],
1139
- actionMap: {
1140
- "sentinel::request_attack": "sentinel_attack",
1141
- "sentinel::consume_prompt": "sentinel_settle"
1142
- }
1143
- };
1144
- function mapAgent(raw) {
1145
- return {
1146
- id: raw.agent_id,
1147
- objectId: raw.agent_object_id,
1148
- name: raw.agent_name,
1149
- model: raw.model ?? "unknown",
1150
- systemPrompt: raw.prompt,
1151
- attackFee: BigInt(raw.cost_per_message),
1152
- prizePool: BigInt(raw.total_balance),
1153
- totalAttacks: raw.total_attacks,
1154
- successfulBreaches: raw.successful_breaches ?? 0,
1155
- state: raw.state
1156
- };
1157
- }
1158
- async function listSentinels() {
1159
- const res = await fetch(SENTINEL.SENTINELS_API);
1160
- if (!res.ok) {
1161
- throw new T2000Error("SENTINEL_API_ERROR", `Sentinel API returned ${res.status}`);
1162
- }
1163
- const data = await res.json();
1164
- if (!Array.isArray(data.agents)) {
1165
- throw new T2000Error("SENTINEL_API_ERROR", "Unexpected API response shape");
1166
- }
1167
- return data.agents.filter((a) => a.state === "active").map(mapAgent);
1168
- }
1169
- async function getSentinelInfo(client, sentinelObjectId) {
1170
- const agents = await listSentinels();
1171
- const match = agents.find((a) => a.objectId === sentinelObjectId || a.id === sentinelObjectId);
1172
- if (match) return match;
1173
- const obj = await client.getObject({
1174
- id: sentinelObjectId,
1175
- options: { showContent: true, showType: true }
1176
- });
1177
- if (!obj.data) {
1178
- throw new T2000Error("SENTINEL_NOT_FOUND", `Sentinel ${sentinelObjectId} not found on-chain`);
1179
- }
1180
- const content = obj.data.content;
1181
- if (!content || content.dataType !== "moveObject") {
1182
- throw new T2000Error("SENTINEL_NOT_FOUND", `Object ${sentinelObjectId} is not a Move object`);
1183
- }
1184
- const fields = content.fields;
1185
- return {
1186
- id: fields.id?.id ?? sentinelObjectId,
1187
- objectId: sentinelObjectId,
1188
- name: fields.name ?? "Unknown",
1189
- model: fields.model ?? "unknown",
1190
- systemPrompt: fields.system_prompt ?? "",
1191
- attackFee: BigInt(fields.cost_per_message ?? "0"),
1192
- prizePool: BigInt(fields.balance ?? "0"),
1193
- totalAttacks: Number(fields.total_attacks ?? "0"),
1194
- successfulBreaches: Number(fields.successful_breaches ?? "0"),
1195
- state: fields.state ?? "unknown"
1196
- };
1197
- }
1198
- async function requestAttack(client, signer, sentinelObjectId, feeMist) {
1199
- if (feeMist < SENTINEL.MIN_FEE_MIST) {
1200
- throw new T2000Error("INVALID_AMOUNT", `Attack fee must be at least 0.1 SUI (${SENTINEL.MIN_FEE_MIST} MIST)`);
1201
- }
1202
- const address = signer.getAddress();
1203
- const tx = new transactions.Transaction();
1204
- tx.setSender(address);
1205
- const [coin] = tx.splitCoins(tx.gas, [Number(feeMist)]);
1206
- const [attack2] = tx.moveCall({
1207
- target: `${SENTINEL.PACKAGE}::sentinel::request_attack`,
1208
- arguments: [
1209
- tx.object(SENTINEL.AGENT_REGISTRY),
1210
- tx.object(sentinelObjectId),
1211
- tx.object(SENTINEL.PROTOCOL_CONFIG),
1212
- coin,
1213
- tx.object(SENTINEL.RANDOM),
1214
- tx.object(CLOCK_ID)
1215
- ]
1216
- });
1217
- tx.transferObjects([attack2], address);
1218
- const built = await tx.build({ client });
1219
- const { signature } = await signer.signTransaction(built);
1220
- const result = await client.executeTransactionBlock({
1221
- transactionBlock: built,
1222
- signature,
1223
- options: { showObjectChanges: true, showEffects: true }
1224
- });
1225
- await client.waitForTransaction({ digest: result.digest });
1226
- const attackObj = result.objectChanges?.find(
1227
- (c) => c.type === "created" && c.objectType?.includes("::sentinel::Attack")
1228
- );
1229
- const attackObjectId = attackObj && "objectId" in attackObj ? attackObj.objectId : void 0;
1230
- if (!attackObjectId) {
1231
- throw new T2000Error("SENTINEL_TX_FAILED", "Attack object was not created \u2014 transaction may have failed");
1232
- }
1233
- return { attackObjectId, digest: result.digest };
1234
- }
1235
- async function submitPrompt(agentId, attackObjectId, prompt) {
1236
- const res = await fetch(SENTINEL.TEE_API, {
1237
- method: "POST",
1238
- headers: { "Content-Type": "application/json" },
1239
- body: JSON.stringify({
1240
- agent_id: agentId,
1241
- attack_object_id: attackObjectId,
1242
- message: prompt
1243
- })
1244
- });
1245
- if (!res.ok) {
1246
- const body = await res.text().catch(() => "");
1247
- throw new T2000Error("SENTINEL_TEE_ERROR", `TEE returned ${res.status}: ${body.slice(0, 200)}`);
1248
- }
1249
- const raw = await res.json();
1250
- const envelope = raw.response ?? raw;
1251
- const data = envelope.data ?? envelope;
1252
- const signature = raw.signature ?? data.signature;
1253
- const timestampMs = envelope.timestamp_ms ?? data.timestamp_ms;
1254
- if (typeof signature !== "string") {
1255
- throw new T2000Error("SENTINEL_TEE_ERROR", "TEE response missing signature");
1256
- }
1257
- return {
1258
- success: data.success ?? data.is_success,
1259
- score: data.score,
1260
- agentResponse: data.agent_response,
1261
- juryResponse: data.jury_response,
1262
- funResponse: data.fun_response ?? "",
1263
- signature,
1264
- timestampMs
1265
- };
1266
- }
1267
- async function settleAttack(client, signer, sentinelObjectId, attackObjectId, prompt, verdict) {
1268
- const sigBytes = Array.from(Buffer.from(verdict.signature.replace(/^0x/, ""), "hex"));
1269
- const address = signer.getAddress();
1270
- const tx = new transactions.Transaction();
1271
- tx.setSender(address);
1272
- tx.moveCall({
1273
- target: `${SENTINEL.PACKAGE}::sentinel::consume_prompt`,
1274
- arguments: [
1275
- tx.object(SENTINEL.AGENT_REGISTRY),
1276
- tx.object(SENTINEL.PROTOCOL_CONFIG),
1277
- tx.object(sentinelObjectId),
1278
- tx.pure.bool(verdict.success),
1279
- tx.pure.string(verdict.agentResponse),
1280
- tx.pure.string(verdict.juryResponse),
1281
- tx.pure.string(verdict.funResponse),
1282
- tx.pure.string(prompt),
1283
- tx.pure.u8(verdict.score),
1284
- tx.pure.u64(verdict.timestampMs),
1285
- tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(sigBytes)),
1286
- tx.object(SENTINEL.ENCLAVE),
1287
- tx.object(attackObjectId),
1288
- tx.object(CLOCK_ID)
1289
- ]
1290
- });
1291
- const built = await tx.build({ client });
1292
- const { signature } = await signer.signTransaction(built);
1293
- const result = await client.executeTransactionBlock({
1294
- transactionBlock: built,
1295
- signature,
1296
- options: { showEffects: true }
1297
- });
1298
- await client.waitForTransaction({ digest: result.digest });
1299
- const txSuccess = result.effects?.status?.status === "success";
1300
- return { digest: result.digest, success: txSuccess };
1301
- }
1302
- async function attack(client, signer, sentinelId, prompt, feeMist) {
1303
- const sentinel = await getSentinelInfo(client, sentinelId);
1304
- const fee = feeMist ?? sentinel.attackFee;
1305
- if (fee < SENTINEL.MIN_FEE_MIST) {
1306
- throw new T2000Error("INVALID_AMOUNT", `Attack fee must be at least 0.1 SUI`);
1307
- }
1308
- const { attackObjectId, digest: requestTx } = await requestAttack(
1309
- client,
1310
- signer,
1311
- sentinel.objectId,
1312
- fee
1313
- );
1314
- const verdict = await submitPrompt(sentinel.id, attackObjectId, prompt);
1315
- const { digest: settleTx } = await settleAttack(
1316
- client,
1317
- signer,
1318
- sentinel.objectId,
1319
- attackObjectId,
1320
- prompt,
1321
- verdict
1322
- );
1323
- const won = verdict.success && verdict.score >= 70;
1324
- return {
1325
- attackObjectId,
1326
- sentinelId: sentinel.id,
1327
- prompt,
1328
- verdict,
1329
- requestTx,
1330
- settleTx,
1331
- won,
1332
- feePaid: Number(fee) / Number(MIST_PER_SUI)
1333
- };
1334
- }
1335
1124
 
1336
1125
  // src/adapters/registry.ts
1337
1126
  var ProtocolRegistry = class {
@@ -1478,8 +1267,9 @@ var ProtocolRegistry = class {
1478
1267
  }
1479
1268
  };
1480
1269
 
1481
- // src/adapters/navi.ts
1482
- var descriptor2 = {
1270
+ // src/adapters/descriptors.ts
1271
+ var SUILEND_PACKAGE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf";
1272
+ var naviDescriptor = {
1483
1273
  id: "navi",
1484
1274
  name: "NAVI Protocol",
1485
1275
  packages: [],
@@ -1495,6 +1285,42 @@ var descriptor2 = {
1495
1285
  "incentive_v3::repay": "repay"
1496
1286
  }
1497
1287
  };
1288
+ var suilendDescriptor = {
1289
+ id: "suilend",
1290
+ name: "Suilend",
1291
+ packages: [SUILEND_PACKAGE],
1292
+ actionMap: {
1293
+ "lending_market::deposit_liquidity_and_mint_ctokens": "save",
1294
+ "lending_market::deposit_ctokens_into_obligation": "save",
1295
+ "lending_market::create_obligation": "save",
1296
+ "lending_market::withdraw_ctokens": "withdraw",
1297
+ "lending_market::redeem_ctokens_and_withdraw_liquidity": "withdraw",
1298
+ "lending_market::redeem_ctokens_and_withdraw_liquidity_request": "withdraw",
1299
+ "lending_market::fulfill_liquidity_request": "withdraw",
1300
+ "lending_market::unstake_sui_from_staker": "withdraw",
1301
+ "lending_market::borrow": "borrow",
1302
+ "lending_market::repay": "repay"
1303
+ }
1304
+ };
1305
+ var cetusDescriptor = {
1306
+ id: "cetus",
1307
+ name: "Cetus DEX",
1308
+ packages: [CETUS_PACKAGE],
1309
+ actionMap: {
1310
+ "router::swap": "swap",
1311
+ "router::swap_ab_bc": "swap",
1312
+ "router::swap_ab_cb": "swap",
1313
+ "router::swap_ba_bc": "swap",
1314
+ "router::swap_ba_cb": "swap"
1315
+ }
1316
+ };
1317
+ var allDescriptors = [
1318
+ naviDescriptor,
1319
+ suilendDescriptor,
1320
+ cetusDescriptor
1321
+ ];
1322
+
1323
+ // src/adapters/navi.ts
1498
1324
  var NaviAdapter = class {
1499
1325
  id = "navi";
1500
1326
  name = "NAVI Protocol";
@@ -1774,18 +1600,6 @@ function fallbackQuote(fromAsset, amount, poolPrice) {
1774
1600
  }
1775
1601
 
1776
1602
  // src/adapters/cetus.ts
1777
- var descriptor3 = {
1778
- id: "cetus",
1779
- name: "Cetus DEX",
1780
- packages: [CETUS_PACKAGE],
1781
- actionMap: {
1782
- "router::swap": "swap",
1783
- "router::swap_ab_bc": "swap",
1784
- "router::swap_ab_cb": "swap",
1785
- "router::swap_ba_bc": "swap",
1786
- "router::swap_ba_cb": "swap"
1787
- }
1788
- };
1789
1603
  var CetusAdapter = class {
1790
1604
  id = "cetus";
1791
1605
  name = "Cetus";
@@ -1844,7 +1658,6 @@ var CetusAdapter = class {
1844
1658
  });
1845
1659
  }
1846
1660
  };
1847
- var SUILEND_PACKAGE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf";
1848
1661
  var MIN_HEALTH_FACTOR2 = 1.5;
1849
1662
  async function quietSuilend(fn) {
1850
1663
  const origLog = console.log;
@@ -1861,23 +1674,6 @@ async function quietSuilend(fn) {
1861
1674
  console.warn = origWarn;
1862
1675
  });
1863
1676
  }
1864
- var descriptor4 = {
1865
- id: "suilend",
1866
- name: "Suilend",
1867
- packages: [SUILEND_PACKAGE],
1868
- actionMap: {
1869
- "lending_market::deposit_liquidity_and_mint_ctokens": "save",
1870
- "lending_market::deposit_ctokens_into_obligation": "save",
1871
- "lending_market::create_obligation": "save",
1872
- "lending_market::withdraw_ctokens": "withdraw",
1873
- "lending_market::redeem_ctokens_and_withdraw_liquidity": "withdraw",
1874
- "lending_market::redeem_ctokens_and_withdraw_liquidity_request": "withdraw",
1875
- "lending_market::fulfill_liquidity_request": "withdraw",
1876
- "lending_market::unstake_sui_from_staker": "withdraw",
1877
- "lending_market::borrow": "borrow",
1878
- "lending_market::repay": "repay"
1879
- }
1880
- };
1881
1677
  var SuilendAdapter = class {
1882
1678
  id = "suilend";
1883
1679
  name = "Suilend";
@@ -2685,8 +2481,7 @@ async function resolveGas(client, signer, buildTx) {
2685
2481
  // src/safeguards/types.ts
2686
2482
  var OUTBOUND_OPS = /* @__PURE__ */ new Set([
2687
2483
  "send",
2688
- "pay",
2689
- "sentinel"
2484
+ "pay"
2690
2485
  ]);
2691
2486
  var DEFAULT_SAFEGUARD_CONFIG = {
2692
2487
  locked: false,
@@ -5954,17 +5749,6 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
5954
5749
  async fundStatus() {
5955
5750
  return getFundStatus(this.client, this._address);
5956
5751
  }
5957
- // -- Sentinel --
5958
- async sentinelList() {
5959
- return listSentinels();
5960
- }
5961
- async sentinelInfo(id) {
5962
- return getSentinelInfo(this.client, id);
5963
- }
5964
- async sentinelAttack(id, prompt, fee) {
5965
- this.enforcer.check({ operation: "sentinel", amount: fee ? Number(fee) / 1e9 : 0.1 });
5966
- return attack(this.client, this._signer, id, prompt, fee);
5967
- }
5968
5752
  // -- Helpers --
5969
5753
  async getFreeBalance(asset) {
5970
5754
  if (!(asset in INVESTMENT_ASSETS)) return Infinity;
@@ -6117,14 +5901,6 @@ function parseMoveAbort(errorStr) {
6117
5901
  return { reason: errorStr };
6118
5902
  }
6119
5903
 
6120
- // src/adapters/index.ts
6121
- var allDescriptors = [
6122
- descriptor2,
6123
- descriptor4,
6124
- descriptor3,
6125
- descriptor
6126
- ];
6127
-
6128
5904
  exports.AutoInvestManager = AutoInvestManager;
6129
5905
  exports.BPS_DENOMINATOR = BPS_DENOMINATOR;
6130
5906
  exports.CLOCK_ID = CLOCK_ID;
@@ -6144,7 +5920,6 @@ exports.OUTBOUND_OPS = OUTBOUND_OPS;
6144
5920
  exports.PERPS_MARKETS = PERPS_MARKETS;
6145
5921
  exports.PortfolioManager = PortfolioManager;
6146
5922
  exports.ProtocolRegistry = ProtocolRegistry;
6147
- exports.SENTINEL = SENTINEL;
6148
5923
  exports.STABLE_ASSETS = STABLE_ASSETS;
6149
5924
  exports.SUI_DECIMALS = SUI_DECIMALS;
6150
5925
  exports.SUPPORTED_ASSETS = SUPPORTED_ASSETS;
@@ -6159,7 +5934,7 @@ exports.ZkLoginSigner = ZkLoginSigner;
6159
5934
  exports.addCollectFeeToTx = addCollectFeeToTx;
6160
5935
  exports.allDescriptors = allDescriptors;
6161
5936
  exports.calculateFee = calculateFee;
6162
- exports.cetusDescriptor = descriptor3;
5937
+ exports.cetusDescriptor = cetusDescriptor;
6163
5938
  exports.executeAutoTopUp = executeAutoTopUp;
6164
5939
  exports.executeWithGas = executeWithGas;
6165
5940
  exports.exportPrivateKey = exportPrivateKey;
@@ -6172,28 +5947,21 @@ exports.getDecimals = getDecimals;
6172
5947
  exports.getGasStatus = getGasStatus;
6173
5948
  exports.getPoolPrice = getPoolPrice;
6174
5949
  exports.getRates = getRates;
6175
- exports.getSentinelInfo = getSentinelInfo;
6176
5950
  exports.keypairFromPrivateKey = keypairFromPrivateKey;
6177
- exports.listSentinels = listSentinels;
6178
5951
  exports.loadKey = loadKey;
6179
5952
  exports.mapMoveAbortCode = mapMoveAbortCode;
6180
5953
  exports.mapWalletError = mapWalletError;
6181
5954
  exports.mistToSui = mistToSui;
6182
- exports.naviDescriptor = descriptor2;
5955
+ exports.naviDescriptor = naviDescriptor;
6183
5956
  exports.rawToStable = rawToStable;
6184
5957
  exports.rawToUsdc = rawToUsdc;
6185
- exports.requestAttack = requestAttack;
6186
5958
  exports.saveKey = saveKey;
6187
- exports.sentinelAttack = attack;
6188
- exports.sentinelDescriptor = descriptor;
6189
- exports.settleAttack = settleAttack;
6190
5959
  exports.shouldAutoTopUp = shouldAutoTopUp;
6191
5960
  exports.simulateTransaction = simulateTransaction;
6192
5961
  exports.solveHashcash = solveHashcash;
6193
5962
  exports.stableToRaw = stableToRaw;
6194
- exports.submitPrompt = submitPrompt;
6195
5963
  exports.suiToMist = suiToMist;
6196
- exports.suilendDescriptor = descriptor4;
5964
+ exports.suilendDescriptor = suilendDescriptor;
6197
5965
  exports.throwIfSimulationFailed = throwIfSimulationFailed;
6198
5966
  exports.truncateAddress = truncateAddress;
6199
5967
  exports.usdcToRaw = usdcToRaw;