Skip to content

Commit

Permalink
run linter
Browse files Browse the repository at this point in the history
  • Loading branch information
byeongsu-hong committed Mar 8, 2024
1 parent 99a0899 commit 22e5964
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 56 deletions.
6 changes: 0 additions & 6 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,4 @@ module.exports = {
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
'prettier/prettier': [
'error',
{
usePrettierrc: true,
},
],
};
Binary file modified .yarn/install-state.gz
Binary file not shown.
5 changes: 4 additions & 1 deletion script/commands/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ contractCmd
const { ctx, client } = CONTAINER.get(Dependencies);
const network = getNetwork(opts.networkId);

const mailbox = ctx.deployments.core?.mailbox!;
if (!ctx.deployments.core?.mailbox)
throw new Error('Mailbox contract not found');

const mailbox = ctx.deployments.core.mailbox;

const res = await executeContract(
client,
Expand Down
28 changes: 20 additions & 8 deletions script/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const deployCmd = new Command('deploy')
.configureHelp({ showGlobalOptions: true })
.action(handleDeploy);

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

ctx.deployments = ctx.deployments || {};
Expand All @@ -23,28 +23,40 @@ async function handleDeploy(_: any, cmd: any) {
// TODO: deploy warp
ctx.deployments.test = await deployTest(opts, ctx, client);

if (!ctx.deployments.core?.mailbox)
throw new Error('deployed Mailbox contract not found on context');

if (!ctx.deployments.isms)
throw new Error('deployed ISM contract not found on context');

if (!ctx.deployments.hooks?.default)
throw new Error('deployed Default Hook contract not found on context');

if (!ctx.deployments.hooks?.required)
throw new Error('deployed Required Hook contract not found on context');

await executeMultiMsg(client, [
{
contract: ctx.deployments.core?.mailbox!,
contract: ctx.deployments.core.mailbox,
msg: {
set_default_ism: {
ism: ctx.deployments.isms?.address!,
ism: ctx.deployments.isms.address,
},
},
},
{
contract: ctx.deployments.core?.mailbox!,
contract: ctx.deployments.core.mailbox,
msg: {
set_default_hook: {
hook: ctx.deployments.hooks?.default!.address,
hook: ctx.deployments.hooks.default.address,
},
},
},
{
contract: ctx.deployments.core?.mailbox!,
contract: ctx.deployments.core.mailbox,
msg: {
set_required_hook: {
hook: ctx.deployments.hooks?.required!.address,
hook: ctx.deployments.hooks.required.address,
},
},
},
Expand Down
23 changes: 12 additions & 11 deletions script/commands/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@ import { Command } from 'commander';
import * as fs from 'fs';

import {
REMOTE_MIN_VERSION,
contractNames,
defaultArtifactPath,
defaultTmpDir,
} from '../shared/constants';
import { saveContext } from '../shared/context';
import { ContractNames } from '../shared/contract';
import {
MIN_RELEASE_VERSION,
downloadReleases,
getReleases,
} from '../shared/github';
import { downloadReleases, getReleases } from '../shared/github';
import { CONTAINER, Dependencies } from '../shared/ioc';
import { askQuestion, sleep, waitTx } from '../shared/utils';
import { askQuestion, waitTx } from '../shared/utils';
import { getWasmPath, loadWasmFileDigest } from '../shared/wasm';

// ============ Command Definitions
Expand All @@ -43,7 +40,7 @@ uploadCmd
uploadCmd
.command('remote')
.description('upload artifacts from remote')
.argument('<tag-name>', `name of release tag. min: ${MIN_RELEASE_VERSION}`)
.argument('<tag-name>', `name of release tag. min: ${REMOTE_MIN_VERSION}`)
.option('-o --out <out dir>', 'artifact output directory', defaultTmpDir)
.action(handleRemote);

Expand All @@ -56,11 +53,15 @@ export { uploadCmd };

// ============ Handler Functions

async function handleRemote(tagName: string, _: any, cmd: any): Promise<void> {
const opts = cmd.optsWithGlobals();
async function handleRemote(
tagName: string,
_: object,
cmd: Command,
): Promise<void> {
const opts = cmd.optsWithGlobals() as { networkId: string; out: string };

if (tagName < MIN_RELEASE_VERSION)
throw new Error(`${tagName} < ${MIN_RELEASE_VERSION}`);
if (tagName < REMOTE_MIN_VERSION)
throw new Error(`${tagName} < ${REMOTE_MIN_VERSION}`);

const releases = await getReleases();
if (!releases[tagName])
Expand Down
30 changes: 20 additions & 10 deletions script/deploy/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export const deployHook = async (
): Promise<ContextHook> => {
switch (hook.type) {
// deploy fee hook
case 'fee':
case 'fee': {
const { gas } = getNetwork(networkId);

return deployContract(ctx, client, 'hpl_hook_fee', {
Expand All @@ -193,30 +193,35 @@ export const deployHook = async (
amount: hook.fee.amount.toString(),
},
});
}

// deploy merkle hook
case 'merkle':
case 'merkle': {
return deployContract(ctx, client, 'hpl_hook_merkle', {
mailbox: ctx.deployments.core?.mailbox?.address,
});
}

// deploy mock hook
case 'mock':
case 'mock': {
return deployContract(ctx, client, 'hpl_test_mock_hook', {});
}

// deploy pausable hook
case 'pausable':
case 'pausable': {
return deployContract(ctx, client, 'hpl_hook_pausable', {
owner: hook.owner === '<signer>' ? client.signer : hook.owner,
paused: hook.paused || false,
});
}

// deploy igp hook
case 'igp':
case 'igp': {
return deployIgp(networkId, ctx, client, hook);
}

// deploy aggregate hook
case 'aggregate':
case 'aggregate': {
const aggr = [];
for (const v of hook.hooks) {
aggr.push(await deployHook(networkId, ctx, client, v));
Expand All @@ -233,20 +238,25 @@ export const deployHook = async (
);

return { ...aggregate, hooks: aggr };
}

// deploy routing hook
case 'routing':
case 'routing': {
return deployRoutingHook(networkId, ctx, client, hook);
}

// deploy custom routing hook
case 'routing-custom':
case 'routing-custom': {
return deployCustomRoutingHook(networkId, ctx, client, hook);
}

// deploy fallback routing hook
case 'routing-fallback':
case 'routing-fallback': {
return deployFallbackRoitingHook(networkId, ctx, client, hook);
}

default:
default: {
throw new Error('invalid hook type');
}
}
};
12 changes: 8 additions & 4 deletions script/deploy/ism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function deployIsm(
): Promise<ContextIsm> {
switch (ism.type) {
// deploy multisig ism
case 'multisig':
case 'multisig': {
const multisig = await deployContract(ctx, client, 'hpl_ism_multisig', {
owner: ism.owner === '<signer>' ? client.signer : ism.owner,
});
Expand All @@ -69,9 +69,10 @@ export async function deployIsm(
);

return multisig;
}

// deploy aggregate ism
case 'aggregate':
case 'aggregate': {
const aggr = [];
for (const v of ism.isms) {
aggr.push(await deployIsm(ctx, client, v));
Expand All @@ -83,12 +84,15 @@ export async function deployIsm(
});

return { ...aggregate, isms: aggr };
}

// deploy routing ism
case 'routing':
case 'routing': {
return deployRoutingIsm(ctx, client, ism);
}

default:
default: {
throw new Error('invalid ism type');
}
}
}
20 changes: 13 additions & 7 deletions script/shared/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,23 @@ export async function fromContext(
): Promise<AgentConfig> {
const { hooks, core } = context.deployments;

const mailboxAddr = core?.mailbox?.address!;
// FIXME: use zod to validate the context
if (!core?.mailbox) throw new Error('Mailbox contract not found');
if (!core?.validator_announce)
throw new Error('Validator announce contract not found');
if (!hooks?.default || !hooks?.required)
throw new Error('No hooks found on this context');

const mailboxAddr = core.mailbox.address;
const mailboxContractInfo = await getContractInfo(network, mailboxAddr);

const igp =
findHook(hooks?.default!, 'hpl_igp') ||
findHook(hooks?.required!, 'hpl_igp');
findHook(hooks.default, 'hpl_igp') || findHook(hooks.required, 'hpl_igp');
if (!igp) throw new Error('no igp on this context');

const merkleTreeHook =
findHook(hooks?.default!, 'hpl_hook_merkle') ||
findHook(hooks?.required!, 'hpl_hook_merkle');
findHook(hooks.default, 'hpl_hook_merkle') ||
findHook(hooks.required, 'hpl_hook_merkle');
if (!merkleTreeHook) throw new Error('no merkle tree hook on this context');

const agent: AgentConfig = {
Expand Down Expand Up @@ -60,8 +66,8 @@ export async function fromContext(
},

// contract addresses
mailbox: fromBech32(core?.mailbox?.address!),
validatorAnnounce: fromBech32(core?.validator_announce?.address!),
mailbox: fromBech32(core.mailbox.address),
validatorAnnounce: fromBech32(core.validator_announce.address),
interchainGasPaymaster: fromBech32(igp.address),
merkleTreeHook: fromBech32(merkleTreeHook.address),
},
Expand Down
7 changes: 3 additions & 4 deletions script/shared/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ export type IsmType =
| {
type: 'aggregate';
owner: string;
isms: Exclude<IsmType, number[]>[];
isms: IsmType[];
}
| {
type: 'routing';
owner: string;
isms: { [domain: number]: Exclude<IsmType, number[]> };
}
| number[];
isms: { [domain: number]: IsmType };
};

export type FeeHookType = {
type: 'fee';
Expand Down
8 changes: 7 additions & 1 deletion script/shared/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ export function loadContext(
const fileName = path.join(contextPath, `${network}.json`);
const result = fs.readFileSync(fileName, 'utf-8');
return JSON.parse(result.toString()) as Context;
} catch (err) {}
} catch (err) {
console.error(
'Failed to load context. Returning an empty context object.',
'err:',
err,
);
}

return {
artifacts: {},
Expand Down
6 changes: 3 additions & 3 deletions script/shared/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function deployContract<T extends ContractNames>(
ctx: Context,
{ wasm, stargate, signer }: Client,
contractName: T,
initMsg: any,
initMsg: object,
): Promise<{ type: T; address: string }> {
console.log(`Deploying ${contractName}`);

Expand All @@ -35,7 +35,7 @@ export async function deployContract<T extends ContractNames>(
export async function executeContract(
{ wasm, stargate, signer }: Client,
deployment: { type: ContractNames; address: string },
msg: any,
msg: object,
funds: { amount: string; denom: string }[] = [],
): Promise<IndexedTx> {
console.log(`Executing ${deployment.type}'s ${Object.keys(msg)[0]}`);
Expand All @@ -58,7 +58,7 @@ export async function executeContract(

export async function executeMultiMsg(
{ wasm, stargate, signer }: Client,
msgs: { contract: { type: ContractNames; address: string }; msg: any }[],
msgs: { contract: { type: ContractNames; address: string }; msg: object }[],
): Promise<IndexedTx> {
const long = msgs
.map((v) => v.contract.type.length)
Expand Down
2 changes: 1 addition & 1 deletion script/shared/wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export type ContractInfoResp = {
tx_index: string;
};
ibc_por_id?: string;
extension?: any;
extension?: object;
};
};

Expand Down

0 comments on commit 22e5964

Please sign in to comment.