From e00c604d04d78991eac666fc3a6494946968603f Mon Sep 17 00:00:00 2001 From: Charlie Date: Wed, 4 Sep 2024 18:10:48 +0100 Subject: [PATCH] temp --- .env | 2 +- tests/vega_query/fixtures.py | 12 +- .../test_get_current_referral_program.py | 13 + ...est_get_current_volume_discount_program.py | 15 ++ .../test_get_current_volume_rebate_program.py | 15 ++ .../service_trading_data/test_get_epoch.py | 26 ++ .../test_get_referral_program_stats.py | 0 .../test_get_volume_discount_program_stats.py | 32 +++ .../test_get_volume_rebate_program_stats.py | 29 +++ vega_query/service/service_trading_data.py | 78 ++++-- vega_sim/scenario/benchmark/registry.py | 16 ++ vega_sim/scenario/benchmark/scenario.py | 32 +++ vega_sim/scenario/common/agents.py | 231 ++++++++++++++++++ vega_sim/scenario/fuzzed_markets/agents.py | 205 ++-------------- 14 files changed, 507 insertions(+), 199 deletions(-) create mode 100644 tests/vega_query/service/service_trading_data/test_get_current_referral_program.py create mode 100644 tests/vega_query/service/service_trading_data/test_get_current_volume_discount_program.py create mode 100644 tests/vega_query/service/service_trading_data/test_get_current_volume_rebate_program.py create mode 100644 tests/vega_query/service/service_trading_data/test_get_epoch.py create mode 100644 tests/vega_query/service/service_trading_data/test_get_referral_program_stats.py create mode 100644 tests/vega_query/service/service_trading_data/test_get_volume_discount_program_stats.py create mode 100644 tests/vega_query/service/service_trading_data/test_get_volume_rebate_program_stats.py diff --git a/.env b/.env index e3c5ba3b8..1f1836680 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -VEGA_SIM_VEGA_TAG=v0.78.0-preview.4 +VEGA_SIM_VEGA_TAG=develop VEGA_SIM_CONSOLE_TAG=develop VEGA_DEFAULT_KEY_NAME='Key 1' VEGA_SIM_NETWORKS_INTERNAL_TAG=main diff --git a/tests/vega_query/fixtures.py b/tests/vega_query/fixtures.py index 6e80d8648..a3e42fd84 100644 --- a/tests/vega_query/fixtures.py +++ b/tests/vega_query/fixtures.py @@ -11,12 +11,15 @@ logger = logging.getLogger(__name__) -DEFAULT_NETWORK = Network.NETWORK_TESTNET +DEFAULT_NETWORK = Network.NETWORK_LOCAL +DEFAULT_PORT_DATA_NODE = 56345 @fixture(scope="session") def tds(): - client = TradingDataService(network=DEFAULT_NETWORK) + client = TradingDataService( + network=DEFAULT_NETWORK, port_data_node=DEFAULT_PORT_DATA_NODE + ) yield client @@ -106,3 +109,8 @@ def end_timestamp(tds: TradingDataService) -> int: @fixture(scope="session") def amms(tds: TradingDataService) -> List[protos.vega.events.v1.events.AMM]: return tds.list_amms(max_pages=1) + + +@fixture(scope="session") +def epoch(tds: TradingDataService) -> protos.vega.vega.Epoch: + return tds.get_epoch() diff --git a/tests/vega_query/service/service_trading_data/test_get_current_referral_program.py b/tests/vega_query/service/service_trading_data/test_get_current_referral_program.py new file mode 100644 index 000000000..6f88d9686 --- /dev/null +++ b/tests/vega_query/service/service_trading_data/test_get_current_referral_program.py @@ -0,0 +1,13 @@ +import pytest + +from vega_query.service.service_trading_data import TradingDataService +from tests.vega_query.fixtures import tds + +import vega_protos.protos as protos + + +@pytest.mark.vega_query +def test_get_current_referral_program(tds: TradingDataService): + program = tds.get_current_referral_program() + if program is not None: + assert isinstance(program, protos.data_node.api.v2.trading_data.ReferralProgram) diff --git a/tests/vega_query/service/service_trading_data/test_get_current_volume_discount_program.py b/tests/vega_query/service/service_trading_data/test_get_current_volume_discount_program.py new file mode 100644 index 000000000..3ff70c6c2 --- /dev/null +++ b/tests/vega_query/service/service_trading_data/test_get_current_volume_discount_program.py @@ -0,0 +1,15 @@ +import pytest + +from vega_query.service.service_trading_data import TradingDataService +from tests.vega_query.fixtures import tds + +import vega_protos.protos as protos + + +@pytest.mark.vega_query +def test_get_latest_volume_discount_program(tds: TradingDataService): + program = tds.get_current_volume_discount_program() + if program is not None: + assert isinstance( + program, protos.data_node.api.v2.trading_data.VolumeDiscountProgram + ) diff --git a/tests/vega_query/service/service_trading_data/test_get_current_volume_rebate_program.py b/tests/vega_query/service/service_trading_data/test_get_current_volume_rebate_program.py new file mode 100644 index 000000000..bf1654752 --- /dev/null +++ b/tests/vega_query/service/service_trading_data/test_get_current_volume_rebate_program.py @@ -0,0 +1,15 @@ +import pytest + +from vega_query.service.service_trading_data import TradingDataService +from tests.vega_query.fixtures import tds + +import vega_protos.protos as protos + + +@pytest.mark.vega_query +def test_get_latest_volume_rebate_program(tds: TradingDataService): + program = tds.get_current_volume_rebate_program() + if program is not None: + assert isinstance( + program, protos.data_node.api.v2.trading_data.VolumeRebateProgram + ) diff --git a/tests/vega_query/service/service_trading_data/test_get_epoch.py b/tests/vega_query/service/service_trading_data/test_get_epoch.py new file mode 100644 index 000000000..18b10fbb4 --- /dev/null +++ b/tests/vega_query/service/service_trading_data/test_get_epoch.py @@ -0,0 +1,26 @@ +import pytest + +from vega_query.service.service_trading_data import TradingDataService +from tests.vega_query.fixtures import tds, epoch + +import vega_protos.protos as protos + + +@pytest.mark.vega_query +def test_get_epoch(tds: TradingDataService): + epoch = tds.get_epoch() + assert isinstance(epoch, protos.vega.vega.Epoch) + + +@pytest.mark.vega_query +def test_get_epoch_id(tds: TradingDataService, epoch: protos.vega.vega.Epoch): + id = epoch.seq + epoch = tds.get_epoch(id=id) + assert epoch.seq == id + + +@pytest.mark.vega_query +def test_get_epoch_block(tds: TradingDataService, epoch: protos.vega.vega.Epoch): + block = epoch.timestamps.first_block + epoch = tds.get_epoch(block=block) + assert epoch.timestamps.first_block == block diff --git a/tests/vega_query/service/service_trading_data/test_get_referral_program_stats.py b/tests/vega_query/service/service_trading_data/test_get_referral_program_stats.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/vega_query/service/service_trading_data/test_get_volume_discount_program_stats.py b/tests/vega_query/service/service_trading_data/test_get_volume_discount_program_stats.py new file mode 100644 index 000000000..e6e5f5def --- /dev/null +++ b/tests/vega_query/service/service_trading_data/test_get_volume_discount_program_stats.py @@ -0,0 +1,32 @@ +import pytest + +from vega_query.service.service_trading_data import TradingDataService +from tests.vega_query.fixtures import tds, parties + +from typing import List + +import vega_protos.protos as protos + + +@pytest.mark.vega_query +def test_get_volume_discount_stats(tds: TradingDataService): + for stat in tds.get_volume_discount_stats(): + assert isinstance( + stat, protos.data_node.api.v2.trading_data.VolumeDiscountStats + ) + + +@pytest.mark.vega_query +def test_get_volume_discount_stats_at_epoch(tds: TradingDataService): + at_epoch = 0 + for stat in tds.get_volume_discount_stats(at_epoch=0): + assert stat.at_epoch == at_epoch + + +@pytest.mark.vega_query +def test_get_volume_discount_stats_party_id( + tds: TradingDataService, parties: List[str] +): + party_id = parties[0] + for stat in tds.get_volume_discount_stats(party_id=party_id): + assert stat.party_id == party_id diff --git a/tests/vega_query/service/service_trading_data/test_get_volume_rebate_program_stats.py b/tests/vega_query/service/service_trading_data/test_get_volume_rebate_program_stats.py new file mode 100644 index 000000000..73e913219 --- /dev/null +++ b/tests/vega_query/service/service_trading_data/test_get_volume_rebate_program_stats.py @@ -0,0 +1,29 @@ +import pytest + +from vega_query.service.service_trading_data import TradingDataService +from tests.vega_query.fixtures import tds, parties + +from typing import List + +import vega_protos.protos as protos + + +@pytest.mark.vega_query +def test_get_volume_rebate_stats(tds: TradingDataService): + for stat in tds.get_volume_rebate_stats(): + assert isinstance(stat, protos.data_node.api.v2.trading_data.VolumeRebateStats) + + +@pytest.mark.vega_query +def test_get_volume_rebate_stats_at_epoch(tds: TradingDataService): + at_epoch = 0 + for stat in tds.get_volume_rebate_stats(at_epoch=0): + assert stat.at_epoch == at_epoch + + +@pytest.mark.vega_query +def test_get_volume_rebate_stats_party_id(tds: TradingDataService, parties: List[str]): + party_id = parties[0] + stats = tds.get_volume_rebate_stats(party_id=party_id) + for stat in stats: + assert stat.party_id == party_id diff --git a/vega_query/service/service_trading_data.py b/vega_query/service/service_trading_data.py index 3c5d79e12..f0127d9b2 100644 --- a/vega_query/service/service_trading_data.py +++ b/vega_query/service/service_trading_data.py @@ -763,9 +763,13 @@ def list_governance_data( # # TODO: Implement method # pass - # def get_epoch(self, max_pages: Optional[int] = None) -> Any: - # # TODO: Implement method - # pass + @log_client_method + def get_epoch( + self, id: Optional[int] = None, block: Optional[int] = None + ) -> protos.vega.vega.Epoch: + return self.__stub.GetEpoch( + trading_data.GetEpochRequest(id=id, block=block) + ).epoch # def estimate_fee(self, max_pages: Optional[int] = None) -> Any: # # TODO: Implement method @@ -972,11 +976,11 @@ def list_funding_payments( # # TODO: Implement method # pass - # def get_current_referral_program( - # self, max_pages: Optional[int] = None - # ) -> Any: - # # TODO: Implement method - # pass + @log_client_method + def get_current_referral_program(self, max_pages: Optional[int] = None) -> Any: + return self.__stub.GetCurrentReferralProgram( + trading_data.GetCurrentReferralProgramRequest() + ).current_referral_program # def list_referral_sets(self, max_pages: Optional[int] = None) -> Any: # # TODO: Implement method @@ -1014,17 +1018,55 @@ def list_funding_payments( # # TODO: Implement method # pass - # def get_current_volume_discount_program( - # self, max_pages: Optional[int] = None - # ) -> Any: - # # TODO: Implement method - # pass + @log_client_method + def get_current_volume_discount_program( + self, + ) -> trading_data.VolumeDiscountProgram: + return self.__stub.GetCurrentVolumeDiscountProgram( + trading_data.GetCurrentVolumeDiscountProgramRequest() + ).current_volume_discount_program - # def get_volume_discount_stats( - # self, max_pages: Optional[int] = None - # ) -> Any: - # # TODO: Implement method - # pass + @log_client_method + def get_volume_discount_stats( + self, + at_epoch: Optional[int] = None, + party_id: Optional[int] = None, + max_pages: Optional[int] = None, + ) -> List[trading_data.VolumeDiscountStats]: + return unroll_v2_pagination( + base_request=trading_data.GetVolumeDiscountStatsRequest( + at_epoch=at_epoch, + party_id=party_id, + ), + request_func=lambda x: self.__stub.GetVolumeDiscountStats(x).stats, + extraction_func=lambda res: [i.node for i in res.edges], + max_pages=max_pages, + ) + + @log_client_method + def get_current_volume_rebate_program( + self, + ) -> trading_data.VolumeRebateProgram: + return self.__stub.GetCurrentVolumeRebateProgram( + trading_data.GetCurrentVolumeRebateProgramRequest() + ).current_volume_rebate_program + + @log_client_method + def get_volume_rebate_stats( + self, + at_epoch: Optional[int] = None, + party_id: Optional[int] = None, + max_pages: Optional[int] = None, + ) -> List[trading_data.VolumeRebateStats]: + return unroll_v2_pagination( + base_request=trading_data.GetVolumeRebateStatsRequest( + at_epoch=at_epoch, + party_id=party_id, + ), + request_func=lambda x: self.__stub.GetVolumeRebateStats(x).stats, + extraction_func=lambda res: [i.node for i in res.edges], + max_pages=max_pages, + ) # def get_vesting_balances_summary( # self, max_pages: Optional[int] = None diff --git a/vega_sim/scenario/benchmark/registry.py b/vega_sim/scenario/benchmark/registry.py index 070de3b3b..7404ce9b8 100644 --- a/vega_sim/scenario/benchmark/registry.py +++ b/vega_sim/scenario/benchmark/registry.py @@ -161,4 +161,20 @@ ), ], ), + "programs": BenchmarkScenario( + block_length_seconds=1, + step_length_seconds=30, + benchmark_configs=[ + BenchmarkConfig( + market_config=configs.research.futr.BTCUSDT.CONFIG, + initial_price=70000, + annualised_volatility=1, + notional_trade_volume=100, + ), + ], + volume_discounts_enabled=True, + volume_rebate_enabled=True, + referrals_enabled=True, + initial_network_parameters={"market.fee.factors.infrastructureFee": "0.0002"}, + ), } diff --git a/vega_sim/scenario/benchmark/scenario.py b/vega_sim/scenario/benchmark/scenario.py index c2def24bf..ba64983e1 100644 --- a/vega_sim/scenario/benchmark/scenario.py +++ b/vega_sim/scenario/benchmark/scenario.py @@ -20,6 +20,9 @@ ExponentialShapedMarketMaker, MarketOrderTrader, LimitOrderTrader, + ReferralProgramManager, + VolumeRebateProgramManager, + VolumeDiscountProgramManager, ) from vega_sim.scenario.fuzzed_markets.agents import ( RiskyMarketOrderTrader, @@ -35,6 +38,9 @@ def __init__( block_length_seconds: float = 1, step_length_seconds: Optional[float] = None, initial_network_parameters: Dict[str, Any] = None, + volume_discounts_enabled: bool = False, + volume_rebate_enabled: bool = False, + referrals_enabled: bool = False, output: bool = True, ): super().__init__() @@ -54,6 +60,9 @@ def __init__( self.initial_network_parameters = ( initial_network_parameters if initial_network_parameters is not None else {} ) + self.volume_discounts_enabled = volume_discounts_enabled + self.volume_rebate_enabled = volume_rebate_enabled + self.referrals_enabled = referrals_enabled def configure_agents( self, @@ -74,6 +83,29 @@ def configure_agents( network_parameters=self.initial_network_parameters, ) ) + + if self.referrals_enabled: + self.agents.append( + ReferralProgramManager( + wallet_name="ProgramManagers", + key_name="ReferralProgramManager", + ) + ) + if self.volume_discounts_enabled: + self.agents.append( + VolumeDiscountProgramManager( + wallet_name="ProgramManagers", + key_name="VolumeDiscountProgramManager", + ) + ) + if self.volume_rebate_enabled: + self.agents.append( + VolumeRebateProgramManager( + wallet_name="ProgramManagers", + key_name="VolumeRebateProgramManager", + ) + ) + for _, benchmark_config in enumerate(self.benchmark_configs): market_name = benchmark_config.market_config.instrument.name diff --git a/vega_sim/scenario/common/agents.py b/vega_sim/scenario/common/agents.py index e569e0576..a5b1b860e 100644 --- a/vega_sim/scenario/common/agents.py +++ b/vega_sim/scenario/common/agents.py @@ -22,6 +22,7 @@ from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union from numpy.typing import ArrayLike +from numpy.random import RandomState import vega_sim.api.faucet as faucet import vega_sim.builders as build @@ -4181,3 +4182,233 @@ def __reset(self): market_id=self.market_id, ) self.__check_in_progress = False + + +class ReferralProgramManager(StateAgentWithWallet): + NAME_BASE = "referral_program_manager" + + def __init__( + self, + key_name: str, + step_bias=0.5, + attempts_per_step=100, + stake_key: bool = False, + wallet_name: Optional[str] = None, + random_state: Optional[RandomState] = None, + tag: Optional[str] = None, + ): + self.key_name = key_name + self.wallet_name = wallet_name + self.tag = tag + self.stake_key = stake_key + + self.step_bias = step_bias + self.attempts_per_step = attempts_per_step + + self.random_state = random_state if random_state is not None else RandomState() + + def initialise(self, vega: VegaServiceNull, create_key: bool = True, mint_key=True): + super().initialise(vega, create_key) + self.vega.wait_for_total_catchup() + if mint_key: + self.vega.mint( + wallet_name=self.wallet_name, + asset=self.vega.find_asset_id(symbol="VOTE", enabled=True), + amount=1e4, + key_name=self.key_name, + ) + self.vega.wait_for_total_catchup() + if self.stake_key: + self.vega.stake( + amount=1, + key_name=self.key_name, + wallet_name=self.wallet_name, + ) + self.vega.wait_for_total_catchup() + self._sensible_proposal() + + def _sensible_proposal(self): + # Updating program requires method to get the current blockchain time. Ensure + # datanode is synced before requesting the current blockchain time. + self.vega.wait_for_datanode_sync() + self.vega.update_referral_program( + forward_time_to_enactment=False, + proposal_key=self.key_name, + wallet_name=self.wallet_name, + benefit_tiers=[ + { + "minimum_running_notional_taker_volume": 1, + "minimum_epochs": 1, + "infrastructure_discount_factor": 0.1, + "liquidity_discount_factor": 0.1, + "maker_discount_factor": 0.1, + "infrastructure_reward_factor": 0.1, + "liquidity_reward_factor": 0.1, + "maker_reward_factor": 0.1, + }, + { + "minimum_running_notional_taker_volume": 2, + "minimum_epochs": 2, + "infrastructure_discount_factor": 0.2, + "liquidity_discount_factor": 0.2, + "maker_discount_factor": 0.2, + "infrastructure_reward_factor": 0.2, + "liquidity_reward_factor": 0.2, + "maker_reward_factor": 0.2, + }, + { + "minimum_running_notional_taker_volume": 3, + "minimum_epochs": 3, + "infrastructure_discount_factor": 0.3, + "liquidity_discount_factor": 0.3, + "maker_discount_factor": 0.3, + "infrastructure_reward_factor": 0.3, + "liquidity_reward_factor": 0.3, + "maker_reward_factor": 0.3, + }, + ], + staking_tiers=[ + {"minimum_staked_tokens": 1, "referral_reward_multiplier": 1}, + ], + window_length=1, + ) + + +class VolumeDiscountProgramManager(StateAgentWithWallet): + + NAME_BASE = "volume_discount_program_manager" + + def __init__( + self, + key_name: str, + step_bias=0.5, + attempts_per_step=100, + stake_key: bool = False, + wallet_name: Optional[str] = None, + random_state: Optional[RandomState] = None, + tag: Optional[str] = None, + ): + self.key_name = key_name + self.wallet_name = wallet_name + self.tag = tag + self.stake_key = stake_key + + self.step_bias = step_bias + self.attempts_per_step = attempts_per_step + + self.random_state = random_state if random_state is not None else RandomState() + + def initialise(self, vega: VegaServiceNull, create_key: bool = True, mint_key=True): + super().initialise(vega, create_key) + self.vega.wait_for_total_catchup() + if mint_key: + self.vega.mint( + wallet_name=self.wallet_name, + asset=self.vega.find_asset_id(symbol="VOTE", enabled=True), + amount=1e4, + key_name=self.key_name, + ) + self.vega.wait_for_total_catchup() + if self.stake_key: + self.vega.stake( + amount=1, + key_name=self.key_name, + wallet_name=self.wallet_name, + ) + self.vega.wait_for_total_catchup() + self._sensible_proposal() + + def _sensible_proposal(self): + self.vega.update_volume_discount_program( + forward_time_to_enactment=False, + proposal_key=self.key_name, + wallet_name=self.wallet_name, + benefit_tiers=[ + { + "minimum_running_notional_taker_volume": 1000, + "infrastructure_discount_factor": 0.01, + "liquidity_discount_factor": 0.01, + "maker_discount_factor": 0.01, + }, + { + "minimum_running_notional_taker_volume": 2000, + "infrastructure_discount_factor": 0.01, + "liquidity_discount_factor": 0.01, + "maker_discount_factor": 0.01, + }, + { + "minimum_running_notional_taker_volume": 3000, + "infrastructure_discount_factor": 0.01, + "liquidity_discount_factor": 0.01, + "maker_discount_factor": 0.01, + }, + ], + window_length=1, + ) + + +class VolumeRebateProgramManager(StateAgentWithWallet): + + NAME_BASE = "volume_rebate_program_manager" + + def __init__( + self, + key_name: str, + step_bias=0.5, + attempts_per_step=100, + stake_key: bool = False, + wallet_name: Optional[str] = None, + random_state: Optional[RandomState] = None, + tag: Optional[str] = None, + ): + self.key_name = key_name + self.wallet_name = wallet_name + self.tag = tag + self.stake_key = stake_key + + self.step_bias = step_bias + self.attempts_per_step = attempts_per_step + + self.random_state = random_state if random_state is not None else RandomState() + + def initialise(self, vega: VegaServiceNull, create_key: bool = True, mint_key=True): + super().initialise(vega, create_key) + self.vega.wait_for_total_catchup() + if mint_key: + self.vega.mint( + wallet_name=self.wallet_name, + asset=self.vega.find_asset_id(symbol="VOTE", enabled=True), + amount=1e4, + key_name=self.key_name, + ) + self.vega.wait_for_total_catchup() + if self.stake_key: + self.vega.stake( + amount=1, + key_name=self.key_name, + wallet_name=self.wallet_name, + ) + self.vega.wait_for_total_catchup() + self._sensible_proposal() + + def _sensible_proposal(self): + self.vega.update_volume_rebate_program( + forward_time_to_enactment=False, + proposal_key=self.key_name, + wallet_name=self.wallet_name, + benefit_tiers=[ + { + "minimum_party_maker_volume_fraction": str(0.002), + "additional_maker_rebate": f"{0.0002/10:.9f}", + }, + { + "minimum_party_maker_volume_fraction": str(0.020), + "additional_maker_rebate": f"{0.0002/5:.9f}", + }, + { + "minimum_party_maker_volume_fraction": str(0.200), + "additional_maker_rebate": f"{0.0002/2:.9f}", + }, + ], + window_length=5, + ) diff --git a/vega_sim/scenario/fuzzed_markets/agents.py b/vega_sim/scenario/fuzzed_markets/agents.py index 7a312cade..abb8dba80 100644 --- a/vega_sim/scenario/fuzzed_markets/agents.py +++ b/vega_sim/scenario/fuzzed_markets/agents.py @@ -28,6 +28,12 @@ from vega_protos.protos.vega import markets as markets_protos from vega_sim.service import MarketStateUpdateType, PeggedOrder, VegaService +from vega_sim.scenario.common.agents import ( + ReferralProgramManager, + VolumeRebateProgramManager, + VolumeDiscountProgramManager, +) + COMMAND_AND_TYPES = [ (commands_protos.OrderSubmission, "order_submission", 2), (commands_protos.BatchMarketInstructions, "batch_market_instructions", 5), @@ -1367,7 +1373,7 @@ def step(self, vega_state) -> None: ) -class FuzzyReferralProgramManager(StateAgentWithWallet): +class FuzzyReferralProgramManager(ReferralProgramManager): """Agent proposes sensible and fuzzed update referral program proposals at a controlled frequency. """ @@ -1394,26 +1400,6 @@ def __init__( self.random_state = random_state if random_state is not None else RandomState() - def initialise(self, vega: VegaServiceNull, create_key: bool = True, mint_key=True): - super().initialise(vega, create_key) - self.vega.wait_for_total_catchup() - if mint_key: - self.vega.mint( - wallet_name=self.wallet_name, - asset=self.vega.find_asset_id(symbol="VOTE", enabled=True), - amount=1e4, - key_name=self.key_name, - ) - self.vega.wait_for_total_catchup() - if self.stake_key: - self.vega.stake( - amount=1, - key_name=self.key_name, - wallet_name=self.wallet_name, - ) - self.vega.wait_for_total_catchup() - self._sensible_proposal() - def step(self, vega_state): if self.random_state.rand() < self.step_bias: for i in range(self.attempts_per_step): @@ -1435,52 +1421,6 @@ def step(self, vega_state): except ProposalNotAcceptedError: logging.warning("Sensible UpdateReferralProgram failed.") - def _sensible_proposal(self): - # Updating program requires method to get the current blockchain time. Ensure - # datanode is synced before requesting the current blockchain time. - self.vega.wait_for_datanode_sync() - self.vega.update_referral_program( - forward_time_to_enactment=False, - proposal_key=self.key_name, - wallet_name=self.wallet_name, - benefit_tiers=[ - { - "minimum_running_notional_taker_volume": 1, - "minimum_epochs": 1, - "infrastructure_discount_factor": 0.1, - "liquidity_discount_factor": 0.1, - "maker_discount_factor": 0.1, - "infrastructure_reward_factor": 0.1, - "liquidity_reward_factor": 0.1, - "maker_reward_factor": 0.1, - }, - { - "minimum_running_notional_taker_volume": 2, - "minimum_epochs": 2, - "infrastructure_discount_factor": 0.2, - "liquidity_discount_factor": 0.2, - "maker_discount_factor": 0.2, - "infrastructure_reward_factor": 0.2, - "liquidity_reward_factor": 0.2, - "maker_reward_factor": 0.2, - }, - { - "minimum_running_notional_taker_volume": 3, - "minimum_epochs": 3, - "infrastructure_discount_factor": 0.3, - "liquidity_discount_factor": 0.3, - "maker_discount_factor": 0.3, - "infrastructure_reward_factor": 0.3, - "liquidity_reward_factor": 0.3, - "maker_reward_factor": 0.3, - }, - ], - staking_tiers=[ - {"minimum_staked_tokens": 1, "referral_reward_multiplier": 1}, - ], - window_length=1, - ) - def _fuzzed_proposal(self): self.vega.update_referral_program( forward_time_to_enactment=False, @@ -1519,7 +1459,7 @@ def _fuzzed_proposal(self): ) -class FuzzyVolumeDiscountProgramManager(StateAgentWithWallet): +class FuzzyVolumeDiscountProgramManager(VolumeDiscountProgramManager): """Agent proposes sensible and fuzzed update referral program proposals at a controlled frequency. """ @@ -1536,35 +1476,15 @@ def __init__( random_state: Optional[RandomState] = None, tag: Optional[str] = None, ): - self.key_name = key_name - self.wallet_name = wallet_name - self.tag = tag - self.stake_key = stake_key - - self.step_bias = step_bias - self.attempts_per_step = attempts_per_step - - self.random_state = random_state if random_state is not None else RandomState() - - def initialise(self, vega: VegaServiceNull, create_key: bool = True, mint_key=True): - super().initialise(vega, create_key) - self.vega.wait_for_total_catchup() - if mint_key: - self.vega.mint( - wallet_name=self.wallet_name, - asset=self.vega.find_asset_id(symbol="VOTE", enabled=True), - amount=1e4, - key_name=self.key_name, - ) - self.vega.wait_for_total_catchup() - if self.stake_key: - self.vega.stake( - amount=1, - key_name=self.key_name, - wallet_name=self.wallet_name, - ) - self.vega.wait_for_total_catchup() - self._sensible_proposal() + super().__init__( + key_name, + wallet_name, + tag, + stake_key, + step_bias, + attempts_per_step, + random_state, + ) def step(self, vega_state): if self.random_state.rand() < self.step_bias: @@ -1590,34 +1510,6 @@ def step(self, vega_state): except ProposalNotAcceptedError: logging.warning("Sensible UpdateVolumeDiscountProgram proposal failed.") - def _sensible_proposal(self): - self.vega.update_volume_discount_program( - forward_time_to_enactment=False, - proposal_key=self.key_name, - wallet_name=self.wallet_name, - benefit_tiers=[ - { - "minimum_running_notional_taker_volume": 1000, - "infrastructure_discount_factor": 0.01, - "liquidity_discount_factor": 0.01, - "maker_discount_factor": 0.01, - }, - { - "minimum_running_notional_taker_volume": 2000, - "infrastructure_discount_factor": 0.01, - "liquidity_discount_factor": 0.01, - "maker_discount_factor": 0.01, - }, - { - "minimum_running_notional_taker_volume": 3000, - "infrastructure_discount_factor": 0.01, - "liquidity_discount_factor": 0.01, - "maker_discount_factor": 0.01, - }, - ], - window_length=1, - ) - def _fuzzed_proposal(self): self.vega.update_volume_discount_program( forward_time_to_enactment=False, @@ -1645,7 +1537,7 @@ def _fuzzed_proposal(self): ) -class FuzzyVolumeRebateProgramManager(StateAgentWithWallet): +class FuzzyVolumeRebateProgramManager(VolumeRebateProgramManager): """Agent proposes sensible and fuzzed update volume rebate program proposals at a controlled frequency. """ @@ -1662,35 +1554,15 @@ def __init__( random_state: Optional[RandomState] = None, tag: Optional[str] = None, ): - self.key_name = key_name - self.wallet_name = wallet_name - self.tag = tag - self.stake_key = stake_key - - self.step_bias = step_bias - self.attempts_per_step = attempts_per_step - - self.random_state = random_state if random_state is not None else RandomState() - - def initialise(self, vega: VegaServiceNull, create_key: bool = True, mint_key=True): - super().initialise(vega, create_key) - self.vega.wait_for_total_catchup() - if mint_key: - self.vega.mint( - wallet_name=self.wallet_name, - asset=self.vega.find_asset_id(symbol="VOTE", enabled=True), - amount=1e4, - key_name=self.key_name, - ) - self.vega.wait_for_total_catchup() - if self.stake_key: - self.vega.stake( - amount=1, - key_name=self.key_name, - wallet_name=self.wallet_name, - ) - self.vega.wait_for_total_catchup() - self._sensible_proposal() + super().__init__( + key_name, + wallet_name, + tag, + stake_key, + step_bias, + attempts_per_step, + random_state, + ) def step(self, vega_state): if self.random_state.rand() < self.step_bias: @@ -1716,30 +1588,7 @@ def step(self, vega_state): except ProposalNotAcceptedError: logging.warning("Sensible UpdateVolumeRebate proposal failed.") - def _sensible_proposal(self): - self.vega.update_volume_rebate_program( - forward_time_to_enactment=False, - proposal_key=self.key_name, - wallet_name=self.wallet_name, - benefit_tiers=[ - { - "minimum_party_maker_volume_fraction": str(0.002), - "additional_maker_rebate": f"{0.0002/10:.9f}", - }, - { - "minimum_party_maker_volume_fraction": str(0.020), - "additional_maker_rebate": f"{0.0002/5:.9f}", - }, - { - "minimum_party_maker_volume_fraction": str(0.200), - "additional_maker_rebate": f"{0.0002/2:.9f}", - }, - ], - window_length=5, - ) - def _fuzzed_proposal(self): - return self.vega.update_volume_rebate_program( forward_time_to_enactment=False, proposal_key=self.key_name,