Skip to content

Commit

Permalink
update deposit amount out calculation in reader
Browse files Browse the repository at this point in the history
  • Loading branch information
xdev10 committed Jun 17, 2024
1 parent 0694543 commit ca7d92b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions contracts/reader/ReaderDepositUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ library ReaderDepositUtils {
);

uint256 mintAmount;
uint256 amountIn = fees.amountAfterFees;

MarketPoolValueInfo.Props memory poolValueInfo = MarketUtils.getPoolValueInfo(
params.dataStore,
Expand Down Expand Up @@ -149,7 +150,7 @@ library ReaderDepositUtils {
}

if (params.priceImpactUsd > 0) {
(int256 positiveImpactAmount, /* uint256 cappedDiffUsd */) = MarketUtils.getSwapImpactAmountWithCap(
(int256 positiveImpactAmount, uint256 cappedDiffUsd) = MarketUtils.getSwapImpactAmountWithCap(
params.dataStore,
params.market.marketToken,
params.tokenOut,
Expand All @@ -162,6 +163,18 @@ library ReaderDepositUtils {
poolValue,
marketTokensSupply
);

if (cappedDiffUsd != 0) {
(int256 tokenInPriceImpactAmount, /* uint256 cappedDiffUsd */) = MarketUtils.getSwapImpactAmountWithCap(
params.dataStore,
params.market.marketToken,
params.tokenIn,
params.tokenInPrice,
cappedDiffUsd.toInt256()
);

amountIn += tokenInPriceImpactAmount.toUint256();
}
}

if (params.priceImpactUsd < 0) {
Expand All @@ -173,11 +186,11 @@ library ReaderDepositUtils {
params.priceImpactUsd
);

fees.amountAfterFees -= (-negativeImpactAmount).toUint256();
amountIn -= (-negativeImpactAmount).toUint256();
}

mintAmount += MarketUtils.usdToMarketTokenAmount(
fees.amountAfterFees * params.tokenInPrice.min,
amountIn * params.tokenInPrice.min,
poolValue,
marketTokensSupply
);
Expand Down

0 comments on commit ca7d92b

Please sign in to comment.