@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.
- package/dist/browser/index.js +77 -16
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.js +77 -16
- package/dist/node/index.js.map +1 -1
- package/package.json +1 -1
package/dist/node/index.js
CHANGED
|
@@ -15901,6 +15901,7 @@ var BidManager = class {
|
|
|
15901
15901
|
async selectBid(order, bids, sessionPrivateKey) {
|
|
15902
15902
|
const commitment = order.id;
|
|
15903
15903
|
const sessionKeyAddress = order.session;
|
|
15904
|
+
console.log(`[BidManager] selectBid called for commitment=${commitment}, received ${bids.length} bid(s)`);
|
|
15904
15905
|
const sessionKeyData = sessionPrivateKey ? { privateKey: sessionPrivateKey } : await this.ctx.sessionKeyStorage.getSessionKeyByAddress(sessionKeyAddress);
|
|
15905
15906
|
if (!sessionKeyData) {
|
|
15906
15907
|
throw new Error("SessionKey not found for commitment: " + commitment);
|
|
@@ -15912,6 +15913,7 @@ var BidManager = class {
|
|
|
15912
15913
|
throw new Error("IntentsCoprocessor required");
|
|
15913
15914
|
}
|
|
15914
15915
|
const sortedBids = await this.validateAndSortBids(bids, order);
|
|
15916
|
+
console.log(`[BidManager] ${sortedBids.length}/${bids.length} bid(s) passed validation and sorting`);
|
|
15915
15917
|
if (sortedBids.length === 0) {
|
|
15916
15918
|
throw new Error("No valid bids found");
|
|
15917
15919
|
}
|
|
@@ -15928,8 +15930,11 @@ var BidManager = class {
|
|
|
15928
15930
|
);
|
|
15929
15931
|
let selectedBid = null;
|
|
15930
15932
|
let sessionSignature = null;
|
|
15931
|
-
|
|
15933
|
+
console.log(`[BidManager] Simulating ${sortedBids.length} sorted bid(s) to find a valid one`);
|
|
15934
|
+
for (let idx = 0; idx < sortedBids.length; idx++) {
|
|
15935
|
+
const bidWithOptions = sortedBids[idx];
|
|
15932
15936
|
const solverAddress2 = bidWithOptions.bid.userOp.sender;
|
|
15937
|
+
console.log(`[BidManager] Simulating bid ${idx + 1}/${sortedBids.length} from solver=${solverAddress2}`);
|
|
15933
15938
|
const signature = await this.crypto.signSolverSelection(
|
|
15934
15939
|
commitment,
|
|
15935
15940
|
solverAddress2,
|
|
@@ -15937,6 +15942,7 @@ var BidManager = class {
|
|
|
15937
15942
|
sessionKeyData.privateKey
|
|
15938
15943
|
);
|
|
15939
15944
|
if (!signature) {
|
|
15945
|
+
console.warn(`[BidManager] Bid ${idx + 1}: failed to sign solver selection, skipping`);
|
|
15940
15946
|
continue;
|
|
15941
15947
|
}
|
|
15942
15948
|
const selectOptions = {
|
|
@@ -15946,22 +15952,19 @@ var BidManager = class {
|
|
|
15946
15952
|
};
|
|
15947
15953
|
try {
|
|
15948
15954
|
await this.simulate(bidWithOptions.bid, selectOptions, intentGatewayV2Address);
|
|
15955
|
+
console.log(`[BidManager] Bid ${idx + 1} from solver=${solverAddress2}: simulation PASSED`);
|
|
15949
15956
|
selectedBid = bidWithOptions;
|
|
15950
15957
|
sessionSignature = signature;
|
|
15951
15958
|
break;
|
|
15952
15959
|
} catch (err) {
|
|
15953
|
-
console.
|
|
15954
|
-
|
|
15955
|
-
JSON.stringify({
|
|
15956
|
-
commitment,
|
|
15957
|
-
solver: solverAddress2,
|
|
15958
|
-
error: err instanceof Error ? err.message : String(err)
|
|
15959
|
-
})
|
|
15960
|
+
console.warn(
|
|
15961
|
+
`[BidManager] Bid ${idx + 1} from solver=${solverAddress2}: simulation FAILED: ${err instanceof Error ? err.message : String(err)}`
|
|
15960
15962
|
);
|
|
15961
15963
|
continue;
|
|
15962
15964
|
}
|
|
15963
15965
|
}
|
|
15964
15966
|
if (!selectedBid || !sessionSignature) {
|
|
15967
|
+
console.error(`[BidManager] All ${sortedBids.length} bid(s) failed simulation for commitment=${commitment}`);
|
|
15965
15968
|
throw new Error("No bids passed simulation");
|
|
15966
15969
|
}
|
|
15967
15970
|
const solverAddress = selectedBid.bid.userOp.sender;
|
|
@@ -16039,13 +16042,16 @@ var BidManager = class {
|
|
|
16039
16042
|
const outputs = order.output.assets;
|
|
16040
16043
|
const decodedBids = this.decodeBids(bids);
|
|
16041
16044
|
if (outputs.length <= 1) {
|
|
16045
|
+
console.log(`[BidManager] Using single-output sorting (1 output asset)`);
|
|
16042
16046
|
return this.sortSingleOutput(decodedBids, outputs[0]);
|
|
16043
16047
|
}
|
|
16044
16048
|
const chainId = this.ctx.dest.config.stateMachineId;
|
|
16045
16049
|
const allStables = outputs.every((o) => this.isStableToken(bytes32ToBytes20(o.token), chainId));
|
|
16046
16050
|
if (allStables) {
|
|
16051
|
+
console.log(`[BidManager] Using all-stables sorting (${outputs.length} stable output assets)`);
|
|
16047
16052
|
return this.sortAllStables(decodedBids, outputs, chainId);
|
|
16048
16053
|
}
|
|
16054
|
+
console.log(`[BidManager] Using mixed-output sorting (${outputs.length} output assets, some non-stable)`);
|
|
16049
16055
|
return this.sortMixedOutputs(decodedBids, outputs, chainId);
|
|
16050
16056
|
}
|
|
16051
16057
|
decodeBids(bids) {
|
|
@@ -16054,8 +16060,11 @@ var BidManager = class {
|
|
|
16054
16060
|
const fillOptions = this.decodeBidFillOptions(bid);
|
|
16055
16061
|
if (fillOptions) {
|
|
16056
16062
|
result.push({ bid, options: fillOptions });
|
|
16063
|
+
} else {
|
|
16064
|
+
console.warn(`[BidManager] Failed to decode fillOptions from bid by solver=${bid.userOp.sender}`);
|
|
16057
16065
|
}
|
|
16058
16066
|
}
|
|
16067
|
+
console.log(`[BidManager] Decoded ${result.length}/${bids.length} bid(s) successfully`);
|
|
16059
16068
|
return result;
|
|
16060
16069
|
}
|
|
16061
16070
|
decodeBidFillOptions(bid) {
|
|
@@ -16110,12 +16119,29 @@ var BidManager = class {
|
|
|
16110
16119
|
* Filter bids whose first output amount < required, sort descending.
|
|
16111
16120
|
*/
|
|
16112
16121
|
sortSingleOutput(decodedBids, requiredAsset) {
|
|
16122
|
+
const requiredAmount = new Decimal3(requiredAsset.amount.toString());
|
|
16123
|
+
console.log(
|
|
16124
|
+
`[BidManager] sortSingleOutput: required token=${requiredAsset.token}, amount=${requiredAmount.toString()}`
|
|
16125
|
+
);
|
|
16113
16126
|
const validBids = [];
|
|
16114
16127
|
for (const { bid, options } of decodedBids) {
|
|
16115
16128
|
const bidOutput = options.outputs[0];
|
|
16116
16129
|
const bidAmount = new Decimal3(bidOutput.amount.toString());
|
|
16117
|
-
|
|
16118
|
-
|
|
16130
|
+
if (bidOutput.token.toLowerCase() !== requiredAsset.token.toLowerCase()) {
|
|
16131
|
+
console.warn(
|
|
16132
|
+
`[BidManager] Bid from solver=${bid.userOp.sender} REJECTED: token mismatch (bid=${bidOutput.token}, required=${requiredAsset.token})`
|
|
16133
|
+
);
|
|
16134
|
+
continue;
|
|
16135
|
+
}
|
|
16136
|
+
if (bidAmount.lt(requiredAmount)) {
|
|
16137
|
+
console.warn(
|
|
16138
|
+
`[BidManager] Bid from solver=${bid.userOp.sender} REJECTED: amount too low (bid=${bidAmount.toString()}, required=${requiredAmount.toString()}, shortfall=${requiredAmount.minus(bidAmount).toString()})`
|
|
16139
|
+
);
|
|
16140
|
+
continue;
|
|
16141
|
+
}
|
|
16142
|
+
console.log(
|
|
16143
|
+
`[BidManager] Bid from solver=${bid.userOp.sender} ACCEPTED: amount=${bidAmount.toString()} (surplus=${bidAmount.minus(requiredAmount).toString()})`
|
|
16144
|
+
);
|
|
16119
16145
|
validBids.push({ bid, options, amount: bidOutput.amount });
|
|
16120
16146
|
}
|
|
16121
16147
|
validBids.sort((a, b) => {
|
|
@@ -16131,10 +16157,19 @@ var BidManager = class {
|
|
|
16131
16157
|
*/
|
|
16132
16158
|
sortAllStables(decodedBids, orderOutputs, chainId) {
|
|
16133
16159
|
const requiredUsd = this.computeStablesUsdValue(orderOutputs, chainId);
|
|
16160
|
+
console.log(`[BidManager] sortAllStables: required USD value=${requiredUsd.toString()}`);
|
|
16134
16161
|
const validBids = [];
|
|
16135
16162
|
for (const { bid, options } of decodedBids) {
|
|
16136
16163
|
const bidUsd = this.computeStablesUsdValue(options.outputs, chainId);
|
|
16137
|
-
if (bidUsd === null || bidUsd.lt(requiredUsd))
|
|
16164
|
+
if (bidUsd === null || bidUsd.lt(requiredUsd)) {
|
|
16165
|
+
console.warn(
|
|
16166
|
+
`[BidManager] Bid from solver=${bid.userOp.sender} REJECTED: USD value too low (bid=${bidUsd?.toString() ?? "null"}, required=${requiredUsd.toString()})`
|
|
16167
|
+
);
|
|
16168
|
+
continue;
|
|
16169
|
+
}
|
|
16170
|
+
console.log(
|
|
16171
|
+
`[BidManager] Bid from solver=${bid.userOp.sender} ACCEPTED: USD value=${bidUsd.toString()}`
|
|
16172
|
+
);
|
|
16138
16173
|
validBids.push({ bid, options, usdValue: bidUsd });
|
|
16139
16174
|
}
|
|
16140
16175
|
validBids.sort((a, b) => b.usdValue.comparedTo(a.usdValue));
|
|
@@ -16148,13 +16183,22 @@ var BidManager = class {
|
|
|
16148
16183
|
async sortMixedOutputs(decodedBids, orderOutputs, chainId) {
|
|
16149
16184
|
const requiredUsd = await this.computeOutputsUsdValue(orderOutputs, chainId);
|
|
16150
16185
|
if (requiredUsd === null) {
|
|
16151
|
-
console.warn("BidManager: output tokens unpriceable, falling back to raw-amount sort");
|
|
16186
|
+
console.warn("[BidManager] sortMixedOutputs: output tokens unpriceable, falling back to raw-amount sort");
|
|
16152
16187
|
return this.sortByRawAmountFallback(decodedBids, orderOutputs);
|
|
16153
16188
|
}
|
|
16189
|
+
console.log(`[BidManager] sortMixedOutputs: required USD value=${requiredUsd.toString()}`);
|
|
16154
16190
|
const validBids = [];
|
|
16155
16191
|
for (const { bid, options } of decodedBids) {
|
|
16156
16192
|
const bidUsd = await this.computeOutputsUsdValue(options.outputs, chainId);
|
|
16157
|
-
if (bidUsd === null || bidUsd.lt(requiredUsd))
|
|
16193
|
+
if (bidUsd === null || bidUsd.lt(requiredUsd)) {
|
|
16194
|
+
console.warn(
|
|
16195
|
+
`[BidManager] Bid from solver=${bid.userOp.sender} REJECTED: mixed USD value too low (bid=${bidUsd?.toString() ?? "unpriceable"}, required=${requiredUsd.toString()})`
|
|
16196
|
+
);
|
|
16197
|
+
continue;
|
|
16198
|
+
}
|
|
16199
|
+
console.log(
|
|
16200
|
+
`[BidManager] Bid from solver=${bid.userOp.sender} ACCEPTED: mixed USD value=${bidUsd.toString()}`
|
|
16201
|
+
);
|
|
16158
16202
|
validBids.push({ bid, options, usdValue: bidUsd });
|
|
16159
16203
|
}
|
|
16160
16204
|
validBids.sort((a, b) => b.usdValue.comparedTo(a.usdValue));
|
|
@@ -16167,21 +16211,35 @@ var BidManager = class {
|
|
|
16167
16211
|
* Remaining bids are sorted by total spread descending.
|
|
16168
16212
|
*/
|
|
16169
16213
|
sortByRawAmountFallback(decodedBids, orderOutputs) {
|
|
16214
|
+
console.log(`[BidManager] sortByRawAmountFallback: checking ${decodedBids.length} bid(s) against ${orderOutputs.length} required output(s)`);
|
|
16170
16215
|
const validBids = [];
|
|
16171
16216
|
for (const { bid, options } of decodedBids) {
|
|
16172
16217
|
let valid = true;
|
|
16173
16218
|
let totalSpread = new Decimal3(0);
|
|
16219
|
+
let rejectReason = "";
|
|
16174
16220
|
for (const required of orderOutputs) {
|
|
16175
16221
|
const matching = options.outputs.find((o) => o.token.toLowerCase() === required.token.toLowerCase());
|
|
16176
|
-
if (!matching
|
|
16222
|
+
if (!matching) {
|
|
16177
16223
|
valid = false;
|
|
16224
|
+
rejectReason = `missing output token=${required.token}`;
|
|
16225
|
+
break;
|
|
16226
|
+
}
|
|
16227
|
+
if (matching.amount < required.amount) {
|
|
16228
|
+
valid = false;
|
|
16229
|
+
rejectReason = `token=${required.token} amount too low (bid=${matching.amount.toString()}, required=${required.amount.toString()})`;
|
|
16178
16230
|
break;
|
|
16179
16231
|
}
|
|
16180
16232
|
totalSpread = totalSpread.plus(
|
|
16181
16233
|
new Decimal3(matching.amount.toString()).minus(required.amount.toString())
|
|
16182
16234
|
);
|
|
16183
16235
|
}
|
|
16184
|
-
if (!valid)
|
|
16236
|
+
if (!valid) {
|
|
16237
|
+
console.warn(`[BidManager] Bid from solver=${bid.userOp.sender} REJECTED (fallback): ${rejectReason}`);
|
|
16238
|
+
continue;
|
|
16239
|
+
}
|
|
16240
|
+
console.log(
|
|
16241
|
+
`[BidManager] Bid from solver=${bid.userOp.sender} ACCEPTED (fallback): totalSpread=${totalSpread.toString()}`
|
|
16242
|
+
);
|
|
16185
16243
|
validBids.push({ bid, options, totalSpread });
|
|
16186
16244
|
}
|
|
16187
16245
|
validBids.sort((a, b) => b.totalSpread.comparedTo(a.totalSpread));
|
|
@@ -16426,7 +16484,7 @@ var GasEstimator = class {
|
|
|
16426
16484
|
BundlerMethod.ETH_ESTIMATE_USER_OPERATION_GAS,
|
|
16427
16485
|
[bundlerUserOp, entryPointAddress, bundlerStateOverrides]
|
|
16428
16486
|
);
|
|
16429
|
-
callGasLimit = BigInt(gasEstimate.callGasLimit) *
|
|
16487
|
+
callGasLimit = BigInt(gasEstimate.callGasLimit) * 160n / 100n;
|
|
16430
16488
|
verificationGasLimit = BigInt(gasEstimate.verificationGasLimit) * 105n / 100n;
|
|
16431
16489
|
preVerificationGas = BigInt(gasEstimate.preVerificationGas) * 105n / 100n;
|
|
16432
16490
|
if (this.ctx.bundlerUrl?.toLowerCase().includes("pimlico.io")) {
|
|
@@ -16746,6 +16804,9 @@ var IntentsV2 = class _IntentsV2 {
|
|
|
16746
16804
|
maxPriorityFeePerGasBumpPercent: options?.maxPriorityFeePerGasBumpPercent,
|
|
16747
16805
|
maxFeePerGasBumpPercent: options?.maxFeePerGasBumpPercent
|
|
16748
16806
|
});
|
|
16807
|
+
if (estimate.totalGasCostWei === 0n || estimate.totalGasInFeeToken === 0n) {
|
|
16808
|
+
throw new Error("Gas estimation failed");
|
|
16809
|
+
}
|
|
16749
16810
|
feesInWei = estimate.totalGasCostWei + estimate.totalGasCostWei * 2n / 100n;
|
|
16750
16811
|
order.fees = estimate.totalGasInFeeToken + estimate.totalGasInFeeToken * 1n / 100n;
|
|
16751
16812
|
}
|