---          
apiVersion: v1
kind: Service
metadata:
  name: {{ .NAME }}-eth
  namespace: {{ .NAMESPACE }}
  labels:
    app: {{ .NAME }}-eth
spec:
  selector:
    app: {{ .NAME }}-eth
  ports:
    - port: {{ .PORT }}
      targetPort: {{ .PORT }}
      name: {{ .NAME }}-eth
      protocol: TCP
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: blockchain-watcher-eth-pvc
  namespace: {{ .NAMESPACE }}
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Mi
  storageClassName: gp2
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .NAME }}-eth-jobs
  namespace: {{ .NAMESPACE }}
data:
  testnet-jobs.json: |-
    [
      {
        "id": "poll-log-message-published-ethereum",
        "chain": "ethereum",
        "source": {
          "action": "PollEvm",
          "config": {
            "fromBlock": "10012499",
            "blockBatchSize": 100,
            "commitment": "latest",
            "interval": 15000,
            "addresses": ["0x706abc4E45D419950511e474C7B9Ed348A4a716c"],
            "chain": "ethereum"
          }
        },
        "handlers": [
          {
            "action": "HandleEvmLogs",
            "target": "sns",
            "mapper": "evmLogMessagePublishedMapper",
            "config": {
              "abi": "event LogMessagePublished(address indexed sender, uint64 sequence, uint32 nonce, bytes payload, uint8 consistencyLevel)",
              "filter": {
                "addresses": ["0x706abc4E45D419950511e474C7B9Ed348A4a716c"],
                "topics": ["0x6eb224fb001ed210e379b335e35efe88672a8ce935d981a6896b27ffdf52a3b2"]
              }
            }
          }
        ]
      },
      {
        "id": "poll-log-message-published-karura",
        "chain": "karura",
        "source": {
            "action": "PollEvm",
            "config": {
                "blockBatchSize": 100,
                "commitment": "finalized",
                "interval": 15000,
                "addresses": [
                    "0xE4eacc10990ba3308DdCC72d985f2a27D20c7d03"
                ],
                "chain": "karura"
            }
        },
        "handlers": [
            {
                "action": "HandleEvmLogs",
                "target": "sns",
                "mapper": "evmLogMessagePublishedMapper",
                "config": {
                    "abi": "event LogMessagePublished(address indexed sender, uint64 sequence, uint32 nonce, bytes payload, uint8 consistencyLevel)",
                    "filter": {
                        "addresses": [
                            "0xE4eacc10990ba3308DdCC72d985f2a27D20c7d03"
                        ],
                        "topics": [
                            "0x6eb224fb001ed210e379b335e35efe88672a8ce935d981a6896b27ffdf52a3b2"
                        ]
                    }
                }
            }
        ]
      },
      {
        "id": "poll-log-message-published-fantom",
        "chain": "fantom",
        "source": {
            "action": "PollEvm",
            "config": {
                "blockBatchSize": 100,
                "commitment": "latest",
                "interval": 15000,
                "addresses": [
                    "0x1BB3B4119b7BA9dfad76B0545fb3F531383c3bB7"
                ],
                "chain": "fantom"
            }
        },
        "handlers": [
            {
                "action": "HandleEvmLogs",
                "target": "sns",
                "mapper": "evmLogMessagePublishedMapper",
                "config": {
                    "abi": "event LogMessagePublished(address indexed sender, uint64 sequence, uint32 nonce, bytes payload, uint8 consistencyLevel)",
                    "filter": {
                        "addresses": [
                            "0x1BB3B4119b7BA9dfad76B0545fb3F531383c3bB7"
                        ],
                        "topics": [
                            "0x6eb224fb001ed210e379b335e35efe88672a8ce935d981a6896b27ffdf52a3b2"
                        ]
                    }
                }
            }
        ]
      },
      {
        "id": "poll-log-message-published-acala",
        "chain": "acala",
        "source": {
            "action": "PollEvm",
            "config": {
                "blockBatchSize": 100,
                "commitment": "finalized",
                "interval": 15000,
                "addresses": [
                    "0x4377B49d559c0a9466477195C6AdC3D433e265c0"
                ],
                "chain": "acala"
            }
        },
        "handlers": [
            {
                "action": "HandleEvmLogs",
                "target": "sns",
                "mapper": "evmLogMessagePublishedMapper",
                "config": {
                    "abi": "event LogMessagePublished(address indexed sender, uint64 sequence, uint32 nonce, bytes payload, uint8 consistencyLevel)",
                    "filter": {
                        "addresses": [
                            "0x4377B49d559c0a9466477195C6AdC3D433e265c0"
                        ],
                        "topics": [
                            "0x6eb224fb001ed210e379b335e35efe88672a8ce935d981a6896b27ffdf52a3b2"
                        ]
                    }
                }
            }
        ]
      },
      {
        "id": "poll-log-message-published-avalanche",
        "chain": "avalanche",
        "source": {
            "action": "PollEvm",
            "config": {
                "blockBatchSize": 100,
                "commitment": "finalized",
                "interval": 15000,
                "addresses": [
                    "0x7bbcE28e64B3F8b84d876Ab298393c38ad7aac4C"
                ],
                "chain": "avalanche",
                "topics": []
            }
        },
        "handlers": [
            {
                "action": "HandleEvmLogs",
                "target": "sns",
                "mapper": "evmLogMessagePublishedMapper",
                "config": {
                    "abi": "event LogMessagePublished(address indexed sender, uint64 sequence, uint32 nonce, bytes payload, uint8 consistencyLevel)",
                    "filter": {
                        "addresses": [
                            "0x7bbcE28e64B3F8b84d876Ab298393c38ad7aac4C"
                        ],
                        "topics": [
                            "0x6eb224fb001ed210e379b335e35efe88672a8ce935d981a6896b27ffdf52a3b2"
                        ]
                    }
                }
            }
        ]
      },
      {
        "id": "poll-log-message-published-bsc",
        "chain": "bsc",
        "source": {
          "action": "PollEvm",
          "config": {
            "blockBatchSize": 100,
            "commitment": "latest",
            "interval": 15000,
            "addresses": ["0x68605AD7b15c732a30b1BbC62BE8F2A509D74b4D"],
            "chain": "bsc"
          }
        },
        "handlers": [
          {
            "action": "HandleEvmLogs",
            "target": "sns",
            "mapper": "evmLogMessagePublishedMapper",
            "config": {
              "abi": "event LogMessagePublished(address indexed sender, uint64 sequence, uint32 nonce, bytes payload, uint8 consistencyLevel)",
              "filter": {
                "addresses": ["0x68605AD7b15c732a30b1BbC62BE8F2A509D74b4D"],
                "topics": ["0x6eb224fb001ed210e379b335e35efe88672a8ce935d981a6896b27ffdf52a3b2"]
              }
            }
          }
        ]
      },
      {
        "id": "poll-log-message-published-moonbeam",
        "chain": "moonbeam",
        "source": {
          "action": "PollEvm",
          "config": {
            "blockBatchSize": 100,
            "commitment": "latest",
            "interval": 15000,
            "addresses": ["0xa5B7D85a8f27dd7907dc8FdC21FA5657D5E2F901"],
            "chain": "moonbeam"
          }
        },
        "handlers": [
          {
            "action": "HandleEvmLogs",
            "target": "sns",
            "mapper": "evmLogMessagePublishedMapper",
            "config": {
              "abi": "event LogMessagePublished(address indexed sender, uint64 sequence, uint32 nonce, bytes payload, uint8 consistencyLevel)",
              "filter": {
                "addresses": ["0xa5B7D85a8f27dd7907dc8FdC21FA5657D5E2F901"],
                "topics": ["0x6eb224fb001ed210e379b335e35efe88672a8ce935d981a6896b27ffdf52a3b2"]
              }
            }
          }
        ]
      }
    ]
  mainnet-jobs.json: |-
    [
      {
        "id": "poll-log-message-published-ethereum",
        "chain": "ethereum",
        "source": {
          "action": "PollEvm",
          "config": {
            "blockBatchSize": 100,
            "commitment": "latest",
            "interval": 15000,
            "addresses": ["0x98f3c9e6E3fAce36bAAd05FE09d375Ef1464288B", "0x27428dd2d3dd32a4d7f7c497eaaa23130d894911", "0x3ee18b2214aff97000d974cf647e7c347e8fa585"],
            "chain": "ethereum"
          }
        },
        "handlers": [
          {
            "action": "HandleEvmLogs",
            "target": "sns",
            "mapper": "evmLogMessagePublishedMapper",
            "config": {
              "abi": "event LogMessagePublished(address indexed sender, uint64 sequence, uint32 nonce, bytes payload, uint8 consistencyLevel)",
              "filter": {
                "addresses": ["0x98f3c9e6E3fAce36bAAd05FE09d375Ef1464288B"],
                "topics": ["0x6eb224fb001ed210e379b335e35efe88672a8ce935d981a6896b27ffdf52a3b2"]
              }
            }
          }
        ]
      },
      {
        "id": "poll-log-message-published-karura",
        "chain": "karura",
        "source": {
            "action": "PollEvm",
            "config": {
                "blockBatchSize": 100,
                "commitment": "finalized",
                "interval": 5000,
                "addresses": [
                    "0xa321448d90d4e5b0A732867c18eA198e75CAC48E"
                ],
                "chain": "karura"
            }
        },
        "handlers": [
            {
                "action": "HandleEvmLogs",
                "target": "sns",
                "mapper": "evmLogMessagePublishedMapper",
                "config": {
                    "abi": "event LogMessagePublished(address indexed sender, uint64 sequence, uint32 nonce, bytes payload, uint8 consistencyLevel)",
                    "filter": {
                        "addresses": [
                            "0xa321448d90d4e5b0A732867c18eA198e75CAC48E"
                        ],
                        "topics": [
                            "0x6eb224fb001ed210e379b335e35efe88672a8ce935d981a6896b27ffdf52a3b2"
                        ]
                    }
                }
            }
        ]
      },
      {
        "id": "poll-log-message-published-fantom",
        "chain": "fantom",
        "source": {
            "action": "PollEvm",
            "config": {
                "blockBatchSize": 100,
                "commitment": "latest",
                "interval": 5000,
                "addresses": [
                    "0x126783A6Cb203a3E35344528B26ca3a0489a1485"
                ],
                "chain": "fantom"
            }
        },
        "handlers": [
            {
                "action": "HandleEvmLogs",
                "target": "sns",
                "mapper": "evmLogMessagePublishedMapper",
                "config": {
                    "abi": "event LogMessagePublished(address indexed sender, uint64 sequence, uint32 nonce, bytes payload, uint8 consistencyLevel)",
                    "filter": {
                        "addresses": [
                            "0x126783A6Cb203a3E35344528B26ca3a0489a1485"
                        ],
                        "topics": [
                            "0x6eb224fb001ed210e379b335e35efe88672a8ce935d981a6896b27ffdf52a3b2"
                        ]
                    }
                }
            }
        ]
      },
      {
        "id": "poll-log-message-published-acala",
        "chain": "acala",
        "source": {
            "action": "PollEvm",
            "config": {
                "blockBatchSize": 100,
                "commitment": "finalized",
                "interval": 5000,
                "addresses": [
                    "0xa321448d90d4e5b0A732867c18eA198e75CAC48E"
                ],
                "chain": "acala"
            }
        },
        "handlers": [
            {
                "action": "HandleEvmLogs",
                "target": "sns",
                "mapper": "evmLogMessagePublishedMapper",
                "config": {
                    "abi": "event LogMessagePublished(address indexed sender, uint64 sequence, uint32 nonce, bytes payload, uint8 consistencyLevel)",
                    "filter": {
                        "addresses": [
                            "0xa321448d90d4e5b0A732867c18eA198e75CAC48E"
                        ],
                        "topics": [
                            "0x6eb224fb001ed210e379b335e35efe88672a8ce935d981a6896b27ffdf52a3b2"
                        ]
                    }
                }
            }
        ]
      },
      {
        "id": "poll-log-message-published-avalanche",
        "chain": "avalanche",
        "source": {
            "action": "PollEvm",
            "config": {
                "blockBatchSize": 100,
                "commitment": "finalized",
                "interval": 5000,
                "addresses": [
                    "0x54a8e5f9c4CbA08F9943965859F6c34eAF03E26c"
                ],
                "chain": "avalanche",
                "topics": []
            }
        },
        "handlers": [
            {
                "action": "HandleEvmLogs",
                "target": "sns",
                "mapper": "evmLogMessagePublishedMapper",
                "config": {
                    "abi": "event LogMessagePublished(address indexed sender, uint64 sequence, uint32 nonce, bytes payload, uint8 consistencyLevel)",
                    "filter": {
                        "addresses": [
                            "0x54a8e5f9c4CbA08F9943965859F6c34eAF03E26c"
                        ],
                        "topics": [
                            "0x6eb224fb001ed210e379b335e35efe88672a8ce935d981a6896b27ffdf52a3b2"
                        ]
                    }
                }
            }
        ]
      },
      {
        "id": "poll-log-message-published-bsc",
        "chain": "bsc",
        "source": {
          "action": "PollEvm",
          "config": {
            "blockBatchSize": 100,
            "commitment": "latest",
            "interval": 5000,
            "addresses": ["0x98f3c9e6E3fAce36bAAd05FE09d375Ef1464288B"],
            "chain": "bsc"
          }
        },
        "handlers": [
          {
            "action": "HandleEvmLogs",
            "target": "sns",
            "mapper": "evmLogMessagePublishedMapper",
            "config": {
              "abi": "event LogMessagePublished(address indexed sender, uint64 sequence, uint32 nonce, bytes payload, uint8 consistencyLevel)",
              "filter": {
                "addresses": ["0x98f3c9e6E3fAce36bAAd05FE09d375Ef1464288B"],
                "topics": ["0x6eb224fb001ed210e379b335e35efe88672a8ce935d981a6896b27ffdf52a3b2"]
              }
            }
          }
        ]
      },
      {
        "id": "poll-log-message-published-moonbeam",
        "chain": "moonbeam",
        "source": {
          "action": "PollEvm",
          "config": {
            "blockBatchSize": 100,
            "commitment": "latest",
            "interval": 5000,
            "addresses": ["0xC8e2b0cD52Cf01b0Ce87d389Daa3d414d4cE29f3"],
            "chain": "moonbeam"
          }
        },
        "handlers": [
          {
            "action": "HandleEvmLogs",
            "target": "sns",
            "mapper": "evmLogMessagePublishedMapper",
            "config": {
              "abi": "event LogMessagePublished(address indexed sender, uint64 sequence, uint32 nonce, bytes payload, uint8 consistencyLevel)",
              "filter": {
                "addresses": ["0xC8e2b0cD52Cf01b0Ce87d389Daa3d414d4cE29f3"],
                "topics": ["0x6eb224fb001ed210e379b335e35efe88672a8ce935d981a6896b27ffdf52a3b2"]
              }
            }
          }
        ]
      }
    ]
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .NAME }}-eth
  namespace: {{ .NAMESPACE }}
