Skip to main content

StakingFactory

Overview

The StakingFactory contract deploy staking contracts with configurable fee structures. It inherits from FactoryFeeManager to provide fee management capabilities for different campaign creators.

Contract Specification

contract StakingFactory is IStakingFactory, FactoryFeeManager

Inheritance:

  • IStakingFactory: Factory interface specification
  • FactoryFeeManager: Fee management functionality

Constructor

constructor(
address feeCollector_,
uint256 defaultGasFee_,
uint256 defaultTokenFee_,
uint8 defaultFeeFunctions_
) FactoryFeeManager(feeCollector_, defaultGasFee_, defaultTokenFee_, defaultFeeFunctions_)

Parameters:

  • feeCollector_: Address designated to receive collected fees
  • defaultGasFee_: Default gas fee amount in wei
  • defaultTokenFee_: Default token fee in basis points (1-10000)
  • defaultFeeFunctions_: Bitmask defining which functions have fees applied

Requirements:

  • feeCollector_ must not be zero address
  • defaultFeeFunctions_ must be ≤ 7 (valid bitmask)

Functions

newStaking

function newStaking(StakingParams calldata params) external returns (address)

Deploys a new Staking contract instance with the provided parameters.

Parameters:

struct StakingParams {
bytes32 merkleRoot; // Merkle root for whitelist verification
ITypes.WhitelistStatus whitelistStatus; // Whitelist configuration mode
uint256 poolMaxCap; // Maximum total tokens stakeable
address stakingToken; // ERC20 token contract address
uint80 timeUnit; // Time unit for reward calculations (seconds)
uint256 rewardRatioNumerator; // Reward ratio numerator
uint256 rewardRatioDenominator; // Reward ratio denominator
uint256 tierUpperBound; // Maximum tokens per individual staker
uint256 tierLowerBound; // Minimum tokens per individual staker
uint80 startStakingDate; // Staking operations start timestamp
uint80 endStakingDate; // Staking operations end timestamp
}

Returns:

  • Address of the newly deployed staking contract

Fee Application: The factory applies fees based on the caller's configuration:

  • If custom fees are set for the caller, those are used
  • Otherwise, default factory fees are applied

Fee Type Determination:

  • Gas fees: Fixed ETH amount per transaction
  • Token fees: Percentage of tokens being operated on

Events Emitted:

event StakingCreated(
address indexed stakingContract,
bytes32 merkleRoot,
address token,
ITypes.FeeType feeType,
uint256 fee,
uint8 feeFunctions
);

Parameter Validation

The factory validates deployment parameters:

Whitelist Configuration:

  • If whitelistStatus is Merkle or MerkleAndTrustedDistributors, merkleRoot must be non-zero
  • If whitelistStatus is Disabled or TrustedDistributors, merkleRoot must be zero

Token Configuration:

  • stakingToken must be a valid ERC20 contract address
  • Cannot be zero address

Time Configuration:

  • startStakingDate must be in the future
  • endStakingDate must be after startStakingDate
  • timeUnit must be greater than zero

Tier Configuration:

  • tierLowerBound must be ≤ tierUpperBound
  • Both bounds must be > 0

Reward Configuration:

  • rewardRatioDenominator must be > 0
  • rewardRatioNumerator can be any value ≥ 0

Fee Management Integration

The factory integrates with the FactoryFeeManager system:

Default Fees: Applied to all deployments unless overridden by custom fees.

Custom Fees: Set per campaign creator address with specific fee types and amounts.

Fee Functions: Bitmask determines which contract functions have fees applied:

  • Bit 0 (1): Stake functions
  • Bit 1 (2): Withdraw functions
  • Bit 2 (4): Claim functions

Deployed Contract Configuration

Each deployed staking contract receives:

Immutable Parameters:

  • Staking token address
  • Fee type and amount
  • Fee collector address
  • Fee functions bitmask
  • Tier bounds
  • Staking date range

Configurable Parameters:

  • Pool maximum capacity
  • Whitelist status and merkle root
  • Reward ratio and time unit (owner-controlled)

Error Conditions

The factory may revert with these errors:

From StakingErrors:

  • InvalidAddress(): Zero address provided
  • InvalidFeeFunctionsMask(): Invalid fee functions bitmask
  • InvalidTierBounds(): Invalid tier bound configuration
  • InvalidStakingDates(): Invalid staking date range
  • StartDateInPast(): Start date is in the past
  • InvalidMerkleRoot(): Invalid merkle root for whitelist status
  • InvalidFeePercentage(): Fee percentage > BASIS_POINTS

From FactoryFeeManager:

  • FeeTooHigh(): Token fee > BASIS_POINTS
  • CustomFeeNotSet(): Attempting to use non-existent custom fee