Skip to content

Commit

Permalink
fix: update optional fields for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cdummett committed Oct 2, 2023
1 parent 79d1e25 commit 7abb11d
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 33 deletions.
34 changes: 28 additions & 6 deletions tests/integration/test_trading.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,25 +286,47 @@ def test_recurring_transfer(vega_service_with_market: VegaServiceNull):
@pytest.mark.integration
def test_funding_reward_pool(vega_service_with_market: VegaServiceNull):
vega = vega_service_with_market
vega.wait_for_total_catchup()
market_id = vega.all_markets()[0].id
asset_id = vega.find_asset_id(symbol=ASSET_NAME, raise_on_missing=True)

create_and_faucet_wallet(vega=vega, wallet=PARTY_A, amount=1e3)
create_and_faucet_wallet(vega=vega, wallet=LIQ, amount=1e5)
create_and_faucet_wallet(vega=vega, wallet=PARTY_B, amount=1e5)
create_and_faucet_wallet(vega=vega, wallet=PARTY_C, amount=1e5)
vega.wait_for_total_catchup()

asset_id = vega.find_asset_id(symbol=ASSET_NAME, raise_on_missing=True)
# Forward one epoch
next_epoch(vega=vega)

vega.recurring_transfer(
from_key_name=PARTY_A.name,
to_key_name=PARTY_B.name,
from_account_type=vega_protos.vega.ACCOUNT_TYPE_GENERAL,
to_account_type=vega_protos.vega.ACCOUNT_TYPE_GENERAL,
to_account_type=vega_protos.vega.ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES,
asset=asset_id,
asset_for_metric=asset_id,
metric=vega_protos.vega.DISPATCH_METRIC_MAKER_FEES_PAID,
amount=100,
factor=1.0,
)
# Generate trades for non-zero metrics
vega.submit_order(
trading_key=PARTY_B.name,
market_id=market_id,
order_type="TYPE_LIMIT",
time_in_force="TIME_IN_FORCE_GTC",
side="SIDE_SELL",
price=0.30,
volume=10000,
)
vega.submit_order(
trading_key=PARTY_C.name,
market_id=market_id,
order_type="TYPE_LIMIT",
time_in_force="TIME_IN_FORCE_GTC",
side="SIDE_BUY",
price=0.30,
volume=10000,
)
vega.wait_for_total_catchup()

party_a_accounts_t0 = vega.list_accounts(key_name=PARTY_A.name, asset_id=asset_id)

Expand All @@ -322,7 +344,7 @@ def test_funding_reward_pool(vega_service_with_market: VegaServiceNull):

party_a_accounts_t2 = vega.list_accounts(key_name=PARTY_A.name, asset_id=asset_id)

assert party_a_accounts_t2[0].balance == 799.8
assert party_a_accounts_t2[0].balance == 899.9


