@bolt-liquidity-hq/sui-client 0.1.0-beta.24 → 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 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
  }
@@ -724,37 +724,32 @@ var signAndExecuteTx = async (suiClient, signer, target, args, typeArguments, tr
724
724
  arguments: txArgs,
725
725
  typeArguments
726
726
  });
727
- try {
728
- if ("toSuiAddress" in signer) {
729
- const result = await suiClient.signAndExecuteTransaction({
730
- signer,
731
- transaction: tx,
732
- options
733
- });
734
- if (result.effects?.status.status === "success") {
735
- return result;
736
- } else {
737
- throw new import_core4.TransactionFailedError(result.digest, result.effects?.status.error, { result });
738
- }
727
+ if ("toSuiAddress" in signer) {
728
+ const result = await suiClient.signAndExecuteTransaction({
729
+ signer,
730
+ transaction: tx,
731
+ options
732
+ });
733
+ if (result.effects?.status.status === "success") {
734
+ return result;
739
735
  } else {
740
- const result = await signer.signAndExecuteTransaction({
741
- transaction: tx
742
- });
743
- if (!result.digest) {
744
- throw new import_core4.TransactionFailedError("not found");
745
- }
746
- const fullTx = await suiClient.waitForTransaction({
747
- digest: result.digest,
748
- options
749
- });
750
- return fullTx;
736
+ throw new import_core4.TransactionFailedError(result.digest, result.effects?.status.error, { result });
751
737
  }
752
- } catch (error) {
753
- throw import_core4.UnexpectedError.from(error, "Failed to execute transaction", {
754
- target: targetString,
755
- args,
756
- typeArguments
738
+ } else {
739
+ const result = await signer.signAndExecuteTransaction({
740
+ transaction: tx
741
+ });
742
+ if (!result.digest) {
743
+ throw new import_core4.TransactionFailedError("not found");
744
+ }
745
+ const fullTx = await suiClient.waitForTransaction({
746
+ digest: result.digest,
747
+ options
757
748
  });
749
+ if (fullTx.effects?.status.status !== "success") {
750
+ throw new import_core4.TransactionFailedError(result.digest, fullTx.effects?.status.error, { result });
751
+ }
752
+ return fullTx;
758
753
  }
759
754
  };
760
755
  var estimateTxGasPrice = async (suiClient, senderAddress, target, args, typeArguments, transaction, gasAdjustment = import_core4.DEFAULT_GAS_ADJUSTMENT) => {
@@ -1243,9 +1238,20 @@ var RouterClient = class {
1243
1238
  constructor(pools) {
1244
1239
  this.pools = pools;
1245
1240
  }
1246
- getPool(denomIn, denomOut) {
1241
+ getPool(denomIn, denomOut, swapType = "buy") {
1247
1242
  const normalizedDenomIn = (0, import_utils9.normalizeStructTag)(denomIn);
1248
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
+ }
1249
1255
  const directPairPool = this.pools.find(
1250
1256
  (item) => item.baseDenom === normalizedDenomOut && item.quoteDenoms.includes(normalizedDenomIn)
1251
1257
  );
@@ -1255,14 +1261,16 @@ var RouterClient = class {
1255
1261
  isInverse: false
1256
1262
  };
1257
1263
  }
1258
- const inversePairPool = this.pools.find(
1259
- (item) => item.baseDenom === normalizedDenomIn && item.quoteDenoms.includes(normalizedDenomOut)
1260
- );
1261
- if (inversePairPool) {
1262
- return {
1263
- ...inversePairPool,
1264
- isInverse: true
1265
- };
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
+ }
1266
1274
  }
1267
1275
  return;
1268
1276
  }
@@ -1275,8 +1283,8 @@ var RouterClient = class {
1275
1283
  var import_core14 = require("@bolt-liquidity-hq/core");
1276
1284
  var import_bcs10 = require("@mysten/bcs");
1277
1285
  var import_utils10 = require("@mysten/sui/utils");
1278
- var simulateSwap = async (client, { assetIn, amountIn, assetOut }) => {
1279
- 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);
1280
1288
  if (!pool) {
1281
1289
  throw new import_core14.NotFoundError("Pool", `Didn't find a pool to swap ${assetIn} for ${assetOut}`);
1282
1290
  }
@@ -1588,6 +1596,7 @@ var BoltSuiClient = class extends import_core15.BaseClient {
1588
1596
  * assetOut: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN", // USDC address
1589
1597
  * minimumAmountOut: "1950000", // Minimum 1.95 USDC expected (6 decimals)
1590
1598
  * receiver: "0x..." // Optional custom receiver address
1599
+ * swapType: 'buy' | 'sell' // Optional swap type (default is 'buy')
1591
1600
  * }, signer);
1592
1601
  *
1593
1602
  * console.log(`Swap successful!`);