-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented functions for microchain agent #59
Conversation
gabrielfior
commented
Apr 9, 2024
- getWalletBalance
- get markets given user positions
- fetch individual token balances for a given market outcome
* First commit with microchain agent * Separate out functions to separate file * Mypy and formatting * Formatting
# Conflicts: # prediction_market_agent/agents/microchain_agent/functions.py # prediction_market_agent/agents/microchain_agent/microchain_agent.py
WalkthroughThe update introduces the initial steps towards implementing a General Agent that utilizes the microchain framework for interacting with Omen prediction markets. This integration sets the foundation for incorporating Omen-specific functions into the PMA repository, enhancing market interaction capabilities and preparing for future agent executions within the system. Changes
Possibly related issues
Recent Review StatusConfiguration used: CodeRabbit UI Files selected for processing (3)
Files skipped from review as they are similar to previous changes (1)
Additional comments not posted (6)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
@@ -0,0 +1,5 @@ | |||
# General agent | |||
|
|||
Idea of this agent is to be able to reason freely about which actions it should take in order to partake in Omen's markets. This includes actions such as `getMarkets`, `getYesTokens`, `getNoTokens`, `removeFunding`, etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider rephrasing for conciseness and clarity.
- Idea of this agent is to be able to reason freely about which actions it should take in order to partake in Omen's markets.
+ The agent is designed to strategically interact with Omen's markets by determining actions such as `getMarkets`, `getYesTokens`, `getNoTokens`, `removeFunding`, etc.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
Idea of this agent is to be able to reason freely about which actions it should take in order to partake in Omen's markets. This includes actions such as `getMarkets`, `getYesTokens`, `getNoTokens`, `removeFunding`, etc. | |
The agent is designed to strategically interact with Omen's markets by determining actions such as `getMarkets`, `getYesTokens`, `getNoTokens`, `removeFunding`, etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean to have prediction_market_agent/agents/general_agent in there?
Also, I think prediction_market_agent/agents/microchain_agent/tools.py should be in prediction_market_agent/agents/microchain_agent/utils.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
def get_omen_market_token_balance( | ||
user_address: ChecksumAddress, market_condition_id: HexBytes, market_index_set: int | ||
) -> Wei: | ||
# We get the multiple positions for each market | ||
positions = OmenSubgraphHandler().get_positions(market_condition_id) | ||
# Find position matching market_outcome | ||
position_for_index_set = next( | ||
p for p in positions if market_index_set in p.indexSets | ||
) | ||
position_as_int = int(position_for_index_set.id.hex(), 16) | ||
balance = OmenConditionalTokenContract().balanceOf(user_address, position_as_int) | ||
return balance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure proper error handling for the case where no position matches the market_index_set
.
- position_for_index_set = next(
- p for p in positions if market_index_set in p.indexSets
- )
+ position_for_index_set = next((
+ p for p in positions if market_index_set in p.indexSets
+ ), None)
+ if position_for_index_set is None:
+ raise ValueError("No matching position found for the given market_index_set.")
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
def get_omen_market_token_balance( | |
user_address: ChecksumAddress, market_condition_id: HexBytes, market_index_set: int | |
) -> Wei: | |
# We get the multiple positions for each market | |
positions = OmenSubgraphHandler().get_positions(market_condition_id) | |
# Find position matching market_outcome | |
position_for_index_set = next( | |
p for p in positions if market_index_set in p.indexSets | |
) | |
position_as_int = int(position_for_index_set.id.hex(), 16) | |
balance = OmenConditionalTokenContract().balanceOf(user_address, position_as_int) | |
return balance | |
def get_omen_market_token_balance( | |
user_address: ChecksumAddress, market_condition_id: HexBytes, market_index_set: int | |
) -> Wei: | |
# We get the multiple positions for each market | |
positions = OmenSubgraphHandler().get_positions(market_condition_id) | |
# Find position matching market_outcome | |
position_for_index_set = next(( | |
p for p in positions if market_index_set in p.indexSets | |
), None) | |
if position_for_index_set is None: | |
raise ValueError("No matching position found for the given market_index_set.") | |
position_as_int = int(position_for_index_set.id.hex(), 16) | |
balance = OmenConditionalTokenContract().balanceOf(user_address, position_as_int) | |
return balance |
def test_agent_0_has_bet_on_market() -> None: | ||
user_positions = GetUserPositions()(AGENT_0_ADDRESS) | ||
# Assert 3 conditionIds are included | ||
expected_condition_ids = [ | ||
HexBytes("0x9c7711bee0902cc8e6838179058726a7ba769cc97d4d0ea47b31370d2d7a117b"), | ||
HexBytes("0xe2bf80af2a936cdabeef4f511620a2eec46f1caf8e75eb5dc189372367a9154c"), | ||
HexBytes("0x3f8153364001b26b983dd92191a084de8230f199b5ad0b045e9e1df61089b30d"), | ||
] | ||
unique_condition_ids = sum([u.position.conditionIds for u in user_positions], []) | ||
assert set(expected_condition_ids).issubset(unique_condition_ids) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a check to ensure user_positions
is not empty before proceeding with assertions.
+ if not user_positions:
+ pytest.fail("No user positions found.")
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
def test_agent_0_has_bet_on_market() -> None: | |
user_positions = GetUserPositions()(AGENT_0_ADDRESS) | |
# Assert 3 conditionIds are included | |
expected_condition_ids = [ | |
HexBytes("0x9c7711bee0902cc8e6838179058726a7ba769cc97d4d0ea47b31370d2d7a117b"), | |
HexBytes("0xe2bf80af2a936cdabeef4f511620a2eec46f1caf8e75eb5dc189372367a9154c"), | |
HexBytes("0x3f8153364001b26b983dd92191a084de8230f199b5ad0b045e9e1df61089b30d"), | |
] | |
unique_condition_ids = sum([u.position.conditionIds for u in user_positions], []) | |
assert set(expected_condition_ids).issubset(unique_condition_ids) | |
def test_agent_0_has_bet_on_market() -> None: | |
user_positions = GetUserPositions()(AGENT_0_ADDRESS) | |
if not user_positions: | |
pytest.fail("No user positions found.") | |
# Assert 3 conditionIds are included | |
expected_condition_ids = [ | |
HexBytes("0x9c7711bee0902cc8e6838179058726a7ba769cc97d4d0ea47b31370d2d7a117b"), | |
HexBytes("0xe2bf80af2a936cdabeef4f511620a2eec46f1caf8e75eb5dc189372367a9154c"), | |
HexBytes("0x3f8153364001b26b983dd92191a084de8230f199b5ad0b045e9e1df61089b30d"), | |
] | |
unique_condition_ids = sum([u.position.conditionIds for u in user_positions], []) | |
assert set(expected_condition_ids).issubset(unique_condition_ids) |