PartyPoolView

This commit is contained in:
tim
2025-10-07 12:36:24 -04:00
parent 20af14c872
commit 677ce4886c
8 changed files with 245 additions and 214 deletions

50
src/PartyPoolHelpers.sol Normal file
View File

@@ -0,0 +1,50 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.30;
import {ABDKMath64x64} from "../lib/abdk-libraries-solidity/ABDKMath64x64.sol";
abstract contract PartyPoolHelpers {
using ABDKMath64x64 for int128;
/// @notice Ceiling fee helper: computes ceil(x * feePpm / 1_000_000)
/// @dev Internal helper; public-facing functions use this to ensure fees round up in favor of pool.
function _ceilFee(uint256 x, uint256 feePpm) internal pure returns (uint256) {
if (feePpm == 0) return 0;
// ceil division: (num + denom - 1) / denom
return (x * feePpm + 1_000_000 - 1) / 1_000_000;
}
/// @notice Compute fee and net amounts for a gross input (fee rounded up to favor the pool).
/// @param gross total gross input
/// @param feePpm fee in ppm to apply
/// @return feeUint fee taken (uint) and netUint remaining for protocol use (uint)
function _computeFee(uint256 gross, uint256 feePpm) internal pure returns (uint256 feeUint, uint256 netUint) {
if (feePpm == 0) {
return (0, gross);
}
feeUint = _ceilFee(gross, feePpm);
netUint = gross - feeUint;
}
/// @notice Convenience: return gross = net + fee(net) using ceiling for fee.
/// @param netUint net amount
/// @param feePpm fee in ppm to apply
function _addFee(uint256 netUint, uint256 feePpm) internal pure returns (uint256 gross) {
if (feePpm == 0) return netUint;
uint256 fee = _ceilFee(netUint, feePpm);
return netUint + fee;
}
/// @notice Helper to compute size metric (sum of all asset quantities) from internal balances
/// @dev Returns the sum of all provided qInternal_ entries as a Q64.64 value.
function _computeSizeMetric(int128[] memory qInternal_) internal pure returns (int128) {
int128 total = int128(0);
for (uint i = 0; i < qInternal_.length; ) {
total = total.add(qInternal_[i]);
unchecked { i++; }
}
return total;
}
}