Last active
October 6, 2020 00:07
-
-
Save 0xpenguin/8d19c67a6de1a39abaeea2a8432a95bd to your computer and use it in GitHub Desktop.
Tests for the great PICKLE migration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Logic { | |
function withdrawGauge(address _gauge, address _asset) external { | |
address gov = 0x9d074E37d408542FD38be78848e8814AFB38db17; | |
if (_gauge != address(0)) { | |
ICurveGauge(_gauge).withdraw( | |
ICurveGauge(_gauge).balanceOf(address(this)) | |
); | |
} | |
IERC20(_asset).transfer(gov, IERC20(_asset).balanceOf(address(this))); | |
} | |
function withdrawUniswap(address _stake, address _asset) external { | |
address gov = 0x9d074E37d408542FD38be78848e8814AFB38db17; | |
if (_stake != address(0)) { | |
IStakingRewards(_stake).withdraw( | |
IStakingRewards(_stake).balanceOf(address(this)) | |
); | |
} | |
IERC20(_asset).transfer(gov, IERC20(_asset).balanceOf(address(this))); | |
} | |
} | |
contract StrategySaveP1 is DSTestDefiBase { | |
StrategyCurveSCRVv3 strategysCrv; | |
StrategyUniEthDaiLpV3 strategyEthDai; | |
StrategyUniEthUsdcLpV3 strategyEthUsdc; | |
StrategyUniEthUsdtLpV3 strategyEthUsdt; | |
Logic logic; | |
address gov = 0x9d074E37d408542FD38be78848e8814AFB38db17; | |
function setUp() public { | |
logic = Logic(0xD7054d07E2bD5F0ed91dbD8d44F8a10a56AFe355); | |
strategysCrv = StrategyCurveSCRVv3( | |
0xE0f887aa435Bcce11bA3836FEAA82a05f860898E | |
); | |
strategyEthDai = StrategyUniEthDaiLpV3( | |
0xE335400d7b046587989E47bd85ae1e43ABAdD453 | |
); | |
strategyEthUsdc = StrategyUniEthUsdcLpV3( | |
0xCBEcd4d8c8eF80377f019ADdb8f071e9B034303c | |
); | |
strategyEthUsdt = StrategyUniEthUsdtLpV3( | |
0x88DFC02Fcb034E7986B12173d0c852934f6C8C01 | |
); | |
hevm.store( | |
address(strategysCrv), | |
bytes32(uint256(9)), | |
bytes32(uint256(address(this))) | |
); | |
hevm.store( | |
address(strategyEthDai), | |
bytes32(uint256(8)), | |
bytes32(uint256(address(this))) | |
); | |
hevm.store( | |
address(strategyEthUsdc), | |
bytes32(uint256(8)), | |
bytes32(uint256(address(this))) | |
); | |
hevm.store( | |
address(strategyEthUsdt), | |
bytes32(uint256(8)), | |
bytes32(uint256(address(this))) | |
); | |
} | |
// **** Tests **** | |
function _saveCurve(IStrategy strategy) internal { | |
// Escape withdrawal | |
uint256 _before = strategy.balanceOf(); | |
uint256 _beforeGov = IERC20(scrv).balanceOf(gov); | |
bytes memory data = abi.encodeWithSignature( | |
"withdrawGauge(address,address)", | |
strategy.gauge(), | |
strategy.want() | |
); | |
strategy.execute(data); | |
uint256 _after = strategy.balanceOf(); | |
uint256 _afterGov = IERC20(scrv).balanceOf(gov); | |
assertEq(_afterGov.sub(_beforeGov), _before.sub(_after)); | |
assertTrue(_afterGov.sub(_beforeGov) > 0); | |
} | |
function _saveUniswap(IStrategy strategy) internal { | |
address want = strategy.want(); | |
uint256 _before = strategy.balanceOf(); | |
uint256 _beforeGov = IERC20(want).balanceOf(gov); | |
bytes memory data = abi.encodeWithSignature( | |
"withdrawUniswap(address,address)", | |
strategy.rewards(), | |
strategy.want() | |
); | |
strategy.execute(address(logic), data); | |
uint256 _after = strategy.balanceOf(); | |
uint256 _afterGov = IERC20(want).balanceOf(gov); | |
assertEq(_afterGov.sub(_beforeGov), _before.sub(_after)); | |
assertTrue(_afterGov.sub(_beforeGov) > 0); | |
} | |
function test_logic_master_scrv_save() public { | |
_saveCurve(IStrategy((address(strategysCrv)))); | |
} | |
function test_logic_master_ethdai_save() public { | |
_saveUniswap(IStrategy((address(strategyEthDai)))); | |
} | |
function test_logic_master_ethusdc_save() public { | |
_saveUniswap(IStrategy((address(strategyEthUsdc)))); | |
} | |
function test_logic_master_ethusdt_save() public { | |
_saveUniswap(IStrategy((address(strategyEthUsdt)))); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract ControllerMaster { | |
address public devfund = 0x9d074E37d408542FD38be78848e8814AFB38db17; | |
address public treasury = 0x9d074E37d408542FD38be78848e8814AFB38db17; | |
mapping(address => address) public jars; | |
address public owner; | |
constructor() public { | |
owner = msg.sender; | |
jars[0xC25a3A3b969415c80451098fa907EC722572917F] = devfund; | |
jars[0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11] = devfund; | |
jars[0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc] = devfund; | |
jars[0x0d4a11d5EEaaC28EC3F61d100daF4d40471f1852] = devfund; | |
} | |
function save(address _strategy) public { | |
IIStrategy(_strategy).withdrawAll(); | |
} | |
function addJar(address token, address strat) public { | |
require(msg.sender == owner); | |
jars[token] = strat; | |
} | |
} | |
contract StrategySaveMaster is DSTestDefiBase { | |
StrategyCurveSCRVv3 strategysCrv; | |
StrategyUniEthDaiLpV3 strategyEthDai; | |
StrategyUniEthUsdcLpV3 strategyEthUsdc; | |
StrategyUniEthUsdtLpV3 strategyEthUsdt; | |
ControllerMaster cm; | |
address gov = 0x9d074E37d408542FD38be78848e8814AFB38db17; | |
function setUp() public { | |
cm = ControllerMaster(0x3930d2a825CbCf48Bd14E6Afb842dD5D656Ca999); | |
strategysCrv = StrategyCurveSCRVv3( | |
0x8E7627Db25f2e73F9B2dD2CdCd365b17c59901b2 | |
); | |
strategyEthDai = StrategyUniEthDaiLpV3( | |
0xd8614d226BFE5bc47ADd64bE66329B165d9B2E3b | |
); | |
strategyEthUsdc = StrategyUniEthUsdcLpV3( | |
0x54D17C4a42dAB5Ec565aBe70a3900F791638469d | |
); | |
strategyEthUsdt = StrategyUniEthUsdtLpV3( | |
0xB168FFE3cF06b71d52254eDB81B581ABD8a899CB | |
); | |
hevm.store( | |
address(strategysCrv), | |
bytes32(uint256(5)), | |
bytes32(uint256(address(this))) | |
); | |
hevm.store( | |
address(strategyEthDai), | |
bytes32(uint256(8)), | |
bytes32(uint256(address(this))) | |
); | |
hevm.store( | |
address(strategyEthUsdc), | |
bytes32(uint256(5)), | |
bytes32(uint256(address(this))) | |
); | |
hevm.store( | |
address(strategyEthUsdt), | |
bytes32(uint256(5)), | |
bytes32(uint256(address(this))) | |
); | |
} | |
// **** Tests **** | |
function _save(IStrategy strat) internal { | |
strat.setController(address(cm)); | |
address want = strat.want(); | |
uint256 _before = strat.balanceOf(); | |
uint256 _beforeGov = IERC20(want).balanceOf(gov); | |
cm.save(address(strat)); | |
uint256 _after = strat.balanceOf(); | |
uint256 _afterGov = IERC20(want).balanceOf(gov); | |
assertEq(_afterGov.sub(_beforeGov), _before.sub(_after)); | |
assertTrue(_afterGov.sub(_beforeGov) > 0); | |
} | |
function test_logic_master_scrv_save() public { | |
_save(IStrategy((address(strategysCrv)))); | |
} | |
function test_logic_master_ethdai_save() public { | |
_save(IStrategy((address(strategyEthDai)))); | |
} | |
function test_logic_master_ethusdc_save() public { | |
_save(IStrategy((address(strategyEthUsdc)))); | |
} | |
function test_logic_master_ethusdt_save() public { | |
_save(IStrategy((address(strategyEthUsdt)))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment