Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foundry v2 #489

Merged
merged 27 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1b60ecc
feat : add error msg when invalid private key
jrcarlos2000 Aug 2, 2023
9cd4439
feat : simulate hardhat way --network on deploy
jrcarlos2000 Aug 2, 2023
02157e2
feat : find network name in foundry.toml
jrcarlos2000 Aug 2, 2023
9ad78cb
chor : change error msg in script
jrcarlos2000 Aug 3, 2023
b2c7c30
forge install: openzeppelin-contracts
jrcarlos2000 Aug 3, 2023
7030a2f
add remappings
jrcarlos2000 Aug 3, 2023
60d166e
merge conflict
jrcarlos2000 Aug 7, 2023
720fcca
chor
jrcarlos2000 Aug 7, 2023
e19e9ce
merge conflict
jrcarlos2000 Aug 7, 2023
4eda578
update OZ gh URL to use capitalize O
technophile-04 Aug 8, 2023
f8906fa
update readme
technophile-04 Aug 8, 2023
d3a177d
update OZ gitmodule name to match org name
technophile-04 Aug 8, 2023
02bec3f
Merge remote-tracking branch 'upstream/foundry' into foundry-v2
jrcarlos2000 Aug 14, 2023
6976135
fix : error handling
jrcarlos2000 Aug 14, 2023
1da511d
Merge branch 'foundry-v2' of github.com:jrcarlos2000/scaffold into fo…
jrcarlos2000 Aug 14, 2023
7f2b037
feat : use watch to get the final result
jrcarlos2000 Aug 14, 2023
582214a
fix : reduce complexity
jrcarlos2000 Aug 14, 2023
4227258
feat : verify after deployment done
jrcarlos2000 Aug 14, 2023
fdde500
fix typo
jrcarlos2000 Aug 14, 2023
8be4f54
fix : delete hardcoded value
jrcarlos2000 Aug 15, 2023
ef7ba9d
fix : add ffi call
jrcarlos2000 Aug 15, 2023
db74242
feat : better logging'
jrcarlos2000 Aug 15, 2023
6755263
enh : try diff constructors
jrcarlos2000 Aug 15, 2023
fabcfc0
feat : support for all types of constrcutors
jrcarlos2000 Aug 15, 2023
4cf3b51
feat : cleaner loggin using tryffi
jrcarlos2000 Aug 20, 2023
cebd002
handle warning
jrcarlos2000 Aug 27, 2023
0333a57
add logging for contract address
jrcarlos2000 Aug 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
[submodule "packages/foundry/lib/openzeppelin-contracts"]
path = packages/foundry/lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "packages/foundry/lib/solidity-bytes-utils"]
path = packages/foundry/lib/solidity-bytes-utils
url = https://github.com/gnsps/solidity-bytes-utils
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"scripts": {
"account": "yarn workspace @se-2/foundry account",
"fork": "yarn workspace @se-2/foundry fork",
"verify": "yarn workspace @se-2/hardhat verify",
"verify": "yarn workspace @se-2/foundry verify",
"compile": "yarn workspace @se-2/foundry compile",
"chain": "yarn workspace @se-2/foundry chain",
"deploy": "yarn workspace @se-2/foundry deploy",
Expand Down
1 change: 1 addition & 0 deletions packages/foundry/lib/solidity-bytes-utils
Submodule solidity-bytes-utils added at 6458fb
3 changes: 2 additions & 1 deletion packages/foundry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"compile": "forge compile",
"generate": "node script/generateAccount.js",
"deploy": "forge build --build-info --build-info-path out/build-info/ && forge script script/Deploy.s.sol --rpc-url ${1:-default_network} --broadcast --legacy && node script/generateTsAbis.js",
"deploy:verify": "forge build --build-info --build-info-path out/build-info/ && forge script script/Deploy.s.sol --rpc-url ${1:-default_network} --broadcast --legacy --verify && node script/generateTsAbis.js",
"deploy:verify": "forge build --build-info --build-info-path out/build-info/ && forge script script/Deploy.s.sol --rpc-url ${1:-default_network} --broadcast --legacy --verify ; node script/generateTsAbis.js",
"verify": "forge build --build-info --build-info-path out/build-info/ && forge script script/VerifyAll.s.sol --ffi --rpc-url ${1:-default_network}",
"lint": "forge fmt",
"test": "forge test"
},
Expand Down
157 changes: 157 additions & 0 deletions packages/foundry/script/VerifyAll.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "forge-std/Script.sol";
import "forge-std/Vm.sol";
import "solidity-bytes-utils/BytesLib.sol";

/**
* @dev Temp Vm implementation
* @notice calls the tryffi function on the Vm contract
* @notice will be deleted once the forge/std is updated
*/

struct FfiResult {
int32 exit_code;
bytes stdout;
bytes stderr;
}

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

contract VerifyAll is Script {
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);

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 _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";

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));
}
return;
}

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 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);
}
}