@hyperbridge/sdk 1.4.9 → 1.5.0

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.
@@ -590,6 +590,7 @@ declare class ChainConfigService {
590
590
  constructor(env?: NodeJS.ProcessEnv);
591
591
  getChainConfig(chain: string): ChainConfig;
592
592
  getIntentGatewayAddress(chain: string): `0x${string}`;
593
+ getTokenGatewayAddress(chain: string): `0x${string}`;
593
594
  getHostAddress(chain: string): `0x${string}`;
594
595
  getWrappedNativeAssetWithDecimals(chain: string): {
595
596
  asset: HexString;
@@ -3079,6 +3080,15 @@ declare class IntentGateway {
3079
3080
  * @returns True if the order has been filled, false otherwise
3080
3081
  */
3081
3082
  isOrderFilled(order: Order): Promise<boolean>;
3083
+ /**
3084
+ * Checks if an order has been refunded by verifying the escrowed token amounts on-chain.
3085
+ * Reads the storage slots for the `_orders` mapping on the source chain (where the escrow is held).
3086
+ * An order is considered refunded when all input token amounts in the `_orders` mapping are 0.
3087
+ *
3088
+ * @param order - The order to check
3089
+ * @returns True if the order has been refunded (all token amounts are 0), false otherwise
3090
+ */
3091
+ isOrderRefunded(order: Order): Promise<boolean>;
3082
3092
  private submitAndConfirmReceipt;
3083
3093
  /**
3084
3094
  * Returns the native token amount required to dispatch a cancellation GET request for the given order.
@@ -3170,6 +3180,124 @@ type CancelEvent = {
3170
3180
  };
3171
3181
  }[keyof CancelEventMap];
3172
3182
 
3183
+ /**
3184
+ * Result of the quoteNative fee estimation
3185
+ */
3186
+ interface QuoteNativeResult {
3187
+ /** Total native token cost including relayer fee and protocol fee with 1% buffer */
3188
+ totalNativeCost: bigint;
3189
+ /** Relayer fee converted to source chain fee token */
3190
+ relayerFeeInSourceFeeToken: bigint;
3191
+ }
3192
+ /**
3193
+ * Parameters for token gateway teleport operations
3194
+ */
3195
+ interface TeleportParams {
3196
+ /** Amount to be sent */
3197
+ amount: bigint;
3198
+ /** The token identifier to send */
3199
+ assetId: HexString;
3200
+ /** Redeem ERC20 on the destination? */
3201
+ redeem: boolean;
3202
+ /** Recipient address */
3203
+ to: HexString;
3204
+ /** Recipient state machine */
3205
+ dest: string | Uint8Array;
3206
+ /** Request timeout in seconds */
3207
+ timeout: bigint;
3208
+ /** Destination contract call data */
3209
+ data?: HexString | Uint8Array;
3210
+ }
3211
+ /**
3212
+ * TokenGateway class for managing cross-chain token transfers via Hyperbridge
3213
+ *
3214
+ * This class provides methods to interact with the TokenGateway contract, including
3215
+ * estimating fees for cross-chain token teleports.
3216
+ *
3217
+ * Supports both EVM and Substrate chains as destination.
3218
+ *
3219
+ * @example
3220
+ * ```typescript
3221
+ * const tokenGateway = new TokenGateway({
3222
+ * source: sourceChain,
3223
+ * dest: destChain // Can be EvmChain or SubstrateChain
3224
+ * })
3225
+ *
3226
+ * const teleportParams: TeleportParams = {
3227
+ * amount: parseEther("1.0"),
3228
+ * assetId: keccak256(toHex("USDC")),
3229
+ * redeem: true,
3230
+ * to: pad("0xRecipientAddress", { size: 32 }),
3231
+ * dest: "EVM-1",
3232
+ * timeout: 3600n,
3233
+ * }
3234
+ *
3235
+ * // Estimate native cost (relayer fee + protocol fee with 1% buffer)
3236
+ * const { totalNativeCost, relayerFeeInSourceFeeToken } = await tokenGateway.quoteNative(teleportParams)
3237
+ * console.log(`Total native cost: ${formatEther(totalNativeCost)} ETH`)
3238
+ * console.log(`Relayer fee in fee token: ${relayerFeeInSourceFeeToken}`)
3239
+ * ```
3240
+ */
3241
+ declare class TokenGateway {
3242
+ private readonly source;
3243
+ private readonly dest;
3244
+ constructor(params: {
3245
+ source: EvmChain;
3246
+ dest: EvmChain | SubstrateChain;
3247
+ });
3248
+ /**
3249
+ * Get the TokenGateway contract address for a given chain
3250
+ *
3251
+ * @param chain - The chain identifier (e.g., "EVM-1", "EVM-56")
3252
+ * @returns The TokenGateway contract address
3253
+ */
3254
+ private getTokenGatewayAddress;
3255
+ /**
3256
+ * Estimate the native token cost for a token gateway teleport operation.
3257
+ * This includes both relayer fees and protocol fees for cross-chain delivery.
3258
+ *
3259
+ * The relayer fee is automatically estimated for EVM destination chains by:
3260
+ * 1. Creating a dummy post request with 191 bytes of random data in the body
3261
+ * 2. Estimating gas for delivery on the destination chain
3262
+ * 3. Converting the gas estimate to native tokens
3263
+ * 4. Adding a 1% buffer to the relayer fee for safety margin
3264
+ *
3265
+ * For non-EVM destination chains, the relayer fee is set to zero.
3266
+ *
3267
+ * The function then constructs a proper post request and calls quoteNative on the
3268
+ * source chain to get protocol fees (with 1% buffer), converts the relayer fee to
3269
+ * source chain fee token using Uniswap V2's getAmountsOut, and returns both values.
3270
+ *
3271
+ * @param params - The teleport parameters
3272
+ * @returns Object containing totalNativeCost (with 1% buffer) and relayerFeeInSourceFeeToken
3273
+ *
3274
+ * @throws Will throw an error if the contract call fails
3275
+ *
3276
+ * @example
3277
+ * ```typescript
3278
+ * const params: TeleportParams = {
3279
+ * amount: parseEther("1.0"),
3280
+ * assetId: keccak256(toHex("USDC")),
3281
+ * redeem: true,
3282
+ * to: pad("0xRecipientAddress", { size: 32 }),
3283
+ * dest: "EVM-1",
3284
+ * timeout: 3600n,
3285
+ * data: "0x"
3286
+ * }
3287
+ *
3288
+ * const { totalNativeCost, relayerFeeInSourceFeeToken } = await tokenGateway.quoteNative(params)
3289
+ * console.log(`Total native cost: ${formatEther(totalNativeCost)} ETH`)
3290
+ * console.log(`Relayer fee in fee token: ${relayerFeeInSourceFeeToken}`)
3291
+ * ```
3292
+ */
3293
+ quoteNative(params: TeleportParams): Promise<QuoteNativeResult>;
3294
+ /**
3295
+ * Convert native token amount to fee token amount using Uniswap V2 router
3296
+ * @private
3297
+ */
3298
+ private convertNativeToFeeToken;
3299
+ }
3300
+
3173
3301
  /**
3174
3302
  * Extracts the IntentGateway OrderPlaced event from a transaction hash.
3175
3303
  * @param client - A viem PublicClient-compatible instance
@@ -3502,4 +3630,4 @@ declare const popularTokens: {
3502
3630
  "EVM-130": string[];
3503
3631
  };
3504
3632
 
3505
- export { ADDRESS_ZERO, type AllStatusKey, type AssetTeleported, type AssetTeleportedResponse, type BlockMetadata, type CancelOptions, type ChainConfig, ChainConfigService, type ChainId, Chains, type ClientConfig, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DUMMY_PRIVATE_KEY, type DecodedOrderPlacedLog, type DecodedPostRequestEvent, type DecodedPostResponseEvent, type DispatchGet, type DispatchPost, ERC20Method, type EstimateGasCallData, EvmChain, type EvmChainParams, type ExecutionResult, type FillOptions, type FillerConfig, type GetRequestResponse, type GetRequestWithStatus, type GetResponseByRequestIdResponse, type GetResponseStorageValues, type HexString, type HostParams, HyperClientStatus, type HyperbridgeTxEvents, type IChain, type IConfig, type IEvmConfig, type IGetRequest, type IGetRequestMessage, type IGetResponse, type IGetResponseMessage, type IHyperbridgeConfig, type IIsmpMessage, type IMessage, type IPostRequest, type IPostResponse, type IProof, type IRequestMessage, type ISubstrateConfig, type ITimeoutPostRequestMessage, IndexerClient, type IndexerQueryClient, IntentGateway, type IntentGatewayParams, type IsmpRequest, type NewDeployment, type Order, type OrderResponse, OrderStatus, type OrderStatusMetadata, type OrderWithStatus, type Params, type PaymentInfo, type PostRequestStatus, type PostRequestTimeoutStatus, type PostRequestWithStatus, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, type RequestBody, type RequestCommitment, RequestKind, type RequestResponse, RequestStatus, type RequestStatusKey, type RequestStatusWithMetadata, type ResponseCommitmentWithValues, type RetryConfig, STATE_COMMITMENTS_SLOT, type StateMachineHeight, type StateMachineIdParams, type StateMachineResponse, type StateMachineUpdate, type StorageFacade, SubstrateChain, TESTNET_CHAINS, TeleportStatus, TimeoutStatus, type TimeoutStatusKey, type TokenGatewayAssetTeleportedResponse, type TokenGatewayAssetTeleportedWithStatus, type TokenInfo, type TokenPrice, type TokenPricesResponse, type TokenRegistry, type TokenRegistryResponse, type Transaction, USE_ETHERSCAN_CHAINS, WrappedNativeDecimals, type XcmGatewayParams, __test, addresses, adjustFeeDecimals, assets, bytes20ToBytes32, bytes32ToBytes20, chainIds, coingeckoIds, consensusStateIds, constructRedeemEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createChain, createEvmChain, createIndexerClient, createQueryClient, createRpcUrls, encodeISMPMessage, estimateGasForPost, fetchPrice, generateRootWithProof, getChain, getGasPriceFromEtherscan, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, hexToString, maxBigInt, orderCommitment, popularTokens, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, requestCommitmentKey, retryPromise, teleport, teleportDot, viemChains };
3633
+ export { ADDRESS_ZERO, type AllStatusKey, type AssetTeleported, type AssetTeleportedResponse, type BlockMetadata, type CancelOptions, type ChainConfig, ChainConfigService, type ChainId, Chains, type ClientConfig, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DUMMY_PRIVATE_KEY, type DecodedOrderPlacedLog, type DecodedPostRequestEvent, type DecodedPostResponseEvent, type DispatchGet, type DispatchPost, ERC20Method, type EstimateGasCallData, EvmChain, type EvmChainParams, type ExecutionResult, type FillOptions, type FillerConfig, type GetRequestResponse, type GetRequestWithStatus, type GetResponseByRequestIdResponse, type GetResponseStorageValues, type HexString, type HostParams, HyperClientStatus, type HyperbridgeTxEvents, type IChain, type IConfig, type IEvmConfig, type IGetRequest, type IGetRequestMessage, type IGetResponse, type IGetResponseMessage, type IHyperbridgeConfig, type IIsmpMessage, type IMessage, type IPostRequest, type IPostResponse, type IProof, type IRequestMessage, type ISubstrateConfig, type ITimeoutPostRequestMessage, IndexerClient, type IndexerQueryClient, IntentGateway, type IntentGatewayParams, type IsmpRequest, type NewDeployment, type Order, type OrderResponse, OrderStatus, type OrderStatusMetadata, type OrderWithStatus, type Params, type PaymentInfo, type PostRequestStatus, type PostRequestTimeoutStatus, type PostRequestWithStatus, type QuoteNativeResult, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, type RequestBody, type RequestCommitment, RequestKind, type RequestResponse, RequestStatus, type RequestStatusKey, type RequestStatusWithMetadata, type ResponseCommitmentWithValues, type RetryConfig, STATE_COMMITMENTS_SLOT, type StateMachineHeight, type StateMachineIdParams, type StateMachineResponse, type StateMachineUpdate, type StorageFacade, SubstrateChain, TESTNET_CHAINS, type TeleportParams, TeleportStatus, TimeoutStatus, type TimeoutStatusKey, TokenGateway, type TokenGatewayAssetTeleportedResponse, type TokenGatewayAssetTeleportedWithStatus, type TokenInfo, type TokenPrice, type TokenPricesResponse, type TokenRegistry, type TokenRegistryResponse, type Transaction, USE_ETHERSCAN_CHAINS, WrappedNativeDecimals, type XcmGatewayParams, __test, addresses, adjustFeeDecimals, assets, bytes20ToBytes32, bytes32ToBytes20, chainIds, coingeckoIds, consensusStateIds, constructRedeemEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createChain, createEvmChain, createIndexerClient, createQueryClient, createRpcUrls, encodeISMPMessage, estimateGasForPost, fetchPrice, generateRootWithProof, getChain, getGasPriceFromEtherscan, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, hexToString, maxBigInt, orderCommitment, popularTokens, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, requestCommitmentKey, retryPromise, teleport, teleportDot, viemChains };
@@ -3421,6 +3421,17 @@ var addresses = {
3421
3421
  ["EVM-137" /* POLYGON_MAINNET */]: "0x1a4ee689a004b10210a1df9f24a387ea13359acf",
3422
3422
  ["EVM-130" /* UNICHAIN_MAINNET */]: "0x1a4ee689a004b10210a1df9f24a387ea13359acf"
3423
3423
  },
3424
+ TokenGateway: {
3425
+ ["EVM-97" /* BSC_CHAPEL */]: "0xFcDa26cA021d5535C3059547390E6cCd8De7acA6",
3426
+ ["EVM-10200" /* GNOSIS_CHIADO */]: "0xFcDa26cA021d5535C3059547390E6cCd8De7acA6",
3427
+ ["EVM-11155111" /* SEPOLIA */]: "0xFcDa26cA021d5535C3059547390E6cCd8De7acA6",
3428
+ ["EVM-1" /* MAINNET */]: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
3429
+ ["EVM-56" /* BSC_MAINNET */]: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
3430
+ ["EVM-42161" /* ARBITRUM_MAINNET */]: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
3431
+ ["EVM-8453" /* BASE_MAINNET */]: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
3432
+ ["EVM-137" /* POLYGON_MAINNET */]: "0x8b536105b6Fae2aE9199f5146D3C57Dfe53b614E",
3433
+ ["EVM-130" /* UNICHAIN_MAINNET */]: "0x8b536105b6Fae2aE9199f5146D3C57Dfe53b614E"
3434
+ },
3424
3435
  Host: {
3425
3436
  ["EVM-97" /* BSC_CHAPEL */]: "0x8Aa0Dea6D675d785A882967Bf38183f6117C09b7",
3426
3437
  ["EVM-10200" /* GNOSIS_CHIADO */]: "0x58a41b89f4871725e5d898d98ef4bf917601c5eb",
@@ -3612,6 +3623,9 @@ var ChainConfigService = class {
3612
3623
  getIntentGatewayAddress(chain) {
3613
3624
  return addresses.IntentGateway[chain];
3614
3625
  }
3626
+ getTokenGatewayAddress(chain) {
3627
+ return addresses.TokenGateway[chain];
3628
+ }
3615
3629
  getHostAddress(chain) {
3616
3630
  return addresses.Host[chain];
3617
3631
  }
@@ -12823,6 +12837,40 @@ var IntentGateway = class {
12823
12837
  });
12824
12838
  return filledStatus !== "0x0000000000000000000000000000000000000000000000000000000000000000";
12825
12839
  }
12840
+ /**
12841
+ * Checks if an order has been refunded by verifying the escrowed token amounts on-chain.
12842
+ * Reads the storage slots for the `_orders` mapping on the source chain (where the escrow is held).
12843
+ * An order is considered refunded when all input token amounts in the `_orders` mapping are 0.
12844
+ *
12845
+ * @param order - The order to check
12846
+ * @returns True if the order has been refunded (all token amounts are 0), false otherwise
12847
+ */
12848
+ async isOrderRefunded(order) {
12849
+ order = transformOrder(order);
12850
+ const intentGatewayAddress = this.destIntentGatewayAddress ?? this.source.configService.getIntentGatewayAddress(order.sourceChain);
12851
+ const commitment = order.id;
12852
+ const ORDERS_MAPPING_SLOT = 4n;
12853
+ const firstLevelSlot = keccak256(
12854
+ encodeAbiParameters([{ type: "bytes32" }, { type: "uint256" }], [commitment, ORDERS_MAPPING_SLOT])
12855
+ );
12856
+ for (const input of order.inputs) {
12857
+ const tokenAddress = bytes32ToBytes20(input.token);
12858
+ const storageSlot = keccak256(
12859
+ encodeAbiParameters(
12860
+ [{ type: "address" }, { type: "bytes32" }],
12861
+ [tokenAddress, firstLevelSlot]
12862
+ )
12863
+ );
12864
+ const escrowedAmount = await this.source.client.getStorageAt({
12865
+ address: intentGatewayAddress,
12866
+ slot: storageSlot
12867
+ });
12868
+ if (escrowedAmount !== "0x0000000000000000000000000000000000000000000000000000000000000000") {
12869
+ return false;
12870
+ }
12871
+ }
12872
+ return true;
12873
+ }
12826
12874
  async submitAndConfirmReceipt(hyperbridge, commitment, message) {
12827
12875
  let storageValue = await hyperbridge.queryRequestReceipt(commitment);
12828
12876
  if (!storageValue) {
@@ -13103,6 +13151,140 @@ async function fetchSourceProof(commitment, source, sourceStateMachine, sourceCo
13103
13151
  proof: proofHex
13104
13152
  };
13105
13153
  }
13154
+ var TokenGateway = class {
13155
+ source;
13156
+ dest;
13157
+ constructor(params) {
13158
+ this.source = params.source;
13159
+ this.dest = params.dest;
13160
+ }
13161
+ /**
13162
+ * Get the TokenGateway contract address for a given chain
13163
+ *
13164
+ * @param chain - The chain identifier (e.g., "EVM-1", "EVM-56")
13165
+ * @returns The TokenGateway contract address
13166
+ */
13167
+ getTokenGatewayAddress(chain) {
13168
+ const chainStr = typeof chain === "string" ? chain : new TextDecoder().decode(chain);
13169
+ return this.source.configService.getTokenGatewayAddress(chainStr);
13170
+ }
13171
+ /**
13172
+ * Estimate the native token cost for a token gateway teleport operation.
13173
+ * This includes both relayer fees and protocol fees for cross-chain delivery.
13174
+ *
13175
+ * The relayer fee is automatically estimated for EVM destination chains by:
13176
+ * 1. Creating a dummy post request with 191 bytes of random data in the body
13177
+ * 2. Estimating gas for delivery on the destination chain
13178
+ * 3. Converting the gas estimate to native tokens
13179
+ * 4. Adding a 1% buffer to the relayer fee for safety margin
13180
+ *
13181
+ * For non-EVM destination chains, the relayer fee is set to zero.
13182
+ *
13183
+ * The function then constructs a proper post request and calls quoteNative on the
13184
+ * source chain to get protocol fees (with 1% buffer), converts the relayer fee to
13185
+ * source chain fee token using Uniswap V2's getAmountsOut, and returns both values.
13186
+ *
13187
+ * @param params - The teleport parameters
13188
+ * @returns Object containing totalNativeCost (with 1% buffer) and relayerFeeInSourceFeeToken
13189
+ *
13190
+ * @throws Will throw an error if the contract call fails
13191
+ *
13192
+ * @example
13193
+ * ```typescript
13194
+ * const params: TeleportParams = {
13195
+ * amount: parseEther("1.0"),
13196
+ * assetId: keccak256(toHex("USDC")),
13197
+ * redeem: true,
13198
+ * to: pad("0xRecipientAddress", { size: 32 }),
13199
+ * dest: "EVM-1",
13200
+ * timeout: 3600n,
13201
+ * data: "0x"
13202
+ * }
13203
+ *
13204
+ * const { totalNativeCost, relayerFeeInSourceFeeToken } = await tokenGateway.quoteNative(params)
13205
+ * console.log(`Total native cost: ${formatEther(totalNativeCost)} ETH`)
13206
+ * console.log(`Relayer fee in fee token: ${relayerFeeInSourceFeeToken}`)
13207
+ * ```
13208
+ */
13209
+ async quoteNative(params) {
13210
+ const dataHex = params.data ? typeof params.data === "string" ? params.data : toHex(params.data) : "0x";
13211
+ const sourceTokenGatewayAddress = this.getTokenGatewayAddress(this.source.config.stateMachineId);
13212
+ const destTokenGatewayAddress = this.getTokenGatewayAddress(params.dest);
13213
+ let relayerFee = 0n;
13214
+ const destChainId = typeof params.dest === "string" ? params.dest : new TextDecoder().decode(params.dest);
13215
+ const isEvmDest = destChainId.startsWith("EVM-") && this.dest instanceof EvmChain;
13216
+ if (isEvmDest) {
13217
+ const randomHex = "0x" + Array.from({ length: 191 * 2 }, () => Math.floor(Math.random() * 16).toString(16)).join("");
13218
+ const randomBody = randomHex;
13219
+ const dummyPostRequest = {
13220
+ source: this.source.config.stateMachineId,
13221
+ dest: destChainId,
13222
+ from: sourceTokenGatewayAddress,
13223
+ to: destTokenGatewayAddress,
13224
+ nonce: 0n,
13225
+ body: randomBody,
13226
+ timeoutTimestamp: params.timeout
13227
+ };
13228
+ const { gas } = await this.dest.estimateGas(dummyPostRequest);
13229
+ const gasPrice = await this.dest.client.getGasPrice();
13230
+ const gasCostInNative = gas * gasPrice;
13231
+ relayerFee = gasCostInNative * 101n / 100n;
13232
+ }
13233
+ const teleportBody = encodeAbiParameters(
13234
+ parseAbiParameters("uint256, uint256, bytes32, bool, bytes32, bytes"),
13235
+ [
13236
+ params.amount,
13237
+ relayerFee,
13238
+ // Use the calculated relayer fee (0 for non-EVM destinations)
13239
+ params.assetId,
13240
+ params.redeem,
13241
+ params.to,
13242
+ dataHex
13243
+ ]
13244
+ );
13245
+ const postRequest = {
13246
+ source: this.source.config.stateMachineId,
13247
+ dest: destChainId,
13248
+ from: sourceTokenGatewayAddress,
13249
+ to: destTokenGatewayAddress,
13250
+ nonce: 0n,
13251
+ body: teleportBody,
13252
+ timeoutTimestamp: params.timeout
13253
+ };
13254
+ const protocolFeeInNative = await this.source.quoteNative(postRequest, relayerFee);
13255
+ const protocolFeeWithBuffer = protocolFeeInNative * 101n / 100n;
13256
+ let relayerFeeInSourceFeeToken = 0n;
13257
+ if (relayerFee > 0n) {
13258
+ const feeToken = await this.source.getFeeTokenWithDecimals();
13259
+ relayerFeeInSourceFeeToken = await this.convertNativeToFeeToken(
13260
+ relayerFee,
13261
+ feeToken.address,
13262
+ this.source.config.stateMachineId
13263
+ );
13264
+ }
13265
+ return {
13266
+ totalNativeCost: protocolFeeWithBuffer,
13267
+ relayerFeeInSourceFeeToken
13268
+ };
13269
+ }
13270
+ /**
13271
+ * Convert native token amount to fee token amount using Uniswap V2 router
13272
+ * @private
13273
+ */
13274
+ async convertNativeToFeeToken(nativeAmount, feeTokenAddress, chain) {
13275
+ const v2Router = this.source.configService.getUniswapRouterV2Address(chain);
13276
+ const WETH = this.source.configService.getWrappedNativeAssetWithDecimals(chain).asset;
13277
+ const v2AmountOut = await this.source.client.simulateContract({
13278
+ address: v2Router,
13279
+ abi: uniswapRouterV2_default.ABI,
13280
+ // @ts-ignore
13281
+ functionName: "getAmountsOut",
13282
+ // @ts-ignore
13283
+ args: [nativeAmount, [WETH, feeTokenAddress]]
13284
+ });
13285
+ return v2AmountOut.result[1];
13286
+ }
13287
+ };
13106
13288
  async function getOrderPlacedFromTx(client, txHash) {
13107
13289
  const receipt = await client.getTransactionReceipt({ hash: txHash });
13108
13290
  const events = parseEventLogs({
@@ -13418,6 +13600,6 @@ async function teleportDot(param_) {
13418
13600
  return stream;
13419
13601
  }
13420
13602
 
13421
- export { ADDRESS_ZERO, ChainConfigService, Chains, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DUMMY_PRIVATE_KEY, ERC20Method, EvmChain, HyperClientStatus, IndexerClient, IntentGateway, OrderStatus, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, RequestKind, RequestStatus, STATE_COMMITMENTS_SLOT, SubstrateChain, TESTNET_CHAINS, TeleportStatus, TimeoutStatus, USE_ETHERSCAN_CHAINS, WrappedNativeDecimals, __test, addresses, adjustFeeDecimals, assets, bytes20ToBytes32, bytes32ToBytes20, chainIds, coingeckoIds, consensusStateIds, constructRedeemEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createChain, createEvmChain, createIndexerClient, createQueryClient, createRpcUrls, encodeISMPMessage, estimateGasForPost, fetchPrice, generateRootWithProof, getChain, getGasPriceFromEtherscan, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, hexToString, maxBigInt, orderCommitment, popularTokens, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, requestCommitmentKey, retryPromise, teleport, teleportDot, viemChains };
13603
+ export { ADDRESS_ZERO, ChainConfigService, Chains, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DUMMY_PRIVATE_KEY, ERC20Method, EvmChain, HyperClientStatus, IndexerClient, IntentGateway, OrderStatus, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, RequestKind, RequestStatus, STATE_COMMITMENTS_SLOT, SubstrateChain, TESTNET_CHAINS, TeleportStatus, TimeoutStatus, TokenGateway, USE_ETHERSCAN_CHAINS, WrappedNativeDecimals, __test, addresses, adjustFeeDecimals, assets, bytes20ToBytes32, bytes32ToBytes20, chainIds, coingeckoIds, consensusStateIds, constructRedeemEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createChain, createEvmChain, createIndexerClient, createQueryClient, createRpcUrls, encodeISMPMessage, estimateGasForPost, fetchPrice, generateRootWithProof, getChain, getGasPriceFromEtherscan, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, hexToString, maxBigInt, orderCommitment, popularTokens, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, requestCommitmentKey, retryPromise, teleport, teleportDot, viemChains };
13422
13604
  //# sourceMappingURL=index.js.map
13423
13605
  //# sourceMappingURL=index.js.map