@pytest.mark.integration
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/utils/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def vega_service():
retain_log_files=True,
transactions_per_block=1,
listen_for_high_volume_stream_updates=False,
use_full_vega_wallet=False,
use_full_vega_wallet=True,
) as vega:
yield vega
logging.debug("vega_service teardown")
Expand Down
121 changes: 95 additions & 26 deletions vega_sim/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2274,15 +2274,15 @@ def recurring_transfer(
asset_for_metric: Optional[str] = None,
metric: Optional[vega_protos.vega.DispatchMetric] = None,
markets: Optional[List[str]] = None,
entity_scope: vega_protos.vega.EntityScope = vega_protos.vega.ENTITY_SCOPE_INDIVIDUALS,
individual_scope: vega_protos.vega.IndividualScope = vega_protos.vega.INDIVIDUAL_SCOPE_ALL,
entity_scope: Optional[vega_protos.vega.EntityScope] = None,
individual_scope: Optional[vega_protos.vega.IndividualScope] = None,
team_scope: Optional[List[str]] = None,
n_top_performers: Optional[float] = None,
staking_requirement: Optional[float] = None,
notional_time_weighted_average_position_requirement: Optional[float] = None,
window_length: int = 1,
lock_period: int = 1,
distribution_strategy: vega_protos.vega.DistributionStrategy = vega_protos.vega.DISTRIBUTION_STRATEGY_PRO_RATA,
window_length: Optional[int] = None,
lock_period: Optional[int] = None,
distribution_strategy: Optional[vega_protos.vega.DistributionStrategy] = None,
rank_table: Optional[List[vega_protos.vega.Rank]] = None,
):
"""Create a recurring transfer of funds.
Expand Down Expand Up @@ -2348,9 +2348,97 @@ def recurring_transfer(
if val is not None:
setattr(recurring_transfer, attr, val)

# Set the mandatory DispatchStrategy fields
# If any dispatch strategy field is set, try and create a dispatch strategy
if any(
[
arg is not None
for arg in [
entity_scope,
window_length,
lock_period,
distribution_strategy,
metric,
asset_for_metric,
individual_scope,
n_top_performers,
staking_requirement,
notional_time_weighted_average_position_requirement,
markets,
team_scope,
]
]
):
dispatch_strategy = self.dispatch_strategy(
asset_for_metric=asset_for_metric,
metric=metric,
markets=markets,
entity_scope=entity_scope,
individual_scope=individual_scope,
team_scope=team_scope,
n_top_performers=n_top_performers,
staking_requirement=staking_requirement,
notional_time_weighted_average_position_requirement=notional_time_weighted_average_position_requirement,
window_length=window_length,
lock_period=lock_period,
distribution_strategy=distribution_strategy,
rank_table=rank_table,
)
recurring_transfer.dispatch_strategy.CopyFrom(dispatch_strategy)

trading.transfer(
wallet=self.wallet,
wallet_name=from_wallet_name,
key_name=from_key_name,
from_account_type=from_account_type,
to=(
self.wallet.public_key(wallet_name=to_wallet_name, name=to_key_name)
if to_key_name is not None
else "0000000000000000000000000000000000000000000000000000000000000000"
),
to_account_type=to_account_type,
asset=asset,
amount=str(num_to_padded_int(amount, self.asset_decimals[asset])),
reference=reference,
recurring=recurring_transfer,
)

def dispatch_strategy(
self,
metric: vega_protos.vega.DispatchMetric,
asset_for_metric: Optional[str] = None,
markets: Optional[List[str]] = None,
entity_scope: Optional[vega_protos.vega.EntityScope] = None,
individual_scope: Optional[vega_protos.vega.IndividualScope] = None,
team_scope: Optional[List[str]] = None,
n_top_performers: Optional[float] = None,
staking_requirement: Optional[float] = None,
notional_time_weighted_average_position_requirement: Optional[float] = None,
window_length: Optional[int] = None,
lock_period: Optional[int] = None,
distribution_strategy: Optional[vega_protos.vega.DistributionStrategy] = None,
rank_table: Optional[List[vega_protos.vega.Rank]] = None,
) -> vega_protos.vega.DispatchStrategy:
# Set defaults for mandatory fields
if entity_scope is None:
entity_scope = vega_protos.vega.ENTITY_SCOPE_INDIVIDUALS
if individual_scope is None:
individual_scope = vega_protos.vega.INDIVIDUAL_SCOPE_ALL
if distribution_strategy is None:
distribution_strategy = vega_protos.vega.DISTRIBUTION_STRATEGY_PRO_RATA
if window_length is None:
window_length = 1
if lock_period is None:
lock_period = 1

# Set the mandatory (and conditionally mandatory) DispatchStrategy fields
dispatch_strategy = vega_protos.vega.DispatchStrategy(
asset_for_metric=None
if metric in [vega_protos.vega.DISPATCH_METRIC_VALIDATOR_RANKING]
else asset_for_metric,
entity_scope=entity_scope,
individual_scope=individual_scope
if entity_scope is vega_protos.vega.ENTITY_SCOPE_INDIVIDUALS
else None,
window_length=None
if metric in [vega_protos.vega.DISPATCH_METRIC_MARKET_VALUE]
else window_length,
Expand All @@ -2362,8 +2450,6 @@ def recurring_transfer(
# Set the optional DispatchStrategy fields
for attr, val in [
("metric", metric),
("asset_for_metric", asset_for_metric),
("individual_scope", individual_scope),
("n_top_performers", n_top_performers),
("staking_requirement", staking_requirement),
(
Expand All @@ -2379,24 +2465,7 @@ def recurring_transfer(
dispatch_strategy.team_scope.extend(team_scope)
if rank_table is not None:
dispatch_strategy.rank_table.extend(rank_table)
recurring_transfer.dispatch_strategy.CopyFrom(dispatch_strategy)

trading.transfer(
wallet=self.wallet,
wallet_name=from_wallet_name,
key_name=from_key_name,
from_account_type=from_account_type,
to=(
self.wallet.public_key(wallet_name=to_wallet_name, name=to_key_name)
if to_key_name is not None
else "0000000000000000000000000000000000000000000000000000000000000000"
),
to_account_type=to_account_type,
asset=asset,
amount=str(num_to_padded_int(amount, self.asset_decimals[asset])),
reference=reference,
recurring=recurring_transfer,
)
return dispatch_strategy

def list_transfers(
self,
Expand Down

0 comments on commit 7abb11d

Please sign in to comment.