Skip to content

Commit ca7d92b

Browse files
committed
update deposit amount out calculation in reader
1 parent 0694543 commit ca7d92b

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

contracts/reader/ReaderDepositUtils.sol

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ library ReaderDepositUtils {
121121
);
122122

123123
uint256 mintAmount;
124+
uint256 amountIn = fees.amountAfterFees;
124125

125126
MarketPoolValueInfo.Props memory poolValueInfo = MarketUtils.getPoolValueInfo(
126127
params.dataStore,
@@ -149,7 +150,7 @@ library ReaderDepositUtils {
149150
}
150151

151152
if (params.priceImpactUsd > 0) {
152-
(int256 positiveImpactAmount, /* uint256 cappedDiffUsd */) = MarketUtils.getSwapImpactAmountWithCap(
153+
(int256 positiveImpactAmount, uint256 cappedDiffUsd) = MarketUtils.getSwapImpactAmountWithCap(
153154
params.dataStore,
154155
params.market.marketToken,
155156
params.tokenOut,
@@ -162,6 +163,18 @@ library ReaderDepositUtils {
162163
poolValue,
163164
marketTokensSupply
164165
);
166+
167+
if (cappedDiffUsd != 0) {
168+
(int256 tokenInPriceImpactAmount, /* uint256 cappedDiffUsd */) = MarketUtils.getSwapImpactAmountWithCap(
169+
params.dataStore,
170+
params.market.marketToken,
171+
params.tokenIn,
172+
params.tokenInPrice,
173+
cappedDiffUsd.toInt256()
174+
);
175+
176+
amountIn += tokenInPriceImpactAmount.toUint256();
177+
}
165178
}
166179

167180
if (params.priceImpactUsd < 0) {
@@ -173,11 +186,11 @@ library ReaderDepositUtils {
173186
params.priceImpactUsd
174187
);
175188

176-
fees.amountAfterFees -= (-negativeImpactAmount).toUint256();
189+
amountIn -= (-negativeImpactAmount).toUint256();
177190
}
178191

179192
mintAmount += MarketUtils.usdToMarketTokenAmount(
180-
fees.amountAfterFees * params.tokenInPrice.min,
193+
amountIn * params.tokenInPrice.min,
181194
poolValue,
182195
marketTokensSupply
183196
);

0 commit comments

Comments
 (0)