@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/browser/index.js
CHANGED
|
@@ -2529,30 +2529,30 @@ var handlerV2_default = { ABI: ABI2 };
|
|
|
2529
2529
|
function tronAddress(base58) {
|
|
2530
2530
|
return `0x${TronWeb.address.toHex(base58).slice(2)}`;
|
|
2531
2531
|
}
|
|
2532
|
-
var Chains = /* @__PURE__ */ ((
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
return
|
|
2532
|
+
var Chains = /* @__PURE__ */ ((Chains2) => {
|
|
2533
|
+
Chains2["BSC_CHAPEL"] = "EVM-97";
|
|
2534
|
+
Chains2["GNOSIS_CHIADO"] = "EVM-10200";
|
|
2535
|
+
Chains2["HYPERBRIDGE_GARGANTUA"] = "KUSAMA-4009";
|
|
2536
|
+
Chains2["SEPOLIA"] = "EVM-11155111";
|
|
2537
|
+
Chains2["MAINNET"] = "EVM-1";
|
|
2538
|
+
Chains2["BSC_MAINNET"] = "EVM-56";
|
|
2539
|
+
Chains2["ARBITRUM_MAINNET"] = "EVM-42161";
|
|
2540
|
+
Chains2["ARBITRUM_SEPOLIA"] = "EVM-421614";
|
|
2541
|
+
Chains2["BASE_MAINNET"] = "EVM-8453";
|
|
2542
|
+
Chains2["BASE_SEPOLIA"] = "EVM-84532";
|
|
2543
|
+
Chains2["OPTIMISM_MAINNET"] = "EVM-10";
|
|
2544
|
+
Chains2["OPTIMISM_SEPOLIA"] = "EVM-11155420";
|
|
2545
|
+
Chains2["GNOSIS_MAINNET"] = "EVM-100";
|
|
2546
|
+
Chains2["SONEIUM_MAINNET"] = "EVM-1868";
|
|
2547
|
+
Chains2["POLYGON_MAINNET"] = "EVM-137";
|
|
2548
|
+
Chains2["POLKADOT_HUB_MAINNET"] = "EVM-420420419";
|
|
2549
|
+
Chains2["POLYGON_AMOY"] = "EVM-80002";
|
|
2550
|
+
Chains2["POLKADOT_ASSET_HUB_PASEO"] = "EVM-420420417";
|
|
2551
|
+
Chains2["TRON_MAINNET"] = "EVM-728126428";
|
|
2552
|
+
Chains2["TRON_NILE"] = "EVM-3448148188";
|
|
2553
|
+
Chains2["PHAROS_MAINNET"] = "EVM-688600";
|
|
2554
|
+
Chains2["PHAROS_ATLANTIC"] = "EVM-688689";
|
|
2555
|
+
return Chains2;
|
|
2556
2556
|
})(Chains || {});
|
|
2557
2557
|
var polkadotAssetHubPaseo = defineChain({
|
|
2558
2558
|
id: 420420417,
|
|
@@ -2635,7 +2635,7 @@ var chainConfigs = {
|
|
|
2635
2635
|
UniswapV3Quoter: "0x0000000000000000000000000000000000000000",
|
|
2636
2636
|
UniswapV4Quoter: "0x0000000000000000000000000000000000000000",
|
|
2637
2637
|
EntryPointV08: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108",
|
|
2638
|
-
SolverAccount: "
|
|
2638
|
+
SolverAccount: "0x110C7E1814c923127469Ca8939a12dAa70B96a17"
|
|
2639
2639
|
},
|
|
2640
2640
|
rpcEnvKey: "BSC_CHAPEL",
|
|
2641
2641
|
defaultRpcUrl: "https://bnb-testnet.api.onfinality.io/public",
|
|
@@ -2743,7 +2743,7 @@ var chainConfigs = {
|
|
|
2743
2743
|
},
|
|
2744
2744
|
addresses: {
|
|
2745
2745
|
IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
|
|
2746
|
-
SolverAccount: "
|
|
2746
|
+
SolverAccount: "0xfCd233b937D7622AAc63ced3C9A1A12F4a6B64E3",
|
|
2747
2747
|
TokenGateway: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
|
|
2748
2748
|
Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
|
|
2749
2749
|
UniswapRouter02: "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
|
|
@@ -2798,7 +2798,7 @@ var chainConfigs = {
|
|
|
2798
2798
|
},
|
|
2799
2799
|
addresses: {
|
|
2800
2800
|
IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
|
|
2801
|
-
SolverAccount: "
|
|
2801
|
+
SolverAccount: "0xfCd233b937D7622AAc63ced3C9A1A12F4a6B64E3",
|
|
2802
2802
|
TokenGateway: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
|
|
2803
2803
|
Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
|
|
2804
2804
|
UniswapRouter02: "0x10ED43C718714eb63d5aA57B78B54704E256024E",
|
|
@@ -2854,7 +2854,7 @@ var chainConfigs = {
|
|
|
2854
2854
|
},
|
|
2855
2855
|
addresses: {
|
|
2856
2856
|
IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
|
|
2857
|
-
SolverAccount: "
|
|
2857
|
+
SolverAccount: "0xfCd233b937D7622AAc63ced3C9A1A12F4a6B64E3",
|
|
2858
2858
|
TokenGateway: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
|
|
2859
2859
|
Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
|
|
2860
2860
|
UniswapRouter02: "0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24",
|
|
@@ -2911,7 +2911,7 @@ var chainConfigs = {
|
|
|
2911
2911
|
},
|
|
2912
2912
|
addresses: {
|
|
2913
2913
|
IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
|
|
2914
|
-
SolverAccount: "
|
|
2914
|
+
SolverAccount: "0xfCd233b937D7622AAc63ced3C9A1A12F4a6B64E3",
|
|
2915
2915
|
TokenGateway: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
|
|
2916
2916
|
Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
|
|
2917
2917
|
UniswapRouter02: "0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24",
|
|
@@ -2970,7 +2970,7 @@ var chainConfigs = {
|
|
|
2970
2970
|
},
|
|
2971
2971
|
addresses: {
|
|
2972
2972
|
IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
|
|
2973
|
-
SolverAccount: "
|
|
2973
|
+
SolverAccount: "0xfCd233b937D7622AAc63ced3C9A1A12F4a6B64E3",
|
|
2974
2974
|
TokenGateway: "0x8b536105b6Fae2aE9199f5146D3C57Dfe53b614E",
|
|
2975
2975
|
Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
|
|
2976
2976
|
UniswapRouter02: "0xd2f9496824951D5237cC71245D659E48d0d5f9E8",
|
|
@@ -3057,7 +3057,7 @@ var chainConfigs = {
|
|
|
3057
3057
|
Calldispatcher: "0x876F1891982E260026630c233A4897160A281Fb8",
|
|
3058
3058
|
Permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
|
|
3059
3059
|
EntryPointV08: "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108",
|
|
3060
|
-
SolverAccount: "
|
|
3060
|
+
SolverAccount: "0x110C7E1814c923127469Ca8939a12dAa70B96a17"
|
|
3061
3061
|
},
|
|
3062
3062
|
rpcEnvKey: "POLYGON_AMOY",
|
|
3063
3063
|
defaultRpcUrl: "https://rpc-amoy.polygon.technology",
|
|
@@ -3081,7 +3081,7 @@ var chainConfigs = {
|
|
|
3081
3081
|
},
|
|
3082
3082
|
addresses: {
|
|
3083
3083
|
IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
|
|
3084
|
-
SolverAccount: "
|
|
3084
|
+
SolverAccount: "0xfCd233b937D7622AAc63ced3C9A1A12F4a6B64E3",
|
|
3085
3085
|
TokenGateway: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
|
|
3086
3086
|
Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
|
|
3087
3087
|
UniswapRouter02: "0x4A7b5Da61326A6379179b40d00F57E5bbDC962c2",
|
|
@@ -3116,7 +3116,7 @@ var chainConfigs = {
|
|
|
3116
3116
|
},
|
|
3117
3117
|
addresses: {
|
|
3118
3118
|
IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
|
|
3119
|
-
SolverAccount: "
|
|
3119
|
+
SolverAccount: "0xfCd233b937D7622AAc63ced3C9A1A12F4a6B64E3",
|
|
3120
3120
|
TokenGateway: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
|
|
3121
3121
|
Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
|
|
3122
3122
|
UniswapRouter02: "0xB2e26652e4BAd1e56055A051f922E06760cA0BFE",
|
|
@@ -3271,7 +3271,7 @@ var chainConfigs = {
|
|
|
3271
3271
|
},
|
|
3272
3272
|
addresses: {
|
|
3273
3273
|
IntentGateway: "0xAe041F7B0CB581876832830baeB6a2Aa2a3C9716",
|
|
3274
|
-
SolverAccount: "
|
|
3274
|
+
SolverAccount: "0xfCd233b937D7622AAc63ced3C9A1A12F4a6B64E3",
|
|
3275
3275
|
Host: "0x620128E2B19193d6Bd244a3AC8D3bBa0541B19c3",
|
|
3276
3276
|
Calldispatcher: "0xE2C7e576E26E0bE7aC97c6fE925bcDAbD87c4bEd"
|
|
3277
3277
|
},
|
|
@@ -5157,6 +5157,24 @@ var ChainConfigService = class {
|
|
|
5157
5157
|
getAssetAddress(chain, symbol) {
|
|
5158
5158
|
return this.getConfig(chain)?.assets?.[symbol];
|
|
5159
5159
|
}
|
|
5160
|
+
/**
|
|
5161
|
+
* Resolves configured token metadata from an address on a specific chain.
|
|
5162
|
+
* This is used by SDK helpers that accept token addresses rather than caller-
|
|
5163
|
+
* supplied symbols or decimals.
|
|
5164
|
+
*/
|
|
5165
|
+
getAssetMetadataByAddress(chain, address) {
|
|
5166
|
+
const config = this.getConfig(chain);
|
|
5167
|
+
if (!config?.assets) return;
|
|
5168
|
+
const normalizedAddress = address.toLowerCase();
|
|
5169
|
+
for (const [symbol, configuredAddress] of Object.entries(config.assets)) {
|
|
5170
|
+
if (configuredAddress.toLowerCase() !== normalizedAddress) continue;
|
|
5171
|
+
return {
|
|
5172
|
+
symbol,
|
|
5173
|
+
address: configuredAddress,
|
|
5174
|
+
decimals: config.tokenDecimals?.[symbol]
|
|
5175
|
+
};
|
|
5176
|
+
}
|
|
5177
|
+
}
|
|
5160
5178
|
getUsdtAsset(chain) {
|
|
5161
5179
|
return this.getConfig(chain)?.assets?.USDT ?? "0x";
|
|
5162
5180
|
}
|
|
@@ -7830,7 +7848,7 @@ var IntentsCoprocessor = class _IntentsCoprocessor {
|
|
|
7830
7848
|
*/
|
|
7831
7849
|
async sendExtrinsicWithRetries(extrinsic, maxRetries, timeoutMs) {
|
|
7832
7850
|
const keyPair = this.getKeyPair();
|
|
7833
|
-
|
|
7851
|
+
const baseTip = 1000000000n;
|
|
7834
7852
|
let attempt = 0;
|
|
7835
7853
|
while (attempt < maxRetries) {
|
|
7836
7854
|
const currentTip = baseTip * BigInt(2 ** attempt);
|
|
@@ -11500,6 +11518,33 @@ query OrderStatus($commitment: String!) {
|
|
|
11500
11518
|
}
|
|
11501
11519
|
}
|
|
11502
11520
|
}`;
|
|
11521
|
+
var LATEST_PHANTOM_ORDER_PRICE_SNAPSHOT = `
|
|
11522
|
+
query LatestPhantomOrderPriceSnapshot($tokenA: String!, $tokenB: String!) {
|
|
11523
|
+
phantomOrderPriceSnapshots(
|
|
11524
|
+
filter: {
|
|
11525
|
+
and: [
|
|
11526
|
+
{ tokenA: { equalTo: $tokenA } }
|
|
11527
|
+
{ tokenB: { equalTo: $tokenB } }
|
|
11528
|
+
{ medianPrice: { isNull: false } }
|
|
11529
|
+
]
|
|
11530
|
+
}
|
|
11531
|
+
orderBy: BLOCK_NUMBER_DESC
|
|
11532
|
+
first: 1
|
|
11533
|
+
) {
|
|
11534
|
+
nodes {
|
|
11535
|
+
commitment
|
|
11536
|
+
tokenA
|
|
11537
|
+
tokenB
|
|
11538
|
+
standardAmount
|
|
11539
|
+
blockNumber
|
|
11540
|
+
medianPrice
|
|
11541
|
+
lowestPrice
|
|
11542
|
+
highestPrice
|
|
11543
|
+
bidCount
|
|
11544
|
+
snapshotTime
|
|
11545
|
+
}
|
|
11546
|
+
}
|
|
11547
|
+
}`;
|
|
11503
11548
|
var TOKEN_GATEWAY_ASSET_TELEPORTED_STATUS = `
|
|
11504
11549
|
query TokenGatewayAssetTeleportedStatus($commitment: String!) {
|
|
11505
11550
|
tokenGatewayAssetTeleportedV2s(
|
|
@@ -11561,6 +11606,29 @@ async function queryAssetTeleported(params) {
|
|
|
11561
11606
|
function queryGetRequest(params) {
|
|
11562
11607
|
return _queryGetRequestInternal(params);
|
|
11563
11608
|
}
|
|
11609
|
+
async function _queryLatestPhantomOrderPriceSnapshot(params) {
|
|
11610
|
+
const response = await params.queryClient.request(
|
|
11611
|
+
LATEST_PHANTOM_ORDER_PRICE_SNAPSHOT,
|
|
11612
|
+
{
|
|
11613
|
+
tokenA: params.tokenA.toLowerCase(),
|
|
11614
|
+
tokenB: params.tokenB.toLowerCase()
|
|
11615
|
+
}
|
|
11616
|
+
);
|
|
11617
|
+
const snapshot = response.phantomOrderPriceSnapshots.nodes[0];
|
|
11618
|
+
if (!snapshot?.medianPrice) return;
|
|
11619
|
+
return {
|
|
11620
|
+
commitment: snapshot.commitment,
|
|
11621
|
+
tokenA: snapshot.tokenA,
|
|
11622
|
+
tokenB: snapshot.tokenB,
|
|
11623
|
+
standardAmount: BigInt(snapshot.standardAmount),
|
|
11624
|
+
blockNumber: BigInt(snapshot.blockNumber),
|
|
11625
|
+
medianPrice: BigInt(snapshot.medianPrice),
|
|
11626
|
+
lowestPrice: snapshot.lowestPrice === null ? void 0 : BigInt(snapshot.lowestPrice),
|
|
11627
|
+
highestPrice: snapshot.highestPrice === null ? void 0 : BigInt(snapshot.highestPrice),
|
|
11628
|
+
bidCount: snapshot.bidCount,
|
|
11629
|
+
snapshotTime: new Date(snapshot.snapshotTime)
|
|
11630
|
+
};
|
|
11631
|
+
}
|
|
11564
11632
|
async function _queryTokenGatewayAssetTeleportedInternal(params) {
|
|
11565
11633
|
const { commitmentHash, queryClient: client, logger = DEFAULT_LOGGER } = params;
|
|
11566
11634
|
const response = await retryPromise(
|
|
@@ -14823,6 +14891,67 @@ var CryptoUtils = class _CryptoUtils {
|
|
|
14823
14891
|
encodePacked(["bytes1", "bytes1", "bytes32", "bytes32"], ["0x19", "0x01", domainSeparator, structHash])
|
|
14824
14892
|
);
|
|
14825
14893
|
}
|
|
14894
|
+
/**
|
|
14895
|
+
* Derives the ERC-4337 nonce key that binds a bid UserOperation to its
|
|
14896
|
+
* order and session key: the lower 192 bits of
|
|
14897
|
+
* `keccak256(commitment ‖ sessionKey)`. `SolverAccount` rejects bid
|
|
14898
|
+
* operations whose nonce key differs — this is what lets the solver sign
|
|
14899
|
+
* the plain userOpHash while staying committed to the order and to the
|
|
14900
|
+
* session key it bid against.
|
|
14901
|
+
*
|
|
14902
|
+
* @param commitment - The order commitment (`order.id`).
|
|
14903
|
+
* @param sessionKey - The order's session key address (`order.session`).
|
|
14904
|
+
* @returns The 192-bit nonce key as a bigint (pass to `EntryPoint.getNonce`).
|
|
14905
|
+
*/
|
|
14906
|
+
static bidNonceKey(commitment, sessionKey) {
|
|
14907
|
+
return BigInt(keccak256(encodePacked(["bytes32", "address"], [commitment, sessionKey]))) & (1n << 192n) - 1n;
|
|
14908
|
+
}
|
|
14909
|
+
/**
|
|
14910
|
+
* Builds the EIP-712 typed-data payload whose digest is the EntryPoint v0.8
|
|
14911
|
+
* `userOpHash` (i.e. `hashTypedData(packedUserOpTypedData(...)) ===
|
|
14912
|
+
* computeUserOpHash(...)`). Signing this typed data is bit-identical to
|
|
14913
|
+
* signing the raw userOpHash, but keeps the full operation visible to
|
|
14914
|
+
* signing infrastructure (hardware wallets, MPC/TEE policy engines) instead
|
|
14915
|
+
* of an opaque 32-byte digest.
|
|
14916
|
+
*
|
|
14917
|
+
* @param userOp - The packed UserOperation to sign (signature field ignored).
|
|
14918
|
+
* @param entryPoint - Address of the EntryPoint v0.8 contract.
|
|
14919
|
+
* @param chainId - Chain ID of the network on which the operation will execute.
|
|
14920
|
+
* @returns A viem `TypedDataDefinition` for the operation.
|
|
14921
|
+
*/
|
|
14922
|
+
static packedUserOpTypedData(userOp, entryPoint, chainId) {
|
|
14923
|
+
return {
|
|
14924
|
+
domain: {
|
|
14925
|
+
name: "ERC4337",
|
|
14926
|
+
version: "1",
|
|
14927
|
+
chainId,
|
|
14928
|
+
verifyingContract: entryPoint
|
|
14929
|
+
},
|
|
14930
|
+
types: {
|
|
14931
|
+
PackedUserOperation: [
|
|
14932
|
+
{ name: "sender", type: "address" },
|
|
14933
|
+
{ name: "nonce", type: "uint256" },
|
|
14934
|
+
{ name: "initCode", type: "bytes" },
|
|
14935
|
+
{ name: "callData", type: "bytes" },
|
|
14936
|
+
{ name: "accountGasLimits", type: "bytes32" },
|
|
14937
|
+
{ name: "preVerificationGas", type: "uint256" },
|
|
14938
|
+
{ name: "gasFees", type: "bytes32" },
|
|
14939
|
+
{ name: "paymasterAndData", type: "bytes" }
|
|
14940
|
+
]
|
|
14941
|
+
},
|
|
14942
|
+
primaryType: "PackedUserOperation",
|
|
14943
|
+
message: {
|
|
14944
|
+
sender: userOp.sender,
|
|
14945
|
+
nonce: userOp.nonce,
|
|
14946
|
+
initCode: userOp.initCode,
|
|
14947
|
+
callData: userOp.callData,
|
|
14948
|
+
accountGasLimits: userOp.accountGasLimits,
|
|
14949
|
+
preVerificationGas: userOp.preVerificationGas,
|
|
14950
|
+
gasFees: userOp.gasFees,
|
|
14951
|
+
paymasterAndData: userOp.paymasterAndData
|
|
14952
|
+
}
|
|
14953
|
+
};
|
|
14954
|
+
}
|
|
14826
14955
|
/**
|
|
14827
14956
|
* Computes the EIP-712 struct hash of a `PackedUserOperation`.
|
|
14828
14957
|
*
|
|
@@ -16331,9 +16460,12 @@ var BidManager = class {
|
|
|
16331
16460
|
* Constructs a signed `PackedUserOperation` that a solver can submit to the
|
|
16332
16461
|
* Hyperbridge coprocessor as a bid to fill an order.
|
|
16333
16462
|
*
|
|
16334
|
-
* The solver
|
|
16335
|
-
*
|
|
16336
|
-
*
|
|
16463
|
+
* The solver signs the operation as EntryPoint v0.8 EIP-712 typed data,
|
|
16464
|
+
* whose digest is the plain userOpHash. The binding to the order lives in
|
|
16465
|
+
* the operation itself: the 4337 nonce key must be the lower 192 bits of
|
|
16466
|
+
* the order commitment (`SolverAccount` enforces this during validation),
|
|
16467
|
+
* and the callData carries the order. This keeps the signed payload fully
|
|
16468
|
+
* transparent to signing infrastructure instead of an opaque digest.
|
|
16337
16469
|
*
|
|
16338
16470
|
* @param options - Parameters describing the solver account, gas limits, fee
|
|
16339
16471
|
* market values, and pre-built `callData` for the fill operation.
|
|
@@ -16371,10 +16503,17 @@ var BidManager = class {
|
|
|
16371
16503
|
paymasterAndData,
|
|
16372
16504
|
signature: "0x"
|
|
16373
16505
|
};
|
|
16374
|
-
const
|
|
16375
|
-
const
|
|
16376
|
-
|
|
16377
|
-
|
|
16506
|
+
const nonceKey = BigInt(nonce) >> 64n;
|
|
16507
|
+
const expectedKey = CryptoUtils.bidNonceKey(order.id, order.session);
|
|
16508
|
+
if (nonceKey !== expectedKey) {
|
|
16509
|
+
console.warn(
|
|
16510
|
+
`[BidManager] bid nonce key does not bind the order commitment and session key; on-chain validation will fail (order=${order.id})`
|
|
16511
|
+
);
|
|
16512
|
+
}
|
|
16513
|
+
const solverSignature = await solverSigner.signTypedData(
|
|
16514
|
+
CryptoUtils.packedUserOpTypedData(userOp, entryPointAddress, chainId),
|
|
16515
|
+
Number(chainId)
|
|
16516
|
+
);
|
|
16378
16517
|
const signature = concat([order.id, solverSignature]);
|
|
16379
16518
|
return { ...userOp, signature };
|
|
16380
16519
|
}
|
|
@@ -17299,15 +17438,67 @@ var UnsupportedIntentQuoteStrategyError = class extends Error {
|
|
|
17299
17438
|
var UnsupportedIntentQuotePairError = class extends Error {
|
|
17300
17439
|
constructor(params) {
|
|
17301
17440
|
super(
|
|
17302
|
-
`No Uniswap v4 pool config found for ${params.tokenIn
|
|
17441
|
+
`No ${params.quoteSource ?? "Uniswap v4 pool config"} found for ${params.tokenIn} -> ${params.tokenOut} on ${params.source} -> ${params.destination}`
|
|
17303
17442
|
);
|
|
17304
17443
|
this.name = "UnsupportedIntentQuotePairError";
|
|
17305
17444
|
}
|
|
17306
17445
|
};
|
|
17446
|
+
var PhantomSnapshotUnavailableError = class extends Error {
|
|
17447
|
+
constructor(tokenA, tokenB) {
|
|
17448
|
+
super(`No Phantom order price snapshot found for ${tokenA} -> ${tokenB}`);
|
|
17449
|
+
this.name = "PhantomSnapshotUnavailableError";
|
|
17450
|
+
}
|
|
17451
|
+
};
|
|
17452
|
+
var InvalidPhantomSnapshotError = class extends Error {
|
|
17453
|
+
constructor(commitment, reason) {
|
|
17454
|
+
super(`Invalid Phantom order price snapshot ${commitment}: ${reason}`);
|
|
17455
|
+
this.name = "InvalidPhantomSnapshotError";
|
|
17456
|
+
}
|
|
17457
|
+
};
|
|
17458
|
+
var BPS_DENOMINATOR = 10000n;
|
|
17459
|
+
function validateQuoteParams(params) {
|
|
17460
|
+
const hasAmountIn = params.amountIn !== void 0;
|
|
17461
|
+
const hasAmountOut = params.amountOut !== void 0;
|
|
17462
|
+
if (hasAmountIn === hasAmountOut) throw new Error("Provide exactly one of amountIn or amountOut");
|
|
17463
|
+
if (params.amountIn !== void 0 && params.amountIn <= 0n) throw new Error("amountIn must be greater than zero");
|
|
17464
|
+
if (params.amountOut !== void 0 && params.amountOut <= 0n) throw new Error("amountOut must be greater than zero");
|
|
17465
|
+
if (params.tokenIn.toLowerCase() === params.tokenOut.toLowerCase()) {
|
|
17466
|
+
throw new Error("tokenIn and tokenOut cannot be the same");
|
|
17467
|
+
}
|
|
17468
|
+
}
|
|
17469
|
+
async function readProtocolFeeBps(chainConfigService, source) {
|
|
17470
|
+
const gatewayAddress = chainConfigService.getIntentGatewayAddress(source.stateMachineId);
|
|
17471
|
+
if (!gatewayAddress || gatewayAddress === "0x" || gatewayAddress === zeroAddress) {
|
|
17472
|
+
throw new Error(`IntentGatewayV2 is not configured for chain ${source.stateMachineId}`);
|
|
17473
|
+
}
|
|
17474
|
+
const gatewayParams = await source.client.readContract({
|
|
17475
|
+
address: gatewayAddress,
|
|
17476
|
+
abi: IntentGatewayV2_default.ABI,
|
|
17477
|
+
functionName: "params"
|
|
17478
|
+
});
|
|
17479
|
+
const protocolFeeBps = Array.isArray(gatewayParams) ? BigInt(gatewayParams[4]) : BigInt(gatewayParams.protocolFeeBps ?? 0);
|
|
17480
|
+
if (protocolFeeBps < 0n || protocolFeeBps >= BPS_DENOMINATOR) {
|
|
17481
|
+
throw new Error(`Invalid IntentGateway protocol fee: ${protocolFeeBps} bps`);
|
|
17482
|
+
}
|
|
17483
|
+
return protocolFeeBps;
|
|
17484
|
+
}
|
|
17485
|
+
function deductProtocolFee(amount, protocolFeeBps) {
|
|
17486
|
+
if (protocolFeeBps <= 0n) return amount;
|
|
17487
|
+
const fee = amount * protocolFeeBps / BPS_DENOMINATOR;
|
|
17488
|
+
return amount - fee;
|
|
17489
|
+
}
|
|
17490
|
+
function grossUpForProtocolFee(netAmount, protocolFeeBps) {
|
|
17491
|
+
if (protocolFeeBps <= 0n) return netAmount;
|
|
17492
|
+
if (protocolFeeBps >= BPS_DENOMINATOR) throw new Error("protocolFeeBps must be less than 10,000");
|
|
17493
|
+
return divCeil(netAmount * BPS_DENOMINATOR, BPS_DENOMINATOR - protocolFeeBps);
|
|
17494
|
+
}
|
|
17495
|
+
function divCeil(numerator, denominator) {
|
|
17496
|
+
if (denominator <= 0n) throw new Error("denominator must be greater than zero");
|
|
17497
|
+
return (numerator + denominator - 1n) / denominator;
|
|
17498
|
+
}
|
|
17307
17499
|
|
|
17308
17500
|
// src/protocols/intents/quote/uniswapV4.ts
|
|
17309
17501
|
var UNISWAP_INTENT_QUOTE_CHAIN = "EVM-8453" /* BASE_MAINNET */;
|
|
17310
|
-
var BPS_DENOMINATOR = 10000n;
|
|
17311
17502
|
var UniswapV4IntentQuoteStrategy = class {
|
|
17312
17503
|
constructor(chainConfigService) {
|
|
17313
17504
|
this.chainConfigService = chainConfigService;
|
|
@@ -17315,10 +17506,10 @@ var UniswapV4IntentQuoteStrategy = class {
|
|
|
17315
17506
|
chainConfigService;
|
|
17316
17507
|
baseQuoteClient;
|
|
17317
17508
|
async quote(params, source, destination) {
|
|
17318
|
-
|
|
17319
|
-
const protocolFeeBps = await
|
|
17509
|
+
validateQuoteParams(params);
|
|
17510
|
+
const protocolFeeBps = await readProtocolFeeBps(this.chainConfigService, source);
|
|
17320
17511
|
const quoteClient = this.resolveQuoteClient(source, destination);
|
|
17321
|
-
const poolConfig = this.resolvePoolConfig(params, source.stateMachineId,
|
|
17512
|
+
const poolConfig = this.resolvePoolConfig(params, source.stateMachineId, destination.stateMachineId);
|
|
17322
17513
|
return params.amountIn !== void 0 ? this.quoteExactInput({ params, client: quoteClient, protocolFeeBps, poolConfig }) : this.quoteExactOutput({ params, client: quoteClient, protocolFeeBps, poolConfig });
|
|
17323
17514
|
}
|
|
17324
17515
|
resolveQuoteClient(source, destination) {
|
|
@@ -17334,34 +17525,11 @@ var UniswapV4IntentQuoteStrategy = class {
|
|
|
17334
17525
|
this.baseQuoteClient = baseQuoteClient;
|
|
17335
17526
|
return baseQuoteClient;
|
|
17336
17527
|
}
|
|
17337
|
-
validateQuoteParams(params) {
|
|
17338
|
-
const hasAmountIn = params.amountIn !== void 0;
|
|
17339
|
-
const hasAmountOut = params.amountOut !== void 0;
|
|
17340
|
-
if (hasAmountIn === hasAmountOut) throw new Error("Provide exactly one of amountIn or amountOut");
|
|
17341
|
-
if (hasAmountIn && params.amountIn <= 0n) throw new Error("amountIn must be greater than zero");
|
|
17342
|
-
if (hasAmountOut && params.amountOut <= 0n) throw new Error("amountOut must be greater than zero");
|
|
17343
|
-
if (params.tokenIn.address.toLowerCase() === params.tokenOut.address.toLowerCase()) {
|
|
17344
|
-
throw new Error("tokenIn and tokenOut cannot be the same");
|
|
17345
|
-
}
|
|
17346
|
-
}
|
|
17347
|
-
async readProtocolFeeBps(client, chain) {
|
|
17348
|
-
const gatewayAddress = this.chainConfigService.getIntentGatewayAddress(chain);
|
|
17349
|
-
if (!gatewayAddress || gatewayAddress === "0x" || gatewayAddress === zeroAddress) {
|
|
17350
|
-
throw new Error(`IntentGatewayV2 is not configured for chain ${chain}`);
|
|
17351
|
-
}
|
|
17352
|
-
const gatewayParams = await client.readContract({
|
|
17353
|
-
address: gatewayAddress,
|
|
17354
|
-
abi: IntentGatewayV2_default.ABI,
|
|
17355
|
-
functionName: "params"
|
|
17356
|
-
});
|
|
17357
|
-
if (isGatewayParamsTuple(gatewayParams)) return BigInt(gatewayParams[4]);
|
|
17358
|
-
return BigInt(gatewayParams.protocolFeeBps ?? 0);
|
|
17359
|
-
}
|
|
17360
17528
|
resolvePoolConfig(params, source, destination) {
|
|
17361
17529
|
const override = params.uniswapV4?.poolKey;
|
|
17362
17530
|
if (override) {
|
|
17363
17531
|
const poolKey = normalizePoolKey(override);
|
|
17364
|
-
const tokenInForQuote = getAddress(override.currencyIn ?? params.tokenIn
|
|
17532
|
+
const tokenInForQuote = getAddress(override.currencyIn ?? params.tokenIn);
|
|
17365
17533
|
if (tokenInForQuote !== poolKey.currency0 && tokenInForQuote !== poolKey.currency1) {
|
|
17366
17534
|
throw new Error(
|
|
17367
17535
|
`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.`
|
|
@@ -17369,11 +17537,11 @@ var UniswapV4IntentQuoteStrategy = class {
|
|
|
17369
17537
|
}
|
|
17370
17538
|
return {
|
|
17371
17539
|
poolKey,
|
|
17372
|
-
quoterAddress: this.resolveQuoterAddress(
|
|
17540
|
+
quoterAddress: this.resolveQuoterAddress(UNISWAP_INTENT_QUOTE_CHAIN, override.quoterAddress),
|
|
17373
17541
|
tokenInForQuote
|
|
17374
17542
|
};
|
|
17375
17543
|
}
|
|
17376
|
-
const poolConfig = this.resolveConfiguredPool(params, destination);
|
|
17544
|
+
const poolConfig = this.resolveConfiguredPool(params, source, destination, UNISWAP_INTENT_QUOTE_CHAIN);
|
|
17377
17545
|
if (poolConfig) return poolConfig;
|
|
17378
17546
|
throw new UnsupportedIntentQuotePairError({
|
|
17379
17547
|
source,
|
|
@@ -17382,12 +17550,12 @@ var UniswapV4IntentQuoteStrategy = class {
|
|
|
17382
17550
|
tokenOut: params.tokenOut
|
|
17383
17551
|
});
|
|
17384
17552
|
}
|
|
17385
|
-
resolveConfiguredPool(params,
|
|
17386
|
-
for (const pool of this.chainConfigService.getUniswapV4PoolConfigs(
|
|
17387
|
-
const resolvedPool = this.resolveConfiguredPoolTokens(
|
|
17553
|
+
resolveConfiguredPool(params, sourceChain, destinationChain, quoteChain) {
|
|
17554
|
+
for (const pool of this.chainConfigService.getUniswapV4PoolConfigs(quoteChain)) {
|
|
17555
|
+
const resolvedPool = this.resolveConfiguredPoolTokens(quoteChain, pool);
|
|
17388
17556
|
if (!resolvedPool) continue;
|
|
17389
|
-
const tokenInForQuote = matchPoolToken(params.tokenIn, resolvedPool);
|
|
17390
|
-
const tokenOutForQuote = matchPoolToken(params.tokenOut, resolvedPool);
|
|
17557
|
+
const tokenInForQuote = this.matchPoolToken(params.tokenIn, sourceChain, resolvedPool);
|
|
17558
|
+
const tokenOutForQuote = this.matchPoolToken(params.tokenOut, destinationChain, resolvedPool);
|
|
17391
17559
|
if (!tokenInForQuote || !tokenOutForQuote || tokenInForQuote.symbol === tokenOutForQuote.symbol) continue;
|
|
17392
17560
|
const { currency0, currency1 } = sortCurrencies(resolvedPool[0].address, resolvedPool[1].address);
|
|
17393
17561
|
return {
|
|
@@ -17398,7 +17566,7 @@ var UniswapV4IntentQuoteStrategy = class {
|
|
|
17398
17566
|
tickSpacing: pool.tickSpacing,
|
|
17399
17567
|
hooks: getAddress(pool.hooks ?? zeroAddress)
|
|
17400
17568
|
},
|
|
17401
|
-
quoterAddress: this.resolveQuoterAddress(
|
|
17569
|
+
quoterAddress: this.resolveQuoterAddress(quoteChain),
|
|
17402
17570
|
tokenInForQuote: tokenInForQuote.address
|
|
17403
17571
|
};
|
|
17404
17572
|
}
|
|
@@ -17421,8 +17589,18 @@ var UniswapV4IntentQuoteStrategy = class {
|
|
|
17421
17589
|
if (!address || address === "0x") return null;
|
|
17422
17590
|
return { symbol, address: getAddress(address) };
|
|
17423
17591
|
}
|
|
17592
|
+
matchPoolToken(tokenAddress, orderChain, poolTokens) {
|
|
17593
|
+
const addressMatch = poolTokens.find(
|
|
17594
|
+
(poolToken) => poolToken.address.toLowerCase() === tokenAddress.toLowerCase()
|
|
17595
|
+
);
|
|
17596
|
+
if (addressMatch) return addressMatch;
|
|
17597
|
+
const metadata = this.chainConfigService.getAssetMetadataByAddress(orderChain, tokenAddress);
|
|
17598
|
+
if (!metadata) return null;
|
|
17599
|
+
return poolTokens.find((poolToken) => poolToken.symbol === metadata.symbol) ?? null;
|
|
17600
|
+
}
|
|
17424
17601
|
async quoteExactInput(args) {
|
|
17425
17602
|
const amountIn = args.params.amountIn;
|
|
17603
|
+
if (amountIn === void 0) throw new Error("amountIn is required for an exact-input quote");
|
|
17426
17604
|
const swapAmountIn = deductProtocolFee(amountIn, args.protocolFeeBps);
|
|
17427
17605
|
const amountOut = await this.readV4QuoteExactInput(args.client, args.poolConfig, swapAmountIn);
|
|
17428
17606
|
return {
|
|
@@ -17440,6 +17618,7 @@ var UniswapV4IntentQuoteStrategy = class {
|
|
|
17440
17618
|
}
|
|
17441
17619
|
async quoteExactOutput(args) {
|
|
17442
17620
|
const amountOut = args.params.amountOut;
|
|
17621
|
+
if (amountOut === void 0) throw new Error("amountOut is required for an exact-output quote");
|
|
17443
17622
|
const swapAmountIn = await this.readV4QuoteExactOutput(args.client, args.poolConfig, amountOut);
|
|
17444
17623
|
const amountIn = grossUpForProtocolFee(swapAmountIn, args.protocolFeeBps);
|
|
17445
17624
|
return {
|
|
@@ -17518,34 +17697,125 @@ function sortCurrencies(tokenIn, tokenOut) {
|
|
|
17518
17697
|
const output = getAddress(tokenOut);
|
|
17519
17698
|
return BigInt(input) < BigInt(output) ? { currency0: input, currency1: output } : { currency0: output, currency1: input };
|
|
17520
17699
|
}
|
|
17521
|
-
function matchPoolToken(token, poolTokens) {
|
|
17522
|
-
const tokenAddress = token.address.toLowerCase();
|
|
17523
|
-
const addressMatch = poolTokens.find((poolToken) => poolToken.address.toLowerCase() === tokenAddress);
|
|
17524
|
-
if (addressMatch) return addressMatch;
|
|
17525
|
-
const tokenSymbol = token.symbol?.toUpperCase();
|
|
17526
|
-
if (!tokenSymbol) return null;
|
|
17527
|
-
return poolTokens.find((poolToken) => poolToken.symbol.toUpperCase() === tokenSymbol) ?? null;
|
|
17528
|
-
}
|
|
17529
17700
|
function getZeroForOne(tokenIn, poolKey) {
|
|
17530
17701
|
return getAddress(tokenIn).toLowerCase() === getAddress(poolKey.currency0).toLowerCase();
|
|
17531
17702
|
}
|
|
17532
|
-
|
|
17533
|
-
|
|
17534
|
-
|
|
17535
|
-
|
|
17536
|
-
|
|
17537
|
-
|
|
17538
|
-
|
|
17539
|
-
}
|
|
17540
|
-
|
|
17541
|
-
|
|
17542
|
-
|
|
17703
|
+
|
|
17704
|
+
// src/protocols/intents/quote/phantomSnapshot.ts
|
|
17705
|
+
var PHANTOM_INTENT_QUOTE_CHAIN = "EVM-8453" /* BASE_MAINNET */;
|
|
17706
|
+
var BASE_SNAPSHOT_ASSET_BY_ORDER_ASSET = {
|
|
17707
|
+
USDC: "USDC",
|
|
17708
|
+
USDT: "USDC",
|
|
17709
|
+
cNGN: "cNGN"
|
|
17710
|
+
};
|
|
17711
|
+
var SUPPORTED_BASE_SNAPSHOT_PAIRS = /* @__PURE__ */ new Set(["USDC:cNGN", "cNGN:USDC"]);
|
|
17712
|
+
var PhantomSnapshotIntentQuoteStrategy = class {
|
|
17713
|
+
constructor(chainConfigService, getQueryClient) {
|
|
17714
|
+
this.chainConfigService = chainConfigService;
|
|
17715
|
+
this.getQueryClient = getQueryClient;
|
|
17716
|
+
}
|
|
17717
|
+
chainConfigService;
|
|
17718
|
+
getQueryClient;
|
|
17719
|
+
async quote(params, source, destination) {
|
|
17720
|
+
validateQuoteParams(params);
|
|
17721
|
+
const pair = this.resolveBaseSnapshotPair(params, source.stateMachineId, destination.stateMachineId);
|
|
17722
|
+
if (!pair) {
|
|
17723
|
+
throw new UnsupportedIntentQuotePairError({
|
|
17724
|
+
source: source.stateMachineId,
|
|
17725
|
+
destination: destination.stateMachineId,
|
|
17726
|
+
tokenIn: params.tokenIn,
|
|
17727
|
+
tokenOut: params.tokenOut,
|
|
17728
|
+
quoteSource: "Phantom snapshot pair"
|
|
17729
|
+
});
|
|
17730
|
+
}
|
|
17731
|
+
const queryClient = this.getQueryClient();
|
|
17732
|
+
const [protocolFeeBps, snapshot] = await Promise.all([
|
|
17733
|
+
readProtocolFeeBps(this.chainConfigService, source),
|
|
17734
|
+
_queryLatestPhantomOrderPriceSnapshot({
|
|
17735
|
+
tokenA: pair.tokenA,
|
|
17736
|
+
tokenB: pair.tokenB,
|
|
17737
|
+
queryClient
|
|
17738
|
+
})
|
|
17739
|
+
]);
|
|
17740
|
+
if (!snapshot) throw new PhantomSnapshotUnavailableError(pair.tokenA, pair.tokenB);
|
|
17741
|
+
this.validateSnapshot(snapshot);
|
|
17742
|
+
return this.quoteSnapshot(params, protocolFeeBps, snapshot);
|
|
17743
|
+
}
|
|
17744
|
+
quoteSnapshot(params, protocolFeeBps, snapshot) {
|
|
17745
|
+
if (params.amountIn !== void 0) {
|
|
17746
|
+
const netAmountIn2 = deductProtocolFee(params.amountIn, protocolFeeBps);
|
|
17747
|
+
const amountOut = netAmountIn2 * snapshot.medianPrice / snapshot.standardAmount;
|
|
17748
|
+
if (amountOut <= 0n) {
|
|
17749
|
+
throw new InvalidPhantomSnapshotError(snapshot.commitment, "quote rounds down to zero output");
|
|
17750
|
+
}
|
|
17751
|
+
return this.buildResult("EXACT_INPUT", params.amountIn, amountOut, protocolFeeBps, snapshot);
|
|
17752
|
+
}
|
|
17753
|
+
if (params.amountOut === void 0) throw new Error("Quote amount is missing after validation");
|
|
17754
|
+
const netAmountIn = divCeil(params.amountOut * snapshot.standardAmount, snapshot.medianPrice);
|
|
17755
|
+
const amountIn = grossUpForProtocolFee(netAmountIn, protocolFeeBps);
|
|
17756
|
+
return this.buildResult("EXACT_OUTPUT", amountIn, params.amountOut, protocolFeeBps, snapshot);
|
|
17757
|
+
}
|
|
17758
|
+
buildResult(tradeType, amountIn, amountOut, protocolFeeBps, snapshot) {
|
|
17759
|
+
return {
|
|
17760
|
+
strategy: "phantom_snapshot",
|
|
17761
|
+
tradeType,
|
|
17762
|
+
amountIn,
|
|
17763
|
+
amountOut,
|
|
17764
|
+
quoteMetadata: {
|
|
17765
|
+
quoteChain: PHANTOM_INTENT_QUOTE_CHAIN,
|
|
17766
|
+
commitment: snapshot.commitment,
|
|
17767
|
+
tokenA: snapshot.tokenA,
|
|
17768
|
+
tokenB: snapshot.tokenB,
|
|
17769
|
+
standardAmount: snapshot.standardAmount,
|
|
17770
|
+
medianPrice: snapshot.medianPrice,
|
|
17771
|
+
lowestPrice: snapshot.lowestPrice,
|
|
17772
|
+
highestPrice: snapshot.highestPrice,
|
|
17773
|
+
blockNumber: snapshot.blockNumber,
|
|
17774
|
+
snapshotTime: snapshot.snapshotTime,
|
|
17775
|
+
bidCount: snapshot.bidCount,
|
|
17776
|
+
protocolFeeBps
|
|
17777
|
+
}
|
|
17778
|
+
};
|
|
17779
|
+
}
|
|
17780
|
+
validateSnapshot(snapshot) {
|
|
17781
|
+
if (snapshot.standardAmount <= 0n) {
|
|
17782
|
+
throw new InvalidPhantomSnapshotError(snapshot.commitment, "standardAmount must be greater than zero");
|
|
17783
|
+
}
|
|
17784
|
+
if (snapshot.medianPrice <= 0n) {
|
|
17785
|
+
throw new InvalidPhantomSnapshotError(snapshot.commitment, "medianPrice must be greater than zero");
|
|
17786
|
+
}
|
|
17787
|
+
if (snapshot.bidCount <= 0) {
|
|
17788
|
+
throw new InvalidPhantomSnapshotError(snapshot.commitment, "bidCount must be greater than zero");
|
|
17789
|
+
}
|
|
17790
|
+
if (Number.isNaN(snapshot.snapshotTime.getTime())) {
|
|
17791
|
+
throw new InvalidPhantomSnapshotError(snapshot.commitment, "snapshotTime is invalid");
|
|
17792
|
+
}
|
|
17793
|
+
}
|
|
17794
|
+
resolveBaseSnapshotPair(params, sourceStateMachineId, destinationStateMachineId) {
|
|
17795
|
+
const tokenIn = this.resolveBaseSnapshotToken(sourceStateMachineId, params.tokenIn);
|
|
17796
|
+
const tokenOut = this.resolveBaseSnapshotToken(destinationStateMachineId, params.tokenOut);
|
|
17797
|
+
if (!tokenIn || !tokenOut || !isSupportedSnapshotPair(tokenIn.symbol, tokenOut.symbol)) return;
|
|
17798
|
+
return { tokenA: tokenIn.address, tokenB: tokenOut.address };
|
|
17799
|
+
}
|
|
17800
|
+
resolveBaseSnapshotToken(chain, tokenAddress) {
|
|
17801
|
+
const orderAsset = this.chainConfigService.getAssetMetadataByAddress(chain, tokenAddress)?.symbol;
|
|
17802
|
+
if (!orderAsset) return;
|
|
17803
|
+
const snapshotAsset = BASE_SNAPSHOT_ASSET_BY_ORDER_ASSET[orderAsset];
|
|
17804
|
+
if (!snapshotAsset) return;
|
|
17805
|
+
const address = this.chainConfigService.getAssetAddress(PHANTOM_INTENT_QUOTE_CHAIN, snapshotAsset);
|
|
17806
|
+
if (!isConfiguredAddress(address)) return;
|
|
17807
|
+
return { symbol: snapshotAsset, address };
|
|
17808
|
+
}
|
|
17809
|
+
};
|
|
17810
|
+
function isSupportedSnapshotPair(tokenA, tokenB) {
|
|
17811
|
+
return SUPPORTED_BASE_SNAPSHOT_PAIRS.has(`${tokenA}:${tokenB}`);
|
|
17543
17812
|
}
|
|
17544
|
-
function
|
|
17545
|
-
return (
|
|
17813
|
+
function isConfiguredAddress(address) {
|
|
17814
|
+
return Boolean(address && address !== "0x" && !/^0x0{40}$/i.test(address));
|
|
17546
17815
|
}
|
|
17547
17816
|
|
|
17548
17817
|
// src/protocols/intents/IntentGateway.ts
|
|
17818
|
+
var CROSS_CHAIN_ORDER_FEE_GAS_BUMP = 600000n;
|
|
17549
17819
|
var IntentGateway = class _IntentGateway {
|
|
17550
17820
|
/** EVM chain on which orders are placed and escrowed. */
|
|
17551
17821
|
source;
|
|
@@ -17617,6 +17887,10 @@ var IntentGateway = class _IntentGateway {
|
|
|
17617
17887
|
this.gasEstimator = gasEstimator;
|
|
17618
17888
|
this._crypto = crypto;
|
|
17619
17889
|
this.quoteStrategies = {
|
|
17890
|
+
phantom_snapshot: new PhantomSnapshotIntentQuoteStrategy(
|
|
17891
|
+
dest.configService,
|
|
17892
|
+
() => this.requireIndexer().queryClient
|
|
17893
|
+
),
|
|
17620
17894
|
uniswap_v4: new UniswapV4IntentQuoteStrategy(dest.configService)
|
|
17621
17895
|
};
|
|
17622
17896
|
}
|
|
@@ -17666,37 +17940,39 @@ var IntentGateway = class _IntentGateway {
|
|
|
17666
17940
|
/**
|
|
17667
17941
|
* Quotes an intent between this gateway's source and destination chains.
|
|
17668
17942
|
*
|
|
17669
|
-
*
|
|
17670
|
-
*
|
|
17943
|
+
* Uses the latest directional Phantom order price snapshot from the attached
|
|
17944
|
+
* indexer by default. Pass `strategy: "uniswap_v4"` only when explicitly
|
|
17945
|
+
* requesting a Uniswap quote. Provide exactly one of `amountIn` or `amountOut`.
|
|
17671
17946
|
*
|
|
17672
|
-
*
|
|
17673
|
-
*
|
|
17947
|
+
* Both built-in strategies resolve their canonical market on Base,
|
|
17948
|
+
* regardless of this gateway's destination chain. Returned
|
|
17674
17949
|
* `amountIn`/`amountOut` already account for the gateway's protocol fee
|
|
17675
17950
|
* (`quoteMetadata.protocolFeeBps`), which the gateway deducts from order
|
|
17676
|
-
* inputs;
|
|
17951
|
+
* inputs; use the returned amounts directly when placing the order.
|
|
17677
17952
|
*
|
|
17678
17953
|
* @param params - Token pair, amount, and optional strategy/pool overrides.
|
|
17679
17954
|
* @returns The quoted amounts plus strategy-specific metadata.
|
|
17680
17955
|
* @throws {UnsupportedIntentQuoteStrategyError} For unknown strategies.
|
|
17681
|
-
* @throws {UnsupportedIntentQuotePairError} When
|
|
17956
|
+
* @throws {UnsupportedIntentQuotePairError} When the selected strategy does not support the pair.
|
|
17957
|
+
* @throws {PhantomSnapshotUnavailableError} When an eligible cNGN pair has no snapshot.
|
|
17682
17958
|
*/
|
|
17683
17959
|
async quoteIntent(params) {
|
|
17684
|
-
const
|
|
17960
|
+
const source = { stateMachineId: this.source.config.stateMachineId, client: this.source.client };
|
|
17961
|
+
const destination = { stateMachineId: this.dest.config.stateMachineId, client: this.dest.client };
|
|
17962
|
+
const strategy = params.strategy ?? "phantom_snapshot";
|
|
17685
17963
|
const handler = this.quoteStrategies[strategy];
|
|
17686
17964
|
if (!handler) throw new UnsupportedIntentQuoteStrategyError(strategy);
|
|
17687
|
-
return handler.quote(
|
|
17688
|
-
{ ...params, strategy },
|
|
17689
|
-
{ stateMachineId: this.source.config.stateMachineId, client: this.source.client },
|
|
17690
|
-
{ stateMachineId: this.dest.config.stateMachineId, client: this.dest.client }
|
|
17691
|
-
);
|
|
17965
|
+
return handler.quote({ ...params, strategy }, source, destination);
|
|
17692
17966
|
}
|
|
17693
17967
|
/**
|
|
17694
17968
|
* Bidirectional async generator that orchestrates the full order lifecycle:
|
|
17695
17969
|
* placement, fee estimation, bid collection, and execution.
|
|
17696
17970
|
*
|
|
17697
17971
|
* **Yield/receive protocol:**
|
|
17698
|
-
* 1. If `order.fees` is unset or zero, estimates gas and sets
|
|
17699
|
-
*
|
|
17972
|
+
* 1. If `order.fees` is unset or zero, estimates gas and sets same-chain
|
|
17973
|
+
* `order.fees` to twice the estimate. Cross-chain orders retain a 1% buffer
|
|
17974
|
+
* and include an additional 600k-gas fee uplift, while the wei cost used for
|
|
17975
|
+
* the `value` field receives a 2% buffer.
|
|
17700
17976
|
* 2. Yields `AWAITING_PLACE_ORDER` with `{ to, data, value, sessionPrivateKey }`.
|
|
17701
17977
|
* The caller must sign the transaction and pass it back via `gen.next(signedTx)`.
|
|
17702
17978
|
* 3. Yields `ORDER_PLACED` with the finalised order and transaction hash once
|
|
@@ -17728,8 +18004,15 @@ var IntentGateway = class _IntentGateway {
|
|
|
17728
18004
|
if (estimate.totalGasCostWei === 0n || estimate.totalGasInFeeToken === 0n) {
|
|
17729
18005
|
throw new Error("Gas estimation failed");
|
|
17730
18006
|
}
|
|
18007
|
+
const isSameChain = this.source.config.stateMachineId === this.dest.config.stateMachineId;
|
|
17731
18008
|
value = estimate.totalGasCostWei + estimate.totalGasCostWei * 2n / 100n;
|
|
17732
|
-
|
|
18009
|
+
const crossChainFeeBump = isSameChain ? 0n : await convertGasToFeeToken(
|
|
18010
|
+
this.ctx,
|
|
18011
|
+
CROSS_CHAIN_ORDER_FEE_GAS_BUMP,
|
|
18012
|
+
"source",
|
|
18013
|
+
this.source.config.stateMachineId
|
|
18014
|
+
);
|
|
18015
|
+
order.fees = isSameChain ? estimate.totalGasInFeeToken * 2n : estimate.totalGasInFeeToken + (crossChainFeeBump + estimate.totalGasInFeeToken * 1n / 100n);
|
|
17733
18016
|
}
|
|
17734
18017
|
const placeOrderGen = this.orderPlacer.placeOrder(order, graffiti);
|
|
17735
18018
|
const placeOrderFirst = await placeOrderGen.next();
|
|
@@ -18110,7 +18393,9 @@ var IntentGateway = class _IntentGateway {
|
|
|
18110
18393
|
}
|
|
18111
18394
|
requireIndexer() {
|
|
18112
18395
|
if (!this.indexer) {
|
|
18113
|
-
throw new Error(
|
|
18396
|
+
throw new Error(
|
|
18397
|
+
"IntentGateway: call withQueryClient(queryClient) before using indexer-backed methods or Phantom quotes"
|
|
18398
|
+
);
|
|
18114
18399
|
}
|
|
18115
18400
|
return this.indexer;
|
|
18116
18401
|
}
|
|
@@ -22624,6 +22909,6 @@ async function teleportDot(param_) {
|
|
|
22624
22909
|
return stream;
|
|
22625
22910
|
}
|
|
22626
22911
|
|
|
22627
|
-
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 };
|
|
22912
|
+
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 };
|
|
22628
22913
|
//# sourceMappingURL=index.js.map
|
|
22629
22914
|
//# sourceMappingURL=index.js.map
|