Skip to content

allow withdraw all tokens #1763

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

Merged
merged 1 commit into from
Sep 18, 2020
Merged
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
17 changes: 13 additions & 4 deletions packages/loopring_v3/contracts/test/AmmPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -231,21 +231,30 @@ contract AmmPool is IBlockReceiver {
// Withdraw any outstanding balances for the pool account on the exchange
address[] memory owners = new address[](tokens.length);
address[] memory tokenAddresses = new address[](tokens.length);

for (uint i = 0; i < tokens.length; i++) {
owners[i] = address(this);
tokenAddresses[i] = tokens[i].addr;
}
exchange.withdrawFromApprovedWithdrawals(owners, tokenAddresses);

// Withdraw
uint96[] memory withdrawn = new uint96[](tokens.length);
for (uint i = 0; i < tokens.length; i++) {
address token = tokens[i].addr;
require(availableBalance(token, msg.sender) >= amounts[i], "INSUFFICIENT_BALANCE");
balance[token][msg.sender] = balance[token][msg.sender].sub(amounts[i]);
withdrawInternal(token, amounts[i], msg.sender);
uint available = availableBalance(token, msg.sender);
if (amounts[i] == 0 || amounts[i] > available) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe remove amounts[i] == 0 here because not withdrawing some tokens may be useful. Just being able to use a very large value to withdraw everything seems enough.

withdrawn[i] = uint96(available);
} else {
withdrawn[i] = amounts[i];
}
if (withdrawn[i] > 0) {
balance[token][msg.sender] = balance[token][msg.sender].sub(withdrawn[i]);
withdrawInternal(token, withdrawn[i], msg.sender);
}
}

emit Withdrawal(msg.sender, amounts);
emit Withdrawal(msg.sender, withdrawn);
}

// Needs to be able to receive ETH from the exchange contract
Expand Down