@hyperbridge/sdk 1.1.12 → 1.2.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.
@@ -3,6 +3,7 @@ import { GraphQLClient } from 'graphql-request';
3
3
  import { Hex, Log, PublicClient } from 'viem';
4
4
  import { ApiPromise } from '@polkadot/api';
5
5
  import { SignerOptions } from '@polkadot/api/types';
6
+ import { Chain } from 'viem/chains';
6
7
 
7
8
  type HexString = `0x${string}`;
8
9
  interface IConfig {
@@ -859,10 +860,6 @@ interface HostParams {
859
860
  */
860
861
  hyperbridge: HexString;
861
862
  }
862
- declare enum EvmLanguage {
863
- Solidity = 0,
864
- Vyper = 1
865
- }
866
863
  interface OrderStatusMetadata {
867
864
  status: OrderStatus;
868
865
  chain: string;
@@ -947,6 +944,32 @@ declare class AbortSignalInternal extends Error {
947
944
  static isError(error: unknown): error is AbortSignalInternal;
948
945
  }
949
946
 
947
+ declare class ChainConfigService {
948
+ private rpcUrls;
949
+ constructor(env?: NodeJS.ProcessEnv);
950
+ getChainConfig(chain: string): ChainConfig;
951
+ getIntentGatewayAddress(chain: string): `0x${string}`;
952
+ getHostAddress(chain: string): `0x${string}`;
953
+ getWrappedNativeAssetWithDecimals(chain: string): {
954
+ asset: HexString;
955
+ decimals: number;
956
+ };
957
+ getDaiAsset(chain: string): HexString;
958
+ getUsdtAsset(chain: string): HexString;
959
+ getUsdcAsset(chain: string): HexString;
960
+ getChainId(chain: string): number;
961
+ getConsensusStateId(chain: string): HexString;
962
+ getHyperbridgeChainId(): number;
963
+ getRpcUrl(chain: string): string;
964
+ getUniswapRouterV2Address(chain: string): HexString;
965
+ getUniswapV2FactoryAddress(chain: string): HexString;
966
+ getBatchExecutorAddress(chain: string): HexString;
967
+ getUniversalRouterAddress(chain: string): HexString;
968
+ getUniswapV3RouterAddress(chain: string): HexString;
969
+ getUniswapV3FactoryAddress(chain: string): HexString;
970
+ getUniswapV3QuoterAddress(chain: string): HexString;
971
+ }
972
+
950
973
  /**
951
974
  * The default address used as fallback when no address is provided.
952
975
  * This represents the zero address in EVM chains.
@@ -975,7 +998,11 @@ interface EvmChainParams {
975
998
  declare class EvmChain implements IChain {
976
999
  private readonly params;
977
1000
  private publicClient;
1001
+ private chainConfigService;
978
1002
  constructor(params: EvmChainParams);
1003
+ get client(): PublicClient;
1004
+ get host(): HexString;
1005
+ get config(): ChainConfigService;
979
1006
  /**
980
1007
  * Derives the key for the request receipt.
981
1008
  * @param {HexString} commitment - The commitment to derive the key from.
@@ -1016,7 +1043,7 @@ declare class EvmChain implements IChain {
1016
1043
  latestStateMachineHeight(stateMachineId: StateMachineIdParams): Promise<bigint>;
1017
1044
  /**
1018
1045
  * Get the state machine update time for a given state machine height.
1019
- * @param {StateMachineHeight} stateMachineheight - The state machine height.
1046
+ * @param {StateMachineHeight} stateMachineHeight - The state machine height.
1020
1047
  * @returns {Promise<bigint>} The statemachine update time in seconds.
1021
1048
  */
1022
1049
  stateMachineUpdateTime(stateMachineHeight: StateMachineHeight): Promise<bigint>;
@@ -1032,6 +1059,43 @@ declare class EvmChain implements IChain {
1032
1059
  * @returns {HexString} The encoded calldata.
1033
1060
  */
1034
1061
  encode(message: IIsmpMessage): HexString;
1062
+ /**
1063
+ * Calculates the fee required to send a post request to the destination chain.
1064
+ * The fee is calculated based on the per-byte fee for the destination chain
1065
+ * multiplied by the size of the request body.
1066
+ *
1067
+ * @param request - The post request to calculate the fee for
1068
+ * @returns The total fee in wei required to send the post request
1069
+ */
1070
+ quote(request: IPostRequest): Promise<bigint>;
1071
+ /**
1072
+ * Estimates the gas required for a post request execution on this chain.
1073
+ * This function generates mock proofs for the post request, creates a state override
1074
+ * with the necessary overlay root, and estimates the gas cost for executing the
1075
+ * handlePostRequests transaction on the handler contract.
1076
+ *
1077
+ * @param request - The post request to estimate gas for
1078
+ * @param paraId - The ID of the parachain (Hyperbridge) that will process the request
1079
+ * @returns The estimated gas amount in gas units
1080
+ */
1081
+ estimateGas(request: IPostRequest): Promise<bigint>;
1082
+ /**
1083
+ * Gets the fee token address and decimals for the chain.
1084
+ * This function gets the fee token address and decimals for the chain.
1085
+ *
1086
+ * @returns The fee token address and decimals
1087
+ */
1088
+ getFeeTokenWithDecimals(): Promise<{
1089
+ address: HexString;
1090
+ decimals: number;
1091
+ }>;
1092
+ /**
1093
+ * Gets the nonce of the host.
1094
+ * This function gets the nonce of the host.
1095
+ *
1096
+ * @returns The nonce of the host
1097
+ */
1098
+ getHostNonce(): Promise<bigint>;
1035
1099
  }
1036
1100
  /**
1037
1101
  * Slot for storing request commitments.
@@ -1158,15 +1222,50 @@ declare function estimateGasForPost(params: {
1158
1222
  */
1159
1223
  declare function constructRedeemEscrowRequestBody(order: Order, beneficiary: HexString): HexString;
1160
1224
  /**
1161
- * Calculates the balance mapping location for a given slot and holder address.
1162
- * This function handles the different encoding formats used by Solidity and Vyper.
1225
+ * Fetches the USD price of a token from CoinGecko with Defillama fallback
1226
+ * @param identifier - The ticker symbol of the token (e.g., "BTC", "ETH", "USDC") or contract address
1227
+ * @note This function will be replaced by internal price indexer
1228
+ * @returns The USD price of the token as a number (preserves decimals)
1229
+ */
1230
+ declare function fetchTokenUsdPrice(identifier: string): Promise<number>;
1231
+ /**
1232
+ * Retrieves the storage slot for a contract call using debug_traceCall
1233
+ *
1234
+ * This function uses the Ethereum debug API to trace contract execution and identify
1235
+ * the storage slot accessed during the call. It's commonly used for ERC20 token state
1236
+ * mappings like balanceOf and allowance, but can work with any contract call that
1237
+ * performs SLOAD operations.
1238
+ *
1239
+ * @param client - The viem PublicClient instance connected to an RPC node with debug API enabled
1240
+ * @param tokenAddress - The address of the contract to trace
1241
+ * @param data - The full encoded function call data (method signature + encoded parameters)
1242
+ * @returns The storage slot as a hex string
1243
+ * @throws Error if the storage slot cannot be found or if debug API is not available
1244
+ *
1245
+ * @example
1246
+ * ```ts
1247
+ * import { ERC20Method, bytes20ToBytes32 } from '@hyperbridge/sdk'
1163
1248
  *
1164
- * @param slot - The slot number to calculate the mapping location for.
1165
- * @param holder - The address of the holder to calculate the mapping location for.
1166
- * @param language - The language of the contract.
1167
- * @returns The balance mapping location as a HexString.
1249
+ * // Get balance storage slot for ERC20
1250
+ * const balanceData = ERC20Method.BALANCE_OF + bytes20ToBytes32(userAddress).slice(2)
1251
+ * const balanceSlot = await getStorageSlot(
1252
+ * client,
1253
+ * tokenAddress,
1254
+ * balanceData as HexString
1255
+ * )
1256
+ *
1257
+ * // Get allowance storage slot for ERC20
1258
+ * const allowanceData = ERC20Method.ALLOWANCE +
1259
+ * bytes20ToBytes32(ownerAddress).slice(2) +
1260
+ * bytes20ToBytes32(spenderAddress).slice(2)
1261
+ * const allowanceSlot = await getStorageSlot(
1262
+ * client,
1263
+ * tokenAddress,
1264
+ * allowanceData as HexString
1265
+ * )
1266
+ * ```
1168
1267
  */
1169
- declare function calculateBalanceMappingLocation(slot: bigint, holder: string, language: EvmLanguage): HexString;
1268
+ declare function getStorageSlot(client: PublicClient, contractAddress: HexString, data: HexString): Promise<string>;
1170
1269
 
1171
1270
  interface SubstrateChainParams {
1172
1271
  ws: string;
@@ -1794,6 +1893,91 @@ declare function queryGetRequest(params: {
1794
1893
  queryClient: IndexerQueryClient;
1795
1894
  }): Promise<GetRequestWithStatus | undefined>;
1796
1895
 
1896
+ /**
1897
+ * IntentGateway handles cross-chain intent operations between EVM chains.
1898
+ * It provides functionality for estimating fill orders, finding optimal swap protocols,
1899
+ * and checking order statuses across different chains.
1900
+ */
1901
+ declare class IntentGateway {
1902
+ readonly source: EvmChain;
1903
+ readonly dest: EvmChain;
1904
+ /**
1905
+ * Creates a new IntentGateway instance for cross-chain operations.
1906
+ * @param source - The source EVM chain
1907
+ * @param dest - The destination EVM chain
1908
+ */
1909
+ constructor(source: EvmChain, dest: EvmChain);
1910
+ /**
1911
+ * Estimates the total cost required to fill an order, including gas fees, relayer fees,
1912
+ * protocol fees, and swap operations.
1913
+ *
1914
+ * @param order - The order to estimate fill costs for
1915
+ * @returns The estimated total cost in the source chain's fee token
1916
+ */
1917
+ estimateFillOrder(order: Order): Promise<bigint>;
1918
+ /**
1919
+ * Finds the best Uniswap protocol (V2 or V3) for swapping tokens given a desired output amount.
1920
+ * Compares liquidity and pricing across different protocols and fee tiers.
1921
+ *
1922
+ * @param chain - The chain identifier where the swap will occur
1923
+ * @param tokenIn - The address of the input token
1924
+ * @param tokenOut - The address of the output token
1925
+ * @param amountOut - The desired output amount
1926
+ * @returns Object containing the best protocol, required input amount, fee tier (for V3), and gas estimate
1927
+ */
1928
+ findBestProtocolWithAmountOut(chain: string, tokenIn: HexString, tokenOut: HexString, amountOut: bigint): Promise<{
1929
+ protocol: "v2" | "v3" | null;
1930
+ amountIn: bigint;
1931
+ fee?: number;
1932
+ gasEstimate?: bigint;
1933
+ }>;
1934
+ /**
1935
+ * Finds the best Uniswap protocol (V2 or V3) for swapping tokens given an input amount.
1936
+ * Compares liquidity and pricing across different protocols and fee tiers.
1937
+ *
1938
+ * @param chain - The chain identifier where the swap will occur
1939
+ * @param tokenIn - The address of the input token
1940
+ * @param tokenOut - The address of the output token
1941
+ * @param amountIn - The input amount to swap
1942
+ * @returns Object containing the best protocol, expected output amount, fee tier (for V3), and gas estimate
1943
+ */
1944
+ findBestProtocolWithAmountIn(chain: string, tokenIn: HexString, tokenOut: HexString, amountIn: bigint): Promise<{
1945
+ protocol: "v2" | "v3" | null;
1946
+ amountOut: bigint;
1947
+ fee?: number;
1948
+ gasEstimate?: bigint;
1949
+ }>;
1950
+ /**
1951
+ * Converts gas costs to the equivalent amount in the fee token (DAI).
1952
+ * Uses USD pricing to convert between native token gas costs and fee token amounts.
1953
+ *
1954
+ * @param gasEstimate - The estimated gas units
1955
+ * @param publicClient - The client for the chain to get gas prices
1956
+ * @param targetDecimals - The decimal places of the target fee token
1957
+ * @returns The gas cost converted to fee token amount
1958
+ * @private
1959
+ */
1960
+ private convertGasToFeeToken;
1961
+ /**
1962
+ * Adjusts fee amounts between different decimal precisions.
1963
+ * Handles scaling up or down based on the decimal difference.
1964
+ *
1965
+ * @param feeInFeeToken - The fee amount to adjust
1966
+ * @param fromDecimals - The current decimal precision
1967
+ * @param toDecimals - The target decimal precision
1968
+ * @returns The adjusted fee amount with the target decimal precision
1969
+ */
1970
+ adjustFeeDecimals(feeInFeeToken: bigint, fromDecimals: number, toDecimals: number): bigint;
1971
+ /**
1972
+ * Checks if an order has been filled by verifying the commitment status on-chain.
1973
+ * Reads the storage slot corresponding to the order's commitment hash.
1974
+ *
1975
+ * @param order - The order to check
1976
+ * @returns True if the order has been filled, false otherwise
1977
+ */
1978
+ isOrderFilled(order: Order): Promise<boolean>;
1979
+ }
1980
+
1797
1981
  type HyperbridgeTxEvents = {
1798
1982
  kind: "Ready";
1799
1983
  transaction_hash: HexString;
@@ -1949,4 +2133,58 @@ declare function teleport(teleport_param: {
1949
2133
  options: Partial<SignerOptions>;
1950
2134
  }): Promise<ReadableStream<HyperbridgeTxEvents>>;
1951
2135
 
1952
- export { ADDRESS_ZERO, AbortSignalInternal, type AllStatusKey, type AssetTeleported, type AssetTeleportedResponse, type BlockMetadata, type CancelOptions, type ChainConfig, type ClientConfig, DEFAULT_ADDRESS, DUMMY_PRIVATE_KEY, type DecodedOrderPlacedLog, type DispatchGet, type DispatchPost, EvmChain, type EvmChainParams, EvmLanguage, 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, 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, SubstrateChain, type SubstrateChainParams, TeleportStatus, TimeoutStatus, type TimeoutStatusKey, type TokenGatewayAssetTeleportedResponse, type TokenGatewayAssetTeleportedWithStatus, type TokenInfo, type XcmGatewayParams, __test, bytes20ToBytes32, bytes32ToBytes20, calculateBalanceMappingLocation, constructRedeemEscrowRequestBody, convertStateMachineIdToEnum, createQueryClient, encodeISMPMessage, estimateGasForPost, generateRootWithProof, getChain, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, hexToString, orderCommitment, postRequestCommitment, queryGetRequest, queryPostRequest, teleport, teleportDot };
2136
+ declare enum Chains {
2137
+ BSC_CHAPEL = "EVM-97",
2138
+ GNOSIS_CHIADO = "EVM-10200",
2139
+ HYPERBRIDGE_GARGANTUA = "KUSAMA-4009",
2140
+ SEPOLIA = "EVM-11155111"
2141
+ }
2142
+ type AddressMap = {
2143
+ [key: string]: {
2144
+ [K in Chains]?: `0x${string}`;
2145
+ };
2146
+ };
2147
+ type RpcMap = Record<Chains, string>;
2148
+ declare const chainIds: {
2149
+ readonly "EVM-97": 97;
2150
+ readonly "EVM-10200": 10200;
2151
+ readonly "KUSAMA-4009": 4009;
2152
+ readonly "EVM-11155111": 11155111;
2153
+ };
2154
+ type ChainId = typeof chainIds;
2155
+ declare const viemChains: Record<string, Chain>;
2156
+ declare const WrappedNativeDecimals: {
2157
+ "EVM-97": number;
2158
+ "EVM-10200": number;
2159
+ "EVM-11155111": number;
2160
+ };
2161
+ declare const assets: {
2162
+ "EVM-97": {
2163
+ WETH: string;
2164
+ DAI: string;
2165
+ USDC: string;
2166
+ USDT: string;
2167
+ };
2168
+ "EVM-10200": {
2169
+ WETH: string;
2170
+ DAI: string;
2171
+ USDC: string;
2172
+ USDT: string;
2173
+ };
2174
+ "EVM-11155111": {
2175
+ WETH: string;
2176
+ USDC: string;
2177
+ USDT: string;
2178
+ DAI: string;
2179
+ };
2180
+ };
2181
+ declare const addresses: AddressMap;
2182
+ declare const createRpcUrls: (env: NodeJS.ProcessEnv) => RpcMap;
2183
+ declare const consensusStateIds: {
2184
+ "EVM-97": string;
2185
+ "EVM-10200": string;
2186
+ "KUSAMA-4009": string;
2187
+ "EVM-11155111": string;
2188
+ };
2189
+
2190
+ export { ADDRESS_ZERO, AbortSignalInternal, type AllStatusKey, type AssetTeleported, type AssetTeleportedResponse, type BlockMetadata, type CancelOptions, type ChainConfig, ChainConfigService, type ChainId, Chains, type ClientConfig, DEFAULT_ADDRESS, DUMMY_PRIVATE_KEY, type DecodedOrderPlacedLog, type DispatchGet, type DispatchPost, 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, SubstrateChain, type SubstrateChainParams, TeleportStatus, TimeoutStatus, type TimeoutStatusKey, type TokenGatewayAssetTeleportedResponse, type TokenGatewayAssetTeleportedWithStatus, type TokenInfo, WrappedNativeDecimals, type XcmGatewayParams, __test, addresses, assets, bytes20ToBytes32, bytes32ToBytes20, chainIds, consensusStateIds, constructRedeemEscrowRequestBody, convertStateMachineIdToEnum, createQueryClient, createRpcUrls, encodeISMPMessage, estimateGasForPost, fetchTokenUsdPrice, generateRootWithProof, getChain, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, hexToString, orderCommitment, postRequestCommitment, queryGetRequest, queryPostRequest, teleport, teleportDot, viemChains };