dxod repo init

This commit is contained in:
tim
2025-09-15 14:21:56 -04:00
commit 5fb2b17b2e
18 changed files with 4996 additions and 0 deletions

149
src/IPartyPool.sol Normal file
View File

@@ -0,0 +1,149 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.30;
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
/// @title PartyPool - LMSR-backed multi-asset pool with LP ERC20 token
/// @notice Uses LMSRStabilized library; stores per-token uint bases to convert to/from 64.64 fixed point.
/// - Caches qInternal[] (int128 64.64) and cachedUintBalances[] to minimize balanceOf() calls.
/// - swap and swapToLimit mimic core lib; mint/burn call updateForProportionalChange() and manage LP tokens.
interface IPartyPool is IERC20Metadata {
// All int128's are ABDKMath64x64 format
// Events
event Mint(address payer, address indexed receiver, uint256[] amounts, uint256 lpMinted);
event Burn(address payer, address indexed receiver, uint256[] amounts, uint256 lpBurned);
event Swap(
address payer,
address indexed receiver,
address indexed tokenIn,
address indexed tokenOut,
uint256 amountIn,
uint256 amountOut
);
/// @notice Emitted when a single-token swapMint is executed.
/// Records payer/receiver, input token index, gross transfer (net+fee), net input and fee taken.
event SwapMint(
address indexed payer,
address indexed receiver,
uint256 indexed inputTokenIndex,
uint256 grossTransfer, // total tokens transferred (net + fee)
uint256 netInput, // net input credited to swaps (after fee)
uint256 feeTaken // fee taken (ceil)
);
/// @notice Emitted when a burnSwap is executed.
/// Records payer/receiver, target token index and the uint payout sent to the receiver.
event BurnSwap(
address indexed payer,
address indexed receiver,
uint256 indexed targetTokenIndex,
uint256 payoutUint
);
// Immutable pool configuration (public getters)
function tokens(uint256) external view returns (address); // get single token
function numTokens() external view returns (uint256);
function allTokens() external view returns (address[] memory);
function tradeFrac() external view returns (int128); // ABDK 64x64
function targetSlippage() external view returns (int128); // ABDK 64x64
function swapFeePpm() external view returns (uint256);
function tokenAddressToIndexPlusOne(address) external view returns (uint);
// Initialization / Mint / Burn (LP token managed)
/// @notice Calculate the proportional deposit amounts required for a given LP token amount
/// @param lpTokenAmount The amount of LP tokens desired
/// @return depositAmounts Array of token amounts to deposit (rounded up)
function computeMintAmounts(uint256 lpTokenAmount) external view returns (uint256[] memory depositAmounts);
/// @notice Proportional mint (or initial supply if first call).
/// For initial supply: assumes tokens have already been transferred to the pool
/// For subsequent mints: payer must approve tokens beforehand, receiver gets the LP tokens
/// @param payer address that provides the input tokens (ignored for initial deposit)
/// @param receiver address that receives the LP tokens
/// @param lpTokenAmount desired amount of LP tokens to mint (ignored for initial deposit)
/// @param deadline timestamp after which the transaction will revert. Pass 0 to ignore.
function mint(address payer, address receiver, uint256 lpTokenAmount, uint256 deadline) external;
/// @notice Calculate the proportional withdrawal amounts for a given LP token amount
/// @param lpTokenAmount The amount of LP tokens to burn
/// @return withdrawAmounts Array of token amounts to withdraw (rounded down)
function computeBurnAmounts(uint256 lpTokenAmount) external view returns (uint256[] memory withdrawAmounts);
/// @notice Burn LP tokens and withdraw the proportional basket to receiver.
/// Payer must own the LP tokens; withdraw amounts are computed from current proportions.
/// @param payer address that provides the LP tokens to burn
/// @param receiver address that receives the withdrawn tokens
/// @param lpAmount amount of LP tokens to burn (proportional withdrawal)
/// @param deadline timestamp after which the transaction will revert. Pass 0 to ignore.
function burn(address payer, address receiver, uint256 lpAmount, uint256 deadline) external;
// Swaps
function swap(
address payer,
address receiver,
uint256 i,
uint256 j,
uint256 maxAmountIn,
int128 limitPrice,
uint256 deadline
) external returns (uint256 amountIn, uint256 amountOut);
function swapToLimit(
address payer,
address receiver,
uint256 i,
uint256 j,
int128 limitPrice,
uint256 deadline
) external returns (uint256 amountInUsed, uint256 amountOut);
/// @notice Single-token mint: deposit a single token, charge swap-LMSR cost, and mint LP.
/// @param payer who transfers the input token
/// @param receiver who receives the minted LP tokens
/// @param i index of the input token
/// @param maxAmountIn maximum uint token input (inclusive of fee)
/// @param deadline optional deadline
/// @return lpMinted actual LP minted (uint)
function swapMint(
address payer,
address receiver,
uint256 i,
uint256 maxAmountIn,
uint256 deadline
) external returns (uint256 lpMinted);
/// @notice Burn LP tokens then swap the redeemed proportional basket into a single asset `i` and send to receiver.
/// @param payer who burns LP tokens
/// @param receiver who receives the single asset
/// @param lpAmount amount of LP tokens to burn
/// @param i index of target asset to receive
/// @param deadline optional deadline
/// @return amountOutUint uint amount of asset i sent to receiver
function burnSwap(
address payer,
address receiver,
uint256 lpAmount,
uint256 i,
uint256 deadline
) external returns (uint256 amountOutUint);
/// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
/// @dev The caller of this method receives a callback in the form of IPartyFlashCallback#partyFlashCallback
/// @param recipient The address which will receive the token amounts
/// @param amounts The amount of each token to send
/// @param data Any data to be passed through to the callback
function flash(
address recipient,
uint256[] memory amounts,
bytes calldata data
) external;
}