staking

package
v4.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DelegateGas           = 40_000 // 98000 - 160000 // 165000
	UndelegateGas         = 45_000 // 94000 - 163000 // 172000
	WithdrawGas           = 30_000 // 94000 // 120000
	DelegationGas         = 30_000 // 98000
	DelegationRewardsGas  = 30_000 // 94000
	TransferSharesGas     = 50_000 // 134000 - 190000
	ApproveSharesGas      = 10_000 // 4400
	AllowanceSharesGas    = 5_000  // 1240
	TransferFromSharesGas = 60_000 // 134000 - 200000

	DelegateMethodName           = "delegate"
	UndelegateMethodName         = "undelegate"
	WithdrawMethodName           = "withdraw"
	DelegationMethodName         = "delegation"
	DelegationRewardsMethodName  = "delegationRewards"
	ApproveSharesMethodName      = "approveShares"
	AllowanceSharesMethodName    = "allowanceShares"
	TransferSharesMethodName     = "transferShares"
	TransferFromSharesMethodName = "transferFromShares"

	DelegateEventName       = "Delegate"
	UndelegateEventName     = "Undelegate"
	WithdrawEventName       = "Withdraw"
	TransferSharesEventName = "TransferShares"
	ApproveSharesEventName  = "ApproveShares"
)

Variables

