rewardmanager

package
v0.6.12 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: GPL-3.0, LGPL-3.0 Imports: 11 Imported by: 3

Documentation

Index

Constants

View Source
const (
	AllowFeeRecipientsGasCost      uint64 = contract.WriteGasCostPerSlot + allowlist.ReadAllowListGasCost // write 1 slot + read allow list
	AreFeeRecipientsAllowedGasCost uint64 = allowlist.ReadAllowListGasCost
	CurrentRewardAddressGasCost    uint64 = allowlist.ReadAllowListGasCost
	DisableRewardsGasCost          uint64 = contract.WriteGasCostPerSlot + allowlist.ReadAllowListGasCost // write 1 slot + read allow list
	SetRewardAddressGasCost        uint64 = contract.WriteGasCostPerSlot + allowlist.ReadAllowListGasCost // write 1 slot + read allow list
)
View Source
const (
	// FeeRecipientsAllowedEventGasCost is the gas cost of the FeeRecipientsAllowed event.
	// It is calculated as the gas cost of the log operation + the gas cost of 2 topic hashes (signature + sender).
	FeeRecipientsAllowedEventGasCost = contract.LogGas + contract.LogTopicGas*2
	// RewardAddressChangedEventGasCost is the gas cost of the RewardAddressChanged event.
	// It is calculated as the gas cost of the log operation + the gas cost of 3 topic hashes (signature + sender + oldRewardAddress).
	// + the gas cost of reading old reward address.
	RewardAddressChangedEventGasCost = contract.LogGas + contract.LogTopicGas*4 + contract.ReadGasCostPerSlot
	// RewardsDisabledEventGasCost is the gas cost of the RewardsDisabled event.
	// It is calculated as the gas cost of the log operation + the gas cost of 2 topic hashes (signature + sender).
	RewardsDisabledEventGasCost = contract.LogGas + contract.LogTopicGas*2
)
View Source
const ConfigKey = "rewardManagerConfig"

ConfigKey is the key used in json config files to specify this precompile config. must be unique across all precompiles.

Variables

View Source
var (
	ErrCannotAllowFeeRecipients      = errors.New("non-enabled cannot call allowFeeRecipients")
	ErrCannotAreFeeRecipientsAllowed = errors.New("non-enabled cannot call areFeeRecipientsAllowed")
	ErrCannotCurrentRewardAddress    = errors.New("non-enabled cannot call currentRewardAddress")
	ErrCannotDisableRewards          = errors.New("non-enabled cannot call disableRewards")
	ErrCannotSetRewardAddress        = errors.New("non-enabled cannot call setRewardAddress")

	ErrCannotEnableBothRewards = errors.New("cannot enable both fee recipients and reward address at the same time")
	ErrEmptyRewardAddress      = errors.New("reward address cannot be empty")

	// RewardManagerRawABI contains the raw ABI of RewardManager contract.
	//go:embed contract.abi
	RewardManagerRawABI string

	RewardManagerABI        = contract.ParseABI(RewardManagerRawABI)
	RewardManagerPrecompile = createRewardManagerPrecompile() // will be initialized by init function

)

Singleton StatefulPrecompiledContract and signatures.

View Source
var ContractAddress = common.HexToAddress("0x0200000000000000000000000000000000000004")
View Source
var Module = modules.Module{
	ConfigKey:    ConfigKey,
	Address:      ContractAddress,
	Contract:     RewardManagerPrecompile,
	Configurator: &configurator{},
}

Module is the precompile module. It is used to register the precompile contract.

Functions

func DisableFeeRewards

func DisableFeeRewards(stateDB contract.StateDB)

DisableRewardAddress disables rewards and burns them by sending to Blackhole Address.

func EnableAllowFeeRecipients

func EnableAllowFeeRecipients(stateDB contract.StateDB)

EnableAllowFeeRecipients enables fee recipients.

func GetRewardManagerAllowListStatus

func GetRewardManagerAllowListStatus(stateDB contract.StateDB, address common.Address) allowlist.Role

GetRewardManagerAllowListStatus returns the role of [address] for the RewardManager list.

func GetStoredRewardAddress

func GetStoredRewardAddress(stateDB contract.StateDB) (common.Address, bool)

GetStoredRewardAddress returns the current value of the address stored under rewardAddressStorageKey. Returns an empty address and true if allow fee recipients is enabled, otherwise returns current reward address and false.

func PackAllowFeeRecipients

func PackAllowFeeRecipients() ([]byte, error)

PackAllowFeeRecipients packs the function selector (first 4 func signature bytes). This function is mostly used for tests.

func PackAreFeeRecipientsAllowed

func PackAreFeeRecipientsAllowed() ([]byte, error)

PackAreFeeRecipientsAllowed packs the include selector (first 4 func signature bytes). This function is mostly used for tests.

func PackAreFeeRecipientsAllowedOutput

func PackAreFeeRecipientsAllowedOutput(isAllowed bool) ([]byte, error)

PackAreFeeRecipientsAllowedOutput attempts to pack given isAllowed of type bool to conform the ABI outputs.

func PackCurrentRewardAddress

func PackCurrentRewardAddress() ([]byte, error)

PackCurrentRewardAddress packs the include selector (first 4 func signature bytes). This function is mostly used for tests.

func PackCurrentRewardAddressOutput

func PackCurrentRewardAddressOutput(rewardAddress common.Address) ([]byte, error)

PackCurrentRewardAddressOutput attempts to pack given rewardAddress of type common.Address to conform the ABI outputs.

func PackDisableRewards

func PackDisableRewards() ([]byte, error)

PackDisableRewards packs the include selector (first 4 func signature bytes). This function is mostly used for tests.

func PackFeeRecipientsAllowedEvent added in v0.5.11

func PackFeeRecipientsAllowedEvent(sender common.Address) ([]common.Hash, []byte, error)

PackFeeRecipientsAllowedEvent packs the event into the appropriate arguments for FeeRecipientsAllowed. It returns topic hashes and the encoded non-indexed data.

func PackRewardAddressChangedEvent added in v0.5.11

func PackRewardAddressChangedEvent(sender common.Address, oldRewardAddress common.Address, newRewardAddress common.Address) ([]common.Hash, []byte, error)

PackRewardAddressChangedEvent packs the event into the appropriate arguments for RewardAddressChanged. It returns topic hashes and the encoded non-indexed data.

func PackRewardsDisabledEvent added in v0.5.11

func PackRewardsDisabledEvent(sender common.Address) ([]common.Hash, []byte, error)

PackRewardsDisabledEvent packs the event into the appropriate arguments for RewardsDisabled. It returns topic hashes and the encoded non-indexed data.

func PackSetRewardAddress

func PackSetRewardAddress(addr common.Address) ([]byte, error)

PackSetRewardAddress packs [addr] of type common.Address into the appropriate arguments for setRewardAddress. the packed bytes include selector (first 4 func signature bytes). This function is mostly used for tests.

func SetRewardManagerAllowListStatus

func SetRewardManagerAllowListStatus(stateDB contract.StateDB, address common.Address, role allowlist.Role)

SetRewardManagerAllowListStatus sets the permissions of [address] to [role] for the RewardManager list. Assumes [role] has already been verified as valid.

func StoreRewardAddress

func StoreRewardAddress(stateDB contract.StateDB, val common.Address)

StoredRewardAddress stores the given [val] under rewardAddressStorageKey.

func UnpackSetRewardAddressInput

func UnpackSetRewardAddressInput(input []byte, useStrictMode bool) (common.Address, error)

UnpackSetRewardAddressInput attempts to unpack [input] into the common.Address type argument assumes that [input] does not include selector (omits first 4 func signature bytes) if [useStrictMode] is true, it will return an error if the length of [input] is not divisible by 32

Types

type Config

type Config struct {
	allowlist.AllowListConfig
	precompileconfig.Upgrade
	InitialRewardConfig *InitialRewardConfig `json:"initialRewardConfig,omitempty"`
}

Config implements the StatefulPrecompileConfig interface while adding in the RewardManager specific precompile config.

func NewConfig

func NewConfig(blockTimestamp *uint64, admins []common.Address, enableds []common.Address, managers []common.Address, initialConfig *InitialRewardConfig) *Config

NewConfig returns a config for a network upgrade at [blockTimestamp] that enables RewardManager with the given [admins], [enableds] and [managers] as members of the allowlist with [initialConfig] as initial rewards config if specified.

func NewDisableConfig

func NewDisableConfig(blockTimestamp *uint64) *Config

NewDisableConfig returns config for a network upgrade at [blockTimestamp] that disables RewardManager.

func (*Config) Equal

func (c *Config) Equal(cfg precompileconfig.Config) bool

Equal returns true if [cfg] is a [*RewardManagerConfig] and it has been configured identical to [c].

func (*Config) Key

func (*Config) Key() string

Key returns the key for the Contract precompileconfig. This should be the same key as used in the precompile module.

func (*Config) Verify

func (c *Config) Verify(chainConfig precompileconfig.ChainConfig) error

Verify tries to verify Config and returns an error accordingly.

type InitialRewardConfig

type InitialRewardConfig struct {
	AllowFeeRecipients bool           `json:"allowFeeRecipients"`
	RewardAddress      common.Address `json:"rewardAddress,omitempty"`
}

func (*InitialRewardConfig) Configure

func (i *InitialRewardConfig) Configure(state contract.StateDB) error

func (*InitialRewardConfig) Equal

func (i *InitialRewardConfig) Equal(other *InitialRewardConfig) bool

func (*InitialRewardConfig) Verify

func (i *InitialRewardConfig) Verify() error

Jump to

Keyboard shortcuts

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