timeseries

package
v0.0.0-...-0939e29 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Depth recorder fills keeps track of historical depth values and inserts changes in the block_pool_depths table.

Index

Constants

View Source
const DefaultLimit = 50
View Source
const DefaultPoolStatus = "staged"
View Source
const OutboundTimeout = time.Hour * 48

OutboundTimeout is an upperboundary for the amount of time for a followup on outbound events.

View Source
const WeeksInYear = 52

Variables

View Source
var NetworkNilNode = metrics.MustCounter(
	"midgard_network_nil_node",
	"Number of times thornode returned nil node in thorchain/nodes.")
View Source
var RewardEntriesAggregate = db.RegisterAggregate(
	db.NewAggregate("rewards_event_entries", "rewards_event_entries").
		AddGroupColumn("pool").
		AddBigintSumColumn("rune_e8").
		AddBigintSumColumn("saver_e8"))

Functions

func ActiveAndStandbyBondMetrics

func ActiveAndStandbyBondMetrics(active, standby sortedBonds, minimumEligibleBond int64) *bondMetricsInts

func ActiveNetworkVersion

func ActiveNetworkVersion(ctx context.Context) (string, error)

func ActiveNodeCount

func ActiveNodeCount(ctx context.Context, moment db.Nano) (int64, error)

Returns Active node count for a given Unix Nano timestamp

func AssetAndRuneDepths

func AssetAndRuneDepths() (assetE8PerPool, runeE8PerPool map[string]int64, timestamp time.Time)

Deprecated, use timeseries.Latest.GetState().PoolInfo(poolname) instead

func AssetPrice

func AssetPrice(assetDepth, runeDepth int64) float64

func CalculateAPYInterest

func CalculateAPYInterest(periodicRate float64, periodsPerYear float64) float64

func CalculateSynthUnits

func CalculateSynthUnits(assetDepth, synthDepth, liquidityUnits int64) int64

CalculateSynthUnits calculate dynamic synth units (L*S)/(2*A-S) L = LP units S = synth balance A = asset balance

func GetActions

func GetActions(ctx context.Context, moment time.Time, params ActionsParams) (
	oapigen.ActionsResponse, error)

Gets a list of actions generated by external transactions and return its associated data

func GetAllLastConstantValue

func GetAllLastConstantValue(ctx context.Context) (map[string]int64, error)

func GetBalances

func GetBalances(ctx context.Context, address string, height string, timestamp string) (oapigen.BalanceResponse, miderr.Err)

func GetBorrowerIds

func GetBorrowerIds(ctx context.Context, asset *string) (addrs []string, err error)

func GetChurnsData

func GetChurnsData(ctx context.Context) (oapigen.Churns, error)

func GetLastConstantValue

func GetLastConstantValue(ctx context.Context, key string) (int64, error)

Get value from Mimir overrides or from the Thorchain constants.

func GetLendingData

func GetLendingData(ctx context.Context) (map[string]LendingInfo, error)

func GetMemberIds

func GetMemberIds(ctx context.Context, pool *string) (addrs []string, err error)

GetMemberIds returns the ids of all known members.

The id of a member is defined as their rune address if they are participating with their rune address, or as their asset address otherwise (for members with asset address only.)

Member ids present in multiple pools will be only returned once.

func GetNetworkData

func GetNetworkData(ctx context.Context) (oapigen.Network, error)

func GetPoolsStatuses

func GetPoolsStatuses(ctx context.Context, moment db.Nano) (map[string]string, error)

Returns last status change for pool for a given point in time (UnixNano timestamp) If a pool with assets has no status change, it means it is in "staged" status status is lowercase

func GetTHORNamesByAddress

func GetTHORNamesByAddress(ctx context.Context, addr string) (names []string, err error)

NOTE: there is probably a pure-postrgres means of doing this, which would be more performant. If we find that the performance of this query to be too slow, can try that. I don't imagine it being much of a problem since people aren't going to associate their address with 100's of thornames

func GetTHORNamesByOwnerAddress

func GetTHORNamesByOwnerAddress(ctx context.Context, addr string) (names []string, err error)

func GetTopSwaps

func GetTopSwaps(ctx context.Context) (oapigen.ActionsResponse, error)

func LastBlock

func LastBlock() (height int64, timestamp time.Time, hash []byte)

Deprecated, use timeseries.Latest.GetState().{Heiht,Timestamp} instead

func LastChurnHeight

func LastChurnHeight(ctx context.Context) (int64, error)

LastChurnHeight gets the latest block where a vault was activated

func NodesSecpAndEd

func NodesSecpAndEd(ctx context.Context, t time.Time) (secp256k1Addrs, ed25519Addrs map[string]string, err error)

NodesSecpAndEd returs the public keys mapped to their respective addresses.

func PoolBasedOfType

func PoolBasedOfType(poolName string, poolType MemberPoolType) bool

func PoolExists

func PoolExists(pool string) bool

func PoolExistsNow

func PoolExistsNow(pool string) bool

func PoolStatus

func PoolStatus(ctx context.Context, pool string) (string, error)

func PoolsWithDeposit

func PoolsWithDeposit(ctx context.Context) ([]string, error)

PoolsWithDeposit gets all asset identifiers that have at least one stake

func ProcessBlock

func ProcessBlock(block *chain.Block, commit bool) (err error)

func QueryOneValue

func QueryOneValue(dest interface{}, ctx context.Context, query string, args ...interface{}) error

