-
Notifications
You must be signed in to change notification settings - Fork 158
Update deploy_exchange.sh #15
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
AfuroIsCrazy
wants to merge
1
commit into
Polymarket:main
Choose a base branch
from
AfuroIsCrazy: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,83 @@ | ||
| #!/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 | ||
| # File paths for environment variables | ||
| LOCAL_ENV=".env.local" | ||
| TESTNET_ENV=".env.testnet" | ||
| MAINNET_ENV=".env" | ||
|
|
||
| # --- 1. Argument and Environment Selection --- | ||
| if [ -z "$1" ]; then | ||
| 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 argument '$1'." | ||
| echo "Usage: deploy_exchange.sh [local | testnet | mainnet]" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
| if [ ! -f "$ENV_FILE" ]; then | ||
| echo "Error: Environment file '$ENV_FILE' not found." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Deploying CTF Exchange..." | ||
| # CRITICAL SECURITY WARNING: Sourcing private keys directly from environment files | ||
| # is highly insecure. For production, use hardware wallets (Ledger/Trezor) or | ||
| # dedicated secrets management services (e.g., AWS KMS, Azure Key Vault) via Foundry. | ||
| source "$ENV_FILE" | ||
|
|
||
| echo "Deploy args: | ||
| echo "Deploying CTF Exchange to $1 network..." | ||
|
|
||
| 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 \ | ||
| # --- 2. Optimized Foundry Command --- | ||
| 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)" | ||
| --slow # Use --slow to rely on the RPC URL for fetching dynamic gas price, or remove to rely on default EIP-1559 | ||
|
|
||
| EXCHANGE=$(echo "$OUTPUT" | grep "{" | jq -r .returns.exchange.value) | ||
| echo "Exchange deployed: $EXCHANGE" | ||
| # Removed: --with-gas-price 200000000000 to use dynamic gas price from RPC | ||
| # If EIP-1559 is supported, Foundry automatically uses it. | ||
| # If legacy pricing is needed for non-EIP-1559 chains (e.g., Polygon pre-London), use: | ||
| # --gas-price $(cast gas-price --rpc-url $RPC_URL) | ||
|
|
||
| -s "deployExchange(address,address,address,address,address)" "$ADMIN" "$COLLATERAL" "$CTF" "$PROXY_FACTORY" "$SAFE_FACTORY" | ||
| ) | ||
|
|
||
| echo "Complete!" | ||
| # --- 3. Process Output (Requires 'jq') --- | ||
| # Extracting the deployed contract address from the JSON output | ||
| EXCHANGE=$(echo "$OUTPUT" | jq -r ' | ||
| .transactions[] | | ||
| select(.transactionType == "CREATE" and .contractName == "CTFExchange") | | ||
| .contractAddress | ||
| ') | ||
|
|
||
| if [ -z "$EXCHANGE" ]; then | ||
| echo "Error: Deployment failed or could not retrieve contract address." | ||
| echo "Full Forge Output:" | ||
| echo "$OUTPUT" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Exchange deployed: $EXCHANGE" | ||
| echo "Deployment 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: Missing line continuation breaks forge script command
The forge script command line continuation is broken. Line 57 ends with
--slow # commentwithout a backslash, which terminates the command prematurely instead of continuing to the-sflag on line 65. This causes the deployment to fail because the actual script function and its arguments are never executed.