Skip to content

Commit

Permalink
feat: Adding transaction fuzzing, enabled by default
Browse files Browse the repository at this point in the history
  • Loading branch information
TomMcL committed Jun 14, 2024
1 parent 1cda791 commit 5eeb07e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
10 changes: 10 additions & 0 deletions vega_sim/api/governance.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def __propose_market(
wallet_name: Optional[str] = None,
parent_market_id: Optional[str] = None,
parent_market_insurance_pool_fraction: float = 1,
enable_transaction_reordering: bool = True,
) -> str:
# Make sure Vega network has governance asset
vote_asset_id = find_asset_id(
Expand Down Expand Up @@ -234,6 +235,7 @@ def __propose_market(
composite_price_type=vega_protos.markets.COMPOSITE_PRICE_TYPE_LAST_TRADE,
),
tick_size="1",
enable_transaction_reordering=enable_transaction_reordering,
),
)
if parent_market_id is not None:
Expand Down Expand Up @@ -287,6 +289,7 @@ def propose_future_market(
wallet_name: Optional[str] = None,
parent_market_id: Optional[str] = None,
parent_market_insurance_pool_fraction: float = 1,
enable_transaction_reordering: bool = True,
) -> str:
"""Propose a future market as specified user.
Expand Down Expand Up @@ -343,6 +346,8 @@ def propose_future_market(
parent_market_insurance_pool_fraction:
float, Fraction of parent market insurance pool to carry over.
defaults to 1. No-op if parent_market_id is not set.
enable_transaction_reordering:
bool, Whether to enable the transaction reordering feature on this market.
Returns:
str, the ID of the future market proposal on chain
Expand Down Expand Up @@ -424,6 +429,7 @@ def propose_future_market(
wallet_name=wallet_name,
parent_market_id=parent_market_id,
parent_market_insurance_pool_fraction=parent_market_insurance_pool_fraction,
enable_transaction_reordering=enable_transaction_reordering,
)


Expand Down Expand Up @@ -457,6 +463,7 @@ def propose_perps_market(
wallet_name: Optional[str] = None,
parent_market_id: Optional[str] = None,
parent_market_insurance_pool_fraction: float = 1,
enable_transaction_reordering: bool = True,
) -> str:
"""Propose a perps market as specified user.
Expand Down Expand Up @@ -513,6 +520,8 @@ def propose_perps_market(
parent_market_insurance_pool_fraction:
float, Fraction of parent market insurance pool to carry over.
defaults to 1. No-op if parent_market_id is not set.
enable_transaction_reordering:
bool, Whether to enable the transaction reordering feature on this market
Returns:
str, the ID of the future market proposal on chain
Expand Down Expand Up @@ -604,6 +613,7 @@ def propose_perps_market(
wallet_name=wallet_name,
parent_market_id=parent_market_id,
parent_market_insurance_pool_fraction=parent_market_insurance_pool_fraction,
enable_transaction_reordering=enable_transaction_reordering,
)


Expand Down
6 changes: 6 additions & 0 deletions vega_sim/api/market.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ class MarketConfig(Config):
"liquidation_strategy": "default",
"mark_price_configuration": "default",
"tick_size": "1",
"enable_transaction_reordering": True,
},
"future": {
"decimal_places": 4,
Expand All @@ -243,6 +244,7 @@ class MarketConfig(Config):
"liquidation_strategy": "default",
"mark_price_configuration": "default",
"tick_size": "1",
"enable_transaction_reordering": True,
},
"perpetual": {
"decimal_places": 4,
Expand All @@ -260,6 +262,7 @@ class MarketConfig(Config):
"liquidation_strategy": "default",
"mark_price_configuration": "default",
"tick_size": "1",
"enable_transaction_reordering": True,
},
}

Expand Down Expand Up @@ -300,6 +303,8 @@ def load(self, opt: Optional[str] = None):
opt=config["mark_price_configuration"]
)

self.enable_transaction_reordering = config["enable_transaction_reordering"]

