computed bases

This commit is contained in:
tim
2025-10-25 18:18:18 -04:00
parent 2972152e58
commit ba08da2fca
14 changed files with 93 additions and 98 deletions

View File

@@ -33,30 +33,38 @@ contract PartyPoolMintImpl is PartyPoolBase {
bool isInitialDeposit = _totalSupply == 0 || _lmsr.nAssets == 0;
require(isInitialDeposit, "initialMint: pool already initialized");
// Update cached balances for all assets
// Read initial on-chain balances, require all > 0, and compute denominators (bases) from deposits.
// We assume equal-valued deposits; set base[i] = depositAmount so internal q_i starts at 1.0.
int128[] memory newQInternal = new int128[](n);
uint256[] memory depositAmounts = new uint256[](n);
for (uint i = 0; i < n; ) {
uint256 bal = IERC20(_tokens[i]).balanceOf(address(this));
_cachedUintBalances[i] = bal;
newQInternal[i] = _uintToInternalFloor(bal, _bases[i]);
require(bal > 0, "initialMint: zero initial balance");
depositAmounts[i] = bal;
// Cache external balances
_cachedUintBalances[i] = bal;
// Set per-asset denominator to the observed deposit amount (at least 1)
_bases[i] = bal;
// Compute internal q_i = bal / base_i => ~1.0 in 64.64
newQInternal[i] = _uintToInternalFloor(bal, _bases[i]);
require(newQInternal[i] > int128(0), "initialMint: zero internal q");
unchecked { i++; }
}
// Initialize the stabilized LMSR state with provided kappa
_lmsr.init(newQInternal, KAPPA);
// Compute actual LP _tokens to mint based on size metric (scaled)
if( lpTokens != 0 )
lpMinted = lpTokens;
else {
int128 newTotal = _computeSizeMetric(newQInternal);
lpMinted = ABDKMath64x64.mulu(newTotal, LP_SCALE);
}
// Obey the passed-in initial LP amount. If 0, default to 1e18
lpMinted = lpTokens == 0 ? 1e18 : lpTokens;
require(lpMinted > 0, "initialMint: zero LP amount");
_mint(receiver, lpMinted);
if (lpMinted > 0) {
_mint(receiver, lpMinted);
}
emit IPartyPool.Mint(address(0), receiver, depositAmounts, lpMinted);
}