-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guide to using Ignition to deploy Diamonds (ERC-2535) #775
Comments
Right now I'm trying this approach: import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import { toFunctionSelector, zeroAddress } from "viem";
const FacetCutAction = {
Add: 0,
Replace: 1,
Remove: 2,
};
export default buildModule("DiamondModule", (m) => {
// Diamond Future
const diamond = m.contract("Diamond");
// Facet Futures
const tokenAdminFacet = m.contract("TokenAdminFacet");
const erc20Facet= m.contract("Erc20Facet");
// Add facets to the diamond
// TODO: take selectors from ABIs
const tokenAdminFacetSelectors = [
toFunctionSelector("function setMetadata(string calldata name, string calldata symbol)"),
toFunctionSelector("function mint(address to, uint256 amount)"),
];
const erc20FacetSelectors = [
toFunctionSelector("function totalSupply()"),
toFunctionSelector("function balanceOf(address account)"),
toFunctionSelector("function allowance(address holder, address spender)"),
toFunctionSelector("function approve(address spender, uint256 amount)"),
toFunctionSelector("function transfer(address recipient, uint256 amount)"),
toFunctionSelector("function transferFrom(address holder, address recipient, uint256 amount)"),
toFunctionSelector("function name()"),
toFunctionSelector("function symbol()"),
toFunctionSelector("function decimals()"),
];
const facetCutActions = [
{
action: FacetCutAction.Add,
target: tokenFacetSelectors,
selectors: tokenAdminFacetSelectors ,
},
{
action: FacetCutAction.Add,
target: erc20Facet,
selectors: erc20FacetSelectors,
},
];
m.call(diamond, "diamondCut", [facetCutActions, zeroAddress, "0x"]);
//TODO: return diamond combined with facets
return { diamond };
}); In the test i have: const { diamond } = await hre.ignition.deploy(DiamondModule);
diamond.write.setMetadata("My Token", "MTKN"); And here i have an error, that |
I don't have experience with diamond deployments, but reading over the code, you have a deployment that sets the facets for the Are you able to use viem to make an arbitrary call to the facet function on the deployed contract? Maybe using something like writeContract? |
Yes, i can do it in test like this: const tokenAdminFacetArtifact = await hre.artifacts.readArtifact("TokenAdminFacet");
const erc20FacetArtifact = await hre.artifacts.readArtifact("Erc20Facet");
const tokenAdminFacet= getContract({
address: diamond.address,
abi: tokenAdminFacetArtifact.abi,
client: deployer
});
await tokenAdminFacet.write.setMetadata(["My Token", "MTKN"]); This works. But i see it as a workaraund, not a perfect solution. |
First discussed on discord: https://discord.com/channels/750408878008827925/1153426756901032037/1247471045921734759
We should provide an example guide for deploying upgrade-able contracts based on the Diamond pattern ERC-2535.
The text was updated successfully, but these errors were encountered: