Skip to content

magicdrop cli improvements #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
KEYSTORE_PASSWORD=""
52 changes: 26 additions & 26 deletions cli/cmds/common
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

set_contract_address() {
if [ -z "$contract_address" ]; then
if is_unset_or_null "$contract_address"; then
show_title "$title" "> Enter contract address <"
contract_address=$(get_ethereum_address "Enter contract address")
check_input "$contract_address" "contract address"
Expand All @@ -10,7 +10,7 @@ set_contract_address() {
}

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

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

set_stages_file() {
if [ -z "$stages_file" ] && [ -z "$stages_json" ]; then
if is_unset_or_null "$stages_file" && is_unset_or_null "$stages_json"; then
show_title "$title" "> Set stages file <"
stages_file=$(get_collection_file "Enter stages JSON file")
clear
fi
}

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

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

set_token_standard() {
if [ -z "$token_standard" ]; then
if is_unset_or_null "$token_standard"; then
show_title "$title" "> Set token standard <"
token_standard=$(gum choose "ERC721" "ERC1155")
clear
fi
}

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

set_base_uri() {
if [ -z "$base_uri" ]; then
if is_unset_or_null "$base_uri"; then
show_title "$title" "> Enter the base URI <"
base_uri=$(gum input --placeholder "Enter base URI")
check_input "$base_uri" "base URI"
Expand All @@ -120,7 +120,7 @@ set_base_uri() {
}

set_collection_name() {
if [ -z "$name" ]; then
if is_unset_or_null "$name"; then
show_title "$title" "> Enter the collection name <"
name=$(gum input --placeholder "Enter collection name")
check_input "$name" "name"
Expand All @@ -129,7 +129,7 @@ set_collection_name() {
}

set_collection_symbol() {
if [ -z "$symbol" ]; then
if is_unset_or_null "$symbol"; then
show_title "$title" "> Enter the collection symbol <"
symbol=$(gum input --placeholder "Enter collection symbol")
check_input "$symbol" "symbol"
Expand All @@ -138,7 +138,7 @@ set_collection_symbol() {
}

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

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

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

set_token_id() {
if [ -z "$token_id" ]; then
if is_unset_or_null "$token_id"; then
show_title "$title" "> Enter token ID <"
token_id=$(get_numeric_input "Enter token ID")
check_input "$token_id" "token ID"
Expand All @@ -199,7 +199,7 @@ set_token_id() {
}

set_mintable() {
if [ -z "$mintable" ]; then
if is_unset_or_null "$mintable"; then
show_title "$title" "> Set mintable <"
if gum confirm "Set mintable?" --default=false; then
mintable=true
Expand All @@ -211,7 +211,7 @@ set_mintable() {
}

set_cosigner_address() {
if [ -z "$cosigner" ]; then
if is_unset_or_null "$cosigner"; then
show_title "$title" "> Enter cosigner address <"
cosigner=$(get_ethereum_address "Enter cosigner address")
check_input "$cosigner" "cosigner address"
Expand All @@ -220,7 +220,7 @@ set_cosigner_address() {
}

set_timestamp_expiry() {
if [ -z "$timestamp_expiry" ]; then
if is_unset_or_null "$timestamp_expiry"; then
show_title "$title" "> Enter the timestamp expiry <"
timestamp_expiry=$(get_numeric_input "Enter timestamp expiry in seconds")
check_input "$timestamp_expiry" "timestamp expiry"
Expand All @@ -229,7 +229,7 @@ set_timestamp_expiry() {
}

set_new_owner() {
if [ -z "$new_owner" ]; then
if is_unset_or_null "$new_owner"; then
show_title "$title" "> Enter new owner address <"
new_owner=$(get_ethereum_address "Enter new owner address")
check_input "$new_owner" "new owner address"
Expand All @@ -238,7 +238,7 @@ set_new_owner() {
}

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

set_1155_uri() {
if [ -z "$uri" ]; then
if is_unset_or_null "$uri"; then
show_title "$title" "> Enter new URI <"
uri="$(gum input --placeholder "Enter new URI")"
check_input "$uri" "URI"
Expand All @@ -259,7 +259,7 @@ set_1155_uri() {
}

set_receiver_address() {
if [ -z "$receiver" ]; then
if is_unset_or_null "$receiver"; then
show_title "$title" "> Enter receiver address <"
receiver=$(get_ethereum_address "Enter receiver address")
check_input "$receiver" "receiver address"
Expand All @@ -268,7 +268,7 @@ set_receiver_address() {
}

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

set_quantity() {
if [ -z "$quantity" ]; then
if is_unset_or_null "$quantity"; then
show_title "$title" "> Enter quantity <"
quantity=$(get_numeric_input "Enter quantity")
check_input "$quantity" "quantity"
Expand All @@ -291,7 +291,7 @@ set_quantity() {
}

set_authorized_minter() {
if [ -z "$minter" ]; then
if is_unset_or_null "$minter"; then
show_title "$title" "> Enter minter address <"
minter=$(get_ethereum_address "Enter minter address")
check_input "$minter" "minter address"
Expand All @@ -300,7 +300,7 @@ set_authorized_minter() {
}

set_number_of_1155_tokens() {
if [ -z "$total_tokens" ]; then
if is_unset_or_null "$total_tokens"; then
show_title "$title" "> Enter total tokens <"
echo ""
echo $(gum style --foreground 212 "Notice: This value should match the number of tokens in the stages file. Otherwise, the contract will revert.")
Expand Down
15 changes: 3 additions & 12 deletions cli/cmds/const
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ SUPPORTED_CHAINS=(
)

MAGIC_DROP_KEYSTORE="MAGIC_DROP_KEYSTORE"
MAGIC_DROP_KEYSTORE_FILE="$HOME/.foundry/keystores/$MAGIC_DROP_KEYSTORE"
export ETH_KEYSTORE_ACCOUNT=$MAGIC_DROP_KEYSTORE

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

get_factory_address() {
local chain_id="$1"
case $chain_id in
137) echo "0x00001E4949B59B0f52fC84227AF67ab131931256" ;;
11155111) echo "0x00001E4949B59B0f52fC84227AF67ab131931256" ;;
*) echo "Unknown chain id"; exit 1 ;;
esac
echo "0x000000009e44eBa131196847C685F20Cd4b68aC4"
}

get_registry_address() {
local chain_id="$1"
case $chain_id in
137) echo "0x0000Dd87036aDf1477916e36BB12e19fef5517aC" ;;
11155111) echo "0x0000Dd87036aDf1477916e36BB12e19fef5517aC" ;;
*) echo "Unknown chain id"; exit 1 ;;
esac
echo "0x00000000caF1E3978e291c5Fb53FeedB957eC146"
}
27 changes: 19 additions & 8 deletions cli/cmds/contract
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

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

STAGES_FILE="$BASE_DIR/../collections/stagesInput.tmp"
DEFAULT_IMPL_ID="0"

get_impl_id() {
if [ "$token_standard" == "ERC721" ] && [ "$use_erc721c" == "true" ]; then
echo "2" # ERC721C implementation ID
else
echo $DEFAULT_IMPL_ID
fi
}

deploy_contract() {
trap "echo 'Exiting...'; exit 1" SIGINT
clear
Expand All @@ -24,8 +31,10 @@ deploy_contract() {
standard_id=$(get_standard_id $token_standard)
password=$(get_password_if_set)

impl_id=$(get_impl_id)

echo "Fetching deployment fee..."
deployment_fee=$(cast call $registry_address "getDeploymentFee(uint8,uint32)" $standard_id $DEFAULT_IMPL_ID --rpc-url "$RPC_URL" $password)
deployment_fee=$(cast call $registry_address "getDeploymentFee(uint8,uint32)" $standard_id $impl_id --rpc-url "$RPC_URL" $password)
if [ "$deployment_fee" == "0" ]; then
value="--value $deployment_fee"
fi
Expand All @@ -43,7 +52,7 @@ deploy_contract() {
"$symbol" \
"$standard_id" \
"$SIGNER" \
$DEFAULT_IMPL_ID \
$impl_id \
$password \
$value \
--json)
Expand Down Expand Up @@ -206,9 +215,10 @@ setup_contract() {
confirm_setup

echo "Processing stages file... this will take a moment."
process_stages "$stages_file" "$stages_json" "$token_standard"
stages_data=$(cat "$STAGES_FILE") # this file is created by getStagesData.ts
rm "$STAGES_FILE"
process_stages
output_file_dir="$(dirname "$collection_file")"
stages_data=$(cat "$output_file_dir/stagesInput.tmp") # this file is created by getStagesData.ts
rm "$output_file_dir/stagesInput.tmp"
echo ""

password=$(get_password_if_set)
Expand Down Expand Up @@ -447,8 +457,9 @@ set_stages_contract() {
print_signer_with_balance $chain_id

process_stages
stages_data=$(cat "$STAGES_FILE")
rm "$STAGES_FILE"
output_file_dir="$(dirname "$collection_file")"
stages_data=$(cat "$output_file_dir/stagesInput.tmp") # this file is created by getStagesData.ts
rm "$output_file_dir/stagesInput.tmp"
echo ""

if gum confirm "Do you want to proceed?"; then
Expand Down
5 changes: 3 additions & 2 deletions cli/cmds/display
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ confirm_deployment() {
confirm_setup() {
echo ""
echo "==================== CONTRACT DETAILS ===================="
echo "Chain: $(gum style --foreground 212 "$chain")"
echo "Chain: $(gum style --foreground 212 "$chain_id")"
echo "Token Standard: $(gum style --foreground 212 "$token_standard")"
echo "Contract Address: $(gum style --foreground 212 "$(format_address "$contract_address")")"
echo "======================= SETUP INFO ======================="
Expand All @@ -101,7 +101,8 @@ confirm_setup() {
echo "Mint Currency: $(gum style --foreground 212 "$(format_address "$mint_currency")")"
echo "Royalty Receiver: $(gum style --foreground 212 "$(format_address "$royalty_receiver")")"
echo "Royalty Fee: $(gum style --foreground 212 "$royalty_fee")"
echo "Stages File: $(gum style --foreground 212 "$stages_file")"
echo "Stages File: $(gum style --foreground 212 "${stages_file:-N/A}")"
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")")"
echo "Fund Receiver: $(gum style --foreground 212 "$(format_address "$fund_receiver")")"
echo "=========================================================="
echo ""
Expand Down
10 changes: 7 additions & 3 deletions cli/cmds/getters
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ get_ethereum_address() {

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

if file_exists "$file"; then
if [[ -d "$file" ]]; then
# Recursively call with the selected directory
get_collection_file "$prompt" "$file"
elif file_exists "$file"; then
echo "$file"
else
exit 1
Expand All @@ -57,7 +61,7 @@ get_collection_file() {
get_password_if_set() {
if [[ -n "$KEYSTORE_PASSWORD" ]]; then
echo "--password $KEYSTORE_PASSWORD --account $MAGIC_DROP_KEYSTORE"
else
elif file_exists "$MAGIC_DROP_KEYSTORE_FILE"; then
local password=$(gum input --placeholder "Enter password")
echo "--password $password --account $MAGIC_DROP_KEYSTORE"
fi
Expand Down
Loading
Loading