-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
WalkthroughThe update enhances the Changes
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.
Review Status
Actionable comments generated: 6
Configuration used: CodeRabbit UI
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 typeMarketSource
. 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 thehexbytes
module, marked withnoqa: F401
to ignore unused import warnings, is a good practice for facilitating easier importing within other modules.- 12-12: Renaming
Wei
toWad
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, usingtyper
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 themain
function is correctly set up with all required parameters, including the conversion ofinitial_funds
toxdai_type
and the use ofverify_address
to validate thefrom_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
andWXDAI_CONTRACT_ADDRESS
, along with theWXDAI_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 oncall_function_on_contract
is an excellent application of thetenacity
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 atimeout
parameter and receipt verification, significantly improve the function's robustness and flexibility. The use ofparse_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 usingEnum
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.
OMEN_DEFAULT_MARKET_FEE = 0.02 # 2% fee from the buying shares amount. | ||
DEFAULT_COLLATERAL_TOKEN_CONTRACT_ADDRESS = WXDAI_CONTRACT_ADDRESS |
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.
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.
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 |
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, |
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.
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.
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, |
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 |
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.
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.
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 |
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 |
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.
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
andfee
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.
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. |
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.
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?
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: |
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.
📝 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.
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.
Review Status
Actionable comments generated: 3
Configuration used: CodeRabbit UI
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
andDEFAULT_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 theArbitrator
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 ofrandom.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()) |
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.
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) |
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.
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. |
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.
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.
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.
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") |
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.
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( |
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.
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.
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.
Review Status
Actionable comments generated: 3
Configuration used: CodeRabbit UI
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
andDEFAULT_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.
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( |
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.
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.
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, |
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.
📝 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.
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 |
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.
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. |
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.
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.
Summary by CodeRabbit