@bolt-liquidity-hq/sui-client 0.1.0-beta.25 → 0.1.0-beta.26
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 +27 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -5
- package/dist/index.d.ts +12 -5
- package/dist/index.js +28 -16
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -685,8 +685,8 @@ var import_transactions2 = require("@mysten/sui/transactions");
|
|
|
685
685
|
var import_utils5 = require("@mysten/sui/utils");
|
|
686
686
|
var import_bignumber = require("bignumber.js");
|
|
687
687
|
var buildSwapTxArgs = async (client, swapParams, signer) => {
|
|
688
|
-
const { assetIn, amountIn, assetOut, minimumAmountOut, receiver } = swapParams;
|
|
689
|
-
const pool = client.routerClient.getPool(assetIn, assetOut);
|
|
688
|
+
const { assetIn, amountIn, assetOut, minimumAmountOut, receiver, swapType = "buy" } = swapParams;
|
|
689
|
+
const pool = client.routerClient.getPool(assetIn, assetOut, swapType);
|
|
690
690
|
if (!pool) {
|
|
691
691
|
throw new import_core4.NotFoundError(`Pool for the pair ${assetIn}/${assetOut}`);
|
|
692
692
|
}
|
|
@@ -1238,9 +1238,20 @@ var RouterClient = class {
|
|
|
1238
1238
|
constructor(pools) {
|
|
1239
1239
|
this.pools = pools;
|
|
1240
1240
|
}
|
|
1241
|
-
getPool(denomIn, denomOut) {
|
|
1241
|
+
getPool(denomIn, denomOut, swapType = "buy") {
|
|
1242
1242
|
const normalizedDenomIn = (0, import_utils9.normalizeStructTag)(denomIn);
|
|
1243
1243
|
const normalizedDenomOut = (0, import_utils9.normalizeStructTag)(denomOut);
|
|
1244
|
+
if (swapType === "sell") {
|
|
1245
|
+
const inversePairPool = this.pools.find(
|
|
1246
|
+
(item) => item.baseDenom === normalizedDenomIn && item.quoteDenoms.includes(normalizedDenomOut)
|
|
1247
|
+
);
|
|
1248
|
+
if (inversePairPool) {
|
|
1249
|
+
return {
|
|
1250
|
+
...inversePairPool,
|
|
1251
|
+
isInverse: true
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1244
1255
|
const directPairPool = this.pools.find(
|
|
1245
1256
|
(item) => item.baseDenom === normalizedDenomOut && item.quoteDenoms.includes(normalizedDenomIn)
|
|
1246
1257
|
);
|
|
@@ -1250,14 +1261,16 @@ var RouterClient = class {
|
|
|
1250
1261
|
isInverse: false
|
|
1251
1262
|
};
|
|
1252
1263
|
}
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1264
|
+
if (swapType === "buy") {
|
|
1265
|
+
const inversePairPool = this.pools.find(
|
|
1266
|
+
(item) => item.baseDenom === normalizedDenomIn && item.quoteDenoms.includes(normalizedDenomOut)
|
|
1267
|
+
);
|
|
1268
|
+
if (inversePairPool) {
|
|
1269
|
+
return {
|
|
1270
|
+
...inversePairPool,
|
|
1271
|
+
isInverse: true
|
|
1272
|
+
};
|
|
1273
|
+
}
|
|
1261
1274
|
}
|
|
1262
1275
|
return;
|
|
1263
1276
|
}
|
|
@@ -1270,8 +1283,8 @@ var RouterClient = class {
|
|
|
1270
1283
|
var import_core14 = require("@bolt-liquidity-hq/core");
|
|
1271
1284
|
var import_bcs10 = require("@mysten/bcs");
|
|
1272
1285
|
var import_utils10 = require("@mysten/sui/utils");
|
|
1273
|
-
var simulateSwap = async (client, { assetIn, amountIn, assetOut }) => {
|
|
1274
|
-
const pool = client.routerClient.getPool(assetIn, assetOut);
|
|
1286
|
+
var simulateSwap = async (client, { assetIn, amountIn, assetOut, swapType }) => {
|
|
1287
|
+
const pool = client.routerClient.getPool(assetIn, assetOut, swapType);
|
|
1275
1288
|
if (!pool) {
|
|
1276
1289
|
throw new import_core14.NotFoundError("Pool", `Didn't find a pool to swap ${assetIn} for ${assetOut}`);
|
|
1277
1290
|
}
|
|
@@ -1583,6 +1596,7 @@ var BoltSuiClient = class extends import_core15.BaseClient {
|
|
|
1583
1596
|
* assetOut: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN", // USDC address
|
|
1584
1597
|
* minimumAmountOut: "1950000", // Minimum 1.95 USDC expected (6 decimals)
|
|
1585
1598
|
* receiver: "0x..." // Optional custom receiver address
|
|
1599
|
+
* swapType: 'buy' | 'sell' // Optional swap type (default is 'buy')
|
|
1586
1600
|
* }, signer);
|
|
1587
1601
|
*
|
|
1588
1602
|
* console.log(`Swap successful!`);
|