Skip to content

Commit 29eaf40

Browse files
authored
improvements (#160)
Signed-off-by: Adam Wolf <[email protected]>
1 parent 693134f commit 29eaf40

File tree

12 files changed

+105
-132
lines changed

12 files changed

+105
-132
lines changed

cli/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
KEYSTORE_PASSWORD=""

cli/cmds/common

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
set_contract_address() {
4-
if [ -z "$contract_address" ]; then
4+
if is_unset_or_null "$contract_address"; then
55
show_title "$title" "> Enter contract address <"
66
contract_address=$(get_ethereum_address "Enter contract address")
77
check_input "$contract_address" "contract address"
@@ -10,7 +10,7 @@ set_contract_address() {
1010
}
1111

1212
set_fund_receiver() {
13-
if [ -z "$fund_receiver" ]; then
13+
if is_unset_or_null "$fund_receiver"; then
1414
show_title "$title" "> Set fund receiver <"
1515
if gum confirm "Override fund receiver? (default: $(format_address $SIGNER))" --default=false; then
1616
fund_receiver=$(get_ethereum_address "Fund receiver (eg: 0x000...000)")
@@ -22,7 +22,7 @@ set_fund_receiver() {
2222
}
2323

2424
set_royalties() {
25-
if [ -z "$royalty_receiver" ] && [ -z "$royalty_fee" ]; then
25+
if is_unset_or_null "$royalty_receiver" && is_unset_or_null "$royalty_fee"; then
2626
show_title "$title" "> Do you want to set royalties? <"
2727
if gum confirm "Use royalties?" --default=false; then
2828
# Set royalty receiver
@@ -44,15 +44,15 @@ set_royalties() {
4444
}
4545

4646
set_stages_file() {
47-
if [ -z "$stages_file" ] && [ -z "$stages_json" ]; then
47+
if is_unset_or_null "$stages_file" && is_unset_or_null "$stages_json"; then
4848
show_title "$title" "> Set stages file <"
4949
stages_file=$(get_collection_file "Enter stages JSON file")
5050
clear
5151
fi
5252
}
5353

5454
set_mint_currency() {
55-
if [ -z "$mint_currency" ]; then
55+
if is_unset_or_null "$mint_currency"; then
5656
show_title "$title" "> Set mint currency <"
5757
if gum confirm "Override default mint currency? ($DEFAULT_MINT_CURRENCY)" --default=false; then
5858
mint_currency=$(get_ethereum_address "Mint currency (default: Native Gas Token)")
@@ -64,7 +64,7 @@ set_mint_currency() {
6464
}
6565

6666
set_max_mintable_supply() {
67-
if [ -z "$max_mintable_supply" ]; then
67+
if is_unset_or_null "$max_mintable_supply"; then
6868
if [ "$token_standard" = "ERC1155" ] && [ -z "$token_id" ]; then
6969
show_title "$title" "> Set max mintable supply for each token <"
7070
max_mintable_supply="["
@@ -91,15 +91,15 @@ set_max_mintable_supply() {
9191
}
9292

9393
set_token_standard() {
94-
if [ -z "$token_standard" ]; then
94+
if is_unset_or_null "$token_standard"; then
9595
show_title "$title" "> Set token standard <"
9696
token_standard=$(gum choose "ERC721" "ERC1155")
9797
clear
9898
fi
9999
}
100100

101101
set_chain() {
102-
if [ -z "$chain_id" ]; then
102+
if is_unset_or_null "$chain_id"; then
103103
show_title "$title" "> Choose a chain to deploy on <"
104104
chain=$(printf "%s\n" "${SUPPORTED_CHAINS[@]}" | cut -d':' -f2 | gum choose)
105105
# Extract the chain ID based on the selected chain name
@@ -111,7 +111,7 @@ set_chain() {
111111
}
112112

113113
set_base_uri() {
114-
if [ -z "$base_uri" ]; then
114+
if is_unset_or_null "$base_uri"; then
115115
show_title "$title" "> Enter the base URI <"
116116
base_uri=$(gum input --placeholder "Enter base URI")
117117
check_input "$base_uri" "base URI"
@@ -120,7 +120,7 @@ set_base_uri() {
120120
}
121121

122122
set_collection_name() {
123-
if [ -z "$name" ]; then
123+
if is_unset_or_null "$name"; then
124124
show_title "$title" "> Enter the collection name <"
125125
name=$(gum input --placeholder "Enter collection name")
126126
check_input "$name" "name"
@@ -129,7 +129,7 @@ set_collection_name() {
129129
}
130130

131131
set_collection_symbol() {
132-
if [ -z "$symbol" ]; then
132+
if is_unset_or_null "$symbol"; then
133133
show_title "$title" "> Enter the collection symbol <"
134134
symbol=$(gum input --placeholder "Enter collection symbol")
135135
check_input "$symbol" "symbol"
@@ -138,7 +138,7 @@ set_collection_symbol() {
138138
}
139139

140140
set_contract_owner() {
141-
if [ -z "$initial_owner" ]; then
141+
if is_unset_or_null "$initial_owner"; then
142142
show_title "$title" "> Set initial contract owner <"
143143
if gum confirm "Override initial contract owner? ($(format_address $SIGNER))" --default=false; then
144144
initial_owner=$(get_ethereum_address "Initial contract owner")
@@ -150,7 +150,7 @@ set_contract_owner() {
150150
}
151151

152152
set_impl_id() {
153-
if [ -z "$impl_id" ]; then
153+
if is_unset_or_null "$impl_id"; then
154154
show_title "$title" "> Set implementation ID <"
155155
if gum confirm "Override default implementation?" --default=false; then
156156
impl_id=$(get_numeric_input "Enter implementation ID")
@@ -163,7 +163,7 @@ set_impl_id() {
163163
}
164164

165165
set_global_wallet_limit() {
166-
if [ -z "$global_wallet_limit" ]; then
166+
if is_unset_or_null "$global_wallet_limit"; then
167167
if [ "$token_standard" = "ERC1155" ] && [ -z "$token_id" ]; then
168168
show_title "$title" "> Set global wallet limit for each token <"
169169
global_wallet_limit="["
@@ -190,7 +190,7 @@ set_global_wallet_limit() {
190190
}
191191

192192
set_token_id() {
193-
if [ -z "$token_id" ]; then
193+
if is_unset_or_null "$token_id"; then
194194
show_title "$title" "> Enter token ID <"
195195
token_id=$(get_numeric_input "Enter token ID")
196196
check_input "$token_id" "token ID"
@@ -199,7 +199,7 @@ set_token_id() {
199199
}
200200

201201
set_mintable() {
202-
if [ -z "$mintable" ]; then
202+
if is_unset_or_null "$mintable"; then
203203
show_title "$title" "> Set mintable <"
204204
if gum confirm "Set mintable?" --default=false; then
205205
mintable=true
@@ -211,7 +211,7 @@ set_mintable() {
211211
}
212212

213213
set_cosigner_address() {
214-
if [ -z "$cosigner" ]; then
214+
if is_unset_or_null "$cosigner"; then
215215
show_title "$title" "> Enter cosigner address <"
216216
cosigner=$(get_ethereum_address "Enter cosigner address")
217217
check_input "$cosigner" "cosigner address"
@@ -220,7 +220,7 @@ set_cosigner_address() {
220220
}
221221

222222
set_timestamp_expiry() {
223-
if [ -z "$timestamp_expiry" ]; then
223+
if is_unset_or_null "$timestamp_expiry"; then
224224
show_title "$title" "> Enter the timestamp expiry <"
225225
timestamp_expiry=$(get_numeric_input "Enter timestamp expiry in seconds")
226226
check_input "$timestamp_expiry" "timestamp expiry"
@@ -229,7 +229,7 @@ set_timestamp_expiry() {
229229
}
230230

231231
set_new_owner() {
232-
if [ -z "$new_owner" ]; then
232+
if is_unset_or_null "$new_owner"; then
233233
show_title "$title" "> Enter new owner address <"
234234
new_owner=$(get_ethereum_address "Enter new owner address")
235235
check_input "$new_owner" "new owner address"
@@ -238,7 +238,7 @@ set_new_owner() {
238238
}
239239

240240
set_token_uri_suffix() {
241-
if [ -z "$token_uri_suffix" ]; then
241+
if is_unset_or_null "$token_uri_suffix"; then
242242
show_title "$title" "> Set token URI suffix <"
243243
if gum confirm "Override default token URI suffix? ($DEFAULT_TOKEN_URI_SUFFIX)" --default=false; then
244244
token_uri_suffix=$(gum input --placeholder ".json")
@@ -250,7 +250,7 @@ set_token_uri_suffix() {
250250
}
251251

252252
set_1155_uri() {
253-
if [ -z "$uri" ]; then
253+
if is_unset_or_null "$uri"; then
254254
show_title "$title" "> Enter new URI <"
255255
uri="$(gum input --placeholder "Enter new URI")"
256256
check_input "$uri" "URI"
@@ -259,7 +259,7 @@ set_1155_uri() {
259259
}
260260

261261
set_receiver_address() {
262-
if [ -z "$receiver" ]; then
262+
if is_unset_or_null "$receiver"; then
263263
show_title "$title" "> Enter receiver address <"
264264
receiver=$(get_ethereum_address "Enter receiver address")
265265
check_input "$receiver" "receiver address"
@@ -268,7 +268,7 @@ set_receiver_address() {
268268
}
269269

270270
set_fee_numerator() {
271-
if [ -z "$fee_numerator" ]; then
271+
if is_unset_or_null "$fee_numerator"; then
272272
show_title "$title" "> Enter fee numerator <"
273273
echo "Notice: The fee numerator is a number from 0 to 10000."
274274
echo "It shows the royalty fee as a percentage."
@@ -282,7 +282,7 @@ set_fee_numerator() {
282282
}
283283

284284
set_quantity() {
285-
if [ -z "$quantity" ]; then
285+
if is_unset_or_null "$quantity"; then
286286
show_title "$title" "> Enter quantity <"
287287
quantity=$(get_numeric_input "Enter quantity")
288288
check_input "$quantity" "quantity"
@@ -291,7 +291,7 @@ set_quantity() {
291291
}
292292

293293
set_authorized_minter() {
294-
if [ -z "$minter" ]; then
294+
if is_unset_or_null "$minter"; then
295295
show_title "$title" "> Enter minter address <"
296296
minter=$(get_ethereum_address "Enter minter address")
297297
check_input "$minter" "minter address"
@@ -300,7 +300,7 @@ set_authorized_minter() {
300300
}
301301

302302
set_number_of_1155_tokens() {
303-
if [ -z "$total_tokens" ]; then
303+
if is_unset_or_null "$total_tokens"; then
304304
show_title "$title" "> Enter total tokens <"
305305
echo ""
306306
echo $(gum style --foreground 212 "Notice: This value should match the number of tokens in the stages file. Otherwise, the contract will revert.")

cli/cmds/const

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ SUPPORTED_CHAINS=(
1313
)
1414

1515
MAGIC_DROP_KEYSTORE="MAGIC_DROP_KEYSTORE"
16+
MAGIC_DROP_KEYSTORE_FILE="$HOME/.foundry/keystores/$MAGIC_DROP_KEYSTORE"
1617
export ETH_KEYSTORE_ACCOUNT=$MAGIC_DROP_KEYSTORE
1718

1819
ME_TRANSFER_VALIDATOR_V3="0x721C00D4FB075b22a5469e9CF2440697F729aA13"
@@ -22,19 +23,9 @@ ICREATOR_TOKEN_INTERFACE_ID="0xad0d7f6c" # type(ICreatorToken).interfaceId
2223
TRUE_HEX="0x0000000000000000000000000000000000000000000000000000000000000001"
2324

2425
get_factory_address() {
25-
local chain_id="$1"
26-
case $chain_id in
27-
137) echo "0x00001E4949B59B0f52fC84227AF67ab131931256" ;;
28-
11155111) echo "0x00001E4949B59B0f52fC84227AF67ab131931256" ;;
29-
*) echo "Unknown chain id"; exit 1 ;;
30-
esac
26+
echo "0x000000009e44eBa131196847C685F20Cd4b68aC4"
3127
}
3228

3329
get_registry_address() {
34-
local chain_id="$1"
35-
case $chain_id in
36-
137) echo "0x0000Dd87036aDf1477916e36BB12e19fef5517aC" ;;
37-
11155111) echo "0x0000Dd87036aDf1477916e36BB12e19fef5517aC" ;;
38-
*) echo "Unknown chain id"; exit 1 ;;
39-
esac
30+
echo "0x00000000caF1E3978e291c5Fb53FeedB957eC146"
4031
}

cli/cmds/contract

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22

33
trap "echo 'Exiting...'; exit 1" SIGINT
44

5-
STAGES_FILE="$BASE_DIR/../collections/stagesInput.tmp"
65
DEFAULT_IMPL_ID="0"
76

7+
get_impl_id() {
8+
if [ "$token_standard" == "ERC721" ] && [ "$use_erc721c" == "true" ]; then
9+
echo "2" # ERC721C implementation ID
10+
else
11+
echo $DEFAULT_IMPL_ID
12+
fi
13+
}
14+
815
deploy_contract() {
916
trap "echo 'Exiting...'; exit 1" SIGINT
1017
clear
@@ -24,8 +31,10 @@ deploy_contract() {
2431
standard_id=$(get_standard_id $token_standard)
2532
password=$(get_password_if_set)
2633

34+
impl_id=$(get_impl_id)
35+
2736
echo "Fetching deployment fee..."
28-
deployment_fee=$(cast call $registry_address "getDeploymentFee(uint8,uint32)" $standard_id $DEFAULT_IMPL_ID --rpc-url "$RPC_URL" $password)
37+
deployment_fee=$(cast call $registry_address "getDeploymentFee(uint8,uint32)" $standard_id $impl_id --rpc-url "$RPC_URL" $password)
2938
if [ "$deployment_fee" == "0" ]; then
3039
value="--value $deployment_fee"
3140
fi
@@ -43,7 +52,7 @@ deploy_contract() {
4352
"$symbol" \
4453
"$standard_id" \
4554
"$SIGNER" \
46-
$DEFAULT_IMPL_ID \
55+
$impl_id \
4756
$password \
4857
$value \
4958
--json)
@@ -206,9 +215,10 @@ setup_contract() {
206215
confirm_setup
207216

208217
echo "Processing stages file... this will take a moment."
209-
process_stages "$stages_file" "$stages_json" "$token_standard"
210-
stages_data=$(cat "$STAGES_FILE") # this file is created by getStagesData.ts
211-
rm "$STAGES_FILE"
218+
process_stages
219+
output_file_dir="$(dirname "$collection_file")"
220+
stages_data=$(cat "$output_file_dir/stagesInput.tmp") # this file is created by getStagesData.ts
221+
rm "$output_file_dir/stagesInput.tmp"
212222
echo ""
213223

214224
password=$(get_password_if_set)
@@ -447,8 +457,9 @@ set_stages_contract() {
447457
print_signer_with_balance $chain_id
448458

449459
process_stages
450-
stages_data=$(cat "$STAGES_FILE")
451-
rm "$STAGES_FILE"
460+
output_file_dir="$(dirname "$collection_file")"
461+
stages_data=$(cat "$output_file_dir/stagesInput.tmp") # this file is created by getStagesData.ts
462+
rm "$output_file_dir/stagesInput.tmp"
452463
echo ""
453464

454465
if gum confirm "Do you want to proceed?"; then

cli/cmds/display

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ confirm_deployment() {
9292
confirm_setup() {
9393
echo ""
9494
echo "==================== CONTRACT DETAILS ===================="
95-
echo "Chain: $(gum style --foreground 212 "$chain")"
95+
echo "Chain: $(gum style --foreground 212 "$chain_id")"
9696
echo "Token Standard: $(gum style --foreground 212 "$token_standard")"
9797
echo "Contract Address: $(gum style --foreground 212 "$(format_address "$contract_address")")"
9898
echo "======================= SETUP INFO ======================="
@@ -101,7 +101,8 @@ confirm_setup() {
101101
echo "Mint Currency: $(gum style --foreground 212 "$(format_address "$mint_currency")")"
102102
echo "Royalty Receiver: $(gum style --foreground 212 "$(format_address "$royalty_receiver")")"
103103
echo "Royalty Fee: $(gum style --foreground 212 "$royalty_fee")"
104-
echo "Stages File: $(gum style --foreground 212 "$stages_file")"
104+
echo "Stages File: $(gum style --foreground 212 "${stages_file:-N/A}")"
105+
echo "Stages JSON: $(gum style --foreground 212 "$(echo "$stages_json" | tr -d '\n\t ' | cut -c 1-30)$([ ${#stages_json} -gt 30 ] && echo "... rest omitted")")"
105106
echo "Fund Receiver: $(gum style --foreground 212 "$(format_address "$fund_receiver")")"
106107
echo "=========================================================="
107108
echo ""

cli/cmds/getters

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@ get_ethereum_address() {
4545

4646
get_collection_file() {
4747
local prompt="$1"
48-
local file file=$(gum file --directory "$BASE_DIR/../collections" --height 10)
48+
local directory="${2:-$BASE_DIR/../collections}" # Use provided directory or default
49+
local file=$(gum file --directory "$directory" --height 10)
4950

50-
if file_exists "$file"; then
51+
if [[ -d "$file" ]]; then
52+
# Recursively call with the selected directory
53+
get_collection_file "$prompt" "$file"
54+
elif file_exists "$file"; then
5155
echo "$file"
5256
else
5357
exit 1
@@ -57,7 +61,7 @@ get_collection_file() {
5761
get_password_if_set() {
5862
if [[ -n "$KEYSTORE_PASSWORD" ]]; then
5963
echo "--password $KEYSTORE_PASSWORD --account $MAGIC_DROP_KEYSTORE"
60-
else
64+
elif file_exists "$MAGIC_DROP_KEYSTORE_FILE"; then
6165
local password=$(gum input --placeholder "Enter password")
6266
echo "--password $password --account $MAGIC_DROP_KEYSTORE"
6367
fi

0 commit comments

Comments
 (0)