proxied swapToLimit

This commit is contained in:
tim
2025-10-06 17:38:47 -04:00
parent 63f6e66d08
commit 20af14c872
7 changed files with 273 additions and 224 deletions

View File

@@ -5,6 +5,7 @@ import {IERC20} from "../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20
import {SafeERC20} from "../lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
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";
@@ -33,11 +34,11 @@ contract PartyPlanner is IPartyPlanner {
function protocolFeeAddress() external view returns (address) { return PROTOCOL_FEE_ADDRESS; }
// On-chain pool indexing
PartyPool[] private _allPools;
IPartyPool[] private _allPools;
IERC20[] private _allTokens;
mapping(PartyPool => bool) private _poolSupported;
mapping(IPartyPool => bool) private _poolSupported;
mapping(IERC20 => bool) private _tokenSupported;
mapping(IERC20 => PartyPool[]) private _poolsByToken;
mapping(IERC20 => IPartyPool[]) private _poolsByToken;
/// @param _swapMintImpl address of the SwapMint implementation contract to be used by all pools
/// @param _mintImpl address of the Mint implementation contract to be used by all pools
@@ -76,7 +77,7 @@ contract PartyPlanner is IPartyPlanner {
uint256[] memory initialDeposits,
uint256 initialLpAmount,
uint256 deadline
) public returns (PartyPool pool, uint256 lpAmount) {
) public returns (IPartyPool pool, uint256 lpAmount) {
// Validate inputs
require(deadline == 0 || block.timestamp <= deadline, "Planner: deadline exceeded");
require(_tokens.length == initialDeposits.length, "Planner: tokens and deposits length mismatch");
@@ -165,7 +166,7 @@ contract PartyPlanner is IPartyPlanner {
uint256[] memory initialDeposits,
uint256 initialLpAmount,
uint256 deadline
) external returns (PartyPool pool, uint256 lpAmount) {
) external returns (IPartyPool pool, uint256 lpAmount) {
// Validate fixed-point fractions: must be less than 1.0 in 64.64 fixed-point
require(_tradeFrac < ONE, "Planner: tradeFrac must be < 1 (64.64)");
require(_targetSlippage < ONE, "Planner: targetSlippage must be < 1 (64.64)");
@@ -193,7 +194,7 @@ contract PartyPlanner is IPartyPlanner {
/// @inheritdoc IPartyPlanner
function getPoolSupported(address pool) external view returns (bool) {
return _poolSupported[PartyPool(pool)];
return _poolSupported[IPartyPool(pool)];
}
/// @inheritdoc IPartyPlanner
@@ -202,19 +203,19 @@ contract PartyPlanner is IPartyPlanner {
}
/// @inheritdoc IPartyPlanner
function getAllPools(uint256 offset, uint256 limit) external view returns (PartyPool[] memory pools) {
function getAllPools(uint256 offset, uint256 limit) external view returns (IPartyPool[] memory pools) {
uint256 totalPools = _allPools.length;
// If offset is beyond array bounds, return empty array
if (offset >= totalPools) {
return new PartyPool[](0);
return new IPartyPool[](0);
}
// Calculate actual number of pools to return (respecting bounds)
uint256 itemsToReturn = (offset + limit > totalPools) ? (totalPools - offset) : limit;
// Create result array of appropriate size
pools = new PartyPool[](itemsToReturn);
pools = new IPartyPool[](itemsToReturn);
// Fill the result array
for (uint256 i = 0; i < itemsToReturn; i++) {
@@ -258,20 +259,20 @@ contract PartyPlanner is IPartyPlanner {
}
/// @inheritdoc IPartyPlanner
function getPoolsByToken(IERC20 token, uint256 offset, uint256 limit) external view returns (PartyPool[] memory pools) {
PartyPool[] storage tokenPools = _poolsByToken[token];
function getPoolsByToken(IERC20 token, uint256 offset, uint256 limit) external view returns (IPartyPool[] memory pools) {
IPartyPool[] storage tokenPools = _poolsByToken[token];
uint256 totalPools = tokenPools.length;
// If offset is beyond array bounds, return empty array
if (offset >= totalPools) {
return new PartyPool[](0);
return new IPartyPool[](0);
}
// Calculate actual number of pools to return (respecting bounds)
uint256 itemsToReturn = (offset + limit > totalPools) ? (totalPools - offset) : limit;
// Create result array of appropriate size
pools = new PartyPool[](itemsToReturn);
pools = new IPartyPool[](itemsToReturn);
// Fill the result array
for (uint256 i = 0; i < itemsToReturn; i++) {