@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.cjs CHANGED
@@ -53,14 +53,15 @@ __export(index_exports, {
53
53
  RawPairStruct: () => RawPairStruct,
54
54
  RawPriceStruct: () => RawPriceStruct,
55
55
  RouterConfigStruct: () => RouterConfigStruct,
56
+ SwapSimulationResultStruct: () => SwapSimulationResultStruct,
56
57
  TypeNameStruct: () => TypeNameStruct
57
58
  });
58
59
  module.exports = __toCommonJS(index_exports);
59
60
 
60
61
  // src/lib/client.ts
61
- var import_core13 = require("@bolt-liquidity-hq/core");
62
+ var import_core15 = require("@bolt-liquidity-hq/core");
62
63
  var import_client = require("@mysten/sui/client");
63
- var import_utils9 = require("@mysten/sui/utils");
64
+ var import_utils10 = require("@mysten/sui/utils");
64
65
  var import_axios = __toESM(require("axios"), 1);
65
66
 
66
67
  // src/config/common.ts
@@ -158,6 +159,9 @@ var TestnetAssets = {
158
159
  }
159
160
  };
160
161
 
162
+ // src/lib/constants/defaults.ts
163
+ var BASIS_POINTS = 1e4;
164
+
161
165
  // src/lib/constants/sui-objects.ts
162
166
  var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000000";
163
167
  var PRICE_ORACLE_MODULE = "price_oracle";
@@ -641,8 +645,7 @@ var buildSwapTxArgs = async (client, swapParams, signer) => {
641
645
  if (!pool) {
642
646
  throw new import_core4.NotFoundError(`Pool for the pair ${assetIn}/${assetOut}`);
643
647
  }
644
- const isSell = (0, import_utils5.normalizeStructTag)(assetIn) === pool.baseDenom;
645
- const FUNCTION_NAME = isSell ? "swap_sell" : "swap_buy";
648
+ const FUNCTION_NAME = pool.isInverse ? "swap_sell" : "swap_buy";
646
649
  const finalSigner = client.getSigner(signer);
647
650
  const tx = new import_transactions2.Transaction();
648
651
  const signerAddress = getSignerAddress(finalSigner);
@@ -661,7 +664,7 @@ var buildSwapTxArgs = async (client, swapParams, signer) => {
661
664
  import_bcs2.bcs.option(import_bcs2.bcs.u64()).serialize(minimumAmountOut),
662
665
  import_bcs2.bcs.option(import_bcs2.bcs.string()).serialize(receiver)
663
666
  ],
664
- typeArguments: [isSell ? assetIn : assetOut, isSell ? assetOut : assetIn],
667
+ typeArguments: [pool.isInverse ? assetIn : assetOut, pool.isInverse ? assetOut : assetIn],
665
668
  tx
666
669
  };
667
670
  };
@@ -904,6 +907,14 @@ var BaseLiquidityResponseStruct = import_bcs6.bcs.struct("BaseLiquidityResponse"
904
907
  base_assets: import_bcs6.bcs.vector(BaseLiquidityInfoStruct),
905
908
  ...PaginationStruct
906
909
  });
910
+ var SwapSimulationResultStruct = import_bcs6.bcs.struct("SwapSimulationResult", {
911
+ amount_out: import_bcs6.bcs.u128(),
912
+ dynamic_fee_pct: import_bcs6.bcs.u64(),
913
+ ideal_quote_amt: import_bcs6.bcs.u128(),
914
+ swap_fee: import_bcs6.bcs.u64(),
915
+ lp_fee: import_bcs6.bcs.u64(),
916
+ protocol_fee: import_bcs6.bcs.u64()
917
+ });
907
918
 
908
919
  // src/types/pool.ts
909
920
  var import_bcs8 = require("@mysten/bcs");
@@ -919,7 +930,6 @@ var PoolFeesInfoStruct = import_bcs8.bcs.struct("PoolFeesInfo", {
919
930
  lp_fee_pct: import_bcs8.bcs.u64()
920
931
  });
921
932
  var ProtocolFeesInfoStruct = import_bcs8.bcs.struct("ProtocolFeesInfo", {
922
- bolt_fee_addr: BcsAddressType,
923
933
  swap_fee_pct: import_bcs8.bcs.u64(),
924
934
  lp_withdrawal_fee_pct: import_bcs8.bcs.u64()
925
935
  });
@@ -1089,6 +1099,21 @@ var getRouterConfig = async (_client) => {
1089
1099
  throw new import_core11.NotImplementedError("getRouterConfig on Sui Client");
1090
1100
  };
1091
1101
 
