deploy.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 "=========== Building dependencies ==========="
  14. npx lerna run build --scope="@pythnetwork/pyth-evm-contract" --include-dependencies
  15. echo "=========== Compiling ==========="
  16. if [[ -e contracts/pyth/PythUpgradable_merged.sol ]]; then
  17. echo "Flattened contract PythUpgradable_merged.sol exists. Removing before compiling."
  18. rm contracts/pyth/PythUpgradable_merged.sol
  19. fi
  20. echo "Building the contract..."
  21. # Ensure that we deploy a fresh build with up-to-date dependencies.
  22. rm -rf build && npx truffle compile --all
  23. echo "Adding network metadata to the contract"
  24. # Merge the network addresses into the artifacts, if some contracts are already deployed.
  25. npx apply-registry
  26. while [[ $# -ne 0 ]]; do
  27. NETWORK=$1
  28. shift
  29. echo "=========== Deploying to ${NETWORK} (if not deployed) ==========="
  30. # Load the configuration environment variables for deploying your network. make sure to use right env file.
  31. # If it is a new chain you are deploying to, create a new env file and commit it to the repo.
  32. if [[ $NETWORK != development ]]; then
  33. node create-env.js $NETWORK
  34. else
  35. echo "Skipping env file creation for development network"
  36. fi
  37. set -o allexport && source .env set && set +o allexport
  38. if [[ $NETWORK == zksync* ]]; then
  39. echo "Skipping truffle migration on $NETWORK. If you wish to deploy a fresh contract read Deploying.md."
  40. else
  41. echo "Migrating..."
  42. npx truffle migrate --network $MIGRATIONS_NETWORK --compile-none
  43. echo "Deployment to $NETWORK finished successfully"
  44. fi
  45. done
  46. echo "=========== Finished ==========="