Skip to content

Commit

Permalink
[REG-1395] linter, prettier configs, lint apply to all files
Browse files Browse the repository at this point in the history
  • Loading branch information
Armen-Arakelian committed Sep 6, 2024
1 parent b9b02c1 commit 7cfeee7
Show file tree
Hide file tree
Showing 30 changed files with 388 additions and 462 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"generator-star-spacing": ["error", "before"],
"indent": ["error", 2],
"linebreak-style": ["error", "unix"],
"max-len": ["error", { "code": 120, "tabWidth": 2, "ignorePattern": "^import\\W.*" }],
"max-len": ["error", { "code": 120, "tabWidth": 2, "ignorePattern": "^import\\W.*|^\\s*(it|describe)\\s*\\(\\s*['\"`].*['\"`]" }],
"no-debugger": "off",
"no-dupe-args": "error",
"no-dupe-keys": "error",
Expand Down
25 changes: 25 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
@maticnetwork/
@ens/

.env
.DS_Store
package-lock.json

# Dotfiles
.*
!.*.js
**/*.js
**/*.d.ts

# Node modules
node_modules
**/node_modules
**/@types
types/*

# Hardhat files
cache
artifacts
coverage.json
coverage

# Sandbox files
sandbox/*
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{
"files": "*.ts",
"options": {
"printWidth": 120,
"printWidth": 119,
"tabWidth": 2
}
},
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"lint": "yarn lint:ts && yarn lint:sol",
"lint:fix": "yarn lint:ts:fix && yarn lint:sol:fix",
"lint:ts": "eslint --ignore-path .gitignore .",
"lint:ts:fix": "eslint --ignore-path .gitignore . --fix",
"prettier:ts:check": "prettier --check --config ./.prettierrc --ignore-path ./.prettierignore \"test/**/*.ts\"",
"prettier:ts:fix": "prettier --write -l --config ./.prettierrc --ignore-path ./.prettierignore \"test/marketplace/SeaportProxyBuyer.test.ts\"",
"lint:ts:fix": "yarn prettier:ts:fix && eslint --ignore-path .gitignore . --fix",
"prettier:ts:check": "prettier --check --config ./.prettierrc --ignore-path ./.prettierignore \"./**/*.ts\"",
"prettier:ts:fix": "prettier --write -l --config ./.prettierrc --ignore-path ./.prettierignore \"./**/*.ts\"",
"lint:sol": "solhint 'contracts/**/*.sol' && prettier -c 'contracts/**/*.sol'",
"lint:sol:fix": "prettier --write \"contracts/**/*.sol\"",
"deploy:localhost": "hardhat run --network localhost scripts/deploy.ts",
Expand Down
33 changes: 8 additions & 25 deletions scripts/blockexplorer_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ type ContractSetup = {
legacyAddresses: string[];
deprecated: boolean;
};
const Config = JSON.parse(
fs.readFileSync(`${__dirname}/../uns-config.json`).toString(),
) as { networks: Record<string, { contracts: Record<string, ContractSetup> }> };
const Config = JSON.parse(fs.readFileSync(`${__dirname}/../uns-config.json`).toString()) as {
networks: Record<string, { contracts: Record<string, ContractSetup> }>;
};

const ContractNames = Object.keys(Config.networks['1'].contracts);

