@hyperlane-xyz/helloworld
Version: 
A basic skeleton of an Hyperlane app
55 lines • 2.5 kB
JavaScript
import { RouterApp, } from '@hyperlane-xyz/sdk';
import { addBufferToGasLimit, rootLogger } from '@hyperlane-xyz/utils';
export class HelloWorldApp extends RouterApp {
    core;
    constructor(core, contractsMap, multiProvider, foreignDeployments = {}) {
        super(contractsMap, multiProvider, rootLogger.child({ module: 'HelloWorldApp' }), foreignDeployments);
        this.core = core;
    }
    router(contracts) {
        return contracts.router;
    }
    async sendHelloWorld(from, to, message, value) {
        const sender = this.getContracts(from).router;
        const toDomain = this.multiProvider.getDomainId(to);
        const { blocks, transactionOverrides } = this.multiProvider.getChainMetadata(from);
        // apply gas buffer due to https://github.com/hyperlane-xyz/hyperlane-monorepo/issues/634
        const estimated = await sender.estimateGas.sendHelloWorld(toDomain, message, { ...transactionOverrides, value });
        const quote = await sender.quoteDispatch(toDomain, message);
        const tx = await sender.sendHelloWorld(toDomain, message, {
            gasLimit: addBufferToGasLimit(estimated),
            ...transactionOverrides,
            value: value.add(quote),
        });
        this.logger.info('Sending hello message', {
            from,
            to,
            message,
            tx,
        });
        return tx.wait(blocks?.confirmations ?? 1);
    }
    async waitForMessageReceipt(receipt) {
        return this.core.waitForMessageProcessing(receipt);
    }
    async waitForMessageProcessed(receipt) {
        return this.core.waitForMessageProcessed(receipt);
    }
    async channelStats(from, to) {
        const sent = await this.getContracts(from).router.sentTo(this.multiProvider.getDomainId(to));
        const received = await this.getContracts(to).router.receivedFrom(this.multiProvider.getDomainId(from));
        return { sent: sent.toNumber(), received: received.toNumber() };
    }
    async stats() {
        const entries = await Promise.all(this.chains().map(async (source) => {
            const remoteChains = await this.remoteChains(source);
            const destinationEntries = await Promise.all(remoteChains.map(async (destination) => [
                destination,
                await this.channelStats(source, destination),
            ]));
            return [source, Object.fromEntries(destinationEntries)];
        }));
        return Object.fromEntries(entries);
    }
}
//# sourceMappingURL=app.js.map