Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
snreynolds committed Jul 12, 2024
1 parent 379a5bd commit 7ae9ebd
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/autocompound_exactUnclaimedFees.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
291215
291244
Original file line number Diff line number Diff line change
@@ -1 +1 @@
223574
223603
2 changes: 1 addition & 1 deletion .forge-snapshots/autocompound_excessFeesCredit.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
311754
311783
2 changes: 1 addition & 1 deletion .forge-snapshots/decreaseLiquidity_erc20.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
209285
209314
2 changes: 1 addition & 1 deletion .forge-snapshots/decreaseLiquidity_erc6909.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
209297
209326
2 changes: 1 addition & 1 deletion .forge-snapshots/increaseLiquidity_erc20.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
194833
194862
2 changes: 1 addition & 1 deletion .forge-snapshots/increaseLiquidity_erc6909.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
194845
194874
2 changes: 1 addition & 1 deletion .forge-snapshots/mint.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
493134
493163
3 changes: 2 additions & 1 deletion contracts/NonfungiblePositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ contract NonfungiblePositionManager is INonfungiblePositionManager, BaseLiquidit
internal
returns (bytes[] memory returnData)
{
returnData = new bytes[](actions.length);
if (actions.length != params.length) revert MismatchedLengths();

returnData = new bytes[](actions.length);
for (uint256 i; i < actions.length; i++) {
if (actions[i] == Actions.INCREASE) {
(uint256 tokenId, uint256 liquidity, bytes memory hookData, bool claims) =
Expand Down
2 changes: 2 additions & 0 deletions contracts/interfaces/INonfungiblePositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ enum Actions {
}

interface INonfungiblePositionManager {
error MismatchedLengths();

struct TokenPosition {
address owner;
LiquidityRange range;
Expand Down
4 changes: 1 addition & 3 deletions test/position-managers/FeeCollection.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,9 @@ contract FeeCollectionTest is Test, Deployers, GasSnapshot, LiquidityFuzzers, Li
uint256 balance1Before = currency1.balanceOfSelf();
BalanceDelta delta = _collect(tokenId, address(this), ZERO_BYTES, false);

assertEq(delta.amount0(), 0);

// express key.fee as wad (i.e. 3000 = 0.003e18)
assertApproxEqAbs(uint256(int256(delta.amount1())), swapAmount.mulWadDown(FEE_WAD), 1 wei);

assertEq(uint256(int256(delta.amount0())), currency0.balanceOfSelf() - balance0Before);
assertEq(uint256(int256(delta.amount1())), currency1.balanceOfSelf() - balance1Before);
}

Expand Down
1 change: 0 additions & 1 deletion test/position-managers/Gas.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ contract GasTest is Test, Deployers, GasSnapshot, LiquidityOperations {
// bob provides liquidity
vm.prank(bob);
_mint(range, liquidityBob, block.timestamp + 1, bob, ZERO_BYTES);
uint256 tokenIdBob = lpm.nextTokenId() - 1;

// donate to create fees
donateRouter.donate(key, 20e18, 20e18, ZERO_BYTES);
Expand Down
2 changes: 0 additions & 2 deletions test/position-managers/IncreaseLiquidity.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ contract IncreaseLiquidityTest is Test, Deployers, GasSnapshot, Fuzzers, Liquidi
// Alice uses her fees to increase liquidity. Both unclaimed fees and cached fees are used to exactly increase the liquidity
uint256 liquidityAlice = 3_000e18;
uint256 liquidityBob = 1_000e18;
uint256 totalLiquidity = liquidityAlice + liquidityBob;

// alice provides liquidity
vm.prank(alice);
Expand Down Expand Up @@ -397,7 +396,6 @@ contract IncreaseLiquidityTest is Test, Deployers, GasSnapshot, Fuzzers, Liquidi
// Alice uses her fees to increase liquidity. Both unclaimed fees and cached fees are used to exactly increase the liquidity
uint256 liquidityAlice = 3_000e18;
uint256 liquidityBob = 1_000e18;
uint256 totalLiquidity = liquidityAlice + liquidityBob;

// alice provides liquidity
vm.prank(alice);
Expand Down
22 changes: 19 additions & 3 deletions test/position-managers/NonfungiblePositionManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ contract NonfungiblePositionManagerTest is Test, Deployers, GasSnapshot, Liquidi
IERC20(Currency.unwrap(currency1)).approve(address(lpm), type(uint256).max);
}

function test_modifyLiquidities_reverts_mismatchedLengths() public {
Planner.Plan memory planner = Planner.init();
planner = planner.add(Actions.MINT, abi.encode("test"));
planner = planner.add(Actions.BURN, abi.encode("test"));

Currency[] memory currencies = new Currency[](2);
currencies[0] = currency0;
currencies[1] = currency1;

bytes[] memory badParams = new bytes[](1);

vm.expectRevert(INonfungiblePositionManager.MismatchedLengths.selector);
lpm.modifyLiquidities(abi.encode(planner.actions, badParams, currencies));
}

function test_mint_withLiquidityDelta(IPoolManager.ModifyLiquidityParams memory params) public {
params = createFuzzyLiquidityParams(key, params, SQRT_PRICE_1_1);
// liquidity is a uint
Expand All @@ -75,7 +90,8 @@ contract NonfungiblePositionManagerTest is Test, Deployers, GasSnapshot, Liquidi

(BalanceDelta delta, uint256 tokenId) = abi.decode(result[0], (BalanceDelta, uint256));

assertEq(lpm.ownerOf(1), address(this));
assertEq(tokenId, 1);
assertEq(lpm.ownerOf(tokenId), address(this));
(,, uint256 liquidity,,,,) = lpm.positions(address(this), range.toId());
assertEq(liquidity, uint256(params.liquidityDelta));
assertEq(balance0Before - currency0.balanceOfSelf(), uint256(int256(-delta.amount0())), "incorrect amount0");
Expand Down Expand Up @@ -142,7 +158,7 @@ contract NonfungiblePositionManagerTest is Test, Deployers, GasSnapshot, Liquidi

bytes[] memory results = lpm.modifyLiquidities(abi.encode(planner.actions, planner.params, currencies));

(BalanceDelta delta, uint256 tokenId) = abi.decode(results[0], (BalanceDelta, uint256));
(, uint256 tokenId) = abi.decode(results[0], (BalanceDelta, uint256));
assertEq(tokenId, 1);
assertEq(lpm.ownerOf(tokenId), alice);
}
Expand Down Expand Up @@ -252,7 +268,7 @@ contract NonfungiblePositionManagerTest is Test, Deployers, GasSnapshot, Liquidi

uint256 balance0Before = currency0.balanceOfSelf();
uint256 balance1Before = currency1.balanceOfSelf();
BalanceDelta delta = _decreaseLiquidity(tokenId, decreaseLiquidityDelta, ZERO_BYTES, false);
_decreaseLiquidity(tokenId, decreaseLiquidityDelta, ZERO_BYTES, false);

(,, uint256 liquidity,,,,) = lpm.positions(address(this), range.toId());
assertEq(liquidity, uint256(params.liquidityDelta) - decreaseLiquidityDelta);
Expand Down
2 changes: 1 addition & 1 deletion test/shared/LiquidityOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ contract LiquidityOperations {
Currency[] memory currencies = new Currency[](0);
Planner.Plan memory planner = Planner.init();
planner = planner.add(Actions.BURN, abi.encode(tokenId));
bytes[] memory result = lpm.modifyLiquidities(abi.encode(planner.actions, planner.params, currencies));
lpm.modifyLiquidities(abi.encode(planner.actions, planner.params, currencies));
}
}
8 changes: 2 additions & 6 deletions test/utils/Planner.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ library Planner {
bytes[] params;
}

function init() public returns (Plan memory plan) {
function init() public pure returns (Plan memory plan) {
return Plan({actions: new Actions[](0), params: new bytes[](0)});
}

function add(Plan memory plan, Actions action, bytes memory param) public returns (Plan memory) {
function add(Plan memory plan, Actions action, bytes memory param) public pure returns (Plan memory) {
Actions[] memory actions = new Actions[](plan.actions.length + 1);
bytes[] memory params = new bytes[](plan.params.length + 1);

Expand All @@ -28,8 +28,4 @@ library Planner {

return Plan({actions: actions, params: params});
}

function zip(Plan memory plan) public returns (bytes memory) {
return abi.encode(plan.actions, plan.params);
}
}

0 comments on commit 7ae9ebd

Please sign in to comment.