@nomad-xyz/sdk
Version:
193 lines • 7.41 kB
TypeScript
import { providers, Signer, ContractTransaction, BytesLike } from 'ethers';
import { MultiProvider } from '@nomad-xyz/multi-provider';
import * as core from '@nomad-xyz/contracts-core';
import * as config from '@nomad-xyz/configuration';
import { CoreContracts } from './CoreContracts';
import { NomadMessage } from './messages/NomadMessage';
import { MessageBackend } from './messageBackend';
export declare type Address = string;
declare type Path = [
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike,
BytesLike
];
export declare type MessageProof = {
message: BytesLike;
proof: {
leaf: BytesLike;
index: number;
path: Path;
};
};
/**
* The NomadContext manages connections to Nomad core and Bridge contracts.
* It inherits from the {@link MultiProvider}, and ensures that its contracts
* always use the latest registered providers and signers.
*
* For convenience, we've pre-constructed contexts for mainnet and testnet
* deployments. These can be imported directly.
*
* @example
* // Set up mainnet and then access contracts as below:
* let router = mainnet.mustGetBridge('celo').bridgeRouter;
*/
export declare class NomadContext extends MultiProvider<config.Domain> {
protected _cores: Map<string, CoreContracts<this>>;
protected _blacklist: Set<number>;
_backend?: MessageBackend;
readonly conf: config.NomadConfig;
constructor(environment?: string | config.NomadConfig, backend?: MessageBackend);
/**
* Create default backend for the context
*/
withDefaultBackend(): NomadContext;
get governor(): config.NomadLocator;
get environment(): string;
/**
* Register an ethers Provider for a specified domain.
*
* @param nameOrDomain A domain name or number.
* @param provider An ethers Provider to be used by requests to that domain.
*/
registerProvider(nameOrDomain: string | number, provider: providers.Provider): void;
/**
* Register an ethers Signer for a specified domain.
*
* @param nameOrDomain A domain name or number.
* @param signer An ethers Signer to be used by requests to that domain.
*/
registerSigner(nameOrDomain: string | number, signer: Signer): void;
/**
* Remove the registered ethers Signer from a domain. This function will
* attempt to preserve any Provider that was previously connected to this
* domain.
*
* @param nameOrDomain A domain name or number.
*/
unregisterSigner(nameOrDomain: string | number): void;
/**
* Clear all signers from all registered domains.
*/
clearSigners(): void;
/**
* Get the {@link CoreContracts} for a given domain (or undefined)
*
* @param nameOrDomain A domain name or number.
* @returns a {@link CoreContracts} object (or undefined)
*/
getCore(nameOrDomain: string | number): CoreContracts<this> | undefined;
/**
* Get the {@link CoreContracts} for a given domain (or throw an error)
*
* @param nameOrDomain A domain name or number.
* @returns a {@link CoreContracts} object
* @throws if no {@link CoreContracts} object exists on that domain.
*/
mustGetCore(nameOrDomain: string | number): CoreContracts<this>;
/**
* Resolve the replica for the Home domain on the Remote domain (if any).
*
* WARNING: do not hold references to this contract, as it will not be
* reconnected in the event the chain connection changes.
*
* @param home the sending domain
* @param remote the receiving domain
* @returns An interface for the Replica (if any)
*/
getReplicaFor(home: string | number, remote: string | number): core.Replica | undefined;
/**
* Resolve the replica for the Home domain on the Remote domain (or throws).
*
* WARNING: do not hold references to this contract, as it will not be
* reconnected in the event the chain connection changes.
*
* @param home the sending domain
* @param remote the receiving domain
* @returns An interface for the Replica
* @throws If no replica is found.
*/
mustGetReplicaFor(home: string | number, remote: string | number): core.Replica;
/**
* Discovers the governor domain of this nomad deployment and returns the
* associated Core.
*
* @returns The identifier of the governing domain
*/
governorCore(): CoreContracts<this>;
/**
* Proves and Processes a transaction on the destination chain. This is subsidize and
* automatic on non-Ethereum destinations
*
* @dev Ensure that a transaction is ready to be processed. You should ensure the following
* criteria have been met prior to calling this function:
* 1. The tx has been relayed (has status of 2):
* `const status = await NomadMessage.status()`
* 2. The `confirmAt` timestamp for the tx is in the past:
* `const confirmAt = await NomadMessage.confirmAt()`
*
* @param message NomadMessage
* @returns The Contract Transaction receipt
*/
process(message: NomadMessage<NomadContext>): Promise<ContractTransaction>;
processProof(origin: string | number, destination: string | number, proof: MessageProof): Promise<ContractTransaction>;
fetchProof(origin: string | number, leafIndex: number): Promise<MessageProof>;
processByOriginDestinationAndLeaf(origin: string | number, destination: string | number, leafIndex: number): Promise<ContractTransaction>;
blacklist(): Set<number>;
checkHomes(networks: (string | number)[]): Promise<void>;
checkHome(nameOrDomain: string | number): Promise<void>;
/**
* Fetch a config from the Nomad config static site.
*
* @param environment the environment name to attempt to fetch
* @returns A NomadConfig
* @throws If the site is down, the config is not on the site, or the config
* is not of a valid format
*/
static fetchConfig(environment: string): Promise<config.NomadConfig>;
/**
* Fetch a config from the Nomad config static site and instantiate a context
* from it. If there is an issue, this function will fallback to the latest
* version of the config shipped with the configuration package.
*
* Fallback may be disabled by setting `allowFallback` to false
*
* @param this this type for the descendant
* @param env the environment name to attempt to fetch
* @param allowFallback allow fallback to the builtin env configuration
* @returns A NomadContext with the latest configuration for the specified env
* @throws If `allowFallback` is false and the site is down, the config is
* not on the site, or the config is not of a valid format
*/
static fetch<T extends NomadContext>(this: new (env: string | config.NomadConfig) => T, env: string, allowFallback?: boolean): Promise<T>;
}
export {};
//# sourceMappingURL=NomadContext.d.ts.map