pure kappa formulation: target slippage extracted into pool creator code
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
pragma solidity ^0.8.30;
|
||||
|
||||
import "forge-std/Test.sol";
|
||||
import "../src/LMSRStabilized.sol";
|
||||
import "../src/PartyPlanner.sol";
|
||||
import "../src/PartyPool.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
@@ -83,14 +84,15 @@ contract PartyPlannerTest is Test {
|
||||
uint256 initialTokenACount = planner.poolsByTokenCount(IERC20(address(tokenA)));
|
||||
uint256 initialTokenBCount = planner.poolsByTokenCount(IERC20(address(tokenB)));
|
||||
|
||||
// Create pool
|
||||
// Compute kappa then create pool via kappa overload
|
||||
int128 computedKappa = LMSRStabilized.computeKappaFromSlippage(tokens.length, tradeFrac, targetSlippage);
|
||||
|
||||
(PartyPool pool, uint256 lpAmount) = planner.createPool(
|
||||
name,
|
||||
symbol,
|
||||
tokens,
|
||||
bases,
|
||||
tradeFrac,
|
||||
targetSlippage,
|
||||
computedKappa,
|
||||
swapFeePpm,
|
||||
flashFeePpm,
|
||||
false, // not stable
|
||||
@@ -163,9 +165,10 @@ contract PartyPlannerTest is Test {
|
||||
deposits1[0] = INITIAL_DEPOSIT_AMOUNT;
|
||||
deposits1[1] = INITIAL_DEPOSIT_AMOUNT;
|
||||
|
||||
int128 kappa1 = LMSRStabilized.computeKappaFromSlippage(tokens1.length, int128((1 << 64) - 1), int128(1 << 62));
|
||||
(PartyPool pool1,) = planner.createPool(
|
||||
"Pool 1", "LP1", tokens1, bases1,
|
||||
int128((1 << 64) - 1), int128(1 << 62), 3000, 5000, false,
|
||||
kappa1, 3000, 5000, false,
|
||||
payer, receiver, deposits1, 1000e18, 0
|
||||
);
|
||||
|
||||
@@ -182,9 +185,10 @@ contract PartyPlannerTest is Test {
|
||||
deposits2[0] = INITIAL_DEPOSIT_AMOUNT;
|
||||
deposits2[1] = INITIAL_DEPOSIT_AMOUNT / 1e12; // Adjust for 6 decimals
|
||||
|
||||
int128 kappa2 = LMSRStabilized.computeKappaFromSlippage(tokens2.length, int128((1 << 64) - 1), int128(1 << 62));
|
||||
(PartyPool pool2,) = planner.createPool(
|
||||
"Pool 2", "LP2", tokens2, bases2,
|
||||
int128((1 << 64) - 1), int128(1 << 62), 3000, 5000, false,
|
||||
kappa2, 3000, 5000, false,
|
||||
payer, receiver, deposits2, 1000e18, 0
|
||||
);
|
||||
|
||||
@@ -225,6 +229,7 @@ contract PartyPlannerTest is Test {
|
||||
|
||||
// Test token/deposit length mismatch
|
||||
vm.expectRevert("Planner: tokens and deposits length mismatch");
|
||||
// call old-signature convenience (it will still exist) for the mismatched-length revert check
|
||||
planner.createPool(
|
||||
"Test Pool", "TESTLP", tokens, bases,
|
||||
int128((1 << 64) - 1), int128(1 << 62), 3000, 5000, false,
|
||||
@@ -236,10 +241,12 @@ contract PartyPlannerTest is Test {
|
||||
validDeposits[0] = INITIAL_DEPOSIT_AMOUNT;
|
||||
validDeposits[1] = INITIAL_DEPOSIT_AMOUNT;
|
||||
|
||||
int128 kappaErr = LMSRStabilized.computeKappaFromSlippage(tokens.length, int128((1 << 64) - 1), int128(1 << 62));
|
||||
|
||||
vm.expectRevert("Planner: payer cannot be zero address");
|
||||
planner.createPool(
|
||||
"Test Pool", "TESTLP", tokens, bases,
|
||||
int128((1 << 64) - 1), int128(1 << 62), 3000, 5000, false,
|
||||
kappaErr, 3000, 5000, false,
|
||||
address(0), receiver, validDeposits, 1000e18, 0
|
||||
);
|
||||
|
||||
@@ -247,17 +254,18 @@ contract PartyPlannerTest is Test {
|
||||
vm.expectRevert("Planner: receiver cannot be zero address");
|
||||
planner.createPool(
|
||||
"Test Pool", "TESTLP", tokens, bases,
|
||||
int128((1 << 64) - 1), int128(1 << 62), 3000, 5000, false,
|
||||
kappaErr, 3000, 5000, false,
|
||||
payer, address(0), validDeposits, 1000e18, 0
|
||||
);
|
||||
|
||||
// Test deadline exceeded
|
||||
// The default timestamp is 1 and 1-0 is 0 which means "ignore deadline," so we need to set a proper timestamp.
|
||||
int128 kappaDeadline = LMSRStabilized.computeKappaFromSlippage(tokens.length, int128((1 << 64) - 1), int128(1 << 62));
|
||||
vm.warp(1000);
|
||||
vm.expectRevert("Planner: deadline exceeded");
|
||||
planner.createPool(
|
||||
"Test Pool", "TESTLP", tokens, bases,
|
||||
int128((1 << 64) - 1), int128(1 << 62), 3000, 5000, false,
|
||||
kappaDeadline, 3000, 5000, false,
|
||||
payer, receiver, validDeposits, 1000e18, block.timestamp - 1
|
||||
);
|
||||
}
|
||||
@@ -280,11 +288,12 @@ contract PartyPlannerTest is Test {
|
||||
deposits[0] = INITIAL_DEPOSIT_AMOUNT;
|
||||
deposits[1] = INITIAL_DEPOSIT_AMOUNT;
|
||||
|
||||
int128 kappaLoop = LMSRStabilized.computeKappaFromSlippage(tokens.length, int128((1 << 64) - 1), int128(1 << 62));
|
||||
(PartyPool pool,) = planner.createPool(
|
||||
string(abi.encodePacked("Pool ", vm.toString(i))),
|
||||
string(abi.encodePacked("LP", vm.toString(i))),
|
||||
tokens, bases,
|
||||
int128((1 << 64) - 1), int128(1 << 62), 3000, 5000, false,
|
||||
kappaLoop, 3000, 5000, false,
|
||||
payer, receiver, deposits, 1000e18, 0
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user