github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/staking/types/errors.go (about) 1 // nolint 2 package types 3 4 import ( 5 "fmt" 6 "strings" 7 8 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 9 sdkerrors "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/errors" 10 ) 11 12 const ( 13 DefaultCodespace string = ModuleName 14 15 CodeNoValidatorFound uint32 = 67000 16 CodeInvalidDelegation uint32 = 67001 17 CodeNilValidatorAddr uint32 = 67002 18 CodeBadValidatorAddr uint32 = 67003 19 CodeMoreMinSelfDelegation uint32 = 67004 20 CodeProxyNotFound uint32 = 67005 21 CodeEmptyValidators uint32 = 67006 22 CodeProxyAlreadyExist uint32 = 67007 23 CodeAddressNotEqual uint32 = 67009 24 CodeDescriptionIsEmpty uint32 = 67010 25 CodeGetConsPubKeyBech32Failed uint32 = 67011 26 CodeUnknownStakingQueryType uint32 = 67012 27 CodeValidatorOwnerExists uint32 = 67013 28 CodeValidatorPubKeyExists uint32 = 67014 29 CodeValidatorPubKeyTypeNotSupported uint32 = 67015 30 CodeBondedPoolOrNotBondedIsNotExist uint32 = 67016 31 CodeInvalidDescriptionLength uint32 = 67017 32 CodeCommissionNegative uint32 = 67018 33 CodeCommissionHuge uint32 = 67019 34 CodeCommissionGTMaxRate uint32 = 67020 35 CodeCommissionUpdateTime uint32 = 67021 36 CodeCommissionChangeRateNegative uint32 = 67022 37 CodeCommissionChangeRateGTMaxRate uint32 = 67023 38 CodeCommissionGTMaxChangeRate uint32 = 67024 39 CodeMinSelfDelegationInvalid uint32 = 67025 40 CodeNilDelegatorAddr uint32 = 67026 41 CodeDelegatorEqualToProxyAddr uint32 = 67027 42 CodeBadDenom uint32 = 67028 43 CodeBadDelegationAmount uint32 = 67029 44 CodeNoUnbondingDelegation uint32 = 67030 45 CodeAddSharesToDismission uint32 = 67031 46 CodeAddSharesDuringProxy uint32 = 67032 47 CodeDoubleProxy uint32 = 67033 48 CodeExceedValidatorAddrs uint32 = 67034 49 CodeNoDelegationToAddShares uint32 = 67035 50 CodeNotInDelegating uint32 = 67036 51 CodeInsufficientDelegation uint32 = 67037 52 CodeInsufficientQuantity uint32 = 67038 53 CodeInvalidMinSelfDelegation uint32 = 67039 54 CodeBadUnDelegationAmount uint32 = 67040 55 CodeInvalidProxyUpdating uint32 = 67041 56 CodeInvalidProxyWithdrawTotal uint32 = 67042 57 CodeAlreadyAddedShares uint32 = 67043 58 CodeNoDelegatorExisted uint32 = 67044 59 CodeTargetValsDuplicate uint32 = 67045 60 CodeAlreadyBound uint32 = 67046 61 ) 62 63 var ( 64 ErrInvalidHistoricalInfo = sdkerrors.Register(ModuleName, 144, "invalid historical info") 65 ErrNoHistoricalInfo = sdkerrors.Register(ModuleName, 145, "no historical info found") 66 ) 67 68 // ErrNoValidatorFound returns an error when a validator doesn't exist 69 func ErrNoValidatorFound(valAddr string) sdk.EnvelopedErr { 70 return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultCodespace, CodeNoValidatorFound, fmt.Sprintf("validator %s does not exist", valAddr))} 71 } 72 73 // ErrInvalidDelegation returns an error when the delegation is invalid 74 func ErrInvalidDelegation(delegator string) sdk.EnvelopedErr { 75 return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultCodespace, CodeInvalidDelegation, 76 fmt.Sprintf("failed. invalid delegation on %s", delegator))} 77 } 78 79 // ErrNilValidatorAddr returns an error when an empty validator address appears 80 func ErrNilValidatorAddr() sdk.Error { 81 return sdkerrors.New(DefaultCodespace, CodeNilValidatorAddr, "empty validator address") 82 } 83 84 // ErrBadValidatorAddr returns an error when an invalid validator address appears 85 func ErrBadValidatorAddr() sdk.Error { 86 return sdkerrors.New(DefaultCodespace, CodeBadValidatorAddr, "validator address is invalid") 87 } 88 89 // ErrMoreMinSelfDelegation returns an error when the msd doesn't match the rest of shares on a validator 90 func ErrMoreMinSelfDelegation(valAddr string) sdk.Error { 91 return sdkerrors.New(DefaultCodespace, CodeMoreMinSelfDelegation, 92 fmt.Sprintf("failed. min self delegation of %s is more than its shares", valAddr)) 93 } 94 95 // ErrProxyNotFound returns an error when a delegator who's not a proxy tries to unreg 96 func ErrProxyNotFound(delegator string) sdk.EnvelopedErr { 97 return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultCodespace, CodeProxyNotFound, 98 fmt.Sprintf("failed. proxy %s not found", delegator))} 99 } 100 101 // ErrEmptyValidators returns an error when none of the validators in shares adding list is available 102 func ErrEmptyValidators() sdk.Error { 103 return sdkerrors.New(DefaultCodespace, CodeEmptyValidators, 104 "failed. empty validators") 105 } 106 107 // ErrProxyAlreadyExist returns an error when a proxy tries to reg the second time 108 func ErrProxyAlreadyExist(delegator string) sdk.EnvelopedErr { 109 return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultCodespace, CodeProxyAlreadyExist, 110 fmt.Sprintf("failed. delegator %s has already registered as a proxy", delegator))} 111 } 112 113 // ErrDescriptionIsEmpty returns an error when description is empty. 114 func ErrDescriptionIsEmpty() sdk.Error { 115 return sdkerrors.New(DefaultCodespace, CodeDescriptionIsEmpty, "empty description") 116 } 117 118 // ErrGetConsPubKeyBech32 returns an error when get bech32 consensus public key failed. 119 func ErrGetConsPubKeyBech32() sdk.Error { 120 return sdkerrors.New(DefaultCodespace, CodeGetConsPubKeyBech32Failed, "get bech32 consensus public key failed") 121 } 122 123 // ErrUnknownStakingQueryType returns an error when encounter unknown staking query type. 124 func ErrUnknownStakingQueryType() sdk.Error { 125 return sdkerrors.New(DefaultCodespace, CodeUnknownStakingQueryType, "unknown staking query type") 126 } 127 128 // ErrValidatorOwnerExists returns an error when the validator address has been registered 129 func ErrValidatorOwnerExists() sdk.Error { 130 return sdkerrors.New(DefaultCodespace, CodeValidatorOwnerExists, 131 "validator already exist for this operator address, must use new validator operator address") 132 } 133 134 // ErrValidatorPubKeyExists returns an error when the validator consensus pubkey has been registered 135 func ErrValidatorPubKeyExists() sdk.Error { 136 return sdkerrors.New(DefaultCodespace, CodeValidatorPubKeyExists, 137 "validator already exist for this pubkey, must use new validator pubkey") 138 } 139 140 // ErrValidatorPubKeyTypeNotSupported returns an error when the type of pubkey was not supported 141 func ErrValidatorPubKeyTypeNotSupported(keyType string, 142 supportedTypes []string) sdk.Error { 143 return sdkerrors.New(DefaultCodespace, CodeValidatorPubKeyTypeNotSupported, 144 fmt.Sprintf("validator pubkey type %s is not supported, must use %s", keyType, strings.Join(supportedTypes, ","))) 145 } 146 147 // ErrBondedPoolOrNotBondedIsNotExist returns an error when bonded pool or not bonded pool is empty. 148 func ErrBondedPoolOrNotBondedIsNotExist() sdk.Error { 149 return sdkerrors.New(DefaultCodespace, CodeBondedPoolOrNotBondedIsNotExist, "bonded pool or not bonded pool is empty") 150 } 151 152 // ErrDescriptionLength returns an error when the description of validator has a wrong length 153 func ErrDescriptionLength(descriptor string, got, max int) sdk.Error { 154 return sdkerrors.New(DefaultCodespace, CodeInvalidDescriptionLength, 155 fmt.Sprintf("bad description length for %v, got length %v, max is %v", descriptor, got, max)) 156 } 157 158 // ErrCommissionNegative returns an error when the commission is not positive 159 func ErrCommissionNegative() sdk.Error { 160 return sdkerrors.New(DefaultCodespace, CodeCommissionNegative, "commission must be positive") 161 } 162 163 // ErrCommissionHuge returns an error when the commission is greater than 100% 164 func ErrCommissionHuge() sdk.Error { 165 return sdkerrors.New(DefaultCodespace, CodeCommissionHuge, "commission cannot be more than 100%") 166 } 167 168 // ErrCommissionGTMaxRate returns an error when the commission rate is greater than the max rate 169 func ErrCommissionGTMaxRate() sdk.Error { 170 return sdkerrors.New(DefaultCodespace, CodeCommissionGTMaxRate, "commission cannot be more than the max rate") 171 } 172 173 // ErrCommissionUpdateTime returns an error when the commission is remodified within 24 hours 174 func ErrCommissionUpdateTime() sdk.Error { 175 return sdkerrors.New(DefaultCodespace, CodeCommissionUpdateTime, "commission cannot be changed more than once in 24h") 176 } 177 178 // ErrCommissionChangeRateNegative returns an error when the commission change rate is not positive 179 func ErrCommissionChangeRateNegative() sdk.Error { 180 return sdkerrors.New(DefaultCodespace, CodeCommissionChangeRateNegative, "commission change rate must be positive") 181 } 182 183 // ErrCommissionChangeRateGTMaxRate returns an error when the commission change rate is greater than the max rate 184 func ErrCommissionChangeRateGTMaxRate() sdk.Error { 185 return sdkerrors.New(DefaultCodespace, CodeCommissionChangeRateGTMaxRate, "commission change rate cannot be more than the max rate") 186 } 187 188 // ErrCommissionGTMaxChangeRate returns an error when the new rate % points change is greater than the max change rate 189 func ErrCommissionGTMaxChangeRate() sdk.Error { 190 return sdkerrors.New(DefaultCodespace, CodeCommissionGTMaxChangeRate, "commission cannot be changed more than max change rate") 191 } 192 193 // ErrMinSelfDelegationInvalid returns an error when the msd isn't positive 194 func ErrMinSelfDelegationInvalid() sdk.Error { 195 return sdkerrors.New(DefaultCodespace, CodeMinSelfDelegationInvalid, "minimum self delegation must be a positive integer") 196 } 197 198 // ErrNilDelegatorAddr returns an error when the delegator address is nil 199 func ErrNilDelegatorAddr() sdk.Error { 200 return sdkerrors.New(DefaultCodespace, CodeNilDelegatorAddr, "delegator address is nil") 201 } 202 203 // ErrDelegatorEqualToProxyAddr returns an error when the address is not expected 204 func ErrDelegatorEqualToProxyAddr() sdk.Error { 205 return sdkerrors.New(DefaultCodespace, CodeDelegatorEqualToProxyAddr, "delegator address can not equals to proxy address") 206 } 207 208 // ErrBadDenom returns an error when the coin denomination is invalid 209 func ErrBadDenom() sdk.EnvelopedErr { 210 return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultCodespace, CodeBadDenom, "invalid coin denomination")} 211 } 212 213 // ErrBadDelegationAmount returns an error when the amount of delegation isn't positive 214 func ErrBadDelegationAmount() sdk.Error { 215 return sdkerrors.New(DefaultCodespace, CodeBadDelegationAmount, "amount must be more than 0") 216 } 217 218 // ErrNoUnbondingDelegation returns an error when the unbonding delegation doesn't exist 219 func ErrNoUnbondingDelegation() sdk.Error { 220 return sdkerrors.New(DefaultCodespace, CodeNoUnbondingDelegation, "no unbonding delegation found") 221 } 222 223 // ErrAddSharesToDismission returns an error when a zero-msd validator becomes the shares adding target 224 func ErrAddSharesToDismission(valAddr string) sdk.Error { 225 return sdkerrors.New(DefaultCodespace, CodeAddSharesToDismission, 226 fmt.Sprintf("failed. destroyed validator %s isn't allowed to add shares to. please get rid of it from the "+ 227 "shares adding list by adding shares to other validators again or unbond all delegated tokens", valAddr)) 228 } 229 230 // ErrAddSharesDuringProxy returns an error when a delegator who has bound tries to add shares to validators by itself 231 func ErrAddSharesDuringProxy(delegator string, proxy string) sdk.EnvelopedErr { 232 return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultCodespace, CodeAddSharesDuringProxy, 233 fmt.Sprintf("failed. banned to add shares to validators before unbinding proxy relationship between %s and %s", delegator, proxy))} 234 } 235 236 // ErrDoubleProxy returns an error when a delegator trys to bind more than one proxy 237 func ErrDoubleProxy(delegator string) sdk.EnvelopedErr { 238 return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultCodespace, CodeDoubleProxy, 239 fmt.Sprintf("failed. proxy isn't allowed to bind with other proxy %s", delegator))} 240 } 241 242 // ErrExceedValidatorAddrs returns an error when the number of target validators exceeds the max limit 243 func ErrExceedValidatorAddrs(num int) sdk.EnvelopedErr { 244 return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultCodespace, CodeExceedValidatorAddrs, 245 fmt.Sprintf("failed. the number of validator addresses is over the limit %d", num))} 246 } 247 248 // ErrNoDelegationToAddShares returns an error when there's no delegation to support adding shares to validators 249 func ErrNoDelegationToAddShares(delegator string) sdk.EnvelopedErr { 250 return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultCodespace, CodeNoDelegationToAddShares, 251 fmt.Sprintf("failed. there's no delegation of %s", delegator))} 252 } 253 254 // ErrNotInDelegating returns an error when the UndelegationInfo doesn't exist during it's unbonding period 255 func ErrNotInDelegating(addr string) sdk.Error { 256 return sdkerrors.New(DefaultCodespace, CodeNotInDelegating, 257 fmt.Sprintf("failed. the addr %s is not in the status of undelegating", addr)) 258 } 259 260 // ErrInsufficientDelegation returns an error when the delegation left is not enough for unbonding 261 func ErrInsufficientDelegation(quantity, delLeft string) sdk.Error { 262 return sdkerrors.New(DefaultCodespace, CodeInsufficientDelegation, 263 fmt.Sprintf("failed. insufficient delegation. [delegation left]:%s, [quantity to unbond]:%s", delLeft, quantity)) 264 } 265 266 // ErrInsufficientQuantity returns an error when the quantity is less than the min delegation limit 267 func ErrInsufficientQuantity(quantity, minLimit string) sdk.Error { 268 return sdkerrors.New(DefaultCodespace, CodeInsufficientQuantity, 269 fmt.Sprintf("failed. insufficient quantity. [min limit]:%s, [quantity]:%s", minLimit, quantity)) 270 } 271 272 // ErrNoMinSelfDelegation returns an error when the msd has already been unbonded 273 func ErrNoMinSelfDelegation(valAddr string) sdk.Error { 274 return sdkerrors.New(DefaultCodespace, CodeInvalidMinSelfDelegation, 275 fmt.Sprintf("failed. there's no min self delegation on %s", valAddr)) 276 } 277 278 // ErrBadUnDelegationAmount returns an error when the amount of delegation is not positive 279 func ErrBadUnDelegationAmount() sdk.Error { 280 return sdkerrors.New(DefaultCodespace, CodeBadUnDelegationAmount, 281 "failed. undelegated amount must be greater than 0") 282 } 283 284 // ErrInvalidProxyUpdating returns an error when the total delegated tokens on a proxy are going to be negative 285 func ErrInvalidProxyUpdating() sdk.Error { 286 return sdkerrors.New(DefaultCodespace, CodeInvalidProxyUpdating, 287 "failed. the total delegated tokens on the proxy will be negative after this update") 288 } 289 290 // ErrInvalidProxyWithdrawTotal returns an error when proxy withdraws total tokens 291 func ErrInvalidProxyWithdrawTotal(addr string) sdk.Error { 292 return sdkerrors.New(DefaultCodespace, CodeInvalidProxyWithdrawTotal, 293 fmt.Sprintf("failed. proxy %s has to unreg before withdrawing total tokens", addr)) 294 } 295 296 // ErrAlreadyAddedShares returns an error when a delegator tries to bind proxy after adding shares 297 func ErrAlreadyAddedShares(delAddr string) sdk.EnvelopedErr { 298 return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultCodespace, CodeAlreadyAddedShares, 299 fmt.Sprintf("failed. delegator %s isn't allowed to bind proxy while it has added shares. please unbond the delegation first", delAddr))} 300 } 301 302 // ErrNoDelegatorExisted returns an error when the info if a certain delegator doesn't exist 303 func ErrNoDelegatorExisted(delAddr string) sdk.Error { 304 return sdkerrors.New(DefaultCodespace, CodeNoDelegatorExisted, 305 fmt.Sprintf("failed. delegator %s doesn't exist", delAddr)) 306 } 307 308 // ErrTargetValsDuplicate returns an error when the target validators in voting list are duplicate 309 func ErrTargetValsDuplicate() sdk.Error { 310 return sdkerrors.New(DefaultCodespace, CodeTargetValsDuplicate, 311 "failed. duplicate target validators") 312 } 313 314 // ErrAlreadyBound returns an error when a delegator keeps binding a proxy before proxy register 315 func ErrAlreadyBound(delAddr string) sdk.EnvelopedErr { 316 return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultCodespace, CodeAlreadyBound, 317 fmt.Sprintf("failed. %s has already bound a proxy. it's necessary to unbind before proxy register", 318 delAddr))} 319 }