diff --git a/README.md b/README.md index 18469eb..df4e216 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ const config: LockliftConfig = { version: "0.61.2", // Specify config for extarnal contracts as in exapmple + // This filed for generating types only // externalContracts: { // "node_modules/broxus-ton-tokens-contracts/build": ['TokenRoot', 'TokenWallet'] // } diff --git a/package.json b/package.json index e752a21..202ae8e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "locklift", - "version": "2.1.3", + "version": "2.1.4", "description": "Node JS framework for working with Ever contracts. Inspired by Truffle and Hardhat. Helps you to build, test, run and maintain your smart contracts.", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", diff --git a/src/compilerComponentsStore/dirUtils.ts b/src/compilerComponentsStore/dirUtils.ts index 2066fe5..a502ea4 100644 --- a/src/compilerComponentsStore/dirUtils.ts +++ b/src/compilerComponentsStore/dirUtils.ts @@ -5,13 +5,13 @@ import path from "path"; import { ComponentType, PACKAGE_NAME } from "./constants"; import { replaceDots } from "./utils"; -const getDataDir = (): string => { - const dataDir = envPaths(PACKAGE_NAME).data; +const getCacheDir = (): string => { + const dataDir = envPaths(PACKAGE_NAME).cache; fs.ensureDirSync(dataDir); return dataDir; }; const getComponentsDir = ({ component }: { component: ComponentType }): string => { - const dir = path.resolve(getDataDir(), component); + const dir = path.resolve(getCacheDir(), component); fs.ensureDirSync(dir); return dir; }; diff --git a/src/compilerComponentsStore/index.ts b/src/compilerComponentsStore/index.ts index 6d6e496..960d35f 100644 --- a/src/compilerComponentsStore/index.ts +++ b/src/compilerComponentsStore/index.ts @@ -27,7 +27,7 @@ export const getComponent = async ({ await fs.ensureDir(tempFileBaseDir); const gzFilePath = path.join(tempFileBaseDir, getGzFileName(fileNames[component]({ version }))); - await download(downloadLink, gzFilePath).catch(async e => { + await download(downloadLink, gzFilePath).catch(async () => { const supportedVersions = await getSupportedVersions({ component }); console.error(`Can't download ${component} version ${version}, supported versions: ${supportedVersions.join(" ")}`); await fs.rmdir(tempFileBaseDir); diff --git a/src/factory/account.ts b/src/factory/account.ts index ff3871f..199a089 100644 --- a/src/factory/account.ts +++ b/src/factory/account.ts @@ -58,7 +58,7 @@ export class Account { return this.accountContract.address; } - public async runTarget( + public runTarget = async ( config: { contract: Contract; value?: string; @@ -71,7 +71,7 @@ export class Account { AbiFunctionInputs>, DecodedAbiFunctionOutputs> >, - ) { + ) => { return errorExtractor( (this.accountContract as unknown as Contract).methods .sendTransaction({ @@ -83,7 +83,7 @@ export class Account { }) .sendExternal({ publicKey: this.publicKey }), ); - } + }; } export type DeployNewAccountParams = Abi extends { data: infer D } @@ -108,9 +108,9 @@ export class AccountFactory { getAccount = (accountAddress: Address, publicKey: string): Account => Account.getAccount(accountAddress, this.ever, publicKey, this.abi); - async deployNewAccount( + public deployNewAccount = async ( args: DeployNewAccountParams, - ): Promise<{ account: Account; tx: TransactionWithOutput }> { + ): Promise<{ account: Account; tx: TransactionWithOutput }> => { return Account["deployNewAccount"]( this.deployer, args.publicKey, @@ -124,5 +124,5 @@ export class AccountFactory { } as GetExpectedAddressParams, args.constructorParams, ); - } + }; } diff --git a/src/factory/index.ts b/src/factory/index.ts index 806aceb..0185c1b 100644 --- a/src/factory/index.ts +++ b/src/factory/index.ts @@ -50,9 +50,9 @@ export class Factory { return new Deployer(this.ever, this.giver); } - public async deployContract( + public deployContract = async ( args: DeployContractParams, - ): Promise<{ contract: Contract } & DeployTransaction> { + ): Promise<{ contract: Contract } & DeployTransaction> => { const { tvc, abi } = this.getContractArtifacts(args.contract); return this.deployer.deployContract( abi, @@ -65,13 +65,13 @@ export class Factory { args.constructorParams, args.value, ); - } + }; - public getAccountsFactory(contractName: ContractName) { + public getAccountsFactory = (contractName: ContractName) => { const { tvc, abi } = this.getContractArtifacts(contractName as ContractName); validateAccountAbi(abi); return new AccountFactory(this.deployer, this.ever, abi, tvc); - } + }; public getDeployedContract = ( name: ContractName, @@ -101,16 +101,16 @@ export class Factory { }; }; - public getContractArtifacts(name: key): ContractData { + public getContractArtifacts = (name: key): ContractData => { return this.factoryCache[name] as ContractData; - } + }; - public getAllArtifacts(): Array<{ contractName: keyof T; artifacts: ContractData }> { + public getAllArtifacts = (): Array<{ contractName: keyof T; artifacts: ContractData }> => { return Object.entries(this.factoryCache).map(([contractName, artifacts]) => ({ contractName, artifacts, })) as unknown as Array<{ contractName: keyof T; artifacts: ContractData }>; - } + }; public getContractByCodeHash = (codeHash: string, address: Address): ContractWithName | undefined => { const contractArtifacts = this.getAllArtifacts().find(({ artifacts }) => artifacts.codeHash === codeHash); diff --git a/src/index.ts b/src/index.ts index bb127f6..176ff0b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -33,50 +33,46 @@ export class Locklift { config: LockliftConfig, network: keyof LockliftConfig["networks"] = "local", ): Promise> { - try { - const networkConfig = config.networks[network]; + const networkConfig = config.networks[network]; - const giverKeys = getGiverKeyPair(networkConfig.giver); - const keys = await Keys.generate(networkConfig.keys); + const giverKeys = getGiverKeyPair(networkConfig.giver); + const keys = await Keys.generate(networkConfig.keys); - const keystore = new SimpleKeystore( - [...keys].reduce( - (acc, keyPair, idx) => ({ - ...acc, - [idx]: keyPair, - }), - {}, - ), - ); - keystore.addKeyPair("giver", giverKeys); + const keystore = new SimpleKeystore( + [...keys].reduce( + (acc, keyPair, idx) => ({ + ...acc, + [idx]: keyPair, + }), + {}, + ), + ); + keystore.addKeyPair("giver", giverKeys); - const clock = new Clock(); - const provider = new ProviderRpcClient({ - fallback: () => - EverscaleStandaloneClient.create({ - connection: networkConfig.connection, - keystore, - clock, - }), - }); - await provider.ensureInitialized(); + const clock = new Clock(); + const provider = new ProviderRpcClient({ + fallback: () => + EverscaleStandaloneClient.create({ + connection: networkConfig.connection, + keystore, + clock, + }), + }); + await provider.ensureInitialized(); - const giver = networkConfig.giver.giverFactory(provider, giverKeys, networkConfig.giver.address); + const giver = networkConfig.giver.giverFactory(provider, giverKeys, networkConfig.giver.address); - const factory = await Factory.setup(provider, giver); + const factory = await Factory.setup(provider, giver); - const transactions = new Transactions(provider); + const transactions = new Transactions(provider); - const tracing = createTracing({ - ever: provider, - features: transactions, - factory, - endpoint: networkConfig.tracing?.endpoint, - }); + const tracing = createTracing({ + ever: provider, + features: transactions, + factory, + endpoint: networkConfig.tracing?.endpoint, + }); - return new Locklift(factory, giver, provider, clock, keystore, transactions, tracing); - } catch (e) { - throw e; - } + return new Locklift(factory, giver, provider, clock, keystore, transactions, tracing); } } diff --git a/src/utils/index.ts b/src/utils/index.ts index c70e12d..67de8e2 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,6 +1,6 @@ import fs from "fs"; import BigNumber from "bignumber.js"; -import { Address, ProviderRpcClient, Transaction } from "everscale-inpage-provider"; +import { ProviderRpcClient, Transaction } from "everscale-inpage-provider"; import { getPublicKey, KeyPair } from "everscale-crypto"; import { Dimension } from "../constants";