version: "3.4"

services:
  # this is a helper service used because there's no official hardhat image
  l1_chain:
    image: ethereumoptimism/hardhat:${DOCKER_TAG:-latest}
    build:
      context: ./docker/hardhat
      dockerfile: Dockerfile
    env_file:
      -  ./envs/l1_chain.env
    ports:
        # expose the service to the host for integration testing
      - ${L1CHAIN_HTTP_PORT:-9545}:8545

  deployer:
    depends_on:
      - l1_chain
    build:
      context: ..
      dockerfile: ./ops/docker/Dockerfile.packages
      target: deployer
    entrypoint: ./deployer.sh
    environment:
      # Env vars for the deployment script.
      CONTRACTS_RPC_URL: http://l1_chain:8545
      CONTRACTS_DEPLOYER_KEY: "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
      CONTRACTS_TARGET_NETWORK: "custom"
      OVM_ADDRESS_MANAGER_OWNER: "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
      OVM_PROPOSER_ADDRESS: "0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc"
      OVM_SEQUENCER_ADDRESS: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8"
      SCC_FRAUD_PROOF_WINDOW: 0
      NUM_DEPLOY_CONFIRMATIONS: 0
      # skip compilation when run in docker-compose, since the contracts
      # were already compiled in the builder step
      NO_COMPILE: 1

      # Env vars for the dump script.
      # Default hardhat account 5
      GAS_PRICE_ORACLE_OWNER: "0x9965507d1a55bcc2695c58ba16fb37d819b0a4dc"
      # setting the whitelist owner to address(0) disables the whitelist
      WHITELIST_OWNER: "0x0000000000000000000000000000000000000000"
      L1_FEE_WALLET_ADDRESS: "0x391716d440c151c42cdf1c95c1d83a5427bca52c"
      L2_CHAIN_ID: 420
      L2_BLOCK_GAS_LIMIT: 15000000
      BLOCK_SIGNER_ADDRESS: "0x00000398232E2064F896018496b4b44b3D62751F"
      GAS_PRICE_ORACLE_OVERHEAD: 2750
      GAS_PRICE_ORACLE_SCALAR: 1500000
      GAS_PRICE_ORACLE_L1_BASE_FEE: 1
      GAS_PRICE_ORACLE_GAS_PRICE: 1
      GAS_PRICE_ORACLE_DECIMALS: 6
    ports:
        # expose the service to the host for getting the contract addrs
      - ${DEPLOYER_PORT:-8080}:8081

  dtl:
    depends_on:
      - l1_chain
      - deployer
      - l2geth
    build:
      context: ..
      dockerfile: ./ops/docker/Dockerfile.packages
      target: data-transport-layer
    # override with the dtl script and the env vars required for it
    entrypoint: ./dtl.sh
    env_file:
      -  ./envs/dtl.env
    # set the rest of the env vars for the network whcih do not
    # depend on the docker-compose setup
    environment:
        # used for setting the address manager address
        URL: http://deployer:8081/addresses.json
        # connect to the 2 layers
        DATA_TRANSPORT_LAYER__L1_RPC_ENDPOINT: http://l1_chain:8545
        DATA_TRANSPORT_LAYER__L2_RPC_ENDPOINT: http://l2geth:8545
        DATA_TRANSPORT_LAYER__SYNC_FROM_L2: 'true'
        DATA_TRANSPORT_LAYER__L2_CHAIN_ID: 420
    ports:
      - ${DTL_PORT:-7878}:7878

  l2geth:
    depends_on:
      - l1_chain
      - deployer
    build:
      context: ..
      dockerfile: ./ops/docker/Dockerfile.geth
    # override with the geth script and the env vars required for it
    entrypoint: sh ./geth.sh
    env_file:
      - ./envs/geth.env
    environment:
        ETH1_HTTP: http://l1_chain:8545
        ROLLUP_TIMESTAMP_REFRESH: 5s
        ROLLUP_STATE_DUMP_PATH: http://deployer:8081/state-dump.latest.json
        # connecting to the DTL
        ROLLUP_CLIENT_HTTP: http://dtl:7878
        ETH1_CTC_DEPLOYMENT_HEIGHT: 8
        RETRIES: 60
        # no need to keep this secret, only used internally to sign blocks
        BLOCK_SIGNER_KEY: "6587ae678cf4fc9a33000cdbf9f35226b71dcc6a4684a31203241f9bcfd55d27"
        BLOCK_SIGNER_ADDRESS: "0x00000398232E2064F896018496b4b44b3D62751F"
    ports:
      - ${L2GETH_HTTP_PORT:-8545}:8545
      - ${L2GETH_WS_PORT:-8546}:8546

  relayer:
    depends_on:
      - l1_chain
      - deployer
      - l2geth
    deploy:
      replicas: 0
    build:
      context: ..
      dockerfile: ./ops/docker/Dockerfile.packages
      target: relayer
    entrypoint: ./relayer.sh
    environment:
        L1_NODE_WEB3_URL: http://l1_chain:8545
        L2_NODE_WEB3_URL: http://l2geth:8545
        URL: http://deployer:8081/addresses.json
        # a funded hardhat account
        L1_WALLET_KEY: "0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97"
        RETRIES: 60
        POLLING_INTERVAL: 500
        GET_LOGS_INTERVAL: 500

  verifier:
    depends_on:
      - l1_chain
      - deployer
      - dtl
    deploy:
      replicas: 0
    build:
      context: ..
      dockerfile: ./ops/docker/Dockerfile.geth
    entrypoint: sh ./geth.sh
    env_file:
      - ./envs/geth.env
    environment:
        ETH1_HTTP: http://l1_chain:8545
        ROLLUP_STATE_DUMP_PATH: http://deployer:8081/state-dump.latest.json
        ROLLUP_CLIENT_HTTP: http://dtl:7878
        ROLLUP_BACKEND: 'l1'
        ETH1_CTC_DEPLOYMENT_HEIGHT: 8
        RETRIES: 60
        ROLLUP_VERIFIER_ENABLE: 'true'
    ports:
      - ${VERIFIER_HTTP_PORT:-8547}:8545
      - ${VERIFIER_WS_PORT:-8548}:8546

  replica:
    depends_on:
      - dtl
    deploy:
      replicas: 1
    build:
      context: ..
      dockerfile: ./ops/docker/Dockerfile.geth
    entrypoint: sh ./geth.sh
    env_file:
      - ./envs/geth.env
    environment:
        ETH1_HTTP: http://l1_chain:8545
        ROLLUP_STATE_DUMP_PATH: http://deployer:8081/state-dump.latest.json
        ROLLUP_CLIENT_HTTP: http://dtl:7878
        ROLLUP_BACKEND: 'l2'
        ROLLUP_VERIFIER_ENABLE: 'true'
        ETH1_CTC_DEPLOYMENT_HEIGHT: 8
        RETRIES: 60
    ports:
      - ${REPLICA_HTTP_PORT:-8549}:8545
      - ${REPLICA_WS_PORT:-8550}:8546

  integration_tests:
    deploy:
       replicas: 0
    build:
      context: ..
      dockerfile: ./ops/docker/Dockerfile.packages
      target: integration-tests
    entrypoint: ./integration-tests.sh
    environment:
      L1_URL: http://l1_chain:8545
      L2_URL: http://l2geth:8545
      REPLICA_URL: http://replica:8545
      VERIFIER_URL: http://verifier:8545
      URL: http://deployer:8081/addresses.json
      ENABLE_GAS_REPORT: 1
      NO_NETWORK: 1

  gas_oracle:
    deploy:
       replicas: 0
    build:
      context: ..
      dockerfile: ./ops/docker/Dockerfile.gas-oracle
    entrypoint: ./gas-oracle.sh
    environment:
      GAS_PRICE_ORACLE_ETHEREUM_HTTP_URL: http://l2geth:8545
      # Default hardhat account 5
      GAS_PRICE_ORACLE_PRIVATE_KEY: "0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba"
