@hyperbridge/sdk 1.2.0 → 1.2.2

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.
@@ -3546,23 +3546,31 @@ var Chains = /* @__PURE__ */ ((Chains2) => {
3546
3546
  Chains2["GNOSIS_CHIADO"] = "EVM-10200";
3547
3547
  Chains2["HYPERBRIDGE_GARGANTUA"] = "KUSAMA-4009";
3548
3548
  Chains2["SEPOLIA"] = "EVM-11155111";
3549
+ Chains2["MAINNET"] = "EVM-1";
3550
+ Chains2["BSC_MAINNET"] = "EVM-56";
3549
3551
  return Chains2;
3550
3552
  })(Chains || {});
3551
3553
  var chainIds = {
3552
3554
  ["EVM-97" /* BSC_CHAPEL */]: 97,
3553
3555
  ["EVM-10200" /* GNOSIS_CHIADO */]: 10200,
3554
3556
  ["KUSAMA-4009" /* HYPERBRIDGE_GARGANTUA */]: 4009,
3555
- ["EVM-11155111" /* SEPOLIA */]: 11155111
3557
+ ["EVM-11155111" /* SEPOLIA */]: 11155111,
3558
+ ["EVM-1" /* MAINNET */]: 1,
3559
+ ["EVM-56" /* BSC_MAINNET */]: 56
3556
3560
  };
3557
3561
  var viemChains = {
3558
3562
  "97": bscTestnet,
3559
3563
  "10200": gnosisChiado,
3560
- "11155111": sepolia
3564
+ "11155111": sepolia,
3565
+ "1": mainnet,
3566
+ "56": bsc
3561
3567
  };
3562
3568
  var WrappedNativeDecimals = {
3563
3569
  ["EVM-97" /* BSC_CHAPEL */]: 18,
3564
3570
  ["EVM-10200" /* GNOSIS_CHIADO */]: 18,
3565
- ["EVM-11155111" /* SEPOLIA */]: 18
3571
+ ["EVM-11155111" /* SEPOLIA */]: 18,
3572
+ ["EVM-1" /* MAINNET */]: 18,
3573
+ ["EVM-56" /* BSC_MAINNET */]: 18
3566
3574
  };
