-
Notifications
You must be signed in to change notification settings - Fork 12
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
Create ERC20 token out of facet #9
Comments
Hey @Walodja1987, thanks for making an issue about this. Let's get to the bottom of it. It should work fine in a facet. delegatecall is okay for this. Where is the source code for the ERC20 contract? What is the full error message and stack trace? Thanks |
Hi Nick (@mudgen), I really appreciate your help on this issue. I have spent many hours trying to solve it, but without success. You are my last hope :-) I have simplified the example, see below the three relevant code snippets. The error message is "Error: Returned error: VM Exception while processing transaction: revert". Many thanks again! OptionFacet.sol:
DirectionToken.sol:
test.js (for truffle test):
|
Anyone who could help with my issue? Unfortunately, there are not that many projects yet that implement the diamond standard that I could use as a potential reference example for my issue :-( |
Hey, sorry, looking now. |
@Walodja1987 thanks for this. Where's your migration script? For example like this: https://github.com/mudgen/diamond-1/blob/master/migrations/2_diamond.js |
@mudgen I am so glad you replied. Really appreciate your help on this. Here the 2_diamond.js file. It's the standard file with the OptionFacet included.
Just for completeness as this is in the test.js file (although you don't really need it for this particular case), here the separate ERC20CollateralToken migration script which I named 3_others.js:
Many thanks for your help again! |
@Walodja1987 Thank you. One thing that stuck out at me is this line: If you add another function to Thanks, Nick |
@mudgen good point about OptionFacet.sol. I fixed that but that didn't seem to cause the issue. I was actually able to fix the above issue in that particular example by replacing .send() with .call() in my test file resulting in the following updated test:
However, in my actual code, the ERC20 creation is not part of a view function but of a function that also updates storage variables. So I added a function (setValue) that sets the value of a storage variable OptionFacet.sol (incl. additional functions):
In my test.js file I added the following test:
Interestingly, the test fails with VM Exception error when the DirectionToken part is included in the setValue function. However, when I drop this part / comment it out, then the test goes through. Conclusion: It looks like creating the ERC20 token within a function that updates variables doesn't work. |
Great you are making progress. It does work, but you can't use state variables declared like Here's some links about these: Understanding Diamonds on Ethereum How Diamond Storage Works AppStorage Pattern for State Variables in Solidity |
@mudgen I am aware that I should declarestate variables like Thanks for sharing the links but unfortunately, I was not able to find a solution to my issue. :-( |
@divaprotocol Okay, I'm not sure what the problem is but it is possible to create new contracts (include ERC20) from within facets in diamonds. It is done successfully here: https://github.com/aavegotchi/aavegotchi-contracts/blob/cbb90bce8a1ef047b376ce7e388ca1c81ac48e00/contracts/Aavegotchi/facets/AavegotchiFacet.sol#L235 I suggest simplifying your code as much as possible to help determine the cause of the problem. |
Thanks for your prompt response. I will have a look at the aavegotchi example. Many thanks! |
@divaprotocol Yes, maybe try creating a new but very simple contract that isn't ERC20 and see if that works. |
Hi @mudgen, after several hours of testing, we were able to narrow down the error. It looks like there is a limit on how many functions one can use in a contract. We can't explain this behavior and hope for your help. Let me explain what we did : Would you know what could cause this issue? If there is a limitation on the number of functions in a contract, we would need to split the openzeppelin's ERC20 contract to make it work which I think is not an option. Really appreciate your help on this strange issue.
|
@divaprotocol There isn't a maximum number of functions you can have. But there is a maximum number of bytes the bytecode of your contract can be which is about 24KB. The DirectionToken contract is not large enough to hit the 24KB contract size limit by itself. But since you are creating the contract from within the OptionFacet facet the DirectionToken contract bytecode is probably being added to the OptionFacet contract bytecode and that is hitting the maximum size. You can fix this by moving some of the functions or functionality in OptionFacet to another facet. You can test this by measuring the bytecode of the contracts to see if they hit the 24KB limit. |
@mudgen Thanks for getting back. If it was exceeding the 24KB limit, shouldn't it say it in the error message? We had this issue already in the past and that was the main reason why we moved to the diamond standard. We are using the |
@mudgen To test whether it's a 24KB error, I duplicated the OptionFacet contract within the OptionFacet.sol file and named it OptionFacet2 (same for all the functions in the duplicate). I did this just to increase the size of the contract. If I remove the one function in the DirectionToken that causes the problem, it still runs through. This suggests that it's probably not a 24KB error. It seems to be specific to the one function in the DirectionToken contract. We are really stuck :-( |
Hi everyone,
I am struggling to create an ERC20 token inside a facet contract. In other words, the following statement is failing (it throws an VM exception error):
ERC20 erc20Token = new ERC20("TestToken","TEST");
I have the suspicion that this operation doesn't work when a delegate call is used. Could someone share an example how to do this operation insde a facet contract?
Best
Wladimir
The text was updated successfully, but these errors were encountered: