Skip to content

Commit

Permalink
feat(evm): split deployer and allow async contract verification
Browse files Browse the repository at this point in the history
  • Loading branch information
hussein-aitlahcen committed Dec 17, 2024
1 parent ee2633c commit 16e2861
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 23 deletions.
103 changes: 99 additions & 4 deletions evm/evm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ _: {
yul = true
[profile.default]
fs_permissions = [{ access = "read", path = "./"}]
fs_permissions = [{ access = "read", path = "./" }, { access = "write", path = "contracts.json" }]
libs = ["libs"]
gas_reports = ["*"]
via_ir = true
Expand Down Expand Up @@ -175,6 +175,17 @@ _: {
--set FOUNDRY_CONFIG "${foundryConfig}/foundry.toml"
'';
};
wrappedForgeOnline = pkgs.symlinkJoin {
name = "forge";
paths = [ pkgs.foundry-bin ];
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/forge \
--set HOME ${compilers} \
--set SSL_CERT_FILE "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" \
--set FOUNDRY_CONFIG "${foundryConfig}/foundry.toml"
'';
};
networks = [
{
network = "devnet";
Expand Down Expand Up @@ -204,7 +215,7 @@ _: {
network = "holesky";
rpc-url = "https://holesky.drpc.org";
private-key = ''"$1"'';
extra-args = ''--verify --verifier sourcify --verifier-url https://sourcify.dev/server'';
extra-args = ''--verify --verifier etherscan --etherscan-api-key "$2"'';
}
{
network = "scroll-testnet";
Expand All @@ -224,6 +235,38 @@ _: {
}
];

eth-deploy =
{
rpc-url,
private-key,
extra-args ? "",
...
}:
mkCi false (
pkgs.writeShellApplication {
name = "eth-deploy-full";
runtimeInputs = [ self'.packages.forge ];
text = ''
${ensureAtRepositoryRoot}
OUT="$(mktemp -d)"
pushd "$OUT"
cp --no-preserve=mode -r ${self'.packages.evm-contracts}/* .
cp --no-preserve=mode -r ${evmSources}/* .
PRIVATE_KEY=${private-key} \
DEPLOYER="$3" \
FOUNDRY_PROFILE="script" \
forge script scripts/Deploy.s.sol:DeployIBC \
-vvvv \
--rpc-url ${rpc-url} \
--broadcast ${extra-args}
popd
rm -rf "$OUT"
'';
}
);

eth-deploy-full =
{
rpc-url,
Expand Down Expand Up @@ -255,6 +298,41 @@ _: {
}
);

eth-verify =
{
rpc-url,
private-key,
extra-args ? "",
...
}:
mkCi false (
pkgs.writeShellApplication {
name = "eth-verify";
runtimeInputs = [ wrappedForgeOnline ];
text = ''
${ensureAtRepositoryRoot}
nix run .#evm-contracts-addresses -- "$1" "$2" ${rpc-url}
PROJECT_ROOT=$(pwd)
OUT="$(mktemp -d)"
pushd "$OUT"
cp --no-preserve=mode -r ${self'.packages.evm-contracts}/* .
cp --no-preserve=mode -r ${evmSources}/* .
jq -r 'to_entries | map([.key, .value]) | .[] | @tsv' "$PROJECT_ROOT"/contracts.json | \
while IFS=$'\t' read -r contract address; do
PRIVATE_KEY=${private-key} \
FOUNDRY_PROFILE="script" \
forge verify-contract --force --watch "$address" "$contract" --api-key "$3" \
--rpc-url ${rpc-url}
done
popd
rm -rf "$OUT"
'';
}
);

eth-deploy-multicall =
{
rpc-url,
Expand Down Expand Up @@ -538,10 +616,15 @@ _: {
cp --no-preserve=mode -r ${self'.packages.evm-contracts}/* .
cp --no-preserve=mode -r ${evmSources}/* .
DEPLOYER="$1" SENDER="$2" FOUNDRY_PROFILE="script" forge script scripts/Deploy.s.sol:GetDeployed -vvv
DEPLOYER="$1" \
SENDER="$2" \
OUTPUT="contracts.json" \
FOUNDRY_PROFILE="script" \
forge script scripts/Deploy.s.sol:GetDeployed -vvvv --fork-url "$3"
rm -rf "$OUT"
popd
cp "$OUT"/contracts.json contracts.json
rm -rf "$OUT"
'';
}
);
Expand Down Expand Up @@ -582,12 +665,24 @@ _: {
}
);
}
// builtins.listToAttrs (
builtins.map (args: {
name = "eth-verify-${args.network}";
value = eth-verify args;
}) networks
)
// builtins.listToAttrs (
builtins.map (args: {
name = "eth-deploy-${args.network}-full";
value = eth-deploy-full args;
}) networks
)
// builtins.listToAttrs (
builtins.map (args: {
name = "eth-deploy-${args.network}";
value = eth-deploy args;
}) networks
)
// builtins.listToAttrs (
builtins.map (args: {
name = "eth-deploy-${args.network}-multicall";
Expand Down
55 changes: 36 additions & 19 deletions evm/scripts/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
pragma solidity ^0.8.27;

import "forge-std/Vm.sol";
import "forge-std/StdJson.sol";
import "forge-std/Script.sol";

import "solady/utils/CREATE3.sol";
import "solady/utils/LibString.sol";
import "@openzeppelin-foundry-upgradeable/Upgrades.sol";
import "@openzeppelin/proxy/ERC1967/ERC1967Proxy.sol";
import "@openzeppelin/proxy/ERC1967/ERC1967Utils.sol";
import "@openzeppelin/access/Ownable.sol";

import "../contracts/Multicall.sol";
Expand All @@ -17,24 +21,7 @@ import "../contracts/apps/ucs/01-relay/Relay.sol";
import "../contracts/apps/ucs/02-nft/NFT.sol";
import "../contracts/lib/Hex.sol";

import "solady/utils/CREATE3.sol";
import "solady/utils/LibString.sol";

contract Deployer {
using LibString for *;

function deploy(
string memory salt,
bytes calldata creationCode,
uint256 value
) public returns (address) {
return CREATE3.deployDeterministic(
value,
creationCode,
keccak256(abi.encodePacked(msg.sender.toHexString(), "/", salt))
);
}
}
import "./Deployer.sol";

library LIB {
string constant NAMESPACE = "lib";
Expand Down Expand Up @@ -314,6 +301,7 @@ contract DeployDeployerAndIBC is UnionScript {

contract GetDeployed is Script {
using LibString for *;
using stdJson for string;

address immutable deployer;
address immutable sender;
Expand All @@ -332,10 +320,15 @@ contract GetDeployed is Script {
);
}

function run() public view {
function implOf(address x) internal returns (address) {
return address(bytes20(vm.load(x, ERC1967Utils.IMPLEMENTATION_SLOT) << 96));
}

function run() public {
address handler = getDeployed(IBC.BASED);
address cometblsClient =
getDeployed(LightClients.make(LightClients.COMETBLS));
address ucs00 = getDeployed(Protocols.make(Protocols.UCS00));
address ucs01 = getDeployed(Protocols.make(Protocols.UCS01));
address ucs02 = getDeployed(Protocols.make(Protocols.UCS02));

Expand All @@ -349,8 +342,32 @@ contract GetDeployed is Script {
)
)
);
console.log(string(abi.encodePacked("UCS00: ", ucs00.toHexString())));
console.log(string(abi.encodePacked("UCS01: ", ucs01.toHexString())));
console.log(string(abi.encodePacked("UCS02: ", ucs02.toHexString())));

string memory json = "";
json.serialize(
"contracts/core/OwnableIBCHandler.sol:OwnableIBCHandler",
implOf(handler)
);
json.serialize(
"contracts/clients/CometblsClient.sol:CometblsClient",
implOf(cometblsClient)
);
json.serialize(
"contracts/apps/ucs/00-pingpong/PingPong.sol:PingPong",
implOf(ucs00)
);
json.serialize(
"contracts/apps/ucs/01-relay/Relay.sol:UCS01Relay",
implOf(ucs01)
);
json = json.serialize(
"contracts/apps/ucs/02-nft/NFT.sol:UCS02NFT",
implOf(ucs02)
);
json.write(vm.envString("OUTPUT"));
}
}

Expand Down
20 changes: 20 additions & 0 deletions evm/scripts/Deployer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
pragma solidity ^0.8.27;

import "solady/utils/CREATE3.sol";
import "solady/utils/LibString.sol";

contract Deployer {
using LibString for *;

function deploy(
string memory salt,
bytes calldata creationCode,
uint256 value
) public returns (address) {
return CREATE3.deployDeterministic(
value,
creationCode,
keccak256(abi.encodePacked(msg.sender.toHexString(), "/", salt))
);
}
}

0 comments on commit 16e2861

Please sign in to comment.