@hyperbridge/sdk 1.6.5 → 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 +84 -19
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.js +84 -19
- package/dist/node/index.js.map +1 -1
- package/package.json +1 -1
package/dist/node/index.js
CHANGED
|
@@ -548,12 +548,14 @@ var chainConfigs = {
|
|
|
548
548
|
DAI: "0x50c5725949a6f0c72e6c4a641f24049a917db0cb",
|
|
549
549
|
USDC: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
|
|
550
550
|
USDT: "0xfde4c96c8593536e31f229ea8f37b2ada2699bb2",
|
|
551
|
+
EXT: "0x0e668E5127087e236578893a0e01E41837A28469",
|
|
551
552
|
cNGN: "0x46C85152bFe9f96829aA94755D9f915F9B10EF5F"
|
|
552
553
|
},
|
|
553
554
|
tokenDecimals: {
|
|
554
555
|
USDC: 6,
|
|
555
556
|
USDT: 6,
|
|
556
|
-
cNGN: 6
|
|
557
|
+
cNGN: 6,
|
|
558
|
+
EXT: 18
|
|
557
559
|
},
|
|
558
560
|
tokenStorageSlots: {
|
|
559
561
|
USDT: { balanceSlot: 0, allowanceSlot: 1 },
|
|
@@ -600,11 +602,13 @@ var chainConfigs = {
|
|
|
600
602
|
DAI: "0x8f3cf7ad23cd3cadbd9735aff958023239c6a063",
|
|
601
603
|
USDC: "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359",
|
|
602
604
|
USDT: "0xc2132d05d31c914a87c6611c10748aeb04b58e8f",
|
|
605
|
+
EXT: "0x7C8c11ADb8EF7cd3CFa718008Ea048445C6E7209",
|
|
603
606
|
cNGN: "0x52828daa48C1a9A06F37500882b42daf0bE04C3B"
|
|
604
607
|
},
|
|
605
608
|
tokenDecimals: {
|
|
606
609
|
USDC: 6,
|
|
607
610
|
USDT: 6,
|
|
611
|
+
EXT: 18,
|
|
608
612
|
cNGN: 6
|
|
609
613
|
},
|
|
610
614
|
tokenStorageSlots: {
|
|
@@ -15897,6 +15901,7 @@ var BidManager = class {
|
|
|
15897
15901
|
async selectBid(order, bids, sessionPrivateKey) {
|
|
15898
15902
|
const commitment = order.id;
|
|
15899
15903
|
const sessionKeyAddress = order.session;
|
|
15904
|
+
console.log(`[BidManager] selectBid called for commitment=${commitment}, received ${bids.length} bid(s)`);
|
|
15900
15905
|
const sessionKeyData = sessionPrivateKey ? { privateKey: sessionPrivateKey } : await this.ctx.sessionKeyStorage.getSessionKeyByAddress(sessionKeyAddress);
|
|
15901
15906
|
if (!sessionKeyData) {
|
|
15902
15907
|
throw new Error("SessionKey not found for commitment: " + commitment);
|
|
@@ -15908,6 +15913,7 @@ var BidManager = class {
|
|
|
15908
15913
|
throw new Error("IntentsCoprocessor required");
|
|
15909
15914
|
}
|
|
15910
15915
|
const sortedBids = await this.validateAndSortBids(bids, order);
|
|
15916
|
+
console.log(`[BidManager] ${sortedBids.length}/${bids.length} bid(s) passed validation and sorting`);
|
|
15911
15917
|
if (sortedBids.length === 0) {
|
|
15912
15918
|
throw new Error("No valid bids found");
|
|
15913
15919
|
}
|
|
@@ -15924,8 +15930,11 @@ var BidManager = class {
|
|
|
15924
15930
|
);
|
|
15925
15931
|
let selectedBid = null;
|
|
15926
15932
|
let sessionSignature = null;
|
|
15927
|
-
|
|
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];
|
|
15928
15936
|
const solverAddress2 = bidWithOptions.bid.userOp.sender;
|
|
15937
|
+
console.log(`[BidManager] Simulating bid ${idx + 1}/${sortedBids.length} from solver=${solverAddress2}`);
|
|
15929
15938
|
const signature = await this.crypto.signSolverSelection(
|
|
15930
15939
|
commitment,
|
|
15931
15940
|
solverAddress2,
|
|
@@ -15933,6 +15942,7 @@ var BidManager = class {
|
|
|
15933
15942
|
sessionKeyData.privateKey
|
|
15934
15943
|
);
|
|
15935
15944
|
if (!signature) {
|
|
15945
|
+
console.warn(`[BidManager] Bid ${idx + 1}: failed to sign solver selection, skipping`);
|
|
15936
15946
|
continue;
|
|
15937
15947
|
}
|
|
15938
15948
|
const selectOptions = {
|
|
@@ -15942,22 +15952,19 @@ var BidManager = class {
|
|
|
15942
15952
|
};
|
|
15943
15953
|
try {
|
|
15944
15954
|
await this.simulate(bidWithOptions.bid, selectOptions, intentGatewayV2Address);
|
|
15955
|
+
console.log(`[BidManager] Bid ${idx + 1} from solver=${solverAddress2}: simulation PASSED`);
|
|
15945
15956
|
selectedBid = bidWithOptions;
|
|
15946
15957
|
sessionSignature = signature;
|
|
15947
15958
|
break;
|
|
15948
15959
|
} catch (err) {
|
|
15949
|
-
console.
|
|
15950
|
-
|
|
15951
|
-
JSON.stringify({
|
|
15952
|
-
commitment,
|
|
15953
|
-
solver: solverAddress2,
|
|
15954
|
-
error: err instanceof Error ? err.message : String(err)
|
|
15955
|
-
})
|
|
15960
|
+
console.warn(
|
|
15961
|
+
`[BidManager] Bid ${idx + 1} from solver=${solverAddress2}: simulation FAILED: ${err instanceof Error ? err.message : String(err)}`
|
|
15956
15962
|
);
|
|
15957
15963
|
continue;
|
|
15958
15964
|
}
|
|
15959
15965
|
}
|
|
15960
15966
|
if (!selectedBid || !sessionSignature) {
|
|
15967
|
+
console.error(`[BidManager] All ${sortedBids.length} bid(s) failed simulation for commitment=${commitment}`);
|
|
15961
15968
|
throw new Error("No bids passed simulation");
|
|
15962
15969
|
}
|
|
15963
15970
|
const solverAddress = selectedBid.bid.userOp.sender;
|
|
@@ -16035,13 +16042,16 @@ var BidManager = class {
|
|
|
16035
16042
|
const outputs = order.output.assets;
|
|
16036
16043
|
const decodedBids = this.decodeBids(bids);
|
|
16037
16044
|
if (outputs.length <= 1) {
|
|
16045
|
+
console.log(`[BidManager] Using single-output sorting (1 output asset)`);
|
|
16038
16046
|
return this.sortSingleOutput(decodedBids, outputs[0]);
|
|
16039
16047
|
}
|
|
16040
16048
|
const chainId = this.ctx.dest.config.stateMachineId;
|
|
16041
16049
|
const allStables = outputs.every((o) => this.isStableToken(bytes32ToBytes20(o.token), chainId));
|
|
16042
16050
|
if (allStables) {
|
|
16051
|
+
console.log(`[BidManager] Using all-stables sorting (${outputs.length} stable output assets)`);
|
|
16043
16052
|
return this.sortAllStables(decodedBids, outputs, chainId);
|
|
16044
16053
|
}
|
|
16054
|
+
console.log(`[BidManager] Using mixed-output sorting (${outputs.length} output assets, some non-stable)`);
|
|
16045
16055
|
return this.sortMixedOutputs(decodedBids, outputs, chainId);
|
|
16046
16056
|
}
|
|
16047
16057
|
decodeBids(bids) {
|
|
@@ -16050,8 +16060,11 @@ var BidManager = class {
|
|
|
16050
16060
|
const fillOptions = this.decodeBidFillOptions(bid);
|
|
16051
16061
|
if (fillOptions) {
|
|
16052
16062
|
result.push({ bid, options: fillOptions });
|
|
16063
|
+
} else {
|
|
16064
|
+
console.warn(`[BidManager] Failed to decode fillOptions from bid by solver=${bid.userOp.sender}`);
|
|
16053
16065
|
}
|
|
16054
16066
|
}
|
|
16067
|
+
console.log(`[BidManager] Decoded ${result.length}/${bids.length} bid(s) successfully`);
|
|
16055
16068
|
return result;
|
|
16056
16069
|
}
|
|
16057
16070
|
decodeBidFillOptions(bid) {
|
|
@@ -16106,12 +16119,29 @@ var BidManager = class {
|
|
|
16106
16119
|
* Filter bids whose first output amount < required, sort descending.
|
|
16107
16120
|
*/
|
|
16108
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
|
+
);
|
|
16109
16126
|
const validBids = [];
|
|
16110
16127
|
for (const { bid, options } of decodedBids) {
|
|
16111
16128
|
const bidOutput = options.outputs[0];
|
|
16112
16129
|
const bidAmount = new Decimal3(bidOutput.amount.toString());
|
|
16113
|
-
|
|
16114
|
-
|
|
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
|
+
);
|
|
16115
16145
|
validBids.push({ bid, options, amount: bidOutput.amount });
|
|
16116
16146
|
}
|
|
16117
16147
|
validBids.sort((a, b) => {
|
|
@@ -16127,10 +16157,19 @@ var BidManager = class {
|
|
|
16127
16157
|
*/
|
|
16128
16158
|
sortAllStables(decodedBids, orderOutputs, chainId) {
|
|
16129
16159
|
const requiredUsd = this.computeStablesUsdValue(orderOutputs, chainId);
|
|
16160
|
+
console.log(`[BidManager] sortAllStables: required USD value=${requiredUsd.toString()}`);
|
|
16130
16161
|
const validBids = [];
|
|
16131
16162
|
for (const { bid, options } of decodedBids) {
|
|
16132
16163
|
const bidUsd = this.computeStablesUsdValue(options.outputs, chainId);
|
|
16133
|
-
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
|
+
);
|
|
16134
16173
|
validBids.push({ bid, options, usdValue: bidUsd });
|
|
16135
16174
|
}
|
|
16136
16175
|
validBids.sort((a, b) => b.usdValue.comparedTo(a.usdValue));
|
|
@@ -16144,13 +16183,22 @@ var BidManager = class {
|
|
|
16144
16183
|
async sortMixedOutputs(decodedBids, orderOutputs, chainId) {
|
|
16145
16184
|
const requiredUsd = await this.computeOutputsUsdValue(orderOutputs, chainId);
|
|
16146
16185
|
if (requiredUsd === null) {
|
|
16147
|
-
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");
|
|
16148
16187
|
return this.sortByRawAmountFallback(decodedBids, orderOutputs);
|
|
16149
16188
|
}
|
|
16189
|
+
console.log(`[BidManager] sortMixedOutputs: required USD value=${requiredUsd.toString()}`);
|
|
16150
16190
|
const validBids = [];
|
|
16151
16191
|
for (const { bid, options } of decodedBids) {
|
|
16152
16192
|
const bidUsd = await this.computeOutputsUsdValue(options.outputs, chainId);
|
|
16153
|
-
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
|
+
);
|
|
16154
16202
|
validBids.push({ bid, options, usdValue: bidUsd });
|
|
16155
16203
|
}
|
|
16156
16204
|
validBids.sort((a, b) => b.usdValue.comparedTo(a.usdValue));
|
|
@@ -16163,21 +16211,35 @@ var BidManager = class {
|
|
|
16163
16211
|
* Remaining bids are sorted by total spread descending.
|
|
16164
16212
|
*/
|
|
16165
16213
|
sortByRawAmountFallback(decodedBids, orderOutputs) {
|
|
16214
|
+
console.log(`[BidManager] sortByRawAmountFallback: checking ${decodedBids.length} bid(s) against ${orderOutputs.length} required output(s)`);
|
|
16166
16215
|
const validBids = [];
|
|
16167
16216
|
for (const { bid, options } of decodedBids) {
|
|
16168
16217
|
let valid = true;
|
|
16169
16218
|
let totalSpread = new Decimal3(0);
|
|
16219
|
+
let rejectReason = "";
|
|
16170
16220
|
for (const required of orderOutputs) {
|
|
16171
16221
|
const matching = options.outputs.find((o) => o.token.toLowerCase() === required.token.toLowerCase());
|
|
16172
|
-
if (!matching
|
|
16222
|
+
if (!matching) {
|
|
16173
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()})`;
|
|
16174
16230
|
break;
|
|
16175
16231
|
}
|
|
16176
16232
|
totalSpread = totalSpread.plus(
|
|
16177
16233
|
new Decimal3(matching.amount.toString()).minus(required.amount.toString())
|
|
16178
16234
|
);
|
|
16179
16235
|
}
|
|
16180
|
-
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
|
+
);
|
|
16181
16243
|
validBids.push({ bid, options, totalSpread });
|
|
16182
16244
|
}
|
|
16183
16245
|
validBids.sort((a, b) => b.totalSpread.comparedTo(a.totalSpread));
|
|
@@ -16422,7 +16484,7 @@ var GasEstimator = class {
|
|
|
16422
16484
|
BundlerMethod.ETH_ESTIMATE_USER_OPERATION_GAS,
|
|
16423
16485
|
[bundlerUserOp, entryPointAddress, bundlerStateOverrides]
|
|
16424
16486
|
);
|
|
16425
|
-
callGasLimit = BigInt(gasEstimate.callGasLimit) *
|
|
16487
|
+
callGasLimit = BigInt(gasEstimate.callGasLimit) * 160n / 100n;
|
|
16426
16488
|
verificationGasLimit = BigInt(gasEstimate.verificationGasLimit) * 105n / 100n;
|
|
16427
16489
|
preVerificationGas = BigInt(gasEstimate.preVerificationGas) * 105n / 100n;
|
|
16428
16490
|
if (this.ctx.bundlerUrl?.toLowerCase().includes("pimlico.io")) {
|
|
@@ -16435,8 +16497,8 @@ var GasEstimator = class {
|
|
|
16435
16497
|
if (level) {
|
|
16436
16498
|
const pimMaxFeePerGas = BigInt(level.maxFeePerGas);
|
|
16437
16499
|
const pimMaxPriorityFeePerGas = BigInt(level.maxPriorityFeePerGas);
|
|
16438
|
-
maxFeePerGas = pimMaxFeePerGas;
|
|
16439
|
-
maxPriorityFeePerGas = pimMaxPriorityFeePerGas;
|
|
16500
|
+
maxFeePerGas = pimMaxFeePerGas + pimMaxFeePerGas * BigInt(maxFeeBumpPercent) / 100n;
|
|
16501
|
+
maxPriorityFeePerGas = pimMaxPriorityFeePerGas + pimMaxPriorityFeePerGas * BigInt(priorityFeeBumpPercent) / 100n;
|
|
16440
16502
|
}
|
|
16441
16503
|
} catch (e) {
|
|
16442
16504
|
console.warn("Pimlico gas price fetch failed, using default gas price:", e);
|
|
@@ -16742,6 +16804,9 @@ var IntentsV2 = class _IntentsV2 {
|
|
|
16742
16804
|
maxPriorityFeePerGasBumpPercent: options?.maxPriorityFeePerGasBumpPercent,
|
|
16743
16805
|
maxFeePerGasBumpPercent: options?.maxFeePerGasBumpPercent
|
|
16744
16806
|
});
|
|
16807
|
+
if (estimate.totalGasCostWei === 0n || estimate.totalGasInFeeToken === 0n) {
|
|
16808
|
+
throw new Error("Gas estimation failed");
|
|
16809
|
+
}
|
|
16745
16810
|
feesInWei = estimate.totalGasCostWei + estimate.totalGasCostWei * 2n / 100n;
|
|
16746
16811
|
order.fees = estimate.totalGasInFeeToken + estimate.totalGasInFeeToken * 1n / 100n;
|
|
16747
16812
|
}
|