Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: apply linter #113

Merged
merged 6 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ insert_final_newline = true
indent_size = 4

[*.ts]
quote_type = single
indent_size = 2
10 changes: 10 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.cargo/
.github/
.vscode/
.yarn/
asset/
contracts/
integration-test/
node_modules/
packages/
target/
10 changes: 10 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
};
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"printWidth": 80,
"tabWidth": 2,
"trailingComma": "all",
"singleQuote": true,
"semi": true,
"useTabs": false,
"importOrder": ["^[./]"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true,
"plugins": ["@trivago/prettier-plugin-sort-imports"]
}
Binary file modified .yarn/install-state.gz
Binary file not shown.
19 changes: 10 additions & 9 deletions codegen.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import * as fs from "fs";
import codegen from "@cosmwasm/ts-codegen";
import path from "path";
import codegen from '@cosmwasm/ts-codegen';
import * as fs from 'fs';
import path from 'path';

const SCHEMA_DIR = process.env.SCHEMA_DIR || path.join(process.cwd(), "schema");
const SCHEMA_DIR = process.env.SCHEMA_DIR || path.join(process.cwd(), 'schema');

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const capitalize = (str: string): string =>
str.charAt(0).toUpperCase() + str.slice(1);

const contracts = fs
.readdirSync(SCHEMA_DIR, { withFileTypes: true })
.filter((c) => !c.isDirectory())
.map((c) => ({
name: c.name.replace(".json", ""),
name: c.name.replace('.json', ''),
dir: SCHEMA_DIR,
}));

