0

AAVE V1 's redeem() function requires us to wait for COOLDOWN_SECONDS and withdraw money in UNSTAKE_WINDOW.

  /**
   * @dev Redeems staked tokens, and stop earning rewards
   * @param to Address to redeem to
   * @param amount Amount to redeem
   **/
  function redeem(address to, uint256 amount) external override {
    require(amount != 0, 'INVALID_ZERO_AMOUNT');

    uint256 cooldownStartTimestamp = stakersCooldowns[msg.sender];

    require(
      block.timestamp > cooldownStartTimestamp.add(COOLDOWN_SECONDS),
      'INSUFFICIENT_COOLDOWN'
    );
    require(
      block.timestamp.sub(cooldownStartTimestamp.add(COOLDOWN_SECONDS)) <= UNSTAKE_WINDOW,
      'UNSTAKE_WINDOW_FINISHED'
    );
    uint256 balanceOfMessageSender = balanceOf(msg.sender);

    uint256 amountToRedeem = (amount > balanceOfMessageSender) ? balanceOfMessageSender : amount;

    _updateCurrentUnclaimedRewards(msg.sender, balanceOfMessageSender, true);

    _burn(msg.sender, amountToRedeem);

    if (balanceOfMessageSender.sub(amountToRedeem) == 0) {
      stakersCooldowns[msg.sender] = 0;
    }

    IERC20(STAKED_TOKEN).safeTransfer(to, amountToRedeem);

    emit Redeem(msg.sender, to, amountToRedeem);
  }

  /**
   * @dev Activates the cooldown period to unstake
   * - It can't be called if the user is not staking
   **/
  function cooldown() external override {
    require(balanceOf(msg.sender) != 0, "INVALID_BALANCE_ON_COOLDOWN");
    //solium-disable-next-line
    stakersCooldowns[msg.sender] = block.timestamp;

    emit Cooldown(msg.sender);
  }

The unstake window is 2 days after the cooldown completes. If you don't unstake during this time, you'll have to activate the cooldown again. link : https://twitter.com/AaveAave/status/1347250535087419402

My question 1: waiting for COOLDOWN_SECONDS to call redeem() is to make sure that users can not stake and redeem again and again in a short time. But why? What will happend if stake and redeem again and again in a short time.

My question 2: why design UNSTAKE_WINDOW? We need to call cooldown() ,wait for another time and must withdraw in UNSTAKE_WINDOW time. It costs more gas and it's not convenient for users. Maybe it is for security or the Business Logic of AAVE.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.