Skip to content

Commit

Permalink
test_collectProtocolFees_unlocked_revertsWithProtocolFeeCurrencySynced
Browse files Browse the repository at this point in the history
  • Loading branch information
wjmelements committed Oct 23, 2024
1 parent 4d56810 commit e2af146
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
10 changes: 9 additions & 1 deletion src/test/ActionsRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ enum Actions {
ASSERT_RESERVES_EQUALS,
ASSERT_DELTA_EQUALS,
ASSERT_NONZERO_DELTA_COUNT_EQUALS,
TRANSFER_FROM
TRANSFER_FROM,
COLLECT_PROTOCOL_FEES
}
// TODO: Add other actions as needed.
// BURN,
Expand Down Expand Up @@ -81,6 +82,8 @@ contract ActionsRouter is IUnlockCallback, Test, GasSnapshot {
_assertNonzeroDeltaCountEquals(param);
} else if (action == Actions.TRANSFER_FROM) {
_transferFrom(param);
} else if (action == Actions.COLLECT_PROTOCOL_FEES) {
_collectProtocolFees(param);
}
}
return "";
Expand Down Expand Up @@ -160,4 +163,9 @@ contract ActionsRouter is IUnlockCallback, Test, GasSnapshot {
abi.decode(params, (Currency, address, address, uint256));
MockERC20(Currency.unwrap(currency)).transferFrom(from, recipient, uint256(amount));
}

function _collectProtocolFees(bytes memory params) internal {
(address to, Currency currency, uint256 amount) = abi.decode(params, (address, Currency, uint256));
manager.collectProtocolFees(to, currency, amount);
}
}
21 changes: 13 additions & 8 deletions test/PoolManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {AmountHelpers} from "./utils/AmountHelpers.sol";
import {ProtocolFeeLibrary} from "../src/libraries/ProtocolFeeLibrary.sol";
import {IProtocolFees} from "../src/interfaces/IProtocolFees.sol";
import {StateLibrary} from "../src/libraries/StateLibrary.sol";
import {TransientStateLibrary} from "../src/libraries/TransientStateLibrary.sol";
import {Actions} from "../src/test/ActionsRouter.sol";

contract PoolManagerTest is Test, Deployers, GasSnapshot {
Expand All @@ -40,7 +39,6 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot {
using SafeCast for *;
using ProtocolFeeLibrary for uint24;
using StateLibrary for IPoolManager;
using TransientStateLibrary for IPoolManager;

event UnlockCallback();
event ProtocolFeeControllerUpdated(address feeController);
Expand Down Expand Up @@ -985,13 +983,20 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot {
manager.burn(address(this), key.currency0.toId(), 1);
}

function test_collectProtocolFees_locked_revertsWithProtocolFeeCurrencySynced() public {
assertNotEq(Currency.unwrap(key.currency1), address(0));
manager.sync(key.currency1);
assertEq(Currency.unwrap(key.currency1), Currency.unwrap(manager.getSyncedCurrency()));
vm.prank(feeController);
function test_collectProtocolFees_unlocked_revertsWithProtocolFeeCurrencySynced() public {
manager.setProtocolFeeController(address(actionsRouter));

Actions[] memory actions = new Actions[](2);
bytes[] memory params = new bytes[](2);

actions[0] = Actions.SYNC;
params[0] = abi.encode(key.currency1);

actions[1] = Actions.COLLECT_PROTOCOL_FEES;
params[1] = abi.encode(address(this), key.currency1, 1);

vm.expectRevert(IProtocolFees.ProtocolFeeCurrencySynced.selector);
manager.collectProtocolFees(address(this), key.currency1, 1);
actionsRouter.executeActions(actions, params);
}

function test_collectProtocolFees_ERC20_accumulateFees_gas() public {
Expand Down

0 comments on commit e2af146

Please sign in to comment.