@hyperbridge/sdk 2.3.3 → 2.4.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 +151 -33
- package/dist/browser/index.js +402 -117
- package/dist/browser/index.js.map +1 -1
- package/dist/node/{IntentGatewayV2-SB851bZs.d.cts → IntentGatewayV2-PzbhFn_7.d.cts} +39 -1
- package/dist/node/{IntentGatewayV2-SB851bZs.d.ts → IntentGatewayV2-PzbhFn_7.d.ts} +39 -1
- package/dist/node/index.cjs +403 -116
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +115 -35
- package/dist/node/index.d.ts +115 -35
- package/dist/node/index.js +402 -117
- package/dist/node/index.js.map +1 -1
- package/dist/node/intents-helpers.cjs.map +1 -1
- package/dist/node/intents-helpers.d.cts +1 -1
- package/dist/node/intents-helpers.d.ts +1 -1
- package/dist/node/intents-helpers.js.map +1 -1
- package/package.json +1 -1
package/dist/node/index.js
CHANGED
|
@@ -2479,30 +2479,30 @@ var handlerV2_default = { ABI: ABI2 };
|
|
|
2479
2479
|
function tronAddress(base58) {
|
|
2480
2480
|
return `0x${TronWeb.address.toHex(base58).slice(2)}`;
|
|
2481
2481
|
}
|
|
2482
|
-
var Chains = /* @__PURE__ */ ((
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
return
|
|
2482
|
+
var Chains = /* @__PURE__ */ ((Chains2) => {
|
|
2483
|
+
Chains2["BSC_CHAPEL"] = "EVM-97";
|
|
2484
|
+
Chains2["GNOSIS_CHIADO"] = "EVM-10200";
|
|
2485
|
+
Chains2["HYPERBRIDGE_GARGANTUA"] = "KUSAMA-4009";
|
|
2486
|
+
Chains2["SEPOLIA"] = "EVM-11155111";
|
|
2487
|
+
Chains2["MAINNET"] = "EVM-1";
|
|
2488
|
+
Chains2["BSC_MAINNET"] = "EVM-56";
|
|
2489
|
+
Chains2["ARBITRUM_MAINNET"] = "EVM-42161";
|
|
2490
|
+
Chains2["ARBITRUM_SEPOLIA"] = "EVM-421614";
|
|
2491
|
+
Chains2["BASE_MAINNET"] = "EVM-8453";
|
|
2492
|
+
Chains2["BASE_SEPOLIA"] = "EVM-84532";
|
|
2493
|
+
Chains2["OPTIMISM_MAINNET"] = "EVM-10";
|
|
2494
|
+
Chains2["OPTIMISM_SEPOLIA"] = "EVM-11155420";
|
|
2495
|
+
Chains2["GNOSIS_MAINNET"] = "EVM-100";
|
|
2496
|
+
Chains2["SONEIUM_MAINNET"] = "EVM-1868";
|
|
2497
|
+
Chains2["POLYGON_MAINNET"] = "EVM-137";
|
|
2498
|
+
Chains2["POLKADOT_HUB_MAINNET"] = "EVM-420420419";
|
|
2499
|
+
Chains2["POLYGON_AMOY"] = "EVM-80002";
|
|
2500
|
+
Chains2["POLKADOT_ASSET_HUB_PASEO"] = "EVM-420420417";
|
|
2501
|
+
Chains2["TRON_MAINNET"] = "EVM-728126428";
|
|
2502
|
+
Chains2["TRON_NILE"] = "EVM-3448148188";
|
|
2503
|
+
Chains2["PHAROS_MAINNET"] = "EVM-688600";
|
|
2504
|
+
Chains2["PHAROS_ATLANTIC"] = "EVM-688689";
|
|
2505
|
+
return Chains2;
|
|
2506
2506
|
})(Chains || {});
|
|
2507
2507
|
var polkadotAssetHubPaseo = defineChain({
|
|
2508
2508
|
id: 420420417,
|
|
@@ -2585,7 +2585,7 @@ var chainConfigs = {
|
|
|
2585
2585
|
UniswapV3Quoter: "0x0000000000000000000000000000000000000000",
|
|
2586
2586
|
UniswapV4Quoter: "0x0000000000000000000000000000000000000000",
|
|
2587
2587
|
EntryPointV08: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108",
|
|
2588
|
-
SolverAccount: "
|
|
2588
|
+
SolverAccount: "0x110C7E1814c923127469Ca8939a12dAa70B96a17"
|
|
2589
2589
|
},
|
|
2590
2590
|
rpcEnvKey: "BSC_CHAPEL",
|
|
2591
2591
|
defaultRpcUrl: "https://bnb-testnet.api.onfinality.io/public",
|
|
@@ -2693,7 +2693,7 @@ var chainConfigs = {
|
|
|
2693
2693
|
},
|
|
2694
2694
|
addresses: {
|
|
2695
2695
|
IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
|
|
2696
|
-
SolverAccount: "
|
|
2696
|
+
SolverAccount: "0xfCd233b937D7622AAc63ced3C9A1A12F4a6B64E3",
|
|
2697
2697
|
TokenGateway: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
|
|
2698
2698
|
Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
|
|
2699
2699
|
UniswapRouter02: "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
|
|
@@ -2748,7 +2748,7 @@ var chainConfigs = {
|
|
|
2748
2748
|
},
|
|
2749
2749
|
addresses: {
|
|
2750
2750
|
IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
|
|
2751
|
-
SolverAccount: "
|
|
2751
|
+
SolverAccount: "0xfCd233b937D7622AAc63ced3C9A1A12F4a6B64E3",
|
|
2752
2752
|
TokenGateway: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
|
|
2753
2753
|
Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
|
|
2754
2754
|
UniswapRouter02: "0x10ED43C718714eb63d5aA57B78B54704E256024E",
|
|
@@ -2804,7 +2804,7 @@ var chainConfigs = {
|
|
|
2804
2804
|
},
|
|
2805
2805
|
addresses: {
|
|
2806
2806
|
IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
|
|
2807
|
-
SolverAccount: "
|
|
2807
|
+
SolverAccount: "0xfCd233b937D7622AAc63ced3C9A1A12F4a6B64E3",
|
|
2808
2808
|
TokenGateway: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
|
|
2809
2809
|
Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
|
|
2810
2810
|
UniswapRouter02: "0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24",
|
|
@@ -2861,7 +2861,7 @@ var chainConfigs = {
|
|
|
2861
2861
|
},
|
|
2862
2862
|
addresses: {
|
|
2863
2863
|
IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
|
|
2864
|
-
SolverAccount: "
|
|
2864
|
+
SolverAccount: "0xfCd233b937D7622AAc63ced3C9A1A12F4a6B64E3",
|
|
2865
2865
|
TokenGateway: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
|
|
2866
2866
|
Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
|
|
2867
2867
|
UniswapRouter02: "0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24",
|
|
@@ -2920,7 +2920,7 @@ var chainConfigs = {
|
|
|
2920
2920
|
},
|
|
2921
2921
|
addresses: {
|
|
2922
2922
|
IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
|
|
2923
|
-
SolverAccount: "
|
|
2923
|
+
SolverAccount: "0xfCd233b937D7622AAc63ced3C9A1A12F4a6B64E3",
|
|
2924
2924
|
TokenGateway: "0x8b536105b6Fae2aE9199f5146D3C57Dfe53b614E",
|
|
2925
2925
|
Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
|
|
2926
2926
|
UniswapRouter02: "0xd2f9496824951D5237cC71245D659E48d0d5f9E8",
|
|
@@ -3007,7 +3007,7 @@ var chainConfigs = {
|
|
|
3007
3007
|
Calldispatcher: "0x876F1891982E260026630c233A4897160A281Fb8",
|
|
3008
3008
|
Permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
|
|
3009
3009
|
EntryPointV08: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108",
|
|
3010
|
-
SolverAccount: "
|
|
3010
|
+
SolverAccount: "0x110C7E1814c923127469Ca8939a12dAa70B96a17"
|
|
3011
3011
|
},
|
|
3012
3012
|
rpcEnvKey: "POLYGON_AMOY",
|
|
3013
3013
|
defaultRpcUrl: "https://rpc-amoy.polygon.technology",
|
|
@@ -3031,7 +3031,7 @@ var chainConfigs = {
|
|
|
3031
3031
|
},
|
|
3032
3032
|
addresses: {
|
|
3033
3033
|
IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
|
|
3034
|
-
SolverAccount: "
|
|
3034
|
+
SolverAccount: "0xfCd233b937D7622AAc63ced3C9A1A12F4a6B64E3",
|
|
3035
3035
|
TokenGateway: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
|
|
3036
3036
|
Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
|
|
3037
3037
|
UniswapRouter02: "0x4A7b5Da61326A6379179b40d00F57E5bbDC962c2",
|
|
@@ -3066,7 +3066,7 @@ var chainConfigs = {
|
|
|
3066
3066
|
},
|
|
3067
3067
|
addresses: {
|
|
3068
3068
|
IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
|
|
3069
|
-
SolverAccount: "
|
|
3069
|
+
SolverAccount: "0xfCd233b937D7622AAc63ced3C9A1A12F4a6B64E3",
|
|
3070
3070
|
TokenGateway: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
|
|
3071
3071
|
Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
|
|
3072
3072
|
UniswapRouter02: "0xB2e26652e4BAd1e56055A051f922E06760cA0BFE",
|
|
@@ -3221,7 +3221,7 @@ var chainConfigs = {
|
|
|
3221
3221
|
},
|
|
3222
3222
|
addresses: {
|
|
3223
3223
|
IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
|
|
3224
|
-
SolverAccount: "
|
|
3224
|
+
SolverAccount: "0xfCd233b937D7622AAc63ced3C9A1A12F4a6B64E3",
|
|
3225
3225
|
Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
|
|
3226
3226
|
Calldispatcher: "0xE2C7e576E26E0bE7aC97c6fE925bcDAbD87c4bEd"
|
|
3227
3227
|
},
|
|
@@ -5107,6 +5107,24 @@ var ChainConfigService = class {
|
|
|
5107
5107
|
getAssetAddress(chain, symbol) {
|
|
5108
5108
|
return this.getConfig(chain)?.assets?.[symbol];
|
|
5109
5109
|
}
|
|
5110
|
+
/**
|
|
5111
|
+
* Resolves configured token metadata from an address on a specific chain.
|
|
5112
|
+
* This is used by SDK helpers that accept token addresses rather than caller-
|
|
5113
|
+
* supplied symbols or decimals.
|
|
5114
|
+
*/
|
|
5115
|
+
getAssetMetadataByAddress(chain, address) {
|
|
5116
|
+
const config = this.getConfig(chain);
|
|
5117
|
+
if (!config?.assets) return;
|
|
5118
|
+
const normalizedAddress = address.toLowerCase();
|
|
5119
|
+
for (const [symbol, configuredAddress] of Object.entries(config.assets)) {
|
|
5120
|
+
if (configuredAddress.toLowerCase() !== normalizedAddress) continue;
|
|
5121
|
+
return {
|
|
5122
|
+
symbol,
|
|
5123
|
+
address: configuredAddress,
|
|
5124
|
+
decimals: config.tokenDecimals?.[symbol]
|
|
5125
|
+
};
|
|
5126
|
+
}
|
|
5127
|
+
}
|
|
5110
5128
|
getUsdtAsset(chain) {
|
|
5111
5129
|
return this.getConfig(chain)?.assets?.USDT ?? "0x";
|
|
5112
5130
|
}
|
|
@@ -7780,7 +7798,7 @@ var IntentsCoprocessor = class _IntentsCoprocessor {
|
|
|
7780
7798
|
*/
|
|
7781
7799
|
async sendExtrinsicWithRetries(extrinsic, maxRetries, timeoutMs) {
|
|
7782
7800
|
const keyPair = this.getKeyPair();
|
|
7783
|
-
|
|
7801
|
+
const baseTip = 1000000000n;
|
|
7784
7802
|
let attempt = 0;
|
|
7785
7803
|
while (attempt < maxRetries) {
|
|
7786
7804
|
const currentTip = baseTip * BigInt(2 ** attempt);
|
|
@@ -11450,6 +11468,33 @@ query OrderStatus($commitment: String!) {
|
|
|
11450
11468
|
}
|
|
11451
11469
|
}
|
|
11452
11470
|
}`;
|
|
11471
|
+
var LATEST_PHANTOM_ORDER_PRICE_SNAPSHOT = `
|
|
11472
|
+
query LatestPhantomOrderPriceSnapshot($tokenA: String!, $tokenB: String!) {
|
|
11473
|
+
phantomOrderPriceSnapshots(
|
|
11474
|
+
filter: {
|
|
11475
|
+
and: [
|
|
11476
|
+
{ tokenA: { equalTo: $tokenA } }
|
|
11477
|
+
{ tokenB: { equalTo: $tokenB } }
|
|
11478
|
+
{ medianPrice: { isNull: false } }
|
|
11479
|
+
]
|
|
11480
|
+
}
|
|
11481
|
+
orderBy: BLOCK_NUMBER_DESC
|
|
11482
|
+
first: 1
|
|
11483
|
+
) {
|
|
11484
|
+
nodes {
|
|
11485
|
+
commitment
|
|
11486
|
+
tokenA
|
|
11487
|
+
tokenB
|
|
11488
|
+
standardAmount
|
|
11489
|
+
blockNumber
|
|
11490
|
+
medianPrice
|
|
11491
|
+
lowestPrice
|
|
11492
|
+
highestPrice
|
|
11493
|
+
bidCount
|
|
11494
|
+
snapshotTime
|
|
11495
|
+
}
|
|
11496
|
+
}
|
|
11497
|
+
}`;
|
|
11453
11498
|
var TOKEN_GATEWAY_ASSET_TELEPORTED_STATUS = `
|
|
11454
11499
|
query TokenGatewayAssetTeleportedStatus($commitment: String!) {
|
|
11455
11500
|
tokenGatewayAssetTeleportedV2s(
|
|
@@ -11511,6 +11556,29 @@ async function queryAssetTeleported(params) {
|
|
|
11511
11556
|
function queryGetRequest(params) {
|
|
11512
11557
|
return _queryGetRequestInternal(params);
|
|
11513
11558
|
}
|
|
11559
|
+
async function _queryLatestPhantomOrderPriceSnapshot(params) {
|
|
11560
|
+
const response = await params.queryClient.request(
|
|
11561
|
+
LATEST_PHANTOM_ORDER_PRICE_SNAPSHOT,
|
|
11562
|
+
{
|
|
11563
|
+
tokenA: params.tokenA.toLowerCase(),
|
|
11564
|
+
tokenB: params.tokenB.toLowerCase()
|
|
11565
|
+
}
|
|
11566
|
+
);
|
|
11567
|
+
const snapshot = response.phantomOrderPriceSnapshots.nodes[0];
|
|
11568
|
+
if (!snapshot?.medianPrice) return;
|
|
11569
|
+
return {
|
|
11570
|
+
commitment: snapshot.commitment,
|
|
11571
|
+
tokenA: snapshot.tokenA,
|
|
11572
|
+
tokenB: snapshot.tokenB,
|
|
11573
|
+
standardAmount: BigInt(snapshot.standardAmount),
|
|
11574
|
+
blockNumber: BigInt(snapshot.blockNumber),
|
|
11575
|
+
medianPrice: BigInt(snapshot.medianPrice),
|
|
11576
|
+
lowestPrice: snapshot.lowestPrice === null ? void 0 : BigInt(snapshot.lowestPrice),
|
|
11577
|
+
highestPrice: snapshot.highestPrice === null ? void 0 : BigInt(snapshot.highestPrice),
|
|
11578
|
+
bidCount: snapshot.bidCount,
|
|
11579
|
+
snapshotTime: new Date(snapshot.snapshotTime)
|
|
11580
|
+
};
|
|
11581
|
+
}
|
|
11514
11582
|
async function _queryTokenGatewayAssetTeleportedInternal(params) {
|
|
11515
11583
|
const { commitmentHash, queryClient: client, logger = DEFAULT_LOGGER } = params;
|
|
11516
11584
|
const response = await retryPromise(
|
|
@@ -14763,6 +14831,67 @@ var CryptoUtils = class _CryptoUtils {
|
|
|
14763
14831
|
encodePacked(["bytes1", "bytes1", "bytes32", "bytes32"], ["0x19", "0x01", domainSeparator, structHash])
|
|
14764
14832
|
);
|
|
14765
14833
|
}
|
|
14834
|
+
/**
|
|
14835
|
+
* Derives the ERC-4337 nonce key that binds a bid UserOperation to its
|
|
14836
|
+
* order and session key: the lower 192 bits of
|
|
14837
|
+
* `keccak256(commitment ‖ sessionKey)`. `SolverAccount` rejects bid
|
|
14838
|
+
* operations whose nonce key differs — this is what lets the solver sign
|
|
14839
|
+
* the plain userOpHash while staying committed to the order and to the
|
|
14840
|
+
* session key it bid against.
|
|
14841
|
+
*
|
|
14842
|
+
* @param commitment - The order commitment (`order.id`).
|
|
14843
|
+
* @param sessionKey - The order's session key address (`order.session`).
|
|
14844
|
+
* @returns The 192-bit nonce key as a bigint (pass to `EntryPoint.getNonce`).
|
|
14845
|
+
*/
|
|
14846
|
+
static bidNonceKey(commitment, sessionKey) {
|
|
14847
|
+
return BigInt(keccak256(encodePacked(["bytes32", "address"], [commitment, sessionKey]))) & (1n << 192n) - 1n;
|
|
14848
|
+
}
|
|
14849
|
+
/**
|
|
14850
|
+
* Builds the EIP-712 typed-data payload whose digest is the EntryPoint v0.8
|
|
14851
|
+
* `userOpHash` (i.e. `hashTypedData(packedUserOpTypedData(...)) ===
|
|
14852
|
+
* computeUserOpHash(...)`). Signing this typed data is bit-identical to
|
|
14853
|
+
* signing the raw userOpHash, but keeps the full operation visible to
|
|
14854
|
+
* signing infrastructure (hardware wallets, MPC/TEE policy engines) instead
|
|
14855
|
+
* of an opaque 32-byte digest.
|
|
14856
|
+
*
|
|
14857
|
+
* @param userOp - The packed UserOperation to sign (signature field ignored).
|
|
14858
|
+
* @param entryPoint - Address of the EntryPoint v0.8 contract.
|
|
14859
|
+
* @param chainId - Chain ID of the network on which the operation will execute.
|
|
14860
|
+
* @returns A viem `TypedDataDefinition` for the operation.
|
|
14861
|
+
*/
|
|
14862
|
+
static packedUserOpTypedData(userOp, entryPoint, chainId) {
|
|
14863
|
+
return {
|
|
14864
|
+
domain: {
|
|
14865
|
+
name: "ERC4337",
|
|
14866
|
+
version: "1",
|
|
14867
|
+
chainId,
|
|
14868
|
+
verifyingContract: entryPoint
|
|
14869
|
+
},
|
|
14870
|
+
types: {
|
|
14871
|
+
PackedUserOperation: [
|
|
14872
|
+
{ name: "sender", type: "address" },
|
|
14873
|
+
{ name: "nonce", type: "uint256" },
|
|
14874
|
+
{ name: "initCode", type: "bytes" },
|
|
14875
|
+
{ name: "callData", type: "bytes" },
|
|
14876
|
+
{ name: "accountGasLimits", type: "bytes32" },
|
|
14877
|
+
{ name: "preVerificationGas", type: "uint256" },
|
|
14878
|
+
{ name: "gasFees", type: "bytes32" },
|
|
14879
|
+
{ name: "paymasterAndData", type: "bytes" }
|
|
14880
|
+
]
|
|
14881
|
+
},
|
|
14882
|
+
primaryType: "PackedUserOperation",
|
|
14883
|
+
message: {
|
|
14884
|
+
sender: userOp.sender,
|
|
14885
|
+
nonce: userOp.nonce,
|
|
14886
|
+
initCode: userOp.initCode,
|
|
14887
|
+
callData: userOp.callData,
|
|
14888
|
+
accountGasLimits: userOp.accountGasLimits,
|
|
14889
|
+
preVerificationGas: userOp.preVerificationGas,
|
|
14890
|
+
gasFees: userOp.gasFees,
|
|
14891
|
+
paymasterAndData: userOp.paymasterAndData
|
|
14892
|
+
}
|
|
14893
|
+
};
|
|
14894
|
+
}
|
|
14766
14895
|
/**
|
|
14767
14896
|
* Computes the EIP-712 struct hash of a `PackedUserOperation`.
|
|
14768
14897
|
*
|
|
@@ -16271,9 +16400,12 @@ var BidManager = class {
|
|
|
16271
16400
|
* Constructs a signed `PackedUserOperation` that a solver can submit to the
|
|
16272
16401
|
* Hyperbridge coprocessor as a bid to fill an order.
|
|
16273
16402
|
*
|
|
16274
|
-
* The solver
|
|
16275
|
-
*
|
|
16276
|
-
*
|
|
16403
|
+
* The solver signs the operation as EntryPoint v0.8 EIP-712 typed data,
|
|
16404
|
+
* whose digest is the plain userOpHash. The binding to the order lives in
|
|
16405
|
+
* the operation itself: the 4337 nonce key must be the lower 192 bits of
|
|
16406
|
+
* the order commitment (`SolverAccount` enforces this during validation),
|
|
16407
|
+
* and the callData carries the order. This keeps the signed payload fully
|
|
16408
|
+
* transparent to signing infrastructure instead of an opaque digest.
|
|
16277
16409
|
*
|
|
16278
16410
|
* @param options - Parameters describing the solver account, gas limits, fee
|
|
16279
16411
|
* market values, and pre-built `callData` for the fill operation.
|
|
@@ -16311,10 +16443,17 @@ var BidManager = class {
|
|
|
16311
16443
|
paymasterAndData,
|
|
16312
16444
|
signature: "0x"
|
|
16313
16445
|
};
|
|
16314
|
-
const
|
|
16315
|
-
const
|
|
16316
|
-
|
|
16317
|
-
|
|
16446
|
+
const nonceKey = BigInt(nonce) >> 64n;
|
|
16447
|
+
const expectedKey = CryptoUtils.bidNonceKey(order.id, order.session);
|
|
16448
|
+
if (nonceKey !== expectedKey) {
|
|
16449
|
+
console.warn(
|
|
16450
|
+
`[BidManager] bid nonce key does not bind the order commitment and session key; on-chain validation will fail (order=${order.id})`
|
|
16451
|
+
);
|
|
16452
|
+
}
|
|
16453
|
+
const solverSignature = await solverSigner.signTypedData(
|
|
16454
|
+
CryptoUtils.packedUserOpTypedData(userOp, entryPointAddress, chainId),
|
|
16455
|
+
Number(chainId)
|
|
16456
|
+
);
|
|
16318
16457
|
const signature = concat([order.id, solverSignature]);
|
|
16319
16458
|
return { ...userOp, signature };
|
|
16320
16459
|
}
|
|
@@ -17239,15 +17378,67 @@ var UnsupportedIntentQuoteStrategyError = class extends Error {
|
|
|
17239
17378
|
var UnsupportedIntentQuotePairError = class extends Error {
|
|
17240
17379
|
constructor(params) {
|
|
17241
17380
|
super(
|
|
17242
|
-
`No Uniswap v4 pool config found for ${params.tokenIn
|
|
17381
|
+
`No ${params.quoteSource ?? "Uniswap v4 pool config"} found for ${params.tokenIn} -> ${params.tokenOut} on ${params.source} -> ${params.destination}`
|
|
17243
17382
|
);
|
|
17244
17383
|
this.name = "UnsupportedIntentQuotePairError";
|
|
17245
17384
|
}
|
|
17246
17385
|
};
|
|
17386
|
+
var PhantomSnapshotUnavailableError = class extends Error {
|
|
17387
|
+
constructor(tokenA, tokenB) {
|
|
17388
|
+
super(`No Phantom order price snapshot found for ${tokenA} -> ${tokenB}`);
|
|
17389
|
+
this.name = "PhantomSnapshotUnavailableError";
|
|
17390
|
+
}
|
|
17391
|
+
};
|
|
17392
|
+
var InvalidPhantomSnapshotError = class extends Error {
|
|
17393
|
+
constructor(commitment, reason) {
|
|
17394
|
+
super(`Invalid Phantom order price snapshot ${commitment}: ${reason}`);
|
|
17395
|
+
this.name = "InvalidPhantomSnapshotError";
|
|
17396
|
+
}
|
|
17397
|
+
};
|
|
17398
|
+
var BPS_DENOMINATOR = 10000n;
|
|
17399
|
+
function validateQuoteParams(params) {
|
|
17400
|
+
const hasAmountIn = params.amountIn !== void 0;
|
|
17401
|
+
const hasAmountOut = params.amountOut !== void 0;
|
|
17402
|
+
if (hasAmountIn === hasAmountOut) throw new Error("Provide exactly one of amountIn or amountOut");
|
|
17403
|
+
if (params.amountIn !== void 0 && params.amountIn <= 0n) throw new Error("amountIn must be greater than zero");
|
|
17404
|
+
if (params.amountOut !== void 0 && params.amountOut <= 0n) throw new Error("amountOut must be greater than zero");
|
|
17405
|
+
if (params.tokenIn.toLowerCase() === params.tokenOut.toLowerCase()) {
|
|
17406
|
+
throw new Error("tokenIn and tokenOut cannot be the same");
|
|
17407
|
+
}
|
|
17408
|
+
}
|
|
17409
|
+
async function readProtocolFeeBps(chainConfigService, source) {
|
|
17410
|
+
const gatewayAddress = chainConfigService.getIntentGatewayAddress(source.stateMachineId);
|
|
17411
|
+
if (!gatewayAddress || gatewayAddress === "0x" || gatewayAddress === zeroAddress) {
|
|
17412
|
+
throw new Error(`IntentGatewayV2 is not configured for chain ${source.stateMachineId}`);
|
|
17413
|
+
}
|
|
17414
|
+
const gatewayParams = await source.client.readContract({
|
|
17415
|
+
address: gatewayAddress,
|
|
17416
|
+
abi: IntentGatewayV2_default.ABI,
|
|
17417
|
+
functionName: "params"
|
|
17418
|
+
});
|
|
17419
|
+
const protocolFeeBps = Array.isArray(gatewayParams) ? BigInt(gatewayParams[4]) : BigInt(gatewayParams.protocolFeeBps ?? 0);
|
|
17420
|
+
if (protocolFeeBps < 0n || protocolFeeBps >= BPS_DENOMINATOR) {
|
|
17421
|
+
throw new Error(`Invalid IntentGateway protocol fee: ${protocolFeeBps} bps`);
|
|
17422
|
+
}
|
|
17423
|
+
return protocolFeeBps;
|
|
17424
|
+
}
|
|
17425
|
+
function deductProtocolFee(amount, protocolFeeBps) {
|
|
17426
|
+
if (protocolFeeBps <= 0n) return amount;
|
|
17427
|
+
const fee = amount * protocolFeeBps / BPS_DENOMINATOR;
|
|
17428
|
+
return amount - fee;
|
|
17429
|
+
}
|
|
17430
|
+
function grossUpForProtocolFee(netAmount, protocolFeeBps) {
|
|
17431
|
+
if (protocolFeeBps <= 0n) return netAmount;
|
|
17432
|
+
if (protocolFeeBps >= BPS_DENOMINATOR) throw new Error("protocolFeeBps must be less than 10,000");
|
|
17433
|
+
return divCeil(netAmount * BPS_DENOMINATOR, BPS_DENOMINATOR - protocolFeeBps);
|
|
17434
|
+
}
|
|
17435
|
+
function divCeil(numerator, denominator) {
|
|
17436
|
+
if (denominator <= 0n) throw new Error("denominator must be greater than zero");
|
|
17437
|
+
return (numerator + denominator - 1n) / denominator;
|
|
17438
|
+
}
|
|
17247
17439
|
|
|
17248
17440
|
// src/protocols/intents/quote/uniswapV4.ts
|
|
17249
17441
|
var UNISWAP_INTENT_QUOTE_CHAIN = "EVM-8453" /* BASE_MAINNET */;
|
|
17250
|
-
var BPS_DENOMINATOR = 10000n;
|
|
17251
17442
|
var UniswapV4IntentQuoteStrategy = class {
|
|
17252
17443
|
constructor(chainConfigService) {
|
|
17253
17444
|
this.chainConfigService = chainConfigService;
|
|
@@ -17255,10 +17446,10 @@ var UniswapV4IntentQuoteStrategy = class {
|
|
|
17255
17446
|
chainConfigService;
|
|
17256
17447
|
baseQuoteClient;
|
|
17257
17448
|
async quote(params, source, destination) {
|
|
17258
|
-
|
|
17259
|
-
const protocolFeeBps = await
|
|
17449
|
+
validateQuoteParams(params);
|
|
17450
|
+
const protocolFeeBps = await readProtocolFeeBps(this.chainConfigService, source);
|
|
17260
17451
|
const quoteClient = this.resolveQuoteClient(source, destination);
|
|
17261
|
-
const poolConfig = this.resolvePoolConfig(params, source.stateMachineId,
|
|
17452
|
+
const poolConfig = this.resolvePoolConfig(params, source.stateMachineId, destination.stateMachineId);
|
|
17262
17453
|
return params.amountIn !== void 0 ? this.quoteExactInput({ params, client: quoteClient, protocolFeeBps, poolConfig }) : this.quoteExactOutput({ params, client: quoteClient, protocolFeeBps, poolConfig });
|
|
17263
17454
|
}
|
|
17264
17455
|
resolveQuoteClient(source, destination) {
|
|
@@ -17274,34 +17465,11 @@ var UniswapV4IntentQuoteStrategy = class {
|
|
|
17274
17465
|
this.baseQuoteClient = baseQuoteClient;
|
|
17275
17466
|
return baseQuoteClient;
|
|
17276
17467
|
}
|
|
17277
|
-
validateQuoteParams(params) {
|
|
17278
|
-
const hasAmountIn = params.amountIn !== void 0;
|
|
17279
|
-
const hasAmountOut = params.amountOut !== void 0;
|
|
17280
|
-
if (hasAmountIn === hasAmountOut) throw new Error("Provide exactly one of amountIn or amountOut");
|
|
17281
|
-
if (hasAmountIn && params.amountIn <= 0n) throw new Error("amountIn must be greater than zero");
|
|
17282
|
-
if (hasAmountOut && params.amountOut <= 0n) throw new Error("amountOut must be greater than zero");
|
|
17283
|
-
if (params.tokenIn.address.toLowerCase() === params.tokenOut.address.toLowerCase()) {
|
|
17284
|
-
throw new Error("tokenIn and tokenOut cannot be the same");
|
|
17285
|
-
}
|
|
17286
|
-
}
|
|
17287
|
-
async readProtocolFeeBps(client, chain) {
|
|
17288
|
-
const gatewayAddress = this.chainConfigService.getIntentGatewayAddress(chain);
|
|
17289
|
-
if (!gatewayAddress || gatewayAddress === "0x" || gatewayAddress === zeroAddress) {
|
|
17290
|
-
throw new Error(`IntentGatewayV2 is not configured for chain ${chain}`);
|
|
17291
|
-
}
|
|
17292
|
-
const gatewayParams = await client.readContract({
|
|
17293
|
-
address: gatewayAddress,
|
|
17294
|
-
abi: IntentGatewayV2_default.ABI,
|
|
17295
|
-
functionName: "params"
|
|
17296
|
-
});
|
|
17297
|
-
if (isGatewayParamsTuple(gatewayParams)) return BigInt(gatewayParams[4]);
|
|
17298
|
-
return BigInt(gatewayParams.protocolFeeBps ?? 0);
|
|
17299
|
-
}
|
|
17300
17468
|
resolvePoolConfig(params, source, destination) {
|
|
17301
17469
|
const override = params.uniswapV4?.poolKey;
|
|
17302
17470
|
if (override) {
|
|
17303
17471
|
const poolKey = normalizePoolKey(override);
|
|
17304
|
-
const tokenInForQuote = getAddress(override.currencyIn ?? params.tokenIn
|
|
17472
|
+
const tokenInForQuote = getAddress(override.currencyIn ?? params.tokenIn);
|
|
17305
17473
|
if (tokenInForQuote !== poolKey.currency0 && tokenInForQuote !== poolKey.currency1) {
|
|
17306
17474
|
throw new Error(
|
|
17307
17475
|
`Input currency ${tokenInForQuote} is not part of the override pool (${poolKey.currency0}, ${poolKey.currency1}). For cross-chain quotes pass uniswapV4.poolKey.currencyIn with the Base-side input currency address.`
|
|
@@ -17309,11 +17477,11 @@ var UniswapV4IntentQuoteStrategy = class {
|
|
|
17309
17477
|
}
|
|
17310
17478
|
return {
|
|
17311
17479
|
poolKey,
|
|
17312
|
-
quoterAddress: this.resolveQuoterAddress(
|
|
17480
|
+
quoterAddress: this.resolveQuoterAddress(UNISWAP_INTENT_QUOTE_CHAIN, override.quoterAddress),
|
|
17313
17481
|
tokenInForQuote
|
|
17314
17482
|
};
|
|
17315
17483
|
}
|
|
17316
|
-
const poolConfig = this.resolveConfiguredPool(params, destination);
|
|
17484
|
+
const poolConfig = this.resolveConfiguredPool(params, source, destination, UNISWAP_INTENT_QUOTE_CHAIN);
|
|
17317
17485
|
if (poolConfig) return poolConfig;
|
|
17318
17486
|
throw new UnsupportedIntentQuotePairError({
|
|
17319
17487
|
source,
|
|
@@ -17322,12 +17490,12 @@ var UniswapV4IntentQuoteStrategy = class {
|
|
|
17322
17490
|
tokenOut: params.tokenOut
|
|
17323
17491
|
});
|
|
17324
17492
|
}
|
|
17325
|
-
resolveConfiguredPool(params,
|
|
17326
|
-
for (const pool of this.chainConfigService.getUniswapV4PoolConfigs(
|
|
17327
|
-
const resolvedPool = this.resolveConfiguredPoolTokens(
|
|
17493
|
+
resolveConfiguredPool(params, sourceChain, destinationChain, quoteChain) {
|
|
17494
|
+
for (const pool of this.chainConfigService.getUniswapV4PoolConfigs(quoteChain)) {
|
|
17495
|
+
const resolvedPool = this.resolveConfiguredPoolTokens(quoteChain, pool);
|
|
17328
17496
|
if (!resolvedPool) continue;
|
|
17329
|
-
const tokenInForQuote = matchPoolToken(params.tokenIn, resolvedPool);
|
|
17330
|
-
const tokenOutForQuote = matchPoolToken(params.tokenOut, resolvedPool);
|
|
17497
|
+
const tokenInForQuote = this.matchPoolToken(params.tokenIn, sourceChain, resolvedPool);
|
|
17498
|
+
const tokenOutForQuote = this.matchPoolToken(params.tokenOut, destinationChain, resolvedPool);
|
|
17331
17499
|
if (!tokenInForQuote || !tokenOutForQuote || tokenInForQuote.symbol === tokenOutForQuote.symbol) continue;
|
|
17332
17500
|
const { currency0, currency1 } = sortCurrencies(resolvedPool[0].address, resolvedPool[1].address);
|
|
17333
17501
|
return {
|
|
@@ -17338,7 +17506,7 @@ var UniswapV4IntentQuoteStrategy = class {
|
|
|
17338
17506
|
tickSpacing: pool.tickSpacing,
|
|
17339
17507
|
hooks: getAddress(pool.hooks ?? zeroAddress)
|
|
17340
17508
|
},
|
|
17341
|
-
quoterAddress: this.resolveQuoterAddress(
|
|
17509
|
+
quoterAddress: this.resolveQuoterAddress(quoteChain),
|
|
17342
17510
|
tokenInForQuote: tokenInForQuote.address
|
|
17343
17511
|
};
|
|
17344
17512
|
}
|
|
@@ -17361,8 +17529,18 @@ var UniswapV4IntentQuoteStrategy = class {
|
|
|
17361
17529
|
if (!address || address === "0x") return null;
|
|
17362
17530
|
return { symbol, address: getAddress(address) };
|
|
17363
17531
|
}
|
|
17532
|
+
matchPoolToken(tokenAddress, orderChain, poolTokens) {
|
|
17533
|
+
const addressMatch = poolTokens.find(
|
|
17534
|
+
(poolToken) => poolToken.address.toLowerCase() === tokenAddress.toLowerCase()
|
|
17535
|
+
);
|
|
17536
|
+
if (addressMatch) return addressMatch;
|
|
17537
|
+
const metadata = this.chainConfigService.getAssetMetadataByAddress(orderChain, tokenAddress);
|
|
17538
|
+
if (!metadata) return null;
|
|
17539
|
+
return poolTokens.find((poolToken) => poolToken.symbol === metadata.symbol) ?? null;
|
|
17540
|
+
}
|
|
17364
17541
|
async quoteExactInput(args) {
|
|
17365
17542
|
const amountIn = args.params.amountIn;
|
|
17543
|
+
if (amountIn === void 0) throw new Error("amountIn is required for an exact-input quote");
|
|
17366
17544
|
const swapAmountIn = deductProtocolFee(amountIn, args.protocolFeeBps);
|
|
17367
17545
|
const amountOut = await this.readV4QuoteExactInput(args.client, args.poolConfig, swapAmountIn);
|
|
17368
17546
|
return {
|
|
@@ -17380,6 +17558,7 @@ var UniswapV4IntentQuoteStrategy = class {
|
|
|
17380
17558
|
}
|
|
17381
17559
|
async quoteExactOutput(args) {
|
|
17382
17560
|
const amountOut = args.params.amountOut;
|
|
17561
|
+
if (amountOut === void 0) throw new Error("amountOut is required for an exact-output quote");
|
|
17383
17562
|
const swapAmountIn = await this.readV4QuoteExactOutput(args.client, args.poolConfig, amountOut);
|
|
17384
17563
|
const amountIn = grossUpForProtocolFee(swapAmountIn, args.protocolFeeBps);
|
|
17385
17564
|
return {
|
|
@@ -17458,34 +17637,125 @@ function sortCurrencies(tokenIn, tokenOut) {
|
|
|
17458
17637
|
const output = getAddress(tokenOut);
|
|
17459
17638
|
return BigInt(input) < BigInt(output) ? { currency0: input, currency1: output } : { currency0: output, currency1: input };
|
|
17460
17639
|
}
|
|
17461
|
-
function matchPoolToken(token, poolTokens) {
|
|
17462
|
-
const tokenAddress = token.address.toLowerCase();
|
|
17463
|
-
const addressMatch = poolTokens.find((poolToken) => poolToken.address.toLowerCase() === tokenAddress);
|
|
17464
|
-
if (addressMatch) return addressMatch;
|
|
17465
|
-
const tokenSymbol = token.symbol?.toUpperCase();
|
|
17466
|
-
if (!tokenSymbol) return null;
|
|
17467
|
-
return poolTokens.find((poolToken) => poolToken.symbol.toUpperCase() === tokenSymbol) ?? null;
|
|
17468
|
-
}
|
|
17469
17640
|
function getZeroForOne(tokenIn, poolKey) {
|
|
17470
17641
|
return getAddress(tokenIn).toLowerCase() === getAddress(poolKey.currency0).toLowerCase();
|
|
17471
17642
|
}
|
|
17472
|
-
|
|
17473
|
-
|
|
17474
|
-
|
|
17475
|
-
|
|
17476
|
-
|
|
17477
|
-
|
|
17478
|
-
|
|
17479
|
-
}
|
|
17480
|
-
|
|
17481
|
-
|
|
17482
|
-
|
|
17643
|
+
|
|
17644
|
+
// src/protocols/intents/quote/phantomSnapshot.ts
|
|
17645
|
+
var PHANTOM_INTENT_QUOTE_CHAIN = "EVM-8453" /* BASE_MAINNET */;
|
|
17646
|
+
var BASE_SNAPSHOT_ASSET_BY_ORDER_ASSET = {
|
|
17647
|
+
USDC: "USDC",
|
|
17648
|
+
USDT: "USDC",
|
|
17649
|
+
cNGN: "cNGN"
|
|
17650
|
+
};
|
|
17651
|
+
var SUPPORTED_BASE_SNAPSHOT_PAIRS = /* @__PURE__ */ new Set(["USDC:cNGN", "cNGN:USDC"]);
|
|
17652
|
+
var PhantomSnapshotIntentQuoteStrategy = class {
|
|
17653
|
+
constructor(chainConfigService, getQueryClient) {
|
|
17654
|
+
this.chainConfigService = chainConfigService;
|
|
17655
|
+
this.getQueryClient = getQueryClient;
|
|
17656
|
+
}
|
|
17657
|
+
chainConfigService;
|
|
17658
|
+
getQueryClient;
|
|
17659
|
+
async quote(params, source, destination) {
|
|
17660
|
+
validateQuoteParams(params);
|
|
17661
|
+
const pair = this.resolveBaseSnapshotPair(params, source.stateMachineId, destination.stateMachineId);
|
|
17662
|
+
if (!pair) {
|
|
17663
|
+
throw new UnsupportedIntentQuotePairError({
|
|
17664
|
+
source: source.stateMachineId,
|
|
17665
|
+
destination: destination.stateMachineId,
|
|
17666
|
+
tokenIn: params.tokenIn,
|
|
17667
|
+
tokenOut: params.tokenOut,
|
|
17668
|
+
quoteSource: "Phantom snapshot pair"
|
|
17669
|
+
});
|
|
17670
|
+
}
|
|
17671
|
+
const queryClient = this.getQueryClient();
|
|
17672
|
+
const [protocolFeeBps, snapshot] = await Promise.all([
|
|
17673
|
+
readProtocolFeeBps(this.chainConfigService, source),
|
|
17674
|
+
_queryLatestPhantomOrderPriceSnapshot({
|
|
17675
|
+
tokenA: pair.tokenA,
|
|
17676
|
+
tokenB: pair.tokenB,
|
|
17677
|
+
queryClient
|
|
17678
|
+
})
|
|
17679
|
+
]);
|
|
17680
|
+
if (!snapshot) throw new PhantomSnapshotUnavailableError(pair.tokenA, pair.tokenB);
|
|
17681
|
+
this.validateSnapshot(snapshot);
|
|
17682
|
+
return this.quoteSnapshot(params, protocolFeeBps, snapshot);
|
|
17683
|
+
}
|
|
17684
|
+
quoteSnapshot(params, protocolFeeBps, snapshot) {
|
|
17685
|
+
if (params.amountIn !== void 0) {
|
|
17686
|
+
const netAmountIn2 = deductProtocolFee(params.amountIn, protocolFeeBps);
|
|
17687
|
+
const amountOut = netAmountIn2 * snapshot.medianPrice / snapshot.standardAmount;
|
|
17688
|
+
if (amountOut <= 0n) {
|
|
17689
|
+
throw new InvalidPhantomSnapshotError(snapshot.commitment, "quote rounds down to zero output");
|
|
17690
|
+
}
|
|
17691
|
+
return this.buildResult("EXACT_INPUT", params.amountIn, amountOut, protocolFeeBps, snapshot);
|
|
17692
|
+
}
|
|
17693
|
+
if (params.amountOut === void 0) throw new Error("Quote amount is missing after validation");
|
|
17694
|
+
const netAmountIn = divCeil(params.amountOut * snapshot.standardAmount, snapshot.medianPrice);
|
|
17695
|
+
const amountIn = grossUpForProtocolFee(netAmountIn, protocolFeeBps);
|
|
17696
|
+
return this.buildResult("EXACT_OUTPUT", amountIn, params.amountOut, protocolFeeBps, snapshot);
|
|
17697
|
+
}
|
|
17698
|
+
buildResult(tradeType, amountIn, amountOut, protocolFeeBps, snapshot) {
|
|
17699
|
+
return {
|
|
17700
|
+
strategy: "phantom_snapshot",
|
|
17701
|
+
tradeType,
|
|
17702
|
+
amountIn,
|
|
17703
|
+
amountOut,
|
|
17704
|
+
quoteMetadata: {
|
|
17705
|
+
quoteChain: PHANTOM_INTENT_QUOTE_CHAIN,
|
|
17706
|
+
commitment: snapshot.commitment,
|
|
17707
|
+
tokenA: snapshot.tokenA,
|
|
17708
|
+
tokenB: snapshot.tokenB,
|
|
17709
|
+
standardAmount: snapshot.standardAmount,
|
|
17710
|
+
medianPrice: snapshot.medianPrice,
|
|
17711
|
+
lowestPrice: snapshot.lowestPrice,
|
|
17712
|
+
highestPrice: snapshot.highestPrice,
|
|
17713
|
+
blockNumber: snapshot.blockNumber,
|
|
17714
|
+
snapshotTime: snapshot.snapshotTime,
|
|
17715
|
+
bidCount: snapshot.bidCount,
|
|
17716
|
+
protocolFeeBps
|
|
17717
|
+
}
|
|
17718
|
+
};
|
|
17719
|
+
}
|
|
17720
|
+
validateSnapshot(snapshot) {
|
|
17721
|
+
if (snapshot.standardAmount <= 0n) {
|
|
17722
|
+
throw new InvalidPhantomSnapshotError(snapshot.commitment, "standardAmount must be greater than zero");
|
|
17723
|
+
}
|
|
17724
|
+
if (snapshot.medianPrice <= 0n) {
|
|
17725
|
+
throw new InvalidPhantomSnapshotError(snapshot.commitment, "medianPrice must be greater than zero");
|
|
17726
|
+
}
|
|
17727
|
+
if (snapshot.bidCount <= 0) {
|
|
17728
|
+
throw new InvalidPhantomSnapshotError(snapshot.commitment, "bidCount must be greater than zero");
|
|
17729
|
+
}
|
|
17730
|
+
if (Number.isNaN(snapshot.snapshotTime.getTime())) {
|
|
17731
|
+
throw new InvalidPhantomSnapshotError(snapshot.commitment, "snapshotTime is invalid");
|
|
17732
|
+
}
|
|
17733
|
+
}
|
|
17734
|
+
resolveBaseSnapshotPair(params, sourceStateMachineId, destinationStateMachineId) {
|
|
17735
|
+
const tokenIn = this.resolveBaseSnapshotToken(sourceStateMachineId, params.tokenIn);
|
|
17736
|
+
const tokenOut = this.resolveBaseSnapshotToken(destinationStateMachineId, params.tokenOut);
|
|
17737
|
+
if (!tokenIn || !tokenOut || !isSupportedSnapshotPair(tokenIn.symbol, tokenOut.symbol)) return;
|
|
17738
|
+
return { tokenA: tokenIn.address, tokenB: tokenOut.address };
|
|
17739
|
+
}
|
|
17740
|
+
resolveBaseSnapshotToken(chain, tokenAddress) {
|
|
17741
|
+
const orderAsset = this.chainConfigService.getAssetMetadataByAddress(chain, tokenAddress)?.symbol;
|
|
17742
|
+
if (!orderAsset) return;
|
|
17743
|
+
const snapshotAsset = BASE_SNAPSHOT_ASSET_BY_ORDER_ASSET[orderAsset];
|
|
17744
|
+
if (!snapshotAsset) return;
|
|
17745
|
+
const address = this.chainConfigService.getAssetAddress(PHANTOM_INTENT_QUOTE_CHAIN, snapshotAsset);
|
|
17746
|
+
if (!isConfiguredAddress(address)) return;
|
|
17747
|
+
return { symbol: snapshotAsset, address };
|
|
17748
|
+
}
|
|
17749
|
+
};
|
|
17750
|
+
function isSupportedSnapshotPair(tokenA, tokenB) {
|
|
17751
|
+
return SUPPORTED_BASE_SNAPSHOT_PAIRS.has(`${tokenA}:${tokenB}`);
|
|
17483
17752
|
}
|
|
17484
|
-
function
|
|
17485
|
-
return (
|
|
17753
|
+
function isConfiguredAddress(address) {
|
|
17754
|
+
return Boolean(address && address !== "0x" && !/^0x0{40}$/i.test(address));
|
|
17486
17755
|
}
|
|
17487
17756
|
|
|
17488
17757
|
// src/protocols/intents/IntentGateway.ts
|
|
17758
|
+
var CROSS_CHAIN_ORDER_FEE_GAS_BUMP = 600000n;
|
|
17489
17759
|
var IntentGateway = class _IntentGateway {
|
|
17490
17760
|
/** EVM chain on which orders are placed and escrowed. */
|
|
17491
17761
|
source;
|
|
@@ -17557,6 +17827,10 @@ var IntentGateway = class _IntentGateway {
|
|
|
17557
17827
|
this.gasEstimator = gasEstimator;
|
|
17558
17828
|
this._crypto = crypto;
|
|
17559
17829
|
this.quoteStrategies = {
|
|
17830
|
+
phantom_snapshot: new PhantomSnapshotIntentQuoteStrategy(
|
|
17831
|
+
dest.configService,
|
|
17832
|
+
() => this.requireIndexer().queryClient
|
|
17833
|
+
),
|
|
17560
17834
|
uniswap_v4: new UniswapV4IntentQuoteStrategy(dest.configService)
|
|
17561
17835
|
};
|
|
17562
17836
|
}
|
|
@@ -17606,37 +17880,39 @@ var IntentGateway = class _IntentGateway {
|
|
|
17606
17880
|
/**
|
|
17607
17881
|
* Quotes an intent between this gateway's source and destination chains.
|
|
17608
17882
|
*
|
|
17609
|
-
*
|
|
17610
|
-
*
|
|
17883
|
+
* Uses the latest directional Phantom order price snapshot from the attached
|
|
17884
|
+
* indexer by default. Pass `strategy: "uniswap_v4"` only when explicitly
|
|
17885
|
+
* requesting a Uniswap quote. Provide exactly one of `amountIn` or `amountOut`.
|
|
17611
17886
|
*
|
|
17612
|
-
*
|
|
17613
|
-
*
|
|
17887
|
+
* Both built-in strategies resolve their canonical market on Base,
|
|
17888
|
+
* regardless of this gateway's destination chain. Returned
|
|
17614
17889
|
* `amountIn`/`amountOut` already account for the gateway's protocol fee
|
|
17615
17890
|
* (`quoteMetadata.protocolFeeBps`), which the gateway deducts from order
|
|
17616
|
-
* inputs;
|
|
17891
|
+
* inputs; use the returned amounts directly when placing the order.
|
|
17617
17892
|
*
|
|
17618
17893
|
* @param params - Token pair, amount, and optional strategy/pool overrides.
|
|
17619
17894
|
* @returns The quoted amounts plus strategy-specific metadata.
|
|
17620
17895
|
* @throws {UnsupportedIntentQuoteStrategyError} For unknown strategies.
|
|
17621
|
-
* @throws {UnsupportedIntentQuotePairError} When
|
|
17896
|
+
* @throws {UnsupportedIntentQuotePairError} When the selected strategy does not support the pair.
|
|
17897
|
+
* @throws {PhantomSnapshotUnavailableError} When an eligible cNGN pair has no snapshot.
|
|
17622
17898
|
*/
|
|
17623
17899
|
async quoteIntent(params) {
|
|
17624
|
-
const
|
|
17900
|
+
const source = { stateMachineId: this.source.config.stateMachineId, client: this.source.client };
|
|
17901
|
+
const destination = { stateMachineId: this.dest.config.stateMachineId, client: this.dest.client };
|
|
17902
|
+
const strategy = params.strategy ?? "phantom_snapshot";
|
|
17625
17903
|
const handler = this.quoteStrategies[strategy];
|
|
17626
17904
|
if (!handler) throw new UnsupportedIntentQuoteStrategyError(strategy);
|
|
17627
|
-
return handler.quote(
|
|
17628
|
-
{ ...params, strategy },
|
|
17629
|
-
{ stateMachineId: this.source.config.stateMachineId, client: this.source.client },
|
|
17630
|
-
{ stateMachineId: this.dest.config.stateMachineId, client: this.dest.client }
|
|
17631
|
-
);
|
|
17905
|
+
return handler.quote({ ...params, strategy }, source, destination);
|
|
17632
17906
|
}
|
|
17633
17907
|
/**
|
|
17634
17908
|
* Bidirectional async generator that orchestrates the full order lifecycle:
|
|
17635
17909
|
* placement, fee estimation, bid collection, and execution.
|
|
17636
17910
|
*
|
|
17637
17911
|
* **Yield/receive protocol:**
|
|
17638
|
-
* 1. If `order.fees` is unset or zero, estimates gas and sets
|
|
17639
|
-
*
|
|
17912
|
+
* 1. If `order.fees` is unset or zero, estimates gas and sets same-chain
|
|
17913
|
+
* `order.fees` to twice the estimate. Cross-chain orders retain a 1% buffer
|
|
17914
|
+
* and include an additional 600k-gas fee uplift, while the wei cost used for
|
|
17915
|
+
* the `value` field receives a 2% buffer.
|
|
17640
17916
|
* 2. Yields `AWAITING_PLACE_ORDER` with `{ to, data, value, sessionPrivateKey }`.
|
|
17641
17917
|
* The caller must sign the transaction and pass it back via `gen.next(signedTx)`.
|
|
17642
17918
|
* 3. Yields `ORDER_PLACED` with the finalised order and transaction hash once
|
|
@@ -17668,8 +17944,15 @@ var IntentGateway = class _IntentGateway {
|
|
|
17668
17944
|
if (estimate.totalGasCostWei === 0n || estimate.totalGasInFeeToken === 0n) {
|
|
17669
17945
|
throw new Error("Gas estimation failed");
|
|
17670
17946
|
}
|
|
17947
|
+
const isSameChain = this.source.config.stateMachineId === this.dest.config.stateMachineId;
|
|
17671
17948
|
value = estimate.totalGasCostWei + estimate.totalGasCostWei * 2n / 100n;
|
|
17672
|
-
|
|
17949
|
+
const crossChainFeeBump = isSameChain ? 0n : await convertGasToFeeToken(
|
|
17950
|
+
this.ctx,
|
|
17951
|
+
CROSS_CHAIN_ORDER_FEE_GAS_BUMP,
|
|
17952
|
+
"source",
|
|
17953
|
+
this.source.config.stateMachineId
|
|
17954
|
+
);
|
|
17955
|
+
order.fees = isSameChain ? estimate.totalGasInFeeToken * 2n : estimate.totalGasInFeeToken + (crossChainFeeBump + estimate.totalGasInFeeToken * 1n / 100n);
|
|
17673
17956
|
}
|
|
17674
17957
|
const placeOrderGen = this.orderPlacer.placeOrder(order, graffiti);
|
|
17675
17958
|
const placeOrderFirst = await placeOrderGen.next();
|
|
@@ -18050,7 +18333,9 @@ var IntentGateway = class _IntentGateway {
|
|
|
18050
18333
|
}
|
|
18051
18334
|
requireIndexer() {
|
|
18052
18335
|
if (!this.indexer) {
|
|
18053
|
-
throw new Error(
|
|
18336
|
+
throw new Error(
|
|
18337
|
+
"IntentGateway: call withQueryClient(queryClient) before using indexer-backed methods or Phantom quotes"
|
|
18338
|
+
);
|
|
18054
18339
|
}
|
|
18055
18340
|
return this.indexer;
|
|
18056
18341
|
}
|
|
@@ -22564,6 +22849,6 @@ async function teleportDot(param_) {
|
|
|
22564
22849
|
return stream;
|
|
22565
22850
|
}
|
|
22566
22851
|
|
|
22567
|
-
export { ADDRESS_ZERO2 as ADDRESS_ZERO, BundlerMethod, ChainConfigService, Chains, CryptoUtils, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DOMAIN_TYPEHASH, DUMMY_PRIVATE_KEY, ERC20Method, ERC7821_BATCH_MODE, EvmChain, ABI as EvmHostABI, EvmLanguage, HyperClientStatus, HyperFungibleToken, HyperFungibleTokenABI, IntentGateway, ABI3 as IntentGatewayABI, IntentOrderStatus, IntentsCoprocessor, IsmpClient, MOCK_ADDRESS, ORDER_V2_PARAM_TYPE, OrderStatus, OrderStatusChecker, PACKED_USEROP_TYPEHASH, PLACE_ORDER_SELECTOR, PharosChain, PolkadotHubChain, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, RequestKind, RequestStatus, SELECT_SOLVER_TYPEHASH, STATE_COMMITMENTS_SLOT, SubstrateChain, Swap, TESTNET_CHAINS, TeleportStatus, TimeoutStatus, TokenGateway, TronChain, USE_ETHERSCAN_CHAINS, UnsupportedIntentQuotePairError, UnsupportedIntentQuoteStrategyError, WrappedHyperFungibleTokenABI, __test, adjustDecimals, bytes20ToBytes32, bytes32ToBytes20, calculateAllowanceMappingLocation, calculateBalanceMappingLocation, chainConfigs, constructRedeemEscrowRequestBody, constructRefundEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createEvmChain, createQueryClient, decodeERC7821ExecuteBatch, decodeUserOpScale, encodeERC7821ExecuteBatch, encodeISMPMessage, encodeStateMachineId, encodeUserOpScale, encodeWithdrawalRequest, estimateGasForPost, fetchPrice, fetchSourceProof, generateRootWithProof, getChainId, getConfigByStateMachineId, getContractCallInput, getContractCallInputs, getGasPriceFromEtherscan, getOrFetchStorageSlot, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, getViemChain, hexToString, hyperbridgeAddress, maxBigInt, normalizeAddressForEvmBytes32, normalizeAddressForStateMachine, normalizeEvmChainId, normalizeStateMachineId, orderCommitment, parseStateMachineId, pharosAtlantic, pharosMainnet, polkadotAssetHubPaseo, polkadotHubMainnet, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, quoteUniswap, requestCommitmentKey, responseCommitmentKey, retryPromise, teleport, teleportDot, transformOrderForContract, tronChainIds, tronNile };
|
|
22852
|
+
export { ADDRESS_ZERO2 as ADDRESS_ZERO, BundlerMethod, ChainConfigService, Chains, CryptoUtils, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DOMAIN_TYPEHASH, DUMMY_PRIVATE_KEY, ERC20Method, ERC7821_BATCH_MODE, EvmChain, ABI as EvmHostABI, EvmLanguage, HyperClientStatus, HyperFungibleToken, HyperFungibleTokenABI, IntentGateway, ABI3 as IntentGatewayABI, IntentOrderStatus, IntentsCoprocessor, InvalidPhantomSnapshotError, IsmpClient, MOCK_ADDRESS, ORDER_V2_PARAM_TYPE, OrderStatus, OrderStatusChecker, PACKED_USEROP_TYPEHASH, PLACE_ORDER_SELECTOR, PhantomSnapshotUnavailableError, PharosChain, PolkadotHubChain, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, RequestKind, RequestStatus, SELECT_SOLVER_TYPEHASH, STATE_COMMITMENTS_SLOT, SubstrateChain, Swap, TESTNET_CHAINS, TeleportStatus, TimeoutStatus, TokenGateway, TronChain, USE_ETHERSCAN_CHAINS, UnsupportedIntentQuotePairError, UnsupportedIntentQuoteStrategyError, WrappedHyperFungibleTokenABI, __test, adjustDecimals, bytes20ToBytes32, bytes32ToBytes20, calculateAllowanceMappingLocation, calculateBalanceMappingLocation, chainConfigs, constructRedeemEscrowRequestBody, constructRefundEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createEvmChain, createQueryClient, decodeERC7821ExecuteBatch, decodeUserOpScale, encodeERC7821ExecuteBatch, encodeISMPMessage, encodeStateMachineId, encodeUserOpScale, encodeWithdrawalRequest, estimateGasForPost, fetchPrice, fetchSourceProof, generateRootWithProof, getChainId, getConfigByStateMachineId, getContractCallInput, getContractCallInputs, getGasPriceFromEtherscan, getOrFetchStorageSlot, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, getViemChain, hexToString, hyperbridgeAddress, maxBigInt, normalizeAddressForEvmBytes32, normalizeAddressForStateMachine, normalizeEvmChainId, normalizeStateMachineId, orderCommitment, parseStateMachineId, pharosAtlantic, pharosMainnet, polkadotAssetHubPaseo, polkadotHubMainnet, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, quoteUniswap, requestCommitmentKey, responseCommitmentKey, retryPromise, teleport, teleportDot, transformOrderForContract, tronChainIds, tronNile };
|
|
22568
22853
|
//# sourceMappingURL=index.js.map
|
|
22569
22854
|
//# sourceMappingURL=index.js.map
|