@bolt-liquidity-hq/sui-client 0.1.0-beta.14 → 0.1.0-beta.16

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, BaseClient, OracleConfig, OracleAssetPair, InvertiblePrice, Price, RouterConfig, Address, BaseLiquidityDetails, Coin, PoolConfig, Asset, SwapParams, SwapResult } from '@bolt-liquidity-hq/core';
1
+ import { ChainConfig, ClientConfig, Pool, BaseClient, OracleConfig, OracleAssetPair, InvertiblePrice, Price, RouterConfig, Address, BaseLiquidityDetails, Coin, PoolConfig, Asset, SwapParams, SwapResult, SwapRequiredParams, 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';
@@ -238,6 +238,18 @@ declare const BaseLiquidityResponseStruct: _mysten_bcs.BcsStruct<{
238
238
  }, string>;
239
239
  }, string>;
240
240
  type BaseLiquidityResponseStructOutput = BcsParsed<typeof BaseLiquidityResponseStruct>;
241
+ declare const SwapSimulationResultStruct: _mysten_bcs.BcsStruct<{
242
+ amount_out: _mysten_bcs.BcsType<string, string | number | bigint, "u128">;
243
+ dynamic_fee_pct: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
244
+ ideal_quote_amt: _mysten_bcs.BcsType<string, string | number | bigint, "u128">;
245
+ swap_fee: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
246
+ lp_fee: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
247
+ protocol_fee: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
248
+ }, string>;
249
+ type SwapSimulationResultStructOutput = BcsParsed<typeof SwapSimulationResultStruct>;
250
+ type RouterPool = Pool & {
251
+ isInverse: boolean;
252
+ };
241
253
 
