indexer

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const BaseVolumeDenom = "uosmo"
View Source
const (
	DefaultBlocksPerHour = 720
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ExpectedRPC

type ExpectedRPC interface {
	DenomTrace(ibc string) (IBCTypes.DenomTrace, error)
	DenomTraces() ([]IBCTypes.DenomTrace, error)
	BlockAt(height int64) (*tmtypes.Block, error)
	ChainID() (string, error)
	Close() error
	Mempool() ([]*types.Transaction, error)
	PoolsAt(height int64, ids ...uint64) ([]*pmtypes.PoolI, error)
	PoolsTotalLiquidityAt(height int64, ids ...uint64) ([]types.PoolLiquidity, error)
	PoolsVolumeAt(height int64, ids ...uint64) ([]types.PoolVolume, error)
	Subscribe(eventName string, handle func(events <-chan ctypes.ResultEvent) error) error
}

type Indexer

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

func New

func New(ctx context.Context, cancel context.CancelCauseFunc, group *errgroup.Group, logger *slog.Logger, repo repository.Repository, rpc ExpectedRPC, poolIds []uint64, blocks uint64, verbose bool) (*Indexer, error)

func (*Indexer) AverageBlockTime

func (d *Indexer) AverageBlockTime() time.Duration

func (*Indexer) BlockToTimestamp

func (d *Indexer) BlockToTimestamp(height uint64) time.Time

Calculates block timestamp based on latest block height and latest block timestamp FIXME: This is approximation. Better way would be to record each block timestamp and find that block's timestamp and return it instead. If no block exists with that height, find a closest block and interpolate/extrapolate from that.

func (*Indexer) CalculateVolumes

func (d *Indexer) CalculateVolumes(pools []types.PoolStatus) error

func (*Indexer) DenomTrace

func (d *Indexer) DenomTrace(ibc string) (ibctypes.DenomTrace, error)

func (*Indexer) GetStatus

func (d *Indexer) GetStatus() map[string]any

func (*Indexer) PoolStatusAt

func (d *Indexer) PoolStatusAt(height, poolId uint64) (types.PoolStatus, uint64, error)

func (*Indexer) PoolStatusesAt

func (d *Indexer) PoolStatusesAt(height uint64, poolId ...uint64) ([]types.PoolStatus, uint64, error)

func (*Indexer) SetLatestBlockHeight

func (d *Indexer) SetLatestBlockHeight(height uint64, blockTime time.Time)

func (*Indexer) SetLatestPrice

func (d *Indexer) SetLatestPrice(token, base string, value float64, lastUpdated time.Time) error

type PoolMap

type PoolMap struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*PoolMap) Get

func (p *PoolMap) Get(height, id uint64) (repository.Pool, bool)

func (*PoolMap) Has

func (p *PoolMap) Has(height, id uint64) bool

func (*PoolMap) Prune

func (p *PoolMap) Prune(minHeight uint64) int

func (*PoolMap) Set

func (p *PoolMap) Set(pool repository.Pool)

type PriceMap

type PriceMap struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*PriceMap) Estimate

func (p *PriceMap) Estimate(lastUpdated time.Time, denom string) (float64, time.Duration)

Estimate will extrapolate or interpolate(depending on cache state and lastUpdated param) the price.

  • If the price is outside of cache dates - final price will be the same as closest price available.
  • If the price is inside cache dates - final price will be the average of two prices(unless exact match is found) Estimation time error will be returned.

func (*PriceMap) Nearest

func (p *PriceMap) Nearest(timestamp time.Time, name string) []repository.TokenPrice

func (*PriceMap) Prune

func (p *PriceMap) Prune(minLastUpdated time.Time) int

func (*PriceMap) Set

func (p *PriceMap) Set(price repository.TokenPrice) bool

Set will add a token price if such does not exist (must not match LastUpdated). Will return true if it results in unsorted array.

func (*PriceMap) Sort

func (p *PriceMap) Sort()

func (*PriceMap) SortToken

func (p *PriceMap) SortToken(denom string)

Jump to

Keyboard shortcuts

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