Skip to content

Commit

Permalink
fix script & deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
byeongsu-hong committed Feb 14, 2024
1 parent 19adc71 commit 4c41703
Show file tree
Hide file tree
Showing 5 changed files with 335 additions and 234 deletions.
202 changes: 40 additions & 162 deletions scripts/action/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import "reflect-metadata";

import { writeFileSync } from "fs";

import { loadContext } from "../src/load_context";
import { Client, HookType, config, getSigningClient } from "../src/config";
import {
Client,
DEFAULT_HOOK,
DEFAULT_ISM,
HookType,
config,
getSigningClient,
} from "../src/config";

import { ContractFetcher } from "./fetch";
import { Context } from "../src/types";
import { Contracts, deploy_ism } from "../src/deploy";
import { Contracts, deploy_ism, deploy_hook } from "../src/deploy";

const name = (c: any) => c.contractName;
const addr = (ctx: Context, c: any) => ctx.contracts[name(c)].address!;
Expand All @@ -22,8 +31,7 @@ async function main() {
} = contracts;

ctx = await deploy_core(ctx, client, contracts);
ctx = await deploy_igp(ctx, client, contracts);
ctx = await deploy_ism_hook(ctx, client, contracts);
ctx = await deploy_ism_and_hook(ctx, client, contracts);

