1
+ # Function to display script usage
2
+ usage () {
3
+ forge script --help
4
+
5
+ echo " "
6
+ echo " \033[33mFoundry Script Usage:\033[0m"
7
+ echo " Usage: $0 [forge_options] --no-postcheck --sender {sender_address} --force-generate-artifact"
8
+ echo " Options:"
9
+ echo " --no-postcheck: Disable post-check"
10
+ echo " --sender: Specify the default sender address"
11
+ echo " --force-generate-artifact: Force generate artifact"
12
+
13
+ exit 1
14
+ }
15
+
16
+ # Check if command-line arguments are provided
17
+ if [ " $# " -eq 0 ]; then
18
+ usage
19
+ fi
20
+
1
21
verify_arg=" "
2
22
extra_argument=" "
3
23
@@ -6,6 +26,64 @@ op_command=""
6
26
network_name=" "
7
27
is_broadcast=false
8
28
should_verify=false
29
+ force_generate_artifact=false
30
+ # Define the deployments folder by concatenating it with the child folder
31
+ root=" deployments/"
32
+
33
+ export_address () {
34
+ index=0
35
+
36
+ start_time=$( date +%s)
37
+
38
+ for folder in " $root " /* ; do
39
+ # If exported_address.toml exists, delete it
40
+ if [ -f " $folder " /exported_address ]; then
41
+ rm " $folder " /exported_address
42
+ fi
43
+
44
+ # Create a new exported_address file
45
+ touch " $folder " /exported_address
46
+
47
+ for file in " $folder " /* .json; do
48
+
49
+ # Check if the file exists and is a regular file
50
+ if [ -f " $file " ] && [ " $( basename " $file " ) " != " .chainId" ] && [ " $( basename " $file " ) " != " exported_address" ]; then
51
+ (( index++ ))
52
+ (
53
+ # Extract address from the JSON file
54
+ contractAddress=$( jq -r ' .address' " $file " )
55
+ # Extract contractName from file name without the extension
56
+ contractName=$( basename " $file " .json)
57
+
58
+ # Check if contractName and address are not empty
59
+ if [ -n " $contractName " ]; then
60
+ # Write to file the contractName and address
61
+ echo " $contractName .json@$contractAddress " >> " $folder " /exported_address
62
+ else
63
+ echo " Error: Missing contractName or address in $file "
64
+ fi
65
+ ) &
66
+ fi
67
+
68
+ # Check if index is a multiple of 10, then wait
69
+ if [ $(( index % 10 )) -eq 0 ]; then
70
+ wait
71
+ fi
72
+ done
73
+ done
74
+
75
+ wait
76
+
77
+ end_time=$( date +%s)
78
+ echo " Export address in deployment folder: $(( end_time - start_time)) seconds"
79
+ }
80
+
81
+ export_address
82
+
83
+ echo " \033[33mTrying to compile contracts ...\033[0m"
84
+ forge build # Ensure the contracts are compiled before running the script
85
+
86
+ index=0
9
87
10
88
for arg in " $@ " ; do
11
89
case $arg in
@@ -22,11 +100,15 @@ for arg in "$@"; do
22
100
;;
23
101
-f | --fork-url)
24
102
network_name=${@: index+2: 1}
25
- extra_argument+=" network.${network_name} @"
103
+ # skip if network_name is localhost
104
+ if [[ $network_name != " localhost" ]]; then
105
+ extra_argument+=" network.${network_name} @"
106
+
107
+ set -- " ${@/# -f/ } "
108
+ set -- " ${@/# --fork-url/ } "
109
+ set -- " ${@/# $network_name / } "
110
+ fi
26
111
27
- set -- " ${@/# -f/ } "
28
- set -- " ${@/# --fork-url/ } "
29
- set -- " ${@/# $network_name / } "
30
112
;;
31
113
--fork-block-number)
32
114
fork_block_number=${@: index+2: 1}
@@ -38,14 +120,31 @@ for arg in "$@"; do
38
120
--broadcast)
39
121
is_broadcast=true
40
122
;;
123
+ --sender)
124
+ sender=${@: index+2: 1}
125
+ extra_argument+=" sender.${sender} @"
126
+ ;;
127
+ --force-generate-artifact)
128
+ force_generate_artifact=true
129
+
130
+ set -- " ${@/# --force-generate-artifact/ } "
131
+ ;;
132
+ --help)
133
+ usage
134
+ exist 1
135
+ ;;
41
136
* ) ;;
42
137
esac
43
138
index=$(( index + 1 ))
44
139
done
45
140
46
141
should_verify=$( [[ $should_verify == true && $is_broadcast == true ]] && echo true || echo false)
47
142
48
- if [[ $should_verify == true ]]; then
143
+ if [[ $force_generate_artifact == true ]]; then
144
+ extra_argument+=generate-artifact@
145
+ fi
146
+
147
+ if [[ $should_verify == true ]] && [[ $force_generate_artifact == false ]]; then
49
148
extra_argument+=generate-artifact@
50
149
fi
51
150
@@ -67,17 +166,16 @@ if [[ ! $extra_argument == *"sender"* ]] && [[ ! $extra_argument == *"trezor"* ]
67
166
fi
68
167
fi
69
168
70
- calldata=$( cast calldata ' run()' )
71
169
start_time=$( date +%s)
72
170
73
- ${op_command} forge script ${verify_arg} ${@ } -g 200 --sig ' run(bytes,string)' ${ calldata} " ${extra_argument} "
171
+ ${op_command} forge script ${verify_arg} ${@ } -g 200 --sig ' run(bytes,string)' $( cast calldata ' run() ' ) " ${extra_argument} "
74
172
75
173
# Check if the command was successful
76
174
if [ $? -eq 0 ]; then
77
175
if [[ $should_verify == true ]]; then
78
176
if [[ $network_name == " ronin-mainnet" ]] || [[ $network_name == " ronin-testnet" ]]; then
79
177
echo " Verifying contract..."
80
- ${op_command} yarn hardhat sourcify --endpoint https://sourcify.roninchain.com/server --network ${network_name}
178
+ yarn hardhat sourcify --endpoint https://sourcify.roninchain.com/server --network ${network_name}
81
179
fi
82
180
fi
83
181
fi
0 commit comments