@hyperbridge/sdk 2.8.18 → 2.8.21

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.
@@ -2607,7 +2607,7 @@ var chainConfigs = {
2607
2607
  UniswapV3Quoter: "0x0000000000000000000000000000000000000000",
2608
2608
  UniswapV4Quoter: "0x0000000000000000000000000000000000000000",
2609
2609
  EntryPointV08: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108",
2610
- SolverAccount: "0x153DB990FE3b761B54ad71D0f1A0987dF11740DB"
2610
+ SolverAccount: "0xf98E484858F59C30e31D2695ac18F92bc7C7b799"
2611
2611
  },
2612
2612
  rpcEnvKey: "BSC_CHAPEL",
2613
2613
  defaultRpcUrl: "https://bnb-testnet.api.onfinality.io/public",
@@ -2733,7 +2733,7 @@ var chainConfigs = {
2733
2733
  },
2734
2734
  addresses: {
2735
2735
  IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
2736
- SolverAccount: "0xd5535d4DeB17F050e52B6efda2fDe00435f39279",
2736
+ SolverAccount: "0x77c3394CA5881A74f18139AC87D0c11F8Faa90cC",
2737
2737
  TokenGateway: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
2738
2738
  Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
2739
2739
  UniswapRouter02: "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
@@ -2800,7 +2800,7 @@ var chainConfigs = {
2800
2800
  },
2801
2801
  addresses: {
2802
2802
  IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
2803
- SolverAccount: "0xd5535d4DeB17F050e52B6efda2fDe00435f39279",
2803
+ SolverAccount: "0x77c3394CA5881A74f18139AC87D0c11F8Faa90cC",
2804
2804
  TokenGateway: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
2805
2805
  Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
2806
2806
  UniswapRouter02: "0x10ED43C718714eb63d5aA57B78B54704E256024E",
@@ -2861,7 +2861,7 @@ var chainConfigs = {
2861
2861
  },
2862
2862
  addresses: {
2863
2863
  IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
2864
- SolverAccount: "0xd5535d4DeB17F050e52B6efda2fDe00435f39279",
2864
+ SolverAccount: "0x77c3394CA5881A74f18139AC87D0c11F8Faa90cC",
2865
2865
  TokenGateway: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
2866
2866
  Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
2867
2867
  UniswapRouter02: "0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24",
@@ -2935,7 +2935,7 @@ var chainConfigs = {
2935
2935
  },
2936
2936
  addresses: {
2937
2937
  IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
2938
- SolverAccount: "0xd5535d4DeB17F050e52B6efda2fDe00435f39279",
2938
+ SolverAccount: "0x77c3394CA5881A74f18139AC87D0c11F8Faa90cC",
2939
2939
  TokenGateway: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
2940
2940
  Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
2941
2941
  UniswapRouter02: "0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24",
@@ -3009,7 +3009,7 @@ var chainConfigs = {
3009
3009
  },
3010
3010
  addresses: {
3011
3011
  IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
3012
- SolverAccount: "0xd5535d4DeB17F050e52B6efda2fDe00435f39279",
3012
+ SolverAccount: "0x77c3394CA5881A74f18139AC87D0c11F8Faa90cC",
3013
3013
  TokenGateway: "0x8b536105b6Fae2aE9199f5146D3C57Dfe53b614E",
3014
3014
  Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
3015
3015
  UniswapRouter02: "0xd2f9496824951D5237cC71245D659E48d0d5f9E8",
@@ -3103,7 +3103,7 @@ var chainConfigs = {
3103
3103
  Calldispatcher: "0x876F1891982E260026630c233A4897160A281Fb8",
3104
3104
  Permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
3105
3105
  EntryPointV08: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108",
3106
- SolverAccount: "0x153DB990FE3b761B54ad71D0f1A0987dF11740DB"
3106
+ SolverAccount: "0xf98E484858F59C30e31D2695ac18F92bc7C7b799"
3107
3107
  },
3108
3108
  rpcEnvKey: "POLYGON_AMOY",
3109
3109
  defaultRpcUrl: "https://rpc-amoy.polygon.technology",
@@ -3127,7 +3127,7 @@ var chainConfigs = {
3127
3127
  },
3128
3128
  addresses: {
3129
3129
  IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
3130
- SolverAccount: "0xd5535d4DeB17F050e52B6efda2fDe00435f39279",
3130
+ SolverAccount: "0x77c3394CA5881A74f18139AC87D0c11F8Faa90cC",
3131
3131
  TokenGateway: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
3132
3132
  Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
3133
3133
  UniswapRouter02: "0x4A7b5Da61326A6379179b40d00F57E5bbDC962c2",
@@ -3162,7 +3162,7 @@ var chainConfigs = {
3162
3162
  },
3163
3163
  addresses: {
3164
3164
  IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
3165
- SolverAccount: "0xd5535d4DeB17F050e52B6efda2fDe00435f39279",
3165
+ SolverAccount: "0x77c3394CA5881A74f18139AC87D0c11F8Faa90cC",
3166
3166
  TokenGateway: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
3167
3167
  Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
3168
3168
  UniswapRouter02: "0xB2e26652e4BAd1e56055A051f922E06760cA0BFE",
@@ -3318,7 +3318,7 @@ var chainConfigs = {
3318
3318
  },
3319
3319
  addresses: {
3320
3320
  IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
3321
- SolverAccount: "0xd5535d4DeB17F050e52B6efda2fDe00435f39279",
3321
+ SolverAccount: "0x77c3394CA5881A74f18139AC87D0c11F8Faa90cC",
3322
3322
  Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
3323
3323
  Calldispatcher: "0xE2C7e576E26E0bE7aC97c6fE925bcDAbD87c4bEd"
3324
3324
  },
@@ -18264,6 +18264,16 @@ var NO_BUNDLER_FILL_GAS_BASE = 700000n;
18264
18264
  var NO_BUNDLER_FILL_GAS_PER_OUTPUT = 150000n;
18265
18265
  var NO_BUNDLER_PAYMASTER_VERIFICATION_GAS = 250000n;
18266
18266
  var NO_BUNDLER_PAYMASTER_POST_OP_GAS = 100000n;
18267
+ var BID_PVG_ESTIMATION_ACCOUNT_CODE = "0x60003560e01c631626ba7e1460145760206000f35b631626ba7e60e01b60005260206000f3";
18268
+ var SELECTED_BID_SIGNATURE_BYTES = 32 + 65 + 65;
18269
+ var BID_PVG_HEADROOM_PERCENT = 10n;
18270
+ var ESCROW_MAPPING_SLOT = 9n;
18271
+ function escrowSlot(commitment, leg) {
18272
+ const byCommitment = viem.keccak256(
18273
+ viem.encodeAbiParameters([{ type: "bytes32" }, { type: "uint256" }], [commitment, ESCROW_MAPPING_SLOT])
18274
+ );
18275
+ return viem.keccak256(viem.encodeAbiParameters([{ type: "uint256" }, { type: "bytes32" }], [BigInt(leg), byCommitment]));
18276
+ }
18267
18277
  var GasEstimator = class {
18268
18278
  /**
18269
18279
  * @param ctx - Shared IntentsV2 context providing the source and destination
@@ -18342,6 +18352,7 @@ var GasEstimator = class {
18342
18352
  assetsForOverrides.push({ token: feeTokenAsBytes32, amount: 0n });
18343
18353
  }
18344
18354
  const isSameChain = souceStateMachineId === destStateMachineId;
18355
+ const commitment = orderCommitment(order);
18345
18356
  const [stateOverridesResult, crossChainFees] = await Promise.all([
18346
18357
  this.ctx.bundlerUrl ? this.buildStateOverride({
18347
18358
  accountAddress: solverAccountAddress,
@@ -18349,7 +18360,16 @@ var GasEstimator = class {
18349
18360
  outputAssets: assetsForOverrides,
18350
18361
  spenderAddress: intentGatewayV2Address,
18351
18362
  intentGatewayV2Address,
18352
- entryPointAddress
18363
+ entryPointAddress,
18364
+ // A fee quote runs before the order is placed, so nothing is escrowed under
18365
+ // its commitment yet. Cross-chain fills release escrow on the source chain.
18366
+ escrow: isSameChain ? {
18367
+ commitment,
18368
+ inputs: order.inputs.map((input) => ({
18369
+ token: normalizeAddressForEvmBytes32(input.token),
18370
+ amount: input.amount
18371
+ }))
18372
+ } : void 0
18353
18373
  }) : Promise.resolve({ viem: [], bundler: {} }),
18354
18374
  isSameChain ? Promise.resolve({ postRequestFee: 0n, relayerFeeInSourceFeeToken: 0n }) : this.estimateCrossChainFees(
18355
18375
  sourceFeeToken,
@@ -18378,10 +18398,8 @@ var GasEstimator = class {
18378
18398
  const maxFeeBumpPercent = params.maxFeePerGasBumpPercent ?? 10;
18379
18399
  let maxPriorityFeePerGas = gasPrice + gasPrice * BigInt(priorityFeeBumpPercent) / 100n;
18380
18400
  let maxFeePerGas = gasPrice + gasPrice * BigInt(maxFeeBumpPercent) / 100n;
18381
- const orderForEstimation = { ...order, session: solverAccountAddress };
18382
- const commitment = orderCommitment(orderForEstimation);
18383
18401
  await assertGatewayRelease(this.ctx.dest.client, intentGatewayV2Address);
18384
- const fillOrderCalldata = encodeFillOrder(transformOrderForContract(orderForEstimation), fillOptions);
18402
+ const fillOrderCalldata = encodeFillOrder(transformOrderForContract(order), fillOptions);
18385
18403
  let callGasLimit = 500000n;
18386
18404
  let verificationGasLimit = 100000n;
18387
18405
  let preVerificationGas = 100000n;
@@ -18393,7 +18411,7 @@ var GasEstimator = class {
18393
18411
  ...params.prependCalls ?? [],
18394
18412
  { target: intentGatewayV2Address, value: totalNativeValue, data: fillOrderCalldata }
18395
18413
  ]);
18396
- const accountGasLimits = CryptoUtils.packGasLimits(100000n, callGasLimit);
18414
+ const accountGasLimits = CryptoUtils.packGasLimits(0n, 0n);
18397
18415
  const gasFees = CryptoUtils.packGasFees(maxPriorityFeePerGas, maxFeePerGas);
18398
18416
  const nonce = 0n;
18399
18417
  const preliminaryUserOp = {
@@ -18402,7 +18420,7 @@ var GasEstimator = class {
18402
18420
  initCode: "0x",
18403
18421
  callData,
18404
18422
  accountGasLimits,
18405
- preVerificationGas: 100000n,
18423
+ preVerificationGas: 0n,
18406
18424
  gasFees,
18407
18425
  paymasterAndData: "0x",
18408
18426
  signature: "0x"
@@ -18532,6 +18550,53 @@ var GasEstimator = class {
18532
18550
  inputs
18533
18551
  };
18534
18552
  }
18553
+ /**
18554
+ * Asks the bundler for the `preVerificationGas` of the bid UserOperation that will
18555
+ * actually be signed, with every funding call, approval and signature byte in it.
18556
+ *
18557
+ * On an L2, `preVerificationGas` also pays the L1 data fee for the op's bytes, a fixed
18558
+ * amount of wei that the bundler converts to gas at the price the op pays. A bundler
18559
+ * admits an op priced at its `maxFeePerGas`, but bundles it at the base fee plus its
18560
+ * priority fee, where the same wei costs more gas. An op sized only for admission is
18561
+ * accepted and then skipped in every bundle until it expires. The estimate is taken
18562
+ * at the bundle's price: the latest base fee plus the op's priority fee, capped at its
18563
+ * `maxFeePerGas`.
18564
+ *
18565
+ * The solver account's code is overridden with {@link BID_PVG_ESTIMATION_ACCOUNT_CODE}
18566
+ * for the call, so only the bytes are priced and the fill itself is not simulated.
18567
+ *
18568
+ * @param params - The bid's fields as they will be signed.
18569
+ * @returns The `preVerificationGas` to sign, with {@link BID_PVG_HEADROOM_PERCENT} added.
18570
+ * @throws If no bundler is configured or the bundler rejects the estimate.
18571
+ */
18572
+ async estimateBidPreVerificationGas(params) {
18573
+ const { solverAccount, maxFeePerGas, maxPriorityFeePerGas } = params;
18574
+ const latestBlock = await this.ctx.dest.client.getBlock({ blockTag: "latest" });
18575
+ const baseFeePerGas = latestBlock.baseFeePerGas;
18576
+ const bundlePrice = baseFeePerGas == null || baseFeePerGas + maxPriorityFeePerGas > maxFeePerGas ? maxFeePerGas : baseFeePerGas + maxPriorityFeePerGas;
18577
+ const priorityFee = maxPriorityFeePerGas < bundlePrice ? maxPriorityFeePerGas : bundlePrice;
18578
+ const userOp = {
18579
+ sender: solverAccount,
18580
+ nonce: params.nonce,
18581
+ initCode: "0x",
18582
+ callData: params.callData,
18583
+ accountGasLimits: CryptoUtils.packGasLimits(params.verificationGasLimit, params.callGasLimit),
18584
+ // Bundlers return a non-zero preVerificationGas as given rather than estimating it.
18585
+ preVerificationGas: 0n,
18586
+ gasFees: CryptoUtils.packGasFees(priorityFee, bundlePrice),
18587
+ paymasterAndData: params.paymasterAndData ?? "0x",
18588
+ signature: `0x${"ff".repeat(SELECTED_BID_SIGNATURE_BYTES)}`
18589
+ };
18590
+ const estimate = await this.crypto.sendBundler(
18591
+ BundlerMethod.ETH_ESTIMATE_USER_OPERATION_GAS,
18592
+ [
18593
+ CryptoUtils.prepareBundlerCall(userOp),
18594
+ params.entryPointAddress,
18595
+ { [solverAccount]: { code: BID_PVG_ESTIMATION_ACCOUNT_CODE } }
18596
+ ]
18597
+ );
18598
+ return BigInt(estimate.preVerificationGas) * (100n + BID_PVG_HEADROOM_PERCENT) / 100n;
18599
+ }
18535
18600
  /**
18536
18601
  * Estimates the cross-chain ISMP POST request fee (the relayer fee for the
18537
18602
  * RedeemEscrow message), in both the source and destination fee tokens.
@@ -18584,20 +18649,38 @@ var GasEstimator = class {
18584
18649
  * @returns An object with `viem` and `bundler` state-override collections.
18585
18650
  */
18586
18651
  async buildStateOverride(params) {
18587
- const { accountAddress, chain, outputAssets, spenderAddress, intentGatewayV2Address, entryPointAddress } = params;
18588
- const testValue = viem.toHex(viem.maxUint256 / 2n, { size: 32 });
18652
+ const {
18653
+ accountAddress,
18654
+ chain,
18655
+ outputAssets,
18656
+ spenderAddress,
18657
+ intentGatewayV2Address,
18658
+ entryPointAddress,
18659
+ escrow
18660
+ } = params;
18661
+ const testValue = viem.toHex(2n ** 128n, { size: 32 });
18589
18662
  const viemOverrides = [];
18590
18663
  const bundlerOverrides = {};
18591
18664
  if (intentGatewayV2Address) {
18592
18665
  const paramsSlot5 = viem.pad(viem.toHex(5n), { size: 32 });
18593
18666
  const dispatcherAddress = this.ctx.dest.configService.getCalldispatcherAddress(chain);
18594
18667
  const newSlot5Value = "0x" + "0".repeat(22) + "00" + dispatcherAddress.slice(2).toLowerCase();
18668
+ const gatewayDiffs = [{ slot: paramsSlot5, value: newSlot5Value }];
18669
+ for (const [leg, input] of (escrow?.inputs ?? []).entries()) {
18670
+ gatewayDiffs.push({
18671
+ slot: escrowSlot(escrow.commitment, leg),
18672
+ value: viem.toHex(input.amount, { size: 32 })
18673
+ });
18674
+ }
18675
+ const releasesNative = escrow?.inputs.some((input) => bytes32ToBytes20(input.token) === ADDRESS_ZERO2);
18595
18676
  viemOverrides.push({
18596
18677
  address: intentGatewayV2Address,
18597
- stateDiff: [{ slot: paramsSlot5, value: newSlot5Value }]
18678
+ ...releasesNative ? { balance: 2n ** 128n } : {},
18679
+ stateDiff: gatewayDiffs
18598
18680
  });
18599
18681
  bundlerOverrides[intentGatewayV2Address] = {
18600
- stateDiff: { [paramsSlot5]: newSlot5Value }
18682
+ ...releasesNative ? { balance: testValue } : {},
18683
+ stateDiff: Object.fromEntries(gatewayDiffs.map(({ slot, value }) => [slot, value]))
18601
18684
  };
18602
18685
  }
18603
18686
  if (entryPointAddress) {
@@ -18628,6 +18711,25 @@ var GasEstimator = class {
18628
18711
  bundlerOverrides[result.address] = { stateDiff: result.bundlerStateDiffs };
18629
18712
  }
18630
18713
  }
18714
+ if (intentGatewayV2Address && escrow) {
18715
+ const gatewayBalances = await Promise.all(
18716
+ escrow.inputs.map((input) => this.tokenBalanceSlot(input.token, intentGatewayV2Address, chain))
18717
+ );
18718
+ for (const override of gatewayBalances) {
18719
+ if (!override) continue;
18720
+ const existing = viemOverrides.find((entry) => entry.address === override.address && entry.stateDiff);
18721
+ if (existing) existing.stateDiff.push({ slot: override.slot, value: testValue });
18722
+ else
18723
+ viemOverrides.push({
18724
+ address: override.address,
18725
+ stateDiff: [{ slot: override.slot, value: testValue }]
18726
+ });
18727
+ bundlerOverrides[override.address] = {
18728
+ ...bundlerOverrides[override.address],
18729
+ stateDiff: { ...bundlerOverrides[override.address]?.stateDiff, [override.slot]: testValue }
18730
+ };
18731
+ }
18732
+ }
18631
18733
  const solverAccountContract = this.ctx.dest.configService.getSolverAccountAddress(chain);
18632
18734
  if (solverAccountContract) {
18633
18735
  try {
@@ -18650,6 +18752,21 @@ var GasEstimator = class {
18650
18752
  }
18651
18753
  return { viem: viemOverrides, bundler: bundlerOverrides };
18652
18754
  }
18755
+ /**
18756
+ * The balance slot of `holder` in an ERC-20 token, for overriding. `null` for the native
18757
+ * token or when the slot cannot be discovered.
18758
+ */
18759
+ async tokenBalanceSlot(tokenHex, holder, chain) {
18760
+ const tokenAddress = bytes32ToBytes20(tokenHex);
18761
+ if (tokenAddress === ADDRESS_ZERO2) return null;
18762
+ try {
18763
+ const balanceData = "0x70a08231" /* BALANCE_OF */ + bytes20ToBytes32(holder).slice(2);
18764
+ const slot = await getOrFetchStorageSlot(this.ctx.dest.client, chain, tokenAddress, balanceData);
18765
+ return slot ? { address: tokenAddress, slot } : null;
18766
+ } catch {
18767
+ return null;
18768
+ }
18769
+ }
18653
18770
  /**
18654
18771
  * Resolves the balance and allowance storage slot overrides for a single
18655
18772
  * ERC-20 token in parallel. Returns `null` for native-ETH tokens or when
@@ -19763,6 +19880,16 @@ var IntentGateway = class _IntentGateway {
19763
19880
  async estimateFillOrder(params) {
19764
19881
  return this.gasEstimator.estimateFillOrder(params);
19765
19882
  }
19883
+ /**
19884
+ * Asks the bundler for the `preVerificationGas` of a bid as it will be signed, priced at
19885
+ * the gas price its bundle pays. Call it with the final calldata and `paymasterAndData`,
19886
+ * before {@link prepareSubmitBid} signs the op.
19887
+ *
19888
+ * Delegates to {@link GasEstimator.estimateBidPreVerificationGas}.
19889
+ */
19890
+ async estimateBidPreVerificationGas(params) {
19891
+ return this.gasEstimator.estimateBidPreVerificationGas(params);
19892
+ }
19766
19893
  /**
19767
19894
  * Quotes the solver fee for an order using the same policy {@link execute} /
19768
19895
  * {@link executeBest} apply when `order.fees` is `0n`.