pure kappa formulation: target slippage extracted into pool creator code
This commit is contained in:
@@ -49,12 +49,10 @@ contract PartyPool is IPartyPool, ERC20, ReentrancyGuard {
|
||||
// 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.
|
||||
|
||||
/// @notice Trade fraction (Q64.64) representing a reference trade size as fraction of one asset's inventory.
|
||||
/// @dev Used by the LMSR stabilization logic to compute target slippage.
|
||||
int128 public immutable tradeFrac; // slippage target trade size as a fraction of one asset's inventory
|
||||
|
||||
/// @notice Target slippage (Q64.64) applied for the reference trade size specified by tradeFrac.
|
||||
int128 public immutable targetSlippage; // target slippage applied to that trade size
|
||||
/// @notice Liquidity parameter κ (Q64.64) used by the LMSR kernel: b = κ * S(q)
|
||||
/// @dev Pool is constructed with a fixed κ. Clients that previously passed tradeFrac/targetSlippage
|
||||
/// should use LMSRStabilized.computeKappaFromSlippage(...) to derive κ and pass it here.
|
||||
int128 public immutable kappa; // kappa in Q64.64
|
||||
|
||||
/// @notice Per-swap fee in parts-per-million (ppm). Fee is taken from input amounts before LMSR computations.
|
||||
uint256 public immutable swapFeePpm;
|
||||
@@ -94,8 +92,7 @@ contract PartyPool is IPartyPool, ERC20, ReentrancyGuard {
|
||||
/// @param symbol_ LP token symbol
|
||||
/// @param _tokens token addresses (n)
|
||||
/// @param _bases scaling bases for each token (n) - used when converting to/from internal 64.64 amounts
|
||||
/// @param _tradeFrac trade fraction in 64.64 fixed-point (as used by LMSR)
|
||||
/// @param _targetSlippage target slippage in 64.64 fixed-point (as used by LMSR)
|
||||
/// @param _kappa liquidity parameter κ (Q64.64) used to derive b = κ * S(q)
|
||||
/// @param _swapFeePpm fee in parts-per-million, taken from swap input amounts before LMSR calculations
|
||||
/// @param _flashFeePpm fee in parts-per-million, taken for flash loans
|
||||
/// @param _stable if true and assets.length==2, then the optimization for 2-asset stablecoin pools is activated.
|
||||
@@ -104,8 +101,7 @@ contract PartyPool is IPartyPool, ERC20, ReentrancyGuard {
|
||||
string memory symbol_,
|
||||
IERC20[] memory _tokens,
|
||||
uint256[] memory _bases,
|
||||
int128 _tradeFrac,
|
||||
int128 _targetSlippage,
|
||||
int128 _kappa,
|
||||
uint256 _swapFeePpm,
|
||||
uint256 _flashFeePpm,
|
||||
bool _stable
|
||||
@@ -114,8 +110,7 @@ contract PartyPool is IPartyPool, ERC20, ReentrancyGuard {
|
||||
require(_tokens.length == _bases.length, "Pool: lengths mismatch");
|
||||
tokens = _tokens;
|
||||
bases = _bases;
|
||||
tradeFrac = _tradeFrac;
|
||||
targetSlippage = _targetSlippage;
|
||||
kappa = _kappa;
|
||||
require(_swapFeePpm < 1_000_000, "Pool: fee >= ppm");
|
||||
swapFeePpm = _swapFeePpm;
|
||||
require(_flashFeePpm < 1_000_000, "Pool: flash fee >= ppm");
|
||||
@@ -192,8 +187,8 @@ contract PartyPool is IPartyPool, ERC20, ReentrancyGuard {
|
||||
unchecked { i++; }
|
||||
}
|
||||
|
||||
// Initialize the stabilized LMSR state
|
||||
lmsr.init(newQInternal, tradeFrac, targetSlippage);
|
||||
// Initialize the stabilized LMSR state with provided kappa
|
||||
lmsr.init(newQInternal, kappa);
|
||||
|
||||
// Compute actual LP tokens to mint based on size metric (scaled)
|
||||
if( lpTokens != 0 )
|
||||
|
||||
Reference in New Issue
Block a user