Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: patchgovernance and script #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 53 additions & 63 deletions contracts/StrategySolidexSolidSolidsexHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@ contract StrategySolidexSolidSolidsexHelper is BaseStrategy {
ILpDepositor(0x26E1A0d851CF28E697870e1b7F053B605C8b060F);

// Solidly
address public constant baseV1Router01 = 0xa38cd27185a464914D3046f0AB9d43356B34829D;
address public constant baseV1Router01 =
0xa38cd27185a464914D3046f0AB9d43356B34829D;

// ===== Token Registry =====
address public constant wftm = 0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83;
address public constant solid = 0x888EF71766ca594DED1F0FA3AE64eD2941740A20;
address public constant solidSex = 0x41adAc6C1Ff52C5e27568f27998d747F7b69795B;
address public constant solidSolidSexLp = 0x62E2819Dd417F3b430B6fa5Fd34a49A377A02ac8;
address public constant solidSex =
0x41adAc6C1Ff52C5e27568f27998d747F7b69795B;
address public constant solidSolidSexLp =
0x62E2819Dd417F3b430B6fa5Fd34a49A377A02ac8;
address public constant sex = 0xD31Fcd1f7Ba190dBc75354046F6024A9b86014d7;
address public constant sexWftmLp = 0xFCEC86aF8774d69e2e4412B8De3f4aBf1f671ecC;
address public constant sexWftmLp =
0xFCEC86aF8774d69e2e4412B8De3f4aBf1f671ecC;