View Source
var (
	ApproveSharesEvent = abi.NewEvent(
		ApproveSharesEventName,
		ApproveSharesEventName,
		false,
		abi.Arguments{
			abi.Argument{Name: "owner", Type: types.TypeAddress, Indexed: true},
			abi.Argument{Name: "spender", Type: types.TypeAddress, Indexed: true},
			abi.Argument{Name: "validator", Type: types.TypeString, Indexed: false},
			abi.Argument{Name: "shares", Type: types.TypeUint256, Indexed: false},
		},
	)

	DelegateEvent = abi.NewEvent(
		DelegateEventName,
		DelegateEventName,
		false,
		abi.Arguments{
			abi.Argument{Name: "delegator", Type: types.TypeAddress, Indexed: true},
			abi.Argument{Name: "validator", Type: types.TypeString, Indexed: false},
			abi.Argument{Name: "amount", Type: types.TypeUint256, Indexed: false},
			abi.Argument{Name: "shares", Type: types.TypeUint256, Indexed: false},
		},
	)

	TransferSharesEvent = abi.NewEvent(
		TransferSharesEventName,
		TransferSharesEventName,
		false,
		abi.Arguments{
			abi.Argument{Name: "from", Type: types.TypeAddress, Indexed: true},
			abi.Argument{Name: "to", Type: types.TypeAddress, Indexed: true},
			abi.Argument{Name: "validator", Type: types.TypeString, Indexed: false},
			abi.Argument{Name: "shares", Type: types.TypeUint256, Indexed: false},
			abi.Argument{Name: "token", Type: types.TypeUint256, Indexed: false},
		},
	)

	UndelegateEvent = abi.NewEvent(
		UndelegateEventName,
		UndelegateEventName,
		false,
		abi.Arguments{
			abi.Argument{Name: "sender", Type: types.TypeAddress, Indexed: true},
			abi.Argument{Name: "validator", Type: types.TypeString, Indexed: false},
			abi.Argument{Name: "shares", Type: types.TypeUint256, Indexed: false},
			abi.Argument{Name: "amount", Type: types.TypeUint256, Indexed: false},
			abi.Argument{Name: "completionTime", Type: types.TypeUint256, Indexed: false},
		},
	)

	WithdrawEvent = abi.NewEvent(
		WithdrawEventName,
		WithdrawEventName,
		false,
		abi.Arguments{
			abi.Argument{Name: "sender", Type: types.TypeAddress, Indexed: true},
			abi.Argument{Name: "validator", Type: types.TypeString, Indexed: false},
			abi.Argument{Name: "reward", Type: types.TypeUint256, Indexed: false},
		},
	)
)
View Source
var (
	// AllowanceSharesMethod Query the amount of shares an owner allowed to a spender.
	AllowanceSharesMethod = abi.NewMethod(
		AllowanceSharesMethodName,
		AllowanceSharesMethodName,
		abi.Function, "view", false, false,
		abi.Arguments{
			abi.Argument{Name: "_val", Type: types.TypeString},
			abi.Argument{Name: "_owner", Type: types.TypeAddress},
			abi.Argument{Name: "_spender", Type: types.TypeAddress},
		},
		abi.Arguments{
			abi.Argument{Name: "_shares", Type: types.TypeUint256},
		},
	)

	// DelegationMethod Query the amount of shares in val.
	DelegationMethod = abi.NewMethod(
		DelegationMethodName,
		DelegationMethodName,
		abi.Function, "view", false, false,
		abi.Arguments{
			abi.Argument{Name: "_val", Type: types.TypeString},
			abi.Argument{Name: "_del", Type: types.TypeAddress},
		},
		abi.Arguments{
			abi.Argument{Name: "_shares", Type: types.TypeUint256},
			abi.Argument{Name: "_delegateAmount", Type: types.TypeUint256},
		},
	)

	// DelegationRewardsMethod Query the amount of rewards in val.
	DelegationRewardsMethod = abi.NewMethod(
		DelegationRewardsMethodName,
		DelegationRewardsMethodName,
		abi.Function, "view", false, false,
		abi.Arguments{
			abi.Argument{Name: "_val", Type: types.TypeString},
			abi.Argument{Name: "_del", Type: types.TypeAddress},
		},
		abi.Arguments{
			abi.Argument{Name: "_reward", Type: types.TypeUint256},
		},
	)
)
View Source
var (
	// ApproveSharesMethod Approve shares to a spender.
	ApproveSharesMethod = abi.NewMethod(
		ApproveSharesMethodName,
		ApproveSharesMethodName,
		abi.Function, "nonpayable", false, false,
		abi.Arguments{
			abi.Argument{Name: "_val", Type: types.TypeString},
			abi.Argument{Name: "_spender", Type: types.TypeAddress},
			abi.Argument{Name: "_shares", Type: types.TypeUint256},
		},
		abi.Arguments{
			abi.Argument{Name: "_result", Type: types.TypeBool},
		},
	)

	// DelegateMethod Delegate token to a validator.
	DelegateMethod = abi.NewMethod(
		DelegateMethodName,
		DelegateMethodName,
		abi.Function, "payable", false, false,
		abi.Arguments{
			abi.Argument{Name: "_val", Type: types.TypeString},
		},
		abi.Arguments{
			abi.Argument{Name: "_shares", Type: types.TypeUint256},
			abi.Argument{Name: "_reward", Type: types.TypeUint256},
		},
	)

	// TransferSharesMethod Transfer shares to a recipient.
	TransferSharesMethod = abi.NewMethod(
		TransferSharesMethodName,
		TransferSharesMethodName,
		abi.Function, "nonpayable", false, false,
		abi.Arguments{
			abi.Argument{Name: "_val", Type: types.TypeString},
			abi.Argument{Name: "_to", Type: types.TypeAddress},
			abi.Argument{Name: "_shares", Type: types.TypeUint256},
		},
		abi.Arguments{
			abi.Argument{Name: "_token", Type: types.TypeUint256},
			abi.Argument{Name: "_reward", Type: types.TypeUint256},
		},
	)

	// TransferFromSharesMethod Transfer shares from a sender to a recipient.
	TransferFromSharesMethod = abi.NewMethod(
		TransferFromSharesMethodName,
		TransferFromSharesMethodName,
		abi.Function, "nonpayable", false, false,
		abi.Arguments{
			abi.Argument{Name: "_val", Type: types.TypeString},
			abi.Argument{Name: "_from", Type: types.TypeAddress},
			abi.Argument{Name: "_to", Type: types.TypeAddress},
			abi.Argument{Name: "_shares", Type: types.TypeUint256},
		},
		abi.Arguments{
			abi.Argument{Name: "_token", Type: types.TypeUint256},
			abi.Argument{Name: "_reward", Type: types.TypeUint256},
		},
	)

	// UndelegateMethod Undelegate shares from a validator.
	UndelegateMethod = abi.NewMethod(
		UndelegateMethodName,
		UndelegateMethodName,
		abi.Function, "nonpayable", false, false,
		abi.Arguments{
			abi.Argument{Name: "_val", Type: types.TypeString},
			abi.Argument{Name: "_shares", Type: types.TypeUint256},
		},
		abi.Arguments{
			abi.Argument{Name: "_amount", Type: types.TypeUint256},
			abi.Argument{Name: "_reward", Type: types.TypeUint256},
			abi.Argument{Name: "_completionTime", Type: types.TypeUint256},
		},
	)

	// WithdrawMethod Withdraw rewards from a validator.
	WithdrawMethod = abi.NewMethod(
		WithdrawMethodName,
		WithdrawMethodName,
		abi.Function, "nonpayable", false, false,
		abi.Arguments{
			abi.Argument{Name: "_val", Type: types.TypeString},
		},
		abi.Arguments{
			abi.Argument{Name: "_reward", Type: types.TypeUint256},
		},
	)
)

Functions

func ApproveSharesEmitEvents

func ApproveSharesEmitEvents(ctx sdk.Context, validator sdk.ValAddress, owner, spender sdk.AccAddress, shares sdkmath.Int)

func DelegateEmitEvents

func DelegateEmitEvents(ctx sdk.Context, delegator sdk.AccAddress, validator sdk.ValAddress, amount *big.Int, newShares sdk.Dec)

func GetABI

func GetABI() abi.ABI

func GetAddress

func GetAddress() common.Address

func TransferSharesEmitEvents

func TransferSharesEmitEvents(ctx sdk.Context, validator sdk.ValAddress, from, recipient sdk.AccAddress, shares, token sdkmath.Int)

func Undelegate

func Undelegate(ctx sdk.Context, sk StakingKeeper, bk BankKeeper, delAddr sdk.AccAddress,
	valAddr sdk.ValAddress, shares sdk.Dec, bondDenom string,
) (sdkmath.Int, time.Time, error)

func UndelegateEmitEvents

func UndelegateEmitEvents(ctx sdk.Context, delegator sdk.AccAddress, validator sdk.ValAddress, amount sdkmath.Int, completionTime time.Time)

func WithdrawEmitEvents

func WithdrawEmitEvents(ctx sdk.Context, delegator sdk.AccAddress, amount sdk.Coins)

Types

type AllowanceSharesArgs

type AllowanceSharesArgs struct {
	Validator string         `abi:"_val"`
	Owner     common.Address `abi:"_owner"`
	Spender   common.Address `abi:"_spender"`
}

func (*AllowanceSharesArgs) GetValidator

func (args *AllowanceSharesArgs) GetValidator() sdk.ValAddress

GetValidator returns the validator address, caller must ensure the validator address is valid

func (*AllowanceSharesArgs) Validate

func (args *AllowanceSharesArgs) Validate() error

Validate validates the args

type ApproveSharesArgs

type ApproveSharesArgs struct {
	Validator string         `abi:"_val"`
	Spender   common.Address `abi:"_spender"`
	Shares    *big.Int       `abi:"_shares"`
}

func (*ApproveSharesArgs) GetValidator

func (args *ApproveSharesArgs) GetValidator() sdk.ValAddress

GetValidator returns the validator address, caller must ensure the validator address is valid

func (*ApproveSharesArgs) Validate

func (args *ApproveSharesArgs) Validate() error

Validate validates the args

type BankKeeper

type BankKeeper interface {
	MintCoins(ctx sdk.Context, moduleName string, amounts sdk.Coins) error
	SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
	SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error
}

type Contract

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

func NewPrecompiledContract

func NewPrecompiledContract(
	ctx sdk.Context,
	bankKeeper BankKeeper,
	stakingKeeper StakingKeeper,
	distrKeeper DistrKeeper,
	evmKeeper EvmKeeper,
) *Contract

func (*Contract) AddLog

func (c *Contract) AddLog(evm *vm.EVM, event abi.Event, topics []common.Hash, args ...interface{}) error

func (*Contract) Address

func (c *Contract) Address() common.Address

func (*Contract) AllowanceShares

func (c *Contract) AllowanceShares(ctx sdk.Context, _ *vm.EVM, contract *vm.Contract, _ bool) ([]byte, error)

func (*Contract) ApproveShares

func (c *Contract) ApproveShares(ctx sdk.Context, evm *vm.EVM, contract *vm.Contract, readonly bool) ([]byte, error)

func (*Contract) Delegate

func (c *Contract) Delegate(ctx sdk.Context, evm *vm.EVM, contract *vm.Contract, readonly bool) ([]byte, error)

func (*Contract) Delegation

func (c *Contract) Delegation(ctx sdk.Context, _ *vm.EVM, contract *vm.Contract, _ bool) ([]byte, error)

func (*Contract) DelegationRewards

func (c *Contract) DelegationRewards(ctx sdk.Context, _ *vm.EVM, contract *vm.Contract, _ bool) ([]byte, error)

func (*Contract) IsStateful

func (c *Contract) IsStateful() bool

func (*Contract) RequiredGas

func (c *Contract) RequiredGas(input []byte) uint64

func (*Contract) Run

func (c *Contract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) (ret []byte, err error)

func (*Contract) TransferFromShares

func (c *Contract) TransferFromShares(ctx sdk.Context, evm *vm.EVM, contract *vm.Contract, readonly bool) ([]byte, error)

func (*Contract) TransferShares

func (c *Contract) TransferShares(ctx sdk.Context, evm *vm.EVM, contract *vm.Contract, readonly bool) ([]byte, error)

func (*Contract) Undelegate

func (c *Contract) Undelegate(ctx sdk.Context, evm *vm.EVM, contract *vm.Contract, readonly bool) ([]byte, error)

func (*Contract) Withdraw

func (c *Contract) Withdraw(ctx sdk.Context, evm *vm.EVM, contract *vm.Contract, readonly bool) ([]byte, error)

type DelegateArgs

type DelegateArgs struct {
	Validator string `abi:"_val"`
}

func (*DelegateArgs) GetValidator

func (args *DelegateArgs) GetValidator() sdk.ValAddress

GetValidator returns the validator address, caller must ensure the validator address is valid

func (*DelegateArgs) Validate

func (args *DelegateArgs) Validate() error

Validate validates the args

type DelegationArgs

type DelegationArgs struct {
	Validator string         `abi:"_val"`
	Delegator common.Address `abi:"_del"`
}

func (*DelegationArgs) GetValidator

func (args *DelegationArgs) GetValidator() sdk.ValAddress

GetValidator returns the validator address, caller must ensure the validator address is valid

func (*DelegationArgs) Validate

func (args *DelegationArgs) Validate() error

Validate validates the args

type DelegationRewardsArgs

type DelegationRewardsArgs struct {
	Validator string         `abi:"_val"`
	Delegator common.Address `abi:"_del"`
}

func (*DelegationRewardsArgs) GetValidator

func (args *DelegationRewardsArgs) GetValidator() sdk.ValAddress

GetValidator returns the validator address, caller must ensure the validator address is valid

func (*DelegationRewardsArgs) Validate

func (args *DelegationRewardsArgs) Validate() error

Validate validates the args

type DistrKeeper