3567
3575
  var assets = {
3568
3576
  ["EVM-97" /* BSC_CHAPEL */]: {
@@ -3582,43 +3590,83 @@ var assets = {
3582
3590
  USDC: "0x0000000000000000000000000000000000000000".toLowerCase(),
3583
3591
  USDT: "0x0000000000000000000000000000000000000000".toLowerCase(),
3584
3592
  DAI: "0x0000000000000000000000000000000000000000".toLowerCase()
3593
+ },
3594
+ ["EVM-1" /* MAINNET */]: {
3595
+ WETH: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2".toLowerCase(),
3596
+ DAI: "0x6B175474E89094C44Da98b954EedeAC495271d0F".toLowerCase(),
3597
+ USDC: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48".toLowerCase(),
3598
+ USDT: "0xdAC17F958D2ee523a2206206994597C13D831ec7".toLowerCase()
3599
+ },
3600
+ ["EVM-56" /* BSC_MAINNET */]: {
3601
+ WETH: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c".toLowerCase(),
3602
+ DAI: "0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3".toLowerCase(),
3603
+ USDC: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d".toLowerCase(),
3604
+ USDT: "0x55d398326f99059fF775485246999027B3197955".toLowerCase()
3585
3605
  }
3586
3606
  };
3587
3607
  var addresses = {
3588
3608
  IntentGateway: {
3589
3609
  ["EVM-97" /* BSC_CHAPEL */]: "0xb6C27F4beF379d0b5e2fe3Bb36c248D6B71f91A6",
3590
3610
  ["EVM-10200" /* GNOSIS_CHIADO */]: "0xb6C27F4beF379d0b5e2fe3Bb36c248D6B71f91A6",
3591
- ["EVM-11155111" /* SEPOLIA */]: "0x0000000000000000000000000000000000000000"
3611
+ ["EVM-11155111" /* SEPOLIA */]: "0x0000000000000000000000000000000000000000",
3612
+ ["EVM-1" /* MAINNET */]: "0xd54165e45926720b062C192a5bacEC64d5bB08DA",
3613
+ ["EVM-56" /* BSC_MAINNET */]: "0xd54165e45926720b062C192a5bacEC64d5bB08DA"
3592
3614
  },
3593
3615
  Host: {
3594
3616
  ["EVM-97" /* BSC_CHAPEL */]: "0x8Aa0Dea6D675d785A882967Bf38183f6117C09b7",
3595
3617
  ["EVM-10200" /* GNOSIS_CHIADO */]: "0x58a41b89f4871725e5d898d98ef4bf917601c5eb",
3596
- ["EVM-11155111" /* SEPOLIA */]: "0x2EdB74C269948b60ec1000040E104cef0eABaae8"
3618
+ ["EVM-11155111" /* SEPOLIA */]: "0x2EdB74C269948b60ec1000040E104cef0eABaae8",
3619
+ ["EVM-1" /* MAINNET */]: "0x792A6236AF69787C40cF76b69B4c8c7B28c4cA20",
3620
+ ["EVM-56" /* BSC_MAINNET */]: "0x24B5d421Ec373FcA57325dd2F0C074009Af021F7"
3597
3621
  },
3598
3622
  UniswapRouter02: {
3599
3623
  ["EVM-97" /* BSC_CHAPEL */]: "0x9639379819420704457B07A0C33B678D9E0F8Df0",
3600
3624
  ["EVM-10200" /* GNOSIS_CHIADO */]: "0x0000000000000000000000000000000000000000",
3601
- ["EVM-11155111" /* SEPOLIA */]: "0x0000000000000000000000000000000000000000"
3625
+ ["EVM-11155111" /* SEPOLIA */]: "0x0000000000000000000000000000000000000000",
3626
+ ["EVM-1" /* MAINNET */]: "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
3627
+ ["EVM-56" /* BSC_MAINNET */]: "0x0000000000000000000000000000000000000000"
3602
3628
  },
3603
3629
  UniswapV2Factory: {
3604
3630
  ["EVM-97" /* BSC_CHAPEL */]: "0x12e036669DA18F4A2777853d6e2136b32AceEC86",
3605
3631
  ["EVM-10200" /* GNOSIS_CHIADO */]: "0x0000000000000000000000000000000000000000",
3606
- ["EVM-11155111" /* SEPOLIA */]: "0x0000000000000000000000000000000000000000"
3632
+ ["EVM-11155111" /* SEPOLIA */]: "0x0000000000000000000000000000000000000000",
3633
+ ["EVM-1" /* MAINNET */]: "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
3634
+ ["EVM-56" /* BSC_MAINNET */]: "0x0000000000000000000000000000000000000000"
3607
3635
  },
3608
3636
  BatchExecutor: {
3609
- ["EVM-97" /* BSC_CHAPEL */]: "0x4CC58B5D8FBf838d062E4b21F75C327835B5F0ef"
3637
+ ["EVM-97" /* BSC_CHAPEL */]: "0x4CC58B5D8FBf838d062E4b21F75C327835B5F0ef",
3638
+ ["EVM-1" /* MAINNET */]: "0x0000000000000000000000000000000000000000",
3639
+ ["EVM-56" /* BSC_MAINNET */]: "0x0000000000000000000000000000000000000000"
3610
3640
  },
3611
3641
  UniversalRouter: {
3612
- ["EVM-97" /* BSC_CHAPEL */]: "0xcc6d5ece3d4a57245bf5a2f64f3ed9179b81f714"
3642
+ ["EVM-97" /* BSC_CHAPEL */]: "0xcc6d5ece3d4a57245bf5a2f64f3ed9179b81f714",
3643
+ ["EVM-1" /* MAINNET */]: "0x0000000000000000000000000000000000000000",
3644
+ ["EVM-56" /* BSC_MAINNET */]: "0x0000000000000000000000000000000000000000"
3613
3645
  },
3614
3646
  UniswapV3Router: {
3615
- ["EVM-97" /* BSC_CHAPEL */]: "0x0000000000000000000000000000000000000000"
3647
+ ["EVM-97" /* BSC_CHAPEL */]: "0x0000000000000000000000000000000000000000",
3648
+ ["EVM-1" /* MAINNET */]: "0x1F98431c8aD98523631AE4a59f267346ea31F984",
3649
+ ["EVM-56" /* BSC_MAINNET */]: "0x0000000000000000000000000000000000000000"
3616
3650
  },
3617
3651
  UniswapV3Factory: {
3618
- ["EVM-97" /* BSC_CHAPEL */]: "0x0000000000000000000000000000000000000000"
3652
+ ["EVM-97" /* BSC_CHAPEL */]: "0x0000000000000000000000000000000000000000",
3653
+ ["EVM-1" /* MAINNET */]: "0x1F98431c8aD98523631AE4a59f267346ea31F984",
3654
+ ["EVM-56" /* BSC_MAINNET */]: "0x0000000000000000000000000000000000000000"
3619
3655
  },
3620
3656
  UniswapV3Quoter: {
3621
- ["EVM-97" /* BSC_CHAPEL */]: "0x0000000000000000000000000000000000000000"
3657
+ ["EVM-97" /* BSC_CHAPEL */]: "0x0000000000000000000000000000000000000000",
3658
+ ["EVM-1" /* MAINNET */]: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e",
3659
+ ["EVM-56" /* BSC_MAINNET */]: "0x0000000000000000000000000000000000000000"
3660
+ },
3661
+ UniswapV4PoolManager: {
3662
+ ["EVM-97" /* BSC_CHAPEL */]: "0x0000000000000000000000000000000000000000",
3663
+ ["EVM-1" /* MAINNET */]: "0x0000000000000000000000000000000000000000",
3664
+ ["EVM-56" /* BSC_MAINNET */]: "0x0000000000000000000000000000000000000000"
3665
+ },
3666
+ UniswapV4Quoter: {
3667
+ ["EVM-97" /* BSC_CHAPEL */]: "0x0000000000000000000000000000000000000000",
3668
+ ["EVM-1" /* MAINNET */]: "0x52f0e24d1c21c8a0cb1e5a5dd6198556bd9e1203",
3669
+ ["EVM-56" /* BSC_MAINNET */]: "0x0000000000000000000000000000000000000000"
3622
3670
  },
3623
3671
  Calldispatcher: {
3624
3672
  ["EVM-11155111" /* SEPOLIA */]: "0xC7f13b6D03A0A7F3239d38897503E90553ABe155"
@@ -3628,13 +3676,17 @@ var createRpcUrls = (env2) => ({
3628
3676
  ["EVM-97" /* BSC_CHAPEL */]: env2.BSC_CHAPEL || "https://bnb-testnet.api.onfinality.io/public",
3629
3677
  ["EVM-10200" /* GNOSIS_CHIADO */]: env2.GNOSIS_CHIADO || "https://gnosis-chiado-rpc.publicnode.com",
3630
3678
  ["KUSAMA-4009" /* HYPERBRIDGE_GARGANTUA */]: env2.HYPERBRIDGE_GARGANTUA || "",
3631
- ["EVM-11155111" /* SEPOLIA */]: env2.SEPOLIA || "https://1rpc.io/sepolia"
3679
+ ["EVM-11155111" /* SEPOLIA */]: env2.SEPOLIA || "https://1rpc.io/sepolia",
3680
+ ["EVM-1" /* MAINNET */]: env2.ETH_MAINNET || "https://eth-mainnet.g.alchemy.com/v2/demo",
3681
+ ["EVM-56" /* BSC_MAINNET */]: env2.BSC_MAINNET || "https://binance.llamarpc.com"
3632
3682
  });
3633
3683
  var consensusStateIds = {
3634
3684
  ["EVM-97" /* BSC_CHAPEL */]: "BSC0",
3635
3685
  ["EVM-10200" /* GNOSIS_CHIADO */]: "GNO0",
3636
3686
  ["KUSAMA-4009" /* HYPERBRIDGE_GARGANTUA */]: "PAS0",
3637
- ["EVM-11155111" /* SEPOLIA */]: "ETH0"
3687
+ ["EVM-11155111" /* SEPOLIA */]: "ETH0",
3688
+ ["EVM-1" /* MAINNET */]: "ETH0",
3689
+ ["EVM-56" /* BSC_MAINNET */]: "BSC0"
3638
3690
  };
3639
3691
 
3640
3692
  // src/configs/ChainConfigService.ts
@@ -3704,6 +3756,12 @@ var ChainConfigService = class {
3704
3756
  getUniswapV3QuoterAddress(chain) {
3705
3757
  return addresses.UniswapV3Quoter[chain];
3706
3758
  }
3759
+ getUniswapV4PoolManagerAddress(chain) {
3760
+ return addresses.UniswapV4PoolManager[chain];
3761
+ }
3762
+ getUniswapV4QuoterAddress(chain) {
3763
+ return addresses.UniswapV4Quoter[chain];
3764
+ }
3707
3765
  };
3708
3766
 
3709
3767
  // src/chains/evm.ts
@@ -4028,7 +4086,8 @@ var EvmChain = class {
4028
4086
  functionName: "perByteFee",
4029
4087
  args: [toHex(request.dest)]
4030
4088
  });
4031
- const length = request.body.length > 32 ? 32 : request.body.length;
4089
+ const bodyByteLength = Math.floor((request.body.length - 2) / 2);
4090
+ const length = bodyByteLength < 32 ? 32 : bodyByteLength;
4032
4091
  return perByteFee * BigInt(length);
4033
4092
  }
4034
4093
  /**
@@ -5350,6 +5409,10 @@ var dateStringtoTimestamp = (date) => {
5350
5409
  function mapTestnetToMainnet(identifier) {
5351
5410
  identifier = identifier.toLowerCase();
5352
5411
  switch (identifier) {
5412
+ case "bnb":
5413
+ return "wbnb";
5414
+ case "eth":
5415
+ return "weth";
5353
5416
  case "tbnb":
5354
5417
  return "wbnb";
5355
5418
  case "0xc043f483373072f7f27420d6e7d7ad269c018e18".toLowerCase():
@@ -5413,6 +5476,11 @@ async function fetchFromDefillama(identifier) {
5413
5476
  }
5414
5477
  return price;
5415
5478
  }
5479
+ var ERC20Method = /* @__PURE__ */ ((ERC20Method2) => {
5480
+ ERC20Method2["BALANCE_OF"] = "0x70a08231";
5481
+ ERC20Method2["ALLOWANCE"] = "0xdd62ed3e";
5482
+ return ERC20Method2;
5483
+ })(ERC20Method || {});
5416
5484
  async function getStorageSlot2(client, contractAddress, data) {
5417
5485
  const traceCallClient = client.extend((client2) => ({
5418
5486
  async traceCall(args) {
@@ -5442,6 +5510,16 @@ async function getStorageSlot2(client, contractAddress, data) {
5442
5510
  }
5443
5511
  throw new Error(`Storage slot not found for data: ${methodSignature}`);
5444
5512
  }
5513
+ function adjustFeeDecimals(feeInFeeToken, fromDecimals, toDecimals) {
5514
+ if (fromDecimals === toDecimals) return feeInFeeToken;
5515
+ if (fromDecimals < toDecimals) {
5516
+ const scaleFactor = BigInt(10 ** (toDecimals - fromDecimals));
5517
+ return feeInFeeToken * scaleFactor;
5518
+ } else {
5519
+ const scaleFactor = BigInt(10 ** (fromDecimals - toDecimals));
5520
+ return (feeInFeeToken + scaleFactor - 1n) / scaleFactor;
5521
+ }
5522
+ }
5445
5523
  function createQueryClient(config) {
5446
5524
  return new GraphQLClient(config.url);
5447
5525
  }
@@ -10925,6 +11003,302 @@ var ABI8 = [
10925
11003
  ];
10926
11004
  var uniswapV3Quoter_default = { ABI: ABI8 };
10927
11005
 
11006
+ // src/abis/uniswapV4Quoter.ts
11007
+ var UNISWAP_V4_QUOTER_ABI = [
11008
+ {
11009
+ type: "constructor",
11010
+ inputs: [{ name: "_poolManager", type: "address", internalType: "contract IPoolManager" }],
11011
+ stateMutability: "nonpayable"
11012
+ },
11013
+ {
11014
+ type: "function",
11015
+ name: "_quoteExactInput",
11016
+ inputs: [
11017
+ {
11018
+ name: "params",
11019
+ type: "tuple",
11020
+ internalType: "struct IV4Quoter.QuoteExactParams",
11021
+ components: [
11022
+ { name: "exactCurrency", type: "address", internalType: "Currency" },
11023
+ {
11024
+ name: "path",
11025
+ type: "tuple[]",
11026
+ internalType: "struct PathKey[]",
11027
+ components: [
11028
+ { name: "intermediateCurrency", type: "address", internalType: "Currency" },
11029
+ { name: "fee", type: "uint24", internalType: "uint24" },
11030
+ { name: "tickSpacing", type: "int24", internalType: "int24" },
11031
+ { name: "hooks", type: "address", internalType: "contract IHooks" },
11032
+ { name: "hookData", type: "bytes", internalType: "bytes" }
11033
+ ]
11034
+ },
11035
+ { name: "exactAmount", type: "uint128", internalType: "uint128" }
11036
+ ]
11037
+ }
11038
+ ],
11039
+ outputs: [{ name: "", type: "bytes", internalType: "bytes" }],
11040
+ stateMutability: "nonpayable"
11041
+ },
11042
+ {
11043
+ type: "function",
11044
+ name: "_quoteExactInputSingle",
11045
+ inputs: [
11046
+ {
11047
+ name: "params",
11048
+ type: "tuple",
11049
+ internalType: "struct IV4Quoter.QuoteExactSingleParams",
11050
+ components: [
11051
+ {
11052
+ name: "poolKey",
11053
+ type: "tuple",
11054
+ internalType: "struct PoolKey",
11055
+ components: [
11056
+ { name: "currency0", type: "address", internalType: "Currency" },
11057
+ { name: "currency1", type: "address", internalType: "Currency" },
11058
+ { name: "fee", type: "uint24", internalType: "uint24" },
11059
+ { name: "tickSpacing", type: "int24", internalType: "int24" },
11060
+ { name: "hooks", type: "address", internalType: "contract IHooks" }
11061
+ ]
11062
+ },
11063
+ { name: "zeroForOne", type: "bool", internalType: "bool" },
11064
+ { name: "exactAmount", type: "uint128", internalType: "uint128" },
11065
+ { name: "hookData", type: "bytes", internalType: "bytes" }
11066
+ ]
11067
+ }
11068
+ ],
11069
+ outputs: [{ name: "", type: "bytes", internalType: "bytes" }],
11070
+ stateMutability: "nonpayable"
11071
+ },
11072
+ {
11073
+ type: "function",
11074
+ name: "_quoteExactOutput",
11075
+ inputs: [
11076
+ {
11077
+ name: "params",
11078
+ type: "tuple",
11079
+ internalType: "struct IV4Quoter.QuoteExactParams",
11080
+ components: [
11081
+ { name: "exactCurrency", type: "address", internalType: "Currency" },
11082
+ {
11083
+ name: "path",
11084
+ type: "tuple[]",
11085
+ internalType: "struct PathKey[]",
11086
+ components: [
11087
+ { name: "intermediateCurrency", type: "address", internalType: "Currency" },
11088
+ { name: "fee", type: "uint24", internalType: "uint24" },
11089
+ { name: "tickSpacing", type: "int24", internalType: "int24" },
11090
+ { name: "hooks", type: "address", internalType: "contract IHooks" },
11091
+ { name: "hookData", type: "bytes", internalType: "bytes" }
11092
+ ]
11093
+ },
11094
+ { name: "exactAmount", type: "uint128", internalType: "uint128" }
11095
+ ]
11096
+ }
11097
+ ],
11098
+ outputs: [{ name: "", type: "bytes", internalType: "bytes" }],
11099
+ stateMutability: "nonpayable"
11100
+ },
11101
+ {
11102
+ type: "function",
11103
+ name: "_quoteExactOutputSingle",
11104
+ inputs: [
11105
+ {
11106
+ name: "params",
11107
+ type: "tuple",
11108
+ internalType: "struct IV4Quoter.QuoteExactSingleParams",
11109
+ components: [
11110
+ {
11111
+ name: "poolKey",
11112
+ type: "tuple",
11113
+ internalType: "struct PoolKey",
11114
+ components: [
11115
+ { name: "currency0", type: "address", internalType: "Currency" },
11116
+ { name: "currency1", type: "address", internalType: "Currency" },
11117
+ { name: "fee", type: "uint24", internalType: "uint24" },
11118
+ { name: "tickSpacing", type: "int24", internalType: "int24" },
11119
+ { name: "hooks", type: "address", internalType: "contract IHooks" }
11120
+ ]
11121
+ },
11122
+ { name: "zeroForOne", type: "bool", internalType: "bool" },
11123
+ { name: "exactAmount", type: "uint128", internalType: "uint128" },
11124
+ { name: "hookData", type: "bytes", internalType: "bytes" }
11125
+ ]
11126
+ }
11127
+ ],
11128
+ outputs: [{ name: "", type: "bytes", internalType: "bytes" }],
11129
+ stateMutability: "nonpayable"
11130
+ },
11131
+ {
11132
+ type: "function",
11133
+ name: "msgSender",
11134
+ inputs: [],
11135
+ outputs: [{ name: "", type: "address", internalType: "address" }],
11136
+ stateMutability: "view"
11137
+ },
11138
+ {
11139
+ type: "function",
11140
+ name: "poolManager",
11141
+ inputs: [],
11142
+ outputs: [{ name: "", type: "address", internalType: "contract IPoolManager" }],
11143
+ stateMutability: "view"
11144
+ },
11145
+ {
11146
+ type: "function",
11147
+ name: "quoteExactInput",
11148
+ inputs: [
11149
+ {
11150
+ name: "params",
11151
+ type: "tuple",
11152
+ internalType: "struct IV4Quoter.QuoteExactParams",
11153
+ components: [
11154
+ { name: "exactCurrency", type: "address", internalType: "Currency" },
11155
+ {
11156
+ name: "path",
11157
+ type: "tuple[]",
11158
+ internalType: "struct PathKey[]",
11159
+ components: [
11160
+ { name: "intermediateCurrency", type: "address", internalType: "Currency" },
11161
+ { name: "fee", type: "uint24", internalType: "uint24" },
11162
+ { name: "tickSpacing", type: "int24", internalType: "int24" },
11163
+ { name: "hooks", type: "address", internalType: "contract IHooks" },
11164
+ { name: "hookData", type: "bytes", internalType: "bytes" }
11165
+ ]
11166
+ },
11167
+ { name: "exactAmount", type: "uint128", internalType: "uint128" }
11168
+ ]
11169
+ }
11170
+ ],
11171
+ outputs: [
11172
+ { name: "amountOut", type: "uint256", internalType: "uint256" },
11173
+ { name: "gasEstimate", type: "uint256", internalType: "uint256" }
11174
+ ],
11175
+ stateMutability: "nonpayable"
11176
+ },
11177
+ {
11178
+ type: "function",
11179
+ name: "quoteExactInputSingle",
11180
+ inputs: [
11181
+ {
11182
+ name: "params",
11183
+ type: "tuple",
11184
+ internalType: "struct IV4Quoter.QuoteExactSingleParams",
11185
+ components: [
11186
+ {
11187
+ name: "poolKey",
11188
+ type: "tuple",
11189
+ internalType: "struct PoolKey",
11190
+ components: [
11191
+ { name: "currency0", type: "address", internalType: "Currency" },
11192
+ { name: "currency1", type: "address", internalType: "Currency" },
11193
+ { name: "fee", type: "uint24", internalType: "uint24" },
11194
+ { name: "tickSpacing", type: "int24", internalType: "int24" },
11195
+ { name: "hooks", type: "address", internalType: "contract IHooks" }
11196
+ ]
11197
+ },
11198
+ { name: "zeroForOne", type: "bool", internalType: "bool" },
11199
+ { name: "exactAmount", type: "uint128", internalType: "uint128" },
11200
+ { name: "hookData", type: "bytes", internalType: "bytes" }
11201
+ ]
11202
+ }
11203
+ ],
11204
+ outputs: [
11205
+ { name: "amountOut", type: "uint256", internalType: "uint256" },
11206
+ { name: "gasEstimate", type: "uint256", internalType: "uint256" }
11207
+ ],
11208
+ stateMutability: "nonpayable"
11209
+ },
11210
+ {
11211
+ type: "function",
11212
+ name: "quoteExactOutput",
11213
+ inputs: [
11214
+ {
11215
+ name: "params",
11216
+ type: "tuple",
11217
+ internalType: "struct IV4Quoter.QuoteExactParams",
11218
+ components: [
11219
+ { name: "exactCurrency", type: "address", internalType: "Currency" },
11220
+ {
11221
+ name: "path",
11222
+ type: "tuple[]",
11223
+ internalType: "struct PathKey[]",
11224
+ components: [
11225
+ { name: "intermediateCurrency", type: "address", internalType: "Currency" },
11226
+ { name: "fee", type: "uint24", internalType: "uint24" },
11227
+ { name: "tickSpacing", type: "int24", internalType: "int24" },
11228
+ { name: "hooks", type: "address", internalType: "contract IHooks" },
11229
+ { name: "hookData", type: "bytes", internalType: "bytes" }
11230
+ ]
11231
+ },
11232
+ { name: "exactAmount", type: "uint128", internalType: "uint128" }
11233
+ ]
11234
+ }
11235
+ ],
11236
+ outputs: [
11237
+ { name: "amountIn", type: "uint256", internalType: "uint256" },
11238
+ { name: "gasEstimate", type: "uint256", internalType: "uint256" }
11239
+ ],
11240
+ stateMutability: "nonpayable"
11241
+ },
11242
+ {
11243
+ type: "function",
11244
+ name: "quoteExactOutputSingle",
11245
+ inputs: [
11246
+ {
11247
+ name: "params",
11248
+ type: "tuple",
11249
+ internalType: "struct IV4Quoter.QuoteExactSingleParams",
11250
+ components: [
11251
+ {
11252
+ name: "poolKey",
11253
+ type: "tuple",
11254
+ internalType: "struct PoolKey",
11255
+ components: [
11256
+ { name: "currency0", type: "address", internalType: "Currency" },
11257
+ { name: "currency1", type: "address", internalType: "Currency" },
11258
+ { name: "fee", type: "uint24", internalType: "uint24" },
11259
+ { name: "tickSpacing", type: "int24", internalType: "int24" },
11260
+ { name: "hooks", type: "address", internalType: "contract IHooks" }
11261
+ ]
11262
+ },
11263
+ { name: "zeroForOne", type: "bool", internalType: "bool" },
11264
+ { name: "exactAmount", type: "uint128", internalType: "uint128" },
11265
+ { name: "hookData", type: "bytes", internalType: "bytes" }
11266
+ ]
11267
+ }
11268
+ ],
11269
+ outputs: [
11270
+ { name: "amountIn", type: "uint256", internalType: "uint256" },
11271
+ { name: "gasEstimate", type: "uint256", internalType: "uint256" }
11272
+ ],
11273
+ stateMutability: "nonpayable"
11274
+ },
11275
+ {
11276
+ type: "function",
11277
+ name: "unlockCallback",
11278
+ inputs: [{ name: "data", type: "bytes", internalType: "bytes" }],
11279
+ outputs: [{ name: "", type: "bytes", internalType: "bytes" }],
11280
+ stateMutability: "nonpayable"
11281
+ },
11282
+ {
11283
+ type: "error",
11284
+ name: "NotEnoughLiquidity",
11285
+ inputs: [{ name: "poolId", type: "bytes32", internalType: "PoolId" }]
11286
+ },
11287
+ { type: "error", name: "NotPoolManager", inputs: [] },
11288
+ { type: "error", name: "NotSelf", inputs: [] },
11289
+ {
11290
+ type: "error",
11291
+ name: "QuoteSwap",
11292
+ inputs: [{ name: "amount", type: "uint256", internalType: "uint256" }]
11293
+ },
11294
+ { type: "error", name: "UnexpectedCallSuccess", inputs: [] },
11295
+ {
11296
+ type: "error",
11297
+ name: "UnexpectedRevertBytes",
11298
+ inputs: [{ name: "revertData", type: "bytes", internalType: "bytes" }]
11299
+ }
11300
+ ];
11301
+
10928
11302
  // src/protocols/intents.ts
10929
11303
  var IntentGateway = class {
10930
11304
  /**
@@ -10963,7 +11337,7 @@ var IntentGateway = class {
10963
11337
  );
10964
11338
  const RELAYER_FEE_BPS = 200n;
10965
11339
  const relayerFeeInSourceFeeToken = postGasEstimateInSourceFeeToken + postGasEstimateInSourceFeeToken * RELAYER_FEE_BPS / 10000n;
10966
- const relayerFeeInDestFeeToken = this.adjustFeeDecimals(
11340
+ const relayerFeeInDestFeeToken = adjustFeeDecimals(
10967
11341
  relayerFeeInSourceFeeToken,
10968
11342
  sourceChainFeeTokenDecimals,
10969
11343
  destChainFeeTokenDecimals
@@ -10973,7 +11347,7 @@ var IntentGateway = class {
10973
11347
  };
10974
11348
  const totalEthValue = order.outputs.filter((output) => bytes32ToBytes202(output.token) === ADDRESS_ZERO2).reduce((sum, output) => sum + output.amount, 0n);
10975
11349
  const intentGatewayAddress = this.source.config.getIntentGatewayAddress(order.destChain);
10976
- const testValue = toHex(maxUint256);
11350
+ const testValue = toHex(maxUint256 / 2n);
10977
11351
  const orderOverrides = await Promise.all(
10978
11352
  order.outputs.map(async (output) => {
10979
11353
  const tokenAddress = bytes32ToBytes202(output.token);
@@ -11023,6 +11397,18 @@ var IntentGateway = class {
11023
11397
  address: destChainFeeTokenAddress,
11024
11398
  stateDiff: feeTokenStateDiffs
11025
11399
  });
11400
+ const stateOverride = [
11401
+ // Mock address with ETH balance so that any chain estimation runs
11402
+ // even when the address doesn't hold any native token in that chain
11403
+ {
11404
+ address: MOCK_ADDRESS2,
11405
+ balance: maxUint256
11406
+ },
11407
+ ...orderOverrides.map((override) => ({
11408
+ address: override.address,
11409
+ stateDiff: override.stateDiff
11410
+ }))
11411
+ ];
11026
11412
  const destChainFillGas = await this.dest.client.estimateContractGas({
11027
11413
  abi: IntentGateway_default.ABI,
11028
11414
  address: intentGatewayAddress,
@@ -11030,15 +11416,16 @@ var IntentGateway = class {
11030
11416
  args: [transformOrderForContract(order), fillOptions],
11031
11417
  account: MOCK_ADDRESS2,
11032
11418
  value: totalEthValue,
11033
- stateOverride: orderOverrides
11419
+ stateOverride
11034
11420
  });
11035
11421
  const fillGasInSourceFeeToken = await this.convertGasToFeeToken(
11036
11422
  destChainFillGas,
11037
11423
  this.dest.client,
11038
11424
  sourceChainFeeTokenDecimals
11039
11425
  );
11040
- const protocolFeeInSourceFeeToken = this.adjustFeeDecimals(
11041
- await this.dest.quote(postRequest),
11426
+ const protocolFeeInSourceFeeToken = adjustFeeDecimals(
11427
+ // Following baseIsmpModule.sol, the protocol fee is added to the relayer fee
11428
+ await this.dest.quote(postRequest) + relayerFeeInDestFeeToken,
11042
11429
  destChainFeeTokenDecimals,
11043
11430
  sourceChainFeeTokenDecimals
11044
11431
  );
@@ -11055,31 +11442,37 @@ var IntentGateway = class {
11055
11442
  * @param tokenIn - The address of the input token
11056
11443
  * @param tokenOut - The address of the output token
11057
11444
  * @param amountOut - The desired output amount
11058
- * @returns Object containing the best protocol, required input amount, fee tier (for V3), and gas estimate
11445
+ * @returns Object containing the best protocol, required input amount, and fee tier (for V3)
11059
11446
  */
11060
11447
  async findBestProtocolWithAmountOut(chain, tokenIn, tokenOut, amountOut) {
11061
11448
  const destClient = this.dest.client;
11062
11449
  let amountInV2 = maxUint256;
11063
11450
  let amountInV3 = maxUint256;
11451
+ let amountInV4 = maxUint256;
11064
11452
  let bestV3Fee = 0;
11065
- let v3GasEstimate = BigInt(0);
11453
+ let bestV4Fee = 0;
11454
+ const commonFees = [100, 500, 3e3, 1e4];
11066
11455
  const v2Router = this.source.config.getUniswapRouterV2Address(chain);
11067
11456
  const v2Factory = this.source.config.getUniswapV2FactoryAddress(chain);
11068
11457
  const v3Factory = this.source.config.getUniswapV3FactoryAddress(chain);
11069
11458
  const v3Quoter = this.source.config.getUniswapV3QuoterAddress(chain);
11459
+ const v4Quoter = this.source.config.getUniswapV4QuoterAddress(chain);
11460
+ const wethAsset = this.source.config.getWrappedNativeAssetWithDecimals(chain).asset;
11461
+ const tokenInForQuote = tokenIn === ADDRESS_ZERO2 ? wethAsset : tokenIn;
11462
+ const tokenOutForQuote = tokenOut === ADDRESS_ZERO2 ? wethAsset : tokenOut;
11070
11463
  try {
11071
11464
  const v2PairExists = await destClient.readContract({
11072
11465
  address: v2Factory,
11073
11466
  abi: uniswapV2Factory_default.ABI,
11074
11467
  functionName: "getPair",
11075
- args: [tokenIn, tokenOut]
11468
+ args: [tokenInForQuote, tokenOutForQuote]
11076
11469
  });
11077
11470
  if (v2PairExists !== ADDRESS_ZERO2) {
11078
11471
  const v2AmountIn = await destClient.readContract({
11079
11472
  address: v2Router,
11080
11473
  abi: uniswapRouterV2_default.ABI,
11081
11474
  functionName: "getAmountsIn",
11082
- args: [amountOut, [tokenIn, tokenOut]]
11475
+ args: [amountOut, [tokenInForQuote, tokenOutForQuote]]
11083
11476
  });
11084
11477
  amountInV2 = v2AmountIn[0];
11085
11478
  }
@@ -11087,14 +11480,13 @@ var IntentGateway = class {
11087
11480
  console.warn("V2 quote failed:", error);
11088
11481
  }
11089
11482
  let bestV3AmountIn = maxUint256;
11090
- const fees = [500, 3e3, 1e4];
11091
- for (const fee of fees) {
11483
+ for (const fee of commonFees) {
11092
11484
  try {
11093
11485
  const pool = await destClient.readContract({
11094
11486
  address: v3Factory,
11095
11487
  abi: uniswapV3Factory_default.ABI,
11096
11488
  functionName: "getPool",
11097
- args: [tokenIn, tokenOut, fee]
11489
+ args: [tokenInForQuote, tokenOutForQuote, fee]
11098
11490
  });
11099
11491
  if (pool !== ADDRESS_ZERO2) {
11100
11492
  const liquidity = await destClient.readContract({
@@ -11103,25 +11495,24 @@ var IntentGateway = class {
11103
11495
  functionName: "liquidity"
11104
11496
  });
11105
11497
  if (liquidity > BigInt(0)) {
11106
- const quoteResult = await destClient.readContract({
11498
+ const quoteResult = (await destClient.simulateContract({
11107
11499
  address: v3Quoter,
11108
11500
  abi: uniswapV3Quoter_default.ABI,
11109
11501
  functionName: "quoteExactOutputSingle",
11110
11502
  args: [
11111
11503
  {
11112
- tokenIn,
11113
- tokenOut,
11504
+ tokenIn: tokenInForQuote,
11505
+ tokenOut: tokenOutForQuote,
11114
11506
  fee,
11115
11507
  amount: amountOut,
11116
11508
  sqrtPriceLimitX96: BigInt(0)
11117
11509
  }
11118
11510
  ]
11119
- });
11120
- const [amountIn, , , gasEstimate] = quoteResult;
11511
+ })).result;
11512
+ const amountIn = quoteResult[0];
11121
11513
  if (amountIn < bestV3AmountIn) {
11122
11514
  bestV3AmountIn = amountIn;
11123
11515
  bestV3Fee = fee;
11124
- v3GasEstimate = gasEstimate;
11125
11516
  }
11126
11517
  }
11127
11518
  }
@@ -11130,13 +11521,81 @@ var IntentGateway = class {
11130
11521
  }
11131
11522
  }
11132
11523
  amountInV3 = bestV3AmountIn;
11133
- if (amountInV2 === maxUint256 && amountInV3 === maxUint256) {
11134
- return { protocol: null, amountIn: maxUint256 };
11524
+ let bestV4AmountIn = maxUint256;
11525
+ for (const fee of commonFees) {
11526
+ try {
11527
+ const currency0 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenIn : tokenOut;
11528
+ const currency1 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenOut : tokenIn;
11529
+ const zeroForOne = tokenIn.toLowerCase() === currency0.toLowerCase();
11530
+ const poolKey = {
11531
+ currency0,
11532
+ currency1,
11533
+ fee,
11534
+ tickSpacing: this.getTickSpacing(fee),
11535
+ hooks: ADDRESS_ZERO2
11536
+ // No hooks
11537
+ };
11538
+ const quoteResult = (await destClient.simulateContract({
11539
+ address: v4Quoter,
11540
+ abi: UNISWAP_V4_QUOTER_ABI,
11541
+ functionName: "quoteExactOutputSingle",
11542
+ args: [
11543
+ {
11544
+ poolKey,
11545
+ zeroForOne,
11546
+ exactAmount: amountOut,
11547
+ hookData: "0x"
11548
+ // Empty hook data
11549
+ }
11550
+ ]
11551
+ })).result;
11552
+ const amountIn = quoteResult[0];
11553
+ if (amountIn < bestV4AmountIn) {
11554
+ bestV4AmountIn = amountIn;
11555
+ bestV4Fee = fee;
11556
+ }
11557
+ } catch (error) {
11558
+ console.warn(`V4 quote failed for fee ${fee}, continuing to next fee tier`);
11559
+ }
11135
11560
  }
11136
- if (amountInV2 <= amountInV3) {
11137
- return { protocol: "v2", amountIn: amountInV2 };
11561
+ amountInV4 = bestV4AmountIn;
11562
+ if (amountInV2 === maxUint256 && amountInV3 === maxUint256 && amountInV4 === maxUint256) {
11563
+ return {
11564
+ protocol: null,
11565
+ amountIn: maxUint256
11566
+ };
11567
+ }
11568
+ if (amountInV4 !== maxUint256) {
11569
+ const thresholdBps = 100n;
11570
+ if (amountInV3 !== maxUint256 && this.isWithinThreshold(amountInV4, amountInV3, thresholdBps)) {
11571
+ return { protocol: "v4", amountIn: amountInV4, fee: bestV4Fee };
11572
+ }
11573
+ if (amountInV2 !== maxUint256 && this.isWithinThreshold(amountInV4, amountInV2, thresholdBps)) {
11574
+ return { protocol: "v4", amountIn: amountInV4, fee: bestV4Fee };
11575
+ }
11576
+ }
11577
+ const minAmount = [
11578
+ { protocol: "v2", amountIn: amountInV2 },
11579
+ { protocol: "v3", amountIn: amountInV3, fee: bestV3Fee },
11580
+ { protocol: "v4", amountIn: amountInV4, fee: bestV4Fee }
11581
+ ].reduce((best, current) => current.amountIn < best.amountIn ? current : best);
11582
+ if (minAmount.protocol === "v2") {
11583
+ return {
11584
+ protocol: "v2",
11585
+ amountIn: amountInV2
11586
+ };
11587
+ } else if (minAmount.protocol === "v3") {
11588
+ return {
11589
+ protocol: "v3",
11590
+ amountIn: amountInV3,
11591
+ fee: bestV3Fee
11592
+ };
11138
11593
  } else {
11139
- return { protocol: "v3", amountIn: amountInV3, fee: bestV3Fee, gasEstimate: v3GasEstimate };
11594
+ return {
11595
+ protocol: "v4",
11596
+ amountIn: amountInV4,
11597
+ fee: bestV4Fee
11598
+ };
11140
11599
  }
11141
11600
  }
11142
11601
  /**
@@ -11147,31 +11606,37 @@ var IntentGateway = class {
11147
11606
  * @param tokenIn - The address of the input token
11148
11607
  * @param tokenOut - The address of the output token
11149
11608
  * @param amountIn - The input amount to swap
11150
- * @returns Object containing the best protocol, expected output amount, fee tier (for V3), and gas estimate
11609
+ * @returns Object containing the best protocol, expected output amount, and fee tier (for V3)
11151
11610
  */
11152
11611
  async findBestProtocolWithAmountIn(chain, tokenIn, tokenOut, amountIn) {
11153
11612
  const destClient = this.dest.client;
11154
11613
  let amountOutV2 = BigInt(0);
11155
11614
  let amountOutV3 = BigInt(0);
11615
+ let amountOutV4 = BigInt(0);
11156
11616
  let bestV3Fee = 0;
11157
- let v3GasEstimate = BigInt(0);
11617
+ let bestV4Fee = 0;
11618
+ const commonFees = [100, 500, 3e3, 1e4];
11158
11619
  const v2Router = this.source.config.getUniswapRouterV2Address(chain);
11159
11620
  const v2Factory = this.source.config.getUniswapV2FactoryAddress(chain);
11160
11621
  const v3Factory = this.source.config.getUniswapV3FactoryAddress(chain);
11161
11622
  const v3Quoter = this.source.config.getUniswapV3QuoterAddress(chain);
11623
+ const v4Quoter = this.source.config.getUniswapV4QuoterAddress(chain);
11624
+ const wethAsset = this.source.config.getWrappedNativeAssetWithDecimals(chain).asset;
11625
+ const tokenInForQuote = tokenIn === ADDRESS_ZERO2 ? wethAsset : tokenIn;
11626
+ const tokenOutForQuote = tokenOut === ADDRESS_ZERO2 ? wethAsset : tokenOut;
11162
11627
  try {
11163
11628
  const v2PairExists = await destClient.readContract({
11164
11629
  address: v2Factory,
11165
11630
  abi: uniswapV2Factory_default.ABI,
11166
11631
  functionName: "getPair",
11167
- args: [tokenIn, tokenOut]
11632
+ args: [tokenInForQuote, tokenOutForQuote]
11168
11633
  });
11169
11634
  if (v2PairExists !== ADDRESS_ZERO2) {
11170
11635
  const v2AmountOut = await destClient.readContract({
11171
11636
  address: v2Router,
11172
11637
  abi: uniswapRouterV2_default.ABI,
11173
11638
  functionName: "getAmountsOut",
11174
- args: [amountIn, [tokenIn, tokenOut]]
11639
+ args: [amountIn, [tokenInForQuote, tokenOutForQuote]]
11175
11640
  });
11176
11641
  amountOutV2 = v2AmountOut[1];
11177
11642
  }
@@ -11179,14 +11644,13 @@ var IntentGateway = class {
11179
11644
  console.warn("V2 quote failed:", error);
11180
11645
  }
11181
11646
  let bestV3AmountOut = BigInt(0);
11182
- const fees = [500, 3e3, 1e4];
11183
- for (const fee of fees) {
11647
+ for (const fee of commonFees) {
11184
11648
  try {
11185
11649
  const pool = await destClient.readContract({
11186
11650
  address: v3Factory,
11187
11651
  abi: uniswapV3Factory_default.ABI,
11188
11652
  functionName: "getPool",
11189
- args: [tokenIn, tokenOut, fee]
11653
+ args: [tokenInForQuote, tokenOutForQuote, fee]
11190
11654
  });
11191
11655
  if (pool !== ADDRESS_ZERO2) {
11192
11656
  const liquidity = await destClient.readContract({
@@ -11195,25 +11659,24 @@ var IntentGateway = class {
11195
11659
  functionName: "liquidity"
11196
11660
  });
11197
11661
  if (liquidity > BigInt(0)) {
11198
- const quoteResult = await destClient.readContract({
11662
+ const quoteResult = (await destClient.simulateContract({
11199
11663
  address: v3Quoter,
11200
11664
  abi: uniswapV3Quoter_default.ABI,
11201
11665
  functionName: "quoteExactInputSingle",
11202
11666
  args: [
11203
11667
  {
11204
- tokenIn,
11205
- tokenOut,
11668
+ tokenIn: tokenInForQuote,
11669
+ tokenOut: tokenOutForQuote,
11206
11670
  fee,
11207
11671
  amountIn,
11208
11672
  sqrtPriceLimitX96: BigInt(0)
11209
11673
  }
11210
11674
  ]
11211
- });
11212
- const [amountOut, , , gasEstimate] = quoteResult;
11675
+ })).result;
11676
+ const amountOut = quoteResult[0];
11213
11677
  if (amountOut > bestV3AmountOut) {
11214
11678
  bestV3AmountOut = amountOut;
11215
11679
  bestV3Fee = fee;
11216
- v3GasEstimate = gasEstimate;
11217
11680
  }
11218
11681
  }
11219
11682
  }
@@ -11222,13 +11685,81 @@ var IntentGateway = class {
11222
11685
  }
11223
11686
  }
11224
11687
  amountOutV3 = bestV3AmountOut;
11225
- if (amountOutV2 === BigInt(0) && amountOutV3 === BigInt(0)) {
11226
- return { protocol: null, amountOut: BigInt(0) };
11688
+ let bestV4AmountOut = BigInt(0);
11689
+ for (const fee of commonFees) {
11690
+ try {
11691
+ const currency0 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenIn : tokenOut;
11692
+ const currency1 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenOut : tokenIn;
11693
+ const zeroForOne = tokenIn.toLowerCase() === currency0.toLowerCase();
11694
+ const poolKey = {
11695
+ currency0,
11696
+ currency1,
11697
+ fee,
11698
+ tickSpacing: this.getTickSpacing(fee),
11699
+ hooks: ADDRESS_ZERO2
11700
+ // No hooks
11701
+ };
11702
+ const quoteResult = (await destClient.simulateContract({
11703
+ address: v4Quoter,
11704
+ abi: UNISWAP_V4_QUOTER_ABI,
11705
+ functionName: "quoteExactInputSingle",
11706
+ args: [
11707
+ {
11708
+ poolKey,
11709
+ zeroForOne,
11710
+ exactAmount: amountIn,
11711
+ hookData: "0x"
11712
+ // Empty hook data
11713
+ }
11714
+ ]
11715
+ })).result;
11716
+ const amountOut = quoteResult[0];
11717
+ if (amountOut > bestV4AmountOut) {
11718
+ bestV4AmountOut = amountOut;
11719
+ bestV4Fee = fee;
11720
+ }
11721
+ } catch (error) {
11722
+ console.warn(`V4 quote failed for fee ${fee}, continuing to next fee tier`);
11723
+ }
11227
11724
  }
11228
- if (amountOutV2 >= amountOutV3) {
11229
- return { protocol: "v2", amountOut: amountOutV2 };
11725
+ amountOutV4 = bestV4AmountOut;
11726
+ if (amountOutV2 === BigInt(0) && amountOutV3 === BigInt(0) && amountOutV4 === BigInt(0)) {
11727
+ return {
11728
+ protocol: null,
11729
+ amountOut: BigInt(0)
11730
+ };
11731
+ }
11732
+ if (amountOutV4 !== BigInt(0)) {
11733
+ const thresholdBps = 100n;
11734
+ if (amountOutV3 !== BigInt(0) && this.isWithinThreshold(amountOutV4, amountOutV3, thresholdBps)) {
11735
+ return { protocol: "v4", amountOut: amountOutV4, fee: bestV4Fee };
11736
+ }
11737
+ if (amountOutV2 !== BigInt(0) && this.isWithinThreshold(amountOutV4, amountOutV2, thresholdBps)) {
11738
+ return { protocol: "v4", amountOut: amountOutV4, fee: bestV4Fee };
11739
+ }
11740
+ }
11741
+ const maxAmount = [
11742
+ { protocol: "v2", amountOut: amountOutV2 },
11743
+ { protocol: "v3", amountOut: amountOutV3, fee: bestV3Fee },
11744
+ { protocol: "v4", amountOut: amountOutV4, fee: bestV4Fee }
11745
+ ].reduce((best, current) => current.amountOut > best.amountOut ? current : best);
11746
+ if (maxAmount.protocol === "v2") {
11747
+ return {
11748
+ protocol: "v2",
11749
+ amountOut: amountOutV2
11750
+ };
11751
+ } else if (maxAmount.protocol === "v3") {
11752
+ return {
11753
+ protocol: "v3",
11754
+ amountOut: amountOutV3,
11755
+ fee: bestV3Fee
11756
+ };
11230
11757
  } else {
11231
- return { protocol: "v3", amountOut: amountOutV3, fee: bestV3Fee, gasEstimate: v3GasEstimate };
11758
+ return {
11759
+ protocol: "v4",
11760
+ amountOut: amountOutV4,
11761
+ fee: bestV4Fee
11762
+ };
11232
11763
  }
11233
11764
  }
11234
11765
  /**
@@ -11255,25 +11786,6 @@ var IntentGateway = class {
11255
11786
  const gasCostInFeeToken = gasCostUsd / feeTokenPriceUsd;
11256
11787
  return BigInt(Math.floor(gasCostInFeeToken * Math.pow(10, targetDecimals)));
11257
11788
  }
11258
- /**
11259
- * Adjusts fee amounts between different decimal precisions.
11260
- * Handles scaling up or down based on the decimal difference.
11261
- *
11262
- * @param feeInFeeToken - The fee amount to adjust
11263
- * @param fromDecimals - The current decimal precision
11264
- * @param toDecimals - The target decimal precision
11265
- * @returns The adjusted fee amount with the target decimal precision
11266
- */
11267
- adjustFeeDecimals(feeInFeeToken, fromDecimals, toDecimals) {
11268
- if (fromDecimals === toDecimals) return feeInFeeToken;
11269
- if (fromDecimals < toDecimals) {
11270
- const scaleFactor = BigInt(10 ** (toDecimals - fromDecimals));
11271
- return feeInFeeToken * scaleFactor;
11272
- } else {
11273
- const scaleFactor = BigInt(10 ** (fromDecimals - toDecimals));
11274
- return (feeInFeeToken + scaleFactor - 1n) / scaleFactor;
11275
- }
11276
- }
11277
11789
  /**
11278
11790
  * Checks if an order has been filled by verifying the commitment status on-chain.
11279
11791
  * Reads the storage slot corresponding to the order's commitment hash.
@@ -11295,6 +11807,36 @@ var IntentGateway = class {
11295
11807
  });
11296
11808
  return filledStatus !== "0x0000000000000000000000000000000000000000000000000000000000000000";
11297
11809
  }
11810
+ /**
11811
+ * Returns the tick spacing for a given fee tier in Uniswap V4
11812
+ * @param fee - The fee tier in basis points
11813
+ * @returns The tick spacing value
11814
+ */
11815
+ getTickSpacing(fee) {
11816
+ switch (fee) {
11817
+ case 100:
11818
+ return 1;
11819
+ case 500:
11820
+ return 10;
11821
+ case 3e3:
11822
+ return 60;
11823
+ case 1e4:
11824
+ return 200;
11825
+ default:
11826
+ return 60;
11827
+ }
11828
+ }
11829
+ /**
11830
+ * Returns true if candidate <= reference * (1 + thresholdBps/10000)
11831
+ * @param candidate - The candidate amount to compare
11832
+ * @param reference - The reference amount
11833
+ * @param thresholdBps - The threshold in basis points
11834
+ * @returns True if candidate is within threshold of reference
11835
+ */
11836
+ isWithinThreshold(candidate, reference, thresholdBps) {
11837
+ const basisPoints = 10000n;
11838
+ return candidate * basisPoints <= reference * (basisPoints + thresholdBps);
11839
+ }
11298
11840
  };
11299
11841
  function transformOrderForContract(order) {
11300
11842
  return {
@@ -11608,6 +12150,6 @@ async function teleportDot(param_) {
11608
12150
  return stream;
11609
12151
  }
11610
12152
 
11611
- export { ADDRESS_ZERO2 as ADDRESS_ZERO, AbortSignalInternal, ChainConfigService, Chains, DEFAULT_ADDRESS, DUMMY_PRIVATE_KEY, EvmChain, HyperClientStatus, IndexerClient, IntentGateway, OrderStatus, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, RequestKind, RequestStatus, STATE_COMMITMENTS_SLOT, SubstrateChain, TeleportStatus, TimeoutStatus, WrappedNativeDecimals, __test, addresses, assets, bytes20ToBytes32, bytes32ToBytes202 as bytes32ToBytes20, chainIds, consensusStateIds, constructRedeemEscrowRequestBody2 as constructRedeemEscrowRequestBody, convertStateMachineIdToEnum, createQueryClient, createRpcUrls, encodeISMPMessage, estimateGasForPost, fetchTokenUsdPrice2 as fetchTokenUsdPrice, generateRootWithProof, getChain, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot2 as getStorageSlot, hexToString2 as hexToString, orderCommitment2 as orderCommitment, postRequestCommitment, queryGetRequest, queryPostRequest, teleport, teleportDot, viemChains };
12153
+ export { ADDRESS_ZERO2 as ADDRESS_ZERO, AbortSignalInternal, ChainConfigService, Chains, DEFAULT_ADDRESS, DUMMY_PRIVATE_KEY, ERC20Method, EvmChain, HyperClientStatus, IndexerClient, IntentGateway, OrderStatus, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, RequestKind, RequestStatus, STATE_COMMITMENTS_SLOT, SubstrateChain, TeleportStatus, TimeoutStatus, WrappedNativeDecimals, __test, addresses, adjustFeeDecimals, assets, bytes20ToBytes32, bytes32ToBytes202 as bytes32ToBytes20, chainIds, consensusStateIds, constructRedeemEscrowRequestBody2 as constructRedeemEscrowRequestBody, convertStateMachineIdToEnum, createQueryClient, createRpcUrls, encodeISMPMessage, estimateGasForPost, fetchTokenUsdPrice2 as fetchTokenUsdPrice, generateRootWithProof, getChain, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot2 as getStorageSlot, hexToString2 as hexToString, orderCommitment2 as orderCommitment, postRequestCommitment, queryGetRequest, queryPostRequest, teleport, teleportDot, viemChains };
11612
12154
  //# sourceMappingURL=index.js.map
11613
12155
  //# sourceMappingURL=index.js.map