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

     1  package types
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     8  )
     9  
    10  // FarmPool is the pool where an address can lock specified token to yield other tokens
    11  type FarmPool struct {
    12  	Owner         sdk.AccAddress `json:"owner"`
    13  	Name          string         `json:"name"`
    14  	MinLockAmount sdk.SysCoin    `json:"min_lock_amount"`
    15  	DepositAmount sdk.SysCoin    `json:"deposit_amount"`
    16  	// sum of LockInfo.Amount
    17  	TotalValueLocked        sdk.SysCoin       `json:"total_value_locked"`
    18  	YieldedTokenInfos       YieldedTokenInfos `json:"yielded_token_infos"`
    19  	TotalAccumulatedRewards sdk.SysCoins      `json:"total_accumulated_rewards"`
    20  }
    21  
    22  // NewFarmPool creates a new instance of FarmPool
    23  func NewFarmPool(
    24  	owner sdk.AccAddress, name string, minLockAmount sdk.SysCoin, depositAmount, totalValueLocked sdk.SysCoin,
    25  	yieldedTokenInfos YieldedTokenInfos, accumulatedRewards sdk.SysCoins,
    26  ) FarmPool {
    27  	return FarmPool{
    28  		Owner:                   owner,
    29  		Name:                    name,
    30  		MinLockAmount:           minLockAmount,
    31  		DepositAmount:           depositAmount,
    32  		TotalValueLocked:        totalValueLocked,
    33  		YieldedTokenInfos:       yieldedTokenInfos,
    34  		TotalAccumulatedRewards: accumulatedRewards,
    35  	}
    36  }
    37  
    38  func (fp FarmPool) Finished() bool {
    39  	for _, yieldedTokenInfo := range fp.YieldedTokenInfos {
    40  		if yieldedTokenInfo.RemainingAmount.IsPositive() {
    41  			return false
    42  		}
    43  	}
    44  	return fp.TotalValueLocked.IsZero()
    45  }
    46  
    47  // String returns a human readable string representation of FarmPool
    48  func (fp FarmPool) String() string {
    49  	return fmt.Sprintf(`FarmPool:
    50    Pool Name:  					    %s	
    51    Owner:							%s
    52    Min Lock Amount:      			    %s
    53    Deposit Amount:                   %s
    54    Total Value Locked:               %s
    55    Yielded Token Infos:			    %s
    56    Total Accumulated Rewards:        %s`,
    57  		fp.Name, fp.Owner, fp.MinLockAmount.String(), fp.DepositAmount, fp.TotalValueLocked, fp.YieldedTokenInfos, fp.TotalAccumulatedRewards)
    58  }
    59  
    60  // FarmPools is a collection of FarmPool
    61  type FarmPools []FarmPool
    62  
    63  // String returns a human readable string representation of FarmPools
    64  func (fps FarmPools) String() (out string) {
    65  	for _, fp := range fps {
    66  		out += fp.String() + "\n"
    67  	}
    68  	return strings.TrimSpace(out)
    69  }
    70  
    71  // PoolNum is a wrapped structure of uint to display by cli query
    72  type PoolNum struct {
    73  	Number uint `json:"number"`
    74  }
    75  
    76  // NewPoolNum creates a new instance of PoolNum
    77  func NewPoolNum(num uint) PoolNum {
    78  	return PoolNum{
    79  		Number: num,
    80  	}
    81  }
    82  
    83  // String returns a human readable string representation of PoolNum
    84  func (pn PoolNum) String() string {
    85  	return fmt.Sprintf(`Number Of Pools:
    86    Number: 		%d`, pn.Number)
    87  }