242
254
  declare const PoolInfoStruct: _mysten_bcs.BcsStruct<{
243
255
  base_liquidity: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
@@ -253,7 +265,6 @@ declare const PoolFeesInfoStruct: _mysten_bcs.BcsStruct<{
253
265
  }, string>;
254
266
  type PoolFeesInfoStructOutput = BcsParsed<typeof PoolFeesInfoStruct>;
255
267
  declare const ProtocolFeesInfoStruct: _mysten_bcs.BcsStruct<{
256
- bolt_fee_addr: _mysten_bcs.BcsType<string, string, "address">;
257
268
  swap_fee_pct: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
258
269
  lp_withdrawal_fee_pct: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
259
270
  }, string>;
@@ -262,7 +273,7 @@ type ProtocolFeesInfoStructOutput = BcsParsed<typeof ProtocolFeesInfoStruct>;
262
273
  declare class RouterClient {
263
274
  pools: Pool[];
264
275
  constructor(pools: Pool[]);
265
- getPool(denomIn: string, denomOut: string): Pool | undefined;
276
+ getPool(denomIn: string, denomOut: string): RouterPool | undefined;
266
277
  getPools(): Pool[];
267
278
  }
268
279
 
@@ -524,6 +535,8 @@ declare class BoltSuiClient extends BaseClient<Signer, SuiTransactionBlockRespon
524
535
  * - Sui's gas model includes computation, storage, and storage rebates
525
536
  */
526
537
  estimateSwapGasFees(params: SwapParams, signer?: Signer | WalletSigner, gasAdjustment?: number): Promise<Coin | undefined>;
538
+ /** @inheritdoc */
539
+ simulateSwap(params: SwapRequiredParams): Promise<SimulateSwapResult>;
527
540
  /**
528
541
  * Loads configuration from a remote URL for testnet environments.
529
542
  *
@@ -547,4 +560,4 @@ declare class BoltSuiClient extends BaseClient<Signer, SuiTransactionBlockRespon
547
560
  private loadConfigFromUrl;
548
561
  }
549
562
 
550
- export { AssetPairResponseStruct, type AssetPairResponseStructOutput, AssetPairStruct, type AssetPairStructOutput, AssetPairsResponseStruct, type AssetPairsResponseStructOutput, BaseLiquidityInfoStruct, type BaseLiquidityInfoStructOutput, BaseLiquidityResponseStruct, type BaseLiquidityResponseStructOutput, BcsAddressType, type BcsParsed, type BcsParsedMultiple, BoltSuiClient, MarketResponseStruct, type MarketResponseStructOutput, MarketStruct, type MarketStructOutput, MarketsResponsePaginatedStruct, type MarketsResponsePaginatedStructOutput, MarketsResponseStruct, type MarketsResponseStructOutput, OracleConfigStruct, type OracleConfigStructOutput, PaginationStruct, PoolFeesInfoStruct, type PoolFeesInfoStructOutput, PoolInfoStruct, type PoolInfoStructOutput, PriceDataStruct, type PriceDataStructOutput, PriceResponseStruct, type PriceResponseStructOutput, ProtocolFeesInfoStruct, type ProtocolFeesInfoStructOutput, RawPairStruct, type RawPairStructOutput, RawPriceStruct, type RawPriceStructOutput, RouterConfigStruct, type RouterConfigStructOutput, type SuiChainConfig, type SuiClientConfig, TypeNameStruct, type TypeNameStructOutput, type WalletSigner };
563
+ export { AssetPairResponseStruct, type AssetPairResponseStructOutput, AssetPairStruct, type AssetPairStructOutput, AssetPairsResponseStruct, type AssetPairsResponseStructOutput, BaseLiquidityInfoStruct, type BaseLiquidityInfoStructOutput, BaseLiquidityResponseStruct, type BaseLiquidityResponseStructOutput, BcsAddressType, type BcsParsed, type BcsParsedMultiple, BoltSuiClient, MarketResponseStruct, type MarketResponseStructOutput, MarketStruct, type MarketStructOutput, MarketsResponsePaginatedStruct, type MarketsResponsePaginatedStructOutput, MarketsResponseStruct, type MarketsResponseStructOutput, OracleConfigStruct, type OracleConfigStructOutput, PaginationStruct, PoolFeesInfoStruct, type PoolFeesInfoStructOutput, 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 };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ChainConfig, ClientConfig, Pool, BaseClient, OracleConfig, OracleAssetPair, InvertiblePrice, Price, RouterConfig, Address, BaseLiquidityDetails, Coin, PoolConfig, Asset, SwapParams, SwapResult } from '@bolt-liquidity-hq/core';
1
+ import { ChainConfig, ClientConfig, Pool, BaseClient, OracleConfig, OracleAssetPair, InvertiblePrice, Price, RouterConfig, Address, BaseLiquidityDetails, Coin, PoolConfig, Asset, SwapParams, SwapResult, SwapRequiredParams, 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';
@@ -238,6 +238,18 @@ declare const BaseLiquidityResponseStruct: _mysten_bcs.BcsStruct<{
238
238
  }, string>;
239
239
  }, string>;
240
240
  type BaseLiquidityResponseStructOutput = BcsParsed<typeof BaseLiquidityResponseStruct>;
241
+ declare const SwapSimulationResultStruct: _mysten_bcs.BcsStruct<{
242
+ amount_out: _mysten_bcs.BcsType<string, string | number | bigint, "u128">;
243
+ dynamic_fee_pct: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
244
+ ideal_quote_amt: _mysten_bcs.BcsType<string, string | number | bigint, "u128">;
245
+ swap_fee: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
246
+ lp_fee: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
247
+ protocol_fee: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
248
+ }, string>;
249
+ type SwapSimulationResultStructOutput = BcsParsed<typeof SwapSimulationResultStruct>;
250
+ type RouterPool = Pool & {
251
+ isInverse: boolean;
252
+ };
241
253
 
242
254
  declare const PoolInfoStruct: _mysten_bcs.BcsStruct<{
243
255
  base_liquidity: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
@@ -253,7 +265,6 @@ declare const PoolFeesInfoStruct: _mysten_bcs.BcsStruct<{
253
265
  }, string>;
254
266
  type PoolFeesInfoStructOutput = BcsParsed<typeof PoolFeesInfoStruct>;
255
267
  declare const ProtocolFeesInfoStruct: _mysten_bcs.BcsStruct<{
256
- bolt_fee_addr: _mysten_bcs.BcsType<string, string, "address">;
257
268
  swap_fee_pct: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
258
269
  lp_withdrawal_fee_pct: _mysten_bcs.BcsType<string, string | number | bigint, "u64">;
259
270
  }, string>;
@@ -262,7 +273,7 @@ type ProtocolFeesInfoStructOutput = BcsParsed<typeof ProtocolFeesInfoStruct>;
262
273
  declare class RouterClient {
263
274
  pools: Pool[];
264
275
  constructor(pools: Pool[]);
265
- getPool(denomIn: string, denomOut: string): Pool | undefined;
276
+ getPool(denomIn: string, denomOut: string): RouterPool | undefined;
266
277
  getPools(): Pool[];
267
278
  }
268
279
 
@@ -524,6 +535,8 @@ declare class BoltSuiClient extends BaseClient<Signer, SuiTransactionBlockRespon
524
535
  * - Sui's gas model includes computation, storage, and storage rebates
525
536
  */
526
537
  estimateSwapGasFees(params: SwapParams, signer?: Signer | WalletSigner, gasAdjustment?: number): Promise<Coin | undefined>;
538
+ /** @inheritdoc */
539
+ simulateSwap(params: SwapRequiredParams): Promise<SimulateSwapResult>;
527
540
  /**
528
541
  * Loads configuration from a remote URL for testnet environments.
529
542
  *
@@ -547,4 +560,4 @@ declare class BoltSuiClient extends BaseClient<Signer, SuiTransactionBlockRespon
547
560
  private loadConfigFromUrl;
548
561
  }
549
562
 
550
- export { AssetPairResponseStruct, type AssetPairResponseStructOutput, AssetPairStruct, type AssetPairStructOutput, AssetPairsResponseStruct, type AssetPairsResponseStructOutput, BaseLiquidityInfoStruct, type BaseLiquidityInfoStructOutput, BaseLiquidityResponseStruct, type BaseLiquidityResponseStructOutput, BcsAddressType, type BcsParsed, type BcsParsedMultiple, BoltSuiClient, MarketResponseStruct, type MarketResponseStructOutput, MarketStruct, type MarketStructOutput, MarketsResponsePaginatedStruct, type MarketsResponsePaginatedStructOutput, MarketsResponseStruct, type MarketsResponseStructOutput, OracleConfigStruct, type OracleConfigStructOutput, PaginationStruct, PoolFeesInfoStruct, type PoolFeesInfoStructOutput, PoolInfoStruct, type PoolInfoStructOutput, PriceDataStruct, type PriceDataStructOutput, PriceResponseStruct, type PriceResponseStructOutput, ProtocolFeesInfoStruct, type ProtocolFeesInfoStructOutput, RawPairStruct, type RawPairStructOutput, RawPriceStruct, type RawPriceStructOutput, RouterConfigStruct, type RouterConfigStructOutput, type SuiChainConfig, type SuiClientConfig, TypeNameStruct, type TypeNameStructOutput, type WalletSigner };
563
+ export { AssetPairResponseStruct, type AssetPairResponseStructOutput, AssetPairStruct, type AssetPairStructOutput, AssetPairsResponseStruct, type AssetPairsResponseStructOutput, BaseLiquidityInfoStruct, type BaseLiquidityInfoStructOutput, BaseLiquidityResponseStruct, type BaseLiquidityResponseStructOutput, BcsAddressType, type BcsParsed, type BcsParsedMultiple, BoltSuiClient, MarketResponseStruct, type MarketResponseStructOutput, MarketStruct, type MarketStructOutput, MarketsResponsePaginatedStruct, type MarketsResponsePaginatedStructOutput, MarketsResponseStruct, type MarketsResponseStructOutput, OracleConfigStruct, type OracleConfigStructOutput, PaginationStruct, PoolFeesInfoStruct, type PoolFeesInfoStructOutput, 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 };
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
5
5
  // src/lib/client.ts
6
6
  import { BaseClient, MissingParameterError as MissingParameterError2 } from "@bolt-liquidity-hq/core";
7
7
  import { SuiClient } from "@mysten/sui/client";
8
- import { normalizeStructTag as normalizeStructTag7 } from "@mysten/sui/utils";
8
+ import { normalizeStructTag as normalizeStructTag6 } from "@mysten/sui/utils";
9
9
  import axios from "axios";
10
10
 
11
11
  // src/config/common.ts
@@ -103,6 +103,9 @@ var TestnetAssets = {
103
103
  }
104
104
  };
105
105
 
106
+ // src/lib/constants/defaults.ts
107
+ var BASIS_POINTS = 1e4;
108
+
106
109
  // src/lib/constants/sui-objects.ts
107
110
  var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000000";
108
111
  var PRICE_ORACLE_MODULE = "price_oracle";
@@ -583,7 +586,7 @@ import {
583
586
  } from "@bolt-liquidity-hq/core";
584
587
  import { bcs as bcs2 } from "@mysten/bcs";
585
588
  import { Transaction as Transaction2 } from "@mysten/sui/transactions";
586
- import { normalizeStructTag as normalizeStructTag3, SUI_CLOCK_OBJECT_ID } from "@mysten/sui/utils";
589
+ import { SUI_CLOCK_OBJECT_ID } from "@mysten/sui/utils";
587
590
  import { BigNumber } from "bignumber.js";
588
591
  var buildSwapTxArgs = async (client, swapParams, signer) => {
589
592
  const { assetIn, amountIn, assetOut, minimumAmountOut, receiver } = swapParams;
@@ -591,8 +594,7 @@ var buildSwapTxArgs = async (client, swapParams, signer) => {
591
594
  if (!pool) {
592
595
  throw new NotFoundError(`Pool for the pair ${assetIn}/${assetOut}`);
593
596
  }
594
- const isSell = normalizeStructTag3(assetIn) === pool.baseDenom;
595
- const FUNCTION_NAME = isSell ? "swap_sell" : "swap_buy";
597
+ const FUNCTION_NAME = pool.isInverse ? "swap_sell" : "swap_buy";
596
598
  const finalSigner = client.getSigner(signer);
597
599
  const tx = new Transaction2();
598
600
  const signerAddress = getSignerAddress(finalSigner);
@@ -611,7 +613,7 @@ var buildSwapTxArgs = async (client, swapParams, signer) => {
611
613
  bcs2.option(bcs2.u64()).serialize(minimumAmountOut),
612
614
  bcs2.option(bcs2.string()).serialize(receiver)
613
615
  ],
614
- typeArguments: [isSell ? assetIn : assetOut, isSell ? assetOut : assetIn],
616
+ typeArguments: [pool.isInverse ? assetIn : assetOut, pool.isInverse ? assetOut : assetIn],
615
617
  tx
616
618
  };
617
619
  };
@@ -854,6 +856,14 @@ var BaseLiquidityResponseStruct = bcs5.struct("BaseLiquidityResponse", {
854
856
  base_assets: bcs5.vector(BaseLiquidityInfoStruct),
855
857
  ...PaginationStruct
856
858
  });
859
+ var SwapSimulationResultStruct = bcs5.struct("SwapSimulationResult", {
860
+ amount_out: bcs5.u128(),
861
+ dynamic_fee_pct: bcs5.u64(),
862
+ ideal_quote_amt: bcs5.u128(),
863
+ swap_fee: bcs5.u64(),
864
+ lp_fee: bcs5.u64(),
865
+ protocol_fee: bcs5.u64()
866
+ });
857
867
 
858
868
  // src/types/pool.ts
859
869
  import { bcs as bcs6 } from "@mysten/bcs";
@@ -869,7 +879,6 @@ var PoolFeesInfoStruct = bcs6.struct("PoolFeesInfo", {
869
879
  lp_fee_pct: bcs6.u64()
870
880
  });
871
881
  var ProtocolFeesInfoStruct = bcs6.struct("ProtocolFeesInfo", {
872
- bolt_fee_addr: BcsAddressType,
873
882
  swap_fee_pct: bcs6.u64(),
874
883
  lp_withdrawal_fee_pct: bcs6.u64()
875
884
  });
@@ -887,18 +896,18 @@ var getAssetPairs = async (client) => {
887
896
  };
888
897
 
889
898
  // src/lib/oracle/get-assets.ts
890
- import { normalizeStructTag as normalizeStructTag4 } from "@mysten/sui/utils";
899
+ import { normalizeStructTag as normalizeStructTag3 } from "@mysten/sui/utils";
891
900
  var getAssets = async (client) => {
892
901
  const assetPairs = await client.getAllOracleAssetPairs();
893
902
  const uniqueOracleAssets = {};
894
903
  for (const item of assetPairs) {
895
- uniqueOracleAssets[normalizeStructTag4(item.base.symbol)] = {
904
+ uniqueOracleAssets[normalizeStructTag3(item.base.symbol)] = {
896
905
  ...item.base,
897
- symbol: normalizeStructTag4(item.base.symbol)
906
+ symbol: normalizeStructTag3(item.base.symbol)
898
907
  };
899
- uniqueOracleAssets[normalizeStructTag4(item.quote.symbol)] = {
908
+ uniqueOracleAssets[normalizeStructTag3(item.quote.symbol)] = {
900
909
  ...item.quote,
901
- symbol: normalizeStructTag4(item.quote.symbol)
910
+ symbol: normalizeStructTag3(item.quote.symbol)
902
911
  };
903
912
  }
904
913
  return Object.values(uniqueOracleAssets).map(
@@ -907,7 +916,7 @@ var getAssets = async (client) => {
907
916
  symbol: item.name,
908
917
  name: item.name,
909
918
  chainId: client.chainConfig.id,
910
- denom: normalizeStructTag4(item.symbol),
919
+ denom: normalizeStructTag3(item.symbol),
911
920
  decimals: item.precision,
912
921
  logo: void 0,
913
922
  coingeckoId: void 0
@@ -942,7 +951,7 @@ var getPrice = async (client, baseDenom, quoteDenom) => {
942
951
 
943
952
  // src/lib/oracle/get-prices.ts
944
953
  import { NotFoundError as NotFoundError2 } from "@bolt-liquidity-hq/core";
945
- import { normalizeStructTag as normalizeStructTag5 } from "@mysten/sui/utils";
954
+ import { normalizeStructTag as normalizeStructTag4 } from "@mysten/sui/utils";
946
955
  var getPrices = async (client) => {
947
956
  const oracleObject = await client.suiClient.getObject({
948
957
  id: client.contracts.oracle,
@@ -977,8 +986,8 @@ var getPrices = async (client) => {
977
986
  const pairKey = dynamicFields.data[index]?.name?.value;
978
987
  if (fields && pairKey) {
979
988
  prices.push({
980
- baseDenom: normalizeStructTag5(pairKey.base.name),
981
- quoteDenom: normalizeStructTag5(pairKey.quote.name),
989
+ baseDenom: normalizeStructTag4(pairKey.base.name),
990
+ quoteDenom: normalizeStructTag4(pairKey.quote.name),
982
991
  price: fields.price,
983
992
  expiryTime: fields.expiry
984
993
  });
@@ -1041,26 +1050,47 @@ var getRouterConfig = async (_client) => {
1041
1050
  throw new NotImplementedError3("getRouterConfig on Sui Client");
1042
1051
  };
1043
1052
 
1053
+ // src/lib/router/parsers.ts
1054
+ import { NotFoundError as NotFoundError4 } from "@bolt-liquidity-hq/core";
1055
+ import { BigNumber as BigNumber3 } from "bignumber.js";
1056
+ var parseSwapSimulationResultStructOutput = (output, poolAddress, assetOut) => {
1057
+ return {
1058
+ poolAddress,
1059
+ amountOut: output.amount_out,
1060
+ assetOut,
1061
+ protocolFee: output.protocol_fee,
1062
+ lpFee: output.lp_fee,
1063
+ dynamicFeePercentage: BigNumber3(output.dynamic_fee_pct).div(BASIS_POINTS).toFixed(),
1064
+ totalFees: output.swap_fee
1065
+ };
1066
+ };
1067
+
1044
1068
  // src/lib/router/router-client/RouterClient.ts
1045
- import { normalizeStructTag as normalizeStructTag6 } from "@mysten/sui/utils";
1069
+ import { normalizeStructTag as normalizeStructTag5 } from "@mysten/sui/utils";
1046
1070
  var RouterClient = class {
1047
1071
  constructor(pools) {
1048
1072
  this.pools = pools;
1049
1073
  }
1050
1074
  getPool(denomIn, denomOut) {
1051
- const normalizedDenomIn = normalizeStructTag6(denomIn);
1052
- const normalizedDenomOut = normalizeStructTag6(denomOut);
1075
+ const normalizedDenomIn = normalizeStructTag5(denomIn);
1076
+ const normalizedDenomOut = normalizeStructTag5(denomOut);
1053
1077
  const directPairPool = this.pools.find(
1054
1078
  (item) => item.baseDenom === normalizedDenomOut && item.quoteDenoms.includes(normalizedDenomIn)
1055
1079
  );
1056
1080
  if (directPairPool) {
1057
- return directPairPool;
1081
+ return {
1082
+ ...directPairPool,
1083
+ isInverse: false
1084
+ };
1058
1085
  }
1059
1086
  const inversePairPool = this.pools.find(
1060
1087
  (item) => item.baseDenom === normalizedDenomIn && item.quoteDenoms.includes(normalizedDenomOut)
1061
1088
  );
1062
1089
  if (inversePairPool) {
1063
- return inversePairPool;
1090
+ return {
1091
+ ...inversePairPool,
1092
+ isInverse: true
1093
+ };
1064
1094
  }
1065
1095
  return;
1066
1096
  }
@@ -1069,6 +1099,28 @@ var RouterClient = class {
1069
1099
  }
1070
1100
  };
1071
1101
 
1102
+ // src/lib/router/simulate-swap.ts
1103
+ import {
1104
+ NotFoundError as NotFoundError5
1105
+ } from "@bolt-liquidity-hq/core";
1106
+ import { bcs as bcs7 } from "@mysten/bcs";
1107
+ import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID2 } from "@mysten/sui/utils";
1108
+ var simulateSwap = async (client, { assetIn, amountIn, assetOut }) => {
1109
+ const pool = await client.routerClient.getPool(assetIn, assetOut);
1110
+ if (!pool) {
1111
+ throw new NotFoundError5("Pool", `Didn't find a pool to swap ${assetIn} for ${assetOut}`);
1112
+ }
1113
+ const FUNCTION_NAME = pool.isInverse ? "simulate_sell_swap" : "simulate_buy_swap";
1114
+ const response = await queryDevInspect(
1115
+ client.suiClient,
1116
+ [client.packageId, POOL_MODULE, FUNCTION_NAME],
1117
+ [pool.poolAddress, client.contracts.oracle, SUI_CLOCK_OBJECT_ID2, bcs7.u64().serialize(amountIn)],
1118
+ [pool.isInverse ? assetIn : assetOut, pool.isInverse ? assetOut : assetIn]
1119
+ );
1120
+ const output = parseDevInspectResult(response, SwapSimulationResultStruct);
1121
+ return parseSwapSimulationResultStructOutput(output, pool.poolAddress, assetOut);
1122
+ };
1123
+
1072
1124
  // src/lib/router/swap-exact-in.ts
1073
1125
  var swapExactIn = async (client, swapParams, signer) => {
1074
1126
  const swapArgs = await buildSwapTxArgs(client, swapParams, signer);
@@ -1090,16 +1142,16 @@ var swapExactIn = async (client, swapParams, signer) => {
1090
1142
  };
1091
1143
 
1092
1144
  // src/lib/settlement/get-pool-info.ts
1093
- import { NotFoundError as NotFoundError4 } from "@bolt-liquidity-hq/core";
1145
+ import { NotFoundError as NotFoundError6 } from "@bolt-liquidity-hq/core";
1094
1146
 
1095
1147
  // src/lib/settlement/parsers.ts
1096
- import { BigNumber as BigNumber3 } from "bignumber.js";
1097
- var parseSettlementConfigStructOutput = (routerClient, poolFeesInfo, protocolFeesInfo, priceOracleContract) => {
1148
+ import { BigNumber as BigNumber4 } from "bignumber.js";
1149
+ var parseSettlementConfigStructOutput = (routerClient, poolFeesInfo, priceOracleContract) => {
1098
1150
  return {
1099
1151
  priceOracleContract,
1100
- protocolFeeRecipient: protocolFeesInfo.bolt_fee_addr,
1101
- protocolFee: BigNumber3(poolFeesInfo.swap_fee_pct).div(100).toFixed(),
1102
- lpFee: BigNumber3(poolFeesInfo.lp_fee_pct).div(100).toFixed(),
1152
+ protocolFeeRecipient: "0x",
1153
+ protocolFee: BigNumber4(poolFeesInfo.swap_fee_pct).div(BASIS_POINTS).toFixed(),
1154
+ lpFee: BigNumber4(poolFeesInfo.lp_fee_pct).div(BASIS_POINTS).toFixed(),
1103
1155
  allowanceMode: "allow",
1104
1156
  // Should come from pool config
1105
1157
  lps: routerClient.getPools().map((item) => item.poolAddress),
@@ -1111,33 +1163,20 @@ var parseSettlementConfigStructOutput = (routerClient, poolFeesInfo, protocolFee
1111
1163
  // src/lib/settlement/get-pool-info.ts
1112
1164
  var getPoolInfo = async (client, contractAddress) => {
1113
1165
  const GET_POOL_FEES_INFO_FUNCTION = "get_pool_fees_info";
1114
- const GET_PROTOCOL_FEES_INFO_FUNCTION = "get_protocol_fees_info";
1115
1166
  const pool = client.routerClient.pools.find((item) => item.poolAddress === contractAddress);
1116
1167
  if (!pool) {
1117
- throw new NotFoundError4(`Pool with the address ${contractAddress}`);
1168
+ throw new NotFoundError6(`Pool with the address ${contractAddress}`);
1118
1169
  }
1119
- const [poolFeesInfo, protocolFeesInfo] = await Promise.all([
1120
- // Query pool fee information
1121
- queryDevInspect(
1122
- client.suiClient,
1123
- [client.packageId, POOL_MODULE, GET_POOL_FEES_INFO_FUNCTION],
1124
- [contractAddress],
1125
- [pool.baseDenom]
1126
- ),
1127
- // Query protocol fee information
1128
- queryDevInspect(
1129
- client.suiClient,
1130
- [client.packageId, POOL_MODULE, GET_PROTOCOL_FEES_INFO_FUNCTION],
1131
- [contractAddress],
1132
- [pool.baseDenom]
1133
- )
1134
- ]);
1170
+ const poolFeesInfo = await queryDevInspect(
1171
+ client.suiClient,
1172
+ [client.packageId, POOL_MODULE, GET_POOL_FEES_INFO_FUNCTION],
1173
+ [contractAddress],
1174
+ [pool.baseDenom]
1175
+ );
1135
1176
  const poolFeesInfoOutput = parseDevInspectResult(poolFeesInfo, PoolFeesInfoStruct);
1136
- const protocolFeesInfoOutput = parseDevInspectResult(protocolFeesInfo, ProtocolFeesInfoStruct);
1137
1177
  return parseSettlementConfigStructOutput(
1138
1178
  client.routerClient,
1139
1179
  poolFeesInfoOutput,
1140
- protocolFeesInfoOutput,
1141
1180
  client.contracts.oracle
1142
1181
  );
1143
1182
  };
@@ -1469,6 +1508,10 @@ var BoltSuiClient = class extends BaseClient {
1469
1508
  await this.loadConfigFromUrl();
1470
1509
  return await estimateSwapExactInGasFees(this, params, signer, gasAdjustment);
1471
1510
  }
1511
+ /** @inheritdoc */
1512
+ async simulateSwap(params) {
1513
+ return await simulateSwap(this, params);
1514
+ }
1472
1515
  /**
1473
1516
  * Loads configuration from a remote URL for testnet environments.
1474
1517
  *
@@ -1520,8 +1563,8 @@ var BoltSuiClient = class extends BaseClient {
1520
1563
  for (const item of pools) {
1521
1564
  this.routerClient.pools.push({
1522
1565
  poolAddress: item.pool_object_id,
1523
- baseDenom: normalizeStructTag7(item.base),
1524
- quoteDenoms: Object.values(assets).map((auxAsset) => normalizeStructTag7(auxAsset)).filter((auxAsset) => auxAsset !== normalizeStructTag7(item.base))
1566
+ baseDenom: normalizeStructTag6(item.base),
1567
+ quoteDenoms: Object.values(assets).map((auxAsset) => normalizeStructTag6(auxAsset)).filter((auxAsset) => auxAsset !== normalizeStructTag6(item.base))
1525
1568
  });
1526
1569
  }
1527
1570
  }
@@ -1550,6 +1593,7 @@ export {
1550
1593
  RawPairStruct,
1551
1594
  RawPriceStruct,
1552
1595
  RouterConfigStruct,
1596
+ SwapSimulationResultStruct,
1553
1597
  TypeNameStruct
1554
1598
  };
1555
1599
  //# sourceMappingURL=index.js.map