@nomad-xyz/sdk-bridge
Version:
151 lines • 6.63 kB
TypeScript
import { BigNumber } from '@ethersproject/bignumber';
import { TransactionReceipt } from '@ethersproject/abstract-provider';
import * as bridge from '@nomad-xyz/contracts-bridge';
import { NomadMessage, Dispatch } from '@nomad-xyz/sdk';
import { ResolvedTokenInfo, TokenIdentifier } from './tokens';
import { BridgeContracts } from './BridgeContracts';
import { BridgeContext } from './BridgeContext';
import BridgeMessageBackend from './backend';
declare type Transfer = {
type: 'transfer';
to: string;
amount: BigNumber;
detailsHash: string;
allowFast: boolean;
};
export declare type Action = Transfer;
export declare type ParsedBridgeMessage<T extends Action> = {
token: TokenIdentifier;
action: T;
};
export declare type AnyBridgeMessage = TransferMessage;
export declare type ParsedTransferMessage = ParsedBridgeMessage<Transfer>;
export declare function parseBody(messageBody: string): ParsedTransferMessage;
/**
* The BridgeMessage extends {@link nomadMessage} with Bridge-specific
* functionality.
*/
export declare class BridgeMessage extends NomadMessage<BridgeContext> {
readonly token: TokenIdentifier;
readonly fromBridge: BridgeContracts;
readonly toBridge: BridgeContracts;
readonly _backend?: BridgeMessageBackend;
/**
* @hideconstructor
*/
constructor(context: BridgeContext, dispatch: Dispatch, token: TokenIdentifier, callerKnowsWhatTheyAreDoing: boolean, _backend?: BridgeMessageBackend);
get backend(): BridgeMessageBackend;
getReceived(): Promise<string | undefined>;
getSender(): Promise<string | undefined>;
static bridgeFirstFromBackend(context: BridgeContext, transactionHash: string): Promise<BridgeMessage>;
static bridgeFromMessageHash(context: BridgeContext, messageHash: string): Promise<BridgeMessage>;
/**
* Attempt to instantiate a BridgeMessage from an existing
* {@link nomadMessage}
*
* @param context The {@link NomadContext} to use.
* @param nomadMessage The existing nomadMessage
* @returns A Bridge message
* @throws if the message cannot be parsed as a bridge message
*/
static fromNomadMessage(context: BridgeContext, nomadMessage: NomadMessage<BridgeContext>, _backend?: BridgeMessageBackend): AnyBridgeMessage;
/**
* Attempt to instantiate some BridgeMessages from a transaction receipt
*
* @param context The {@link NomadContext} to use.
* @param receipt The receipt
* @returns an array of {@link BridgeMessage} objects
* @throws if any message cannot be parsed as a bridge message
*/
static fromReceipt(context: BridgeContext, receipt: TransactionReceipt, _backend?: BridgeMessageBackend): Promise<AnyBridgeMessage[]>;
/**
* Attempt to instantiate EXACTLY one BridgeMessage from a transaction receipt
*
* @param context The {@link BridgeContext} to use.
* @param receipt The receipt
* @returns an array of {@link BridgeMessage} objects
* @throws if any message cannot be parsed as a bridge message, or if there
* is not EXACTLY 1 BridgeMessage in the receipt
*/
static singleFromReceipt(context: BridgeContext, receipt: TransactionReceipt, _backend?: BridgeMessageBackend): Promise<AnyBridgeMessage>;
/**
* Attempt to instantiate some BridgeMessages from a transaction hash by
* retrieving and parsing the receipt.
*
* @param context The {@link NomadContext} to use.
* @param nameOrDomain the domain on which the receipt was logged
* @param transactionHash the transaction hash on the origin chain
* @returns an array of {@link BridgeMessage} objects
* @throws if any message cannot be parsed as a bridge message
*/
static fromTransactionHash(context: BridgeContext, nameOrDomain: string | number, transactionHash: string, _backend?: BridgeMessageBackend): Promise<AnyBridgeMessage[]>;
/**
* Attempt to instantiate EXACTLY one BridgeMessages from a transaction hash
* by retrieving and parsing the receipt.
*
* @param context The {@link NomadContext} to use.
* @param nameOrDomain the domain on which the receipt was logged
* @param transactionHash the transaction hash on the origin chain
* @returns an array of {@link BridgeMessage} objects
* @throws if any message cannot be parsed as a bridge message, or if there is
* not EXACTLY one such message
*/
static singleFromTransactionHash(context: BridgeContext, nameOrDomain: string | number, transactionHash: string, _backend?: BridgeMessageBackend): Promise<AnyBridgeMessage>;
/**
* Resolves the asset that is being transfered
*
* WARNING: do not hold references to these contract, as they will not be
* reconnected in the event the chain connection changes.
*
* @returns The resolved token information.
*/
asset(): Promise<ResolvedTokenInfo>;
/**
* Resolves an interface for the asset that is being transfered on the chain
* FROM WHICH it is being transferred
*
* WARNING: do not hold references to this contract, as it will not be
* reconnected in the event the chain connection changes.
*
* @returns The resolved token interface.
*/
assetAtOrigin(): Promise<bridge.BridgeToken | undefined>;
/**
* Resolves an interface for the asset that is being transfered on the chain
* TO WHICH it is being transferred
*
* WARNING: do not hold references to this contract, as it will not be
* reconnected in the event the chain connection changes.
*
* @returns The resolved token interface.
*/
assetAtDestination(): Promise<bridge.BridgeToken | undefined>;
}
/**
* A TransferMessage extends the {@link BridgeMessage} with transfer-specific
* functionality.
*/
export declare class TransferMessage extends BridgeMessage {
action: Transfer;
constructor(context: BridgeContext, dispatch: Dispatch, parsed: ParsedTransferMessage, _backend?: BridgeMessageBackend);
/**
* Check if the transfer has been prefilled using the fast liquidity system.
*
* @returns true if the transfer has been prefilled. Else false.
*/
currentlyPrefilled(): Promise<boolean>;
/**
* The amount of tokens being transferred (in the smallest unit)
*/
get amount(): BigNumber;
/**
* The identifier for the recipient of the tokens
*/
get to(): string;
/**
* The ID used for prefilling this transfer message.
*/
get prefillId(): string;
}
export {};
//# sourceMappingURL=BridgeMessage.d.ts.map