Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ jobs:
# is why we use both in this way.
- name: Post coverage report
if: github.event_name == 'pull_request' # This action fails when ran outside of a pull request.
uses: romeovs/lcov-reporter-action@v0.3.1
uses: romeovs/lcov-reporter-action@v0.4.0
with:
delete-old-comments: true
lcov-file: ./lcov.info
github-token: ${{ secrets.GITHUB_TOKEN }} # Adds a coverage summary comment to the PR.

- name: Verify minimum coverage
uses: zgosalvez/github-actions-report-lcov@v2
uses: zgosalvez/github-actions-report-lcov@v3
with:
coverage-files: ./lcov.info
minimum-coverage: 95 # Set coverage threshold.
6 changes: 3 additions & 3 deletions example.env
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
GC_RPC=
POLYGON_RPC=
INFURA_KEY=
export PRIVATE_KEY=
ETHERSCAN_KEY=
GNOSISSCAN_KEY=
POLYGONSCAN_KEY=
OPTIMISM_KEY=
OPTIMISM_ETHERSCAN_KEY=
ARBISCAN_KEY=
FOUNDRY_PROFILE=
BASESCAN_KEY=
CELOSCAN_KEY=
24 changes: 14 additions & 10 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ optimizer_runs = 1_000_000
bytecode_hash = "none"
gas_reports = []
auto_detect_solc = false
solc = "0.8.19"
solc = "0.8.28"
evm_version = "cancun"
remappings = [
"ds-test/=lib/forge-std/lib/ds-test/src/",
"forge-std/=lib/forge-std/src/",
Expand Down Expand Up @@ -51,21 +52,24 @@ wrap_comments = true

[rpc_endpoints]
arbitrum = "https://arbitrum-mainnet.infura.io/v3/${INFURA_KEY}"
base = "https://base-mainnet.infura.io/v3/${INFURA_KEY}"
celo = "https://celo-mainnet.infura.io/v3/${INFURA_KEY}"
gnosis = "${GC_RPC}"
goerli = "https://goerli.infura.io/v3/${INFURA_KEY}"
local = "http://localhost:8545"
mainnet = "https://mainnet.infura.io/v3/${INFURA_KEY}"
optimism = "https://optimism-mainnet.infura.io/v3/${INFURA_KEY}"
polygon = "${POLYGON_RPC}"
polygon = "https://polygon-mainnet.infura.io/v3/${INFURA_KEY}"
sepolia = "https://sepolia.infura.io/v3/${INFURA_KEY}"

[etherscan]
arbitrum = { key = "${ARBISCAN_KEY}", url = "https://api.arbiscan.io/api" }
goerli = { key = "${ETHERSCAN_KEY}", url = "https://api-goerli.etherscan.io/api" }
gnosis = { key = "${GNOSISSCAN_KEY}", url = "https://api.gnosisscan.io/api" }
mainnet = { key = "${ETHERSCAN_KEY}", url = "https://api.etherscan.io/api" }
optimism = { key = "${OPTIMISM_KEY}", url = "https://api-optimistic.etherscan.io/api" }
sepolia = { key = "${ETHERSCAN_KEY}", url = "https://api-sepolia.etherscan.io/api" }
polygon = { key = "${POLYGONSCAN_KEY}", url = "https://api.polygonscan.com/api" }
arbitrum = {key = "${ARBISCAN_KEY}", url = "https://api.arbiscan.io/api"}
base = {key = "${BASESCAN_KEY}", url = "https://api.basescan.org/api"}
celo = {key = "${CELOSCAN_KEY}", url = "https://api.celoscan.org/api"}
goerli = {key = "${ETHERSCAN_KEY}", url = "https://api-goerli.etherscan.io/api"}
mainnet = {key = "${ETHERSCAN_KEY}", url = "https://api.etherscan.io/api"}
optimism = {key = "${OPTIMISM_ETHERSCAN_KEY}", url = "https://api-optimistic.etherscan.io/api"}
polygon = {key = "${POLYGONSCAN_KEY}", url = "https://api.polygonscan.com/api"}
gnosis = {key = "${GNOSISSCAN_KEY}", url = "https://api.gnosisscan.io/api"}
sepolia = {key = "${ETHERSCAN_KEY}", url = "https://api-sepolia.etherscan.io/api"}

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
26 changes: 16 additions & 10 deletions script/Counter.s.sol → script/Contract.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.18;

import { Script, console2 } from "forge-std/Script.sol";
import { Counter } from "../src/Counter.sol";
import { Contract } from "../src/Contract.sol";

interface ImmutableCreate2Factory {
function create2(bytes32 salt, bytes calldata initializationCode)
Expand All @@ -12,32 +12,34 @@ interface ImmutableCreate2Factory {
}

contract Deploy is Script {
Counter public counter;
Contract public cntrct;
bytes32 public SALT = bytes32(abi.encode("lets add some salt to these eggs"));

// default values
bool internal _verbose = true;
// init other variables

/// @dev Override default values, if desired
function prepare(bool verbose) public {
_verbose = verbose;
// set other variables
}

/// @dev Set up the deployer via their private key from the environment
function deployer() public returns (address) {
function _deployer() internal returns (address) {
uint256 privKey = vm.envUint("PRIVATE_KEY");
return vm.rememberKey(privKey);
}

function _log(string memory prefix) internal view {
if (_verbose) {
console2.log(string.concat(prefix, "Counter:"), address(counter));
console2.log(string.concat(prefix, "Contract:"), address(cntrct));
}
}

/// @dev Deploy the contract to a deterministic address via forge's create2 deployer factory.
function run() public virtual {
vm.startBroadcast(deployer());
function run() public virtual returns (Contract) {
vm.startBroadcast(_deployer());

/**
* @dev Deploy the contract to a deterministic address via forge's create2 deployer factory, which is at this
Expand All @@ -47,29 +49,33 @@ contract Deploy is Script {
* never differs regardless of where its being compiled
* 2. The provided salt, `SALT`
*/
counter = new Counter{ salt: SALT}(/* insert constructor args here */);
cntrct = new Contract{ salt: SALT }( /* insert constructor args here */ );

vm.stopBroadcast();

_log("");

return cntrct;
}
}

/// @dev Deploy pre-compiled ir-optimized bytecode to a non-deterministic address
contract DeployPrecompiled is Deploy {
/// @dev Update SALT and default values in Deploy contract

function run() public override {
vm.startBroadcast(deployer());
function run() public override returns (Contract) {
vm.startBroadcast(_deployer());

bytes memory args = abi.encode( /* insert constructor args here */ );

/// @dev Load and deploy pre-compiled ir-optimized bytecode.
counter = Counter(deployCode("optimized-out/Counter.sol/Counter.json", args));
cntrct = Contract(deployCode("optimized-out/Contract.sol/Contract.json", args));

vm.stopBroadcast();

_log("Precompiled ");

return cntrct;
}
}

Expand Down
13 changes: 4 additions & 9 deletions src/Counter.sol → src/Contract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.18;

// import { console2 } from "forge-std/Test.sol"; // remove before deploy

contract Counter {
contract Contract {
/*//////////////////////////////////////////////////////////////
CUSTOM ERRORS
//////////////////////////////////////////////////////////////*/
Expand All @@ -17,13 +17,12 @@ contract Counter {
//////////////////////////////////////////////////////////////*/

/*//////////////////////////////////////////////////////////////
CONSANTS
CONSTANTS
//////////////////////////////////////////////////////////////*/

/*//////////////////////////////////////////////////////////////
MUTABLE STATE
//////////////////////////////////////////////////////////////*/
uint256 public number;

/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
Expand All @@ -33,11 +32,7 @@ contract Counter {
PUBLIC FUNCTIONS
//////////////////////////////////////////////////////////////*/

function setNumber(uint256 newNumber) public {
number = newNumber;
}

function increment() public {
number++;
function doSomething() public pure returns (uint256) {
return 1;
}
}
37 changes: 37 additions & 0 deletions test/Contract.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.18;

import { Test, console2 } from "forge-std/Test.sol";
import { Contract } from "../src/Contract.sol";
import { Deploy, DeployPrecompiled } from "../script/Contract.s.sol";

contract ContractTest is Test {
/// @dev Inherit from DeployPrecompiled instead of Deploy if working with pre-compiled contracts

Contract public cntrct;
uint256 public constant TEST_SALT_NONCE = 1;
bytes32 public constant TEST_SALT = bytes32(abi.encode(TEST_SALT_NONCE));

uint256 public fork;
uint256 public BLOCK_NUMBER;

function _deploy() internal returns (Contract) {
Deploy deployer = new Deploy();
deployer.prepare(false);
return deployer.run();
}

function setUp() public virtual {
// OPTIONAL: create and activate a fork, at BLOCK_NUMBER
// fork = vm.createSelectFork(vm.rpcUrl("mainnet"), BLOCK_NUMBER);

// deploy the contract
cntrct = _deploy();
}
}

contract UnitTests is ContractTest {
function test_doSomething() public view {
cntrct.doSomething();
}
}
32 changes: 0 additions & 32 deletions test/Counter.t.sol

This file was deleted.

Loading