utils

package
v0.0.0-...-1845101 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: GPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

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

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

	// status on beacon chain
	ValidatorStatusWaiting      = uint8(5)
	ValidatorStatusActive       = uint8(6)
	ValidatorStatusExited       = uint8(7)
	ValidatorStatusWithdrawable = uint8(8)
	ValidatorStatusWithdrawDone = uint8(9)

	// after distribute reward
	ValidatorStatusDistributed = uint8(10) // 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 (
	NodeTypeSolo  = uint8(1)
	NodeTypeTrust = uint8(2)
)

1 Solo node 2 trust node

View Source
const (
	NodeClaimTypeNone         = uint8(0)
	NodeClaimTypeClaimReward  = uint8(1)
	NodeClaimTypeClaimDeposit = uint8(2)
	NodeClaimTypeClaimTotal   = uint8(3)

	DistributeTypeNone        = uint8(0)
	DistributeTypeWithdrawals = uint8(1)
	DistributeTypePriorityFee = uint8(2)
)
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 (
	RetryLimit    = 300
	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 (
	GweiDeci = decimal.NewFromInt(1e9)

	Percent5Deci  = decimal.NewFromFloat(0.05)
	Percent90Deci = decimal.NewFromFloat(0.9)

	StandardEffectiveBalance     = uint64(32e9)
	StandardEffectiveBalanceDeci = decimal.NewFromBigInt(big.NewInt(32), 18)

	StandardTrustNodeFakeDepositBalance = decimal.NewFromInt(1e18)

	MaxPartialWithdrawalAmount     = uint64(8e9)
	MaxPartialWithdrawalAmountDeci = decimal.NewFromInt(8e18)
)
View Source
var (
	ErrPairNotExist     = errors.New("PairNotExist")
	ErrLeafNodeNotExist = errors.New("LeafNodeNotExist")
	ErrInvalidTree      = errors.New("InvalidateTree")
)
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 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 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 EventTopics

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

func ExecuteFns

func ExecuteFns(fns ...func() error) (err 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 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 GetNowUTC8Date

func GetNowUTC8Date() string

func GetSwapHash

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

func GetUserNodePlatformReward

func GetUserNodePlatformReward(nodeCommissionRate, platformCommissionRate, nodeDepositAmountDeci, rewardDeci decimal.Decimal) (decimal.Decimal, decimal.Decimal, decimal.Decimal)

user = 90%*(1-nodedeposit/32) node = 5% + (90% * nodedeposit/32) platform = 5% nodeDepositAmount decimals 18 rewardDeci decimals 18 return (user reward, node reward, paltform fee) decimals 18

func GetYesterdayUTC8Date

func GetYesterdayUTC8Date() string

func IsDir

func IsDir(path string) (bool, error)

isDirectory determines if a file represented by `path` is a directory or not

func IsImageExt

func IsImageExt(extName string) bool

func Max

func Max[T constraints.Ordered](a, b T) T

func Min

func Min[T constraints.Ordered](n1 T, nums ...T) T

func NodeRewardsFileNameAtEpoch

func NodeRewardsFileNameAtEpoch(lsdToken string, epoch uint64) string

func NodeRewardsFileNameAtEpochOld

func NodeRewardsFileNameAtEpochOld(lsdToken string, epoch uint64) string

func PriceSymbolValid

func PriceSymbolValid(symbol string) bool

func ProposalId

func ProposalId(to common.Address, callData []byte, proposalFactor *big.Int) [32]byte

bytes32 proposalId = keccak256(abi.encodePacked("execProposal", _to, _callData, _proposalFactor));

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 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 Sleep

func Sleep(stop <-chan struct{}, dur time.Duration)

func SlotAtTimestamp

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

func Stack

func Stack(skip int) []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

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 XOR

func XOR(data []byte) []byte

XOR returns an XORd copy of the bytes.

Types

type KeyedMutex

type KeyedMutex[T comparable] struct {
	// contains filtered or unexported fields
}

func (*KeyedMutex[T]) Delete

func (m *KeyedMutex[T]) Delete(key T)

func (*KeyedMutex[T]) Lock

func (m *KeyedMutex[T]) Lock(key T) func()

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() (NodeHash, 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 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"`
}

Jump to

Keyboard shortcuts

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