@hyperbridge/sdk 1.3.4 → 1.3.5
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 +30 -5
- package/dist/browser/index.js +194 -71
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.d.ts +30 -5
- package/dist/node/index.js +194 -71
- package/dist/node/index.js.map +1 -1
- package/package.json +2 -2
package/dist/browser/index.d.ts
CHANGED
|
@@ -941,6 +941,7 @@ interface GetRequestWithStatus extends GenericRequestWithStatuses {
|
|
|
941
941
|
height: bigint;
|
|
942
942
|
keys: HexString[];
|
|
943
943
|
context: HexString;
|
|
944
|
+
commitment: HexString;
|
|
944
945
|
}
|
|
945
946
|
interface GetResponseByRequestIdResponse {
|
|
946
947
|
getResponses: {
|
|
@@ -2262,14 +2263,14 @@ declare class IndexerClient {
|
|
|
2262
2263
|
* @param commitment_hash - Can be commitment
|
|
2263
2264
|
* @returns Latest status and block metadata of the request
|
|
2264
2265
|
*/
|
|
2265
|
-
queryPostRequest(commitment_hash:
|
|
2266
|
+
queryPostRequest(commitment_hash: HexString): Promise<PostRequestWithStatus | undefined>;
|
|
2266
2267
|
/**
|
|
2267
2268
|
* Queries a request by any of its associated hashes and returns it alongside its statuses
|
|
2268
2269
|
* Statuses will be one of SOURCE, HYPERBRIDGE_DELIVERED and DESTINATION
|
|
2269
2270
|
* @param hash - Can be commitment, hyperbridge tx hash, source tx hash, destination tx hash, or timeout tx hash
|
|
2270
2271
|
* @returns Latest status and block metadata of the request
|
|
2271
2272
|
*/
|
|
2272
|
-
queryGetRequest(hash:
|
|
2273
|
+
queryGetRequest(hash: HexString): Promise<GetRequestWithStatus | undefined>;
|
|
2273
2274
|
/**
|
|
2274
2275
|
* Queries the response associated with a specific request ID and returns its commitment
|
|
2275
2276
|
* @param requestId - The ID of the request to find the associated response for
|
|
@@ -2316,7 +2317,31 @@ declare class IndexerClient {
|
|
|
2316
2317
|
* @returns Full request data with all inferred status events, including SOURCE_FINALIZED and HYPERBRIDGE_FINALIZED
|
|
2317
2318
|
* @remarks Unlike queryRequest(), this method adds derived finalization status events by querying state machine updates
|
|
2318
2319
|
*/
|
|
2319
|
-
queryRequestWithStatus(hash:
|
|
2320
|
+
queryRequestWithStatus(hash: HexString): Promise<PostRequestWithStatus | undefined>;
|
|
2321
|
+
/**
|
|
2322
|
+
* Queries a GET request and returns it alongside its statuses,
|
|
2323
|
+
* including any finalization events.
|
|
2324
|
+
* @param hash - Can be commitment, hyperbridge tx hash, source tx hash, destination tx hash, or timeout tx hash
|
|
2325
|
+
* @returns Full GET request data with all inferred status events, including SOURCE_FINALIZED and HYPERBRIDGE_FINALIZED
|
|
2326
|
+
* @remarks Unlike queryGetRequest(), this method adds derived finalization status events by querying state machine updates
|
|
2327
|
+
*/
|
|
2328
|
+
queryGetRequestWithStatus(hash: HexString): Promise<GetRequestWithStatus | undefined>;
|
|
2329
|
+
/**
|
|
2330
|
+
* Enhances a GET request with finality events by querying state machine updates.
|
|
2331
|
+
*
|
|
2332
|
+
* This method augments a GET request object with additional inferred status events
|
|
2333
|
+
* that represent chain finality confirmations. It adds:
|
|
2334
|
+
* - SOURCE_FINALIZED: When the source chain has finalized the request
|
|
2335
|
+
* - HYPERBRIDGE_FINALIZED: When Hyperbridge has finalized the delivery confirmation and response is ready
|
|
2336
|
+
*
|
|
2337
|
+
* The method also generates appropriate calldata for submitting cross-chain proofs
|
|
2338
|
+
* when applicable.
|
|
2339
|
+
*
|
|
2340
|
+
* @param request - The GET request to enhance with finality events
|
|
2341
|
+
* @returns The request with finality events added
|
|
2342
|
+
* @private
|
|
2343
|
+
*/
|
|
2344
|
+
private addGetRequestFinalityEvents;
|
|
2320
2345
|
/**
|
|
2321
2346
|
* Create a Stream of status updates for a post request.
|
|
2322
2347
|
* Stream ends when either the request reaches the destination or times out.
|
|
@@ -2596,7 +2621,7 @@ declare class IntentGateway {
|
|
|
2596
2621
|
* @param amountOut - The desired output amount
|
|
2597
2622
|
* @returns Object containing the best protocol, required input amount, and fee tier (for V3/V4)
|
|
2598
2623
|
*/
|
|
2599
|
-
findBestProtocolWithAmountOut(
|
|
2624
|
+
findBestProtocolWithAmountOut(getQuoteIn: "source" | "dest", tokenIn: HexString, tokenOut: HexString, amountOut: bigint): Promise<{
|
|
2600
2625
|
protocol: "v2" | "v3" | "v4" | null;
|
|
2601
2626
|
amountIn: bigint;
|
|
2602
2627
|
fee?: number;
|
|
@@ -2611,7 +2636,7 @@ declare class IntentGateway {
|
|
|
2611
2636
|
* @param amountIn - The input amount to swap
|
|
2612
2637
|
* @returns Object containing the best protocol, expected output amount, and fee tier (for V3/V4)
|
|
2613
2638
|
*/
|
|
2614
|
-
findBestProtocolWithAmountIn(
|
|
2639
|
+
findBestProtocolWithAmountIn(getQuoteIn: "source" | "dest", tokenIn: HexString, tokenOut: HexString, amountIn: bigint, selectedProtocol?: "v2" | "v3" | "v4"): Promise<{
|
|
2615
2640
|
protocol: "v2" | "v3" | "v4" | null;
|
|
2616
2641
|
amountOut: bigint;
|
|
2617
2642
|
fee?: number;
|
package/dist/browser/index.js
CHANGED
|
@@ -3459,18 +3459,18 @@ var addresses = {
|
|
|
3459
3459
|
["EVM-10200" /* GNOSIS_CHIADO */]: "0x0000000000000000000000000000000000000000",
|
|
3460
3460
|
["EVM-11155111" /* SEPOLIA */]: "0x0000000000000000000000000000000000000000",
|
|
3461
3461
|
["EVM-1" /* MAINNET */]: "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
|
|
3462
|
-
["EVM-56" /* BSC_MAINNET */]: "
|
|
3463
|
-
["EVM-42161" /* ARBITRUM_MAINNET */]: "
|
|
3464
|
-
["EVM-8453" /* BASE_MAINNET */]: "
|
|
3462
|
+
["EVM-56" /* BSC_MAINNET */]: "0x10ED43C718714eb63d5aA57B78B54704E256024E",
|
|
3463
|
+
["EVM-42161" /* ARBITRUM_MAINNET */]: "0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24",
|
|
3464
|
+
["EVM-8453" /* BASE_MAINNET */]: "0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24"
|
|
3465
3465
|
},
|
|
3466
3466
|
UniswapV2Factory: {
|
|
3467
3467
|
["EVM-97" /* BSC_CHAPEL */]: "0x12e036669DA18F4A2777853d6e2136b32AceEC86",
|
|
3468
3468
|
["EVM-10200" /* GNOSIS_CHIADO */]: "0x0000000000000000000000000000000000000000",
|
|
3469
3469
|
["EVM-11155111" /* SEPOLIA */]: "0x0000000000000000000000000000000000000000",
|
|
3470
3470
|
["EVM-1" /* MAINNET */]: "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
|
|
3471
|
-
["EVM-56" /* BSC_MAINNET */]: "
|
|
3472
|
-
["EVM-42161" /* ARBITRUM_MAINNET */]: "
|
|
3473
|
-
["EVM-8453" /* BASE_MAINNET */]: "
|
|
3471
|
+
["EVM-56" /* BSC_MAINNET */]: "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73",
|
|
3472
|
+
["EVM-42161" /* ARBITRUM_MAINNET */]: "0xf1D7CC64Fb4452F05c498126312eBE29f30Fbcf9",
|
|
3473
|
+
["EVM-8453" /* BASE_MAINNET */]: "0x8909Dc15e40173Ff4699343b6eB8132c65e18eC6"
|
|
3474
3474
|
},
|
|
3475
3475
|
BatchExecutor: {
|
|
3476
3476
|
["EVM-97" /* BSC_CHAPEL */]: "0x4CC58B5D8FBf838d062E4b21F75C327835B5F0ef",
|
|
@@ -5741,6 +5741,7 @@ async function _queryGetRequestInternal(params) {
|
|
|
5741
5741
|
const { statusMetadata, ...rest } = response.getRequests.nodes[0];
|
|
5742
5742
|
return {
|
|
5743
5743
|
...rest,
|
|
5744
|
+
commitment: commitmentHash,
|
|
5744
5745
|
timeoutTimestamp: BigInt(rest.timeoutTimestamp),
|
|
5745
5746
|
nonce: BigInt(rest.nonce),
|
|
5746
5747
|
height: BigInt(rest.height),
|
|
@@ -6158,6 +6159,120 @@ var IndexerClient = class {
|
|
|
6158
6159
|
);
|
|
6159
6160
|
return request;
|
|
6160
6161
|
}
|
|
6162
|
+
/**
|
|
6163
|
+
* Queries a GET request and returns it alongside its statuses,
|
|
6164
|
+
* including any finalization events.
|
|
6165
|
+
* @param hash - Can be commitment, hyperbridge tx hash, source tx hash, destination tx hash, or timeout tx hash
|
|
6166
|
+
* @returns Full GET request data with all inferred status events, including SOURCE_FINALIZED and HYPERBRIDGE_FINALIZED
|
|
6167
|
+
* @remarks Unlike queryGetRequest(), this method adds derived finalization status events by querying state machine updates
|
|
6168
|
+
*/
|
|
6169
|
+
async queryGetRequestWithStatus(hash) {
|
|
6170
|
+
let request = await this.queryGetRequest(hash);
|
|
6171
|
+
if (!request) return;
|
|
6172
|
+
request = await this.addGetRequestFinalityEvents(request);
|
|
6173
|
+
request.statuses = request.statuses.sort(
|
|
6174
|
+
(a, b) => COMBINED_STATUS_WEIGHTS[a.status] - COMBINED_STATUS_WEIGHTS[b.status]
|
|
6175
|
+
);
|
|
6176
|
+
return request;
|
|
6177
|
+
}
|
|
6178
|
+
/**
|
|
6179
|
+
* Enhances a GET request with finality events by querying state machine updates.
|
|
6180
|
+
*
|
|
6181
|
+
* This method augments a GET request object with additional inferred status events
|
|
6182
|
+
* that represent chain finality confirmations. It adds:
|
|
6183
|
+
* - SOURCE_FINALIZED: When the source chain has finalized the request
|
|
6184
|
+
* - HYPERBRIDGE_FINALIZED: When Hyperbridge has finalized the delivery confirmation and response is ready
|
|
6185
|
+
*
|
|
6186
|
+
* The method also generates appropriate calldata for submitting cross-chain proofs
|
|
6187
|
+
* when applicable.
|
|
6188
|
+
*
|
|
6189
|
+
* @param request - The GET request to enhance with finality events
|
|
6190
|
+
* @returns The request with finality events added
|
|
6191
|
+
* @private
|
|
6192
|
+
*/
|
|
6193
|
+
async addGetRequestFinalityEvents(request) {
|
|
6194
|
+
const events = [];
|
|
6195
|
+
const addFinalityEvents = (request2) => {
|
|
6196
|
+
this.logger.trace(`Added ${events.length} \`GetRequest\` finality events`, events);
|
|
6197
|
+
request2.statuses = [...request2.statuses, ...events];
|
|
6198
|
+
return request2;
|
|
6199
|
+
};
|
|
6200
|
+
let hyperbridgeDelivered;
|
|
6201
|
+
if (request.source === this.config.hyperbridge.stateMachineId) {
|
|
6202
|
+
hyperbridgeDelivered = request.statuses[0];
|
|
6203
|
+
return addFinalityEvents(request);
|
|
6204
|
+
} else {
|
|
6205
|
+
const sourceFinality = await this.queryStateMachineUpdateByHeight({
|
|
6206
|
+
statemachineId: request.source,
|
|
6207
|
+
height: request.statuses[0].metadata.blockNumber,
|
|
6208
|
+
chain: this.config.hyperbridge.stateMachineId
|
|
6209
|
+
});
|
|
6210
|
+
if (!sourceFinality) return addFinalityEvents(request);
|
|
6211
|
+
events.push({
|
|
6212
|
+
status: RequestStatus.SOURCE_FINALIZED,
|
|
6213
|
+
metadata: {
|
|
6214
|
+
blockHash: sourceFinality.blockHash,
|
|
6215
|
+
blockNumber: sourceFinality.height,
|
|
6216
|
+
transactionHash: sourceFinality.transactionHash,
|
|
6217
|
+
timestamp: sourceFinality.timestamp
|
|
6218
|
+
}
|
|
6219
|
+
});
|
|
6220
|
+
hyperbridgeDelivered = request.statuses.find((item) => item.status === RequestStatus.HYPERBRIDGE_DELIVERED);
|
|
6221
|
+
if (!hyperbridgeDelivered) return addFinalityEvents(request);
|
|
6222
|
+
}
|
|
6223
|
+
const hyperbridgeFinality = await this.queryStateMachineUpdateByHeight({
|
|
6224
|
+
statemachineId: this.config.hyperbridge.stateMachineId,
|
|
6225
|
+
height: hyperbridgeDelivered.metadata.blockNumber,
|
|
6226
|
+
chain: request.source
|
|
6227
|
+
});
|
|
6228
|
+
if (!hyperbridgeFinality) return addFinalityEvents(request);
|
|
6229
|
+
const sourceChain = await getChain(this.config.source);
|
|
6230
|
+
const hyperbridge = await getChain({
|
|
6231
|
+
...this.config.hyperbridge,
|
|
6232
|
+
hasher: "Keccak"
|
|
6233
|
+
});
|
|
6234
|
+
try {
|
|
6235
|
+
const response = await this.queryResponseByRequestId(request.commitment);
|
|
6236
|
+
if (!response) return addFinalityEvents(request);
|
|
6237
|
+
const proof = await hyperbridge.queryProof(
|
|
6238
|
+
{ Responses: [response.commitment] },
|
|
6239
|
+
request.source,
|
|
6240
|
+
BigInt(hyperbridgeFinality.height)
|
|
6241
|
+
);
|
|
6242
|
+
const calldata = sourceChain.encode({
|
|
6243
|
+
kind: "GetResponse",
|
|
6244
|
+
proof: {
|
|
6245
|
+
stateMachine: this.config.hyperbridge.stateMachineId,
|
|
6246
|
+
consensusStateId: this.config.hyperbridge.consensusStateId,
|
|
6247
|
+
proof,
|
|
6248
|
+
height: BigInt(hyperbridgeFinality.height)
|
|
6249
|
+
},
|
|
6250
|
+
responses: [
|
|
6251
|
+
{
|
|
6252
|
+
get: request,
|
|
6253
|
+
values: request.keys.map((key, index) => ({
|
|
6254
|
+
key,
|
|
6255
|
+
value: response.values[index] || "0x"
|
|
6256
|
+
}))
|
|
6257
|
+
}
|
|
6258
|
+
],
|
|
6259
|
+
signer: pad("0x")
|
|
6260
|
+
});
|
|
6261
|
+
events.push({
|
|
6262
|
+
status: RequestStatus.HYPERBRIDGE_FINALIZED,
|
|
6263
|
+
metadata: {
|
|
6264
|
+
blockHash: hyperbridgeFinality.blockHash,
|
|
6265
|
+
blockNumber: hyperbridgeFinality.height,
|
|
6266
|
+
transactionHash: hyperbridgeFinality.transactionHash,
|
|
6267
|
+
timestamp: hyperbridgeFinality.timestamp,
|
|
6268
|
+
calldata
|
|
6269
|
+
}
|
|
6270
|
+
});
|
|
6271
|
+
} catch (error) {
|
|
6272
|
+
this.logger.trace("Could not generate HYPERBRIDGE_FINALIZED event for GET request:", error);
|
|
6273
|
+
}
|
|
6274
|
+
return addFinalityEvents(request);
|
|
6275
|
+
}
|
|
6161
6276
|
/**
|
|
6162
6277
|
* Create a Stream of status updates for a post request.
|
|
6163
6278
|
* Stream ends when either the request reaches the destination or times out.
|
|
@@ -11451,14 +11566,10 @@ var IntentGateway = class {
|
|
|
11451
11566
|
from: this.source.config.getIntentGatewayAddress(order.destChain),
|
|
11452
11567
|
to: this.source.config.getIntentGatewayAddress(order.sourceChain)
|
|
11453
11568
|
};
|
|
11454
|
-
const { decimals: sourceChainFeeTokenDecimals
|
|
11569
|
+
const { decimals: sourceChainFeeTokenDecimals } = await this.source.getFeeTokenWithDecimals();
|
|
11455
11570
|
const { address: destChainFeeTokenAddress, decimals: destChainFeeTokenDecimals } = await this.dest.getFeeTokenWithDecimals();
|
|
11456
11571
|
const { gas: postGasEstimate, postRequestCalldata } = await this.source.estimateGas(postRequest);
|
|
11457
|
-
const postGasEstimateInSourceFeeToken = await this.convertGasToFeeToken(
|
|
11458
|
-
postGasEstimate,
|
|
11459
|
-
this.source.client,
|
|
11460
|
-
sourceChainFeeTokenDecimals
|
|
11461
|
-
);
|
|
11572
|
+
const postGasEstimateInSourceFeeToken = await this.convertGasToFeeToken(postGasEstimate, "source");
|
|
11462
11573
|
const relayerFeeInSourceFeeToken = postGasEstimateInSourceFeeToken + 25n * 10n ** BigInt(sourceChainFeeTokenDecimals - 2);
|
|
11463
11574
|
const relayerFeeInDestFeeToken = adjustFeeDecimals(
|
|
11464
11575
|
relayerFeeInSourceFeeToken,
|
|
@@ -11559,9 +11670,10 @@ var IntentGateway = class {
|
|
|
11559
11670
|
stateOverride: stateOverrides
|
|
11560
11671
|
});
|
|
11561
11672
|
}
|
|
11562
|
-
const
|
|
11563
|
-
|
|
11564
|
-
|
|
11673
|
+
const fillGasInDestFeeToken = await this.convertGasToFeeToken(destChainFillGas, "dest");
|
|
11674
|
+
const fillGasInSourceFeeToken = adjustFeeDecimals(
|
|
11675
|
+
fillGasInDestFeeToken,
|
|
11676
|
+
destChainFeeTokenDecimals,
|
|
11565
11677
|
sourceChainFeeTokenDecimals
|
|
11566
11678
|
);
|
|
11567
11679
|
const protocolFeeInSourceFeeToken = adjustFeeDecimals(
|
|
@@ -11574,11 +11686,7 @@ var IntentGateway = class {
|
|
|
11574
11686
|
const SWAP_OPERATIONS_BPS = 3500n;
|
|
11575
11687
|
const swapOperationsInFeeToken = totalEstimate * SWAP_OPERATIONS_BPS / 10000n;
|
|
11576
11688
|
const totalFeeTokenAmount = totalEstimate + swapOperationsInFeeToken;
|
|
11577
|
-
const totalNativeTokenAmount = await this.convertFeeTokenToNative(
|
|
11578
|
-
totalFeeTokenAmount,
|
|
11579
|
-
this.source.client,
|
|
11580
|
-
sourceChainFeeTokenDecimals
|
|
11581
|
-
);
|
|
11689
|
+
const totalNativeTokenAmount = await this.convertFeeTokenToNative(totalFeeTokenAmount, "source");
|
|
11582
11690
|
return {
|
|
11583
11691
|
feeTokenAmount: totalFeeTokenAmount,
|
|
11584
11692
|
nativeTokenAmount: totalNativeTokenAmount,
|
|
@@ -11595,16 +11703,19 @@ var IntentGateway = class {
|
|
|
11595
11703
|
* @returns The fee token amount converted to native token amount
|
|
11596
11704
|
* @private
|
|
11597
11705
|
*/
|
|
11598
|
-
async convertFeeTokenToNative(feeTokenAmount,
|
|
11599
|
-
const
|
|
11600
|
-
const
|
|
11601
|
-
|
|
11602
|
-
|
|
11603
|
-
}
|
|
11604
|
-
|
|
11605
|
-
|
|
11606
|
-
|
|
11607
|
-
|
|
11706
|
+
async convertFeeTokenToNative(feeTokenAmount, getQuoteIn) {
|
|
11707
|
+
const client = this[getQuoteIn].client;
|
|
11708
|
+
const evmChainID = `EVM-${client.chain?.id}`;
|
|
11709
|
+
const wethAsset = this[getQuoteIn].config.getWrappedNativeAssetWithDecimals(evmChainID).asset;
|
|
11710
|
+
const feeToken = await this[getQuoteIn].getFeeTokenWithDecimals();
|
|
11711
|
+
const { amountOut } = await this.findBestProtocolWithAmountIn(
|
|
11712
|
+
getQuoteIn,
|
|
11713
|
+
feeToken.address,
|
|
11714
|
+
wethAsset,
|
|
11715
|
+
feeTokenAmount,
|
|
11716
|
+
"v2"
|
|
11717
|
+
);
|
|
11718
|
+
return amountOut;
|
|
11608
11719
|
}
|
|
11609
11720
|
/**
|
|
11610
11721
|
* Converts gas costs to the equivalent amount in the fee token (DAI).
|
|
@@ -11616,20 +11727,21 @@ var IntentGateway = class {
|
|
|
11616
11727
|
* @returns The gas cost converted to fee token amount
|
|
11617
11728
|
* @private
|
|
11618
11729
|
*/
|
|
11619
|
-
async convertGasToFeeToken(gasEstimate,
|
|
11620
|
-
const
|
|
11730
|
+
async convertGasToFeeToken(gasEstimate, gasEstimateIn) {
|
|
11731
|
+
const client = this[gasEstimateIn].client;
|
|
11732
|
+
const gasPrice = await client.getGasPrice();
|
|
11621
11733
|
const gasCostInWei = gasEstimate * gasPrice;
|
|
11622
|
-
const
|
|
11623
|
-
const
|
|
11624
|
-
|
|
11625
|
-
|
|
11626
|
-
|
|
11627
|
-
|
|
11628
|
-
|
|
11629
|
-
|
|
11630
|
-
|
|
11631
|
-
|
|
11632
|
-
return
|
|
11734
|
+
const evmChainID = `EVM-${client.chain?.id}`;
|
|
11735
|
+
const wethAddr = this[gasEstimateIn].config.getWrappedNativeAssetWithDecimals(evmChainID).asset;
|
|
11736
|
+
const feeToken = await this[gasEstimateIn].getFeeTokenWithDecimals();
|
|
11737
|
+
const { amountOut } = await this.findBestProtocolWithAmountIn(
|
|
11738
|
+
gasEstimateIn,
|
|
11739
|
+
wethAddr,
|
|
11740
|
+
feeToken.address,
|
|
11741
|
+
gasCostInWei,
|
|
11742
|
+
"v2"
|
|
11743
|
+
);
|
|
11744
|
+
return amountOut;
|
|
11633
11745
|
}
|
|
11634
11746
|
async quoteNative(postRequest, fee) {
|
|
11635
11747
|
const dispatchPost = {
|
|
@@ -11658,31 +11770,32 @@ var IntentGateway = class {
|
|
|
11658
11770
|
* @param amountOut - The desired output amount
|
|
11659
11771
|
* @returns Object containing the best protocol, required input amount, and fee tier (for V3/V4)
|
|
11660
11772
|
*/
|
|
11661
|
-
async findBestProtocolWithAmountOut(
|
|
11662
|
-
const
|
|
11773
|
+
async findBestProtocolWithAmountOut(getQuoteIn, tokenIn, tokenOut, amountOut) {
|
|
11774
|
+
const client = this[getQuoteIn].client;
|
|
11775
|
+
const evmChainID = `EVM-${client.chain?.id}`;
|
|
11663
11776
|
let amountInV2 = maxUint256;
|
|
11664
11777
|
let amountInV3 = maxUint256;
|
|
11665
11778
|
let amountInV4 = maxUint256;
|
|
11666
11779
|
let bestV3Fee = 0;
|
|
11667
11780
|
let bestV4Fee = 0;
|
|
11668
11781
|
const commonFees = [100, 500, 3e3, 1e4];
|
|
11669
|
-
const v2Router = this.source.config.getUniswapRouterV2Address(
|
|
11670
|
-
const v2Factory = this.source.config.getUniswapV2FactoryAddress(
|
|
11671
|
-
const v3Factory = this.source.config.getUniswapV3FactoryAddress(
|
|
11672
|
-
const v3Quoter = this.source.config.getUniswapV3QuoterAddress(
|
|
11673
|
-
const v4Quoter = this.source.config.getUniswapV4QuoterAddress(
|
|
11674
|
-
const wethAsset = this.source.config.getWrappedNativeAssetWithDecimals(
|
|
11782
|
+
const v2Router = this.source.config.getUniswapRouterV2Address(evmChainID);
|
|
11783
|
+
const v2Factory = this.source.config.getUniswapV2FactoryAddress(evmChainID);
|
|
11784
|
+
const v3Factory = this.source.config.getUniswapV3FactoryAddress(evmChainID);
|
|
11785
|
+
const v3Quoter = this.source.config.getUniswapV3QuoterAddress(evmChainID);
|
|
11786
|
+
const v4Quoter = this.source.config.getUniswapV4QuoterAddress(evmChainID);
|
|
11787
|
+
const wethAsset = this.source.config.getWrappedNativeAssetWithDecimals(evmChainID).asset;
|
|
11675
11788
|
const tokenInForQuote = tokenIn === ADDRESS_ZERO ? wethAsset : tokenIn;
|
|
11676
11789
|
const tokenOutForQuote = tokenOut === ADDRESS_ZERO ? wethAsset : tokenOut;
|
|
11677
11790
|
try {
|
|
11678
|
-
const v2PairExists = await
|
|
11791
|
+
const v2PairExists = await client.readContract({
|
|
11679
11792
|
address: v2Factory,
|
|
11680
11793
|
abi: uniswapV2Factory_default.ABI,
|
|
11681
11794
|
functionName: "getPair",
|
|
11682
11795
|
args: [tokenInForQuote, tokenOutForQuote]
|
|
11683
11796
|
});
|
|
11684
11797
|
if (v2PairExists !== ADDRESS_ZERO) {
|
|
11685
|
-
const v2AmountIn = await
|
|
11798
|
+
const v2AmountIn = await client.readContract({
|
|
11686
11799
|
address: v2Router,
|
|
11687
11800
|
abi: uniswapRouterV2_default.ABI,
|
|
11688
11801
|
functionName: "getAmountsIn",
|
|
@@ -11696,20 +11809,20 @@ var IntentGateway = class {
|
|
|
11696
11809
|
let bestV3AmountIn = maxUint256;
|
|
11697
11810
|
for (const fee of commonFees) {
|
|
11698
11811
|
try {
|
|
11699
|
-
const pool = await
|
|
11812
|
+
const pool = await client.readContract({
|
|
11700
11813
|
address: v3Factory,
|
|
11701
11814
|
abi: uniswapV3Factory_default.ABI,
|
|
11702
11815
|
functionName: "getPool",
|
|
11703
11816
|
args: [tokenInForQuote, tokenOutForQuote, fee]
|
|
11704
11817
|
});
|
|
11705
11818
|
if (pool !== ADDRESS_ZERO) {
|
|
11706
|
-
const liquidity = await
|
|
11819
|
+
const liquidity = await client.readContract({
|
|
11707
11820
|
address: pool,
|
|
11708
11821
|
abi: uniswapV3Pool_default.ABI,
|
|
11709
11822
|
functionName: "liquidity"
|
|
11710
11823
|
});
|
|
11711
11824
|
if (liquidity > BigInt(0)) {
|
|
11712
|
-
const quoteResult = (await
|
|
11825
|
+
const quoteResult = (await client.simulateContract({
|
|
11713
11826
|
address: v3Quoter,
|
|
11714
11827
|
abi: uniswapV3Quoter_default.ABI,
|
|
11715
11828
|
functionName: "quoteExactOutputSingle",
|
|
@@ -11749,7 +11862,7 @@ var IntentGateway = class {
|
|
|
11749
11862
|
hooks: ADDRESS_ZERO
|
|
11750
11863
|
// No hooks
|
|
11751
11864
|
};
|
|
11752
|
-
const quoteResult = (await
|
|
11865
|
+
const quoteResult = (await client.simulateContract({
|
|
11753
11866
|
address: v4Quoter,
|
|
11754
11867
|
abi: UNISWAP_V4_QUOTER_ABI,
|
|
11755
11868
|
functionName: "quoteExactOutputSingle",
|
|
@@ -11822,37 +11935,41 @@ var IntentGateway = class {
|
|
|
11822
11935
|
* @param amountIn - The input amount to swap
|
|
11823
11936
|
* @returns Object containing the best protocol, expected output amount, and fee tier (for V3/V4)
|
|
11824
11937
|
*/
|
|
11825
|
-
async findBestProtocolWithAmountIn(
|
|
11826
|
-
const
|
|
11938
|
+
async findBestProtocolWithAmountIn(getQuoteIn, tokenIn, tokenOut, amountIn, selectedProtocol) {
|
|
11939
|
+
const client = this[getQuoteIn].client;
|
|
11940
|
+
const evmChainID = `EVM-${client.chain?.id}`;
|
|
11827
11941
|
let amountOutV2 = BigInt(0);
|
|
11828
11942
|
let amountOutV3 = BigInt(0);
|
|
11829
11943
|
let amountOutV4 = BigInt(0);
|
|
11830
11944
|
let bestV3Fee = 0;
|
|
11831
11945
|
let bestV4Fee = 0;
|
|
11832
11946
|
const commonFees = [100, 500, 3e3, 1e4];
|
|
11833
|
-
const v2Router = this.source.config.getUniswapRouterV2Address(
|
|
11834
|
-
const v2Factory = this.source.config.getUniswapV2FactoryAddress(
|
|
11835
|
-
const v3Factory = this.source.config.getUniswapV3FactoryAddress(
|
|
11836
|
-
const v3Quoter = this.source.config.getUniswapV3QuoterAddress(
|
|
11837
|
-
const v4Quoter = this.source.config.getUniswapV4QuoterAddress(
|
|
11838
|
-
const wethAsset = this.source.config.getWrappedNativeAssetWithDecimals(
|
|
11947
|
+
const v2Router = this.source.config.getUniswapRouterV2Address(evmChainID);
|
|
11948
|
+
const v2Factory = this.source.config.getUniswapV2FactoryAddress(evmChainID);
|
|
11949
|
+
const v3Factory = this.source.config.getUniswapV3FactoryAddress(evmChainID);
|
|
11950
|
+
const v3Quoter = this.source.config.getUniswapV3QuoterAddress(evmChainID);
|
|
11951
|
+
const v4Quoter = this.source.config.getUniswapV4QuoterAddress(evmChainID);
|
|
11952
|
+
const wethAsset = this.source.config.getWrappedNativeAssetWithDecimals(evmChainID).asset;
|
|
11839
11953
|
const tokenInForQuote = tokenIn === ADDRESS_ZERO ? wethAsset : tokenIn;
|
|
11840
11954
|
const tokenOutForQuote = tokenOut === ADDRESS_ZERO ? wethAsset : tokenOut;
|
|
11841
11955
|
try {
|
|
11842
|
-
const v2PairExists = await
|
|
11956
|
+
const v2PairExists = await client.readContract({
|
|
11843
11957
|
address: v2Factory,
|
|
11844
11958
|
abi: uniswapV2Factory_default.ABI,
|
|
11845
11959
|
functionName: "getPair",
|
|
11846
11960
|
args: [tokenInForQuote, tokenOutForQuote]
|
|
11847
11961
|
});
|
|
11848
11962
|
if (v2PairExists !== ADDRESS_ZERO) {
|
|
11849
|
-
const v2AmountOut = await
|
|
11963
|
+
const v2AmountOut = await client.readContract({
|
|
11850
11964
|
address: v2Router,
|
|
11851
11965
|
abi: uniswapRouterV2_default.ABI,
|
|
11852
11966
|
functionName: "getAmountsOut",
|
|
11853
11967
|
args: [amountIn, [tokenInForQuote, tokenOutForQuote]]
|
|
11854
11968
|
});
|
|
11855
11969
|
amountOutV2 = v2AmountOut[1];
|
|
11970
|
+
if (selectedProtocol === "v2") {
|
|
11971
|
+
return { protocol: "v2", amountOut: amountOutV2 };
|
|
11972
|
+
}
|
|
11856
11973
|
}
|
|
11857
11974
|
} catch (error) {
|
|
11858
11975
|
console.warn("V2 quote failed:", error);
|
|
@@ -11860,20 +11977,20 @@ var IntentGateway = class {
|
|
|
11860
11977
|
let bestV3AmountOut = BigInt(0);
|
|
11861
11978
|
for (const fee of commonFees) {
|
|
11862
11979
|
try {
|
|
11863
|
-
const pool = await
|
|
11980
|
+
const pool = await client.readContract({
|
|
11864
11981
|
address: v3Factory,
|
|
11865
11982
|
abi: uniswapV3Factory_default.ABI,
|
|
11866
11983
|
functionName: "getPool",
|
|
11867
11984
|
args: [tokenInForQuote, tokenOutForQuote, fee]
|
|
11868
11985
|
});
|
|
11869
11986
|
if (pool !== ADDRESS_ZERO) {
|
|
11870
|
-
const liquidity = await
|
|
11987
|
+
const liquidity = await client.readContract({
|
|
11871
11988
|
address: pool,
|
|
11872
11989
|
abi: uniswapV3Pool_default.ABI,
|
|
11873
11990
|
functionName: "liquidity"
|
|
11874
11991
|
});
|
|
11875
11992
|
if (liquidity > BigInt(0)) {
|
|
11876
|
-
const quoteResult = (await
|
|
11993
|
+
const quoteResult = (await client.simulateContract({
|
|
11877
11994
|
address: v3Quoter,
|
|
11878
11995
|
abi: uniswapV3Quoter_default.ABI,
|
|
11879
11996
|
functionName: "quoteExactInputSingle",
|
|
@@ -11899,6 +12016,9 @@ var IntentGateway = class {
|
|
|
11899
12016
|
}
|
|
11900
12017
|
}
|
|
11901
12018
|
amountOutV3 = bestV3AmountOut;
|
|
12019
|
+
if (selectedProtocol === "v3") {
|
|
12020
|
+
return { protocol: "v3", amountOut: amountOutV3, fee: bestV3Fee };
|
|
12021
|
+
}
|
|
11902
12022
|
let bestV4AmountOut = BigInt(0);
|
|
11903
12023
|
for (const fee of commonFees) {
|
|
11904
12024
|
try {
|
|
@@ -11913,7 +12033,7 @@ var IntentGateway = class {
|
|
|
11913
12033
|
hooks: ADDRESS_ZERO
|
|
11914
12034
|
// No hooks
|
|
11915
12035
|
};
|
|
11916
|
-
const quoteResult = (await
|
|
12036
|
+
const quoteResult = (await client.simulateContract({
|
|
11917
12037
|
address: v4Quoter,
|
|
11918
12038
|
abi: UNISWAP_V4_QUOTER_ABI,
|
|
11919
12039
|
functionName: "quoteExactInputSingle",
|
|
@@ -11937,6 +12057,9 @@ var IntentGateway = class {
|
|
|
11937
12057
|
}
|
|
11938
12058
|
}
|
|
11939
12059
|
amountOutV4 = bestV4AmountOut;
|
|
12060
|
+
if (selectedProtocol === "v4") {
|
|
12061
|
+
return { protocol: "v4", amountOut: amountOutV4, fee: bestV4Fee };
|
|
12062
|
+
}
|
|
11940
12063
|
if (amountOutV2 === BigInt(0) && amountOutV3 === BigInt(0) && amountOutV4 === BigInt(0)) {
|
|
11941
12064
|
return {
|
|
11942
12065
|
protocol: null,
|