Skip to content

Commit

Permalink
Use function expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaStebaev committed Sep 13, 2023
1 parent e01af2d commit ed9477e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 41 deletions.
1 change: 0 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = {
"never"
],

"func-style": "warn",
"id-length": "warn",
"init-declarations": "warn",
"line-comment-position": "warn",
Expand Down
4 changes: 2 additions & 2 deletions src/abi.ts
Original file line number Diff line number Diff line change
@@ -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}) => {
Expand All @@ -19,4 +19,4 @@ export function getAbi (contractInterface: Interface) {
});

return abi;
}
};
24 changes: 11 additions & 13 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import {promises as fs} from "fs";
import {SkaleManifestData} from "./types/SkaleManifestData";

Check warning on line 4 in src/deploy.ts

View workflow job for this annotation

GitHub Actions / test (16.x)

Imports should be sorted alphabetically

Check warning on line 4 in src/deploy.ts

View workflow job for this annotation

GitHub Actions / test (18.x)

Imports should be sorted alphabetically

Check warning on line 4 in src/deploy.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Imports should be sorted alphabetically
import {Artifact} from "hardhat/types";

Check warning on line 5 in src/deploy.ts

View workflow job for this annotation

GitHub Actions / test (16.x)

Imports should be sorted alphabetically

Check warning on line 5 in src/deploy.ts

View workflow job for this annotation

GitHub Actions / test (18.x)

Imports should be sorted alphabetically

Check warning on line 5 in src/deploy.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Imports should be sorted alphabetically

async function _deployLibrary (libraryName: string) {
const _deployLibrary = async (libraryName: string) => {

Check warning on line 7 in src/deploy.ts

View workflow job for this annotation

GitHub Actions / test (16.x)

Unexpected dangling '_' in '_deployLibrary'

Check warning on line 7 in src/deploy.ts

View workflow job for this annotation

GitHub Actions / test (18.x)

Unexpected dangling '_' in '_deployLibrary'

Check warning on line 7 in src/deploy.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Unexpected dangling '_' in '_deployLibrary'
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<string, string>();
for (const libraryName of libraryNames) {
libraries.set(
Expand All @@ -21,9 +21,9 @@ export async function deployLibraries (libraryNames: string[]) {
);
}
return libraries;
}
};

function _linkBytecode (artifact: Artifact, libraries: Map<string, string>) {
const _linkBytecode = (artifact: Artifact, libraries: Map<string, string>) => {

Check warning on line 26 in src/deploy.ts

View workflow job for this annotation

GitHub Actions / test (16.x)

Unexpected dangling '_' in '_linkBytecode'

Check warning on line 26 in src/deploy.ts

View workflow job for this annotation

GitHub Actions / test (18.x)

Unexpected dangling '_' in '_linkBytecode'

Check warning on line 26 in src/deploy.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Unexpected dangling '_' in '_linkBytecode'
let {bytecode} = artifact;
for (const [, fileReferences] of Object.entries(artifact.linkReferences)) {
for (const [
Expand All @@ -46,9 +46,9 @@ function _linkBytecode (artifact: Artifact, libraries: Map<string, string>) {
}
}
return bytecode;
}
};

export async function getLinkedContractFactory (contractName: string, libraries: Map<string, string>) {
export const getLinkedContractFactory = async (contractName: string, libraries: Map<string, string>) => {
const
cArtifact = await artifacts.readArtifact(contractName);
const linkedBytecode = _linkBytecode(
Expand All @@ -60,13 +60,11 @@ export async function getLinkedContractFactory (contractName: string, libraries:
linkedBytecode
);
return ContractFactory;
}
};

export async function getManifestFile (): Promise<string> {
return (await Manifest.forNetwork(ethers.provider)).file;
}
export const getManifestFile = async (): Promise<string> => (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);
Expand Down Expand Up @@ -121,4 +119,4 @@ export async function getContractFactory (contract: string) {
contract,
libraries
);
}
};
24 changes: 12 additions & 12 deletions src/gnosis-safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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[]) {
Expand All @@ -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();
Expand All @@ -114,19 +114,19 @@ async function proposeTransaction (safeAddress: string, safeTransaction: SafeTra
"senderAddress": safeOwner.address,
"senderSignature": senderSignature.data
});
}
};

async function getEthAdapter (): Promise<EthersAdapter> {
const getEthAdapter = async (): Promise<EthersAdapter> => {
const
[safeOwner] = await ethers.getSigners();
const ethAdapter = new EthersAdapter({
ethers,
"signerOrProvider": safeOwner
});
return ethAdapter;
}
};

async function getSafeService () {
const getSafeService = async () => {
const
{chainId} = await ethers.provider.getNetwork();
const ethAdapter: EthersAdapter = await getEthAdapter();
Expand All @@ -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}`);
}
};
8 changes: 3 additions & 5 deletions src/multiSend.ts
Original file line number Diff line number Diff line change
@@ -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),
Expand Down Expand Up @@ -55,4 +53,4 @@ export function encodeTransaction (operation: 0 | 1, to: string, value: BigNumbe
_dataLength,
_data
].join("")}`;
}
};
8 changes: 4 additions & 4 deletions src/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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(
Expand All @@ -44,4 +44,4 @@ export async function verifyProxy (contractName: string, proxyAddress: string, c
),
constructorArguments
);
}
};
10 changes: 6 additions & 4 deletions src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const exec = util.promisify(asyncExec);

class VersionNotFound extends Error {}

async function getVersionFilename (folder?: string) {
const getVersionFilename = async (folder?: string): Promise<string> => {
if (folder === undefined) {
return getVersionFilename((await exec("git rev-parse --show-toplevel")).stdout.trim());
}
Expand All @@ -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) {
Expand Down

0 comments on commit ed9477e

Please sign in to comment.