Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Thanks for all the fish #13

Merged
merged 7 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM dipdup/dipdup:6.1-slim
FROM dipdup/dipdup:6
COPY . .
RUN install_dependencies requirements.txt
RUN pip install -r requirements.txt
19 changes: 7 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
##
## 🚧 DipDup developer tools
##
## DEV=1 Install dev dependencies
## DEV=1 Whether to install dev dependencies
DEV=1
## TAG=latest Tag for the `image` command
TAG=latest
Expand All @@ -13,15 +13,15 @@ TAG=latest
help: ## Show this help (default)
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'

all: ## Run a whole CI pipeline: lint, run tests, build docs
all: ## Run all checks
make install lint

install: ## Install project dependencies
poetry install \
`if [ "${DEV}" = "0" ]; then echo "--without dev"; fi`

lint: ## Lint with all tools
make isort black flake mypy
make isort black ruff mypy

##

Expand All @@ -31,8 +31,8 @@ isort: ## Format with isort
black: ## Format with black
poetry run black src

flake: ## Lint with flake8
poetry run flakeheaven lint src
ruff: ## Lint with ruff
poetry run ruff check src

mypy: ## Lint with mypy
poetry run mypy src
Expand All @@ -41,14 +41,9 @@ build: ## Build Python wheel package
poetry build

image: ## Build Docker image
docker buildx build . --progress plain -t juster-dipdup:${TAG}

##
docker build . -t juster-dipdup:${TAG}

clean: ## Remove all files from .gitignore except for `.venv`
git clean -xdf --exclude=".venv"

update: ## Update dependencies, export requirements.txt (wait an eternity)
make install
poetry update
# poetry export --without-hashes -o requirements.txt
##
43 changes: 21 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
# Juster indexer
# juster-dipdup

## Installation
This repo contains a Juster betting protocol indexer based on DipDup.

```
poetry install
```
Juster protocol was sunsetted on May 2023; this repo is archived. Thanks for your support!

## Debugging

### Sqlite
## Installation

```
poetry shell
dipdup run
```
Python 3.10 is required to run DipDup v6. Use the following commands to set up dev environment:

### Postgres
```shell
# Using poetry
$ poetry install
$ poetry shell

```
poetry shell
make up
make run
make down
# Using pip
$ python3.10 -m venv .venv
$ source .venv/bin/activate
$ python3.10 -m pip install -e .
```

## Running
## Running and deployment

```
docker-compose pull
docker-compose up -d
```shell
# SQLite database
$ dipdup run

# PostgreSQL in docker-compose
$ docker-compose up -d db hasura
$ dipdup -c dipdup.yml -c dipdup.local.yml run
```
2 changes: 1 addition & 1 deletion dipdup.prod.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sentry:
dsn: ${SENTRY_DSN:-"https://[email protected]/6"}
dsn: ${SENTRY_DSN:-""}
environment: ${SENTRY_ENVIRONMENT:-""}
server_name: ${SENTRY_SERVER_NAME:-""}
release: ${SENTRY_RELEASE:-""}
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
- ADMIN_SECRET=${ADMIN_SECRET:-changeme}

db:
image: postgres:14
image: postgres:15
restart: always
ports:
- 127.0.0.1:5432:5432
Expand All @@ -29,7 +29,7 @@ services:
retries: 5

hasura:
image: hasura/graphql-engine:v2.8.3
image: hasura/graphql-engine:v2.28.0
ports:
- 127.0.0.1:8080:8080
depends_on:
Expand Down
1 change: 0 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[mypy]
python_version = 3.10
plugins = pydantic.mypy

[mypy-ruamel]
ignore_missing_imports = True
2,209 changes: 1,226 additions & 983 deletions poetry.lock

Large diffs are not rendered by default.

44 changes: 16 additions & 28 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
[tool.poetry]
name = "juster-dipdup"
version = "0.0.1"
description = ""
authors = ["Lev Gorodetskiy <[email protected]>"]
version = "1.0.0"
description = "DipDup indexer for Juster protocol"
authors = [
"Lev Gorodetskiy <[email protected]>",
"Stepan Naumov <[email protected]>",
"Michael Zaikin <[email protected]>"
]
packages = [
{ include = "juster", from = "src" },
]

[tool.poetry.dependencies]
python = ">=3.10,<3.11"
dipdup = "^6.1.0"
# dipdup = {path = "../dipdup", develop = true}
# dipdup = {git = "https://github.com/dipdup-net/dipdup-py.git", branch = "feat/db-rollback"}
dipdup = "^6"
strict-rfc3339 = "^0.7"

