@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/browser/index.js
CHANGED
|
@@ -598,12 +598,14 @@ var chainConfigs = {
|
|
|
598
598
|
DAI: "0x50c5725949a6f0c72e6c4a641f24049a917db0cb",
|
|
599
599
|
USDC: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
|
|
600
600
|
USDT: "0xfde4c96c8593536e31f229ea8f37b2ada2699bb2",
|
|
601
|
+
EXT: "0x0e668E5127087e236578893a0e01E41837A28469",
|
|
601
602
|
cNGN: "0x46C85152bFe9f96829aA94755D9f915F9B10EF5F"
|
|
602
603
|
},
|
|
603
604
|
tokenDecimals: {
|
|
604
605
|
USDC: 6,
|
|
605
606
|
USDT: 6,
|
|
606
|
-
cNGN: 6
|
|
607
|
+
cNGN: 6,
|
|
608
|
+
EXT: 18
|
|
607
609
|
},
|
|
608
610
|
tokenStorageSlots: {
|
|
609
611
|
USDT: { balanceSlot: 0, allowanceSlot: 1 },
|
|
@@ -650,11 +652,13 @@ var chainConfigs = {
|
|
|
650
652
|
DAI: "0x8f3cf7ad23cd3cadbd9735aff958023239c6a063",
|
|
651
653
|
USDC: "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359",
|
|
652
654
|
USDT: "0xc2132d05d31c914a87c6611c10748aeb04b58e8f",
|
|
655
|
+
EXT: "0x7C8c11ADb8EF7cd3CFa718008Ea048445C6E7209",
|
|
653
656
|
cNGN: "0x52828daa48C1a9A06F37500882b42daf0bE04C3B"
|
|
654
657
|
},
|
|
655
658
|
tokenDecimals: {
|
|
656
659
|
USDC: 6,
|
|
657
660
|
USDT: 6,
|
|
661
|
+
EXT: 18,
|
|
658
662
|
cNGN: 6
|
|
659
663
|
},
|
|
660
664
|
tokenStorageSlots: {
|
|
@@ -15957,6 +15961,7 @@ var BidManager = class {
|
|
|
15957
15961
|
async selectBid(order, bids, sessionPrivateKey) {
|
|
15958
15962
|
const commitment = order.id;
|
|
15959
15963
|
const sessionKeyAddress = order.session;
|
|
15964
|
+
console.log(`[BidManager] selectBid called for commitment=${commitment}, received ${bids.length} bid(s)`);
|
|
15960
15965
|
const sessionKeyData = sessionPrivateKey ? { privateKey: sessionPrivateKey } : await this.ctx.sessionKeyStorage.getSessionKeyByAddress(sessionKeyAddress);
|
|
15961
15966
|
if (!sessionKeyData) {
|
|
15962
15967
|
throw new Error("SessionKey not found for commitment: " + commitment);
|
|
@@ -15968,6 +15973,7 @@ var BidManager = class {
|
|
|
15968
15973
|
throw new Error("IntentsCoprocessor required");
|
|
15969
15974
|
}
|
|
15970
15975
|
const sortedBids = await this.validateAndSortBids(bids, order);
|
|
15976
|
+
console.log(`[BidManager] ${sortedBids.length}/${bids.length} bid(s) passed validation and sorting`);
|
|
15971
15977
|
if (sortedBids.length === 0) {
|
|
15972
15978
|
throw new Error("No valid bids found");
|
|
15973
15979
|
}
|
|
@@ -15984,8 +15990,11 @@ var BidManager = class {
|
|
|
15984
15990
|
);
|
|
15985
15991
|
let selectedBid = null;
|
|
15986
15992
|
let sessionSignature = null;
|
|
15987
|
-
|
|
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];
|
|
15988
15996
|
const solverAddress2 = bidWithOptions.bid.userOp.sender;
|
|
15997
|
+
console.log(`[BidManager] Simulating bid ${idx + 1}/${sortedBids.length} from solver=${solverAddress2}`);
|
|
15989
15998
|
const signature = await this.crypto.signSolverSelection(
|
|
15990
15999
|
commitment,
|
|
15991
16000
|
solverAddress2,
|
|
@@ -15993,6 +16002,7 @@ var BidManager = class {
|
|
|
15993
16002
|
sessionKeyData.privateKey
|
|
15994
16003
|
);
|
|
15995
16004
|
if (!signature) {
|
|
16005
|
+
console.warn(`[BidManager] Bid ${idx + 1}: failed to sign solver selection, skipping`);
|
|
15996
16006
|
continue;
|
|
15997
16007
|
}
|
|
15998
16008
|
const selectOptions = {
|
|
@@ -16002,22 +16012,19 @@ var BidManager = class {
|
|
|
16002
16012
|
};
|
|
16003
16013
|
try {
|
|
16004
16014
|
await this.simulate(bidWithOptions.bid, selectOptions, intentGatewayV2Address);
|
|
16015
|
+
console.log(`[BidManager] Bid ${idx + 1} from solver=${solverAddress2}: simulation PASSED`);
|
|
16005
16016
|
selectedBid = bidWithOptions;
|
|
16006
16017
|
sessionSignature = signature;
|
|
16007
16018
|
break;
|
|
16008
16019
|
} catch (err) {
|
|
16009
|
-
console.
|
|
16010
|
-
|
|
16011
|
-
JSON.stringify({
|
|
16012
|
-
commitment,
|
|
16013
|
-
solver: solverAddress2,
|
|
16014
|
-
error: err instanceof Error ? err.message : String(err)
|
|
16015
|
-
})
|
|
16020
|
+
console.warn(
|
|
16021
|
+
`[BidManager] Bid ${idx + 1} from solver=${solverAddress2}: simulation FAILED: ${err instanceof Error ? err.message : String(err)}`
|
|
16016
16022
|
);
|
|
16017
16023
|
continue;
|
|
16018
16024
|
}
|
|
16019
16025
|
}
|
|
16020
16026
|
if (!selectedBid || !sessionSignature) {
|
|
16027
|
+
console.error(`[BidManager] All ${sortedBids.length} bid(s) failed simulation for commitment=${commitment}`);
|
|
16021
16028
|
throw new Error("No bids passed simulation");
|
|
16022
16029
|
}
|
|
16023
16030
|
const solverAddress = selectedBid.bid.userOp.sender;
|
|
@@ -16095,13 +16102,16 @@ var BidManager = class {
|
|
|
16095
16102
|
const outputs = order.output.assets;
|
|
16096
16103
|
const decodedBids = this.decodeBids(bids);
|
|
16097
16104
|
if (outputs.length <= 1) {
|
|
16105
|
+
console.log(`[BidManager] Using single-output sorting (1 output asset)`);
|
|
16098
16106
|
return this.sortSingleOutput(decodedBids, outputs[0]);
|
|
16099
16107
|
}
|
|
16100
16108
|
const chainId = this.ctx.dest.config.stateMachineId;
|
|
16101
16109
|
const allStables = outputs.every((o) => this.isStableToken(bytes32ToBytes20(o.token), chainId));
|
|
16102
16110
|
if (allStables) {
|
|
16111
|
+
console.log(`[BidManager] Using all-stables sorting (${outputs.length} stable output assets)`);
|
|
16103
16112
|
return this.sortAllStables(decodedBids, outputs, chainId);
|
|
16104
16113
|
}
|
|
16114
|
+
console.log(`[BidManager] Using mixed-output sorting (${outputs.length} output assets, some non-stable)`);
|
|
16105
16115
|
return this.sortMixedOutputs(decodedBids, outputs, chainId);
|
|
16106
16116
|
}
|
|
16107
16117
|
decodeBids(bids) {
|
|
@@ -16110,8 +16120,11 @@ var BidManager = class {
|
|
|
16110
16120
|
const fillOptions = this.decodeBidFillOptions(bid);
|
|
16111
16121
|
if (fillOptions) {
|
|
16112
16122
|
result.push({ bid, options: fillOptions });
|
|
16123
|
+
} else {
|
|
16124
|
+
console.warn(`[BidManager] Failed to decode fillOptions from bid by solver=${bid.userOp.sender}`);
|
|
16113
16125
|
}
|
|
16114
16126
|
}
|
|
16127
|
+
console.log(`[BidManager] Decoded ${result.length}/${bids.length} bid(s) successfully`);
|
|
16115
16128
|
return result;
|
|
16116
16129
|
}
|
|
16117
16130
|
decodeBidFillOptions(bid) {
|
|
@@ -16166,12 +16179,29 @@ var BidManager = class {
|
|
|
16166
16179
|
* Filter bids whose first output amount < required, sort descending.
|
|
16167
16180
|
*/
|
|
16168
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
|
+
);
|
|
16169
16186
|
const validBids = [];
|
|
16170
16187
|
for (const { bid, options } of decodedBids) {
|
|
16171
16188
|
const bidOutput = options.outputs[0];
|
|
16172
16189
|
const bidAmount = new Decimal3(bidOutput.amount.toString());
|
|
16173
|
-
|
|
16174
|
-
|
|
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
|
+
);
|
|
16175
16205
|
validBids.push({ bid, options, amount: bidOutput.amount });
|
|
16176
16206
|
}
|
|
16177
16207
|
validBids.sort((a, b) => {
|
|
@@ -16187,10 +16217,19 @@ var BidManager = class {
|
|
|
16187
16217
|
*/
|
|
16188
16218
|
sortAllStables(decodedBids, orderOutputs, chainId) {
|
|
16189
16219
|
const requiredUsd = this.computeStablesUsdValue(orderOutputs, chainId);
|
|
16220
|
+
console.log(`[BidManager] sortAllStables: required USD value=${requiredUsd.toString()}`);
|
|
16190
16221
|
const validBids = [];
|
|
16191
16222
|
for (const { bid, options } of decodedBids) {
|
|
16192
16223
|
const bidUsd = this.computeStablesUsdValue(options.outputs, chainId);
|
|
16193
|
-
if (bidUsd === null || bidUsd.lt(requiredUsd))
|
|
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
|
+
);
|
|
16194
16233
|
validBids.push({ bid, options, usdValue: bidUsd });
|
|
16195
16234
|
}
|
|
16196
16235
|
validBids.sort((a, b) => b.usdValue.comparedTo(a.usdValue));
|
|
@@ -16204,13 +16243,22 @@ var BidManager = class {
|
|
|
16204
16243
|
async sortMixedOutputs(decodedBids, orderOutputs, chainId) {
|
|
16205
16244
|
const requiredUsd = await this.computeOutputsUsdValue(orderOutputs, chainId);
|
|
16206
16245
|
if (requiredUsd === null) {
|
|
16207
|
-
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");
|
|
16208
16247
|
return this.sortByRawAmountFallback(decodedBids, orderOutputs);
|
|
16209
16248
|
}
|
|
16249
|
+
console.log(`[BidManager] sortMixedOutputs: required USD value=${requiredUsd.toString()}`);
|
|
16210
16250
|
const validBids = [];
|
|
16211
16251
|
for (const { bid, options } of decodedBids) {
|
|
16212
16252
|
const bidUsd = await this.computeOutputsUsdValue(options.outputs, chainId);
|
|
16213
|
-
if (bidUsd === null || bidUsd.lt(requiredUsd))
|
|
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
|
+
);
|
|
16214
16262
|
validBids.push({ bid, options, usdValue: bidUsd });
|
|
16215
16263
|
}
|
|
16216
16264
|
validBids.sort((a, b) => b.usdValue.comparedTo(a.usdValue));
|
|
@@ -16223,21 +16271,35 @@ var BidManager = class {
|
|
|
16223
16271
|
* Remaining bids are sorted by total spread descending.
|
|
16224
16272
|
*/
|
|
16225
16273
|
sortByRawAmountFallback(decodedBids, orderOutputs) {
|
|
16274
|
+
console.log(`[BidManager] sortByRawAmountFallback: checking ${decodedBids.length} bid(s) against ${orderOutputs.length} required output(s)`);
|
|
16226
16275
|
const validBids = [];
|
|
16227
16276
|
for (const { bid, options } of decodedBids) {
|
|
16228
16277
|
let valid = true;
|
|
16229
16278
|
let totalSpread = new Decimal3(0);
|
|
16279
|
+
let rejectReason = "";
|
|
16230
16280
|
for (const required of orderOutputs) {
|
|
16231
16281
|
const matching = options.outputs.find((o) => o.token.toLowerCase() === required.token.toLowerCase());
|
|
16232
|
-
if (!matching
|
|
16282
|
+
if (!matching) {
|
|
16233
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()})`;
|
|
16234
16290
|
break;
|
|
16235
16291
|
}
|
|
16236
16292
|
totalSpread = totalSpread.plus(
|
|
16237
16293
|
new Decimal3(matching.amount.toString()).minus(required.amount.toString())
|
|
16238
16294
|
);
|
|
16239
16295
|
}
|
|
16240
|
-
if (!valid)
|
|
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
|
+
);
|
|
16241
16303
|
validBids.push({ bid, options, totalSpread });
|
|
16242
16304
|
}
|
|
16243
16305
|
validBids.sort((a, b) => b.totalSpread.comparedTo(a.totalSpread));
|
|
@@ -16482,7 +16544,7 @@ var GasEstimator = class {
|
|
|
16482
16544
|
BundlerMethod.ETH_ESTIMATE_USER_OPERATION_GAS,
|
|
16483
16545
|
[bundlerUserOp, entryPointAddress, bundlerStateOverrides]
|
|
16484
16546
|
);
|
|
16485
|
-
callGasLimit = BigInt(gasEstimate.callGasLimit) *
|
|
16547
|
+
callGasLimit = BigInt(gasEstimate.callGasLimit) * 160n / 100n;
|
|
16486
16548
|
verificationGasLimit = BigInt(gasEstimate.verificationGasLimit) * 105n / 100n;
|
|
16487
16549
|
preVerificationGas = BigInt(gasEstimate.preVerificationGas) * 105n / 100n;
|
|
16488
16550
|
if (this.ctx.bundlerUrl?.toLowerCase().includes("pimlico.io")) {
|
|
@@ -16495,8 +16557,8 @@ var GasEstimator = class {
|
|
|
16495
16557
|
if (level) {
|
|
16496
16558
|
const pimMaxFeePerGas = BigInt(level.maxFeePerGas);
|
|
16497
16559
|
const pimMaxPriorityFeePerGas = BigInt(level.maxPriorityFeePerGas);
|
|
16498
|
-
maxFeePerGas = pimMaxFeePerGas;
|
|
16499
|
-
maxPriorityFeePerGas = pimMaxPriorityFeePerGas;
|
|
16560
|
+
maxFeePerGas = pimMaxFeePerGas + pimMaxFeePerGas * BigInt(maxFeeBumpPercent) / 100n;
|
|
16561
|
+
maxPriorityFeePerGas = pimMaxPriorityFeePerGas + pimMaxPriorityFeePerGas * BigInt(priorityFeeBumpPercent) / 100n;
|
|
16500
16562
|
}
|
|
16501
16563
|
} catch (e) {
|
|
16502
16564
|
console.warn("Pimlico gas price fetch failed, using default gas price:", e);
|
|
@@ -16802,6 +16864,9 @@ var IntentsV2 = class _IntentsV2 {
|
|
|
16802
16864
|
maxPriorityFeePerGasBumpPercent: options?.maxPriorityFeePerGasBumpPercent,
|
|
16803
16865
|
maxFeePerGasBumpPercent: options?.maxFeePerGasBumpPercent
|
|
16804
16866
|
});
|
|
16867
|
+
if (estimate.totalGasCostWei === 0n || estimate.totalGasInFeeToken === 0n) {
|
|
16868
|
+
throw new Error("Gas estimation failed");
|
|
16869
|
+
}
|
|
16805
16870
|
feesInWei = estimate.totalGasCostWei + estimate.totalGasCostWei * 2n / 100n;
|
|
16806
16871
|
order.fees = estimate.totalGasInFeeToken + estimate.totalGasInFeeToken * 1n / 100n;
|
|
16807
16872
|
}
|