Skip to content

Commit

Permalink
Fixed lint
Browse files Browse the repository at this point in the history
  • Loading branch information
danitome24 committed Sep 14, 2024
1 parent e13ec3f commit 808a87e
Show file tree
Hide file tree
Showing 12 changed files with 527 additions and 568 deletions.
108 changes: 53 additions & 55 deletions packages/foundry/script/DeployHelpers.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,74 +5,72 @@ import "forge-std/Script.sol";
import "forge-std/Vm.sol";

contract ScaffoldETHDeploy is Script {
error InvalidChain();
error InvalidChain();

struct Deployment {
string name;
address addr;
}
struct Deployment {
string name;
address addr;
}

string root;
string path;
Deployment[] public deployments;
string root;
string path;
Deployment[] public deployments;

function setupLocalhostEnv() internal returns (uint256 localhostPrivateKey) {
if (block.chainid == 31337) {
root = vm.projectRoot();
path = string.concat(root, "/localhost.json");
string memory json = vm.readFile(path);
bytes memory mnemonicBytes = vm.parseJson(json, ".wallet.mnemonic");
string memory mnemonic = abi.decode(mnemonicBytes, (string));
return vm.deriveKey(mnemonic, 0);
} else {
return vm.envUint("DEPLOYER_PRIVATE_KEY");
function setupLocalhostEnv() internal returns (uint256 localhostPrivateKey) {
if (block.chainid == 31337) {
root = vm.projectRoot();
path = string.concat(root, "/localhost.json");
string memory json = vm.readFile(path);
bytes memory mnemonicBytes = vm.parseJson(json, ".wallet.mnemonic");
string memory mnemonic = abi.decode(mnemonicBytes, (string));
return vm.deriveKey(mnemonic, 0);
} else {
return vm.envUint("DEPLOYER_PRIVATE_KEY");
}
}
}

function exportDeployments() internal {
// fetch already existing contracts
root = vm.projectRoot();
path = string.concat(root, "/deployments/");
string memory chainIdStr = vm.toString(block.chainid);
path = string.concat(path, string.concat(chainIdStr, ".json"));
function exportDeployments() internal {
// fetch already existing contracts
root = vm.projectRoot();
path = string.concat(root, "/deployments/");
string memory chainIdStr = vm.toString(block.chainid);
path = string.concat(path, string.concat(chainIdStr, ".json"));

string memory jsonWrite;
string memory jsonWrite;

uint256 len = deployments.length;
uint256 len = deployments.length;

for (uint256 i = 0; i < len; i++) {
vm.serializeString(
jsonWrite, vm.toString(deployments[i].addr), deployments[i].name
);
}
for (uint256 i = 0; i < len; i++) {
vm.serializeString(jsonWrite, vm.toString(deployments[i].addr), deployments[i].name);
}

string memory chainName;
string memory chainName;

try this.getChain() returns (Chain memory chain) {
chainName = chain.name;
} catch {
chainName = findChainName();
try this.getChain() returns (Chain memory chain) {
chainName = chain.name;
} catch {
chainName = findChainName();
}
jsonWrite = vm.serializeString(jsonWrite, "networkName", chainName);
vm.writeJson(jsonWrite, path);
}
jsonWrite = vm.serializeString(jsonWrite, "networkName", chainName);
vm.writeJson(jsonWrite, path);
}

function getChain() public returns (Chain memory) {
return getChain(block.chainid);
}
function getChain() public returns (Chain memory) {
return getChain(block.chainid);
}

function findChainName() public returns (string memory) {
uint256 thisChainId = block.chainid;
string[2][] memory allRpcUrls = vm.rpcUrls();
for (uint256 i = 0; i < allRpcUrls.length; i++) {
try vm.createSelectFork(allRpcUrls[i][1]) {
if (block.chainid == thisChainId) {
return allRpcUrls[i][0];
function findChainName() public returns (string memory) {
uint256 thisChainId = block.chainid;
string[2][] memory allRpcUrls = vm.rpcUrls();
for (uint256 i = 0; i < allRpcUrls.length; i++) {
try vm.createSelectFork(allRpcUrls[i][1]) {
if (block.chainid == thisChainId) {
return allRpcUrls[i][0];
}
} catch {
continue;
}
}
} catch {
continue;
}
revert InvalidChain();
}
revert InvalidChain();
}
}
170 changes: 66 additions & 104 deletions packages/foundry/script/VerifyAll.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,129 +11,91 @@ import "solidity-bytes-utils/BytesLib.sol";
* @notice will be deleted once the forge/std is updated
*/
struct FfiResult {
int32 exit_code;
bytes stdout;
bytes stderr;
int32 exit_code;
bytes stdout;
bytes stderr;
}

interface tempVm {
function tryFfi(
string[] calldata
) external returns (FfiResult memory);
function tryFfi(string[] calldata) external returns (FfiResult memory);
}

contract VerifyAll is Script {
uint96 currTransactionIdx;
uint96 currTransactionIdx;

function run() external {
string memory root = vm.projectRoot();
string memory path = string.concat(
root,
"/broadcast/Deploy.s.sol/",
vm.toString(block.chainid),
"/run-latest.json"
);
string memory content = vm.readFile(path);
function run() external {
string memory root = vm.projectRoot();
string memory path =
string.concat(root, "/broadcast/Deploy.s.sol/", vm.toString(block.chainid), "/run-latest.json");
string memory content = vm.readFile(path);

while (this.nextTransaction(content)) {
_verifyIfContractDeployment(content);
currTransactionIdx++;
while (this.nextTransaction(content)) {
_verifyIfContractDeployment(content);
currTransactionIdx++;
}
}
}

function _verifyIfContractDeployment(
string memory content
) internal {
string memory txType = abi.decode(
vm.parseJson(content, searchStr(currTransactionIdx, "transactionType")),
(string)
);
if (keccak256(bytes(txType)) == keccak256(bytes("CREATE"))) {
_verifyContract(content);
function _verifyIfContractDeployment(string memory content) internal {
string memory txType =
abi.decode(vm.parseJson(content, searchStr(currTransactionIdx, "transactionType")), (string));
if (keccak256(bytes(txType)) == keccak256(bytes("CREATE"))) {
_verifyContract(content);
}
}
}

function _verifyContract(
string memory content
) internal {
string memory contractName = abi.decode(
vm.parseJson(content, searchStr(currTransactionIdx, "contractName")),
(string)
);
address contractAddr = abi.decode(
vm.parseJson(content, searchStr(currTransactionIdx, "contractAddress")),
(address)
);
bytes memory deployedBytecode = abi.decode(
vm.parseJson(content, searchStr(currTransactionIdx, "transaction.data")),
(bytes)
);
bytes memory compiledBytecode = abi.decode(
vm.parseJson(_getCompiledBytecode(contractName), ".bytecode.object"),
(bytes)
);
bytes memory constructorArgs = BytesLib.slice(
deployedBytecode,
compiledBytecode.length,
deployedBytecode.length - compiledBytecode.length
);
function _verifyContract(string memory content) internal {
string memory contractName =
abi.decode(vm.parseJson(content, searchStr(currTransactionIdx, "contractName")), (string));
address contractAddr =
abi.decode(vm.parseJson(content, searchStr(currTransactionIdx, "contractAddress")), (address));
bytes memory deployedBytecode =
abi.decode(vm.parseJson(content, searchStr(currTransactionIdx, "transaction.data")), (bytes));
bytes memory compiledBytecode =
abi.decode(vm.parseJson(_getCompiledBytecode(contractName), ".bytecode.object"), (bytes));
bytes memory constructorArgs =
BytesLib.slice(deployedBytecode, compiledBytecode.length, deployedBytecode.length - compiledBytecode.length);

string[] memory inputs = new string[](9);
inputs[0] = "forge";
inputs[1] = "verify-contract";
inputs[2] = vm.toString(contractAddr);
inputs[3] = contractName;
inputs[4] = "--chain";
inputs[5] = vm.toString(block.chainid);
inputs[6] = "--constructor-args";
inputs[7] = vm.toString(constructorArgs);
inputs[8] = "--watch";
string[] memory inputs = new string[](9);
inputs[0] = "forge";
inputs[1] = "verify-contract";
inputs[2] = vm.toString(contractAddr);
inputs[3] = contractName;
inputs[4] = "--chain";
inputs[5] = vm.toString(block.chainid);
inputs[6] = "--constructor-args";
inputs[7] = vm.toString(constructorArgs);
inputs[8] = "--watch";

FfiResult memory f = tempVm(address(vm)).tryFfi(inputs);
FfiResult memory f = tempVm(address(vm)).tryFfi(inputs);

if (f.stderr.length != 0) {
console.logString(
string.concat(
"Submitting verification for contract: ", vm.toString(contractAddr)
)
);
console.logString(string(f.stderr));
} else {
console.logString(string(f.stdout));
if (f.stderr.length != 0) {
console.logString(string.concat("Submitting verification for contract: ", vm.toString(contractAddr)));
console.logString(string(f.stderr));
} else {
console.logString(string(f.stdout));
}
return;
}
return;
}

function nextTransaction(
string memory content
) external view returns (bool) {
try this.getTransactionFromRaw(content, currTransactionIdx) {
return true;
} catch {
return false;
function nextTransaction(string memory content) external view returns (bool) {
try this.getTransactionFromRaw(content, currTransactionIdx) {
return true;
} catch {
return false;
}
}
}

function _getCompiledBytecode(
string memory contractName
) internal view returns (string memory compiledBytecode) {
string memory root = vm.projectRoot();
string memory path =
string.concat(root, "/out/", contractName, ".sol/", contractName, ".json");
compiledBytecode = vm.readFile(path);
}
function _getCompiledBytecode(string memory contractName) internal view returns (string memory compiledBytecode) {
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/out/", contractName, ".sol/", contractName, ".json");
compiledBytecode = vm.readFile(path);
}

function getTransactionFromRaw(
string memory content,
uint96 idx
) external pure {
abi.decode(vm.parseJson(content, searchStr(idx, "hash")), (bytes32));
}
function getTransactionFromRaw(string memory content, uint96 idx) external pure {
abi.decode(vm.parseJson(content, searchStr(idx, "hash")), (bytes32));
}

function searchStr(
uint96 idx,
string memory searchKey
) internal pure returns (string memory) {
return string.concat(".transactions[", vm.toString(idx), "].", searchKey);
}
function searchStr(uint96 idx, string memory searchKey) internal pure returns (string memory) {
return string.concat(".transactions[", vm.toString(idx), "].", searchKey);
}
}
28 changes: 13 additions & 15 deletions packages/nextjs/app/api/transactions/route.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import { NextResponse } from "next/server";
import { TransactionType } from "~~/types/transaction";

let nextId = 0;
let transactions: TransactionType[] = [];

export async function GET(request: Request) {
return Response.json(transactions)
export async function GET() {
return NextResponse.json(transactions);
}

export async function POST(request: Request) {
const body = await request.json();
const newTx = body as TransactionType;
newTx.id = nextId;
transactions.push(newTx)
nextId++;
return Response.json(newTx);
const body = await request.json();
const newTx = body as TransactionType;
newTx.id = nextId;
transactions.push(newTx);
nextId++;
return NextResponse.json(newTx);
}

export async function PUT(request: Request) {
const body = await request.json();
const updatedTransaction = body as TransactionType;
transactions = transactions.map(tx => (tx.id === updatedTransaction.id ? { ...tx, ...updatedTransaction } : tx));

const body = await request.json();
const updatedTransaction = body as TransactionType;
transactions = transactions.map(tx =>
tx.id === updatedTransaction.id ? { ...tx, ...updatedTransaction } : tx
);

return Response.json(updatedTransaction)
return NextResponse.json(updatedTransaction);
}
27 changes: 14 additions & 13 deletions packages/nextjs/app/transactions/_components/Banner.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
export const Banner = () => {
return (
<>
<div className="text-center mt-8 bg-secondary p-6">
<h1 className="text-4xl my-0">Transactions</h1>
<p className="text-neutral">
Select a type of transaction to create and wait for other signers to validate it.
<br />Then it will be executed automatically
</p>
</div>
</>
)
}
return (
<>
<div className="text-center mt-8 bg-secondary p-6">
<h1 className="text-4xl my-0">Transactions</h1>
<p className="text-neutral">
Select a type of transaction to create and wait for other signers to validate it.
<br />
Then it will be executed automatically
</p>
</div>
</>
);
};

export default Banner;
export default Banner;
Loading

0 comments on commit 808a87e

Please sign in to comment.