utils

package
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2023 License: GPL-3.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ValidatorStatusUnInitial = uint8(0)
	ValidatorStatusDeposited = uint8(1)

	// lightnode + super node related
	ValidatorStatusWithdrawMatch   = uint8(2)
	ValidatorStatusStaked          = uint8(3)
	ValidatorStatusWithdrawUnmatch = uint8(4)

	// lightnode related
	ValidatorStatusOffBoard            = uint8(5)
	ValidatorStatusOffBoardCanWithdraw = uint8(6)
	ValidatorStatusOffBoardWithdrawed  = uint8(7)

	// status on beacon chain
	ValidatorStatusWaiting      = uint8(8)
	ValidatorStatusActive       = uint8(9)
	ValidatorStatusExited       = uint8(10)
	ValidatorStatusWithdrawable = uint8(11)
	ValidatorStatusWithdrawDone = uint8(12)

	// after distribute reward
	ValidatorStatusDistributed = uint8(13) // distribute full withdrawal

	// after slash
	ValidatorStatusActiveSlash       = uint8(51)
	ValidatorStatusExitedSlash       = uint8(52)
	ValidatorStatusWithdrawableSlash = uint8(53)
	ValidatorStatusWithdrawDoneSlash = uint8(54)

	ValidatorStatusDistributedSlash = uint8(55) // distribute full withdrawal
)

1 deposited { 2 withdrawl match 3 staked 4 withdrawl unmatch } { 5 offboard 6 OffBoard can withdraw 7 OffBoard withdrawed } 8 waiting 9 active 10 exited 11 withdrawable 12 withdrawdone { 13 distributed } 51 active+slash 52 exit+slash 53 withdrawable+slash 54 withdrawdone+slash 55 distributed+slash

View Source
const (
	NodeTypeCommon = uint8(1)
	NodeTypeTrust  = uint8(2)
	NodeTypeLight  = uint8(3)
	NodeTypeSuper  = uint8(4)
)

1 common node 2 trust node 3 light node 4 super node

View Source
const (
	ValidatorEverSlashedFalse = uint8(0)
	ValidatorEverSlashedTrue  = uint8(1)
)
View Source
const (
	FeePool          = uint8(1)
	SuperNodeFeePool = uint8(2)
)
View Source
const (
	MetaTypeEth1BlockSyncer            = uint8(1) // dealed block height
	MetaTypeEth2ValidatorInfoSyncer    = uint8(2) // dealed epoch
	MetaTypeEth2ValidatorBalanceSyncer = uint8(3) // dealed epoch
	MetaTypeV1ValidatorSyncer          = uint8(4) // dealed block height
	MetaTypeEth2BlockSyncer            = uint8(5) // dealed epoch
	MetaTypeEth2NodeBalanceCollector   = uint8(6) // dealed epoch
)
View Source
const (
	SlashTypeFeeRecipient  = uint8(1)
	SlashTypeProposerSlash = uint8(2)
	SlashTypeAttesterSlash = uint8(3)

	SlashTypeNotExitSlash = uint8(7)

	// not show in front end
	SlashTypeSyncMiss     = uint8(4)
	SlashTypeAttesterMiss = uint8(5)
	SlashTypeProposerMiss = uint8(6)
)
View Source
const (
	TheMergeEpoch       = uint64(148000)
	TheMergeSlot        = uint64(4736000)
	TheMergeBlockNumber = uint64(15572967)

	RewardV1EndEpoch    = uint64(195975) //todo mainnet
	RewardEpochInterval = uint64(75)
	SlashStartEpoch     = uint64(180000)
	//dev
	DevTheMergeEpoch       = uint64(4400)
	DevTheMergeBlockNumber = uint64(133654)
	DevRewardV1EndEpoch    = uint64(75)

	StandardEffectiveBalance            = uint64(32e9) //gwei
	StandardSuperNodeFakeDepositBalance = uint64(1e9)  //gwei
	OfficialSlashAmount                 = uint64(1e9)  //gwei
	MaxPartialWithdrawalAmount          = uint64(8e9)  //gwei

	// node deposit amount(gwei)
	NodeDepositAmount0  = uint64(0)    //gwei super
	NodeDepositAmount4  = uint64(4e9)  //gwei solo 4
	NodeDepositAmount8  = uint64(8e9)  //gwei solo 8
	NodeDepositAmount12 = uint64(12e9) //gwei solo 12
)
View Source
const (
	NodeClaimTypeNone         = uint8(0)
	NodeClaimTypeClaimReward  = uint8(1)
	NodeClaimTypeClaimDeposit = uint8(2)
	NodeClaimTypeClaimTotal   = uint8(3)
)
enum ClaimType {
    None,
    CLAIMREWARD,
    CLAIMDEPOSIT,
    CLAIMTOTAL
}
View Source
const (
	StakerWithdrawalClaimableTimestamp = uint64(1)
	MinValidatorWithdrawabilityDelay   = uint64(256 + 5)
	MaxDistributeWaitSeconds           = uint64(8 * 60 * 60)
	MaxDistributeWaitEpoch             = uint64(75)

	EjectorUptimeInterval = uint64(10 * 60)
)
View Source
const (
	MaxPageSize     = 50
	DefaultPageSize = 10
)
View Source
const (
	CodeParamParseErr            = "80001"
	CodeSymbolErr                = "80002"
	CodeInternalErr              = "80003"
	CodeParamErr                 = "80004"
	CodePriceEmptyErr            = "80005"
	CodeAddressNotExist          = "80005"
	CodeValidatorNotExist        = "80006"
	CodeStakerUnstakingPlanExist = "80007"
)
View Source
const (
	RetryLimit    = 200
	RetryInterval = 6 * time.Second
)
View Source
const (
	SymbolDot  = "DOT"
	SymbolKsm  = "KSM"
	SymbolAtom = "ATOM"
	SymbolEth  = "ETH"
	SymbolFis  = "FIS"
)
View Source
const DropRate10 = "10000000000000000000"
View Source
const DropRate4 = "4000000000000000000"
View Source
const DropRate7 = "7000000000000000000"

