Skip to content

Commit

Permalink
feat: add deployMock script
Browse files Browse the repository at this point in the history
  • Loading branch information
Doge-is-Dope committed Nov 15, 2024
1 parent a7f40a8 commit 5e67418
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 3 deletions.
54 changes: 54 additions & 0 deletions deployMock.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

# Error handling: check for required arguments
if [ -z "$1" ]; then
echo "Error: RPC URL is required."
echo "Usage: $0 <rpc-url> <verifier-url>"
exit 1
fi

if [ -z "$2" ]; then
echo "Error: Verifier URL is required."
echo "Usage: $0 <rpc-url> <verifier-url>"
exit 1
fi

# Assign arguments to variables
RPC_URL=$1
VERIFIER_URL=$2
IS_LEGACY=${3:-false}

# Display the configuration being used
echo "RPC URL: $RPC_URL"
echo "Verifier URL: $VERIFIER_URL"
echo "Is Legacy: $IS_LEGACY"

# Clear cache
rm -rf cache

COMMAND="forge script script/DeployMock.s.sol:DeployMock \
--broadcast \
--rpc-url \"$RPC_URL\" \
--verify \
--verifier blockscout \
--verifier-url \"$VERIFIER_URL/api/\""

# Add --legacy if IS_LEGACY is true
if [ "$IS_LEGACY" = "true" ]; then
COMMAND="$COMMAND --legacy"
fi

# Execute constructed command
eval $COMMAND


# Examples
# ./deployMock.sh base-sepolia https://base-sepolia.blockscout.com
# ./deployMock.sh world-sepolia https://worldchain-sepolia.explorer.alchemy.com
# ./deployMock.sh mantle-sepolia https://explorer.sepolia.mantle.xyz
# ./deployMock.sh polygonzkevm-cardona https://explorer-ui.cardona.zkevm-rpc.com true

# Hedera Testnet
# forge script script/DeployMock.s.sol:DeployMock \
# --broadcast \
# --rpc-url hedera-testnet
7 changes: 4 additions & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ libs = ["lib"]
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
[rpc_endpoints]
base-sepolia = "${RPC_BASE_SEPOLIA}"

[etherscan]
base-sepolia = { key = "${ETHERSCAN_API_KEY}" }
world-sepolia = "${RPC_WORLD_SEPOLIA}"
mantle-sepolia = "${RPC_MANTLE_SEPOLIA}"
polygonzkevm-cardona = "${RPC_POLYGONZKEVM_CARDONA}"
hedera-testnet = "${RPC_HEDERA_TESTNET}"
19 changes: 19 additions & 0 deletions script/BaseDeploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import "../lib/forge-std/src/Script.sol";
import {console} from "forge-std/console.sol";

contract BaseDeploy is Script {
uint256 internal immutable deployerPrivateKey = vm.envUint("PRIVATE_KEY");

modifier broadcast() {
vm.startBroadcast(deployerPrivateKey);
_;
vm.stopBroadcast();
}

function calculateSalt(string memory input) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(input)) & ~bytes32(uint256(0xfff));
}
}
26 changes: 26 additions & 0 deletions script/DeployMock.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import {Create2} from "../lib/openzeppelin-contracts/contracts/utils/Create2.sol";
import {console} from "../lib/forge-std/src/console.sol";
import {ERC20Mock} from "../src/mocks/ERC20Mock.sol";
import {BaseDeploy} from "./BaseDeploy.s.sol";

contract DeployMock is BaseDeploy {
function run() public {
// Calculate salt
bytes32 salt = calculateSalt("Drip.Erc20Mock");
// Deploy contracts on all supported chains
address deployed = _deployContract(salt);
console.log("ERC20Mock deployed to", deployed);
}

function _deployContract(bytes32 salt) internal broadcast returns (address) {
return Create2.deploy(0, salt, _getCreationBytecode());
}

function _getCreationBytecode() public pure returns (bytes memory) {
bytes memory bytecode = type(ERC20Mock).creationCode;
return abi.encodePacked(bytecode, abi.encode("Mock Token", "MTK"));
}
}

0 comments on commit 5e67418

Please sign in to comment.