Skip to content

Commit

Permalink
feat: introduce tracking for totalShares
Browse files Browse the repository at this point in the history
  • Loading branch information
xenide committed Nov 19, 2024
1 parent 07261a4 commit a461939
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 59 deletions.
9 changes: 4 additions & 5 deletions src/asset-management/EulerV2Manager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ contract EulerV2Manager is IAssetManager, Owned(msg.sender), ReentrancyGuard {
//////////////////////////////////////////////////////////////////////////*/

function setVaultForAsset(IERC20 aAsset, IERC4626 aVault) external onlyOwner {
IERC4626 lVault = assetVault;
IERC4626 lVault = assetVault[aAsset];
// this is to prevent accidental moving of vaults when there are still shares outstanding
// as it will prevent the AMM pairs from getting their tokens back from the vault
if (lVault != address(0) && totalShares[lVault] != 0) {
if (address(lVault) != address(0) && totalShares[lVault] != 0) {
revert OutstandingSharesForVault();
}

Expand Down Expand Up @@ -112,7 +112,7 @@ contract EulerV2Manager is IAssetManager, Owned(msg.sender), ReentrancyGuard {
returns (uint256 rShares)
{
rShares = aVault.previewDeposit(aAmount);
totalShares += rShares;
totalShares[aVault] += rShares;
shares[aPair][aToken] += rShares;
}

Expand All @@ -121,7 +121,7 @@ contract EulerV2Manager is IAssetManager, Owned(msg.sender), ReentrancyGuard {
returns (uint256 rShares)
{
rShares = aVault.previewWithdraw(aAmount);
totalShares -= rShares;
totalShares[aVault] -= rShares;
shares[aPair][aToken] -= rShares;
}

Expand Down Expand Up @@ -228,7 +228,6 @@ contract EulerV2Manager is IAssetManager, Owned(msg.sender), ReentrancyGuard {
SafeTransferLib.safeApprove(address(aToken), address(aVault), aAmount);

uint256 lSharesReceived = aVault.deposit(aAmount, address(this));

require(lExpectedShares == lSharesReceived, "AM: INVEST_SHARES_MISMATCH");

emit Investment(aPair, aToken, lSharesReceived);
Expand Down
66 changes: 12 additions & 54 deletions test/integration/Euler.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ contract EulerIntegrationTest is BaseTest {
vm.makePersistent(address(_tokenC));
}

function testSetVaultForAsset_OutstandingShares() external allNetworks {
// arrange
_pair = _pairs[0];
_increaseManagementOneToken(123);

// act & assert
vm.expectRevert(EulerV2Manager.OutstandingSharesForVault.selector);
_manager.setVaultForAsset(USDC,USDCVault);
}

// TODO: add back test cases for totalShares

function testOnlyOwnerOrGuardian() external allNetworks {
// arrange
_manager.setGuardian(_alice);
Expand Down Expand Up @@ -512,60 +524,6 @@ contract EulerIntegrationTest is BaseTest {
);
}

// function testAfterLiquidityEvent_Mint_RevertIfFrozen() public allNetworks allPairs {
// // arrange
// uint256 lMintAmt = 100e6;
// vm.prank(_aaveAdmin);
// _poolConfigurator.setReserveFreeze(address(USDC), true);
//
// // act & assert
// _deal(address(USDC), address(this), lMintAmt);
// USDC.transfer(address(_pair), lMintAmt);
// _tokenA.mint(address(_pair), lMintAmt);
// vm.expectRevert(bytes(Errors.RESERVE_FROZEN));
// _pair.mint(address(this));
// }
//
// function testAfterLiquidityEvent_Mint_RevertIfPaused() public allNetworks allPairs {
// // arrange
// uint256 lMintAmt = 100e6;
// vm.prank(_aaveAdmin);
// _poolConfigurator.setReservePause(address(USDC), true);
//
// // act & assert
// _deal(address(USDC), address(this), lMintAmt);
// USDC.transfer(address(_pair), lMintAmt);
// _tokenA.mint(address(_pair), lMintAmt);
// vm.expectRevert(bytes(Errors.RESERVE_PAUSED));
// _pair.mint(address(this));
// }
//
// function testAfterLiquidityEvent_Burn_RevertIfFrozen() public allNetworks allPairs {
// // arrange
// uint256 lAmtToBurn = _pair.balanceOf(_alice) / 2;
// vm.prank(_aaveAdmin);
// _poolConfigurator.setReserveFreeze(address(USDC), true);
//
// // act & assert
// vm.prank(_alice);
// _pair.transfer(address(_pair), lAmtToBurn);
// vm.expectRevert(bytes(Errors.RESERVE_FROZEN));
// _pair.burn(address(this));
// }
//
// function testAfterLiquidityEvent_Burn_RevertIfPaused() public allNetworks allPairs {
// // arrange
// uint256 lAmtToBurn = _pair.balanceOf(_alice) / 2;
// vm.prank(_aaveAdmin);
// _poolConfigurator.setReservePause(address(USDC), true);
//
// // act & assert
// vm.prank(_alice);
// _pair.transfer(address(_pair), lAmtToBurn);
// vm.expectRevert(bytes(Errors.RESERVE_PAUSED));
// _pair.burn(address(this));
// }

function testAfterLiquidityEvent_RevertIfNotPair() public allNetworks {
// act & assert
vm.expectRevert();
Expand Down

0 comments on commit a461939

Please sign in to comment.