Skip to content

Commit

Permalink
add black to pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Nov 17, 2023
1 parent 99708f3 commit 465c796
Show file tree
Hide file tree
Showing 23 changed files with 426 additions and 241 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
- id: black
language_version: python3.10
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ test:

lint:
poetry run black --check --diff src tests
poetry run flake8 src tests
poetry run mypy src tests

lintfix:
poetry run black src tests

83 changes: 54 additions & 29 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,19 @@ websockets = "10.4"
yarl = "1.8.2"
zstandard = "0.18.0"
jinja2 = "<3.1"
mypy = "^1.7.0"

[tool.poetry.dev-dependencies]
pytest = "^7.2.0"
flake8 = "6.0.0"
mypy = "^0.931"
black = "^23.3.0"
pytest-asyncio = "^0.21.0"
mkdocs = "^1.3.0"
mkdocstrings = "^0.17.0"
mkdocs-material = "^8.1.8"
bump2version = "^1.0.1"
autopep8 = "^2.0.4"
mypy = "^1.7.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
21 changes: 10 additions & 11 deletions src/driftpy/_types.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from driftpy.constants.numeric_constants import SPOT_RATE_PRECISION
from driftpy.types import OracleSource
from typing import Optional, Any
from dataclasses import dataclass
from sumtypes import constructor # type: ignore
Expand Down Expand Up @@ -287,9 +289,10 @@ class MarketPosition:
padding3: int
padding4: int

## dw why this doesnt register :(
# dw why this doesnt register :(
# def is_available(self):
# return self.base_asset_amount == 0 and self.open_orders == 0 and self.lp_shares == 0
# return self.base_asset_amount == 0 and self.open_orders == 0 and
# self.lp_shares == 0


@dataclass
Expand Down Expand Up @@ -377,14 +380,14 @@ class AMM:
quote_asset_amount_long: int = 0
quote_asset_amount_short: int = 0

## lp stuff
# lp stuff
cumulative_funding_payment_per_lp: int = 0
cumulative_fee_per_lp: int = 0
cumulative_base_asset_amount_with_amm_per_lp: int = 0
lp_cooldown_time: int = 0
user_lp_shares: int = 0

## funding
# funding
last_funding_rate: int = 0
last_funding_rate_ts: int = 0
funding_period: int = 0
Expand All @@ -397,11 +400,11 @@ class AMM:
last_mark_price_twap: int = 0
last_mark_price_twap_ts: int = 0

## trade constraints
# trade constraints
minimum_quote_asset_trade_size: int = 0
base_asset_amount_step_size: int = 0

## market making
# market making
base_spread: int = 0
long_spread: int = 0
short_spread: int = 0
Expand All @@ -420,7 +423,7 @@ class AMM:
short_intensity_volume: int = 0
curve_update_intensity: int = 0

## fee tracking
# fee tracking
total_fee: int = 0
total_mm_fee: int = 0
total_exchange_fee: int = 0
Expand Down Expand Up @@ -462,10 +465,6 @@ class Market:
padding4: int = 0


from driftpy.types import OracleSource
from driftpy.constants.numeric_constants import SPOT_RATE_PRECISION


@dataclass
class SpotMarket:
mint: PublicKey # this
Expand Down
2 changes: 1 addition & 1 deletion src/driftpy/accounts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .get_accounts import *
from .types import *
from .types import *
2 changes: 1 addition & 1 deletion src/driftpy/accounts/cache/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .drift_client import *
from .user import *
from .user import *
40 changes: 28 additions & 12 deletions src/driftpy/accounts/cache/drift_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
from solders.pubkey import Pubkey
from solana.rpc.commitment import Commitment

from driftpy.accounts import get_state_account_and_slot, get_spot_market_account_and_slot, \
get_perp_market_account_and_slot
from driftpy.accounts import (
get_state_account_and_slot,
get_spot_market_account_and_slot,
get_perp_market_account_and_slot,
)
from driftpy.accounts.oracle import get_oracle_price_data_and_slot
from driftpy.accounts.types import DriftClientAccountSubscriber, DataAndSlot
from typing import Optional
Expand All @@ -28,30 +31,37 @@ async def update_cache(self):

spot_markets = []
for i in range(state_and_slot.data.number_of_spot_markets):
spot_market_and_slot = await get_spot_market_account_and_slot(self.program, i)
spot_market_and_slot = await get_spot_market_account_and_slot(
self.program, i
)
spot_markets.append(spot_market_and_slot)

oracle_price_data_and_slot = await get_oracle_price_data_and_slot(
self.program.provider.connection,
spot_market_and_slot.data.oracle,
spot_market_and_slot.data.oracle_source

spot_market_and_slot.data.oracle_source,
)
oracle_data[str(spot_market_and_slot.data.oracle)] = oracle_price_data_and_slot
oracle_data[
str(spot_market_and_slot.data.oracle)
] = oracle_price_data_and_slot

self.cache["spot_markets"] = spot_markets

perp_markets = []
for i in range(state_and_slot.data.number_of_markets):
perp_market_and_slot = await get_perp_market_account_and_slot(self.program, i)
perp_market_and_slot = await get_perp_market_account_and_slot(
self.program, i
)
perp_markets.append(perp_market_and_slot)

oracle_price_data_and_slot = await get_oracle_price_data_and_slot(
self.program.provider.connection,
perp_market_and_slot.data.amm.oracle,
perp_market_and_slot.data.amm.oracle_source
perp_market_and_slot.data.amm.oracle_source,
)
oracle_data[str(perp_market_and_slot.data.amm.oracle)] = oracle_price_data_and_slot
oracle_data[
str(perp_market_and_slot.data.amm.oracle)
] = oracle_price_data_and_slot

self.cache["perp_markets"] = perp_markets

Expand All @@ -61,15 +71,21 @@ async def get_state_account_and_slot(self) -> Optional[DataAndSlot[State]]:
await self.cache_if_needed()
return self.cache["state"]

async def get_perp_market_and_slot(self, market_index: int) -> Optional[DataAndSlot[PerpMarket]]:
async def get_perp_market_and_slot(
self, market_index: int
) -> Optional[DataAndSlot[PerpMarket]]:
await self.cache_if_needed()
return self.cache["perp_markets"][market_index]

async def get_spot_market_and_slot(self, market_index: int) -> Optional[DataAndSlot[SpotMarket]]:
async def get_spot_market_and_slot(
self, market_index: int
) -> Optional[DataAndSlot[SpotMarket]]:
await self.cache_if_needed()
return self.cache["spot_markets"][market_index]

async def get_oracle_data_and_slot(self, oracle: Pubkey) -> Optional[DataAndSlot[OraclePriceData]]:
async def get_oracle_data_and_slot(
self, oracle: Pubkey
) -> Optional[DataAndSlot[OraclePriceData]]:
await self.cache_if_needed()
return self.cache["oracle_price_data"][str(oracle)]

Expand Down
7 changes: 6 additions & 1 deletion src/driftpy/accounts/cache/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@


class CachedUserAccountSubscriber(UserAccountSubscriber):
def __init__(self, user_pubkey: Pubkey, program: Program, commitment: Commitment = "confirmed"):
def __init__(
self,
user_pubkey: Pubkey,
program: Program,
commitment: Commitment = "confirmed",
):
self.program = program
self.commitment = commitment
self.user_pubkey = user_pubkey
Expand Down
Loading

0 comments on commit 465c796

Please sign in to comment.