From 6c217dbd6890f65bbd07e2f772ab443a40a37633 Mon Sep 17 00:00:00 2001 From: byeongsu-hong Date: Fri, 1 Mar 2024 21:49:25 +0900 Subject: [PATCH] feat: add ism deployer --- script/deploy/ism.ts | 94 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 script/deploy/ism.ts diff --git a/script/deploy/ism.ts b/script/deploy/ism.ts new file mode 100644 index 00000000..a4844ea4 --- /dev/null +++ b/script/deploy/ism.ts @@ -0,0 +1,94 @@ +import { Client, IsmType } from "../shared/config"; +import { Context, ContextIsm } from "../shared/context"; +import { + deployContract, + executeContract, + executeMultiMsg, +} from "../shared/contract"; + +const deployRoutingIsm = async ( + ctx: Context, + client: Client, + ism: Extract +) => { + const routes = []; + for (const [domain, v] of Object.entries(ism.isms)) { + routes.push({ + domain: parseInt(domain), + route: await deployIsm(ctx, client, v), + }); + } + + const routing = await deployContract(ctx, client, "hpl_ism_routing", { + owner: ism.owner === "" ? client.signer : ism.owner, + }); + + await executeContract(client, routing, { + router: { + set_routes: { + set: routes.map(({ domain, route }) => ({ + domain, + route: route.address, + })), + }, + }, + }); + + return { + ...routing, + isms: routes.reduce((acc, v) => ({ [v.domain]: v.route, ...acc })), + }; +}; + +export async function deployIsm( + ctx: Context, + client: Client, + ism: Exclude +): Promise { + switch (ism.type) { + // deploy multisig ism + case "multisig": + const multisig = await deployContract(ctx, client, "hpl_ism_multisig", { + owner: ism.owner === "" ? client.signer : ism.owner, + }); + + await executeMultiMsg( + client, + Object.entries(ism.validators).map( + ([domain, { addrs, threshold }]) => ({ + contract: multisig, + msg: { + set_validators: { + domain: Number(domain), + threshold, + validators: addrs, + }, + }, + }) + ) + ); + + return multisig; + + // deploy aggregate ism + case "aggregate": + const aggr = []; + for (const v of ism.isms) { + aggr.push(await deployIsm(ctx, client, v)); + } + + const aggregate = await deployContract(ctx, client, "hpl_ism_aggregate", { + owner: ism.owner === "" ? client.signer : ism.owner, + isms: aggr.map((v) => v.address), + }); + + return { ...aggregate, isms: aggr }; + + // deploy routing ism + case "routing": + return deployRoutingIsm(ctx, client, ism); + + default: + throw new Error("invalid ism type"); + } +}