deploy.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. # The channel to use for the price sources. Can be `stable` or `beta`.
  27. export CHANNEL=stable
  28. while [[ $# -ne 0 ]]; do
  29. NETWORK=$1
  30. shift
  31. echo "=========== Deploying to ${NETWORK} (if not deployed) ==========="
  32. # Load the configuration environment variables for deploying your network. make sure to use right env file.
  33. # If it is a new chain you are deploying to, create a new env file and commit it to the repo.
  34. if [[ $NETWORK != development ]]; then
  35. node create-env.js $NETWORK
  36. else
  37. echo "Skipping env file creation for development network"
  38. fi
  39. set -o allexport && source .env set && set +o allexport
  40. if [[ $NETWORK == zksync* ]]; then
  41. echo "Skipping truffle migration on $NETWORK. If you wish to deploy a fresh contract read Deploying.md."
  42. else
  43. echo "Migrating..."
  44. npx truffle migrate --network $MIGRATIONS_NETWORK --compile-none
  45. echo "Deployment to $NETWORK finished successfully"
  46. fi
  47. if [[ $CHANNEL == stable ]]; then
  48. echo "=========== Syncing guardian sets to ${NETWORK} ==========="
  49. npm run receiver-submit-guardian-sets -- --network $NETWORK
  50. fi
  51. done
  52. echo "=========== Finished ==========="