Skip to content

Commit

Permalink
frank/vat tweaks (#191)
Browse files Browse the repository at this point in the history
* vat tweaks

* fix black
  • Loading branch information
soundsonacid authored Jul 24, 2024
1 parent ca5db45 commit feebbbe
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 110 deletions.
203 changes: 102 additions & 101 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jito-searcher-client = "0.1.4"
[tool.poetry.dev-dependencies]
pytest = "^7.2.0"
flake8 = "6.0.0"
black = "^23.3.0"
black = "24.4.2"
pytest-asyncio = "^0.21.0"
mkdocs = "^1.3.0"
mkdocstrings = "^0.17.0"
Expand Down
2 changes: 1 addition & 1 deletion src/driftpy/constants/perp_markets.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class PerpMarketConfig:
symbol="RNDR-PERP",
base_asset_symbol="RNDR",
market_index=12,
oracle=Pubkey.from_string("F3mPHRtJqqq57JPDBmUwUVhpyPLmjE5dAzDfpVgpFkug"),
oracle=Pubkey.from_string("8TQztfGcNjHGRusX4ejQQtPZs3Ypczt9jWF6pkgQMqUX"),
oracle_source=OracleSource.PythPull(),
),
PerpMarketConfig(
Expand Down
2 changes: 1 addition & 1 deletion src/driftpy/constants/spot_markets.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class SpotMarketConfig:
SpotMarketConfig(
symbol="RNDR",
market_index=12,
oracle=Pubkey.from_string("F3mPHRtJqqq57JPDBmUwUVhpyPLmjE5dAzDfpVgpFkug"),
oracle=Pubkey.from_string("8TQztfGcNjHGRusX4ejQQtPZs3Ypczt9jWF6pkgQMqUX"),
oracle_source=OracleSource.PythPull(),
mint=Pubkey.from_string("rndrizKT3MK1iimdxRdWabcF7Zg7AR5T4nud4EkHBof"),
),
Expand Down
11 changes: 7 additions & 4 deletions src/driftpy/pickle/vat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pickle
import os
from dataclasses import dataclass
from typing import Optional
from driftpy.drift_client import DriftClient
from driftpy.market_map.market_map import MarketMap
Expand All @@ -14,7 +15,7 @@ def __init__(
self,
drift_client: DriftClient,
users: UserMap,
user_stats: UserStatsMap,
user_stats: Optional[UserStatsMap],
spot_markets: MarketMap,
perp_markets: MarketMap,
):
Expand All @@ -31,8 +32,9 @@ async def pickle(self):
await self.users.sync()
self.users.dump()

await self.user_stats.sync()
self.user_stats.dump()
if self.user_stats is not None:
await self.user_stats.sync()
self.user_stats.dump()

await self.spot_markets.dump()
await self.perp_markets.dump()
Expand All @@ -54,7 +56,8 @@ async def unpickle(
self.perp_markets.clear()

await self.users.load(users_filename)
await self.user_stats.load(user_stats_filename)
if self.user_stats is not None:
await self.user_stats.load(user_stats_filename)
await self.spot_markets.load(spot_markets_filename)
await self.perp_markets.load(perp_markets_filename)

Expand Down
4 changes: 2 additions & 2 deletions src/driftpy/user_map/user_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@ async def load(self, filename: Optional[str] = None):
data = decode_user(decompress(user.data))
await self.add_pubkey(user.pubkey, DataAndSlot(slot, data))

def dump(self):
def dump(self, filename: Optional[str] = None):
users = []
for pubkey, user in self.raw.items():
users.append(PickledData(pubkey=pubkey, data=compress(user)))
self.last_dumped_slot = self.get_slot()
filename = f"usermap_{self.last_dumped_slot}.pkl"
filename = filename or f"usermap_{self.last_dumped_slot}.pkl"
with open(filename, "wb") as f:
pickle.dump(users, f, pickle.HIGHEST_PROTOCOL)

0 comments on commit feebbbe

Please sign in to comment.