/
BaseAuraStrategy.sol
107 lines (93 loc) · 3.51 KB
/
BaseAuraStrategy.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title OETH Base Balancer Abstract Strategy
* @author Origin Protocol Inc
*/
import { BaseBalancerStrategy } from "./BaseBalancerStrategy.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IRateProvider } from "../../interfaces/balancer/IRateProvider.sol";
import { IERC20 } from "../../utils/InitializableAbstractStrategy.sol";
import { IERC4626 } from "../../../lib/openzeppelin/interfaces/IERC4626.sol";
import { StableMath } from "../../utils/StableMath.sol";
import { IRewardStaking } from "../IRewardStaking.sol";
abstract contract BaseAuraStrategy is BaseBalancerStrategy {
using SafeERC20 for IERC20;
using StableMath for uint256;
/// @notice Address of the Aura rewards pool
address public immutable auraRewardPoolAddress;
// renamed from __reserved to not shadow BaseBalancerStrategy.__reserved,
int256[50] private __reserved_baseAuraStrategy;
constructor(address _auraRewardPoolAddress) {
auraRewardPoolAddress = _auraRewardPoolAddress;
}
/**
* @dev Deposit all Balancer Pool Tokens (BPT) in this strategy contract
* to the Aura rewards pool.
*/
function _lpDepositAll() internal virtual override {
uint256 bptBalance = IERC20(platformAddress).balanceOf(address(this));
uint256 auraLp = IERC4626(auraRewardPoolAddress).deposit(
bptBalance,
address(this)
);
require(bptBalance == auraLp, "Aura LP != BPT");
}
/**
* @dev Withdraw `numBPTTokens` Balancer Pool Tokens (BPT) from
* the Aura rewards pool to this strategy contract.
* @param numBPTTokens Number of Balancer Pool Tokens (BPT) to withdraw
*/
function _lpWithdraw(uint256 numBPTTokens) internal virtual override {
IRewardStaking(auraRewardPoolAddress).withdrawAndUnwrap(
numBPTTokens,
true // also claim reward tokens
);
}
/**
* @dev Withdraw all Balancer Pool Tokens (BPT) from
* the Aura rewards pool to this strategy contract.
*/
function _lpWithdrawAll() internal virtual override {
// Get all the strategy's BPTs in Aura
// maxRedeem is implemented as balanceOf(address) in Aura
uint256 bptBalance = IERC4626(auraRewardPoolAddress).maxRedeem(
address(this)
);
IRewardStaking(auraRewardPoolAddress).withdrawAndUnwrap(
bptBalance,
true // also claim reward tokens
);
}
/**
* @notice Collects BAL and AURA tokens from the rewards pool.
*/
function collectRewardTokens()
external
virtual
override
onlyHarvester
nonReentrant
{
// Collect BAL and AURA
IRewardStaking(auraRewardPoolAddress).getReward();
_collectRewardTokens();
}
/// @notice Balancer Pool Tokens (BPT) in the Balancer pool and the Aura rewards pool.
function _getBalancerPoolTokens()
internal
view
override
returns (uint256 balancerPoolTokens)
{
balancerPoolTokens =
IERC20(platformAddress).balanceOf(address(this)) +
// maxRedeem is implemented as balanceOf(address) in Aura
IERC4626(auraRewardPoolAddress).maxRedeem(address(this));
}
function _approveBase() internal virtual override {
super._approveBase();
IERC20 pToken = IERC20(platformAddress);
pToken.safeApprove(auraRewardPoolAddress, type(uint256).max);
}
}