deploy.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. #
  3. # This script deploys changes to given networks. Usage:
  4. # $ ./deploy.sh <network_a> <network_a> <...>
  5. # Network names are defined in `truffle-config.js`.
  6. #
  7. # Example: Deploying to some testnet networks
  8. # $ ./deploy.sh bnb_testnet fantom_testnet mumbai
  9. #
  10. # Example: Deploying to some mainnet networks
  11. # $ ./deploy.sh ethereum bnb avalanche
  12. set -euo pipefail
  13. echo "=========== Compiling ==========="
  14. echo "Building the contract..."
  15. # Ensure that we deploy a fresh build with up-to-date dependencies.
  16. rm -rf build && npx truffle compile --all
  17. echo "Adding network metadata to the contract"
  18. # Merge the network addresses into the artifacts, if some contracts are already deployed.
  19. npx apply-registry
  20. while [[ $# -ne 0 ]]; do
  21. NETWORK=$1
  22. shift
  23. echo "=========== Deploying to ${NETWORK} (if not deployed) ==========="
  24. # Load the configuration environment variables for deploying your network. make sure to use right env file.
  25. # If it is a new chain you are deploying to, create a new env file and commit it to the repo.
  26. rm -f .env; ln -s .env.prod.$NETWORK .env && set -o allexport && source .env set && set +o allexport
  27. if [[ $NETWORK == zksync* ]]; then
  28. echo "Skipping truffle migration on $NETWORK. If you wish to deploy a fresh contract read Deploying.md."
  29. else
  30. echo "Migrating..."
  31. npx truffle migrate --network $MIGRATIONS_NETWORK
  32. echo "Deployment to $NETWORK finished successfully"
  33. fi
  34. echo "=========== Syncing contract state ==========="
  35. npx truffle exec scripts/syncPythState.js --network $MIGRATIONS_NETWORK || echo "Syncing failed/incomplete.. skipping"
  36. done
  37. echo "=========== Finished ==========="