dropped USE_ from Funding constants

This commit is contained in:
tim
2025-11-12 14:19:04 -04:00
parent d8f7bef4ac
commit c2ac0e3624
6 changed files with 29 additions and 29 deletions

View File

@@ -4,8 +4,8 @@ pragma solidity ^0.8.30;
library Funding {
/// @notice a constant passed to swap as the fundingSelector to indicate that the payer has used regular ERC20 approvals to allow the pool to move the necessary input tokens.
bytes4 internal constant USE_APPROVALS = 0x00000000;
bytes4 internal constant APPROVALS = 0x00000000;
/// @notice a constant passed to swap as the fundingSelector to indicate that the payer has already sent sufficient input tokens to the pool before calling swap, so no movement of input tokens is required.
bytes4 internal constant USE_PREFUNDING = 0x00000001;
bytes4 internal constant PREFUNDING = 0x00000001;
}

View File

@@ -264,10 +264,10 @@ contract PartyPool is PartyPoolBase, OwnableExternal, ERC20External, IPartyPool
IERC20 tokenIn = _tokens[inputTokenIndex];
IERC20 tokenOut = _tokens[outputTokenIndex];
if (fundingSelector == Funding.USE_APPROVALS)
if (fundingSelector == Funding.APPROVALS)
// Regular ERC20 permit of the pool to move the tokens
_receiveTokenFrom(payer, tokenIn, totalTransferAmount);
else if (fundingSelector == Funding.USE_PREFUNDING) {
else if (fundingSelector == Funding.PREFUNDING) {
require(limitPrice==0, 'Prefunding cannot be used with a limit price');
uint256 balance = tokenIn.balanceOf(address(this));
uint256 prevBalance = _cachedUintBalances[inputTokenIndex] + _protocolFeesOwed[inputTokenIndex];

View File

@@ -177,7 +177,7 @@ contract FundingTest is Test {
// Execute swap using Funding.USE_PREFUNDING for pre-funded: token0 -> token1
(uint256 amountIn, uint256 amountOut, uint256 fee) = pool.swap(
alice, // payer (not used with pre-funded)
Funding.USE_PREFUNDING,
Funding.PREFUNDING,
bob, // receiver
0, // inputTokenIndex (token0)
1, // outputTokenIndex (token1)
@@ -227,7 +227,7 @@ contract FundingTest is Test {
// Execute swap
(uint256 amountIn, uint256 amountOut, uint256 fee) = poolZeroFee.swap(
alice,
Funding.USE_PREFUNDING,
Funding.PREFUNDING,
bob,
0, // token0 -> token1
1,
@@ -263,7 +263,7 @@ contract FundingTest is Test {
vm.expectRevert();
pool.swap(
alice,
Funding.USE_PREFUNDING,
Funding.PREFUNDING,
bob,
0,
1,
@@ -405,7 +405,7 @@ contract FundingTest is Test {
(uint256 refAmountIn, uint256 refAmountOut, uint256 refFee) = pool.swap(
bob,
Funding.USE_APPROVALS,
Funding.APPROVALS,
bob,
0,
1,
@@ -442,7 +442,7 @@ contract FundingTest is Test {
(uint256 preAmountIn, uint256 preAmountOut, uint256 preFee) = testPool.swap(
alice,
Funding.USE_PREFUNDING,
Funding.PREFUNDING,
alice,
0,
1,
@@ -469,7 +469,7 @@ contract FundingTest is Test {
(uint256 refAmountIn, uint256 refAmountOut, uint256 refFee) = pool.swap(
bob,
Funding.USE_APPROVALS,
Funding.APPROVALS,
bob,
0,
1,
@@ -574,7 +574,7 @@ contract FundingTest is Test {
vm.startPrank(alice);
token0.approve(address(poolApproval), type(uint256).max);
(uint256 apprIn, uint256 apprOut, ) = poolApproval.swap(
alice, Funding.USE_APPROVALS, alice, 0, 1, swapAmount, 0, 0, false
alice, Funding.APPROVALS, alice, 0, 1, swapAmount, 0, 0, false
);
vm.stopPrank();
@@ -582,7 +582,7 @@ contract FundingTest is Test {
vm.startPrank(alice);
token0.transfer(address(poolPreFund), swapAmount);
(uint256 preIn, uint256 preOut, ) = poolPreFund.swap(
alice, Funding.USE_PREFUNDING, alice, 0, 1, swapAmount, 0, 0, false
alice, Funding.PREFUNDING, alice, 0, 1, swapAmount, 0, 0, false
);
vm.stopPrank();

View File

@@ -238,7 +238,7 @@ contract GasTest is Test {
/// @notice Helper function: perform 10 swaps back-and-forth between the first two _tokens.
function _performSwapGasTest(IPartyPool testPool) internal {
_performSwapGasTest(testPool, Funding.USE_APPROVALS);
_performSwapGasTest(testPool, Funding.APPROVALS);
}
function sendTokensCallback(IERC20 token, uint256 amount) external {
@@ -253,11 +253,11 @@ contract GasTest is Test {
address payer;
address spender;
if (fundingSelector == Funding.USE_PREFUNDING) {
if (fundingSelector == Funding.PREFUNDING) {
payer = address(this);
spender = address(this);
}
else if (fundingSelector == Funding.USE_APPROVALS) {
else if (fundingSelector == Funding.APPROVALS) {
payer = alice;
spender = address(testPool);
}
@@ -278,13 +278,13 @@ contract GasTest is Test {
vm.startPrank(alice);
for (uint256 i = 0; i < 20; i++) {
if (i % 2 == 0) {
if (fundingSelector == Funding.USE_PREFUNDING)
if (fundingSelector == Funding.PREFUNDING)
token0.transfer(address(testPool), maxIn);
// swap token0 -> token1
testPool.swap(payer, fundingSelector, alice, 0, 1, maxIn, 0, 0, false);
} else {
// swap token1 -> token0
if (fundingSelector == Funding.USE_PREFUNDING)
if (fundingSelector == Funding.PREFUNDING)
token1.transfer(address(testPool), maxIn);
testPool.swap(payer, fundingSelector, alice, 1, 0, maxIn, 0, 0, false);
}
@@ -312,7 +312,7 @@ contract GasTest is Test {
/// @notice Gas measurement: perform 10 swaps back-and-forth between first two _tokens in the 10-token pool using the callback funding method.
function testSwapGasPrefunding() public {
_performSwapGasTest(pool10, Funding.USE_PREFUNDING);
_performSwapGasTest(pool10, Funding.PREFUNDING);
}
/// @notice Gas measurement: perform 10 swaps back-and-forth between first two _tokens in the 20-token pool.

View File

@@ -148,7 +148,7 @@ contract NativeTest is Test {
// Send native currency with {value: maxIn}
(uint256 amountIn, uint256 amountOut, ) = pool.swap{value: maxIn}(
alice, // payer
Funding.USE_APPROVALS,
Funding.APPROVALS,
alice, // receiver
2, // inputTokenIndex (WETH)
0, // outputTokenIndex (token0)
@@ -186,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
Funding.USE_APPROVALS, // no selector: use ERC20 approvals
Funding.APPROVALS, // no selector: use ERC20 approvals
alice, // receiver
0, // inputTokenIndex (token0)
2, // outputTokenIndex (WETH)
@@ -222,7 +222,7 @@ contract NativeTest is Test {
// Execute swap with excess native currency
(uint256 amountIn, , ) = pool.swap{value: totalSent}(
alice, // payer
Funding.USE_APPROVALS,
Funding.APPROVALS,
alice, // receiver
2, // inputTokenIndex (WETH)
0, // outputTokenIndex (token0)
@@ -551,14 +551,14 @@ contract NativeTest is Test {
// 2. Swap native currency for token0
uint256 swapAmount = 5_000;
(, uint256 amountOut, ) = pool.swap{value: swapAmount}(
alice,Funding.USE_APPROVALS,alice, 2, 0, swapAmount, 0, 0, false
alice,Funding.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, Funding.USE_APPROVALS, alice, 0, 2, token0Balance / 2, 0, 0, true
alice, Funding.APPROVALS, alice, 0, 2, token0Balance / 2, 0, 0, true
);
assertTrue(swapOut2 > 0, "Should receive native currency");
@@ -585,7 +585,7 @@ contract NativeTest is Test {
// Swap token0 -> WETH without unwrap
(, uint256 amountOut, ) = pool.swap(
alice, Funding.USE_APPROVALS, alice, 0, 2, maxIn, 0, 0, false // unwrap=false
alice, Funding.APPROVALS, alice, 0, 2, maxIn, 0, 0, false // unwrap=false
);
assertTrue(amountOut > 0, "Should receive WETH tokens");
@@ -606,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, Funding.USE_APPROVALS, alice, 0, 1, 10_000, 0, 0, false
alice, Funding.APPROVALS, alice, 0, 1, 10_000, 0, 0, false
);
vm.stopPrank();

View File

@@ -431,7 +431,7 @@ contract PartyPoolTest is Test {
// Execute swap: token0 -> token1
vm.prank(alice);
(uint256 amountInUsed, uint256 amountOut, uint256 fee) = pool.swap(alice, Funding.USE_APPROVALS, bob, 0, 1, maxIn, 0, 0, false);
(uint256 amountInUsed, uint256 amountOut, uint256 fee) = pool.swap(alice, Funding.APPROVALS, bob, 0, 1, maxIn, 0, 0, false);
// Amounts should be positive and not exceed provided max
assertTrue(amountInUsed > 0, "expected some input used");
@@ -460,7 +460,7 @@ contract PartyPoolTest is Test {
vm.prank(alice);
vm.expectRevert(bytes("LMSR: limitPrice <= current price"));
pool.swap(alice, Funding.USE_APPROVALS, alice, 0, 1, 1000, limitPrice, 0, false);
pool.swap(alice, Funding.APPROVALS, alice, 0, 1, 1000, limitPrice, 0, false);
}
/// @notice swapToLimit should compute input needed to reach a slightly higher price and execute.
@@ -1032,8 +1032,8 @@ contract PartyPoolTest is Test {
token0.approve(address(poolCustom), type(uint256).max);
// Perform identical swaps: token0 -> token1
(uint256 amountInDefault, uint256 amountOutDefault, uint256 feeDefault) = poolDefault.swap(alice, Funding.USE_APPROVALS, alice, 0, 1, swapAmount, 0, 0, false);
(uint256 amountInCustom, uint256 amountOutCustom, uint256 feeCustom) = poolCustom.swap(alice, Funding.USE_APPROVALS, alice, 0, 1, swapAmount, 0, 0, false);
(uint256 amountInDefault, uint256 amountOutDefault, uint256 feeDefault) = poolDefault.swap(alice, Funding.APPROVALS, alice, 0, 1, swapAmount, 0, 0, false);
(uint256 amountInCustom, uint256 amountOutCustom, uint256 feeCustom) = poolCustom.swap(alice, Funding.APPROVALS, alice, 0, 1, swapAmount, 0, 0, false);
// Swap results should be identical
assertEq(amountInDefault, amountInCustom, "Swap input amounts should be identical");