Skip to content
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

fix: only add assets when balance > 0 #243

Merged
merged 2 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/core/AccountManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,10 @@ contract AccountManager is ReentrancyGuard, Pausable, IAccountManager {
data
);
if (!isAllowed) revert Errors.FunctionCallRestricted();
_updateTokensIn(account, tokensIn);
(bool success, ) = IAccount(account).exec(target, amt, data);
if (!success)
revert Errors.AccountInteractionFailure(account, target, amt, data);
_updateTokensIn(account, tokensIn);
_updateTokensOut(account, tokensOut);
if (IAccount(account).getAssets().length > assetCap + 1)
revert Errors.MaxAssetCap();
Expand Down Expand Up @@ -358,8 +358,9 @@ contract AccountManager is ReentrancyGuard, Pausable, IAccountManager {
{
uint256 tokensInLen = tokensIn.length;
for (uint256 i; i < tokensInLen; ++i) {
if (IAccount(account).hasAsset(tokensIn[i]) == false)
IAccount(account).addAsset(tokensIn[i]);
address token = tokensIn[i];
if (IAccount(account).hasAsset(token) == false && IERC20(token).balanceOf(account) > 0)
IAccount(account).addAsset(token);
}
}

Expand All @@ -368,7 +369,7 @@ contract AccountManager is ReentrancyGuard, Pausable, IAccountManager {
{
uint256 tokensOutLen = tokensOut.length;
for (uint256 i; i < tokensOutLen; ++i) {
if (tokensOut[i].balanceOf(account) == 0)
if (IAccount(account).hasAsset(tokensOut[i]) == true && tokensOut[i].balanceOf(account) == 0)
IAccount(account).removeAsset(tokensOut[i]);
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/test/account/Account.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ contract AccountTest is BaseTest {
assertFalse(account.hasAsset(token));
}

function testRemoveNonExistingAsset(address token) public {
// Test
cheats.prank(address(accountManager));
account.removeAsset(token);

// Assert
assertEq(0, account.getAssets().length);
assertFalse(account.hasAsset(token));
}

function testRemoveAssetError(address token) public {
// Test
cheats.expectRevert(Errors.AccountManagerOnly.selector);
Expand Down
2 changes: 1 addition & 1 deletion src/test/integrations/Balancer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ contract BalancerIntegrationTest is IntegrationBaseTest {
// Assert
assertEq(IERC20(balancerWeightedPool).balanceOf(account), 0);
assertGt(account.balance, 0);
assertEq(IAccount(account).getAssets().length, 1);
assertEq(IAccount(account).getAssets().length, 0);
}

function testVaultExitStablePool() public {
Expand Down
1 change: 1 addition & 0 deletions src/test/integrations/Weth.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ contract WethIntegrationTest is IntegrationBaseTest {

function testWrapEth(uint96 amt) public {
// Setup
cheats.assume(amt > 0);
deposit(user, account, address(0), amt);
bytes memory data = abi.encodeWithSignature("deposit()");

Expand Down