PartyPoolView
This commit is contained in:
@@ -80,6 +80,9 @@ contract PartyPool is PartyPoolBase, ERC20External, IPartyPool {
|
||||
/// @inheritdoc IPartyPool
|
||||
function denominators() external view returns (uint256[] memory) { return bases; }
|
||||
|
||||
function LMSR() external view returns (LMSRStabilized.State memory) { return lmsr; }
|
||||
|
||||
|
||||
/// @param name_ LP token name
|
||||
/// @param symbol_ LP token symbol
|
||||
/// @param tokens_ token addresses (n)
|
||||
@@ -87,7 +90,7 @@ contract PartyPool is PartyPoolBase, ERC20External, IPartyPool {
|
||||
/// @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 swapMintImpl_ address of the SwapMint implementation contract
|
||||
/// @param swapImpl_ address of the SwapMint implementation contract
|
||||
/// @param mintImpl_ address of the Mint implementation contract
|
||||
constructor(
|
||||
string memory name_,
|
||||
@@ -99,7 +102,7 @@ contract PartyPool is PartyPoolBase, ERC20External, IPartyPool {
|
||||
uint256 flashFeePpm_,
|
||||
uint256 protocolFeePpm_, // NEW: protocol share of fees (ppm)
|
||||
address protocolFeeAddress_, // NEW: recipient for collected protocol tokens
|
||||
PartyPoolSwapImpl swapMintImpl_,
|
||||
PartyPoolSwapImpl swapImpl_,
|
||||
PartyPoolMintImpl mintImpl_
|
||||
) ERC20External(name_, symbol_) {
|
||||
require(tokens_.length > 1, "Pool: need >1 asset");
|
||||
@@ -114,7 +117,7 @@ contract PartyPool is PartyPoolBase, ERC20External, IPartyPool {
|
||||
require(protocolFeePpm_ < 1_000_000, "Pool: protocol fee >= ppm");
|
||||
PROTOCOL_FEE_PPM = protocolFeePpm_;
|
||||
PROTOCOL_FEE_ADDRESS = protocolFeeAddress_;
|
||||
SWAP_IMPL = swapMintImpl_;
|
||||
SWAP_IMPL = swapImpl_;
|
||||
MINT_IMPL = mintImpl_;
|
||||
|
||||
uint256 n = tokens_.length;
|
||||
@@ -134,47 +137,6 @@ contract PartyPool is PartyPoolBase, ERC20External, IPartyPool {
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Current marginal prices
|
||||
//
|
||||
|
||||
/// @notice Marginal price of `base` in terms of `quote` (p_quote / p_base) as Q64.64
|
||||
/// @dev Returns the LMSR marginal price directly (raw 64.64) for use by off-chain quoting logic.
|
||||
function price(uint256 baseTokenIndex, uint256 quoteTokenIndex) external view returns (int128) {
|
||||
uint256 n = tokens.length;
|
||||
require(baseTokenIndex < n && quoteTokenIndex < n, "price: idx");
|
||||
require(lmsr.nAssets > 0, "price: uninit");
|
||||
return lmsr.price(baseTokenIndex, quoteTokenIndex);
|
||||
}
|
||||
|
||||
/// @notice Price of one LP token denominated in `quote` asset as Q64.64
|
||||
/// @dev Computes LMSR poolPrice (quote per unit qTotal) and scales it by totalSupply() / qTotal
|
||||
/// to return price per LP token unit in quote asset (raw 64.64).
|
||||
function poolPrice(uint256 quoteTokenIndex) external view returns (int128) {
|
||||
uint256 n = tokens.length;
|
||||
require(quoteTokenIndex < n, "poolPrice: idx");
|
||||
require(lmsr.nAssets > 0, "poolPrice: uninit");
|
||||
|
||||
// price per unit of qTotal (Q64.64) from LMSR
|
||||
int128 pricePerQ = lmsr.poolPrice(quoteTokenIndex);
|
||||
|
||||
// total internal q (qTotal) as Q64.64
|
||||
int128 qTotal = _computeSizeMetric(lmsr.qInternal);
|
||||
require(qTotal > int128(0), "poolPrice: qTotal zero");
|
||||
|
||||
// totalSupply as Q64.64
|
||||
uint256 supply = totalSupply();
|
||||
require(supply > 0, "poolPrice: zero supply");
|
||||
int128 supplyQ64 = ABDKMath64x64.fromUInt(supply);
|
||||
|
||||
// factor = totalSupply / qTotal (Q64.64)
|
||||
int128 factor = supplyQ64.div(qTotal);
|
||||
|
||||
// price per LP token = pricePerQ * factor (Q64.64)
|
||||
return pricePerQ.mul(factor);
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------
|
||||
Initialization / Mint / Burn (LP token managed)
|
||||
---------------------- */
|
||||
@@ -192,11 +154,6 @@ contract PartyPool is PartyPoolBase, ERC20External, IPartyPool {
|
||||
return abi.decode(result, (uint256));
|
||||
}
|
||||
|
||||
/// @inheritdoc IPartyPool
|
||||
function mintAmounts(uint256 lpTokenAmount) public view returns (uint256[] memory depositAmounts) {
|
||||
return MINT_IMPL.mintAmounts(lpTokenAmount, lmsr.nAssets, totalSupply(), cachedUintBalances);
|
||||
}
|
||||
|
||||
/// @notice Proportional mint for existing pool.
|
||||
/// @dev This function forwards the call to the mint implementation via delegatecall
|
||||
/// @param payer address that provides the input tokens
|
||||
@@ -216,11 +173,6 @@ contract PartyPool is PartyPoolBase, ERC20External, IPartyPool {
|
||||
return abi.decode(result, (uint256));
|
||||
}
|
||||
|
||||
/// @inheritdoc IPartyPool
|
||||
function burnAmounts(uint256 lpTokenAmount) external view returns (uint256[] memory withdrawAmounts) {
|
||||
return MINT_IMPL.burnAmounts(lpTokenAmount, lmsr.nAssets, totalSupply(), cachedUintBalances);
|
||||
}
|
||||
|
||||
/// @notice Burn LP tokens and withdraw the proportional basket to receiver.
|
||||
/// @dev This function forwards the call to the burn implementation via delegatecall
|
||||
/// @param payer address that provides the LP tokens to burn
|
||||
@@ -367,22 +319,6 @@ contract PartyPool is PartyPoolBase, ERC20External, IPartyPool {
|
||||
}
|
||||
|
||||
|
||||
/// @inheritdoc IPartyPool
|
||||
function swapToLimitAmounts(
|
||||
uint256 inputTokenIndex,
|
||||
uint256 outputTokenIndex,
|
||||
int128 limitPrice
|
||||
) external view returns (uint256 amountIn, uint256 amountOut, uint256 fee) {
|
||||
require(inputTokenIndex < tokens.length && outputTokenIndex < tokens.length, "swapToLimit: idx");
|
||||
require(limitPrice > int128(0), "swapToLimit: limit <= 0");
|
||||
require(lmsr.nAssets > 0, "swapToLimit: pool uninitialized");
|
||||
|
||||
return SWAP_IMPL.swapToLimitAmounts(
|
||||
inputTokenIndex, outputTokenIndex, limitPrice,
|
||||
bases, KAPPA, lmsr.qInternal, SWAP_FEE_PPM);
|
||||
}
|
||||
|
||||
|
||||
/// @inheritdoc IPartyPool
|
||||
function swapToLimit(
|
||||
address payer,
|
||||
@@ -407,29 +343,6 @@ contract PartyPool is PartyPoolBase, ERC20External, IPartyPool {
|
||||
return abi.decode(result, (uint256,uint256,uint256));
|
||||
}
|
||||
|
||||
function swapMintAmounts(uint256 inputTokenIndex, uint256 maxAmountIn) external view
|
||||
returns (uint256 amountInUsed, uint256 fee, uint256 lpMinted) {
|
||||
return MINT_IMPL.swapMintAmounts(
|
||||
inputTokenIndex,
|
||||
maxAmountIn,
|
||||
SWAP_FEE_PPM,
|
||||
lmsr,
|
||||
bases,
|
||||
totalSupply()
|
||||
);
|
||||
}
|
||||
|
||||
function burnSwapAmounts(uint256 lpAmount, uint256 inputTokenIndex) external view
|
||||
returns (uint256 amountOut) {
|
||||
return MINT_IMPL.burnSwapAmounts(
|
||||
lpAmount,
|
||||
inputTokenIndex,
|
||||
SWAP_FEE_PPM,
|
||||
lmsr,
|
||||
bases,
|
||||
totalSupply()
|
||||
);
|
||||
}
|
||||
|
||||
/// @notice Single-token mint: deposit a single token, charge swap-LMSR cost, and mint LP.
|
||||
/// @dev This function forwards the call to the swapMint implementation via delegatecall
|
||||
@@ -492,19 +405,6 @@ contract PartyPool is PartyPoolBase, ERC20External, IPartyPool {
|
||||
}
|
||||
|
||||
|
||||
/// @inheritdoc IPartyPool
|
||||
function flashRepaymentAmounts(uint256[] memory loanAmounts) external view
|
||||
returns (uint256[] memory repaymentAmounts) {
|
||||
repaymentAmounts = new uint256[](tokens.length);
|
||||
for (uint256 i = 0; i < tokens.length; i++) {
|
||||
uint256 amount = loanAmounts[i];
|
||||
if (amount > 0) {
|
||||
repaymentAmounts[i] = amount + _ceilFee(amount, FLASH_FEE_PPM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// @notice Receive token amounts and require them to be repaid plus a fee inside a callback.
|
||||
/// @dev The caller must implement IPartyFlashCallback#partyFlashCallback which receives (amounts, repaymentAmounts, data).
|
||||
/// This function verifies that, after the callback returns, the pool's balances have increased by at least the fees
|
||||
@@ -604,7 +504,6 @@ contract PartyPool is PartyPoolBase, ERC20External, IPartyPool {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function _swapAmountsForExactInput(uint256 i, uint256 j, int128 a, int128 limitPrice) internal virtual view
|
||||
returns (int128 amountIn, int128 amountOut) {
|
||||
return lmsr.swapAmountsForExactInput(i, j, a, limitPrice);
|
||||
|
||||
Reference in New Issue
Block a user