rewardmanager

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: GPL-3.0, LGPL-3.0 Imports: 12 Imported by: 0

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 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{},
}

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 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) error

StoredRewardAddress stores the given [val] under rewardAddressStorageKey.

func UnpackSetRewardAddressInput

func UnpackSetRewardAddressInput(input []byte) (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)

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 *big.Int, admins []common.Address, enableds []common.Address, initialConfig *InitialRewardConfig) *Config

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

func NewDisableConfig

func NewDisableConfig(blockTimestamp *big.Int) *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

func (*Config) Verify

func (c *Config) Verify() error

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