/
proposal_register_pool.go
144 lines (131 loc) · 4.71 KB
/
proposal_register_pool.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package types
import (
"fmt"
"strings"
"time"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)
const (
ProposalTypeRegisterPool = "RegisterPool"
)
var (
_ govtypes.Content = &ProposalRegisterPool{}
)
func init() {
govtypes.RegisterProposalType(ProposalTypeRegisterPool)
}
func NewRegisterPoolProposal(title string, description string, poolType PoolType, chainID string, denom string, nativeDenom string, connectionId string, bech32PrefixAccAddr string, bech32PrefixValAddr string, validators []string, minDepositAmount math.Int, prizeStrategy PrizeStrategy, drawSchedule DrawSchedule, UnbondingDuration time.Duration, maxUnbondingEntries math.Int, fees []FeeTaker) govtypes.Content {
return &ProposalRegisterPool{
Title: title,
Description: description,
PoolType: poolType,
ChainId: chainID,
Denom: denom,
NativeDenom: nativeDenom,
ConnectionId: connectionId,
Validators: validators,
MinDepositAmount: minDepositAmount,
Bech32PrefixAccAddr: bech32PrefixAccAddr,
Bech32PrefixValAddr: bech32PrefixValAddr,
PrizeStrategy: prizeStrategy,
DrawSchedule: drawSchedule,
UnbondingDuration: UnbondingDuration,
MaxUnbondingEntries: maxUnbondingEntries,
FeeTakers: fees,
}
}
func (p *ProposalRegisterPool) ProposalRoute() string { return RouterKey }
func (p *ProposalRegisterPool) ProposalType() string {
return ProposalTypeRegisterPool
}
func (p *ProposalRegisterPool) ValidateBasic() error {
// Validate root proposal content
err := govtypes.ValidateAbstract(p)
if err != nil {
return err
}
if p.PoolType == PoolType_Unspecified {
return errorsmod.Wrapf(ErrInvalidPoolType, "%s not allowed", p.PoolType.String())
}
// Validate payload
if len(strings.TrimSpace(p.ChainId)) <= 0 {
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "Chain ID is required")
}
if err := sdk.ValidateDenom(p.Denom); err != nil {
return errorsmod.Wrapf(err, "a valid denom is required")
}
if err := sdk.ValidateDenom(p.NativeDenom); err != nil {
return errorsmod.Wrapf(err, "a valid native_denom is required")
}
if len(p.Validators) <= 0 {
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "at least one validator is required")
}
if p.MinDepositAmount.IsNil() || p.MinDepositAmount.LT(sdk.NewInt(MinAcceptableDepositAmount)) {
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "min deposit denom must be gte %d", MinAcceptableDepositAmount)
}
if p.UnbondingDuration < MinUnbondingDuration {
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "unbonding duration cannot be lower than %s", MinUnbondingDuration)
}
if p.MaxUnbondingEntries.IsNil() || p.MaxUnbondingEntries.IsNegative() || p.MaxUnbondingEntries.GT(sdk.NewInt(DefaultMaxUnbondingEntries)) {
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "Unbonding entries cannot be negative or greated than %d", DefaultMaxUnbondingEntries)
}
if len(strings.TrimSpace(p.Bech32PrefixAccAddr)) <= 0 {
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "bech32 acc prefix is required")
}
if len(strings.TrimSpace(p.Bech32PrefixValAddr)) <= 0 {
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "bech32 val prefix is required")
}
if len(p.PrizeStrategy.PrizeBatches) <= 0 {
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "at least one prize strategy batch is required")
}
if p.DrawSchedule.DrawDelta < MinAcceptableDrawDelta {
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "draw delta cannot be lower than %s", MinAcceptableDrawDelta)
}
return ValidateFeeTakers(p.FeeTakers)
}
func (p ProposalRegisterPool) String() string {
// Prepare the fee takers string by iterating over the array
feeTakers := ""
for _, fee := range p.FeeTakers {
feeTakers += fee.String() + "\n"
}
// Return the string
return fmt.Sprintf(`Register Pool Proposal:
Title: %s
Description: %s
ChainID: %s
Denom: %s
Native Denom: %s
Connection ID %s
Validators: %+v
Min Deposit Amount: %d
Zone Unbonding Duration: %s
Max Unbonding Entries: %d
Bech32 Acc Prefix: %s
Bech32 Val Prefix: %s
Transfer Channel ID: %s
======Draw Schedule======
%s
======Prize Strategy======
%s
======Fee Takers======
%s
`,
p.Title, p.Description,
p.ChainId, p.Denom, p.NativeDenom,
p.ConnectionId,
p.Validators,
p.MinDepositAmount.Int64(),
p.UnbondingDuration.String(),
p.MaxUnbondingEntries.Int64(),
p.Bech32PrefixAccAddr, p.Bech32PrefixValAddr,
p.TransferChannelId,
p.DrawSchedule.String(),
p.PrizeStrategy.String(),
feeTakers,
)
}