From 104c2791235548c839b1a815c02060afd366230d Mon Sep 17 00:00:00 2001 From: tim Date: Tue, 7 Oct 2025 14:50:36 -0400 Subject: [PATCH] deployable sizes --- src/Deploy.sol | 3 ++ src/PartyPlanner.sol | 29 ++++++------- src/PartyPoolDeployer.sol | 87 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 17 deletions(-) create mode 100644 src/PartyPoolDeployer.sol diff --git a/src/Deploy.sol b/src/Deploy.sol index 77a090c..d5f7019 100644 --- a/src/Deploy.sol +++ b/src/Deploy.sol @@ -5,6 +5,7 @@ import {IERC20} from "../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20 import {PartyPlanner} from "./PartyPlanner.sol"; import {PartyPool} from "./PartyPool.sol"; import {PartyPoolBalancedPair} from "./PartyPoolBalancedPair.sol"; +import {PartyPoolDeployer, PartyPoolBalancedPairDeployer} from "./PartyPoolDeployer.sol"; import {PartyPoolMintImpl} from "./PartyPoolMintImpl.sol"; import {PartyPoolSwapImpl} from "./PartyPoolSwapImpl.sol"; import {PartyPoolView} from "./PartyPoolView.sol"; @@ -15,6 +16,8 @@ library Deploy { return new PartyPlanner( new PartyPoolSwapImpl(), new PartyPoolMintImpl(), + new PartyPoolDeployer(), + new PartyPoolBalancedPairDeployer(), 0, // protocolFeePpm = 0 for deploy helper address(0) // protocolFeeAddress = address(0) for deploy helper ); diff --git a/src/PartyPlanner.sol b/src/PartyPlanner.sol index eccc362..ec12bf0 100644 --- a/src/PartyPlanner.sol +++ b/src/PartyPlanner.sol @@ -6,10 +6,9 @@ import {SafeERC20} from "../lib/openzeppelin-contracts/contracts/token/ERC20/uti import {IPartyPlanner} from "./IPartyPlanner.sol"; import {LMSRStabilized} from "./LMSRStabilized.sol"; import {IPartyPool} from "./IPartyPool.sol"; -import {PartyPool} from "./PartyPool.sol"; import {PartyPoolMintImpl} from "./PartyPoolMintImpl.sol"; import {PartyPoolSwapImpl} from "./PartyPoolSwapImpl.sol"; -import {PartyPoolBalancedPair} from "./PartyPoolBalancedPair.sol"; +import {IPartyPoolDeployer} from "./PartyPoolDeployer.sol"; /// @title PartyPlanner /// @notice Factory contract for creating and tracking PartyPool instances @@ -33,6 +32,9 @@ contract PartyPlanner is IPartyPlanner { address private immutable PROTOCOL_FEE_ADDRESS; function protocolFeeAddress() external view returns (address) { return PROTOCOL_FEE_ADDRESS; } + IPartyPoolDeployer private immutable NORMAL_POOL_DEPLOYER; + IPartyPoolDeployer private immutable BALANCED_PAIR_DEPLOYER; + // On-chain pool indexing IPartyPool[] private _allPools; IERC20[] private _allTokens; @@ -47,6 +49,8 @@ contract PartyPlanner is IPartyPlanner { constructor( PartyPoolSwapImpl _swapMintImpl, PartyPoolMintImpl _mintImpl, + IPartyPoolDeployer _deployer, + IPartyPoolDeployer _balancedPairDeployer, uint256 _protocolFeePpm, address _protocolFeeAddress ) { @@ -54,6 +58,10 @@ contract PartyPlanner is IPartyPlanner { SWAP_MINT_IMPL = _swapMintImpl; require(address(_mintImpl) != address(0), "Planner: mintImpl address cannot be zero"); MINT_IMPL = _mintImpl; + require(address(_deployer) != address(0), "Planner: deployer address cannot be zero"); + NORMAL_POOL_DEPLOYER = _deployer; + require(address(_balancedPairDeployer) != address(0), "Planner: balanced pair deployer address cannot be zero"); + BALANCED_PAIR_DEPLOYER = _balancedPairDeployer; require(_protocolFeePpm < 1_000_000, "Planner: protocol fee >= ppm"); PROTOCOL_FEE_PPM = _protocolFeePpm; @@ -88,21 +96,8 @@ contract PartyPlanner is IPartyPlanner { require(_kappa > int128(0), "Planner: kappa must be > 0"); // Create a new PartyPool instance (kappa-based constructor) - pool = _stable && _tokens.length == 2 ? - new PartyPoolBalancedPair( - name_, - symbol_, - _tokens, - _bases, - _kappa, - _swapFeePpm, - _flashFeePpm, - PROTOCOL_FEE_PPM, - PROTOCOL_FEE_ADDRESS, - PartyPoolSwapImpl(SWAP_MINT_IMPL), - MINT_IMPL - ) : - new PartyPool( + IPartyPoolDeployer deployer = _stable && _tokens.length == 2 ? BALANCED_PAIR_DEPLOYER : NORMAL_POOL_DEPLOYER; + pool = deployer.deploy( name_, symbol_, _tokens, diff --git a/src/PartyPoolDeployer.sol b/src/PartyPoolDeployer.sol new file mode 100644 index 0000000..fbdd3dd --- /dev/null +++ b/src/PartyPoolDeployer.sol @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.30; + +import "./PartyPoolMintImpl.sol"; +import "./PartyPoolSwapImpl.sol"; +import {PartyPool} from "./PartyPool.sol"; +import {PartyPoolBalancedPair} from "./PartyPoolBalancedPair.sol"; + +// This pattern is needed because the PartyPlanner constructs two different types of pools (regular and balanced-pair) +// but doesn't have room to store the initialization code of both contracts. Therefore, we delegate pool construction. + +interface IPartyPoolDeployer { + function deploy( + string memory name_, + string memory symbol_, + IERC20[] memory tokens_, + uint256[] memory bases_, + int128 kappa_, + uint256 swapFeePpm_, + uint256 flashFeePpm_, + uint256 protocolFeePpm_, + address protocolFeeAddress_, + PartyPoolSwapImpl swapImpl_, + PartyPoolMintImpl mintImpl_ + ) external returns (IPartyPool pool); +} + +contract PartyPoolDeployer is IPartyPoolDeployer { + function deploy( + string memory name_, + string memory symbol_, + IERC20[] memory tokens_, + uint256[] memory bases_, + int128 kappa_, + uint256 swapFeePpm_, + uint256 flashFeePpm_, + uint256 protocolFeePpm_, + address protocolFeeAddress_, + PartyPoolSwapImpl swapImpl_, + PartyPoolMintImpl mintImpl_ + ) external returns (IPartyPool) { + return new PartyPool( + name_, + symbol_, + tokens_, + bases_, + kappa_, + swapFeePpm_, + flashFeePpm_, + protocolFeePpm_, + protocolFeeAddress_, + swapImpl_, + mintImpl_ + ); + } +} + +contract PartyPoolBalancedPairDeployer is IPartyPoolDeployer { + function deploy( + string memory name_, + string memory symbol_, + IERC20[] memory tokens_, + uint256[] memory bases_, + int128 kappa_, + uint256 swapFeePpm_, + uint256 flashFeePpm_, + uint256 protocolFeePpm_, + address protocolFeeAddress_, + PartyPoolSwapImpl swapImpl_, + PartyPoolMintImpl mintImpl_ + ) external returns (IPartyPool) { + return new PartyPoolBalancedPair( + name_, + symbol_, + tokens_, + bases_, + kappa_, + swapFeePpm_, + flashFeePpm_, + protocolFeePpm_, + protocolFeeAddress_, + swapImpl_, + mintImpl_ + ); + } +} +