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 specificationFactoryFeeManager
: 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 feesdefaultGasFee_
: Default gas fee amount in weidefaultTokenFee_
: Default token fee in basis points (1-10000)defaultFeeFunctions_
: Bitmask defining which functions have fees applied
Requirements:
feeCollector_
must not be zero addressdefaultFeeFunctions_
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
isMerkle
orMerkleAndTrustedDistributors
,merkleRoot
must be non-zero - If
whitelistStatus
isDisabled
orTrustedDistributors
,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 futureendStakingDate
must be afterstartStakingDate
timeUnit
must be greater than zero
Tier Configuration:
tierLowerBound
must be ≤tierUpperBound
- Both bounds must be > 0
Reward Configuration:
rewardRatioDenominator
must be > 0rewardRatioNumerator
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 providedInvalidFeeFunctionsMask()
: Invalid fee functions bitmaskInvalidTierBounds()
: Invalid tier bound configurationInvalidStakingDates()
: Invalid staking date rangeStartDateInPast()
: Start date is in the pastInvalidMerkleRoot()
: Invalid merkle root for whitelist statusInvalidFeePercentage()
: Fee percentage > BASIS_POINTS
From FactoryFeeManager:
FeeTooHigh()
: Token fee > BASIS_POINTSCustomFeeNotSet()
: Attempting to use non-existent custom fee