prefunding

This commit is contained in:
tim
2025-11-11 18:33:14 -04:00
parent ddfe7651ea
commit 70960630ce
8 changed files with 722 additions and 69 deletions

View File

@@ -2,15 +2,21 @@
/* solhint-disable */
pragma solidity ^0.8.30;
import "forge-std/Test.sol";
import "@abdk/ABDKMath64x64.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "../src/LMSRStabilized.sol";
import "../src/PartyPool.sol";
import {NativeWrapper} from "../src/NativeWrapper.sol";
import {PartyPlanner} from "../src/PartyPlanner.sol";
import {Deploy} from "./Deploy.sol";
import {ABDKMath64x64} from "../lib/abdk-libraries-solidity/ABDKMath64x64.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 {Funding} from "../src/Funding.sol";
import {LMSRStabilized} from "../src/LMSRStabilized.sol";
import {PartyInfo} from "../src/PartyInfo.sol";
import {PartyPool} from "../src/PartyPool.sol";
import {Deploy} from "./Deploy.sol";
import {TestERC20Native} from "./NativeTest.t.sol";
import {WETH9} from "./WETH9.sol";
/// @notice Minimal ERC20 token for tests with an external mint function.
@@ -142,7 +148,7 @@ contract NativeTest is Test {
// Send native currency with {value: maxIn}
(uint256 amountIn, uint256 amountOut, ) = pool.swap{value: maxIn}(
alice, // payer
bytes4(0),
Funding.USE_APPROVALS,
alice, // receiver
2, // inputTokenIndex (WETH)
0, // outputTokenIndex (token0)
@@ -180,7 +186,7 @@ contract NativeTest is Test {
// Execute swap: token0 (index 0) -> WETH (index 2) with unwrap=true
(uint256 amountIn, uint256 amountOut, ) = pool.swap(
alice, // payer
bytes4(0), // no selector: use ERC20 approvals
Funding.USE_APPROVALS, // no selector: use ERC20 approvals
alice, // receiver
0, // inputTokenIndex (token0)
2, // outputTokenIndex (WETH)
@@ -216,7 +222,7 @@ contract NativeTest is Test {
// Execute swap with excess native currency
(uint256 amountIn, , ) = pool.swap{value: totalSent}(
alice, // payer
bytes4(0),
Funding.USE_APPROVALS,
alice, // receiver
2, // inputTokenIndex (WETH)
0, // outputTokenIndex (token0)
@@ -545,14 +551,14 @@ contract NativeTest is Test {
// 2. Swap native currency for token0
uint256 swapAmount = 5_000;
(, uint256 amountOut, ) = pool.swap{value: swapAmount}(
alice,bytes4(0),alice, 2, 0, swapAmount, 0, 0, false
alice,Funding.USE_APPROVALS,alice, 2, 0, swapAmount, 0, 0, false
);
assertTrue(amountOut > 0, "Should receive token0");
// 3. Swap token0 back to native currency
uint256 token0Balance = token0.balanceOf(alice);
(, uint256 swapOut2, ) = pool.swap(
alice, bytes4(0), alice, 0, 2, token0Balance / 2, 0, 0, true
alice, Funding.USE_APPROVALS, alice, 0, 2, token0Balance / 2, 0, 0, true
);
assertTrue(swapOut2 > 0, "Should receive native currency");
@@ -579,7 +585,7 @@ contract NativeTest is Test {
// Swap token0 -> WETH without unwrap
(, uint256 amountOut, ) = pool.swap(
alice, bytes4(0), alice, 0, 2, maxIn, 0, 0, false // unwrap=false
alice, Funding.USE_APPROVALS, alice, 0, 2, maxIn, 0, 0, false // unwrap=false
);
assertTrue(amountOut > 0, "Should receive WETH tokens");
@@ -600,7 +606,7 @@ contract NativeTest is Test {
// Try to swap token0 (not WETH) by sending native currency - should revert
vm.expectRevert();
pool.swap{value: 10_000}(
alice, bytes4(0), alice, 0, 1, 10_000, 0, 0, false
alice, Funding.USE_APPROVALS, alice, 0, 1, 10_000, 0, 0, false
);
vm.stopPrank();