Skip to content

Commit

Permalink
fix: use try catch when calling afterLiquidityEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
xenide committed Jan 24, 2025
1 parent d9e9489 commit bd82ae6
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 22 deletions.
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@proxima-oss/eslint-config": "6.0.1",
"markdownlint-cli": "0.31.1",
"prettier": "2.6.2",
"solhint": "5.0.3",
"solhint": "5.0.5",
"ts-node": "10.8.1"
}
}
4 changes: 2 additions & 2 deletions script/optimized-deployer-meta
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"constant_product_hash": "0x10d229cba772589e1df33e1086576f195abcfdb890068f1e9008331694833feb",
"constant_product_hash": "0x3655a1654f428733171b79b5aa0eb876a0b26771aa4c113fe4b447fc164f6f3c",
"factory_hash": "0x87b0f73fafcf4bb41e013c8423dc679f6885527007d6c3f1e1834a670cbaadc5",
"stable_hash": "0x77bb394a2dea26c639518f7a39df2397ee6ae4ac52894e1c90d91d0b69e7acdf"
"stable_hash": "0x3a9c9a0643670e1711efa1d1647c9ad9d483706f2f83adb59a928f522d464ee1"
}
4 changes: 2 additions & 2 deletions src/ReservoirDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ contract ReservoirDeployer {
// Bytecode hashes.
bytes32 public constant FACTORY_HASH = bytes32(0x87b0f73fafcf4bb41e013c8423dc679f6885527007d6c3f1e1834a670cbaadc5);
bytes32 public constant CONSTANT_PRODUCT_HASH =
bytes32(0x10d229cba772589e1df33e1086576f195abcfdb890068f1e9008331694833feb);
bytes32 public constant STABLE_HASH = bytes32(0x77bb394a2dea26c639518f7a39df2397ee6ae4ac52894e1c90d91d0b69e7acdf);
bytes32(0x3655a1654f428733171b79b5aa0eb876a0b26771aa4c113fe4b447fc164f6f3c);
bytes32 public constant STABLE_HASH = bytes32(0x3a9c9a0643670e1711efa1d1647c9ad9d483706f2f83adb59a928f522d464ee1);

// Deployment addresses.
GenericFactory public factory;
Expand Down
6 changes: 4 additions & 2 deletions src/ReservoirPair.sol
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,10 @@ abstract contract ReservoirPair is IAssetManagedPair, ReservoirERC20, RGT {
if (address(assetManager) == address(0)) {
return;
}

assetManager.afterLiquidityEvent();
// Sometimes rebalancing can fail to due to reasons such as exceeding the supply cap, or if there's insufficient cash
// in the vault to fulfil the redemption. So it's necessary to catch the error to prevent an otherwise successful mint/burn from reverting.
// solhint-disable-next-line no-empty-blocks
try assetManager.afterLiquidityEvent() { } catch { }
}

function adjustManagement(int256 aToken0Change, int256 aToken1Change) external {
Expand Down
36 changes: 36 additions & 0 deletions test/integration/Euler.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,42 @@ contract EulerIntegrationTest is BaseTest {
assertEq(_manager.getBalance(_pair, USDC), 0);
}

function testAfterLiquidityEvent_ExceedMaxDeposit() external allNetworks allPairs {
// arrange
IERC4626 lVault = _manager.assetVault(USDC);
uint256 lMaxDeposit = lVault.maxDeposit(address(_manager));
uint256 lAmtToMint = lMaxDeposit * 4;

// act
_deal(address(USDC), address(this), lAmtToMint);
USDC.transfer(address(_pair), lAmtToMint);
_tokenA.mint(address(_pair), lAmtToMint);

// assert - mint should succeed even if it exceeds the max deposit
_pair.mint(address(this));
assertGt(_pair.balanceOf(address(this)), 0);
assertEq(_pair.token0Managed(), 0);
assertEq(_pair.token1Managed(), 0);
}

function testAfterLiquidityEvent_ExceedMaxWithdraw() external allNetworks allPairs {
// arrange
_increaseManagementOneToken(int256(4 * MINT_AMOUNT / 5)); // above the threshold
IERC4626 lVault = _manager.assetVault(USDC);
uint256 lLpTokenBal = _pair.balanceOf(_alice);
uint256 lAmtToBurn = lLpTokenBal / 100; // burn 1%
vm.prank(_alice);
_pair.transfer(address(_pair), lAmtToBurn);

// act - simulate a failure in withdrawing during `afterLiquidityEvent`
vm.mockCallRevert(address(lVault), bytes4(IERC4626.withdraw.selector), "");
_pair.burn(address(this));

// assert - tokens are still redeemed from the pair
assertGt(USDC.balanceOf(address(this)), 0);
assertGt(_tokenA.balanceOf(address(this)), 0);
}

function testSwap_ReturnAsset() public allNetworks allPairs {
// arrange
(uint256 lReserve0, uint256 lReserve1,,) = _pair.getReserves();
Expand Down

0 comments on commit bd82ae6

Please sign in to comment.