diff --git a/src/demo_etherlink/.dockerignore b/src/demo_etherlink/.dockerignore new file mode 100644 index 000000000..850106ba2 --- /dev/null +++ b/src/demo_etherlink/.dockerignore @@ -0,0 +1,22 @@ +# Ignore all +* + +# Add metadata and build files +!demo_etherlink +!pyproject.toml +!pdm.lock +!README.md + +# Add Python code +!**/*.py +**/.*_cache +**/__pycache__ + +# Add configs and scripts (but not env!) +!**/*.graphql +!**/*.json +!**/*.sql +!**/*.yaml +!**/*.yml +!**/*.j2 +!**/.keep \ No newline at end of file diff --git a/src/demo_etherlink/.gitignore b/src/demo_etherlink/.gitignore new file mode 100644 index 000000000..b7f4a9387 --- /dev/null +++ b/src/demo_etherlink/.gitignore @@ -0,0 +1,29 @@ +# Ignore all +* +!*/ + +# Add metadata and build files +!demo_etherlink +!.gitignore +!.dockerignore +!py.typed +!**/Dockerfile +!**/Makefile +!**/pyproject.toml +!**/pdm.lock +!**/README.md +!**/.keep + +# Add Python code +!**/*.py +**/.*_cache +**/__pycache__ + +# Add configs and scripts (but not env!) +!**/*.graphql +!**/*.json +!**/*.sql +!**/*.yaml +!**/*.yml +!**/*.j2 +!**/*.env.default \ No newline at end of file diff --git a/src/demo_etherlink/README.md b/src/demo_etherlink/README.md new file mode 100644 index 000000000..b833479b6 --- /dev/null +++ b/src/demo_etherlink/README.md @@ -0,0 +1,63 @@ +# demo_etherlink + +Indexing Etherlink smart rollup transactions + +## Installation + +This project is based on [DipDup](https://dipdup.io), a framework for building featureful dapps. + +You need a Linux/macOS system with Python 3.11 installed. Use our installer for easy setup: + +```shell +curl -Lsf https://dipdup.io/install.py | python3 +``` + +See the [Installation](https://dipdup.io/docs/installation) page for all options. + +## Usage + +Run the indexer in-memory: + +```shell +dipdup run +``` + +Store data in SQLite database: + +```shell +dipdup -c . -c configs/dipdup.sqlite.yml run +``` + +Or spawn a Compose stack: + +```shell +cd deploy +cp .env.default .env +# Edit .env file before running +docker-compose up +``` + +## Development setup + +We recommend [PDM](https://pdm.fming.dev/latest/) for managing Python projects. To set up the development environment: + +```shell +pdm install +$(pdm venv activate) +``` + +Some tools are included to help you keep the code quality high: black, ruff and mypy. Use scripts from the `pyproject.toml` to run checks manually or in CI: + +```shell +# Format code +pdm format + +# Lint code +pdm lint + +# Build Docker image +pdm image + +# Show all available scripts +pdm run --list +``` \ No newline at end of file diff --git a/demo_etherlink/__init__.py b/src/demo_etherlink/__init__.py similarity index 100% rename from demo_etherlink/__init__.py rename to src/demo_etherlink/__init__.py diff --git a/demo_etherlink/abi/.keep b/src/demo_etherlink/abi/.keep similarity index 100% rename from demo_etherlink/abi/.keep rename to src/demo_etherlink/abi/.keep diff --git a/demo_etherlink/configs/.keep b/src/demo_etherlink/configs/.keep similarity index 100% rename from demo_etherlink/configs/.keep rename to src/demo_etherlink/configs/.keep diff --git a/src/demo_etherlink/configs/dipdup.compose.yaml b/src/demo_etherlink/configs/dipdup.compose.yaml new file mode 100644 index 000000000..ff2b5e1a1 --- /dev/null +++ b/src/demo_etherlink/configs/dipdup.compose.yaml @@ -0,0 +1,20 @@ +database: + kind: postgres + host: ${POSTGRES_HOST:-db} + port: 5432 + user: ${POSTGRES_USER:-dipdup} + password: ${POSTGRES_PASSWORD} + database: ${POSTGRES_DB:-dipdup} + +hasura: + url: http://${HASURA_HOST:-hasura}:8080 + admin_secret: ${HASURA_SECRET} + allow_aggregations: true + camel_case: true + +sentry: + dsn: ${SENTRY_DSN:-""} + environment: ${SENTRY_ENVIRONMENT:-""} + +prometheus: + host: 0.0.0.0 \ No newline at end of file diff --git a/src/demo_etherlink/configs/dipdup.sqlite.yaml b/src/demo_etherlink/configs/dipdup.sqlite.yaml new file mode 100644 index 000000000..5c9e38187 --- /dev/null +++ b/src/demo_etherlink/configs/dipdup.sqlite.yaml @@ -0,0 +1,3 @@ +database: + kind: sqlite + path: ${SQLITE_PATH:-/tmp/demo_etherlink.sqlite} \ No newline at end of file diff --git a/src/demo_etherlink/configs/dipdup.swarm.yaml b/src/demo_etherlink/configs/dipdup.swarm.yaml new file mode 100644 index 000000000..2d77eda6c --- /dev/null +++ b/src/demo_etherlink/configs/dipdup.swarm.yaml @@ -0,0 +1,20 @@ +database: + kind: postgres + host: ${POSTGRES_HOST:-demo_etherlink_db} + port: 5432 + user: ${POSTGRES_USER:-dipdup} + password: ${POSTGRES_PASSWORD} + database: ${POSTGRES_DB:-dipdup} + +hasura: + url: http://${HASURA_HOST:-demo_etherlink_hasura}:8080 + admin_secret: ${HASURA_SECRET} + allow_aggregations: false + camel_case: true + +sentry: + dsn: ${SENTRY_DSN:-""} + environment: ${SENTRY_ENVIRONMENT:-""} + +prometheus: + host: 0.0.0.0 \ No newline at end of file diff --git a/src/demo_etherlink/configs/replay.yaml b/src/demo_etherlink/configs/replay.yaml new file mode 100644 index 000000000..15ef61fb3 --- /dev/null +++ b/src/demo_etherlink/configs/replay.yaml @@ -0,0 +1,17 @@ +# To refresh existing project run `dipdup init --base --force` after modifying this file. +# To generate a new project from this replay run `dipdup new --replay `. +# +spec_version: 2.0 +replay: + dipdup_version: 7 + template: demo_etherlink + package: demo_etherlink + version: 0.0.1 + description: Indexing Etherlink smart rollup transactions + license: MIT + name: John Doe + email: john_doe@example.com + postgres_image: postgres:15 + postgres_data_path: /var/lib/postgresql/data + hasura_image: hasura/graphql-engine:latest + line_length: 120 diff --git a/src/demo_etherlink/demo_etherlink b/src/demo_etherlink/demo_etherlink new file mode 120000 index 000000000..945c9b46d --- /dev/null +++ b/src/demo_etherlink/demo_etherlink @@ -0,0 +1 @@ +. \ No newline at end of file diff --git a/src/demo_etherlink/deploy/.env.default b/src/demo_etherlink/deploy/.env.default new file mode 100644 index 000000000..554e48901 --- /dev/null +++ b/src/demo_etherlink/deploy/.env.default @@ -0,0 +1,12 @@ +# This env file was generated automatically by DipDup. Do not edit it! +# Create a copy with .env extension, fill it with your values and run DipDup with `--env-file` option. +# +HASURA_HOST=hasura +HASURA_SECRET= +POSTGRES_DB=dipdup +POSTGRES_HOST=db +POSTGRES_PASSWORD= +POSTGRES_USER=dipdup +SENTRY_DSN="" +SENTRY_ENVIRONMENT="" +TZKT_URL=https://api.tzkt.io diff --git a/demo_etherlink/deploy/.keep b/src/demo_etherlink/deploy/.keep similarity index 100% rename from demo_etherlink/deploy/.keep rename to src/demo_etherlink/deploy/.keep diff --git a/src/demo_etherlink/deploy/Dockerfile b/src/demo_etherlink/deploy/Dockerfile new file mode 100644 index 000000000..f6e8abe37 --- /dev/null +++ b/src/demo_etherlink/deploy/Dockerfile @@ -0,0 +1,9 @@ +FROM dipdup/dipdup:7 +# FROM ghcr.io/dipdup-io/dipdup:7 +# FROM ghcr.io/dipdup-io/dipdup:next + +# COPY --chown=dipdup pyproject.toml README.md . +# RUN pip install . + +COPY --chown=dipdup . demo_etherlink +WORKDIR demo_etherlink \ No newline at end of file diff --git a/src/demo_etherlink/deploy/compose.sqlite.yaml b/src/demo_etherlink/deploy/compose.sqlite.yaml new file mode 100644 index 000000000..497c58190 --- /dev/null +++ b/src/demo_etherlink/deploy/compose.sqlite.yaml @@ -0,0 +1,19 @@ +version: "3.8" +name: demo_etherlink + +services: + dipdup: + build: + context: .. + dockerfile: deploy/Dockerfile + command: ["-c", "dipdup.yaml", "-c", "configs/dipdup.sqlite.yaml", "run"] + restart: always + env_file: .env + ports: + - 46339 + - 9000 + volumes: + - sqlite:${SQLITE_PATH:-/tmp/demo_etherlink.sqlite} + +volumes: + sqlite: \ No newline at end of file diff --git a/src/demo_etherlink/deploy/compose.swarm.yaml b/src/demo_etherlink/deploy/compose.swarm.yaml new file mode 100644 index 000000000..72d7cb3b9 --- /dev/null +++ b/src/demo_etherlink/deploy/compose.swarm.yaml @@ -0,0 +1,92 @@ +version: "3.8" +name: demo_etherlink + +services: + dipdup: + image: ${IMAGE:-ghcr.io/dipdup-io/dipdup}:${TAG:-7} + depends_on: + - db + - hasura + command: ["-c", "dipdup.yaml", "-c", "configs/dipdup.swarm.yaml", "run"] + env_file: .env + networks: + - internal + - prometheus-private + deploy: + mode: replicated + replicas: ${INDEXER_ENABLED:-1} + labels: + - prometheus-job=${SERVICE} + - prometheus-port=8000 + placement: &placement + constraints: + - node.labels.${SERVICE} == true + logging: &logging + driver: "json-file" + options: + max-size: "10m" + max-file: "10" + tag: "\{\{.Name\}\}.\{\{.ImageID\}\}" + + db: + image: postgres:15 + volumes: + - db:/var/lib/postgresql/data + env_file: .env + environment: + - POSTGRES_USER=dipdup + - POSTGRES_DB=dipdup + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 10s + timeout: 5s + retries: 5 + networks: + - internal + deploy: + mode: replicated + replicas: 1 + placement: *placement + logging: *logging + + hasura: + image: hasura/graphql-engine:latest + depends_on: + - db + environment: + - HASURA_GRAPHQL_DATABASE_URL=postgres://dipdup:${POSTGRES_PASSWORD}@demo_etherlink_db:5432/dipdup + - HASURA_GRAPHQL_ADMIN_SECRET=${HASURA_SECRET} + - HASURA_GRAPHQL_ENABLE_CONSOLE=true + - HASURA_GRAPHQL_DEV_MODE=false + - HASURA_GRAPHQL_LOG_LEVEL=warn + - HASURA_GRAPHQL_ENABLE_TELEMETRY=false + - HASURA_GRAPHQL_UNAUTHORIZED_ROLE=user + - HASURA_GRAPHQL_STRINGIFY_NUMERIC_TYPES=true + networks: + - internal + - traefik-public + deploy: + mode: replicated + replicas: 1 + labels: + - traefik.enable=true + - traefik.http.services.${SERVICE}.loadbalancer.server.port=8080 + - "traefik.http.routers.${SERVICE}.rule=Host(`${HOST}`) && (PathPrefix(`/v1/graphql`) || PathPrefix(`/api/rest`))" + - traefik.http.routers.${SERVICE}.entrypoints=http,${INGRESS:-ingress} + - "traefik.http.routers.${SERVICE}-console.rule=Host(`${SERVICE}.${SWARM_ROOT_DOMAIN}`)" + - traefik.http.routers.${SERVICE}-console.entrypoints=https + - traefik.http.middlewares.${SERVICE}-console.headers.customrequestheaders.X-Hasura-Admin-Secret=${HASURA_SECRET} + - traefik.http.routers.${SERVICE}-console.middlewares=authelia@docker,${SERVICE}-console + placement: *placement + logging: *logging + +volumes: + db: + +networks: + internal: + traefik-public: + external: true + prometheus-private: + external: true \ No newline at end of file diff --git a/src/demo_etherlink/deploy/compose.yaml b/src/demo_etherlink/deploy/compose.yaml new file mode 100644 index 000000000..e08c04d87 --- /dev/null +++ b/src/demo_etherlink/deploy/compose.yaml @@ -0,0 +1,55 @@ +version: "3.8" +name: demo_etherlink + +services: + dipdup: + build: + context: .. + dockerfile: deploy/Dockerfile + restart: always + env_file: .env + ports: + - 46339 + - 9000 + command: ["-c", "dipdup.yaml", "-c", "configs/dipdup.compose.yaml", "run"] + depends_on: + - db + - hasura + + db: + image: postgres:15 + ports: + - 5432 + volumes: + - db:/var/lib/postgresql/data + restart: always + env_file: .env + environment: + - POSTGRES_USER=dipdup + - POSTGRES_DB=dipdup + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + healthcheck: + test: ["CMD-SHELL", "pg_isready -U dipdup"] + interval: 10s + timeout: 5s + retries: 5 + + hasura: + image: hasura/graphql-engine:latest + ports: + - 8080 + depends_on: + - db + restart: always + environment: + - HASURA_GRAPHQL_DATABASE_URL=postgres://dipdup:${POSTGRES_PASSWORD}@db:5432/dipdup + - HASURA_GRAPHQL_ADMIN_SECRET=${HASURA_SECRET} + - HASURA_GRAPHQL_ENABLE_CONSOLE=true + - HASURA_GRAPHQL_DEV_MODE=true + - HASURA_GRAPHQL_LOG_LEVEL=info + - HASURA_GRAPHQL_ENABLE_TELEMETRY=false + - HASURA_GRAPHQL_UNAUTHORIZED_ROLE=user + - HASURA_GRAPHQL_STRINGIFY_NUMERIC_TYPES=true + +volumes: + db: \ No newline at end of file diff --git a/src/demo_etherlink/deploy/sqlite.env.default b/src/demo_etherlink/deploy/sqlite.env.default new file mode 100644 index 000000000..b860d4dee --- /dev/null +++ b/src/demo_etherlink/deploy/sqlite.env.default @@ -0,0 +1,5 @@ +# This env file was generated automatically by DipDup. Do not edit it! +# Create a copy with .env extension, fill it with your values and run DipDup with `--env-file` option. +# +SQLITE_PATH=/tmp/demo_etherlink.sqlite +TZKT_URL=https://api.tzkt.io diff --git a/src/demo_etherlink/deploy/swarm.env.default b/src/demo_etherlink/deploy/swarm.env.default new file mode 100644 index 000000000..04d553878 --- /dev/null +++ b/src/demo_etherlink/deploy/swarm.env.default @@ -0,0 +1,12 @@ +# This env file was generated automatically by DipDup. Do not edit it! +# Create a copy with .env extension, fill it with your values and run DipDup with `--env-file` option. +# +HASURA_HOST=demo_etherlink_hasura +HASURA_SECRET= +POSTGRES_DB=dipdup +POSTGRES_HOST=demo_etherlink_db +POSTGRES_PASSWORD= +POSTGRES_USER=dipdup +SENTRY_DSN="" +SENTRY_ENVIRONMENT="" +TZKT_URL=https://api.tzkt.io diff --git a/dipdup.yaml b/src/demo_etherlink/dipdup.yaml similarity index 90% rename from dipdup.yaml rename to src/demo_etherlink/dipdup.yaml index b2a4d8d1f..67e36577f 100644 --- a/dipdup.yaml +++ b/src/demo_etherlink/dipdup.yaml @@ -1,6 +1,11 @@ spec_version: 2.0 package: demo_etherlink +datasources: + tzkt: + kind: tezos.tzkt + url: ${TZKT_URL:-https://api.tzkt.io} + contracts: controller: kind: tezos @@ -11,11 +16,6 @@ contracts: address: sr1SW7VtD6xbSAEoRk8LXewr3igfWjBx7FPB typename: rollup -datasources: - tzkt: - kind: tezos.tzkt - url: https://api.tzkt.io - indexes: rollup_operations: kind: tezos.tzkt.operations @@ -33,4 +33,4 @@ indexes: - type: transaction destination: rollup entrypoint: default - alias: rollup_default + alias: rollup_default \ No newline at end of file diff --git a/demo_etherlink/graphql/.keep b/src/demo_etherlink/graphql/.keep similarity index 100% rename from demo_etherlink/graphql/.keep rename to src/demo_etherlink/graphql/.keep diff --git a/demo_etherlink/handlers/.keep b/src/demo_etherlink/handlers/.keep similarity index 100% rename from demo_etherlink/handlers/.keep rename to src/demo_etherlink/handlers/.keep diff --git a/demo_etherlink/handlers/on_rollup_call.py b/src/demo_etherlink/handlers/on_rollup_call.py similarity index 74% rename from demo_etherlink/handlers/on_rollup_call.py rename to src/demo_etherlink/handlers/on_rollup_call.py index 6d6c736ab..9825ddc4d 100644 --- a/demo_etherlink/handlers/on_rollup_call.py +++ b/src/demo_etherlink/handlers/on_rollup_call.py @@ -11,4 +11,9 @@ async def on_rollup_call( controller_default: TzktTransaction[ControllerDefaultParameter, ControllerStorage], rollup_default: TzktTransaction[RollupDefaultParameter, RollupStorage], ) -> None: - ... \ No newline at end of file + ctx.logger.info( + 'Smart rollup %s has been called by contract %s with parameter %s', + rollup_default.data.target_address, + controller_default.data.target_address, + rollup_default.parameter.__root__, + ) \ No newline at end of file diff --git a/demo_etherlink/hasura/.keep b/src/demo_etherlink/hasura/.keep similarity index 100% rename from demo_etherlink/hasura/.keep rename to src/demo_etherlink/hasura/.keep diff --git a/demo_etherlink/hooks/.keep b/src/demo_etherlink/hooks/.keep similarity index 100% rename from demo_etherlink/hooks/.keep rename to src/demo_etherlink/hooks/.keep diff --git a/demo_etherlink/hooks/on_index_rollback.py b/src/demo_etherlink/hooks/on_index_rollback.py similarity index 100% rename from demo_etherlink/hooks/on_index_rollback.py rename to src/demo_etherlink/hooks/on_index_rollback.py diff --git a/demo_etherlink/hooks/on_reindex.py b/src/demo_etherlink/hooks/on_reindex.py similarity index 100% rename from demo_etherlink/hooks/on_reindex.py rename to src/demo_etherlink/hooks/on_reindex.py diff --git a/demo_etherlink/hooks/on_restart.py b/src/demo_etherlink/hooks/on_restart.py similarity index 100% rename from demo_etherlink/hooks/on_restart.py rename to src/demo_etherlink/hooks/on_restart.py diff --git a/demo_etherlink/hooks/on_synchronized.py b/src/demo_etherlink/hooks/on_synchronized.py similarity index 100% rename from demo_etherlink/hooks/on_synchronized.py rename to src/demo_etherlink/hooks/on_synchronized.py diff --git a/demo_etherlink/models/.keep b/src/demo_etherlink/models/.keep similarity index 100% rename from demo_etherlink/models/.keep rename to src/demo_etherlink/models/.keep diff --git a/demo_etherlink/models/__init__.py b/src/demo_etherlink/models/__init__.py similarity index 100% rename from demo_etherlink/models/__init__.py rename to src/demo_etherlink/models/__init__.py diff --git a/demo_etherlink/sql/.keep b/src/demo_etherlink/py.typed similarity index 100% rename from demo_etherlink/sql/.keep rename to src/demo_etherlink/py.typed diff --git a/src/demo_etherlink/pyproject.toml b/src/demo_etherlink/pyproject.toml new file mode 100644 index 000000000..1d234f9fd --- /dev/null +++ b/src/demo_etherlink/pyproject.toml @@ -0,0 +1,66 @@ +# Generated by DipDup 7.1.1+editable +[project] +name = "demo_etherlink" +version = "0.0.1" +description = "Indexing Etherlink smart rollup transactions" +license = { text = "MIT" } +authors = [ + { name = "John Doe", email = "john_doe@example.com" }, +] +readme = "README.md" +requires-python = ">=3.11,<3.12" +dependencies = [ + "dipdup>=7,<8", +] + +[tool.pdm.dev-dependencies] +dev = [ + "isort", + "black", + "ruff", + "mypy", +] + +[tool.pdm.scripts] +_isort = "isort ." +_black = "black ." +_ruff = "ruff check --fix ." +_mypy = "mypy --no-incremental --exclude demo_etherlink ." + +[tool.pdm.scripts.all] +help = "Run all checks" +composite = ["format", "lint"] + +[tool.pdm.scripts.format] +help = "Format code with isort and black" +composite = ["_isort", "_black"] + +[tool.pdm.scripts.image] +help = "Build Docker image" +cmd = "docker buildx build . --load --progress plain -f deploy/Dockerfile -t demo_etherlink:latest" + +[tool.pdm.scripts.lint] +help = "Check code with ruff and mypy" +composite = ["_ruff", "_mypy"] + +[tool.isort] +line_length = 120 +force_single_line = true + +[tool.black] +line-length = 120 +target-version = ['py311'] +skip-string-normalization = true + +[tool.ruff] +line-length = 120 +target-version = 'py311' +extend-select = ["B", "C4", "FA", "G", "PTH", "RUF", "TCH"] + +[tool.mypy] +python_version = "3.11" +plugins = ["pydantic.mypy"] + +[build-system] +requires = ["pdm-backend"] +build-backend = "pdm.backend" \ No newline at end of file diff --git a/demo_etherlink/sql/on_index_rollback/.keep b/src/demo_etherlink/sql/.keep similarity index 100% rename from demo_etherlink/sql/on_index_rollback/.keep rename to src/demo_etherlink/sql/.keep diff --git a/demo_etherlink/sql/on_reindex/.keep b/src/demo_etherlink/sql/on_index_rollback/.keep similarity index 100% rename from demo_etherlink/sql/on_reindex/.keep rename to src/demo_etherlink/sql/on_index_rollback/.keep diff --git a/demo_etherlink/sql/on_restart/.keep b/src/demo_etherlink/sql/on_reindex/.keep similarity index 100% rename from demo_etherlink/sql/on_restart/.keep rename to src/demo_etherlink/sql/on_reindex/.keep diff --git a/demo_etherlink/sql/on_synchronized/.keep b/src/demo_etherlink/sql/on_restart/.keep similarity index 100% rename from demo_etherlink/sql/on_synchronized/.keep rename to src/demo_etherlink/sql/on_restart/.keep diff --git a/demo_etherlink/types/.keep b/src/demo_etherlink/sql/on_synchronized/.keep similarity index 100% rename from demo_etherlink/types/.keep rename to src/demo_etherlink/sql/on_synchronized/.keep diff --git a/src/demo_etherlink/types/.keep b/src/demo_etherlink/types/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/demo_etherlink/types/controller/tezos_parameters/default.py b/src/demo_etherlink/types/controller/tezos_parameters/default.py similarity index 81% rename from demo_etherlink/types/controller/tezos_parameters/default.py rename to src/demo_etherlink/types/controller/tezos_parameters/default.py index 59952b8ac..a2e251e8a 100644 --- a/demo_etherlink/types/controller/tezos_parameters/default.py +++ b/src/demo_etherlink/types/controller/tezos_parameters/default.py @@ -3,7 +3,8 @@ from __future__ import annotations -from pydantic import BaseModel, Extra +from pydantic import BaseModel +from pydantic import Extra class DefaultParameter(BaseModel): diff --git a/demo_etherlink/types/controller/tezos_storage.py b/src/demo_etherlink/types/controller/tezos_storage.py similarity index 100% rename from demo_etherlink/types/controller/tezos_storage.py rename to src/demo_etherlink/types/controller/tezos_storage.py diff --git a/demo_etherlink/types/rollup/tezos_parameters/default.py b/src/demo_etherlink/types/rollup/tezos_parameters/default.py similarity index 100% rename from demo_etherlink/types/rollup/tezos_parameters/default.py rename to src/demo_etherlink/types/rollup/tezos_parameters/default.py diff --git a/demo_etherlink/types/rollup/tezos_storage.py b/src/demo_etherlink/types/rollup/tezos_storage.py similarity index 100% rename from demo_etherlink/types/rollup/tezos_storage.py rename to src/demo_etherlink/types/rollup/tezos_storage.py diff --git a/src/dipdup/project.py b/src/dipdup/project.py index 33b40d1b6..d4f3bd22e 100644 --- a/src/dipdup/project.py +++ b/src/dipdup/project.py @@ -27,18 +27,19 @@ 'demo_uniswap', ), 'tezos': ( - 'demo_domains', + 'demo_auction', 'demo_big_maps', + 'demo_dao', + 'demo_dex', + 'demo_domains', 'demo_events', + 'demo_etherlink', + 'demo_factories', 'demo_head', 'demo_nft_marketplace', - 'demo_dex', - 'demo_factories', - 'demo_dao', + 'demo_raw', 'demo_token', 'demo_token_transfers', - 'demo_auction', - 'demo_raw', ), 'other': ('demo_blank',), } diff --git a/src/dipdup/projects/demo_etherlink/dipdup.yaml.j2 b/src/dipdup/projects/demo_etherlink/dipdup.yaml.j2 new file mode 100644 index 000000000..943573d75 --- /dev/null +++ b/src/dipdup/projects/demo_etherlink/dipdup.yaml.j2 @@ -0,0 +1,36 @@ +spec_version: 2.0 +package: {{ project.package }} + +datasources: + tzkt: + kind: tezos.tzkt + url: ${TZKT_URL:-https://api.tzkt.io} + +contracts: + controller: + kind: tezos + address: KT1Ax1oGGjooakyYJvtrX3q5zxRwYv6EAeC2 + typename: controller + rollup: + kind: tezos + address: sr1SW7VtD6xbSAEoRk8LXewr3igfWjBx7FPB + typename: rollup + +indexes: + rollup_operations: + kind: tezos.tzkt.operations + datasource: tzkt + contracts: + - controller + - rollup + handlers: + - callback: on_rollup_call + pattern: + - type: transaction + destination: controller + entrypoint: default + alias: controller_default + - type: transaction + destination: rollup + entrypoint: default + alias: rollup_default diff --git a/src/dipdup/projects/demo_etherlink/handlers/on_rollup_call.py.j2 b/src/dipdup/projects/demo_etherlink/handlers/on_rollup_call.py.j2 new file mode 100644 index 000000000..cd0ca540b --- /dev/null +++ b/src/dipdup/projects/demo_etherlink/handlers/on_rollup_call.py.j2 @@ -0,0 +1,19 @@ +from {{ project.package }}.types.controller.tezos_parameters.default import DefaultParameter as ControllerDefaultParameter +from {{ project.package }}.types.controller.tezos_storage import ControllerStorage +from {{ project.package }}.types.rollup.tezos_parameters.default import DefaultParameter as RollupDefaultParameter +from {{ project.package }}.types.rollup.tezos_storage import RollupStorage +from dipdup.context import HandlerContext +from dipdup.models.tezos_tzkt import TzktTransaction + + +async def on_rollup_call( + ctx: HandlerContext, + controller_default: TzktTransaction[ControllerDefaultParameter, ControllerStorage], + rollup_default: TzktTransaction[RollupDefaultParameter, RollupStorage], +) -> None: + ctx.logger.info( + 'Smart rollup %s has been called by contract %s with parameter %s', + rollup_default.data.target_address, + controller_default.data.target_address, + rollup_default.parameter.__root__, + ) diff --git a/src/dipdup/projects/demo_etherlink/replay.yaml b/src/dipdup/projects/demo_etherlink/replay.yaml new file mode 100644 index 000000000..092de55cd --- /dev/null +++ b/src/dipdup/projects/demo_etherlink/replay.yaml @@ -0,0 +1,5 @@ +spec_version: 2.0 +replay: + description: Indexing Etherlink smart rollup transactions + package: demo_etherlink + template: demo_etherlink \ No newline at end of file diff --git a/tests/configs/demo_etherlink.yaml b/tests/configs/demo_etherlink.yaml new file mode 100644 index 000000000..7d9ff185a --- /dev/null +++ b/tests/configs/demo_etherlink.yaml @@ -0,0 +1,38 @@ +spec_version: 2.0 +package: demo_etherlink + +datasources: + tzkt: + kind: tezos.tzkt + url: ${TZKT_URL:-https://api.tzkt.io} + +contracts: + controller: + kind: tezos + address: KT1Ax1oGGjooakyYJvtrX3q5zxRwYv6EAeC2 + typename: controller + rollup: + kind: tezos + address: sr1SW7VtD6xbSAEoRk8LXewr3igfWjBx7FPB + typename: rollup + +indexes: + rollup_operations: + kind: tezos.tzkt.operations + datasource: tzkt + contracts: + - controller + - rollup + handlers: + - callback: on_rollup_call + pattern: + - type: transaction + destination: controller + entrypoint: default + alias: controller_default + - type: transaction + destination: rollup + entrypoint: default + alias: rollup_default + first_level: 3507389 + last_level: 3507389 \ No newline at end of file diff --git a/tests/test_demos.py b/tests/test_demos.py index db706a837..38e343078 100644 --- a/tests/test_demos.py +++ b/tests/test_demos.py @@ -202,6 +202,8 @@ async def assert_run_dao() -> None: ('demo_evm_events.yml', 'demo_evm_events', 'run', assert_run_evm_events), ('demo_evm_events.yml', 'demo_evm_events', 'init', None), ('demo_evm_events_node.yml', 'demo_evm_events', 'run', assert_run_evm_events), + ('demo_etherlink.yml', 'demo_evm_events', 'run', None), + ('demo_etherlink.yml', 'demo_evm_events', 'init', None), # NOTE: Smoke tests for small tools. ('demo_dex.yml', 'demo_dex', ('config', 'env', '--compose', '--internal'), None), ('demo_dex.yml', 'demo_dex', ('config', 'export', '--full'), None),