From ed9477e7ba9d1803175194a240d395911f7e848e Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Wed, 13 Sep 2023 19:02:07 +0300 Subject: [PATCH] Use function expressions --- .eslintrc.cjs | 1 - src/abi.ts | 4 ++-- src/deploy.ts | 24 +++++++++++------------- src/gnosis-safe.ts | 24 ++++++++++++------------ src/multiSend.ts | 8 +++----- src/verification.ts | 8 ++++---- src/version.ts | 10 ++++++---- 7 files changed, 38 insertions(+), 41 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 056b910..0cc44e9 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -23,7 +23,6 @@ module.exports = { "never" ], - "func-style": "warn", "id-length": "warn", "init-declarations": "warn", "line-comment-position": "warn", diff --git a/src/abi.ts b/src/abi.ts index af56d5d..335f114 100644 --- a/src/abi.ts +++ b/src/abi.ts @@ -1,6 +1,6 @@ import {Interface} from "ethers/lib/utils"; -export function getAbi (contractInterface: Interface) { +export const getAbi = (contractInterface: Interface) => { const abi = JSON.parse(contractInterface.format("json") as string) as []; abi.forEach((obj: {type: string}) => { @@ -19,4 +19,4 @@ export function getAbi (contractInterface: Interface) { }); return abi; -} +}; diff --git a/src/deploy.ts b/src/deploy.ts index 002ff27..355848a 100644 --- a/src/deploy.ts +++ b/src/deploy.ts @@ -4,15 +4,15 @@ import {promises as fs} from "fs"; import {SkaleManifestData} from "./types/SkaleManifestData"; import {Artifact} from "hardhat/types"; -async function _deployLibrary (libraryName: string) { +const _deployLibrary = async (libraryName: string) => { const Library = await ethers.getContractFactory(libraryName); const library = await Library.deploy(); await library.deployed(); return library.address; -} +}; -export async function deployLibraries (libraryNames: string[]) { +export const deployLibraries = async (libraryNames: string[]) => { const libraries = new Map(); for (const libraryName of libraryNames) { libraries.set( @@ -21,9 +21,9 @@ export async function deployLibraries (libraryNames: string[]) { ); } return libraries; -} +}; -function _linkBytecode (artifact: Artifact, libraries: Map) { +const _linkBytecode = (artifact: Artifact, libraries: Map) => { let {bytecode} = artifact; for (const [, fileReferences] of Object.entries(artifact.linkReferences)) { for (const [ @@ -46,9 +46,9 @@ function _linkBytecode (artifact: Artifact, libraries: Map) { } } return bytecode; -} +}; -export async function getLinkedContractFactory (contractName: string, libraries: Map) { +export const getLinkedContractFactory = async (contractName: string, libraries: Map) => { const cArtifact = await artifacts.readArtifact(contractName); const linkedBytecode = _linkBytecode( @@ -60,13 +60,11 @@ export async function getLinkedContractFactory (contractName: string, libraries: linkedBytecode ); return ContractFactory; -} +}; -export async function getManifestFile (): Promise { - return (await Manifest.forNetwork(ethers.provider)).file; -} +export const getManifestFile = async (): Promise => (await Manifest.forNetwork(ethers.provider)).file; -export async function getContractFactory (contract: string) { +export const getContractFactory = async (contract: string) => { const {linkReferences} = await artifacts.readArtifact(contract); if (!Object.keys(linkReferences).length) { return await ethers.getContractFactory(contract); @@ -121,4 +119,4 @@ export async function getContractFactory (contract: string) { contract, libraries ); -} +}; diff --git a/src/gnosis-safe.ts b/src/gnosis-safe.ts index 1363bce..ce383b2 100644 --- a/src/gnosis-safe.ts +++ b/src/gnosis-safe.ts @@ -24,7 +24,7 @@ const URLS = { // Public functions -export async function createMultiSendTransaction (safeAddress: string, transactions: UnsignedTransaction[]) { +export const createMultiSendTransaction = async (safeAddress: string, transactions: UnsignedTransaction[]) => { const safeTransactionData: MetaTransactionData[] = []; for (const transaction of transactions) { safeTransactionData.push({ @@ -73,11 +73,11 @@ export async function createMultiSendTransaction (safeAddress: string, transacti safeAddress, safeTransaction ); -} +}; // Private functions -async function estimateSafeTransaction (safeAddress: string, safeTransactionData: SafeTransactionDataPartial | MetaTransactionData[]) { +const estimateSafeTransaction = async (safeAddress: string, safeTransactionData: SafeTransactionDataPartial | MetaTransactionData[]) => { console.log("Estimate gas"); const safeService = await getSafeService(); for (const transaction of safeTransactionData as MetaTransactionData[]) { @@ -96,9 +96,9 @@ async function estimateSafeTransaction (safeAddress: string, safeTransactionData )}`)); } console.log(chalk.green("Send transaction to gnosis safe")); -} +}; -async function proposeTransaction (safeAddress: string, safeTransaction: SafeTransaction) { +const proposeTransaction = async (safeAddress: string, safeTransaction: SafeTransaction) => { const [safeOwner] = await ethers.getSigners(); const ethAdapter = await getEthAdapter(); @@ -114,9 +114,9 @@ async function proposeTransaction (safeAddress: string, safeTransaction: SafeTra "senderAddress": safeOwner.address, "senderSignature": senderSignature.data }); -} +}; -async function getEthAdapter (): Promise { +const getEthAdapter = async (): Promise => { const [safeOwner] = await ethers.getSigners(); const ethAdapter = new EthersAdapter({ @@ -124,9 +124,9 @@ async function getEthAdapter (): Promise { "signerOrProvider": safeOwner }); return ethAdapter; -} +}; -async function getSafeService () { +const getSafeService = async () => { const {chainId} = await ethers.provider.getNetwork(); const ethAdapter: EthersAdapter = await getEthAdapter(); @@ -135,11 +135,11 @@ async function getSafeService () { ethAdapter }); return safeService; -} +}; -function getSafeTransactionUrl (chainId: number) { +const getSafeTransactionUrl = (chainId: number) => { if (Object.keys(URLS.safe_transaction).includes(chainId.toString())) { return URLS.safe_transaction[chainId as keyof typeof URLS.safe_transaction]; } throw Error(`Can't get safe-transaction url at network with chainId = ${chainId}`); -} +}; diff --git a/src/multiSend.ts b/src/multiSend.ts index aa04415..185cdb2 100644 --- a/src/multiSend.ts +++ b/src/multiSend.ts @@ -1,10 +1,8 @@ import {BigNumber} from "ethers"; -function padWithZeros (value: string, targetLength: number) { - return ("0".repeat(targetLength) + value).slice(-targetLength); -} +const padWithZeros = (value: string, targetLength: number) => ("0".repeat(targetLength) + value).slice(-targetLength); -export function encodeTransaction (operation: 0 | 1, to: string, value: BigNumber | number, data: string) { +export const encodeTransaction = (operation: 0 | 1, to: string, value: BigNumber | number, data: string) => { // / operation as a uint8 with 0 for a call or 1 for a delegatecall (=> 1 byte), // / to as a address (=> 20 bytes), // / value as a uint256 (=> 32 bytes), @@ -55,4 +53,4 @@ export function encodeTransaction (operation: 0 | 1, to: string, value: BigNumbe _dataLength, _data ].join("")}`; -} +}; diff --git a/src/verification.ts b/src/verification.ts index 9685b57..a589248 100644 --- a/src/verification.ts +++ b/src/verification.ts @@ -3,7 +3,7 @@ import {builtinChains} from "@nomicfoundation/hardhat-verify/internal/chain-conf import chalk from "chalk"; import {getImplementationAddress} from "@openzeppelin/upgrades-core"; -export async function verify (contractName: string, contractAddress: string, constructorArguments: object) { +export const verify = async (contractName: string, contractAddress: string, constructorArguments: object) => { const {chainId} = await ethers.provider.getNetwork(); if (builtinChains.find((chain) => chain.chainId === chainId) !== undefined) { for (let retry = 0; retry <= 5; retry += 1) { @@ -33,9 +33,9 @@ export async function verify (contractName: string, contractAddress: string, con } } } -} +}; -export async function verifyProxy (contractName: string, proxyAddress: string, constructorArguments: object) { +export const verifyProxy = async (contractName: string, proxyAddress: string, constructorArguments: object) => { await verify( contractName, await getImplementationAddress( @@ -44,4 +44,4 @@ export async function verifyProxy (contractName: string, proxyAddress: string, c ), constructorArguments ); -} +}; diff --git a/src/version.ts b/src/version.ts index f79148d..a182828 100644 --- a/src/version.ts +++ b/src/version.ts @@ -7,7 +7,7 @@ const exec = util.promisify(asyncExec); class VersionNotFound extends Error {} -async function getVersionFilename (folder?: string) { +const getVersionFilename = async (folder?: string): Promise => { if (folder === undefined) { return getVersionFilename((await exec("git rev-parse --show-toplevel")).stdout.trim()); } @@ -18,15 +18,17 @@ async function getVersionFilename (folder?: string) { } for (const entry of await fs.readdir( folder, - {"withFileTypes": true, - "recursive": true} + { + "withFileTypes": true, + "recursive": true + } )) { if (entry.isFile() && entry.name === VERSION_FILENAME) { return `${entry.path}/${entry.name}`; } } throw new VersionNotFound("Can't find version file"); -} +}; export const getVersion = async () => { if (process.env.VERSION) {