swapMintImpl moved into mintImpl
This commit is contained in:
@@ -15,6 +15,7 @@ import {PartyPoolMintImpl} from "./PartyPoolMintImpl.sol";
|
||||
import {PartyPoolSwapMintImpl} from "./PartyPoolSwapMintImpl.sol";
|
||||
import {ERC20External} from "./ERC20External.sol";
|
||||
|
||||
|
||||
/// @title PartyPool - LMSR-backed multi-asset pool with LP ERC20 token
|
||||
/// @notice A multi-asset liquidity pool backed by the LMSRStabilized pricing model.
|
||||
/// The pool issues an ERC20 LP token representing proportional ownership.
|
||||
@@ -250,13 +251,6 @@ contract PartyPool is PartyPoolBase, ERC20External, IPartyPool {
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Helper to record cached balances as effectiveBalance = onchain - owed. Reverts if owed > onchain.
|
||||
function _recordCachedBalance(uint256 idx, uint256 onchainBal) internal {
|
||||
uint256 owed = protocolFeesOwed[idx];
|
||||
require(onchainBal >= owed, "balance < protocol owed");
|
||||
cachedUintBalances[idx] = onchainBal - owed;
|
||||
}
|
||||
|
||||
/// @notice Swap input token i -> token j. Payer must approve token i.
|
||||
/// @dev This function transfers the exact gross input (including fee) from payer and sends the computed output to receiver.
|
||||
/// Non-standard tokens (fee-on-transfer, rebasers) are rejected via balance checks.
|
||||
@@ -499,7 +493,7 @@ contract PartyPool is PartyPoolBase, ERC20External, IPartyPool {
|
||||
|
||||
function swapMintAmounts(uint256 inputTokenIndex, uint256 maxAmountIn) external view
|
||||
returns (uint256 amountInUsed, uint256 fee, uint256 lpMinted) {
|
||||
return SWAP_MINT_IMPL.swapMintAmounts(
|
||||
return MINT_IMPL.swapMintAmounts(
|
||||
inputTokenIndex,
|
||||
maxAmountIn,
|
||||
SWAP_FEE_PPM,
|
||||
@@ -511,7 +505,7 @@ contract PartyPool is PartyPoolBase, ERC20External, IPartyPool {
|
||||
|
||||
function burnSwapAmounts(uint256 lpAmount, uint256 inputTokenIndex) external view
|
||||
returns (uint256 amountOut) {
|
||||
return SWAP_MINT_IMPL.burnSwapAmounts(
|
||||
return MINT_IMPL.burnSwapAmounts(
|
||||
lpAmount,
|
||||
inputTokenIndex,
|
||||
SWAP_FEE_PPM,
|
||||
@@ -537,32 +531,18 @@ contract PartyPool is PartyPoolBase, ERC20External, IPartyPool {
|
||||
uint256 deadline
|
||||
) external returns (uint256 lpMinted) {
|
||||
bytes memory data = abi.encodeWithSignature(
|
||||
"swapMint(address,address,uint256,uint256,uint256,uint256)",
|
||||
"swapMint(address,address,uint256,uint256,uint256,uint256,uint256)",
|
||||
payer,
|
||||
receiver,
|
||||
inputTokenIndex,
|
||||
maxAmountIn,
|
||||
deadline,
|
||||
SWAP_FEE_PPM
|
||||
SWAP_FEE_PPM,
|
||||
PROTOCOL_FEE_PPM
|
||||
);
|
||||
|
||||
bytes memory result = Address.functionDelegateCall(address(SWAP_MINT_IMPL), data);
|
||||
// New ABI: implementation returns (uint256 lpMinted, uint256 feeUintActual)
|
||||
(uint256 lpOut, uint256 feeUintActual) = abi.decode(result, (uint256, uint256));
|
||||
|
||||
// Accrue protocol share (floor) from the fee on the input token
|
||||
if (PROTOCOL_FEE_PPM > 0 && feeUintActual > 0 && PROTOCOL_FEE_ADDRESS != address(0)) {
|
||||
uint256 protoShare = (feeUintActual * PROTOCOL_FEE_PPM) / 1_000_000;
|
||||
if (protoShare > 0) {
|
||||
protocolFeesOwed[inputTokenIndex] += protoShare;
|
||||
}
|
||||
}
|
||||
|
||||
// Update cached balance for the input token to effective onchain - owed
|
||||
uint256 bal = IERC20(tokens[inputTokenIndex]).balanceOf(address(this));
|
||||
_recordCachedBalance(inputTokenIndex, bal);
|
||||
|
||||
return lpOut;
|
||||
bytes memory result = Address.functionDelegateCall(address(MINT_IMPL), data);
|
||||
return abi.decode(result, (uint256));
|
||||
}
|
||||
|
||||
/// @notice Burn LP tokens then swap the redeemed proportional basket into a single asset `inputTokenIndex` and send to receiver.
|
||||
@@ -581,32 +561,18 @@ contract PartyPool is PartyPoolBase, ERC20External, IPartyPool {
|
||||
uint256 deadline
|
||||
) external returns (uint256 amountOutUint) {
|
||||
bytes memory data = abi.encodeWithSignature(
|
||||
"burnSwap(address,address,uint256,uint256,uint256,uint256)",
|
||||
"burnSwap(address,address,uint256,uint256,uint256,uint256,uint256)",
|
||||
payer,
|
||||
receiver,
|
||||
lpAmount,
|
||||
inputTokenIndex,
|
||||
deadline,
|
||||
SWAP_FEE_PPM
|
||||
SWAP_FEE_PPM,
|
||||
PROTOCOL_FEE_PPM
|
||||
);
|
||||
|
||||
bytes memory result = Address.functionDelegateCall(address(SWAP_MINT_IMPL), data);
|
||||
// New ABI: implementation returns (uint256 amountOutUint, uint256 feeTokenUint)
|
||||
(uint256 outAmt, uint256 feeTokenUint) = abi.decode(result, (uint256, uint256));
|
||||
|
||||
// Accrue protocol share (floor) from the token-side fee computed by implementation
|
||||
if (PROTOCOL_FEE_PPM > 0 && feeTokenUint > 0 && PROTOCOL_FEE_ADDRESS != address(0)) {
|
||||
uint256 protoShare = (feeTokenUint * PROTOCOL_FEE_PPM) / 1_000_000;
|
||||
if (protoShare > 0) {
|
||||
protocolFeesOwed[inputTokenIndex] += protoShare;
|
||||
}
|
||||
}
|
||||
|
||||
// Update cached balance for the target token to effective onchain - owed
|
||||
uint256 bal = IERC20(tokens[inputTokenIndex]).balanceOf(address(this));
|
||||
_recordCachedBalance(inputTokenIndex, bal);
|
||||
|
||||
return outAmt;
|
||||
bytes memory result = Address.functionDelegateCall(address(MINT_IMPL), data);
|
||||
return abi.decode(result, (uint256));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user