price() view bugfix
This commit is contained in:
@@ -1107,5 +1107,43 @@ contract PartyPoolTest is Test {
|
||||
assertEq(uint256(uint128(priceAfter)), uint256(uint128(expected)), "Pool price should remain 1.0000000 after mint");
|
||||
}
|
||||
|
||||
/// @notice Create a 3-token pool where token0 has 3x the balance of token1 and verify
|
||||
/// that the relative price token1/token0 equals 3 (in ABDK 64.64 fixed point).
|
||||
function testPriceWhenToken0HasThreeTimesToken1() public {
|
||||
// Build tokens array (reuse test tokens)
|
||||
IERC20[] memory tokens = new IERC20[](3);
|
||||
tokens[0] = IERC20(address(token0));
|
||||
tokens[1] = IERC20(address(token1));
|
||||
tokens[2] = IERC20(address(token2));
|
||||
|
||||
uint256 feePpm = 1000;
|
||||
// Compute kappa using existing tradeFrac/targetSlippage setup
|
||||
int128 kappa = LMSRStabilized.computeKappaFromSlippage(tokens.length, tradeFrac, targetSlippage);
|
||||
|
||||
// Prepare explicit per-token initial deposits so token0 starts at 3x token1
|
||||
uint256[] memory deposits = new uint256[](3);
|
||||
deposits[0] = INIT_BAL * 3; // token0 = 3 * INIT_BAL
|
||||
deposits[1] = INIT_BAL; // token1 = INIT_BAL
|
||||
deposits[2] = INIT_BAL; // token2 = INIT_BAL
|
||||
|
||||
// Deploy a fresh pool with the specified deposits (no subsequent minting required)
|
||||
(IPartyPool poolCustom, ) = Deploy.newPartyPoolWithDeposits("LP3X", "LP3X", tokens, kappa, feePpm, feePpm, false, deposits, 0);
|
||||
|
||||
// Sanity-check balances
|
||||
uint256 b0 = token0.balanceOf(address(poolCustom));
|
||||
uint256 b1 = token1.balanceOf(address(poolCustom));
|
||||
assertEq(b0, INIT_BAL * 3, "token0 balance should be 3x INIT_BAL");
|
||||
assertEq(b1, INIT_BAL, "token1 balance should be INIT_BAL");
|
||||
|
||||
// Query the price of token1 in terms of token0 (token1/token0)
|
||||
int128 price = info.price(poolCustom, 1, 0);
|
||||
|
||||
// Expected price is 3.0 in ABDK 64.64 fixed point
|
||||
int128 expected = ABDKMath64x64.fromInt(3);
|
||||
|
||||
// Compare as uint representation (values are non-negative)
|
||||
assertEq(uint256(uint128(price)), uint256(uint128(expected)), "Price token1/token0 should be 3.0000000");
|
||||
}
|
||||
|
||||
}
|
||||
/* solhint-enable */
|
||||
|
||||
Reference in New Issue
Block a user