Skip to content

Commit d5ab9e7

Browse files
authored
Add Staking UI Helpers code (#26)
* feat: Add UI Helpers * feat: Add deployment tasks for stake ui helpers * ci: Fix dependencies files * ci: Bump solidity-coverage version
1 parent 2e76a22 commit d5ab9e7

19 files changed

+25881
-6803
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.7.5;
3+
4+
interface BPTPriceFeedI {
5+
function latestAnswer() external view returns (uint256);
6+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: agpl-3.0
2+
pragma solidity 0.7.5;
3+
4+
import {IERC20} from './IERC20.sol';
5+
6+
/**
7+
* @title interface EIP2612
8+
* @author Aave
9+
* @dev Generic interface for the EIP2612 permit function
10+
*/
11+
interface IEIP2612Token is IERC20 {
12+
/**
13+
* @dev implements the permit function as for https://github.com/ethereum/EIPs/blob/8a34d644aacf0f9f8f00815307fd7dd5da07655f/EIPS/eip-2612.md
14+
* @param owner the owner of the funds
15+
* @param spender the spender
16+
* @param value the amount
17+
* @param deadline the deadline timestamp, type(uint256).max for max deadline
18+
* @param v signature param
19+
* @param s signature param
20+
* @param r signature param
21+
*/
22+
function permit(
23+
address owner,
24+
address spender,
25+
uint256 value,
26+
uint256 deadline,
27+
uint8 v,
28+
bytes32 r,
29+
bytes32 s
30+
) external virtual;
31+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.7.5;
3+
4+
import {IERC20} from '../lib/ERC20.sol';
5+
6+
interface IERC20WithNonce is IERC20 {
7+
function _nonces(address user) external view returns (uint256);
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.7.5;
3+
4+
interface IPriceOracle {
5+
function getAssetPrice(address asset) external view returns (uint256);
6+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: agpl-3.0
2+
pragma solidity 0.7.5;
3+
4+
interface IStakedAaveImplWithInitialize {
5+
function initialize(
6+
address aaveGovernance,
7+
string calldata name,
8+
string calldata symbol,
9+
uint8 decimals
10+
) external;
11+
12+
function stake(address onBehalfOf, uint256 amount) external;
13+
14+
function redeem(address to, uint256 amount) external;
15+
16+
function cooldown() external;
17+
18+
function claimRewards(address to, uint256 amount) external;
19+
20+
function balanceOf(address user) external view returns (uint256);
21+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.7.5;
3+
pragma experimental ABIEncoderV2;
4+
5+
interface IStakedToken {
6+
struct AssetData {
7+
uint128 emissionPerSecond;
8+
uint128 lastUpdateTimestamp;
9+
uint256 index;
10+
}
11+
12+
function totalSupply() external view returns (uint256);
13+
14+
function COOLDOWN_SECONDS() external view returns (uint256);
15+
16+
function UNSTAKE_WINDOW() external view returns (uint256);
17+
18+
function DISTRIBUTION_END() external view returns (uint256);
19+
20+
function assets(address asset) external view returns (AssetData memory);
21+
22+
function balanceOf(address user) external view returns (uint256);
23+
24+
function getTotalRewardsBalance(address user) external view returns (uint256);
25+
26+
function stakersCooldowns(address user) external view returns (uint256);
27+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.7.5;
3+
pragma experimental ABIEncoderV2;
4+
5+
interface StakeUIHelperI {
6+
struct AssetUIData {
7+
uint256 stakeTokenTotalSupply;
8+
uint256 stakeCooldownSeconds;
9+
uint256 stakeUnstakeWindow;
10+
uint256 stakeTokenPriceEth;
11+
uint256 rewardTokenPriceEth;
12+
uint256 stakeApy;
13+
uint128 distributionPerSecond;
14+
uint256 distributionEnd;
15+
uint256 stakeTokenUserBalance;
16+
uint256 underlyingTokenUserBalance;
17+
uint256 userCooldown;
18+
uint256 userIncentivesToClaim;
19+
uint256 userPermitNonce;
20+
}
21+
22+
struct GeneralStakeUIData {
23+
uint256 stakeTokenTotalSupply;
24+
uint256 stakeCooldownSeconds;
25+
uint256 stakeUnstakeWindow;
26+
uint256 stakeTokenPriceEth;
27+
uint256 rewardTokenPriceEth;
28+
uint256 stakeApy;
29+
uint128 distributionPerSecond;
30+
uint256 distributionEnd;
31+
}
32+
33+
struct UserStakeUIData {
34+
uint256 stakeTokenUserBalance;
35+
uint256 underlyingTokenUserBalance;
36+
uint256 userCooldown;
37+
uint256 userIncentivesToClaim;
38+
uint256 userPermitNonce;
39+
}
40+
41+
function getStkAaveData(address user) external view returns (AssetUIData memory);
42+
43+
function getStkBptData(address user) external view returns (AssetUIData memory);
44+
45+
function getStkGeneralAaveData() external view returns (GeneralStakeUIData memory);
46+
47+
function getStkGeneralBptData() external view returns (GeneralStakeUIData memory);
48+
49+
function getStkUserAaveData(address user) external view returns (UserStakeUIData memory);
50+
51+
function getStkUserBptData(address user) external view returns (UserStakeUIData memory);
52+
53+
/// @dev This will return user + general for fallback
54+
function getUserUIData(address user)
55+
external
56+
view
57+
returns (
58+
AssetUIData memory,
59+
AssetUIData memory,
60+
uint256
61+
);
62+
63+
function getGeneralStakeUIData()
64+
external
65+
view
66+
returns (
67+
GeneralStakeUIData memory,
68+
GeneralStakeUIData memory,
69+
uint256
70+
);
71+
72+
function getUserStakeUIData(address user)
73+
external
74+
view
75+
returns (
76+
UserStakeUIData memory,
77+
UserStakeUIData memory,
78+
uint256
79+
);
80+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// SPDX-License-Identifier: agpl-3.0
2+
pragma solidity 0.7.5;
3+
4+
import {IStakedAaveImplWithInitialize} from '../interfaces/IStakedAaveImplWithInitialize.sol';
5+
import {IEIP2612Token} from '../interfaces/IEIP2612Token.sol';
6+
7+
/**
8+
* @title StakingHelper contract
9+
* @author Aave
10+
* @dev implements a staking function that allows staking through the EIP2612 capabilities of the AAVE token
11+
**/
12+
13+
contract AaveStakingHelper {
14+
IStakedAaveImplWithInitialize public immutable STAKE;
15+
IEIP2612Token public immutable AAVE;
16+
17+
constructor(address stake, address aave) public {
18+
STAKE = IStakedAaveImplWithInitialize(stake);
19+
AAVE = IEIP2612Token(aave);
20+
//approves the stake to transfer uint256.max tokens from this contract
21+
//avoids approvals on every stake action
22+
IEIP2612Token(aave).approve(address(stake), type(uint256).max);
23+
}
24+
25+
/**
26+
* @dev stakes on behalf of msg.sender using signed approval.
27+
* The function expects a valid signed message from the user, and executes a permit()
28+
* to approve the transfer. The helper then stakes on behalf of the user
29+
* @param user the user for which the staking is being executed
30+
* @param amount the amount to stake
31+
* @param v signature param
32+
* @param r signature param
33+
* @param s signature param
34+
**/
35+
function stake(
36+
address user,
37+
uint256 amount,
38+
uint8 v,
39+
bytes32 r,
40+
bytes32 s
41+
) external {
42+
AAVE.permit(user, address(this), amount, type(uint256).max, v, r, s);
43+
AAVE.transferFrom(user, address(this), amount);
44+
STAKE.stake(user, amount);
45+
}
46+
}

0 commit comments

Comments
 (0)