Skip to content

Commit

Permalink
update templates for deploy/update (#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezynda3 authored Feb 27, 2024
1 parent 2707eb2 commit 6a19258
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 58 deletions.
2 changes: 1 addition & 1 deletion plopfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
35 changes: 10 additions & 25 deletions templates/facetDeployScript.template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
60 changes: 28 additions & 32 deletions templates/facetUpdateScript.template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 6a19258

Please sign in to comment.