Expand All @@ -26,35 +26,20 @@ const BlockExplorerUrls = {

const Networks = Object.keys(BlockExplorerUrls);

const Keys = [
'network',
'address',
'forwarder',
] as const;
const Keys = ['network', 'address', 'forwarder'] as const;

const link = (network: string, address: string): string => {
return address.toString().match(/0x[0-9a-f]{40}/i)
? `<a href="${BlockExplorerUrls[network]}/address/${address}">${address}</a>`
: address;
};

const contractLinks = (
network: string,
address: string | string[],
): string => {
const addresses =
address instanceof Array
? address
: isValidAddress(address)
? [address]
: [];
return addresses.length
? addresses.map((a) => link(network, a)).join('<br/>')
: '&mdash;';
const contractLinks = (network: string, address: string | string[]): string => {
const addresses = address instanceof Array ? address : isValidAddress(address) ? [address] : [];
return addresses.length ? addresses.map((a) => link(network, a)).join('<br/>') : '&mdash;';
};

const fragments = ContractNames.map((name) => {

const deployments = Networks.map((network) => ({
network,
...Config.networks[network.toString()].contracts[name],
Expand All @@ -64,9 +49,7 @@ const fragments = ContractNames.map((name) => {
const rows = deployments
.map(
(config) =>
'<tr>'
+ Keys.map((key) => `<td>${contractLinks(config.network, config[key])}</td>`).join('') +
'</tr>',
'<tr>' + Keys.map((key) => `<td>${contractLinks(config.network, config[key])}</td>`).join('') + '</tr>',
)
.join('\n\n');

Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function main () {

main()
.then(() => process.exit(0))
.catch(error => {
.catch((error) => {
console.error(error);
process.exit(1);
});
2 changes: 1 addition & 1 deletion scripts/deploy_CNS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function main () {

main()
.then(() => process.exit(0))
.catch(error => {
.catch((error) => {
console.error(error);
process.exit(1);
});
12 changes: 5 additions & 7 deletions scripts/deploy_multisig.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import Safe, { SafeAccountConfig, SafeFactory } from '@safe-global/protocol-kit';


async function createSafe () {
const owners = [
];
const owners = [];

const threshold = 2;
const safeAccountConfig: SafeAccountConfig = {
Expand All @@ -19,10 +17,10 @@ async function createSafe () {

const safe: Safe = await safeFactory.deploySafe({ safeAccountConfig });

console.log('Is deployed: ' + await safe.isSafeDeployed());
console.log('Threshold: ' + await safe.getThreshold());
console.log('Owners: ' + await safe.getOwners());
console.log('Address: ' + await safe.getAddress());
console.log('Is deployed: ' + (await safe.isSafeDeployed()));
console.log('Threshold: ' + (await safe.getThreshold()));
console.log('Owners: ' + (await safe.getOwners()));
console.log('Address: ' + (await safe.getAddress()));
}

async function main () {
Expand Down
16 changes: 6 additions & 10 deletions scripts/upload_blockchain_families.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ function readCsv () {
function getNetworkFamiles (csv: string[][]) {
const result = {};

for(const row of csv) {
for (const row of csv) {
const [, family, network, ,] = row;

if(!result[network]) {
if (!result[network]) {
result[network] = family;
} else {
if(result[network] !== family) {
if (result[network] !== family) {
throw new Error(`Network ${network} can only have one family: ${result[network]} or ${family}`);
}
}
Expand All @@ -36,7 +36,7 @@ function getNetworkFamiles (csv: string[][]) {
function getLegacyKeys (csv: string[][]) {
const result = {};

for(const row of csv) {
for (const row of csv) {
const [legacyKey, family, network, token] = row;

const tokenKey = `token.${family}.${network}.${token}.address`;
Expand Down Expand Up @@ -71,13 +71,10 @@ async function uploadLegacyKeys (proxyReader: ProxyReader) {

console.log(`Found ${Object.keys(legacyKeys).length} keys`);

for(const keysChunk of chunk(Object.keys(legacyKeys), CHUNK_SIZE)) {
for (const keysChunk of chunk(Object.keys(legacyKeys), CHUNK_SIZE)) {
console.log(`Uploading chunk of legacy keys with size ${CHUNK_SIZE}`);

const tx = await proxyReader.addLegacyRecords(
keysChunk,
at(legacyKeys, keysChunk),
);
const tx = await proxyReader.addLegacyRecords(keysChunk, at(legacyKeys, keysChunk));

console.log(`TX hash: ${tx.hash}`);

Expand Down Expand Up @@ -115,4 +112,3 @@ main()
console.error(error);
process.exit(1);
});

19 changes: 9 additions & 10 deletions scripts/util/deploy_ERC1271SimpleWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,20 @@ async function main () {

const factory = await ethers.getContractFactory('ERC1271SimpleWallet', signer);

const result = await factory.deploy(
walletOwnerAddress,
);
const result = await factory.deploy(walletOwnerAddress);

await result.waitForDeployment();

console.log('Deployed ERC1271SimpleWallet address:', await result.getAddress());
console.log('ERC1271 owner address:', walletOwnerAddress);
}


// eslint-disable-next-line promise/catch-or-return
main().catch((err) => {
console.error(err);
process.exitCode = 1;
}).finally(() => {
process.exit();
});
main()
.catch((err) => {
console.error(err);
process.exitCode = 1;
})
.finally(() => {
process.exit();
});
18 changes: 5 additions & 13 deletions src/deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type DeployedContract = {
implementation: string;
forwarder: string;
transaction: TransactionResponse;
}
};

type DeployConfig = {
contracts: {
Expand Down Expand Up @@ -62,12 +62,7 @@ export class Deployer {
);
}

constructor (
options: DeployerOptions,
accounts: AccountsMap,
minters: string[],
multisig: string,
) {
constructor (options: DeployerOptions, accounts: AccountsMap, minters: string[], multisig: string) {
this.options = {
...DEFAULT_OPTIONS,
...options,
Expand Down Expand Up @@ -163,19 +158,16 @@ export class Deployer {
[name]: {
address: await contract.getAddress(),
implementation: implAddress,
transaction: (await contract.deploymentTransaction()?.wait()),
forwarder: forwarder && await forwarder.getAddress(),
transaction: await contract.deploymentTransaction()?.wait(),
forwarder: forwarder && (await forwarder.getAddress()),
},
},
});

this._saveConfig(_config);
}

async saveContractLegacyAddresses (
name: ContractName,
legacyAddresses: string[] = [],
): Promise<void> {
async saveContractLegacyAddresses (name: ContractName, legacyAddresses: string[] = []): Promise<void> {
const config = this.getDeployConfig();

const _config = merge(config, {
Expand Down
4 changes: 1 addition & 3 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,5 @@ function filterTldsByChainId (tldConfig: TLDConfig): boolean {
return true;
}

return tldConfig.networks
.flatMap((n) => NetworkChainIds[n])
.includes(chainId);
return tldConfig.networks.flatMap((n) => NetworkChainIds[n]).includes(chainId);
}
14 changes: 8 additions & 6 deletions src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export type Task = {
ensureDependencies: (ctx: Deployer, config?: NsNetworkConfig) => DependenciesMap;
};


export const deployCNSTask: Task = {
tags: ['cns', 'full'],
priority: 0,
Expand Down Expand Up @@ -562,13 +561,12 @@ const mintUnsTldsTask: Task = {
priority: 110,
run: async (ctx: Deployer, dependencies: DependenciesMap, params?: Record<string, string>) => {

Check warning on line 562 in src/tasks.ts

View workflow job for this annotation

GitHub Actions / lint

'dependencies' is defined but never used

Check warning on line 562 in src/tasks.ts

View workflow job for this annotation

GitHub Actions / lint

'params' is defined but never used
const { owner } = ctx.accounts;
if(!isSandbox){
if (!isSandbox) {
throw new Error('This task is only available for sandbox');
}

const mintingManagerAddr = ctx.getNetworkConfig()
.networks[network.config.chainId!]
.contracts[UnsContractName.MintingManager].address;
const mintingManagerAddr =
ctx.getNetworkConfig().networks[network.config.chainId!].contracts[UnsContractName.MintingManager].address;

Check warning on line 569 in src/tasks.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion

const mintingManager = await ethers.getContractAt(ArtifactName.MintingManager, mintingManagerAddr, owner);
await mintUnsTlds(mintingManager, owner);
Expand Down Expand Up @@ -749,7 +747,11 @@ const configurePolygonPosBridgeTask: Task = {
UnsContractName.RootChainManager,
]);

const rootChainManager = await ethers.getContractAt(ArtifactName.RootChainManager, RootChainManager.address, owner);
const rootChainManager = await ethers.getContractAt(
ArtifactName.RootChainManager,
RootChainManager.address,
owner,
);

const tokenType = keccak256(UNSRegistry.address);
await rootChainManager.registerPredicate(tokenType, MintableERC721Predicate.address);
Expand Down
Loading

0 comments on commit 7cfeee7

Please sign in to comment.