Skip to content

Commit

Permalink
Aerodrome AMO remove liquidity proper fix (#2290)
Browse files Browse the repository at this point in the history
* enhance the way we withdraw liquidity

* better location

* fix comment

* update tests and simplify liquidity calculation

* small fix
  • Loading branch information
sparrowDom authored Oct 25, 2024
1 parent 3bd3be1 commit 7fdd6c3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion contracts/contracts/interfaces/aerodrome/ISugarHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface ISugarHelper {
uint160 sqrtRatioX96,
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96
) external pure returns (uint256 liquidity);
) external pure returns (uint128 liquidity);

/// @notice Computes the amount of token0 for a given amount of token1 and price range
/// @param amount1 Amount of token1 to estimate liquidity
Expand Down
16 changes: 6 additions & 10 deletions contracts/contracts/strategies/aerodrome/AerodromeAMOStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ contract AerodromeAMOStrategy is InitializableAbstractStrategy {
*/
function depositAll() external override onlyVault nonReentrant {
uint256 _wethBalance = IERC20(WETH).balanceOf(address(this));
if (_wethBalance > 0) {
if (_wethBalance > 1e12) {
_deposit(WETH, _wethBalance);
}
}
Expand Down Expand Up @@ -431,9 +431,6 @@ contract AerodromeAMOStrategy is InitializableAbstractStrategy {
*/
if (tokenId != 0 && _swapWeth && _amountToSwap > 0) {
_ensureWETHBalance(_amountToSwap);

Check warning on line 433 in contracts/contracts/strategies/aerodrome/AerodromeAMOStrategy.sol

View check run for this annotation

Codecov / codecov/patch

contracts/contracts/strategies/aerodrome/AerodromeAMOStrategy.sol#L433

Added line #L433 was not covered by tests

// burn remaining OETHb -- TODO:
_burnOethbOnTheContract();
}

// in some cases we will just want to add liquidity and not issue a swap to move the
Expand Down Expand Up @@ -536,6 +533,8 @@ contract AerodromeAMOStrategy is InitializableAbstractStrategy {
_amountOethbCollected,
underlyingAssets
);

_burnOethbOnTheContract();

Check warning on line 537 in contracts/contracts/strategies/aerodrome/AerodromeAMOStrategy.sol

View check run for this annotation

Codecov / codecov/patch

contracts/contracts/strategies/aerodrome/AerodromeAMOStrategy.sol#L537

Added line #L537 was not covered by tests
}

/**
Expand All @@ -550,7 +549,7 @@ contract AerodromeAMOStrategy is InitializableAbstractStrategy {
uint256 _balance = _tokenToSwap.balanceOf(address(this));

if (_balance < _amountToSwap) {
// This should never trigger since _removeLiquidityToEnsureSwap will already
// This should never trigger since _ensureWETHBalance will already
// throw an error if there is not enough WETH
if (_swapWeth) {
revert NotEnoughWethForSwap(_balance, _amountToSwap);
Expand Down Expand Up @@ -605,7 +604,8 @@ contract AerodromeAMOStrategy is InitializableAbstractStrategy {
function _addLiquidity() internal gaugeUnstakeAndRestake {
uint256 _wethBalance = IERC20(WETH).balanceOf(address(this));
uint256 _oethbBalance = IERC20(OETHb).balanceOf(address(this));
if (_wethBalance == 0) {
// don't deposit small liquidity amounts
if (_wethBalance <= 1e12) {
return;

Check warning on line 609 in contracts/contracts/strategies/aerodrome/AerodromeAMOStrategy.sol

View check run for this annotation

Codecov / codecov/patch

contracts/contracts/strategies/aerodrome/AerodromeAMOStrategy.sol#L609

Added line #L609 was not covered by tests
}

Expand Down Expand Up @@ -867,8 +867,6 @@ contract AerodromeAMOStrategy is InitializableAbstractStrategy {

_ensureWETHBalance(_amount);

Check warning on line 868 in contracts/contracts/strategies/aerodrome/AerodromeAMOStrategy.sol

View check run for this annotation

Codecov / codecov/patch

contracts/contracts/strategies/aerodrome/AerodromeAMOStrategy.sol#L868

Added line #L868 was not covered by tests

// burn remaining OETHb
_burnOethbOnTheContract();
_withdraw(_recipient, _amount);
}

Expand All @@ -884,8 +882,6 @@ contract AerodromeAMOStrategy is InitializableAbstractStrategy {
if (_balance > 0) {
_withdraw(vaultAddress, _balance);
}
// burn remaining OETHb
_burnOethbOnTheContract();
}

function _withdraw(address _recipient, uint256 _amount) internal {
Expand Down
14 changes: 10 additions & 4 deletions contracts/test/strategies/aerodrome-amo.base.fork-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ describe("ForkTest: Aerodrome AMO Strategy (Base)", async function () {
oethUnits("0")
);

await assetLpNOTStakedInGauge();
await verifyEndConditions(false);
});

it("Should withdraw when there's little OETHb in the pool", async () => {
Expand Down Expand Up @@ -774,13 +774,15 @@ describe("ForkTest: Aerodrome AMO Strategy (Base)", async function () {
oethUnits("0")
);

await assetLpNOTStakedInGauge();
await verifyEndConditions(false);
});
});

describe("Deposit and rebalance", function () {
it("Should be able to deposit to the strategy", async () => {
await mintAndDepositToStrategy();

await verifyEndConditions();
});

it("Should revert when not depositing WETH or amount is 0", async () => {
Expand Down Expand Up @@ -1219,8 +1221,12 @@ describe("ForkTest: Aerodrome AMO Strategy (Base)", async function () {
* - nft LP token should remain staked
* - there should be no substantial amount of WETH / OETHb left on the strategy contract
*/
const verifyEndConditions = async () => {
await assetLpStakedInGauge();
const verifyEndConditions = async (lpStaked = true) => {
if (lpStaked) {
await assetLpStakedInGauge();
} else {
await assetLpNOTStakedInGauge();
}

await expect(await weth.balanceOf(aerodromeAmoStrategy.address)).to.lte(
oethUnits("0.00001")
Expand Down

0 comments on commit 7fdd6c3

Please sign in to comment.