Skip to content

Commit

Permalink
Merge pull request #189 from etherfi-protocol/jtdev/feat/provide-disc…
Browse files Browse the repository at this point in the history
…ount-pricing

Discount Pricing Function
  • Loading branch information
seongyun-ko authored Oct 17, 2024
2 parents be643a4 + d60ed5a commit b105236
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Liquifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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++) {
Expand Down
4 changes: 4 additions & 0 deletions test/Liquifier.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b105236

Please sign in to comment.