owlprotocol / contracts

MIT License
3 stars 4 forks source link

Deploy Scripts #338

Closed HrikB closed 2 years ago

HrikB commented 2 years ago

Description

Given that our product is designed to be multi-chain, it would be very convenient for users and developers if the same contracts were deployed on the same addresses across different chains. The address of an EVM smart contract is computed deterministically, with two variables: the caller (msg.sender) and the nonce (the transaction # of the msg.sender). So, for example, if a wallet's 39th transaction on 7 different chains is launching CrafterTransfer.sol, that instance of CrafterTransfer.sol will have the same address across all those chains.

Because it is so easy to mess this up, we want to make 2 checks

Implementation

Our deploying wallet address is 0x6fd935c3BbbDf664b67e28B14236a66a7588D683. It is currently at nonce 17. So, inside the 001_Implementation folder, simply set the first contract's nonceToDeploy to 17 (skip the ProxyFactory though because we don't need to re-deploy that one. ) And the next one to 18, etc... And any time a new Implementation deploy script is added, just give it the next nonce. This isn't needed for non-Implementation scripts.

Verifying the address is slightly longer process. Use the private key for 0x6fd935c3BbbDf664b67e28B14236a66a7588D683 as your first account in the hardhat config. If you're running the deploy scripts on hardhat network, the scripts will auto burn nonces until the right nonce is reached. You just have to make sure that they are running in order. So now you have the same contracts deploying on an EVM network with the same msg.sender and the same nonce. So the address you get is what we will get on other EVM chains as well.

vszammit commented 2 years ago

/cib

github-actions[bot] commented 2 years ago

Branch issue-338 created! Clone with: git fetch && git checkout --track origin/issue-338 Rebase develop branch changes with: git checkout issue-338 && git rebase develop