Variables

View Source
var (
	// dev use
	OldRethSupply, _ = new(big.Int).SetString("25642334000000000000", 10)

	GweiDeci = decimal.NewFromInt(1e9)

	PlatformFeeV1Deci = decimal.NewFromFloat(0.1)
	NodeFeeV1Deci     = decimal.NewFromFloat(0.1)

	Percent5Deci  = decimal.NewFromFloat(0.05)
	Percent90Deci = decimal.NewFromFloat(0.9)
)
View Source
var OneWeekSeconds = 7 * 24 * 60 * 60
View Source
var ShutdownRequestChannel = make(chan struct{})

shutdownRequestChannel is used to initiate shutdown from one of the subsystems using the same code paths as when an interrupt signal is received.

Functions

func AddOneDay

func AddOneDay(day string) (string, error)

func AddPrefix

func AddPrefix(value string) string

Add a prefix to a hex string if not present

func AppendToFile

func AppendToFile(filePath, content string) error

func BatchGetOperatorsOnChain added in v0.4.2

func BatchGetOperatorsOnChain(multicaller *multicall.Caller, ssvNetworkViewsContractAddress common.Address, ids []uint64) (map[uint64]*OperatorInfoOnChain, error)

func Bytes1

func Bytes1(val uint64) []byte

Bytes1 returns the first byte of the little-endian representation of the supplied value.

func Bytes16

func Bytes16(x uint64) []byte

Bytes16 returns the first sixteen bytes of the little-endian representation of the supplied value.

func Bytes2

func Bytes2(val uint64) []byte

Bytes2 returns the first two bytes of the little-endian representation of the supplied value.

func Bytes32

func Bytes32(x uint64) []byte

Bytes32 returns the first thirty-two bytes of the little-endian representation of the supplied value.

func Bytes4

func Bytes4(x uint64) []byte

Bytes4 returns the first four bytes of the little-endian representation of the supplied value.

func Bytes64

func Bytes64(x uint64) []byte

Bytes64 returns the first thirty-two bytes of the little-endian representation of the supplied value.

func Bytes8

func Bytes8(x uint64) []byte

Bytes8 returns the first eight bytes of the little-endian representation of the supplied value.

func ContractStorageKey

func ContractStorageKey(name string) [32]byte

keccak256(abi.encodePacked("contract.address", _contractName))

func DistributeFeeProposalNodeKey

func DistributeFeeProposalNodeKey(sender common.Address, _dealedHeight, _userAmount, _nodeAmount, _platformAmount *big.Int) [32]byte

func DistributeSuperNodeFeeProposalNodeKey

func DistributeSuperNodeFeeProposalNodeKey(sender common.Address, _dealedHeight, _userAmount, _nodeAmount, _platformAmount *big.Int) [32]byte

