ERC functionality split into internal/external

This commit is contained in:
tim
2025-10-03 12:48:45 -04:00
parent 269236cfba
commit 2e675bceb9
7 changed files with 343 additions and 43 deletions

View File

@@ -20,14 +20,12 @@ contract PartyPoolMintImpl is PartyPoolBase {
event Mint(address indexed payer, address indexed receiver, uint256[] depositAmounts, uint256 lpMinted);
event Burn(address indexed payer, address indexed receiver, uint256[] withdrawAmounts, uint256 lpBurned);
constructor() PartyPoolBase('','') {}
function initialMint(address receiver, uint256 lpTokens, int128 KAPPA) external
returns (uint256 lpMinted) {
uint256 n = tokens.length;
// Check if this is initial deposit - revert if not
bool isInitialDeposit = totalSupply() == 0 || lmsr.nAssets == 0;
bool isInitialDeposit = _totalSupply == 0 || lmsr.nAssets == 0;
require(isInitialDeposit, "initialMint: pool already initialized");
// Update cached balances for all assets
@@ -62,7 +60,7 @@ contract PartyPoolMintImpl is PartyPoolBase {
uint256 n = tokens.length;
// Check if this is NOT initial deposit - revert if it is
bool isInitialDeposit = totalSupply() == 0 || lmsr.nAssets == 0;
bool isInitialDeposit = _totalSupply == 0 || lmsr.nAssets == 0;
require(!isInitialDeposit, "mint: use initialMint for pool initialization");
require(lpTokenAmount > 0, "mint: zero LP amount");
@@ -71,7 +69,7 @@ contract PartyPoolMintImpl is PartyPoolBase {
uint256 oldScaled = ABDKMath64x64.mulu(oldTotal, LP_SCALE);
// Calculate required deposit amounts for the desired LP tokens
uint256[] memory depositAmounts = mintAmounts(lpTokenAmount, lmsr.nAssets, totalSupply(), cachedUintBalances);
uint256[] memory depositAmounts = mintAmounts(lpTokenAmount, lmsr.nAssets, _totalSupply, cachedUintBalances);
// Transfer in all token amounts
for (uint i = 0; i < n; ) {
@@ -104,7 +102,7 @@ contract PartyPoolMintImpl is PartyPoolBase {
// Proportional issuance: totalSupply * delta / oldScaled
if (delta > 0) {
// floor truncation rounds in favor of the pool
actualLpToMint = (totalSupply() * delta) / oldScaled;
actualLpToMint = (_totalSupply * delta) / oldScaled;
} else {
actualLpToMint = 0;
}
@@ -135,10 +133,10 @@ contract PartyPoolMintImpl is PartyPoolBase {
uint256 n = tokens.length;
require(lpAmount > 0, "burn: zero lp");
uint256 supply = totalSupply();
uint256 supply = _totalSupply;
require(supply > 0, "burn: empty supply");
require(lmsr.nAssets > 0, "burn: uninit pool");
require(balanceOf(payer) >= lpAmount, "burn: insufficient LP");
require(_balances[payer] >= lpAmount, "burn: insufficient LP");
// Refresh cached balances to reflect current on-chain balances before computing withdrawal amounts
for (uint i = 0; i < n; ) {
@@ -148,7 +146,7 @@ contract PartyPoolMintImpl is PartyPoolBase {
}
// Compute proportional withdrawal amounts for the requested LP amount (rounded down)
withdrawAmounts = burnAmounts(lpAmount, lmsr.nAssets, totalSupply(), cachedUintBalances);
withdrawAmounts = burnAmounts(lpAmount, lmsr.nAssets, _totalSupply, cachedUintBalances);
// Transfer underlying tokens out to receiver according to computed proportions
for (uint i = 0; i < n; ) {
@@ -185,7 +183,7 @@ contract PartyPoolMintImpl is PartyPoolBase {
// Burn exactly the requested LP amount from payer (authorization via allowance)
if (msg.sender != payer) {
uint256 allowed = allowance(payer, msg.sender);
uint256 allowed = _allowances[payer][msg.sender];
require(allowed >= lpAmount, "burn: allowance insufficient");
_approve(payer, msg.sender, allowed - lpAmount);
}