-
Notifications
You must be signed in to change notification settings - Fork 4
/
deploy.s.sol
72 lines (51 loc) · 2.27 KB
/
deploy.s.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {ERC1967Proxy} from "UDS/proxy/ERC1967Proxy.sol";
import {MyNFTUpgradeableV1} from "./ExampleNFT.sol";
import "forge-std/Script.sol";
/*
For a more complete example (of deploying, upgrading & keeping track of proxies),
have a look at https://github.com/0xPhaze/upgrade-scripts.
Steps to run these scripts:
1. Create a `.env` file with the following variables:
```.env
RPC_URL=https://eth-rinkeby.alchemyapi.io/v2/Q_w...
ETHERSCAN_KEY=NZSD...
PRIVATE_KEY=0x1234...
```
Make sure it's called `.env`!
2. Run script
```sh
source .env && forge script deploy --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast --verify --etherscan-api-key $ETHERSCAN_KEY -vvvv
```
3. (optional) if verification failed
```sh
source .env && forge script deploy --rpc-url $RPC_URL --private-key $PRIVATE_KEY --resume --verify --etherscan-api-key $ETHERSCAN_KEY -vvvv
```
4. Store deployed proxy address in your `.env` file: `PROXY_ADDRESS=...`.
*/
contract deploy is Script {
MyNFTUpgradeableV1 myNFT;
function run() external {
vm.startBroadcast();
// deploys the implementation contract
address implementation = address(new MyNFTUpgradeableV1());
// insert parameters if the init function has any
bytes memory initParameters = abi.encode(/* parameter1, parameter2 */); // prettier-ignore
// encode calldata for init call
bytes memory initCalldata = abi.encodePacked(MyNFTUpgradeableV1.init.selector, initParameters);
// deploys the proxy contract and calls MyNFTUpgradeableV1.init() in the context of the proxy
address proxy = address(new ERC1967Proxy(implementation, initCalldata));
vm.stopBroadcast();
myNFT = MyNFTUpgradeableV1(proxy);
integrationTest();
console.log("implementation:", implementation);
console.log("Add `PROXY_ADDRESS=%s` to your .env", proxy);
}
/// @notice the script will fail if these conditions aren't met
function integrationTest() internal view {
require(myNFT.owner() == msg.sender);
require(keccak256(abi.encode(myNFT.name())) == keccak256(abi.encode("Non-fungible Contract")));
require(keccak256(abi.encode(myNFT.symbol())) == keccak256(abi.encode("NFT")));
}
}