burnSwap outputIndex/token naming fix

This commit is contained in:
tim
2025-10-28 12:17:01 -04:00
parent 5c5a000961
commit 86410c9a91
5 changed files with 29 additions and 29 deletions

View File

@@ -230,19 +230,19 @@ interface IPartyPool is IERC20Metadata, IOwnable {
uint256 deadline
) external payable returns (uint256 lpMinted);
/// @notice Burn LP tokens then swap the redeemed proportional basket into a single asset `inputTokenIndex` and send to receiver.
/// @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.
/// @param payer who burns LP tokens
/// @param receiver who receives the single asset
/// @param lpAmount amount of LP tokens to burn
/// @param inputTokenIndex index of target asset to receive
/// @param outputTokenIndex index of target asset to receive
/// @param deadline optional deadline
/// @return amountOutUint uint amount of asset inputTokenIndex sent to receiver
/// @return amountOutUint uint amount of asset outputTokenIndex sent to receiver
function burnSwap(
address payer,
address receiver,
uint256 lpAmount,
uint256 inputTokenIndex,
uint256 outputTokenIndex,
uint256 deadline,
bool unwrap
) external returns (uint256 amountOutUint);

View File

@@ -52,8 +52,8 @@ interface IPartyPoolViewer {
/// @notice Calculate the amounts for a burn swap operation
/// @dev This is a pure view function that computes burn swap amounts from provided state
/// @param lpAmount amount of LP _tokens to burn
/// @param inputTokenIndex index of target asset to receive
function burnSwapAmounts(IPartyPool pool, uint256 lpAmount, uint256 inputTokenIndex) external view
/// @param outputTokenIndex index of target asset to receive
function burnSwapAmounts(IPartyPool pool, uint256 lpAmount, uint256 outputTokenIndex) external view
returns (uint256 amountOut);
/// @notice Compute repayment amounts (principal + flash fee) for a proposed flash loan.

View File

@@ -407,14 +407,14 @@ contract PartyPool is PartyPoolBase, OwnableExternal, ERC20External, IPartyPool
/// @param payer who burns LP _tokens
/// @param receiver who receives the single asset
/// @param lpAmount amount of LP _tokens to burn
/// @param inputTokenIndex index of target asset to receive
/// @param outputTokenIndex index of target asset to receive
/// @param deadline optional deadline
/// @return amountOutUint uint amount of asset i sent to receiver
function burnSwap(
address payer,
address receiver,
uint256 lpAmount,
uint256 inputTokenIndex,
uint256 outputTokenIndex,
uint256 deadline,
bool unwrap
) external returns (uint256 amountOutUint) {
@@ -423,7 +423,7 @@ contract PartyPool is PartyPoolBase, OwnableExternal, ERC20External, IPartyPool
payer,
receiver,
lpAmount,
inputTokenIndex,
outputTokenIndex,
deadline,
unwrap,
SWAP_FEE_PPM,

View File

@@ -441,7 +441,7 @@ contract PartyPoolMintImpl is PartyPoolBase {
/// @notice Calculate the amounts for a burn swap operation
/// @dev This is a pure view function that computes burn swap amounts from provided state
/// @param lpAmount amount of LP _tokens to burn
/// @param inputTokenIndex index of target asset to receive
/// @param outputTokenIndex index of target asset to receive
/// @param swapFeePpm fee in parts-per-million
/// @param lmsrState current LMSR state
/// @param bases_ scaling _bases for each token
@@ -449,13 +449,13 @@ contract PartyPoolMintImpl is PartyPoolBase {
/// @return amountOut amount of target asset that would be received
function burnSwapAmounts(
uint256 lpAmount,
uint256 inputTokenIndex,
uint256 outputTokenIndex,
uint256 swapFeePpm,
LMSRStabilized.State memory lmsrState,
uint256[] memory bases_,
uint256 totalSupply_
) public pure returns (uint256 amountOut) {
require(inputTokenIndex < bases_.length, "burnSwapAmounts: idx");
require(outputTokenIndex < bases_.length, "burnSwapAmounts: idx");
require(lpAmount > 0, "burnSwapAmounts: zero lp");
require(totalSupply_ > 0, "burnSwapAmounts: empty supply");
@@ -465,21 +465,21 @@ contract PartyPoolMintImpl is PartyPoolBase {
// Use LMSR view to compute single-asset payout and burned size-metric
(int128 payoutInternal, ) = LMSRStabilized.swapAmountsForBurn(lmsrState.nAssets, lmsrState.kappa, lmsrState.qInternal,
inputTokenIndex, alpha);
outputTokenIndex, alpha);
// Convert payoutInternal -> uint (floor) to favor pool
amountOut = _internalToUintFloorPure(payoutInternal, bases_[inputTokenIndex]);
amountOut = _internalToUintFloorPure(payoutInternal, bases_[outputTokenIndex]);
require(amountOut > 0, "burnSwapAmounts: output zero");
}
/// @notice Burn LP _tokens then swap the redeemed proportional basket into a single asset `inputTokenIndex` and send to receiver.
/// @notice Burn LP _tokens then swap the redeemed proportional basket into a single asset `outputTokenIndex` and send to receiver.
/// This version of burn does not work if the vault has been killed, because it involves a swap. Use regular burn()
/// to recover funds if the pool has been killed.
/// @dev The function burns LP _tokens (authorization via allowance if needed), sends the single-asset payout and updates LMSR state.
/// @param payer who burns LP _tokens
/// @param receiver who receives the single asset
/// @param lpAmount amount of LP _tokens to burn
/// @param inputTokenIndex index of target asset to receive
/// @param outputTokenIndex index of target asset to receive
/// @param deadline optional deadline
/// @param swapFeePpm fee in parts-per-million for this pool (may be used for future fee logic)
/// @return amountOutUint uint amount of asset i sent to receiver
@@ -487,14 +487,14 @@ contract PartyPoolMintImpl is PartyPoolBase {
address payer,
address receiver,
uint256 lpAmount,
uint256 inputTokenIndex,
uint256 outputTokenIndex,
uint256 deadline,
bool unwrap,
uint256 swapFeePpm,
uint256 protocolFeePpm
) external nonReentrant killable returns (uint256 amountOutUint) {
uint256 n = _tokens.length;
require(inputTokenIndex < n, "burnSwap: idx");
require(outputTokenIndex < n, "burnSwap: idx");
require(lpAmount > 0, "burnSwap: zero lp");
require(deadline == 0 || block.timestamp <= deadline, "burnSwap: deadline");
@@ -506,16 +506,16 @@ 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, ) = _lmsr.swapAmountsForBurn(inputTokenIndex, alpha);
(int128 payoutInternal, ) = _lmsr.swapAmountsForBurn(outputTokenIndex, alpha);
// Convert payoutInternal -> uint (floor) to favor pool
amountOutUint = _internalToUintFloor(payoutInternal, _bases[inputTokenIndex]);
amountOutUint = _internalToUintFloor(payoutInternal, _bases[outputTokenIndex]);
require(amountOutUint > 0, "burnSwap: output zero");
// Compute gross payout (no swap fee) so we can determine token-side fee = gross - net
int128 alphaGross = ABDKMath64x64.divu(lpAmount, supply); // gross fraction (no swap fee)
(int128 payoutGrossInternal, ) = _lmsr.swapAmountsForBurn(inputTokenIndex, alphaGross);
uint256 payoutGrossUint = _internalToUintFloor(payoutGrossInternal, _bases[inputTokenIndex]);
(int128 payoutGrossInternal, ) = _lmsr.swapAmountsForBurn(outputTokenIndex, alphaGross);
uint256 payoutGrossUint = _internalToUintFloor(payoutGrossInternal, _bases[outputTokenIndex]);
uint256 feeTokenUint = (payoutGrossUint > amountOutUint) ? (payoutGrossUint - amountOutUint) : 0;
// Accrue protocol share (floor) from the token-side fee
@@ -523,13 +523,13 @@ contract PartyPoolMintImpl is PartyPoolBase {
if (protocolFeePpm > 0 && feeTokenUint > 0) {
protoShare = (feeTokenUint * protocolFeePpm) / 1_000_000;
if (protoShare > 0) {
_protocolFeesOwed[inputTokenIndex] += protoShare;
_protocolFeesOwed[outputTokenIndex] += protoShare;
}
}
// Transfer the payout to receiver via centralized helper
IERC20 inputToken = _tokens[inputTokenIndex];
_sendTokenTo(inputToken, receiver, amountOutUint, unwrap);
IERC20 outputToken = _tokens[outputTokenIndex];
_sendTokenTo(outputToken, receiver, amountOutUint, unwrap);
// Burn LP _tokens from payer (authorization via allowance)
if (msg.sender != payer) {
@@ -542,7 +542,7 @@ contract PartyPoolMintImpl is PartyPoolBase {
int128[] memory newQInternal = new int128[](n);
for (uint256 idx = 0; idx < n; idx++) {
uint256 newBal = _cachedUintBalances[idx];
if (idx == inputTokenIndex) {
if (idx == outputTokenIndex) {
// Effective LP balance decreases by net payout and increased protocol owed
newBal = newBal - amountOutUint - protoShare;
}
@@ -561,7 +561,7 @@ contract PartyPoolMintImpl is PartyPoolBase {
_lmsr.updateForProportionalChange(newQInternal);
}
emit IPartyPool.BurnSwap(payer, receiver, inputToken, lpAmount, amountOutUint,
emit IPartyPool.BurnSwap(payer, receiver, outputToken, lpAmount, amountOutUint,
feeTokenUint-protoShare, protoShare);
return amountOutUint;

View File

@@ -123,12 +123,12 @@ contract PartyPoolViewer is PartyPoolHelpers, IPartyPoolViewer {
}
function burnSwapAmounts(IPartyPool pool, uint256 lpAmount, uint256 inputTokenIndex) external view
function burnSwapAmounts(IPartyPool pool, uint256 lpAmount, uint256 outputTokenIndex) external view
returns (uint256 amountOut) {
LMSRStabilized.State memory lmsr = pool.LMSR();
return MINT_IMPL.burnSwapAmounts(
lpAmount,
inputTokenIndex,
outputTokenIndex,
pool.swapFeePpm(),
lmsr,
pool.denominators(),