service

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: 25 Imported by: 0

Documentation

Overview

Package service is the core backend service for circuit-breaker

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

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

Service wraps multiple modules to provide the circuit breaking functionality

func New

func New(
	ctx context.Context,
	alert *alerts.Alerter,
	mc *multicall.Multicall,
	db *database.Database,
	bc *bclient.Client,
	auther *utils.Authorizer,
	logger *zap.Logger,
	pools []config.Pool,
	gasConfig config.GasPrice) (*Service, error)

New intializes all needed modules and returns a ready to consume service

func (*Service) Close

func (s *Service) Close() error

Close shuts down all internal modules returning any errors encountered from shutdown

func (*Service) GetBalancesWeightsAndSupplies

func (s *Service) GetBalancesWeightsAndSupplies(
	contract *sigmacore.Sigmacore,
	block uint64,
	poolAddress string,
	tokens map[string]common.Address,
) (
	balances map[string]interface{},
	denormWeights map[string]interface{},
	totalSupplies map[string]interface{},
	err error,
)

GetBalancesWeightsAndSupplies returns the balance, weights and total supplies of all tokens held by an IndexPool all keys of the maps are the symbols of a tokein lower case

func (*Service) Prepare

func (s *Service) Prepare() error

Prepare is used to prepare the service the primary responsibility of this function is to check the database and determine if we need to update the records. This will usually only happen during one of two conditions

  1. the very first time the service is started on a fresh database
  2. service starts up after being offline for 1 or more blocks since last run

func (*Service) StartBlockListener

func (s *Service) StartBlockListener() error

StartBlockListener waits for new blocks to be mined to trigger blockchain db updates

func (*Service) StartWatchers

func (s *Service) StartWatchers() error

StartWatchers starts all of our contract watchers which listen for LOG_SWAP events to potentially trigger circuit breaking activities

func (*Service) UpdateBalancesWeightsAndSupplies

func (s *Service) UpdateBalancesWeightsAndSupplies(
	block uint64,
	pool config.Pool,
	contract *sigmacore.Sigmacore,
) (
	balances map[string]interface{},
	denormWeights map[string]interface{},
	totalSupplies map[string]interface{},
	err error,
)

UpdateBalancesWeightsAndSupplies is used to update all balances, weights, and supplies for a given pool Note: If using from many different threads, caller will want to make sure to call the service named locks

Jump to

Keyboard shortcuts

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