Skip to content

Instantly share code, notes, and snippets.

@Timidan
Last active March 19, 2022 05:55
Show Gist options
  • Save Timidan/91dcc6d3c6829e785d3790bcef2dedc7 to your computer and use it in GitHub Desktop.
Save Timidan/91dcc6d3c6829e785d3790bcef2dedc7 to your computer and use it in GitHub Desktop.
// deploy DiamondCutFacet
const DiamondCut = cfx.Contract(getArtifacts("DiamondCutFacet"));
const txReceipt = await DiamondCut.constructor()
.sendTransaction({ from: acct })
.executed();
// deploy Diamond
const Diamond = cfx.Contract(getArtifacts("Diamond"));
const txReceipt2 = await Diamond.constructor(
acct.toString(),
txReceipt.contractCreated,
"DiamondToken",
"DMT"
)
.sendTransaction({ from: acct })
.executed();
DiamondAddress = txReceipt2.contractCreated;
//Deploy facets indiviually
const FacetNames = ["OwnershipFacet", "DiamondLoupeFacet", "DiamondToken"];
const cut = [];
for (const FacetName of FacetNames) {
const Facet = cfx.Contract(getArtifacts(FacetName));
const txReceipt = await Facet.constructor()
.sendTransaction({ from: acct })
.executed();
cut.push({
facetAddress: txReceipt.contractCreated,
action: FacetCutAction.Add,
functionSelectors: await getSelectors(FacetName),
});
}
// upgrade diamond with facets
const DiamondCutFacet = cfx.Contract({
abi: getAbi("DiamondCutFacet"),
address: DiamondAddress,
});
let tx;
//@ts-ignore
tx = await DiamondCutFacet.diamondCut(
cut,
ethers.constants.AddressZero,
"0x"
).sendTransaction({ from: acct });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment