From 336c0fa3a9423e67d9f0a6392a3572046dffd64e Mon Sep 17 00:00:00 2001 From: ze97286 Date: Thu, 29 Aug 2024 12:35:48 +0100 Subject: [PATCH] fix: ensure transfers with eligible entities to have at least one constraint --- CHANGELOG.md | 2 +- commands/transfer_funds.go | 18 ++++++++++++++++++ commands/transfer_funds_test.go | 25 +++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c66c9533b5..8cc6b1461f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ - [11533](https://github.com/vegaprotocol/vega/issues/11533) - Suppose per party fee discounts in fee estimation. - [11577](https://github.com/vegaprotocol/vega/issues/11577) - Add API for party discounts and rewards. - [10716](https://github.com/vegaprotocol/vega/issues/10716) - Set Tendermint defaults during init. - +-[11624](https://github.com/vegaprotocol/vega/issues/11624) - prevent creation of rewards with no payout, but with high computational cost. ### 🐛 Fixes diff --git a/commands/transfer_funds.go b/commands/transfer_funds.go index f3a7bdccf1..f4dc81d886 100644 --- a/commands/transfer_funds.go +++ b/commands/transfer_funds.go @@ -243,6 +243,24 @@ func validateDispatchStrategy(toAccountType vega.AccountType, dispatchStrategy * if dispatchStrategy.EntityScope == vega.EntityScope_ENTITY_SCOPE_TEAMS && len(dispatchStrategy.NTopPerformers) == 0 { errs.AddForProperty(prefix+".n_top_performers", ErrIsRequired) } + if dispatchStrategy.Metric == vega.DispatchMetric_DISPATCH_METRIC_ELIGIBLE_ENTITIES { + var metricAssetDefined, marketScope, stakingRequirement, positionRequirement bool + if len(dispatchStrategy.AssetForMetric) > 0 { + metricAssetDefined = true + } + if len(dispatchStrategy.Markets) > 0 { + marketScope = true + } + if len(dispatchStrategy.StakingRequirement) > 0 { + stakingRequirement = true + } + if len(dispatchStrategy.NotionalTimeWeightedAveragePositionRequirement) > 0 { + positionRequirement = true + } + if !metricAssetDefined && !marketScope && !stakingRequirement && !positionRequirement { + errs.AddForProperty(prefix+".dispatch_metric", fmt.Errorf("eligible_entities metric requires at least one of (markets, asset_for_metric, staking_requirement, notional_time_weighted_average_position_requirement) to be defined")) + } + } if dispatchStrategy.Metric == vega.DispatchMetric_DISPATCH_METRIC_ELIGIBLE_ENTITIES && len(dispatchStrategy.NotionalTimeWeightedAveragePositionRequirement) > 0 && len(dispatchStrategy.AssetForMetric) == 0 { errs.AddForProperty(prefix+".asset_for_metric", fmt.Errorf("asset for metric must be provided if NotionalTimeWeightedAveragePositionRequirement is specified")) diff --git a/commands/transfer_funds_test.go b/commands/transfer_funds_test.go index 649f8178d6..6a16deca4e 100644 --- a/commands/transfer_funds_test.go +++ b/commands/transfer_funds_test.go @@ -1441,6 +1441,31 @@ func TestTransferFunds(t *testing.T) { Reference: "testing", }, }, + { + transfer: commandspb.Transfer{ + FromAccountType: vega.AccountType_ACCOUNT_TYPE_GENERAL, + ToAccountType: vega.AccountType_ACCOUNT_TYPE_REWARD_ELIGIBLE_ENTITIES, + Kind: &commandspb.Transfer_Recurring{ + Recurring: &commandspb.RecurringTransfer{ + StartEpoch: 10, + EndEpoch: ptr.From(uint64(11)), + Factor: "1", + DispatchStrategy: &vega.DispatchStrategy{ + AssetForMetric: "", + Metric: vega.DispatchMetric_DISPATCH_METRIC_ELIGIBLE_ENTITIES, + DistributionStrategy: vega.DistributionStrategy_DISTRIBUTION_STRATEGY_PRO_RATA, + EntityScope: vega.EntityScope_ENTITY_SCOPE_TEAMS, + // no asset for metric, no markets in scope, no position requirement, no staking requirement + }, + }, + }, + To: "84e2b15102a8d6c1c6b4bdf40af8a0dc21b040eaaa1c94cd10d17604b75fdc35", + Asset: "080538b7cc2249de568cb4272a17f4d5e0b0a69a1a240acbf5119d816178daff", + Amount: "1", + Reference: "testing", + }, + errString: "transfer.kind.dispatch_strategy.dispatch_metric (eligible_entities metric requires at least one of (markets, asset_for_metric, staking_requirement, notional_time_weighted_average_position_requirement) to be defined)", + }, } invalidAccountTypesForOneOff := []vega.AccountType{