@hyperbridge/simplex 0.16.7 → 0.16.8

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
@@ -18642,20 +18642,32 @@ var ContractInteractionService = class {
18642
18642
  } else {
18643
18643
  this.logger.warn({ reason: pmResult.reason }, "No paymaster for bid UserOp; relying on EntryPoint deposit");
18644
18644
  }
18645
- const userOp = await sdkHelper.prepareSubmitBid({
18646
- order,
18647
- fillOptions,
18645
+ const bidGas = {
18648
18646
  solverAccount: solverAccountAddress,
18649
- solverSigner: sdkSigningAccount(this.signer),
18650
18647
  nonce,
18651
18648
  entryPointAddress,
18652
18649
  callGasLimit,
18653
18650
  verificationGasLimit: cachedEstimate.verificationGasLimit,
18654
- preVerificationGas: cachedEstimate.preVerificationGas,
18655
18651
  maxFeePerGas: cachedEstimate.maxFeePerGas,
18656
18652
  maxPriorityFeePerGas: cachedEstimate.maxPriorityFeePerGas,
18657
18653
  callData,
18658
18654
  paymasterAndData
18655
+ };
18656
+ let preVerificationGas = cachedEstimate.preVerificationGas;
18657
+ try {
18658
+ preVerificationGas = await sdkHelper.estimateBidPreVerificationGas(bidGas);
18659
+ } catch (err) {
18660
+ this.logger.warn(
18661
+ { orderId: order.id, err, preVerificationGas: preVerificationGas.toString() },
18662
+ "Could not estimate the bid's preVerificationGas; using the fill estimate's"
18663
+ );
18664
+ }
18665
+ const userOp = await sdkHelper.prepareSubmitBid({
18666
+ ...bidGas,
18667
+ order,
18668
+ fillOptions,
18669
+ solverSigner: sdkSigningAccount(this.signer),
18670
+ preVerificationGas
18659
18671
  });
18660
18672
  const encodedUserOp = (0, import_sdk7.encodeUserOpScale)(userOp);
18661
18673
  this.logger.info(
@@ -18664,6 +18676,7 @@ var ContractInteractionService = class {
18664
18676
  solverAccount: solverAccountAddress,
18665
18677
  nonce: nonce.toString(),
18666
18678
  callGasLimit: callGasLimit.toString(),
18679
+ preVerificationGas: preVerificationGas.toString(),
18667
18680
  maxFeePerGas: cachedEstimate.maxFeePerGas.toString()
18668
18681
  },
18669
18682
  "Prepared bid UserOp"
@@ -21772,10 +21785,6 @@ var import_decimal6 = require("decimal.js");
21772
21785
  function limitOrderLegs(order) {
21773
21786
  return order.side === "BID" ? { input: order.base, output: order.quote } : { input: order.quote, output: order.base };
21774
21787
  }
21775
- function availableOn(order) {
21776
- const available = BigInt(order.remaining) - BigInt(order.reserved);
21777
- return available > 0n ? available : 0n;
21778
- }
21779
21788
  function matchLimitOrders(orders, incoming, resolve, now = /* @__PURE__ */ new Date()) {
21780
21789
  const qualifying = orders.filter((order) => serves(order, incoming, resolve, now)).map((order) => {
21781
21790
  const offer = offerFor({
@@ -21784,7 +21793,7 @@ function matchLimitOrders(orders, incoming, resolve, now = /* @__PURE__ */ new D
21784
21793
  price: BigInt(order.price),
21785
21794
  outputDecimals: incoming.outputDecimals
21786
21795
  });
21787
- const available = availableOn(order);
21796
+ const available = BigInt(order.remaining);
21788
21797
  return { order, offer, available, payout: offer < available ? offer : available };
21789
21798
  }).filter((candidate) => candidate.offer >= incoming.requestedOutput && candidate.payout > 0n).sort(byBestOfferFirst);
21790
21799
  return qualifying;
@@ -23671,48 +23680,42 @@ async function bootFiller(config, options) {
23671
23680
  assertPairSymbolsResolve(config.pairs, assetRegistry, configuredChainNames);
23672
23681
  }
23673
23682
  const adminStrategies = [];
23674
- const strategies = [];
23675
- let confirmationPolicy;
23676
- let tradingPairs;
23677
- let engine;
23678
- if (config.pairs?.length) {
23679
- tradingPairs = config.pairs.map((pair) => ({ token0: pair.token0, token1: pair.token1 }));
23680
- tradingPairs.forEach((pair, pairIndex) => {
23681
- adminStrategies.push({
23682
- index: pairIndex,
23683
- pairIndex,
23684
- exotic: `${pair.token0}/${pair.token1}`,
23685
- token0: pair.token0,
23686
- token1: pair.token1,
23687
- sameToken: normalizeSymbol(pair.token0) === normalizeSymbol(pair.token1)
23688
- });
23683
+ const tradingPairs = (config.pairs ?? []).map((pair) => ({
23684
+ token0: pair.token0,
23685
+ token1: pair.token1
23686
+ }));
23687
+ tradingPairs.forEach((pair, pairIndex) => {
23688
+ adminStrategies.push({
23689
+ index: pairIndex,
23690
+ pairIndex,
23691
+ exotic: `${pair.token0}/${pair.token1}`,
23692
+ token0: pair.token0,
23693
+ token1: pair.token1,
23694
+ sameToken: normalizeSymbol(pair.token0) === normalizeSymbol(pair.token1)
23689
23695
  });
23690
- confirmationPolicy = assertConfirmationCoverage(
23691
- config.confirmationPolicies,
23692
- resolvedChains.map((c) => c.chainId)
23693
- );
23694
- const fundingVenues = vaultVenue ? [vaultVenue] : [];
23695
- engine = new FXFiller(
23696
- runtimeSigner,
23697
- configService,
23698
- chainClientManager,
23699
- contractService,
23700
- tradingPairs,
23701
- assetRegistry,
23702
- { confirmationPolicy, fundingVenues, limitOrders: options.data.limitOrders }
23703
- );
23704
- logger.info("Hydrating funding venue state...");
23705
- await engine.initialise();
23706
- strategies.push(engine);
23707
- }
23696
+ });
23697
+ const confirmationPolicy = assertConfirmationCoverage(
23698
+ config.confirmationPolicies,
23699
+ resolvedChains.map((c) => c.chainId)
23700
+ );
23701
+ const fundingVenues = vaultVenue ? [vaultVenue] : [];
23702
+ const engine = new FXFiller(
23703
+ runtimeSigner,
23704
+ configService,
23705
+ chainClientManager,
23706
+ contractService,
23707
+ tradingPairs,
23708
+ assetRegistry,
23709
+ { confirmationPolicy, fundingVenues, limitOrders: options.data.limitOrders }
23710
+ );
23711
+ logger.info("Hydrating funding venue state...");
23712
+ await engine.initialise();
23713
+ const strategies = [engine];
23708
23714
  const haltControls = strategies.map((engine2, index) => ({
23709
23715
  index,
23710
23716
  isHalted: () => engine2.isHalted(),
23711
23717
  resetHalt: () => engine2.resetHalt()
23712
23718
  }));
23713
- if (vaultVenue) {
23714
- await vaultVenue.initialise(runtimeSigner.address);
23715
- }
23716
23719
  let rebalancingService;
23717
23720
  const rebalancingConfig = configService.getRebalancingConfig();
23718
23721
  if (rebalancingConfig?.triggerPercentage !== void 0 && rebalancingConfig?.baseBalances) {
@@ -24229,8 +24232,8 @@ var MemoryLimitOrderStore = class {
24229
24232
  async reserve(id, amount) {
24230
24233
  const order = this.orders.get(id);
24231
24234
  if (!order || order.status !== "open") return false;
24235
+ if (BigInt(amount) > BigInt(order.remaining)) return false;
24232
24236
  const reserved = BigInt(order.reserved) + BigInt(amount);
24233
- if (reserved > BigInt(order.remaining)) return false;
24234
24237
  this.patch(id, { reserved: reserved.toString() });
24235
24238
  return true;
24236
24239
  }
@@ -24982,10 +24985,7 @@ var PairController = class {
24982
24985
  * the pair's symbols have to resolve before the market can be hydrated.
24983
24986
  */
24984
24987
  async add(pair, options) {
24985
- const { engine, tradingPairs, assetRegistry, adminStrategies, balanceTokens, config } = this.runtime;
24986
- if (!engine || !tradingPairs) {
24987
- throw new Error("No trading engine is running \u2014 this filler was started without pairs");
24988
- }
24988
+ const { engine, assetRegistry, adminStrategies, balanceTokens, config } = this.runtime;
24989
24989
  const assets = options?.assets;
24990
24990
  const nextAssets = { ...config.assets ?? {}, ...assets ?? {} };
24991
24991
  const nextPairs = [...this.pairs, pair];
@@ -25024,7 +25024,6 @@ var PairController = class {
25024
25024
  /** Closes a market. Orders already in flight against it still complete. */
25025
25025
  async remove(index) {
25026
25026
  const { engine, tradingPairs, adminStrategies, config } = this.runtime;
25027
- if (!engine || !tradingPairs) throw new Error("No trading engine is running");
25028
25027
  if (index < 0 || index >= this.pairs.length) throw new Error(`Unknown pair ${index}`);
25029
25028
  engine.removePair(tradingPairs[index]);
25030
25029
  config.pairs = this.pairs.filter((_, i) => i !== index);
@@ -25036,7 +25035,7 @@ var PairController = class {
25036
25035
  await this.persist();
25037
25036
  }
25038
25037
  livePair(index) {
25039
- const pair = this.runtime.tradingPairs?.[index];
25038
+ const pair = this.runtime.tradingPairs[index];
25040
25039
  if (!pair) throw new Error(`Unknown pair ${index}`);
25041
25040
  return pair;
25042
25041
  }
@@ -25128,9 +25127,9 @@ var ChainController = class {
25128
25127
  throw error;
25129
25128
  }
25130
25129
  const curve = confirmationPolicies[String(chainId)];
25131
- if (curve) this.runtime.confirmationPolicy?.add(chainId, curve);
25132
- else if (!this.runtime.confirmationPolicy?.has(chainId)) {
25133
- this.runtime.confirmationPolicy?.adopt(chainId, resolvedPolicy);
25130
+ if (curve) this.runtime.confirmationPolicy.add(chainId, curve);
25131
+ else if (!this.runtime.confirmationPolicy.has(chainId)) {
25132
+ this.runtime.confirmationPolicy.adopt(chainId, resolvedPolicy);
25134
25133
  }
25135
25134
  this.runtime.resolvedChains.push(resolved);
25136
25135
  config.chains = [...config.chains, { rpcUrls: chain.rpcUrls, bundlerUrl: chain.bundlerUrl }];
@@ -25158,7 +25157,7 @@ var ChainController = class {
25158
25157
  await intentFiller.removeChain(chainId);
25159
25158
  if (this.ownsScanner) await this.scanner.removeChain(chainId);
25160
25159
  configService.removeChain(chainId);
25161
- this.runtime.confirmationPolicy?.remove(chainId);
25160
+ this.runtime.confirmationPolicy.remove(chainId);
25162
25161
  this.runtime.chainClientManager.invalidate(chainKey);
25163
25162
  this.runtime.resolvedChains.splice(index, 1);
25164
25163
  config.chains = config.chains.filter((_, i) => i !== index);