@hyperbridge/sdk 2.6.1 → 2.8.0

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.
@@ -2693,7 +2693,8 @@ var chainConfigs = {
2693
2693
  ZARP: "0xb755506531786C8aC63B756BaB1ac387bACB0C04",
2694
2694
  EURC: "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
2695
2695
  XSGD: "0x70e8dE73cE538DA2bEEd35d14187F6959a8ecA96",
2696
- TRYB: "0x2C537E5624e4af88A7ae4060C022609376C8D0EB"
2696
+ TRYB: "0x2C537E5624e4af88A7ae4060C022609376C8D0EB",
2697
+ USDR: "0x9623DfB044D5612Ce0c0F1606973CCAEFd03CD05"
2697
2698
  },
2698
2699
  tokenDecimals: {
2699
2700
  USDC: 6,
@@ -2732,6 +2733,10 @@ var chainConfigs = {
2732
2733
  consensusStateId: "ETH0",
2733
2734
  coingeckoId: "ethereum",
2734
2735
  layerZeroEid: 30101,
2736
+ erc4626Vaults: [
2737
+ { label: "Aave stataUSDC", address: "0xD4fa2D31b7968E448877f69A96DE69f5de8cD23E", asset: "USDC" },
2738
+ { label: "Aave stataUSDT", address: "0x7Bc3485026Ac48b6cf9BaF0A377477Fff5703Af8", asset: "USDT" }
2739
+ ],
2735
2740
  popularTokens: [
2736
2741
  "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
2737
2742
  "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
@@ -2786,6 +2791,10 @@ var chainConfigs = {
2786
2791
  defaultRpcUrl: "https://binance.llamarpc.com",
2787
2792
  consensusStateId: "BSC0",
2788
2793
  coingeckoId: "binance-smart-chain",
2794
+ erc4626Vaults: [
2795
+ { label: "Aave stataUSDC", address: "0x3906cDdfb781f02B21f21BD81ed7Fd8DC37075E1", asset: "USDC" },
2796
+ { label: "Aave stataUSDT", address: "0x0471D185cc7Be61E154277cAB2396cD397663da6", asset: "USDT" }
2797
+ ],
2789
2798
  popularTokens: [
2790
2799
  "0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82",
2791
2800
  "0x000Ae314E2A2172a039B26378814C252734f556A",
@@ -2845,6 +2854,10 @@ var chainConfigs = {
2845
2854
  consensusStateId: "ETH0",
2846
2855
  coingeckoId: "arbitrum-one",
2847
2856
  layerZeroEid: 30110,
2857
+ erc4626Vaults: [
2858
+ { label: "Aave stataUSDC", address: "0x7F6501d3B98eE91f9b9535E4b0ac710Fb0f9e0bc", asset: "USDC" },
2859
+ { label: "Aave stataUSDT", address: "0xa6D12574eFB239FC1D2099732bd8b5dC6306897F", asset: "USDT" }
2860
+ ],
2848
2861
  popularTokens: [
2849
2862
  "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
2850
2863
  "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
@@ -2865,7 +2878,8 @@ var chainConfigs = {
2865
2878
  EXT: "0x0e668E5127087e236578893a0e01E41837A28469",
2866
2879
  cNGN: "0x46C85152bFe9f96829aA94755D9f915F9B10EF5F",
2867
2880
  ZARP: "0xb755506531786C8aC63B756BaB1ac387bACB0C04",
2868
- EURC: "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42"
2881
+ EURC: "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42",
2882
+ USDR: "0x3B5F2810fB2168FfA9C73160F97BF9f2461fFa5c"
2869
2883
  },
2870
2884
  tokenDecimals: {
2871
2885
  USDC: 6,
@@ -2907,6 +2921,10 @@ var chainConfigs = {
2907
2921
  coingeckoId: "base",
2908
2922
  layerZeroEid: 30184,
2909
2923
  uniswapV4Pools: [{ tokens: ["USDC", "cNGN"], fee: 1500, tickSpacing: 30 }],
2924
+ erc4626Vaults: [
2925
+ { label: "Aave stataUSDC", address: "0xC768c589647798a6EE01A91FdE98EF2ed046DBD6", asset: "USDC" },
2926
+ { label: "Yield Bearing cNGN", address: "0xa82A3531021317240Fb32E67f9c7bC091F737D3b", asset: "cNGN" }
2927
+ ],
2910
2928
  popularTokens: [
2911
2929
  "0x4200000000000000000000000000000000000006",
2912
2930
  "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
@@ -2927,7 +2945,8 @@ var chainConfigs = {
2927
2945
  EXT: "0x7C8c11ADb8EF7cd3CFa718008Ea048445C6E7209",
2928
2946
  cNGN: "0x52828daa48C1a9A06F37500882b42daf0bE04C3B",
2929
2947
  ZARP: "0xb755506531786C8aC63B756BaB1ac387bACB0C04",
2930
- XSGD: "0xDC3326e71D45186F113a2F448984CA0e8D201995"
2948
+ XSGD: "0xDC3326e71D45186F113a2F448984CA0e8D201995",
2949
+ USDR: "0x3B5F2810fB2168FfA9C73160F97BF9f2461fFa5c"
2931
2950
  },
2932
2951
  tokenDecimals: {
2933
2952
  USDC: 6,
@@ -2967,6 +2986,10 @@ var chainConfigs = {
2967
2986
  consensusStateId: "POLY",
2968
2987
  coingeckoId: "polygon-pos",
2969
2988
  layerZeroEid: 30109,
2989
+ erc4626Vaults: [
2990
+ { label: "Aave stataUSDC", address: "0x79261231698B26Ed9085b59ae89d59843Ae925a8", asset: "USDC" },
2991
+ { label: "Aave stataUSDT", address: "0x2eaD203C5C1C00612B1DdbBb20e4180dA822d6ff", asset: "USDT" }
2992
+ ],
2970
2993
  popularTokens: [
2971
2994
  "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
2972
2995
  "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
@@ -3013,7 +3036,7 @@ var chainConfigs = {
3013
3036
  WETH: "0x360ad4f9a9A8EFe9A8DCB5f461c4Cc1047E1Dcf9",
3014
3037
  //wmatic, change it to wpol
3015
3038
  DAI: "0x0000000000000000000000000000000000000000",
3016
- USDC: "0x693b854d6965ffeaae21c74049dea644b56fcacb",
3039
+ USDC: "0xBE97E73126D66188d72fbF99029126D0340a7f18",
3017
3040
  USDT: "0x0000000000000000000000000000000000000000"
3018
3041
  },
3019
3042
  tokenDecimals: {
@@ -3022,7 +3045,7 @@ var chainConfigs = {
3022
3045
  },
3023
3046
  tokenStorageSlots: {
3024
3047
  USDT: { balanceSlot: 0, allowanceSlot: 1 },
3025
- USDC: { balanceSlot: 1, allowanceSlot: 2 }
3048
+ USDC: { balanceSlot: 0, allowanceSlot: 1 }
3026
3049
  },
3027
3050
  addresses: {
3028
3051
  IntentGateway: "0x6CF42FA9BecbC5b6a26884964956b113530f7cFA",
@@ -4829,6 +4852,24 @@ var ABI3 = [
4829
4852
  internalType: "uint256"
4830
4853
  }
4831
4854
  ]
4855
+ },
4856
+ {
4857
+ name: "predispatchCall",
4858
+ type: "bytes",
4859
+ indexed: false,
4860
+ internalType: "bytes"
4861
+ },
4862
+ {
4863
+ name: "outputCall",
4864
+ type: "bytes",
4865
+ indexed: false,
4866
+ internalType: "bytes"
4867
+ },
4868
+ {
4869
+ name: "graffiti",
4870
+ type: "bytes32",
4871
+ indexed: false,
4872
+ internalType: "bytes32"
4832
4873
  }
4833
4874
  ],
4834
4875
  anonymous: false
@@ -5188,6 +5229,19 @@ var ChainConfigService = class {
5188
5229
  getExtDecimals(chain) {
5189
5230
  return this.getConfig(chain)?.tokenDecimals?.EXT;
5190
5231
  }
5232
+ /** Configured exotic (non-USD) tokens on a chain, for selection UIs. EXT is a test asset and is not offered. */
5233
+ getKnownExoticTokens(chain) {
5234
+ const config = this.getConfig(chain);
5235
+ const tokens = [];
5236
+ if (config?.assets?.cNGN) {
5237
+ tokens.push({ symbol: "cNGN", address: config.assets.cNGN, decimals: config.tokenDecimals?.cNGN });
5238
+ }
5239
+ return tokens;
5240
+ }
5241
+ /** Known ERC-4626 treasury vaults on a chain, for selection UIs. */
5242
+ getKnownVaults(chain) {
5243
+ return this.getConfig(chain)?.erc4626Vaults ?? [];
5244
+ }
5191
5245
  getChainId(chain) {
5192
5246
  return this.getConfig(chain)?.chainId ?? 0;
5193
5247
  }
@@ -7477,17 +7531,30 @@ var SubstrateChain = class _SubstrateChain {
7477
7531
  rotationMap.set(BigInt(setId.toString()), BigInt(height.toString()));
7478
7532
  }
7479
7533
  const proofs = [];
7480
- let epoch = currentEpoch - 1n;
7534
+ let epoch = currentEpoch + 1n;
7481
7535
  while (rotationMap.has(epoch)) {
7482
- const height = rotationMap.get(epoch);
7483
- const key = beefyOffchainKey(height);
7484
- const proof = await this.rpcClient.call("offchain_localStorageGet", ["PERSISTENT", key]);
7536
+ const key = rotationOffchainKey(epoch);
7537
+ let proof = await this.rpcClient.call("offchain_localStorageGet", ["PERSISTENT", key]);
7538
+ if (!proof) {
7539
+ const legacyKey = messagingOffchainKey(rotationMap.get(epoch));
7540
+ proof = await this.rpcClient.call("offchain_localStorageGet", ["PERSISTENT", legacyKey]);
7541
+ }
7485
7542
  if (!proof) return void 0;
7486
7543
  proofs.push(proof);
7487
7544
  epoch++;
7488
7545
  }
7489
- const messagingKey = beefyOffchainKey(lastProvenHeight);
7490
- const messagingProof = await this.rpcClient.call("offchain_localStorageGet", ["PERSISTENT", messagingKey]);
7546
+ const messagingKey = messagingOffchainKey(lastProvenHeight);
7547
+ let messagingProof = await this.rpcClient.call("offchain_localStorageGet", ["PERSISTENT", messagingKey]);
7548
+ if (!messagingProof) {
7549
+ for (const [setId, height] of rotationMap) {
7550
+ if (height !== lastProvenHeight) continue;
7551
+ messagingProof = await this.rpcClient.call("offchain_localStorageGet", [
7552
+ "PERSISTENT",
7553
+ rotationOffchainKey(setId)
7554
+ ]);
7555
+ break;
7556
+ }
7557
+ }
7491
7558
  if (!messagingProof) return void 0;
7492
7559
  proofs.push(messagingProof);
7493
7560
  return { proofs, provenHeight: lastProvenHeight };
@@ -7504,11 +7571,17 @@ var SubstrateChain = class _SubstrateChain {
7504
7571
  throw new Error(`${name} not found in runtime`);
7505
7572
  }
7506
7573
  };
7507
- function beefyOffchainKey(provenHeight) {
7508
- const prefix = new TextEncoder().encode("beefy_consensus_proofs::");
7509
- const heightBytes = new Uint8Array(8);
7510
- new DataView(heightBytes.buffer).setBigUint64(0, provenHeight, false);
7511
- return viem.toHex(new Uint8Array([...prefix, ...heightBytes]));
7574
+ function beefyOffchainKey(prefix, id) {
7575
+ const prefixBytes = new TextEncoder().encode(prefix);
7576
+ const idBytes = new Uint8Array(8);
7577
+ new DataView(idBytes.buffer).setBigUint64(0, id, false);
7578
+ return viem.toHex(new Uint8Array([...prefixBytes, ...idBytes]));
7579
+ }
7580
+ function messagingOffchainKey(provenHeight) {
7581
+ return beefyOffchainKey("beefy_consensus_proofs::", provenHeight);
7582
+ }
7583
+ function rotationOffchainKey(setId) {
7584
+ return beefyOffchainKey("beefy_consensus_proofs::rotation::", setId);
7512
7585
  }
7513
7586
  function requestCommitmentStorageKey(key) {
7514
7587
  const prefix = new TextEncoder().encode("RequestCommitments");
@@ -8178,14 +8251,17 @@ var IntentsCoprocessor = class _IntentsCoprocessor {
8178
8251
  const orders = [];
8179
8252
  for (const { event } of records) {
8180
8253
  if (event.section !== "intentsCoprocessor" || event.method !== "PhantomOrderRegistered") continue;
8181
- const [commitment, chain, createdAt, tokenA, tokenB, standardAmount] = event.data;
8254
+ const [commitment, chain, createdAt, legs] = event.data;
8182
8255
  orders.push({
8183
8256
  commitment: commitment.toHex(),
8184
8257
  chain: new TextDecoder().decode(util.hexToU8a(chain.toHex())),
8185
8258
  createdAt: createdAt.toNumber(),
8186
- tokenA: tokenA.toHex(),
8187
- tokenB: tokenB.toHex(),
8188
- standardAmount: BigInt(standardAmount.toString())
8259
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8260
+ legs: legs.map((leg) => ({
8261
+ tokenA: leg.tokenA.toHex(),
8262
+ tokenB: leg.tokenB.toHex(),
8263
+ standardAmount: BigInt(leg.standardAmount.toString())
8264
+ }))
8189
8265
  });
8190
8266
  }
8191
8267
  return orders;
@@ -15396,14 +15472,21 @@ function orderCommitment(order) {
15396
15472
  const encoded = viem.encodeAbiParameters([orderType], [transformOrderForContract(order)]);
15397
15473
  return viem.keccak256(encoded);
15398
15474
  }
15399
- async function convertGasToFeeToken(ctx, gasEstimate, gasEstimateIn, evmChainID, gasPriceOverride) {
15475
+ function bumpGasPrice(gasPrice, bumpPercent) {
15476
+ if (bumpPercent < 0n) {
15477
+ throw new Error("Gas price bump percent cannot be negative");
15478
+ }
15479
+ return (gasPrice * (100n + bumpPercent) + 99n) / 100n;
15480
+ }
15481
+ async function convertGasToFeeToken(ctx, gasEstimate, gasEstimateIn, evmChainID, gasPriceOverride, gasPriceBumpPercent = 0n) {
15400
15482
  if (TESTNET_CHAINS.has(evmChainID)) return 1n;
15401
15483
  const chain = ctx[gasEstimateIn];
15402
15484
  const client = chain.client;
15403
- const gasPrice = gasPriceOverride ?? await retryPromise(() => client.getGasPrice(), {
15485
+ const baseGasPrice = gasPriceOverride ?? await retryPromise(() => client.getGasPrice(), {
15404
15486
  maxRetries: 3,
15405
15487
  backoffMs: 250
15406
15488
  });
15489
+ const gasPrice = bumpGasPrice(baseGasPrice, gasPriceBumpPercent);
15407
15490
  const gasCostInWei = gasEstimate * gasPrice;
15408
15491
  const wethAddr = chain.configService.getWrappedNativeAssetWithDecimals(evmChainID).asset;
15409
15492
  const feeToken = await getFeeToken(ctx, evmChainID, chain);
@@ -15474,13 +15557,13 @@ function deriveCanonicalPlacedOrder(order, args) {
15474
15557
  session: args.session,
15475
15558
  predispatch: {
15476
15559
  assets: args.predispatch.map((asset) => ({ ...asset })),
15477
- call: order.predispatch.call
15560
+ call: args.predispatchCall ?? order.predispatch.call
15478
15561
  },
15479
15562
  inputs: args.inputs.map((asset) => ({ ...asset })),
15480
15563
  output: {
15481
15564
  beneficiary: args.beneficiary,
15482
15565
  assets: args.outputs.map((asset) => ({ ...asset })),
15483
- call: order.output.call
15566
+ call: args.outputCall ?? order.output.call
15484
15567
  }
15485
15568
  };
15486
15569
  return { ...canonicalOrder, id: orderCommitment(canonicalOrder) };
@@ -15904,6 +15987,12 @@ var OrderCanceller = class _OrderCanceller {
15904
15987
  static DEFAULT_MAX_RECOVERY_RESTARTS = 1;
15905
15988
  static PROOF_FRESHNESS_MAX_RETRIES = 3;
15906
15989
  static PROOF_FRESHNESS_BACKOFF_MS = 500;
15990
+ /**
15991
+ * Gas budget used to size the relayer fee for a cross-chain cancellation
15992
+ * message (the GET response or RefundEscrow POST executed on the source
15993
+ * chain), priced at the source chain's gas price.
15994
+ */
15995
+ static CANCEL_MESSAGE_GAS = 800000n;
15907
15996
  logger = consola.createConsola({
15908
15997
  level: consola.LogLevels.info,
15909
15998
  formatOptions: { columns: 80, colors: true, compact: true, date: false }
@@ -15962,9 +16051,14 @@ var OrderCanceller = class _OrderCanceller {
15962
16051
  timeoutTimestamp: 0n,
15963
16052
  context
15964
16053
  };
15965
- const feeInSourceFeeToken = await convertGasToFeeToken(this.ctx, 400000n, "source", sourceStateMachine);
16054
+ const feeInSourceFeeToken = await convertGasToFeeToken(
16055
+ this.ctx,
16056
+ _OrderCanceller.CANCEL_MESSAGE_GAS,
16057
+ "source",
16058
+ sourceStateMachine
16059
+ );
15966
16060
  const relayerFee = feeInSourceFeeToken * 1005n / 1000n;
15967
- const nativeValue = await this.ctx.source.quoteNative(getRequest, relayerFee);
16061
+ const nativeValue = await this.ctx.source.quoteNative(getRequest, relayerFee) * 101n / 100n;
15968
16062
  return { nativeValue, relayerFee };
15969
16063
  }
15970
16064
  /**
@@ -16223,7 +16317,7 @@ var OrderCanceller = class _OrderCanceller {
16223
16317
  body,
16224
16318
  timeoutTimestamp: 0n
16225
16319
  };
16226
- const nativeValue = await this.ctx.dest.quoteNative(postRequest, relayerFee);
16320
+ const nativeValue = await this.ctx.dest.quoteNative(postRequest, relayerFee) * 101n / 100n;
16227
16321
  return { nativeValue, relayerFee };
16228
16322
  }
16229
16323
  /**
@@ -16553,8 +16647,12 @@ var OrderCanceller = class _OrderCanceller {
16553
16647
  * Converts estimated gas on the source chain into the dest chain's fee token.
16554
16648
  */
16555
16649
  async estimateRelayerFee(sourceChainId, destChainId) {
16556
- const POST_REQUEST_GAS = 400000n;
16557
- const feeInSourceFeeToken = await convertGasToFeeToken(this.ctx, POST_REQUEST_GAS, "source", sourceChainId);
16650
+ const feeInSourceFeeToken = await convertGasToFeeToken(
16651
+ this.ctx,
16652
+ _OrderCanceller.CANCEL_MESSAGE_GAS,
16653
+ "source",
16654
+ sourceChainId
16655
+ );
16558
16656
  const sourceFeeToken = await getFeeToken(this.ctx, sourceChainId, this.ctx.source);
16559
16657
  const destFeeToken = await getFeeToken(this.ctx, destChainId, this.ctx.dest);
16560
16658
  const feeInDestFeeToken = adjustDecimals(feeInSourceFeeToken, sourceFeeToken.decimals, destFeeToken.decimals);
@@ -17313,12 +17411,15 @@ var GasEstimator = class {
17313
17411
  *
17314
17412
  * @param params - Parameters including the order to estimate and optional
17315
17413
  * percentage bumps for `maxPriorityFeePerGas` and `maxFeePerGas`.
17414
+ * @param pricingOptions - Internal fee-pricing policy. Direct estimates use
17415
+ * the default zero gas-price bump; SDK order-fee quotes opt into headroom.
17316
17416
  * @returns A {@link FillOrderEstimate} containing all gas components,
17317
17417
  * EIP-1559 fee values, total cost in wei, and total cost in the source
17318
17418
  * chain's fee token.
17319
17419
  */
17320
- async estimateFillOrder(params) {
17420
+ async estimateFillOrder(params, pricingOptions = {}) {
17321
17421
  const { order } = params;
17422
+ const orderFeeGasPriceBumpPercent = pricingOptions.orderFeeGasPriceBumpPercent ?? 0n;
17322
17423
  const solverPrivateKey = accounts.generatePrivateKey();
17323
17424
  const solverAccountAddress = accounts.privateKeyToAddress(solverPrivateKey);
17324
17425
  const souceStateMachineId = viem.isHex(order.source) ? viem.hexToString(order.source) : order.source;
@@ -17349,7 +17450,12 @@ var GasEstimator = class {
17349
17450
  intentGatewayV2Address,
17350
17451
  entryPointAddress
17351
17452
  }),
17352
- isSameChain ? Promise.resolve({ postRequestFee: 0n, relayerFeeInSourceFeeToken: 0n }) : this.estimateCrossChainFees(sourceFeeToken, destFeeToken, souceStateMachineId)
17453
+ isSameChain ? Promise.resolve({ postRequestFee: 0n, relayerFeeInSourceFeeToken: 0n }) : this.estimateCrossChainFees(
17454
+ sourceFeeToken,
17455
+ destFeeToken,
17456
+ souceStateMachineId,
17457
+ orderFeeGasPriceBumpPercent
17458
+ )
17353
17459
  ]);
17354
17460
  const { viem: stateOverrides, bundler: bundlerStateOverrides } = stateOverridesResult;
17355
17461
  const fillOptions = {
@@ -17514,7 +17620,8 @@ var GasEstimator = class {
17514
17620
  totalGas,
17515
17621
  "dest",
17516
17622
  destStateMachineId,
17517
- gasPrice
17623
+ gasPrice,
17624
+ orderFeeGasPriceBumpPercent
17518
17625
  );
17519
17626
  const totalGasInSourceFeeToken = isSameChain ? totalGasInDestFeeToken : adjustDecimals(totalGasInDestFeeToken, destFeeToken.decimals, sourceFeeToken.decimals);
17520
17627
  const totalGasCostWei = isSameChain ? rawTotalGasCostWei : await convertFeeTokenToWei(this.ctx, totalGasInSourceFeeToken, "source", souceStateMachineId);
@@ -17538,12 +17645,14 @@ var GasEstimator = class {
17538
17645
  * The dispatch is always paid in the fee token — the native rail was
17539
17646
  * removed because it silently drew on a native balance nothing guarantees.
17540
17647
  */
17541
- async estimateCrossChainFees(sourceFeeToken, destFeeToken, sourceChainId) {
17648
+ async estimateCrossChainFees(sourceFeeToken, destFeeToken, sourceChainId, orderFeeGasPriceBumpPercent) {
17542
17649
  const postRequestFeeInSourceFeeToken = await convertGasToFeeToken(
17543
17650
  this.ctx,
17544
17651
  RELAYER_MESSAGE_GAS,
17545
17652
  "source",
17546
- sourceChainId
17653
+ sourceChainId,
17654
+ void 0,
17655
+ orderFeeGasPriceBumpPercent
17547
17656
  );
17548
17657
  const postRequestFeeInDestFeeToken = adjustDecimals(
17549
17658
  postRequestFeeInSourceFeeToken,
@@ -18313,6 +18422,7 @@ function isConfiguredAddress(address) {
18313
18422
  }
18314
18423
 
18315
18424
  // src/protocols/intents/IntentGateway.ts
18425
+ var CROSS_CHAIN_ORDER_FEE_GAS_PRICE_BUMP_PERCENT = 10n;
18316
18426
  var IntentGateway = class _IntentGateway {
18317
18427
  /** EVM chain on which orders are placed and escrowed. */
18318
18428
  source;
@@ -18499,14 +18609,22 @@ var IntentGateway = class _IntentGateway {
18499
18609
  * placement, fee estimation, bid collection, and execution.
18500
18610
  *
18501
18611
  * **Yield/receive protocol:**
18502
- * 1. If `order.fees` is unset or zero, estimates gas on an internal copy and
18503
- * sets same-chain fees to twice the estimate. Cross-chain orders attach
18504
- * (fill gas + a settlement-message uplift of `RELAYER_MESSAGE_GAS`, the
18505
- * same gas budget the solver's relayer fee uses) with a 5% buffer over
18506
- * the whole sum — strictly above the solver's unpadded requirement. The
18507
- * wei cost used for the `value` field receives a 2% buffer.
18508
- * 2. Yields `AWAITING_PLACE_ORDER` with `{ to, data, value, sessionPrivateKey }`.
18509
- * The caller must sign the transaction and pass it back via `gen.next(signedTx)`.
18612
+ * 1. If `order.fees` is unset or zero, prices the fee on an internal copy
18613
+ * via {@link quoteOrderFees}: same-chain fees are twice the fill-gas
18614
+ * estimate without a gas-price bump; cross-chain gas is priced 10% above
18615
+ * the live price before attaching (fill gas + the settlement relayer fee)
18616
+ * with a further 5% buffer over the whole sum — strictly above the solver's
18617
+ * unpadded requirement. Direct solver estimates remain unbumped. The wei
18618
+ * cost used for the `value` field receives a 2% buffer.
18619
+ * 2. Yields `AWAITING_PLACE_ORDER` with `{ to, data, value, nativeFee,
18620
+ * feeTokenAmount, feeTokenAddress, sessionPrivateKey }`. `value` carries
18621
+ * only the order's native-token input amounts; `nativeFee` is the native
18622
+ * amount that funds `order.fees` (`0n` when the caller set `order.fees`);
18623
+ * `feeTokenAmount`/`feeTokenAddress` are the exact fee encoded in `data`
18624
+ * and the source-chain token it is charged in. To pay the fee in native
18625
+ * token, sign the transaction with `value + nativeFee`; with a fee-token
18626
+ * allowance, `value` alone. Pass the signed transaction back via
18627
+ * `gen.next(signedTx)`.
18510
18628
  * 3. Yields `ORDER_PLACED` with the finalised order and transaction hash once
18511
18629
  * the `OrderPlaced` event is confirmed.
18512
18630
  * 4. Delegates to {@link OrderExecutor.executeOrder} and forwards all
@@ -18527,33 +18645,33 @@ var IntentGateway = class _IntentGateway {
18527
18645
  */
18528
18646
  async *execute(order, graffiti = DEFAULT_GRAFFITI, options) {
18529
18647
  const executionOrder = { ...order };
18530
- let value;
18648
+ let nativeFee = 0n;
18531
18649
  if (!executionOrder.fees || executionOrder.fees === 0n) {
18532
- const estimate = await this.gasEstimator.estimateFillOrder({
18533
- order: executionOrder,
18650
+ const feesQuote = await this.quoteOrderFees(executionOrder, {
18534
18651
  maxPriorityFeePerGasBumpPercent: options?.maxPriorityFeePerGasBumpPercent,
18535
18652
  maxFeePerGasBumpPercent: options?.maxFeePerGasBumpPercent
18536
18653
  });
18537
- if (estimate.totalGasCostWei === 0n || estimate.totalGasInFeeToken === 0n) {
18538
- throw new Error("Gas estimation failed");
18539
- }
18540
- const isSameChain = this.source.config.stateMachineId === this.dest.config.stateMachineId;
18541
- value = estimate.totalGasCostWei + estimate.totalGasCostWei * 2n / 100n;
18542
- const crossChainFeeBump = isSameChain ? 0n : await convertGasToFeeToken(
18543
- this.ctx,
18544
- RELAYER_MESSAGE_GAS,
18545
- "source",
18546
- this.source.config.stateMachineId
18547
- );
18548
- executionOrder.fees = isSameChain ? estimate.totalGasInFeeToken * 2n : (estimate.totalGasInFeeToken + crossChainFeeBump) * 105n / 100n;
18654
+ nativeFee = feesQuote.nativeValue;
18655
+ executionOrder.fees = feesQuote.fees;
18549
18656
  }
18657
+ const value = executionOrder.inputs.filter((input) => bytes32ToBytes20(input.token) === ADDRESS_ZERO2).reduce((sum, input) => sum + input.amount, 0n);
18550
18658
  const placeOrderGen = this.orderPlacer.placeOrder(executionOrder, graffiti);
18551
18659
  const placeOrderFirst = await placeOrderGen.next();
18552
18660
  if (placeOrderFirst.done) {
18553
18661
  throw new Error("placeOrder generator completed without yielding");
18554
18662
  }
18555
18663
  const { to, data, sessionPrivateKey } = placeOrderFirst.value;
18556
- const signedTransaction = yield { status: "AWAITING_PLACE_ORDER", to, data, value, sessionPrivateKey };
18664
+ const { address: feeTokenAddress } = await getFeeToken(this.ctx, this.source.config.stateMachineId, this.source);
18665
+ const signedTransaction = yield {
18666
+ status: "AWAITING_PLACE_ORDER",
18667
+ to,
18668
+ data,
18669
+ value,
18670
+ nativeFee,
18671
+ sessionPrivateKey,
18672
+ feeTokenAmount: executionOrder.fees,
18673
+ feeTokenAddress
18674
+ };
18557
18675
  const placeOrderSecond = await placeOrderGen.next(signedTransaction);
18558
18676
  if (placeOrderSecond.done === false) {
18559
18677
  throw new Error("placeOrder generator yielded unexpectedly after signing");
@@ -18853,6 +18971,50 @@ var IntentGateway = class _IntentGateway {
18853
18971
  async estimateFillOrder(params) {
18854
18972
  return this.gasEstimator.estimateFillOrder(params);
18855
18973
  }
18974
+ /**
18975
+ * Quotes the solver fee for an order using the same policy {@link execute} /
18976
+ * {@link executeBest} apply when `order.fees` is `0n`.
18977
+ *
18978
+ * Use this before placing to display the fee, or to check what the user can
18979
+ * afford: pay `fees` in the source-chain fee token (check balance and
18980
+ * allowance, then set `order.fees` and submit with `value: 0`), or leave
18981
+ * `order.fees` at `0n` and let the SDK attach `nativeValue` to the placement
18982
+ * transaction (check the native balance).
18983
+ *
18984
+ * @param order - The order to quote. `order.fees` is ignored and not mutated.
18985
+ * Gas prices used to derive cross-chain `fees` receive 10% SDK-only headroom.
18986
+ * Same-chain quotes and direct calls to {@link estimateFillOrder}, including
18987
+ * Simplex solver estimates, remain unbumped.
18988
+ *
18989
+ * @param options - Optional transaction gas-price bump percentages, as in {@link execute}.
18990
+ * @returns An {@link OrderFeesQuote} with the fee-token amount, the native
18991
+ * value for the native rail, and the underlying estimate.
18992
+ * @throws If gas estimation returns zero.
18993
+ */
18994
+ async quoteOrderFees(order, options) {
18995
+ const isSameChain = this.source.config.stateMachineId === this.dest.config.stateMachineId;
18996
+ const estimate = await this.gasEstimator.estimateFillOrder(
18997
+ {
18998
+ order,
18999
+ maxPriorityFeePerGasBumpPercent: options?.maxPriorityFeePerGasBumpPercent,
19000
+ maxFeePerGasBumpPercent: options?.maxFeePerGasBumpPercent
19001
+ },
19002
+ {
19003
+ orderFeeGasPriceBumpPercent: isSameChain ? 0n : CROSS_CHAIN_ORDER_FEE_GAS_PRICE_BUMP_PERCENT
19004
+ }
19005
+ );
19006
+ if (estimate.totalGasCostWei === 0n || estimate.totalGasInFeeToken === 0n) {
19007
+ throw new Error("Gas estimation failed");
19008
+ }
19009
+ const fees = isSameChain ? estimate.totalGasInFeeToken * 2n : (estimate.totalGasInFeeToken + estimate.relayerFeeInSourceFeeToken) * 105n / 100n;
19010
+ const { address: feeToken } = await this.source.getFeeTokenWithDecimals();
19011
+ return {
19012
+ fees,
19013
+ nativeValue: estimate.totalGasCostWei + estimate.totalGasCostWei * 2n / 100n,
19014
+ feeToken,
19015
+ estimate
19016
+ };
19017
+ }
18856
19018
  /**
18857
19019
  * Encodes a list of calls into ERC-7821 `execute` calldata using
18858
19020
  * single-batch mode.
@@ -18979,6 +19141,44 @@ var IntentGateway = class _IntentGateway {
18979
19141
  }
18980
19142
  }
18981
19143
  };
19144
+ var FILL_ORDER_ABI = IntentGatewayV2_default.ABI;
19145
+ var DECLARATION_VERSION = 1;
19146
+ var MAX_DECLARED_CHAINS = 255;
19147
+ function encodeAcceptedSourceChains(chains2) {
19148
+ if (chains2.length > MAX_DECLARED_CHAINS) {
19149
+ throw new Error(`Cannot declare more than ${MAX_DECLARED_CHAINS} source chains`);
19150
+ }
19151
+ const bytes = [DECLARATION_VERSION, chains2.length];
19152
+ for (const chain of chains2) {
19153
+ const encoded = util.stringToU8a(chain);
19154
+ if (encoded.length === 0 || encoded.length > 255) {
19155
+ throw new Error(`Invalid state machine id in source chain declaration: ${chain}`);
19156
+ }
19157
+ bytes.push(encoded.length, ...encoded);
19158
+ }
19159
+ return util.u8aToHex(new Uint8Array(bytes));
19160
+ }
19161
+ function decodeAcceptedSourceChains(paymasterAndData) {
19162
+ if (!paymasterAndData || !util.isHex(paymasterAndData)) return null;
19163
+ const bytes = util.hexToU8a(paymasterAndData);
19164
+ if (bytes.length < 2 || bytes[0] !== DECLARATION_VERSION) return null;
19165
+ const count = bytes[1];
19166
+ const chains2 = [];
19167
+ let offset = 2;
19168
+ for (let entry = 0; entry < count; entry++) {
19169
+ if (offset >= bytes.length) return null;
19170
+ const length = bytes[offset];
19171
+ offset += 1;
19172
+ if (length === 0 || offset + length > bytes.length) return null;
19173
+ chains2.push(util.u8aToString(bytes.subarray(offset, offset + length)));
19174
+ offset += length;
19175
+ }
19176
+ if (offset !== bytes.length) return null;
19177
+ return chains2;
19178
+ }
19179
+ FILL_ORDER_ABI.find(
19180
+ (item) => item?.type === "function" && item?.name === "fillOrder"
19181
+ )?.inputs?.[0];
18982
19182
  var TokenGateway = class {
18983
19183
  source;
18984
19184
  dest;
@@ -23518,8 +23718,10 @@ exports.convertStateMachineEnumToString = convertStateMachineEnumToString;
23518
23718
  exports.convertStateMachineIdToEnum = convertStateMachineIdToEnum;
23519
23719
  exports.createEvmChain = createEvmChain;
23520
23720
  exports.createQueryClient = createQueryClient;
23721
+ exports.decodeAcceptedSourceChains = decodeAcceptedSourceChains;
23521
23722
  exports.decodeERC7821ExecuteBatch = decodeERC7821ExecuteBatch;
23522
23723
  exports.decodeUserOpScale = decodeUserOpScale;
23724
+ exports.encodeAcceptedSourceChains = encodeAcceptedSourceChains;
23523
23725
  exports.encodeERC7821ExecuteBatch = encodeERC7821ExecuteBatch;
23524
23726
  exports.encodeISMPMessage = encodeISMPMessage;
23525
23727
  exports.encodeStateMachineId = encodeStateMachineId;