diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 165e029..4f86406 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 18 - name: Install node.js dependencies run: yarn --frozen-lockfile - name: Run linter on *.sol and *.json diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5e88782..80f9b51 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -15,14 +15,13 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: 16 - - uses: ApeWorX/github-action@v2 - with: - ape-version-pin: "==0.6.7" + node-version: 18 + - uses: ApeWorX/github-action + - run: ape compile --size - run: npm install hardhat - run: ape test - timeout-minutes: 10 + timeout-minutes: 20 env: WEB3_ALCHEMY_PROJECT_ID: ${{ secrets.WEB3_ALCHEMY_PROJECT_ID }} WEB3_INFURA_PROJECT_ID: ${{ secrets.WEB3_INFURA_PROJECT_ID }} diff --git a/ape-config.yaml b/ape-config.yaml index 67a63e8..1de93f8 100644 --- a/ape-config.yaml +++ b/ape-config.yaml @@ -12,24 +12,26 @@ default_ecosystem: ethereum dependencies: - name: openzeppelin github: OpenZeppelin/openzeppelin-contracts - version: 4.8.2 + version: 4.9.5 + - name: tokenized-strategy github: yearn/tokenized-strategy - ref: v3.0.1 + ref: v3.0.2 contracts_folder: src - exclude: - - test/ + exclude: + - test/**/* + - name: periphery github: yearn/tokenized-strategy-periphery ref: master contracts_folder: src - exclude: - - test/ + exclude: + - test/**/* solidity: import_remapping: - - "@openzeppelin/contracts=openzeppelin/v4.8.2" - - "@tokenized-strategy=tokenized-strategy/v3.0.1" + - "@openzeppelin/contracts=openzeppelin/v4.9.5" + - "@tokenized-strategy=tokenized-strategy/v3.0.2" - "@periphery=periphery/master" ethereum: diff --git a/contracts/Strategy.sol b/contracts/Strategy.sol index 4f6b3c6..72499cd 100644 --- a/contracts/Strategy.sol +++ b/contracts/Strategy.sol @@ -33,14 +33,14 @@ contract Strategy is BaseStrategy { //////////////////////////////////////////////////////////////*/ /** - * @dev Should deploy up to '_amount' of 'asset' in the yield source. + * @dev Can deploy up to '_amount' of 'asset' in the yield source. * * This function is called at the end of a {deposit} or {mint} * call. Meaning that unless a whitelist is implemented it will * be entirely permissionless and thus can be sandwiched or otherwise * manipulated. * - * @param _amount The amount of 'asset' that the strategy should attempt + * @param _amount The amount of 'asset' that the strategy can attempt * to deposit in the yield source. */ function _deployFunds(uint256 _amount) internal override { @@ -50,9 +50,9 @@ contract Strategy is BaseStrategy { } /** - * @dev Will attempt to free the '_amount' of 'asset'. + * @dev Should attempt to free the '_amount' of 'asset'. * - * The amount of 'asset' that is already loose has already + * NOTE: The amount of 'asset' that is already loose has already * been accounted for. * * This function is called during {withdraw} and {redeem} calls. @@ -134,9 +134,7 @@ contract Strategy is BaseStrategy { * sandwiched can use the tend when a certain threshold * of idle to totalAssets has been reached. * - * The TokenizedStrategy contract will do all needed debt and idle updates - * after this has finished and will have no effect on PPS of the strategy - * till report() is called. + * This will have no effect on PPS of the strategy till report() is called. * * @param _totalIdle The current amount of idle funds that are available to deploy. * @@ -191,10 +189,10 @@ contract Strategy is BaseStrategy { * * This function will be called before any withdraw or redeem to enforce * any limits desired by the strategist. This can be used for illiquid - * or sandwichable strategies. It should never be lower than `totalIdle`. + * or sandwichable strategies. * * EX: - * return TokenIzedStrategy.totalIdle(); + * return asset.balanceOf(address(this));; * * This does not need to take into account the `_owner`'s share balance * or conversion rates from shares to assets. @@ -208,7 +206,7 @@ contract Strategy is BaseStrategy { TODO: If desired Implement withdraw limit logic and any needed state variables. EX: - return TokenizedStrategy.totalIdle(); + return asset.balanceOf(address(this)); } */ diff --git a/package.json b/package.json index 071faab..54cccd4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "tokenized_strategy_ape_mix", "devDependencies": { - "@openzeppelin/contracts": "4.8.2", + "@openzeppelin/contracts": "4.9.5", "@commitlint/cli": "^17.0.0", "@commitlint/config-conventional": "^17.0.0", "hardhat": "^2.12.2", diff --git a/requirements.txt b/requirements.txt index ee3fa89..e67b331 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ black==22.3.0 -eth-ape>=0.6.7 \ No newline at end of file +eth-ape>0.7.0 \ No newline at end of file diff --git a/scripts/deploy.py b/scripts/deploy.py index 23b646e..e87007b 100644 --- a/scripts/deploy.py +++ b/scripts/deploy.py @@ -1,7 +1,7 @@ from ape import project, accounts, chain import click -deployer = accounts.load("v3_deployer") +deployer = accounts.load("") def deploy(): diff --git a/tests/test_function_signatures.py b/tests/test_function_signatures.py index 4773d28..866727e 100644 --- a/tests/test_function_signatures.py +++ b/tests/test_function_signatures.py @@ -8,7 +8,9 @@ def test_function_collisions(strategy, asset, management, rewards, user, keeper) wad = int(1e18) with ape.reverts("initialized"): - strategy.init(asset, "name", management, rewards, keeper, sender=management) + strategy.initialize( + asset, "name", management, rewards, keeper, sender=management + ) # Check view functions assert strategy.convertToAssets(wad) == wad @@ -21,11 +23,8 @@ def test_function_collisions(strategy, asset, management, rewards, user, keeper) assert strategy.totalSupply() == 0 assert strategy.unlockedShares() == 0 assert strategy.asset() == asset - assert strategy.apiVersion() == "3.0.1" - assert strategy.totalIdle() == 0 - assert strategy.totalDebt() == 0 + assert strategy.apiVersion() == "3.0.2" assert strategy.MAX_FEE() == 5_000 - assert strategy.MIN_FEE() == 500 assert strategy.fullProfitUnlockDate() == 0 assert strategy.profitUnlockingRate() == 0 assert strategy.lastReport() > 0 @@ -51,8 +50,6 @@ def test_function_collisions(strategy, asset, management, rewards, user, keeper) strategy.setProfitMaxUnlockTime(1, sender=user) # Assure checks are being used - with ape.reverts("MIN FEE"): - strategy.setPerformanceFee(int(0), sender=management) with ape.reverts("Cannot be self"): strategy.setPerformanceFeeRecipient(strategy.address, sender=management) with ape.reverts("too long"): diff --git a/tests/test_operation.py b/tests/test_operation.py index 7670d60..51517b8 100644 --- a/tests/test_operation.py +++ b/tests/test_operation.py @@ -1,7 +1,6 @@ import ape from ape import Contract from utils.constants import MAX_BPS -from utils.checks import check_strategy_totals from utils.helpers import days_to_secs, increase_time, withdraw_and_check import pytest @@ -20,17 +19,14 @@ def test__operation( # Deposit to the strategy deposit() - # TODO: Implement logic so total_debt ends > 0 - check_strategy_totals( - strategy, total_assets=amount, total_debt=0, total_idle=amount - ) + assert strategy.totalAssets() == amount increase_time(chain, 10) # withdrawal withdraw_and_check(strategy, asset, amount, user) - check_strategy_totals(strategy, total_assets=0, total_debt=0, total_idle=0) + assert strategy.totalAssets() == 0 assert asset.balanceOf(user) == user_balance_before @@ -52,10 +48,7 @@ def test_profitable_report( # Deposit to the strategy deposit() - # TODO: Implement logic so total_debt ends > 0 - check_strategy_totals( - strategy, total_assets=amount, total_debt=0, total_idle=amount - ) + assert strategy.totalAssets() == amount # TODO: Add some code to simulate earning yield to_airdrop = amount // 100 @@ -73,18 +66,13 @@ def test_profitable_report( assert profit >= to_airdrop - # TODO: Implement logic so total_debt == amount + profit - check_strategy_totals( - strategy, total_assets=amount + profit, total_debt=0, total_idle=amount + profit - ) + assert strategy.totalAssets() == amount + profit # needed for profits to unlock increase_time(chain, strategy.profitMaxUnlockTime() - 1) - # TODO: Implement logic so total_debt == amount + profit - check_strategy_totals( - strategy, total_assets=amount + profit, total_debt=0, total_idle=amount + profit - ) + assert strategy.totalAssets() == amount + profit + assert strategy.pricePerShare() > before_pps # withdrawal @@ -117,10 +105,7 @@ def test__profitable_report__with_fee( # Deposit to the strategy deposit() - # TODO: Implement logic so total_debt ends > 0 - check_strategy_totals( - strategy, total_assets=amount, total_debt=0, total_idle=amount - ) + assert strategy.totalAssets() == amount # TODO: Add some code to simulate earning yield to_airdrop = amount // 100 @@ -145,18 +130,12 @@ def test__profitable_report__with_fee( (profit * performance_fee // MAX_BPS) * (10_000 - protocol_fee) // MAX_BPS ) - # TODO: Implement logic so total_debt == amount + profit - check_strategy_totals( - strategy, total_assets=amount + profit, total_debt=0, total_idle=amount + profit - ) + assert strategy.totalAssets() == amount + profit # needed for profits to unlock increase_time(chain, strategy.profitMaxUnlockTime() - 1) - # TODO: Implement logic so total_debt == amount + profit - check_strategy_totals( - strategy, total_assets=amount + profit, total_debt=0, total_idle=amount + profit - ) + assert strategy.totalAssets() == amount + profit assert strategy.pricePerShare() > before_pps diff --git a/tests/test_oracle.py b/tests/test_oracle.py index 630e435..75d92bd 100644 --- a/tests/test_oracle.py +++ b/tests/test_oracle.py @@ -1,6 +1,5 @@ import ape from ape import Contract, reverts, project -from utils.checks import check_strategy_totals from utils.helpers import days_to_secs import pytest diff --git a/tests/test_shutdown.py b/tests/test_shutdown.py index 74418dd..51374e9 100644 --- a/tests/test_shutdown.py +++ b/tests/test_shutdown.py @@ -1,6 +1,5 @@ import ape from ape import Contract, reverts -from utils.checks import check_strategy_totals, check_strategy_mins from utils.helpers import days_to_secs import pytest @@ -21,23 +20,19 @@ def test__shutdown__can_withdraw( # Deposit to the strategy deposit() - check_strategy_totals( - strategy, total_assets=amount, total_debt=0, total_idle=amount - ) + assert strategy.totalAssets() == amount chain.mine(14) # Need to shutdown the strategy, withdraw and then report the updated balances strategy.shutdownStrategy(sender=management) - check_strategy_mins( - strategy, min_total_assets=amount, min_total_debt=0, min_total_idle=amount - ) + assert strategy.totalAssets() >= amount # withdrawal strategy.redeem(amount, user, user, sender=user) - check_strategy_totals(strategy, total_assets=0, total_debt=0, total_idle=0) + assert strategy.totalAssets() == 0 assert ( pytest.approx(asset.balanceOf(user), rel=RELATIVE_APPROX) == user_balance_before diff --git a/tests/utils/checks.py b/tests/utils/checks.py index 190678e..fd48654 100644 --- a/tests/utils/checks.py +++ b/tests/utils/checks.py @@ -7,15 +7,3 @@ def assert_strategy_reported(log, strategy, gain, loss, performance_fee, protoco assert log.loss == loss assert log.performance_fee == performance_fee assert log.protocol_fee == protocol_fee - - -def check_strategy_totals(strategy, total_assets, total_debt, total_idle): - assert pytest.approx(strategy.totalAssets(), abs=2) == total_assets - assert pytest.approx(strategy.totalDebt(), abs=2) == total_debt - assert pytest.approx(strategy.totalIdle(), abs=2) == total_idle - - -def check_strategy_mins(strategy, min_total_assets, min_total_debt, min_total_idle): - assert strategy.totalAssets() >= min_total_assets - assert strategy.totalDebt() >= min_total_debt - assert strategy.totalIdle() >= min_total_idle diff --git a/tests/utils/helpers.py b/tests/utils/helpers.py index 6449b9e..ab91fc5 100644 --- a/tests/utils/helpers.py +++ b/tests/utils/helpers.py @@ -1,5 +1,5 @@ import ape -from utils.checks import check_strategy_totals +import pytest def days_to_secs(days: int) -> int: @@ -13,11 +13,9 @@ def increase_time(chain, seconds): def get_strategy_totals(strategy): assets = strategy.totalAssets() - debt = strategy.totalDebt() - idle = strategy.totalIdle() supply = strategy.totalSupply() - return (assets, debt, idle, supply) + return (assets, supply) def deposit(strategy, asset, amount, user): @@ -45,17 +43,10 @@ def withdraw_and_check(strategy, asset, amount, user): def check_normal_flow(chain, strategy, asset, amount, user): - assets, debt, idle, supply = get_strategy_totals(strategy) - # Deposit into the strategy deposit(strategy, asset, amount, user) - check_strategy_totals( - strategy=strategy, - total_assets=assets + amount, - total_debt=debt, - total_idle=idle + amount, - ) + assert pytest.approx(strategy.totalAssets(), abs=2) == amount increase_time(chain, 15) @@ -67,4 +58,4 @@ def check_normal_flow(chain, strategy, asset, amount, user): # Withdraw withdraw_and_check(strategy, asset, amount, user) - check_strategy_totals(strategy=strategy, total_assets=0, total_debt=0, total_idle=0) + assert strategy.totalAssets() == 0