// init test mock msg receiver
ctx.contracts[name(mocks.receiver)] = await mocks.receiver.instantiate({
Expand Down Expand Up @@ -86,191 +94,61 @@ const deploy_core = async (
return ctx;
};

const deploy_igp = async (
ctx: Context,
client: Client,
{ igp }: Contracts
): Promise<Context> => {
// init igp
ctx.contracts[name(igp.core)] = await igp.core.instantiate({
hrp: config.network.hrp,
owner: client.signer,
gas_token: config.deploy.igp.token || config.network.gas.denom,
beneficiary: client.signer,
});

// init igp oracle
ctx.contracts[name(igp.oracle)] = await igp.oracle.instantiate({
owner: client.signer,
});

await client.wasm.execute(
client.signer,
addr(ctx, igp.oracle),
{
set_remote_gas_data_configs: {
configs: Object.entries(config.deploy.igp.configs).map(
([domain, v]) => ({
remote_domain: Number(domain),
token_exchange_rate: v.exchange_rate.toString(),
gas_price: v.gas_price.toString(),
})
),
},
},
"auto"
);

await client.wasm.execute(
client.signer,
addr(ctx, igp.core),
{
router: {
set_routes: {
set: Object.keys(config.deploy.igp.configs).map((domain) => ({
domain: Number(domain),
route: addr(ctx, igp.oracle),
})),
},
},
},
"auto"
);

return ctx;
};

const deploy_ism_hook = async (
const deploy_ism_and_hook = async (
ctx: Context,
client: Client,
contracts: Contracts
) => {
// deploy default ism

ctx.contracts["hpl_default_ism"] = {
...ctx.contracts[`hpl_ism_${config.deploy.ism?.type || "multisig"}`],

address: await deploy_ism(
client,
config.deploy.ism || {
type: "multisig",
owner: "<signer>",
validators: {
5: {
addrs: [client.signer_addr],
threshold: 1,
},
},
},
contracts
),
};

[ctx, ctx.contracts["hpl_default_ism"].address] = await deploy_ism(
ctx,
client,
config.deploy.ism || DEFAULT_ISM(client.signer_addr),
contracts
);

// deploy default hook

ctx.contracts["hpl_default_hook"] = {
...ctx.contracts[
config.deploy.hooks?.default?.type &&
config.deploy.hooks?.default?.type !== "mock"
? `hpl_hook_${config.deploy.hooks.default.type}`
: "hpl_test_mock_hook"
],

address: await deploy_hook(
ctx,
client,
config.deploy.hooks?.default || { type: "mock" },
contracts
),
};

[ctx, ctx.contracts["hpl_default_hook"].address] = await deploy_hook(
ctx,
client,
config.deploy.hooks?.default || DEFAULT_HOOK,
contracts
);

// deploy required hook

ctx.contracts["hpl_required_hook"] = {
...ctx.contracts[
config.deploy.hooks?.required?.type &&
config.deploy.hooks?.required?.type !== "mock"
? `hpl_hook_${config.deploy.hooks.required.type}`
: "hpl_test_mock_hook"
],

address: await deploy_hook(
ctx,
client,
config.deploy.hooks?.required || { type: "mock" },
contracts
),
};

return ctx;
};

const deploy_hook = async (
ctx: Context,
client: Client,
hook: HookType,
contracts: Contracts
): Promise<string> => {
const {
core: { mailbox },
hooks,
igp,
mocks,
} = contracts;

switch (hook.type) {
case "aggregate":
const aggregate_hook_res = await hooks.aggregate.instantiate({
owner: hook.owner === "<signer>" ? client.signer : hook.owner,
hooks: await Promise.all(
hook.hooks.map((v) => deploy_hook(ctx, client, v, contracts))
),
});

return aggregate_hook_res.address!;

case "merkle":
const merkle_hook_res = await hooks.merkle.instantiate({
owner: hook.owner === "<signer>" ? client.signer : hook.owner,
mailbox: addr(ctx, mailbox),
});

return merkle_hook_res.address!;

case "mock":
const mock_hook_res = await mocks.hook.instantiate({});

return mock_hook_res.address!;

case "pausable":
const pausable_hook_res = await hooks.pausable.instantiate({
owner: hook.owner === "<signer>" ? client.signer : hook.owner,
});

return pausable_hook_res.address!;

case "igp":
return ctx.contracts[name(igp.core)].address!;

case "routing":
const routing_hook_res = await hooks.routing.instantiate({
owner: hook.owner === "<signer>" ? client.signer : hook.owner,
});
[ctx, ctx.contracts["hpl_required_hook"].address] = await deploy_hook(
ctx,
client,
config.deploy.hooks?.required || DEFAULT_HOOK,
contracts
);

await client.wasm.execute(
client.signer,
routing_hook_res.address!,
{
router: {
set_routes: {
set: await Promise.all(
Object.entries(hook.hooks).map(async ([domain, v]) => {
const route = await deploy_hook(ctx, client, v, contracts);
return { domain, route };
})
),
},
},
},
"auto"
);
default:
throw new Error("invalid hook type");
}
return ctx;
};

main().catch(console.error);
4 changes: 4 additions & 0 deletions scripts/action/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
HplTestMockMsgReceiver,
HplWarpCw20,
HplWarpNative,
HplHookFee,
HplTestMockIsm,
} from "../src/contracts";

type Const<T> = new (
Expand Down Expand Up @@ -50,6 +52,7 @@ export class ContractFetcher {
},
hooks: {
aggregate: this.get(HplHookAggregate, "hpl_hook_aggregate"),
fee: this.get(HplHookFee, "hpl_hook_fee"),
merkle: this.get(HplHookMerkle, "hpl_hook_merkle"),
pausable: this.get(HplHookPausable, "hpl_hook_pausable"),
routing: this.get(HplHookRouting, "hpl_hook_routing"),
Expand All @@ -73,6 +76,7 @@ export class ContractFetcher {
},
mocks: {
hook: this.get(HplTestMockHook, "hpl_test_mock_hook"),
ism: this.get(HplTestMockIsm, "hpl_test_mock_ism"),
receiver: this.get(
HplTestMockMsgReceiver,
"hpl_test_mock_msg_receiver"
Expand Down
26 changes: 25 additions & 1 deletion scripts/context/osmo-test-5.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
{
"contracts": {
"hpl_hook_aggregate": {
"address": "osmo10sr7uqmdxf70eym34g3agpqcg3dlhalj2qhskg40224advh5a74qc5htag",
"codeId": 6715,
"digest": "2ae680bad348a4cf289b1cc951bbaf0c68a9c31693b7deb2e0985cd65b5268be"
},
"hpl_hook_fee": {
"address": "osmo143008a6pn465z8u5pxmjy8dypkhwhkxchua99wq9ukj94k7mvs5syfdpnx",
"codeId": 6716,
"digest": "a7d2db4c76cd6e34978ee19ce25268b705e16db0f0e4fb815f343b289e892777"
},
"hpl_hook_merkle": {
"address": "osmo164y69rngl4n3uny0mejfpve9pe2j75lwcn4why5c9a4lwtethyksm75wu0",
"codeId": 6717,
"digest": "35da6025ef81ace5ad9b36edf0997828b65b434d87cecdd171a05b50679d263e"
},
"hpl_hook_pausable": {
"address": "osmo19d0cj9wys0556stak9wvrhg7yr4u3xp77wwy6egmvse4rrfv8e2qhcqjpv",
"codeId": 6718,
"digest": "493a4a637a9a9d73e926a42797524cec6799e895973b6a41e4a9cb7082c138f6"
},
Expand Down Expand Up @@ -41,6 +45,7 @@
"digest": "fa9ae6d1a129f88e56a35bc836f39427c2a589db6795d97b1c19c18c7eb8b823"
},
"hpl_ism_multisig": {
"address": "osmo1kcgs2qw2lgsqlg0ah4t9e5d5trz7pha56pzjae4yjnjnpuey2qwqape0mx",
"codeId": 6725,
"digest": "17ffef91b62b5fdb715e598f555901f55df277d94e3a157c63b5d73f883bb80a"
},
Expand All @@ -53,10 +58,12 @@
"digest": "641c803101059ab7bc40ebf5f9730e463733b7d0486364367e979873004afe2a"
},
"hpl_mailbox": {
"address": "osmo17w8776pqahas8el82xcq6lp6ylcreqv9jl3wq32x5l9hm4jds7yqaunlyt",
"codeId": 6728,
"digest": "5e3b0f950b4bcf5e67b12e9cdab953e37c22ee9190f82de5ce2e5e92fa33820b"
},
"hpl_test_mock_hook": {
"address": "osmo18ssgfr36mnqzmjt6r86jxxunte92zhrhwx6x8ckvmlrysy6cqpks94efx6",
"codeId": 6729,
"digest": "ca19b41ad96e6105d0a63d0984c52b50c3849dd15bf4a4e2c083c9628e19167b"
},
Expand All @@ -65,10 +72,12 @@
"digest": "c4cd903cdaf43c73932c3bdd3c9717d0cb9c4647541e9ec5ab4c16e86b9b70ec"
},
"hpl_test_mock_msg_receiver": {
"address": "osmo18ughnf23dqd5tdwmh3fnm4amapdn27shgjmr9akraujx9t80uuxqw8l679",
"codeId": 6731,
"digest": "ba40b0ed08399fd7a00d7453f74f4994c1dc1cba365e7149f63ceb9e9e29b34a"
},
"hpl_validator_announce": {
"address": "osmo1y25235tnv7y8levemflae8wllq32jfrr8rerseyt9mm2t2pa6pgsqksg20",
"codeId": 6732,
"digest": "716f8b3124e53f5d3534106ae40640dee11e7df2003106f0f2476d1ff3c12e57"
},
Expand All @@ -79,7 +88,22 @@
"hpl_warp_native": {
"codeId": 6734,
"digest": "581c35d20a031d11debbf452ac1b18dfe18a16da2d43b31767c963dfc7e90fd6"
},
"hpl_default_ism": {
"codeId": 6725,
"digest": "17ffef91b62b5fdb715e598f555901f55df277d94e3a157c63b5d73f883bb80a",
"address": "osmo1kcgs2qw2lgsqlg0ah4t9e5d5trz7pha56pzjae4yjnjnpuey2qwqape0mx"
},
"hpl_default_hook": {
"codeId": 6729,
"digest": "ca19b41ad96e6105d0a63d0984c52b50c3849dd15bf4a4e2c083c9628e19167b",
"address": "osmo18ssgfr36mnqzmjt6r86jxxunte92zhrhwx6x8ckvmlrysy6cqpks94efx6"
},
"hpl_required_hook": {
"codeId": 6715,
"digest": "2ae680bad348a4cf289b1cc951bbaf0c68a9c31693b7deb2e0985cd65b5268be",
"address": "osmo10sr7uqmdxf70eym34g3agpqcg3dlhalj2qhskg40224advh5a74qc5htag"
}
},
"address": "osmo1g3q542hpttdrj9aaczsq0tkl0uyfk7nkydklz6"
}
}
Loading

0 comments on commit 4c41703

Please sign in to comment.