Skip to content

Commit

Permalink
Merge pull request #11571 from vegaprotocol/11562
Browse files Browse the repository at this point in the history
feat: Include the required set of parties for evaluation for eligible…
  • Loading branch information
ze97286 authored Aug 13, 2024
2 parents aecf399 + 0c88bc4 commit 7f436a1
Show file tree
Hide file tree
Showing 13 changed files with 359 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- [11536](https://github.com/vegaprotocol/vega/issues/11536) - Make the batch market instructions errors programmatically usable.
- [11546](https://github.com/vegaprotocol/vega/issues/11546) - Add validation to market proposals metadata.
- [11562](https://github.com/vegaprotocol/vega/issues/11562) - Update average notional metric with mark price at the end of the epoch and when calculating live score.
- [11570](https://github.com/vegaprotocol/vega/issues/11570) - Include the required set of parties for evaluation for eligible entities reward.

### 🐛 Fixes

Expand Down
17 changes: 17 additions & 0 deletions core/collateral/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ func (e *Engine) CheckOrderSpamAllMarkets(party string) error {
return fmt.Errorf("party " + party + " is not eligible to submit order transaction with no market in scope")
}

func (e *Engine) GetAllParties() []string {
keys := make([]string, 0, len(e.partiesAccsBalanceCache))
for k := range e.partiesAccsBalanceCache {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}

func (e *Engine) CheckOrderSpam(party, market string, assets []string) error {
e.cacheLock.RLock()
defer e.cacheLock.RUnlock()
Expand Down Expand Up @@ -448,6 +457,14 @@ func (e *Engine) ReloadConf(cfg Config) {
e.cfgMu.Unlock()
}

func (e *Engine) OnEpochEvent(ctx context.Context, epoch types.Epoch) {
if epoch.Action == vega.EpochAction_EPOCH_ACTION_START {
e.snapshotBalances()
}
}

func (e *Engine) OnEpochRestore(ctx context.Context, epoch types.Epoch) {}

// EnableAsset adds a new asset in the collateral engine
// this enable the asset to be used by new markets or
// parties to deposit funds.
Expand Down
1 change: 1 addition & 0 deletions core/execution/amm/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const (

type Collateral interface {
GetAssetQuantum(asset string) (num.Decimal, error)
GetAllParties() []string
GetPartyMarginAccount(market, party, asset string) (*types.Account, error)
GetPartyGeneralAccount(party, asset string) (*types.Account, error)
SubAccountUpdate(
Expand Down
14 changes: 14 additions & 0 deletions core/execution/amm/mocks/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions core/execution/common/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ type Collateral interface {
GetOrCreateLiquidityFeesBonusDistributionAccount(ctx context.Context, marketID, asset string) (*types.Account, error)
CheckOrderSpam(party, market string, assets []string) error
CheckOrderSpamAllMarkets(party string) error
GetAllParties() []string

// amm stuff
SubAccountClosed(ctx context.Context, party, subAccount, asset, market string) ([]*types.LedgerMovement, error)
Expand Down Expand Up @@ -415,6 +416,7 @@ type CommonMarket interface {

type AccountBalanceChecker interface {
GetAvailableBalance(party string) (*num.Uint, error)
GetAllStakingParties() []string
}

type Teams interface {
Expand Down
21 changes: 20 additions & 1 deletion core/execution/common/market_activity_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var (

type QuantumGetter interface {
GetAssetQuantum(asset string) (num.Decimal, error)
GetAllParties() []string
}

type twPosition struct {
Expand Down Expand Up @@ -819,7 +820,25 @@ func (mat *MarketActivityTracker) getPartiesInScope(ds *vega.DispatchStrategy) [
if ds.IndividualScope == vega.IndividualScope_INDIVIDUAL_SCOPE_IN_TEAM {
parties = mat.teams.GetAllPartiesInTeams(mat.minEpochsInTeamForRewardEligibility)
} else if ds.IndividualScope == vega.IndividualScope_INDIVIDUAL_SCOPE_ALL {
parties = sortedK(mat.getAllParties(ds.AssetForMetric, ds.Markets))
if ds.Metric == vega.DispatchMetric_DISPATCH_METRIC_ELIGIBLE_ENTITIES {
notionalReq := num.UintZero()
stakingReq := num.UintZero()
if len(ds.NotionalTimeWeightedAveragePositionRequirement) > 0 {
notionalReq = num.MustUintFromString(ds.NotionalTimeWeightedAveragePositionRequirement, 10)
}
if len(ds.StakingRequirement) > 0 {
stakingReq = num.MustUintFromString(ds.StakingRequirement, 10)
}
if !notionalReq.IsZero() {
parties = sortedK(mat.getAllParties(ds.AssetForMetric, ds.Markets))
} else if !stakingReq.IsZero() {
parties = mat.balanceChecker.GetAllStakingParties()
} else {
parties = mat.collateral.GetAllParties()
}
} else {
parties = sortedK(mat.getAllParties(ds.AssetForMetric, ds.Markets))
}
} else if ds.IndividualScope == vega.IndividualScope_INDIVIDUAL_SCOPE_NOT_IN_TEAM {
parties = sortedK(excludePartiesInTeams(mat.getAllParties(ds.AssetForMetric, ds.Markets), mat.teams.GetAllPartiesInTeams(mat.minEpochsInTeamForRewardEligibility)))
} else if ds.IndividualScope == vega.IndividualScope_INDIVIDUAL_SCOPE_AMM {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,10 @@ func (e DummyCollateralEngine) GetAssetQuantum(asset string) (num.Decimal, error
return num.DecimalOne(), nil
}

func (e DummyCollateralEngine) GetAllParties() []string {
return []string{}
}

type DummyEligibilityChecker struct{}

func (e *DummyEligibilityChecker) IsEligibleForProposerBonus(marketID string, volumeTraded *num.Uint) bool {
Expand Down
28 changes: 28 additions & 0 deletions core/execution/common/mocks/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7f436a1

Please sign in to comment.