From d383ec4e3a3e9e8088edd4c6d4172fdf12da6966 Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Mon, 31 Aug 2020 12:59:20 +0530 Subject: [PATCH] Fixed max withdrawal bug --- contracts/pools/erc20.sol | 2 +- contracts/pools/eth.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/pools/erc20.sol b/contracts/pools/erc20.sol index 00c7e3c..d183790 100644 --- a/contracts/pools/erc20.sol +++ b/contracts/pools/erc20.sol @@ -165,7 +165,6 @@ contract PoolToken is ReentrancyGuard, DSMath, ERC20Pausable { function withdraw(uint tknAmt, address to) external nonReentrant whenNotPaused returns (uint _tknAmt) { uint poolBal = baseToken.balanceOf(address(this)); require(to != address(0), "to-address-not-vaild"); - require(tknAmt <= poolBal, "not-enough-liquidity-available"); uint _bal = balanceOf(msg.sender); uint _tknBal = wdiv(_bal, exchangeRate); uint _burnAmt; @@ -176,6 +175,7 @@ contract PoolToken is ReentrancyGuard, DSMath, ERC20Pausable { _burnAmt = wmul(tknAmt, exchangeRate); _tknAmt = tknAmt; } + require(tknAmt <= poolBal, "not-enough-liquidity-available"); tokenBalance = sub(tokenBalance, _tknAmt); diff --git a/contracts/pools/eth.sol b/contracts/pools/eth.sol index b184ccf..15acfa2 100644 --- a/contracts/pools/eth.sol +++ b/contracts/pools/eth.sol @@ -161,7 +161,6 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath { function withdraw(uint tknAmt, address to) external nonReentrant whenNotPaused returns (uint _tknAmt) { uint poolBal = address(this).balance; require(to != address(0), "to-address-not-vaild"); - require(tknAmt <= poolBal, "not-enough-liquidity-available"); uint _bal = balanceOf(msg.sender); uint _tknBal = wdiv(_bal, exchangeRate); uint _burnAmt; @@ -172,6 +171,7 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath { _burnAmt = wmul(tknAmt, exchangeRate); _tknAmt = tknAmt; } + require(tknAmt <= poolBal, "not-enough-liquidity-available"); tokenBalance = sub(tokenBalance, _tknAmt);