1102
+ // src/lib/router/parsers.ts
1103
+ var import_core12 = require("@bolt-liquidity-hq/core");
1104
+ var import_bignumber3 = require("bignumber.js");
1105
+ var parseSwapSimulationResultStructOutput = (output, poolAddress, assetOut) => {
1106
+ return {
1107
+ poolAddress,
1108
+ amountOut: output.amount_out,
1109
+ assetOut,
1110
+ protocolFee: output.protocol_fee,
1111
+ lpFee: output.lp_fee,
1112
+ dynamicFeePercentage: (0, import_bignumber3.BigNumber)(output.dynamic_fee_pct).div(BASIS_POINTS).toFixed(),
1113
+ totalFees: output.swap_fee
1114
+ };
1115
+ };
1116
+
1092
1117
  // src/lib/router/router-client/RouterClient.ts
1093
1118
  var import_utils8 = require("@mysten/sui/utils");
1094
1119
  var RouterClient = class {
@@ -1102,13 +1127,19 @@ var RouterClient = class {
1102
1127
  (item) => item.baseDenom === normalizedDenomOut && item.quoteDenoms.includes(normalizedDenomIn)
1103
1128
  );
1104
1129
  if (directPairPool) {
1105
- return directPairPool;
1130
+ return {
1131
+ ...directPairPool,
1132
+ isInverse: false
1133
+ };
1106
1134
  }
1107
1135
  const inversePairPool = this.pools.find(
1108
1136
  (item) => item.baseDenom === normalizedDenomIn && item.quoteDenoms.includes(normalizedDenomOut)
1109
1137
  );
1110
1138
  if (inversePairPool) {
1111
- return inversePairPool;
1139
+ return {
1140
+ ...inversePairPool,
1141
+ isInverse: true
1142
+ };
1112
1143
  }
1113
1144
  return;
1114
1145
  }
@@ -1117,6 +1148,26 @@ var RouterClient = class {
1117
1148
  }
1118
1149
  };
1119
1150
 
1151
+ // src/lib/router/simulate-swap.ts
1152
+ var import_core13 = require("@bolt-liquidity-hq/core");
1153
+ var import_bcs10 = require("@mysten/bcs");
1154
+ var import_utils9 = require("@mysten/sui/utils");
1155
+ var simulateSwap = async (client, { assetIn, amountIn, assetOut }) => {
1156
+ const pool = await client.routerClient.getPool(assetIn, assetOut);
1157
+ if (!pool) {
1158
+ throw new import_core13.NotFoundError("Pool", `Didn't find a pool to swap ${assetIn} for ${assetOut}`);
1159
+ }
1160
+ const FUNCTION_NAME = pool.isInverse ? "simulate_sell_swap" : "simulate_buy_swap";
1161
+ const response = await queryDevInspect(
1162
+ client.suiClient,
1163
+ [client.packageId, POOL_MODULE, FUNCTION_NAME],
1164
+ [pool.poolAddress, client.contracts.oracle, import_utils9.SUI_CLOCK_OBJECT_ID, import_bcs10.bcs.u64().serialize(amountIn)],
1165
+ [pool.isInverse ? assetIn : assetOut, pool.isInverse ? assetOut : assetIn]
1166
+ );
1167
+ const output = parseDevInspectResult(response, SwapSimulationResultStruct);
1168
+ return parseSwapSimulationResultStructOutput(output, pool.poolAddress, assetOut);
1169
+ };
1170
+
1120
1171
  // src/lib/router/swap-exact-in.ts
