Getting the addresses of 2 contracts which are deployed with 1 function call. #3007
Replies: 1 comment 3 replies
-
In your contract, you can emit an event after the deployment and on the client-side get the transaction receipt to see the event logs in it. Since this is much cheaper than a storage write, it is the preferred way than being just a workaround, the whole purpose of events is to emit some data for external things instead of using the costly storage + function call. Uniswap emits a Pool Created event as well (and I think they also store it on the storage for the convenience of some devs). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Normally I interact with contract deployments like:
Method 1:
This works fine when only 1 "ExampleContract" is deployed. But in the case that there is a function that deploys 2 contracts, what would be a work around? For example, imagine I have 1 LP Token and want to deploy 2 contracts that represent token0 and token1 with:
The reason I am asking this is because I believe there might be unexpected behaviour in regards to custom errors introduced in Sol 0.8.4.
Since I wrote the 2 contracts that would be deployed, the work around I implemented was to deploy the 2 contracts with the 1 function from above but this time store token0 and token1 deployed addresses in a mapping (lpToken => struct) to then get them with ethers:
Method 2:
Now the problem is that when I run tests on the contracts with waffle, they behave correctly, but without showing any custom errors. All error messages show as:
AssertionError: Expected transaction to be reverted with { reason }, but other exception was thrown: ProviderError: VM Exception while processing transaction: revert with unrecognized return data or custom error
If I deploy and test the contracts with Method 1, they show all custom errors correctly. Using method 2, they revert when they should, but it seems as if the errors in the interfaces aren't getting recognized... Surprisingly, events aren't affected though.
Is this a problem of the custom reverts feature?
Any ideas on a work around to get the contract object when it is deployed from another contract's methods (such as a Uniswap Factory which deploys 2 contracts for example)?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions