util

package
v0.0.0-...-11a4fed Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: LGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const KeyTypeAWSMnemonic = "aws_mnemonic"
View Source
const KeyTypeAWSPrivateKey = "aws_private_key"
View Source
const KeyTypeMnemonic = "mnemonic"
View Source
const KeyTypePrivateKey = "private_key"

Variables

View Source
var (
	// Logger instance for quick declarative logging levels
	Logger    = logging.MustGetLogger("deputy")
	SdkLogger = &sdkLogger{}
)

Functions

func CalcActualOutAmount

func CalcActualOutAmount(amount *big.Int, ratio *big.Float, fixedFee *big.Int) *big.Int

func GetBigIntForDecimal

func GetBigIntForDecimal(decimal int) *big.Int

func GetS3Object

func GetS3Object(region string, bucket string, key string) (string, error)

func GetSecret

func GetSecret(secretName, region string) (string, error)

func InitLogger

func InitLogger(config LogConfig)

InitLogger initialises the logger.

func MustRegisterMetrics

func MustRegisterMetrics()

func PrepareDB

func PrepareDB(config *Config) (*gorm.DB, error)

func QuoBigInt

func QuoBigInt(a *big.Int, b *big.Int) *big.Float

func SendTelegramMessage

func SendTelegramMessage(botId string, chatId string, msg string)

Types

type AdminConfig

type AdminConfig struct {
	ListenAddr string `json:"listen_addr"`
}

func (*AdminConfig) Validate

func (cfg *AdminConfig) Validate()

type AlertConfig

type AlertConfig struct {
	TelegramBotId  string `json:"telegram_bot_id"`
	TelegramChatId string `json:"telegram_chat_id"`

	BnbBlockUpdateTimeOut        int64 `json:"bnb_block_update_time_out"`
	OtherChainBlockUpdateTimeOut int64 `json:"other_chain_block_update_time_out"`

	ReconciliationDiffAmount *big.Float `json:"reconciliation_diff_amount"` // real number without decimal
}

type BnbConfig

type BnbConfig struct {
	KeyType                    string           `json:"key_type"`
	AWSRegion                  string           `json:"aws_region"`
	AWSSecretName              string           `json:"aws_secret_name"`
	Mnemonic                   string           `json:"mnemonic"`
	RpcAddr                    string           `json:"rpc_addr"`
	Symbol                     string           `json:"symbol"`
	FetchInterval              int64            `json:"fetch_interval"`
	TokenBalanceAlertThreshold int64            `json:"token_balance_alert_threshold"`
	BnbBalanceAlertThreshold   int64            `json:"bnb_balance_alert_threshold"`
	DeputyAddr                 types.AccAddress `json:"deputy_addr"`
	ColdWalletAddr             types.AccAddress `json:"cold_wallet_addr"`
}

func (*BnbConfig) Validate

func (cfg *BnbConfig) Validate()

type ChainConfig

type ChainConfig struct {
	BnbConfirmNum                int64      `json:"bnb_confirm_num"`
	BnbAutoRetryNum              int        `json:"bnb_auto_retry_num"`
	BnbAutoRetryTimeout          int64      `json:"bnb_auto_retry_timeout"`
	BnbExpireHeightSpan          int64      `json:"bnb_expire_height_span"`
	BnbMinAcceptExpireHeightSpan int64      `json:"bnb_min_accept_expire_height_span"`
	BnbMinRemainHeight           int64      `json:"bnb_min_remain_height"`
	BnbMinSwapAmount             *big.Int   `json:"bnb_min_swap_amount"`
	BnbMaxSwapAmount             *big.Int   `json:"bnb_max_swap_amount"`
	BnbMaxDeputyOutAmount        *big.Int   `json:"bnb_max_deputy_out_amount"`
	BnbRatio                     *big.Float `json:"bnb_ratio"`
	BnbFixedFee                  *big.Int   `json:"bnb_fixed_fee"`
	BnbStartHeight               int64      `json:"bnb_start_height"`
	BnbHotWalletOverflow         *big.Int   `json:"bnb_hot_wallet_overflow"` // deputy's balance above this threshold will be sent to the cold wallet

	OtherChain                          string     `json:"other_chain"`
	OtherChainConfirmNum                int64      `json:"other_chain_confirm_num"`
	OtherChainDecimal                   int        `json:"other_chain_decimal"`
	OtherChainExpireHeightSpan          int64      `json:"other_chain_expire_height_span"`
	OtherChainAutoRetryNum              int        `json:"other_chain_auto_retry_num"`
	OtherChainAutoRetryTimeout          int64      `json:"other_chain_auto_retry_timeout"`
	OtherChainMinAcceptExpireHeightSpan int64      `json:"other_chain_min_accept_expire_height_span"`
	OtherChainMinRemainHeight           int64      `json:"other_chain_min_remain_height"`
	OtherChainMinSwapAmount             *big.Int   `json:"other_chain_min_swap_amount"`
	OtherChainMaxSwapAmount             *big.Int   `json:"other_chain_max_swap_amount"`
	OtherChainMaxDeputyOutAmount        *big.Int   `json:"other_chain_max_deputy_out_amount"`
	OtherChainRatio                     *big.Float `json:"other_chain_ratio"`
	OtherChainFixedFee                  *big.Int   `json:"other_chain_fixed_fee"`
	OtherChainStartHeight               int64      `json:"other_chain_start_height"`
	OtherChainHotWalletOverflow         *big.Int   `json:"other_chain_hot_wallet_overflow"` // deputy's balance above this threshold will be sent to the cold wallet
}

func (*ChainConfig) Validate

func (cfg *ChainConfig) Validate()

type Config

type Config struct {
	DBConfig              *DBConfig              `json:"db_config"`
	AlertConfig           *AlertConfig           `json:"alert_config"`
	ChainConfig           *ChainConfig           `json:"chain_config"`
	LogConfig             *LogConfig             `json:"log_config"`
	InstrumentationConfig *InstrumentationConfig `json:"instrumentation_config"`
	AdminConfig           *AdminConfig           `json:"admin_config"`
	BnbConfig             *BnbConfig             `json:"bnb_config"`
	EthConfig             *EthConfig             `json:"eth_config"`
	KavaConfig            *KavaConfig            `json:"kava_config"`
}

func GetTestConfig

func GetTestConfig() *Config

func ParseConfigFromFile

func ParseConfigFromFile(filePath string) *Config

func ParseConfigFromJson

func ParseConfigFromJson(content string) *Config

func (*Config) Validate

func (cfg *Config) Validate()

type DBConfig

type DBConfig struct {
	Dialect                 string `json:"dialect"`
	DBPath                  string `json:"db_path"`
	MaxBnbKeptBlockHeight   int64  `json:"max_bnb_kept_block_height"`
	MaxOtherKeptBlockHeight int64  `json:"max_other_kept_block_height"`
}

func (*DBConfig) Validate

func (cfg *DBConfig) Validate()

type EthConfig

type EthConfig struct {
	SwapType                       string         `json:"swap_type"`
	KeyType                        string         `json:"key_type"`
	AWSRegion                      string         `json:"aws_region"`
	AWSSecretName                  string         `json:"aws_secret_name"`
	PrivateKey                     string         `json:"private_key"`
	Provider                       string         `json:"provider"`
	SwapContractAddr               common.Address `json:"swap_contract_addr"`
	TokenContractAddr              common.Address `json:"token_contract_addr"`
	DeputyAddr                     common.Address `json:"deputy_addr"`
	ColdWalletAddr                 common.Address `json:"cold_wallet_addr"`
	TokenBalanceAlertThreshold     *big.Int       `json:"token_balance_alert_threshold"`
	EthBalanceAlertThreshold       *big.Int       `json:"eth_balance_alert_threshold"`
	AllowanceBalanceAlertThreshold *big.Int       `json:"allowance_balance_alert_threshold"`
	FetchInterval                  int64          `json:"fetch_interval"`
	GasLimit                       int64          `json:"gas_limit"`
	GasPrice                       *big.Int       `json:"gas_price"`
}

func (*EthConfig) Validate

func (cfg *EthConfig) Validate()

type InstrumentationConfig

type InstrumentationConfig struct {
	Prometheus           bool   `json:"prometheus"`
	PrometheusListenAddr string `json:"prometheus_listen_addr"`
}

type KavaConfig

type KavaConfig struct {
	KeyType                    string         `json:"key_type"`
	AWSRegion                  string         `json:"aws_region"`
	AWSSecretName              string         `json:"aws_secret_name"`
	Mnemonic                   string         `json:"mnemonic"`
	RpcAddr                    string         `json:"rpc_addr"`
	Symbol                     string         `json:"symbol"`
	FetchInterval              int64          `json:"fetch_interval"`
	TokenBalanceAlertThreshold int64          `json:"token_balance_alert_threshold"`
	KavaBalanceAlertThreshold  int64          `json:"kava_balance_alert_threshold"`
	DeputyAddr                 sdk.AccAddress `json:"deputy_addr"`
	ColdWalletAddr             sdk.AccAddress `json:"cold_wallet_addr"`
}

func (*KavaConfig) Validate

func (cfg *KavaConfig) Validate()

type LogConfig

type LogConfig struct {
	Level                        string `json:"level"`
	Filename                     string `json:"filename"`
	MaxFileSizeInMB              int    `json:"max_file_size_in_mb"`
	MaxBackupsOfLogFiles         int    `json:"max_backups_of_log_files"`
	MaxAgeToRetainLogFilesInDays int    `json:"max_age_to_retain_log_files_in_days"`
	UseConsoleLogger             bool   `json:"use_console_logger"`
	UseFileLogger                bool   `json:"use_file_logger"`
	Compress                     bool   `json:"compress"`
}

func (*LogConfig) Validate

func (cfg *LogConfig) Validate()

type Metrics

type Metrics struct {
	NumSwaps           *prometheus.GaugeVec
	FetchedBlockHeight *prometheus.GaugeVec
	Balance            *prometheus.GaugeVec
}
var PrometheusMetrics *Metrics

Jump to

Keyboard shortcuts

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