diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 656fec40..eb183388 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -7,10 +7,4 @@ module.exports = { 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended', ], - 'prettier/prettier': [ - 'error', - { - usePrettierrc: true, - }, - ], }; diff --git a/.yarn/install-state.gz b/.yarn/install-state.gz index a5e03780..6a216513 100644 Binary files a/.yarn/install-state.gz and b/.yarn/install-state.gz differ diff --git a/script/commands/contract.ts b/script/commands/contract.ts index 4568f5d3..eb820c44 100644 --- a/script/commands/contract.ts +++ b/script/commands/contract.ts @@ -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, diff --git a/script/commands/deploy.ts b/script/commands/deploy.ts index 8e841419..56b2f567 100644 --- a/script/commands/deploy.ts +++ b/script/commands/deploy.ts @@ -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 || {}; @@ -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, }, }, }, diff --git a/script/commands/upload.ts b/script/commands/upload.ts index 3bd66b0e..88638e95 100644 --- a/script/commands/upload.ts +++ b/script/commands/upload.ts @@ -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 @@ -43,7 +40,7 @@ uploadCmd uploadCmd .command('remote') .description('upload artifacts from remote') - .argument('', `name of release tag. min: ${MIN_RELEASE_VERSION}`) + .argument('', `name of release tag. min: ${REMOTE_MIN_VERSION}`) .option('-o --out ', 'artifact output directory', defaultTmpDir) .action(handleRemote); @@ -56,11 +53,15 @@ export { uploadCmd }; // ============ Handler Functions -async function handleRemote(tagName: string, _: any, cmd: any): Promise { - const opts = cmd.optsWithGlobals(); +async function handleRemote( + tagName: string, + _: object, + cmd: Command, +): Promise { + 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]) diff --git a/script/deploy/hook.ts b/script/deploy/hook.ts index 33b7adc5..85867551 100644 --- a/script/deploy/hook.ts +++ b/script/deploy/hook.ts @@ -183,7 +183,7 @@ export const deployHook = async ( ): Promise => { switch (hook.type) { // deploy fee hook - case 'fee': + case 'fee': { const { gas } = getNetwork(networkId); return deployContract(ctx, client, 'hpl_hook_fee', { @@ -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 === '' ? 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)); @@ -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'); + } } }; diff --git a/script/deploy/ism.ts b/script/deploy/ism.ts index 2dd709e4..3aea24b2 100644 --- a/script/deploy/ism.ts +++ b/script/deploy/ism.ts @@ -47,7 +47,7 @@ export async function deployIsm( ): Promise { switch (ism.type) { // deploy multisig ism - case 'multisig': + case 'multisig': { const multisig = await deployContract(ctx, client, 'hpl_ism_multisig', { owner: ism.owner === '' ? client.signer : ism.owner, }); @@ -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)); @@ -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'); + } } } diff --git a/script/shared/agent.ts b/script/shared/agent.ts index d70a7b5c..d838f05f 100644 --- a/script/shared/agent.ts +++ b/script/shared/agent.ts @@ -15,17 +15,23 @@ export async function fromContext( ): Promise { 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 = { @@ -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), }, diff --git a/script/shared/config.ts b/script/shared/config.ts index aba99270..11a018fe 100644 --- a/script/shared/config.ts +++ b/script/shared/config.ts @@ -28,14 +28,13 @@ export type IsmType = | { type: 'aggregate'; owner: string; - isms: Exclude[]; + isms: IsmType[]; } | { type: 'routing'; owner: string; - isms: { [domain: number]: Exclude }; - } - | number[]; + isms: { [domain: number]: IsmType }; + }; export type FeeHookType = { type: 'fee'; diff --git a/script/shared/context.ts b/script/shared/context.ts index ead1d3ce..0af8d65f 100644 --- a/script/shared/context.ts +++ b/script/shared/context.ts @@ -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: {}, diff --git a/script/shared/contract.ts b/script/shared/contract.ts index 2b5f0cac..18d4e7c1 100644 --- a/script/shared/contract.ts +++ b/script/shared/contract.ts @@ -11,7 +11,7 @@ export async function deployContract( ctx: Context, { wasm, stargate, signer }: Client, contractName: T, - initMsg: any, + initMsg: object, ): Promise<{ type: T; address: string }> { console.log(`Deploying ${contractName}`); @@ -35,7 +35,7 @@ export async function deployContract( export async function executeContract( { wasm, stargate, signer }: Client, deployment: { type: ContractNames; address: string }, - msg: any, + msg: object, funds: { amount: string; denom: string }[] = [], ): Promise { console.log(`Executing ${deployment.type}'s ${Object.keys(msg)[0]}`); @@ -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 { const long = msgs .map((v) => v.contract.type.length) diff --git a/script/shared/wasm.ts b/script/shared/wasm.ts index 962a4d30..f6f2446f 100644 --- a/script/shared/wasm.ts +++ b/script/shared/wasm.ts @@ -54,7 +54,7 @@ export type ContractInfoResp = { tx_index: string; }; ibc_por_id?: string; - extension?: any; + extension?: object; }; };