Skip to content

Commit

Permalink
feat: keep functions simple and save a bit of gas in the process
Browse files Browse the repository at this point in the history
  • Loading branch information
danielattilasimon committed Apr 26, 2024
1 parent 3080262 commit 65a8cfa
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions contracts/src/ActivePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,19 @@ contract ActivePool is Ownable, CheckContract, IActivePool {
function sendETH(address _account, uint256 _amount) external override {
_requireCallerIsBOorTroveMorSP();

_accountForSendETH(_account, _amount);
emit ActivePoolETHBalanceUpdated(ETHBalance -= _amount);
emit EtherSent(_account, _amount);

ETH.safeTransfer(_account, _amount);
}

function sendETHToDefaultPool(uint256 _amount) external override {
_requireCallerIsTroveManager();

address defaultPoolAddressCached = defaultPoolAddress;
_accountForSendETH(defaultPoolAddressCached, _amount);

IDefaultPool(defaultPoolAddressCached).receiveETH(_amount);
}
emit ActivePoolETHBalanceUpdated(ETHBalance -= _amount);
emit EtherSent(defaultPoolAddress, _amount);

function _accountForSendETH(address _account, uint256 _amount) internal {
uint256 newETHBalance = ETHBalance - _amount;
ETHBalance = newETHBalance;
emit ActivePoolETHBalanceUpdated(newETHBalance);
emit EtherSent(_account, _amount);
IDefaultPool(defaultPoolAddress).receiveETH(_amount);
}

function receiveETH(uint256 _amount) external {
Expand All @@ -163,16 +157,12 @@ contract ActivePool is Ownable, CheckContract, IActivePool {
// Pull ETH tokens from sender
ETH.safeTransferFrom(msg.sender, address(this), _amount);

accountForReceivedETH(_amount);
emit ActivePoolETHBalanceUpdated(ETHBalance += _amount);
}

function accountForReceivedETH(uint256 _amount) public {
function accountForReceivedETH(uint256 _amount) external {
_requireCallerIsBorrowerOperationsOrDefaultPool();

uint256 newETHBalance = ETHBalance + _amount;
ETHBalance = newETHBalance;

emit ActivePoolETHBalanceUpdated(newETHBalance);
emit ActivePoolETHBalanceUpdated(ETHBalance += _amount);
}

function increaseRecordedDebtSum(uint256 _amount) external {
Expand Down

0 comments on commit 65a8cfa

Please sign in to comment.