From aeb14c7e8af59e1c53fe811ddacc8da0edb7389b Mon Sep 17 00:00:00 2001 From: "pata.eth" Date: Sun, 22 May 2022 20:27:12 -0400 Subject: [PATCH] updates following review from strategists and security on https://github.com/dudesahn/StrategyCurveTemplate/pull/8 --- brownie-config.yml | 20 ++-- contracts/StrategyCurveGeist.sol | 113 +++++++----------- contracts/interfaces/curve.sol | 120 ++------------------ contracts/interfaces/yearn.sol | 43 ------- scripts/deploy.py | 6 +- tests/conftest.py | 6 +- tests/test_base_strategy.py | 2 +- tests/test_change_debt.py | 2 +- tests/test_change_debt_with_profit.py | 2 +- tests/test_emergency_exit.py | 6 +- tests/test_emergency_shutdown_from_vault.py | 2 +- tests/test_liq_gauge.py | 8 +- tests/test_migration.py | 46 ++++++-- tests/test_odds_and_ends.py | 30 ++--- tests/test_remove_from_withdrawal_queue.py | 2 +- tests/test_revoke.py | 2 +- tests/test_setters.py | 2 +- tests/test_simple_harvest.py | 10 +- tests/test_sweep.py | 2 +- tests/test_triggers.py | 4 +- tests/test_withdraw_after_donation.py | 16 +-- 21 files changed, 152 insertions(+), 292 deletions(-) delete mode 100644 contracts/interfaces/yearn.sol diff --git a/brownie-config.yml b/brownie-config.yml index d64cadf..d9f8bc9 100644 --- a/brownie-config.yml +++ b/brownie-config.yml @@ -1,24 +1,24 @@ # use Ganache's forked mainnet mode as the default network # NOTE: You don't *have* to do this, but it is often helpful for testing networks: - default: ftm-main-fork + default: ftm-main-fork # automatically fetch contract sources from Etherscan autofetch_sources: True # require OpenZepplin Contracts dependencies: - - yearn/yearn-vaults@0.4.3 - - OpenZeppelin/openzeppelin-contracts@3.1.0 + - yearn/yearn-vaults@0.4.3-1 + - OpenZeppelin/openzeppelin-contracts@3.1.0 # path remapping to support imports from GitHub/NPM compiler: - solc: - version: - remappings: - - "@yearnvaults=yearn/yearn-vaults@0.4.3" - - "@openzeppelin=OpenZeppelin/openzeppelin-contracts@3.1.0" + solc: + version: + remappings: + - "@yearnvaults=yearn/yearn-vaults@0.4.3-1" + - "@openzeppelin=OpenZeppelin/openzeppelin-contracts@3.1.0" reports: - exclude_contracts: - - SafeMath + exclude_contracts: + - SafeMath diff --git a/contracts/StrategyCurveGeist.sol b/contracts/StrategyCurveGeist.sol index 063499f..7e03d3f 100644 --- a/contracts/StrategyCurveGeist.sol +++ b/contracts/StrategyCurveGeist.sol @@ -9,32 +9,9 @@ import "@openzeppelin/contracts/utils/Address.sol"; import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; import "@openzeppelin/contracts/math/Math.sol"; -import "./interfaces/curve.sol"; -import "./interfaces/yearn.sol"; +import {IGauge, IGaugeFactory, ICurveFi} from "./interfaces/curve.sol"; import {IUniswapV2Router02} from "./interfaces/uniswap.sol"; -import { - BaseStrategy, - StrategyParams -} from "@yearnvaults/contracts/BaseStrategy.sol"; - -interface IBaseFee { - function isCurrentBaseFeeAcceptable() external view returns (bool); -} - -interface IUniV3 { - struct ExactInputParams { - bytes path; - address recipient; - uint256 deadline; - uint256 amountIn; - uint256 amountOutMinimum; - } - - function exactInput(ExactInputParams calldata params) - external - payable - returns (uint256 amountOut); -} +import {BaseStrategy, StrategyParams} from "@yearnvaults/contracts/BaseStrategy.sol"; abstract contract StrategyCurveBase is BaseStrategy { using SafeERC20 for IERC20; @@ -46,10 +23,10 @@ abstract contract StrategyCurveBase is BaseStrategy { // Curve stuff IGauge public constant gauge = - IGauge(0xF7b9c402c4D6c2eDbA04a7a515b53D11B1E9b2cc); // Curve gauge contract, most are tokenized, held by strategy + IGauge(0xF7b9c402c4D6c2eDbA04a7a515b53D11B1E9b2cc); // Curve gauge contract, most are tokenized, held by strategy IGaugeFactory public constant gaugeFactory = - IGaugeFactory(0xabC000d88f23Bb45525E447528DBF656A9D55bf5); + IGaugeFactory(0xabC000d88f23Bb45525E447528DBF656A9D55bf5); // keepCRV stuff uint256 public keepCRV; // the percentage of CRV we re-lock for boost (in basis points) @@ -133,7 +110,23 @@ abstract contract StrategyCurveBase is BaseStrategy { return balanceOfWant(); } + function _claimRewards() internal { + // Claims any pending CRV + // + // Mints claimable CRV from the factory gauge. Reward tokens are sent to `msg.sender` + gaugeFactory.mint(address(gauge)); + + // harvest third-party rewards from the gauge, if any + gauge.claim_rewards(); + } + + function claimRewards() external onlyVaultManagers { + _claimRewards(); + } + function prepareMigration(address _newStrategy) internal override { + // Withdraw LP tokens from the gauge. The transfer to the new strategy is done + // by migrate() in BaseStrategy.sol uint256 _stakedBal = stakedBalance(); if (_stakedBal > 0) { gauge.withdraw(_stakedBal); @@ -204,10 +197,8 @@ contract StrategyCurveGeist is StrategyCurveBase { address spirit = 0x16327E3FbDaCA3bcF7E38F5Af2599D2DDc33aE52; want.approve(address(gauge), type(uint256).max); crv.approve(spooky, type(uint256).max); - wftm.approve(spooky, type(uint256).max); geist.approve(spooky, type(uint256).max); crv.approve(spirit, type(uint256).max); - wftm.approve(spirit, type(uint256).max); geist.approve(spirit, type(uint256).max); // set our strategy's name @@ -216,10 +207,12 @@ contract StrategyCurveGeist is StrategyCurveBase { // these are our approvals and path specific to this contract dai.approve(address(curve), type(uint256).max); usdc.approve(address(curve), type(uint256).max); - fusdt.safeApprove(address(curve), type(uint256).max); + fusdt.approve(address(curve), type(uint256).max); - // start off with fusdt - targetToken = address(fusdt); + //'targetToken' is the token with the least impact on the curve pool at the time of deposit + // or the one with the biggest bonus. 'targetToken' is updated by yearn when granted by + // market conditions. We start off with usdc. + targetToken = address(usdc); } /* ========== MUTATIVE FUNCTIONS ========== */ @@ -234,17 +227,14 @@ contract StrategyCurveGeist is StrategyCurveBase { uint256 _debtPayment ) { - // Mint CRV from the gauge factory. CRV is then transfered to the strategy (msg.sender) - gaugeFactory.mint(address(gauge)); + // Claim and get a fresh snapshot of the strategy's CRV and GEIST balance + _claimRewards(); uint256 crvBalance = crv.balanceOf(address(this)); - // harvest third-party rewards from the gauge, if any - gauge.claim_rewards(); - - uint256 wftmBalance = wftm.balanceOf(address(this)); uint256 geistBalance = geist.balanceOf(address(this)); - // if we claimed any CRV, then sell it + + // Sell CRV if we have any if (crvBalance > 0) { // keep some of our CRV to increase our boost uint256 sendToVoter = crvBalance.mul(keepCRV).div(FEE_DENOMINATOR); @@ -260,12 +250,8 @@ contract StrategyCurveGeist is StrategyCurveBase { _sellToken(address(crv), crvBalance); } } - // sell WFTM if we have any - if (wftmBalance > 0) { - _sellToken(address(wftm), wftmBalance); - } - // sell the rest of our CRV + // Sell GEIST if we have any if (geistBalance > 0) { _sellToken(address(geist), geistBalance); } @@ -316,32 +302,19 @@ contract StrategyCurveGeist is StrategyCurveBase { forceHarvestTriggerOnce = false; } - // Sells our CRV, WFTM, or GEIST for our target token + // Sells our CRV or GEIST for our target token function _sellToken(address token, uint256 _amount) internal { - if (token == address(wftm)) { - address[] memory tokenPath = new address[](2); - tokenPath[0] = address(wftm); - tokenPath[1] = address(targetToken); - IUniswapV2Router02(router).swapExactTokensForTokens( - _amount, - uint256(0), - tokenPath, - address(this), - block.timestamp - ); - } else { - address[] memory tokenPath = new address[](3); - tokenPath[0] = address(token); - tokenPath[1] = address(wftm); - tokenPath[2] = address(targetToken); - IUniswapV2Router02(router).swapExactTokensForTokens( - _amount, - uint256(0), - tokenPath, - address(this), - block.timestamp - ); - } + address[] memory tokenPath = new address[](3); + tokenPath[0] = address(token); + tokenPath[1] = address(wftm); + tokenPath[2] = address(targetToken); + IUniswapV2Router02(router).swapExactTokensForTokens( + _amount, + uint256(0), + tokenPath, + address(this), + block.timestamp + ); } /* ========== KEEP3RS ========== */ @@ -382,7 +355,7 @@ contract StrategyCurveGeist is StrategyCurveBase { // These functions are useful for setting parameters of the strategy that may need to be adjusted. // Set optimal token to sell harvested funds for depositing to Curve. - // Default is fUSDT, but can be set to USDC or DAI as needed by strategist or governance. + // Default is USDC, but can be set to fUSDT or DAI as needed by strategist or governance. function setOptimal(uint256 _optimal) external onlyAuthorized { if (_optimal == 0) { targetToken = address(dai); diff --git a/contracts/interfaces/curve.sol b/contracts/interfaces/curve.sol index c3a1b19..5a49c06 100644 --- a/contracts/interfaces/curve.sol +++ b/contracts/interfaces/curve.sol @@ -2,135 +2,31 @@ pragma solidity 0.6.12; pragma experimental ABIEncoderV2; -import {IERC20} from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; - interface IGauge { function deposit(uint256) external; function balanceOf(address) external view returns (uint256); + function withdraw(uint256) external; + function claim_rewards() external; - function withdraw(uint256) external; + // CRV + function claimable_tokens(address) external returns (uint256); + + // Third-party tokens only + function claimable_reward(address, address) external view returns (uint256); } interface IGaugeFactory { - function mint(address _gauge) external; + function mint(address _gauge) external; } interface ICurveFi { - function get_virtual_price() external view returns (uint256); - - function add_liquidity( - // EURt - uint256[2] calldata amounts, - uint256 min_mint_amount - ) external payable; - - function add_liquidity( - // Compound, sAave - uint256[2] calldata amounts, - uint256 min_mint_amount, - bool _use_underlying - ) external payable returns (uint256); - function add_liquidity( // Iron Bank, Aave uint256[3] calldata amounts, uint256 min_mint_amount, bool _use_underlying ) external payable returns (uint256); - - function add_liquidity( - // 3Crv Metapools - address pool, - uint256[4] calldata amounts, - uint256 min_mint_amount - ) external; - - function add_liquidity( - // Y and yBUSD - uint256[4] calldata amounts, - uint256 min_mint_amount, - bool _use_underlying - ) external payable returns (uint256); - - function add_liquidity( - // 3pool - uint256[3] calldata amounts, - uint256 min_mint_amount - ) external payable; - - function add_liquidity( - // sUSD - uint256[4] calldata amounts, - uint256 min_mint_amount - ) external payable; - - function remove_liquidity_imbalance( - uint256[2] calldata amounts, - uint256 max_burn_amount - ) external; - - function remove_liquidity(uint256 _amount, uint256[2] calldata amounts) - external; - - function remove_liquidity_one_coin( - uint256 _token_amount, - int128 i, - uint256 min_amount - ) external; - - function exchange( - int128 from, - int128 to, - uint256 _from_amount, - uint256 _min_to_amount - ) external; - - function balances(uint256) external view returns (uint256); - - function get_dy( - int128 from, - int128 to, - uint256 _from_amount - ) external view returns (uint256); - - // EURt - function calc_token_amount(uint256[2] calldata _amounts, bool _is_deposit) - external - view - returns (uint256); - - // 3Crv Metapools - function calc_token_amount( - address _pool, - uint256[4] calldata _amounts, - bool _is_deposit - ) external view returns (uint256); - - // sUSD, Y pool, etc - function calc_token_amount(uint256[4] calldata _amounts, bool _is_deposit) - external - view - returns (uint256); - - // 3pool, Iron Bank, etc - function calc_token_amount(uint256[3] calldata _amounts, bool _is_deposit) - external - view - returns (uint256); - - function calc_withdraw_one_coin(uint256 amount, int128 i) - external - view - returns (uint256); -} - -interface ICrvV3 is IERC20 { - function minter() external view returns (address); -} - -interface IMinter { - function mint(address) external; } diff --git a/contracts/interfaces/yearn.sol b/contracts/interfaces/yearn.sol deleted file mode 100644 index fa8104e..0000000 --- a/contracts/interfaces/yearn.sol +++ /dev/null @@ -1,43 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0 -pragma solidity 0.6.12; -pragma experimental ABIEncoderV2; - -import {IERC20} from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; - -interface ICurveStrategyProxy { - function proxy() external returns (address); - - function balanceOf(address _gauge) external view returns (uint256); - - function deposit(address _gauge, address _token) external; - - function withdraw( - address _gauge, - address _token, - uint256 _amount - ) external returns (uint256); - - function withdrawAll(address _gauge, address _token) - external - returns (uint256); - - function harvest(address _gauge) external; - - function lock() external; - - function approveStrategy(address) external; - - function revokeStrategy(address) external; - - function claimRewards(address _gauge, address _token) external; -} - -interface IVoter { - function execute( - address to, - uint256 value, - bytes calldata data - ) external returns (bool, bytes memory); - - function increaseAmount(uint256) external; -} diff --git a/scripts/deploy.py b/scripts/deploy.py index 61ded47..55af9f2 100644 --- a/scripts/deploy.py +++ b/scripts/deploy.py @@ -1,6 +1,6 @@ from pathlib import Path -from brownie import Strategy, accounts, config, network, project, web3 +from brownie import StrategyCurveGeist, accounts, config, network, project, web3 from eth_utils import is_checksum_address import click @@ -55,4 +55,6 @@ def main(): if input("Deploy Strategy? y/[N]: ").lower() != "y": return - strategy = Strategy.deploy(vault, {"from": dev}, publish_source=publish_source) + strategy = StrategyCurveGeist.deploy( + vault, "StrategyCurveGeist", {"from": dev}, publish_source=publish_source + ) diff --git a/tests/conftest.py b/tests/conftest.py index 3f57d16..8aa9b2b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -61,12 +61,14 @@ def wftm(): def other_vault_strategy(): yield Contract("0xfF8bb7261E4D51678cB403092Ae219bbEC52aa51") + # only applicable if you are migrating an existing strategy (i.e., you are not # deploying a brand new one). This strat is using an old version of a curve gauge @pytest.fixture(scope="module") def strategy_to_migrate_from(): yield Contract("0x7ff6fe5bDa1b26fa46880dF8AF844326DAd50d13") + @pytest.fixture(scope="module") def farmed(): yield Contract("0x7d016eec9c25232b01F23EF992D98ca97fc2AF5a") @@ -158,7 +160,7 @@ def vault(pm, gov, rewards, guardian, management, token, chain): Vault = pm(config["dependencies"][0]).Vault vault = guardian.deploy(Vault) vault.initialize(token, gov, rewards, "", "", guardian) - vault.setDepositLimit(2 ** 256 - 1, {"from": gov}) + vault.setDepositLimit(2**256 - 1, {"from": gov}) vault.setManagement(management, {"from": gov}) chain.sleep(1) yield vault @@ -198,7 +200,7 @@ def strategy( # set our management fee to zero so it doesn't mess with our profit checking vault.setManagementFee(0, {"from": gov}) # add our new strategy - vault.addStrategy(strategy, 10_000, 0, 2 ** 256 - 1, 1_000, {"from": gov}) + vault.addStrategy(strategy, 10_000, 0, 2**256 - 1, 1_000, {"from": gov}) strategy.setHealthCheck(healthCheck, {"from": gov}) strategy.setDoHealthCheck(True, {"from": gov}) chain.sleep(1) diff --git a/tests/test_base_strategy.py b/tests/test_base_strategy.py index bb1c62e..689fb0b 100644 --- a/tests/test_base_strategy.py +++ b/tests/test_base_strategy.py @@ -16,7 +16,7 @@ def test_base_strategy( ): ## deposit to the vault after approving startingWhale = token.balanceOf(whale) - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) newWhale = token.balanceOf(whale) diff --git a/tests/test_change_debt.py b/tests/test_change_debt.py index 8d8ad04..eee73b7 100644 --- a/tests/test_change_debt.py +++ b/tests/test_change_debt.py @@ -16,7 +16,7 @@ def test_change_debt( ): ## deposit to the vault after approving startingWhale = token.balanceOf(whale) - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) diff --git a/tests/test_change_debt_with_profit.py b/tests/test_change_debt_with_profit.py index 4c36ea2..45e2ab3 100644 --- a/tests/test_change_debt_with_profit.py +++ b/tests/test_change_debt_with_profit.py @@ -15,7 +15,7 @@ def test_change_debt_with_profit( ): ## deposit to the vault after approving - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) diff --git a/tests/test_emergency_exit.py b/tests/test_emergency_exit.py index 6bb4eae..298a2fb 100644 --- a/tests/test_emergency_exit.py +++ b/tests/test_emergency_exit.py @@ -15,7 +15,7 @@ def test_emergency_exit( ): ## deposit to the vault after approving startingWhale = token.balanceOf(whale) - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) @@ -56,7 +56,7 @@ def test_emergency_exit_with_profit( ## deposit to the vault after approving. turn off health check since we're doing weird shit strategy.setDoHealthCheck(False, {"from": gov}) startingWhale = token.balanceOf(whale) - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) @@ -102,7 +102,7 @@ def test_emergency_exit_with_no_gain_or_loss( ## deposit to the vault after approving. turn off health check since we're doing weird shit strategy.setDoHealthCheck(False, {"from": gov}) startingWhale = token.balanceOf(whale) - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) diff --git a/tests/test_emergency_shutdown_from_vault.py b/tests/test_emergency_shutdown_from_vault.py index b93b626..62a4bda 100644 --- a/tests/test_emergency_shutdown_from_vault.py +++ b/tests/test_emergency_shutdown_from_vault.py @@ -15,7 +15,7 @@ def test_emergency_shutdown_from_vault( ): ## deposit to the vault after approving startingWhale = token.balanceOf(whale) - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) diff --git a/tests/test_liq_gauge.py b/tests/test_liq_gauge.py index 37eb6b2..8dd77af 100644 --- a/tests/test_liq_gauge.py +++ b/tests/test_liq_gauge.py @@ -21,5 +21,9 @@ def test_gauge_is_properly_setup(gauge, geist): # Pull current inflation_rate and verify it's not 0; i.e., the # reward APY is greater than 0%. - if gauge.inflation_rate(weeksNum) == 0: - warn("This gauge is not currently rewarding any CRV") + # if gauge.inflation_rate(weeksNum) > 0: + # warn("This gauge is not currently rewarding any CRV") + + assert ( + gauge.inflation_rate(weeksNum) > 0 + ), "This gauge is not currently rewarding any CRV" diff --git a/tests/test_migration.py b/tests/test_migration.py index a2f6a60..ee8ab14 100644 --- a/tests/test_migration.py +++ b/tests/test_migration.py @@ -1,8 +1,6 @@ import brownie -from brownie import Contract -from brownie import config import math - +from warnings import warn def test_migration( StrategyCurveGeist, @@ -20,6 +18,8 @@ def test_migration( pool, strategy_name, gauge, + crv, + geist, ): ## deposit to the vault after approving @@ -47,11 +47,37 @@ def test_migration( chain.sleep(86400) chain.mine(1) + claimable_crv_tokens = gauge.claimable_tokens.call(strategy) + + assert claimable_crv_tokens > 0, "No CRV to be claimed" + + claimable_geist = gauge.claimable_reward(strategy, geist) + + if claimable_geist > 0: + warn("No GEIST tokens to be claimed") + # migrate our old strategy vault.migrateStrategy(strategy, new_strategy, {"from": gov}) new_strategy.setHealthCheck(healthCheck, {"from": gov}) new_strategy.setDoHealthCheck(True, {"from": gov}) + with brownie.reverts("!authorized"): + strategy.claimRewards({"from": whale}) + + strategy.claimRewards({"from": gov}) + + assert crv.balanceOf(strategy) > 0, "No tokens were claimed" + + strategy.sweep(crv, {"from": gov}) + + assert crv.balanceOf(strategy) == 0, "Tokens were not swept" + + assert geist.balanceOf(strategy) >= 0, "No tokens were claimed" + + strategy.sweep(geist, {"from": gov}) + + assert geist.balanceOf(strategy) == 0, "Tokens were not swept" + # assert that our old strategy is empty updated_total_old = strategy.estimatedTotalAssets() assert updated_total_old == 0 @@ -66,8 +92,8 @@ def test_migration( new_strat_balance, total_old, abs_tol=5 ) - startingVault = vault.totalAssets() - print("\nVault starting assets with new strategy: ", startingVault) + starting_vault_assets = vault.totalAssets() + print("\nVault starting assets with new strategy: ", starting_vault_assets) # simulate one day of earnings chain.sleep(86400) @@ -77,8 +103,8 @@ def test_migration( new_strategy.harvest({"from": gov}) vaultAssets_2 = vault.totalAssets() # confirm we made money, or at least that we have about the same - assert vaultAssets_2 >= startingVault or math.isclose( - vaultAssets_2, startingVault, abs_tol=5 + assert vaultAssets_2 >= starting_vault_assets or math.isclose( + vaultAssets_2, starting_vault_assets, abs_tol=5 ) print("\nAssets after 1 day harvest: ", vaultAssets_2) @@ -121,8 +147,8 @@ def test_migration_from_real_strat( # confirm that at least the same amount of assets were moved to the new strat assert new_strat_balance >= total_old - startingVault = vaultDeployed.totalAssets() - print("\nVault starting assets with new strategy: ", startingVault) + starting_vault_assets = vaultDeployed.totalAssets() + print("\nVault starting assets with new strategy: ", starting_vault_assets) # simulate one day of earnings chain.sleep(86400) @@ -133,4 +159,4 @@ def test_migration_from_real_strat( vaultAssets_2 = vaultDeployed.totalAssets() # confirm we made money, or remained the same - assert vaultAssets_2 >= startingVault + assert vaultAssets_2 >= starting_vault_assets diff --git a/tests/test_odds_and_ends.py b/tests/test_odds_and_ends.py index e63167e..58a3d71 100644 --- a/tests/test_odds_and_ends.py +++ b/tests/test_odds_and_ends.py @@ -24,7 +24,7 @@ def test_odds_and_ends( ## deposit to the vault after approving. turn off health check before each harvest since we're doing weird shit strategy.setDoHealthCheck(False, {"from": gov}) startingWhale = token.balanceOf(whale) - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) @@ -75,8 +75,8 @@ def test_odds_and_ends( new_strat_balance = new_strategy.estimatedTotalAssets() assert new_strat_balance >= total_old - startingVault = vault.totalAssets() - print("\nVault starting assets with new strategy: ", startingVault) + starting_vault_assets = vault.totalAssets() + print("\nVault starting assets with new strategy: ", starting_vault_assets) # simulate one day of earnings chain.sleep(86400) @@ -85,7 +85,7 @@ def test_odds_and_ends( # Test out our migrated strategy, confirm we're making a profit new_strategy.harvest({"from": gov}) vaultAssets_2 = vault.totalAssets() - assert vaultAssets_2 >= startingVault + assert vaultAssets_2 >= starting_vault_assets print("\nAssets after 1 day harvest: ", vaultAssets_2) # check our oracle @@ -121,7 +121,7 @@ def test_odds_and_ends_2( ## deposit to the vault after approving. turn off health check since we're doing weird shit strategy.setDoHealthCheck(False, {"from": gov}) startingWhale = token.balanceOf(whale) - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) @@ -161,7 +161,7 @@ def test_odds_and_ends_migration( ): ## deposit to the vault after approving - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) @@ -201,8 +201,8 @@ def test_odds_and_ends_migration( new_strat_balance, total_old, abs_tol=5 ) - startingVault = vault.totalAssets() - print("\nVault starting assets with new strategy: ", startingVault) + starting_vault_assets = vault.totalAssets() + print("\nVault starting assets with new strategy: ", starting_vault_assets) # simulate one day of earnings chain.sleep(86400) @@ -216,8 +216,8 @@ def test_odds_and_ends_migration( new_strategy.harvest({"from": gov}) vaultAssets_2 = vault.totalAssets() # confirm we made money, or at least that we have about the same - assert vaultAssets_2 >= startingVault or math.isclose( - vaultAssets_2, startingVault, abs_tol=5 + assert vaultAssets_2 >= starting_vault_assets or math.isclose( + vaultAssets_2, starting_vault_assets, abs_tol=5 ) print("\nAssets after 1 day harvest: ", vaultAssets_2) @@ -237,7 +237,7 @@ def test_odds_and_ends_liquidatePosition( ): ## deposit to the vault after approving startingWhale = token.balanceOf(whale) - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) newWhale = token.balanceOf(whale) @@ -308,7 +308,7 @@ def test_odds_and_ends_rekt( ## deposit to the vault after approving. turn off health check since we're doing weird shit strategy.setDoHealthCheck(False, {"from": gov}) startingWhale = token.balanceOf(whale) - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) @@ -349,7 +349,7 @@ def test_odds_and_ends_liquidate_rekt( ## deposit to the vault after approving. turn off health check since we're doing weird shit strategy.setDoHealthCheck(False, {"from": gov}) startingWhale = token.balanceOf(whale) - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) @@ -408,7 +408,7 @@ def test_odds_and_ends_inactive_strat( amount, ): ## deposit to the vault after approving - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) @@ -440,7 +440,7 @@ def test_odds_and_ends_weird_amounts( ): ## deposit to the vault after approving - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) strategy.harvest({"from": gov}) diff --git a/tests/test_remove_from_withdrawal_queue.py b/tests/test_remove_from_withdrawal_queue.py index 2d1c2fa..94a7293 100644 --- a/tests/test_remove_from_withdrawal_queue.py +++ b/tests/test_remove_from_withdrawal_queue.py @@ -15,7 +15,7 @@ def test_remove_from_withdrawal_queue( ): ## deposit to the vault after approving startingWhale = token.balanceOf(whale) - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) diff --git a/tests/test_revoke.py b/tests/test_revoke.py index 4e2bac0..f9d1555 100644 --- a/tests/test_revoke.py +++ b/tests/test_revoke.py @@ -16,7 +16,7 @@ def test_revoke_strategy_from_vault( ## deposit to the vault after approving startingWhale = token.balanceOf(whale) - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) diff --git a/tests/test_setters.py b/tests/test_setters.py index 5db6e45..eb98e23 100644 --- a/tests/test_setters.py +++ b/tests/test_setters.py @@ -38,7 +38,7 @@ def test_setters( ## deposit to the vault after approving startingWhale = token.balanceOf(whale) - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) diff --git a/tests/test_simple_harvest.py b/tests/test_simple_harvest.py index d810303..58377bb 100644 --- a/tests/test_simple_harvest.py +++ b/tests/test_simple_harvest.py @@ -19,7 +19,7 @@ def test_simple_harvest( ): ## deposit to the vault after approving startingWhale = token.balanceOf(whale) - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) newWhale = token.balanceOf(whale) @@ -52,7 +52,7 @@ def test_simple_harvest( chain.sleep(1) new_assets = vault.totalAssets() # confirm we made money, or at least that we have about the same - assert new_assets >= old_assets + assert new_assets > old_assets print("\nAssets after 1 day: ", new_assets / 1e18) # Display estimated APR @@ -83,7 +83,7 @@ def test_simple_harvest( chain.sleep(1) after_usdc_assets = vault.totalAssets() # confirm we made money, or at least that we have about the same - assert after_usdc_assets >= before_usdc_assets + assert after_usdc_assets > before_usdc_assets # Display estimated APR print( @@ -114,7 +114,7 @@ def test_simple_harvest( chain.sleep(1) after_usdc_assets = vault.totalAssets() # confirm we made money, or at least that we have about the same - assert after_usdc_assets >= before_usdc_assets + assert after_usdc_assets > before_usdc_assets # Display estimated APR print( @@ -131,4 +131,4 @@ def test_simple_harvest( # withdraw and confirm we made money, or at least that we have about the same vault.withdraw({"from": whale}) - assert token.balanceOf(whale) >= startingWhale + assert token.balanceOf(whale) > startingWhale diff --git a/tests/test_sweep.py b/tests/test_sweep.py index 26965fa..cc9df50 100644 --- a/tests/test_sweep.py +++ b/tests/test_sweep.py @@ -17,7 +17,7 @@ def test_sweep( ): ## deposit to the vault after approving - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) diff --git a/tests/test_triggers.py b/tests/test_triggers.py index 8c2b0c1..3b826a3 100644 --- a/tests/test_triggers.py +++ b/tests/test_triggers.py @@ -17,7 +17,7 @@ def test_triggers( ): ## deposit to the vault after approving startingWhale = token.balanceOf(whale) - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) newWhale = token.balanceOf(whale) starting_assets = vault.totalAssets() @@ -71,7 +71,7 @@ def test_less_useful_triggers( ): ## deposit to the vault after approving startingWhale = token.balanceOf(whale) - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) newWhale = token.balanceOf(whale) starting_assets = vault.totalAssets() diff --git a/tests/test_withdraw_after_donation.py b/tests/test_withdraw_after_donation.py index 07c01cf..c631221 100644 --- a/tests/test_withdraw_after_donation.py +++ b/tests/test_withdraw_after_donation.py @@ -15,7 +15,7 @@ def test_withdraw_after_donation_1( ): ## deposit to the vault after approving - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) @@ -89,7 +89,7 @@ def test_withdraw_after_donation_2( ): ## deposit to the vault after approving - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) @@ -160,7 +160,7 @@ def test_withdraw_after_donation_3( ): ## deposit to the vault after approving - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) @@ -231,7 +231,7 @@ def test_withdraw_after_donation_4( ): ## deposit to the vault after approving - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) @@ -309,7 +309,7 @@ def test_withdraw_after_donation_5( ): ## deposit to the vault after approving - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) @@ -371,7 +371,7 @@ def test_withdraw_after_donation_6( ): ## deposit to the vault after approving - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) @@ -435,7 +435,7 @@ def test_withdraw_after_donation_7( ): ## deposit to the vault after approving - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov}) @@ -518,7 +518,7 @@ def test_withdraw_after_donation_8( ): ## deposit to the vault after approving - token.approve(vault, 2 ** 256 - 1, {"from": whale}) + token.approve(vault, 2**256 - 1, {"from": whale}) vault.deposit(amount, {"from": whale}) chain.sleep(1) strategy.harvest({"from": gov})