diff --git a/great_ape_safe/ape_api/aave.py b/great_ape_safe/ape_api/aave.py index c9ac6a93..eb281fa4 100644 --- a/great_ape_safe/ape_api/aave.py +++ b/great_ape_safe/ape_api/aave.py @@ -214,11 +214,7 @@ def delever(self, collateral_token, borrow_token): bal_borrow_token_after = borrow_token.balanceOf(self.safe) - ## 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/great_ape_safe/ape_api/uni_v3.py b/great_ape_safe/ape_api/uni_v3.py index 91761948..820b0665 100644 --- a/great_ape_safe/ape_api/uni_v3.py +++ b/great_ape_safe/ape_api/uni_v3.py @@ -455,7 +455,7 @@ def swap(self, path, mantissa, destination=None): path_encoded = self._encode_path(multihop_path) min_out = self.quoter.quoteExactInput.call(path_encoded, mantissa) * ( - 1 - self.slippage + self.slippage ) params = ( diff --git a/scripts/issue/533/leveraged_wbtc.py b/scripts/issue/533/leveraged_wbtc.py index cc13dedd..33233b75 100644 --- a/scripts/issue/533/leveraged_wbtc.py +++ b/scripts/issue/533/leveraged_wbtc.py @@ -7,6 +7,14 @@ AWBTC = SAFE.contract(registry.eth.treasury_tokens.aWBTC) USDC = SAFE.contract(registry.eth.treasury_tokens.USDC) +INITIAL_DEPOSIT = ( + 5 * 10 ** WBTC.decimals() +) # Ref: https://etherscan.io/tx/0x52b76fb6f90df24eaa23d2793e3aef3d35a7f0f5ed2e95b6f8fed6f488b8c77b + +# slippages +COEF = 0.95 +DEADLINE = 60 * 60 * 12 + def lever_up(): SAFE.init_aave() @@ -20,9 +28,17 @@ def lever_up(): def delever(): SAFE.init_aave() + SAFE.init_cow(True) SAFE.take_snapshot([WBTC, AWBTC, USDC]) + wbtc_bal_before = WBTC.balanceOf(SAFE.account) SAFE.aave.delever(WBTC, USDC) SAFE.aave.withdraw_all(WBTC) + wbtc_bal_after = WBTC.balanceOf(SAFE.account) - SAFE.post_safe_tx() + wbtc_gained = (wbtc_bal_after - wbtc_bal_before) - INITIAL_DEPOSIT + print("wBTC Gained:", wbtc_gained) + + SAFE.cow.market_sell(WBTC, USDC, wbtc_gained, deadline=DEADLINE, coef=COEF) + + SAFE.post_safe_tx(skip_preview=True, replace_nonce=231)