1121
1172
  var swapExactIn = async (client, swapParams, signer) => {
1122
1173
  const swapArgs = await buildSwapTxArgs(client, swapParams, signer);
@@ -1138,16 +1189,16 @@ var swapExactIn = async (client, swapParams, signer) => {
1138
1189
  };
1139
1190
 
1140
1191
  // src/lib/settlement/get-pool-info.ts
1141
- var import_core12 = require("@bolt-liquidity-hq/core");
1192
+ var import_core14 = require("@bolt-liquidity-hq/core");
1142
1193
 
1143
1194
  // src/lib/settlement/parsers.ts
1144
- var import_bignumber3 = require("bignumber.js");
1145
- var parseSettlementConfigStructOutput = (routerClient, poolFeesInfo, protocolFeesInfo, priceOracleContract) => {
1195
+ var import_bignumber4 = require("bignumber.js");
1196
+ var parseSettlementConfigStructOutput = (routerClient, poolFeesInfo, priceOracleContract) => {
1146
1197
  return {
1147
1198
  priceOracleContract,
1148
- protocolFeeRecipient: protocolFeesInfo.bolt_fee_addr,
1149
- protocolFee: (0, import_bignumber3.BigNumber)(poolFeesInfo.swap_fee_pct).div(100).toFixed(),
1150
- lpFee: (0, import_bignumber3.BigNumber)(poolFeesInfo.lp_fee_pct).div(100).toFixed(),
1199
+ protocolFeeRecipient: "0x",
1200
+ protocolFee: (0, import_bignumber4.BigNumber)(poolFeesInfo.swap_fee_pct).div(BASIS_POINTS).toFixed(),
1201
+ lpFee: (0, import_bignumber4.BigNumber)(poolFeesInfo.lp_fee_pct).div(BASIS_POINTS).toFixed(),
1151
1202
  allowanceMode: "allow",
1152
1203
  // Should come from pool config
1153
1204
  lps: routerClient.getPools().map((item) => item.poolAddress),
@@ -1159,33 +1210,20 @@ var parseSettlementConfigStructOutput = (routerClient, poolFeesInfo, protocolFee
1159
1210
  // src/lib/settlement/get-pool-info.ts
1160
1211
  var getPoolInfo = async (client, contractAddress) => {
1161
1212
  const GET_POOL_FEES_INFO_FUNCTION = "get_pool_fees_info";
1162
- const GET_PROTOCOL_FEES_INFO_FUNCTION = "get_protocol_fees_info";
1163
1213
  const pool = client.routerClient.pools.find((item) => item.poolAddress === contractAddress);
1164
1214
  if (!pool) {
1165
- throw new import_core12.NotFoundError(`Pool with the address ${contractAddress}`);
1215
+ throw new import_core14.NotFoundError(`Pool with the address ${contractAddress}`);
1166
1216
  }
1167
- const [poolFeesInfo, protocolFeesInfo] = await Promise.all([
1168
- // Query pool fee information
1169
- queryDevInspect(
1170
- client.suiClient,
1171
- [client.packageId, POOL_MODULE, GET_POOL_FEES_INFO_FUNCTION],
1172
- [contractAddress],
1173
- [pool.baseDenom]
1174
- ),
1175
- // Query protocol fee information
1176
- queryDevInspect(
1177
- client.suiClient,
1178
- [client.packageId, POOL_MODULE, GET_PROTOCOL_FEES_INFO_FUNCTION],
1179
- [contractAddress],
1180
- [pool.baseDenom]
1181
- )
1182
- ]);
1217
+ const poolFeesInfo = await queryDevInspect(
1218
+ client.suiClient,
1219
+ [client.packageId, POOL_MODULE, GET_POOL_FEES_INFO_FUNCTION],
1220
+ [contractAddress],
1221
+ [pool.baseDenom]
1222
+ );
1183
1223
  const poolFeesInfoOutput = parseDevInspectResult(poolFeesInfo, PoolFeesInfoStruct);
1184
- const protocolFeesInfoOutput = parseDevInspectResult(protocolFeesInfo, ProtocolFeesInfoStruct);
1185
1224
  return parseSettlementConfigStructOutput(
1186
1225
  client.routerClient,
1187
1226
  poolFeesInfoOutput,
1188
- protocolFeesInfoOutput,
1189
1227
  client.contracts.oracle
1190
1228
  );
1191
1229
  };
@@ -1197,7 +1235,7 @@ var getPoolInfoByDenom = async (client, baseDenom, quoteDenom) => {
1197
1235
  };
1198
1236
 
1199
1237
  // src/lib/client.ts
1200
- var BoltSuiClient = class extends import_core13.BaseClient {
1238
+ var BoltSuiClient = class extends import_core15.BaseClient {
1201
1239
  /**
1202
1240
  * Creates a new instance of the BoltSuiClient.
1203
1241
  *
@@ -1369,7 +1407,7 @@ var BoltSuiClient = class extends import_core13.BaseClient {
1369
1407
  getSigner(newSigner) {
1370
1408
  this.signer = newSigner ?? this.signer;
1371
1409
  if (!this.signer) {
1372
- throw new import_core13.MissingParameterError("signer");
1410
+ throw new import_core15.MissingParameterError("signer");
1373
1411
  }
1374
1412
  return this.signer;
1375
1413
  }
@@ -1517,6 +1555,10 @@ var BoltSuiClient = class extends import_core13.BaseClient {
1517
1555
  await this.loadConfigFromUrl();
1518
1556
  return await estimateSwapExactInGasFees(this, params, signer, gasAdjustment);
1519
1557
  }
1558
+ /** @inheritdoc */
1559
+ async simulateSwap(params) {
1560
+ return await simulateSwap(this, params);
1561
+ }
1520
1562
  /**
1521
1563
  * Loads configuration from a remote URL for testnet environments.
1522
1564
  *
@@ -1568,8 +1610,8 @@ var BoltSuiClient = class extends import_core13.BaseClient {
1568
1610
  for (const item of pools) {
1569
1611
  this.routerClient.pools.push({
1570
1612
  poolAddress: item.pool_object_id,
1571
- baseDenom: (0, import_utils9.normalizeStructTag)(item.base),
1572
- quoteDenoms: Object.values(assets).map((auxAsset) => (0, import_utils9.normalizeStructTag)(auxAsset)).filter((auxAsset) => auxAsset !== (0, import_utils9.normalizeStructTag)(item.base))
1613
+ baseDenom: (0, import_utils10.normalizeStructTag)(item.base),
1614
+ quoteDenoms: Object.values(assets).map((auxAsset) => (0, import_utils10.normalizeStructTag)(auxAsset)).filter((auxAsset) => auxAsset !== (0, import_utils10.normalizeStructTag)(item.base))
1573
1615
  });
1574
1616
  }
1575
1617
  }