generated from yearn/brownie-strategy-mix
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathStrategyMigration.t.sol
54 lines (46 loc) · 2.1 KB
/
StrategyMigration.t.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
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.12;
import {StrategyFixture} from "./utils/StrategyFixture.sol";
import {IVault} from "../interfaces/Yearn/Vault.sol";
import {Strategy} from "../Strategy.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "@yearnvaults/contracts/yToken.sol";
// NOTE: if the name of the strat or file changes this needs to be updated
contract StrategyMigrationTest is StrategyFixture {
function setUp() public override {
super.setUp();
}
function testMigration(uint256 _fuzzAmount) public {
vm.assume(_fuzzAmount > minFuzzAmt && _fuzzAmount < maxFuzzAmt);
for(uint8 i = 0; i < assetFixtures.length; ++i) {
AssetFixture memory _assetFixture = assetFixtures[i];
IVault vault = _assetFixture.vault;
Strategy strategy = _assetFixture.strategy;
IERC20 want = _assetFixture.want;
uint256 _amount = _fuzzAmount;
uint8 _wantDecimals = IERC20Metadata(address(want)).decimals();
if (_wantDecimals != 18) {
uint256 _decimalDifference = 18 - _wantDecimals;
_amount = _amount / (10 ** _decimalDifference);
}
deal(address(want), user, _amount);
// Deposit to the vault and harvest
vm.prank(user);
want.approve(address(vault), _amount);
vm.prank(user);
vault.deposit(_amount);
skip(1);
vm.prank(strategist);
strategy.harvest();
assertRelApproxEq(strategy.estimatedTotalAssets(), _amount, DELTA);
// Migrate to a new strategy
vm.prank(strategist);
Strategy newStrategy = Strategy(deployStrategy(address(vault), IERC20Metadata(address(want)).symbol()));
vm.prank(gov);
strategy.claimRewards(); // manual claim rewards
vm.prank(gov);
vault.migrateStrategy(address(strategy), address(newStrategy));
assertRelApproxEq(newStrategy.estimatedTotalAssets(), _amount, DELTA);
}
}
}