code.vegaprotocol.io/vega@v0.79.0/core/types/delegation.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package types
    17  
    18  import (
    19  	"fmt"
    20  
    21  	"code.vegaprotocol.io/vega/libs/num"
    22  	"code.vegaprotocol.io/vega/libs/stringer"
    23  	"code.vegaprotocol.io/vega/protos/vega"
    24  	commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1"
    25  )
    26  
    27  type Delegation struct {
    28  	Party    string
    29  	NodeID   string
    30  	Amount   *num.Uint
    31  	EpochSeq string
    32  }
    33  
    34  func DelegationFromProto(d *vega.Delegation) *Delegation {
    35  	amt, _ := num.UintFromString(d.Amount, 10)
    36  	return &Delegation{
    37  		Party:    d.Party,
    38  		NodeID:   d.NodeId,
    39  		Amount:   amt,
    40  		EpochSeq: d.EpochSeq,
    41  	}
    42  }
    43  
    44  func (d Delegation) IntoProto() *vega.Delegation {
    45  	return &vega.Delegation{
    46  		Party:    d.Party,
    47  		NodeId:   d.NodeID,
    48  		Amount:   num.UintToString(d.Amount),
    49  		EpochSeq: d.EpochSeq,
    50  	}
    51  }
    52  
    53  type Delegate struct {
    54  	NodeID string
    55  	Amount *num.Uint
    56  }
    57  
    58  func (d Delegate) IntoProto() *commandspb.DelegateSubmission {
    59  	return &commandspb.DelegateSubmission{
    60  		NodeId: d.NodeID,
    61  		Amount: num.UintToString(d.Amount),
    62  	}
    63  }
    64  
    65  func (d Delegate) String() string {
    66  	return fmt.Sprintf(
    67  		"nodeID(%s) amount(%s)",
    68  		d.NodeID,
    69  		stringer.PtrToString(d.Amount),
    70  	)
    71  }
    72  
    73  type Undelegate struct {
    74  	NodeID string
    75  	Amount *num.Uint
    76  	Method string
    77  }
    78  
    79  func (u Undelegate) IntoProto() *commandspb.UndelegateSubmission {
    80  	return &commandspb.UndelegateSubmission{
    81  		NodeId: u.NodeID,
    82  		Amount: num.UintToString(u.Amount),
    83  		Method: commandspb.UndelegateSubmission_Method(commandspb.UndelegateSubmission_Method_value[u.Method]),
    84  	}
    85  }
    86  
    87  func (u Undelegate) String() string {
    88  	return fmt.Sprintf(
    89  		"nodeID(%s) amount(%s) method(%s)",
    90  		u.NodeID,
    91  		stringer.PtrToString(u.Amount),
    92  		u.Method,
    93  	)
    94  }
    95  
    96  // ValidatorData is delegation data for validator.
    97  type ValidatorData struct {
    98  	NodeID            string
    99  	PubKey            string
   100  	StakeByDelegators *num.Uint
   101  	SelfStake         *num.Uint
   102  	Delegators        map[string]*num.Uint
   103  	TmPubKey          string
   104  }
   105  
   106  // ValidatorVotingPower is the scaled voting power for the given tm key.
   107  type ValidatorVotingPower struct {
   108  	TmPubKey    string
   109  	VotingPower int64
   110  }
   111  
   112  type StakeScoreParams struct {
   113  	MinVal                 num.Decimal
   114  	CompLevel              num.Decimal
   115  	OptimalStakeMultiplier num.Decimal
   116  }