-
Notifications
You must be signed in to change notification settings - Fork 55
/
proposal.go
104 lines (87 loc) · 2.75 KB
/
proposal.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package types
import (
"fmt"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
gov "github.com/cosmos/cosmos-sdk/x/gov/types"
)
const (
ProposalTypeMarketMaker string = "MarketMaker"
)
// Implements Proposal Interface
var _ gov.Content = &MarketMakerProposal{}
func init() {
gov.RegisterProposalType(ProposalTypeMarketMaker)
gov.RegisterProposalTypeCodec(&MarketMakerProposal{}, "crescent/MarketMakerProposal")
}
// NewMarketMakerProposal creates a new MarketMakerProposal object.
func NewMarketMakerProposal(
title string,
description string,
inclusions []MarketMakerHandle,
exclusions []MarketMakerHandle,
rejections []MarketMakerHandle,
distributions []IncentiveDistribution,
) *MarketMakerProposal {
return &MarketMakerProposal{
Title: title,
Description: description,
Inclusions: inclusions,
Exclusions: exclusions,
Rejections: rejections,
Distributions: distributions,
}
}
func (p *MarketMakerProposal) GetTitle() string { return p.Title }
func (p *MarketMakerProposal) GetDescription() string { return p.Description }
func (p *MarketMakerProposal) ProposalRoute() string { return RouterKey }
func (p *MarketMakerProposal) ProposalType() string { return ProposalTypeMarketMaker }
func (p *MarketMakerProposal) ValidateBasic() error {
if len(p.Inclusions) == 0 && len(p.Exclusions) == 0 && len(p.Rejections) == 0 && len(p.Distributions) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "proposal request must not be empty")
}
// checking duplicated market maker for inclusion, exclusion, rejection
addrMap := make(map[MarketMakerHandle]struct{})
for _, mm := range p.Inclusions {
if _, ok := addrMap[mm]; ok {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "market maker can't be duplicated")
}
addrMap[mm] = struct{}{}
if err := mm.Validate(); err != nil {
return err
}
}
for _, mm := range p.Exclusions {
if _, ok := addrMap[mm]; ok {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "market maker can't be duplicated")
}
addrMap[mm] = struct{}{}
if err := mm.Validate(); err != nil {
return err
}
}
for _, mm := range p.Rejections {
if _, ok := addrMap[mm]; ok {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "market maker can't be duplicated")
}
addrMap[mm] = struct{}{}
if err := mm.Validate(); err != nil {
return err
}
}
for _, dp := range p.Distributions {
if err := dp.Validate(); err != nil {
return err
}
}
return gov.ValidateAbstract(p)
}
func (p MarketMakerProposal) String() string {
return fmt.Sprintf(`Market Maker Proposal:
Title: %s
Description: %s
Inclusions: %v
Exclusions: %v
Rejections: %v
Distributions: %v
`, p.Title, p.Description, p.Inclusions, p.Exclusions, p.Rejections, p.Distributions)
}