# IStakeManager

The StakeManager Interface

In order to prevent an attacker from registering a large number of unresponsive relays, the GSN requires the Relay Server to maintain a permanently locked stake in the system before being able to register.

Also, in some cases the behavior of a Relay Server may be found to be illegal by a Penalizer contract. In such case, the stake will never be returned to the Relay Server operator and will be slashed.

An implementation of this interface is tasked with keeping Relay Servers' stakes, made in any ERC-20 token. Note that the RelayHub chooses which ERC-20 tokens to support and how much stake is needed.

# Functions

# setRelayManagerOwner(address owner)

(external)

Set the owner of a Relay Manager. Called only by the RelayManager itself. Note that owners cannot transfer ownership - if the entry already exists, reverts.

owner: - owner of the relay (as configured off-chain)


# stakeForRelayManager(contract IERC20 token, address relayManager, uint256 unstakeDelay, uint256 amount)

(external)

Put a stake for a relayManager and set its unstake delay. Only the owner can call this function. If the entry does not exist, reverts. The owner must give allowance of the ERC-20 token to the StakeManager before calling this method. It is the RelayHub who has a configurable list of minimum stakes per token. StakeManager accepts all tokens.

token: The address of an ERC-20 token that is used by the relayManager as a stake

relayManager: The address that represents a stake entry and controls relay registrations on relay hubs

unstakeDelay: The number of seconds to elapse before an owner can retrieve the stake after calling unlock

amount: The amount of tokens to be taken from the relayOwner and locked in the StakeManager as a stake


# unlockStake(address relayManager)

(external)

Schedule the unlocking of the stake. The unstakeDelay must pass before owner can call withdrawStake.

relayManager: The address of a Relay Manager whose stake is to be unlocked.


# withdrawStake(address relayManager)

(external)

Withdraw the unlocked stake.

relayManager: The address of a Relay Manager whose stake is to be withdrawn.


# authorizeHubByOwner(address relayManager, address relayHub)

(external)

Add the RelayHub to a list of authorized by this Relay Manager. This allows the RelayHub to penalize this Relay Manager. The RelayHub cannot trust a Relay it cannot penalize.

relayManager: The address of a Relay Manager whose stake is to be authorized for the new RelayHub.

relayHub: The address of a RelayHub to be authorized.


# authorizeHubByManager(address relayHub)

(external)

Same as authorizeHubByOwner but can be called by the RelayManager itself.


# unauthorizeHubByOwner(address relayManager, address relayHub)

(external)

Remove the RelayHub from a list of authorized by this Relay Manager.

relayManager: The address of a Relay Manager.

relayHub: The address of a RelayHub to be unauthorized.


# unauthorizeHubByManager(address relayHub)

(external)

Same as unauthorizeHubByOwner but can be called by the RelayManager itself.


# penalizeRelayManager(address relayManager, address beneficiary, uint256 amount)

(external)

Slash the stake of the relay relayManager. In order to prevent stake kidnapping, burns part of stake on the way.

relayManager: The address of a Relay Manager to be penalized.

beneficiary: The address that receives part of the penalty amount.

amount: A total amount of penalty to be withdrawn from stake.


# markRelayAbandoned(address relayManager)

(external)

Allows the contract owner to set the given relayManager as abandoned after a configurable delay. Its entire stake and balance will be taken from a relay if it does not respond to being marked as abandoned.


# escheatAbandonedRelayStake(address relayManager)

(external)

If more than abandonmentDelay has passed since the last Keepalive transaction, and relay manager has been marked as abandoned, and after that more that escheatmentDelay have passed, entire stake and balance will be taken from this relay.


# updateRelayKeepaliveTime(address relayManager)

(external)

Sets a new keepaliveTime for the given relayManager, preventing it from being marked as abandoned. Can be called by an authorized RelayHub or by the relayOwner address.


# isRelayEscheatable(address relayManager)

→ bool (external)

Check if the Relay Manager can be considered abandoned or not. Returns true if the stake's abandonment time is in the past including the escheatment delay, false otherwise.


# getStakeInfo(address relayManager)

→ struct IStakeManager.StakeInfo stakeInfo, bool isSenderAuthorizedHub (external)

Get the stake details information for the given Relay Manager.

relayManager: The address of a Relay Manager.

# Return values

The StakeInfo structure.

true if the msg.sender for this call was a RelayHub that is authorized now. false if the msg.sender for this call is not authorized.


# getMaxUnstakeDelay()

→ uint256 (external)

# Return values

maximum unstake delay this StakeManger allows. This is to prevent locking money forever by mistake.


# setBurnAddress(address _burnAddress)

(external)

Change the address that will receive the 'burned' part of the penalized stake. This is done to prevent malicious Relay Server from penalizing itself and breaking even.


# getBurnAddress()

→ address (external)

# Return values

address that will receive the 'burned' part of the penalized stake.


# setDevAddress(address _burnAddress)

(external)

Change the address that will receive the 'abandoned' stake. This is done to prevent Relay Servers that lost their keys from losing access to funds.


# getAbandonedRelayServerConfig()

→ struct IStakeManager.AbandonedRelayServerConfig (external)

# Return values

structure that contains all configuration values for the 'abandoned' stake.


# getCreationBlock()

→ uint256 (external)

# Return values

block number in which the contract has been deployed.


# versionSM()

→ string (external)

# Return values

SemVer-compliant version of the StakeManager contract.


# Events

# StakeAdded(address relayManager, address owner, contract IERC20 token, uint256 stake, uint256 unstakeDelay)

Emitted when a stake or unstakeDelay are initialized or increased.


# StakeUnlocked(address relayManager, address owner, uint256 withdrawTime)

Emitted once a stake is scheduled for withdrawal.


# StakeWithdrawn(address relayManager, address owner, contract IERC20 token, uint256 amount)

Emitted when owner withdraws relayManager funds.


# StakePenalized(address relayManager, address beneficiary, contract IERC20 token, uint256 reward)

Emitted when an authorized RelayHub penalizes a relayManager.


# HubAuthorized(address relayManager, address relayHub)

Emitted when a relayManager adds a new RelayHub to a list of authorized.


# HubUnauthorized(address relayManager, address relayHub, uint256 removalTime)

Emitted when a relayManager removes a RelayHub from a list of authorized.


# OwnerSet(address relayManager, address owner)

Emitted when a relayManager sets its owner. This is necessary to prevent stake hijacking.


# BurnAddressSet(address burnAddress)

Emitted when a burnAddress is changed.


# DevAddressSet(address devAddress)

Emitted when a devAddress is changed.


# RelayServerAbandoned(address relayManager, uint256 abandonedTime)

Emitted if Relay Server is inactive for an abandonmentDelay and contract owner initiates its removal.


# RelayServerKeepalive(address relayManager, uint256 keepaliveTime)

Emitted to indicate an action performed by a relay server to prevent it from being marked as abandoned.


# AbandonedRelayManagerStakeEscheated(address relayManager, address owner, contract IERC20 token, uint256 amount)

Emitted when the stake of an abandoned relayer has been confiscated and transferred to the devAddress.


# Structs

# StakeInfo

uint256 stake

uint256 unstakeDelay

uint256 withdrawTime

uint256 abandonedTime

uint256 keepaliveTime

contract IERC20 token

address owner


# RelayHubInfo

uint256 removalTime


# AbandonedRelayServerConfig

address devAddress

uint256 abandonmentDelay

uint256 escheatmentDelay