-
Notifications
You must be signed in to change notification settings - Fork 2
/
params.go
151 lines (133 loc) · 4.19 KB
/
params.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
145
146
147
148
149
150
151
package types
import (
"fmt"
"time"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
host "github.com/cosmos/ibc-go/v6/modules/core/24-host"
"github.com/cvn-network/cvn/v2/utils"
)
var (
// DefaultClaimsDenom is acvnt
DefaultClaimsDenom = utils.BaseDenom
// DefaultDurationUntilDecay is 1 month = 30.4375 days
DefaultDurationUntilDecay = 2629800 * time.Second
// DefaultDurationOfDecay is 2 months
DefaultDurationOfDecay = 2 * DefaultDurationUntilDecay
// DefaultAuthorizedChannels defines the list of default IBC authorized channels that can perform
// IBC address attestations in order to migrate claimable amounts. By default
// only Osmosis and Cosmos Hub channels are authorized
DefaultAuthorizedChannels = []string{
"channel-0", // Osmosis
"channel-3", // Cosmos Hub
}
DefaultEVMChannels = []string{
"channel-2", // Injective
}
DefaultEnableClaims = true
DefaultAirdropStartTime = time.Time{}
)
// ParamsKey store key for params
var ParamsKey = []byte("Params")
// NewParams creates a new Params object
func NewParams(
enableClaim bool,
claimsDenom string,
airdropStartTime time.Time,
durationUntilDecay,
durationOfDecay time.Duration,
authorizedChannels,
evmChannels []string,
) Params {
return Params{
EnableClaims: enableClaim,
ClaimsDenom: claimsDenom,
AirdropStartTime: airdropStartTime,
DurationUntilDecay: durationUntilDecay,
DurationOfDecay: durationOfDecay,
AuthorizedChannels: authorizedChannels,
EVMChannels: evmChannels,
}
}
// DefaultParams creates a parameter instance with default values
// for the claims module.
func DefaultParams() Params {
return Params{
EnableClaims: DefaultEnableClaims,
ClaimsDenom: DefaultClaimsDenom,
AirdropStartTime: DefaultAirdropStartTime,
DurationUntilDecay: DefaultDurationUntilDecay,
DurationOfDecay: DefaultDurationOfDecay,
AuthorizedChannels: DefaultAuthorizedChannels,
EVMChannels: DefaultEVMChannels,
}
}
// ValidateChannels checks if channels ids are valid
func ValidateChannels(i interface{}) error {
channels, ok := i.([]string)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
for _, channel := range channels {
if err := host.ChannelIdentifierValidator(channel); err != nil {
return errorsmod.Wrap(
channeltypes.ErrInvalidChannelIdentifier, err.Error(),
)
}
}
return nil
}
func (p Params) Validate() error {
if p.DurationOfDecay <= 0 {
return fmt.Errorf("duration of decay must be positive: %d", p.DurationOfDecay)
}
if p.DurationUntilDecay <= 0 {
return fmt.Errorf("duration until decay must be positive: %d", p.DurationOfDecay)
}
if err := sdk.ValidateDenom(p.ClaimsDenom); err != nil {
return err
}
if err := ValidateChannels(p.AuthorizedChannels); err != nil {
return err
}
return ValidateChannels(p.EVMChannels)
}
// DecayStartTime returns the time at which the Decay period starts
func (p Params) DecayStartTime() time.Time {
return p.AirdropStartTime.Add(p.DurationUntilDecay)
}
// AirdropEndTime returns the time at which no further claims will be processed.
func (p Params) AirdropEndTime() time.Time {
return p.AirdropStartTime.Add(p.DurationUntilDecay).Add(p.DurationOfDecay)
}
// IsClaimsActive returns true if the claiming process is active:
// - claims are enabled AND
// - block time is equal or after the airdrop start time AND
// - block time is before or equal the airdrop end time
func (p Params) IsClaimsActive(blockTime time.Time) bool {
if !p.EnableClaims || blockTime.Before(p.AirdropStartTime) || blockTime.After(p.AirdropEndTime()) {
return false
}
return true
}
// IsAuthorizedChannel returns true if the channel provided is in the list of
// authorized channels
func (p Params) IsAuthorizedChannel(channel string) bool {
for _, authorizedChannel := range p.AuthorizedChannels {
if channel == authorizedChannel {
return true
}
}
return false
}
// IsEVMChannel returns true if the channel provided is in the list of
// EVM channels
func (p Params) IsEVMChannel(channel string) bool {
for _, evmChannel := range p.EVMChannels {
if channel == evmChannel {
return true
}
}
return false
}