QueryOneValue is a helper to make store single value queries result into dest Also, if there is no row to be shown it will return the empty interface{} instead of making error

func ResetDepthManagerForTest

func ResetDepthManagerForTest()

func ResetLatestStateForTest

func ResetLatestStateForTest()

func SetDepthsForTest

func SetDepthsForTest(depths []Depth)

func SetLastHeightForTest

func SetLastHeightForTest(height int64)

func SetLastTimeForTest

func SetLastTimeForTest(timestamp db.Second)

Often current height or timestamp is read from the last track, this function helps to set them for tests.

func Setup

func Setup() error

Setup initializes the package. The previous state is restored (if there was any).

func StatusPerNode

func StatusPerNode(ctx context.Context, moment time.Time) (map[string]string, error)

StatusPerNode gets the labels for a given point in time. New nodes have the empty string (for no confirmed status). A zero moment defaults to the latest available. Requests beyond the last block cause an error.

func TotalLiquidityFeesRune

func TotalLiquidityFeesRune(ctx context.Context, from time.Time, to time.Time) (int64, error)

TotalLiquidityFeesRune gets sum of liquidity fees in Rune for a given time interval

func TotalLiquidityFeesRuneAtBlock

func TotalLiquidityFeesRuneAtBlock(ctx context.Context, timestamp time.Time) (int64, error)

Types

type ActionsParams

type ActionsParams struct {
	Limit         string
	NextPageToken string
	PrevPageToken string
	Timestamp     string
	Height        string
	FromTimestamp string
	FromHeight    string
	Offset        string
	ActionType    string
	Address       string
	TXId          string
	Asset         string
	TxType        string
	Affiliate     string
}

type BlockState

type BlockState struct {
	Height    int64
	Timestamp db.Nano
	Pools     DepthMap
}

func (BlockState) NextSecond

func (s BlockState) NextSecond() db.Second

func (BlockState) PoolExists

func (s BlockState) PoolExists(pool string) bool

func (BlockState) PoolInfo

func (s BlockState) PoolInfo(pool string) *PoolDepths

Returns nil if pool doesn't exist

type Borrower

type Borrower struct {
	CollateralAsset        string
	TargetAssets           []string
	DebtIssuedTor          int64
	DebtRepaidTor          int64
	CollateralDeposited    int64
	CollateralWithdrawn    int64
	LastOpenLoanTimestamp  int64
	LastRepayLoanTimestamp int64
}

type Borrowers

type Borrowers []Borrower

func GetBorrower

func GetBorrower(ctx context.Context, address []string) (Borrowers, error)

func (Borrowers) ToOapigen

func (borrowers Borrowers) ToOapigen() []oapigen.BorrowerPool

type Depth

type Depth struct {
	Pool       string
	AssetDepth int64
	RuneDepth  int64
	SynthDepth int64
}

type DepthMap

type DepthMap map[string]PoolDepths

type LatestState

type LatestState struct {
	sync.RWMutex
	// contains filtered or unexported fields
}
var Latest LatestState

func (*LatestState) GetState

func (latest *LatestState) GetState() BlockState

type LendingInfo

type LendingInfo struct {
	TotalCollateral int64
	TotalDebtTor    int64
}

type MemberPool

type MemberPool struct {
	Pool           string
	RuneAddress    string
	AssetAddress   string
	LiquidityUnits int64
	AssetDeposit   int64
	RuneDeposit    int64
	RuneAdded      int64
	AssetAdded     int64
	RunePending    int64
	AssetPending   int64
	DateFirstAdded int64
	DateLastAdded  int64
	RuneWithdrawn  int64
	AssetWithdrawn int64
}

TODO(HooriRn): this struct might not be needed since the graphql depracation. (delete-graphql) Info of a member in a specific pool.

type MemberPoolType

type MemberPoolType int
const (
	RegularAndSaverPools MemberPoolType = iota // regular and synth pools too
	RegularPools                               // regular (non-synth) pools e.g. 'BTC.BTC'
	SaverPools                                 // LPs of synth pools e.g. 'BTC/BTC'
)

type MemberPools

type MemberPools []MemberPool

Pools data associated with a single member

func GetMemberPools

func GetMemberPools(ctx context.Context, address []string, poolType MemberPoolType) (MemberPools, error)

func GetRUNEPoolProvider

func GetRUNEPoolProvider(ctx context.Context, address []string, poolType MemberPoolType) (MemberPools, error)

func (MemberPools) ToOapigen

func (memberPools MemberPools) ToOapigen() []oapigen.MemberPool

func (MemberPools) ToRUNEPool

func (memberPools MemberPools) ToRUNEPool() []oapigen.RUNEPoolProvider

func (MemberPools) ToSavers

func (memberPools MemberPools) ToSavers(poolRedeemValueMap map[string]int64) []oapigen.SaverPool

type PoolDepths

type PoolDepths struct {
	AssetDepth int64
	RuneDepth  int64
	SynthDepth int64
}

func (PoolDepths) AssetPrice

func (p PoolDepths) AssetPrice() float64

func (PoolDepths) ExistsNow

func (p PoolDepths) ExistsNow() bool

When a pool becomes suspended all the funds are burned. We use this as a detection of pools which no longer exist.

type THORName

type THORName struct {
	Owner   string
	Expire  int64
	Entries []THORNameEntry
}

func GetTHORName

func GetTHORName(ctx context.Context, name string) (tName THORName, err error)

type THORNameEntry

type THORNameEntry struct {
	Chain   string
	Address string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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