-
Notifications
You must be signed in to change notification settings - Fork 57
/
AaveStakingHelper.sol
46 lines (41 loc) · 1.51 KB
/
AaveStakingHelper.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.7.5;
import {IStakedAaveImplWithInitialize} from '../interfaces/IStakedAaveImplWithInitialize.sol';
import {IEIP2612Token} from '../interfaces/IEIP2612Token.sol';
/**
* @title StakingHelper contract
* @author Aave
* @dev implements a staking function that allows staking through the EIP2612 capabilities of the AAVE token
**/
contract AaveStakingHelper {
IStakedAaveImplWithInitialize public immutable STAKE;
IEIP2612Token public immutable AAVE;
constructor(address stake, address aave) public {
STAKE = IStakedAaveImplWithInitialize(stake);
AAVE = IEIP2612Token(aave);
//approves the stake to transfer uint256.max tokens from this contract
//avoids approvals on every stake action
IEIP2612Token(aave).approve(address(stake), type(uint256).max);
}
/**
* @dev stakes on behalf of msg.sender using signed approval.
* The function expects a valid signed message from the user, and executes a permit()
* to approve the transfer. The helper then stakes on behalf of the user
* @param user the user for which the staking is being executed
* @param amount the amount to stake
* @param v signature param
* @param r signature param
* @param s signature param
**/
function stake(
address user,
uint256 amount,
uint8 v,
bytes32 r,
bytes32 s
) external {
AAVE.permit(user, address(this), amount, type(uint256).max, v, r, s);
AAVE.transferFrom(user, address(this), amount);
STAKE.stake(user, amount);
}
}