-
Notifications
You must be signed in to change notification settings - Fork 159
tests: core functionality #140
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
Conversation
godzillaba
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's just leave this open for now.
in #141 i've removed the pause thing and we'll handle the 0 assets case + donation attack mitigation separately in a subsequent PR
once we get 141 done let's merge it in here, then merge this one, then do the donation attack mitigation
* wip * wip: conversion and deposit/withdraw functions look okay * settargetAllocationWad * deploy with initial vault * use factory in core test setup * slippage tolerance on setTargetAllocationWad * big simplify * WIP: mastervault donation attack mitigation (#142) * wip: dead shares and fix div by zero * doc * add one * initial approval and small refactor * tests * fix PerformanceFeesWithdrawn event * move event * rebalancing does not count profit * distribute fees before disabling * fix maxMint * fix outdated comment * remove unused errors * nonReentrant * handle max in maxMint * sanity check we have no sub shares when switching * init reentrancy guard * rebalance after setting target * update docs * update outdated comment * fix nonReentrant modifier placement * remove testFoo * fix tests
| function _rebalance() internal { | ||
| uint256 totalAssetsUp = _totalAssetsLessProfit(MathUpgradeable.Rounding.Up); | ||
| uint256 totalAssetsDown = _totalAssetsLessProfit(MathUpgradeable.Rounding.Down); | ||
| uint256 idleTargetUp = totalAssetsUp.mulDiv(1e18 - targetAllocationWad, 1e18, MathUpgradeable.Rounding.Up); | ||
| uint256 idleTargetDown = totalAssetsDown.mulDiv(1e18 - targetAllocationWad, 1e18, MathUpgradeable.Rounding.Down); | ||
| uint256 idleBalance = IERC20(asset()).balanceOf(address(this)); | ||
|
|
||
| if (idleTargetDown <= idleBalance && idleBalance <= idleTargetUp) { | ||
| return; | ||
| } | ||
| uint256 profitAssets = totalProfit(rounding); | ||
| if (profitAssets == 0) { | ||
| return 0; | ||
|
|
||
| if (idleBalance < idleTargetDown) { | ||
| // we need to withdraw from subvault | ||
| uint256 assetsToWithdraw = idleTargetDown - idleBalance; | ||
| subVault.withdraw(assetsToWithdraw, address(this), address(this)); | ||
| } | ||
| else { | ||
| // we need to deposit into subvault | ||
| uint256 assetsToDeposit = idleBalance - idleTargetUp; | ||
| subVault.deposit(assetsToDeposit, address(this)); | ||
| } | ||
| return _assetsToSubVaultShares(profitAssets, rounding); | ||
| } |
Check warning
Code scanning / Slither
Unused return Medium
| function _rebalance() internal { | ||
| uint256 totalAssetsUp = _totalAssetsLessProfit(MathUpgradeable.Rounding.Up); | ||
| uint256 totalAssetsDown = _totalAssetsLessProfit(MathUpgradeable.Rounding.Down); | ||
| uint256 idleTargetUp = totalAssetsUp.mulDiv(1e18 - targetAllocationWad, 1e18, MathUpgradeable.Rounding.Up); | ||
| uint256 idleTargetDown = totalAssetsDown.mulDiv(1e18 - targetAllocationWad, 1e18, MathUpgradeable.Rounding.Down); | ||
| uint256 idleBalance = IERC20(asset()).balanceOf(address(this)); | ||
|
|
||
| if (idleTargetDown <= idleBalance && idleBalance <= idleTargetUp) { | ||
| return; | ||
| } | ||
| uint256 profitAssets = totalProfit(rounding); | ||
| if (profitAssets == 0) { | ||
| return 0; | ||
|
|
||
| if (idleBalance < idleTargetDown) { | ||
| // we need to withdraw from subvault | ||
| uint256 assetsToWithdraw = idleTargetDown - idleBalance; | ||
| subVault.withdraw(assetsToWithdraw, address(this), address(this)); | ||
| } | ||
| else { | ||
| // we need to deposit into subvault | ||
| uint256 assetsToDeposit = idleBalance - idleTargetUp; | ||
| subVault.deposit(assetsToDeposit, address(this)); | ||
| } | ||
| return _assetsToSubVaultShares(profitAssets, rounding); | ||
| } |
Check warning
Code scanning / Slither
Unused return Medium
this PR is to include tests for core functionalities like deposit, mint, redeem and withdraw