[tool.poetry.dev-dependencies]
black = "^22.1.0"
bump2version = "^1.0.1"
diff-cover = "^6.5.0"
flake8-return = "^1.1.3"
flake8-comprehensions = "^3.8.0"
flake8-bugbear = "^22.1.11"
flake8-simplify = "^0.19.2"
flakeheaven = "^2.0.0"
isort = "^5.9.3"
mypy = "^0.971"
isort = "*"
black = "*"
ruff = "*"
mypy = "*"

[tool.isort]
line_length = 140
Expand All @@ -35,19 +31,11 @@ line-length = 140
target-version = ['py310']
skip-string-normalization = true

[tool.flakeheaven]
format = "colored"
max_line_length = 140
show_source = true
extended_default_ignore = []
[tool.ruff]
line-length = 140
target-version = 'py310'

[tool.flakeheaven.plugins]
"*" = ["+*"]
flake8-comprehensions = ["-C417"]
flake8-docstrings = ["-*"]
flake8-simplify = ["-SIM106", "-SIM114", "-SIM102"]
pycodestyle = ["-*"]

[build-system]
requires = ["poetry_core==1.0.0"]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
8 changes: 0 additions & 8 deletions src/juster/graphql/candles.graphql

This file was deleted.

8 changes: 0 additions & 8 deletions src/juster/graphql/quotes.graphql

This file was deleted.

1 change: 0 additions & 1 deletion src/juster/handlers/pool/on_add_line.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from decimal import Decimal
from typing import Tuple

from dipdup.context import HandlerContext
from dipdup.models import Transaction
Expand Down
2 changes: 0 additions & 2 deletions src/juster/handlers/pool/on_approve_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
from juster.types.pool.parameter.approve_entry import ApproveEntryParameter
from juster.types.pool.storage import PoolStorage
from juster.utils import get_shares
from juster.utils import process_pool_shares
from juster.utils import update_pool_state


async def on_approve_entry(
ctx: HandlerContext,
approve_entry: Transaction[ApproveEntryParameter, PoolStorage],
) -> None:

provider, new_shares = get_shares(approve_entry.storage)

user, _ = await models.User.get_or_create(address=provider)
Expand Down
1 change: 0 additions & 1 deletion src/juster/handlers/pool/on_cancel_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ async def on_cancel_entry(
ctx: HandlerContext,
cancel_entry: Transaction[CancelEntryParameter, PoolStorage],
) -> None:

entry_id = int(cancel_entry.parameter.__root__)
pool_address = cancel_entry.data.target_address
pool = await models.Pool.get(address=pool_address)
Expand Down
3 changes: 1 addition & 2 deletions src/juster/handlers/pool/on_claim_liquidity.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ async def on_claim_liquidity(
claim_liquidity: Transaction[ClaimLiquidityParameter, PoolStorage],
transaction_1: Optional[OperationData] = None,
) -> None:

