@hyperbridge/sdk 1.6.6 → 1.6.7

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.
@@ -15961,6 +15961,7 @@ var BidManager = class {
15961
15961
  async selectBid(order, bids, sessionPrivateKey) {
15962
15962
  const commitment = order.id;
15963
15963
  const sessionKeyAddress = order.session;
15964
+ console.log(`[BidManager] selectBid called for commitment=${commitment}, received ${bids.length} bid(s)`);
15964
15965
  const sessionKeyData = sessionPrivateKey ? { privateKey: sessionPrivateKey } : await this.ctx.sessionKeyStorage.getSessionKeyByAddress(sessionKeyAddress);
15965
15966
  if (!sessionKeyData) {
15966
15967
  throw new Error("SessionKey not found for commitment: " + commitment);
@@ -15972,6 +15973,7 @@ var BidManager = class {
15972
15973
  throw new Error("IntentsCoprocessor required");
15973
15974
  }
15974
15975
  const sortedBids = await this.validateAndSortBids(bids, order);
15976
+ console.log(`[BidManager] ${sortedBids.length}/${bids.length} bid(s) passed validation and sorting`);
15975
15977
  if (sortedBids.length === 0) {
15976
15978
  throw new Error("No valid bids found");
15977
15979
  }
@@ -15988,8 +15990,11 @@ var BidManager = class {
15988
15990
  );
15989
15991
  let selectedBid = null;
15990
15992
  let sessionSignature = null;
15991
- for (const bidWithOptions of sortedBids) {
15993
+ console.log(`[BidManager] Simulating ${sortedBids.length} sorted bid(s) to find a valid one`);
15994
+ for (let idx = 0; idx < sortedBids.length; idx++) {
15995
+ const bidWithOptions = sortedBids[idx];
15992
15996
  const solverAddress2 = bidWithOptions.bid.userOp.sender;
15997
+ console.log(`[BidManager] Simulating bid ${idx + 1}/${sortedBids.length} from solver=${solverAddress2}`);
15993
15998
  const signature = await this.crypto.signSolverSelection(
15994
15999
  commitment,
15995
16000
  solverAddress2,
@@ -15997,6 +16002,7 @@ var BidManager = class {
15997
16002
  sessionKeyData.privateKey
15998
16003
  );
15999
16004
  if (!signature) {
16005
+ console.warn(`[BidManager] Bid ${idx + 1}: failed to sign solver selection, skipping`);
16000
16006
  continue;
16001
16007
  }
16002
16008
  const selectOptions = {
@@ -16006,22 +16012,19 @@ var BidManager = class {
16006
16012
  };
16007
16013
  try {
16008
16014
  await this.simulate(bidWithOptions.bid, selectOptions, intentGatewayV2Address);
16015
+ console.log(`[BidManager] Bid ${idx + 1} from solver=${solverAddress2}: simulation PASSED`);
16009
16016
  selectedBid = bidWithOptions;
16010
16017
  sessionSignature = signature;
16011
16018
  break;
16012
16019
  } catch (err) {
16013
- console.debug(
16014
- "Bid simulation failed",
16015
- JSON.stringify({
16016
- commitment,
16017
- solver: solverAddress2,
16018
- error: err instanceof Error ? err.message : String(err)
16019
- })
16020
+ console.warn(
16021
+ `[BidManager] Bid ${idx + 1} from solver=${solverAddress2}: simulation FAILED: ${err instanceof Error ? err.message : String(err)}`
16020
16022
  );
16021
16023
  continue;
16022
16024
  }
16023
16025
  }
16024
16026
  if (!selectedBid || !sessionSignature) {
16027
+ console.error(`[BidManager] All ${sortedBids.length} bid(s) failed simulation for commitment=${commitment}`);
16025
16028
  throw new Error("No bids passed simulation");
16026
16029
  }
16027
16030
  const solverAddress = selectedBid.bid.userOp.sender;
@@ -16099,13 +16102,16 @@ var BidManager = class {
16099
16102
  const outputs = order.output.assets;
16100
16103
  const decodedBids = this.decodeBids(bids);
16101
16104
  if (outputs.length <= 1) {
16105
+ console.log(`[BidManager] Using single-output sorting (1 output asset)`);
16102
16106
  return this.sortSingleOutput(decodedBids, outputs[0]);
16103
16107
  }
16104
16108
  const chainId = this.ctx.dest.config.stateMachineId;
16105
16109
  const allStables = outputs.every((o) => this.isStableToken(bytes32ToBytes20(o.token), chainId));
16106
16110
  if (allStables) {
16111
+ console.log(`[BidManager] Using all-stables sorting (${outputs.length} stable output assets)`);
16107
16112
  return this.sortAllStables(decodedBids, outputs, chainId);
16108
16113
  }
16114
+ console.log(`[BidManager] Using mixed-output sorting (${outputs.length} output assets, some non-stable)`);
16109
16115
  return this.sortMixedOutputs(decodedBids, outputs, chainId);
16110
16116
  }
16111
16117
  decodeBids(bids) {
@@ -16114,8 +16120,11 @@ var BidManager = class {
16114
16120
  const fillOptions = this.decodeBidFillOptions(bid);
16115
16121
  if (fillOptions) {
16116
16122
  result.push({ bid, options: fillOptions });
16123
+ } else {
16124
+ console.warn(`[BidManager] Failed to decode fillOptions from bid by solver=${bid.userOp.sender}`);
16117
16125
  }
16118
16126
  }
16127
+ console.log(`[BidManager] Decoded ${result.length}/${bids.length} bid(s) successfully`);
16119
16128
  return result;
16120
16129
  }
16121
16130
  decodeBidFillOptions(bid) {
@@ -16170,12 +16179,29 @@ var BidManager = class {
16170
16179
  * Filter bids whose first output amount < required, sort descending.
16171
16180
  */
16172
16181
  sortSingleOutput(decodedBids, requiredAsset) {
16182
+ const requiredAmount = new Decimal3(requiredAsset.amount.toString());
16183
+ console.log(
16184
+ `[BidManager] sortSingleOutput: required token=${requiredAsset.token}, amount=${requiredAmount.toString()}`
16185
+ );
16173
16186
  const validBids = [];
16174
16187
  for (const { bid, options } of decodedBids) {
16175
16188
  const bidOutput = options.outputs[0];
16176
16189
  const bidAmount = new Decimal3(bidOutput.amount.toString());
16177
- const requiredAmount = new Decimal3(requiredAsset.amount.toString());
16178
- if (bidAmount.lt(requiredAmount)) continue;
16190
+ if (bidOutput.token.toLowerCase() !== requiredAsset.token.toLowerCase()) {
16191
+ console.warn(
16192
+ `[BidManager] Bid from solver=${bid.userOp.sender} REJECTED: token mismatch (bid=${bidOutput.token}, required=${requiredAsset.token})`
16193
+ );
16194
+ continue;
16195
+ }
16196
+ if (bidAmount.lt(requiredAmount)) {
16197
+ console.warn(
16198
+ `[BidManager] Bid from solver=${bid.userOp.sender} REJECTED: amount too low (bid=${bidAmount.toString()}, required=${requiredAmount.toString()}, shortfall=${requiredAmount.minus(bidAmount).toString()})`
16199
+ );
16200
+ continue;
16201
+ }
16202
+ console.log(
16203
+ `[BidManager] Bid from solver=${bid.userOp.sender} ACCEPTED: amount=${bidAmount.toString()} (surplus=${bidAmount.minus(requiredAmount).toString()})`
16204
+ );
16179
16205
  validBids.push({ bid, options, amount: bidOutput.amount });
16180
16206
  }
16181
16207
  validBids.sort((a, b) => {
@@ -16191,10 +16217,19 @@ var BidManager = class {
16191
16217
  */
16192
16218
  sortAllStables(decodedBids, orderOutputs, chainId) {
16193
16219
  const requiredUsd = this.computeStablesUsdValue(orderOutputs, chainId);
16220
+ console.log(`[BidManager] sortAllStables: required USD value=${requiredUsd.toString()}`);
16194
16221
  const validBids = [];
16195
16222
  for (const { bid, options } of decodedBids) {
16196
16223
  const bidUsd = this.computeStablesUsdValue(options.outputs, chainId);
16197
- if (bidUsd === null || bidUsd.lt(requiredUsd)) continue;
16224
+ if (bidUsd === null || bidUsd.lt(requiredUsd)) {
16225
+ console.warn(
16226
+ `[BidManager] Bid from solver=${bid.userOp.sender} REJECTED: USD value too low (bid=${bidUsd?.toString() ?? "null"}, required=${requiredUsd.toString()})`
16227
+ );
16228
+ continue;
16229
+ }
16230
+ console.log(
16231
+ `[BidManager] Bid from solver=${bid.userOp.sender} ACCEPTED: USD value=${bidUsd.toString()}`
16232
+ );
16198
16233
  validBids.push({ bid, options, usdValue: bidUsd });
16199
16234
  }
16200
16235
  validBids.sort((a, b) => b.usdValue.comparedTo(a.usdValue));
@@ -16208,13 +16243,22 @@ var BidManager = class {
16208
16243
  async sortMixedOutputs(decodedBids, orderOutputs, chainId) {
16209
16244
  const requiredUsd = await this.computeOutputsUsdValue(orderOutputs, chainId);
16210
16245
  if (requiredUsd === null) {
16211
- console.warn("BidManager: output tokens unpriceable, falling back to raw-amount sort");
16246
+ console.warn("[BidManager] sortMixedOutputs: output tokens unpriceable, falling back to raw-amount sort");
16212
16247
  return this.sortByRawAmountFallback(decodedBids, orderOutputs);
16213
16248
  }
16249
+ console.log(`[BidManager] sortMixedOutputs: required USD value=${requiredUsd.toString()}`);
16214
16250
  const validBids = [];
16215
16251
  for (const { bid, options } of decodedBids) {
16216
16252
  const bidUsd = await this.computeOutputsUsdValue(options.outputs, chainId);
16217
- if (bidUsd === null || bidUsd.lt(requiredUsd)) continue;
16253
+ if (bidUsd === null || bidUsd.lt(requiredUsd)) {
16254
+ console.warn(
16255
+ `[BidManager] Bid from solver=${bid.userOp.sender} REJECTED: mixed USD value too low (bid=${bidUsd?.toString() ?? "unpriceable"}, required=${requiredUsd.toString()})`
16256
+ );
16257
+ continue;
16258
+ }
16259
+ console.log(
16260
+ `[BidManager] Bid from solver=${bid.userOp.sender} ACCEPTED: mixed USD value=${bidUsd.toString()}`
16261
+ );
16218
16262
  validBids.push({ bid, options, usdValue: bidUsd });
16219
16263
  }
16220
16264
  validBids.sort((a, b) => b.usdValue.comparedTo(a.usdValue));
@@ -16227,21 +16271,35 @@ var BidManager = class {
16227
16271
  * Remaining bids are sorted by total spread descending.
16228
16272
  */
16229
16273
  sortByRawAmountFallback(decodedBids, orderOutputs) {
16274
+ console.log(`[BidManager] sortByRawAmountFallback: checking ${decodedBids.length} bid(s) against ${orderOutputs.length} required output(s)`);
16230
16275
  const validBids = [];
16231
16276
  for (const { bid, options } of decodedBids) {
16232
16277
  let valid = true;
16233
16278
  let totalSpread = new Decimal3(0);
16279
+ let rejectReason = "";
16234
16280
  for (const required of orderOutputs) {
16235
16281
  const matching = options.outputs.find((o) => o.token.toLowerCase() === required.token.toLowerCase());
16236
- if (!matching || matching.amount < required.amount) {
16282
+ if (!matching) {
16237
16283
  valid = false;
16284
+ rejectReason = `missing output token=${required.token}`;
16285
+ break;
16286
+ }
16287
+ if (matching.amount < required.amount) {
16288
+ valid = false;
16289
+ rejectReason = `token=${required.token} amount too low (bid=${matching.amount.toString()}, required=${required.amount.toString()})`;
16238
16290
  break;
16239
16291
  }
16240
16292
  totalSpread = totalSpread.plus(
16241
16293
  new Decimal3(matching.amount.toString()).minus(required.amount.toString())
16242
16294
  );
16243
16295
  }
16244
- if (!valid) continue;
16296
+ if (!valid) {
16297
+ console.warn(`[BidManager] Bid from solver=${bid.userOp.sender} REJECTED (fallback): ${rejectReason}`);
16298
+ continue;
16299
+ }
16300
+ console.log(
16301
+ `[BidManager] Bid from solver=${bid.userOp.sender} ACCEPTED (fallback): totalSpread=${totalSpread.toString()}`
16302
+ );
16245
16303
  validBids.push({ bid, options, totalSpread });
16246
16304
  }
16247
16305
  validBids.sort((a, b) => b.totalSpread.comparedTo(a.totalSpread));
@@ -16486,7 +16544,7 @@ var GasEstimator = class {
16486
16544
  BundlerMethod.ETH_ESTIMATE_USER_OPERATION_GAS,
16487
16545
  [bundlerUserOp, entryPointAddress, bundlerStateOverrides]
16488
16546
  );
16489
- callGasLimit = BigInt(gasEstimate.callGasLimit) * 130n / 100n;
16547
+ callGasLimit = BigInt(gasEstimate.callGasLimit) * 160n / 100n;
16490
16548
  verificationGasLimit = BigInt(gasEstimate.verificationGasLimit) * 105n / 100n;
16491
16549
  preVerificationGas = BigInt(gasEstimate.preVerificationGas) * 105n / 100n;
16492
16550
  if (this.ctx.bundlerUrl?.toLowerCase().includes("pimlico.io")) {
@@ -16806,6 +16864,9 @@ var IntentsV2 = class _IntentsV2 {
16806
16864
  maxPriorityFeePerGasBumpPercent: options?.maxPriorityFeePerGasBumpPercent,
16807
16865
  maxFeePerGasBumpPercent: options?.maxFeePerGasBumpPercent
16808
16866
  });
16867
+ if (estimate.totalGasCostWei === 0n || estimate.totalGasInFeeToken === 0n) {
16868
+ throw new Error("Gas estimation failed");
16869
+ }
16809
16870
  feesInWei = estimate.totalGasCostWei + estimate.totalGasCostWei * 2n / 100n;
16810
16871
  order.fees = estimate.totalGasInFeeToken + estimate.totalGasInFeeToken * 1n / 100n;
16811
16872
  }