From 03a6d6ed853eff41f2a19b8a09dd1f240954ad7c Mon Sep 17 00:00:00 2001 From: mingda Date: Fri, 24 Jul 2020 01:48:32 +0800 Subject: [PATCH] reduce gas cost --- contracts/impl/Settlement.sol | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/contracts/impl/Settlement.sol b/contracts/impl/Settlement.sol index 5c1b0cb..d11eb29 100644 --- a/contracts/impl/Settlement.sol +++ b/contracts/impl/Settlement.sol @@ -34,31 +34,23 @@ contract Settlement is Storage { // ============ Assets IN/OUT Functions ============ function _baseTokenTransferIn(address from, uint256 amount) internal { - uint256 beforeBalance = IERC20(_BASE_TOKEN_).balanceOf(address(this)); IERC20(_BASE_TOKEN_).safeTransferFrom(from, address(this), amount); - uint256 afterBalance = IERC20(_BASE_TOKEN_).balanceOf(address(this)); - _BASE_BALANCE_ = _BASE_BALANCE_.add(afterBalance.sub(beforeBalance)); + _BASE_BALANCE_ = _BASE_BALANCE_.add(amount); } function _quoteTokenTransferIn(address from, uint256 amount) internal { - uint256 beforeBalance = IERC20(_QUOTE_TOKEN_).balanceOf(address(this)); IERC20(_QUOTE_TOKEN_).safeTransferFrom(from, address(this), amount); - uint256 afterBalance = IERC20(_QUOTE_TOKEN_).balanceOf(address(this)); - _QUOTE_BALANCE_ = _QUOTE_BALANCE_.add(afterBalance.sub(beforeBalance)); + _QUOTE_BALANCE_ = _QUOTE_BALANCE_.add(amount); } function _baseTokenTransferOut(address to, uint256 amount) internal { - uint256 beforeBalance = IERC20(_BASE_TOKEN_).balanceOf(address(this)); IERC20(_BASE_TOKEN_).safeTransfer(to, amount); - uint256 afterBalance = IERC20(_BASE_TOKEN_).balanceOf(address(this)); - _BASE_BALANCE_ = _BASE_BALANCE_.sub(beforeBalance.sub(afterBalance)); + _BASE_BALANCE_ = _BASE_BALANCE_.sub(amount); } function _quoteTokenTransferOut(address to, uint256 amount) internal { - uint256 beforeBalance = IERC20(_QUOTE_TOKEN_).balanceOf(address(this)); IERC20(_QUOTE_TOKEN_).safeTransfer(to, amount); - uint256 afterBalance = IERC20(_QUOTE_TOKEN_).balanceOf(address(this)); - _QUOTE_BALANCE_ = _QUOTE_BALANCE_.sub(beforeBalance.sub(afterBalance)); + _QUOTE_BALANCE_ = _QUOTE_BALANCE_.sub(amount); } // ============ Donate to Liquidity Pool Functions ============