pool_address = claim_liquidity.data.target_address
pool = await models.Pool.get(address=pool_address)
pool_state = await pool.get_last_state()
Expand All @@ -46,7 +45,7 @@ async def on_claim_liquidity(
position.withdrawn_shares += claimed_shares

claimed_fraction = claimed_shares / pool_state.total_shares
user = await position.user.get() # type: ignore
user = await position.user.get()
claimed_sum = Decimal(0)

for claim_pair in claim_liquidity.storage.claims:
Expand Down
2 changes: 1 addition & 1 deletion src/juster/handlers/pool/on_create_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async def on_create_event(

# Event added to PoolEvent after its creation so it is possible to reuse
# pool_event.id type which casted from int to BigIntField:
pool_event.event = await models.Event.get_or_none(id=pool_event.id)
pool_event.event = await models.Event.get_or_none(id=pool_event.id) # type: ignore[assignment]
await pool_event.save()

await update_pool_state(
Expand Down
1 change: 0 additions & 1 deletion src/juster/handlers/pool/on_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ async def on_default(
ctx: HandlerContext,
default: Transaction[DefaultParameter, PoolStorage],
) -> None:

if default.data.amount == 0:
return

Expand Down
1 change: 0 additions & 1 deletion src/juster/handlers/pool/on_disband.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ async def on_disband(
ctx: HandlerContext,
disband: Transaction[DisbandParameter, PoolStorage],
) -> None:

assert disband.storage.isDisbandAllow is True
pool_address = disband.data.target_address
pool = await models.Pool.get(address=pool_address)
Expand Down
2 changes: 0 additions & 2 deletions src/juster/handlers/pool/on_pay_reward.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from decimal import Decimal

from dipdup.context import HandlerContext
from dipdup.models import Transaction

Expand Down
16 changes: 8 additions & 8 deletions src/juster/handlers/pool/on_pool_origination.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ async def on_pool_origination(
ctx: HandlerContext,
pool_origination: Origination[PoolStorage],
) -> None:

pool_metadata_raw = pool_origination.storage.metadata['contents']
metadata = json.loads(bytes.fromhex(pool_metadata_raw))
contract_address = pool_origination.data.originated_contract_address
Expand All @@ -29,12 +28,13 @@ async def on_pool_origination(

if is_approved:
contracts_names = {contract.address: name for name, contract in ctx.config.contracts.items()}
is_added_to_indexer = contract_address in contracts_names
contract_name = contracts_names.get(contract_address)

if not is_added_to_indexer:
contract_name = f'pool_{contract_address}'
await ctx.add_contract(name=contract_name, address=contract_address, typename='pool')
contract_name = contracts_names.get(contract_address, f'pool_{contract_address}')
if contract_address not in contracts_names:
await ctx.add_contract(
name=contract_name,
address=contract_address,
typename='pool',
)

await ctx.add_index(
name=contract_name,
Expand All @@ -61,7 +61,7 @@ async def on_pool_origination(
initial_liquidity = from_mutez(amt) if amt else Decimal(0)
total_liquidity = from_high_precision(storage['activeLiquidityF']) + initial_liquidity

# TODO: consider using update_pool_state with last_state initiated with zeros to create first state?
# TODO: Consider using update_pool_state with last_state initiated with zeros to create first state?
pool_state = models.PoolState(
pool=pool,
action=models.PoolHistoryAction.POOL_ORIGINATED,
Expand Down
2 changes: 0 additions & 2 deletions src/juster/handlers/pool/on_set_entry_lock_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
import juster.models as models
from juster.types.pool.parameter.set_entry_lock_period import SetEntryLockPeriodParameter
from juster.types.pool.storage import PoolStorage
from juster.utils import update_pool_state


async def on_set_entry_lock_period(
ctx: HandlerContext,
set_entry_lock_period: Transaction[SetEntryLockPeriodParameter, PoolStorage],
) -> None:

pool_address = set_entry_lock_period.data.target_address
pool = await models.Pool.get(address=pool_address)
new_period = int(set_entry_lock_period.storage.entryLockPeriod)
Expand Down
1 change: 0 additions & 1 deletion src/juster/handlers/pool/on_trigger_pause_deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ async def on_trigger_pause_deposit(
ctx: HandlerContext,
trigger_pause_deposit: Transaction[TriggerPauseDepositParameter, PoolStorage],
) -> None:

pool_address = trigger_pause_deposit.data.target_address
pool = await models.Pool.get(address=pool_address)

Expand Down
2 changes: 0 additions & 2 deletions src/juster/handlers/pool/on_trigger_pause_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
from juster.types.pool.parameter.trigger_pause_line import TriggerPauseLineParameter
from juster.types.pool.storage import PoolStorage
from juster.utils import get_line
from juster.utils import update_pool_state


async def on_trigger_pause_line(
ctx: HandlerContext,
trigger_pause_line: Transaction[TriggerPauseLineParameter, PoolStorage],
) -> None:

line_id, line_diff = get_line(trigger_pause_line.storage)
pool_address = trigger_pause_line.data.target_address
pool = await models.Pool.get(address=pool_address)
Expand Down
2 changes: 1 addition & 1 deletion src/juster/handlers/pool/on_withdraw_claims.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async def on_withdraw_claims(
user = await models.User.get(address=claim_key.provider)
position = await models.PoolPosition.filter(pool=pool, user=user).get()
claim = await models.Claim.filter(pool=pool, event=event, user=user).get()
claim.withdrawn = True # type: ignore
claim.withdrawn = True
reward = quantize_down(event.result * claim.amount / event.provided, high_precision)
position.withdrawn_amount += reward
position.realized_profit += reward - claim.amount
Expand Down
Empty file added src/juster/hasura/.keep
Empty file.
Loading
Loading