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

Omen market maker functions #24

Merged
merged 8 commits into from
Feb 22, 2024
Merged

Omen market maker functions #24

merged 8 commits into from
Feb 22, 2024

Conversation

kongzii
Copy link
Contributor

@kongzii kongzii commented Feb 21, 2024

Summary by CodeRabbit

  • New Features
    • Introduced a script for creating markets on the Omen prediction platform with customizable details.
    • Added tools for interacting with Realitio contracts, creating markets, and managing conditions.
  • Enhancements
    • Improved configuration flexibility by updating the default GNOSIS_RPC_URL setup.
    • Enhanced smart contract interaction with new utilities, retry mechanisms, and additional constants.

Copy link

coderabbitai bot commented Feb 21, 2024

Walkthrough

The update enhances the prediction_market_agent_tooling package by improving its integration with the Ethereum blockchain and the Omen prediction market. It introduces new imports, classes, and functions across various modules for better interaction with smart contracts, market creation, and condition management. The addition of scripts for market creation and replication on Omen, alongside updates to tooling for more flexible configuration and improved utility functions, significantly broadens the package's capabilities.

Changes

File(s) Summary
.../gtypes.py Added HexBytes import and renamed Wei to Wad.
.../markets/omen.py, .../tools/web3_utils.py Added new imports, global variables, classes, functions, and constants related to interacting with Realitio contracts, creating markets, and managing conditions. Included detailed ABIs and addresses for components.
.../tools/gnosis_rpc.py Updated GNOSIS_RPC_URL to support environment variable for flexible configuration.
scripts/create_market_omen.py, scripts/replicate_to_omen.py Introduced scripts for creating markets on Omen with customizable details and for fetching/replicating markets based on criteria.

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: 6

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between bc88190 and 0f31e1e.
Files ignored due to path filters (6)
  • prediction_market_agent_tooling/abis/omen_dxdao.abi.json is excluded by: !**/*.json
  • prediction_market_agent_tooling/abis/omen_fpmm_conditionaltokens.abi.json is excluded by: !**/*.json
  • prediction_market_agent_tooling/abis/omen_fpmm_factory.abi.json is excluded by: !**/*.json
  • prediction_market_agent_tooling/abis/omen_kleros.abi.json is excluded by: !**/*.json
  • prediction_market_agent_tooling/abis/omen_oracle.abi.json is excluded by: !**/*.json
  • prediction_market_agent_tooling/abis/omen_realitio.abi.json is excluded by: !**/*.json
Files selected for processing (6)
  • prediction_market_agent_tooling/gtypes.py (1 hunks)
  • prediction_market_agent_tooling/markets/omen.py (18 hunks)
  • prediction_market_agent_tooling/tools/gnosis_rpc.py (1 hunks)
  • prediction_market_agent_tooling/tools/web3_utils.py (6 hunks)
  • scripts/create_market_omen.py (1 hunks)
  • scripts/replicate_to_omen.py (1 hunks)
Additional comments: 17
scripts/replicate_to_omen.py (2)
  • 3-7: The import statements are clear and well-organized, ensuring that necessary functions and types from the benchmark.utils module are available for use.
  • 10-12: The function signature for main is concise, accepting a single parameter of type MarketSource. This design choice keeps the script focused on its intended functionality.
prediction_market_agent_tooling/tools/gnosis_rpc.py (2)
  • 1-1: The import of the os module is necessary for accessing environment variables, which is used effectively here to configure the GNOSIS_RPC_URL.
  • 6-6: The update to GNOSIS_RPC_URL to use an environment variable with a fallback value is a good practice for flexible configuration, allowing for easy adjustments without modifying the codebase.
prediction_market_agent_tooling/gtypes.py (2)
  • 10-12: The import of HexBytes from the hexbytes module, marked with noqa: F401 to ignore unused import warnings, is a good practice for facilitating easier importing within other modules.
  • 12-12: Renaming Wei to Wad with a comment explaining the aliasing is a thoughtful change that aligns with the variable naming conventions used in contracts. This enhances readability and consistency in the codebase.
scripts/create_market_omen.py (3)
  • 1-12: The import statements are well-organized, ensuring that necessary types, functions, and constants from various modules are available for use in creating a market on Omen.
  • 17-28: The main function is well-structured, using typer options to accept various parameters for market creation. This approach makes the script user-friendly and flexible for different market configurations.
  • 44-56: The call to omen_create_market_tx within the main function is correctly set up with all required parameters, including the conversion of initial_funds to xdai_type and the use of verify_address to validate the from_address. This ensures that the market creation process is executed with valid and correctly formatted inputs.
prediction_market_agent_tooling/tools/web3_utils.py (5)
  • 5-5: The addition of the tenacity library for implementing retry mechanisms is a valuable enhancement, improving the reliability of interactions with the blockchain by automatically retrying failed operations.
  • 25-33: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [19-30]

