-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix strategy, update unreal addresses, IFO event, scripts
- Loading branch information
Showing
10 changed files
with
266 additions
and
14 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.21; | ||
|
||
import "forge-std/Script.sol"; | ||
import "../src/interfaces/IVault.sol"; | ||
import "../src/HarvesterVault.sol"; | ||
import "../src/interfaces/IMultiPool.sol"; | ||
import "../src/IFO.sol"; | ||
import "../src/PearlStrategyCustomIFO.sol"; | ||
|
||
|
||
contract DeployCustomIfoVaultAndStrategy is Script { | ||
address public constant CONTROLLER = 0x4F69329E8dE13aA7EAc664368C5858AF6371FA4c; | ||
address public constant STGN = 0x609e0d74fAB81085283df92B563750624054F8bE; | ||
address public constant PEARL_TOKEN = 0xCE1581d7b4bA40176f0e219b2CaC30088Ad50C7A; | ||
|
||
function run() external { | ||
address underlying = 0xAB5a4189e947E0e3EbEc25637f73deb55f6CEEA9; | ||
address pearlGauge = 0x54CbD289B263CD14E6707EcbDa01161c4385DFe3; | ||
|
||
uint deployerPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
vm.startBroadcast(deployerPrivateKey); | ||
|
||
IFO ifo = new IFO(12e17); | ||
ifo.setup(CONTROLLER, STGN, PEARL_TOKEN); | ||
|
||
address vault = address( | ||
new HarvesterVault( | ||
CONTROLLER, | ||
IERC20(underlying), | ||
"IFO Harvester DAI-USDC custom", | ||
"ifocTDT-DAI-USDC", | ||
4_000 | ||
) | ||
); | ||
address strategy = address(new PearlStrategyCustomIFO(address(ifo), vault, pearlGauge, true, address(0))); | ||
IVault(vault).setStrategy(strategy); | ||
address multigauge = IController(CONTROLLER).multigauge(); | ||
IGauge(multigauge).addStakingToken(vault); | ||
IController(CONTROLLER).registerVault(vault, true); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
|
||
function testDeploy_() external {} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.21; | ||
|
||
import "forge-std/Script.sol"; | ||
import "../src/interfaces/IVault.sol"; | ||
import "../src/HarvesterVault.sol"; | ||
import "../src/PearlStrategy.sol"; | ||
import "../src/interfaces/IMultiPool.sol"; | ||
|
||
|
||
contract DeployVaultAndStrategy is Script { | ||
address public constant CONTROLLER = 0x4F69329E8dE13aA7EAc664368C5858AF6371FA4c; | ||
|
||
function run() external { | ||
address underlying = 0xAB5a4189e947E0e3EbEc25637f73deb55f6CEEA9; | ||
address pearlGauge = 0x54CbD289B263CD14E6707EcbDa01161c4385DFe3; | ||
address compounderVault = 0xE983c2da7Ef6bFFF9b0b10ADdBF2f0E1ed9b5043; | ||
|
||
uint deployerPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
vm.startBroadcast(deployerPrivateKey); | ||
|
||
address vault = address( | ||
new HarvesterVault( | ||
CONTROLLER, | ||
IERC20(underlying), | ||
"Harvester DAI-USDC (New)", | ||
"xTDT-DAI-USDC", | ||
4_000 | ||
) | ||
); | ||
address strategy = address(new PearlStrategy(vault, pearlGauge, false, compounderVault)); | ||
IVault(vault).setStrategy(strategy); | ||
address multigauge = IController(CONTROLLER).multigauge(); | ||
IGauge(multigauge).addStakingToken(vault); | ||
IMultiPool(multigauge).registerRewardToken(vault, compounderVault); | ||
IController(CONTROLLER).registerVault(vault, true); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
|
||
function testDeploy_() external {} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.21; | ||
|
||
import "forge-std/Script.sol"; | ||
import "../src/Factory.sol"; | ||
|
||
contract PrepareFactoryUpgrade is Script { | ||
function run() external { | ||
uint deployerPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
vm.startBroadcast(deployerPrivateKey); | ||
new Factory(); | ||
vm.stopBroadcast(); | ||
} | ||
|
||
function testDeploy_() external {} | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.21; | ||
|
||
import "./base/StrategyStrictBase.sol"; | ||
import "./interfaces/IVault.sol"; | ||
import "./interfaces/IGaugeV2ALM.sol"; | ||
import "./interfaces/IController.sol"; | ||
import "./interfaces/IIFO.sol"; | ||
import "./interfaces/IGauge.sol"; | ||
import "./interfaces/ITetuLiquidator.sol"; | ||
import "./interfaces/IVeDistributor.sol"; | ||
|
||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.°:°•.°+.*•´.*:*.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*/ | ||
/* Pearl strategy */ | ||
/* Contract for taking care of all necessary actions for the underlying token such us: */ | ||
/* Rewards utilization via Liquidator */ | ||
/* Compounding - creating more underlying */ | ||
/* Sending profit to different destinations */ | ||
/* Have rewards/compounding logic, depending on setup case */ | ||
/* Strategy should send gas compensation on every compounding */ | ||
/* Compensation will be taken from user part of profit but no more than 10% */ | ||
/* Compounding should be called no more frequently than 1 per 12h */ | ||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.°:°•.°+.*•´.*:*.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*/ | ||
|
||
contract PearlStrategyCustomIFO is StrategyStrictBase { | ||
using SafeERC20 for IERC20; | ||
|
||
uint internal constant LIQUIDATOR_PRICE_IMPACT_TOLERANCE = 20_000; | ||
|
||
uint public lastHardWork; | ||
|
||
address public gauge; | ||
|
||
address public gaugeRewardToken; | ||
|
||
address public ifoAddress; | ||
|
||
bool public ifo; | ||
|
||
address public compounder; | ||
|
||
constructor(address ifoAddress_, address vault_, address gauge_, bool ifo_, address compounder_) StrategyStrictBase(vault_) { | ||
gauge = gauge_; | ||
ifo = ifo_; | ||
ifoAddress = ifoAddress_; | ||
compounder = compounder_; | ||
IERC20(asset).approve(gauge_, type(uint).max); | ||
IController controller = IController(IVault(vault).controller()); | ||
address _gaugeRewardToken = IGaugeV2ALM(gauge_).rewardToken(); | ||
gaugeRewardToken = _gaugeRewardToken; | ||
if (ifo) { | ||
IERC20(_gaugeRewardToken).approve(ifoAddress_, type(uint).max); | ||
IERC20(controller.stgn()).approve(controller.multigauge(), type(uint).max); | ||
} else { | ||
IERC20(_gaugeRewardToken).approve(controller.liquidator(), type(uint).max); | ||
address compounderAsset = IERC4626(compounder_).asset(); | ||
IERC20(compounderAsset).approve(compounder_, type(uint).max); | ||
IERC20(compounder_).approve(controller.multigauge(), type(uint).max); | ||
} | ||
} | ||
|
||
function isReadyToHardWork() external view returns (bool) { | ||
return IGaugeV2ALM(gauge).earnedReward(address(this)) > 0; | ||
} | ||
|
||
function doHardWork() external /* returns (uint earned, uint lost)*/ { | ||
// claim fees if available | ||
// liquidate fee if available | ||
|
||
uint rtReward = _claim(); | ||
uint perfFee = rtReward / 10; | ||
uint veDistFee = perfFee / 2; | ||
rtReward -= perfFee; | ||
IERC20 rt = IERC20(gaugeRewardToken); | ||
|
||
IController controller = IController(IVault(vault).controller()); | ||
IVeDistributor veDist = IVeDistributor(controller.veDistributor()); | ||
rt.safeTransfer(address(veDist), veDistFee); | ||
veDist.checkpoint(); | ||
rt.safeTransfer(controller.perfFeeTreasury(), perfFee - veDistFee); | ||
|
||
IGauge multigauge = IGauge(controller.multigauge()); | ||
if (ifo) { | ||
IIFO _ifo = IIFO(ifoAddress); | ||
(bool exchanged, uint got) = _ifo.exchange(rtReward); | ||
if (exchanged && got > 0) { | ||
multigauge.notifyRewardAmount(vault, controller.stgn(), got); | ||
} | ||
} else { | ||
address _compounder = compounder; | ||
ITetuLiquidator l = ITetuLiquidator(controller.liquidator()); | ||
address asset = IERC4626(_compounder).asset(); | ||
uint b = IERC20(asset).balanceOf(address(this)); | ||
l.liquidate(gaugeRewardToken, asset, rtReward, LIQUIDATOR_PRICE_IMPACT_TOLERANCE); | ||
uint got = IERC20(asset).balanceOf(address(this)) - b; | ||
if (got > 0) { | ||
uint shares = IERC4626(_compounder).deposit(got, address(this)); | ||
multigauge.notifyRewardAmount(vault, _compounder, shares); | ||
} | ||
} | ||
} | ||
|
||
function investedAssets() public view override returns (uint) { | ||
return IGaugeV2ALM(gauge).balanceOf(address(this)); | ||
} | ||
|
||
function _claim() internal override returns (uint rtReward) { | ||
IERC20 rt = IERC20(gaugeRewardToken); | ||
uint oldBal = rt.balanceOf(address(this)); | ||
IGaugeV2ALM(gauge).collectReward(); | ||
rtReward = rt.balanceOf(address(this)) - oldBal; | ||
} | ||
|
||
function _depositToPool(uint amount) internal override { | ||
IGaugeV2ALM(gauge).deposit(amount); | ||
} | ||
|
||
function _emergencyExitFromPool() internal override { | ||
_withdrawAllFromPool(); | ||
IERC20(asset).safeTransfer(vault, IERC20(asset).balanceOf(address(this))); | ||
} | ||
|
||
function _withdrawFromPool(uint amount) internal override { | ||
IGaugeV2ALM(gauge).withdraw(amount); | ||
IERC20(asset).safeTransfer(vault, amount); | ||
} | ||
|
||
function _withdrawAllFromPool() internal override { | ||
_withdrawFromPool(IGaugeV2ALM(gauge).balanceOf(address(this))); | ||
} | ||
} |
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