@t2000/sdk 0.8.5 → 0.8.7

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
@@ -124,10 +124,25 @@ function mapMoveAbortCode(code) {
124
124
  7: "Package version mismatch \u2014 upgrade required",
125
125
  8: "Timelock is active \u2014 wait for expiry",
126
126
  9: "No pending change to execute",
127
- 10: "Already at current version"
127
+ 10: "Already at current version",
128
+ // NAVI Protocol abort codes
129
+ 1502: "Oracle price is stale \u2014 try again in a moment",
130
+ 1600: "Health factor too low \u2014 withdrawal would risk liquidation",
131
+ 1605: "Asset borrowing is disabled or at capacity on this protocol"
128
132
  };
129
133
  return abortMessages[code] ?? `Move abort code: ${code}`;
130
134
  }
135
+ function isMoveAbort(msg) {
136
+ return msg.includes("MoveAbort") || msg.includes("MovePrimitiveRuntimeError");
137
+ }
138
+ function parseMoveAbortMessage(msg) {
139
+ const abortMatch = msg.match(/abort code:\s*(\d+)/i) ?? msg.match(/MoveAbort[^,]*,\s*(\d+)/);
140
+ if (abortMatch) {
141
+ const code = parseInt(abortMatch[1], 10);
142
+ return mapMoveAbortCode(code);
143
+ }
144
+ return msg;
145
+ }
131
146
 
132
147
  // src/utils/sui.ts
133
148
  var cachedClient = null;
@@ -278,9 +293,13 @@ function formatSui(amount) {
278
293
  if (amount < 1e-3) return `${amount.toFixed(6)} SUI`;
279
294
  return `${amount.toFixed(3)} SUI`;
280
295
  }
281
- var ASSET_LOOKUP = new Map(
282
- Object.keys(SUPPORTED_ASSETS).map((k) => [k.toUpperCase(), k])
283
- );
296
+ var ASSET_LOOKUP = /* @__PURE__ */ new Map();
297
+ for (const [key, info] of Object.entries(SUPPORTED_ASSETS)) {
298
+ ASSET_LOOKUP.set(key.toUpperCase(), key);
299
+ if (info.displayName && info.displayName.toUpperCase() !== key.toUpperCase()) {
300
+ ASSET_LOOKUP.set(info.displayName.toUpperCase(), key);
301
+ }
302
+ }
284
303
  function normalizeAsset(input) {
285
304
  return ASSET_LOOKUP.get(input.toUpperCase()) ?? input;
286
305
  }
@@ -1405,6 +1424,9 @@ async function buildSwapTx(params) {
1405
1424
  const { client, address, fromAsset, toAsset, amount, maxSlippageBps = DEFAULT_SLIPPAGE_BPS } = params;
1406
1425
  const fromInfo = SUPPORTED_ASSETS[fromAsset];
1407
1426
  const toInfo = SUPPORTED_ASSETS[toAsset];
1427
+ if (!fromInfo || !toInfo) {
1428
+ throw new T2000Error("ASSET_NOT_SUPPORTED", `Swap pair ${fromAsset}/${toAsset} is not supported`);
1429
+ }
1408
1430
  const rawAmount = BigInt(Math.floor(amount * 10 ** fromInfo.decimals));
1409
1431
  const aggClient = createAggregatorClient(client, address);
1410
1432
  const result = await aggClient.findRouters({
@@ -1457,6 +1479,9 @@ async function getPoolPrice(client) {
1457
1479
  async function getSwapQuote(client, fromAsset, toAsset, amount) {
1458
1480
  const fromInfo = SUPPORTED_ASSETS[fromAsset];
1459
1481
  const toInfo = SUPPORTED_ASSETS[toAsset];
1482
+ if (!fromInfo || !toInfo) {
1483
+ throw new T2000Error("ASSET_NOT_SUPPORTED", `Swap pair ${fromAsset}/${toAsset} is not supported`);
1484
+ }
1460
1485
  const rawAmount = BigInt(Math.floor(amount * 10 ** fromInfo.decimals));
1461
1486
  const poolPrice = await getPoolPrice(client);
1462
1487
  try {
@@ -1508,19 +1533,14 @@ var CetusAdapter = class {
1508
1533
  this.client = client;
1509
1534
  }
1510
1535
  async getQuote(from, to, amount) {
1511
- return getSwapQuote(
1512
- this.client,
1513
- from.toUpperCase(),
1514
- to.toUpperCase(),
1515
- amount
1516
- );
1536
+ return getSwapQuote(this.client, from, to, amount);
1517
1537
  }
1518
1538
  async buildSwapTx(address, from, to, amount, maxSlippageBps) {
1519
1539
  const result = await buildSwapTx({
1520
1540
  client: this.client,
1521
1541
  address,
1522
- fromAsset: from.toUpperCase(),
1523
- toAsset: to.toUpperCase(),
1542
+ fromAsset: from,
1543
+ toAsset: to,
1524
1544
  amount,
1525
1545
  maxSlippageBps
1526
1546
  });
@@ -2232,7 +2252,11 @@ async function executeWithGas(client, keypair, buildTx) {
2232
2252
  if (result) return result;
2233
2253
  errors.push("self-funded: SUI below threshold");
2234
2254
  } catch (err) {
2235
- errors.push(`self-funded: ${err instanceof Error ? err.message : String(err)}`);
2255
+ const msg = err instanceof Error ? err.message : String(err);
2256
+ if (isMoveAbort(msg)) {
2257
+ throw new T2000Error("TRANSACTION_FAILED", parseMoveAbortMessage(msg));
2258
+ }
2259
+ errors.push(`self-funded: ${msg}`);
2236
2260
  }
2237
2261
  try {
2238
2262
  const tx = await buildTx();