per-asset fees

This commit is contained in:
tim
2025-10-29 18:22:23 -04:00
parent 86410c9a91
commit 20758cfb35
18 changed files with 475 additions and 164 deletions

View File

@@ -61,8 +61,8 @@ interface IPartyPool is IERC20Metadata, IOwnable {
IERC20 indexed tokenOut,
uint256 amountIn,
uint256 amountOut,
uint256 lpFee,
uint256 protocolFee
uint256 lpFee, // taken from the output token
uint256 protocolFee // taken from the output token
);
event Flash(
@@ -97,8 +97,11 @@ interface IPartyPool is IERC20Metadata, IOwnable {
/// @dev denominators()[i] is the base for tokens[i]. These bases are chosen by deployer and must match token decimals.
function denominators() external view returns (uint256[] memory);
/// @notice Per-swap fee in parts-per-million (ppm). Fee is taken from input amounts before LMSR computations.
function swapFeePpm() external view returns (uint256);
/// @notice Per-asset swap fees in ppm. Fees are applied on input; for asset-to-asset swaps, the effective pair fee is 1 - (1 - f_i)(1 - f_j).
function fees() external view returns (uint256[] memory);
/// @notice Effective combined fee in ppm for the given asset pair (i as input, j as output).
function fee(uint256 i, uint256 j) external view returns (uint256);
/// @notice Flash-loan fee in parts-per-million (ppm) applied to flash borrow amounts.
function flashFeePpm() external view returns (uint256);
@@ -163,13 +166,13 @@ interface IPartyPool is IERC20Metadata, IOwnable {
/// @param outputTokenIndex index of output token
/// @param maxAmountIn maximum gross input allowed (inclusive of fee)
/// @param limitPrice maximum acceptable marginal price (pass 0 to ignore)
/// @return amountIn gross input amount to transfer (includes fee), amountOut output amount user would receive, fee fee amount taken
/// @return amountIn gross input amount to transfer (includes fee), amountOut output amount user would receive, inFee fee taken from input amount
function swapAmounts(
uint256 inputTokenIndex,
uint256 outputTokenIndex,
uint256 maxAmountIn,
int128 limitPrice
) external view returns (uint256 amountIn, uint256 amountOut, uint256 fee);
) external view returns (uint256 amountIn, uint256 amountOut, uint256 inFee);
/// @notice Swap input token inputTokenIndex -> token outputTokenIndex. Payer must approve token inputTokenIndex.
/// @dev This function transfers the exact gross input (including fee) from payer and sends the computed output to receiver.
@@ -181,7 +184,7 @@ interface IPartyPool is IERC20Metadata, IOwnable {
/// @param maxAmountIn maximum amount of token inputTokenIndex (uint256) to transfer in (inclusive of fees)
/// @param limitPrice maximum acceptable marginal price (64.64 fixed point). Pass 0 to ignore.
/// @param deadline timestamp after which the transaction will revert. Pass 0 to ignore.
/// @return amountIn actual input used (uint256), amountOut actual output sent (uint256), fee fee taken from the input (uint256)
/// @return amountIn actual input used (uint256), amountOut actual output sent (uint256), inFee fee taken from the input (uint256)
function swap(
address payer,
address receiver,
@@ -191,7 +194,7 @@ interface IPartyPool is IERC20Metadata, IOwnable {
int128 limitPrice,
uint256 deadline,
bool unwrap
) external payable returns (uint256 amountIn, uint256 amountOut, uint256 fee);
) external payable returns (uint256 amountIn, uint256 amountOut, uint256 inFee);
/// @notice Swap up to the price limit; computes max input to reach limit then performs swap.
/// @dev If balances prevent fully reaching the limit, the function caps and returns actuals.
@@ -202,7 +205,7 @@ interface IPartyPool is IERC20Metadata, IOwnable {
/// @param outputTokenIndex index of output asset
/// @param limitPrice target marginal price to reach (must be > 0)
/// @param deadline timestamp after which the transaction will revert. Pass 0 to ignore.
/// @return amountInUsed actual input used excluding fee (uint256), amountOut actual output sent (uint256), fee fee taken from the input (uint256)
/// @return amountInUsed actual input used excluding fee (uint256), amountOut actual output sent (uint256), inFee fee taken from the input (uint256)
function swapToLimit(
address payer,
address receiver,
@@ -211,7 +214,7 @@ interface IPartyPool is IERC20Metadata, IOwnable {
int128 limitPrice,
uint256 deadline,
bool unwrap
) external payable returns (uint256 amountInUsed, uint256 amountOut, uint256 fee);
) external payable returns (uint256 amountInUsed, uint256 amountOut, uint256 inFee);
/// @notice Single-token mint: deposit a single token, charge swap-LMSR cost, and mint LP.
/// @dev swapMint executes as an exact-in planned swap followed by proportional scaling of qInternal.
@@ -221,14 +224,14 @@ interface IPartyPool is IERC20Metadata, IOwnable {
/// @param inputTokenIndex index of the input token
/// @param maxAmountIn maximum uint token input (inclusive of fee)
/// @param deadline optional deadline
/// @return lpMinted actual LP minted (uint)
/// @return amountInUsed actual input used (uint256), lpMinted actual LP minted (uint256), inFee fee taken from the input (uint256)
function swapMint(
address payer,
address receiver,
uint256 inputTokenIndex,
uint256 maxAmountIn,
uint256 deadline
) external payable returns (uint256 lpMinted);
) external payable returns (uint256 amountInUsed, uint256 lpMinted, uint256 inFee);
/// @notice Burn LP tokens then swap the redeemed proportional basket into a single asset `outputTokenIndex` and send to receiver.
/// @dev The function burns LP tokens (authorization via allowance if needed), sends the single-asset payout and updates LMSR state.