Skip to content

Commit

Permalink
feat: add ism deployer
Browse files Browse the repository at this point in the history
  • Loading branch information
byeongsu-hong committed Mar 7, 2024
1 parent bb5b1c6 commit 6c217db
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions script/deploy/ism.ts
Original file line number Diff line number Diff line change
@@ -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<IsmType, { type: "routing" }>
) => {
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 === "<signer>" ? 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<IsmType, number[]>
): Promise<ContextIsm> {
switch (ism.type) {
// deploy multisig ism
case "multisig":
const multisig = await deployContract(ctx, client, "hpl_ism_multisig", {
owner: ism.owner === "<signer>" ? 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 === "<signer>" ? 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");
}
}

0 comments on commit 6c217db

Please sign in to comment.