Skip to content

Commit

Permalink
Merge pull request #547 from liquity/zappers_rename_setInitialBalances
Browse files Browse the repository at this point in the history
fix: Send leftovers to receiver in Zappers lever up and down
  • Loading branch information
bingen authored Oct 31, 2024
2 parents e3b4367 + 9c9ba2b commit cffc3e2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
4 changes: 2 additions & 2 deletions contracts/src/Zappers/GasCompZapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ contract GasCompZapper is BaseZapper {

// Set initial balances to make sure there are not lefovers
InitialBalances memory initialBalances;
_setInitialBalances(collToken, boldToken, initialBalances);
_setInitialTokensAndBalances(collToken, boldToken, initialBalances);

// Pull Bold
boldToken.transferFrom(msg.sender, address(this), _boldAmount);
Expand Down Expand Up @@ -184,7 +184,7 @@ contract GasCompZapper is BaseZapper {
_checkAdjustTroveManagers(_troveId, _collChange, _isCollIncrease, _boldChange, _isDebtIncrease);

// Set initial balances to make sure there are not lefovers
_setInitialBalances(collToken, boldToken, _initialBalances);
_setInitialTokensAndBalances(collToken, boldToken, _initialBalances);

// Pull coll
if (_isCollIncrease) {
Expand Down
9 changes: 8 additions & 1 deletion contracts/src/Zappers/LeftoversSweep.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ contract LeftoversSweep {
address receiver;
}

function _setInitialBalances(IERC20 _collToken, IBoldToken _boldToken, InitialBalances memory _initialBalances)
function _setInitialTokensAndBalances(IERC20 _collToken, IBoldToken _boldToken, InitialBalances memory _initialBalances)
internal
view
{
_setInitialTokensBalancesAndReceiver(_collToken, _boldToken, _initialBalances, msg.sender);
}

function _setInitialTokensBalancesAndReceiver(IERC20 _collToken, IBoldToken _boldToken, InitialBalances memory _initialBalances, address _receiver)
internal
view
{
Expand Down
10 changes: 5 additions & 5 deletions contracts/src/Zappers/LeverageLSTZapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ contract LeverageLSTZapper is GasCompZapper, ILeverageZapper {

// Set initial balances to make sure there are not lefovers
InitialBalances memory initialBalances;
_setInitialBalances(collToken, boldToken, initialBalances);
_setInitialTokensAndBalances(collToken, boldToken, initialBalances);

// Convert ETH to WETH
WETH.deposit{value: msg.value}();
Expand Down Expand Up @@ -107,11 +107,11 @@ contract LeverageLSTZapper is GasCompZapper, ILeverageZapper {

function leverUpTrove(LeverUpTroveParams calldata _params) external {
address owner = troveNFT.ownerOf(_params.troveId);
_requireSenderIsOwnerOrRemoveManagerAndGetReceiver(_params.troveId, owner);
address receiver = _requireSenderIsOwnerOrRemoveManagerAndGetReceiver(_params.troveId, owner);

// Set initial balances to make sure there are not lefovers
InitialBalances memory initialBalances;
_setInitialBalances(collToken, boldToken, initialBalances);
_setInitialTokensBalancesAndReceiver(collToken, boldToken, initialBalances, receiver);

// Flash loan coll
flashLoanProvider.makeFlashLoan(
Expand Down Expand Up @@ -152,11 +152,11 @@ contract LeverageLSTZapper is GasCompZapper, ILeverageZapper {

function leverDownTrove(LeverDownTroveParams calldata _params) external {
address owner = troveNFT.ownerOf(_params.troveId);
_requireSenderIsOwnerOrRemoveManagerAndGetReceiver(_params.troveId, owner);
address receiver = _requireSenderIsOwnerOrRemoveManagerAndGetReceiver(_params.troveId, owner);

// Set initial balances to make sure there are not lefovers
InitialBalances memory initialBalances;
_setInitialBalances(collToken, boldToken, initialBalances);
_setInitialTokensBalancesAndReceiver(collToken, boldToken, initialBalances, receiver);

// Flash loan coll
flashLoanProvider.makeFlashLoan(
Expand Down
10 changes: 5 additions & 5 deletions contracts/src/Zappers/LeverageWETHZapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contract LeverageWETHZapper is WETHZapper, ILeverageZapper {

// Set initial balances to make sure there are not lefovers
InitialBalances memory initialBalances;
_setInitialBalances(WETH, boldToken, initialBalances);
_setInitialTokensAndBalances(WETH, boldToken, initialBalances);

// Convert ETH to WETH
WETH.deposit{value: msg.value}();
Expand Down Expand Up @@ -104,11 +104,11 @@ contract LeverageWETHZapper is WETHZapper, ILeverageZapper {

function leverUpTrove(LeverUpTroveParams calldata _params) external {
address owner = troveNFT.ownerOf(_params.troveId);
_requireSenderIsOwnerOrRemoveManagerAndGetReceiver(_params.troveId, owner);
address receiver = _requireSenderIsOwnerOrRemoveManagerAndGetReceiver(_params.troveId, owner);

// Set initial balances to make sure there are not lefovers
InitialBalances memory initialBalances;
_setInitialBalances(WETH, boldToken, initialBalances);
_setInitialTokensBalancesAndReceiver(WETH, boldToken, initialBalances, receiver);

// Flash loan coll
flashLoanProvider.makeFlashLoan(
Expand Down Expand Up @@ -149,11 +149,11 @@ contract LeverageWETHZapper is WETHZapper, ILeverageZapper {

function leverDownTrove(LeverDownTroveParams calldata _params) external {
address owner = troveNFT.ownerOf(_params.troveId);
_requireSenderIsOwnerOrRemoveManagerAndGetReceiver(_params.troveId, owner);
address receiver = _requireSenderIsOwnerOrRemoveManagerAndGetReceiver(_params.troveId, owner);

// Set initial balances to make sure there are not lefovers
InitialBalances memory initialBalances;
_setInitialBalances(WETH, boldToken, initialBalances);
_setInitialTokensBalancesAndReceiver(WETH, boldToken, initialBalances, receiver);

// Flash loan coll
flashLoanProvider.makeFlashLoan(
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/Zappers/Modules/Exchanges/UniV3Exchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract UniV3Exchange is LeftoversSweep, IExchange {

// Set initial balances to make sure there are not lefovers
InitialBalances memory initialBalances;
_setInitialBalances(collToken, boldToken, initialBalances);
_setInitialTokensAndBalances(collToken, boldToken, initialBalances);

boldToken.transferFrom(msg.sender, address(this), _boldAmount);
boldToken.approve(address(uniV3RouterCached), _boldAmount);
Expand All @@ -58,7 +58,7 @@ contract UniV3Exchange is LeftoversSweep, IExchange {

// Set initial balances to make sure there are not lefovers
InitialBalances memory initialBalances;
_setInitialBalances(collToken, boldToken, initialBalances);
_setInitialTokensAndBalances(collToken, boldToken, initialBalances);

collToken.safeTransferFrom(msg.sender, address(this), _collAmount);
collToken.approve(address(uniV3RouterCached), _collAmount);
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/Zappers/WETHZapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ contract WETHZapper is BaseZapper {

// Set initial balances to make sure there are not lefovers
InitialBalances memory initialBalances;
_setInitialBalances(WETH, boldToken, initialBalances);
_setInitialTokensAndBalances(WETH, boldToken, initialBalances);

// Pull Bold
boldToken.transferFrom(msg.sender, address(this), _boldAmount);
Expand Down Expand Up @@ -177,7 +177,7 @@ contract WETHZapper is BaseZapper {
payable(_checkAdjustTroveManagers(_troveId, _collChange, _isCollIncrease, _boldChange, _isDebtIncrease));

// Set initial balances to make sure there are not lefovers
_setInitialBalances(WETH, boldToken, _initialBalances);
_setInitialTokensAndBalances(WETH, boldToken, _initialBalances);

// ETH -> WETH
if (_isCollIncrease) {
Expand Down

0 comments on commit cffc3e2

Please sign in to comment.