worker

package
v0.0.0-...-07d62d3 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FeeSwitchReasonDatabase when a fee switch is found in the database
	FeeSwitchReasonDatabase = "database"

	// FeeSwitchReasonAmm when a fee switch happens because the recipient is the AMM
	FeeSwitchReasonAmm = "amm"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CalculationType

type CalculationType string

CalculationType to determine how payouts are calculated

const (
	// CalculationTypeNormal to indicate the calculation type that the
	// fluid token and tokens like it use (normal trf operation)
	CalculationTypeNormal CalculationType = ""

	// CalculationTypeWorkerOverrides to indicate the calculation type used for
	// tokens that don't use the optimistic solution and may have workerconfig overrides
	CalculationTypeWorkerOverrides CalculationType = "worker config overrides"
)

type Emission

type Emission struct {
	LastUpdated time.Time `json:"last_updated"`

	Network          string                     `json:"network"`
	TokenDetails     token_details.TokenDetails `json:"token_details"`
	TransactionHash  string                     `json:"transaction_hash"`
	RecipientAddress string                     `json:"recipient_address"`
	SenderAddress    string                     `json:"sender_address"`

	EthereumBlockNumber misc.BigInt `json:"ethereum_block_number"`
	SolanaSlotNumber    misc.BigInt `json:"solana_slot_number"`
	SuiCheckpointNumber misc.BigInt `json:"sui_checkpoint_number"`

	AverageTransfersInBlock float64 `json:"average_transfers_in_block"`

	AtxBufferSize    int    `json:"atx_buffer_size"`
	TransfersInBlock int    `json:"transfers_in_block"`
	TransfersPast    string `json:"transfers_past"`

	SecondsSinceLastBlock uint64 `json:"seconds_since_last_block"`

	GasLimit misc.BigInt `json:"gas_limit"`
	GasPrice misc.BigInt `json:"gas_price"`

	GasTipCap misc.BigInt `json:"gas_tip_cap"`

	GasLimitNormal  float64 `json:"gas_limit_normal"`
	GasTipCapNormal float64 `json:"gas_tip_cap_normal"`

	GasUsed       misc.BigInt `json:"gas_used"`
	GasUsedNormal float64     `json:"gas_used_normal"`

	TransferFeeNormal float64 `json:"transfer_fee_normal"`

	BlockBaseFee       misc.BigInt `json:"block_base_fee"`
	BlockBaseFeeNormal float64     `json:"block_base_fee_normal"`

	MaxPriorityFeePerGas       misc.BigInt `json:"max_priority_fee_per_gas"`
	MaxPriorityFeePerGasNormal float64     `json:"max_priority_fee_per_gas_normal"`

	MaxFeePerGas       misc.BigInt `json:"max_fee_per_gas"`
	MaxFeePerGasNormal float64     `json:"max_fee_per_gas_normal"`

	EffectiveGasPriceNormal float64 `json:"effective_gas_price_normal"`

	Payout struct {
		Winnings        float64 `json:"winnings"` // Winnings
		P               float64 `json:"p"`        // Probability
		A               float64 `json:"a"`
		M               int64   `json:"m"` // Winning classes / divisions
		G               float64 `json:"g"` // Gas fee
		B               int64   `json:"b"` // Balls in a single ticket
		Delta           float64 `json:"delta"`
		ApyPlusDelta    float64 `json:"apy+delta"`
		Atx             float64 `json:"atx"`                // Annual number fluid transactions
		Apy             float64 `json:"apy"`                // Annual percentage yield
		BpyForStakedUsd float64 `json:"bpy_for_staked_usd"` // Yield for USD
		BlockTime       uint64  `json:"block_time"`         // Block time
		RewardPool      float64 `json:"reward_pool"`
	} `json:"payout"`

	// app fees for solana transactions
	SolanaAppFees SolanaAppFees `json:"solana_fees"`

	// app fees for eth transactions
	EthereumAppFees EthereumAppFees `json:"ethereum_fees"`

	// app fees for sui transactions
	SuiAppFees SuiAppFees `json:"sui_fees"`

	// calculate n function
	CalculateN struct {
		ProbabilityM float64 `json:"probability_m"`
		Factorial    float64 `json:"factorial"`
		Atx          float64 `json:"atx"`
		N            int64   `json:"n"`
	} `json:"calculate_n"`

	NaiveIsWinning struct {
		TestingBalls []uint32 `json:"testing_balls"`
		IsWinning    bool     `json:"is_winning"`
		MatchedBalls int      `json:"matched_balls"`
	} `json:"naive_is_winning"`

	CalculateBpy struct {
		BlockTimeInSeconds                          uint64  `json:"block_time_in_seconds"`
		CompSupplyApy                               float64 `json:"comp_supply_apy"`
		BlockTimeInSecondsMultipliedByCompSupplyApy float64 `json:"block_time_in_seconds_multiplied_by_comp_supply_apy"`
	} `json:"calculate_bpy"`

	AaveGetTokenApy struct {
		DepositApr       float64 `json:"deposit_apr"`
		APRPerDay        float64 `json:"apr_per_day"`
		OnePlusAprPerDay float64 `json:"one_plus_apr_per_day"`
		CompoundedApr    float64 `json:"compounded_apr"`
		DepositApy       float64 `json:"deposit_apy"`
	} `json:"aave_get_token_apy"`

	CompoundGetTokenApy struct {
		BlocksPerDay                      uint64  `json:"blocks_per_day"`
		SupplyRatePerBlockDivEthMantissa  float64 `json:"supply_rate_per_block_div_eth_mantissa"`
		SupplyRatePerBlockMulBlocksPerDay float64 `json:"supply_rate_per_block_mul_blocks_per_day"`
		PowLeftSide                       float64 `json:"pow_left_side"`
		PowLeftSideDaysPerYear            float64 `json:"pow_left_side_days_per_year"`
		SupplyApy                         float64 `json:"supply_apy"`
	} `json:"compound_get_token_apy"`

	WinningChances struct {
		AtxAtEnd float64 `json:"atx_at_end"`

		Payout1 float64 `json:"payout_1"`
		Payout2 float64 `json:"payout_2"`
		Payout3 float64 `json:"payout_3"`
		Payout4 float64 `json:"payout_4"`
		Payout5 float64 `json:"payout_5"`

		Probability1 float64 `json:"probability_1"`
		Probability2 float64 `json:"probability_2"`
		Probability3 float64 `json:"probability_3"`
		Probability4 float64 `json:"probability_4"`
		Probability5 float64 `json:"probability_5"`

		TotalBpy          float64 `json:"total_bpy"`
		DistributionPools string  `json:"distribution_pools"`
	} `json:"winning_chances"`

	// FeeSwitchSender if enabled and their custom arguments
	FeeSwitchSender struct {
		OriginalAddress string `json:"original_address"`
		NewAddress      string `json:"new_address"`
		Reason          string `json:"fee_switch_reason"`
	} `json:"fee_switch_sender"`

	// FeeSwitchRecipient if enabled and their custom arguments
	FeeSwitchRecipient struct {
		OriginalAddress string `json:"original_address"`
		NewAddress      string `json:"new_address"`
		Reason          string `json:"fee_switch_reason"`
	} `json:"fee_switch_recipient"`

	// SpecialPoolOptions enabled by enabling the utility mining feature
	SpecialPoolOptions struct {
		PayoutFreqOverride     float64 `json:"payout_freq_override"`
		DeltaWeightOverride    float64 `json:"delta_weight_override"`
		WinningClassesOverride float64 `json:"winning_classes_override"`
	} `json:"special_pool_options"`
}

Emission contains information on the modelling information that led up to the rewarding of the user

func NewEthereumEmission

func NewEthereumEmission() *Emission

func NewSolanaEmission

func NewSolanaEmission() *Emission

func NewSuiEmission

func NewSuiEmission() *Emission

func (Emission) String

func (emission Emission) String() string

String the emission to make it suitable for printing

func (*Emission) Update

func (emission *Emission) Update()

Update LastUpdated using the current time

type EthereumAnnouncement

type EthereumAnnouncement struct {
	TransactionHash ethereum.Hash                         `json:"transaction_hash"`
	BlockNumber     *misc.BigInt                          `json:"block_number"`
	LogIndex        *misc.BigInt                          `json:"log_index"`
	FromAddress     ethereum.Address                      `json:"from_address"`
	ToAddress       ethereum.Address                      `json:"to_address"`
	RandomSource    []uint32                              `json:"random_source"`
	RandomPayouts   map[applications.UtilityName][]Payout `json:"random_payouts"`
	TokenDetails    token_details.TokenDetails            `json:"token_details"`
	Emissions       Emission                              `json:"emissions"`
	Application     applications.Application              `json:"application"`
	Decorator       *EthereumWorkerDecorator              `json:"decorator"`
}

EthereumAnnouncement contains the data to call the reward function of the contract with

type EthereumAppFees

type EthereumAppFees struct {
	UniswapV3        float64 `json:"uniswap_v3",`
	UniswapV2        float64 `json:"uniswap_v2"`
	BalancerV2       float64 `json:"balancer_v2"`
	OneInchV2        float64 `json:"oneinch_v2"`
	OneInchV1        float64 `json:"oneinch_v1"`
	Mooniswap        float64 `json:"mooniswap"`
	OneInchFixedRate float64 `json:"oneinch_fixedrate"`
	DodoV2           float64 `json:"dodo_v2"`
	Curve            float64 `json:"curve"`

	// Multichain is no longer used, but is kept here to be consistent with the database.
	Multichain   float64 `json:"multichain"`
	XyFinance    float64 `json:"xyfinance"`
	Apeswap      float64 `json:"apeswap"`
	Saddle       float64 `json:"saddle"`
	GTradeV6_1   float64 `json:"gtrade_v6_1"`
	Meson        float64 `json:"meson"`
	Camelot      float64 `json:"camelot"`
	CamelotV3    float64 `json:"camelot_v3"`
	Chronos      float64 `json:"chronos"`
	Sushiswap    float64 `json:"sushiswap"`
	KyberClassic float64 `json:"kyber_classic"`
	Wombat       float64 `json:"wombat"`
	SeawaterAmm  float64 `json:"seawater_amm"`
	TraderJoe    float64 `json:"trader_joe"`
	Lifi         float64 `json:"lifi"`
	Odos         float64 `json:"odos"`
	BetSwirl     float64 `json:"betswirl"`
	Paraswap     float64 `json:"paraswap"`
	Pancakeswap  float64 `json:"pancakeswap"`
}

app fees for ethereum transactions

type EthereumApplicationEvent

type EthereumApplicationEvent struct {
	ApplicationTransfers []EthereumApplicationTransfer `json:"application_transfers"`
	BlockLog             EthereumBlockLog              `json:"block_log"`
}

An event the worker server sends for processing when it finds a log of interest

type EthereumApplicationTransfer

type EthereumApplicationTransfer struct {
	TransactionHash ethereum.Hash `json:"transaction"`
	// the log classified as an application transfer
	// to be processed by the application server
	Log ethereum.Log `json:"log"`
	// an enum representing the application this
	// transfer is produced by
	Application applications.Application `json:"application"`
}

An individual log included in an application event

type EthereumBlockLog

type EthereumBlockLog struct {
	BlockHash    ethereum.Hash          `json:"block_hash"`
	BlockBaseFee misc.BigInt            `json:"block_base_fee"`
	BlockTime    uint64                 `json:"block_time"`
	BaseFee      misc.BigInt            `json:"base_fee"`
	Logs         []ethereum.Log         `json:"logs"`
	Transactions []ethereum.Transaction `json:"transactions"`
	BlockNumber  misc.BigInt            `json:"block_number"`
}

type EthereumDecoratedTransaction

type EthereumDecoratedTransaction struct {
	Transaction ethereum.Transaction        `json:"transaction"`
	Receipt     ethereum.Receipt            `json:"receipt"`
	Transfers   []EthereumDecoratedTransfer `json:"transfers"`
}

EthereumDecoratedTransaction is a transaction, its receipt, and any associated transfers

type EthereumDecoratedTransfer

type EthereumDecoratedTransfer struct {
	TransactionHash ethereum.Hash `json:"transaction_hash"`

	// Parties involved in the swap, where sender recieves the majority
	// of a potential reward, and one party could be a smart contract
	SenderAddress ethereum.Address `json:"sender_address"`

	RecipientAddress ethereum.Address `json:"recipient_address"`

	LogIndex *misc.BigInt `json:"log_index"`

	Decorator *EthereumWorkerDecorator `json:"decorator"`

	AppEmissions EthereumAppFees `json:"app_emissions"`
}

Transfer with application information attached

type EthereumHintedBlock

type EthereumHintedBlock struct {
	BlockHash             ethereum.Hash                                  `json:"block_hash"`
	BlockBaseFee          misc.BigInt                                    `json:"block_base_fee"`
	BlockTime             uint64                                         `json:"block_time"`
	BlockNumber           misc.BigInt                                    `json:"block_number"`
	DecoratedTransactions map[ethereum.Hash]EthereumDecoratedTransaction `json:"decorated_transfers"`
}

Hinted block sent from the application server

type EthereumReward

type EthereumReward struct {
	Category        string                     `json:"category"`
	Winner          ethereum.Address           `json:"winner"`
	WinAmount       *misc.BigInt               `json:"amount"`
	Utilityname     applications.UtilityName   `json:"utility"`
	TransactionHash ethereum.Hash              `json:"transaction_hash"`
	BlockNumber     *misc.BigInt               `json:"block_number"`
	TokenDetails    token_details.TokenDetails `json:"token_details"`
	Network         network.BlockchainNetwork  `json:"network"`
}

type EthereumSpooledLpRewards

type EthereumSpooledLpRewards struct {
	Rewards map[applications.UtilityName]misc.BigInt `json:"rewards"`
	Address ethereum.Address                         `json:"address"`
}

type EthereumSpooledRewards

type EthereumSpooledRewards struct {
	Network    network.BlockchainNetwork                                     `json:"network"`
	Token      token_details.TokenDetails                                    `json:"token_details"`
	FirstBlock *misc.BigInt                                                  `json:"first_block"`
	LastBlock  *misc.BigInt                                                  `json:"last_block"`
	Rewards    map[applications.UtilityName]map[ethereum.Address]misc.BigInt `json:"rewards"`
}

type EthereumWinnerAnnouncement

type EthereumWinnerAnnouncement struct {
	Network         network.BlockchainNetwork           `json:"network"`
	TransactionHash ethereum.Hash                       `json:"transaction_hash"`
	LogIndex        *misc.BigInt                        `json:"log_index"`
	BlockNumber     *misc.BigInt                        `json:"block_number"`
	FromAddress     ethereum.Address                    `json:"from_address"`
	ToAddress       ethereum.Address                    `json:"to_address"`
	FromWinAmount   map[applications.UtilityName]Payout `json:"from_win_amount"`
	ToWinAmount     map[applications.UtilityName]Payout `json:"to_win_amount"`
	TokenDetails    token_details.TokenDetails          `json:"token_details"`
	Application     applications.Application            `json:"application"`
	Decorator       *EthereumWorkerDecorator            `json:"decorator"`
	RewardTier      int                                 `json:"reward_tier"`
}

type EthereumWorkerDecorator

type EthereumWorkerDecorator struct {
	// Enum corresponding to the application
	Application applications.Application `json:"application"`
	// optional utility corresponding to the application
	UtilityName applications.UtilityName `json:"utility_name"`
	// Application fee in USD
	ApplicationFee *big.Rat `json:"application_fee"`
	Volume         *big.Int `json:"volume"`

	ApplicationData applications.ApplicationData `json:"application_data"`
}

Decorator attached to a transfer, able to be expanded to include application data as needed

type FeeSwitch

type FeeSwitch struct {
	OriginalAddress ethereum.Address          `json:"original_address"`
	NewAddress      ethereum.Address          `json:"new_address"`
	Network         network.BlockchainNetwork `json:"network"`
}

type Payout

type Payout struct {
	// amount in native tokens, can be passed to chain
	Native misc.BigInt

	// amount normalised to usd (native/1e(decimals)*exchangeRate) for the spooler
	// this is a float and might be imprecise!
	Usd float64
}

Payout to store details on payouts in different token units

type SolanaAppFees

type SolanaAppFees struct {
	Saber    float64 `json:"saber"`
	Orca     float64 `json:"orca"`
	Raydium  float64 `json:"raydium"`
	AldrinV1 float64 `json:"aldrin_v1"`
	AldrinV2 float64 `json:"aldrin_v2"`
	Lifinity float64 `json:"lifinity"`
}

app fees for solana transactions

type SolanaApplicationTransaction

type SolanaApplicationTransaction struct {
	Signature    string                     `json:"signature"`
	Result       solana.TransactionResult   `json:"result"`
	AdjustedFee  *big.Rat                   `json:"adjusted_fee"`
	Applications []applications.Application `json:"applications"`
}

SolanaApplicationTransaction is a solana transaction that is relevant to fluidity with some added metadata

type SolanaBufferedApplicationTransactions

type SolanaBufferedApplicationTransactions struct {
	Transactions []SolanaApplicationTransaction `json:"transactions"`
	Slot         uint64                         `json:"slot"`
}

type SolanaBufferedParsedTransactions

type SolanaBufferedParsedTransactions struct {
	Transactions []SolanaParsedTransaction `json:"transactions"`
	Slot         uint64                    `json:"slot"`
}

SolanaBufferedParsedTransactions is several SolanaParsedTransaction objects, buffered by slot

type SolanaBufferedTransfers

type SolanaBufferedTransfers struct {
	Transfers            []SolanaDecoratedTransfer `json:"transfers"`
	SecondsSinceLastSlot uint64                    `json:"seconds_since_last_slot"`
}

SolanaBufferedTransfers buffers decorated transfers by slot

type SolanaDecoratedTransfer

type SolanaDecoratedTransfer struct {
	// Transaction containing the event
	Transaction SolanaApplicationTransaction `json:"transaction"`

	Token token_details.TokenDetails `json:"token_details"`

	// SPL accounts of the parties involved in the swap,
	// where sender recieves the majority of a potential reward,
	// and one party could be a smart contract
	SenderSplAddress    string `json:"sender_spl_address"`
	RecipientSplAddress string `json:"recipient_spl_address"`

	// addresses of the accounts that own the SPL accounts
	SenderOwnerAddress    string `json:"sender_owner_address"`
	RecipientOwnerAddress string `json:"recipient_owner_address"`

	Decorator *SolanaWorkerDecorator `json:"decorator"`

	AppEmissions SolanaAppFees `json:"app_emissions"`
}

SolanaDecoratedTransfer contains a solana transfer, and optionally, an adjusted app fee

type SolanaParsedTransaction

type SolanaParsedTransaction struct {
	Transaction SolanaApplicationTransaction `json:"transaction"`
	Transfers   []user_actions.UserAction    `json:"transfers"`
}

SolanaParsedTransaction is a solana transaction with spl user actions

type SolanaWinnerAnnouncement

type SolanaWinnerAnnouncement struct {
	WinningTransactionHash string   `json:"transaction_winning"`
	SenderAddress          string   `json:"sender_address"`
	RecipientAddress       string   `json:"receiver_address"`
	WinningAmount          uint64   `json:"winning_amount"`
	TokenName              string   `json:"token_name"`
	FluidMintPubkey        string   `json:"fluid_mint_pubkey"`
	Emissions              Emission `json:"emissions"`
}

SolanaWinnerAnnouncement to use to report a winner and its randomness

type SolanaWork

type SolanaWork struct {
	BufferedTransfers SolanaBufferedTransfers `json:"buffered_transfers"`
	Tvl               uint64                  `json:"tvl"`
	MintSupply        uint64                  `json:"mint_supply"`
}

SolanaWork augments SolanaBufferedTransfers with tvl and mint details

type SolanaWorkerDecorator

type SolanaWorkerDecorator struct {
	ApplicationFee *big.Rat `json:"application_fee"`
}

SolanaWorkerDecorator contains an adjusted application fee (able to be expanded with more specific app details)

