@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.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 {
|
|
@@ -196,6 +183,8 @@ function mapMoveAbortCode(code) {
|
|
|
196
183
|
1503: 'Withdrawal amount is invalid (zero or dust) \u2014 try a specific amount instead of "all"',
|
|
197
184
|
1600: "Health factor too low \u2014 withdrawal would risk liquidation",
|
|
198
185
|
1605: "Asset borrowing is disabled or at capacity on this protocol",
|
|
186
|
+
// NAVI utils abort codes
|
|
187
|
+
46e3: "Insufficient balance to repay \u2014 withdraw some savings first to get cash",
|
|
199
188
|
// Cetus DEX abort codes
|
|
200
189
|
46001: "Swap failed \u2014 the DEX pool rejected the trade (liquidity or routing issue). Try again."
|
|
201
190
|
};
|
|
@@ -929,6 +918,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
929
918
|
}
|
|
930
919
|
async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
931
920
|
const asset = options.asset ?? "USDC";
|
|
921
|
+
const sponsored = options.sponsored ?? true;
|
|
932
922
|
const assetInfo = resolveAssetInfo(asset);
|
|
933
923
|
const posResult = await getPositions(client, address);
|
|
934
924
|
const supply = posResult.positions.find(
|
|
@@ -946,7 +936,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
|
946
936
|
});
|
|
947
937
|
return { coin, effectiveAmount: 0 };
|
|
948
938
|
}
|
|
949
|
-
await refreshOracle(tx, client, address);
|
|
939
|
+
await refreshOracle(tx, client, address, { skipPythUpdate: sponsored });
|
|
950
940
|
try {
|
|
951
941
|
const coin = await lending.withdrawCoinPTB(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
952
942
|
return { coin, effectiveAmount };
|
|
@@ -970,8 +960,9 @@ async function addSaveToTx(tx, _client, _address, coin, options = {}) {
|
|
|
970
960
|
}
|
|
971
961
|
async function addRepayToTx(tx, client, address, coin, options = {}) {
|
|
972
962
|
const asset = options.asset ?? "USDC";
|
|
963
|
+
const sponsored = options.sponsored ?? true;
|
|
973
964
|
const assetInfo = resolveAssetInfo(asset);
|
|
974
|
-
await refreshOracle(tx, client, address);
|
|
965
|
+
await refreshOracle(tx, client, address, { skipPythUpdate: sponsored });
|
|
975
966
|
try {
|
|
976
967
|
await lending.repayCoinPTB(tx, assetInfo.type, coin, { env: "prod" });
|
|
977
968
|
} catch (err) {
|
|
@@ -1008,12 +999,16 @@ async function buildRepayTx(client, address, amount, options = {}) {
|
|
|
1008
999
|
const asset = options.asset ?? "USDC";
|
|
1009
1000
|
const assetInfo = resolveAssetInfo(asset);
|
|
1010
1001
|
const coins = await fetchCoins(client, address, assetInfo.type);
|
|
1011
|
-
if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", `No ${assetInfo.displayName} coins to repay with
|
|
1002
|
+
if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", `No ${assetInfo.displayName} coins to repay with. Withdraw some savings first to get cash.`);
|
|
1012
1003
|
const totalBalance = coins.reduce((sum, c) => sum + BigInt(c.balance), 0n);
|
|
1004
|
+
const rawRequested = Number(stableToRaw(amount, assetInfo.decimals));
|
|
1005
|
+
if (Number(totalBalance) < rawRequested && Number(totalBalance) < 1e3) {
|
|
1006
|
+
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.`);
|
|
1007
|
+
}
|
|
1013
1008
|
const tx = new transactions.Transaction();
|
|
1014
1009
|
tx.setSender(address);
|
|
1015
1010
|
const coinObj = mergeCoins(tx, coins);
|
|
1016
|
-
const rawAmount = Math.min(
|
|
1011
|
+
const rawAmount = Math.min(rawRequested, Number(totalBalance));
|
|
1017
1012
|
const [repayCoin] = tx.splitCoins(coinObj, [rawAmount]);
|
|
1018
1013
|
await refreshOracle(tx, client, address, {
|
|
1019
1014
|
skipPythUpdate: options.sponsored,
|
|
@@ -1132,206 +1127,6 @@ async function getFundStatus(client, address) {
|
|
|
1132
1127
|
projectedMonthly: earnings.dailyEarning * 30
|
|
1133
1128
|
};
|
|
1134
1129
|
}
|
|
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
1130
|
|
|
1336
1131
|
// src/adapters/registry.ts
|
|
1337
1132
|
var ProtocolRegistry = class {
|
|
@@ -1478,8 +1273,9 @@ var ProtocolRegistry = class {
|
|
|
1478
1273
|
}
|
|
1479
1274
|
};
|
|
1480
1275
|
|
|
1481
|
-
// src/adapters/
|
|
1482
|
-
var
|
|
1276
|
+
// src/adapters/descriptors.ts
|
|
1277
|
+
var SUILEND_PACKAGE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf";
|
|
1278
|
+
var naviDescriptor = {
|
|
1483
1279
|
id: "navi",
|
|
1484
1280
|
name: "NAVI Protocol",
|
|
1485
1281
|
packages: [],
|
|
@@ -1495,6 +1291,42 @@ var descriptor2 = {
|
|
|
1495
1291
|
"incentive_v3::repay": "repay"
|
|
1496
1292
|
}
|
|
1497
1293
|
};
|
|
1294
|
+
var suilendDescriptor = {
|
|
1295
|
+
id: "suilend",
|
|
1296
|
+
name: "Suilend",
|
|
1297
|
+
packages: [SUILEND_PACKAGE],
|
|
1298
|
+
actionMap: {
|
|
1299
|
+
"lending_market::deposit_liquidity_and_mint_ctokens": "save",
|
|
1300
|
+
"lending_market::deposit_ctokens_into_obligation": "save",
|
|
1301
|
+
"lending_market::create_obligation": "save",
|
|
1302
|
+
"lending_market::withdraw_ctokens": "withdraw",
|
|
1303
|
+
"lending_market::redeem_ctokens_and_withdraw_liquidity": "withdraw",
|
|
1304
|
+
"lending_market::redeem_ctokens_and_withdraw_liquidity_request": "withdraw",
|
|
1305
|
+
"lending_market::fulfill_liquidity_request": "withdraw",
|
|
1306
|
+
"lending_market::unstake_sui_from_staker": "withdraw",
|
|
1307
|
+
"lending_market::borrow": "borrow",
|
|
1308
|
+
"lending_market::repay": "repay"
|
|
1309
|
+
}
|
|
1310
|
+
};
|
|
1311
|
+
var cetusDescriptor = {
|
|
1312
|
+
id: "cetus",
|
|
1313
|
+
name: "Cetus DEX",
|
|
1314
|
+
packages: [CETUS_PACKAGE],
|
|
1315
|
+
actionMap: {
|
|
1316
|
+
"router::swap": "swap",
|
|
1317
|
+
"router::swap_ab_bc": "swap",
|
|
1318
|
+
"router::swap_ab_cb": "swap",
|
|
1319
|
+
"router::swap_ba_bc": "swap",
|
|
1320
|
+
"router::swap_ba_cb": "swap"
|
|
1321
|
+
}
|
|
1322
|
+
};
|
|
1323
|
+
var allDescriptors = [
|
|
1324
|
+
naviDescriptor,
|
|
1325
|
+
suilendDescriptor,
|
|
1326
|
+
cetusDescriptor
|
|
1327
|
+
];
|
|
1328
|
+
|
|
1329
|
+
// src/adapters/navi.ts
|
|
1498
1330
|
var NaviAdapter = class {
|
|
1499
1331
|
id = "navi";
|
|
1500
1332
|
name = "NAVI Protocol";
|
|
@@ -1774,18 +1606,6 @@ function fallbackQuote(fromAsset, amount, poolPrice) {
|
|
|
1774
1606
|
}
|
|
1775
1607
|
|
|
1776
1608
|
// 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
1609
|
var CetusAdapter = class {
|
|
1790
1610
|
id = "cetus";
|
|
1791
1611
|
name = "Cetus";
|
|
@@ -1844,7 +1664,6 @@ var CetusAdapter = class {
|
|
|
1844
1664
|
});
|
|
1845
1665
|
}
|
|
1846
1666
|
};
|
|
1847
|
-
var SUILEND_PACKAGE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf";
|
|
1848
1667
|
var MIN_HEALTH_FACTOR2 = 1.5;
|
|
1849
1668
|
async function quietSuilend(fn) {
|
|
1850
1669
|
const origLog = console.log;
|
|
@@ -1861,23 +1680,6 @@ async function quietSuilend(fn) {
|
|
|
1861
1680
|
console.warn = origWarn;
|
|
1862
1681
|
});
|
|
1863
1682
|
}
|
|
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
1683
|
var SuilendAdapter = class {
|
|
1882
1684
|
id = "suilend";
|
|
1883
1685
|
name = "Suilend";
|
|
@@ -2685,8 +2487,7 @@ async function resolveGas(client, signer, buildTx) {
|
|
|
2685
2487
|
// src/safeguards/types.ts
|
|
2686
2488
|
var OUTBOUND_OPS = /* @__PURE__ */ new Set([
|
|
2687
2489
|
"send",
|
|
2688
|
-
"pay"
|
|
2689
|
-
"sentinel"
|
|
2490
|
+
"pay"
|
|
2690
2491
|
]);
|
|
2691
2492
|
var DEFAULT_SAFEGUARD_CONFIG = {
|
|
2692
2493
|
locked: false,
|
|
@@ -3486,14 +3287,20 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
3486
3287
|
const agent = new _T2000(keypair, client, void 0, DEFAULT_CONFIG_DIR);
|
|
3487
3288
|
const address = agent.address();
|
|
3488
3289
|
let sponsored = false;
|
|
3290
|
+
let usdcSponsored = false;
|
|
3489
3291
|
if (options.sponsored !== false) {
|
|
3490
3292
|
try {
|
|
3491
3293
|
await callSponsorApi(address, options.name);
|
|
3492
3294
|
sponsored = true;
|
|
3493
3295
|
} catch {
|
|
3494
3296
|
}
|
|
3297
|
+
try {
|
|
3298
|
+
await callUsdcSponsorApi(address);
|
|
3299
|
+
usdcSponsored = true;
|
|
3300
|
+
} catch {
|
|
3301
|
+
}
|
|
3495
3302
|
}
|
|
3496
|
-
return { agent, address, sponsored };
|
|
3303
|
+
return { agent, address, sponsored, usdcSponsored };
|
|
3497
3304
|
}
|
|
3498
3305
|
// -- Gas --
|
|
3499
3306
|
/** SuiJsonRpcClient used by this agent — exposed for integrations. */
|
|
@@ -5954,17 +5761,6 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
5954
5761
|
async fundStatus() {
|
|
5955
5762
|
return getFundStatus(this.client, this._address);
|
|
5956
5763
|
}
|
|
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
5764
|
// -- Helpers --
|
|
5969
5765
|
async getFreeBalance(asset) {
|
|
5970
5766
|
if (!(asset in INVESTMENT_ASSETS)) return Infinity;
|
|
@@ -6046,6 +5842,30 @@ async function callSponsorApi(address, name) {
|
|
|
6046
5842
|
throw new T2000Error("SPONSOR_FAILED", "Sponsor API unavailable");
|
|
6047
5843
|
}
|
|
6048
5844
|
}
|
|
5845
|
+
async function callUsdcSponsorApi(address) {
|
|
5846
|
+
const res = await fetch(`${API_BASE_URL}/api/sponsor/usdc`, {
|
|
5847
|
+
method: "POST",
|
|
5848
|
+
headers: { "Content-Type": "application/json" },
|
|
5849
|
+
body: JSON.stringify({ address, source: "cli" })
|
|
5850
|
+
});
|
|
5851
|
+
if (res.status === 429) {
|
|
5852
|
+
const data = await res.json();
|
|
5853
|
+
if (data.challenge) {
|
|
5854
|
+
const proof = solveHashcash(data.challenge);
|
|
5855
|
+
const retry = await fetch(`${API_BASE_URL}/api/sponsor/usdc`, {
|
|
5856
|
+
method: "POST",
|
|
5857
|
+
headers: { "Content-Type": "application/json" },
|
|
5858
|
+
body: JSON.stringify({ address, source: "cli", proof })
|
|
5859
|
+
});
|
|
5860
|
+
if (!retry.ok) throw new T2000Error("USDC_SPONSOR_RATE_LIMITED", "USDC sponsor rate limited");
|
|
5861
|
+
return;
|
|
5862
|
+
}
|
|
5863
|
+
}
|
|
5864
|
+
if (res.status === 409) return;
|
|
5865
|
+
if (!res.ok) {
|
|
5866
|
+
throw new T2000Error("USDC_SPONSOR_FAILED", "USDC sponsor unavailable");
|
|
5867
|
+
}
|
|
5868
|
+
}
|
|
6049
5869
|
|
|
6050
5870
|
// src/utils/simulate.ts
|
|
6051
5871
|
async function simulateTransaction(client, tx, sender) {
|
|
@@ -6117,14 +5937,6 @@ function parseMoveAbort(errorStr) {
|
|
|
6117
5937
|
return { reason: errorStr };
|
|
6118
5938
|
}
|
|
6119
5939
|
|
|
6120
|
-
// src/adapters/index.ts
|
|
6121
|
-
var allDescriptors = [
|
|
6122
|
-
descriptor2,
|
|
6123
|
-
descriptor4,
|
|
6124
|
-
descriptor3,
|
|
6125
|
-
descriptor
|
|
6126
|
-
];
|
|
6127
|
-
|
|
6128
5940
|
exports.AutoInvestManager = AutoInvestManager;
|
|
6129
5941
|
exports.BPS_DENOMINATOR = BPS_DENOMINATOR;
|
|
6130
5942
|
exports.CLOCK_ID = CLOCK_ID;
|
|
@@ -6144,7 +5956,6 @@ exports.OUTBOUND_OPS = OUTBOUND_OPS;
|
|
|
6144
5956
|
exports.PERPS_MARKETS = PERPS_MARKETS;
|
|
6145
5957
|
exports.PortfolioManager = PortfolioManager;
|
|
6146
5958
|
exports.ProtocolRegistry = ProtocolRegistry;
|
|
6147
|
-
exports.SENTINEL = SENTINEL;
|
|
6148
5959
|
exports.STABLE_ASSETS = STABLE_ASSETS;
|
|
6149
5960
|
exports.SUI_DECIMALS = SUI_DECIMALS;
|
|
6150
5961
|
exports.SUPPORTED_ASSETS = SUPPORTED_ASSETS;
|
|
@@ -6159,7 +5970,7 @@ exports.ZkLoginSigner = ZkLoginSigner;
|
|
|
6159
5970
|
exports.addCollectFeeToTx = addCollectFeeToTx;
|
|
6160
5971
|
exports.allDescriptors = allDescriptors;
|
|
6161
5972
|
exports.calculateFee = calculateFee;
|
|
6162
|
-
exports.cetusDescriptor =
|
|
5973
|
+
exports.cetusDescriptor = cetusDescriptor;
|
|
6163
5974
|
exports.executeAutoTopUp = executeAutoTopUp;
|
|
6164
5975
|
exports.executeWithGas = executeWithGas;
|
|
6165
5976
|
exports.exportPrivateKey = exportPrivateKey;
|
|
@@ -6172,28 +5983,21 @@ exports.getDecimals = getDecimals;
|
|
|
6172
5983
|
exports.getGasStatus = getGasStatus;
|
|
6173
5984
|
exports.getPoolPrice = getPoolPrice;
|
|
6174
5985
|
exports.getRates = getRates;
|
|
6175
|
-
exports.getSentinelInfo = getSentinelInfo;
|
|
6176
5986
|
exports.keypairFromPrivateKey = keypairFromPrivateKey;
|
|
6177
|
-
exports.listSentinels = listSentinels;
|
|
6178
5987
|
exports.loadKey = loadKey;
|
|
6179
5988
|
exports.mapMoveAbortCode = mapMoveAbortCode;
|
|
6180
5989
|
exports.mapWalletError = mapWalletError;
|
|
6181
5990
|
exports.mistToSui = mistToSui;
|
|
6182
|
-
exports.naviDescriptor =
|
|
5991
|
+
exports.naviDescriptor = naviDescriptor;
|
|
6183
5992
|
exports.rawToStable = rawToStable;
|
|
6184
5993
|
exports.rawToUsdc = rawToUsdc;
|
|
6185
|
-
exports.requestAttack = requestAttack;
|
|
6186
5994
|
exports.saveKey = saveKey;
|
|
6187
|
-
exports.sentinelAttack = attack;
|
|
6188
|
-
exports.sentinelDescriptor = descriptor;
|
|
6189
|
-
exports.settleAttack = settleAttack;
|
|
6190
5995
|
exports.shouldAutoTopUp = shouldAutoTopUp;
|
|
6191
5996
|
exports.simulateTransaction = simulateTransaction;
|
|
6192
5997
|
exports.solveHashcash = solveHashcash;
|
|
6193
5998
|
exports.stableToRaw = stableToRaw;
|
|
6194
|
-
exports.submitPrompt = submitPrompt;
|
|
6195
5999
|
exports.suiToMist = suiToMist;
|
|
6196
|
-
exports.suilendDescriptor =
|
|
6000
|
+
exports.suilendDescriptor = suilendDescriptor;
|
|
6197
6001
|
exports.throwIfSimulationFailed = throwIfSimulationFailed;
|
|
6198
6002
|
exports.truncateAddress = truncateAddress;
|
|
6199
6003
|
exports.usdcToRaw = usdcToRaw;
|