Skip to content

Commit

Permalink
Merge pull request #11626 from vegaprotocol/eligible_constraint
Browse files Browse the repository at this point in the history
fix: ensure transfers with eligible entities to have at least one con…
  • Loading branch information
jeremyletang authored Aug 29, 2024
2 parents e0dcb06 + 336c0fa commit f1e6e81
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions commands/transfer_funds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
25 changes: 25 additions & 0 deletions commands/transfer_funds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit f1e6e81

Please sign in to comment.