PoolBase; warnings cleanup
This commit is contained in:
@@ -597,9 +597,6 @@ library LMSRStabilized {
|
|||||||
int128 newTotal = _computeSizeMetric(newQInternal);
|
int128 newTotal = _computeSizeMetric(newQInternal);
|
||||||
require(newTotal > int128(0), "LMSR: new total zero");
|
require(newTotal > int128(0), "LMSR: new total zero");
|
||||||
|
|
||||||
// With kappa formulation, b automatically scales with pool size
|
|
||||||
int128 newB = s.kappa.mul(newTotal);
|
|
||||||
|
|
||||||
// Update the cached qInternal with new values
|
// Update the cached qInternal with new values
|
||||||
for (uint i = 0; i < s.nAssets; ) {
|
for (uint i = 0; i < s.nAssets; ) {
|
||||||
s.qInternal[i] = newQInternal[i];
|
s.qInternal[i] = newQInternal[i];
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|||||||
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
|
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
|
||||||
import "./PoolLib.sol";
|
import "./PoolLib.sol";
|
||||||
import "./IPartyPool.sol";
|
import "./IPartyPool.sol";
|
||||||
|
import {PoolBase} from "./PoolBase.sol";
|
||||||
|
|
||||||
/// @title PartyPool - LMSR-backed multi-asset pool with LP ERC20 token
|
/// @title PartyPool - LMSR-backed multi-asset pool with LP ERC20 token
|
||||||
/// @notice A multi-asset liquidity pool backed by the LMSRStabilized pricing model.
|
/// @notice A multi-asset liquidity pool backed by the LMSRStabilized pricing model.
|
||||||
@@ -17,12 +18,9 @@ import "./IPartyPool.sol";
|
|||||||
/// - Flash loans via a callback interface.
|
/// - Flash loans via a callback interface.
|
||||||
///
|
///
|
||||||
/// @dev The contract uses PoolLib for all implementation logic and maintains state in a PoolLib.State struct
|
/// @dev The contract uses PoolLib for all implementation logic and maintains state in a PoolLib.State struct
|
||||||
contract PartyPool is IPartyPool, ERC20, ReentrancyGuard {
|
contract PartyPool is PoolBase, IPartyPool {
|
||||||
using PoolLib for PoolLib.State;
|
using PoolLib for PoolLib.State;
|
||||||
|
|
||||||
/// @notice Pool state containing all storage variables
|
|
||||||
PoolLib.State internal s;
|
|
||||||
|
|
||||||
/// @notice Liquidity parameter κ (Q64.64) used by the LMSR kernel: b = κ * S(q)
|
/// @notice Liquidity parameter κ (Q64.64) used by the LMSR kernel: b = κ * S(q)
|
||||||
/// @dev Pool is constructed with a fixed κ. Clients may use LMSRStabilized.computeKappaFromSlippage(...) to
|
/// @dev Pool is constructed with a fixed κ. Clients may use LMSRStabilized.computeKappaFromSlippage(...) to
|
||||||
/// derive κ and pass it here.
|
/// derive κ and pass it here.
|
||||||
@@ -136,7 +134,7 @@ contract PartyPool is IPartyPool, ERC20, ReentrancyGuard {
|
|||||||
/// @param lpAmount amount of LP tokens to burn (proportional withdrawal)
|
/// @param lpAmount amount of LP tokens to burn (proportional withdrawal)
|
||||||
/// @param deadline timestamp after which the transaction will revert. Pass 0 to ignore.
|
/// @param deadline timestamp after which the transaction will revert. Pass 0 to ignore.
|
||||||
function burn(address payer, address receiver, uint256 lpAmount, uint256 deadline) external nonReentrant {
|
function burn(address payer, address receiver, uint256 lpAmount, uint256 deadline) external nonReentrant {
|
||||||
uint256[] memory withdrawAmounts = s.burn(payer, receiver, lpAmount, deadline, totalSupply(), balanceOf(payer));
|
/* uint256[] memory withdrawAmounts = */ s.burn(payer, receiver, lpAmount, deadline, totalSupply(), balanceOf(payer));
|
||||||
|
|
||||||
// Handle LP token burning with allowance
|
// Handle LP token burning with allowance
|
||||||
if (msg.sender != payer) {
|
if (msg.sender != payer) {
|
||||||
|
|||||||
14
src/PoolBase.sol
Normal file
14
src/PoolBase.sol
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// SPDX-License-Identifier: UNLICENSED
|
||||||
|
pragma solidity ^0.8.30;
|
||||||
|
|
||||||
|
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||||
|
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||||
|
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
|
||||||
|
import "./PoolLib.sol";
|
||||||
|
|
||||||
|
/// @notice This contract has all the storage for PartyPool and can be inherited by implementation contracts that
|
||||||
|
/// are delegate-called
|
||||||
|
abstract contract PoolBase is ERC20, ReentrancyGuard {
|
||||||
|
/// @notice Pool state containing all storage variables
|
||||||
|
PoolLib.State internal s;
|
||||||
|
}
|
||||||
@@ -711,7 +711,7 @@ contract LMSRStabilizedTest is Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Path 1: Direct swap from asset 0 to asset 2
|
// Path 1: Direct swap from asset 0 to asset 2
|
||||||
(int128 directAmountIn, int128 directAmountOut) = s.swapAmountsForExactInput(0, 2, directSwapAmount, 0);
|
(/* int128 directAmountIn */, int128 directAmountOut) = s.swapAmountsForExactInput(0, 2, directSwapAmount, 0);
|
||||||
|
|
||||||
// Restore original state for second path
|
// Restore original state for second path
|
||||||
_updateCachedQInternal(backupQ);
|
_updateCachedQInternal(backupQ);
|
||||||
@@ -724,7 +724,7 @@ contract LMSRStabilizedTest is Test {
|
|||||||
s.qInternal[1] = s.qInternal[1].add(indirectAmountOut1);
|
s.qInternal[1] = s.qInternal[1].add(indirectAmountOut1);
|
||||||
|
|
||||||
// Second swap: asset 1 -> asset 2
|
// Second swap: asset 1 -> asset 2
|
||||||
(int128 indirectAmountIn2, int128 indirectAmountOut2) = s.swapAmountsForExactInput(1, 2, indirectAmountOut1, 0);
|
(/* int128 indirectAmountIn2 */, int128 indirectAmountOut2) = s.swapAmountsForExactInput(1, 2, indirectAmountOut1, 0);
|
||||||
|
|
||||||
// The path independence property isn't perfect due to discrete swap mechanics,
|
// The path independence property isn't perfect due to discrete swap mechanics,
|
||||||
// but the difference should be within reasonable bounds
|
// but the difference should be within reasonable bounds
|
||||||
@@ -765,7 +765,7 @@ contract LMSRStabilizedTest is Test {
|
|||||||
s.qInternal[1] = s.qInternal[1].add(amountOut1);
|
s.qInternal[1] = s.qInternal[1].add(amountOut1);
|
||||||
|
|
||||||
// Step 2: Swap back asset 1 -> asset 0
|
// Step 2: Swap back asset 1 -> asset 0
|
||||||
(int128 amountIn2, int128 amountOut2) = s.swapAmountsForExactInput(1, 0, amountOut1, 0);
|
(/* int128 amountIn2 */, int128 amountOut2) = s.swapAmountsForExactInput(1, 0, amountOut1, 0);
|
||||||
|
|
||||||
// Calculate round-trip slippage: (initial amount - final amount) / initial amount
|
// Calculate round-trip slippage: (initial amount - final amount) / initial amount
|
||||||
int128 roundTripSlippage = (amountIn1.sub(amountOut2)).div(amountIn1);
|
int128 roundTripSlippage = (amountIn1.sub(amountOut2)).div(amountIn1);
|
||||||
|
|||||||
Reference in New Issue
Block a user