-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Use memory instead of storage for returning leftovers in Zappers
Plus move those functions to a common base contract.
- Loading branch information
Showing
3 changed files
with
73 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.18; | ||
|
||
import "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; | ||
|
||
import "../Interfaces/IBoldToken.sol"; | ||
|
||
contract LeftoversSweep { | ||
struct InitialBalances { | ||
uint256 boldBalance; | ||
uint256 collBalance; | ||
address sender; | ||
} | ||
|
||
function _setInitialBalances(IERC20 _collToken, IBoldToken _boldToken, InitialBalances memory initialBalances) internal view { | ||
initialBalances.boldBalance = _boldToken.balanceOf(address(this)); | ||
initialBalances.collBalance = _collToken.balanceOf(address(this)); | ||
initialBalances.sender = msg.sender; | ||
} | ||
|
||
function _returnLeftovers(IERC20 _collToken, IBoldToken _boldToken, InitialBalances memory initialBalances) internal { | ||
uint256 currentCollBalance = _collToken.balanceOf(address(this)); | ||
if (currentCollBalance > initialBalances.collBalance) { | ||
_collToken.transfer(initialBalances.sender, currentCollBalance - initialBalances.collBalance); | ||
} | ||
uint256 currentBoldBalance = _boldToken.balanceOf(address(this)); | ||
if (currentBoldBalance > initialBalances.boldBalance) { | ||
_boldToken.transfer(initialBalances.sender, currentBoldBalance - initialBalances.boldBalance); | ||
} | ||
initialBalances.sender = address(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters