@hyperbridge/sdk 1.3.15 → 1.3.16
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 +4 -1
- package/dist/browser/index.js +24 -15
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.d.ts +4 -1
- package/dist/node/index.js +24 -15
- package/dist/node/index.js.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.d.ts
CHANGED
|
@@ -2611,6 +2611,7 @@ declare class IntentGateway {
|
|
|
2611
2611
|
*
|
|
2612
2612
|
* @param feeTokenAmount - The amount in fee token (DAI)
|
|
2613
2613
|
* @param getQuoteIn - Whether to use "source" or "dest" chain for the conversion
|
|
2614
|
+
* @param evmChainID - The EVM chain ID in format "EVM-{id}"
|
|
2614
2615
|
* @returns The fee token amount converted to native token amount
|
|
2615
2616
|
* @private
|
|
2616
2617
|
*/
|
|
@@ -2621,6 +2622,7 @@ declare class IntentGateway {
|
|
|
2621
2622
|
*
|
|
2622
2623
|
* @param gasEstimate - The estimated gas units
|
|
2623
2624
|
* @param gasEstimateIn - Whether to use "source" or "dest" chain for the conversion
|
|
2625
|
+
* @param evmChainID - The EVM chain ID in format "EVM-{id}"
|
|
2624
2626
|
* @returns The gas cost converted to fee token amount
|
|
2625
2627
|
* @private
|
|
2626
2628
|
*/
|
|
@@ -2656,10 +2658,11 @@ declare class IntentGateway {
|
|
|
2656
2658
|
* @param tokenIn - The address of the input token
|
|
2657
2659
|
* @param tokenOut - The address of the output token
|
|
2658
2660
|
* @param amountIn - The input amount to swap
|
|
2661
|
+
* @param evmChainID - The EVM chain ID in format "EVM-{id}"
|
|
2659
2662
|
* @param selectedProtocol - Optional specific protocol to use ("v2", "v3", or "v4")
|
|
2660
2663
|
* @returns Object containing the best protocol, expected output amount, and fee tier (for V3/V4)
|
|
2661
2664
|
*/
|
|
2662
|
-
findBestProtocolWithAmountIn(getQuoteIn: "source" | "dest", tokenIn: HexString, tokenOut: HexString, amountIn: bigint, selectedProtocol?: "v2" | "v3" | "v4"): Promise<{
|
|
2665
|
+
findBestProtocolWithAmountIn(getQuoteIn: "source" | "dest", tokenIn: HexString, tokenOut: HexString, amountIn: bigint, evmChainID: string, selectedProtocol?: "v2" | "v3" | "v4"): Promise<{
|
|
2663
2666
|
protocol: "v2" | "v3" | "v4" | null;
|
|
2664
2667
|
amountOut: bigint;
|
|
2665
2668
|
fee?: number;
|
package/dist/browser/index.js
CHANGED
|
@@ -3443,7 +3443,7 @@ var assets = {
|
|
|
3443
3443
|
USDT: "0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2".toLowerCase()
|
|
3444
3444
|
},
|
|
3445
3445
|
["EVM-137" /* POLYGON_MAINNET */]: {
|
|
3446
|
-
WETH: "
|
|
3446
|
+
WETH: "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270".toLowerCase(),
|
|
3447
3447
|
DAI: "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063".toLowerCase(),
|
|
3448
3448
|
USDC: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359".toLowerCase(),
|
|
3449
3449
|
USDT: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F".toLowerCase()
|
|
@@ -11751,7 +11751,11 @@ var IntentGateway = class {
|
|
|
11751
11751
|
const { decimals: sourceChainFeeTokenDecimals } = await this.source.getFeeTokenWithDecimals();
|
|
11752
11752
|
const { address: destChainFeeTokenAddress, decimals: destChainFeeTokenDecimals } = await this.dest.getFeeTokenWithDecimals();
|
|
11753
11753
|
const { gas: postGasEstimate, postRequestCalldata } = await this.source.estimateGas(postRequest);
|
|
11754
|
-
const postGasEstimateInSourceFeeToken = await this.convertGasToFeeToken(
|
|
11754
|
+
const postGasEstimateInSourceFeeToken = await this.convertGasToFeeToken(
|
|
11755
|
+
postGasEstimate,
|
|
11756
|
+
"source",
|
|
11757
|
+
order.sourceChain
|
|
11758
|
+
);
|
|
11755
11759
|
const relayerFeeInSourceFeeToken = postGasEstimateInSourceFeeToken + 25n * 10n ** BigInt(sourceChainFeeTokenDecimals - 2);
|
|
11756
11760
|
const relayerFeeInDestFeeToken = adjustFeeDecimals(
|
|
11757
11761
|
relayerFeeInSourceFeeToken,
|
|
@@ -11806,7 +11810,6 @@ var IntentGateway = class {
|
|
|
11806
11810
|
}))
|
|
11807
11811
|
];
|
|
11808
11812
|
let destChainFillGas = 0n;
|
|
11809
|
-
let filledWithNativeToken = false;
|
|
11810
11813
|
try {
|
|
11811
11814
|
let protocolFeeInNativeToken = await this.quoteNative(postRequest, relayerFeeInDestFeeToken);
|
|
11812
11815
|
protocolFeeInNativeToken = protocolFeeInNativeToken + protocolFeeInNativeToken * 50n / 10000n;
|
|
@@ -11819,7 +11822,6 @@ var IntentGateway = class {
|
|
|
11819
11822
|
value: totalEthValue + protocolFeeInNativeToken,
|
|
11820
11823
|
stateOverride: stateOverrides
|
|
11821
11824
|
});
|
|
11822
|
-
filledWithNativeToken = true;
|
|
11823
11825
|
} catch {
|
|
11824
11826
|
console.warn(
|
|
11825
11827
|
`Could not estimate gas for fill order with native token as fees for chain ${order.destChain}, now trying with fee token as fees`
|
|
@@ -11854,7 +11856,7 @@ var IntentGateway = class {
|
|
|
11854
11856
|
stateOverride: stateOverrides
|
|
11855
11857
|
});
|
|
11856
11858
|
}
|
|
11857
|
-
const fillGasInDestFeeToken = await this.convertGasToFeeToken(destChainFillGas, "dest");
|
|
11859
|
+
const fillGasInDestFeeToken = await this.convertGasToFeeToken(destChainFillGas, "dest", order.destChain);
|
|
11858
11860
|
const fillGasInSourceFeeToken = adjustFeeDecimals(
|
|
11859
11861
|
fillGasInDestFeeToken,
|
|
11860
11862
|
destChainFeeTokenDecimals,
|
|
@@ -11866,7 +11868,11 @@ var IntentGateway = class {
|
|
|
11866
11868
|
sourceChainFeeTokenDecimals
|
|
11867
11869
|
);
|
|
11868
11870
|
let totalEstimateInSourceFeeToken = fillGasInSourceFeeToken + protocolFeeInSourceFeeToken + relayerFeeInSourceFeeToken;
|
|
11869
|
-
let totalNativeTokenAmount = await this.convertFeeTokenToNative(
|
|
11871
|
+
let totalNativeTokenAmount = await this.convertFeeTokenToNative(
|
|
11872
|
+
totalEstimateInSourceFeeToken,
|
|
11873
|
+
"source",
|
|
11874
|
+
order.sourceChain
|
|
11875
|
+
);
|
|
11870
11876
|
if ([order.destChain, order.sourceChain].includes("EVM-1")) {
|
|
11871
11877
|
totalEstimateInSourceFeeToken = totalEstimateInSourceFeeToken + totalEstimateInSourceFeeToken * 3000n / 10000n;
|
|
11872
11878
|
totalNativeTokenAmount = totalNativeTokenAmount + totalNativeTokenAmount * 3200n / 10000n;
|
|
@@ -11886,12 +11892,12 @@ var IntentGateway = class {
|
|
|
11886
11892
|
*
|
|
11887
11893
|
* @param feeTokenAmount - The amount in fee token (DAI)
|
|
11888
11894
|
* @param getQuoteIn - Whether to use "source" or "dest" chain for the conversion
|
|
11895
|
+
* @param evmChainID - The EVM chain ID in format "EVM-{id}"
|
|
11889
11896
|
* @returns The fee token amount converted to native token amount
|
|
11890
11897
|
* @private
|
|
11891
11898
|
*/
|
|
11892
|
-
async convertFeeTokenToNative(feeTokenAmount, getQuoteIn) {
|
|
11899
|
+
async convertFeeTokenToNative(feeTokenAmount, getQuoteIn, evmChainID) {
|
|
11893
11900
|
const client = this[getQuoteIn].client;
|
|
11894
|
-
const evmChainID = `EVM-${client.chain?.id}`;
|
|
11895
11901
|
const wethAsset = this[getQuoteIn].config.getWrappedNativeAssetWithDecimals(evmChainID).asset;
|
|
11896
11902
|
const feeToken = await this[getQuoteIn].getFeeTokenWithDecimals();
|
|
11897
11903
|
try {
|
|
@@ -11900,6 +11906,7 @@ var IntentGateway = class {
|
|
|
11900
11906
|
feeToken.address,
|
|
11901
11907
|
wethAsset,
|
|
11902
11908
|
feeTokenAmount,
|
|
11909
|
+
evmChainID,
|
|
11903
11910
|
"v2"
|
|
11904
11911
|
);
|
|
11905
11912
|
if (amountOut === 0n) {
|
|
@@ -11908,7 +11915,7 @@ var IntentGateway = class {
|
|
|
11908
11915
|
return amountOut;
|
|
11909
11916
|
} catch {
|
|
11910
11917
|
const nativeCurrency = client.chain?.nativeCurrency;
|
|
11911
|
-
const chainId =
|
|
11918
|
+
const chainId = Number.parseInt(evmChainID.split("-")[1]);
|
|
11912
11919
|
const feeTokenAmountDecimal = new Decimal(formatUnits(feeTokenAmount, feeToken.decimals));
|
|
11913
11920
|
const nativeTokenPriceUsd = new Decimal(await fetchPrice(nativeCurrency?.symbol, chainId));
|
|
11914
11921
|
const totalCostInNativeToken = feeTokenAmountDecimal.dividedBy(nativeTokenPriceUsd);
|
|
@@ -11921,14 +11928,14 @@ var IntentGateway = class {
|
|
|
11921
11928
|
*
|
|
11922
11929
|
* @param gasEstimate - The estimated gas units
|
|
11923
11930
|
* @param gasEstimateIn - Whether to use "source" or "dest" chain for the conversion
|
|
11931
|
+
* @param evmChainID - The EVM chain ID in format "EVM-{id}"
|
|
11924
11932
|
* @returns The gas cost converted to fee token amount
|
|
11925
11933
|
* @private
|
|
11926
11934
|
*/
|
|
11927
|
-
async convertGasToFeeToken(gasEstimate, gasEstimateIn) {
|
|
11935
|
+
async convertGasToFeeToken(gasEstimate, gasEstimateIn, evmChainID) {
|
|
11928
11936
|
const client = this[gasEstimateIn].client;
|
|
11929
11937
|
const gasPrice = await client.getGasPrice();
|
|
11930
11938
|
const gasCostInWei = gasEstimate * gasPrice;
|
|
11931
|
-
const evmChainID = `EVM-${client.chain?.id}`;
|
|
11932
11939
|
const wethAddr = this[gasEstimateIn].config.getWrappedNativeAssetWithDecimals(evmChainID).asset;
|
|
11933
11940
|
const feeToken = await this[gasEstimateIn].getFeeTokenWithDecimals();
|
|
11934
11941
|
try {
|
|
@@ -11937,15 +11944,17 @@ var IntentGateway = class {
|
|
|
11937
11944
|
wethAddr,
|
|
11938
11945
|
feeToken.address,
|
|
11939
11946
|
gasCostInWei,
|
|
11947
|
+
evmChainID,
|
|
11940
11948
|
"v2"
|
|
11941
11949
|
);
|
|
11942
11950
|
if (amountOut === 0n) {
|
|
11951
|
+
console.log("Amount out not found");
|
|
11943
11952
|
throw new Error();
|
|
11944
11953
|
}
|
|
11945
11954
|
return amountOut;
|
|
11946
11955
|
} catch {
|
|
11947
11956
|
const nativeCurrency = client.chain?.nativeCurrency;
|
|
11948
|
-
const chainId =
|
|
11957
|
+
const chainId = Number.parseInt(evmChainID.split("-")[1]);
|
|
11949
11958
|
const gasCostInToken = new Decimal(formatUnits(gasCostInWei, nativeCurrency?.decimals));
|
|
11950
11959
|
const tokenPriceUsd = await fetchPrice(nativeCurrency?.symbol, chainId);
|
|
11951
11960
|
const gasCostUsd = gasCostInToken.times(tokenPriceUsd);
|
|
@@ -12151,12 +12160,12 @@ var IntentGateway = class {
|
|
|
12151
12160
|
* @param tokenIn - The address of the input token
|
|
12152
12161
|
* @param tokenOut - The address of the output token
|
|
12153
12162
|
* @param amountIn - The input amount to swap
|
|
12163
|
+
* @param evmChainID - The EVM chain ID in format "EVM-{id}"
|
|
12154
12164
|
* @param selectedProtocol - Optional specific protocol to use ("v2", "v3", or "v4")
|
|
12155
12165
|
* @returns Object containing the best protocol, expected output amount, and fee tier (for V3/V4)
|
|
12156
12166
|
*/
|
|
12157
|
-
async findBestProtocolWithAmountIn(getQuoteIn, tokenIn, tokenOut, amountIn, selectedProtocol) {
|
|
12167
|
+
async findBestProtocolWithAmountIn(getQuoteIn, tokenIn, tokenOut, amountIn, evmChainID, selectedProtocol) {
|
|
12158
12168
|
const client = this[getQuoteIn].client;
|
|
12159
|
-
const evmChainID = `EVM-${client.chain?.id}`;
|
|
12160
12169
|
let amountOutV2 = BigInt(0);
|
|
12161
12170
|
let amountOutV3 = BigInt(0);
|
|
12162
12171
|
let amountOutV4 = BigInt(0);
|
|
@@ -12356,7 +12365,7 @@ var IntentGateway = class {
|
|
|
12356
12365
|
if (!value) throw new Error("Receipt not found");
|
|
12357
12366
|
return value;
|
|
12358
12367
|
},
|
|
12359
|
-
{ maxRetries:
|
|
12368
|
+
{ maxRetries: 10, backoffMs: 5e3, logMessage: "Checking for receipt" }
|
|
12360
12369
|
);
|
|
12361
12370
|
}
|
|
12362
12371
|
console.log("Hyperbridge Receipt confirmed.");
|