@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.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { ChainConfig, ClientConfig, Pool, Address, BaseClient, OracleConfig, OracleAssetPair, InvertiblePrice, Price, RouterConfig, BaseLiquidityDetails, Coin, PoolConfig, Asset, SwapParams, SwapResult, SwapRequiredParams, SimulateSwapResult } from '@bolt-liquidity-hq/core';
1
+ import { ChainConfig, ClientConfig, Pool, SwapParams, SwapRequiredParams, Address, BaseClient, OracleConfig, OracleAssetPair, InvertiblePrice, Price, RouterConfig, BaseLiquidityDetails, Coin, PoolConfig, Asset, SwapResult, SimulateSwapResult } from '@bolt-liquidity-hq/core';
2
2
  import { SuiClient, SuiTransactionBlockResponse } from '@mysten/sui/client';
3
3
  import { Signer } from '@mysten/sui/cryptography';
4
4
  import { WalletContextState } from '@suiet/wallet-kit';
@@ -139,6 +139,12 @@ declare const PriceResponseStruct: _mysten_bcs.BcsStruct<{
139
139
  }, string>;
140
140
  type PriceResponseStructOutput = BcsParsed<typeof PriceResponseStruct>;
141
141
 
142
+ type SuiSwapSimulateParams = SwapRequiredParams & {
143
+ swapType?: 'buy' | 'sell';
144
+ };
145
+ type SuiSwapParams = SwapParams & {
146
+ swapType?: 'buy' | 'sell';
147
+ };
142
148
  declare const RouterConfigStruct: _mysten_bcs.BcsStruct<{
143
149
  admin: _mysten_bcs.BcsType<string, string, "address">;
144
150
  default_price_oracle_contract: _mysten_bcs.BcsType<string, string, "address">;
@@ -276,7 +282,7 @@ type BaseLiquidityInfoStructOutput = BcsParsed<typeof BaseLiquidityInfoStruct>;
276
282
  declare class RouterClient {
277
283
  pools: Pool[];
278
284
  constructor(pools: Pool[]);
279
- getPool(denomIn: string, denomOut: string): RouterPool | undefined;
285
+ getPool(denomIn: string, denomOut: string, swapType?: 'buy' | 'sell'): RouterPool | undefined;
280
286
  getPools(): Pool[];
281
287
  }
282
288
 
@@ -497,6 +503,7 @@ declare class BoltSuiClient extends BaseClient<Signer, SuiTransactionBlockRespon
497
503
  * assetOut: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN", // USDC address
498
504
  * minimumAmountOut: "1950000", // Minimum 1.95 USDC expected (6 decimals)
499
505
  * receiver: "0x..." // Optional custom receiver address
506
+ * swapType: 'buy' | 'sell' // Optional swap type (default is 'buy')
500
507
  * }, signer);
501
508
  *
502
509
  * console.log(`Swap successful!`);
@@ -510,7 +517,7 @@ declare class BoltSuiClient extends BaseClient<Signer, SuiTransactionBlockRespon
510
517
  * This implementation returns a SuiTransactionBlockResponse as the transaction output,
511
518
  * which includes details like gas costs, transaction effects, object changes, and events.
512
519
  */
513
- swap(params: SwapParams, signer?: Signer | WalletSigner): Promise<SwapResult<SuiTransactionBlockResponse>>;
520
+ swap(params: SuiSwapParams, signer?: Signer | WalletSigner): Promise<SwapResult<SuiTransactionBlockResponse>>;
514
521
  /**
515
522
  * @inheritdoc
516
523
  *
@@ -541,7 +548,7 @@ declare class BoltSuiClient extends BaseClient<Signer, SuiTransactionBlockRespon
541
548
  */
542
549
  estimateSwapGasFees(params: SwapParams, signer?: Signer | WalletSigner, gasAdjustment?: number): Promise<Coin | undefined>;
543
550
  /** @inheritdoc */
