proxied swapToLimit
This commit is contained in:
@@ -1,12 +1,20 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.30;
|
||||
|
||||
import "forge-std/Test.sol";
|
||||
import "../src/LMSRStabilized.sol";
|
||||
import "../src/PartyPlanner.sol";
|
||||
import "../src/PartyPool.sol";
|
||||
import {CommonBase} from "../lib/forge-std/src/Base.sol";
|
||||
import {StdAssertions} from "../lib/forge-std/src/StdAssertions.sol";
|
||||
import {StdChains} from "../lib/forge-std/src/StdChains.sol";
|
||||
import {StdCheats, StdCheatsSafe} from "../lib/forge-std/src/StdCheats.sol";
|
||||
import {StdUtils} from "../lib/forge-std/src/StdUtils.sol";
|
||||
import {Test} from "../lib/forge-std/src/Test.sol";
|
||||
import {ERC20} from "../lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
|
||||
import {IERC20} from "../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
|
||||
import {Deploy} from "../src/Deploy.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
import {IPartyPool} from "../src/IPartyPool.sol";
|
||||
import {LMSRStabilized} from "../src/LMSRStabilized.sol";
|
||||
import {PartyPlanner} from "../src/PartyPlanner.sol";
|
||||
import {PartyPool} from "../src/PartyPool.sol";
|
||||
import {MockERC20} from "./PartyPlanner.t.sol";
|
||||
|
||||
// Mock ERC20 token for testing
|
||||
contract MockERC20 is ERC20 {
|
||||
@@ -88,7 +96,7 @@ contract PartyPlannerTest is Test {
|
||||
// Compute kappa then create pool via kappa overload
|
||||
int128 computedKappa = LMSRStabilized.computeKappaFromSlippage(tokens.length, tradeFrac, targetSlippage);
|
||||
|
||||
(PartyPool pool, uint256 lpAmount) = planner.newPool(
|
||||
(IPartyPool pool, uint256 lpAmount) = planner.newPool(
|
||||
name,
|
||||
symbol,
|
||||
tokens,
|
||||
@@ -117,7 +125,7 @@ contract PartyPlannerTest is Test {
|
||||
assertEq(planner.poolsByTokenCount(IERC20(address(tokenB))), initialTokenBCount + 1, "TokenB pool count should increase");
|
||||
|
||||
// Verify pools can be retrieved
|
||||
PartyPool[] memory allPools = planner.getAllPools(0, 10);
|
||||
IPartyPool[] memory allPools = planner.getAllPools(0, 10);
|
||||
bool poolFound = false;
|
||||
for (uint256 i = 0; i < allPools.length; i++) {
|
||||
if (allPools[i] == pool) {
|
||||
@@ -128,7 +136,7 @@ contract PartyPlannerTest is Test {
|
||||
assertTrue(poolFound, "Created pool should be in getAllPools result");
|
||||
|
||||
// Verify pool appears in token-specific queries
|
||||
PartyPool[] memory tokenAPools = planner.getPoolsByToken(IERC20(address(tokenA)), 0, 10);
|
||||
IPartyPool[] memory tokenAPools = planner.getPoolsByToken(IERC20(address(tokenA)), 0, 10);
|
||||
bool poolInTokenA = false;
|
||||
for (uint256 i = 0; i < tokenAPools.length; i++) {
|
||||
if (tokenAPools[i] == pool) {
|
||||
@@ -138,7 +146,7 @@ contract PartyPlannerTest is Test {
|
||||
}
|
||||
assertTrue(poolInTokenA, "Pool should be indexed under tokenA");
|
||||
|
||||
PartyPool[] memory tokenBPools = planner.getPoolsByToken(IERC20(address(tokenB)), 0, 10);
|
||||
IPartyPool[] memory tokenBPools = planner.getPoolsByToken(IERC20(address(tokenB)), 0, 10);
|
||||
bool poolInTokenB = false;
|
||||
for (uint256 i = 0; i < tokenBPools.length; i++) {
|
||||
if (tokenBPools[i] == pool) {
|
||||
@@ -167,7 +175,7 @@ contract PartyPlannerTest is Test {
|
||||
deposits1[1] = INITIAL_DEPOSIT_AMOUNT;
|
||||
|
||||
int128 kappa1 = LMSRStabilized.computeKappaFromSlippage(tokens1.length, int128((1 << 64) - 1), int128(1 << 62));
|
||||
(PartyPool pool1,) = planner.newPool(
|
||||
(IPartyPool pool1,) = planner.newPool(
|
||||
"Pool 1", "LP1", tokens1, bases1,
|
||||
kappa1, 3000, 5000, false,
|
||||
payer, receiver, deposits1, 1000e18, 0
|
||||
@@ -187,7 +195,7 @@ contract PartyPlannerTest is Test {
|
||||
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.newPool(
|
||||
(IPartyPool pool2,) = planner.newPool(
|
||||
"Pool 2", "LP2", tokens2, bases2,
|
||||
kappa2, 3000, 5000, false,
|
||||
payer, receiver, deposits2, 1000e18, 0
|
||||
@@ -203,7 +211,7 @@ contract PartyPlannerTest is Test {
|
||||
assertEq(planner.poolsByTokenCount(IERC20(address(tokenC))), 1, "TokenC should be in 1 pool");
|
||||
|
||||
// Verify tokenB appears in both pools
|
||||
PartyPool[] memory tokenBPools = planner.getPoolsByToken(IERC20(address(tokenB)), 0, 10);
|
||||
IPartyPool[] memory tokenBPools = planner.getPoolsByToken(IERC20(address(tokenB)), 0, 10);
|
||||
assertEq(tokenBPools.length, 2, "TokenB should have 2 pools");
|
||||
|
||||
bool pool1Found = false;
|
||||
@@ -274,7 +282,7 @@ contract PartyPlannerTest is Test {
|
||||
function test_poolIndexing_Pagination() public {
|
||||
// Create multiple pools for pagination testing
|
||||
uint256 numPools = 5;
|
||||
PartyPool[] memory createdPools = new PartyPool[](numPools);
|
||||
IPartyPool[] memory createdPools = new IPartyPool[](numPools);
|
||||
|
||||
for (uint256 i = 0; i < numPools; i++) {
|
||||
IERC20[] memory tokens = new IERC20[](2);
|
||||
@@ -290,7 +298,7 @@ contract PartyPlannerTest is Test {
|
||||
deposits[1] = INITIAL_DEPOSIT_AMOUNT;
|
||||
|
||||
int128 kappaLoop = LMSRStabilized.computeKappaFromSlippage(tokens.length, int128((1 << 64) - 1), int128(1 << 62));
|
||||
(PartyPool pool,) = planner.newPool(
|
||||
(IPartyPool pool,) = planner.newPool(
|
||||
string(abi.encodePacked("Pool ", vm.toString(i))),
|
||||
string(abi.encodePacked("LP", vm.toString(i))),
|
||||
tokens, bases,
|
||||
@@ -304,19 +312,19 @@ contract PartyPlannerTest is Test {
|
||||
assertEq(planner.poolCount(), numPools, "Should have created all pools");
|
||||
|
||||
// Test pagination - get first 3 pools
|
||||
PartyPool[] memory page1 = planner.getAllPools(0, 3);
|
||||
IPartyPool[] memory page1 = planner.getAllPools(0, 3);
|
||||
assertEq(page1.length, 3, "First page should have 3 pools");
|
||||
|
||||
// Test pagination - get next 2 pools
|
||||
PartyPool[] memory page2 = planner.getAllPools(3, 3);
|
||||
IPartyPool[] memory page2 = planner.getAllPools(3, 3);
|
||||
assertEq(page2.length, 2, "Second page should have 2 pools");
|
||||
|
||||
// Test pagination - offset beyond bounds
|
||||
PartyPool[] memory emptyPage = planner.getAllPools(10, 3);
|
||||
IPartyPool[] memory emptyPage = planner.getAllPools(10, 3);
|
||||
assertEq(emptyPage.length, 0, "Should return empty array for out of bounds offset");
|
||||
|
||||
// Verify all pools are accessible through pagination
|
||||
PartyPool[] memory allPools = planner.getAllPools(0, 10);
|
||||
IPartyPool[] memory allPools = planner.getAllPools(0, 10);
|
||||
assertEq(allPools.length, numPools, "Should return all pools");
|
||||
|
||||
for (uint256 i = 0; i < numPools; i++) {
|
||||
|
||||
Reference in New Issue
Block a user