Skip to content
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

Check the order of parameters in the constructor of a contract when using buildModule. #741

Open
alicercedigital opened this issue Apr 24, 2024 · 5 comments
Labels
status:needs-decision We need to make a decision about this type:feature Fetaure request

Comments

@alicercedigital
Copy link

Sometimes a contract has multiple parameters in its constructor. It's easy to accidentally swap the order of these parameters.

Does Hardhat Ignition currently offer the functionality to display parameter names, or both names and types?

If not, is it feasible to extract that information from the contract when using Hardhat Ignition?

Just to illustrate, in the example below, we might swap the 'name/symbol' or the 'owner/feeRecipient' parameters:

const FirstDeployModule = buildModule("FirstDeploy", (m) => {
 const currency = m.contract("Currency", [
  "Currency", // In this example we could have swapped the name with symbol
  "CRNCY",
  1000000,
  m.getAccount(0), // Or swap the owner with the feeRecipient
  m.getAccount(1),
 ]);

 return { currency };
});
@kanej
Copy link
Member

kanej commented Apr 25, 2024

That is interesting. I don't think we would change passing args as an array to say an object with named properties matching the Solidity function parameter names.
However we may be able to enhance the type information for the args array, so turn it into a tuple with named slots. This wouldn't be as explicit but would give you far better intellisense around each parameter (and additional type checking on the parameters).

Currently our viem support leverages the type information for contracts that is generated during the artifact compilation in Hardhat. Maybe a similar approach can be taken within the module api.

@kanej kanej added status:needs-more-information There isn't enough information to start working on this issue and removed status:triaging labels Apr 25, 2024
@alicercedigital
Copy link
Author

Just one idea: perhaps it could have a method that takes a correctly typed object and returns the arguments array in the correct order.

Like:

const arguments = m.buildArguments("ContractName", {
 name: "Test",
 symbol: "TST".
 totalSupply: 10000,
 owner: "0x...",
 feeRecipient: "0x..."
})

console.log(arguments) 
// ["Test","TST", 10000, "0x...", "0x..."]

So, in the example above, the object used to construct the arguments should be correctly typed and include all the arguments specified in the contract.

@alicercedigital
Copy link
Author

Sorry, I accidentally closed the issue. :(

@kanej
Copy link
Member

kanej commented Apr 25, 2024

A helper function on top of the Module API would work.

@kanej kanej added status:needs-decision We need to make a decision about this type:feature Fetaure request and removed status:needs-more-information There isn't enough information to start working on this issue labels Apr 25, 2024
@alicercedigital
Copy link
Author

I can try submitting a pull request.
Where should I add this helper function?
How can we obtain the type information for the contract based on the contract name?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:needs-decision We need to make a decision about this type:feature Fetaure request
Projects
Status: Todo
Development

No branches or pull requests

2 participants