diff --git a/great_ape_safe/ape_api/aave.py b/great_ape_safe/ape_api/aave.py index e5e56b7e..eb281fa4 100644 --- a/great_ape_safe/ape_api/aave.py +++ b/great_ape_safe/ape_api/aave.py @@ -150,7 +150,7 @@ def lever_up(self, collateral_token, borrow_token, perc): ) self.deposit(collateral_token, to_reinvest) - def delever(self, collateral_token, borrow_token, gains_token): + def delever(self, collateral_token, borrow_token): debt_to_repay = self._get_debt_in_token(borrow_token) debt_paid = 0 while debt_paid < debt_to_repay: @@ -214,12 +214,7 @@ def delever(self, collateral_token, borrow_token, gains_token): bal_borrow_token_after = borrow_token.balanceOf(self.safe) - if gains_token == collateral_token: - ## Swap remaining margin of borrow token back into collateral token - self.safe.init_uni_v3() - self.safe.uni_v3.swap( - [borrow_token, collateral_token], - bal_borrow_token_after - bal_borrow_token_before, - ) - assert self._get_debt_in_token(borrow_token) == 0 + + ## Return margin of borrow token in case a swap back to collateral is desired + return bal_borrow_token_after - bal_borrow_token_before diff --git a/scripts/issue/533/leveraged_wbtc.py b/scripts/issue/533/leveraged_wbtc.py index c4812f93..33233b75 100644 --- a/scripts/issue/533/leveraged_wbtc.py +++ b/scripts/issue/533/leveraged_wbtc.py @@ -32,7 +32,7 @@ def delever(): SAFE.take_snapshot([WBTC, AWBTC, USDC]) wbtc_bal_before = WBTC.balanceOf(SAFE.account) - SAFE.aave.delever(WBTC, USDC, USDC) + SAFE.aave.delever(WBTC, USDC) SAFE.aave.withdraw_all(WBTC) wbtc_bal_after = WBTC.balanceOf(SAFE.account)