@@ -289,7 +289,7 @@ contract SwapPairContract is ITokensReceivedCallback, ISwapPairInformation, IUpg
289
289
if (swappableTokenAmount <= 0 )
290
290
return SwapInfo (0 , 0 , 0 );
291
291
292
- _SwapInfoInternal si = _getSwapInfo (swappableTokenRoot, swappableTokenAmount);
292
+ _SwapInfoInternal si = _calculateSwapInfo (swappableTokenRoot, swappableTokenAmount);
293
293
294
294
return SwapInfo (swappableTokenAmount, si.targetTokenAmount, si.fee);
295
295
}
@@ -437,7 +437,6 @@ contract SwapPairContract is ITokensReceivedCallback, ISwapPairInformation, IUpg
437
437
uint256 b = f* k;
438
438
uint256 v = f * _sqrt ( k* k + math.muldiv (4 * feeDenominator* feeNominator, tokenAmount, f));
439
439
440
- // TODO: рефакторинг: возможно стоит заменить на встроенные фукнции для деления
441
440
return uint128 ((v- b)/ (feeNominator+ feeNominator));
442
441
}
443
442
@@ -447,7 +446,7 @@ contract SwapPairContract is ITokensReceivedCallback, ISwapPairInformation, IUpg
447
446
* @param swappableTokenRoot Root contract address of token used for swap
448
447
* @param swappableTokenAmount Amount of token used for swap
449
448
*/
450
- function _getSwapInfo (address swappableTokenRoot , uint128 swappableTokenAmount )
449
+ function _calculateSwapInfo (address swappableTokenRoot , uint128 swappableTokenAmount )
451
450
private
452
451
view
453
452
tokenExistsInPair (swappableTokenRoot)
@@ -458,7 +457,7 @@ contract SwapPairContract is ITokensReceivedCallback, ISwapPairInformation, IUpg
458
457
459
458
uint128 fee = swappableTokenAmount - math.muldivc (swappableTokenAmount, feeNominator, feeDenominator);
460
459
uint128 newFromPool = lps[fromK] + swappableTokenAmount;
461
- uint128 newToPool = uint128 ( math.divc (uint256 (lps[0 ]) * uint256 (lps[1 ]), newFromPool - fee) );
460
+ uint128 newToPool = uint128 ( math.divc (uint256 (lps[T1 ]) * uint256 (lps[T2 ]), newFromPool - fee) );
462
461
463
462
uint128 targetTokenAmount = lps[toK] - newToPool;
464
463
@@ -468,7 +467,7 @@ contract SwapPairContract is ITokensReceivedCallback, ISwapPairInformation, IUpg
468
467
}
469
468
470
469
/**
471
- * Wrapper for _getSwapInfo
470
+ * Wrapper for _calculateSwapInfo that changes the state of the contract
472
471
* @notice This function changes LP volumes
473
472
* @param swappableTokenRoot Root contract address of token used for swap
474
473
* @param swappableTokenAmount Amount of tokens used for swap
@@ -477,17 +476,14 @@ contract SwapPairContract is ITokensReceivedCallback, ISwapPairInformation, IUpg
477
476
private
478
477
returns (SwapInfo)
479
478
{
480
- _SwapInfoInternal _si = _getSwapInfo (swappableTokenRoot, swappableTokenAmount);
479
+ _SwapInfoInternal _si = _calculateSwapInfo (swappableTokenRoot, swappableTokenAmount);
481
480
482
481
if (! notZeroLiquidity (swappableTokenAmount, _si.targetTokenAmount)) {
483
482
return SwapInfo (0 , 0 , 0 );
484
483
}
485
484
486
- uint8 fromK = _si.fromKey;
487
- uint8 toK = _si.toKey;
488
-
489
- lps[fromK] = _si.newFromPool;
490
- lps[toK] = _si.newToPool;
485
+ lps[_si.fromKey] = _si.newFromPool;
486
+ lps[_si.toKey] = _si.newToPool;
491
487
492
488
return SwapInfo (swappableTokenAmount, _si.targetTokenAmount, _si.fee);
493
489
}
0 commit comments