Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Commit

Permalink
feat: 302 (#23)
Browse files Browse the repository at this point in the history
* fix: oracle test

* chore: update to new version

* fix: lint
  • Loading branch information
Schlagonia authored Mar 6, 2024
1 parent 2f8da54 commit 1d5c7fb
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
18 changes: 10 additions & 8 deletions ape-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 8 additions & 10 deletions contracts/Strategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
Expand All @@ -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));
}
*/

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
black==22.3.0
eth-ape>=0.6.7
eth-ape>0.7.0
2 changes: 1 addition & 1 deletion scripts/deploy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ape import project, accounts, chain
import click

deployer = accounts.load("v3_deployer")
deployer = accounts.load("")


def deploy():
Expand Down
11 changes: 4 additions & 7 deletions tests/test_function_signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"):
Expand Down
39 changes: 9 additions & 30 deletions tests/test_operation.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
1 change: 0 additions & 1 deletion tests/test_oracle.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
11 changes: 3 additions & 8 deletions tests/test_shutdown.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
12 changes: 0 additions & 12 deletions tests/utils/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 4 additions & 13 deletions tests/utils/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ape
from utils.checks import check_strategy_totals
import pytest


def days_to_secs(days: int) -> int:
Expand All @@ -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):
Expand Down Expand Up @@ -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)

Expand All @@ -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

0 comments on commit 1d5c7fb

Please sign in to comment.