The introduction of new constants, such as GNOSIS_NETWORK_ID and WXDAI_CONTRACT_ADDRESS, along with the WXDAI_ABI, is a good practice for maintaining clear and easily modifiable configuration values.

  • 79-86: The parse_function_params function is a useful addition, providing flexibility in how function parameters are specified, either as a list or a dictionary. This enhances the usability of contract interaction functions.
  • 89-95: The use of the @tenacity.retry decorator on call_function_on_contract is an excellent application of the tenacity library, ensuring that transient failures in contract interactions are gracefully handled with retries.
  • 127-140: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [116-139]

The enhancements to call_function_on_contract_tx, including the addition of a timeout parameter and receipt verification, significantly improve the function's robustness and flexibility. The use of parse_function_params within this function further demonstrates the utility of the new parsing functionality.

prediction_market_agent_tooling/markets/omen.py (3)
  • 8-13: The addition of new imports (json, random, typing, datetime, Enum) is appropriate for the functionalities introduced in this file. Ensure that these libraries are used efficiently and securely throughout the code.
  • 50-53: The Arbitrator class definition using Enum is a good practice for defining constants with clear, readable names. This approach enhances code readability and maintainability.
  • 182-189: The function get_arbitrator_contract_address_and_abi correctly handles different arbitrators by returning the respective contract address and ABI. However, it's essential to ensure that all possible arbitrators are covered, and the error message for an unknown arbitrator is informative.

Comment on lines 46 to 47
OMEN_DEFAULT_MARKET_FEE = 0.02 # 2% fee from the buying shares amount.
DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS = WXDAI_CONTRACT_ADDRESS
Copy link

Choose a reason for hiding this comment

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

The introduction of new global variables OMEN_DEFAULT_MARKET_FEE and DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS is clear and follows naming conventions. However, consider documenting these variables to explain their purpose and usage within the system.

+ # OMEN_DEFAULT_MARKET_FEE: Default fee percentage for market transactions.
+ # DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS: Default address for the collateral token contract used in market transactions.

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
OMEN_DEFAULT_MARKET_FEE = 0.02 # 2% fee from the buying shares amount.
DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS = WXDAI_CONTRACT_ADDRESS
# OMEN_DEFAULT_MARKET_FEE: Default fee percentage for market transactions.
OMEN_DEFAULT_MARKET_FEE = 0.02 # 2% fee from the buying shares amount.
# DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS: Default address for the collateral token contract used in market transactions.
DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS = WXDAI_CONTRACT_ADDRESS