func DistributeWithdrawalsProposalNodeKey

func DistributeWithdrawalsProposalNodeKey(sender common.Address, _dealedHeight, _userAmount, _nodeAmount, _platformAmount, _maxClaimableWithdrawIndex *big.Int) [32]byte

func EndSlotOfEpoch

func EndSlotOfEpoch(config beacon.Eth2Config, epoch uint64) uint64

func EpochAtTimestamp

func EpochAtTimestamp(config beacon.Eth2Config, time uint64) uint64

Get an eth2 epoch number by time

func Err

func Err(c *gin.Context, status, msg string)

func EventTopics added in v0.2.0

func EventTopics(a abi.ABI, names ...string) ([]common.Hash, error)

func FloatToStr

func FloatToStr(f float64) string

func FromHexString

func FromHexString(data string) ([]byte, error)

FromHexString returns a byte array given a hex string

func GetContractAddress

func GetContractAddress(storage *storage.Storage, name string) (common.Address, error)

func GetDropRate

func GetDropRate(startDayStr, nowDayStr string) (string, error)

func GetDropRateFromTimestamp

func GetDropRateFromTimestamp(startDay, stamp string) (string, error)

func GetGaspriceFromBeacon

func GetGaspriceFromBeacon() (base uint64, err error)

func GetGaspriceFromEthgasstation

func GetGaspriceFromEthgasstation() (base, priority uint64, err error)

func GetNewDayUtc8Seconds

func GetNewDayUtc8Seconds() int64

func GetNodeManagedEth

func GetNodeManagedEth(nodeDeposit, balance uint64, status uint8) uint64

func GetNowUTC8Date

func GetNowUTC8Date() string

func GetPriceFromCoinGecko

func GetPriceFromCoinGecko(url string) (map[string]float64, error)

func GetPriceFromCoinMarket

func GetPriceFromCoinMarket(url string) (map[string]float64, error)

func GetSwapHash

func GetSwapHash(swapType, sender string, created int64) string

func GetYesterdayUTC8Date

func GetYesterdayUTC8Date() string

func IsImageExt

func IsImageExt(extName string) bool

func NodeSubmissionKey

func NodeSubmissionKey(sender common.Address, _block *big.Int, _totalEth *big.Int, _stakingEth *big.Int, _rethSupply *big.Int) [32]byte

func Ok

func Ok(c *gin.Context, msg string, data interface{})

func PriceSymbolValid

func PriceSymbolValid(symbol string) bool

func ReadLastLine

func ReadLastLine(filePath string) (string, error)

func RemovePrefix

func RemovePrefix(value string) string

Remove a prefix from a hex string if present

func ReserveEthForWithdrawProposalId

func ReserveEthForWithdrawProposalId(cycle *big.Int) [32]byte

func SafeGo

func SafeGo(x func())

func SafeGoWithRestart

func SafeGoWithRestart(x func())

func ShutdownListener

func ShutdownListener() context.Context

shutdowntListener listens for OS Signals such as SIGINT (Ctrl+C) and shutdown requests from shutdownRequestChannel. It returns a context that is canceled when either signal is received.

func Stack

func Stack(skip int) []byte

func StafiDistributorProposalNodeKey

func StafiDistributorProposalNodeKey(sender common.Address, proposalId [32]byte) [32]byte

func StafiWithdrawProposalNodeKey

func StafiWithdrawProposalNodeKey(sender common.Address, proposalId [32]byte) [32]byte

func StartSlotOfEpoch

func StartSlotOfEpoch(config beacon.Eth2Config, epoch uint64) uint64

Get an eth2 first slot number by epoch

func StartTimestampOfEpoch

func StartTimestampOfEpoch(config beacon.Eth2Config, epoch uint64) uint64

func StrToFloat

func StrToFloat(str string) float64

func StrToInt64

func StrToInt64(str string) (int64, error)

func SubOneDay

func SubOneDay(day string) (string, error)

func SymbolValid

func SymbolValid(symbol string) bool

func TimestampOfSlot

func TimestampOfSlot(config beacon.Eth2Config, slot uint64) uint64

func ToBytes16

func ToBytes16(val []byte) [16]byte

ToBytes16 returns a 16-byte array with the supplied value placed in the low-order indices.

func ToBytes32

func ToBytes32(val []byte) [32]byte

ToBytes32 returns a 32-byte array with the supplied value placed in the low-order indices.

func ToBytes48

func ToBytes48(val []byte) [48]byte

