Skip to content

Commit

Permalink
add option to save diamond cut in upgradeWithDeployedFacets
Browse files Browse the repository at this point in the history
  • Loading branch information
nickkatsios committed Oct 2, 2024
1 parent 6aec91b commit 571df39
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions protocol/reseed/reseed10.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ async function reseed10(account, L2Beanstalk, mock, verbose = true) {
facetAddresses: facetAddresses,
verbose: true,
account: account,
object: true, // true to save diamond cut json, false to upgrade diamond
checkGas: true
});
});
Expand Down
25 changes: 24 additions & 1 deletion protocol/scripts/diamond.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,11 @@ async function upgradeWithDeployedFacets({
facetAddresses = [],
selectorsToRemove = [],
selectorsToAdd = {},
initFacetName = undefined,
initFacetAddress = ethers.constants.AddressZero,
initArgs = [],
account = null,
object = false,
verbose = false,
}) {
let totalGasUsed = ethers.BigNumber.from("0");
Expand All @@ -494,7 +496,7 @@ async function upgradeWithDeployedFacets({
const diamondCut = [];
const existingFacets = await diamondLoupeFacet.facets();

if (verbose && facetAddresses.length > 0) console.log("\nProcessing Facets");
if (verbose && facetAddresses.length > 0) console.log("\nProcessing Facets...");

if (selectorsToRemove.length > 0) {
// check if any selectorsToRemove are already gone
Expand Down Expand Up @@ -545,6 +547,27 @@ async function upgradeWithDeployedFacets({
if (verbose) console.log(`Function call: ${functionCall.toString().substring(0, 100)}`);
}

if (object) {
dc = {
diamondCut: diamondCut,
initFacetAddress: initFacetAddress,
functionCall: functionCall
};
const encodedDiamondCut = await diamondCutFacet.interface.encodeFunctionData(
"diamondCut",
Object.values(dc)
);
console.log(JSON.stringify(dc, null, 4));
console.log("Encoded: -------------------------------------------------------------");
console.log(encodedDiamondCut);
const dcName = `diamondCut-${initFacetName}-${Math.floor(Date.now() / 1000)}-${facetNames.length}-facets.json`;
await fs.writeFileSync(
`./diamondCuts/${dcName}`,
JSON.stringify({ diamondCut: dc, encoded: encodedDiamondCut }, null, 4)
);
return dc;
}

let result = await diamondCutFacet
.connect(account)
.diamondCut(diamondCut, initFacetAddress, functionCall);
Expand Down

0 comments on commit 571df39

Please sign in to comment.