-
Notifications
You must be signed in to change notification settings - Fork 34
/
build_create2_deployments.sh
executable file
·67 lines (57 loc) · 2.4 KB
/
build_create2_deployments.sh
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
# Download the libs if they aren't yet downloaded.
forge install;
# Create the create2 deployments directory.
mkdir create2 > /dev/null 2>&1;
# Use a temporary directory.
mkdir .tmp > /dev/null 2>&1;
rm -rf .tmp/contracts > /dev/null 2>&1;
rm -rf .tmp/lib > /dev/null 2>&1;
cp -r contracts .tmp/contracts;
cp -r foundry.toml .tmp/foundry.toml;
cp -r remappings.txt .tmp/remappings.txt;
cp -r lib .tmp/lib;
# Go into the temporary directory.
cd .tmp;
# Build the Solidity files.
forge build --out="out" --root=".";
# Install some files for computing the initcodehash.
echo '{ "devDependencies": { "@ethersproject/keccak256": "5.7.0" } }' > package.json;
if [ ! -f package-lock.json ]; then npm install; fi
# Create the deployments directory in the temporary directory.
mkdir create2 > /dev/null 2>&1;
# Function to generate the deployment files.
generateDeployment() {
rm -rf "create2/$1" > /dev/null 2>&1;
mkdir "create2/$1" > /dev/null 2>&1;
# Generate the js file to do the hard work.
echo "
const fs = require(\"fs\"),
rfs = s => fs.readFileSync(s, { encoding: \"utf8\", flag: \"r\" });
const solcOutput = JSON.parse(rfs(\"out/$1.sol/$1.json\"));
const initcode = solcOutput[\"bytecode\"][\"object\"].slice(2);
const d = \"create2/$1\";
fs.writeFileSync(d + \"/initcode.txt\", initcode);
const t = solcOutput[\"metadata\"][\"settings\"][\"compilationTarget\"], k = Object.keys(t)[0];
fs.writeFileSync(d + \"/t\", k + \":\" + t[k]);
fs.writeFileSync(d + \"/initcodehash.txt\", require(\"@ethersproject/keccak256\").keccak256(\"0x\" + initcode));
" > "extract_$1.js";
# Run the js file.
node "extract_$1.js";
# Generate the standard json verification file.
forge verify-contract $(cast --address-zero) "$(<create2/$1/t)" --show-standard-json-input > "create2/$1/input.json";
# Remove the temporary files.
rm "create2/$1/t" > /dev/null 2>&1;
rm "extract_$1.js" > /dev/null 2>&1;
# Move the directory over to the actual deployment directory.
rm -rf "../create2/$1" > /dev/null 2>&1;
cp -r "create2/$1" "../create2/$1";
rm -rf "create2/$1" > /dev/null 2>&1;
}
# Generate the deployments.
generateDeployment "SuperMinter";
generateDeployment "SoundEditionV2";
generateDeployment "SoundCreatorV2";
generateDeployment "SoundOnChainMetadata";
generateDeployment "SoundMetadata";
generateDeployment "SoundEditionV2_1";
generateDeployment "SuperMinterV2";