diff --git a/src/Liquifier.sol b/src/Liquifier.sol index ab3c49a7..191cfe70 100644 --- a/src/Liquifier.sol +++ b/src/Liquifier.sol @@ -168,11 +168,8 @@ contract Liquifier is Initializable, UUPSUpgradeable, OwnableUpgradeable, Pausab // The L1SyncPool's `_anticipatedDeposit` should be the only place to mint the `token` and always send its entirety to the Liquifier contract if(tokenInfos[_token].isL2Eth) _L2SanityChecks(_token); - - uint256 dx = quoteByMarketValue(_token, _amount); - - // discount - dx = (10000 - tokenInfos[_token].discountInBasisPoints) * dx / 10000; + + uint256 dx = quoteByDiscountedValue(_token, _amount); require(!isDepositCapReached(_token, dx), "CAPPED"); uint256 eEthShare = liquidityPool.depositToRecipient(msg.sender, dx, _referral); @@ -420,6 +417,13 @@ contract Liquifier is Initializable, UUPSUpgradeable, OwnableUpgradeable, Pausab revert NotSupportedToken(); } + // Calculates the amount of eETH that will be minted for a given token considering the discount rate + function quoteByDiscountedValue(address _token, uint256 _amount) public view returns (uint256) { + uint256 marketValue = quoteByMarketValue(_token, _amount); + + return (10000 - tokenInfos[_token].discountInBasisPoints) * marketValue / 10000; + } + function verifyQueuedWithdrawal(address _user, IDelegationManager.Withdrawal calldata _queuedWithdrawal) public view returns (bytes32) { require(_queuedWithdrawal.staker == _user && _queuedWithdrawal.withdrawer == address(this), "wrong depositor/withdrawer"); for (uint256 i = 0; i < _queuedWithdrawal.strategies.length; i++) { diff --git a/test/Liquifier.t.sol b/test/Liquifier.t.sol index 7f6936d7..31ad5782 100644 --- a/test/Liquifier.t.sol +++ b/test/Liquifier.t.sol @@ -97,6 +97,10 @@ contract LiquifierTest is TestSetup { vm.stopPrank(); assertApproxEqAbs(eETHInstance.balanceOf(alice), 10 ether - 0.5 ether, 0.1 ether); + + uint256 aliceQuotedEETH = liquifierInstance.quoteByDiscountedValue(address(stEth), 10 ether); + // alice will actually receive 1 wei less due to the infamous 1 wei rounding corner case + assertApproxEqAbs(eETHInstance.balanceOf(alice), aliceQuotedEETH, 1); } function test_deopsit_stEth_and_swap() internal {