Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@aave/aave-stake
Advanced tools
Sets of smart contracts to enable stake of Aave-related assets and rewards distribution based on them.
A common parent contract AaveDistributionManager
is used to keep the "accounting" logic for a set of children front contracts taking care of each type of incentive; being these, initially, a StakedAave
contract for stake of Aave tokens on the Aave SM (Security Module) which will which be used as security fund in the near future, and a AaveIncentivesController
contract through which the Aave protocol will interact in order to provider rewards as incentives to users.
The rationale of this inheritance chain in 2 main layers is the clearly conceptual separation between a common part of configurations of the distributions and mathematical calculation, and one specific part for each type of incentive (locking funds in a stake, providing liquidity to a protocol and potentially more in the future).
Additionally, there will be a Rewards vault where the AAVE rewards will be keep, to distribute through the StakedAave
and the AaveIncentivesController
. Both will be granted in advance with allowance to pull funds from.
The following sections will go in detail on the specification of both the AaveDistributionManager
and the different front contracts.
Core contract for calculation of multiple distributions with different configurations. All the front contracts which users/aave protocol will interact with inherit from the AaveDistributionManager
.
It calculates how many rewards belong to a certain user depending on the user's situation defined by the front contract of the distribution. This calculation is done by using a distribution index representing the accumulation of rewards from an emission per second and snapshoting that index on each user to take into account how much of the total belongs to him.
assets
. Mapping of AssetData
structs which, for each front contract connected to the AaveDistributionManager
stores 1 or more of:
emissionPerSecond
: Amount of rewards per second distribution-wide. It's used to calculate the raw amount of rewards to distribute in a time delta since the last update of the following described index
.index
: Variable representing the accumulated rewards distributed distribution-wide per unit of token used in the specific child contract of the distribution (per unit of staked Aave in the case of the StakedAave
child contract). The next index is calculated by the formula on _getNormalizedDistribution()
emissionPerSecond _ timeDelta _ 10^PRECISION / balanceOnFrontContract + previousIndex, scaling it up multiplying by 10^18 in order to not lose precision.lastUpdateTimestamp
: timestamp when the struct was updated.userIndexes
: mapping user address => index snapshotted on the user from the one of the distribution.For the child StakedAave
, they key of the mapping used is the address of the StakedAave
itself. In the case of the AaveIncentivesController
, there is a different key and struct for each aToken and debtToken submitted to incentives.
This contract allows to do the following:
EMISSION_MANAGER
, allows to list an specific distribution, with some emission per second and front contract.StakedAave
, redeems, deposit on the Aave protocol, etc...claimRewards()
function.Contract to stake AAVE token, to be connected with a slashing mechanism in the near future in order to secure the Aave protocol, forming the so called Aave SM (Security Module).
Holders of Aave tokens stae them in this contract, they receive equivalent amount in stkAAVE
tokens and start accruing rewards in AAVE; rewards previously configured on the father contract AaveDistributionManager
by the a trusted EMISSION_MANAGER. Once they accrued AAVE rewards, they can claim them at any moment but, to withdraw their staked AAVE tokens, they need to activate and wait a cooldown period, and withdraw just after it, during a withdrawal time window.
stakerRewardsToClaim
: mapping storing the accrued rewards accrued and stored for an user, not taking into account those accrued but not stored yet.stakersCooldowns
: mapping the timestamp of activation of cooldown period for an user, if activated.This contract allows to do the following:
stake()
function. The AAVE tokens will be locked in this same contract, and stkAAVE tokens will be minted for the user in the same proportion as AAVE staked, the state in the father AaveDistributionManager
will be updated and the timestamp of the cooldown will be updated too.redeem()
function, burning the stkAAVE and receiving the same proportion of previously staked AAVE. The withdrawal will only suceed if the user in on the withdrawal window after the cooldown period.cooldown()
function and needed to withdraw the staked AAVE.claimRewards()
function, used to update the state and transfer to the user the accrued rewards, consequence of the time he was/is staking.The main objective of the cooldown period is to avoid situations on the future Security Module when, if an slashing event happens, people starts withdrawing in mass their staked funds, leaving the protocol uncover and removing the utility on the stake itself.
To achieve this, the most important condition to be fullfilled on any state update/operation involving the StakedAave
contract is that, if a user staking withdraws, he already respected a cooldown period, which leads that movement of funds should only affect "negatively" the cooldown period.
Depending on the type of operation, the cooldown period is affected in the following way:
Contract in charge of the incentives for activity on the Aave protocol, inheriting from the AaveDistributionManager
. Each time an action involving any incentive for an user happens on the Aave protocol, this contract is called to manage the update of the incentives state.
_usersUnclaimedRewards
: mapping storing the accrued rewards accrued and stored for an user, not taking into account those accrued but not stored yet.This contract allows to do the following:
handleAction()
, only callable by the Aave lending pool. For every asset and user, one call to this function needs to be done, which will trigger a state update in both the rewards of the user and the distribution data.claimRewards()
function, transferring to the user the AAVE rewards. If the user tries to claim his rewards with the StakedAave
as target, a bonus will applied on the rewards accumulated from his activity on the protocol, and the stake()
function on the StakedAave
will be called.The Solidity code in this repository has undergone 2 traditional smart contracts' audits by Consensys Diligence and Certik. The reports are:
[MAIN]
For the proxy-related contracts, we have used the implementation of our friend from OpenZeppelin.
The contents of this repository are under the AGPLv3 license.
FAQs
Safety Module for the Aave Protocol
The npm package @aave/aave-stake receives a total of 4 weekly downloads. As such, @aave/aave-stake popularity was classified as not popular.
We found that @aave/aave-stake demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.