Skip to main content

vesting_contract/
errors.rs

1use crate::storage::AccountStorageKey;
2use cosmwasm_std::{Addr, Coin, OverflowError, StdError, Uint128};
3use mixnet_contract_common::MixId;
4use thiserror::Error;
5
6#[derive(Error, Debug, PartialEq)]
7pub enum ContractError {
8    #[error("VESTING ({}): {0}", line!())]
9    Std(#[from] StdError),
10
11    #[error("VESTING: {0}")]
12    OverflowError(#[from] OverflowError),
13
14    #[error("VESTING ({}): Account does not exist - {0}", line!())]
15    NoAccountForAddress(String),
16
17    #[error("VESTING ({}): Only admin can perform this action, {0} is not admin", line!())]
18    NotAdmin(String),
19
20    #[error("VESTING ({}): Balance not found for existing account ({0}), this is a bug", line!())]
21    NoBalanceForAddress(String),
22
23    #[error("VESTING ({}): Insufficient balance for address {0} -> {1}", line!())]
24    InsufficientBalance(String, u128),
25
26    #[error("VESTING ({}): Insufficient spendable balance for address {0} -> {1}", line!())]
27    InsufficientSpendable(String, u128),
28
29    #[error(
30        "VESTING ({}):Only delegation owner can perform delegation actions, {0} is not the delegation owner"
31    , line!())]
32    NotDelegate(String),
33
34    #[error("VESTING ({}): Total vesting amount is inprobably low -> {0}, this is likely an error", line!())]
35    ImprobableVestingAmount(u128),
36
37    #[error("VESTING ({}): Address {0} has already bonded a node", line!())]
38    AlreadyBonded(String),
39
40    #[error("VESTING ({}): Received empty funds vector", line!())]
41    EmptyFunds,
42
43    #[error("VESTING ({}): Received wrong denom: {0}, expected {1}", line!())]
44    WrongDenom(String, String),
45
46    #[error("VESTING ({}): Received multiple denoms, expected 1", line!())]
47    MultipleDenoms,
48
49    #[error("VESTING ({}): No delegations found for account {0}, mix_identity {1}", line!())]
50    NoSuchDelegation(Addr, MixId),
51
52    #[error("VESTING ({}): Only mixnet contract can perform this operation, got {0}", line!())]
53    NotMixnetContract(Addr),
54
55    #[error("VESTING ({}): Calculation underflowed", line!())]
56    Underflow,
57
58    #[error("VESTING ({}): No bond found for account {0}", line!())]
59    NoBondFound(String),
60
61    #[error("VESTING: Attempted to reduce mixnode bond pledge below zero! The current pledge is {current} and we attempted to reduce it by {decrease_by}.")]
62    InvalidBondPledgeReduction { current: Coin, decrease_by: Coin },
63
64    #[error("VESTING ({}): Action can only be executed by account owner -> {0}", line!())]
65    NotOwner(String),
66
67    #[error("VESTING ({}): Invalid address: {0}", line!())]
68    InvalidAddress(String),
69
70    #[error("VESTING ({}): Account already exists: {0}", line!())]
71    AccountAlreadyExists(String),
72
73    #[error("VESTING ({}): Staking account already exists: {0}", line!())]
74    StakingAccountAlreadyExists(String),
75
76    #[error("VESTING ({}): Too few coins sent for vesting account creation, sent {sent}, need at least {need}", line!())]
77    MinVestingFunds { sent: u128, need: u128 },
78
79    #[error("VESTING ({}): Maximum amount of locked coins has already been pledged: {current}, cap is {cap}", line!())]
80    LockedPledgeCapReached { current: Uint128, cap: Uint128 },
81
82    #[error("VESTING: ({}: Account owned by {owner} has unpopulated vesting periods!", line!())]
83    UnpopulatedVestingPeriods { owner: Addr },
84
85    #[error("VESTING: Vesting account associated with {0} already exists, only addresses with not existing vesting accounts can be added as staking addresses")]
86    StakingAccountExists(String),
87
88    #[error("VESTING: {address} is not permitted to perform staking on behalf of {for_account}")]
89    InvalidStakingAccount { address: Addr, for_account: Addr },
90
91    #[error("VESTING: {address} ({acc_id} has already performed {num} individual delegations towards {mix_id}. No further delegations are allowed. Please consider consolidating those delegations instead. The current cap is {cap}.")]
92    TooManyDelegations {
93        address: Addr,
94        acc_id: AccountStorageKey,
95        mix_id: MixId,
96        num: u32,
97        cap: u32,
98    },
99
100    #[error("VESTING: Failed to parse {value} into a valid SemVer version: {error_message}")]
101    SemVerFailure {
102        value: String,
103        error_message: String,
104    },
105
106    #[error("VESTING: {message}")]
107    Other { message: String },
108}