type SpecialPoolOptions

type SpecialPoolOptions struct {
	PayoutFreqOverride     *big.Rat
	DeltaWeightOverride    *big.Rat
	WinningClassesOverride int
}

type SuiAppFees

type SuiAppFees struct {
}

app fees for sui transactions

type SuiWorkerDecorator

type SuiWorkerDecorator struct {
	// SuiAppFees for emissions
	SuiAppFees SuiAppFees `json:"sui_app_fees"`
	// optional utility corresponding to the application
	UtilityName applications.UtilityName `json:"utility_name"`
	// Application fee in USD
	ApplicationFee *big.Rat `json:"application_fee"`
	Volume         *big.Rat `json:"volume"`
}

type TransferWithFee

type TransferWithFee struct {
	UserAction user_actions.UserAction
	Event      *models.SuiEventResponse
	Checkpoint misc.BigInt
	Decorator  *SuiWorkerDecorator
}

type TrfMode

type TrfMode string

TrfMode allows switching trf features

const (
	// TrfModeNormal to indicate normal trf operation
	TrfModeNormal TrfMode = "normal"

	// TrfModeNoOptimisticSolution to disable the optimistic solution
	TrfModeNoOptimisticSolution TrfMode = "no optimistic solution"
)

type UtilityVars

type UtilityVars struct {
	// Name is the unique onchain id for this utility
	Name applications.UtilityName `json:"utility_name"`

	// PoolSizeNative is the amount of token to distribute in native tokens
	PoolSizeNative *big.Rat `json:"pool_size"`

	// TokenDecimalsScale is 1e(decimals)
	TokenDecimalsScale *big.Rat `json:"token_decimals"`

	// ExchangeRate is the number for which (usd value)/(exchange rate)*(decimal scale) = (native amount)
	ExchangeRate *big.Rat `json:"exchange_rate"`

	// DeltaWeight is the frequency with which to distribute tokens
	// For normal tokens, this is the number of seconds in a year (31536000)
	DeltaWeight *big.Rat `json:"delta_weight"`

	CalculationType CalculationType `json:"calculation_method"`
}

UtilityVars to store the amount of token and its distribution rate, for payout calculations

func (UtilityVars) DebugString

func (v UtilityVars) DebugString() string

DebugString the UtilityVars, returning "name:pool size:token decimals scale:exchange rate:delta weight" for logging purposes

type WorkerConfigEthereum

type WorkerConfigEthereum struct {
	Network                       network.BlockchainNetwork `json:"network"`
	CompoundBlocksPerDay          int                       `json:"compound_blocks_per_day"`
	DefaultSecondsSinceLastBlock  float64                   `json:"default_seconds_since_last_block"`
	CurrentAtxTransactionMargin   int64                     `json:"current_atx_transaction_margin"`
	DefaultTransfersInBlock       int                       `json:"default_transfers_in_block"`
	AtxBufferSize                 int                       `json:"atx_buffer_size"`
	EpochBlocks                   int                       `json:"epoch_blocks"`
	YieldToStakers                bool                      `json:"yield_to_stakers"`
	SpoolerInstantRewardThreshold float64                   `json:"spooler_instant_reward_threshold"`
	SpoolerBatchedRewardThreshold float64                   `json:"spooler_batched_reward_threshold"`
}

WorkerConfigEthereum to be used with any EVM chains to store config that was previously hardcoded

type WorkerConfigSolana

type WorkerConfigSolana struct {
	SolanaBlockTime uint64 `json:"solana_block_time"`
	TransferCompute int    `json:"transfer_compute"`
	AtxBufferSize   int    `json:"atx_buffer_size"`
}

WorkerConfigSolana that was previously hardcoded for Solana only

type WorkerConfigSui

type WorkerConfigSui struct {
	SuiBlockTime                  uint64  `json:"sui_block_time"`
	SpoolerInstantRewardThreshold float64 `json:"spooler_instant_reward_threshold"`
	SpoolerBatchedRewardThreshold float64 `json:"spooler_batched_reward_threshold"`
}

WorkerConfigSui that was previously hardcoded for Sui only

Jump to

Keyboard shortcuts

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