github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/farm/types/errors.go (about)

     1  package types
     2  
     3  import (
     4  	"fmt"
     5  
     6  	sdkerrors "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/errors"
     7  
     8  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     9  )
    10  
    11  type CodeType = uint32
    12  
    13  const (
    14  	DefaultCodespace string = ModuleName
    15  
    16  	CodeInvalidInput                       uint32 = 66000
    17  	CodePoolAlreadyExist                   uint32 = 66001
    18  	CodeNoFarmPoolFound                    uint32 = 66002
    19  	CodePoolNotInWhiteList                 uint32 = 66003
    20  	CodeInvalidLockInfo                    uint32 = 66004
    21  	CodeTokenNotExist                      uint32 = 66005
    22  	CodePoolNotFinished                    uint32 = 66006
    23  	CodeUnexpectedProposalType             uint32 = 66007
    24  	CodeInvalidAddress                     uint32 = 66008
    25  	CodeRemainingAmountNotZero             uint32 = 66009
    26  	CodeInvalidPoolOwner                   uint32 = 66010
    27  	CodeInvalidDenom                       uint32 = 66011
    28  	CodeSendCoinsFromAccountToModuleFailed uint32 = 66012
    29  	CodeUnknownFarmMsgType                 uint32 = 66013
    30  	CodeUnknownFarmQueryType               uint32 = 66014
    31  	CodeInvalidInputAmount                 uint32 = 66015
    32  	CodeInsufficientAmount                 uint32 = 66016
    33  	CodeInvalidStartHeight                 uint32 = 66017
    34  	CodePoolNameLength                     uint32 = 66018
    35  	CodeLockAmountBelowMinimum             uint32 = 66019
    36  	CodeSendCoinsFromModuleToAccountFailed uint32 = 66020
    37  	CodeSwapTokenPairNotExist              uint32 = 66021
    38  )
    39  
    40  // ErrInvalidInput returns an error when an input parameter is invalid
    41  func ErrInvalidInput(msg string) sdk.EnvelopedErr {
    42  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodeInvalidInput, fmt.Sprintf("failed. invalid input: %s", msg))}
    43  }
    44  
    45  // ErrPoolAlreadyExist returns an error when a pool exist
    46  func ErrPoolAlreadyExist(poolName string) sdk.EnvelopedErr {
    47  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodePoolAlreadyExist, fmt.Sprintf("failed. farm pool %s already exists", poolName))}
    48  }
    49  
    50  // ErrNoFarmPoolFound returns an error when a farm pool doesn't exist
    51  func ErrNoFarmPoolFound(poolName string) sdk.EnvelopedErr {
    52  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodeNoFarmPoolFound, fmt.Sprintf("failed. farm pool %s does not exist", poolName))}
    53  }
    54  
    55  // ErrPoolNameNotExistedInWhiteList returns an error when the pool name is not existed in the white list
    56  func ErrPoolNameNotExistedInWhiteList(poolName string) sdk.EnvelopedErr {
    57  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodePoolNotInWhiteList,
    58  		fmt.Sprintf("failed. the pool name %s not exists in the white list", poolName))}
    59  }
    60  
    61  // ErrNoLockInfoFound returns an error when an address doesn't have any lock infos
    62  func ErrNoLockInfoFound(addr string, pool string) sdk.EnvelopedErr {
    63  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodeInvalidLockInfo, fmt.Sprintf("failed. %s hasn't locked in pool %s", addr, pool))}
    64  }
    65  
    66  // ErrTokenNotExist returns an error when a token not exists
    67  func ErrTokenNotExist(tokenName string) sdk.EnvelopedErr {
    68  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodeTokenNotExist, fmt.Sprintf("failed. token %s does not exist", tokenName))}
    69  }
    70  
    71  // ErrPoolNotFinished returns an error when the pool is not finished and can not be destroyed
    72  func ErrPoolNotFinished(poolName string) sdk.EnvelopedErr {
    73  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodePoolNotFinished,
    74  		fmt.Sprintf("failed. the pool %s that is with unclaimed rewards or locked coins can not be destroyed", poolName))}
    75  }
    76  
    77  // ErrUnexpectedProposalType returns an error when the proposal type is not supported in farm module
    78  func ErrUnexpectedProposalType(proposalType string) sdk.EnvelopedErr {
    79  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodeUnexpectedProposalType,
    80  		fmt.Sprintf("failed. the proposal type %s is not supported in farm module", proposalType))}
    81  }
    82  
    83  // ErrNilAddress returns an error when an empty address appears
    84  func ErrNilAddress() sdk.EnvelopedErr {
    85  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodeInvalidAddress, fmt.Sprintf("failed. address is required"))}
    86  }
    87  
    88  // ErrRemainingAmountNotZero returns an error when the remaining amount in yieldedTokenInfo is not zero
    89  func ErrRemainingAmountNotZero(amount string) sdk.EnvelopedErr {
    90  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodeRemainingAmountNotZero,
    91  		fmt.Sprintf("failed. the remaining amount is %s, so it's not enable to provide token repeatedly util amount become zero", amount))}
    92  }
    93  
    94  // ErrInvalidPoolOwner returns an error when an input address is not the owner of pool
    95  func ErrInvalidPoolOwner(address string, poolName string) sdk.EnvelopedErr {
    96  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodeInvalidPoolOwner, fmt.Sprintf("failed. %s isn't the owner of pool %s", address, poolName))}
    97  }
    98  
    99  // ErrInvalidDenom returns an error when it provides an unmatched token name
   100  func ErrInvalidDenom(symbolLocked string, token string) sdk.EnvelopedErr {
   101  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodeInvalidDenom,
   102  		fmt.Sprintf("failed. the coin name should be %s, not %s", symbolLocked, token))}
   103  }
   104  
   105  func ErrSendCoinsFromAccountToModuleFailed(content string) sdk.EnvelopedErr {
   106  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodeSendCoinsFromAccountToModuleFailed, fmt.Sprintf("failed. send coins from account to module failed %s", content))}
   107  }
   108  
   109  func ErrUnknownFarmMsgType(content string) sdk.EnvelopedErr {
   110  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodeUnknownFarmMsgType, fmt.Sprintf("failed. unknown farm msg type %s", content))}
   111  }
   112  
   113  func ErrUnknownFarmQueryType(content string) sdk.EnvelopedErr {
   114  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodeUnknownFarmQueryType, fmt.Sprintf("failed. unknown farm query type %s", content))}
   115  }
   116  
   117  // ErrInvalidInputAmount returns an error when an input amount is invaild
   118  func ErrInvalidInputAmount(amount string) sdk.EnvelopedErr {
   119  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodeInvalidInputAmount, fmt.Sprintf("failed. the input amount %s is invalid", amount))}
   120  }
   121  
   122  // ErrInsufficientAmount returns an error when there is no enough tokens
   123  func ErrInsufficientAmount(amount string, inputAmount string) sdk.EnvelopedErr {
   124  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodeInsufficientAmount,
   125  		fmt.Sprintf("failed. the actual amount %s is less than %s", amount, inputAmount))}
   126  }
   127  
   128  // ErrInvalidStartHeight returns an error when the start_height_to_yield parameter is invalid
   129  func ErrInvalidStartHeight() sdk.EnvelopedErr {
   130  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodeInvalidStartHeight, "failed. the start height to yield is less than current height")}
   131  }
   132  
   133  // ErrPoolNameLength returns an error when length of pool name is invalid
   134  func ErrPoolNameLength(poolName string, got, max int) sdk.EnvelopedErr {
   135  	msg := fmt.Sprintf("invalid pool name length for %v, got length %v, max is %v", poolName, got, max)
   136  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodePoolNameLength, msg)}
   137  }
   138  
   139  // ErrLockAmountBelowMinimum returns an error when lock amount belows minimum
   140  func ErrLockAmountBelowMinimum(minLockAmount, amount sdk.Dec) sdk.EnvelopedErr {
   141  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodeLockAmountBelowMinimum, fmt.Sprintf("lock amount %s must be greater than the pool's min lock amount %s", amount.String(), minLockAmount.String()))}
   142  }
   143  
   144  func ErrSendCoinsFromModuleToAccountFailed(content string) sdk.EnvelopedErr {
   145  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodeSendCoinsFromModuleToAccountFailed, fmt.Sprintf("failed. send coins from module to account failed %s", content))}
   146  }
   147  
   148  // ErrSwapTokenPairNotExist returns an error when a swap token pair not exists
   149  func ErrSwapTokenPairNotExist(tokenName string) sdk.EnvelopedErr {
   150  	return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultParamspace, CodeSwapTokenPairNotExist, fmt.Sprintf("failed. swap token pair %s does not exist", tokenName))}
   151  }