From 6bbe1f80c88c08248c2f61cdb625bbc8c4b79833 Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Wed, 7 Oct 2020 20:52:22 +0530 Subject: [PATCH] Fixed Deflationary/Rebasing Token bug in token pool --- contracts/pools/erc20.sol | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/contracts/pools/erc20.sol b/contracts/pools/erc20.sol index 93b88c2..11d587b 100644 --- a/contracts/pools/erc20.sol +++ b/contracts/pools/erc20.sol @@ -121,13 +121,17 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath { */ function deposit(uint tknAmt) external payable nonReentrant whenNotPaused returns (uint mintAmt) { require(msg.value == 0, "non-eth-pool"); + require(tknAmt != 0, "tknAmt-is-zero"); uint _tokenBal = wdiv(totalSupply(), exchangeRate); uint _newTknBal = add(_tokenBal, tknAmt); require(_newTknBal < registry.poolCap(address(this)), "pool-cap-reached"); + uint initalBal = baseToken.balanceOf(address(this)); baseToken.safeTransferFrom(msg.sender, address(this), tknAmt); - mintAmt = wmul(tknAmt, exchangeRate); + uint finalBal = baseToken.balanceOf(address(this)); + uint _tknAmt = sub(finalBal, initalBal); + mintAmt = wmul(_tknAmt, exchangeRate); _mint(msg.sender, mintAmt); - emit LogDeposit(msg.sender, tknAmt, mintAmt); + emit LogDeposit(msg.sender, _tknAmt, mintAmt); } /**