Skip to content

Commit

Permalink
Merge branch 'main' into peter/withdrawing
Browse files Browse the repository at this point in the history
  • Loading branch information
kongzii authored Feb 27, 2025
2 parents 3ec1770 + 8ee5948 commit d8c5ce2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
10 changes: 8 additions & 2 deletions prediction_market_agent_tooling/markets/omen/omen_resolving.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
OmenSubgraphHandler,
)
from prediction_market_agent_tooling.tools.utils import utcnow
from prediction_market_agent_tooling.tools.web3_utils import ZERO_BYTES, xdai_to_wei
from prediction_market_agent_tooling.tools.web3_utils import (
ZERO_BYTES,
wei_to_xdai,
xdai_to_wei,
)


def claim_bonds_on_realitio_questions(
Expand Down Expand Up @@ -116,7 +120,9 @@ def claim_bonds_on_realitio_question(
current_balance = realitio_contract.balanceOf(public_key, web3=web3)
# Keeping balance on Realitio is not useful, so it's recommended to just withdraw it.
if current_balance > 0 and auto_withdraw:
logger.info(f"Withdrawing remaining balance {current_balance=}")
logger.info(
f"Withdrawing remaining balance {wei_to_xdai(current_balance)} xDai from Realitio."
)
realitio_contract.withdraw(api_keys, web3=web3)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@
byte32_to_ipfscidv0,
)

# TODO: Agents don't know how to convert value between other tokens, we assume 1 unit = 1xDai = $1 (for example if market would be in wETH, betting 1 unit of wETH would be crazy :D)
SAFE_COLLATERAL_TOKEN_MARKETS = (
WrappedxDaiContract().address,
sDaiContract().address,
SAFE_COLLATERAL_TOKENS = (
WrappedxDaiContract(),
sDaiContract(),
)
SAFE_COLLATERAL_TOKENS_ADDRESSES = tuple(
contract.address for contract in SAFE_COLLATERAL_TOKENS
)


Expand Down Expand Up @@ -326,7 +328,7 @@ def get_omen_binary_markets_simple(
excluded_questions: set[str] | None = None, # question titles
collateral_token_address_in: (
tuple[ChecksumAddress, ...] | None
) = SAFE_COLLATERAL_TOKEN_MARKETS,
) = SAFE_COLLATERAL_TOKENS_ADDRESSES,
category: str | None = None,
creator_in: t.Sequence[HexAddress] | None = None,
) -> t.List[OmenMarket]:
Expand Down Expand Up @@ -392,7 +394,7 @@ def get_omen_binary_markets(
outcomes: list[str] = OMEN_BINARY_MARKET_OUTCOMES,
collateral_token_address_in: (
tuple[ChecksumAddress, ...] | None
) = SAFE_COLLATERAL_TOKEN_MARKETS,
) = SAFE_COLLATERAL_TOKENS_ADDRESSES,
category: str | None = None,
) -> t.List[OmenMarket]:
"""
Expand Down
23 changes: 17 additions & 6 deletions prediction_market_agent_tooling/tools/caches/db_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
overload,
)

import psycopg2
from pydantic import BaseModel
from sqlalchemy import Column
from sqlalchemy.dialects.postgresql import JSONB
Expand Down Expand Up @@ -200,12 +201,22 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
result=computed_result,
created_at=utcnow(),
)
with DBManager(
api_keys.sqlalchemy_db_url.get_secret_value()
).get_session() as session:
logger.info(f"Saving {cache_entry} into database.")
session.add(cache_entry)
session.commit()
# Do not raise an exception if saving to the database fails, just log it and let the agent continue the work.
try:
with DBManager(
api_keys.sqlalchemy_db_url.get_secret_value()
).get_session() as session:
logger.info(f"Saving {cache_entry} into database.")
session.add(cache_entry)
session.commit()
except psycopg2.errors.UntranslatableCharacter as e:
logger.warning(
f"Failed to save {cache_entry} into database, ignoring, because: {e}"
)
except Exception:
logger.exception(
f"Failed to save {cache_entry} into database, ignoring."
)

return computed_result

Expand Down

0 comments on commit d8c5ce2

Please sign in to comment.