spec:
  replicas: 1
  selector:
    matchLabels:
      app: {{ .NAME }}-eth
  template:
    metadata:
      labels:
        app: {{ .NAME }}-eth
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "{{ .PORT }}"
    spec:
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      serviceAccountName: event-watcher
      containers:
        - name: {{ .NAME }}
          image: {{ .IMAGE_NAME }}
          env:
            - name: NODE_ENV
              value: {{ .NODE_ENV }}
            - name: PORT
              value: "{{ .PORT }}"
            - name: LOG_LEVEL
              value: {{ .LOG_LEVEL }}
            - name: BLOCKCHAIN_ENV
              value: {{ .BLOCKCHAIN_ENV }}
            - name: DRY_RUN_ENABLED
              value: "{{ .DRY_RUN_ENABLED }}"
            - name: SNS_TOPIC_ARN
              value: {{ .SNS_TOPIC_ARN }}
            - name: SNS_REGION
              value: {{ .SNS_REGION }}
            - name: JOBS_DIR
              value: /home/node/app/jobs
            {{ if .FANTOM_RPCS }}
            - name: FANTOM_RPCS
              value: '{{ .FANTOM_RPCS }}'
            {{ end }}
          resources:
            limits:
              memory: {{ .RESOURCES_LIMITS_MEMORY }}
              cpu: {{ .RESOURCES_LIMITS_CPU }}
            requests:
              memory: {{ .RESOURCES_REQUESTS_MEMORY }}
              cpu: {{ .RESOURCES_REQUESTS_CPU }}
          volumeMounts:
            - name: metadata-volume
              mountPath: /home/node/app/metadata-repo 
            - name: jobs-volume
              mountPath: /home/node/app/jobs
      volumes:
        - name: metadata-volume
          persistentVolumeClaim:
            claimName: blockchain-watcher-eth-pvc
        - name: jobs-volume
          configMap:
            name: {{ .NAME }}-eth-jobs
            items:
              - key: {{ .BLOCKCHAIN_ENV }}-jobs.json
                path: jobs.json
