-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSorbettoFragola.sol
611 lines (526 loc) · 24.3 KB
/
SorbettoFragola.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
// SPDX-License-Identifier: MIT
pragma solidity 0.7.6;
pragma abicoder v2;
import "./interfaces/external/IWETH9.sol";
import "./utils/ReentrancyGuard.sol";
import './libraries/TransferHelper.sol';
import "./libraries/SqrtPriceMath.sol";
import "./base/ERC20Permit.sol";
import "./libraries/Babylonian.sol";
import "./libraries/PoolActions.sol";
import "./interfaces/ISorbettoStrategy.sol";
import "./interfaces/IsorbettoFragola.sol";
/// @title Sorbetto Fragola is a yield enchancement v3 contract
/// @dev Sorbetto fragola is a Uniswap V3 yield enchancement contract which acts as
/// intermediary between the user who wants to provide liquidity to specific pools
/// and earn fees from such actions. The contract ensures that user position is in
/// range and earns maximum amount of fees available at current liquidity utilization
/// rate.
contract SorbettoFragola is ERC20Permit, ReentrancyGuard, ISorbettoFragola {
using LowGasSafeMath for uint256;
using LowGasSafeMath for uint160;
using LowGasSafeMath for uint128;
using UnsafeMath for uint256;
using SafeCast for uint256;
using PoolVariables for IUniswapV3Pool;
using PoolActions for IUniswapV3Pool;
//Any data passed through by the caller via the IUniswapV3PoolActions#mint call
struct MintCallbackData {
address payer;
}
//Any data passed through by the caller via the IUniswapV3PoolActions#swap call
struct SwapCallbackData {
bool zeroForOne;
}
// Info of each user
struct UserInfo {
uint256 token0Rewards; // The amount of fees in token 0
uint256 token1Rewards; // The amount of fees in token 1
uint256 token0PerSharePaid; // Token 0 reward debt
uint256 token1PerSharePaid; // Token 1 reward debt
}
/// @notice Emitted when user adds liquidity
/// @param sender The address that minted the liquidity
/// @param liquidity The amount of liquidity added by the user to position
/// @param amount0 How much token0 was required for the added liquidity
/// @param amount1 How much token1 was required for the added liquidity
event Deposit(
address indexed sender,
uint256 liquidity,
uint256 amount0,
uint256 amount1
);
/// @notice Emitted when user withdraws liquidity
/// @param sender The address that minted the liquidity
/// @param shares of liquidity withdrawn by the user from the position
/// @param amount0 How much token0 was required for the added liquidity
/// @param amount1 How much token1 was required for the added liquidity
event Withdraw(
address indexed sender,
uint256 shares,
uint256 amount0,
uint256 amount1
);
/// @notice Emitted when fees was collected from the pool
/// @param feesFromPool0 Total amount of fees collected in terms of token 0
/// @param feesFromPool1 Total amount of fees collected in terms of token 1
/// @param usersFees0 Total amount of fees collected by users in terms of token 0
/// @param usersFees1 Total amount of fees collected by users in terms of token 1
event CollectFees(
uint256 feesFromPool0,
uint256 feesFromPool1,
uint256 usersFees0,
uint256 usersFees1
);
/// @notice Emitted when sorbetto fragola changes the position in the pool
/// @param tickLower Lower price tick of the positon
/// @param tickUpper Upper price tick of the position
/// @param amount0 Amount of token 0 deposited to the position
/// @param amount1 Amount of token 1 deposited to the position
event Rerange(
int24 tickLower,
int24 tickUpper,
uint256 amount0,
uint256 amount1
);
/// @notice Emitted when user collects his fee share
/// @param sender User address
/// @param fees0 Exact amount of fees claimed by the users in terms of token 0
/// @param fees1 Exact amount of fees claimed by the users in terms of token 1
event RewardPaid(
address indexed sender,
uint256 fees0,
uint256 fees1
);
/// @notice Shows current Sorbetto's balances
/// @param totalAmount0 Current token0 Sorbetto's balance
/// @param totalAmount1 Current token1 Sorbetto's balance
event Snapshot(uint256 totalAmount0, uint256 totalAmount1);
event TransferGovernance(address indexed previousGovernance, address indexed newGovernance);
/// @notice Prevents calls from users
modifier onlyGovernance {
require(msg.sender == governance, "OG");
_;
}
mapping(address => UserInfo) public userInfo; // Info of each user that provides liquidity tokens.
/// @inheritdoc ISorbettoFragola
address public immutable override token0;
/// @inheritdoc ISorbettoFragola
address public immutable override token1;
// WETH address
address public immutable weth = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
// @inheritdoc ISorbettoFragola
int24 public immutable override tickSpacing;
uint24 immutable GLOBAL_DIVISIONER = 1e6; // for basis point (0.0001%)
// @inheritdoc ISorbettoFragola
IUniswapV3Pool public override pool;
// Accrued protocol fees in terms of token0
uint256 public accruedProtocolFees0;
// Accrued protocol fees in terms of token1
uint256 public accruedProtocolFees1;
// Total lifetime accrued users fees in terms of token0
uint256 public usersFees0;
// Total lifetime accrued users fees in terms of token1
uint256 public usersFees1;
// intermediate variable for user fee token0 calculation
uint256 public token0PerShareStored;
// intermediate variable for user fee token1 calculation
uint256 public token1PerShareStored;
// Address of the Sorbetto's owner
address public governance;
// Pending to claim ownership address
address public pendingGovernance;
//Sorbetto fragola settings address
address public strategy;
// Current tick lower of sorbetto pool position
int24 public override tickLower;
// Current tick higher of sorbetto pool position
int24 public override tickUpper;
// Checks if sorbetto is initialized
bool public finalized;
/**
* @dev After deploying, strategy can be set via `setStrategy()`
* @param _pool Underlying Uniswap V3 pool with fee = 3000
* @param _strategy Underlying Sorbetto Strategy for Sorbetto settings
*/
constructor(
address _pool,
address _strategy
) ERC20("Popsicle LP V3 USDT/WETH", "PLP") ERC20Permit("Popsicle LP V3 USDT/WETH") {
pool = IUniswapV3Pool(_pool);
strategy = _strategy;
token0 = pool.token0();
token1 = pool.token1();
tickSpacing = pool.tickSpacing();
governance = msg.sender;
}
//initialize strategy
function init() external onlyGovernance {
require(!finalized, "F");
finalized = true;
int24 baseThreshold = tickSpacing * ISorbettoStrategy(strategy).tickRangeMultiplier();
( , int24 currentTick, , , , , ) = pool.slot0();
int24 tickFloor = PoolVariables.floor(currentTick, tickSpacing);
tickLower = tickFloor - baseThreshold;
tickUpper = tickFloor + baseThreshold;
PoolVariables.checkRange(tickLower, tickUpper); //check ticks also for overflow/underflow
}
/// @inheritdoc ISorbettoFragola
function deposit(
uint256 amount0Desired,
uint256 amount1Desired
)
external
payable
override
nonReentrant
checkDeviation
updateVault(msg.sender)
returns (
uint256 shares,
uint256 amount0,
uint256 amount1
)
{
require(amount0Desired > 0 && amount1Desired > 0, "ANV");
uint128 liquidityLast = pool.positionLiquidity(tickLower, tickUpper);
// compute the liquidity amount
uint128 liquidity = pool.liquidityForAmounts(amount0Desired, amount1Desired, tickLower, tickUpper);
(amount0, amount1) = pool.mint(
address(this),
tickLower,
tickUpper,
liquidity,
abi.encode(MintCallbackData({payer: msg.sender})));
shares = _calcShare(liquidity, liquidityLast);
_mint(msg.sender, shares);
refundETH();
emit Deposit(msg.sender, shares, amount0, amount1);
}
/// @inheritdoc ISorbettoFragola
function withdraw(
uint256 shares
)
external
override
nonReentrant
checkDeviation
updateVault(msg.sender)
returns (
uint256 amount0,
uint256 amount1
)
{
require(shares > 0, "S");
(amount0, amount1) = pool.burnLiquidityShare(tickLower, tickUpper, totalSupply(), shares, msg.sender);
// Burn shares
_burn(msg.sender, shares);
emit Withdraw(msg.sender, shares, amount0, amount1);
}
/// @inheritdoc ISorbettoFragola
function rerange() external override nonReentrant checkDeviation updateVault(address(0)) {
//Burn all liquidity from pool to rerange for Sorbetto's balances.
pool.burnAllLiquidity(tickLower, tickUpper);
// Emit snapshot to record balances
uint256 balance0 = _balance0();
uint256 balance1 = _balance1();
emit Snapshot(balance0, balance1);
int24 baseThreshold = tickSpacing * ISorbettoStrategy(strategy).tickRangeMultiplier();
//Get exact ticks depending on Sorbetto's balances
(tickLower, tickUpper) = pool.getPositionTicks(balance0, balance1, baseThreshold, tickSpacing);
//Get Liquidity for Sorbetto's balances
uint128 liquidity = pool.liquidityForAmounts(balance0, balance1, tickLower, tickUpper);
// Add liquidity to the pool
(uint256 amount0, uint256 amount1) = pool.mint(
address(this),
tickLower,
tickUpper,
liquidity,
abi.encode(MintCallbackData({payer: address(this)})));
emit Rerange(tickLower, tickUpper, amount0, amount1);
}
/// @inheritdoc ISorbettoFragola
function rebalance() external override onlyGovernance nonReentrant checkDeviation updateVault(address(0)) {
//Burn all liquidity from pool to rerange for Sorbetto's balances.
pool.burnAllLiquidity(tickLower, tickUpper);
//Calc base ticks
(uint160 sqrtPriceX96, int24 currentTick, , , , , ) = pool.slot0();
PoolVariables.Info memory cache =
PoolVariables.Info(0, 0, 0, 0, 0, 0, 0);
int24 baseThreshold = tickSpacing * ISorbettoStrategy(strategy).tickRangeMultiplier();
(cache.tickLower, cache.tickUpper) = PoolVariables.baseTicks(currentTick, baseThreshold, tickSpacing);
cache.amount0Desired = _balance0();
cache.amount1Desired = _balance1();
emit Snapshot(cache.amount0Desired, cache.amount1Desired);
// Calc liquidity for base ticks
cache.liquidity = pool.liquidityForAmounts(cache.amount0Desired, cache.amount1Desired, cache.tickLower, cache.tickUpper);
// Get exact amounts for base ticks
(cache.amount0, cache.amount1) = pool.amountsForLiquidity(cache.liquidity, cache.tickLower, cache.tickUpper);
// Get imbalanced token
bool zeroForOne = PoolVariables.amountsDirection(cache.amount0Desired, cache.amount1Desired, cache.amount0, cache.amount1);
// Calculate the amount of imbalanced token that should be swapped. Calculations strive to achieve one to one ratio
int256 amountSpecified =
zeroForOne
? int256(cache.amount0Desired.sub(cache.amount0).unsafeDiv(2))
: int256(cache.amount1Desired.sub(cache.amount1).unsafeDiv(2)); // always positive. "overflow" safe convertion cuz we are dividing by 2
// Calculate Price limit depending on price impact
uint160 exactSqrtPriceImpact = sqrtPriceX96.mul160(ISorbettoStrategy(strategy).priceImpactPercentage() / 2) / GLOBAL_DIVISIONER;
uint160 sqrtPriceLimitX96 = zeroForOne ? sqrtPriceX96.sub160(exactSqrtPriceImpact) : sqrtPriceX96.add160(exactSqrtPriceImpact);
//Swap imbalanced token as long as we haven't used the entire amountSpecified and haven't reached the price limit
pool.swap(
address(this),
zeroForOne,
amountSpecified,
sqrtPriceLimitX96,
abi.encode(SwapCallbackData({zeroForOne: zeroForOne}))
);
(sqrtPriceX96, currentTick, , , , , ) = pool.slot0();
// Emit snapshot to record balances
cache.amount0Desired = _balance0();
cache.amount1Desired = _balance1();
emit Snapshot(cache.amount0Desired, cache.amount1Desired);
//Get exact ticks depending on Sorbetto's new balances
(tickLower, tickUpper) = pool.getPositionTicks(cache.amount0Desired, cache.amount1Desired, baseThreshold, tickSpacing);
cache.liquidity = pool.liquidityForAmounts(cache.amount0Desired, cache.amount1Desired, tickLower, tickUpper);
// Add liquidity to the pool
(cache.amount0, cache.amount1) = pool.mint(
address(this),
tickLower,
tickUpper,
cache.liquidity,
abi.encode(MintCallbackData({payer: address(this)})));
emit Rerange(tickLower, tickUpper, cache.amount0, cache.amount1);
}
// Calcs user share depending on deposited amounts
function _calcShare(uint128 liquidity, uint128 liquidityLast)
internal
view
returns (
uint256 shares
)
{
shares = totalSupply() == 0 ? uint256(liquidity) : uint256(liquidity).mul(totalSupply()).unsafeDiv(uint256(liquidityLast));
}
/// @dev Amount of token0 held as unused balance.
function _balance0() internal view returns (uint256) {
return IERC20(token0).balanceOf(address(this));
}
/// @dev Amount of token1 held as unused balance.
function _balance1() internal view returns (uint256) {
return IERC20(token1).balanceOf(address(this));
}
/// @dev collects fees from the pool
function _earnFees() internal returns (uint256 userCollect0, uint256 userCollect1) {
// Do zero-burns to poke the Uniswap pools so earned fees are updated
pool.burn(tickLower, tickUpper, 0);
(uint256 collect0, uint256 collect1) =
pool.collect(
address(this),
tickLower,
tickUpper,
type(uint128).max,
type(uint128).max
);
// Calculate protocol's and users share of fees
uint256 feeToProtocol0 = collect0.mul(ISorbettoStrategy(strategy).protocolFee()).unsafeDiv(GLOBAL_DIVISIONER);
uint256 feeToProtocol1 = collect1.mul(ISorbettoStrategy(strategy).protocolFee()).unsafeDiv(GLOBAL_DIVISIONER);
accruedProtocolFees0 = accruedProtocolFees0.add(feeToProtocol0);
accruedProtocolFees1 = accruedProtocolFees1.add(feeToProtocol1);
userCollect0 = collect0.sub(feeToProtocol0);
userCollect1 = collect1.sub(feeToProtocol1);
usersFees0 = usersFees0.add(userCollect0);
usersFees1 = usersFees1.add(userCollect1);
emit CollectFees(collect0, collect1, usersFees0, usersFees1);
}
/// @notice Returns current Sorbetto's position in pool
function position() external view returns (uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1) {
bytes32 positionKey = PositionKey.compute(address(this), tickLower, tickUpper);
(liquidity, feeGrowthInside0LastX128, feeGrowthInside1LastX128, tokensOwed0, tokensOwed1) = pool.positions(positionKey);
}
/// @notice Pull in tokens from sender. Called to `msg.sender` after minting liquidity to a position from IUniswapV3Pool#mint.
/// @dev In the implementation you must pay to the pool for the minted liquidity.
/// @param amount0 The amount of token0 due to the pool for the minted liquidity
/// @param amount1 The amount of token1 due to the pool for the minted liquidity
/// @param data Any data passed through by the caller via the IUniswapV3PoolActions#mint call
function uniswapV3MintCallback(
uint256 amount0,
uint256 amount1,
bytes calldata data
) external {
require(msg.sender == address(pool), "FP");
MintCallbackData memory decoded = abi.decode(data, (MintCallbackData));
if (amount0 > 0) pay(token0, decoded.payer, msg.sender, amount0);
if (amount1 > 0) pay(token1, decoded.payer, msg.sender, amount1);
}
/// @notice Called to `msg.sender` after minting swaping from IUniswapV3Pool#swap.
/// @dev In the implementation you must pay to the pool for swap.
/// @param amount0 The amount of token0 due to the pool for the swap
/// @param amount1 The amount of token1 due to the pool for the swap
/// @param _data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
function uniswapV3SwapCallback(
int256 amount0,
int256 amount1,
bytes calldata _data
) external {
require(msg.sender == address(pool), "FP");
require(amount0 > 0 || amount1 > 0); // swaps entirely within 0-liquidity regions are not supported
SwapCallbackData memory data = abi.decode(_data, (SwapCallbackData));
bool zeroForOne = data.zeroForOne;
if (zeroForOne) pay(token0, address(this), msg.sender, uint256(amount0));
else pay(token1, address(this), msg.sender, uint256(amount1));
}
/// @param token The token to pay
/// @param payer The entity that must pay
/// @param recipient The entity that will receive payment
/// @param value The amount to pay
function pay(
address token,
address payer,
address recipient,
uint256 value
) internal {
if (token == weth && address(this).balance >= value) {
// pay with WETH9
IWETH9(weth).deposit{value: value}(); // wrap only what is needed to pay
IWETH9(weth).transfer(recipient, value);
} else if (payer == address(this)) {
// pay with tokens already in the contract (for the exact input multihop case)
TransferHelper.safeTransfer(token, recipient, value);
} else {
// pull payment
TransferHelper.safeTransferFrom(token, payer, recipient, value);
}
}
/**
* @notice Used to withdraw accumulated protocol fees.
*/
function collectProtocolFees(
uint256 amount0,
uint256 amount1
) external nonReentrant onlyGovernance updateVault(address(0)) {
require(accruedProtocolFees0 >= amount0, "A0F");
require(accruedProtocolFees1 >= amount1, "A1F");
uint256 balance0 = _balance0();
uint256 balance1 = _balance1();
if (balance0 >= amount0 && balance1 >= amount1)
{
if (amount0 > 0) pay(token0, address(this), msg.sender, amount0);
if (amount1 > 0) pay(token1, address(this), msg.sender, amount1);
}
else
{
uint128 liquidity = pool.liquidityForAmounts(amount0, amount1, tickLower, tickUpper);
pool.burnExactLiquidity(tickLower, tickUpper, liquidity, msg.sender);
}
accruedProtocolFees0 = accruedProtocolFees0.sub(amount0);
accruedProtocolFees1 = accruedProtocolFees1.sub(amount1);
emit RewardPaid(msg.sender, amount0, amount1);
}
/**
* @notice Used to withdraw accumulated user's fees.
*/
function collectFees(uint256 amount0, uint256 amount1) external nonReentrant updateVault(msg.sender) {
UserInfo storage user = userInfo[msg.sender];
require(user.token0Rewards >= amount0, "A0R");
require(user.token1Rewards >= amount1, "A1R");
uint256 balance0 = _balance0();
uint256 balance1 = _balance1();
if (balance0 >= amount0 && balance1 >= amount1) {
if (amount0 > 0) pay(token0, address(this), msg.sender, amount0);
if (amount1 > 0) pay(token1, address(this), msg.sender, amount1);
}
else {
uint128 liquidity = pool.liquidityForAmounts(amount0, amount1, tickLower, tickUpper);
(amount0, amount1) = pool.burnExactLiquidity(tickLower, tickUpper, liquidity, msg.sender);
}
user.token0Rewards = user.token0Rewards.sub(amount0);
user.token1Rewards = user.token1Rewards.sub(amount1);
emit RewardPaid(msg.sender, amount0, amount1);
}
// Function modifier that calls update fees reward function
modifier updateVault(address account) {
_updateFeesReward(account);
_;
}
// Function modifier that checks if price has not moved a lot recently.
// This mitigates price manipulation during rebalance and also prevents placing orders
// when it's too volatile.
modifier checkDeviation() {
pool.checkDeviation(ISorbettoStrategy(strategy).maxTwapDeviation(), ISorbettoStrategy(strategy).twapDuration());
_;
}
// Updates user's fees reward
function _updateFeesReward(address account) internal {
uint liquidity = pool.positionLiquidity(tickLower, tickUpper);
if (liquidity == 0) return; // we can't poke when liquidity is zero
(uint256 collect0, uint256 collect1) = _earnFees();
token0PerShareStored = _tokenPerShare(collect0, token0PerShareStored);
token1PerShareStored = _tokenPerShare(collect1, token1PerShareStored);
if (account != address(0)) {
UserInfo storage user = userInfo[msg.sender];
user.token0Rewards = _fee0Earned(account, token0PerShareStored);
user.token0PerSharePaid = token0PerShareStored;
user.token1Rewards = _fee1Earned(account, token1PerShareStored);
user.token1PerSharePaid = token1PerShareStored;
}
}
// Calculates how much token0 is entitled for a particular user
function _fee0Earned(address account, uint256 fee0PerShare_) internal view returns (uint256) {
UserInfo memory user = userInfo[account];
return
balanceOf(account)
.mul(fee0PerShare_.sub(user.token0PerSharePaid))
.unsafeDiv(1e18)
.add(user.token0Rewards);
}
// Calculates how much token1 is entitled for a particular user
function _fee1Earned(address account, uint256 fee1PerShare_) internal view returns (uint256) {
UserInfo memory user = userInfo[account];
return
balanceOf(account)
.mul(fee1PerShare_.sub(user.token1PerSharePaid))
.unsafeDiv(1e18)
.add(user.token1Rewards);
}
// Calculates how much token is provided per LP token
function _tokenPerShare(uint256 collected, uint256 tokenPerShareStored) internal view returns (uint256) {
uint _totalSupply = totalSupply();
if (_totalSupply > 0) {
return tokenPerShareStored
.add(
collected
.mul(1e18)
.unsafeDiv(_totalSupply)
);
}
return tokenPerShareStored;
}
/// @notice Refunds any ETH balance held by this contract to the `msg.sender`
/// @dev Useful for bundling with mint or increase liquidity that uses ether, or exact output swaps
/// that use ether for the input amount
function refundETH() internal {
if (address(this).balance > 0) TransferHelper.safeTransferETH(msg.sender, address(this).balance);
}
/**
* @notice `setGovernance()` should be called by the existing governance
* address prior to calling this function.
*/
function setGovernance(address _governance) external onlyGovernance {
pendingGovernance = _governance;
}
/**
* @notice Governance address is not updated until the new governance
* address has called `acceptGovernance()` to accept this responsibility.
*/
function acceptGovernance() external {
require(msg.sender == pendingGovernance, "PG");
emit TransferGovernance(governance, pendingGovernance);
pendingGovernance = address(0);
governance = msg.sender;
}
// Sets new strategy contract address for new settings
function setStrategy(address _strategy) external onlyGovernance {
require(_strategy != address(0), "NA");
strategy = _strategy;
}
}