database

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

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

Database wraps gorm.DB with convenience functions

func New

func New(opts *Opts) (*Database, error)

New returns a new database client

func (*Database) AutoMigrate

func (d *Database) AutoMigrate() error

AutoMigrate is used to automatically migrate datbase tables

func (*Database) Close

func (d *Database) Close() error

Close shuts down the database

func (*Database) GetInfo

func (db *Database) GetInfo(name string, block uint64) (PoolInfo, error)

GetInfo returns the record PoolInfo at the given block

func (*Database) GetNumInfos

func (db *Database) GetNumInfos(poolName string) (int, error)

GetNumInfos returns the number of infos recorded for a pool

func (*Database) GetPool

func (db *Database) GetPool(name string) (*Pool, error)

GetPool returns a pool by its index name

func (*Database) GetTokenDecimals

func (db *Database) GetTokenDecimals(poolName, tokenName string) (uint8, error)

GetTokenDecimals returns the decimal count associated with various tokens

func (*Database) NewPool

func (db *Database) NewPool(
	name string,
	contractAddress string,
	block uint64,
	balances, denormWeights, tokenTotalSupplies, decimals map[string]interface{},
) error

NewPool creates a new entry in the database for an index pool

func (*Database) PurgeOldInfos

func (db *Database) PurgeOldInfos(poolName string, purgeCount int) error

PurgeOldInfos is used to purge old information from the database

func (*Database) RecordInfo

func (db *Database) RecordInfo(
	name string,
	block uint64,
	balances, denormWeights, tokenTotalSupplies map[string]interface{},
) error

RecordInfo is used to record updates infos for the given block

type Opts

type Opts struct {
	Type           string
	Host           string
	Port           string
	User           string
	Password       string
	DBName         string
	DBPath         string
	SSLModeDisable bool
}

Opts is used to configure database connections

func OptsFromConfig

func OptsFromConfig(cfg config.Database) *Opts

OptsFromConfig returns database options from a config file

func (*Opts) DSN

func (db *Opts) DSN() string

DSN returns the config string used with gorm

func (*Opts) Open

func (db *Opts) Open() (gorm.Dialector, error)

Open returns the gorm dialector for the corresponding db type

type Pool

type Pool struct {
	gorm.Model
	Name            string `gorm:"unique"`
	ContractAddress string
	// denotes the last block that we did an update at
	// this is to make sure we dont needlessly update the information
	LastUpdateAt uint64
	// maps block num -> info
	Infos datatypes.JSONMap
	// TokenDecimals tracks the decimal values for a given token
	// at the moment we expect this to be fixed and not updated that often
	// decimal value is of type uint8
	TokenDecimals datatypes.JSONMap
}

Pool is a single IndexPool

type PoolInfo

type PoolInfo struct {
	// tokenName -> balance (big.Int)
	Balances datatypes.JSONMap `json:"balances"`
	// tokenName -> weight (big.Int)
	DenormalizedWeights datatypes.JSONMap `json:"denormalized_weights"`
	// TokenTotalSupplies tracks the total supply for all tokens held by the indice
	// this is not to be confused with the IndexPool tokens themselves. For example
	// DEFI5 holds UNI, SNX, AAVE, CMP and CRV so this will track the supply fo rthose
	// supply value is of type string
	TokenTotalSupplies datatypes.JSONMap `json:"token_total_supplies"`
}

PoolInfo records pool information for a given block

Jump to

Keyboard shortcuts

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