Comment on lines 231 to 246
market_maker_contract_address: ChecksumAddress,
collateral_token_contract_address: ChecksumAddress,
amount_wei: Wei,
from_address: ChecksumAddress,
from_private_key: PrivateKey,
tx_params: Optional[TxParams] = None,
tx_params: t.Optional[TxParams] = None,
) -> TxReceipt:
return call_function_on_contract_tx(
web3=web3,
contract_address=market.collateral_token_contract_address_checksummed,
contract_address=collateral_token_contract_address,
contract_abi=WXDAI_ABI,
from_address=from_address,
from_private_key=from_private_key,
function_name="approve",
function_params=[
market.market_maker_contract_address_checksummed,
market_maker_contract_address,
Copy link

Choose a reason for hiding this comment

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

In the function omen_approve_market_maker_to_spend_collateral_token_tx, consider validating the input parameters, especially amount_wei, to ensure they meet expected criteria (e.g., non-negative values). This can prevent unintended behavior or transactions.

+ if amount_wei < 0:
+     raise ValueError("amount_wei must be non-negative")

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
market_maker_contract_address: ChecksumAddress,
collateral_token_contract_address: ChecksumAddress,
amount_wei: Wei,
from_address: ChecksumAddress,
from_private_key: PrivateKey,
tx_params: Optional[TxParams] = None,
tx_params: t.Optional[TxParams] = None,
) -> TxReceipt:
return call_function_on_contract_tx(
web3=web3,
contract_address=market.collateral_token_contract_address_checksummed,
contract_address=collateral_token_contract_address,
contract_abi=WXDAI_ABI,
from_address=from_address,
from_private_key=from_private_key,
function_name="approve",
function_params=[
market.market_maker_contract_address_checksummed,
market_maker_contract_address,
market_maker_contract_address: ChecksumAddress,
collateral_token_contract_address: ChecksumAddress,
amount_wei: Wei,
from_address: ChecksumAddress,
from_private_key: PrivateKey,
tx_params: t.Optional[TxParams] = None,
) -> TxReceipt:
if amount_wei < 0:
raise ValueError("amount_wei must be non-negative")
return call_function_on_contract_tx(
web3=web3,
contract_address=collateral_token_contract_address,
contract_abi=WXDAI_ABI,
from_address=from_address,
from_private_key=from_private_key,
function_name="approve",
function_params=[
market_maker_contract_address,

Comment on lines 588 to 637
web3: Web3,
question: str,
category: str,
outcomes: list[str],
language: str,
arbitrator: Arbitrator,
opening: datetime,
from_address: ChecksumAddress,
from_private_key: PrivateKey,
nonce: int | None = None,
tx_params: t.Optional[TxParams] = None,
) -> HexBytes:
"""
After the question is created, you can find it at https://reality.eth.link/app/#!/creator/{from_address}.
"""
arbitrator_contract_address, _ = get_arbitrator_contract_address_and_abi(arbitrator)
# See https://realitio.github.io/docs/html/contracts.html#templates
# for possible template ids and how to format the question.
template_id = 2
realitio_question = "␟".join(
[
question,
json.dumps(outcomes),
category,
language,
]
)
receipt_tx = call_function_on_contract_tx(
web3=web3,
contract_address=OMEN_REALITIO_CONTRACT_ADDRESS,
contract_abi=OMEN_REALITIO_ABI,
from_address=from_address,
from_private_key=from_private_key,
function_name="askQuestion",
function_params=dict(
template_id=template_id,
question=realitio_question,
arbitrator=arbitrator_contract_address,
timeout=86400, # See https://github.com/protofire/omen-exchange/blob/2cfdf6bfe37afa8b169731d51fea69d42321d66c/app/src/util/networks.ts#L278.
opening_ts=int(opening.timestamp()),
nonce=(
nonce if nonce is not None else random.randint(0, 1000000)
), # Two equal questions need to have different nonces.
),
tx_params=tx_params,
)
question_id: HexBytes = receipt_tx["logs"][0]["topics"][
1
] # The question id is available in the first emitted log, in the second topic.
return question_id
Copy link

Choose a reason for hiding this comment

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

The function omen_realitio_ask_question_tx introduces a mechanism to ask questions on Realitio. It's crucial to validate input parameters, such as ensuring question, category, outcomes, and language are not empty. Additionally, consider extracting the nonce generation (random.randint(0, 1000000)) into a separate function for better testability and maintainability.

+ if not question or not category or not outcomes or not language:
+     raise ValueError("Question, category, outcomes, and language must not be empty")
+ # Extract nonce generation for better maintainability
+ def generate_nonce():
+     return random.randint(0, 1000000)

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
web3: Web3,
question: str,
category: str,
outcomes: list[str],
language: str,
arbitrator: Arbitrator,
opening: datetime,
from_address: ChecksumAddress,
from_private_key: PrivateKey,
nonce: int | None = None,
tx_params: t.Optional[TxParams] = None,
) -> HexBytes:
"""
After the question is created, you can find it at https://reality.eth.link/app/#!/creator/{from_address}.
"""
arbitrator_contract_address, _ = get_arbitrator_contract_address_and_abi(arbitrator)
# See https://realitio.github.io/docs/html/contracts.html#templates
# for possible template ids and how to format the question.
template_id = 2
realitio_question = "␟".join(
[
question,
json.dumps(outcomes),
category,
language,
]
)
receipt_tx = call_function_on_contract_tx(
web3=web3,
contract_address=OMEN_REALITIO_CONTRACT_ADDRESS,
contract_abi=OMEN_REALITIO_ABI,
from_address=from_address,
from_private_key=from_private_key,
function_name="askQuestion",
function_params=dict(
template_id=template_id,
question=realitio_question,
arbitrator=arbitrator_contract_address,
timeout=86400, # See https://github.com/protofire/omen-exchange/blob/2cfdf6bfe37afa8b169731d51fea69d42321d66c/app/src/util/networks.ts#L278.
opening_ts=int(opening.timestamp()),
nonce=(
nonce if nonce is not None else random.randint(0, 1000000)
), # Two equal questions need to have different nonces.
),
tx_params=tx_params,
)
question_id: HexBytes = receipt_tx["logs"][0]["topics"][
1
] # The question id is available in the first emitted log, in the second topic.
return question_id
web3: Web3,
question: str,
category: str,
outcomes: list[str],
language: str,
arbitrator: Arbitrator,
opening: datetime,
from_address: ChecksumAddress,
from_private_key: PrivateKey,
nonce: int | None = None,
tx_params: t.Optional[TxParams] = None,
) -> HexBytes:
"""
After the question is created, you can find it at https://reality.eth.link/app/#!/creator/{from_address}.
"""
if not question or not category or not outcomes or not language:
raise ValueError("Question, category, outcomes, and language must not be empty")
# Extract nonce generation for better maintainability
def generate_nonce():
return random.randint(0, 1000000)
arbitrator_contract_address, _ = get_arbitrator_contract_address_and_abi(arbitrator)
# See https://realitio.github.io/docs/html/contracts.html#templates
# for possible template ids and how to format the question.
template_id = 2
realitio_question = "␟".join(
[
question,
json.dumps(outcomes),
category,
language,
]
)
receipt_tx = call_function_on_contract_tx(
web3=web3,
contract_address=OMEN_REALITIO_CONTRACT_ADDRESS,
contract_abi=OMEN_REALITIO_ABI,
from_address=from_address,
from_private_key=from_private_key,
function_name="askQuestion",
function_params=dict(
template_id=template_id,
question=realitio_question,
arbitrator=arbitrator_contract_address,
timeout=86400, # See https://github.com/protofire/omen-exchange/blob/2cfdf6bfe37afa8b169731d51fea69d42321d66c/app/src/util/networks.ts#L278.
opening_ts=int(opening.timestamp()),
nonce=(
nonce if nonce is not None else generate_nonce()
), # Two equal questions need to have different nonces.
),
tx_params=tx_params,
)
question_id: HexBytes = receipt_tx["logs"][0]["topics"][
1
] # The question id is available in the first emitted log, in the second topic.
return question_id

Comment on lines 695 to 841
raise RuntimeError(
"The oracle's conditional tokens address is not the same as we are using."
)

# Get the current nonce for the given from_address.
# If making multiple transactions quickly after each other,
# it's better to increae it manually (otherwise we could get stale value from the network and error out).
nonce: Nonce = web3.eth.get_transaction_count(from_address_checksummed)

# Approve the market maker to withdraw our collateral token.
omen_approve_market_maker_to_spend_collateral_token_tx(
web3=web3,
market_maker_contract_address=OMEN_FPMM_FACTORY_CONTRACT_ADDRESS,
collateral_token_contract_address=DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS,
amount_wei=initial_funds_wei,
from_address=from_address_checksummed,
from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.

# Deposit xDai to the collateral token,
# this can be skipped, if we know we already have enough collateral tokens.
if auto_deposit and initial_funds_wei > 0:
omen_deposit_collateral_token_tx(
web3=web3,
collateral_token_contract_address=DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS,
amount_wei=initial_funds_wei,
from_address=from_address_checksummed,
from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.

# Create the question on Realitio.
question_id = omen_realitio_ask_question_tx(
web3=web3,
question=question,
category=category,
outcomes=outcomes,
language=language,
arbitrator=Arbitrator.KLEROS,
opening=closing_time, # The question is opened at the closing time of the market.
from_address=from_address_checksummed,
from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.

# Construct the condition id.
condition_id = omen_construct_condition_id(
web3=web3,
question_id=question_id,
oracle_address=OMEN_ORACLE_CONTRACT_ADDRESS,
outcomes_slot_count=len(outcomes),
)
if not omen_does_condition_exist(web3, condition_id):
omen_prepare_condition_tx(
web3,
question_id=question_id,
oracle_address=OMEN_ORACLE_CONTRACT_ADDRESS,
outcomes_slot_count=len(outcomes),
from_address=from_address_checksummed,
from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.

# Create the market.
create_market_receipt_tx = call_function_on_contract_tx(
web3=web3,
contract_address=OMEN_FPMM_FACTORY_CONTRACT_ADDRESS,
contract_abi=OMEN_FPMM_FACTORY_ABI,
from_address=from_address,
from_private_key=from_private_key,
function_name="create2FixedProductMarketMaker",
function_params=dict(
saltNonce=random.randint(
0, 1000000
), # See https://github.com/protofire/omen-exchange/blob/923756c3a9ac370f8e89af8193393a53531e2c0f/app/src/services/cpk/fns.ts#L942.
conditionalTokens=OMEN_FPMM_CONDITIONALTOKENS_CONTRACT_ADDRESS,
collateralToken=DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS,
conditionIds=[condition_id],
fee=fee_wei,
initialFunds=initial_funds_wei,
distributionHint=[],
),
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.

# Note: In the Omen's Typescript code, there is futher a creation of `stakingRewardsFactoryAddress`,
# (https://github.com/protofire/omen-exchange/blob/763d9c9d05ebf9edacbc1dbaa561aa5d08813c0f/app/src/services/cpk/fns.ts#L979)
# but address of stakingRewardsFactoryAddress on xDai/Gnosis is 0x0000000000000000000000000000000000000000,
# so skipping it here.

market_address = create_market_receipt_tx["logs"][-1][
"address"
] # The market address is available in the last emitted log, in the address field.
return market_address
Copy link

Choose a reason for hiding this comment

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

The omen_create_market_tx function is comprehensive and covers many steps in creating a market. It's well-structured, but there are a few areas for improvement:

  • Validate the initial_funds and fee parameters to ensure they are within expected ranges.
  • The error checks for oracle's realitio and conditional tokens addresses are crucial. Ensure that these checks are accurate and that the addresses used in the checks are up-to-date.
  • The nonce management strategy (manually incrementing nonce) is clear but ensure that this approach is consistent with the rest of the system and documented for future developers.
  • Consider breaking down this function into smaller, more focused functions to improve readability and maintainability.
+ # Validate initial funds and fee
+ if initial_funds < 0 or fee < 0 or fee > 1:
+     raise ValueError("Invalid initial funds or fee")
+ # Suggestion to break down the function into smaller parts for better readability

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 omen_create_market_tx(
initial_funds: xDai,
question: str,
closing_time: datetime,
category: str,
language: str,
from_address: ChecksumAddress,
from_private_key: PrivateKey,
outcomes: list[str],
auto_deposit: bool,
fee: float = OMEN_DEFAULT_MARKET_FEE,
) -> ChecksumAddress:
"""
Based on omen-exchange TypeScript code: https://github.com/protofire/omen-exchange/blob/b0b9a3e71b415d6becf21fe428e1c4fc0dad2e80/app/src/services/cpk/cpk.ts#L308
"""
web3 = Web3(Web3.HTTPProvider(GNOSIS_RPC_URL))
from_address_checksummed = Web3.to_checksum_address(from_address)
initial_funds_wei = xdai_to_wei(initial_funds)
fee_wei = xdai_to_wei(
xdai_type(fee)
) # We need to convert this to the wei units, but in reality it's % fee as stated in the `OMEN_DEFAULT_MARKET_FEE` variable.
# These checks were originally maded somewhere in the middle of the process, but it's safer to do them right away.
# Double check that the oracle's realitio address is the same as we are using.
if (
call_function_on_contract(
web3,
OMEN_ORACLE_CONTRACT_ADDRESS,
OMEN_ORACLE_ABI,
"realitio",
)
!= OMEN_REALITIO_CONTRACT_ADDRESS
):
raise RuntimeError(
"The oracle's realitio address is not the same as we are using."
)
# Double check that the oracle's conditional tokens address is the same as we are using.
if (
call_function_on_contract(
web3,
OMEN_ORACLE_CONTRACT_ADDRESS,
OMEN_ORACLE_ABI,
"conditionalTokens",
)
!= OMEN_FPMM_CONDITIONALTOKENS_CONTRACT_ADDRESS
):
raise RuntimeError(
"The oracle's conditional tokens address is not the same as we are using."
)
# Get the current nonce for the given from_address.
# If making multiple transactions quickly after each other,
# it's better to increae it manually (otherwise we could get stale value from the network and error out).
nonce: Nonce = web3.eth.get_transaction_count(from_address_checksummed)
# Approve the market maker to withdraw our collateral token.
omen_approve_market_maker_to_spend_collateral_token_tx(
web3=web3,
market_maker_contract_address=OMEN_FPMM_FACTORY_CONTRACT_ADDRESS,
collateral_token_contract_address=DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS,
amount_wei=initial_funds_wei,
from_address=from_address_checksummed,
from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.
# Deposit xDai to the collateral token,
# this can be skipped, if we know we already have enough collateral tokens.
if auto_deposit and initial_funds_wei > 0:
omen_deposit_collateral_token_tx(
web3=web3,
collateral_token_contract_address=DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS,
amount_wei=initial_funds_wei,
from_address=from_address_checksummed,
from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.
# Create the question on Realitio.
question_id = omen_realitio_ask_question_tx(
web3=web3,
question=question,
category=category,
outcomes=outcomes,
language=language,
arbitrator=Arbitrator.KLEROS,
opening=closing_time, # The question is opened at the closing time of the market.
from_address=from_address_checksummed,
from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.
# Construct the condition id.
condition_id = omen_construct_condition_id(
web3=web3,
question_id=question_id,
oracle_address=OMEN_ORACLE_CONTRACT_ADDRESS,
outcomes_slot_count=len(outcomes),
)
if not omen_does_condition_exist(web3, condition_id):
omen_prepare_condition_tx(
web3,
question_id=question_id,
oracle_address=OMEN_ORACLE_CONTRACT_ADDRESS,
outcomes_slot_count=len(outcomes),
from_address=from_address_checksummed,
from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.
# Create the market.
create_market_receipt_tx = call_function_on_contract_tx(
web3=web3,
contract_address=OMEN_FPMM_FACTORY_CONTRACT_ADDRESS,
contract_abi=OMEN_FPMM_FACTORY_ABI,
from_address=from_address,
from_private_key=from_private_key,
function_name="create2FixedProductMarketMaker",
function_params=dict(
saltNonce=random.randint(
0, 1000000
), # See https://github.com/protofire/omen-exchange/blob/923756c3a9ac370f8e89af8193393a53531e2c0f/app/src/services/cpk/fns.ts#L942.
conditionalTokens=OMEN_FPMM_CONDITIONALTOKENS_CONTRACT_ADDRESS,
collateralToken=DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS,
conditionIds=[condition_id],
fee=fee_wei,
initialFunds=initial_funds_wei,
distributionHint=[],
),
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.
# Note: In the Omen's Typescript code, there is futher a creation of `stakingRewardsFactoryAddress`,
# (https://github.com/protofire/omen-exchange/blob/763d9c9d05ebf9edacbc1dbaa561aa5d08813c0f/app/src/services/cpk/fns.ts#L979)
# but address of stakingRewardsFactoryAddress on xDai/Gnosis is 0x0000000000000000000000000000000000000000,
# so skipping it here.
market_address = create_market_receipt_tx["logs"][-1][
"address"
] # The market address is available in the last emitted log, in the address field.
return market_address
def omen_create_market_tx(
initial_funds: xDai,
question: str,
closing_time: datetime,
category: str,
language: str,
from_address: ChecksumAddress,
from_private_key: PrivateKey,
outcomes: list[str],
auto_deposit: bool,
fee: float = OMEN_DEFAULT_MARKET_FEE,
) -> ChecksumAddress:
"""
Based on omen-exchange TypeScript code: https://github.com/protofire/omen-exchange/blob/b0b9a3e71b415d6becf21fe428e1c4fc0dad2e80/app/src/services/cpk/cpk.ts#L308
"""
web3 = Web3(Web3.HTTPProvider(GNOSIS_RPC_URL))
from_address_checksummed = Web3.to_checksum_address(from_address)
# Validate initial funds and fee
if initial_funds < 0 or fee < 0 or fee > 1:
raise ValueError("Invalid initial funds or fee")
initial_funds_wei = xdai_to_wei(initial_funds)
fee_wei = xdai_to_wei(
xdai_type(fee)
) # We need to convert this to the wei units, but in reality it's % fee as stated in the `OMEN_DEFAULT_MARKET_FEE` variable.
# These checks were originally maded somewhere in the middle of the process, but it's safer to do them right away.
# Double check that the oracle's realitio address is the same as we are using.
if (
call_function_on_contract(
web3,
OMEN_ORACLE_CONTRACT_ADDRESS,
OMEN_ORACLE_ABI,
"realitio",
)
!= OMEN_REALITIO_CONTRACT_ADDRESS
):
raise RuntimeError(
"The oracle's realitio address is not the same as we are using."
)
# Double check that the oracle's conditional tokens address is the same as we are using.
if (
call_function_on_contract(
web3,
OMEN_ORACLE_CONTRACT_ADDRESS,
OMEN_ORACLE_ABI,
"conditionalTokens",
)
!= OMEN_FPMM_CONDITIONALTOKENS_CONTRACT_ADDRESS
):
raise RuntimeError(
"The oracle's conditional tokens address is not the same as we are using."
)
# Get the current nonce for the given from_address.
# If making multiple transactions quickly after each other,
# it's better to increae it manually (otherwise we could get stale value from the network and error out).
nonce: Nonce = web3.eth.get_transaction_count(from_address_checksummed)
# Approve the market maker to withdraw our collateral token.
omen_approve_market_maker_to_spend_collateral_token_tx(
web3=web3,
market_maker_contract_address=OMEN_FPMM_FACTORY_CONTRACT_ADDRESS,
collateral_token_contract_address=DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS,
amount_wei=initial_funds_wei,
from_address=from_address_checksummed,
from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.
# Deposit xDai to the collateral token,
# this can be skipped, if we know we already have enough collateral tokens.
if auto_deposit and initial_funds_wei > 0:
omen_deposit_collateral_token_tx(
web3=web3,
collateral_token_contract_address=DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS,
amount_wei=initial_funds_wei,
from_address=from_address_checksummed,
from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.
# Create the question on Realitio.
question_id = omen_realitio_ask_question_tx(
web3=web3,
question=question,
category=category,
outcomes=outcomes,
language=language,
arbitrator=Arbitrator.KLEROS,
opening=closing_time, # The question is opened at the closing time of the market.
from_address=from_address_checksummed,
from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.
# Construct the condition id.
condition_id = omen_construct_condition_id(
web3=web3,
question_id=question_id,
oracle_address=OMEN_ORACLE_CONTRACT_ADDRESS,
outcomes_slot_count=len(outcomes),
)
if not omen_does_condition_exist(web3, condition_id):
omen_prepare_condition_tx(
web3,
question_id=question_id,
oracle_address=OMEN_ORACLE_CONTRACT_ADDRESS,
outcomes_slot_count=len(outcomes),
from_address=from_address_checksummed,
from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.
# Create the market.
create_market_receipt_tx = call_function_on_contract_tx(
web3=web3,
contract_address=OMEN_FPMM_FACTORY_CONTRACT_ADDRESS,
contract_abi=OMEN_FPMM_FACTORY_ABI,
from_address=from_address,
from_private_key=from_private_key,
function_name="create2FixedProductMarketMaker",
function_params=dict(
saltNonce=random.randint(
0, 1000000
), # See https://github.com/protofire/omen-exchange/blob/923756c3a9ac370f8e89af8193393a53531e2c0f/app/src/services/cpk/fns.ts#L942.
conditionalTokens=OMEN_FPMM_CONDITIONALTOKENS_CONTRACT_ADDRESS,
collateralToken=DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS,
conditionIds=[condition_id],
fee=fee_wei,
initialFunds=initial_funds_wei,
distributionHint=[],
),
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.
# Note: In the Omen's Typescript code, there is futher a creation of `stakingRewardsFactoryAddress`,
# (https://github.com/protofire/omen-exchange/blob/763d9c9d05ebf9edacbc1dbaa561aa5d08813c0f/app/src/services/cpk/fns.ts#L979)
# but address of stakingRewardsFactoryAddress on xDai/Gnosis is 0x0000000000000000000000000000000000000000,
# so skipping it here.
market_address = create_market_receipt_tx["logs"][-1][
"address"
] # The market address is available in the last emitted log, in the address field.
return market_address
# Suggestion to break down the function into smaller parts for better readability

def main(
market_type: MarketSource,
) -> None:
# TODO: Fetch by newest and finish the rest.
Copy link

Choose a reason for hiding this comment

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

The TODO comment indicates that the functionality to fetch markets by newest and complete the rest of the intended operations is not yet implemented. This is a crucial part of the script's functionality that needs to be addressed.

Would you like me to help implement the missing functionality or open a GitHub issue to track this task?

Comment on lines +1 to 9
import os

import requests
from web3.types import Wei

GNOSIS_RPC_URL = "https://rpc.gnosischain.com/"
GNOSIS_RPC_URL = os.getenv("GNOSIS_RPC_URL", "https://gnosis-rpc.publicnode.com")


def get_balance(address: str) -> Wei:
Copy link

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [8-17]

The get_balance function is well-implemented, making a JSON-RPC call to get the balance of a given address. It correctly handles the response and converts the hex value to an integer. However, it's important to handle potential errors from the JSON-RPC call, such as network issues or invalid responses.

Consider adding error handling for the JSON-RPC call to improve the robustness of the get_balance function.

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: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0f31e1e and 4e87dd2.
Files selected for processing (2)
  • prediction_market_agent_tooling/markets/omen/omen.py (18 hunks)
  • scripts/create_market_omen.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • scripts/create_market_omen.py
Additional comments: 5
prediction_market_agent_tooling/markets/omen/omen.py (5)
  • 65-70: The addition of imports (json, random, typing, datetime, Enum) is appropriate for the functionalities introduced in this file. However, ensure that all imported modules are used within the file to avoid unnecessary imports.
  • 103-104: The global variables OMEN_DEFAULT_MARKET_FEE and DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS are well-defined and follow naming conventions. It's good practice to define such constants at the top of the file for easy configuration and readability.
  • 107-110: The Arbitrator enum is correctly defined and provides a clear, maintainable way to handle arbitrator types. Using an enum for such categorical data enhances code readability and reduces the likelihood of errors.
  • 239-246: The function get_arbitrator_contract_address_and_abi is well-implemented, providing a clear and concise way to retrieve the contract address and ABI for a given arbitrator. The use of the Arbitrator enum in the function signature enhances type safety and readability.
  • 644-694: The function omen_realitio_ask_question_tx is well-structured and provides a clear mechanism for asking a question on Realitio. The use of random.randint for nonce generation is acceptable but consider documenting the choice or exploring deterministic nonce management strategies for improved predictability in transaction ordering.

)
) as f:
# Contract ABI taken from https://gnosisscan.io/address/0x9083A2B699c0a4AD06F63580BDE2635d26a3eeF0#code.
OMEN_FPMM_FACTORY_ABI = ABI(f.read())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have an idea how to refactor this, so we won't have a ton of global constant and file openings here. But let's take a look at that in a following PR.

amount_wei=amount_wei,
from_address=from_address_checksummed,
from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.
check_tx_receipt(approve_tx_receipt)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was always called anyway, so I moved into the utility function.

from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would also like to refactor this, so we don't have to do it manually like this after each tx. Again in the following PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought about that as well. Could make call_function_on_contract_tx take in the nonce as an arg, and return TxReceipt and the updated nonce.

import requests
from web3.types import Wei

GNOSIS_RPC_URL = "https://rpc.gnosischain.com/"
GNOSIS_RPC_URL = os.getenv("GNOSIS_RPC_URL", "https://gnosis-rpc.publicnode.com")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One of the bugs I was dealing with was in the end caused by unstable RPC. Seems like this one works better.

from_address=from_address,
from_private_key=from_private_key,
function_name="create2FixedProductMarketMaker",
function_params=dict(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

function_params should be a list, but sometimes there are so many arguments (like here) that it's hard to follow them. We can use dictionary and then take .values(), because dicts are sorted in Python.

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: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4e87dd2 and 0090dd3.
Files selected for processing (2)
  • prediction_market_agent_tooling/markets/omen/omen.py (18 hunks)
  • scripts/create_market_omen.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • scripts/create_market_omen.py
Additional comments: 4
prediction_market_agent_tooling/markets/omen/omen.py (4)
  • 65-70: The addition of new imports (json, random, datetime, Enum) is appropriate for the functionalities being introduced. However, ensure that all these modules are used within the file to avoid unnecessary imports.
  • 103-104: The introduction of OMEN_DEFAULT_MARKET_FEE and DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS as global variables is a good practice for managing configuration and default values. It enhances readability and maintainability.
  • 107-110: The Arbitrator enum is a clean way to manage arbitrator types. This approach enhances code readability and reduces the likelihood of typos or inconsistencies.
  • 239-246: The function get_arbitrator_contract_address_and_abi correctly handles different arbitrators by returning the appropriate contract address and ABI. This modular approach facilitates future expansions or modifications.

Comment on lines +507 to +530
omen_approve_market_maker_to_spend_collateral_token_tx(
web3=web3,
market=market,
market_maker_contract_address=market.market_maker_contract_address_checksummed,
collateral_token_contract_address=market.collateral_token_contract_address_checksummed,
amount_wei=amount_wei,
from_address=from_address_checksummed,
from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.
check_tx_receipt(approve_tx_receipt)
# Deposit xDai to the collateral token,
# this can be skipped, if we know we already have enough collateral tokens.
if auto_deposit:
deposit_receipt = omen_deposit_collateral_token_tx(
omen_deposit_collateral_token_tx(
web3=web3,
market=market,
collateral_token_contract_address=market.collateral_token_contract_address_checksummed,
amount_wei=amount_wei,
from_address=from_address_checksummed,
from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.
check_tx_receipt(deposit_receipt)
# Buy shares using the deposited xDai in the collateral token.
buy_receipt = omen_buy_shares_tx(
omen_buy_shares_tx(
Copy link

Choose a reason for hiding this comment

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

The function omen_buy_outcome_tx demonstrates a complex transaction process involving multiple steps (approval, deposit, and buying shares). It's crucial to ensure that each step is correctly implemented and that error handling is in place for transaction failures. Consider adding more detailed error handling and logging to improve maintainability and debuggability.

Consider adding error handling for each transaction step to provide more detailed feedback in case of failures.

Comment on lines 598 to 605
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.
check_tx_receipt(approve_tx_receipt)
# Sell the shares.
sell_receipt = omen_sell_shares_tx(
omen_sell_shares_tx(
web3,
market,
amount_wei,
Copy link

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [592-615]

The function omen_sell_outcome_tx follows a similar pattern to omen_buy_outcome_tx, involving approval, selling shares, and optional withdrawal. Again, adding more explicit error handling and logging would enhance the robustness of this function.

Similar to omen_buy_outcome_tx, refine this function by adding error handling for each transaction step.

Comment on lines +752 to +898
raise RuntimeError(
"The oracle's conditional tokens address is not the same as we are using."
)

# Get the current nonce for the given from_address.
# If making multiple transactions quickly after each other,
# it's better to increae it manually (otherwise we could get stale value from the network and error out).
nonce: Nonce = web3.eth.get_transaction_count(from_address_checksummed)

# Approve the market maker to withdraw our collateral token.
omen_approve_market_maker_to_spend_collateral_token_tx(
web3=web3,
market_maker_contract_address=OMEN_FPMM_FACTORY_CONTRACT_ADDRESS,
collateral_token_contract_address=DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS,
amount_wei=initial_funds_wei,
from_address=from_address_checksummed,
from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.

# Deposit xDai to the collateral token,
# this can be skipped, if we know we already have enough collateral tokens.
if auto_deposit and initial_funds_wei > 0:
omen_deposit_collateral_token_tx(
web3=web3,
collateral_token_contract_address=DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS,
amount_wei=initial_funds_wei,
from_address=from_address_checksummed,
from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.

# Create the question on Realitio.
question_id = omen_realitio_ask_question_tx(
web3=web3,
question=question,
category=category,
outcomes=outcomes,
language=language,
arbitrator=Arbitrator.KLEROS,
opening=closing_time, # The question is opened at the closing time of the market.
from_address=from_address_checksummed,
from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.

# Construct the condition id.
condition_id = omen_construct_condition_id(
web3=web3,
question_id=question_id,
oracle_address=OMEN_ORACLE_CONTRACT_ADDRESS,
outcomes_slot_count=len(outcomes),
)
if not omen_does_condition_exist(web3, condition_id):
omen_prepare_condition_tx(
web3,
question_id=question_id,
oracle_address=OMEN_ORACLE_CONTRACT_ADDRESS,
outcomes_slot_count=len(outcomes),
from_address=from_address_checksummed,
from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.

# Create the market.
create_market_receipt_tx = call_function_on_contract_tx(
web3=web3,
contract_address=OMEN_FPMM_FACTORY_CONTRACT_ADDRESS,
contract_abi=OMEN_FPMM_FACTORY_ABI,
from_address=from_address,
from_private_key=from_private_key,
function_name="create2FixedProductMarketMaker",
function_params=dict(
saltNonce=random.randint(
0, 1000000
), # See https://github.com/protofire/omen-exchange/blob/923756c3a9ac370f8e89af8193393a53531e2c0f/app/src/services/cpk/fns.ts#L942.
conditionalTokens=OMEN_FPMM_CONDITIONALTOKENS_CONTRACT_ADDRESS,
collateralToken=DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS,
conditionIds=[condition_id],
fee=fee_wei,
initialFunds=initial_funds_wei,
distributionHint=[],
),
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.

# Note: In the Omen's Typescript code, there is futher a creation of `stakingRewardsFactoryAddress`,
# (https://github.com/protofire/omen-exchange/blob/763d9c9d05ebf9edacbc1dbaa561aa5d08813c0f/app/src/services/cpk/fns.ts#L979)
# but address of stakingRewardsFactoryAddress on xDai/Gnosis is 0x0000000000000000000000000000000000000000,
# so skipping it here.

market_address = create_market_receipt_tx["logs"][-1][
"address"
] # The market address is available in the last emitted log, in the address field.
return market_address
Copy link

Choose a reason for hiding this comment

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

The function omen_create_market_tx is a key component of the market creation process. It's comprehensive and covers many steps, including checks, approvals, deposits, and market creation. While the function is well-implemented, it's quite lengthy and complex, which could impact maintainability. Consider refactoring to break down the function into smaller, more manageable parts.

Refactor omen_create_market_tx to improve readability and maintainability by breaking it down into smaller functions, each handling a specific part of the market creation process.

from_private_key=from_private_key,
tx_params={"nonce": nonce},
)
nonce = Nonce(nonce + ONE_NONCE) # Increase after each tx.
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought about that as well. Could make call_function_on_contract_tx take in the nonce as an arg, and return TxReceipt and the updated nonce.

@kongzii kongzii merged commit fc896bc into main Feb 22, 2024
6 checks passed
@kongzii kongzii deleted the peter/omen-market-maker branch February 22, 2024 13:59
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