From 2540dc592e026b1363209c6ecf48bec9709b9045 Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Mon, 3 Jun 2024 16:08:22 +0530 Subject: [PATCH 1/3] templatise foundry deploy script --- ...Deploy.s.sol => Deploy.s.sol.template.mjs} | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) rename templates/extensions/foundry/packages/foundry/script/{Deploy.s.sol => Deploy.s.sol.template.mjs} (57%) diff --git a/templates/extensions/foundry/packages/foundry/script/Deploy.s.sol b/templates/extensions/foundry/packages/foundry/script/Deploy.s.sol.template.mjs similarity index 57% rename from templates/extensions/foundry/packages/foundry/script/Deploy.s.sol rename to templates/extensions/foundry/packages/foundry/script/Deploy.s.sol.template.mjs index 15b0b1097..046a73aeb 100644 --- a/templates/extensions/foundry/packages/foundry/script/Deploy.s.sol +++ b/templates/extensions/foundry/packages/foundry/script/Deploy.s.sol.template.mjs @@ -1,8 +1,11 @@ -//SPDX-License-Identifier: MIT +import { withDefaults } from "../../../../../utils.js"; + +const content = ({ deploymentsScriptsImports, deploymentsLogic }) => `//SPDX-License-Identifier: MIT pragma solidity ^0.8.19; import "../contracts/YourContract.sol"; import "./DeployHelpers.s.sol"; +${deploymentsScriptsImports.filter(Boolean).join("\n")} contract DeployScript is ScaffoldETHDeploy { error InvalidPrivateKey(string); @@ -11,17 +14,23 @@ contract DeployScript is ScaffoldETHDeploy { uint256 deployerPrivateKey = setupLocalhostEnv(); if (deployerPrivateKey == 0) { revert InvalidPrivateKey( - "You don't have a deployer account. Make sure you have set DEPLOYER_PRIVATE_KEY in .env or use `yarn generate` to generate a new random account" + "You don't have a deployer account. Make sure you have set DEPLOYER_PRIVATE_KEY in .env or use \`yarn generate\` to generate a new random account" ); } vm.startBroadcast(deployerPrivateKey); - YourContract yourContract = - new YourContract(vm.addr(deployerPrivateKey)); + + YourContract yourContract = new YourContract( + vm.addr(deployerPrivateKey) + ); console.logString( string.concat( - "YourContract deployed at: ", vm.toString(address(yourContract)) + "YourContract deployed at: ", + vm.toString(address(yourContract)) ) ); + + ${deploymentsLogic.filter(Boolean).join("\n")} + vm.stopBroadcast(); /** @@ -33,4 +42,9 @@ contract DeployScript is ScaffoldETHDeploy { } function test() public {} -} +}`; + +export default withDefaults(content, { + deploymentsScriptsImports: "", + deploymentsLogic: "", +}); From 0c109be9ad2895222a09602487b08f540c627d5c Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Tue, 4 Jun 2024 09:48:50 +0530 Subject: [PATCH 2/3] move deployment logic below stop bradcast --- .../foundry/packages/foundry/script/Deploy.s.sol.template.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/extensions/foundry/packages/foundry/script/Deploy.s.sol.template.mjs b/templates/extensions/foundry/packages/foundry/script/Deploy.s.sol.template.mjs index 046a73aeb..9089bdad8 100644 --- a/templates/extensions/foundry/packages/foundry/script/Deploy.s.sol.template.mjs +++ b/templates/extensions/foundry/packages/foundry/script/Deploy.s.sol.template.mjs @@ -29,10 +29,10 @@ contract DeployScript is ScaffoldETHDeploy { ) ); - ${deploymentsLogic.filter(Boolean).join("\n")} - vm.stopBroadcast(); + ${deploymentsLogic.filter(Boolean).join("\n")} + /** * This function generates the file containing the contracts Abi definitions. * These definitions are used to derive the types needed in the custom scaffold-eth hooks, for example. From 8e2f18d224030dd65436aef0f5f44936b23429b5 Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Tue, 4 Jun 2024 10:12:31 +0530 Subject: [PATCH 3/3] add 31337 deployemnts on initialy scaffolding --- .../extensions/foundry/packages/foundry/deployments/31337.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 templates/extensions/foundry/packages/foundry/deployments/31337.json diff --git a/templates/extensions/foundry/packages/foundry/deployments/31337.json b/templates/extensions/foundry/packages/foundry/deployments/31337.json new file mode 100644 index 000000000..abb56dd84 --- /dev/null +++ b/templates/extensions/foundry/packages/foundry/deployments/31337.json @@ -0,0 +1,3 @@ +{ + "networkName": "Anvil" +}