flow-cli icon indicating copy to clipboard operation
flow-cli copied to clipboard

Warning on Standard Contract deploy on mainnet

Open bluesign opened this issue 2 years ago • 5 comments

Issue To Be Solved

Many new comers accidentally deploy FungibleToken, NonFungibleToken, NFTStoreFront contracts to their accounts, either because of a mistake or totally because they are uninformed.

Suggest A Solution

We can show a warning and prompt for confirmation in a case like this

bluesign avatar Aug 03 '22 08:08 bluesign

What would the warning be? Something like "it's advised you use already deployed contract ... read more about it here"

sideninja avatar Aug 03 '22 10:08 sideninja

It seems like you are trying to deploy %s to mainnet, it is a standard contract already deployed at address 0x%x. You can read more about it here: %s. Do you still want to deploy the contract (y/n)

I link we have already links for standard contracts at docs.

bluesign avatar Aug 03 '22 10:08 bluesign

That would be nice, I agree 100%.

sideninja avatar Aug 03 '22 10:08 sideninja

Are you ok holding this list in the CLI codebase ? Some kind of Contract Name -> ( mainnet address , web link ) mapping. I think it will be low maintenance

bluesign avatar Aug 03 '22 11:08 bluesign

I'm not a fan of lists of contracts, I feel that should be ideally decentralised and saved in such registries, so we don't special treat any contracts and control that ourselves, but that road is longer and I think it might be ok to do that meanwhile.

sideninja avatar Aug 03 '22 12:08 sideninja

@sideninja I did the most of the work here, but stuck on something.

Considering project deploy flow:

  • Should we replace the contract reference in state with alias ?
  • As we are not exposing direct access to state, should I add some helpers to Project, such as "ContractsToDeploy()andReplaceContractWithAlias` ? or is there a better place for this?

bluesign avatar Aug 22 '22 10:08 bluesign

Should we replace the contract reference in state with alias ?

This is a good idea yeah.

As we are not exposing direct access to state, should I add some helpers to Project, such as "ContractsToDeploy() and ReplaceContractWithAlias` ? or is there a better place for this?

Where are you trying to access state? In the project service you should be able to access the state directly.

sideninja avatar Aug 23 '22 11:08 sideninja

Because I want to prompt the user ( if they want to deploy or replace with alias ), so best option I guess:

  • to do the check and prompt user ( on CLI side )
  • depending on user answer, do the fix / or ignore
  • deploy via flowkit project

So this flow will need access to state ( or some helpers accessing state as I mentioned )

bluesign avatar Aug 23 '22 11:08 bluesign

Because I want to prompt the user ( if they want to deploy or replace with alias ), so best option I guess:

  • to do the check and prompt user ( on CLI side )
  • depending on user answer, do the fix / or ignore
  • deploy via flowkit project

So this flow will need access to state ( or some helpers accessing state as I mentioned )

You could do the prompt in the project service and then based on the answer you can proceed. In the future, we will refactor prompts out of the flowkit and just accept a prompt resolver as an argument, that way you could define the prompt in the command layer.

sideninja avatar Aug 23 '22 12:08 sideninja

@sideninja managed with prompt ui on project, but just one more question remains about where to save the config ( due to cascading -f edge cases ) or I can skip saving totally ?

bluesign avatar Aug 23 '22 17:08 bluesign

@bluesign we currently don't yet support saving to multiple files as per https://github.com/onflow/flow-cli/blob/7401e49afd2d7b89e15dc8f42c75fcb279f4e60f/pkg/flowkit/state.go#L79 There's a plan to make this work in the future once we find some time.

sideninja avatar Aug 24 '22 09:08 sideninja