ToBytes48 returns a 48-byte array with the supplied value placed in the low-order indices.

func ToBytes64

func ToBytes64(val []byte) [64]byte

ToBytes64 returns a 64-byte array with the supplied value placed in the low-order indices.

func ToBytes8

func ToBytes8(val []byte) [8]byte

ToBytes8 returns an 8-byte array with the supplied value placed in the low-order indices.

func ToBytes96

func ToBytes96(val []byte) [96]byte

ToBytes96 returns a 96-byte array with the supplied value placed in the low-order indices.

func ToUpperList

func ToUpperList(list []string) []string

func UnpackEvent added in v0.2.0

func UnpackEvent(a abi.ABI, v interface{}, name string, data []byte, topics []common.Hash) error

func Uuid

func Uuid() string

func VerifyProof

func VerifyProof(leafNode NodeHash, proof []NodeHash, root NodeHash) bool

func WaitTxOkCommon

func WaitTxOkCommon(client *ethclient.Client, txHash common.Hash) (blockNumber uint64, err error)

func XOR

func XOR(data []byte) []byte

XOR returns an XORd copy of the bytes.

Types

type CoinGeckeoPrice

type CoinGeckeoPrice struct {
	Usd float64 `json:"usd"`
}

type MerkleTree

type MerkleTree struct {
	// contains filtered or unexported fields
}

leafNodes on layers[0], rootNode on layers[len(layers)-1]

func NewMerkleTree

func NewMerkleTree(nodeHashList NodeHashList) *MerkleTree

func (*MerkleTree) GetLayers

func (m *MerkleTree) GetLayers() [][]*Node

func (*MerkleTree) GetProof

func (m *MerkleTree) GetProof(leafNodeHash NodeHash) ([]NodeHash, error)

func (*MerkleTree) GetRootHash

func (m *MerkleTree) GetRootHash() (hash NodeHash, err error)

type Node

type Node struct {
	Hash   NodeHash
	Parent *Node
	// contains filtered or unexported fields
}

func (*Node) String

func (n *Node) String() string

type NodeHash

type NodeHash []byte

func ConbinedHash

func ConbinedHash(b0, b1 NodeHash) NodeHash

func GetNodeHash

func GetNodeHash(index *big.Int, account common.Address, rewardAmount, depositAmount *big.Int) NodeHash

func NodeHashFromHexString

func NodeHashFromHexString(hexStr string) (NodeHash, error)

func (*NodeHash) String

func (nodeHash *NodeHash) String() string

type NodeHashList

type NodeHashList []NodeHash

func (NodeHashList) Len

func (nodeHashList NodeHashList) Len() int

func (NodeHashList) Less

func (nodeHashList NodeHashList) Less(i, j int) bool

func (NodeHashList) Swap

func (nodeHashList NodeHashList) Swap(i, j int)

type OperatorFromApi added in v0.4.2

type OperatorFromApi struct {
	ID             int    `json:"id"`
	IDStr          string `json:"id_str"`
	DeclaredFee    string `json:"declared_fee"`
	PreviousFee    string `json:"previous_fee"`
	Fee            string `json:"fee"`
	PublicKey      string `json:"public_key"`
	OwnerAddress   string `json:"owner_address"`
	Location       string `json:"location"`
	SetupProvider  string `json:"setup_provider"`
	Eth1NodeClient string `json:"eth1_node_client"`
	Eth2NodeClient string `json:"eth2_node_client"`
	Description    string `json:"description"`
	WebsiteURL     string `json:"website_url"`
	TwitterURL     string `json:"twitter_url"`
	LinkedinURL    string `json:"linkedin_url"`
	Type           string `json:"type"`
	Name           string `json:"name"`
	Performance    struct {
		Two4H   float64 `json:"24h"`
		Three0D float64 `json:"30d"`
	} `json:"performance"`
	IsValid          bool   `json:"is_valid"`
	IsDeleted        bool   `json:"is_deleted"`
	IsActive         int    `json:"is_active"`
	Status           string `json:"status"`
	ValidatorsCount  int    `json:"validators_count"`
	Version          string `json:"version"`
	Network          string `json:"network"`
	MevRelays        string `json:"mev_relays,omitempty"`
	DkgAddress       string `json:"dkg_address,omitempty"`
	AddressWhitelist string `json:"address_whitelist,omitempty"`
}

func GetAllSsvOperatorsFromApi added in v0.4.2

func GetAllSsvOperatorsFromApi(network string) ([]OperatorFromApi, error)

