@hyperlane-xyz/sdk
Version:
The official SDK for the Hyperlane Network
300 lines • 13.8 kB
TypeScript
import { Logger } from 'pino';
import { Address, HexString } from '@hyperlane-xyz/utils';
import type { PredicateAttestation } from '../predicate/PredicateApiClient.js';
import type { MultiProviderAdapter } from '../providers/MultiProviderAdapter.js';
import { TransactionFeeEstimate } from '../providers/transactionFeeEstimators.js';
import { IToken } from '../token/IToken.js';
import { Token } from '../token/Token.js';
import { TokenAmount } from '../token/TokenAmount.js';
import type { Quote } from '../quoted-calls/codec.js';
import type { QuotedCallsParams } from '../quoted-calls/types.js';
import { ChainName, ChainNameOrId } from '../types.js';
import { FeeConstantConfig, RouteBlacklist, WarpCoreFeeEstimate, WarpTypedTransaction } from './types.js';
export interface WarpCoreOptions {
logger?: Logger;
localFeeConstants?: FeeConstantConfig;
interchainFeeConstants?: FeeConstantConfig;
routeBlacklist?: RouteBlacklist;
}
export declare class WarpCore {
readonly multiProvider: MultiProviderAdapter<{
mailbox?: Address;
}>;
readonly tokens: Token[];
readonly localFeeConstants: FeeConstantConfig;
readonly interchainFeeConstants: FeeConstantConfig;
readonly routeBlacklist: RouteBlacklist;
readonly logger: Logger;
constructor(multiProvider: MultiProviderAdapter<{
mailbox?: Address;
}>, tokens: Token[], options?: WarpCoreOptions);
/**
* Takes the serialized representation of a warp config and returns a WarpCore instance
* @param multiProvider the MultiProviderAdapter containing chain metadata
* @param config the config object of type WarpCoreConfig
*/
static FromConfig(multiProvider: MultiProviderAdapter<{
mailbox?: Address;
}>, config: unknown): WarpCore;
/**
* Queries the token router for an interchain gas quote (i.e. IGP fee).
* and for token fee quote if it exists.
* Sender is only required for Sealevel origins.
*/
getInterchainTransferFee({ originTokenAmount, destination, sender, recipient, destinationToken, }: {
originTokenAmount: TokenAmount<IToken>;
destination: ChainNameOrId;
sender?: Address;
recipient: Address;
destinationToken?: IToken;
}): Promise<{
igpQuote: TokenAmount<IToken>;
tokenFeeQuote?: TokenAmount<IToken>;
}>;
/**
* Simulates a transfer to estimate 'local' gas fees on the origin chain
*/
getLocalTransferFee({ originToken, destination, sender, senderPubKey, interchainFee, tokenFeeQuote, attestation, amount, destinationToken, quotedCalls, }: {
originToken: IToken;
destination: ChainNameOrId;
sender: Address;
senderPubKey?: HexString;
interchainFee?: TokenAmount<IToken>;
tokenFeeQuote?: TokenAmount<IToken>;
attestation?: PredicateAttestation;
amount?: bigint;
destinationToken?: IToken;
quotedCalls?: QuotedCallsParams;
}): Promise<TransactionFeeEstimate>;
/**
* Similar to getLocalTransferFee in that it estimates local gas fees
* but it also resolves the native token and returns a TokenAmount
* @todo: rename to getLocalTransferFee for consistency (requires breaking change)
*/
getLocalTransferFeeAmount({ originToken, destination, sender, senderPubKey, interchainFee, tokenFeeQuote, attestation, amount, destinationToken, quotedCalls, }: {
originToken: IToken;
destination: ChainNameOrId;
sender: Address;
senderPubKey?: HexString;
interchainFee?: TokenAmount<IToken>;
tokenFeeQuote?: TokenAmount<IToken>;
attestation?: PredicateAttestation;
amount?: bigint;
destinationToken?: IToken;
quotedCalls?: QuotedCallsParams;
}): Promise<TokenAmount<IToken>>;
/**
* Gets a list of populated transactions required to transfer a token to a remote chain
* Typically just 1 transaction but sometimes more, like when an approval is required first
*/
getTransferRemoteTxs({ originTokenAmount, destination, sender, recipient, interchainFee, tokenFeeQuote, attestation, destinationToken, quotedCalls, }: {
originTokenAmount: TokenAmount<IToken>;
destination: ChainNameOrId;
sender: Address;
recipient: Address;
interchainFee?: TokenAmount<IToken>;
tokenFeeQuote?: TokenAmount<IToken>;
/** Optional Predicate attestation for compliance-gated warp routes */
attestation?: PredicateAttestation;
destinationToken?: IToken;
/** When provided, builds an atomic QuotedCalls.execute() tx instead of separate approve+transfer */
quotedCalls?: QuotedCallsParams;
}): Promise<Array<WarpTypedTransaction>>;
/**
* Check if this is a CrossCollateralRouter transfer.
* Returns true if both tokens are CrossCollateralRouter tokens.
*/
isCrossCollateralTransfer(originToken: IToken, destinationToken?: IToken): destinationToken is IToken;
/**
* Executes a CrossCollateralRouter transfer between different collateral routers.
* Uses transferRemoteTo for both same-chain and cross-chain transfers.
* Same-chain: calls handle() directly on target router (atomic, no relay needed).
*/
protected getCrossCollateralTransferTxs({ originTokenAmount, destination, sender, recipient, destinationToken, attestation, interchainFee, tokenFeeQuote, }: {
originTokenAmount: TokenAmount<IToken>;
destination: ChainNameOrId;
sender: Address;
recipient: Address;
destinationToken: IToken;
attestation?: PredicateAttestation;
interchainFee?: TokenAmount<IToken>;
tokenFeeQuote?: TokenAmount<IToken>;
}): Promise<Array<WarpTypedTransaction>>;
/**
* Resolve common params for QuotedCalls operations.
*/
protected resolveQuotedCallsParams({ originTokenAmount, destination, recipient, quotedCalls, destinationToken, }: {
originTokenAmount: TokenAmount<IToken>;
destination: ChainNameOrId;
recipient: Address;
quotedCalls: QuotedCallsParams;
destinationToken?: IToken;
}): {
quotedCallsAddress: `0x${string}`;
warpRoute: `0x${string}`;
destination: number;
recipient: `0x${string}`;
amount: bigint;
token: `0x${string}`;
quotes: import("../quoted-calls/types.js").SubmitQuoteCommand[];
clientSalt: `0x${string}`;
targetRouter: `0x${string}` | undefined;
};
/**
* Quote fees for a QuotedCalls transfer via quoteExecute eth_call.
* Returns structured fee data (like getInterchainTransferFee) plus
* the raw Quote[][] needed to build the execute tx.
*/
getQuotedTransferFee({ originTokenAmount, destination, sender, recipient, quotedCalls, destinationToken, }: {
originTokenAmount: TokenAmount<IToken>;
destination: ChainNameOrId;
sender: Address;
recipient: Address;
quotedCalls: QuotedCallsParams;
destinationToken?: IToken;
}): Promise<{
igpQuote: TokenAmount<IToken>;
tokenFeeQuote?: TokenAmount<IToken>;
/** Raw per-command quotes — pass to getTransferRemoteTxs */
feeQuotes: Quote[][];
}>;
/**
* Build transactions for a QuotedCalls atomic transfer.
* Returns [approval (if needed), execute] transactions.
*
* @param feeQuotes Raw Quote[][] from getQuotedTransferFee.
* If not provided, calls quoteExecute internally.
*/
protected getQuotedCallsTransferTxs({ originTokenAmount, destination, sender, recipient, quotedCalls, destinationToken, feeQuotes, }: {
originTokenAmount: TokenAmount<IToken>;
destination: ChainNameOrId;
sender: Address;
recipient: Address;
quotedCalls: QuotedCallsParams;
destinationToken?: IToken;
feeQuotes?: Quote[][];
}): Promise<Array<WarpTypedTransaction>>;
/**
* Fetch local and interchain fee estimates for a remote transfer
*/
estimateTransferRemoteFees({ originTokenAmount, destination, recipient, sender, senderPubKey, attestation, destinationToken, }: {
originTokenAmount: TokenAmount<IToken>;
destination: ChainNameOrId;
recipient: Address;
sender: Address;
senderPubKey?: HexString;
attestation?: PredicateAttestation;
destinationToken?: IToken;
}): Promise<WarpCoreFeeEstimate>;
/**
* Estimate fees for a CrossCollateralRouter transfer.
*/
protected estimateCrossCollateralFees({ originTokenAmount, destination, destinationToken, recipient, sender, senderPubKey, attestation, }: {
originTokenAmount: TokenAmount<IToken>;
destination: ChainNameOrId;
destinationToken: IToken;
recipient: Address;
sender: Address;
senderPubKey?: HexString;
attestation?: PredicateAttestation;
}): Promise<WarpCoreFeeEstimate>;
/**
* Computes the max transferrable amount of the from the given
* token balance, accounting for local and interchain gas fees
*/
getMaxTransferAmount({ balance, destination, recipient, sender, senderPubKey, feeEstimate, destinationToken, }: {
balance: TokenAmount<IToken>;
destination: ChainNameOrId;
recipient: Address;
sender: Address;
senderPubKey?: HexString;
feeEstimate?: WarpCoreFeeEstimate;
destinationToken?: IToken;
}): Promise<TokenAmount<IToken>>;
getTokenCollateral(token: IToken): Promise<bigint>;
/**
* Checks if destination chain's collateral is sufficient to cover the transfer
*/
isDestinationCollateralSufficient({ originTokenAmount, destination, destinationToken, }: {
originTokenAmount: TokenAmount<IToken>;
destination: ChainNameOrId;
destinationToken?: IToken;
}): Promise<boolean>;
/**
* Checks if a token transfer requires an approval tx first
*/
isApproveRequired({ originTokenAmount, owner, }: {
originTokenAmount: TokenAmount<IToken>;
owner: Address;
}): Promise<boolean>;
/**
* Ensure the remote token transfer would be valid for the given chains, amount, sender, and recipient
*/
validateTransfer({ originTokenAmount, destination, recipient, sender, senderPubKey, attestation, destinationToken, }: {
originTokenAmount: TokenAmount<IToken>;
destination: ChainNameOrId;
recipient: Address;
sender: Address;
senderPubKey?: HexString;
attestation?: PredicateAttestation;
destinationToken?: IToken;
}): Promise<Record<string, string> | null>;
/**
* Ensure the origin and destination chains are valid and known by this WarpCore
*/
protected validateChains(origin: ChainNameOrId, destination: ChainNameOrId): Record<string, string> | null;
/**
* Ensure recipient address is valid for the destination chain
*/
protected validateRecipient(recipient: Address, destination: ChainNameOrId): Record<string, string> | null;
/**
* Ensure token amount is valid
*/
protected validateAmount(originTokenAmount: TokenAmount<IToken>, destination: ChainNameOrId, recipient: Address, destinationToken?: IToken): Promise<Record<string, string> | null>;
/**
* Ensure the sender has sufficient balances for transfer and interchain gas
*/
protected validateTokenBalances(originTokenAmount: TokenAmount<IToken>, destination: ChainNameOrId, sender: Address, recipient: Address, senderPubKey?: HexString, attestation?: PredicateAttestation, destinationToken?: IToken): Promise<Record<string, string> | null>;
/**
* Ensure the sender has sufficient balances for transfer and interchain gas
*/
protected validateDestinationCollateral(originTokenAmount: TokenAmount<IToken>, destination: ChainNameOrId, destinationToken?: IToken): Promise<Record<string, string> | null>;
/**
* Ensure the sender has sufficient balances for minting
*/
protected validateDestinationRateLimit(originTokenAmount: TokenAmount<IToken>, destination: ChainNameOrId, destinationToken?: IToken): Promise<Record<string, string> | null>;
/**
* Ensure the sender has sufficient balances for transfer and interchain gas
*/
protected validateOriginCollateral(originTokenAmount: TokenAmount<IToken>): Promise<Record<string, string> | null>;
protected resolveDestinationToken({ originToken, destination, destinationToken, }: {
originToken: IToken;
destination: ChainNameOrId;
destinationToken?: IToken;
}): IToken;
/**
* Search through token list to find token with matching chain and address
*/
findToken(chainName: ChainName, addressOrDenom?: Address | string): Token | null;
/**
* Get the list of chains referenced by the tokens in this WarpCore
*/
getTokenChains(): ChainName[];
/**
* Get the subset of tokens whose chain matches the given chainName
*/
getTokensForChain(chainName: ChainName): Token[];
/**
* Get the subset of tokens whose chain matches the given chainName
* and which are connected to a token on the given destination chain
*/
getTokensForRoute(origin: ChainName, destination: ChainName): Token[];
/**
* Check if a token supports Predicate attestations
* @param token The token to check
* @param destination Optional destination chain for the route
* @returns True if the token's warp route has a PredicateRouterWrapper configured
*/
isPredicateSupported(token: IToken, destination?: ChainName): Promise<boolean>;
}
//# sourceMappingURL=WarpCore.d.ts.map