Skip to content
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

Merged
merged 11 commits into from
Apr 9, 2024

Conversation

gabrielfior
Copy link
Contributor

  • getWalletBalance
  • get markets given user positions
  • fetch individual token balances for a given market outcome

gabrielfior and others added 9 commits April 7, 2024 22:52
* First commit with microchain agent

* Separate out functions to separate file

* Mypy and formatting

* Formatting
)

* Use branch of microchain that contains token-tracking functionality

* Formatting

* Review comment
# Conflicts:
#	prediction_market_agent/agents/microchain_agent/functions.py
#	prediction_market_agent/agents/microchain_agent/microchain_agent.py
Copy link
Contributor

coderabbitai bot commented Apr 9, 2024

Walkthrough

The 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

Files Summary
.../general_agent/README.md Introduces the initial steps towards a General Agent using microchain and Omen integration.
.../general_agent/deploy.py Adds deployment functionality for prediction markets.
.../general_agent/general_agent.py Defines the GeneralAgent class for Omen market interactions.
.../general_agent/omen_functions.py Includes tools for fetching Omen binary markets.
.../microchain_agent/functions.py Adds classes for retrieving user wallet balance and market positions.
.../microchain_agent/utils.py Enhances functionality for interacting with Omen markets and user authentication.
tests/agents/test_microchain.py Updated with new imports, variables, fixtures, and test functions for microchain agent.

Possibly related issues

  • Issue Database: github
    • This update aligns with the objective of integrating a General Agent using microchain and Omen, as outlined in the issue by gabrielfior.

Recent Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ee3be2e and 28bcd9f.
Files selected for processing (3)
  • prediction_market_agent/agents/microchain_agent/functions.py (5 hunks)
  • prediction_market_agent/agents/microchain_agent/utils.py (2 hunks)
  • tests/agents/test_microchain.py (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • prediction_market_agent/agents/microchain_agent/functions.py
Additional comments not posted (6)
prediction_market_agent/agents/microchain_agent/utils.py (2)

1-20: Consider grouping imports from the same module together for better readability.


70-74: Validate the presence of the BET_FROM_PRIVATE_KEY environment variable at the start of the application to avoid runtime failures.

tests/agents/test_microchain.py (4)

1-11: Ensure newly added imports are used within the file to avoid unnecessary import statements.

Verification successful

The verification process has confirmed that the newly added imports HexAddress, HexStr, and Web3 are indeed utilized within the test_microchain.py file. Specifically, HexAddress and HexStr are used to define a market_id, and Web3 is employed to convert a user address to a checksum address. This indicates that the imports are necessary for the functionality implemented in the file and are not extraneous.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify usage of newly added imports.
rg --type py 'HexAddress|HexStr|Web3' tests/agents/test_microchain.py

Length of output: 346


30-33: The before_all_tests fixture is a good practice for setting up environment variables. Ensure .env file is properly secured and documented.


55-57: Great use of the GetWalletBalance callable object to simplify balance retrieval.


72-93: Ensure the hardcoded balance values in assertions are expected and document the source or reasoning behind these specific values.

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?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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.
Copy link
Contributor

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.

Suggested change
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.

prediction_market_agent/agents/general_agent/deploy.py Outdated Show resolved Hide resolved
prediction_market_agent/agents/microchain_agent/tools.py Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

tests/agents/test_microchain.py Outdated Show resolved Hide resolved
Copy link
Contributor

@evangriffiths evangriffiths left a 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

@gabrielfior gabrielfior merged commit dfd6b6c into main Apr 9, 2024
6 checks passed
@gabrielfior gabrielfior deleted the gabriel/getWalletBalance branch April 9, 2024 15:33
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Comment on lines +56 to +67
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
Copy link
Contributor

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.

Suggested change
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

Comment on lines +60 to +69
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)
Copy link
Contributor

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.

Suggested change
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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants