@hyperbridge/sdk 1.3.15 → 1.3.17
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 +30 -19
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.d.ts +4 -1
- package/dist/node/index.js +30 -19
- 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()
|
|
@@ -3588,7 +3588,7 @@ var consensusStateIds = {
|
|
|
3588
3588
|
["EVM-56" /* BSC_MAINNET */]: "BSC0",
|
|
3589
3589
|
["EVM-42161" /* ARBITRUM_MAINNET */]: "ETH0",
|
|
3590
3590
|
["EVM-8453" /* BASE_MAINNET */]: "ETH0",
|
|
3591
|
-
["EVM-137" /* POLYGON_MAINNET */]: "
|
|
3591
|
+
["EVM-137" /* POLYGON_MAINNET */]: "POLY",
|
|
3592
3592
|
["EVM-130" /* UNICHAIN_MAINNET */]: "ETH0"
|
|
3593
3593
|
};
|
|
3594
3594
|
var coingeckoIds = {
|
|
@@ -3600,7 +3600,7 @@ var coingeckoIds = {
|
|
|
3600
3600
|
["EVM-56" /* BSC_MAINNET */]: "binance-smart-chain",
|
|
3601
3601
|
["EVM-42161" /* ARBITRUM_MAINNET */]: "arbitrum-one",
|
|
3602
3602
|
["EVM-8453" /* BASE_MAINNET */]: "base",
|
|
3603
|
-
["EVM-137" /* POLYGON_MAINNET */]: "
|
|
3603
|
+
["EVM-137" /* POLYGON_MAINNET */]: "polygon-pos",
|
|
3604
3604
|
["EVM-130" /* UNICHAIN_MAINNET */]: "ethereum"
|
|
3605
3605
|
};
|
|
3606
3606
|
|
|
@@ -4514,7 +4514,7 @@ var dateStringtoTimestamp = (date) => {
|
|
|
4514
4514
|
}
|
|
4515
4515
|
return new Date(date).getTime();
|
|
4516
4516
|
};
|
|
4517
|
-
function
|
|
4517
|
+
function mapToValidCoingeckoId(identifier) {
|
|
4518
4518
|
identifier = identifier.toLowerCase();
|
|
4519
4519
|
switch (identifier) {
|
|
4520
4520
|
case "bnb":
|
|
@@ -4535,12 +4535,14 @@ function mapTestnetToMainnet(identifier) {
|
|
|
4535
4535
|
return "dai";
|
|
4536
4536
|
case "0xa801da100bf16d07f668f4a49e1f71fc54d05177".toLowerCase():
|
|
4537
4537
|
return "dai";
|
|
4538
|
+
case "pol":
|
|
4539
|
+
return "polygon-ecosystem-token";
|
|
4538
4540
|
default:
|
|
4539
4541
|
return identifier;
|
|
4540
4542
|
}
|
|
4541
4543
|
}
|
|
4542
4544
|
async function fetchPrice(identifier, chainId = 1, apiKey) {
|
|
4543
|
-
const mappedIdentifier =
|
|
4545
|
+
const mappedIdentifier = mapToValidCoingeckoId(identifier);
|
|
4544
4546
|
const network = new ChainConfigService().getCoingeckoId(`EVM-${chainId}`) || "ethereum";
|
|
4545
4547
|
apiKey = apiKey || (typeof process !== "undefined" ? process?.env?.COINGECKO : void 0);
|
|
4546
4548
|
const baseUrl = apiKey ? "https://pro-api.coingecko.com/api/v3" : "https://api.coingecko.com/api/v3";
|
|
@@ -11751,7 +11753,11 @@ var IntentGateway = class {
|
|
|
11751
11753
|
const { decimals: sourceChainFeeTokenDecimals } = await this.source.getFeeTokenWithDecimals();
|
|
11752
11754
|
const { address: destChainFeeTokenAddress, decimals: destChainFeeTokenDecimals } = await this.dest.getFeeTokenWithDecimals();
|
|
11753
11755
|
const { gas: postGasEstimate, postRequestCalldata } = await this.source.estimateGas(postRequest);
|
|
11754
|
-
const postGasEstimateInSourceFeeToken = await this.convertGasToFeeToken(
|
|
11756
|
+
const postGasEstimateInSourceFeeToken = await this.convertGasToFeeToken(
|
|
11757
|
+
postGasEstimate,
|
|
11758
|
+
"source",
|
|
11759
|
+
order.sourceChain
|
|
11760
|
+
);
|
|
11755
11761
|
const relayerFeeInSourceFeeToken = postGasEstimateInSourceFeeToken + 25n * 10n ** BigInt(sourceChainFeeTokenDecimals - 2);
|
|
11756
11762
|
const relayerFeeInDestFeeToken = adjustFeeDecimals(
|
|
11757
11763
|
relayerFeeInSourceFeeToken,
|
|
@@ -11806,7 +11812,6 @@ var IntentGateway = class {
|
|
|
11806
11812
|
}))
|
|
11807
11813
|
];
|
|
11808
11814
|
let destChainFillGas = 0n;
|
|
11809
|
-
let filledWithNativeToken = false;
|
|
11810
11815
|
try {
|
|
11811
11816
|
let protocolFeeInNativeToken = await this.quoteNative(postRequest, relayerFeeInDestFeeToken);
|
|
11812
11817
|
protocolFeeInNativeToken = protocolFeeInNativeToken + protocolFeeInNativeToken * 50n / 10000n;
|
|
@@ -11819,7 +11824,6 @@ var IntentGateway = class {
|
|
|
11819
11824
|
value: totalEthValue + protocolFeeInNativeToken,
|
|
11820
11825
|
stateOverride: stateOverrides
|
|
11821
11826
|
});
|
|
11822
|
-
filledWithNativeToken = true;
|
|
11823
11827
|
} catch {
|
|
11824
11828
|
console.warn(
|
|
11825
11829
|
`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 +11858,7 @@ var IntentGateway = class {
|
|
|
11854
11858
|
stateOverride: stateOverrides
|
|
11855
11859
|
});
|
|
11856
11860
|
}
|
|
11857
|
-
const fillGasInDestFeeToken = await this.convertGasToFeeToken(destChainFillGas, "dest");
|
|
11861
|
+
const fillGasInDestFeeToken = await this.convertGasToFeeToken(destChainFillGas, "dest", order.destChain);
|
|
11858
11862
|
const fillGasInSourceFeeToken = adjustFeeDecimals(
|
|
11859
11863
|
fillGasInDestFeeToken,
|
|
11860
11864
|
destChainFeeTokenDecimals,
|
|
@@ -11866,7 +11870,11 @@ var IntentGateway = class {
|
|
|
11866
11870
|
sourceChainFeeTokenDecimals
|
|
11867
11871
|
);
|
|
11868
11872
|
let totalEstimateInSourceFeeToken = fillGasInSourceFeeToken + protocolFeeInSourceFeeToken + relayerFeeInSourceFeeToken;
|
|
11869
|
-
let totalNativeTokenAmount = await this.convertFeeTokenToNative(
|
|
11873
|
+
let totalNativeTokenAmount = await this.convertFeeTokenToNative(
|
|
11874
|
+
totalEstimateInSourceFeeToken,
|
|
11875
|
+
"source",
|
|
11876
|
+
order.sourceChain
|
|
11877
|
+
);
|
|
11870
11878
|
if ([order.destChain, order.sourceChain].includes("EVM-1")) {
|
|
11871
11879
|
totalEstimateInSourceFeeToken = totalEstimateInSourceFeeToken + totalEstimateInSourceFeeToken * 3000n / 10000n;
|
|
11872
11880
|
totalNativeTokenAmount = totalNativeTokenAmount + totalNativeTokenAmount * 3200n / 10000n;
|
|
@@ -11886,12 +11894,12 @@ var IntentGateway = class {
|
|
|
11886
11894
|
*
|
|
11887
11895
|
* @param feeTokenAmount - The amount in fee token (DAI)
|
|
11888
11896
|
* @param getQuoteIn - Whether to use "source" or "dest" chain for the conversion
|
|
11897
|
+
* @param evmChainID - The EVM chain ID in format "EVM-{id}"
|
|
11889
11898
|
* @returns The fee token amount converted to native token amount
|
|
11890
11899
|
* @private
|
|
11891
11900
|
*/
|
|
11892
|
-
async convertFeeTokenToNative(feeTokenAmount, getQuoteIn) {
|
|
11901
|
+
async convertFeeTokenToNative(feeTokenAmount, getQuoteIn, evmChainID) {
|
|
11893
11902
|
const client = this[getQuoteIn].client;
|
|
11894
|
-
const evmChainID = `EVM-${client.chain?.id}`;
|
|
11895
11903
|
const wethAsset = this[getQuoteIn].config.getWrappedNativeAssetWithDecimals(evmChainID).asset;
|
|
11896
11904
|
const feeToken = await this[getQuoteIn].getFeeTokenWithDecimals();
|
|
11897
11905
|
try {
|
|
@@ -11900,6 +11908,7 @@ var IntentGateway = class {
|
|
|
11900
11908
|
feeToken.address,
|
|
11901
11909
|
wethAsset,
|
|
11902
11910
|
feeTokenAmount,
|
|
11911
|
+
evmChainID,
|
|
11903
11912
|
"v2"
|
|
11904
11913
|
);
|
|
11905
11914
|
if (amountOut === 0n) {
|
|
@@ -11908,7 +11917,7 @@ var IntentGateway = class {
|
|
|
11908
11917
|
return amountOut;
|
|
11909
11918
|
} catch {
|
|
11910
11919
|
const nativeCurrency = client.chain?.nativeCurrency;
|
|
11911
|
-
const chainId =
|
|
11920
|
+
const chainId = Number.parseInt(evmChainID.split("-")[1]);
|
|
11912
11921
|
const feeTokenAmountDecimal = new Decimal(formatUnits(feeTokenAmount, feeToken.decimals));
|
|
11913
11922
|
const nativeTokenPriceUsd = new Decimal(await fetchPrice(nativeCurrency?.symbol, chainId));
|
|
11914
11923
|
const totalCostInNativeToken = feeTokenAmountDecimal.dividedBy(nativeTokenPriceUsd);
|
|
@@ -11921,14 +11930,14 @@ var IntentGateway = class {
|
|
|
11921
11930
|
*
|
|
11922
11931
|
* @param gasEstimate - The estimated gas units
|
|
11923
11932
|
* @param gasEstimateIn - Whether to use "source" or "dest" chain for the conversion
|
|
11933
|
+
* @param evmChainID - The EVM chain ID in format "EVM-{id}"
|
|
11924
11934
|
* @returns The gas cost converted to fee token amount
|
|
11925
11935
|
* @private
|
|
11926
11936
|
*/
|
|
11927
|
-
async convertGasToFeeToken(gasEstimate, gasEstimateIn) {
|
|
11937
|
+
async convertGasToFeeToken(gasEstimate, gasEstimateIn, evmChainID) {
|
|
11928
11938
|
const client = this[gasEstimateIn].client;
|
|
11929
11939
|
const gasPrice = await client.getGasPrice();
|
|
11930
11940
|
const gasCostInWei = gasEstimate * gasPrice;
|
|
11931
|
-
const evmChainID = `EVM-${client.chain?.id}`;
|
|
11932
11941
|
const wethAddr = this[gasEstimateIn].config.getWrappedNativeAssetWithDecimals(evmChainID).asset;
|
|
11933
11942
|
const feeToken = await this[gasEstimateIn].getFeeTokenWithDecimals();
|
|
11934
11943
|
try {
|
|
@@ -11937,15 +11946,17 @@ var IntentGateway = class {
|
|
|
11937
11946
|
wethAddr,
|
|
11938
11947
|
feeToken.address,
|
|
11939
11948
|
gasCostInWei,
|
|
11949
|
+
evmChainID,
|
|
11940
11950
|
"v2"
|
|
11941
11951
|
);
|
|
11942
11952
|
if (amountOut === 0n) {
|
|
11953
|
+
console.log("Amount out not found");
|
|
11943
11954
|
throw new Error();
|
|
11944
11955
|
}
|
|
11945
11956
|
return amountOut;
|
|
11946
11957
|
} catch {
|
|
11947
11958
|
const nativeCurrency = client.chain?.nativeCurrency;
|
|
11948
|
-
const chainId =
|
|
11959
|
+
const chainId = Number.parseInt(evmChainID.split("-")[1]);
|
|
11949
11960
|
const gasCostInToken = new Decimal(formatUnits(gasCostInWei, nativeCurrency?.decimals));
|
|
11950
11961
|
const tokenPriceUsd = await fetchPrice(nativeCurrency?.symbol, chainId);
|
|
11951
11962
|
const gasCostUsd = gasCostInToken.times(tokenPriceUsd);
|
|
@@ -12151,12 +12162,12 @@ var IntentGateway = class {
|
|
|
12151
12162
|
* @param tokenIn - The address of the input token
|
|
12152
12163
|
* @param tokenOut - The address of the output token
|
|
12153
12164
|
* @param amountIn - The input amount to swap
|
|
12165
|
+
* @param evmChainID - The EVM chain ID in format "EVM-{id}"
|
|
12154
12166
|
* @param selectedProtocol - Optional specific protocol to use ("v2", "v3", or "v4")
|
|
12155
12167
|
* @returns Object containing the best protocol, expected output amount, and fee tier (for V3/V4)
|
|
12156
12168
|
*/
|
|
12157
|
-
async findBestProtocolWithAmountIn(getQuoteIn, tokenIn, tokenOut, amountIn, selectedProtocol) {
|
|
12169
|
+
async findBestProtocolWithAmountIn(getQuoteIn, tokenIn, tokenOut, amountIn, evmChainID, selectedProtocol) {
|
|
12158
12170
|
const client = this[getQuoteIn].client;
|
|
12159
|
-
const evmChainID = `EVM-${client.chain?.id}`;
|
|
12160
12171
|
let amountOutV2 = BigInt(0);
|
|
12161
12172
|
let amountOutV3 = BigInt(0);
|
|
12162
12173
|
let amountOutV4 = BigInt(0);
|
|
@@ -12356,7 +12367,7 @@ var IntentGateway = class {
|
|
|
12356
12367
|
if (!value) throw new Error("Receipt not found");
|
|
12357
12368
|
return value;
|
|
12358
12369
|
},
|
|
12359
|
-
{ maxRetries:
|
|
12370
|
+
{ maxRetries: 10, backoffMs: 5e3, logMessage: "Checking for receipt" }
|
|
12360
12371
|
);
|
|
12361
12372
|
}
|
|
12362
12373
|
console.log("Hyperbridge Receipt confirmed.");
|