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

Add script for betting on omen #4

Merged
merged 1 commit into from
Feb 12, 2024
Merged

Conversation

kongzii
Copy link
Contributor

@kongzii kongzii commented Feb 11, 2024

Summary by CodeRabbit

  • New Features
    • Introduced a new betting and selling outcomes feature for the Omen prediction market, enabling users to interact with markets directly through the script.

Copy link

coderabbitai bot commented Feb 11, 2024

Walkthrough

This update introduces a new script, bet_omen.py, designed to facilitate interactions with the Omen prediction market. It allows users to easily buy and sell outcomes of events by specifying parameters such as the amount to bet, wallet addresses, market ID, and the outcome they wish to bet on. The script automates the interaction with Omen contracts using the provided private keys and market information.

Changes

Files Change Summary
scripts/bet_omen.py Introduced a new script for betting on and selling outcomes in Omen market

🏈🐰 A rabbit hopped down the field, with a playful cheer,
"The Chiefs and the 49ers clash, the Super Bowl is here!
With each pass and tackle, excitement in the air,
We bet and watch, in Omen's market, with flair.
May the best team win, with strength and grace,
In this spirited game, a thrilling chase!"
🎉🏆🐾

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-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@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.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f0b069b and 51c1fd4.
Files ignored due to path filters (2)
  • mypy.ini is excluded by: !**/*.ini
  • pyproject.toml is excluded by: !**/*.toml
Files selected for processing (1)
  • scripts/bet_omen.py (1 hunks)
Additional comments: 1
scripts/bet_omen.py (1)
  • 85-86: The script initialization is correctly set up to run the typer app. No issues found here.

