diff --git a/deployMock.sh b/deployMock.sh new file mode 100755 index 0000000..b33a05f --- /dev/null +++ b/deployMock.sh @@ -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 " + exit 1 +fi + +if [ -z "$2" ]; then + echo "Error: Verifier URL is required." + echo "Usage: $0 " + 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 \ No newline at end of file diff --git a/foundry.toml b/foundry.toml index f1352f0..febba2b 100644 --- a/foundry.toml +++ b/foundry.toml @@ -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}" } \ No newline at end of file +world-sepolia = "${RPC_WORLD_SEPOLIA}" +mantle-sepolia = "${RPC_MANTLE_SEPOLIA}" +polygonzkevm-cardona = "${RPC_POLYGONZKEVM_CARDONA}" +hedera-testnet = "${RPC_HEDERA_TESTNET}" \ No newline at end of file diff --git a/script/BaseDeploy.s.sol b/script/BaseDeploy.s.sol new file mode 100644 index 0000000..1747991 --- /dev/null +++ b/script/BaseDeploy.s.sol @@ -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)); + } +} diff --git a/script/DeployMock.s.sol b/script/DeployMock.s.sol new file mode 100644 index 0000000..f6cbe68 --- /dev/null +++ b/script/DeployMock.s.sol @@ -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")); + } +}