From 6a19258f6baae2d12d5ae2d61563014062413fc2 Mon Sep 17 00:00:00 2001 From: Ed Zynda Date: Tue, 27 Feb 2024 16:41:25 +0300 Subject: [PATCH] update templates for deploy/update (#601) --- plopfile.mjs | 2 +- templates/facetDeployScript.template.hbs | 35 ++++---------- templates/facetUpdateScript.template.hbs | 60 +++++++++++------------- 3 files changed, 39 insertions(+), 58 deletions(-) diff --git a/plopfile.mjs b/plopfile.mjs index cddf15380..96a447838 100644 --- a/plopfile.mjs +++ b/plopfile.mjs @@ -8,7 +8,7 @@ export default function ( { type: 'input', name: 'name', - message: 'Give this facet a name:', + message: 'Give this facet a name: e.g Acme will create AcmeFacet', }, { type: 'input', diff --git a/templates/facetDeployScript.template.hbs b/templates/facetDeployScript.template.hbs index 5a0286ccc..6e130576a 100644 --- a/templates/facetDeployScript.template.hbs +++ b/templates/facetDeployScript.template.hbs @@ -14,35 +14,20 @@ contract DeployScript is DeployScriptBase { public returns ({{titleCase name}}Facet deployed, bytes memory constructorArgs) { - string memory path = string.concat( - vm.projectRoot(), - "/config/{{camelCase name}}.json" - ); - string memory json = vm.readFile(path); - address example = json.readAddress( - string.concat(".", network, ".example") - ); + constructorArgs = getConstructorArgs(); - constructorArgs = abi.encode(example); - - vm.startBroadcast(deployerPrivateKey); + deployed = {{titleCase name}}Facet(deploy(type({{titleCase name}}Facet).creationCode)); + } - if (isDeployed()) { - return ({{titleCase name}}Facet(payable(predicted)), constructorArgs); - } + function getConstructorArgs() internal override returns (bytes memory) { + // If you don't have a constructor or it doesn't take any arguments, you can remove this function + string memory path = string.concat(root, "/config/{{camelCase name}}.json"); + string memory json = vm.readFile(path); - deployed = {{titleCase name}}Facet( - payable( - factory.deploy( - salt, - bytes.concat( - type({{titleCase name}}Facet).creationCode, - constructorArgs - ) - ) - ) + address acrossSpokePool = json.readAddress( + string.concat(".", network, ".example") ); - vm.stopBroadcast(); + return abi.encode(example); } } diff --git a/templates/facetUpdateScript.template.hbs b/templates/facetUpdateScript.template.hbs index 109cda582..9f3c7a3cc 100644 --- a/templates/facetUpdateScript.template.hbs +++ b/templates/facetUpdateScript.template.hbs @@ -9,50 +9,46 @@ import { {{titleCase name}}Facet } from "lifi/Facets/{{titleCase name}}Facet.sol contract DeployScript is UpdateScriptBase { using stdJson for string; + struct Config { + uint256 a; + bool b; + address c; + } + function run() public returns (address[] memory facets, bytes memory cutData) { - address facet = json.readAddress(".{{titleCase name}}Facet"); + return update("{{titleCase name}}Facet"); + } + + function getExcludes() internal pure override returns (bytes4[] memory) { + // Use this to exclude any selectors that might clash with other facets in the diamond + // or selectors you don't want accessible e.g. init() functions. + // You can remove this function if it's not needed. + bytes4[] memory excludes = new bytes4[](1); + excludes[0] = {{titleCase name}}Facet.init{{titleCase name}}.selector; + return excludes; + } + + function getCallData() internal override returns (bytes memory) { + // Use this to get initialization calldata that will be executed + // when adding the facet to a diamond. + // You can remove this function it it's not needed. path = string.concat(root, "/config/{{camelCase name}}.json"); json = vm.readFile(path); - - address[] memory exampleAllowedTokens = json.readAddressArray( - string.concat(".", network, ".exampleAllowedTokens") + bytes memory rawConfigs = json.parseRaw(".configs"); + Config[] memory cfg = abi.decode( + rawConfigs, + (Config[]) ); - /// You can remove this if you don't need to call init on the facet bytes memory callData = abi.encodeWithSelector( {{titleCase name}}Facet.init{{titleCase name}}.selector, - exampleAllowedTokens + cfg ); - // {{titleCase name}} - bytes4[] memory exclude; - buildDiamondCut(getSelectors("{{titleCase name}}Facet", exclude), facet); - if (noBroadcast) { - if (cut.length > 0) { - cutData = abi.encodeWithSelector( - DiamondCutFacet.diamondCut.selector, - cut, - address(facet), // address(0) if not calling init - callData // "" if not calling init - ); - } - return (facets, cutData); - } - - vm.startBroadcast(deployerPrivateKey); - if (cut.length > 0) { - cutter.diamondCut( - cut, - address(facet), // address(0) if not calling init - callData // "" if not calling init - ); - } - facets = loupe.facetAddresses(); - - vm.stopBroadcast(); + return callData; } }