Skip to content

Commit

Permalink
Fix funding of markets with sDai (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongzii authored Sep 11, 2024
1 parent d755388 commit 43b39d1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
11 changes: 7 additions & 4 deletions prediction_market_agent_tooling/markets/omen/omen.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,17 +876,20 @@ def omen_fund_market_tx(
market_contract = market.get_contract()
collateral_token_contract = market_contract.get_collateral_token_contract()

if auto_deposit:
auto_deposit_collateral_token(collateral_token_contract, funds, api_keys, web3)
amount_to_fund = collateral_token_contract.get_in_shares(funds, web3)

collateral_token_contract.approve(
api_keys=api_keys,
for_address=market_contract.address,
amount_wei=funds,
amount_wei=amount_to_fund,
web3=web3,
)

market_contract.addFunding(api_keys, funds, web3=web3)
if auto_deposit:
# In auto-depositing, we need to deposit the original `funds`, e.g. we can deposit 2 xDai, but receive 1.8 sDai, so for the funding we will use `amount_to_fund`.
auto_deposit_collateral_token(collateral_token_contract, funds, api_keys, web3)

market_contract.addFunding(api_keys, amount_to_fund, web3=web3)


def build_parent_collection_id() -> HexStr:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "prediction-market-agent-tooling"
version = "0.48.13"
version = "0.48.14"
description = "Tools to benchmark, deploy and monitor prediction market agents."
authors = ["Gnosis"]
readme = "README.md"
Expand Down
22 changes: 21 additions & 1 deletion tests_integration_with_local_chain/markets/omen/test_omen.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,32 @@ def test_balance_for_user_in_market() -> None:
assert float(balance_no.amount) == 0


@pytest.mark.parametrize(
"collateral_token_address, expected_symbol",
[
(WrappedxDaiContract().address, "WXDAI"),
(sDaiContract().address, "sDAI"),
],
)
def test_omen_fund_and_remove_fund_market(
collateral_token_address: ChecksumAddress,
expected_symbol: str,
local_web3: Web3,
test_keys: APIKeys,
) -> None:
# You can double check your address at https://gnosisscan.io/ afterwards or at the market's address.
market = OmenAgentMarket.from_data_model(pick_binary_market())
market = OmenAgentMarket.from_data_model(
OmenSubgraphHandler().get_omen_binary_markets_simple(
limit=1,
filter_by=FilterBy.OPEN,
sort_by=SortBy.CLOSING_SOONEST,
collateral_token_address_in=(collateral_token_address,),
)[0]
)
collateral_token_contract = market.get_contract().get_collateral_token_contract()
assert (
collateral_token_contract.symbol() == expected_symbol
), f"Should have retrieved {expected_symbol} market."
logger.debug(
"Fund and remove funding market test address:",
market.market_maker_contract_address_checksummed,
Expand Down

0 comments on commit 43b39d1

Please sign in to comment.