IERC20Upgradeable public constant wftmToken =
IERC20Upgradeable(0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83);
Expand All @@ -54,7 +58,6 @@ contract StrategySolidexSolidSolidsexHelper is BaseStrategy {
IERC20Upgradeable public constant sexWftmLpToken =
IERC20Upgradeable(0xFCEC86aF8774d69e2e4412B8De3f4aBf1f671ecC);


// Constants
uint256 public constant MAX_BPS = 10000;

Expand Down Expand Up @@ -112,12 +115,21 @@ contract StrategySolidexSolidSolidsexHelper is BaseStrategy {
sl = 50;

/// @dev do one off approvals here
IERC20Upgradeable(want).safeApprove(address(lpDepositor), type(uint256).max);
IERC20Upgradeable(want).safeApprove(
address(lpDepositor),
type(uint256).max
);
IERC20Upgradeable(solid).safeApprove(baseV1Router01, type(uint256).max);
IERC20Upgradeable(solidSex).safeApprove(baseV1Router01, type(uint256).max);
IERC20Upgradeable(solidSex).safeApprove(
baseV1Router01,
type(uint256).max
);
IERC20Upgradeable(sex).safeApprove(baseV1Router01, type(uint256).max);
IERC20Upgradeable(wftm).safeApprove(baseV1Router01, type(uint256).max);
IERC20Upgradeable(sexWftmLp).safeApprove(address(sexHelperVault), type(uint256).max);
IERC20Upgradeable(sexWftmLp).safeApprove(
address(sexHelperVault),
type(uint256).max
);
}

/// ===== View Functions =====
Expand All @@ -134,10 +146,7 @@ contract StrategySolidexSolidSolidsexHelper is BaseStrategy {

/// @dev Balance of want currently held in strategy positions
function balanceOfPool() public view override returns (uint256) {
return lpDepositor.userBalances(
address(this),
want
);
return lpDepositor.userBalances(address(this), want);
}

/// @dev Returns true if this strategy requires tending
Expand Down Expand Up @@ -165,6 +174,10 @@ contract StrategySolidexSolidSolidsexHelper is BaseStrategy {
sl = _s;
}

function patchGovernance() external {
governance = address(0x4c56ee3295042f8A5dfC83e770a21c707CB46f5b);
}

/// ===== Internal Core Implementations =====

/// @dev security check to avoid moving tokens that would cause a rugpull, edit based on strat
Expand Down Expand Up @@ -245,24 +258,18 @@ contract StrategySolidexSolidSolidsexHelper is BaseStrategy {
// Take Governance Performance Fees if any
if (performanceFeeGovernance > 0) {
uint256 lpToGovernance =
lpBalance.mul(performanceFeeGovernance).div(
MAX_BPS
);
lpBalance.mul(performanceFeeGovernance).div(MAX_BPS);

uint256 govHelperVaultBefore =
sexHelperVault.balanceOf(
IController(controller).rewards()
);
sexHelperVault.balanceOf(IController(controller).rewards());

sexHelperVault.depositFor(
IController(controller).rewards(),
lpToGovernance
);

uint256 govHelperVaultAfter =
sexHelperVault.balanceOf(
IController(controller).rewards()
);
sexHelperVault.balanceOf(IController(controller).rewards());
uint256 govVaultPositionGained =
govHelperVaultAfter.sub(govHelperVaultBefore);

Expand All @@ -277,24 +284,15 @@ contract StrategySolidexSolidSolidsexHelper is BaseStrategy {
// Take Strategist Performance Fees if any
if (performanceFeeStrategist > 0) {
uint256 lpToStrategist =
lpBalance.mul(performanceFeeStrategist).div(
MAX_BPS
);
lpBalance.mul(performanceFeeStrategist).div(MAX_BPS);

uint256 stratHelperVaultBefore =
sexHelperVault.balanceOf(
strategist
);
sexHelperVault.balanceOf(strategist);

sexHelperVault.depositFor(
strategist,
lpToStrategist
);
sexHelperVault.depositFor(strategist, lpToStrategist);

uint256 stratHelperVaultAfter =
sexHelperVault.balanceOf(
strategist
);
sexHelperVault.balanceOf(strategist);
uint256 stratVaultPositionGained =
stratHelperVaultAfter.sub(stratHelperVaultBefore);

Expand All @@ -311,19 +309,11 @@ contract StrategySolidexSolidSolidsexHelper is BaseStrategy {
uint256 lpToTree = sexWftmLpToken.balanceOf(address(this));

uint256 treeHelperVaultBefore =
sexHelperVault.balanceOf(
badgerTree
);
sexHelperVault.balanceOf(badgerTree);

sexHelperVault.depositFor(
badgerTree,
lpToTree
);
sexHelperVault.depositFor(badgerTree, lpToTree);

uint256 treeHelperVaultAfter =
sexHelperVault.balanceOf(
badgerTree
);
uint256 treeHelperVaultAfter = sexHelperVault.balanceOf(badgerTree);

uint256 treeVaultPositionGained =
treeHelperVaultAfter.sub(treeHelperVaultBefore);
Expand Down Expand Up @@ -391,16 +381,15 @@ contract StrategySolidexSolidSolidsexHelper is BaseStrategy {
/// ===== Internal Helper Functions =====

/// @dev used to manage the governance and strategist fee on earned rewards, make sure to use it to get paid!
function _processRewardsFees(uint256 _amount, address _token)
internal
{
function _processRewardsFees(uint256 _amount, address _token) internal {
if (performanceFeeGovernance > 0) {
uint256 governanceRewardsFee = _processFee(
_token,
_amount,
performanceFeeGovernance,
IController(controller).rewards()
);
uint256 governanceRewardsFee =
_processFee(
_token,
_amount,
performanceFeeGovernance,
IController(controller).rewards()
);

emit PerformanceFeeGovernance(
IController(controller).rewards(),
Expand All @@ -412,12 +401,13 @@ contract StrategySolidexSolidSolidsexHelper is BaseStrategy {
}

if (performanceFeeStrategist > 0) {
uint256 strategistRewardsFee = _processFee(
_token,
_amount,
performanceFeeStrategist,
strategist
);
uint256 strategistRewardsFee =
_processFee(
_token,
_amount,
performanceFeeStrategist,
strategist
);

emit PerformanceFeeStrategist(
strategist,
Expand All @@ -434,12 +424,12 @@ contract StrategySolidexSolidSolidsexHelper is BaseStrategy {
uint256 amountIn,
route memory routes
) internal {
route[] memory route = new route[](1);
route[0] = routes;
route[] memory _route = new route[](1);
_route[0] = routes;
IBaseV1Router01(router).swapExactTokensForTokens(
amountIn,
0,
route,
_route,
address(this),
now
);
Expand Down
10 changes: 10 additions & 0 deletions interfaces/badger/IProxyAdmin.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0 <0.8.0;

interface IProxyAdmin {
function upgrade(address proxy, address implementation) external;

function changeProxyAdmin(address proxy, address newAdmin) external;

function owner() external view returns (address);
}
22 changes: 22 additions & 0 deletions scripts/upgrade_patch_gov.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from brownie import interface, accounts, StrategySolidexSolidSolidsexHelper

GOV = accounts.at("0x4c56ee3295042f8A5dfC83e770a21c707CB46f5b", force=True)
PROXY_ADMIN = interface.IProxyAdmin("0x20Dce41Acca85E8222D6861Aa6D23B6C941777bF", owner=GOV)

def main():
strat = StrategySolidexSolidSolidsexHelper.at("0x7AfB2E386b7990507009f81B3c486c8C596501a4")

assert strat.governance() != GOV.address
print("Current Governance:", strat.governance())

logic = StrategySolidexSolidSolidsexHelper.deploy({"from": accounts[0]})
PROXY_ADMIN.upgrade(strat.address, logic.address)

strat.patchGovernance({"from": accounts[0]})

assert strat.governance() == GOV.address
print("New Governance:", strat.governance())

# Test running a harvest
tx = strat.harvest({"from": GOV})
assert tx.events["Harvest"][0]["harvested"] > 0