NomicFoundation / hardhat-ignition

Hardhat Ignition is a declarative deployment system that enables you to deploy your smart contracts without navigating the mechanics of the deployment process.
https://hardhat.org/ignition
MIT License
107 stars 25 forks source link

Async support in buildModule #595

Open humayunj opened 1 year ago

humayunj commented 1 year ago

Short version: How can I pass latest block time in constructor args like in hardhat Lock example

Description: I'm not able to find any way to pass async dynamic value to constructor of contract inside buildModule. We can either pass params via code or by parameters.json, parameters.json is static while the buildModule doesn't support promises ( it's orchestrated around Futures ). To pass latest block block time I need to wait for the response from RPC like time.latest() being used in hardhat lock example

kanej commented 1 year ago

Can I clarify, is it in the module file that you are wanting to pass values into the module definition that have been loaded asynchronously? So:

./ignition/modules/LockModule.js

As opposed to the use of hre.ignition.deploy in tests or scripts?

humayunj commented 1 year ago

Correct, it's the module file ./ignition/modules/LockModule.js where async value should be passed

kanej commented 9 months ago

We designed buildModule as synchronous to minimize risks. Our intent is that you should be able to construct the module datastructure in its entirety before execution begins - so we can do static analysis for validation, visualization etc. We don't want users confusing buildModule time and execution time, and trying to interweave control flow and arbitrary JS code based on futures that will only be executed after module construction has completed.

On reflection this doesn't preclude making buildModule async, the constraint is just that the module is fully constructed by the end of buildModule. So this is an option for consideration.

In the meantime, our suggestion would be to leverage buildModule and hre.ignition.deploy(...) from a Hardhat script, allowing the retrieval of the latest time asynchronously before running the deploy. Alternatively to pass the latest time as a module parameter, the time can then be passed on the command line, not ideal but possible.