544
- simulateSwap(params: SwapRequiredParams): Promise<SimulateSwapResult>;
551
+ simulateSwap(params: SuiSwapSimulateParams): Promise<SimulateSwapResult>;
545
552
  /**
546
553
  * Loads configuration from a remote URL for testnet environments.
547
554
  *
@@ -565,4 +572,4 @@ declare class BoltSuiClient extends BaseClient<Signer, SuiTransactionBlockRespon
565
572
  private loadConfigFromUrl;
566
573
  }
567
574
 
568
- export { AssetPairResponseStruct, type AssetPairResponseStructOutput, AssetPairStruct, type AssetPairStructOutput, AssetPairsResponseStruct, type AssetPairsResponseStructOutput, BaseLiquidityInfoStruct, type BaseLiquidityInfoStructOutput, BcsAddressType, type BcsParsed, type BcsParsedMultiple, BoltSuiClient, MarketResponseStruct, type MarketResponseStructOutput, MarketStruct, type MarketStructOutput, MarketsResponsePaginatedStruct, type MarketsResponsePaginatedStructOutput, MarketsResponseStruct, type MarketsResponseStructOutput, OracleConfigStruct, type OracleConfigStructOutput, PaginationStruct, PoolConfigStruct, type PoolConfigStructOutput, type PoolInfo, PoolInfoStruct, type PoolInfoStructOutput, PriceDataStruct, type PriceDataStructOutput, PriceResponseStruct, type PriceResponseStructOutput, ProtocolFeesInfoStruct, type ProtocolFeesInfoStructOutput, RawPairStruct, type RawPairStructOutput, RawPriceStruct, type RawPriceStructOutput, RouterConfigStruct, type RouterConfigStructOutput, type RouterPool, type SuiChainConfig, type SuiClientConfig, SwapSimulationResultStruct, type SwapSimulationResultStructOutput, TypeNameStruct, type TypeNameStructOutput, type WalletSigner };
575
+ export { AssetPairResponseStruct, type AssetPairResponseStructOutput, AssetPairStruct, type AssetPairStructOutput, AssetPairsResponseStruct, type AssetPairsResponseStructOutput, BaseLiquidityInfoStruct, type BaseLiquidityInfoStructOutput, BcsAddressType, type BcsParsed, type BcsParsedMultiple, BoltSuiClient, MarketResponseStruct, type MarketResponseStructOutput, MarketStruct, type MarketStructOutput, MarketsResponsePaginatedStruct, type MarketsResponsePaginatedStructOutput, MarketsResponseStruct, type MarketsResponseStructOutput, OracleConfigStruct, type OracleConfigStructOutput, PaginationStruct, PoolConfigStruct, type PoolConfigStructOutput, type PoolInfo, PoolInfoStruct, type PoolInfoStructOutput, PriceDataStruct, type PriceDataStructOutput, PriceResponseStruct, type PriceResponseStructOutput, ProtocolFeesInfoStruct, type ProtocolFeesInfoStructOutput, RawPairStruct, type RawPairStructOutput, RawPriceStruct, type RawPriceStructOutput, RouterConfigStruct, type RouterConfigStructOutput, type RouterPool, type SuiChainConfig, type SuiClientConfig, type SuiSwapParams, type SuiSwapSimulateParams, SwapSimulationResultStruct, type SwapSimulationResultStructOutput, TypeNameStruct, type TypeNameStructOutput, type WalletSigner };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ChainConfig, ClientConfig, Pool, Address, BaseClient, OracleConfig, OracleAssetPair, InvertiblePrice, Price, RouterConfig, BaseLiquidityDetails, Coin, PoolConfig, Asset, SwapParams, SwapResult, SwapRequiredParams, SimulateSwapResult } from '@bolt-liquidity-hq/core';
1
+ import { ChainConfig, ClientConfig, Pool, SwapParams, SwapRequiredParams, Address, BaseClient, OracleConfig, OracleAssetPair, InvertiblePrice, Price, RouterConfig, BaseLiquidityDetails, Coin, PoolConfig, Asset, SwapResult, SimulateSwapResult } from '@bolt-liquidity-hq/core';
2
2
  import { SuiClient, SuiTransactionBlockResponse } from '@mysten/sui/client';
3
3
  import { Signer } from '@mysten/sui/cryptography';
4
4
  import { WalletContextState } from '@suiet/wallet-kit';
@@ -139,6 +139,12 @@ declare const PriceResponseStruct: _mysten_bcs.BcsStruct<{
139
139
  }, string>;
140
140
  type PriceResponseStructOutput = BcsParsed<typeof PriceResponseStruct>;
141
141
 
142
+ type SuiSwapSimulateParams = SwapRequiredParams & {
143
+ swapType?: 'buy' | 'sell';
144
+ };
145
+ type SuiSwapParams = SwapParams & {
146
+ swapType?: 'buy' | 'sell';
147
+ };
142
148
  declare const RouterConfigStruct: _mysten_bcs.BcsStruct<{
143
149
  admin: _mysten_bcs.BcsType<string, string, "address">;
144
150
  default_price_oracle_contract: _mysten_bcs.BcsType<string, string, "address">;
@@ -276,7 +282,7 @@ type BaseLiquidityInfoStructOutput = BcsParsed<typeof BaseLiquidityInfoStruct>;
276
282
  declare class RouterClient {
277
283
  pools: Pool[];
278
284
  constructor(pools: Pool[]);
279
- getPool(denomIn: string, denomOut: string): RouterPool | undefined;
285
+ getPool(denomIn: string, denomOut: string, swapType?: 'buy' | 'sell'): RouterPool | undefined;
280
286
  getPools(): Pool[];
281
287
  }
282
288
 
@@ -497,6 +503,7 @@ declare class BoltSuiClient extends BaseClient<Signer, SuiTransactionBlockRespon
497
503
  * assetOut: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN", // USDC address
498
504
  * minimumAmountOut: "1950000", // Minimum 1.95 USDC expected (6 decimals)
499
505
  * receiver: "0x..." // Optional custom receiver address
506
+ * swapType: 'buy' | 'sell' // Optional swap type (default is 'buy')
500
507
  * }, signer);
501
508
  *
502
509
  * console.log(`Swap successful!`);
@@ -510,7 +517,7 @@ declare class BoltSuiClient extends BaseClient<Signer, SuiTransactionBlockRespon
510
517
  * This implementation returns a SuiTransactionBlockResponse as the transaction output,
511
518
  * which includes details like gas costs, transaction effects, object changes, and events.
512
519
  */