Comment on lines +17 to +48
@app.command()
def buy(
amount: str = typer.Option(),
from_address: str = typer.Option(),
from_private_key: str = typer.Option(),
market_id: str = typer.Option(),
outcome: str = typer.Option(),
auto_deposit: bool = typer.Option(False),
) -> None:
"""
Helper script to place a bet on Omen, usage:

```bash
python scripts/bet_omen.py buy \
--amount 0.01 \
--from-address your-address \
--from-private-key your-private-key \
--market-id some-market-id \
--outcome one-of-the-outcomes
```

Market ID can be found easily in the URL: https://aiomen.eth.limo/#/0x86376012a5185f484ec33429cadfa00a8052d9d4
"""
market = get_market(market_id)
omen_buy_outcome_tx(
amount=xdai_type(amount),
from_address=verify_address(from_address),
from_private_key=PrivateKey(from_private_key),
market=market,
outcome=outcome,
auto_deposit=auto_deposit,
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The buy function lacks input validation for amount, market_id, and outcome. Ensure inputs are sanitized and validated to prevent injection attacks or errors.

+    if not amount.isdigit():
+        raise ValueError("Amount must be a numeric value.")
+    if not market_id.isalnum():
+        raise ValueError("Market ID must be alphanumeric.")
+    if not outcome.isalnum():
+        raise ValueError("Outcome must be alphanumeric.")

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
@app.command()
def buy(
amount: str = typer.Option(),
from_address: str = typer.Option(),
from_private_key: str = typer.Option(),
market_id: str = typer.Option(),
outcome: str = typer.Option(),
auto_deposit: bool = typer.Option(False),
) -> None:
"""
Helper script to place a bet on Omen, usage:
```bash
python scripts/bet_omen.py buy \
--amount 0.01 \
--from-address your-address \
--from-private-key your-private-key \
--market-id some-market-id \
--outcome one-of-the-outcomes
```
Market ID can be found easily in the URL: https://aiomen.eth.limo/#/0x86376012a5185f484ec33429cadfa00a8052d9d4
"""
market = get_market(market_id)
omen_buy_outcome_tx(
amount=xdai_type(amount),
from_address=verify_address(from_address),
from_private_key=PrivateKey(from_private_key),
market=market,
outcome=outcome,
auto_deposit=auto_deposit,
)
@app.command()
def buy(
amount: str = typer.Option(),
from_address: str = typer.Option(),
from_private_key: str = typer.Option(),
market_id: str = typer.Option(),
outcome: str = typer.Option(),
auto_deposit: bool = typer.Option(False),
) -> None:
"""
Helper script to place a bet on Omen, usage:
```bash
python scripts/bet_omen.py buy \
--amount 0.01 \
--from-address your-address \
--from-private-key your-private-key \
--market-id some-market-id \
--outcome one-of-the-outcomes
```
Market ID can be found easily in the URL: https://aiomen.eth.limo/#/0x86376012a5185f484ec33429cadfa00a8052d9d4
"""
if not amount.isdigit():
raise ValueError("Amount must be a numeric value.")
if not market_id.isalnum():
raise ValueError("Market ID must be alphanumeric.")
if not outcome.isalnum():
raise ValueError("Outcome must be alphanumeric.")
market = get_market(market_id)
omen_buy_outcome_tx(
amount=xdai_type(amount),
from_address=verify_address(from_address),
from_private_key=PrivateKey(from_private_key),
market=market,
outcome=outcome,
auto_deposit=auto_deposit,
)

Comment on lines +51 to +82
@app.command()
def sell(
amount: str = typer.Option(),
from_address: str = typer.Option(),
from_private_key: str = typer.Option(),
market_id: str = typer.Option(),
outcome: str = typer.Option(),
auto_withdraw: bool = typer.Option(False),
) -> None:
"""
Helper script to sell outcome of an existing bet on Omen, usage:

```bash
python scripts/bet_omen.py sell \
--amount 0.01 \
--from-address your-address \
--from-private-key your-private-key \
--market-id some-market-id \
--outcome one-of-the-outcomes
```

Market ID can be found easily in the URL: https://aiomen.eth.limo/#/0x86376012a5185f484ec33429cadfa00a8052d9d4
"""
market = get_market(market_id)
omen_sell_outcome_tx(
amount=xdai_type(amount),
from_address=verify_address(from_address),
from_private_key=PrivateKey(from_private_key),
market=market,
outcome=outcome,
auto_withdraw=auto_withdraw,
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the buy function, the sell function also lacks input validation for amount, market_id, and outcome. Apply the same input validation here to ensure data integrity and security.

+    if not amount.isdigit():
+        raise ValueError("Amount must be a numeric value.")
+    if not market_id.isalnum():
+        raise ValueError("Market ID must be alphanumeric.")
+    if not outcome.isalnum():
+        raise ValueError("Outcome must be alphanumeric.")

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
@app.command()
def sell(
amount: str = typer.Option(),
from_address: str = typer.Option(),
from_private_key: str = typer.Option(),
market_id: str = typer.Option(),
outcome: str = typer.Option(),
auto_withdraw: bool = typer.Option(False),
) -> None:
"""
Helper script to sell outcome of an existing bet on Omen, usage:
```bash
python scripts/bet_omen.py sell \
--amount 0.01 \
--from-address your-address \
--from-private-key your-private-key \
--market-id some-market-id \
--outcome one-of-the-outcomes
```
Market ID can be found easily in the URL: https://aiomen.eth.limo/#/0x86376012a5185f484ec33429cadfa00a8052d9d4
"""
market = get_market(market_id)
omen_sell_outcome_tx(
amount=xdai_type(amount),
from_address=verify_address(from_address),
from_private_key=PrivateKey(from_private_key),
market=market,
outcome=outcome,
auto_withdraw=auto_withdraw,
)
@app.command()
def sell(
amount: str = typer.Option(),
from_address: str = typer.Option(),
from_private_key: str = typer.Option(),
market_id: str = typer.Option(),
outcome: str = typer.Option(),
auto_withdraw: bool = typer.Option(False),
) -> None:
"""
Helper script to sell outcome of an existing bet on Omen, usage:
```bash
python scripts/bet_omen.py sell \
--amount 0.01 \
--from-address your-address \
--from-private-key your-private-key \
--market-id some-market-id \
--outcome one-of-the-outcomes
```
Market ID can be found easily in the URL: https://aiomen.eth.limo/#/0x86376012a5185f484ec33429cadfa00a8052d9d4
"""
if not amount.isdigit():
raise ValueError("Amount must be a numeric value.")
if not market_id.isalnum():
raise ValueError("Market ID must be alphanumeric.")
if not outcome.isalnum():
raise ValueError("Outcome must be alphanumeric.")
market = get_market(market_id)
omen_sell_outcome_tx(
amount=xdai_type(amount),
from_address=verify_address(from_address),
from_private_key=PrivateKey(from_private_key),
market=market,
outcome=outcome,
auto_withdraw=auto_withdraw,
)

@kongzii kongzii merged commit e876089 into main Feb 12, 2024
4 checks passed
@kongzii kongzii deleted the peter/add-bet-omen-script branch February 12, 2024 12:15
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.

2 participants