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

@@ -81,14 +81,14 @@ contract PartyPlanner is OwnableExternal, IPartyPlanner {
protocolFeeAddress = protocolFeeAddress_;
}
/// Main newPool variant: accepts kappa directly (preferred).
/// Main newPool variant: accepts kappa directly (preferred) and a per-asset fee vector.
function newPool(
// Pool constructor args
string memory name_,
string memory symbol_,
IERC20[] memory tokens_,
int128 kappa_,
uint256 swapFeePpm_,
uint256[] memory swapFeesPpm_,
uint256 flashFeePpm_,
bool stable_,
// Initial deposit information
@@ -107,6 +107,9 @@ contract PartyPlanner is OwnableExternal, IPartyPlanner {
// Validate kappa > 0 (Q64.64)
require(kappa_ > int128(0), "Planner: kappa must be > 0");
// Validate fees vector length matches number of tokens
require(swapFeesPpm_.length == tokens_.length, "Planner: fees and tokens length mismatch");
// Create a new PartyPool instance (kappa-based constructor)
IPartyPoolDeployer deployer = stable_ && tokens_.length == 2 ? BALANCED_PAIR_DEPLOYER : NORMAL_POOL_DEPLOYER;
pool = deployer.deploy(
@@ -115,7 +118,7 @@ contract PartyPlanner is OwnableExternal, IPartyPlanner {
symbol_,
tokens_,
kappa_,
swapFeePpm_,
swapFeesPpm_,
flashFeePpm_,
PROTOCOL_FEE_PPM,
protocolFeeAddress,
@@ -155,6 +158,48 @@ contract PartyPlanner is OwnableExternal, IPartyPlanner {
lpAmount = pool.initialMint(receiver, initialLpAmount);
}
/// Convenience overload: legacy single-fee signature — repeat the scalar for every asset and delegate.
function newPool(
// Pool constructor args (legacy single-fee)
string memory name_,
string memory symbol_,
IERC20[] memory tokens_,
int128 kappa_,
uint256 swapFeePpm_,
uint256 flashFeePpm_,
bool stable_,
// Initial deposit information
address payer,
address receiver,
uint256[] memory initialDeposits,
uint256 initialLpAmount,
uint256 deadline
) public onlyOwner returns (IPartyPool pool, uint256 lpAmount) {
// Build per-asset fee vector by repeating the scalar swapFeePpm_
uint256[] memory feesArr = new uint256[](tokens_.length);
for (uint256 i = 0; i < tokens_.length; i++) {
// We divide by two, because the new per-asset fee semantics charges both the in-asset fee and
// out-asset fee. This should be a square-root for exactness.
feesArr[i] = swapFeePpm_ / 2;
}
// Delegate to the vector-based newPool variant
return newPool(
name_,
symbol_,
tokens_,
kappa_,
feesArr,
flashFeePpm_,
stable_,
payer,
receiver,
initialDeposits,
initialLpAmount,
deadline
);
}
// NOTE that the slippage target is only exactly achieved in completely balanced pools where all assets are
// priced the same. This target is actually a minimum slippage that the pool imposes on traders, and the actual
// slippage cost can be multiples bigger in practice due to pool inventory imbalances.