Skip to content

Commit

Permalink
Merge branch 'develop' into bb_auctions
Browse files Browse the repository at this point in the history
  • Loading branch information
ze97286 authored Sep 15, 2024
2 parents 736a850 + 3ed0bf2 commit 89415d1
Show file tree
Hide file tree
Showing 24 changed files with 923 additions and 92 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

### 🐛 Fixes

- [](https://github.com/vegaprotocol/vega/issues/xxx)
- [11672](https://github.com/vegaprotocol/vega/issues/11672) - Add missing fees in GraphQL bindings.
- [11681](https://github.com/vegaprotocol/vega/issues/11681) - Account for conflicts inserting funding payment records.


## 0.78.2
Expand All @@ -35,7 +36,9 @@
- [11650](https://github.com/vegaprotocol/vega/issues/11650) - Add include sub accounts flag to `listPositions`.
- [11641](https://github.com/vegaprotocol/vega/issues/11641) - Panic with pegged orders.
- [11646](https://github.com/vegaprotocol/vega/issues/11646) - Add tier numbers to API.

- [11665](https://github.com/vegaprotocol/vega/issues/11665) - Delay the final termination of a transfer to the following epoch.
- [11679](https://github.com/vegaprotocol/vega/issues/11679) - Fix calculation of fees in party `stats`.
- [11665](https://github.com/vegaprotocol/vega/issues/11665) - Delay the final termination of a transfer to the following epoch.

## 0.78.1

Expand Down Expand Up @@ -70,7 +73,7 @@
- [11612](https://github.com/vegaprotocol/vega/issues/11612) - Reward scaling support.
- [11624](https://github.com/vegaprotocol/vega/issues/11624) - prevent creation of rewards with no payout, but with high computational cost.
- [11512](https://github.com/vegaprotocol/vega/issues/11512) - Add loss socialisation amounts to funding payment API.
- [11627](https://github.com/vegaprotocol/vega/issues/11627) - Add eligible keys filter to reward transfers.
- [11627](https://github.com/vegaprotocol/vega/issues/11627) - Add eligible keys filter to reward transfers.

### 🐛 Fixes

Expand Down
1 change: 1 addition & 0 deletions commands/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (
ErrMustBeLessThan150 = errors.New("must be less than 150")
ErrMustBeAtMost1M = errors.New("must be at most 1000000")
ErrMustBeAtMost100 = errors.New("must be at most 100")
ErrMustBeAtMost200 = errors.New("must be at most 200")
ErrMustBeAtMost2048 = errors.New("must be at most 2048")
ErrMustBeWithinRange7 = errors.New("must be between -7 and 7")
ErrIsNotValid = errors.New("is not a valid value")
Expand Down
14 changes: 7 additions & 7 deletions commands/proposal_submission.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ func checkReferralProgramChanges(changes *vegapb.ReferralProgramChanges, enactme
}
if changes.WindowLength == 0 {
errs.AddForProperty("update_referral_program.changes.window_length", ErrIsRequired)
} else if changes.WindowLength > 100 {
errs.AddForProperty("update_referral_program.changes.window_length", ErrMustBeAtMost100)
} else if changes.WindowLength > 200 {
errs.AddForProperty("update_referral_program.changes.window_length", ErrMustBeAtMost200)
}

tiers := map[string]struct{}{}
Expand Down Expand Up @@ -562,8 +562,8 @@ func checkVolumeRebateProgramChanges(changes *vegapb.VolumeRebateProgramChanges,
}
if changes.WindowLength == 0 {
errs.AddForProperty("update_volume_rebate_program.changes.window_length", ErrIsRequired)
} else if changes.WindowLength > 100 {
errs.AddForProperty("update_volume_rebate_program.changes.window_length", ErrMustBeAtMost100)
} else if changes.WindowLength > 200 {
errs.AddForProperty("update_volume_rebate_program.changes.window_length", ErrMustBeAtMost200)
}
for i, tier := range changes.BenefitTiers {
errs.Merge(checkVolumeRebateBenefitTier(i, tier))
Expand All @@ -574,7 +574,7 @@ func checkVolumeRebateProgramChanges(changes *vegapb.VolumeRebateProgramChanges,

func checkVolumeRebateBenefitTier(index int, tier *vegapb.VolumeRebateBenefitTier) Errors {
errs := NewErrors()
propertyPath := fmt.Sprintf("update_volume_discount_program.changes.benefit_tiers.%d", index)
propertyPath := fmt.Sprintf("update_volume_rebate_program.changes.benefit_tiers.%d", index)
if len(tier.MinimumPartyMakerVolumeFraction) == 0 {
errs.AddForProperty(propertyPath+".minimum_party_maker_volume_fraction", ErrIsRequired)
} else {
Expand Down Expand Up @@ -610,8 +610,8 @@ func checkVolumeDiscountProgramChanges(changes *vegapb.VolumeDiscountProgramChan
}
if changes.WindowLength == 0 {
errs.AddForProperty("update_volume_discount_program.changes.window_length", ErrIsRequired)
} else if changes.WindowLength > 100 {
errs.AddForProperty("update_volume_discount_program.changes.window_length", ErrMustBeAtMost100)
} else if changes.WindowLength > 200 {
errs.AddForProperty("update_volume_discount_program.changes.window_length", ErrMustBeAtMost200)
}
for i, tier := range changes.BenefitTiers {
errs.Merge(checkVolumeBenefitTier(i, tier))
Expand Down
173 changes: 173 additions & 0 deletions commands/proposal_submission_update_rebate_program_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
// Copyright (C) 2023 Gobalsky Labs Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package commands_test

import (
"testing"
"time"

"code.vegaprotocol.io/vega/commands"
types "code.vegaprotocol.io/vega/protos/vega"
commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1"

"github.com/stretchr/testify/assert"
)

func TestVolumeRebateSubmission(t *testing.T) {
t.Run("empty submission", testUpdateRebateProgram)
t.Run("0095-HVMR-001: invalid end timestamp", testInvalidEndTime)
t.Run("0095-HVMR-003: tier validation", testInvalidTiers)
t.Run("0095-HVMR-004: invalid window length", testInvalidWindowLength)
}

func testUpdateRebateProgram(t *testing.T) {
err := checkProposalSubmission(&commandspb.ProposalSubmission{
Terms: &types.ProposalTerms{
Change: &types.ProposalTerms_UpdateVolumeRebateProgram{},
},
})

assert.Contains(t, err.Get("proposal_submission.terms.change.update_volume_rebate_program"), commands.ErrIsRequired)
// missing changes, same problem
err = checkProposalSubmission(&commandspb.ProposalSubmission{
Terms: &types.ProposalTerms{
Change: &types.ProposalTerms_UpdateVolumeRebateProgram{
UpdateVolumeRebateProgram: &types.UpdateVolumeRebateProgram{},
},
},
})

assert.Contains(t, err.Get("proposal_submission.terms.change.update_volume_rebate_program.changes"), commands.ErrIsRequired)
}

// testInvalidEndTime covers 0095-HVMR-001.
func testInvalidEndTime(t *testing.T) {
end := time.Now()
enact := end.Add(time.Second)
prop := &commandspb.ProposalSubmission{
Terms: &types.ProposalTerms{
EnactmentTimestamp: enact.Unix(),
Change: &types.ProposalTerms_UpdateVolumeRebateProgram{
UpdateVolumeRebateProgram: &types.UpdateVolumeRebateProgram{
Changes: &types.VolumeRebateProgramChanges{
EndOfProgramTimestamp: end.Unix(),
},
},
},
},
}
err := checkProposalSubmission(prop)
assert.Contains(t, err.Get("proposal_submission.terms.change.update_volume_rebate_program.changes.end_of_program_timestamp"), commands.ErrMustBeGreaterThanEnactmentTimestamp)
}

// testInvalidWindowLength covers 0095-HVMR-004.
func testInvalidWindowLength(t *testing.T) {
enact := time.Now()
end := enact.Add(time.Second)
prop := &commandspb.ProposalSubmission{
Terms: &types.ProposalTerms{
EnactmentTimestamp: enact.Unix(),
Change: &types.ProposalTerms_UpdateVolumeRebateProgram{
UpdateVolumeRebateProgram: &types.UpdateVolumeRebateProgram{
Changes: &types.VolumeRebateProgramChanges{
EndOfProgramTimestamp: end.Unix(),
WindowLength: 0, // zero is invalid
},
},
},
},
}
err := checkProposalSubmission(prop)
assert.Contains(t, err.Get("proposal_submission.terms.change.update_volume_rebate_program.changes.window_length"), commands.ErrIsRequired)
// now too high of a value
prop = &commandspb.ProposalSubmission{
Terms: &types.ProposalTerms{
EnactmentTimestamp: enact.Unix(),
Change: &types.ProposalTerms_UpdateVolumeRebateProgram{
UpdateVolumeRebateProgram: &types.UpdateVolumeRebateProgram{
Changes: &types.VolumeRebateProgramChanges{
EndOfProgramTimestamp: end.Unix(),
WindowLength: 10000,
},
},
},
},
}
err = checkProposalSubmission(prop)
assert.Contains(t, err.Get("proposal_submission.terms.change.update_volume_rebate_program.changes.window_length"), commands.ErrMustBeAtMost200)
}

// testInvalidTiers covers 0095-HVMR-003.
func testInvalidTiers(t *testing.T) {
errMap := map[string]error{
"proposal_submission.terms.change.update_volume_rebate_program.changes.benefit_tiers.0.minimum_party_maker_volume_fraction": commands.ErrIsRequired,
"proposal_submission.terms.change.update_volume_rebate_program.changes.benefit_tiers.1.minimum_party_maker_volume_fraction": commands.ErrIsNotValidNumber,
"proposal_submission.terms.change.update_volume_rebate_program.changes.benefit_tiers.2.minimum_party_maker_volume_fraction": commands.ErrMustBePositive,
"proposal_submission.terms.change.update_volume_rebate_program.changes.benefit_tiers.3.minimum_party_maker_volume_fraction": commands.ErrMustBePositive,
"proposal_submission.terms.change.update_volume_rebate_program.changes.benefit_tiers.4.additional_maker_rebate": commands.ErrIsRequired,
"proposal_submission.terms.change.update_volume_rebate_program.changes.benefit_tiers.5.additional_maker_rebate": commands.ErrIsNotValidNumber,
"proposal_submission.terms.change.update_volume_rebate_program.changes.benefit_tiers.6.additional_maker_rebate": commands.ErrMustBePositiveOrZero,
}
enact := time.Now()
end := enact.Add(time.Second)
prop := &commandspb.ProposalSubmission{
Terms: &types.ProposalTerms{
EnactmentTimestamp: enact.Unix(),
Change: &types.ProposalTerms_UpdateVolumeRebateProgram{
UpdateVolumeRebateProgram: &types.UpdateVolumeRebateProgram{
Changes: &types.VolumeRebateProgramChanges{
EndOfProgramTimestamp: end.Unix(),
WindowLength: 10,
BenefitTiers: []*types.VolumeRebateBenefitTier{
{
MinimumPartyMakerVolumeFraction: "",
AdditionalMakerRebate: "0.1",
},
{
MinimumPartyMakerVolumeFraction: "invalid",
AdditionalMakerRebate: "0.1",
},
{
MinimumPartyMakerVolumeFraction: "-1",
AdditionalMakerRebate: "0.1",
},
{
MinimumPartyMakerVolumeFraction: "0",
AdditionalMakerRebate: "0.1",
},
{
MinimumPartyMakerVolumeFraction: "0.1",
AdditionalMakerRebate: "",
},
{
MinimumPartyMakerVolumeFraction: "0.1",
AdditionalMakerRebate: "invalid",
},
{
MinimumPartyMakerVolumeFraction: "0.1",
AdditionalMakerRebate: "-0.1",
},
},
},
},
},
},
}
err := checkProposalSubmission(prop)
for g, c := range errMap {
assert.Contains(t, err.Get(g), c, err.Error())
}
}
4 changes: 2 additions & 2 deletions commands/proposal_submission_update_referral_program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ func testSubmissionForReferralProgramUpdateWithWindowLengthOverLimitFails(t *tes
Change: &types.ProposalTerms_UpdateReferralProgram{
UpdateReferralProgram: &types.UpdateReferralProgram{
Changes: &types.ReferralProgramChanges{
WindowLength: 101,
WindowLength: 201,
},
},
},
},
})

assert.Contains(t, err.Get("proposal_submission.terms.change.update_referral_program.changes.window_length"), commands.ErrMustBeAtMost100)
assert.Contains(t, err.Get("proposal_submission.terms.change.update_referral_program.changes.window_length"), commands.ErrMustBeAtMost200)
}

func testSubmissionForReferralProgramUpdateWithoutTierMinimumRunningNotionalTakerVolumeFails(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,14 @@ func testSubmissionForVolumeDiscountProgramUpdateWithWindowLengthOverLimitFails(
Change: &types.ProposalTerms_UpdateVolumeDiscountProgram{
UpdateVolumeDiscountProgram: &types.UpdateVolumeDiscountProgram{
Changes: &types.VolumeDiscountProgramChanges{
WindowLength: 101,
WindowLength: 201,
},
},
},
},
})

assert.Contains(t, err.Get("proposal_submission.terms.change.update_volume_discount_program.changes.window_length"), commands.ErrMustBeAtMost100)
assert.Contains(t, err.Get("proposal_submission.terms.change.update_volume_discount_program.changes.window_length"), commands.ErrMustBeAtMost200)
}

func testSubmissionForVolumeDiscountProgramUpdateWithoutTierMinimumRunningNotionalTakerVolumeFails(t *testing.T) {
Expand Down
7 changes: 0 additions & 7 deletions core/banking/recurring_transfers.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,6 @@ func (e *Engine) distributeRecurringTransfers(ctx context.Context, newEpoch uint
}

tresps = append(tresps, resps...)

// if we don't have anymore
if v.EndEpoch != nil && *v.EndEpoch == e.currentEpoch {
v.Status = types.TransferStatusDone
transfersDone = append(transfersDone, events.NewRecurringTransferFundsEvent(ctx, v, e.getGameID(v)))
doneIDs = append(doneIDs, v.ID)
}
}

// send events
Expand Down
2 changes: 2 additions & 0 deletions core/banking/recurring_transfers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ func TestMaturation(t *testing.T) {
e.OnEpoch(context.Background(), types.Epoch{Seq: 11, Action: vega.EpochAction_EPOCH_ACTION_END})
e.OnEpoch(context.Background(), types.Epoch{Seq: 12, Action: vega.EpochAction_EPOCH_ACTION_START})
e.OnEpoch(context.Background(), types.Epoch{Seq: 12, Action: vega.EpochAction_EPOCH_ACTION_END})
e.OnEpoch(context.Background(), types.Epoch{Seq: 13, Action: vega.EpochAction_EPOCH_ACTION_START})
e.OnEpoch(context.Background(), types.Epoch{Seq: 13, Action: vega.EpochAction_EPOCH_ACTION_END})

require.Equal(t, 10, len(seenEvts))
stoppedIDs := map[string]struct{}{}
Expand Down
2 changes: 2 additions & 0 deletions core/governance/engine_update_referral_program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func testSubmittingProposalForReferralProgramUpdateSucceeds(t *testing.T) {
require.NotNil(t, toSubmit)
}

// testSubmittingProposalForReferralProgramUpdateWithTooManyTiersFails covers 0095-HVMR-002.
func testSubmittingProposalForReferralProgramUpdateWithTooManyTiersFails(t *testing.T) {
now := time.Now()
ctx := vgtest.VegaContext(vgrand.RandomStr(5), vgtest.RandomPositiveI64())
Expand Down Expand Up @@ -324,6 +325,7 @@ func testSubmittingProposalForReferralProgramUpdateWithTooHighDiscountFactorFail
require.Nil(t, toSubmit)
}

// testSubmittingProposalForReferralProgramUpdateEndsBeforeEnactsFails covers 0095-HVMR-001.
func testSubmittingProposalForReferralProgramUpdateEndsBeforeEnactsFails(t *testing.T) {
now := time.Now()
ctx := vgtest.VegaContext(vgrand.RandomStr(5), vgtest.RandomPositiveI64())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Scenario: As a user I can create a recurring transfer that decreases over time w
Then "576380694832d9271682e86fffbbcebc09ca79c259baa5d4d0298e12ecdee303" should have general account balance of "21900" for asset "VEGA"

# end of epoch 5 - the transfer is ended so can't be cancelled
When the network moves ahead "7" blocks
When the network moves ahead "8" blocks
Then "a7c4b181ef9bf5e9029a016f854e4ad471208020fd86187d07f0b420004f06a4" should have general account balance of "962005" for asset "VEGA"
Then "576380694832d9271682e86fffbbcebc09ca79c259baa5d4d0298e12ecdee303" should have general account balance of "25330" for asset "VEGA"

Expand Down Expand Up @@ -174,7 +174,7 @@ Scenario: As a user I can create a recurring transfer that decreases over time w
Then "576380694832d9271682e86fffbbcebc09ca79c259baa5d4d0298e12ecdee303" should have general account balance of "21900" for asset "VEGA"

# end of epoch 5 - the transfer is ended so can't be cancelled
When the network moves ahead "7" blocks
When the network moves ahead "8" blocks
Then "a7c4b181ef9bf5e9029a016f854e4ad471208020fd86187d07f0b420004f06a4" should have general account balance of "956340" for asset "VEGA"
Then "576380694832d9271682e86fffbbcebc09ca79c259baa5d4d0298e12ecdee303" should have general account balance of "25330" for asset "VEGA"

Expand Down
Loading

0 comments on commit 89415d1

Please sign in to comment.