This repository has been archived by the owner on May 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BalancerLPStakingController.sol
145 lines (122 loc) · 4.57 KB
/
BalancerLPStakingController.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
import {IController} from "../core/IController.sol";
interface IChildGauge {
function lp_token() external view returns (address);
function reward_tokens(uint256) external view returns (address);
}
/**
@title Curve LP staking controller
@notice Interaction controller for staking curve LP controllers
*/
contract BalancerLPStakingController is IController {
/* -------------------------------------------------------------------------- */
/* STATE VARIABLES */
/* -------------------------------------------------------------------------- */
/// @notice deposit(uint256)
bytes4 constant DEPOSIT = 0xb6b55f25;
/// @notice deposit(uint256,address,bool)
bytes4 constant DEPOSITCLAIM = 0x83df6747;
/// @notice withdraw(uint256)
bytes4 constant WITHDRAW = 0x2e1a7d4d;
/// @notice withdraw(uint256,address,bool)
bytes4 constant WITHDRAWCLAIM = 0x00ebf5dd;
/// @notice claim_rewards()
bytes4 constant CLAIM = 0xe6f1daf2;
/// @notice reward count
uint256 constant rewardsCount = 8;
/* -------------------------------------------------------------------------- */
/* EXTERNAL FUNCTIONS */
/* -------------------------------------------------------------------------- */
/// @inheritdoc IController
function canCall(address target, bool, bytes calldata data)
external
view
returns (bool, address[] memory, address[] memory)
{
bytes4 sig = bytes4(data);
if (sig == DEPOSIT) return canDeposit(target);
if (sig == DEPOSITCLAIM) return canDepositAndClaim(target);
if (sig == WITHDRAW) return canWithdraw(target);
if (sig == WITHDRAWCLAIM) return canWithdrawAndClaim(target);
if (sig == CLAIM) return canClaim(target);
return (false, new address[](0), new address[](0));
}
function canDeposit(address target)
internal
view
returns (bool, address[] memory, address[] memory)
{
address[] memory tokensIn = new address[](1);
address[] memory tokensOut = new address[](1);
tokensIn[0] = target;
tokensOut[0] = IChildGauge(target).lp_token();
return (true, tokensIn, tokensOut);
}
function canDepositAndClaim(address target)
internal
view
returns (bool, address[] memory, address[] memory)
{
address[] memory tokensIn = new address[](rewardsCount + 1);
address reward; uint i;
for (; i<rewardsCount; i++) {
reward = IChildGauge(target).reward_tokens(i);
if (reward == address(0)) break;
tokensIn[i] = reward;
}
tokensIn[i] = target;
i++;
assembly { mstore(tokensIn, i) }
address[] memory tokensOut = new address[](1);
tokensOut[0] = IChildGauge(target).lp_token();
return (true, tokensIn, tokensOut);
}
function canWithdraw(address target)
internal
view
returns (bool, address[] memory, address[] memory)
{
address[] memory tokensIn = new address[](1);
address[] memory tokensOut = new address[](1);
tokensOut[0] = target;
tokensIn[0] = IChildGauge(target).lp_token();
return (true, tokensIn, tokensOut);
}
function canWithdrawAndClaim(address target)
internal
view
returns (bool, address[] memory, address[] memory)
{
address[] memory tokensIn = new address[](rewardsCount + 1);
address reward;
uint i;
for (; i<rewardsCount; i++) {
reward = IChildGauge(target).reward_tokens(i);
if (reward == address(0)) break;
tokensIn[i] = reward;
}
tokensIn[i] = IChildGauge(target).lp_token();
i++;
assembly { mstore(tokensIn, i) }
address[] memory tokensOut = new address[](1);
tokensOut[0] = target;
return (true, tokensIn, tokensOut);
}
function canClaim(address target)
internal
view
returns (bool, address[] memory, address[] memory)
{
address[] memory tokensIn = new address[](rewardsCount);
address reward;
uint i;
for (; i<rewardsCount; i++) {
reward = IChildGauge(target).reward_tokens(i);
if (reward == address(0)) break;
tokensIn[i] = reward;
}
assembly { mstore(tokensIn, i) }
return (true, tokensIn, new address[](0));
}
}