type DistrKeeper interface {
	WithdrawDelegationRewards(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (sdk.Coins, error)
	GetDelegatorWithdrawAddr(ctx sdk.Context, delAddr sdk.AccAddress) sdk.AccAddress
	IncrementValidatorPeriod(ctx sdk.Context, val stakingtypes.ValidatorI) uint64
	CalculateDelegationRewards(ctx sdk.Context, val stakingtypes.ValidatorI, del stakingtypes.DelegationI, endingPeriod uint64) (rewards sdk.DecCoins)
	GetDelegatorStartingInfo(ctx sdk.Context, val sdk.ValAddress, del sdk.AccAddress) (period distrtypes.DelegatorStartingInfo)
	SetDelegatorStartingInfo(ctx sdk.Context, val sdk.ValAddress, del sdk.AccAddress, period distrtypes.DelegatorStartingInfo)
	DeleteDelegatorStartingInfo(ctx sdk.Context, val sdk.ValAddress, del sdk.AccAddress)
	GetValidatorCurrentRewards(ctx sdk.Context, val sdk.ValAddress) (rewards distrtypes.ValidatorCurrentRewards)
	GetValidatorHistoricalRewards(ctx sdk.Context, val sdk.ValAddress, period uint64) (rewards distrtypes.ValidatorHistoricalRewards)
	SetValidatorHistoricalRewards(ctx sdk.Context, val sdk.ValAddress, period uint64, rewards distrtypes.ValidatorHistoricalRewards)
	DeleteValidatorHistoricalReward(ctx sdk.Context, val sdk.ValAddress, period uint64)
}

type EvmKeeper

type EvmKeeper interface {
	GetParams(ctx sdk.Context) evmtypes.Params
}

type StakingKeeper

type StakingKeeper interface {
	GetDelegation(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (delegation stakingtypes.Delegation, found bool)
	SetDelegation(ctx sdk.Context, delegation stakingtypes.Delegation)
	RemoveDelegation(ctx sdk.Context, delegation stakingtypes.Delegation) error
	GetValidator(ctx sdk.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, found bool)
	Delegate(ctx sdk.Context, delAddr sdk.AccAddress, bondAmt sdkmath.Int, tokenSrc stakingtypes.BondStatus,
		validator stakingtypes.Validator, subtractAccount bool) (newShares sdk.Dec, err error)
	HasMaxUnbondingDelegationEntries(ctx sdk.Context, delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress) bool
	Unbond(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, shares sdk.Dec) (amount sdkmath.Int, err error)
	UnbondingTime(ctx sdk.Context) (res time.Duration)
	SetUnbondingDelegationEntry(ctx sdk.Context, delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress,
		creationHeight int64, minTime time.Time, balance sdkmath.Int) stakingtypes.UnbondingDelegation
	InsertUBDQueue(ctx sdk.Context, ubd stakingtypes.UnbondingDelegation, completionTime time.Time)
	GetAllowance(ctx sdk.Context, valAddr sdk.ValAddress, owner, spender sdk.AccAddress) *big.Int
	SetAllowance(ctx sdk.Context, valAddr sdk.ValAddress, owner, spender sdk.AccAddress, shares *big.Int)
	HasReceivingRedelegation(ctx sdk.Context, delAddr sdk.AccAddress, valDstAddr sdk.ValAddress) bool
}

type TransferFromSharesArgs

type TransferFromSharesArgs struct {
	Validator string         `abi:"_val"`
	From      common.Address `abi:"_from"`
	To        common.Address `abi:"_to"`
	Shares    *big.Int       `abi:"_shares"`
}

func (*TransferFromSharesArgs) GetValidator

func (args *TransferFromSharesArgs) GetValidator() sdk.ValAddress

GetValidator returns the validator address, caller must ensure the validator address is valid

func (*TransferFromSharesArgs) Validate

func (args *TransferFromSharesArgs) Validate() error

Validate validates the args

type TransferSharesArgs

type TransferSharesArgs struct {
	Validator string         `abi:"_val"`
	To        common.Address `abi:"_to"`
	Shares    *big.Int       `abi:"_shares"`
}

func (*TransferSharesArgs) GetValidator

func (args *TransferSharesArgs) GetValidator() sdk.ValAddress

GetValidator returns the validator address, caller must ensure the validator address is valid

func (*TransferSharesArgs) Validate

func (args *TransferSharesArgs) Validate() error

Validate validates the args

type UndelegateArgs

type UndelegateArgs struct {
	Validator string   `abi:"_val"`
	Shares    *big.Int `abi:"_shares"`
}

func (*UndelegateArgs) GetValidator

func (args *UndelegateArgs) GetValidator() sdk.ValAddress

GetValidator returns the validator address, caller must ensure the validator address is valid

func (*UndelegateArgs) Validate

func (args *UndelegateArgs) Validate() error

Validate validates the args

type WithdrawArgs

type WithdrawArgs struct {
	Validator string `abi:"_val"`
}

func (*WithdrawArgs) GetValidator

func (args *WithdrawArgs) GetValidator() sdk.ValAddress

GetValidator returns the validator address, caller must ensure the validator address is valid

func (*WithdrawArgs) Validate

func (args *WithdrawArgs) Validate() error

Validate validates the args

Jump to

Keyboard shortcuts

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