CREATE2 callback validation; init code storage contracts
This commit is contained in:
@@ -12,9 +12,9 @@ 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 {IPartyInfo} from "../src/IPartyInfo.sol";
|
||||
import {IPartyPool} from "../src/IPartyPool.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";
|
||||
@@ -46,8 +46,8 @@ contract NativeTest is Test {
|
||||
TestERC20Native token0;
|
||||
TestERC20Native token1;
|
||||
WETH9 weth; // WETH is our third token
|
||||
PartyPool pool;
|
||||
PartyInfo info;
|
||||
IPartyPool pool;
|
||||
IPartyInfo info;
|
||||
|
||||
address alice;
|
||||
address bob;
|
||||
@@ -78,9 +78,6 @@ contract NativeTest is Test {
|
||||
token0.mint(address(this), INIT_BAL);
|
||||
token1.mint(address(this), INIT_BAL);
|
||||
|
||||
// For WETH, we deposit native currency to get wrapped _tokens
|
||||
weth.deposit{value: INIT_BAL}();
|
||||
|
||||
// Configure LMSR parameters
|
||||
tradeFrac = ABDKMath64x64.divu(100, 10_000); // 0.01
|
||||
targetSlippage = ABDKMath64x64.divu(10, 10_000); // 0.001
|
||||
@@ -100,15 +97,7 @@ contract NativeTest is Test {
|
||||
uint256 feePpm = 1000;
|
||||
|
||||
int128 kappa = LMSRStabilized.computeKappaFromSlippage(tokens.length, tradeFrac, targetSlippage);
|
||||
pool = Deploy.newPartyPool(address(this), "LP", "LP", tokens, kappa, feePpm, feePpm, weth, false);
|
||||
|
||||
// Transfer initial deposit amounts into pool
|
||||
token0.transfer(address(pool), INIT_BAL);
|
||||
token1.transfer(address(pool), INIT_BAL);
|
||||
weth.transfer(address(pool), INIT_BAL);
|
||||
|
||||
// Perform initial mint
|
||||
pool.initialMint(address(this), 0);
|
||||
pool = Deploy.newPartyPool("LP", "LP", tokens, kappa, feePpm, feePpm, weth, false, INIT_BAL, 0);
|
||||
|
||||
// Mint _tokens to alice and bob for testing
|
||||
token0.mint(alice, INIT_BAL);
|
||||
@@ -148,14 +137,15 @@ contract NativeTest is Test {
|
||||
// Send native currency with {value: maxIn}
|
||||
(uint256 amountIn, uint256 amountOut, ) = pool.swap{value: maxIn}(
|
||||
alice, // payer
|
||||
Funding.APPROVALS,
|
||||
Funding.APPROVAL,
|
||||
alice, // receiver
|
||||
2, // inputTokenIndex (WETH)
|
||||
0, // outputTokenIndex (token0)
|
||||
maxIn, // maxAmountIn
|
||||
0, // limitPrice
|
||||
0, // deadline
|
||||
false // unwrap (output is not WETH, so false)
|
||||
false, // unwrap (output is not WETH, so false)
|
||||
''
|
||||
);
|
||||
|
||||
// Verify amounts
|
||||
@@ -186,14 +176,15 @@ contract NativeTest is Test {
|
||||
// Execute swap: token0 (index 0) -> WETH (index 2) with unwrap=true
|
||||
(uint256 amountIn, uint256 amountOut, ) = pool.swap(
|
||||
alice, // payer
|
||||
Funding.APPROVALS, // no selector: use ERC20 approvals
|
||||
Funding.APPROVAL, // no selector: use ERC20 approvals
|
||||
alice, // receiver
|
||||
0, // inputTokenIndex (token0)
|
||||
2, // outputTokenIndex (WETH)
|
||||
maxIn, // maxAmountIn
|
||||
0, // limitPrice
|
||||
0, // deadline
|
||||
true // unwrap (receive native currency instead of WETH)
|
||||
true, // unwrap (receive native currency instead of WETH)
|
||||
''
|
||||
);
|
||||
|
||||
// Verify amounts
|
||||
@@ -222,14 +213,15 @@ contract NativeTest is Test {
|
||||
// Execute swap with excess native currency
|
||||
(uint256 amountIn, , ) = pool.swap{value: totalSent}(
|
||||
alice, // payer
|
||||
Funding.APPROVALS,
|
||||
Funding.APPROVAL,
|
||||
alice, // receiver
|
||||
2, // inputTokenIndex (WETH)
|
||||
0, // outputTokenIndex (token0)
|
||||
maxIn, // maxAmountIn
|
||||
0, // limitPrice
|
||||
0, // deadline
|
||||
false // unwrap
|
||||
false, // unwrap
|
||||
''
|
||||
);
|
||||
|
||||
// Verify that only amountIn was used, and excess was refunded
|
||||
@@ -253,12 +245,14 @@ contract NativeTest is Test {
|
||||
uint256 largeAmount = 100_000;
|
||||
(uint256 amountInUsed, uint256 amountOut, uint256 fee) = pool.swapToLimit{value: largeAmount}(
|
||||
alice, // payer
|
||||
Funding.APPROVAL,
|
||||
alice, // receiver
|
||||
2, // inputTokenIndex (WETH)
|
||||
0, // outputTokenIndex (token0)
|
||||
limitPrice, // limitPrice
|
||||
0, // deadline
|
||||
false // unwrap
|
||||
false, // unwrap
|
||||
''
|
||||
);
|
||||
|
||||
assertTrue(amountInUsed > 0, "expected some input used for swapToLimit");
|
||||
@@ -283,12 +277,14 @@ contract NativeTest is Test {
|
||||
// Execute swapToLimit: token0 (index 0) -> WETH (index 2) with unwrap=true
|
||||
(uint256 amountInUsed, uint256 amountOut, /*uint256 fee*/) = pool.swapToLimit(
|
||||
alice, // payer
|
||||
Funding.APPROVAL,
|
||||
alice, // receiver
|
||||
0, // inputTokenIndex (token0)
|
||||
2, // outputTokenIndex (WETH)
|
||||
limitPrice, // limitPrice
|
||||
0, // deadline
|
||||
true // unwrap (receive native currency)
|
||||
true, // unwrap (receive native currency)
|
||||
''
|
||||
);
|
||||
|
||||
assertTrue(amountInUsed > 0, "expected some input used");
|
||||
@@ -551,14 +547,14 @@ contract NativeTest is Test {
|
||||
// 2. Swap native currency for token0
|
||||
uint256 swapAmount = 5_000;
|
||||
(, uint256 amountOut, ) = pool.swap{value: swapAmount}(
|
||||
alice,Funding.APPROVALS,alice, 2, 0, swapAmount, 0, 0, false
|
||||
alice,Funding.APPROVAL,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, Funding.APPROVALS, alice, 0, 2, token0Balance / 2, 0, 0, true
|
||||
alice, Funding.APPROVAL, alice, 0, 2, token0Balance / 2, 0, 0, true, ''
|
||||
);
|
||||
assertTrue(swapOut2 > 0, "Should receive native currency");
|
||||
|
||||
@@ -585,7 +581,7 @@ contract NativeTest is Test {
|
||||
|
||||
// Swap token0 -> WETH without unwrap
|
||||
(, uint256 amountOut, ) = pool.swap(
|
||||
alice, Funding.APPROVALS, alice, 0, 2, maxIn, 0, 0, false // unwrap=false
|
||||
alice, Funding.APPROVAL, alice, 0, 2, maxIn, 0, 0, false, ''
|
||||
);
|
||||
|
||||
assertTrue(amountOut > 0, "Should receive WETH tokens");
|
||||
@@ -606,7 +602,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, Funding.APPROVALS, alice, 0, 1, 10_000, 0, 0, false
|
||||
alice, Funding.APPROVAL, alice, 0, 1, 10_000, 0, 0, false, ''
|
||||
);
|
||||
|
||||
vm.stopPrank();
|
||||
|
||||
Reference in New Issue
Block a user