UNPKG

@hyperlane-xyz/sdk

Version:

The official SDK for the Hyperlane Network

260 lines 11.8 kB
import type { CosmWasmClient, Contract as CosmWasmContract, ExecuteInstruction } from '@cosmjs/cosmwasm-stargate'; import type { EncodeObject as CmTransaction } from '@cosmjs/proto-signing'; import type { DeliverTxResponse, StargateClient } from '@cosmjs/stargate'; import type { Connection, Transaction as SolTransaction, VersionedTransactionResponse as SolTransactionReceipt } from '@solana/web3.js'; import type { Contract as EV5Contract, providers as EV5Providers, PopulatedTransaction as EV5Transaction } from 'ethers'; import { Contract as StarknetContract, Invocation as StarknetInvocation, Provider as StarknetProvider, GetTransactionReceiptResponse as StarknetTxReceipt } from 'starknet'; import type { GetContractReturnType, PublicClient, Transaction as VTransaction, TransactionReceipt as VTransactionReceipt } from 'viem'; import { Contract as ZKSyncBaseContract, Provider as ZKSyncBaseProvider, types as zkSyncTypes } from 'zksync-ethers'; import { CosmosNativeProvider } from '@hyperlane-xyz/cosmos-sdk'; import { RadixProvider as RadixSDKProvider, RadixSDKReceipt, RadixSDKTransaction } from '@hyperlane-xyz/radix-sdk'; import { Annotated, ProtocolType } from '@hyperlane-xyz/utils'; export declare enum ProviderType { EthersV5 = "ethers-v5", Viem = "viem", SolanaWeb3 = "solana-web3", CosmJs = "cosmjs", CosmJsNative = "cosmjs-native", CosmJsWasm = "cosmjs-wasm", GnosisTxBuilder = "gnosis-txBuilder", Starknet = "starknet", ZkSync = "zksync", Radix = "radix", Aleo = "aleo" } export declare const PROTOCOL_TO_DEFAULT_PROVIDER_TYPE: Record<ProtocolType, ProviderType>; export type ProviderMap<Value> = Partial<Record<ProviderType, Value>>; type ProtocolTypesMapping = { [ProtocolType.Ethereum]: { transaction: EthersV5Transaction; provider: EthersV5Provider; contract: EthersV5Contract; receipt: EthersV5TransactionReceipt; }; [ProtocolType.Sealevel]: { transaction: SolanaWeb3Transaction; provider: SolanaWeb3Provider; contract: SolanaWeb3Contract; receipt: SolanaWeb3TransactionReceipt; }; [ProtocolType.Cosmos]: { transaction: CosmJsWasmTransaction; provider: CosmJsWasmProvider; contract: CosmJsWasmContract; receipt: CosmJsWasmTransactionReceipt; }; [ProtocolType.CosmosNative]: { transaction: CosmJsNativeTransaction; provider: CosmJsNativeProvider; contract: null; receipt: CosmJsNativeTransactionReceipt; }; [ProtocolType.Starknet]: { transaction: StarknetJsTransaction; provider: StarknetJsProvider; contract: StarknetJsContract; receipt: StarknetJsTransactionReceipt; }; [ProtocolType.Radix]: { transaction: RadixTransaction; provider: RadixProvider; contract: null; receipt: RadixTransactionReceipt; }; [ProtocolType.Aleo]: { transaction: any; provider: any; contract: any; receipt: any; }; }; type ProtocolTyped<T extends ProtocolType, K extends keyof ProtocolTypesMapping[T]> = ProtocolTypesMapping[T][K]; export type ProtocolTypedTransaction<T extends ProtocolType> = ProtocolTyped<T, 'transaction'>; export type ProtocolTypedProvider<T extends ProtocolType> = ProtocolTyped<T, 'provider'>; export type ProtocolTypedContract<T extends ProtocolType> = ProtocolTyped<T, 'contract'>; export type ProtocolTypedReceipt<T extends ProtocolType> = ProtocolTyped<T, 'receipt'>; export type AnyProtocolTransaction = ProtocolTransaction<ProtocolType>; export type ProtocolTransaction<T extends ProtocolType> = ProtocolTypedTransaction<T>['transaction']; export type AnyProtocolReceipt = ProtocolReceipt<ProtocolType>; export type ProtocolReceipt<T extends ProtocolType> = ProtocolTypedReceipt<T>['receipt']; export type AnnotatedTypedTransaction<T extends ProtocolType> = Annotated<ProtocolTransaction<T>>; /** * Providers with discriminated union of type */ interface TypedProviderBase<T> { type: ProviderType; provider: T; } export interface EthersV5Provider extends TypedProviderBase<EV5Providers.Provider> { type: ProviderType.EthersV5; provider: EV5Providers.Provider; } export interface ViemProvider extends TypedProviderBase<PublicClient> { type: ProviderType.Viem; provider: PublicClient; } export interface SolanaWeb3Provider extends TypedProviderBase<Connection> { type: ProviderType.SolanaWeb3; provider: Connection; } export interface CosmJsProvider extends TypedProviderBase<Promise<StargateClient>> { type: ProviderType.CosmJs; provider: Promise<StargateClient>; } export interface CosmJsWasmProvider extends TypedProviderBase<Promise<CosmWasmClient>> { type: ProviderType.CosmJsWasm; provider: Promise<CosmWasmClient>; } export interface CosmJsNativeProvider extends TypedProviderBase<Promise<CosmosNativeProvider>> { type: ProviderType.CosmJsNative; provider: Promise<CosmosNativeProvider>; } export interface StarknetJsProvider extends TypedProviderBase<StarknetProvider> { type: ProviderType.Starknet; provider: StarknetProvider; } export interface RadixProvider extends TypedProviderBase<RadixSDKProvider> { type: ProviderType.Radix; provider: RadixSDKProvider; } export interface ZKSyncProvider extends TypedProviderBase<ZKSyncBaseProvider> { type: ProviderType.ZkSync; provider: ZKSyncBaseProvider; } export type TypedProvider = EthersV5Provider | ViemProvider | SolanaWeb3Provider | CosmJsProvider | CosmJsWasmProvider | CosmJsNativeProvider | StarknetJsProvider | ZKSyncProvider | RadixProvider; /** * Contracts with discriminated union of provider type */ interface TypedContractBase<T> { type: ProviderType; contract: T; } export interface EthersV5Contract extends TypedContractBase<EV5Contract> { type: ProviderType.EthersV5; contract: EV5Contract; } export interface ViemContract extends TypedContractBase<GetContractReturnType> { type: ProviderType.Viem; contract: GetContractReturnType; } export interface SolanaWeb3Contract extends TypedContractBase<never> { type: ProviderType.SolanaWeb3; contract: never; } export interface CosmJsContract extends TypedContractBase<never> { type: ProviderType.CosmJs; contract: never; } export interface CosmJsWasmContract extends TypedContractBase<CosmWasmContract> { type: ProviderType.CosmJsWasm; contract: CosmWasmContract; } export interface StarknetJsContract extends TypedContractBase<StarknetContract> { type: ProviderType.Starknet; contract: StarknetContract; } export interface ZKSyncContract extends TypedContractBase<ZKSyncBaseContract> { type: ProviderType.ZkSync; contract: ZKSyncBaseContract; } export type TypedContract = EthersV5Contract | ViemContract | SolanaWeb3Contract | CosmJsContract | CosmJsWasmContract | StarknetJsContract | ZKSyncBaseContract; /** * Transactions with discriminated union of provider type */ interface TypedTransactionBase<T> { type: ProviderType; transaction: T; } export interface EthersV5Transaction extends TypedTransactionBase<EV5Transaction> { type: ProviderType.EthersV5; transaction: EV5Transaction; } export interface ViemTransaction extends TypedTransactionBase<VTransaction> { type: ProviderType.Viem; transaction: VTransaction; } export interface SolanaWeb3Transaction extends TypedTransactionBase<SolTransaction> { type: ProviderType.SolanaWeb3; transaction: SolTransaction; } export interface CosmJsTransaction extends TypedTransactionBase<CmTransaction> { type: ProviderType.CosmJs; transaction: CmTransaction; } export interface CosmJsWasmTransaction extends TypedTransactionBase<ExecuteInstruction> { type: ProviderType.CosmJsWasm; transaction: ExecuteInstruction; } export interface CosmJsNativeTransaction extends TypedTransactionBase<CmTransaction> { type: ProviderType.CosmJsNative; transaction: CmTransaction; } export interface StarknetJsTransaction extends TypedTransactionBase<StarknetInvocation> { type: ProviderType.Starknet; transaction: StarknetInvocation; } export interface RadixTransaction extends TypedTransactionBase<RadixSDKTransaction> { type: ProviderType.Radix; transaction: RadixSDKTransaction; } export interface ZKSyncTransaction extends TypedTransactionBase<zkSyncTypes.TransactionRequest> { type: ProviderType.ZkSync; transaction: zkSyncTypes.TransactionRequest; } export type TypedTransaction = EthersV5Transaction | ViemTransaction | SolanaWeb3Transaction | CosmJsTransaction | CosmJsWasmTransaction | CosmJsNativeTransaction | StarknetJsTransaction | ZKSyncTransaction | RadixTransaction; export type AnnotatedEV5Transaction = Annotated<EV5Transaction>; export type AnnotatedViemTransaction = Annotated<VTransaction>; export type AnnotatedSolanaWeb3Transaction = Annotated<SolTransaction>; export type AnnotatedCosmJsTransaction = Annotated<CmTransaction>; export type AnnotatedCosmJsWasmTransaction = Annotated<ExecuteInstruction>; export type AnnotatedCosmJsNativeTransaction = Annotated<CmTransaction>; export type AnnotatedStarknetJsTransaction = Annotated<StarknetInvocation>; export type AnnotatedZKSyncTransaction = Annotated<zkSyncTypes.TransactionRequest>; export type AnnotatedRadixTransaction = Annotated<RadixSDKTransaction>; export type TypedAnnotatedTransaction = AnnotatedEV5Transaction | AnnotatedViemTransaction | AnnotatedSolanaWeb3Transaction | AnnotatedCosmJsTransaction | AnnotatedCosmJsWasmTransaction | AnnotatedCosmJsNativeTransaction | AnnotatedStarknetJsTransaction | AnnotatedZKSyncTransaction | AnnotatedRadixTransaction; /** * Transaction receipt/response with discriminated union of provider type */ interface TypedTransactionReceiptBase<T> { type: ProviderType; receipt: T; } export interface EthersV5TransactionReceipt extends TypedTransactionReceiptBase<EV5Providers.TransactionReceipt> { type: ProviderType.EthersV5; receipt: EV5Providers.TransactionReceipt; } export interface ViemTransactionReceipt extends TypedTransactionReceiptBase<VTransactionReceipt> { type: ProviderType.Viem; receipt: VTransactionReceipt; } export interface SolanaWeb3TransactionReceipt extends TypedTransactionReceiptBase<SolTransactionReceipt> { type: ProviderType.SolanaWeb3; receipt: SolTransactionReceipt; } export interface CosmJsTransactionReceipt extends TypedTransactionReceiptBase<DeliverTxResponse> { type: ProviderType.CosmJs; receipt: DeliverTxResponse; } export interface CosmJsWasmTransactionReceipt extends TypedTransactionReceiptBase<DeliverTxResponse> { type: ProviderType.CosmJsWasm; receipt: DeliverTxResponse; } export interface CosmJsNativeTransactionReceipt extends TypedTransactionReceiptBase<DeliverTxResponse> { type: ProviderType.CosmJsNative; receipt: DeliverTxResponse; } export interface StarknetJsTransactionReceipt extends TypedTransactionReceiptBase<StarknetTxReceipt> { type: ProviderType.Starknet; receipt: StarknetTxReceipt; } export interface ZKSyncTransactionReceipt extends TypedTransactionReceiptBase<zkSyncTypes.TransactionReceipt> { type: ProviderType.ZkSync; receipt: zkSyncTypes.TransactionReceipt; } export interface RadixTransactionReceipt extends TypedTransactionReceiptBase<RadixSDKReceipt> { type: ProviderType.Radix; receipt: RadixSDKReceipt; } export type TypedTransactionReceipt = EthersV5TransactionReceipt | ViemTransactionReceipt | SolanaWeb3TransactionReceipt | CosmJsTransactionReceipt | CosmJsWasmTransactionReceipt | CosmJsNativeTransactionReceipt | StarknetJsTransactionReceipt | ZKSyncTransactionReceipt | RadixTransactionReceipt; export {}; //# sourceMappingURL=ProviderType.d.ts.map