-
Notifications
You must be signed in to change notification settings - Fork 158
Update deploy_exchange.sh #18
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
Open
Sulios
wants to merge
1
commit into
Polymarket:main
Choose a base branch
from
Sulios:patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,48 +1,95 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| LOCAL=.env.local | ||
| TESTNET=.env.testnet | ||
| MAINNET=.env | ||
|
|
||
| if [ -z $1 ] | ||
| then | ||
| echo "usage: deploy_exchange.sh [local || testnet || mainnet]" | ||
| exit 1 | ||
| elif [ $1 == "local" ] | ||
| then | ||
| ENV=$LOCAL | ||
| elif [ $1 == "testnet" ] | ||
| then | ||
| ENV=$TESTNET | ||
| elif [ $1 == "mainnet" ] | ||
| then | ||
| ENV=$MAINNET | ||
| else | ||
| echo "usage: deploy_exchange.sh [local || testnet || mainnet]" | ||
| exit 1 | ||
| # --- ENVIRONMENT CONFIGURATION --- | ||
| # Define the environment file names. | ||
| LOCAL_ENV=".env.local" | ||
| TESTNET_ENV=".env.testnet" | ||
| MAINNET_ENV=".env.mainnet" # Renamed from '.env' for clarity/safety | ||
|
|
||
| # --- ARGUMENT VALIDATION --- | ||
| if [ -z "$1" ]; then | ||
| echo "Error: Missing environment argument." | ||
| echo "Usage: deploy_exchange.sh [local | testnet | mainnet]" | ||
| exit 1 | ||
| fi | ||
|
|
||
| source $ENV | ||
| case "$1" in | ||
| "local") | ||
| ENV_FILE=$LOCAL_ENV | ||
| ;; | ||
| "testnet") | ||
| ENV_FILE=$TESTNET_ENV | ||
| ;; | ||
| "mainnet") | ||
| ENV_FILE=$MAINNET_ENV | ||
| ;; | ||
| *) | ||
| echo "Error: Invalid environment '$1'." | ||
| echo "Usage: deploy_exchange.sh [local | testnet | mainnet]" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
| # Check if the environment file exists | ||
| if [ ! -f "$ENV_FILE" ]; then | ||
| echo "Error: Environment file not found: $ENV_FILE" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Deploying CTF Exchange..." | ||
| # Load environment variables (RPC_URL, ADMIN, COLLATERAL, etc.). | ||
| # WARNING: Ensure PK (Private Key) is NOT committed to Git. | ||
| source "$ENV_FILE" | ||
|
|
||
| echo "Deploy args: | ||
| # --- DEPLOYMENT PRE-CHECK --- | ||
| if [ -z "$PK" ]; then | ||
| echo "Error: PK (Private Key) is not set in $ENV_FILE. Aborting for security." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "--- Deploying CTF Exchange to $1 ---" | ||
|
|
||
| echo "Deploy Arguments: | ||
| Admin: $ADMIN | ||
| Collateral: $COLLATERAL | ||
| ConditionalTokensFramework: $CTF | ||
| ProxyFactory: $PROXY_FACTORY | ||
| SafeFactory: $SAFE_FACTORY | ||
| " | ||
|
|
||
| OUTPUT="$(forge script ExchangeDeployment \ | ||
| --private-key $PK \ | ||
| --rpc-url $RPC_URL \ | ||
| # --- CORE FORGE EXECUTION --- | ||
|
|
||
| # Forge script command execution. | ||
| # Using standard gas price retrieval (no --with-gas-price) for robustness. | ||
| # PK is read from the environment variable (sourced above). | ||
| OUTPUT=$(forge script ExchangeDeployment \ | ||
| --private-key "$PK" \ | ||
| --rpc-url "$RPC_URL" \ | ||
| --json \ | ||
| --broadcast \ | ||
| --with-gas-price 200000000000 \ | ||
| -s "deployExchange(address,address,address,address,address)" $ADMIN $COLLATERAL $CTF $PROXY_FACTORY $SAFE_FACTORY)" | ||
| -s "deployExchange(address,address,address,address,address)" \ | ||
| "$ADMIN" "$COLLATERAL" "$CTF" "$PROXY_FACTORY" "$SAFE_FACTORY") | ||
|
|
||
| EXCHANGE=$(echo "$OUTPUT" | grep "{" | jq -r .returns.exchange.value) | ||
| echo "Exchange deployed: $EXCHANGE" | ||
| # Check the exit status of the forge script command | ||
| if [ $? -ne 0 ]; then | ||
| echo "--- DEPLOYMENT FAILED ---" | ||
| # Print the full output (including error messages) | ||
| echo "$OUTPUT" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # --- RESULT PARSING --- | ||
|
|
||
| # Extract the deployed address using jq from the raw JSON output. | ||
| # Filtering through "grep {" is unnecessary as we expect JSON output. | ||
| EXCHANGE=$(echo "$OUTPUT" | jq -r '.returns.exchange.value') | ||
|
|
||
| echo "Complete!" | ||
| if [ -z "$EXCHANGE" ]; then | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Null value not detected in exchange address validationThe validation checks if |
||
| echo "Error: Failed to parse deployed exchange address from JSON output." | ||
| echo "Full Forge Output:" | ||
| echo "$OUTPUT" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "--- DEPLOYMENT SUCCESS ---" | ||
| echo "Exchange deployed: $EXCHANGE" | ||
| echo "--- Complete! ---" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Mainnet environment file renamed breaks existing deployments
The mainnet environment file was renamed from
.envto.env.mainnet, breaking existing deployments. Users with the previously expected.envfile will encounter a "file not found" error when deploying to mainnet, as the script now looks for.env.mainnetinstead.