price() view bugfix

This commit is contained in:
tim
2025-11-25 13:26:24 -04:00
parent 0422031c5c
commit 64e73e5570
4 changed files with 108 additions and 3 deletions

View File

@@ -87,6 +87,73 @@ library Deploy {
return newPartyPool2(NPPArgs(name_, symbol_, tokens_, _kappa, _swapFeePpm, _flashFeePpm, wrapper, _stable, _initialBalance, _lpTokens));
}
/// @notice Deploy a pool using explicit per-token initial deposits (useful for non-uniform initial balances)
function newPartyPoolWithDeposits(
string memory name_,
string memory symbol_,
IERC20[] memory tokens_,
int128 _kappa,
uint256 _swapFeePpm,
uint256 _flashFeePpm,
bool _stable,
uint256[] memory initialDeposits,
uint256 _lpTokens
) internal returns (IPartyPool pool, uint256 lpTokens) {
require(initialDeposits.length == tokens_.length, "mismatched deposits length");
NativeWrapper wrapper = new WETH9();
// Prepare planner and arrays
NPPVars memory v = NPPVars(
address(newPartyPlanner(address(this), wrapper)),
new uint256[](tokens_.length),
new uint256[](tokens_.length)
);
address self = address(this);
// Build per-asset fee vector from scalar for tests
for (uint256 i = 0; i < tokens_.length; i++) { v.feesArr[i] = _swapFeePpm; }
// Mint/prepare the specified deposits for each token and approve the planner
for (uint256 i = 0; i < tokens_.length; i++) {
v.deposits[i] = initialDeposits[i];
if (address(tokens_[i]) == address(wrapper)) {
// Wrap native value and approve planner
if (initialDeposits[i] > 0) {
argsWrapperDeposit(wrapper, v.planner, initialDeposits[i]);
}
} else {
MockERC20 t = MockERC20(address(tokens_[i]));
if (initialDeposits[i] > 0) {
t.mint(self, initialDeposits[i]);
t.approve(v.planner, initialDeposits[i]);
}
}
}
// Create pool with provided deposits
(pool, lpTokens) = IPartyPlanner(v.planner).newPool(
name_,
symbol_,
tokens_,
_kappa,
_swapFeePpm,
_flashFeePpm,
_stable,
self,
self,
v.deposits,
_lpTokens,
0
);
}
// Helper to deposit native wrapper value and approve planner (kept separate for clarity)
function argsWrapperDeposit(NativeWrapper wrapper, address planner, uint256 amount) internal {
if (amount == 0) return;
wrapper.deposit{value: amount}();
wrapper.approve(planner, amount);
}
struct NPPVars {
address planner;
uint256[] feesArr;