wighawag / hardhat-deploy

hardhat deployment plugin
MIT License
1.17k stars 283 forks source link

Wrap calls into one tansaction #458

Closed migoldfinger closed 7 months ago

migoldfinger commented 1 year ago

Is your feature request related to a problem? Please describe. I have the need to call 2 functions after a deployment. If one of the calls failed the deployment should be considered failed. There is no way for me to check if I need to call the function or if it's already called.

Describe the solution you'd like There should be a way to put multiple calls into one transaction so that they are only executed together or not at all.

Describe alternatives you've considered Just hope that the calls work.

Additional context None

wighawag commented 1 year ago

to just wrap 2 call you can use a multi call

to wrap a deployment with a call, you can make your constructor do something. Or am I missing something ?

migoldfinger commented 1 year ago

Its bit more complicated. In my deployment scripts first I need to deploy a contract. and after that I need to call 2 functions of other contracts deployed in a previous step.

Normally for example on contracts that implements IOwnable I check if the owner is the expected one and if not I call the function. However the functions I am talking about just reset a timer. I have no way of knowing if I need to reset the timer just by looking at the current value. The only thing I know is that if I deploy contract A I need to call the reset timer functions on contract B and C.

Currently I am calling the functions if deploy is successful there was no reuse of an existing deployed contract. However in case one of the reset timer function fails I am in an inconsistent state (that I have to solve manually at the moment).

So my thought was that if I can put the deployment and the call of the 2 functions inside a transaction the problem would be solved permanently.

An other option would be to add that info into the 2 contracts so that the deploy script can check for it. But that would mean that I add logic into the contracts that's is only needed by the deploy script and that's not pretty either.

wighawag commented 1 year ago

I think a multi call contract should solve that

You can then still use deployment.save() to benefit from hardhat-deploy other features

migoldfinger commented 7 months ago

In fact, you are right. There is no multicall contract on the chain I am deploying to so I have to address that too. But in theory using an multi call contract is the solution.