@@ -9,16 +9,12 @@ import "./RescueFundsLib.sol";
9
9
import "openzeppelin-contracts/contracts/utils/math/Math.sol " ;
10
10
import "openzeppelin-contracts/contracts/security/ReentrancyGuard.sol " ;
11
11
12
-
13
12
// add rebalance external function (called from cron)
14
13
// call rebalance from withdraw and deposit too (with timestamp check, settable by admin)
15
14
// pausable vault
16
15
// redeem all from strategy and detach
17
16
// reentrancy guard
18
17
19
-
20
-
21
-
22
18
contract ParallelVault is Gauge , Ownable2Step , ERC4626 , ReentrancyGuard {
23
19
using SafeTransferLib for ERC20 ;
24
20
ERC20 public immutable token__;
@@ -66,14 +62,13 @@ contract ParallelVault is Gauge, Ownable2Step, ERC4626, ReentrancyGuard {
66
62
uint256 debtOutstanding
67
63
);
68
64
69
- event ShutdownStateUpdated (
70
- bool shutdownState
71
- );
65
+ event ShutdownStateUpdated (bool shutdownState );
72
66
73
67
modifier notShutdown () {
74
68
if (emergencyShutdown) revert VaultShutdown ();
75
69
_;
76
70
}
71
+
77
72
constructor (
78
73
address token_ ,
79
74
string memory name_ ,
@@ -91,11 +86,16 @@ contract ParallelVault is Gauge, Ownable2Step, ERC4626, ReentrancyGuard {
91
86
strategy = strategy_;
92
87
}
93
88
94
- function setRebalanceingDelay (uint128 rebalanceingDelay_ ) external onlyOwner {
89
+ function setRebalanceingDelay (
90
+ uint128 rebalanceingDelay_
91
+ ) external onlyOwner {
95
92
rebalanceingDelay = rebalanceingDelay_;
96
93
}
97
94
98
- function updateEmergencyShutdownState (bool shutdownState_ , bool detachStrategy ) external onlyOwner {
95
+ function updateEmergencyShutdownState (
96
+ bool shutdownState_ ,
97
+ bool detachStrategy
98
+ ) external onlyOwner {
99
99
if (shutdownState_ && detachStrategy) {
100
100
// If we're exiting emergency shutdown, we need to empty strategy
101
101
_withdrawAllFromStrategy ();
@@ -148,9 +148,7 @@ contract ParallelVault is Gauge, Ownable2Step, ERC4626, ReentrancyGuard {
148
148
_withdrawFromStrategy (assets_);
149
149
}
150
150
151
- function _withdrawFromStrategy (
152
- uint256 assets_
153
- ) internal returns (uint256 ) {
151
+ function _withdrawFromStrategy (uint256 assets_ ) internal returns (uint256 ) {
154
152
uint256 preBalance = token__.balanceOf (address (this ));
155
153
IStrategy (strategy).withdraw (assets_);
156
154
uint256 withdrawn = token__.balanceOf (address (this )) - preBalance;
@@ -170,7 +168,6 @@ contract ParallelVault is Gauge, Ownable2Step, ERC4626, ReentrancyGuard {
170
168
return withdrawn;
171
169
}
172
170
173
-
174
171
function maxAvailableShares () public view returns (uint256 ) {
175
172
return convertToShares (_totalAssets ());
176
173
}
@@ -180,28 +177,25 @@ contract ParallelVault is Gauge, Ownable2Step, ERC4626, ReentrancyGuard {
180
177
}
181
178
182
179
function _checkDelayAndRebalance () internal returns (uint256 ) {
183
-
184
180
uint128 timeElapsed = uint128 (block .timestamp ) - lastRebalanceTimestamp;
185
181
if (timeElapsed >= rebalanceingDelay) {
186
182
return _rebalance ();
187
183
}
188
184
}
189
185
190
186
function _rebalance () internal returns (uint256 ) {
191
-
192
187
if (strategy == address (0 )) return ;
193
188
lastRebalanceTimestamp = uint128 (block .timestamp );
194
189
// Compute the line of credit the Vault is able to offer the Strategy (if any)
195
190
uint256 credit = _creditAvailable ();
196
191
uint256 pendingDebt = _debtOutstanding ();
197
192
198
- if (credit> 0 ) {
193
+ if (credit > 0 ) {
199
194
// Credit surplus, give to Strategy
200
195
totalIdle -= credit;
201
196
totalDebt += credit;
202
197
token__.safeTransfer (strategy, credit);
203
198
IStrategy (strategy).invest ();
204
-
205
199
} else if (pendingDebt > 0 ) {
206
200
// Credit deficit, take from Strategy
207
201
_withdrawFromStrategy (pendingDebt);
0 commit comments