Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
feat: start of deploy backend
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtekgrinder committed Jan 17, 2024
1 parent 3cb69be commit 11f8ac1
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions toolchains/solidity/extension/src/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { exec } from "child_process";
import { workspace } from "vscode";
import * as path from 'path';

export type Contract = {
name: string;
path: string;
abi: any[];
address?: string;
}

Check warning on line 10 in toolchains/solidity/extension/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint (osmium-solidity)

Missing semicolon

export type Script = {
path: string;
name: string;
}

Check warning on line 15 in toolchains/solidity/extension/src/deploy.ts

View workflow job for this annotation

GitHub Actions / lint (osmium-solidity)

Missing semicolon

async function getContracts(): Promise<Contract[]> {
const contracts: Contract[] = [];
// TODO read from config file the contract path
const contractFiles = await workspace.findFiles('**/src/*.sol');
for (const contractFile of contractFiles) {
const contractContent = await workspace.fs.readFile(contractFile);
// TODO find a way to get the contract name
// TODO handle multiple contracts inside a single file
// TODO get the abi from the out directory based on the contract name
const contract = {
name: path.basename(contractFile.path, '.sol'),
path: contractFile.path,
abi: JSON.parse(contractContent.toString()).abi,
};
contracts.push(contract);
}
return contracts;
}

async function getScripts(): Promise<Script[]> {
const scripts: Script[] = [];
// TODO read from config file the script path
const scriptFiles = await workspace.findFiles('**/script/*.sol');
for (const scriptFile of scriptFiles) {
// TODO find a way to get the script name
// TODO handle multiple scripts inside a single file
// TODO get the abi from the out directory based on the contract name
const script = {
name: path.basename(scriptFile.path, '.sol'),
path: scriptFile.path,
};
scripts.push(script);
}
return [];
}

async function deployContract(network: number, contract: Contract, verify: boolean, cstrArgs: string): Promise<void> {
const verifyStr = verify ? '--verify' : '';
exec(`forge create ${contract.path}:${contract.name} -c ${network} ${verifyStr} --contructor-args ${cstrArgs}`, (error, _stdout, _stderr) => {
if (error) {
throw error;
}
});
}

async function deployScript(network: number, script: Script, verify: boolean): Promise<void> {
const verifyStr = verify ? '--verify' : '';
exec(`forge script ${script.path}:${script.name} -c ${network} ${verifyStr}`, (error, _stdout, _stderr) => {
if (error) {
throw error;
}
});
}

async function verifyContract(network: number, contract: Contract): Promise<void> {
// TODO load the contructor args path from out
exec(`forge verify-contract ${contract.path} ${contract.address} -c ${network}`, (error, _stdout, _stderr) => {
if (error) {
throw error;
}
});
}

0 comments on commit 11f8ac1

Please sign in to comment.