Skip to content

Commit

Permalink
fix: yaudit fixes (#171)
Browse files Browse the repository at this point in the history
* fix: comments on profit update

* chore: round losses up

* chore: add receiver check

* build: add internal mint

* fix: simple rounding

* feat: simple transfers

* build: fix withdraw (#13)

* build: fix withdraw

* chore: efficiency

* chore: add max loss

* test: max loss add

* feat: redeem max loss

* chore: rounding and redeem fixes

* test: e2e strategy test

* fix: check for over withdaw

* fix: use real values

* fix: typos

* fix: extra underflow check
  • Loading branch information
Schlagonia authored Jun 28, 2023
1 parent 3b0999d commit f315185
Show file tree
Hide file tree
Showing 9 changed files with 616 additions and 157 deletions.
6 changes: 3 additions & 3 deletions contracts/VaultFactory.vy
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
initialized fully on-chain with their init byte code, thus not
requiring any delegatecall patterns or post deployment initialization.
The deployments are done through create2 with a specific `salt`
that is dereived from a combination of the deployers address,
that is derived from a combination of the deployers address,
the underlying asset used, as well as the name and symbol specified.
Meaning a deployer will not be able to deploy the exact same vault
twice and will need to use different name and or symbols for vaults
Expand Down Expand Up @@ -91,7 +91,7 @@ name: public(String[64])
default_protocol_fee_config: public(PFConfig)
# Custom fee to charge for a specific vault or strategy.
custom_protocol_fee: public(HashMap[address, uint16])
# Repersents if a custom protocol fee should be used.
# Represents if a custom protocol fee should be used.
use_custom_protocol_fee: public(HashMap[address, bool])

@external
Expand Down Expand Up @@ -158,7 +158,7 @@ def api_version() -> String[28]:
def protocol_fee_config() -> PFConfig:
"""
@notice Called during vault and strategy reports
to retreive the protocol fee to charge and address
to retrieve the protocol fee to charge and address
to receive the fees.
@return The protocol fee config for the msg sender.
"""
Expand Down
180 changes: 107 additions & 73 deletions contracts/VaultV3.vy

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions tests/e2e/test_profitable_strategy_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def test_profitable_strategy_flow(

assert vault.totalIdle() == deposit_amount

strategy.totalAssets()
add_debt_to_strategy(gov, strategy, vault, strategy.totalAssets() + deposit_amount)

assert vault.totalIdle() == 0
Expand Down Expand Up @@ -120,6 +119,10 @@ def test_profitable_strategy_flow(
assert vault.strategies(strategy).current_debt != new_debt

user_1_withdraw = vault.totalIdle()
print(
f"Unrealized losses 1= {vault.assess_share_of_unrealised_losses(strategy, user_1_withdraw)}"
)
print(f"Asset balance 1 {asset.balanceOf(vault.address)}")
vault.withdraw(user_1_withdraw, user_1, user_1, sender=user_1)

assert pytest.approx(0, abs=1) == vault.totalIdle()
Expand All @@ -144,25 +147,21 @@ def test_profitable_strategy_flow(
- user_1_withdraw
)

# we need to use strategies param to take assets from strategies
vault.redeem(
vault.balanceOf(user_1),
user_1,
user_1,
0,
[strategy.address],
sender=user_1,
)

assert vault.totalIdle() == 0
assert pytest.approx(0, abs=1) == vault.balanceOf(user_1)

assert asset.balanceOf(user_1) > user_1_initial_balance

vault.redeem(
vault.balanceOf(user_2), user_2, user_2, [strategy.address], sender=user_2
)
vault.redeem(vault.balanceOf(user_2), user_2, user_2, 0, sender=user_2)

assert vault.totalIdle() == 0
assert pytest.approx(0, abs=1) == vault.balanceOf(user_2)
assert asset.balanceOf(user_2) > user_2_initial_balance

Expand All @@ -177,5 +176,6 @@ def test_profitable_strategy_flow(
add_debt_to_strategy(gov, strategy, vault, 0)

assert strategy.totalAssets() == 0
assert vault.strategies(strategy).current_debt == 0
vault.revoke_strategy(strategy, sender=gov)
assert vault.strategies(strategy).activation == 0
7 changes: 6 additions & 1 deletion tests/e2e/test_strategy_withdraw_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def test_multiple_strategy_withdraw_flow(
fish_amount // 2,
fish.address,
fish.address,
0,
[s.address for s in strategies],
sender=fish,
)
Expand All @@ -75,7 +76,7 @@ def test_multiple_strategy_withdraw_flow(
assert asset.balanceOf(locked_strategy) == locked_strategy_debt

# drain remaining total idle as whale
vault.withdraw(current_idle, whale.address, whale.address, [], sender=whale)
vault.withdraw(current_idle, whale.address, whale.address, sender=whale)

assert asset.balanceOf(whale) == current_idle
assert vault.totalIdle() == 0
Expand All @@ -89,6 +90,7 @@ def test_multiple_strategy_withdraw_flow(
fish_amount // 2,
bunny.address,
fish.address,
0,
[locked_strategy.address],
sender=fish,
)
Expand All @@ -110,6 +112,7 @@ def test_multiple_strategy_withdraw_flow(
whale_balance,
whale.address,
whale.address,
0,
[liquid_strategy.address],
sender=whale,
)
Expand All @@ -119,6 +122,7 @@ def test_multiple_strategy_withdraw_flow(
whale_balance,
whale.address,
whale.address,
0,
[s.address for s in strategies],
sender=whale,
)
Expand All @@ -143,6 +147,7 @@ def test_multiple_strategy_withdraw_flow(
amount_to_lock,
whale.address,
whale.address,
0,
[s.address for s in strategies],
sender=whale,
)
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/vault/test_emergency_shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ def test_shutdown_cant_deposit_can_withdraw(

assert vault_balance_before == asset.balanceOf(vault)
gov_balance_before = asset.balanceOf(gov)
vault.withdraw(
vault.balanceOf(gov.address), gov.address, gov.address, [], sender=gov
)
vault.withdraw(vault.balanceOf(gov.address), gov.address, gov.address, sender=gov)
assert asset.balanceOf(gov) == gov_balance_before + vault_balance_before
assert asset.balanceOf(vault) == 0

Expand Down
Loading

0 comments on commit f315185

Please sign in to comment.