AECStakingToken.sol
Enables AEC token holders to earn a direct share of the protocol's revenue. This is the primary staking pillar for community members who want yield without impermanent loss exposure. This pool receives 37.5% of the total rewards distributed by the Perpetual Engine.
Quick Links
Contract Path:
contracts/staking/AECStakingToken.sol
Inherits From
ReentrancyGuard
Key State Variables
Public and immutable variables defining staking mechanics, tier structure, and reward accounting.
aecToken
IERC20
The immutable address of the AEC token, which is both staked and distributed as a reward.
perpetualEngine
address
The immutable address of the PerpetualEngine that sends bonus rewards.
initialRewardAllocation
uint256
The immutable initial reward allocation for this pool (133,333,333 AEC).
deploymentTime
uint256
The immutable timestamp of the contract's deployment.
tiers
TierConfig[4]
An array defining the 4 user-selectable staking tiers (lock durations, multipliers).
stakes
mapping(address => StakeInfo)
A mapping of a user's address to their StakeInfo struct, containing their position details.
totalSupply
uint256
The total amount of (unweighted) AEC tokens currently staked.
totalWeightedSupply
uint256
The total sum of all staked tokens multiplied by their tier multipliers, used for reward calculations.
remainingBaseRewards
uint256
The current balance of the initial reward allocation, which decays over time.
lastBaseRewardUpdate
uint256
The timestamp of the last time the base reward pool was decayed.
rewardsDuration
uint256
The duration (in seconds) over which bonus rewards are distributed. Default is 7 days.
rewardPerTokenStored
uint256
The last calculated reward-per-token value.
lastUpdateTime
uint256
The timestamp of the last global reward calculation.
bonusRewardRate
uint256
The current rate of bonus rewards distributed per second.
bonusPeriodFinish
uint256
The timestamp when the current bonus reward distribution period ends.
userRewardPerTokenPaid
mapping(address => uint256)
Tracks the rewardPerTokenStored value for each user at their last interaction.
rewards
mapping(address => uint256)
Stores the accumulated, unclaimed rewards for each user.
totalStakers
uint256
The total number of unique addresses currently staking.
totalRewardsPaid
uint256
The cumulative amount of all rewards paid out.
totalDeposited
uint256
The cumulative amount of all AEC ever staked.
totalWithdrawn
uint256
The cumulative amount of all AEC ever withdrawn.
Write Functions
Functions that modify the state of the contract.
stake(uint256 amount, uint8 tier)
Public
Stakes AEC tokens into a user-selectable tier (0-3).
withdraw(uint256 amount)
Public
Withdraws staked AEC tokens; reverts if the lock period is not over.
claimReward()
Public
Claims all accumulated AEC rewards for the caller.
exit()
Public
Withdraws all staked tokens and claims all rewards in a single transaction.
upgradeTier(uint8 newTier)
Public
Upgrades the staking tier to a higher one without withdrawing.
notifyRewardAmount(uint256 reward)
Engine-Only
Deposits a new batch of bonus rewards from the PerpetualEngine.
setRewardsDuration(uint256 _duration)
Engine-Only
Adjusts the duration over which bonus rewards are distributed.
View Functions
Read-only functions for monitoring staking positions and rewards.
earned(address account)
Returns the total amount of claimable AEC rewards for a given account.
rewardPerToken()
Calculates the current reward-per-token value for use in earned() computation.
lastTimeRewardApplicable()
Returns the timestamp of the last moment bonus rewards are applicable.
getStakeInfo(address account)
Returns a detailed struct of an account's staking position (amount, tier, lock end, earned rewards, etc.).
getPoolStats()
Provides a high-level overview of the entire pool (total staked, remaining rewards, bonus rate, projected APY).
Events
Events emitted for monitoring and off-chain tracking.
Staked(address indexed user, uint256 amount, uint8 tier, uint256 lockEnd)
Emitted when a user successfully stakes AEC tokens.
Withdrawn(address indexed user, uint256 amount)
Emitted when a user withdraws staked AEC tokens.
RewardPaid(address indexed user, uint256 reward)
Emitted when a user claims their AEC rewards.
BonusRewardAdded(uint256 reward)
Emitted when the Engine deposits new rewards into the contract.
BaseRewardDecay(uint256 released, uint256 remaining)
Emitted when the base reward pool decays, showing the amount released for the period.
TierUpgraded(address indexed user, uint8 oldTier, uint8 newTier)
Emitted when a user successfully upgrades their staking tier.
RewardsDurationUpdated(uint256 newDuration)
Emitted when the rewards distribution duration is updated by the Engine.
Closing Note
This reference completes the overview for AECStakingToken.sol. All functions, state variables, and events are documented above for verification, integration, and direct developer usage.
Last updated