@t2000/sdk 0.8.5 → 0.8.6
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/adapters/index.cjs +16 -11
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.js +16 -11
- package/dist/adapters/index.js.map +1 -1
- package/dist/index.cjs +16 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +16 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -278,9 +278,13 @@ function formatSui(amount) {
|
|
|
278
278
|
if (amount < 1e-3) return `${amount.toFixed(6)} SUI`;
|
|
279
279
|
return `${amount.toFixed(3)} SUI`;
|
|
280
280
|
}
|
|
281
|
-
var ASSET_LOOKUP = new Map(
|
|
282
|
-
|
|
283
|
-
);
|
|
281
|
+
var ASSET_LOOKUP = /* @__PURE__ */ new Map();
|
|
282
|
+
for (const [key, info] of Object.entries(SUPPORTED_ASSETS)) {
|
|
283
|
+
ASSET_LOOKUP.set(key.toUpperCase(), key);
|
|
284
|
+
if (info.displayName && info.displayName.toUpperCase() !== key.toUpperCase()) {
|
|
285
|
+
ASSET_LOOKUP.set(info.displayName.toUpperCase(), key);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
284
288
|
function normalizeAsset(input) {
|
|
285
289
|
return ASSET_LOOKUP.get(input.toUpperCase()) ?? input;
|
|
286
290
|
}
|
|
@@ -1405,6 +1409,9 @@ async function buildSwapTx(params) {
|
|
|
1405
1409
|
const { client, address, fromAsset, toAsset, amount, maxSlippageBps = DEFAULT_SLIPPAGE_BPS } = params;
|
|
1406
1410
|
const fromInfo = SUPPORTED_ASSETS[fromAsset];
|
|
1407
1411
|
const toInfo = SUPPORTED_ASSETS[toAsset];
|
|
1412
|
+
if (!fromInfo || !toInfo) {
|
|
1413
|
+
throw new T2000Error("ASSET_NOT_SUPPORTED", `Swap pair ${fromAsset}/${toAsset} is not supported`);
|
|
1414
|
+
}
|
|
1408
1415
|
const rawAmount = BigInt(Math.floor(amount * 10 ** fromInfo.decimals));
|
|
1409
1416
|
const aggClient = createAggregatorClient(client, address);
|
|
1410
1417
|
const result = await aggClient.findRouters({
|
|
@@ -1457,6 +1464,9 @@ async function getPoolPrice(client) {
|
|
|
1457
1464
|
async function getSwapQuote(client, fromAsset, toAsset, amount) {
|
|
1458
1465
|
const fromInfo = SUPPORTED_ASSETS[fromAsset];
|
|
1459
1466
|
const toInfo = SUPPORTED_ASSETS[toAsset];
|
|
1467
|
+
if (!fromInfo || !toInfo) {
|
|
1468
|
+
throw new T2000Error("ASSET_NOT_SUPPORTED", `Swap pair ${fromAsset}/${toAsset} is not supported`);
|
|
1469
|
+
}
|
|
1460
1470
|
const rawAmount = BigInt(Math.floor(amount * 10 ** fromInfo.decimals));
|
|
1461
1471
|
const poolPrice = await getPoolPrice(client);
|
|
1462
1472
|
try {
|
|
@@ -1508,19 +1518,14 @@ var CetusAdapter = class {
|
|
|
1508
1518
|
this.client = client;
|
|
1509
1519
|
}
|
|
1510
1520
|
async getQuote(from, to, amount) {
|
|
1511
|
-
return getSwapQuote(
|
|
1512
|
-
this.client,
|
|
1513
|
-
from.toUpperCase(),
|
|
1514
|
-
to.toUpperCase(),
|
|
1515
|
-
amount
|
|
1516
|
-
);
|
|
1521
|
+
return getSwapQuote(this.client, from, to, amount);
|
|
1517
1522
|
}
|
|
1518
1523
|
async buildSwapTx(address, from, to, amount, maxSlippageBps) {
|
|
1519
1524
|
const result = await buildSwapTx({
|
|
1520
1525
|
client: this.client,
|
|
1521
1526
|
address,
|
|
1522
|
-
fromAsset: from
|
|
1523
|
-
toAsset: to
|
|
1527
|
+
fromAsset: from,
|
|
1528
|
+
toAsset: to,
|
|
1524
1529
|
amount,
|
|
1525
1530
|
maxSlippageBps
|
|
1526
1531
|
});
|