cached pair fees

This commit is contained in:
tim
2025-10-31 12:32:05 -04:00
parent dd9b7474a6
commit 89e67ba69b
3 changed files with 31 additions and 17 deletions

View File

@@ -58,7 +58,7 @@ contract PartyPool is PartyPoolBase, OwnableExternal, ERC20External, IPartyPool
function fees() external view returns (uint256[] memory) { return _fees; }
/// @notice Effective combined fee in ppm for (i as input, j as output)
function fee(uint256 i, uint256 j) external view returns (uint256) { return _pairFeePpm(i,j); }
function fee(uint256 i, uint256 j) external view returns (uint256) { return _pairFeePpmView(i,j); }
/// @notice Flash-loan fee in parts-per-million (ppm) applied to flash borrow amounts.
uint256 private immutable FLASH_FEE_PPM;
@@ -240,7 +240,7 @@ contract PartyPool is PartyPoolBase, OwnableExternal, ERC20External, IPartyPool
uint256 maxAmountIn,
int128 limitPrice
) external view returns (uint256 amountIn, uint256 amountOut, uint256 inFee) {
(uint256 grossIn, uint256 outUint,,,, uint256 feeUint) = _quoteSwapExactIn(inputTokenIndex, outputTokenIndex, maxAmountIn, limitPrice);
(uint256 grossIn, uint256 outUint,,,, uint256 feeUint) = _quoteSwapExactIn(inputTokenIndex, outputTokenIndex, maxAmountIn, limitPrice, _pairFeePpmView(inputTokenIndex, outputTokenIndex));
return (grossIn, outUint, feeUint);
}
@@ -259,7 +259,7 @@ contract PartyPool is PartyPoolBase, OwnableExternal, ERC20External, IPartyPool
// Compute amounts using the same path as views
(uint256 totalTransferAmount, uint256 amountOutUint, int128 amountInInternalUsed, int128 amountOutInternal, , uint256 feeUint) =
_quoteSwapExactIn(inputTokenIndex, outputTokenIndex, maxAmountIn, limitPrice);
_quoteSwapExactIn(inputTokenIndex, outputTokenIndex, maxAmountIn, limitPrice, _pairFeePpm(inputTokenIndex, outputTokenIndex));
// Cache token references for fewer SLOADs
IERC20 tokenIn = _tokens[inputTokenIndex];
@@ -309,7 +309,8 @@ contract PartyPool is PartyPoolBase, OwnableExternal, ERC20External, IPartyPool
uint256 inputTokenIndex,
uint256 outputTokenIndex,
uint256 maxAmountIn,
int128 limitPrice
int128 limitPrice,
uint256 feePpm
) internal view
returns (
uint256 grossIn,
@@ -321,8 +322,7 @@ contract PartyPool is PartyPoolBase, OwnableExternal, ERC20External, IPartyPool
)
{
// Estimate max net input (fee on gross rounded up, then subtract)
uint256 pairFeePpm = _pairFeePpm(inputTokenIndex, outputTokenIndex);
(, uint256 netUintForSwap) = _computeFee(maxAmountIn, pairFeePpm);
(, uint256 netUintForSwap) = _computeFee(maxAmountIn, feePpm);
// Convert to internal (floor)
int128 deltaInternalI = _uintToInternalFloor(netUintForSwap, _bases[inputTokenIndex]);
@@ -338,8 +338,8 @@ contract PartyPool is PartyPoolBase, OwnableExternal, ERC20External, IPartyPool
// Compute gross transfer including fee on the used input (ceil)
feeUint = 0;
grossIn = amountInUintNoFee;
if (pairFeePpm > 0) {
feeUint = _ceilFee(amountInUintNoFee, pairFeePpm);
if (feePpm > 0) {
feeUint = _ceilFee(amountInUintNoFee, feePpm);
grossIn += feeUint;
}