Skip to content

Commit

Permalink
Merge branch 'develop' into 9773
Browse files Browse the repository at this point in the history
  • Loading branch information
ze97286 authored Oct 16, 2023
2 parents 4d0dd0b + e540a44 commit 5ecbba4
Show file tree
Hide file tree
Showing 6 changed files with 246 additions and 81 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@
- [9658](https://github.com/vegaprotocol/vega/issues/9658) - Fix `updateVolumeDiscountProgram` GraphQL resolver.
- [9672](https://github.com/vegaprotocol/vega/issues/9672) - Fix margin being non-zero on `PERPS`, add tests to ensure distressed parties are handled correctly
- [9280](https://github.com/vegaprotocol/vega/issues/9280) - Get block height directly from `blocks` table.
- [9787](https://github.com/vegaprotocol/vega/issues/9787) - Do not sort market input so that tracking of dispatch strategies are not disturbed.
- [9675](https://github.com/vegaprotocol/vega/issues/9675) - Fix snapshot issue with not applying `providersCalculationStep` at epoch start.
- [9693](https://github.com/vegaprotocol/vega/issues/9693) - Add missing validation for general account public key in governance transfer
- [9691](https://github.com/vegaprotocol/vega/issues/9691) - Refactor referral engine snapshot
Expand All @@ -316,6 +317,7 @@
- [9751](https://github.com/vegaprotocol/vega/issues/9751) - Make sure that LP fee party accounts exists.
- [9762](https://github.com/vegaprotocol/vega/issues/9762) - Referral fees API not filtering by party correctly.
- [9775](https://github.com/vegaprotocol/vega/issues/9775) - Do not pay discount if set is not eligible
- [9788](https://github.com/vegaprotocol/vega/issues/9788) - Fix transfer account validation.

## 0.72.1

Expand Down
90 changes: 53 additions & 37 deletions commands/proposal_submission.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,27 @@ import (

const ReferenceMaxLen int = 100

var (
validSources = map[protoTypes.AccountType]struct{}{
protoTypes.AccountType_ACCOUNT_TYPE_INSURANCE: {},
protoTypes.AccountType_ACCOUNT_TYPE_GLOBAL_REWARD: {},
protoTypes.AccountType_ACCOUNT_TYPE_NETWORK_TREASURY: {},
protoTypes.AccountType_ACCOUNT_TYPE_GLOBAL_INSURANCE: {},
}
validDestinations = map[protoTypes.AccountType]struct{}{
var validTransfers = map[protoTypes.AccountType]map[protoTypes.AccountType]struct{}{
protoTypes.AccountType_ACCOUNT_TYPE_NETWORK_TREASURY: {
protoTypes.AccountType_ACCOUNT_TYPE_GENERAL: {},
protoTypes.AccountType_ACCOUNT_TYPE_GLOBAL_INSURANCE: {},
protoTypes.AccountType_ACCOUNT_TYPE_INSURANCE: {},
protoTypes.AccountType_ACCOUNT_TYPE_GLOBAL_REWARD: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_LP_RECEIVED_FEES: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_AVERAGE_POSITION: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_RELATIVE_RETURN: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_RETURN_VOLATILITY: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_VALIDATOR_RANKING: {},
},
protoTypes.AccountType_ACCOUNT_TYPE_INSURANCE: {
protoTypes.AccountType_ACCOUNT_TYPE_GENERAL: {},
protoTypes.AccountType_ACCOUNT_TYPE_GLOBAL_INSURANCE: {},
protoTypes.AccountType_ACCOUNT_TYPE_INSURANCE: {},
protoTypes.AccountType_ACCOUNT_TYPE_NETWORK_TREASURY: {},
protoTypes.AccountType_ACCOUNT_TYPE_GLOBAL_INSURANCE: {},
protoTypes.AccountType_ACCOUNT_TYPE_GLOBAL_REWARD: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_LP_RECEIVED_FEES: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES: {},
Expand All @@ -58,8 +66,22 @@ var (
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_RELATIVE_RETURN: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_RETURN_VOLATILITY: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_VALIDATOR_RANKING: {},
}
)
},
protoTypes.AccountType_ACCOUNT_TYPE_GLOBAL_INSURANCE: {
protoTypes.AccountType_ACCOUNT_TYPE_GENERAL: {},
protoTypes.AccountType_ACCOUNT_TYPE_INSURANCE: {},
protoTypes.AccountType_ACCOUNT_TYPE_NETWORK_TREASURY: {},
protoTypes.AccountType_ACCOUNT_TYPE_GLOBAL_REWARD: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_LP_RECEIVED_FEES: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_AVERAGE_POSITION: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_RELATIVE_RETURN: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_RETURN_VOLATILITY: {},
protoTypes.AccountType_ACCOUNT_TYPE_REWARD_VALIDATOR_RANKING: {},
},
}

func CheckProposalSubmission(cmd *commandspb.ProposalSubmission) error {
return checkProposalSubmission(cmd).ErrorOrNil()
Expand Down Expand Up @@ -494,48 +516,42 @@ func checkNewTransferChanges(change *protoTypes.ProposalTerms_NewTransfer) Error
if changes.SourceType == protoTypes.AccountType_ACCOUNT_TYPE_UNSPECIFIED {
return errs.FinalAddForProperty("proposal_submission.terms.change.new_transfer.changes.source_type", ErrIsRequired)
}

validDest, ok := validTransfers[changes.SourceType]
// source account type may be one of the following:
if _, ok := validSources[changes.SourceType]; !ok {
if !ok {
return errs.FinalAddForProperty("proposal_submission.terms.change.new_transfer.changes.source_type", ErrIsNotValid)
}

if changes.DestinationType == protoTypes.AccountType_ACCOUNT_TYPE_UNSPECIFIED {
return errs.FinalAddForProperty("proposal_submission.terms.change.new_transfer.changes.destination_type", ErrIsRequired)
}

if changes.SourceType == protoTypes.AccountType_ACCOUNT_TYPE_GLOBAL_REWARD && changes.DestinationType == protoTypes.AccountType_ACCOUNT_TYPE_GLOBAL_REWARD {
if _, ok := validDest[changes.DestinationType]; !ok {
return errs.FinalAddForProperty("proposal_submission.terms.change.new_transfer.changes.destination_type", ErrIsNotValid)
}
dest := changes.DestinationType

if changes.SourceType == protoTypes.AccountType_ACCOUNT_TYPE_NETWORK_TREASURY && changes.DestinationType == protoTypes.AccountType_ACCOUNT_TYPE_NETWORK_TREASURY {
return errs.FinalAddForProperty("proposal_submission.terms.change.new_transfer.changes.destination_type", ErrIsNotValid)
}

// destination account type may be one of the following:
if _, ok := validDestinations[changes.DestinationType]; !ok {
return errs.FinalAddForProperty("proposal_submission.terms.change.new_transfer.changes.destination_type", ErrIsNotValid)
}

if changes.DestinationType == protoTypes.AccountType_ACCOUNT_TYPE_GENERAL && !IsVegaPublicKey(changes.Destination) {
// party accounts: check pubkey
if dest == protoTypes.AccountType_ACCOUNT_TYPE_GENERAL && !IsVegaPublicKey(changes.Destination) {
errs.AddForProperty("proposal_submission.terms.change.new_transfer.changes.destination", ErrShouldBeAValidVegaPublicKey)
}

if (changes.SourceType == protoTypes.AccountType_ACCOUNT_TYPE_GLOBAL_REWARD ||
changes.SourceType == protoTypes.AccountType_ACCOUNT_TYPE_NETWORK_TREASURY ||
changes.SourceType == protoTypes.AccountType_ACCOUNT_TYPE_GLOBAL_INSURANCE) &&
len(changes.Source) > 0 {
// insurance account type requires a source, other sources are global
if changes.SourceType == protoTypes.AccountType_ACCOUNT_TYPE_INSURANCE {
if len(changes.Source) == 0 {
return errs.FinalAddForProperty("proposal_submission.terms.change.new_transfer.changes.source", ErrIsNotValid)
}
// destination == source
if dest == changes.SourceType && changes.Source == changes.Destination {
return errs.FinalAddForProperty("proposal_submission.terms.change.new_transfer.changes.destination", ErrIsNotValid)
}
} else if len(changes.Source) > 0 {
return errs.FinalAddForProperty("proposal_submission.terms.change.new_transfer.changes.source", ErrIsNotValid)
}

if (changes.DestinationType == protoTypes.AccountType_ACCOUNT_TYPE_GLOBAL_REWARD ||
changes.DestinationType == protoTypes.AccountType_ACCOUNT_TYPE_NETWORK_TREASURY ||
changes.DestinationType == protoTypes.AccountType_ACCOUNT_TYPE_GLOBAL_INSURANCE) &&
len(changes.Destination) > 0 {
return errs.FinalAddForProperty("proposal_submission.terms.change.new_transfer.changes.destination", ErrIsNotValid)
}

if changes.SourceType == changes.DestinationType && changes.Source == changes.Destination {
// global destination accounts == no source
if (dest == protoTypes.AccountType_ACCOUNT_TYPE_GENERAL ||
dest == protoTypes.AccountType_ACCOUNT_TYPE_INSURANCE) &&
len(changes.Destination) == 0 {
return errs.FinalAddForProperty("proposal_submission.terms.change.new_transfer.changes.destination", ErrIsNotValid)
}

Expand Down
Loading

0 comments on commit 5ecbba4

Please sign in to comment.