gnosis / prediction-market-agent-tooling

Tools to benchmark, deploy and monitor prediction market agents.
GNU Lesser General Public License v3.0
18 stars 4 forks source link

Fix OmenAgentMarket.sell_tokens #240

Closed evangriffiths closed 6 months ago

evangriffiths commented 6 months ago

Raises exception: ValueError: non-hexadecimal number found in fromhex() arg at position 0

To repro (ask @evangriffiths for the pkey):

from prediction_market_agent_tooling.markets.data_models import Currency, TokenAmount
from prediction_market_agent_tooling.markets.omen.omen import OmenAgentMarket
from prediction_market_agent_tooling.markets.omen.omen_subgraph_handler import (
    OmenSubgraphHandler,
)

market_address = "0x555b5fdfd3fec7db7d50afd1c970d798072d80f8"
bet_from_address = "0x18f8f8A755b4e4Cc0F8FAC2C15a888247954A0e5"

# Check user has a position in the market
market = OmenSubgraphHandler().get_omen_market_by_market_id(market_address)
agent_market = OmenAgentMarket.from_data_model(market)
market_positions = [
    position
    for position in OmenAgentMarket.get_positions(bet_from_address)
    if position.market_id == market_address
]
assert len(market_positions) == 1
position = market_positions[0]

# Check market is not resolved
assert agent_market.is_resolved() is False

# Check user has a position in the market (of which we should be able to sell a small fraction!)
sell_amount = 0.0000001
assert position.amounts["Yes"].amount > (100 * sell_amount)

# Try to sell the tokens... ValueError: non-hexadecimal number found in fromhex() arg at position 0
agent_market.sell_tokens(
    outcome=True,
    amount=TokenAmount(amount=sell_amount, currency=Currency.xDai),
)
evangriffiths commented 6 months ago

Ah it's not actually broken!! It's only a problem when you try to sell shares in closed/illiquid markets