mintAmounts
This commit is contained in:
@@ -43,7 +43,7 @@ contract PartyPoolMintImpl is PartyPoolBase {
|
||||
uint256 oldScaled = ABDKMath64x64.mulu(oldTotal, LP_SCALE);
|
||||
|
||||
// Calculate required deposit amounts for the desired LP tokens
|
||||
uint256[] memory depositAmounts = _mintDepositAmounts(lpTokenAmount);
|
||||
uint256[] memory depositAmounts = _mintAmounts(lpTokenAmount, lmsr.nAssets, totalSupply());
|
||||
|
||||
// Transfer in all token amounts
|
||||
for (uint i = 0; i < n; ) {
|
||||
@@ -119,7 +119,7 @@ contract PartyPoolMintImpl is PartyPoolBase {
|
||||
}
|
||||
|
||||
// Compute proportional withdrawal amounts for the requested LP amount (rounded down)
|
||||
uint256[] memory withdrawAmounts = _burnReceiveAmounts(lpAmount);
|
||||
uint256[] memory withdrawAmounts = _burnAmounts(lpAmount);
|
||||
|
||||
// Transfer underlying tokens out to receiver according to computed proportions
|
||||
for (uint i = 0; i < n; ) {
|
||||
@@ -165,34 +165,33 @@ contract PartyPoolMintImpl is PartyPoolBase {
|
||||
emit Burn(payer, receiver, withdrawAmounts, lpAmount);
|
||||
}
|
||||
|
||||
/// @notice Internal helper to calculate required deposit amounts for minting LP tokens
|
||||
function _mintDepositAmounts(uint256 lpTokenAmount) internal view returns (uint256[] memory depositAmounts) {
|
||||
uint256 n = tokens.length;
|
||||
depositAmounts = new uint256[](n);
|
||||
function mintAmounts(uint256 lpTokenAmount, uint256 numAssets, uint256 totalSupply) public view returns (uint256[] memory depositAmounts) {
|
||||
return _mintAmounts(lpTokenAmount, numAssets, totalSupply);
|
||||
}
|
||||
|
||||
function _mintAmounts(uint256 lpTokenAmount, uint256 numAssets, uint256 totalSupply) internal view returns (uint256[] memory depositAmounts) {
|
||||
depositAmounts = new uint256[](numAssets);
|
||||
|
||||
// If this is the first mint or pool is empty, return zeros
|
||||
// For first mint, tokens should already be transferred to the pool
|
||||
if (totalSupply() == 0 || lmsr.nAssets == 0) {
|
||||
if (totalSupply == 0 || numAssets == 0) {
|
||||
return depositAmounts; // Return zeros, initial deposit handled differently
|
||||
}
|
||||
|
||||
// Calculate deposit based on current proportions
|
||||
uint256 totalLpSupply = totalSupply();
|
||||
|
||||
// lpTokenAmount / totalLpSupply = depositAmount / currentBalance
|
||||
// Therefore: depositAmount = (lpTokenAmount * currentBalance) / totalLpSupply
|
||||
// We round up to protect the pool
|
||||
for (uint i = 0; i < n; i++) {
|
||||
for (uint i = 0; i < numAssets; i++) {
|
||||
uint256 currentBalance = cachedUintBalances[i];
|
||||
// Calculate with rounding up: (a * b + c - 1) / c
|
||||
depositAmounts[i] = (lpTokenAmount * currentBalance + totalLpSupply - 1) / totalLpSupply;
|
||||
depositAmounts[i] = (lpTokenAmount * currentBalance + totalSupply - 1) / totalSupply;
|
||||
}
|
||||
|
||||
return depositAmounts;
|
||||
}
|
||||
|
||||
/// @notice Internal helper to calculate withdrawal amounts for burning LP tokens
|
||||
function _burnReceiveAmounts(uint256 lpTokenAmount) internal view returns (uint256[] memory withdrawAmounts) {
|
||||
function _burnAmounts(uint256 lpTokenAmount) internal view returns (uint256[] memory withdrawAmounts) {
|
||||
uint256 n = tokens.length;
|
||||
withdrawAmounts = new uint256[](n);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user