Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access lock #404

Merged
merged 35 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1cc37ed
rebase
snreynolds Nov 9, 2023
2a2321e
add access lock flag
snreynolds Nov 14, 2023
65069b3
create AccessLock tests
snreynolds Nov 15, 2023
589026f
add beforeModifyPosition tests for mint/swap/modify/take/donate
snreynolds Nov 16, 2023
70a869e
add beforeSwap tests
snreynolds Nov 17, 2023
e147a7c
add beforeDonate tests
snreynolds Nov 17, 2023
2396461
fix fuzz boundaries
snreynolds Nov 17, 2023
8b6b850
use transient storage
snreynolds Nov 17, 2023
400ce17
fix ci?
snreynolds Nov 17, 2023
7bda2b1
fix: comments
snreynolds Nov 20, 2023
fbda6c4
add revert test
snreynolds Nov 20, 2023
11c9321
more edge case tests
snreynolds Nov 20, 2023
d6864a4
add failing test
snreynolds Nov 20, 2023
d7829b7
fix: hooks can only call functions in the middle of a lock
snreynolds Nov 20, 2023
9d8f00b
fix comments
snreynolds Nov 20, 2023
2a7ccf9
fix: currentHook must be updated only on the first call, and cleared
snreynolds Nov 21, 2023
2e88e5f
merge main
snreynolds Nov 22, 2023
969fb9d
use IHooks, remove 1155 ref
snreynolds Nov 22, 2023
a958a37
remove special no access lock hook
snreynolds Nov 22, 2023
f70443a
add nested lock test
snreynolds Nov 22, 2023
88d9ce1
unset hook for noOp case
snreynolds Nov 26, 2023
448b557
add initialize
snreynolds Nov 27, 2023
fa432c2
add vanilla initialize tests
snreynolds Nov 27, 2023
fb803c3
fmt error
snreynolds Nov 27, 2023
f455e64
add natspec and flatten onlyByLocker check
snreynolds Nov 27, 2023
528ce4e
snaps
snreynolds Nov 27, 2023
83afc1e
move onlyByLocker, add comments
snreynolds Nov 29, 2023
b9645ef
update comments, use custom error, add test cases
snreynolds Nov 29, 2023
7fc2658
add burn test
snreynolds Nov 30, 2023
e571806
remove logs
snreynolds Nov 30, 2023
680faf7
add settle test
snreynolds Nov 30, 2023
53cdf3e
init test
snreynolds Nov 30, 2023
7755acd
add back noop test
snreynolds Nov 30, 2023
852ed5b
remove else
snreynolds Nov 30, 2023
0aee197
Merge branch 'main' into access-lock
snreynolds Dec 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
init test
  • Loading branch information
snreynolds committed Nov 30, 2023
commit 53cdf3e12af506d59bd5949bc4f84a485852e0a9
6 changes: 4 additions & 2 deletions src/test/AccessLockHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import {Test} from "forge-std/Test.sol";
import {ILockCallback} from "../interfaces/callback/ILockCallback.sol";
import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol";
import {Constants} from "../../test/utils/Constants.sol";
import {PoolIdLibrary} from "../types/PoolId.sol";

contract AccessLockHook is Test, BaseTestHooks {
using PoolIdLibrary for PoolKey;
using CurrencyLibrary for Currency;

IPoolManager manager;
Expand Down Expand Up @@ -119,11 +121,11 @@ contract AccessLockHook is Test, BaseTestHooks {
PoolKey memory newKey = PoolKey({
currency0: key.currency0,
currency1: key.currency1,
fee: Constants.FEE_MEDIUM,
fee: Constants.FEE_LOW,
tickSpacing: 60,
hooks: IHooks(address(0))
});
manager.initialize(newKey, Constants.SQRT_RATIO_1_1, new bytes(0));
manager.initialize(newKey, Constants.SQRT_RATIO_1_2, new bytes(0));
} else {
revert InvalidAction();
}
Expand Down
22 changes: 22 additions & 0 deletions test/AccessLock.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import {IHooks} from "../src/interfaces/IHooks.sol";
import {BalanceDelta} from "../src/types/BalanceDelta.sol";
import {Pool} from "../src/libraries/Pool.sol";
import {TickMath} from "../src/libraries/TickMath.sol";
import {PoolIdLibrary} from "../src/types/PoolId.sol";

contract AccessLockTest is Test, Deployers {
using Pool for Pool.State;
using CurrencyLibrary for Currency;
using PoolIdLibrary for PoolKey;

AccessLockHook accessLockHook;
AccessLockHook noAccessLockHook;
Expand Down Expand Up @@ -288,6 +290,26 @@ contract AccessLockTest is Test, Deployers {
);
}

function test_beforeModifyPosition_initialize_succeedsWithAccessLock() public {
// The hook intitializes a new pool with the new key at Constants.SQRT_RATIO_1_2;
modifyPositionRouter.modifyPosition(
key,
IPoolManager.ModifyPositionParams(-120, 120, 1 * 10 ** 18),
abi.encode(0, AccessLockHook.LockAction.Initialize)
);

PoolKey memory newKey = PoolKey({
currency0: key.currency0,
currency1: key.currency1,
fee: Constants.FEE_LOW,
tickSpacing: 60,
hooks: IHooks(address(0))
});
(Pool.Slot0 memory slot0,,,) = manager.pools(newKey.toId());

assertEq(slot0.sqrtPriceX96, Constants.SQRT_RATIO_1_2);
}

/**
*
* BEFORE SWAP TESTS
Expand Down