513
- swap(params: SwapParams, signer?: Signer | WalletSigner): Promise<SwapResult<SuiTransactionBlockResponse>>;
520
+ swap(params: SuiSwapParams, signer?: Signer | WalletSigner): Promise<SwapResult<SuiTransactionBlockResponse>>;
514
521
  /**
515
522
  * @inheritdoc
516
523
  *
@@ -541,7 +548,7 @@ declare class BoltSuiClient extends BaseClient<Signer, SuiTransactionBlockRespon
541
548
  */
542
549
  estimateSwapGasFees(params: SwapParams, signer?: Signer | WalletSigner, gasAdjustment?: number): Promise<Coin | undefined>;
543
550
  /** @inheritdoc */
544
- simulateSwap(params: SwapRequiredParams): Promise<SimulateSwapResult>;
551
+ simulateSwap(params: SuiSwapSimulateParams): Promise<SimulateSwapResult>;
545
552
  /**
546
553
  * Loads configuration from a remote URL for testnet environments.
547
554
  *
@@ -565,4 +572,4 @@ declare class BoltSuiClient extends BaseClient<Signer, SuiTransactionBlockRespon
565
572
  private loadConfigFromUrl;
566
573
  }
567
574
 
568
- export { AssetPairResponseStruct, type AssetPairResponseStructOutput, AssetPairStruct, type AssetPairStructOutput, AssetPairsResponseStruct, type AssetPairsResponseStructOutput, BaseLiquidityInfoStruct, type BaseLiquidityInfoStructOutput, BcsAddressType, type BcsParsed, type BcsParsedMultiple, BoltSuiClient, MarketResponseStruct, type MarketResponseStructOutput, MarketStruct, type MarketStructOutput, MarketsResponsePaginatedStruct, type MarketsResponsePaginatedStructOutput, MarketsResponseStruct, type MarketsResponseStructOutput, OracleConfigStruct, type OracleConfigStructOutput, PaginationStruct, PoolConfigStruct, type PoolConfigStructOutput, type PoolInfo, PoolInfoStruct, type PoolInfoStructOutput, PriceDataStruct, type PriceDataStructOutput, PriceResponseStruct, type PriceResponseStructOutput, ProtocolFeesInfoStruct, type ProtocolFeesInfoStructOutput, RawPairStruct, type RawPairStructOutput, RawPriceStruct, type RawPriceStructOutput, RouterConfigStruct, type RouterConfigStructOutput, type RouterPool, type SuiChainConfig, type SuiClientConfig, SwapSimulationResultStruct, type SwapSimulationResultStructOutput, TypeNameStruct, type TypeNameStructOutput, type WalletSigner };
575
+ export { AssetPairResponseStruct, type AssetPairResponseStructOutput, AssetPairStruct, type AssetPairStructOutput, AssetPairsResponseStruct, type AssetPairsResponseStructOutput, BaseLiquidityInfoStruct, type BaseLiquidityInfoStructOutput, BcsAddressType, type BcsParsed, type BcsParsedMultiple, BoltSuiClient, MarketResponseStruct, type MarketResponseStructOutput, MarketStruct, type MarketStructOutput, MarketsResponsePaginatedStruct, type MarketsResponsePaginatedStructOutput, MarketsResponseStruct, type MarketsResponseStructOutput, OracleConfigStruct, type OracleConfigStructOutput, PaginationStruct, PoolConfigStruct, type PoolConfigStructOutput, type PoolInfo, PoolInfoStruct, type PoolInfoStructOutput, PriceDataStruct, type PriceDataStructOutput, PriceResponseStruct, type PriceResponseStructOutput, ProtocolFeesInfoStruct, type ProtocolFeesInfoStructOutput, RawPairStruct, type RawPairStructOutput, RawPriceStruct, type RawPriceStructOutput, RouterConfigStruct, type RouterConfigStructOutput, type RouterPool, type SuiChainConfig, type SuiClientConfig, type SuiSwapParams, type SuiSwapSimulateParams, SwapSimulationResultStruct, type SwapSimulationResultStructOutput, TypeNameStruct, type TypeNameStructOutput, type WalletSigner };
package/dist/index.js CHANGED
@@ -635,8 +635,8 @@ import { Transaction as Transaction2 } from "@mysten/sui/transactions";
635
635
  import { SUI_CLOCK_OBJECT_ID } from "@mysten/sui/utils";
636
636
  import { BigNumber } from "bignumber.js";
637
637
  var buildSwapTxArgs = async (client, swapParams, signer) => {
638
- const { assetIn, amountIn, assetOut, minimumAmountOut, receiver } = swapParams;
639
- const pool = client.routerClient.getPool(assetIn, assetOut);
638
+ const { assetIn, amountIn, assetOut, minimumAmountOut, receiver, swapType = "buy" } = swapParams;
639
+ const pool = client.routerClient.getPool(assetIn, assetOut, swapType);
640
640
  if (!pool) {
641
641
  throw new NotFoundError(`Pool for the pair ${assetIn}/${assetOut}`);
642
642
  }
@@ -674,37 +674,32 @@ var signAndExecuteTx = async (suiClient, signer, target, args, typeArguments, tr
674
674
  arguments: txArgs,
675
675
  typeArguments
676
676
  });
677
- try {
678
- if ("toSuiAddress" in signer) {
679
- const result = await suiClient.signAndExecuteTransaction({
680
- signer,
681
- transaction: tx,
682
- options
683
- });
684
- if (result.effects?.status.status === "success") {
685
- return result;
686
- } else {
687
- throw new TransactionFailedError2(result.digest, result.effects?.status.error, { result });
688
- }
677
+ if ("toSuiAddress" in signer) {
678
+ const result = await suiClient.signAndExecuteTransaction({
679
+ signer,
680
+ transaction: tx,
681
+ options
682
+ });
683
+ if (result.effects?.status.status === "success") {
684
+ return result;
689
685
  } else {
690
- const result = await signer.signAndExecuteTransaction({
691
- transaction: tx
692
- });
693
- if (!result.digest) {
694
- throw new TransactionFailedError2("not found");
695
- }
696
- const fullTx = await suiClient.waitForTransaction({
697
- digest: result.digest,
698
- options
699
- });
700
- return fullTx;
686
+ throw new TransactionFailedError2(result.digest, result.effects?.status.error, { result });
701
687
  }
702
- } catch (error) {
703
- throw UnexpectedError2.from(error, "Failed to execute transaction", {
704
- target: targetString,
705
- args,
706
- typeArguments
688
+ } else {
689
+ const result = await signer.signAndExecuteTransaction({
690
+ transaction: tx
707
691
  });
692
+ if (!result.digest) {
693
+ throw new TransactionFailedError2("not found");
694
+ }
695
+ const fullTx = await suiClient.waitForTransaction({
696
+ digest: result.digest,
697
+ options
698
+ });
699
+ if (fullTx.effects?.status.status !== "success") {
700
+ throw new TransactionFailedError2(result.digest, fullTx.effects?.status.error, { result });
701
+ }
702
+ return fullTx;
708
703
  }
709
704
  };
710
705
  var estimateTxGasPrice = async (suiClient, senderAddress, target, args, typeArguments, transaction, gasAdjustment = DEFAULT_GAS_ADJUSTMENT) => {
@@ -1193,9 +1188,20 @@ var RouterClient = class {
1193
1188
  constructor(pools) {
1194
1189
  this.pools = pools;
1195
1190
  }
1196
- getPool(denomIn, denomOut) {
1191
+ getPool(denomIn, denomOut, swapType = "buy") {
1197
1192
  const normalizedDenomIn = normalizeStructTag6(denomIn);
1198
1193
  const normalizedDenomOut = normalizeStructTag6(denomOut);
1194
+ if (swapType === "sell") {
1195
+ const inversePairPool = this.pools.find(
1196
+ (item) => item.baseDenom === normalizedDenomIn && item.quoteDenoms.includes(normalizedDenomOut)
1197
+ );
1198
+ if (inversePairPool) {
1199
+ return {
1200
+ ...inversePairPool,
1201
+ isInverse: true
1202
+ };
1203
+ }
1204
+ }
1199
1205
  const directPairPool = this.pools.find(
1200
1206
  (item) => item.baseDenom === normalizedDenomOut && item.quoteDenoms.includes(normalizedDenomIn)
1201
1207
  );
@@ -1205,14 +1211,16 @@ var RouterClient = class {
1205
1211
  isInverse: false
1206
1212
  };
1207
1213
  }
1208
- const inversePairPool = this.pools.find(
1209
- (item) => item.baseDenom === normalizedDenomIn && item.quoteDenoms.includes(normalizedDenomOut)
1210
- );
1211
- if (inversePairPool) {
1212
- return {
1213
- ...inversePairPool,
1214
- isInverse: true
1215
- };
1214
+ if (swapType === "buy") {
1215
+ const inversePairPool = this.pools.find(
1216
+ (item) => item.baseDenom === normalizedDenomIn && item.quoteDenoms.includes(normalizedDenomOut)
1217
+ );
1218
+ if (inversePairPool) {
1219
+ return {
1220
+ ...inversePairPool,
1221
+ isInverse: true
1222
+ };
1223
+ }
1216
1224
  }
1217
1225
  return;
1218
1226
  }
@@ -1222,13 +1230,11 @@ var RouterClient = class {
1222
1230
  };
1223
1231
 
1224
1232
  // src/lib/router/simulate-swap.ts
1225
- import {
1226
- NotFoundError as NotFoundError7
1227
- } from "@bolt-liquidity-hq/core";
1233
+ import { NotFoundError as NotFoundError7 } from "@bolt-liquidity-hq/core";
1228
1234
  import { bcs as bcs7 } from "@mysten/bcs";
1229
1235
  import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID2 } from "@mysten/sui/utils";
1230
- var simulateSwap = async (client, { assetIn, amountIn, assetOut }) => {
1231
- const pool = client.routerClient.getPool(assetIn, assetOut);
1236
+ var simulateSwap = async (client, { assetIn, amountIn, assetOut, swapType }) => {
1237
+ const pool = client.routerClient.getPool(assetIn, assetOut, swapType);
1232
1238
  if (!pool) {
1233
1239
  throw new NotFoundError7("Pool", `Didn't find a pool to swap ${assetIn} for ${assetOut}`);
1234
1240
  }
@@ -1540,6 +1546,7 @@ var BoltSuiClient = class extends BaseClient {
1540
1546
  * assetOut: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN", // USDC address
1541
1547
  * minimumAmountOut: "1950000", // Minimum 1.95 USDC expected (6 decimals)
1542
1548
  * receiver: "0x..." // Optional custom receiver address
1549
+ * swapType: 'buy' | 'sell' // Optional swap type (default is 'buy')
1543
1550
  * }, signer);
1544
1551
  *
1545
1552
  * console.log(`Swap successful!`);