func GetOperatorFromApi added in v0.4.2

func GetOperatorFromApi(network string, id uint64) (*OperatorFromApi, error)

type OperatorInfoOnChain added in v0.4.2

type OperatorInfoOnChain struct {
	Owner          common.Address
	Fee            *big.Int
	ValidatorCount uint32
	WhiteList      common.Address
	IsPrivete      bool
	IsActive       bool
}

type ResGasPrice

type ResGasPrice struct {
	BaseFee     int     `json:"baseFee"`
	BlockNumber int     `json:"blockNumber"`
	BlockTime   float64 `json:"blockTime"`
	GasPrice    struct {
		Fast     int `json:"fast"`
		Instant  int `json:"instant"`
		Standard int `json:"standard"`
	} `json:"gasPrice"`
	NextBaseFee int `json:"nextBaseFee"`
	PriorityFee struct {
		Fast     int `json:"fast"`
		Instant  int `json:"instant"`
		Standard int `json:"standard"`
	} `json:"priorityFee"`
}

type ResGasPriceFromBeacon

type ResGasPriceFromBeacon struct {
	Code int `json:"code"`
	Data struct {
		Rapid     int64   `json:"rapid"`
		Fast      int64   `json:"fast"`
		Standard  int64   `json:"standard"`
		Slow      int64   `json:"slow"`
		Timestamp int64   `json:"timestamp"`
		PriceUSD  float64 `json:"priceUSD"`
	} `json:"data"`
}

type Rsp

type Rsp struct {
	Status  string      `json:"status"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

type RspCoinGecko

type RspCoinGecko map[string]CoinGeckeoPrice

type RspCoinMarket

type RspCoinMarket struct {
	Status struct {
		Timestamp    time.Time   `json:"timestamp"`
		ErrorCode    int         `json:"error_code"`
		ErrorMessage interface{} `json:"error_message"`
		Elapsed      int         `json:"elapsed"`
		CreditCount  int         `json:"credit_count"`
		Notice       interface{} `json:"notice"`
	} `json:"status"`

	Data map[string]TokenInfo `json:"data"`
}

type RspError added in v0.4.2

type RspError struct {
	Code    int `json:"code"`
	Message struct {
		Error  string `json:"error"`
		Status int    `json:"status"`
	} `json:"message"`
}

type RspSsvOperator added in v0.4.2

type RspSsvOperator struct {
	OperatorFromApi
	Error RspError `json:"error"`
}

type RspSsvOperators added in v0.4.2

type RspSsvOperators struct {
	Pagination struct {
		Total   int `json:"total"`
		Page    int `json:"page"`
		Pages   int `json:"pages"`
		PerPage int `json:"per_page"`
	} `json:"pagination"`
	Operators []OperatorFromApi `json:"operators"`
	Error     RspError          `json:"error"`
}

type TokenInfo

type TokenInfo struct {
	ID                        int         `json:"id"`
	Name                      string      `json:"name"`
	Symbol                    string      `json:"symbol"`
	Slug                      string      `json:"slug"`
	NumMarketPairs            int         `json:"num_market_pairs"`
	DateAdded                 time.Time   `json:"date_added"`
	Tags                      []string    `json:"tags"`
	MaxSupply                 interface{} `json:"max_supply"`
	CirculatingSupply         float64     `json:"circulating_supply"`
	TotalSupply               float64     `json:"total_supply"`
	IsActive                  int         `json:"is_active"`
	IsMarketCapIncludedInCalc int         `json:"is_market_cap_included_in_calc"`
	Platform                  interface{} `json:"platform"`
	CmcRank                   int         `json:"cmc_rank"`
	IsFiat                    int         `json:"is_fiat"`
	LastUpdated               time.Time   `json:"last_updated"`
	Quote                     struct {
		USD struct {
			Price            float64   `json:"price"`
			Volume24H        float64   `json:"volume_24h"`
			PercentChange1H  float64   `json:"percent_change_1h"`
			PercentChange24H float64   `json:"percent_change_24h"`
			PercentChange7D  float64   `json:"percent_change_7d"`
			PercentChange30D float64   `json:"percent_change_30d"`
			PercentChange60D float64   `json:"percent_change_60d"`
			PercentChange90D float64   `json:"percent_change_90d"`
			MarketCap        float64   `json:"market_cap"`
			LastUpdated      time.Time `json:"last_updated"`
		} `json:"USD"`
	} `json:"quote"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL