Skip to content

Commit

Permalink
chore: lint ts with graph lint package
Browse files Browse the repository at this point in the history
Signed-off-by: Tomás Migone <[email protected]>
  • Loading branch information
tmigone committed Mar 7, 2024
1 parent 22b0cca commit 48361b5
Show file tree
Hide file tree
Showing 79 changed files with 463 additions and 852 deletions.
7 changes: 0 additions & 7 deletions packages/contracts/.eslintignore

This file was deleted.

19 changes: 0 additions & 19 deletions packages/contracts/.eslintrc

This file was deleted.

4 changes: 0 additions & 4 deletions packages/contracts/.prettierignore

This file was deleted.

35 changes: 0 additions & 35 deletions packages/contracts/.prettierrc.json

This file was deleted.

17 changes: 17 additions & 0 deletions packages/contracts/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const config = require('eslint-graph-config')

module.exports = [
...config.default,
{
rules: {
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
},
},
{
ignores: ['**/reports/*'],
},
]
14 changes: 7 additions & 7 deletions packages/contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function loadTasks() {
;['contract', 'bridge', 'deployment', 'migrate', 'verify', 'e2e'].forEach((folder) => {
const tasksPath = path.join(__dirname, 'tasks', folder)
fs.readdirSync(tasksPath)
.filter((pth) => pth.includes('.ts'))
.filter(pth => pth.includes('.ts'))
.forEach((task) => {
require(`${tasksPath}/${task}`)
})
Expand Down Expand Up @@ -110,11 +110,11 @@ function setupNetworkProviders(hardhatConfig) {

// Config

const DEFAULT_TEST_MNEMONIC =
'myth like bonus scare over problem client lizard pioneer submit female collect'
const DEFAULT_TEST_MNEMONIC
= 'myth like bonus scare over problem client lizard pioneer submit female collect'

const DEFAULT_L2_TEST_MNEMONIC =
'urge never interest human any economy gentle canvas anxiety pave unlock find'
const DEFAULT_L2_TEST_MNEMONIC
= 'urge never interest human any economy gentle canvas anxiety pave unlock find'

const config: HardhatUserConfig = {
paths: {
Expand Down Expand Up @@ -233,8 +233,8 @@ const config: HardhatUserConfig = {
disambiguatePaths: false,
},
defender: {
apiKey: process.env.DEFENDER_API_KEY!,
apiSecret: process.env.DEFENDER_API_SECRET!,
apiKey: process.env.DEFENDER_API_KEY,
apiSecret: process.env.DEFENDER_API_SECRET,
},
}

Expand Down
23 changes: 7 additions & 16 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,15 @@
"@types/sinon-chai": "^3.2.12",
"@types/winston": "^2.4.4",
"@types/yargs": "^16.0.0",
"@typescript-eslint/eslint-plugin": "^4.0.0",
"@typescript-eslint/parser": "^4.0.0",
"@urql/core": "^2.1.3",
"arbos-precompiles": "^1.0.2",
"bignumber.js": "^9.0.0",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"cli-table": "^0.3.6",
"dotenv": "^9.0.0",
"eslint": "^7.24.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-no-only-tests": "^2.4.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint": "^8.57.0",
"eslint-graph-config": "workspace:^0.0.1",
"ethereum-waffle": "^3.2.0",
"ethers": "^5.7.2",
"form-data": "^4.0.0",
Expand All @@ -72,10 +68,7 @@
"isomorphic-fetch": "^3.0.0",
"lint-staged": "^10.5.4",
"p-queue": "^6.6.1",
"prettier": "^2.2.1",
"prettier-plugin-solidity": "1.0.0-beta.19",
"solhint": "^3.3.6",
"solhint-plugin-prettier": "^0.0.5",
"solidity-coverage": "^0.7.16",
"ts-node": "^10.9.1",
"typechain": "^5.0.0",
Expand All @@ -98,13 +91,11 @@
"test:coverage": "scripts/coverage",
"test:upgrade": "scripts/upgrade",
"lint": "yarn lint:ts && yarn lint:sol",
"lint:fix": "yarn lint:ts:fix && yarn lint:sol:fix",
"lint:ts": "eslint '**/*.{js,ts}'",
"lint:ts:fix": "yarn prettier:ts && eslint '**/*.{js,ts}' --fix",
"lint:fix": "yarn lint:ts && yarn lint:sol:fix",
"lint:ts": "eslint '**/*.{js,ts}' --fix",
"lint:sol": "solhint 'contracts/**/*.sol'",
"lint:sol:fix": "yarn prettier:sol && solhint --fix 'contracts/**/*.sol'",
"prettier": "yarn prettier:ts && yarn prettier:sol",
"prettier:ts": "prettier --write '**/*.{js,ts,json}'",
"prettier:sol": "prettier --write 'contracts/**/*.sol'",
"analyze": "scripts/analyze",
"myth": "scripts/myth",
Expand All @@ -118,13 +109,13 @@
"yarn lint:sol:fix"
],
"**/*.ts": [
"yarn lint:ts:fix"
"yarn lint:ts"
],
"**/*.js": [
"yarn lint:ts:fix"
"yarn lint:ts"
],
"**/*.json": [
"yarn lint:ts:fix"
"yarn lint:ts"
]
},
"repository": {
Expand Down
8 changes: 4 additions & 4 deletions packages/contracts/scripts/ops/parseTestnetAddresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ interface TeamMember {

export const teamAddresses: Array<TeamMember> = []

async function main() {
function main() {
const data = fs.readFileSync('indexers.csv', 'utf8')
const entries = data.split('\n').map((e) => e.trim())
const entries = data.split('\n').map(e => e.trim())
for (const entry of entries) {
if (!entry) continue

const [name, address] = entry.split(',').map((e) => e.trim())
const [name, address] = entry.split(',').map(e => e.trim())

// Verify address
try {
getAddress(address.trim())
} catch (err) {
} catch (_) {
console.log('Invalid', name, address)
process.exit(1)
}
Expand Down
13 changes: 10 additions & 3 deletions packages/contracts/tasks/bridge/deposits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import { Table } from 'console-table-printer'
import { L1ToL2MessageStatus } from '@arbitrum/sdk'
import { getL1ToL2MessageStatus } from '@graphprotocol/sdk'

interface PrintEvent {
blockNumber: string
tx: string
amount: string
status: string
}

greTask('bridge:deposits', 'List deposits initiated on L1GraphTokenGateway')
.addOptionalParam('startBlock', 'Start block for the search')
.addOptionalParam('endBlock', 'End block for the search')
Expand All @@ -21,7 +28,7 @@ greTask('bridge:deposits', 'List deposits initiated on L1GraphTokenGateway')
const events = await Promise.all(
(
await gateway.queryFilter(gateway.filters.DepositInitiated(), startBlock, endBlock)
).map(async (e) => ({
).map(async e => ({
blockNumber: `${e.blockNumber} (${new Date(
(await graph.l1.provider.getBlock(e.blockNumber)).timestamp * 1000,
).toLocaleString()})`,
Expand All @@ -48,7 +55,7 @@ greTask('bridge:deposits', 'List deposits initiated on L1GraphTokenGateway')
printEvents(events)
})

function printEvents(events: any[]) {
function printEvents(events: PrintEvent[]) {
const tablePrinter = new Table({
charLength: { '🚧': 2, '✅': 2, '⚠️': 1, '⌛': 2, '❌': 2 },
columns: [
Expand All @@ -64,7 +71,7 @@ function printEvents(events: any[]) {
],
})

events.map((e) => tablePrinter.addRow(e))
events.map(e => tablePrinter.addRow(e))
tablePrinter.printTable()
}

Expand Down
13 changes: 10 additions & 3 deletions packages/contracts/tasks/bridge/withdrawals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import { L2ToL1MessageStatus } from '@arbitrum/sdk'
import { greTask } from '@graphprotocol/sdk/gre'
import { getL2ToL1MessageStatus } from '@graphprotocol/sdk'

interface PrintEvent {
blockNumber: string
tx: string
amount: string
status: string
}

greTask('bridge:withdrawals', 'List withdrawals initiated on L2GraphTokenGateway')
.addOptionalParam('startBlock', 'Start block for the search')
.addOptionalParam('endBlock', 'End block for the search')
Expand All @@ -21,7 +28,7 @@ greTask('bridge:withdrawals', 'List withdrawals initiated on L2GraphTokenGateway
const events = await Promise.all(
(
await gateway.queryFilter(gateway.filters.WithdrawalInitiated(), startBlock, endBlock)
).map(async (e) => ({
).map(async e => ({
blockNumber: `${e.blockNumber} (${new Date(
(await graph.l2.provider.getBlock(e.blockNumber)).timestamp * 1000,
).toLocaleString()})`,
Expand All @@ -48,7 +55,7 @@ greTask('bridge:withdrawals', 'List withdrawals initiated on L2GraphTokenGateway
printEvents(events)
})

function printEvents(events: any[]) {
function printEvents(events: PrintEvent[]) {
const tablePrinter = new Table({
charLength: { '🚧': 2, '✅': 2, '⚠️': 1, '❌': 2 },
columns: [
Expand All @@ -64,7 +71,7 @@ function printEvents(events: any[]) {
],
})

events.map((e) => tablePrinter.addRow(e))
events.map(e => tablePrinter.addRow(e))
tablePrinter.printTable()
}

Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/tasks/contract/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeployType, GraphNetworkAddressBook, confirm, deploy } from '@graphprotocol/sdk'
import { confirm, deploy, DeployType, GraphNetworkAddressBook } from '@graphprotocol/sdk'
import { greTask } from '@graphprotocol/sdk/gre'

greTask('contract:deploy', 'Deploy a contract')
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/tasks/contract/upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { greTask } from '@graphprotocol/sdk/gre'
import { DeployType, GraphNetworkAddressBook, deploy } from '@graphprotocol/sdk'
import { deploy, DeployType, GraphNetworkAddressBook } from '@graphprotocol/sdk'

greTask('contract:upgrade', 'Upgrades a contract')
.addParam('contract', 'Name of the contract to upgrade')
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/tasks/deployment/config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {
confirm,
GraphNetworkConfigContractList,
GraphNetworkConfigGeneralParams,
updateContractParams,
updateGeneralParams,
writeConfig,
confirm,
} from '@graphprotocol/sdk'
import { greTask } from '@graphprotocol/sdk/gre'

greTask('update-config', 'Update graph config parameters with onchain data')
.addFlag('dryRun', "Only print the changes, don't write them to the config file")
.addFlag('dryRun', 'Only print the changes, don\'t write them to the config file')
.addFlag('skipConfirmation', 'Skip confirmation prompt on write actions.')
.setAction(async (taskArgs, hre) => {
const networkName = hre.network.name
Expand Down
9 changes: 5 additions & 4 deletions packages/contracts/tasks/e2e/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const INIT_TESTS = 'test/e2e/deployment/init/**/*.test.ts'

// Built-in test & run tasks don't support GRE arguments
// so we pass them by overriding GRE config object
const setGraphConfig = async (args: TaskArguments, hre: HardhatRuntimeEnvironment) => {
const setGraphConfig = (args: TaskArguments, hre: HardhatRuntimeEnvironment) => {
const greArgs = [
'graphConfig',
'l1GraphConfig',
Expand Down Expand Up @@ -42,7 +42,7 @@ greTask('e2e', 'Run all e2e tests')
]

if (args.skipBridge) {
testFiles = testFiles.filter((file) => !/l1|l2/.test(file))
testFiles = testFiles.filter(file => !/l1|l2/.test(file))
}

// Disable secure accounts, we don't need them for this task
Expand Down Expand Up @@ -84,7 +84,7 @@ greTask('e2e:init', 'Run deployment initialization e2e tests').setAction(

greTask('e2e:scenario', 'Run scenario scripts and e2e tests')
.addPositionalParam('scenario', 'Name of the scenario to run')
.addFlag('skipScript', "Don't run scenario script")
.addFlag('skipScript', 'Don\'t run scenario script')
.setAction(async (args, hre: HardhatRuntimeEnvironment) => {
setGraphConfig(args, hre)

Expand Down Expand Up @@ -126,7 +126,8 @@ greTask('e2e:upgrade', 'Run upgrade tests')
await runUpgrade(args, hre, args.post ? 'post' : 'pre')
})

async function runUpgrade(args: any, hre: HardhatRuntimeEnvironment, type: 'pre' | 'post') {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async function runUpgrade(args: { [key: string]: any }, hre: HardhatRuntimeEnvironment, type: 'pre' | 'post') {
const script = `test/e2e/upgrades/${args.upgrade}/${type}-upgrade.ts`
const test = `test/e2e/upgrades/${args.upgrade}/${type}-upgrade.test.ts`

Expand Down
8 changes: 5 additions & 3 deletions packages/contracts/tasks/migrate/nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ greTask(
// This adds the testnodes to the SDK configuration
subtask('migrate:nitro:register', 'Adds nitro testnodes to SDK config')
.addParam('deploymentFile', 'The testnode deployment file to use', 'localNetwork.json')
.setAction(async (taskArgs) => {
// eslint-disable-next-line @typescript-eslint/require-await
.setAction(async (taskArgs): Promise<void> => {
helpers.addLocalNetwork(taskArgs.deploymentFile)
})

Expand All @@ -29,6 +30,7 @@ subtask('migrate:nitro:deployment-file', 'Fetches nitro deployment file from a l
'Path to the file where to deployment file will be saved',
'localNetwork.json',
)
// eslint-disable-next-line @typescript-eslint/require-await
.setAction(async (taskArgs) => {
console.log(`Attempting to fetch deployment file from testnode...`)

Expand All @@ -53,15 +55,15 @@ task('migrate:nitro:address-book', 'Write arbitrum addresses to address book')
const deployment = JSON.parse(fs.readFileSync(taskArgs.deploymentFile, 'utf-8'))

const addressBook = {
'1337': {
1337: {
L1GatewayRouter: {
address: deployment.l2Network.tokenBridge.l1GatewayRouter,
},
IInbox: {
address: deployment.l2Network.ethBridge.inbox,
},
},
'412346': {
412346: {
L2GatewayRouter: {
address: deployment.l2Network.tokenBridge.l2GatewayRouter,
},
Expand Down
Loading

0 comments on commit 48361b5

Please sign in to comment.