codegen({
contracts,
outPath: "./dist/",
outPath: './dist/',

// options are completely optional ;)
options: {
bundle: {
bundleFile: "index.ts",
scope: "contracts",
bundleFile: 'index.ts',
scope: 'contracts',
},
client: {
enabled: true,
Expand All @@ -33,5 +34,5 @@ codegen({
},
},
}).then(() => {
console.log("✨ all done!");
console.log('✨ all done!');
});
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,18 @@
},
"devDependencies": {
"@cosmwasm/ts-codegen": "^0.35.7",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/decompress": "^4.2.7",
"@types/eslint": "^8",
"@types/js-yaml": "^4.0.8",
"@types/node": "^20.11.20",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"esbuild": "^0.20.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"prettier": "^3.2.5",
"ts-node": "^10.9.1",
"ts-yaml": "^1.0.0",
"tsx": "^3.13.0",
Expand Down
18 changes: 9 additions & 9 deletions script/commands/context.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Command } from "commander";
import { Command } from 'commander';

import { CONTAINER, Dependencies } from "../shared/ioc";
import { saveAgentConfig } from "../shared/agent";
import { getNetwork } from "../shared/config";
import { saveAgentConfig } from '../shared/agent';
import { getNetwork } from '../shared/config';
import { CONTAINER, Dependencies } from '../shared/ioc';

const contextCmd = new Command("context");
const contextCmd = new Command('context');

contextCmd
.command("make-agent-config")
.description("Make an agent config")
.option("-o --output <output-dir>", "The output directory")
.command('make-agent-config')
.description('Make an agent config')
.option('-o --output <output-dir>', 'The output directory')
.action(async (_, cmd) => {
const opts = cmd.optsWithGlobals();
const { ctx } = CONTAINER.get(Dependencies);
Expand All @@ -18,7 +18,7 @@ contextCmd
await saveAgentConfig(
network,
ctx,
opts.output && { contextPath: opts.output }
opts.output && { contextPath: opts.output },
);
});

Expand Down
37 changes: 20 additions & 17 deletions script/commands/contract.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
import { Command } from "commander";
import { Command } from 'commander';

import { contractNames } from "../shared/constants";
import { executeContract } from "../shared/contract";
import { CONTAINER, Dependencies } from "../shared/ioc";
import { addPad } from "../shared/utils";
import { getNetwork } from "../shared/config";
import { getNetwork } from '../shared/config';
import { contractNames } from '../shared/constants';
import { executeContract } from '../shared/contract';
import { CONTAINER, Dependencies } from '../shared/ioc';
import { addPad } from '../shared/utils';

export const contractCmd = new Command("contract").configureHelp({
export const contractCmd = new Command('contract').configureHelp({
showGlobalOptions: true,
});

contractCmd.command("list").action(() => {
console.log("Available contracts:".green);
contractNames.forEach((v) => console.log("-", v));
contractCmd.command('list').action(() => {
console.log('Available contracts:'.green);
contractNames.forEach((v) => console.log('-', v));
});

contractCmd
.command("test-dispatch")
.argument("dest-domian")
.argument("recipient-addr")
.argument("msg-body")
.command('test-dispatch')
.argument('dest-domian')
.argument('recipient-addr')
.argument('msg-body')
.action(async (destDomain, recipientAddr, msgBody, _, cmd) => {
const opts = cmd.optsWithGlobals();
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 All @@ -34,10 +37,10 @@ contractCmd
dispatch: {
dest_domain: parseInt(destDomain),
recipient_addr: addPad(recipientAddr),
msg_body: Buffer.from(msgBody, "utf-8").toString("hex"),
msg_body: Buffer.from(msgBody, 'utf-8').toString('hex'),
},
},
[{ amount: "500", denom: network.gas.denom }]
[{ amount: '500', denom: network.gas.denom }],
);

console.log(res.hash);
Expand Down
82 changes: 47 additions & 35 deletions script/commands/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Command } from "commander";
import { Command } from 'commander';

import { deployIsm, deployHook } from "../deploy";
import { CONTAINER, Dependencies } from "../shared/ioc";
import { Client, config, getNetwork } from "../shared/config";
import { Context, ContextDeployments, saveContext } from "../shared/context";
import { deployContract, executeMultiMsg } from "../shared/contract";
import { saveAgentConfig } from "../shared/agent";
import { deployHook, deployIsm } from '../deploy';
import { saveAgentConfig } from '../shared/agent';
import { Client, config, getNetwork } from '../shared/config';
import { Context, ContextDeployments, saveContext } from '../shared/context';
import { deployContract, executeMultiMsg } from '../shared/contract';
import { CONTAINER, Dependencies } from '../shared/ioc';

export const deployCmd = new Command("deploy")
.description("Deploy contracts")
export const deployCmd = new Command('deploy')
.description('Deploy contracts')
.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 All @@ -57,19 +69,19 @@ async function handleDeploy(_: any, cmd: any) {
const deployCore = async (
{ networkId }: { networkId: string },
ctx: Context,
client: Client
): Promise<ContextDeployments["core"]> => {
client: Client,
): Promise<ContextDeployments['core']> => {
const { hrp, domain } = getNetwork(networkId);

const log = (v: string) => console.log("[core]".green, v);
const log = (v: string) => console.log('[core]'.green, v);
const preload = ctx.deployments.core;
const deployment = preload || {};

if (preload?.mailbox) {
log(`${preload.mailbox.type} already deployed`);
deployment.mailbox = preload.mailbox;
} else {
deployment.mailbox = await deployContract(ctx, client, "hpl_mailbox", {
deployment.mailbox = await deployContract(ctx, client, 'hpl_mailbox', {
hrp,
domain,
owner: client.signer,
Expand All @@ -78,7 +90,7 @@ const deployCore = async (

deployment.validator_announce =
preload?.validator_announce ||
(await deployContract(ctx, client, "hpl_validator_announce", {
(await deployContract(ctx, client, 'hpl_validator_announce', {
hrp,
mailbox: deployment.mailbox.address,
}));
Expand All @@ -90,13 +102,13 @@ const deployCore = async (

const deployIsms = async (
ctx: Context,
client: Client
): Promise<ContextDeployments["isms"]> => {
client: Client,
): Promise<ContextDeployments['isms']> => {
if (!config.deploy.ism) {
throw new Error("ISM deployment config not found");
throw new Error('ISM deployment config not found');
}

const log = (v: string) => console.log("[ism]".green, v);
const log = (v: string) => console.log('[ism]'.green, v);
const preload = ctx.deployments.isms;
if (preload) {
log(`ism ${preload.type} already deployed`);
Expand All @@ -110,12 +122,12 @@ const deployHooks = async (
{ networkId }: { networkId: string },
ctx: Context,
client: Client,
): Promise<ContextDeployments["hooks"]> => {
): Promise<ContextDeployments['hooks']> => {
if (!config.deploy.hooks) {
throw new Error("Hook deployment config not found");
throw new Error('Hook deployment config not found');
}

const log = (v: string) => console.log("[hooks]".green, v);
const log = (v: string) => console.log('[hooks]'.green, v);
const preload = ctx.deployments?.hooks;
const deployment = preload || {};

Expand All @@ -124,7 +136,7 @@ const deployHooks = async (
deployment.default = preload.default;
} else {
if (!config.deploy.hooks.default)
throw Error("Default hook deployment config not found");
throw Error('Default hook deployment config not found');

deployment.default = await deployHook(
networkId,
Expand All @@ -139,7 +151,7 @@ const deployHooks = async (
deployment.required = preload.required;
} else {
if (!config.deploy.hooks.required)
throw Error("Required hook deployment config not found");
throw Error('Required hook deployment config not found');

deployment.required = await deployHook(
networkId,
Expand All @@ -155,17 +167,17 @@ const deployHooks = async (
const deployTest = async (
{ networkId }: { networkId: string },
ctx: Context,
client: Client
): Promise<ContextDeployments["test"]> => {
client: Client,
): Promise<ContextDeployments['test']> => {
const { hrp } = getNetwork(networkId);

const log = (v: string) => console.log("[test]".green, v);
const log = (v: string) => console.log('[test]'.green, v);
const preload = ctx.deployments.test;
const deployment = preload || {};

deployment.msg_receiver =
preload?.msg_receiver ||
(await deployContract(ctx, client, "hpl_test_mock_msg_receiver", {
(await deployContract(ctx, client, 'hpl_test_mock_msg_receiver', {
hrp,
}));
if (preload?.msg_receiver)
Expand Down
8 changes: 4 additions & 4 deletions script/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { deployCmd } from "./deploy";
export { uploadCmd } from "./upload";
export { contractCmd } from "./contract";
export { migrateCmd } from "./migrate";
export { deployCmd } from './deploy';
export { uploadCmd } from './upload';
export { contractCmd } from './contract';
export { migrateCmd } from './migrate';
Loading
Loading