def build(self, oracle_pubkey: str):
new_market = vega_protos.governance.NewMarket(
changes=vega_protos.governance.NewMarketConfiguration(
Expand All @@ -322,6 +327,7 @@ def build(self, oracle_pubkey: str):
oracle_pubkey=oracle_pubkey
),
tick_size=str(self.tick_size),
enable_transaction_reordering=enable_transaction_reordering,
)
)
return new_market
Expand Down
2 changes: 2 additions & 0 deletions vega_sim/builders/governance.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ def new_spot_market_configuration(
liquidity_fee_settings: vega_protos.markets.LiquidityFeeSettings,
tick_size: float,
metadata: Optional[List[str]] = None,
enable_transaction_reordering: bool = True,
) -> vega_protos.governance.NewMarketConfiguration:
return vega_protos.governance.NewSpotMarketConfiguration(
instrument=instrument,
Expand All @@ -369,4 +370,5 @@ def new_spot_market_configuration(
sla_params=sla_params,
liquidity_fee_settings=liquidity_fee_settings,
tick_size=str(tick_size),
enable_transaction_reordering=enable_transaction_reordering,
)
10 changes: 10 additions & 0 deletions vega_sim/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ def create_simple_perps_market(
forward_time_to_enactment: bool = True,
parent_market_id: Optional[str] = None,
parent_market_insurance_pool_fraction: float = 1,
enable_transaction_reordering: bool = True,
) -> str:
"""Creates a simple perpetual futures market with a predefined reasonable set of parameters.
Expand Down Expand Up @@ -815,6 +816,9 @@ def create_simple_perps_market(
parent_market_insurance_pool_fraction:
float, Fraction of parent market insurance pool to carry over.
defaults to 1. No-op if parent_market_id is not set.
enable_transaction_reordering:
bool, default True, Whether to enable trading transaction reordering
on this market
"""
additional_kwargs = {}
if asset is not None:
Expand Down Expand Up @@ -858,6 +862,7 @@ def create_simple_perps_market(
price_monitoring_parameters=price_monitoring_parameters,
parent_market_id=parent_market_id,
parent_market_insurance_pool_fraction=parent_market_insurance_pool_fraction,
enable_transaction_reordering=enable_transaction_reordering,
**additional_kwargs,
)
if approve_proposal:
Expand Down Expand Up @@ -981,6 +986,7 @@ def create_simple_market(
forward_time_to_enactment: bool = True,
parent_market_id: Optional[str] = None,
parent_market_insurance_pool_fraction: float = 1,
enable_transaction_reordering: bool = True,
) -> str:
"""Creates a simple fixed-expiry futures market with a predefined reasonable set of parameters.
Expand Down Expand Up @@ -1024,6 +1030,9 @@ def create_simple_market(
parent_market_insurance_pool_fraction:
float, Fraction of parent market insurance pool to carry over.
defaults to 1. No-op if parent_market_id is not set.
enable_transaction_reordering:
bool, default True, Whether to enable trading transaction reordering
on this market
"""
additional_kwargs = {}
if future_asset is not None:
Expand Down Expand Up @@ -1066,6 +1075,7 @@ def create_simple_market(
price_monitoring_parameters=price_monitoring_parameters,
parent_market_id=parent_market_id,
parent_market_insurance_pool_fraction=parent_market_insurance_pool_fraction,
enable_transaction_reordering=enable_transaction_reordering,
**additional_kwargs,
)
if approve_proposal:
Expand Down
3 changes: 2 additions & 1 deletion vega_sim/vegahome/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@
"referralProgram.maxReferralDiscountFactor": "1",
"referralProgram.maxPartyNotionalVolumeByQuantumPerEpoch": "10000",
"referralProgram.minStakedVegaTokens": "0",
"referralProgram.maxReferralRewardProportion": "1"
"referralProgram.maxReferralRewardProportion": "1",
"market.aggressiveOrderBlockDelay": "5"
},
"network_limits": {
"propose_market_enabled": true,
Expand Down

0 comments on commit 5eeb07e

Please sign in to comment.