diff --git a/src/dexorder/accounting.py b/src/dexorder/accounting.py index 58158f6..af18ec5 100644 --- a/src/dexorder/accounting.py +++ b/src/dexorder/accounting.py @@ -1,7 +1,7 @@ import asyncio import logging -from sqlalchemy import select, func +from sqlalchemy import select, func, text from typing_extensions import Optional from web3.exceptions import ContractLogicError from web3.types import EventData @@ -212,6 +212,9 @@ async def adjust_balance(account: DbAccount, token=NATIVE_TOKEN, subcategory=Acc async def reconcile(account: DbAccount, block_id: Optional[str] = None, last_accounting_row_id: Optional[int] = None): + # First we lock all the relevant tables to ensure consistency + db.session.execute(text("LOCK TABLE account, accounting, reconciliation IN EXCLUSIVE MODE")) + # Fetch the latest reconciliation for the account latest_recon = db.session.execute( select(Reconciliation).where( diff --git a/src/dexorder/bin/refill.py b/src/dexorder/bin/refill.py new file mode 100644 index 0000000..55c9106 --- /dev/null +++ b/src/dexorder/bin/refill.py @@ -0,0 +1,12 @@ +import logging + +from dexorder.bin.executable import execute + +log = logging.getLogger(__name__) + +async def main(): + pass + + +if __name__ == '__main__': + execute(main()) diff --git a/src/dexorder/configuration/schema.py b/src/dexorder/configuration/schema.py index 9c742a5..33e0ff6 100644 --- a/src/dexorder/configuration/schema.py +++ b/src/dexorder/configuration/schema.py @@ -51,3 +51,6 @@ class Config: stablecoins: list[str] = field(default_factory=list) # primary stablecoins which are marked to $1 quotecoins: list[str] = field(default_factory=list) # quote tokens like WETH that have stablecoin markets nativecoin: Optional[str] = None # used for accounting of native values. e.g. address of WETH + + # account: target_balance + refill: dict[str,str] = field(default_factory=dict) diff --git a/src/dexorder/pools.py b/src/dexorder/pools.py index 5378f32..ba6a7e8 100644 --- a/src/dexorder/pools.py +++ b/src/dexorder/pools.py @@ -195,8 +195,6 @@ async def mark_to_market_adj_dec(token: str, amount: dec, adjust_decimals=True) """ Returns the current USD value for the amount of token. """ - if not accounting_initialized: - await initialize_accounting() if adjust_decimals: amount = await adj_dec(token, amount) return mark_to_market(token, amount)