utils

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ValidatorStatusDeposited = uint8(1)

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

	// lightnode related
	ValidatorStatusWithdrawUnmatch     = uint8(4)
	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 (
	FeePool          = uint8(1)
	SuperNodeFeePool = uint8(2)
)
View Source
const (
	V1  = "v1"
	V2  = "v2"
	Dev = "dev"
)
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)
	SlashTypeSyncMiss      = uint8(4)
	SlashTypeAttesterMiss  = uint8(5)
	SlashTypeProposerMiss  = uint8(6)
)
View Source
const (
	V1EndEpoch      = uint64(148000)
	Eth1StartHeight = uint64(15572967)

	StandardEffectiveBalance            = uint64(32e9) //gwei
	StandardSuperNodeFakeDepositBalance = uint64(1e9)  //gwei
	StandardLightNodeDepositAmount      = uint64(12e9) //gwei
)
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 (
	UnstakingStartTimestamp uint64
	REthTotalApy            float64
	ValidatorAverageApr     float64
)
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 ContractStorageKey

func ContractStorageKey(name string) [32]byte

func DistributeWithdrawalsProposalNodeKey

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

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 FloatToStr

func FloatToStr(f float64) string

func GetApyFromStafiInfo

func GetApyFromStafiInfo(stafiInfoEndpoint string) (float64, error)

https://rtoken-api2.stafi.io/

func GetDropRate

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

func GetDropRateFromTimestamp

func GetDropRateFromTimestamp(startDay, stamp string) (string, 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 GetNodeReward

func GetNodeReward(balance, effectiveBalance, nodeDepositAmount uint64) 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 GetTotalReward

func GetTotalReward(balance, withdrawal uint64) uint64

func GetUserNodePlatformRewardV1

func GetUserNodePlatformRewardV1(userDepositBalance uint64, rewardDeci decimal.Decimal) (decimal.Decimal, decimal.Decimal, decimal.Decimal)

return (user reward, node reward, paltform fee)

func GetUserNodePlatformRewardV2

func GetUserNodePlatformRewardV2(nodeDepositAmount uint64, rewardDeci decimal.Decimal) (decimal.Decimal, decimal.Decimal, decimal.Decimal)

todo split v1/v2 by height platform = 5% node = 5% + (90% * nodedeposit/32) rewardDeci decimals maybe 9/18, also the returns return (user reward, node reward, paltform fee)

func GetUserValPlatformDepositAndRewardV1

func GetUserValPlatformDepositAndRewardV1(validatorBalance, nodeDepositAmount uint64, platformFee, nodeFee decimal.Decimal) (uint64, uint64, uint64, uint64, uint64)

statistic use return (user deposit, user reward, val deposit, val reward, paltform fee)

func GetYesterdayUTC8Date

func GetYesterdayUTC8Date() string

func IsImageExt

func IsImageExt(extName string) bool

func MerkleTreeDealedEpochStorageKey

func MerkleTreeDealedEpochStorageKey() [32]byte

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 ProposalNokeKey

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

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

func ToUpperList(list []string) []string

func Uuid

func Uuid() string

func VerifyProof

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

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, amount *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 Rsp

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

type RspApy

type RspApy struct {
	Data struct {
		TotalStakeValue float64 `json:"totalStakeValue"`
		StakeValueList  []struct {
			StakeAmount string  `json:"stakeAmount"`
			StakeValue  float64 `json:"stakeValue"`
			StakeApy    float64 `json:"stakeApy"`
			MintApy     float64 `json:"mintApy"`
			TotalApy    float64 `json:"totalApy"`
			RTokenType  int64   `json:"rTokenType"`
		} `json:"stakeValueList"`
	} `json:"data"`
	Message string `json:"message"`
	Status  string `json:"status"`
}

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