# trunk-ignore-all(yamllint/empty-values)
version: "3.8"

services:
  starknet:
    image: nethermind/juno:v0.11.1
    ports:
      - 6060:6060
    volumes:
      - juno_files_prod:/var/lib/juno
    command: >
      --pending-poll-interval "1s"
      --http
      --http-host 0.0.0.0
      --http-port 6060
      --db-path /var/lib/juno
      --eth-node ${ETH_NODE_WS}
      --cn-name kakarot-sepolia
      --cn-feeder-url https://gateway.kakarot.sw-dev.io/feeder_gateway/
      --cn-gateway-url https://gateway.kakarot.sw-dev.io/gateway/
      --cn-l1-chain-id 0xaa36a7
      --cn-l2-chain-id kkrt
      --cn-core-contract-address 0x74Ca1aC5BD4c3c97006d2B7b9375Dd3B6C17ACcD
      --cn-unverifiable-range 0,1000000
    networks:
      - internal_prod
  starknet-explorer:
    image: public.ecr.aws/o5q6k5w4/stark_compass_explorer:latest
    ports:
      - 4000:4000
    environment:
      - PHX_HOST=localhost
      - PORT=4000
      - RPC_API_HOST=http://host.docker.internal_prod:6060
      - TESTNET_RPC_API_HOST=http://host.docker.internal_prod:6060
      - SEPOLIA_RPC_API_HOST=http://host.docker.internal_prod:6060
      - DISABLE_MAINNET_SYNC=true
      - DISABLE_SEPOLIA_SYNC=true
      - DATABASE_PATH=ecto://postgres:postgres@starknet-explorer-db:5432/starknet_explorer_dev
      - DB_TYPE=postgres
      - SECRET_KEY_BASE=JyULoT5cLBifW+XNEuCTVoAb+SaFgQt9j227RN0cKpR3wTsrApGd1HNcgeopemyl
      - ENABLE_LISTENER=true
    depends_on:
      starknet-explorer-db:
        condition: service_started
      starknet:
        condition: service_started
    extra_hosts:
      - host.docker.internal_prod:172.17.0.1
    networks:
      - internal_prod

  starknet-explorer-db:
    image: postgres:15.3
    ports:
      - 5432:5432
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=starknet_explorer_dev
      - PGDATA=/var/lib/postgresql/data/pgdata
    volumes:
      - starknet-explorer_prod:/var/lib/postgresql/data/

  kakarot-rpc:
    image: ghcr.io/kkrt-labs/kakarot-rpc/node:v0.6.20
    pull_policy: always
    ports:
      - 3030:3030
    environment:
      - KAKAROT_RPC_URL=0.0.0.0:3030
      - STARKNET_NETWORK=http://starknet:6060
      - RUST_LOG=kakarot_rpc=info
      - MONGO_CONNECTION_STRING=mongodb://mongo:mongo@mongo:27017
      - MONGO_DATABASE_NAME=kakarot-local
      # These values are unique to Sepolia Testnet
      # They'll need to be manually changed in case the testnet is reset
      # To add robustness: parse the `deployments/kakarot-sepolia` folder in `kkrt-labs/kakarot` repo
      - KAKAROT_ADDRESS=0x11c5faab8a76b3caff6e243b8d13059a7fb723a0ca12bbaadde95fb9e501bda
      - UNINITIALIZED_ACCOUNT_CLASS_HASH=0x600f6862938312a05a0cfecba0dcaf37693efc9e4075a6adfb62e196022678e
      - ACCOUNT_CONTRACT_CLASS_HASH=0x1276d0b017701646f8646b69de6c3b3584edce71879678a679f28c07a9971cf
      - MAX_FELTS_IN_CALLDATA=30000
      - TRANSACTION_MAX_RETRIES=10
      - MAX_LOGS=10000
      - RETRY_TX_INTERVAL=10
      - WHITE_LISTED_EIP_155_TRANSACTION_HASHES=0xeddf9e61fb9d8f5111840daef55e5fde0041f5702856532cdbb5a02998033d26,0xb6274b80bc7cda162df89894c7748a5cb7ba2eaa6004183c41a1837c3b072f1e,0x07471adfe8f4ec553c1199f495be97fc8be8e0626ae307281c22534460184ed1,0xb95343413e459a0f97461812111254163ae53467855c0d73e0f1e7c5b8442fa3
    restart: on-failure
    volumes:
      # Mount the indexer code
      - indexer_code_prod:/usr/src/indexer
    depends_on:
      starknet:
        condition: service_started
    networks:
      - internal_prod

  apibara-dna:
    image: quay.io/apibara/starknet:1.5.0
    command:
      - start
      - --rpc=http://starknet:6060
      - --wait-for-rpc
      - --data=/data
      - --head-refresh-interval-ms=1000
    ports:
      - 7171:7171
    volumes:
      - apibara_prod:/data
    networks:
      - internal_prod
    restart: on-failure

  ### MongoDB with Mongo Express
  mongo:
    image: mongo:6.0.8
    restart: always
    ports:
      - 27017:27017
    volumes:
      - mongo_data_prod:/data/db
    networks:
      - internal_prod
    environment:
      MONGO_INITDB_ROOT_USERNAME: mongo
      MONGO_INITDB_ROOT_PASSWORD: mongo

  indexer:
    image: quay.io/apibara/sink-mongo:0.7.0
    command:
      - run
      - /indexer/src/main.ts
    environment:
      # Whitelist environment variables
      - ALLOW_ENV_FROM_ENV=DEBUG,APIBARA_AUTH_TOKEN,STARTING_BLOCK,STREAM_URL,SINK_TYPE,MONGO_CONNECTION_STRING,MONGO_DATABASE_NAME,STARKNET_NETWORK,KAKAROT_ADDRESS,ALLOW_NET,MONGO_REPLACE_DATA_INSIDE_TRANSACTION,DEFAULT_BLOCK_GAS_LIMIT
      - DEBUG=""
      - APIBARA_AUTH_TOKEN=""
      - MONGO_CONNECTION_STRING=mongodb://mongo:mongo@mongo:27017
      - MONGO_DATABASE_NAME=kakarot-local
      - STARTING_BLOCK=0
      - STREAM_URL=http://apibara-dna:7171
      - SINK_TYPE=mongo
      - STARKNET_NETWORK=http://starknet:6060
      - ALLOW_NET=
      - MONGO_REPLACE_DATA_INSIDE_TRANSACTION=false
      - KAKAROT_ADDRESS=0x11c5faab8a76b3caff6e243b8d13059a7fb723a0ca12bbaadde95fb9e501bda
      - DEFAULT_BLOCK_GAS_LIMIT=7000000
    restart: on-failure
    volumes:
      - indexer_code_prod:/indexer
    networks:
      - internal_prod
    depends_on:
      starknet:
        condition: service_started

networks:
  internal_prod:
    driver: bridge
  default:
    driver: bridge
  close:
    driver: bridge

volumes:
  apibara_prod:
  mongo_data_prod:
  indexer_code_prod:
  pgadmin_data_prod:
  juno_files_prod:
  starknet-explorer_prod: