@t2000/sdk 0.19.21 → 0.19.23
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/README.md +0 -9
- package/dist/adapters/descriptors.cjs +68 -0
- package/dist/adapters/descriptors.cjs.map +1 -0
- package/dist/adapters/descriptors.d.cts +3 -0
- package/dist/adapters/descriptors.d.ts +3 -0
- package/dist/adapters/descriptors.js +63 -0
- package/dist/adapters/descriptors.js.map +1 -0
- package/dist/adapters/index.cjs +52 -60
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +171 -3
- package/dist/adapters/index.d.ts +171 -3
- package/dist/adapters/index.js +50 -57
- package/dist/adapters/index.js.map +1 -1
- package/dist/browser.js +4 -15
- package/dist/browser.js.map +1 -1
- package/dist/{index-CRyFiIZm.d.cts → descriptors-B6qt_mwi.d.cts} +4 -226
- package/dist/{index-CRyFiIZm.d.ts → descriptors-B6qt_mwi.d.ts} +4 -226
- package/dist/index.cjs +86 -282
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -20
- package/dist/index.d.ts +19 -20
- package/dist/index.js +84 -272
- package/dist/index.js.map +1 -1
- package/package.json +7 -2
package/dist/index.js
CHANGED
|
@@ -9,7 +9,6 @@ import { access, mkdir, writeFile, readFile } from 'fs/promises';
|
|
|
9
9
|
import { join, dirname, resolve } from 'path';
|
|
10
10
|
import { homedir } from 'os';
|
|
11
11
|
import { getPools, getLendingPositions, getHealthFactor as getHealthFactor$1, depositCoinPTB, withdrawCoinPTB, borrowCoinPTB, repayCoinPTB, getUserAvailableLendingRewards, summaryLendingRewards, claimLendingRewardsPTB, updateOraclePriceBeforeUserOperationPTB } from '@naviprotocol/lending';
|
|
12
|
-
import { bcs } from '@mysten/sui/bcs';
|
|
13
12
|
import { AggregatorClient, Env } from '@cetusprotocol/aggregator-sdk';
|
|
14
13
|
import { SuilendClient, LENDING_MARKET_ID, LENDING_MARKET_TYPE } from '@suilend/sdk/client';
|
|
15
14
|
import { initializeSuilend, initializeObligations } from '@suilend/sdk/lib/initialize';
|
|
@@ -133,18 +132,6 @@ var PERPS_MARKETS = ["SUI-PERP"];
|
|
|
133
132
|
var DEFAULT_MAX_LEVERAGE = 5;
|
|
134
133
|
var DEFAULT_MAX_POSITION_SIZE = 1e3;
|
|
135
134
|
var GAS_RESERVE_MIN = 0.05;
|
|
136
|
-
var SENTINEL = {
|
|
137
|
-
PACKAGE: "0x88b83f36dafcd5f6dcdcf1d2cb5889b03f61264ab3cee9cae35db7aa940a21b7",
|
|
138
|
-
AGENT_REGISTRY: "0xc47564f5f14c12b31e0dfa1a3dc99a6380a1edf8929c28cb0eaa3359c8db36ac",
|
|
139
|
-
ENCLAVE: "0xfb1261aeb9583514cb1341a548a5ec12d1231bd96af22215f1792617a93e1213",
|
|
140
|
-
PROTOCOL_CONFIG: "0x2fa4fa4a1dd0498612304635ff9334e1b922e78af325000e9d9c0e88adea459f",
|
|
141
|
-
TEE_API: "https://app.suisentinel.xyz/api/consume-prompt",
|
|
142
|
-
SENTINELS_API: "https://api.suisentinel.xyz/agents/mainnet",
|
|
143
|
-
RANDOM: "0x8",
|
|
144
|
-
MIN_FEE_MIST: 100000000n,
|
|
145
|
-
// 0.1 SUI
|
|
146
|
-
MAX_PROMPT_TOKENS: 600
|
|
147
|
-
};
|
|
148
135
|
|
|
149
136
|
// src/errors.ts
|
|
150
137
|
var T2000Error = class extends Error {
|
|
@@ -194,6 +181,8 @@ function mapMoveAbortCode(code) {
|
|
|
194
181
|
1503: 'Withdrawal amount is invalid (zero or dust) \u2014 try a specific amount instead of "all"',
|
|
195
182
|
1600: "Health factor too low \u2014 withdrawal would risk liquidation",
|
|
196
183
|
1605: "Asset borrowing is disabled or at capacity on this protocol",
|
|
184
|
+
// NAVI utils abort codes
|
|
185
|
+
46e3: "Insufficient balance to repay \u2014 withdraw some savings first to get cash",
|
|
197
186
|
// Cetus DEX abort codes
|
|
198
187
|
46001: "Swap failed \u2014 the DEX pool rejected the trade (liquidity or routing issue). Try again."
|
|
199
188
|
};
|
|
@@ -927,6 +916,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
927
916
|
}
|
|
928
917
|
async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
929
918
|
const asset = options.asset ?? "USDC";
|
|
919
|
+
const sponsored = options.sponsored ?? true;
|
|
930
920
|
const assetInfo = resolveAssetInfo(asset);
|
|
931
921
|
const posResult = await getPositions(client, address);
|
|
932
922
|
const supply = posResult.positions.find(
|
|
@@ -944,7 +934,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
|
944
934
|
});
|
|
945
935
|
return { coin, effectiveAmount: 0 };
|
|
946
936
|
}
|
|
947
|
-
await refreshOracle(tx, client, address);
|
|
937
|
+
await refreshOracle(tx, client, address, { skipPythUpdate: sponsored });
|
|
948
938
|
try {
|
|
949
939
|
const coin = await withdrawCoinPTB(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
950
940
|
return { coin, effectiveAmount };
|
|
@@ -968,8 +958,9 @@ async function addSaveToTx(tx, _client, _address, coin, options = {}) {
|
|
|
968
958
|
}
|
|
969
959
|
async function addRepayToTx(tx, client, address, coin, options = {}) {
|
|
970
960
|
const asset = options.asset ?? "USDC";
|
|
961
|
+
const sponsored = options.sponsored ?? true;
|
|
971
962
|
const assetInfo = resolveAssetInfo(asset);
|
|
972
|
-
await refreshOracle(tx, client, address);
|
|
963
|
+
await refreshOracle(tx, client, address, { skipPythUpdate: sponsored });
|
|
973
964
|
try {
|
|
974
965
|
await repayCoinPTB(tx, assetInfo.type, coin, { env: "prod" });
|
|
975
966
|
} catch (err) {
|
|
@@ -1006,12 +997,16 @@ async function buildRepayTx(client, address, amount, options = {}) {
|
|
|
1006
997
|
const asset = options.asset ?? "USDC";
|
|
1007
998
|
const assetInfo = resolveAssetInfo(asset);
|
|
1008
999
|
const coins = await fetchCoins(client, address, assetInfo.type);
|
|
1009
|
-
if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", `No ${assetInfo.displayName} coins to repay with
|
|
1000
|
+
if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", `No ${assetInfo.displayName} coins to repay with. Withdraw some savings first to get cash.`);
|
|
1010
1001
|
const totalBalance = coins.reduce((sum, c) => sum + BigInt(c.balance), 0n);
|
|
1002
|
+
const rawRequested = Number(stableToRaw(amount, assetInfo.decimals));
|
|
1003
|
+
if (Number(totalBalance) < rawRequested && Number(totalBalance) < 1e3) {
|
|
1004
|
+
throw new T2000Error("INSUFFICIENT_BALANCE", `Not enough ${assetInfo.displayName} to repay (need $${amount.toFixed(2)}, wallet has ~$${(Number(totalBalance) / 10 ** assetInfo.decimals).toFixed(4)}). Withdraw some savings first.`);
|
|
1005
|
+
}
|
|
1011
1006
|
const tx = new Transaction();
|
|
1012
1007
|
tx.setSender(address);
|
|
1013
1008
|
const coinObj = mergeCoins(tx, coins);
|
|
1014
|
-
const rawAmount = Math.min(
|
|
1009
|
+
const rawAmount = Math.min(rawRequested, Number(totalBalance));
|
|
1015
1010
|
const [repayCoin] = tx.splitCoins(coinObj, [rawAmount]);
|
|
1016
1011
|
await refreshOracle(tx, client, address, {
|
|
1017
1012
|
skipPythUpdate: options.sponsored,
|
|
@@ -1130,206 +1125,6 @@ async function getFundStatus(client, address) {
|
|
|
1130
1125
|
projectedMonthly: earnings.dailyEarning * 30
|
|
1131
1126
|
};
|
|
1132
1127
|
}
|
|
1133
|
-
var descriptor = {
|
|
1134
|
-
id: "sentinel",
|
|
1135
|
-
name: "Sui Sentinel",
|
|
1136
|
-
packages: [SENTINEL.PACKAGE],
|
|
1137
|
-
actionMap: {
|
|
1138
|
-
"sentinel::request_attack": "sentinel_attack",
|
|
1139
|
-
"sentinel::consume_prompt": "sentinel_settle"
|
|
1140
|
-
}
|
|
1141
|
-
};
|
|
1142
|
-
function mapAgent(raw) {
|
|
1143
|
-
return {
|
|
1144
|
-
id: raw.agent_id,
|
|
1145
|
-
objectId: raw.agent_object_id,
|
|
1146
|
-
name: raw.agent_name,
|
|
1147
|
-
model: raw.model ?? "unknown",
|
|
1148
|
-
systemPrompt: raw.prompt,
|
|
1149
|
-
attackFee: BigInt(raw.cost_per_message),
|
|
1150
|
-
prizePool: BigInt(raw.total_balance),
|
|
1151
|
-
totalAttacks: raw.total_attacks,
|
|
1152
|
-
successfulBreaches: raw.successful_breaches ?? 0,
|
|
1153
|
-
state: raw.state
|
|
1154
|
-
};
|
|
1155
|
-
}
|
|
1156
|
-
async function listSentinels() {
|
|
1157
|
-
const res = await fetch(SENTINEL.SENTINELS_API);
|
|
1158
|
-
if (!res.ok) {
|
|
1159
|
-
throw new T2000Error("SENTINEL_API_ERROR", `Sentinel API returned ${res.status}`);
|
|
1160
|
-
}
|
|
1161
|
-
const data = await res.json();
|
|
1162
|
-
if (!Array.isArray(data.agents)) {
|
|
1163
|
-
throw new T2000Error("SENTINEL_API_ERROR", "Unexpected API response shape");
|
|
1164
|
-
}
|
|
1165
|
-
return data.agents.filter((a) => a.state === "active").map(mapAgent);
|
|
1166
|
-
}
|
|
1167
|
-
async function getSentinelInfo(client, sentinelObjectId) {
|
|
1168
|
-
const agents = await listSentinels();
|
|
1169
|
-
const match = agents.find((a) => a.objectId === sentinelObjectId || a.id === sentinelObjectId);
|
|
1170
|
-
if (match) return match;
|
|
1171
|
-
const obj = await client.getObject({
|
|
1172
|
-
id: sentinelObjectId,
|
|
1173
|
-
options: { showContent: true, showType: true }
|
|
1174
|
-
});
|
|
1175
|
-
if (!obj.data) {
|
|
1176
|
-
throw new T2000Error("SENTINEL_NOT_FOUND", `Sentinel ${sentinelObjectId} not found on-chain`);
|
|
1177
|
-
}
|
|
1178
|
-
const content = obj.data.content;
|
|
1179
|
-
if (!content || content.dataType !== "moveObject") {
|
|
1180
|
-
throw new T2000Error("SENTINEL_NOT_FOUND", `Object ${sentinelObjectId} is not a Move object`);
|
|
1181
|
-
}
|
|
1182
|
-
const fields = content.fields;
|
|
1183
|
-
return {
|
|
1184
|
-
id: fields.id?.id ?? sentinelObjectId,
|
|
1185
|
-
objectId: sentinelObjectId,
|
|
1186
|
-
name: fields.name ?? "Unknown",
|
|
1187
|
-
model: fields.model ?? "unknown",
|
|
1188
|
-
systemPrompt: fields.system_prompt ?? "",
|
|
1189
|
-
attackFee: BigInt(fields.cost_per_message ?? "0"),
|
|
1190
|
-
prizePool: BigInt(fields.balance ?? "0"),
|
|
1191
|
-
totalAttacks: Number(fields.total_attacks ?? "0"),
|
|
1192
|
-
successfulBreaches: Number(fields.successful_breaches ?? "0"),
|
|
1193
|
-
state: fields.state ?? "unknown"
|
|
1194
|
-
};
|
|
1195
|
-
}
|
|
1196
|
-
async function requestAttack(client, signer, sentinelObjectId, feeMist) {
|
|
1197
|
-
if (feeMist < SENTINEL.MIN_FEE_MIST) {
|
|
1198
|
-
throw new T2000Error("INVALID_AMOUNT", `Attack fee must be at least 0.1 SUI (${SENTINEL.MIN_FEE_MIST} MIST)`);
|
|
1199
|
-
}
|
|
1200
|
-
const address = signer.getAddress();
|
|
1201
|
-
const tx = new Transaction();
|
|
1202
|
-
tx.setSender(address);
|
|
1203
|
-
const [coin] = tx.splitCoins(tx.gas, [Number(feeMist)]);
|
|
1204
|
-
const [attack2] = tx.moveCall({
|
|
1205
|
-
target: `${SENTINEL.PACKAGE}::sentinel::request_attack`,
|
|
1206
|
-
arguments: [
|
|
1207
|
-
tx.object(SENTINEL.AGENT_REGISTRY),
|
|
1208
|
-
tx.object(sentinelObjectId),
|
|
1209
|
-
tx.object(SENTINEL.PROTOCOL_CONFIG),
|
|
1210
|
-
coin,
|
|
1211
|
-
tx.object(SENTINEL.RANDOM),
|
|
1212
|
-
tx.object(CLOCK_ID)
|
|
1213
|
-
]
|
|
1214
|
-
});
|
|
1215
|
-
tx.transferObjects([attack2], address);
|
|
1216
|
-
const built = await tx.build({ client });
|
|
1217
|
-
const { signature } = await signer.signTransaction(built);
|
|
1218
|
-
const result = await client.executeTransactionBlock({
|
|
1219
|
-
transactionBlock: built,
|
|
1220
|
-
signature,
|
|
1221
|
-
options: { showObjectChanges: true, showEffects: true }
|
|
1222
|
-
});
|
|
1223
|
-
await client.waitForTransaction({ digest: result.digest });
|
|
1224
|
-
const attackObj = result.objectChanges?.find(
|
|
1225
|
-
(c) => c.type === "created" && c.objectType?.includes("::sentinel::Attack")
|
|
1226
|
-
);
|
|
1227
|
-
const attackObjectId = attackObj && "objectId" in attackObj ? attackObj.objectId : void 0;
|
|
1228
|
-
if (!attackObjectId) {
|
|
1229
|
-
throw new T2000Error("SENTINEL_TX_FAILED", "Attack object was not created \u2014 transaction may have failed");
|
|
1230
|
-
}
|
|
1231
|
-
return { attackObjectId, digest: result.digest };
|
|
1232
|
-
}
|
|
1233
|
-
async function submitPrompt(agentId, attackObjectId, prompt) {
|
|
1234
|
-
const res = await fetch(SENTINEL.TEE_API, {
|
|
1235
|
-
method: "POST",
|
|
1236
|
-
headers: { "Content-Type": "application/json" },
|
|
1237
|
-
body: JSON.stringify({
|
|
1238
|
-
agent_id: agentId,
|
|
1239
|
-
attack_object_id: attackObjectId,
|
|
1240
|
-
message: prompt
|
|
1241
|
-
})
|
|
1242
|
-
});
|
|
1243
|
-
if (!res.ok) {
|
|
1244
|
-
const body = await res.text().catch(() => "");
|
|
1245
|
-
throw new T2000Error("SENTINEL_TEE_ERROR", `TEE returned ${res.status}: ${body.slice(0, 200)}`);
|
|
1246
|
-
}
|
|
1247
|
-
const raw = await res.json();
|
|
1248
|
-
const envelope = raw.response ?? raw;
|
|
1249
|
-
const data = envelope.data ?? envelope;
|
|
1250
|
-
const signature = raw.signature ?? data.signature;
|
|
1251
|
-
const timestampMs = envelope.timestamp_ms ?? data.timestamp_ms;
|
|
1252
|
-
if (typeof signature !== "string") {
|
|
1253
|
-
throw new T2000Error("SENTINEL_TEE_ERROR", "TEE response missing signature");
|
|
1254
|
-
}
|
|
1255
|
-
return {
|
|
1256
|
-
success: data.success ?? data.is_success,
|
|
1257
|
-
score: data.score,
|
|
1258
|
-
agentResponse: data.agent_response,
|
|
1259
|
-
juryResponse: data.jury_response,
|
|
1260
|
-
funResponse: data.fun_response ?? "",
|
|
1261
|
-
signature,
|
|
1262
|
-
timestampMs
|
|
1263
|
-
};
|
|
1264
|
-
}
|
|
1265
|
-
async function settleAttack(client, signer, sentinelObjectId, attackObjectId, prompt, verdict) {
|
|
1266
|
-
const sigBytes = Array.from(Buffer.from(verdict.signature.replace(/^0x/, ""), "hex"));
|
|
1267
|
-
const address = signer.getAddress();
|
|
1268
|
-
const tx = new Transaction();
|
|
1269
|
-
tx.setSender(address);
|
|
1270
|
-
tx.moveCall({
|
|
1271
|
-
target: `${SENTINEL.PACKAGE}::sentinel::consume_prompt`,
|
|
1272
|
-
arguments: [
|
|
1273
|
-
tx.object(SENTINEL.AGENT_REGISTRY),
|
|
1274
|
-
tx.object(SENTINEL.PROTOCOL_CONFIG),
|
|
1275
|
-
tx.object(sentinelObjectId),
|
|
1276
|
-
tx.pure.bool(verdict.success),
|
|
1277
|
-
tx.pure.string(verdict.agentResponse),
|
|
1278
|
-
tx.pure.string(verdict.juryResponse),
|
|
1279
|
-
tx.pure.string(verdict.funResponse),
|
|
1280
|
-
tx.pure.string(prompt),
|
|
1281
|
-
tx.pure.u8(verdict.score),
|
|
1282
|
-
tx.pure.u64(verdict.timestampMs),
|
|
1283
|
-
tx.pure(bcs.vector(bcs.u8()).serialize(sigBytes)),
|
|
1284
|
-
tx.object(SENTINEL.ENCLAVE),
|
|
1285
|
-
tx.object(attackObjectId),
|
|
1286
|
-
tx.object(CLOCK_ID)
|
|
1287
|
-
]
|
|
1288
|
-
});
|
|
1289
|
-
const built = await tx.build({ client });
|
|
1290
|
-
const { signature } = await signer.signTransaction(built);
|
|
1291
|
-
const result = await client.executeTransactionBlock({
|
|
1292
|
-
transactionBlock: built,
|
|
1293
|
-
signature,
|
|
1294
|
-
options: { showEffects: true }
|
|
1295
|
-
});
|
|
1296
|
-
await client.waitForTransaction({ digest: result.digest });
|
|
1297
|
-
const txSuccess = result.effects?.status?.status === "success";
|
|
1298
|
-
return { digest: result.digest, success: txSuccess };
|
|
1299
|
-
}
|
|
1300
|
-
async function attack(client, signer, sentinelId, prompt, feeMist) {
|
|
1301
|
-
const sentinel = await getSentinelInfo(client, sentinelId);
|
|
1302
|
-
const fee = feeMist ?? sentinel.attackFee;
|
|
1303
|
-
if (fee < SENTINEL.MIN_FEE_MIST) {
|
|
1304
|
-
throw new T2000Error("INVALID_AMOUNT", `Attack fee must be at least 0.1 SUI`);
|
|
1305
|
-
}
|
|
1306
|
-
const { attackObjectId, digest: requestTx } = await requestAttack(
|
|
1307
|
-
client,
|
|
1308
|
-
signer,
|
|
1309
|
-
sentinel.objectId,
|
|
1310
|
-
fee
|
|
1311
|
-
);
|
|
1312
|
-
const verdict = await submitPrompt(sentinel.id, attackObjectId, prompt);
|
|
1313
|
-
const { digest: settleTx } = await settleAttack(
|
|
1314
|
-
client,
|
|
1315
|
-
signer,
|
|
1316
|
-
sentinel.objectId,
|
|
1317
|
-
attackObjectId,
|
|
1318
|
-
prompt,
|
|
1319
|
-
verdict
|
|
1320
|
-
);
|
|
1321
|
-
const won = verdict.success && verdict.score >= 70;
|
|
1322
|
-
return {
|
|
1323
|
-
attackObjectId,
|
|
1324
|
-
sentinelId: sentinel.id,
|
|
1325
|
-
prompt,
|
|
1326
|
-
verdict,
|
|
1327
|
-
requestTx,
|
|
1328
|
-
settleTx,
|
|
1329
|
-
won,
|
|
1330
|
-
feePaid: Number(fee) / Number(MIST_PER_SUI)
|
|
1331
|
-
};
|
|
1332
|
-
}
|
|
1333
1128
|
|
|
1334
1129
|
// src/adapters/registry.ts
|
|
1335
1130
|
var ProtocolRegistry = class {
|
|
@@ -1476,8 +1271,9 @@ var ProtocolRegistry = class {
|
|
|
1476
1271
|
}
|
|
1477
1272
|
};
|
|
1478
1273
|
|
|
1479
|
-
// src/adapters/
|
|
1480
|
-
var
|
|
1274
|
+
// src/adapters/descriptors.ts
|
|
1275
|
+
var SUILEND_PACKAGE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf";
|
|
1276
|
+
var naviDescriptor = {
|
|
1481
1277
|
id: "navi",
|
|
1482
1278
|
name: "NAVI Protocol",
|
|
1483
1279
|
packages: [],
|
|
@@ -1493,6 +1289,42 @@ var descriptor2 = {
|
|
|
1493
1289
|
"incentive_v3::repay": "repay"
|
|
1494
1290
|
}
|
|
1495
1291
|
};
|
|
1292
|
+
var suilendDescriptor = {
|
|
1293
|
+
id: "suilend",
|
|
1294
|
+
name: "Suilend",
|
|
1295
|
+
packages: [SUILEND_PACKAGE],
|
|
1296
|
+
actionMap: {
|
|
1297
|
+
"lending_market::deposit_liquidity_and_mint_ctokens": "save",
|
|
1298
|
+
"lending_market::deposit_ctokens_into_obligation": "save",
|
|
1299
|
+
"lending_market::create_obligation": "save",
|
|
1300
|
+
"lending_market::withdraw_ctokens": "withdraw",
|
|
1301
|
+
"lending_market::redeem_ctokens_and_withdraw_liquidity": "withdraw",
|
|
1302
|
+
"lending_market::redeem_ctokens_and_withdraw_liquidity_request": "withdraw",
|
|
1303
|
+
"lending_market::fulfill_liquidity_request": "withdraw",
|
|
1304
|
+
"lending_market::unstake_sui_from_staker": "withdraw",
|
|
1305
|
+
"lending_market::borrow": "borrow",
|
|
1306
|
+
"lending_market::repay": "repay"
|
|
1307
|
+
}
|
|
1308
|
+
};
|
|
1309
|
+
var cetusDescriptor = {
|
|
1310
|
+
id: "cetus",
|
|
1311
|
+
name: "Cetus DEX",
|
|
1312
|
+
packages: [CETUS_PACKAGE],
|
|
1313
|
+
actionMap: {
|
|
1314
|
+
"router::swap": "swap",
|
|
1315
|
+
"router::swap_ab_bc": "swap",
|
|
1316
|
+
"router::swap_ab_cb": "swap",
|
|
1317
|
+
"router::swap_ba_bc": "swap",
|
|
1318
|
+
"router::swap_ba_cb": "swap"
|
|
1319
|
+
}
|
|
1320
|
+
};
|
|
1321
|
+
var allDescriptors = [
|
|
1322
|
+
naviDescriptor,
|
|
1323
|
+
suilendDescriptor,
|
|
1324
|
+
cetusDescriptor
|
|
1325
|
+
];
|
|
1326
|
+
|
|
1327
|
+
// src/adapters/navi.ts
|
|
1496
1328
|
var NaviAdapter = class {
|
|
1497
1329
|
id = "navi";
|
|
1498
1330
|
name = "NAVI Protocol";
|
|
@@ -1772,18 +1604,6 @@ function fallbackQuote(fromAsset, amount, poolPrice) {
|
|
|
1772
1604
|
}
|
|
1773
1605
|
|
|
1774
1606
|
// src/adapters/cetus.ts
|
|
1775
|
-
var descriptor3 = {
|
|
1776
|
-
id: "cetus",
|
|
1777
|
-
name: "Cetus DEX",
|
|
1778
|
-
packages: [CETUS_PACKAGE],
|
|
1779
|
-
actionMap: {
|
|
1780
|
-
"router::swap": "swap",
|
|
1781
|
-
"router::swap_ab_bc": "swap",
|
|
1782
|
-
"router::swap_ab_cb": "swap",
|
|
1783
|
-
"router::swap_ba_bc": "swap",
|
|
1784
|
-
"router::swap_ba_cb": "swap"
|
|
1785
|
-
}
|
|
1786
|
-
};
|
|
1787
1607
|
var CetusAdapter = class {
|
|
1788
1608
|
id = "cetus";
|
|
1789
1609
|
name = "Cetus";
|
|
@@ -1842,7 +1662,6 @@ var CetusAdapter = class {
|
|
|
1842
1662
|
});
|
|
1843
1663
|
}
|
|
1844
1664
|
};
|
|
1845
|
-
var SUILEND_PACKAGE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf";
|
|
1846
1665
|
var MIN_HEALTH_FACTOR2 = 1.5;
|
|
1847
1666
|
async function quietSuilend(fn) {
|
|
1848
1667
|
const origLog = console.log;
|
|
@@ -1859,23 +1678,6 @@ async function quietSuilend(fn) {
|
|
|
1859
1678
|
console.warn = origWarn;
|
|
1860
1679
|
});
|
|
1861
1680
|
}
|
|
1862
|
-
var descriptor4 = {
|
|
1863
|
-
id: "suilend",
|
|
1864
|
-
name: "Suilend",
|
|
1865
|
-
packages: [SUILEND_PACKAGE],
|
|
1866
|
-
actionMap: {
|
|
1867
|
-
"lending_market::deposit_liquidity_and_mint_ctokens": "save",
|
|
1868
|
-
"lending_market::deposit_ctokens_into_obligation": "save",
|
|
1869
|
-
"lending_market::create_obligation": "save",
|
|
1870
|
-
"lending_market::withdraw_ctokens": "withdraw",
|
|
1871
|
-
"lending_market::redeem_ctokens_and_withdraw_liquidity": "withdraw",
|
|
1872
|
-
"lending_market::redeem_ctokens_and_withdraw_liquidity_request": "withdraw",
|
|
1873
|
-
"lending_market::fulfill_liquidity_request": "withdraw",
|
|
1874
|
-
"lending_market::unstake_sui_from_staker": "withdraw",
|
|
1875
|
-
"lending_market::borrow": "borrow",
|
|
1876
|
-
"lending_market::repay": "repay"
|
|
1877
|
-
}
|
|
1878
|
-
};
|
|
1879
1681
|
var SuilendAdapter = class {
|
|
1880
1682
|
id = "suilend";
|
|
1881
1683
|
name = "Suilend";
|
|
@@ -2683,8 +2485,7 @@ async function resolveGas(client, signer, buildTx) {
|
|
|
2683
2485
|
// src/safeguards/types.ts
|
|
2684
2486
|
var OUTBOUND_OPS = /* @__PURE__ */ new Set([
|
|
2685
2487
|
"send",
|
|
2686
|
-
"pay"
|
|
2687
|
-
"sentinel"
|
|
2488
|
+
"pay"
|
|
2688
2489
|
]);
|
|
2689
2490
|
var DEFAULT_SAFEGUARD_CONFIG = {
|
|
2690
2491
|
locked: false,
|
|
@@ -3484,14 +3285,20 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
3484
3285
|
const agent = new _T2000(keypair, client, void 0, DEFAULT_CONFIG_DIR);
|
|
3485
3286
|
const address = agent.address();
|
|
3486
3287
|
let sponsored = false;
|
|
3288
|
+
let usdcSponsored = false;
|
|
3487
3289
|
if (options.sponsored !== false) {
|
|
3488
3290
|
try {
|
|
3489
3291
|
await callSponsorApi(address, options.name);
|
|
3490
3292
|
sponsored = true;
|
|
3491
3293
|
} catch {
|
|
3492
3294
|
}
|
|
3295
|
+
try {
|
|
3296
|
+
await callUsdcSponsorApi(address);
|
|
3297
|
+
usdcSponsored = true;
|
|
3298
|
+
} catch {
|
|
3299
|
+
}
|
|
3493
3300
|
}
|
|
3494
|
-
return { agent, address, sponsored };
|
|
3301
|
+
return { agent, address, sponsored, usdcSponsored };
|
|
3495
3302
|
}
|
|
3496
3303
|
// -- Gas --
|
|
3497
3304
|
/** SuiJsonRpcClient used by this agent — exposed for integrations. */
|
|
@@ -5952,17 +5759,6 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
5952
5759
|
async fundStatus() {
|
|
5953
5760
|
return getFundStatus(this.client, this._address);
|
|
5954
5761
|
}
|
|
5955
|
-
// -- Sentinel --
|
|
5956
|
-
async sentinelList() {
|
|
5957
|
-
return listSentinels();
|
|
5958
|
-
}
|
|
5959
|
-
async sentinelInfo(id) {
|
|
5960
|
-
return getSentinelInfo(this.client, id);
|
|
5961
|
-
}
|
|
5962
|
-
async sentinelAttack(id, prompt, fee) {
|
|
5963
|
-
this.enforcer.check({ operation: "sentinel", amount: fee ? Number(fee) / 1e9 : 0.1 });
|
|
5964
|
-
return attack(this.client, this._signer, id, prompt, fee);
|
|
5965
|
-
}
|
|
5966
5762
|
// -- Helpers --
|
|
5967
5763
|
async getFreeBalance(asset) {
|
|
5968
5764
|
if (!(asset in INVESTMENT_ASSETS)) return Infinity;
|
|
@@ -6044,6 +5840,30 @@ async function callSponsorApi(address, name) {
|
|
|
6044
5840
|
throw new T2000Error("SPONSOR_FAILED", "Sponsor API unavailable");
|
|
6045
5841
|
}
|
|
6046
5842
|
}
|
|
5843
|
+
async function callUsdcSponsorApi(address) {
|
|
5844
|
+
const res = await fetch(`${API_BASE_URL}/api/sponsor/usdc`, {
|
|
5845
|
+
method: "POST",
|
|
5846
|
+
headers: { "Content-Type": "application/json" },
|
|
5847
|
+
body: JSON.stringify({ address, source: "cli" })
|
|
5848
|
+
});
|
|
5849
|
+
if (res.status === 429) {
|
|
5850
|
+
const data = await res.json();
|
|
5851
|
+
if (data.challenge) {
|
|
5852
|
+
const proof = solveHashcash(data.challenge);
|
|
5853
|
+
const retry = await fetch(`${API_BASE_URL}/api/sponsor/usdc`, {
|
|
5854
|
+
method: "POST",
|
|
5855
|
+
headers: { "Content-Type": "application/json" },
|
|
5856
|
+
body: JSON.stringify({ address, source: "cli", proof })
|
|
5857
|
+
});
|
|
5858
|
+
if (!retry.ok) throw new T2000Error("USDC_SPONSOR_RATE_LIMITED", "USDC sponsor rate limited");
|
|
5859
|
+
return;
|
|
5860
|
+
}
|
|
5861
|
+
}
|
|
5862
|
+
if (res.status === 409) return;
|
|
5863
|
+
if (!res.ok) {
|
|
5864
|
+
throw new T2000Error("USDC_SPONSOR_FAILED", "USDC sponsor unavailable");
|
|
5865
|
+
}
|
|
5866
|
+
}
|
|
6047
5867
|
|
|
6048
5868
|
// src/utils/simulate.ts
|
|
6049
5869
|
async function simulateTransaction(client, tx, sender) {
|
|
@@ -6115,14 +5935,6 @@ function parseMoveAbort(errorStr) {
|
|
|
6115
5935
|
return { reason: errorStr };
|
|
6116
5936
|
}
|
|
6117
5937
|
|
|
6118
|
-
|
|
6119
|
-
var allDescriptors = [
|
|
6120
|
-
descriptor2,
|
|
6121
|
-
descriptor4,
|
|
6122
|
-
descriptor3,
|
|
6123
|
-
descriptor
|
|
6124
|
-
];
|
|
6125
|
-
|
|
6126
|
-
export { AutoInvestManager, BPS_DENOMINATOR, CLOCK_ID, CetusAdapter, ContactManager, DEFAULT_MAX_LEVERAGE, DEFAULT_MAX_POSITION_SIZE, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DEFAULT_STRATEGIES, GAS_RESERVE_MIN, INVESTMENT_ASSETS, KeypairSigner, MIST_PER_SUI, NaviAdapter, OUTBOUND_OPS, PERPS_MARKETS, PortfolioManager, ProtocolRegistry, SENTINEL, STABLE_ASSETS, SUI_DECIMALS, SUPPORTED_ASSETS, SafeguardEnforcer, SafeguardError, StrategyManager, SuilendAdapter, T2000, T2000Error, USDC_DECIMALS, ZkLoginSigner, addCollectFeeToTx, allDescriptors, calculateFee, descriptor3 as cetusDescriptor, executeAutoTopUp, executeWithGas, exportPrivateKey, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getPoolPrice, getRates, getSentinelInfo, keypairFromPrivateKey, listSentinels, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, descriptor2 as naviDescriptor, rawToStable, rawToUsdc, requestAttack, saveKey, attack as sentinelAttack, descriptor as sentinelDescriptor, settleAttack, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, submitPrompt, suiToMist, descriptor4 as suilendDescriptor, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
|
5938
|
+
export { AutoInvestManager, BPS_DENOMINATOR, CLOCK_ID, CetusAdapter, ContactManager, DEFAULT_MAX_LEVERAGE, DEFAULT_MAX_POSITION_SIZE, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DEFAULT_STRATEGIES, GAS_RESERVE_MIN, INVESTMENT_ASSETS, KeypairSigner, MIST_PER_SUI, NaviAdapter, OUTBOUND_OPS, PERPS_MARKETS, PortfolioManager, ProtocolRegistry, STABLE_ASSETS, SUI_DECIMALS, SUPPORTED_ASSETS, SafeguardEnforcer, SafeguardError, StrategyManager, SuilendAdapter, T2000, T2000Error, USDC_DECIMALS, ZkLoginSigner, addCollectFeeToTx, allDescriptors, calculateFee, cetusDescriptor, executeAutoTopUp, executeWithGas, exportPrivateKey, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getPoolPrice, getRates, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, naviDescriptor, rawToStable, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, suilendDescriptor, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
|
6127
5939
|
//# sourceMappingURL=index.js.map
|
|
6128
5940
|
//# sourceMappingURL=index.js.map
|