removed state.nAssets
This commit is contained in:
@@ -30,7 +30,7 @@ contract PartyPoolMintImpl is PartyPoolBase {
|
||||
uint256 n = _tokens.length;
|
||||
|
||||
// Check if this is initial deposit - revert if not
|
||||
bool isInitialDeposit = _totalSupply == 0 || _lmsr.nAssets == 0;
|
||||
bool isInitialDeposit = _totalSupply == 0 || _lmsr.qInternal.length == 0;
|
||||
require(isInitialDeposit, "initialMint: pool already initialized");
|
||||
|
||||
// Read initial on-chain balances, require all > 0, and compute denominators (bases) from deposits.
|
||||
@@ -79,7 +79,7 @@ contract PartyPoolMintImpl is PartyPoolBase {
|
||||
uint256 n = _tokens.length;
|
||||
|
||||
// Check if this is NOT initial deposit - revert if it is
|
||||
bool isInitialDeposit = _totalSupply == 0 || _lmsr.nAssets == 0;
|
||||
bool isInitialDeposit = _totalSupply == 0 || _lmsr.qInternal.length == 0;
|
||||
require(!isInitialDeposit, "mint: use initialMint for pool initialization");
|
||||
require(lpTokenAmount > 0, "mint: zero LP amount");
|
||||
|
||||
@@ -88,7 +88,7 @@ contract PartyPoolMintImpl is PartyPoolBase {
|
||||
uint256 oldScaled = ABDKMath64x64.mulu(oldTotal, LP_SCALE);
|
||||
|
||||
// Calculate required deposit amounts for the desired LP _tokens
|
||||
uint256[] memory depositAmounts = mintAmounts(lpTokenAmount, _lmsr.nAssets, _totalSupply, _cachedUintBalances);
|
||||
uint256[] memory depositAmounts = mintAmounts(lpTokenAmount, _totalSupply, _cachedUintBalances);
|
||||
|
||||
// Transfer in all token amounts
|
||||
for (uint i = 0; i < n; ) {
|
||||
@@ -160,7 +160,7 @@ contract PartyPoolMintImpl is PartyPoolBase {
|
||||
// Use cached balances; assume standard ERC20 transfers without external interference
|
||||
|
||||
// Compute proportional withdrawal amounts for the requested LP amount (rounded down)
|
||||
withdrawAmounts = burnAmounts(lpAmount, _lmsr.nAssets, _totalSupply, _cachedUintBalances);
|
||||
withdrawAmounts = burnAmounts(lpAmount, _totalSupply, _cachedUintBalances);
|
||||
|
||||
// Transfer underlying _tokens out to receiver according to computed proportions
|
||||
for (uint i = 0; i < n; ) {
|
||||
@@ -213,8 +213,9 @@ contract PartyPoolMintImpl is PartyPoolBase {
|
||||
/// @param lpTokenAmount The amount of LP _tokens desired
|
||||
/// @return depositAmounts Array of token amounts to deposit (rounded up)
|
||||
function mintAmounts(uint256 lpTokenAmount,
|
||||
uint256 numAssets, uint256 totalSupply, uint256[] memory cachedUintBalances) public pure
|
||||
uint256 totalSupply, uint256[] memory cachedUintBalances) public pure
|
||||
returns (uint256[] memory depositAmounts) {
|
||||
uint256 numAssets = cachedUintBalances.length;
|
||||
depositAmounts = new uint256[](numAssets);
|
||||
|
||||
// If this is the first mint or pool is empty, return zeros
|
||||
@@ -236,8 +237,9 @@ contract PartyPoolMintImpl is PartyPoolBase {
|
||||
}
|
||||
|
||||
function burnAmounts(uint256 lpTokenAmount,
|
||||
uint256 numAssets, uint256 totalSupply, uint256[] memory cachedUintBalances) public pure
|
||||
uint256 totalSupply, uint256[] memory cachedUintBalances) public pure
|
||||
returns (uint256[] memory withdrawAmounts) {
|
||||
uint256 numAssets = cachedUintBalances.length;
|
||||
withdrawAmounts = new uint256[](numAssets);
|
||||
|
||||
// If supply is zero or pool uninitialized, return zeros
|
||||
@@ -280,7 +282,7 @@ contract PartyPoolMintImpl is PartyPoolBase {
|
||||
) public pure returns (uint256 amountInUsed, uint256 lpMinted, uint256 inFee) {
|
||||
require(inputTokenIndex < bases_.length, "swapMintAmounts: idx");
|
||||
require(maxAmountIn > 0, "swapMintAmounts: input zero");
|
||||
require(lmsrState.nAssets > 0, "swapMintAmounts: uninit pool");
|
||||
require(lmsrState.qInternal.length > 0, "swapMintAmounts: uninit pool");
|
||||
|
||||
// Compute fee on gross maxAmountIn to get an initial net estimate
|
||||
uint256 feeGuess = 0;
|
||||
@@ -296,7 +298,7 @@ contract PartyPoolMintImpl is PartyPoolBase {
|
||||
|
||||
// Use LMSR view to determine actual internal consumed and size-increase (ΔS) for mint
|
||||
(int128 amountInInternalUsed, int128 sizeIncreaseInternal) =
|
||||
LMSRStabilized.swapAmountsForMint(lmsrState.nAssets, lmsrState.kappa, lmsrState.qInternal,
|
||||
LMSRStabilized.swapAmountsForMint(lmsrState.kappa, lmsrState.qInternal,
|
||||
inputTokenIndex, netInternalGuess);
|
||||
|
||||
// amountInInternalUsed may be <= netInternalGuess. Convert to uint (ceil) to determine actual transfer
|
||||
@@ -359,7 +361,7 @@ contract PartyPoolMintImpl is PartyPoolBase {
|
||||
require(inputTokenIndex < n, "swapMint: idx");
|
||||
require(maxAmountIn > 0, "swapMint: input zero");
|
||||
require(deadline == 0 || block.timestamp <= deadline, "swapMint: deadline");
|
||||
require(_lmsr.nAssets > 0, "swapMint: uninit pool");
|
||||
require(_lmsr.qInternal.length > 0, "swapMint: uninit pool");
|
||||
|
||||
// compute fee on gross maxAmountIn to get an initial net estimate (we'll recompute based on actual used)
|
||||
(, uint256 netUintGuess) = _computeFee(maxAmountIn, swapFeePpm);
|
||||
@@ -467,7 +469,7 @@ contract PartyPoolMintImpl is PartyPoolBase {
|
||||
.mul(ABDKMath64x64.divu(1000000-swapFeePpm, 1000000)); // adjusted for fee
|
||||
|
||||
// Use LMSR view to compute single-asset payout and burned size-metric
|
||||
(int128 payoutInternal, ) = LMSRStabilized.swapAmountsForBurn(lmsrState.nAssets, lmsrState.kappa, lmsrState.qInternal,
|
||||
(int128 payoutInternal, ) = LMSRStabilized.swapAmountsForBurn(lmsrState.kappa, lmsrState.qInternal,
|
||||
outputTokenIndex, alpha);
|
||||
|
||||
// Convert payoutInternal -> uint (floor) to favor pool
|
||||
@@ -476,7 +478,7 @@ contract PartyPoolMintImpl is PartyPoolBase {
|
||||
|
||||
// Compute gross payout (no swap fee) to derive token-side fee = gross - net
|
||||
int128 alphaGross = ABDKMath64x64.divu(lpAmount, totalSupply_); // gross fraction (no swap fee)
|
||||
(int128 payoutGrossInternal, ) = LMSRStabilized.swapAmountsForBurn(lmsrState.nAssets, lmsrState.kappa, lmsrState.qInternal,
|
||||
(int128 payoutGrossInternal, ) = LMSRStabilized.swapAmountsForBurn(lmsrState.kappa, lmsrState.qInternal,
|
||||
outputTokenIndex, alphaGross);
|
||||
uint256 payoutGrossUint = _internalToUintFloorPure(payoutGrossInternal, bases_[outputTokenIndex]);
|
||||
outFee = (payoutGrossUint > amountOut) ? (payoutGrossUint - amountOut) : 0;
|
||||
|
||||
Reference in New Issue
Block a user