Skip to content

Commit

Permalink
feat(script): add commands & entrypoint (#105)
Browse files Browse the repository at this point in the history
* feat: add shared utilities

* fix: correct representation of `instant finality`

* fix: also actual value

* Squashed commit of the following:

commit fad8f9e
Merge: 1639e2f eb77beb
Author: byeongsu-hong <[email protected]>
Date:   Fri Mar 1 23:21:15 2024 +0900

    Merge branch 'eddy/pick-docs' into eddy/pick-cw-hpl

commit 1639e2f
Author: byeongsu-hong <[email protected]>
Date:   Fri Mar 1 23:17:08 2024 +0900

    remove ts/sdk

commit d73647b
Author: byeongsu-hong <[email protected]>
Date:   Fri Mar 1 23:15:19 2024 +0900

    Revert "Merge branch 'main' into eddy/pick-cw-hpl"

    This reverts commit 82fc10f, reversing
    changes made to 6566e7a.

commit 82fc10f
Merge: 6566e7a be64967
Author: byeongsu-hong <[email protected]>
Date:   Fri Mar 1 23:14:05 2024 +0900

    Merge branch 'main' into eddy/pick-cw-hpl

commit be64967
Author: ByeongSu Hong <[email protected]>
Date:   Fri Mar 1 23:08:13 2024 +0900

    doc: documentation (#95)

    * wip

    * project structure & overview

    * toc

    * swap

    * fix(schema): reflect missing contracts

    * refactor(ts): migrate sdk - 1

    * refactor(script): pull back project setup to root

    * reorg script / cli

    * fix(script): make igp deployable

    * build: redeploy

    * build: stride hyperlane deployment

    * fix(hook): default gas denom

    * feat(script): add migrate command

    * chore: detailed ignore policy

    * feat(script): supprot mnemonic

    * chore(script): cleanup

    * chore: trailing comma

    * feat: add grpc endpoint as config

    * feat: generate agent config

    * feat(script): add test-dispatch

    * chore: redundant args

    * docs: owner -> <signer>

    * build: yarn berry

    * env: yarn

    * env: add cw-hpl command

    * feat: mailbox null-check

    * fix: prune imports

    * docs: wip guide & example

    * fix: rename compose file

    * fix: use localosmosis key

    * refactor: restruct guide

    * fix: remove DATA_PATH

    * fix: add `yarn install`

    * fix: handle rest endpoint not working

    * fix: use localwasmd

    * fix: hrp

    * feat: add wallet command

    * feat: wallet generator

    * fix: use osmosis testnet

    * line spacing

    * fix: xor

    * fix: split length

    * feat: more info to replace

    * fix: osmosis testnet network name

    * chore: ignore example

    * feat: add test recipient

    * fix: trouble shooting

    * docs: done

    * docs: update README.md

    * fix: line break

    * chore: remove testnet contexts

    * wip: neutron deployment

    * feat: context -> agent config

    * feat: apply review changes (#97)

    * docs: add context / example

    * fix: real instant finality

    * fix: typo

commit e8716c3
Author: ByeongSu Hong <[email protected]>
Date:   Fri Mar 1 19:57:30 2024 +0900

    review: docs (#98)

    * wip

    * project structure & overview

    * toc

    * swap

    * docs: owner -> <signer>

    * build: yarn berry

    * env: yarn

    * env: add cw-hpl command

    * docs: wip guide & example

    * fix: line break

    * fix: rename compose file

    * fix: use localosmosis key

    * refactor: restruct guide

    * fix: remove DATA_PATH

    * fix: add `yarn install`

    * fix: use localwasmd

    * fix: hrp

    * fix: use osmosis testnet

    * line spacing

    * feat: more info to replace

    * fix: osmosis testnet network name

    * chore: ignore example

    * docs: done

    * docs: update README.md

    * merge: remove conflicts

    * docs: move to root

    * docs: remove outdated docs

commit eb77beb
Author: byeongsu-hong <[email protected]>
Date:   Thu Feb 29 17:55:52 2024 +0900

    docs: remove outdated docs

commit 6a600c5
Author: byeongsu-hong <[email protected]>
Date:   Thu Feb 29 17:54:38 2024 +0900

    docs: move to root

commit 68074f0
Author: ByeongSu Hong <[email protected]>
Date:   Thu Feb 29 02:20:50 2024 +0900

    refactor: ts schema (#99)

    * fix(schema): reflect missing contracts

    * refactor(ts): migrate sdk - 1

commit 5896800
Author: byeongsu-hong <[email protected]>
Date:   Wed Feb 28 17:16:32 2024 +0900

    merge: remove conflicts

commit adb1852
Author: ByeongSu Hong <[email protected]>
Date:   Tue Feb 27 02:59:10 2024 +0900

    docs: update README.md

commit 19c6c60
Author: byeongsu-hong <[email protected]>
Date:   Tue Feb 27 02:57:59 2024 +0900

    docs: done

commit 5cdecaa
Author: byeongsu-hong <[email protected]>
Date:   Tue Feb 27 02:32:56 2024 +0900

    chore: ignore example

commit 28a5e69
Author: byeongsu-hong <[email protected]>
Date:   Tue Feb 27 02:21:21 2024 +0900

    fix: osmosis testnet network name

commit 57e78ea
Author: byeongsu-hong <[email protected]>
Date:   Tue Feb 27 02:18:23 2024 +0900

    feat: more info to replace

commit 56e2700
Author: byeongsu-hong <[email protected]>
Date:   Tue Feb 27 01:35:03 2024 +0900

    line spacing

commit b707b67
Author: byeongsu-hong <[email protected]>
Date:   Tue Feb 27 01:32:35 2024 +0900

    fix: use osmosis testnet

commit aa53d70
Author: byeongsu-hong <[email protected]>
Date:   Tue Feb 27 00:38:22 2024 +0900

    fix: hrp

commit bc1b84f
Author: byeongsu-hong <[email protected]>
Date:   Tue Feb 27 00:36:03 2024 +0900

    fix: use localwasmd

commit 7aaa751
Author: byeongsu-hong <[email protected]>
Date:   Tue Feb 27 00:04:08 2024 +0900

    fix: add `yarn install`

commit ca25459
Author: byeongsu-hong <[email protected]>
Date:   Mon Feb 26 23:56:19 2024 +0900

    fix: remove DATA_PATH

commit 82b5f59
Author: byeongsu-hong <[email protected]>
Date:   Mon Feb 26 23:49:25 2024 +0900

    refactor: restruct guide

commit df1a67c
Author: byeongsu-hong <[email protected]>
Date:   Mon Feb 26 22:32:48 2024 +0900

    fix: use localosmosis key

commit ef17165
Author: byeongsu-hong <[email protected]>
Date:   Mon Feb 26 22:26:51 2024 +0900

    fix: rename compose file

commit 1289770
Author: byeongsu-hong <[email protected]>
Date:   Tue Feb 27 03:00:17 2024 +0900

    fix: line break

commit 2604486
Author: byeongsu-hong <[email protected]>
Date:   Mon Feb 26 22:22:49 2024 +0900

    docs: wip guide & example

commit 2b4c5a1
Author: byeongsu-hong <[email protected]>
Date:   Mon Feb 26 21:21:24 2024 +0900

    env: add cw-hpl command

commit e43cfb3
Author: byeongsu-hong <[email protected]>
Date:   Mon Feb 26 21:21:14 2024 +0900

    env: yarn

commit 76313e8
Author: byeongsu-hong <[email protected]>
Date:   Mon Feb 26 20:49:06 2024 +0900

    build: yarn berry

commit 9dba0a4
Author: byeongsu-hong <[email protected]>
Date:   Mon Feb 26 20:44:20 2024 +0900

    docs: owner -> <signer>

commit 17200dc
Author: byeongsu-hong <[email protected]>
Date:   Wed Feb 14 18:50:16 2024 +0900

    swap

commit 50b01d7
Author: byeongsu-hong <[email protected]>
Date:   Wed Feb 14 18:42:09 2024 +0900

    toc

commit 6cde4c8
Author: byeongsu-hong <[email protected]>
Date:   Wed Feb 14 18:29:22 2024 +0900

    project structure & overview

commit cab7199
Author: byeongsu-hong <[email protected]>
Date:   Wed Feb 14 18:22:41 2024 +0900

    wip

* merge: cw-hpl (#110)

* refactor: ts schema (#99)

* fix(schema): reflect missing contracts

* refactor(ts): migrate sdk - 1

* review: docs (#98)

* wip

* project structure & overview

* toc

* swap

* docs: owner -> <signer>

* build: yarn berry

* env: yarn

* env: add cw-hpl command

* docs: wip guide & example

* fix: line break

* fix: rename compose file

* fix: use localosmosis key

* refactor: restruct guide

* fix: remove DATA_PATH

* fix: add `yarn install`

* fix: use localwasmd

* fix: hrp

* fix: use osmosis testnet

* line spacing

* feat: more info to replace

* fix: osmosis testnet network name

* chore: ignore example

* docs: done

* docs: update README.md

* merge: remove conflicts

* docs: move to root

* docs: remove outdated docs

* doc: documentation (#95)

* wip

* project structure & overview

* toc

* swap

* fix(schema): reflect missing contracts

* refactor(ts): migrate sdk - 1

* refactor(script): pull back project setup to root

* reorg script / cli

* fix(script): make igp deployable

* build: redeploy

* build: stride hyperlane deployment

* fix(hook): default gas denom

* feat(script): add migrate command

* chore: detailed ignore policy

* feat(script): supprot mnemonic

* chore(script): cleanup

* chore: trailing comma

* feat: add grpc endpoint as config

* feat: generate agent config

* feat(script): add test-dispatch

* chore: redundant args

* docs: owner -> <signer>

* build: yarn berry

* env: yarn

* env: add cw-hpl command

* feat: mailbox null-check

* fix: prune imports

* docs: wip guide & example

* fix: rename compose file

* fix: use localosmosis key

* refactor: restruct guide

* fix: remove DATA_PATH

* fix: add `yarn install`

* fix: handle rest endpoint not working

* fix: use localwasmd

* fix: hrp

* feat: add wallet command

* feat: wallet generator

* fix: use osmosis testnet

* line spacing

* fix: xor

* fix: split length

* feat: more info to replace

* fix: osmosis testnet network name

* chore: ignore example

* feat: add test recipient

* fix: trouble shooting

* docs: done

* docs: update README.md

* fix: line break

* chore: remove testnet contexts

* wip: neutron deployment

* feat: context -> agent config

* feat: apply review changes (#97)

* docs: add context / example

* fix: real instant finality

* fix: typo

* Revert "Merge branch 'main' into eddy/pick-cw-hpl"

This reverts commit 82fc10f, reversing
changes made to 6566e7a.

* remove ts/sdk

* merge: schema refactoring (#106)

* fix(schema): reflect missing contracts

* refactor(ts): migrate sdk - 1

* feat(script): initial config setup (#102)

feat: initial config setup

* merge: docs improvements (#108)

* wip

* project structure & overview

* toc

* swap

* docs: owner -> <signer>

* build: yarn berry

* env: yarn

* env: add cw-hpl command

* docs: wip guide & example

* fix: line break

* fix: rename compose file

* fix: use localosmosis key

* refactor: restruct guide

* fix: remove DATA_PATH

* fix: add `yarn install`

* fix: use localwasmd

* fix: hrp

* fix: use osmosis testnet

* line spacing

* feat: more info to replace

* fix: osmosis testnet network name

* chore: ignore example

* docs: done

* docs: update README.md

* merge: remove conflicts

* docs: move to root

* docs: remove outdated docs

* fix: apply code review

* feat: add deploy script for hook

* feat: add ism deployer

* feat: add igp deployer

* feat: export everything

* feat: add commands

* feat: main entrypoint

* chore: prevent logic duplication

* fix: apply review changes
  • Loading branch information
byeongsu-hong authored Mar 8, 2024
1 parent 35dd3b7 commit b354e68
Show file tree
Hide file tree
Showing 8 changed files with 751 additions and 0 deletions.
25 changes: 25 additions & 0 deletions script/commands/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Command } from "commander";

import { CONTAINER, Dependencies } from "../shared/ioc";
import { saveAgentConfig } from "../shared/agent";
import { getNetwork } from "../shared/config";

const contextCmd = new Command("context");

contextCmd
.command("make-agent-config")
.description("Make an agent config")
.option("-o --output <output-dir>", "The output directory")
.action(async (_, cmd) => {
const opts = cmd.optsWithGlobals();
const { ctx } = CONTAINER.get(Dependencies);
const network = getNetwork(opts.networkId);

await saveAgentConfig(
network,
ctx,
opts.output && { contextPath: opts.output }
);
});

export { contextCmd };
44 changes: 44 additions & 0 deletions script/commands/contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Command } from "commander";

import { contractNames } from "../shared/constants";
import { executeContract } from "../shared/contract";
import { CONTAINER, Dependencies } from "../shared/ioc";
import { addPad } from "../shared/utils";
import { getNetwork } from "../shared/config";

export const contractCmd = new Command("contract").configureHelp({
showGlobalOptions: true,
});

contractCmd.command("list").action(() => {
console.log("Available contracts:".green);
contractNames.forEach((v) => console.log("-", v));
});

contractCmd
.command("test-dispatch")
.argument("dest-domian")
.argument("recipient-addr")
.argument("msg-body")
.action(async (destDomain, recipientAddr, msgBody, _, cmd) => {
const opts = cmd.optsWithGlobals();
const { ctx, client } = CONTAINER.get(Dependencies);
const network = getNetwork(opts.networkId);

const mailbox = ctx.deployments.core?.mailbox!;

const res = await executeContract(
client,
mailbox,
{
dispatch: {
dest_domain: parseInt(destDomain),
recipient_addr: addPad(recipientAddr),
msg_body: Buffer.from(msgBody, "utf-8").toString("hex"),
},
},
[{ amount: "500", denom: network.gas.denom }]
);

console.log(res.hash);
});
175 changes: 175 additions & 0 deletions script/commands/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import { Command } from "commander";

import { deployIsm, deployHook } from "../deploy";
import { CONTAINER, Dependencies } from "../shared/ioc";
import { Client, config, getNetwork } from "../shared/config";
import { Context, ContextDeployments, saveContext } from "../shared/context";
import { deployContract, executeMultiMsg } from "../shared/contract";
import { saveAgentConfig } from "../shared/agent";

export const deployCmd = new Command("deploy")
.description("Deploy contracts")
.configureHelp({ showGlobalOptions: true })
.action(handleDeploy);

async function handleDeploy(_: any, cmd: any) {
const opts = cmd.optsWithGlobals();
const { ctx, client } = CONTAINER.get(Dependencies);

ctx.deployments = ctx.deployments || {};
ctx.deployments.core = await deployCore(opts, ctx, client);
ctx.deployments.isms = await deployIsms(ctx, client);
ctx.deployments.hooks = await deployHooks(opts, ctx, client);
// TODO: deploy warp
ctx.deployments.test = await deployTest(opts, ctx, client);

await executeMultiMsg(client, [
{
contract: ctx.deployments.core?.mailbox!,
msg: {
set_default_ism: {
ism: ctx.deployments.isms?.address!,
},
},
},
{
contract: ctx.deployments.core?.mailbox!,
msg: {
set_default_hook: {
hook: ctx.deployments.hooks?.default!.address,
},
},
},
{
contract: ctx.deployments.core?.mailbox!,
msg: {
set_required_hook: {
hook: ctx.deployments.hooks?.required!.address,
},
},
},
]);

saveContext(opts.networkId, ctx);
await saveAgentConfig(getNetwork(opts.networkId), ctx);
}

const deployCore = async (
{ networkId }: { networkId: string },
ctx: Context,
client: Client
): Promise<ContextDeployments["core"]> => {
const { hrp, domain } = getNetwork(networkId);

const log = (v: string) => console.log("[core]".green, v);
const preload = ctx.deployments.core;
const deployment = preload || {};

if (preload?.mailbox) {
log(`${preload.mailbox.type} already deployed`);
deployment.mailbox = preload.mailbox;
} else {
deployment.mailbox = await deployContract(ctx, client, "hpl_mailbox", {
hrp,
domain,
owner: client.signer,
});
}

deployment.validator_announce =
preload?.validator_announce ||
(await deployContract(ctx, client, "hpl_validator_announce", {
hrp,
mailbox: deployment.mailbox.address,
}));
if (preload?.validator_announce)
log(`${deployment.validator_announce.type} already deployed`);

return deployment;
};

const deployIsms = async (
ctx: Context,
client: Client
): Promise<ContextDeployments["isms"]> => {
if (!config.deploy.ism) {
throw new Error("ISM deployment config not found");
}

const log = (v: string) => console.log("[ism]".green, v);
const preload = ctx.deployments.isms;
if (preload) {
log(`ism ${preload.type} already deployed`);
return preload;
}

return deployIsm(ctx, client, config.deploy.ism);
};

const deployHooks = async (
{ networkId }: { networkId: string },
ctx: Context,
client: Client,
): Promise<ContextDeployments["hooks"]> => {
if (!config.deploy.hooks) {
throw new Error("Hook deployment config not found");
}

const log = (v: string) => console.log("[hooks]".green, v);
const preload = ctx.deployments?.hooks;
const deployment = preload || {};

if (preload?.default) {
log(`default hook ${preload.default.type} already deployed`);
deployment.default = preload.default;
} else {
if (!config.deploy.hooks.default)
throw Error("Default hook deployment config not found");

deployment.default = await deployHook(
networkId,
ctx,
client,
config.deploy.hooks.default,
);
}

if (preload?.required) {
log(`required hook ${preload.required.type} already deployed`);
deployment.required = preload.required;
} else {
if (!config.deploy.hooks.required)
throw Error("Required hook deployment config not found");

deployment.required = await deployHook(
networkId,
ctx,
client,
config.deploy.hooks.required,
);
}

return deployment;
};

const deployTest = async (
{ networkId }: { networkId: string },
ctx: Context,
client: Client
): Promise<ContextDeployments["test"]> => {
const { hrp } = getNetwork(networkId);

const log = (v: string) => console.log("[test]".green, v);
const preload = ctx.deployments.test;
const deployment = preload || {};

deployment.msg_receiver =
preload?.msg_receiver ||
(await deployContract(ctx, client, "hpl_test_mock_msg_receiver", {
hrp,
}));
if (preload?.msg_receiver)
log(`${deployment.msg_receiver.type} already deployed`);

return deployment;
};
4 changes: 4 additions & 0 deletions script/commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { deployCmd } from "./deploy";
export { uploadCmd } from "./upload";
export { contractCmd } from "./contract";
export { migrateCmd } from "./migrate";
Loading

0 comments on commit b354e68

Please sign in to comment.