-
Notifications
You must be signed in to change notification settings - Fork 15
/
BaseBalancerLpCompounder.sol
65 lines (51 loc) · 2.04 KB
/
BaseBalancerLpCompounder.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
// SPDX-License-Identifier: GPL-3.0
// Docgen-SOLC: 0.8.25
pragma solidity ^0.8.25;
import {IERC20} from "openzeppelin-contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "openzeppelin-contracts/token/ERC20/utils/SafeERC20.sol";
import {BaseBalancerCompounder, BalancerTradeLibrary, TradePath} from "./BaseBalancerCompounder.sol";
struct HarvestValues {
uint256 amountsInLen;
address depositAsset;
uint256 indexIn;
uint256 indexInUserData;
bytes32 poolId;
address[] underlyings;
}
abstract contract BaseBalancerLpCompounder is BaseBalancerCompounder {
using SafeERC20 for IERC20;
HarvestValues public harvestValues;
error CompoundFailed();
function sellRewardsForLpTokenViaBalancer(address vaultAsset, bytes memory data) internal {
sellRewardsViaBalancer();
// caching
HarvestValues memory harvestValues_ = harvestValues;
uint256 amount = IERC20(harvestValues_.depositAsset).balanceOf(address(this));
BalancerTradeLibrary.addLiquidity(
balancerVault,
harvestValues_.poolId,
harvestValues_.underlyings,
harvestValues_.amountsInLen,
harvestValues_.indexIn,
harvestValues_.indexInUserData,
amount
);
amount = IERC20(vaultAsset).balanceOf(address(this));
uint256 minOut = abi.decode(data, (uint256));
if (amount < minOut) revert CompoundFailed();
}
function setBalancerLpCompounderValues(
address newBalancerVault,
TradePath[] memory newTradePaths,
HarvestValues memory harvestValues_
) internal {
setBalancerTradeValues(newBalancerVault, newTradePaths);
// Reset old base asset
if (harvestValues.depositAsset != address(0)) {
IERC20(harvestValues.depositAsset).forceApprove(address(balancerVault), 0);
}
// approve and set new base asset
IERC20(harvestValues_.depositAsset).forceApprove(newBalancerVault, type(uint256).max);
harvestValues = harvestValues_;
}
}