@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.
- package/dist/browser/index.d.ts +102 -18
- package/dist/browser/index.js +618 -76
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.d.ts +102 -18
- package/dist/node/index.js +618 -76
- package/dist/node/index.js.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.js
CHANGED
|
@@ -3595,23 +3595,31 @@ var Chains = /* @__PURE__ */ ((Chains2) => {
|
|
|
3595
3595
|
Chains2["GNOSIS_CHIADO"] = "EVM-10200";
|
|
3596
3596
|
Chains2["HYPERBRIDGE_GARGANTUA"] = "KUSAMA-4009";
|
|
3597
3597
|
Chains2["SEPOLIA"] = "EVM-11155111";
|
|
3598
|
+
Chains2["MAINNET"] = "EVM-1";
|
|
3599
|
+
Chains2["BSC_MAINNET"] = "EVM-56";
|
|
3598
3600
|
return Chains2;
|
|
3599
3601
|
})(Chains || {});
|
|
3600
3602
|
var chainIds = {
|
|
3601
3603
|
["EVM-97" /* BSC_CHAPEL */]: 97,
|
|
3602
3604
|
["EVM-10200" /* GNOSIS_CHIADO */]: 10200,
|
|
3603
3605
|
["KUSAMA-4009" /* HYPERBRIDGE_GARGANTUA */]: 4009,
|
|
3604
|
-
["EVM-11155111" /* SEPOLIA */]: 11155111
|
|
3606
|
+
["EVM-11155111" /* SEPOLIA */]: 11155111,
|
|
3607
|
+
["EVM-1" /* MAINNET */]: 1,
|
|
3608
|
+
["EVM-56" /* BSC_MAINNET */]: 56
|
|
3605
3609
|
};
|
|
3606
3610
|
var viemChains = {
|
|
3607
3611
|
"97": bscTestnet,
|
|
3608
3612
|
"10200": gnosisChiado,
|
|
3609
|
-
"11155111": sepolia
|
|
3613
|
+
"11155111": sepolia,
|
|
3614
|
+
"1": mainnet,
|
|
3615
|
+
"56": bsc
|
|
3610
3616
|
};
|
|
3611
3617
|
var WrappedNativeDecimals = {
|
|
3612
3618
|
["EVM-97" /* BSC_CHAPEL */]: 18,
|
|
3613
3619
|
["EVM-10200" /* GNOSIS_CHIADO */]: 18,
|
|
3614
|
-
["EVM-11155111" /* SEPOLIA */]: 18
|
|
3620
|
+
["EVM-11155111" /* SEPOLIA */]: 18,
|
|
3621
|
+
["EVM-1" /* MAINNET */]: 18,
|
|
3622
|
+
["EVM-56" /* BSC_MAINNET */]: 18
|
|
3615
3623
|
};
|
|
3616
3624
|
var assets = {
|
|
3617
3625
|
["EVM-97" /* BSC_CHAPEL */]: {
|
|
@@ -3631,43 +3639,83 @@ var assets = {
|
|
|
3631
3639
|
USDC: "0x0000000000000000000000000000000000000000".toLowerCase(),
|
|
3632
3640
|
USDT: "0x0000000000000000000000000000000000000000".toLowerCase(),
|
|
3633
3641
|
DAI: "0x0000000000000000000000000000000000000000".toLowerCase()
|
|
3642
|
+
},
|
|
3643
|
+
["EVM-1" /* MAINNET */]: {
|
|
3644
|
+
WETH: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2".toLowerCase(),
|
|
3645
|
+
DAI: "0x6B175474E89094C44Da98b954EedeAC495271d0F".toLowerCase(),
|
|
3646
|
+
USDC: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48".toLowerCase(),
|
|
3647
|
+
USDT: "0xdAC17F958D2ee523a2206206994597C13D831ec7".toLowerCase()
|
|
3648
|
+
},
|
|
3649
|
+
["EVM-56" /* BSC_MAINNET */]: {
|
|
3650
|
+
WETH: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c".toLowerCase(),
|
|
3651
|
+
DAI: "0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3".toLowerCase(),
|
|
3652
|
+
USDC: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d".toLowerCase(),
|
|
3653
|
+
USDT: "0x55d398326f99059fF775485246999027B3197955".toLowerCase()
|
|
3634
3654
|
}
|
|
3635
3655
|
};
|
|
3636
3656
|
var addresses = {
|
|
3637
3657
|
IntentGateway: {
|
|
3638
3658
|
["EVM-97" /* BSC_CHAPEL */]: "0xb6C27F4beF379d0b5e2fe3Bb36c248D6B71f91A6",
|
|
3639
3659
|
["EVM-10200" /* GNOSIS_CHIADO */]: "0xb6C27F4beF379d0b5e2fe3Bb36c248D6B71f91A6",
|
|
3640
|
-
["EVM-11155111" /* SEPOLIA */]: "0x0000000000000000000000000000000000000000"
|
|
3660
|
+
["EVM-11155111" /* SEPOLIA */]: "0x0000000000000000000000000000000000000000",
|
|
3661
|
+
["EVM-1" /* MAINNET */]: "0xd54165e45926720b062C192a5bacEC64d5bB08DA",
|
|
3662
|
+
["EVM-56" /* BSC_MAINNET */]: "0xd54165e45926720b062C192a5bacEC64d5bB08DA"
|
|
3641
3663
|
},
|
|
3642
3664
|
Host: {
|
|
3643
3665
|
["EVM-97" /* BSC_CHAPEL */]: "0x8Aa0Dea6D675d785A882967Bf38183f6117C09b7",
|
|
3644
3666
|
["EVM-10200" /* GNOSIS_CHIADO */]: "0x58a41b89f4871725e5d898d98ef4bf917601c5eb",
|
|
3645
|
-
["EVM-11155111" /* SEPOLIA */]: "0x2EdB74C269948b60ec1000040E104cef0eABaae8"
|
|
3667
|
+
["EVM-11155111" /* SEPOLIA */]: "0x2EdB74C269948b60ec1000040E104cef0eABaae8",
|
|
3668
|
+
["EVM-1" /* MAINNET */]: "0x792A6236AF69787C40cF76b69B4c8c7B28c4cA20",
|
|
3669
|
+
["EVM-56" /* BSC_MAINNET */]: "0x24B5d421Ec373FcA57325dd2F0C074009Af021F7"
|
|
3646
3670
|
},
|
|
3647
3671
|
UniswapRouter02: {
|
|
3648
3672
|
["EVM-97" /* BSC_CHAPEL */]: "0x9639379819420704457B07A0C33B678D9E0F8Df0",
|
|
3649
3673
|
["EVM-10200" /* GNOSIS_CHIADO */]: "0x0000000000000000000000000000000000000000",
|
|
3650
|
-
["EVM-11155111" /* SEPOLIA */]: "0x0000000000000000000000000000000000000000"
|
|
3674
|
+
["EVM-11155111" /* SEPOLIA */]: "0x0000000000000000000000000000000000000000",
|
|
3675
|
+
["EVM-1" /* MAINNET */]: "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
|
|
3676
|
+
["EVM-56" /* BSC_MAINNET */]: "0x0000000000000000000000000000000000000000"
|
|
3651
3677
|
},
|
|
3652
3678
|
UniswapV2Factory: {
|
|
3653
3679
|
["EVM-97" /* BSC_CHAPEL */]: "0x12e036669DA18F4A2777853d6e2136b32AceEC86",
|
|
3654
3680
|
["EVM-10200" /* GNOSIS_CHIADO */]: "0x0000000000000000000000000000000000000000",
|
|
3655
|
-
["EVM-11155111" /* SEPOLIA */]: "0x0000000000000000000000000000000000000000"
|
|
3681
|
+
["EVM-11155111" /* SEPOLIA */]: "0x0000000000000000000000000000000000000000",
|
|
3682
|
+
["EVM-1" /* MAINNET */]: "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
|
|
3683
|
+
["EVM-56" /* BSC_MAINNET */]: "0x0000000000000000000000000000000000000000"
|
|
3656
3684
|
},
|
|
3657
3685
|
BatchExecutor: {
|
|
3658
|
-
["EVM-97" /* BSC_CHAPEL */]: "0x4CC58B5D8FBf838d062E4b21F75C327835B5F0ef"
|
|
3686
|
+
["EVM-97" /* BSC_CHAPEL */]: "0x4CC58B5D8FBf838d062E4b21F75C327835B5F0ef",
|
|
3687
|
+
["EVM-1" /* MAINNET */]: "0x0000000000000000000000000000000000000000",
|
|
3688
|
+
["EVM-56" /* BSC_MAINNET */]: "0x0000000000000000000000000000000000000000"
|
|
3659
3689
|
},
|
|
3660
3690
|
UniversalRouter: {
|
|
3661
|
-
["EVM-97" /* BSC_CHAPEL */]: "0xcc6d5ece3d4a57245bf5a2f64f3ed9179b81f714"
|
|
3691
|
+
["EVM-97" /* BSC_CHAPEL */]: "0xcc6d5ece3d4a57245bf5a2f64f3ed9179b81f714",
|
|
3692
|
+
["EVM-1" /* MAINNET */]: "0x0000000000000000000000000000000000000000",
|
|
3693
|
+
["EVM-56" /* BSC_MAINNET */]: "0x0000000000000000000000000000000000000000"
|
|
3662
3694
|
},
|
|
3663
3695
|
UniswapV3Router: {
|
|
3664
|
-
["EVM-97" /* BSC_CHAPEL */]: "0x0000000000000000000000000000000000000000"
|
|
3696
|
+
["EVM-97" /* BSC_CHAPEL */]: "0x0000000000000000000000000000000000000000",
|
|
3697
|
+
["EVM-1" /* MAINNET */]: "0x1F98431c8aD98523631AE4a59f267346ea31F984",
|
|
3698
|
+
["EVM-56" /* BSC_MAINNET */]: "0x0000000000000000000000000000000000000000"
|
|
3665
3699
|
},
|
|
3666
3700
|
UniswapV3Factory: {
|
|
3667
|
-
["EVM-97" /* BSC_CHAPEL */]: "0x0000000000000000000000000000000000000000"
|
|
3701
|
+
["EVM-97" /* BSC_CHAPEL */]: "0x0000000000000000000000000000000000000000",
|
|
3702
|
+
["EVM-1" /* MAINNET */]: "0x1F98431c8aD98523631AE4a59f267346ea31F984",
|
|
3703
|
+
["EVM-56" /* BSC_MAINNET */]: "0x0000000000000000000000000000000000000000"
|
|
3668
3704
|
},
|
|
3669
3705
|
UniswapV3Quoter: {
|
|
3670
|
-
["EVM-97" /* BSC_CHAPEL */]: "0x0000000000000000000000000000000000000000"
|
|
3706
|
+
["EVM-97" /* BSC_CHAPEL */]: "0x0000000000000000000000000000000000000000",
|
|
3707
|
+
["EVM-1" /* MAINNET */]: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e",
|
|
3708
|
+
["EVM-56" /* BSC_MAINNET */]: "0x0000000000000000000000000000000000000000"
|
|
3709
|
+
},
|
|
3710
|
+
UniswapV4PoolManager: {
|
|
3711
|
+
["EVM-97" /* BSC_CHAPEL */]: "0x0000000000000000000000000000000000000000",
|
|
3712
|
+
["EVM-1" /* MAINNET */]: "0x0000000000000000000000000000000000000000",
|
|
3713
|
+
["EVM-56" /* BSC_MAINNET */]: "0x0000000000000000000000000000000000000000"
|
|
3714
|
+
},
|
|
3715
|
+
UniswapV4Quoter: {
|
|
3716
|
+
["EVM-97" /* BSC_CHAPEL */]: "0x0000000000000000000000000000000000000000",
|
|
3717
|
+
["EVM-1" /* MAINNET */]: "0x52f0e24d1c21c8a0cb1e5a5dd6198556bd9e1203",
|
|
3718
|
+
["EVM-56" /* BSC_MAINNET */]: "0x0000000000000000000000000000000000000000"
|
|
3671
3719
|
},
|
|
3672
3720
|
Calldispatcher: {
|
|
3673
3721
|
["EVM-11155111" /* SEPOLIA */]: "0xC7f13b6D03A0A7F3239d38897503E90553ABe155"
|
|
@@ -3677,13 +3725,17 @@ var createRpcUrls = (env2) => ({
|
|
|
3677
3725
|
["EVM-97" /* BSC_CHAPEL */]: env2.BSC_CHAPEL || "https://bnb-testnet.api.onfinality.io/public",
|
|
3678
3726
|
["EVM-10200" /* GNOSIS_CHIADO */]: env2.GNOSIS_CHIADO || "https://gnosis-chiado-rpc.publicnode.com",
|
|
3679
3727
|
["KUSAMA-4009" /* HYPERBRIDGE_GARGANTUA */]: env2.HYPERBRIDGE_GARGANTUA || "",
|
|
3680
|
-
["EVM-11155111" /* SEPOLIA */]: env2.SEPOLIA || "https://1rpc.io/sepolia"
|
|
3728
|
+
["EVM-11155111" /* SEPOLIA */]: env2.SEPOLIA || "https://1rpc.io/sepolia",
|
|
3729
|
+
["EVM-1" /* MAINNET */]: env2.ETH_MAINNET || "https://eth-mainnet.g.alchemy.com/v2/demo",
|
|
3730
|
+
["EVM-56" /* BSC_MAINNET */]: env2.BSC_MAINNET || "https://binance.llamarpc.com"
|
|
3681
3731
|
});
|
|
3682
3732
|
var consensusStateIds = {
|
|
3683
3733
|
["EVM-97" /* BSC_CHAPEL */]: "BSC0",
|
|
3684
3734
|
["EVM-10200" /* GNOSIS_CHIADO */]: "GNO0",
|
|
3685
3735
|
["KUSAMA-4009" /* HYPERBRIDGE_GARGANTUA */]: "PAS0",
|
|
3686
|
-
["EVM-11155111" /* SEPOLIA */]: "ETH0"
|
|
3736
|
+
["EVM-11155111" /* SEPOLIA */]: "ETH0",
|
|
3737
|
+
["EVM-1" /* MAINNET */]: "ETH0",
|
|
3738
|
+
["EVM-56" /* BSC_MAINNET */]: "BSC0"
|
|
3687
3739
|
};
|
|
3688
3740
|
|
|
3689
3741
|
// src/configs/ChainConfigService.ts
|
|
@@ -3753,6 +3805,12 @@ var ChainConfigService = class {
|
|
|
3753
3805
|
getUniswapV3QuoterAddress(chain) {
|
|
3754
3806
|
return addresses.UniswapV3Quoter[chain];
|
|
3755
3807
|
}
|
|
3808
|
+
getUniswapV4PoolManagerAddress(chain) {
|
|
3809
|
+
return addresses.UniswapV4PoolManager[chain];
|
|
3810
|
+
}
|
|
3811
|
+
getUniswapV4QuoterAddress(chain) {
|
|
3812
|
+
return addresses.UniswapV4Quoter[chain];
|
|
3813
|
+
}
|
|
3756
3814
|
};
|
|
3757
3815
|
|
|
3758
3816
|
// src/chains/evm.ts
|
|
@@ -4077,7 +4135,8 @@ var EvmChain = class {
|
|
|
4077
4135
|
functionName: "perByteFee",
|
|
4078
4136
|
args: [toHex(request.dest)]
|
|
4079
4137
|
});
|
|
4080
|
-
const
|
|
4138
|
+
const bodyByteLength = Math.floor((request.body.length - 2) / 2);
|
|
4139
|
+
const length = bodyByteLength < 32 ? 32 : bodyByteLength;
|
|
4081
4140
|
return perByteFee * BigInt(length);
|
|
4082
4141
|
}
|
|
4083
4142
|
/**
|
|
@@ -5399,6 +5458,10 @@ var dateStringtoTimestamp = (date) => {
|
|
|
5399
5458
|
function mapTestnetToMainnet(identifier) {
|
|
5400
5459
|
identifier = identifier.toLowerCase();
|
|
5401
5460
|
switch (identifier) {
|
|
5461
|
+
case "bnb":
|
|
5462
|
+
return "wbnb";
|
|
5463
|
+
case "eth":
|
|
5464
|
+
return "weth";
|
|
5402
5465
|
case "tbnb":
|
|
5403
5466
|
return "wbnb";
|
|
5404
5467
|
case "0xc043f483373072f7f27420d6e7d7ad269c018e18".toLowerCase():
|
|
@@ -5462,6 +5525,11 @@ async function fetchFromDefillama(identifier) {
|
|
|
5462
5525
|
}
|
|
5463
5526
|
return price;
|
|
5464
5527
|
}
|
|
5528
|
+
var ERC20Method = /* @__PURE__ */ ((ERC20Method2) => {
|
|
5529
|
+
ERC20Method2["BALANCE_OF"] = "0x70a08231";
|
|
5530
|
+
ERC20Method2["ALLOWANCE"] = "0xdd62ed3e";
|
|
5531
|
+
return ERC20Method2;
|
|
5532
|
+
})(ERC20Method || {});
|
|
5465
5533
|
async function getStorageSlot2(client, contractAddress, data) {
|
|
5466
5534
|
const traceCallClient = client.extend((client2) => ({
|
|
5467
5535
|
async traceCall(args) {
|
|
@@ -5491,6 +5559,16 @@ async function getStorageSlot2(client, contractAddress, data) {
|
|
|
5491
5559
|
}
|
|
5492
5560
|
throw new Error(`Storage slot not found for data: ${methodSignature}`);
|
|
5493
5561
|
}
|
|
5562
|
+
function adjustFeeDecimals(feeInFeeToken, fromDecimals, toDecimals) {
|
|
5563
|
+
if (fromDecimals === toDecimals) return feeInFeeToken;
|
|
5564
|
+
if (fromDecimals < toDecimals) {
|
|
5565
|
+
const scaleFactor = BigInt(10 ** (toDecimals - fromDecimals));
|
|
5566
|
+
return feeInFeeToken * scaleFactor;
|
|
5567
|
+
} else {
|
|
5568
|
+
const scaleFactor = BigInt(10 ** (fromDecimals - toDecimals));
|
|
5569
|
+
return (feeInFeeToken + scaleFactor - 1n) / scaleFactor;
|
|
5570
|
+
}
|
|
5571
|
+
}
|
|
5494
5572
|
function createQueryClient(config) {
|
|
5495
5573
|
return new GraphQLClient(config.url);
|
|
5496
5574
|
}
|
|
@@ -10974,6 +11052,302 @@ var ABI8 = [
|
|
|
10974
11052
|
];
|
|
10975
11053
|
var uniswapV3Quoter_default = { ABI: ABI8 };
|
|
10976
11054
|
|
|
11055
|
+
// src/abis/uniswapV4Quoter.ts
|
|
11056
|
+
var UNISWAP_V4_QUOTER_ABI = [
|
|
11057
|
+
{
|
|
11058
|
+
type: "constructor",
|
|
11059
|
+
inputs: [{ name: "_poolManager", type: "address", internalType: "contract IPoolManager" }],
|
|
11060
|
+
stateMutability: "nonpayable"
|
|
11061
|
+
},
|
|
11062
|
+
{
|
|
11063
|
+
type: "function",
|
|
11064
|
+
name: "_quoteExactInput",
|
|
11065
|
+
inputs: [
|
|
11066
|
+
{
|
|
11067
|
+
name: "params",
|
|
11068
|
+
type: "tuple",
|
|
11069
|
+
internalType: "struct IV4Quoter.QuoteExactParams",
|
|
11070
|
+
components: [
|
|
11071
|
+
{ name: "exactCurrency", type: "address", internalType: "Currency" },
|
|
11072
|
+
{
|
|
11073
|
+
name: "path",
|
|
11074
|
+
type: "tuple[]",
|
|
11075
|
+
internalType: "struct PathKey[]",
|
|
11076
|
+
components: [
|
|
11077
|
+
{ name: "intermediateCurrency", type: "address", internalType: "Currency" },
|
|
11078
|
+
{ name: "fee", type: "uint24", internalType: "uint24" },
|
|
11079
|
+
{ name: "tickSpacing", type: "int24", internalType: "int24" },
|
|
11080
|
+
{ name: "hooks", type: "address", internalType: "contract IHooks" },
|
|
11081
|
+
{ name: "hookData", type: "bytes", internalType: "bytes" }
|
|
11082
|
+
]
|
|
11083
|
+
},
|
|
11084
|
+
{ name: "exactAmount", type: "uint128", internalType: "uint128" }
|
|
11085
|
+
]
|
|
11086
|
+
}
|
|
11087
|
+
],
|
|
11088
|
+
outputs: [{ name: "", type: "bytes", internalType: "bytes" }],
|
|
11089
|
+
stateMutability: "nonpayable"
|
|
11090
|
+
},
|
|
11091
|
+
{
|
|
11092
|
+
type: "function",
|
|
11093
|
+
name: "_quoteExactInputSingle",
|
|
11094
|
+
inputs: [
|
|
11095
|
+
{
|
|
11096
|
+
name: "params",
|
|
11097
|
+
type: "tuple",
|
|
11098
|
+
internalType: "struct IV4Quoter.QuoteExactSingleParams",
|
|
11099
|
+
components: [
|
|
11100
|
+
{
|
|
11101
|
+
name: "poolKey",
|
|
11102
|
+
type: "tuple",
|
|
11103
|
+
internalType: "struct PoolKey",
|
|
11104
|
+
components: [
|
|
11105
|
+
{ name: "currency0", type: "address", internalType: "Currency" },
|
|
11106
|
+
{ name: "currency1", type: "address", internalType: "Currency" },
|
|
11107
|
+
{ name: "fee", type: "uint24", internalType: "uint24" },
|
|
11108
|
+
{ name: "tickSpacing", type: "int24", internalType: "int24" },
|
|
11109
|
+
{ name: "hooks", type: "address", internalType: "contract IHooks" }
|
|
11110
|
+
]
|
|
11111
|
+
},
|
|
11112
|
+
{ name: "zeroForOne", type: "bool", internalType: "bool" },
|
|
11113
|
+
{ name: "exactAmount", type: "uint128", internalType: "uint128" },
|
|
11114
|
+
{ name: "hookData", type: "bytes", internalType: "bytes" }
|
|
11115
|
+
]
|
|
11116
|
+
}
|
|
11117
|
+
],
|
|
11118
|
+
outputs: [{ name: "", type: "bytes", internalType: "bytes" }],
|
|
11119
|
+
stateMutability: "nonpayable"
|
|
11120
|
+
},
|
|
11121
|
+
{
|
|
11122
|
+
type: "function",
|
|
11123
|
+
name: "_quoteExactOutput",
|
|
11124
|
+
inputs: [
|
|
11125
|
+
{
|
|
11126
|
+
name: "params",
|
|
11127
|
+
type: "tuple",
|
|
11128
|
+
internalType: "struct IV4Quoter.QuoteExactParams",
|
|
11129
|
+
components: [
|
|
11130
|
+
{ name: "exactCurrency", type: "address", internalType: "Currency" },
|
|
11131
|
+
{
|
|
11132
|
+
name: "path",
|
|
11133
|
+
type: "tuple[]",
|
|
11134
|
+
internalType: "struct PathKey[]",
|
|
11135
|
+
components: [
|
|
11136
|
+
{ name: "intermediateCurrency", type: "address", internalType: "Currency" },
|
|
11137
|
+
{ name: "fee", type: "uint24", internalType: "uint24" },
|
|
11138
|
+
{ name: "tickSpacing", type: "int24", internalType: "int24" },
|
|
11139
|
+
{ name: "hooks", type: "address", internalType: "contract IHooks" },
|
|
11140
|
+
{ name: "hookData", type: "bytes", internalType: "bytes" }
|
|
11141
|
+
]
|
|
11142
|
+
},
|
|
11143
|
+
{ name: "exactAmount", type: "uint128", internalType: "uint128" }
|
|
11144
|
+
]
|
|
11145
|
+
}
|
|
11146
|
+
],
|
|
11147
|
+
outputs: [{ name: "", type: "bytes", internalType: "bytes" }],
|
|
11148
|
+
stateMutability: "nonpayable"
|
|
11149
|
+
},
|
|
11150
|
+
{
|
|
11151
|
+
type: "function",
|
|
11152
|
+
name: "_quoteExactOutputSingle",
|
|
11153
|
+
inputs: [
|
|
11154
|
+
{
|
|
11155
|
+
name: "params",
|
|
11156
|
+
type: "tuple",
|
|
11157
|
+
internalType: "struct IV4Quoter.QuoteExactSingleParams",
|
|
11158
|
+
components: [
|
|
11159
|
+
{
|
|
11160
|
+
name: "poolKey",
|
|
11161
|
+
type: "tuple",
|
|
11162
|
+
internalType: "struct PoolKey",
|
|
11163
|
+
components: [
|
|
11164
|
+
{ name: "currency0", type: "address", internalType: "Currency" },
|
|
11165
|
+
{ name: "currency1", type: "address", internalType: "Currency" },
|
|
11166
|
+
{ name: "fee", type: "uint24", internalType: "uint24" },
|
|
11167
|
+
{ name: "tickSpacing", type: "int24", internalType: "int24" },
|
|
11168
|
+
{ name: "hooks", type: "address", internalType: "contract IHooks" }
|
|
11169
|
+
]
|
|
11170
|
+
},
|
|
11171
|
+
{ name: "zeroForOne", type: "bool", internalType: "bool" },
|
|
11172
|
+
{ name: "exactAmount", type: "uint128", internalType: "uint128" },
|
|
11173
|
+
{ name: "hookData", type: "bytes", internalType: "bytes" }
|
|
11174
|
+
]
|
|
11175
|
+
}
|
|
11176
|
+
],
|
|
11177
|
+
outputs: [{ name: "", type: "bytes", internalType: "bytes" }],
|
|
11178
|
+
stateMutability: "nonpayable"
|
|
11179
|
+
},
|
|
11180
|
+
{
|
|
11181
|
+
type: "function",
|
|
11182
|
+
name: "msgSender",
|
|
11183
|
+
inputs: [],
|
|
11184
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
11185
|
+
stateMutability: "view"
|
|
11186
|
+
},
|
|
11187
|
+
{
|
|
11188
|
+
type: "function",
|
|
11189
|
+
name: "poolManager",
|
|
11190
|
+
inputs: [],
|
|
11191
|
+
outputs: [{ name: "", type: "address", internalType: "contract IPoolManager" }],
|
|
11192
|
+
stateMutability: "view"
|
|
11193
|
+
},
|
|
11194
|
+
{
|
|
11195
|
+
type: "function",
|
|
11196
|
+
name: "quoteExactInput",
|
|
11197
|
+
inputs: [
|
|
11198
|
+
{
|
|
11199
|
+
name: "params",
|
|
11200
|
+
type: "tuple",
|
|
11201
|
+
internalType: "struct IV4Quoter.QuoteExactParams",
|
|
11202
|
+
components: [
|
|
11203
|
+
{ name: "exactCurrency", type: "address", internalType: "Currency" },
|
|
11204
|
+
{
|
|
11205
|
+
name: "path",
|
|
11206
|
+
type: "tuple[]",
|
|
11207
|
+
internalType: "struct PathKey[]",
|
|
11208
|
+
components: [
|
|
11209
|
+
{ name: "intermediateCurrency", type: "address", internalType: "Currency" },
|
|
11210
|
+
{ name: "fee", type: "uint24", internalType: "uint24" },
|
|
11211
|
+
{ name: "tickSpacing", type: "int24", internalType: "int24" },
|
|
11212
|
+
{ name: "hooks", type: "address", internalType: "contract IHooks" },
|
|
11213
|
+
{ name: "hookData", type: "bytes", internalType: "bytes" }
|
|
11214
|
+
]
|
|
11215
|
+
},
|
|
11216
|
+
{ name: "exactAmount", type: "uint128", internalType: "uint128" }
|
|
11217
|
+
]
|
|
11218
|
+
}
|
|
11219
|
+
],
|
|
11220
|
+
outputs: [
|
|
11221
|
+
{ name: "amountOut", type: "uint256", internalType: "uint256" },
|
|
11222
|
+
{ name: "gasEstimate", type: "uint256", internalType: "uint256" }
|
|
11223
|
+
],
|
|
11224
|
+
stateMutability: "nonpayable"
|
|
11225
|
+
},
|
|
11226
|
+
{
|
|
11227
|
+
type: "function",
|
|
11228
|
+
name: "quoteExactInputSingle",
|
|
11229
|
+
inputs: [
|
|
11230
|
+
{
|
|
11231
|
+
name: "params",
|
|
11232
|
+
type: "tuple",
|
|
11233
|
+
internalType: "struct IV4Quoter.QuoteExactSingleParams",
|
|
11234
|
+
components: [
|
|
11235
|
+
{
|
|
11236
|
+
name: "poolKey",
|
|
11237
|
+
type: "tuple",
|
|
11238
|
+
internalType: "struct PoolKey",
|
|
11239
|
+
components: [
|
|
11240
|
+
{ name: "currency0", type: "address", internalType: "Currency" },
|
|
11241
|
+
{ name: "currency1", type: "address", internalType: "Currency" },
|
|
11242
|
+
{ name: "fee", type: "uint24", internalType: "uint24" },
|
|
11243
|
+
{ name: "tickSpacing", type: "int24", internalType: "int24" },
|
|
11244
|
+
{ name: "hooks", type: "address", internalType: "contract IHooks" }
|
|
11245
|
+
]
|
|
11246
|
+
},
|
|
11247
|
+
{ name: "zeroForOne", type: "bool", internalType: "bool" },
|
|
11248
|
+
{ name: "exactAmount", type: "uint128", internalType: "uint128" },
|
|
11249
|
+
{ name: "hookData", type: "bytes", internalType: "bytes" }
|
|
11250
|
+
]
|
|
11251
|
+
}
|
|
11252
|
+
],
|
|
11253
|
+
outputs: [
|
|
11254
|
+
{ name: "amountOut", type: "uint256", internalType: "uint256" },
|
|
11255
|
+
{ name: "gasEstimate", type: "uint256", internalType: "uint256" }
|
|
11256
|
+
],
|
|
11257
|
+
stateMutability: "nonpayable"
|
|
11258
|
+
},
|
|
11259
|
+
{
|
|
11260
|
+
type: "function",
|
|
11261
|
+
name: "quoteExactOutput",
|
|
11262
|
+
inputs: [
|
|
11263
|
+
{
|
|
11264
|
+
name: "params",
|
|
11265
|
+
type: "tuple",
|
|
11266
|
+
internalType: "struct IV4Quoter.QuoteExactParams",
|
|
11267
|
+
components: [
|
|
11268
|
+
{ name: "exactCurrency", type: "address", internalType: "Currency" },
|
|
11269
|
+
{
|
|
11270
|
+
name: "path",
|
|
11271
|
+
type: "tuple[]",
|
|
11272
|
+
internalType: "struct PathKey[]",
|
|
11273
|
+
components: [
|
|
11274
|
+
{ name: "intermediateCurrency", type: "address", internalType: "Currency" },
|
|
11275
|
+
{ name: "fee", type: "uint24", internalType: "uint24" },
|
|
11276
|
+
{ name: "tickSpacing", type: "int24", internalType: "int24" },
|
|
11277
|
+
{ name: "hooks", type: "address", internalType: "contract IHooks" },
|
|
11278
|
+
{ name: "hookData", type: "bytes", internalType: "bytes" }
|
|
11279
|
+
]
|
|
11280
|
+
},
|
|
11281
|
+
{ name: "exactAmount", type: "uint128", internalType: "uint128" }
|
|
11282
|
+
]
|
|
11283
|
+
}
|
|
11284
|
+
],
|
|
11285
|
+
outputs: [
|
|
11286
|
+
{ name: "amountIn", type: "uint256", internalType: "uint256" },
|
|
11287
|
+
{ name: "gasEstimate", type: "uint256", internalType: "uint256" }
|
|
11288
|
+
],
|
|
11289
|
+
stateMutability: "nonpayable"
|
|
11290
|
+
},
|
|
11291
|
+
{
|
|
11292
|
+
type: "function",
|
|
11293
|
+
name: "quoteExactOutputSingle",
|
|
11294
|
+
inputs: [
|
|
11295
|
+
{
|
|
11296
|
+
name: "params",
|
|
11297
|
+
type: "tuple",
|
|
11298
|
+
internalType: "struct IV4Quoter.QuoteExactSingleParams",
|
|
11299
|
+
components: [
|
|
11300
|
+
{
|
|
11301
|
+
name: "poolKey",
|
|
11302
|
+
type: "tuple",
|
|
11303
|
+
internalType: "struct PoolKey",
|
|
11304
|
+
components: [
|
|
11305
|
+
{ name: "currency0", type: "address", internalType: "Currency" },
|
|
11306
|
+
{ name: "currency1", type: "address", internalType: "Currency" },
|
|
11307
|
+
{ name: "fee", type: "uint24", internalType: "uint24" },
|
|
11308
|
+
{ name: "tickSpacing", type: "int24", internalType: "int24" },
|
|
11309
|
+
{ name: "hooks", type: "address", internalType: "contract IHooks" }
|
|
11310
|
+
]
|
|
11311
|
+
},
|
|
11312
|
+
{ name: "zeroForOne", type: "bool", internalType: "bool" },
|
|
11313
|
+
{ name: "exactAmount", type: "uint128", internalType: "uint128" },
|
|
11314
|
+
{ name: "hookData", type: "bytes", internalType: "bytes" }
|
|
11315
|
+
]
|
|
11316
|
+
}
|
|
11317
|
+
],
|
|
11318
|
+
outputs: [
|
|
11319
|
+
{ name: "amountIn", type: "uint256", internalType: "uint256" },
|
|
11320
|
+
{ name: "gasEstimate", type: "uint256", internalType: "uint256" }
|
|
11321
|
+
],
|
|
11322
|
+
stateMutability: "nonpayable"
|
|
11323
|
+
},
|
|
11324
|
+
{
|
|
11325
|
+
type: "function",
|
|
11326
|
+
name: "unlockCallback",
|
|
11327
|
+
inputs: [{ name: "data", type: "bytes", internalType: "bytes" }],
|
|
11328
|
+
outputs: [{ name: "", type: "bytes", internalType: "bytes" }],
|
|
11329
|
+
stateMutability: "nonpayable"
|
|
11330
|
+
},
|
|
11331
|
+
{
|
|
11332
|
+
type: "error",
|
|
11333
|
+
name: "NotEnoughLiquidity",
|
|
11334
|
+
inputs: [{ name: "poolId", type: "bytes32", internalType: "PoolId" }]
|
|
11335
|
+
},
|
|
11336
|
+
{ type: "error", name: "NotPoolManager", inputs: [] },
|
|
11337
|
+
{ type: "error", name: "NotSelf", inputs: [] },
|
|
11338
|
+
{
|
|
11339
|
+
type: "error",
|
|
11340
|
+
name: "QuoteSwap",
|
|
11341
|
+
inputs: [{ name: "amount", type: "uint256", internalType: "uint256" }]
|
|
11342
|
+
},
|
|
11343
|
+
{ type: "error", name: "UnexpectedCallSuccess", inputs: [] },
|
|
11344
|
+
{
|
|
11345
|
+
type: "error",
|
|
11346
|
+
name: "UnexpectedRevertBytes",
|
|
11347
|
+
inputs: [{ name: "revertData", type: "bytes", internalType: "bytes" }]
|
|
11348
|
+
}
|
|
11349
|
+
];
|
|
11350
|
+
|
|
10977
11351
|
// src/protocols/intents.ts
|
|
10978
11352
|
var IntentGateway = class {
|
|
10979
11353
|
/**
|
|
@@ -11012,7 +11386,7 @@ var IntentGateway = class {
|
|
|
11012
11386
|
);
|
|
11013
11387
|
const RELAYER_FEE_BPS = 200n;
|
|
11014
11388
|
const relayerFeeInSourceFeeToken = postGasEstimateInSourceFeeToken + postGasEstimateInSourceFeeToken * RELAYER_FEE_BPS / 10000n;
|
|
11015
|
-
const relayerFeeInDestFeeToken =
|
|
11389
|
+
const relayerFeeInDestFeeToken = adjustFeeDecimals(
|
|
11016
11390
|
relayerFeeInSourceFeeToken,
|
|
11017
11391
|
sourceChainFeeTokenDecimals,
|
|
11018
11392
|
destChainFeeTokenDecimals
|
|
@@ -11022,7 +11396,7 @@ var IntentGateway = class {
|
|
|
11022
11396
|
};
|
|
11023
11397
|
const totalEthValue = order.outputs.filter((output) => bytes32ToBytes202(output.token) === ADDRESS_ZERO2).reduce((sum, output) => sum + output.amount, 0n);
|
|
11024
11398
|
const intentGatewayAddress = this.source.config.getIntentGatewayAddress(order.destChain);
|
|
11025
|
-
const testValue = toHex(maxUint256);
|
|
11399
|
+
const testValue = toHex(maxUint256 / 2n);
|
|
11026
11400
|
const orderOverrides = await Promise.all(
|
|
11027
11401
|
order.outputs.map(async (output) => {
|
|
11028
11402
|
const tokenAddress = bytes32ToBytes202(output.token);
|
|
@@ -11072,6 +11446,18 @@ var IntentGateway = class {
|
|
|
11072
11446
|
address: destChainFeeTokenAddress,
|
|
11073
11447
|
stateDiff: feeTokenStateDiffs
|
|
11074
11448
|
});
|
|
11449
|
+
const stateOverride = [
|
|
11450
|
+
// Mock address with ETH balance so that any chain estimation runs
|
|
11451
|
+
// even when the address doesn't hold any native token in that chain
|
|
11452
|
+
{
|
|
11453
|
+
address: MOCK_ADDRESS2,
|
|
11454
|
+
balance: maxUint256
|
|
11455
|
+
},
|
|
11456
|
+
...orderOverrides.map((override) => ({
|
|
11457
|
+
address: override.address,
|
|
11458
|
+
stateDiff: override.stateDiff
|
|
11459
|
+
}))
|
|
11460
|
+
];
|
|
11075
11461
|
const destChainFillGas = await this.dest.client.estimateContractGas({
|
|
11076
11462
|
abi: IntentGateway_default.ABI,
|
|
11077
11463
|
address: intentGatewayAddress,
|
|
@@ -11079,15 +11465,16 @@ var IntentGateway = class {
|
|
|
11079
11465
|
args: [transformOrderForContract(order), fillOptions],
|
|
11080
11466
|
account: MOCK_ADDRESS2,
|
|
11081
11467
|
value: totalEthValue,
|
|
11082
|
-
stateOverride
|
|
11468
|
+
stateOverride
|
|
11083
11469
|
});
|
|
11084
11470
|
const fillGasInSourceFeeToken = await this.convertGasToFeeToken(
|
|
11085
11471
|
destChainFillGas,
|
|
11086
11472
|
this.dest.client,
|
|
11087
11473
|
sourceChainFeeTokenDecimals
|
|
11088
11474
|
);
|
|
11089
|
-
const protocolFeeInSourceFeeToken =
|
|
11090
|
-
|
|
11475
|
+
const protocolFeeInSourceFeeToken = adjustFeeDecimals(
|
|
11476
|
+
// Following baseIsmpModule.sol, the protocol fee is added to the relayer fee
|
|
11477
|
+
await this.dest.quote(postRequest) + relayerFeeInDestFeeToken,
|
|
11091
11478
|
destChainFeeTokenDecimals,
|
|
11092
11479
|
sourceChainFeeTokenDecimals
|
|
11093
11480
|
);
|
|
@@ -11104,31 +11491,37 @@ var IntentGateway = class {
|
|
|
11104
11491
|
* @param tokenIn - The address of the input token
|
|
11105
11492
|
* @param tokenOut - The address of the output token
|
|
11106
11493
|
* @param amountOut - The desired output amount
|
|
11107
|
-
* @returns Object containing the best protocol, required input amount, fee tier (for V3)
|
|
11494
|
+
* @returns Object containing the best protocol, required input amount, and fee tier (for V3)
|
|
11108
11495
|
*/
|
|
11109
11496
|
async findBestProtocolWithAmountOut(chain, tokenIn, tokenOut, amountOut) {
|
|
11110
11497
|
const destClient = this.dest.client;
|
|
11111
11498
|
let amountInV2 = maxUint256;
|
|
11112
11499
|
let amountInV3 = maxUint256;
|
|
11500
|
+
let amountInV4 = maxUint256;
|
|
11113
11501
|
let bestV3Fee = 0;
|
|
11114
|
-
let
|
|
11502
|
+
let bestV4Fee = 0;
|
|
11503
|
+
const commonFees = [100, 500, 3e3, 1e4];
|
|
11115
11504
|
const v2Router = this.source.config.getUniswapRouterV2Address(chain);
|
|
11116
11505
|
const v2Factory = this.source.config.getUniswapV2FactoryAddress(chain);
|
|
11117
11506
|
const v3Factory = this.source.config.getUniswapV3FactoryAddress(chain);
|
|
11118
11507
|
const v3Quoter = this.source.config.getUniswapV3QuoterAddress(chain);
|
|
11508
|
+
const v4Quoter = this.source.config.getUniswapV4QuoterAddress(chain);
|
|
11509
|
+
const wethAsset = this.source.config.getWrappedNativeAssetWithDecimals(chain).asset;
|
|
11510
|
+
const tokenInForQuote = tokenIn === ADDRESS_ZERO2 ? wethAsset : tokenIn;
|
|
11511
|
+
const tokenOutForQuote = tokenOut === ADDRESS_ZERO2 ? wethAsset : tokenOut;
|
|
11119
11512
|
try {
|
|
11120
11513
|
const v2PairExists = await destClient.readContract({
|
|
11121
11514
|
address: v2Factory,
|
|
11122
11515
|
abi: uniswapV2Factory_default.ABI,
|
|
11123
11516
|
functionName: "getPair",
|
|
11124
|
-
args: [
|
|
11517
|
+
args: [tokenInForQuote, tokenOutForQuote]
|
|
11125
11518
|
});
|
|
11126
11519
|
if (v2PairExists !== ADDRESS_ZERO2) {
|
|
11127
11520
|
const v2AmountIn = await destClient.readContract({
|
|
11128
11521
|
address: v2Router,
|
|
11129
11522
|
abi: uniswapRouterV2_default.ABI,
|
|
11130
11523
|
functionName: "getAmountsIn",
|
|
11131
|
-
args: [amountOut, [
|
|
11524
|
+
args: [amountOut, [tokenInForQuote, tokenOutForQuote]]
|
|
11132
11525
|
});
|
|
11133
11526
|
amountInV2 = v2AmountIn[0];
|
|
11134
11527
|
}
|
|
@@ -11136,14 +11529,13 @@ var IntentGateway = class {
|
|
|
11136
11529
|
console.warn("V2 quote failed:", error);
|
|
11137
11530
|
}
|
|
11138
11531
|
let bestV3AmountIn = maxUint256;
|
|
11139
|
-
const
|
|
11140
|
-
for (const fee of fees) {
|
|
11532
|
+
for (const fee of commonFees) {
|
|
11141
11533
|
try {
|
|
11142
11534
|
const pool = await destClient.readContract({
|
|
11143
11535
|
address: v3Factory,
|
|
11144
11536
|
abi: uniswapV3Factory_default.ABI,
|
|
11145
11537
|
functionName: "getPool",
|
|
11146
|
-
args: [
|
|
11538
|
+
args: [tokenInForQuote, tokenOutForQuote, fee]
|
|
11147
11539
|
});
|
|
11148
11540
|
if (pool !== ADDRESS_ZERO2) {
|
|
11149
11541
|
const liquidity = await destClient.readContract({
|
|
@@ -11152,25 +11544,24 @@ var IntentGateway = class {
|
|
|
11152
11544
|
functionName: "liquidity"
|
|
11153
11545
|
});
|
|
11154
11546
|
if (liquidity > BigInt(0)) {
|
|
11155
|
-
const quoteResult = await destClient.
|
|
11547
|
+
const quoteResult = (await destClient.simulateContract({
|
|
11156
11548
|
address: v3Quoter,
|
|
11157
11549
|
abi: uniswapV3Quoter_default.ABI,
|
|
11158
11550
|
functionName: "quoteExactOutputSingle",
|
|
11159
11551
|
args: [
|
|
11160
11552
|
{
|
|
11161
|
-
tokenIn,
|
|
11162
|
-
tokenOut,
|
|
11553
|
+
tokenIn: tokenInForQuote,
|
|
11554
|
+
tokenOut: tokenOutForQuote,
|
|
11163
11555
|
fee,
|
|
11164
11556
|
amount: amountOut,
|
|
11165
11557
|
sqrtPriceLimitX96: BigInt(0)
|
|
11166
11558
|
}
|
|
11167
11559
|
]
|
|
11168
|
-
});
|
|
11169
|
-
const
|
|
11560
|
+
})).result;
|
|
11561
|
+
const amountIn = quoteResult[0];
|
|
11170
11562
|
if (amountIn < bestV3AmountIn) {
|
|
11171
11563
|
bestV3AmountIn = amountIn;
|
|
11172
11564
|
bestV3Fee = fee;
|
|
11173
|
-
v3GasEstimate = gasEstimate;
|
|
11174
11565
|
}
|
|
11175
11566
|
}
|
|
11176
11567
|
}
|
|
@@ -11179,13 +11570,81 @@ var IntentGateway = class {
|
|
|
11179
11570
|
}
|
|
11180
11571
|
}
|
|
11181
11572
|
amountInV3 = bestV3AmountIn;
|
|
11182
|
-
|
|
11183
|
-
|
|
11573
|
+
let bestV4AmountIn = maxUint256;
|
|
11574
|
+
for (const fee of commonFees) {
|
|
11575
|
+
try {
|
|
11576
|
+
const currency0 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenIn : tokenOut;
|
|
11577
|
+
const currency1 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenOut : tokenIn;
|
|
11578
|
+
const zeroForOne = tokenIn.toLowerCase() === currency0.toLowerCase();
|
|
11579
|
+
const poolKey = {
|
|
11580
|
+
currency0,
|
|
11581
|
+
currency1,
|
|
11582
|
+
fee,
|
|
11583
|
+
tickSpacing: this.getTickSpacing(fee),
|
|
11584
|
+
hooks: ADDRESS_ZERO2
|
|
11585
|
+
// No hooks
|
|
11586
|
+
};
|
|
11587
|
+
const quoteResult = (await destClient.simulateContract({
|
|
11588
|
+
address: v4Quoter,
|
|
11589
|
+
abi: UNISWAP_V4_QUOTER_ABI,
|
|
11590
|
+
functionName: "quoteExactOutputSingle",
|
|
11591
|
+
args: [
|
|
11592
|
+
{
|
|
11593
|
+
poolKey,
|
|
11594
|
+
zeroForOne,
|
|
11595
|
+
exactAmount: amountOut,
|
|
11596
|
+
hookData: "0x"
|
|
11597
|
+
// Empty hook data
|
|
11598
|
+
}
|
|
11599
|
+
]
|
|
11600
|
+
})).result;
|
|
11601
|
+
const amountIn = quoteResult[0];
|
|
11602
|
+
if (amountIn < bestV4AmountIn) {
|
|
11603
|
+
bestV4AmountIn = amountIn;
|
|
11604
|
+
bestV4Fee = fee;
|
|
11605
|
+
}
|
|
11606
|
+
} catch (error) {
|
|
11607
|
+
console.warn(`V4 quote failed for fee ${fee}, continuing to next fee tier`);
|
|
11608
|
+
}
|
|
11184
11609
|
}
|
|
11185
|
-
|
|
11186
|
-
|
|
11610
|
+
amountInV4 = bestV4AmountIn;
|
|
11611
|
+
if (amountInV2 === maxUint256 && amountInV3 === maxUint256 && amountInV4 === maxUint256) {
|
|
11612
|
+
return {
|
|
11613
|
+
protocol: null,
|
|
11614
|
+
amountIn: maxUint256
|
|
11615
|
+
};
|
|
11616
|
+
}
|
|
11617
|
+
if (amountInV4 !== maxUint256) {
|
|
11618
|
+
const thresholdBps = 100n;
|
|
11619
|
+
if (amountInV3 !== maxUint256 && this.isWithinThreshold(amountInV4, amountInV3, thresholdBps)) {
|
|
11620
|
+
return { protocol: "v4", amountIn: amountInV4, fee: bestV4Fee };
|
|
11621
|
+
}
|
|
11622
|
+
if (amountInV2 !== maxUint256 && this.isWithinThreshold(amountInV4, amountInV2, thresholdBps)) {
|
|
11623
|
+
return { protocol: "v4", amountIn: amountInV4, fee: bestV4Fee };
|
|
11624
|
+
}
|
|
11625
|
+
}
|
|
11626
|
+
const minAmount = [
|
|
11627
|
+
{ protocol: "v2", amountIn: amountInV2 },
|
|
11628
|
+
{ protocol: "v3", amountIn: amountInV3, fee: bestV3Fee },
|
|
11629
|
+
{ protocol: "v4", amountIn: amountInV4, fee: bestV4Fee }
|
|
11630
|
+
].reduce((best, current) => current.amountIn < best.amountIn ? current : best);
|
|
11631
|
+
if (minAmount.protocol === "v2") {
|
|
11632
|
+
return {
|
|
11633
|
+
protocol: "v2",
|
|
11634
|
+
amountIn: amountInV2
|
|
11635
|
+
};
|
|
11636
|
+
} else if (minAmount.protocol === "v3") {
|
|
11637
|
+
return {
|
|
11638
|
+
protocol: "v3",
|
|
11639
|
+
amountIn: amountInV3,
|
|
11640
|
+
fee: bestV3Fee
|
|
11641
|
+
};
|
|
11187
11642
|
} else {
|
|
11188
|
-
return {
|
|
11643
|
+
return {
|
|
11644
|
+
protocol: "v4",
|
|
11645
|
+
amountIn: amountInV4,
|
|
11646
|
+
fee: bestV4Fee
|
|
11647
|
+
};
|
|
11189
11648
|
}
|
|
11190
11649
|
}
|
|
11191
11650
|
/**
|
|
@@ -11196,31 +11655,37 @@ var IntentGateway = class {
|
|
|
11196
11655
|
* @param tokenIn - The address of the input token
|
|
11197
11656
|
* @param tokenOut - The address of the output token
|
|
11198
11657
|
* @param amountIn - The input amount to swap
|
|
11199
|
-
* @returns Object containing the best protocol, expected output amount, fee tier (for V3)
|
|
11658
|
+
* @returns Object containing the best protocol, expected output amount, and fee tier (for V3)
|
|
11200
11659
|
*/
|
|
11201
11660
|
async findBestProtocolWithAmountIn(chain, tokenIn, tokenOut, amountIn) {
|
|
11202
11661
|
const destClient = this.dest.client;
|
|
11203
11662
|
let amountOutV2 = BigInt(0);
|
|
11204
11663
|
let amountOutV3 = BigInt(0);
|
|
11664
|
+
let amountOutV4 = BigInt(0);
|
|
11205
11665
|
let bestV3Fee = 0;
|
|
11206
|
-
let
|
|
11666
|
+
let bestV4Fee = 0;
|
|
11667
|
+
const commonFees = [100, 500, 3e3, 1e4];
|
|
11207
11668
|
const v2Router = this.source.config.getUniswapRouterV2Address(chain);
|
|
11208
11669
|
const v2Factory = this.source.config.getUniswapV2FactoryAddress(chain);
|
|
11209
11670
|
const v3Factory = this.source.config.getUniswapV3FactoryAddress(chain);
|
|
11210
11671
|
const v3Quoter = this.source.config.getUniswapV3QuoterAddress(chain);
|
|
11672
|
+
const v4Quoter = this.source.config.getUniswapV4QuoterAddress(chain);
|
|
11673
|
+
const wethAsset = this.source.config.getWrappedNativeAssetWithDecimals(chain).asset;
|
|
11674
|
+
const tokenInForQuote = tokenIn === ADDRESS_ZERO2 ? wethAsset : tokenIn;
|
|
11675
|
+
const tokenOutForQuote = tokenOut === ADDRESS_ZERO2 ? wethAsset : tokenOut;
|
|
11211
11676
|
try {
|
|
11212
11677
|
const v2PairExists = await destClient.readContract({
|
|
11213
11678
|
address: v2Factory,
|
|
11214
11679
|
abi: uniswapV2Factory_default.ABI,
|
|
11215
11680
|
functionName: "getPair",
|
|
11216
|
-
args: [
|
|
11681
|
+
args: [tokenInForQuote, tokenOutForQuote]
|
|
11217
11682
|
});
|
|
11218
11683
|
if (v2PairExists !== ADDRESS_ZERO2) {
|
|
11219
11684
|
const v2AmountOut = await destClient.readContract({
|
|
11220
11685
|
address: v2Router,
|
|
11221
11686
|
abi: uniswapRouterV2_default.ABI,
|
|
11222
11687
|
functionName: "getAmountsOut",
|
|
11223
|
-
args: [amountIn, [
|
|
11688
|
+
args: [amountIn, [tokenInForQuote, tokenOutForQuote]]
|
|
11224
11689
|
});
|
|
11225
11690
|
amountOutV2 = v2AmountOut[1];
|
|
11226
11691
|
}
|
|
@@ -11228,14 +11693,13 @@ var IntentGateway = class {
|
|
|
11228
11693
|
console.warn("V2 quote failed:", error);
|
|
11229
11694
|
}
|
|
11230
11695
|
let bestV3AmountOut = BigInt(0);
|
|
11231
|
-
const
|
|
11232
|
-
for (const fee of fees) {
|
|
11696
|
+
for (const fee of commonFees) {
|
|
11233
11697
|
try {
|
|
11234
11698
|
const pool = await destClient.readContract({
|
|
11235
11699
|
address: v3Factory,
|
|
11236
11700
|
abi: uniswapV3Factory_default.ABI,
|
|
11237
11701
|
functionName: "getPool",
|
|
11238
|
-
args: [
|
|
11702
|
+
args: [tokenInForQuote, tokenOutForQuote, fee]
|
|
11239
11703
|
});
|
|
11240
11704
|
if (pool !== ADDRESS_ZERO2) {
|
|
11241
11705
|
const liquidity = await destClient.readContract({
|
|
@@ -11244,25 +11708,24 @@ var IntentGateway = class {
|
|
|
11244
11708
|
functionName: "liquidity"
|
|
11245
11709
|
});
|
|
11246
11710
|
if (liquidity > BigInt(0)) {
|
|
11247
|
-
const quoteResult = await destClient.
|
|
11711
|
+
const quoteResult = (await destClient.simulateContract({
|
|
11248
11712
|
address: v3Quoter,
|
|
11249
11713
|
abi: uniswapV3Quoter_default.ABI,
|
|
11250
11714
|
functionName: "quoteExactInputSingle",
|
|
11251
11715
|
args: [
|
|
11252
11716
|
{
|
|
11253
|
-
tokenIn,
|
|
11254
|
-
tokenOut,
|
|
11717
|
+
tokenIn: tokenInForQuote,
|
|
11718
|
+
tokenOut: tokenOutForQuote,
|
|
11255
11719
|
fee,
|
|
11256
11720
|
amountIn,
|
|
11257
11721
|
sqrtPriceLimitX96: BigInt(0)
|
|
11258
11722
|
}
|
|
11259
11723
|
]
|
|
11260
|
-
});
|
|
11261
|
-
const
|
|
11724
|
+
})).result;
|
|
11725
|
+
const amountOut = quoteResult[0];
|
|
11262
11726
|
if (amountOut > bestV3AmountOut) {
|
|
11263
11727
|
bestV3AmountOut = amountOut;
|
|
11264
11728
|
bestV3Fee = fee;
|
|
11265
|
-
v3GasEstimate = gasEstimate;
|
|
11266
11729
|
}
|
|
11267
11730
|
}
|
|
11268
11731
|
}
|
|
@@ -11271,13 +11734,81 @@ var IntentGateway = class {
|
|
|
11271
11734
|
}
|
|
11272
11735
|
}
|
|
11273
11736
|
amountOutV3 = bestV3AmountOut;
|
|
11274
|
-
|
|
11275
|
-
|
|
11737
|
+
let bestV4AmountOut = BigInt(0);
|
|
11738
|
+
for (const fee of commonFees) {
|
|
11739
|
+
try {
|
|
11740
|
+
const currency0 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenIn : tokenOut;
|
|
11741
|
+
const currency1 = tokenIn.toLowerCase() < tokenOut.toLowerCase() ? tokenOut : tokenIn;
|
|
11742
|
+
const zeroForOne = tokenIn.toLowerCase() === currency0.toLowerCase();
|
|
11743
|
+
const poolKey = {
|
|
11744
|
+
currency0,
|
|
11745
|
+
currency1,
|
|
11746
|
+
fee,
|
|
11747
|
+
tickSpacing: this.getTickSpacing(fee),
|
|
11748
|
+
hooks: ADDRESS_ZERO2
|
|
11749
|
+
// No hooks
|
|
11750
|
+
};
|
|
11751
|
+
const quoteResult = (await destClient.simulateContract({
|
|
11752
|
+
address: v4Quoter,
|
|
11753
|
+
abi: UNISWAP_V4_QUOTER_ABI,
|
|
11754
|
+
functionName: "quoteExactInputSingle",
|
|
11755
|
+
args: [
|
|
11756
|
+
{
|
|
11757
|
+
poolKey,
|
|
11758
|
+
zeroForOne,
|
|
11759
|
+
exactAmount: amountIn,
|
|
11760
|
+
hookData: "0x"
|
|
11761
|
+
// Empty hook data
|
|
11762
|
+
}
|
|
11763
|
+
]
|
|
11764
|
+
})).result;
|
|
11765
|
+
const amountOut = quoteResult[0];
|
|
11766
|
+
if (amountOut > bestV4AmountOut) {
|
|
11767
|
+
bestV4AmountOut = amountOut;
|
|
11768
|
+
bestV4Fee = fee;
|
|
11769
|
+
}
|
|
11770
|
+
} catch (error) {
|
|
11771
|
+
console.warn(`V4 quote failed for fee ${fee}, continuing to next fee tier`);
|
|
11772
|
+
}
|
|
11276
11773
|
}
|
|
11277
|
-
|
|
11278
|
-
|
|
11774
|
+
amountOutV4 = bestV4AmountOut;
|
|
11775
|
+
if (amountOutV2 === BigInt(0) && amountOutV3 === BigInt(0) && amountOutV4 === BigInt(0)) {
|
|
11776
|
+
return {
|
|
11777
|
+
protocol: null,
|
|
11778
|
+
amountOut: BigInt(0)
|
|
11779
|
+
};
|
|
11780
|
+
}
|
|
11781
|
+
if (amountOutV4 !== BigInt(0)) {
|
|
11782
|
+
const thresholdBps = 100n;
|
|
11783
|
+
if (amountOutV3 !== BigInt(0) && this.isWithinThreshold(amountOutV4, amountOutV3, thresholdBps)) {
|
|
11784
|
+
return { protocol: "v4", amountOut: amountOutV4, fee: bestV4Fee };
|
|
11785
|
+
}
|
|
11786
|
+
if (amountOutV2 !== BigInt(0) && this.isWithinThreshold(amountOutV4, amountOutV2, thresholdBps)) {
|
|
11787
|
+
return { protocol: "v4", amountOut: amountOutV4, fee: bestV4Fee };
|
|
11788
|
+
}
|
|
11789
|
+
}
|
|
11790
|
+
const maxAmount = [
|
|
11791
|
+
{ protocol: "v2", amountOut: amountOutV2 },
|
|
11792
|
+
{ protocol: "v3", amountOut: amountOutV3, fee: bestV3Fee },
|
|
11793
|
+
{ protocol: "v4", amountOut: amountOutV4, fee: bestV4Fee }
|
|
11794
|
+
].reduce((best, current) => current.amountOut > best.amountOut ? current : best);
|
|
11795
|
+
if (maxAmount.protocol === "v2") {
|
|
11796
|
+
return {
|
|
11797
|
+
protocol: "v2",
|
|
11798
|
+
amountOut: amountOutV2
|
|
11799
|
+
};
|
|
11800
|
+
} else if (maxAmount.protocol === "v3") {
|
|
11801
|
+
return {
|
|
11802
|
+
protocol: "v3",
|
|
11803
|
+
amountOut: amountOutV3,
|
|
11804
|
+
fee: bestV3Fee
|
|
11805
|
+
};
|
|
11279
11806
|
} else {
|
|
11280
|
-
return {
|
|
11807
|
+
return {
|
|
11808
|
+
protocol: "v4",
|
|
11809
|
+
amountOut: amountOutV4,
|
|
11810
|
+
fee: bestV4Fee
|
|
11811
|
+
};
|
|
11281
11812
|
}
|
|
11282
11813
|
}
|
|
11283
11814
|
/**
|
|
@@ -11304,25 +11835,6 @@ var IntentGateway = class {
|
|
|
11304
11835
|
const gasCostInFeeToken = gasCostUsd / feeTokenPriceUsd;
|
|
11305
11836
|
return BigInt(Math.floor(gasCostInFeeToken * Math.pow(10, targetDecimals)));
|
|
11306
11837
|
}
|
|
11307
|
-
/**
|
|
11308
|
-
* Adjusts fee amounts between different decimal precisions.
|
|
11309
|
-
* Handles scaling up or down based on the decimal difference.
|
|
11310
|
-
*
|
|
11311
|
-
* @param feeInFeeToken - The fee amount to adjust
|
|
11312
|
-
* @param fromDecimals - The current decimal precision
|
|
11313
|
-
* @param toDecimals - The target decimal precision
|
|
11314
|
-
* @returns The adjusted fee amount with the target decimal precision
|
|
11315
|
-
*/
|
|
11316
|
-
adjustFeeDecimals(feeInFeeToken, fromDecimals, toDecimals) {
|
|
11317
|
-
if (fromDecimals === toDecimals) return feeInFeeToken;
|
|
11318
|
-
if (fromDecimals < toDecimals) {
|
|
11319
|
-
const scaleFactor = BigInt(10 ** (toDecimals - fromDecimals));
|
|
11320
|
-
return feeInFeeToken * scaleFactor;
|
|
11321
|
-
} else {
|
|
11322
|
-
const scaleFactor = BigInt(10 ** (fromDecimals - toDecimals));
|
|
11323
|
-
return (feeInFeeToken + scaleFactor - 1n) / scaleFactor;
|
|
11324
|
-
}
|
|
11325
|
-
}
|
|
11326
11838
|
/**
|
|
11327
11839
|
* Checks if an order has been filled by verifying the commitment status on-chain.
|
|
11328
11840
|
* Reads the storage slot corresponding to the order's commitment hash.
|
|
@@ -11344,6 +11856,36 @@ var IntentGateway = class {
|
|
|
11344
11856
|
});
|
|
11345
11857
|
return filledStatus !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
11346
11858
|
}
|
|
11859
|
+
/**
|
|
11860
|
+
* Returns the tick spacing for a given fee tier in Uniswap V4
|
|
11861
|
+
* @param fee - The fee tier in basis points
|
|
11862
|
+
* @returns The tick spacing value
|
|
11863
|
+
*/
|
|
11864
|
+
getTickSpacing(fee) {
|
|
11865
|
+
switch (fee) {
|
|
11866
|
+
case 100:
|
|
11867
|
+
return 1;
|
|
11868
|
+
case 500:
|
|
11869
|
+
return 10;
|
|
11870
|
+
case 3e3:
|
|
11871
|
+
return 60;
|
|
11872
|
+
case 1e4:
|
|
11873
|
+
return 200;
|
|
11874
|
+
default:
|
|
11875
|
+
return 60;
|
|
11876
|
+
}
|
|
11877
|
+
}
|
|
11878
|
+
/**
|
|
11879
|
+
* Returns true if candidate <= reference * (1 + thresholdBps/10000)
|
|
11880
|
+
* @param candidate - The candidate amount to compare
|
|
11881
|
+
* @param reference - The reference amount
|
|
11882
|
+
* @param thresholdBps - The threshold in basis points
|
|
11883
|
+
* @returns True if candidate is within threshold of reference
|
|
11884
|
+
*/
|
|
11885
|
+
isWithinThreshold(candidate, reference, thresholdBps) {
|
|
11886
|
+
const basisPoints = 10000n;
|
|
11887
|
+
return candidate * basisPoints <= reference * (basisPoints + thresholdBps);
|
|
11888
|
+
}
|
|
11347
11889
|
};
|
|
11348
11890
|
function transformOrderForContract(order) {
|
|
11349
11891
|
return {
|
|
@@ -11657,6 +12199,6 @@ async function teleportDot(param_) {
|
|
|
11657
12199
|
return stream;
|
|
11658
12200
|
}
|
|
11659
12201
|
|
|
11660
|
-
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 };
|
|
12202
|
+
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 };
|
|
11661
12203
|
//# sourceMappingURL=index.js.map
|
|
11662
12204
|
//# sourceMappingURL=index.js.map
|