Skip to content

Commit

Permalink
Merge branch 'dev-dev' into 'master'
Browse files Browse the repository at this point in the history
Dev dev

See merge request locklift/ever-locklift!18
  • Loading branch information
30mb1 committed Jul 15, 2022
2 parents feb286a + bb90019 commit 533eb45
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 58 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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']
// }
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/compilerComponentsStore/dirUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion src/compilerComponentsStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/factory/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class Account<Abi> {
return this.accountContract.address;
}

public async runTarget(
public runTarget = async (
config: {
contract: Contract<Abi>;
value?: string;
Expand All @@ -71,7 +71,7 @@ export class Account<Abi> {
AbiFunctionInputs<Abi, AbiFunctionName<Abi>>,
DecodedAbiFunctionOutputs<Abi, AbiFunctionName<Abi>>
>,
) {
) => {
return errorExtractor(
(this.accountContract as unknown as Contract<typeof accountAbiBase>).methods
.sendTransaction({
Expand All @@ -83,7 +83,7 @@ export class Account<Abi> {
})
.sendExternal({ publicKey: this.publicKey }),
);
}
};
}

export type DeployNewAccountParams<Abi> = Abi extends { data: infer D }
Expand All @@ -108,9 +108,9 @@ export class AccountFactory<Abi> {
getAccount = (accountAddress: Address, publicKey: string): Account<Abi> =>
Account.getAccount(accountAddress, this.ever, publicKey, this.abi);

async deployNewAccount(
public deployNewAccount = async (
args: DeployNewAccountParams<Abi>,
): Promise<{ account: Account<Abi>; tx: TransactionWithOutput }> {
): Promise<{ account: Account<Abi>; tx: TransactionWithOutput }> => {
return Account["deployNewAccount"](
this.deployer,
args.publicKey,
Expand All @@ -124,5 +124,5 @@ export class AccountFactory<Abi> {
} as GetExpectedAddressParams<Abi>,
args.constructorParams,
);
}
};
}
18 changes: 9 additions & 9 deletions src/factory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export class Factory<T extends FactoryType> {
return new Deployer(this.ever, this.giver);
}

public async deployContract<ContractName extends keyof T>(
public deployContract = async <ContractName extends keyof T>(
args: DeployContractParams<T, ContractName>,
): Promise<{ contract: Contract<T[ContractName]> } & DeployTransaction> {
): Promise<{ contract: Contract<T[ContractName]> } & DeployTransaction> => {
const { tvc, abi } = this.getContractArtifacts(args.contract);
return this.deployer.deployContract(
abi,
Expand All @@ -65,13 +65,13 @@ export class Factory<T extends FactoryType> {
args.constructorParams,
args.value,
);
}
};

public getAccountsFactory<ContractName extends keyof T>(contractName: ContractName) {
public getAccountsFactory = <ContractName extends keyof T>(contractName: ContractName) => {
const { tvc, abi } = this.getContractArtifacts(contractName as ContractName);
validateAccountAbi(abi);
return new AccountFactory(this.deployer, this.ever, abi, tvc);
}
};

public getDeployedContract = <ContractName extends keyof T>(
name: ContractName,
Expand Down Expand Up @@ -101,16 +101,16 @@ export class Factory<T extends FactoryType> {
};
};

public getContractArtifacts<key extends keyof T>(name: key): ContractData<T[key]> {
public getContractArtifacts = <key extends keyof T>(name: key): ContractData<T[key]> => {
return this.factoryCache[name] as ContractData<T[key]>;
}
};

public getAllArtifacts(): Array<{ contractName: keyof T; artifacts: ContractData<T[keyof T]> }> {
public getAllArtifacts = (): Array<{ contractName: keyof T; artifacts: ContractData<T[keyof T]> }> => {
return Object.entries(this.factoryCache).map(([contractName, artifacts]) => ({
contractName,
artifacts,
})) as unknown as Array<{ contractName: keyof T; artifacts: ContractData<T[keyof T]> }>;
}
};

public getContractByCodeHash = (codeHash: string, address: Address): ContractWithName | undefined => {
const contractArtifacts = this.getAllArtifacts().find(({ artifacts }) => artifacts.codeHash === codeHash);
Expand Down
70 changes: 33 additions & 37 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,50 +33,46 @@ export class Locklift<FactorySource = any> {
config: LockliftConfig<ConfigState.INTERNAL>,
network: keyof LockliftConfig["networks"] = "local",
): Promise<Locklift<T>> {
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<T>(provider, giver);
const factory = await Factory.setup<T>(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<T>(factory, giver, provider, clock, keystore, transactions, tracing);
} catch (e) {
throw e;
}
return new Locklift<T>(factory, giver, provider, clock, keystore, transactions, tracing);
}
}
2 changes: 1 addition & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down

0 comments on commit 533eb45

Please sign in to comment.