-
Notifications
You must be signed in to change notification settings - Fork 2
Angstrom Hooks with tests #1
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
8d0d97d
Fix names of files and implement swap tests
joaobrunoah 24a63a5
Create hook logic and tests to verify signatures
joaobrunoah 3480ff0
Fix signature test
joaobrunoah b354a32
Test error OnlyOncePerBlock
joaobrunoah 385e966
100% coverage
joaobrunoah b2b6461
Block unbalanced liquidity operations when Angstrom is locked
joaobrunoah 73c6b13
100% test coverage
joaobrunoah b48049d
Commit test
joaobrunoah 226cf6f
Run github action
joaobrunoah d955e5a
Remove unused dependency
joaobrunoah a6742b9
Natspec
joaobrunoah 77e9d60
Fix solady install
joaobrunoah 78715cf
Fix lint
joaobrunoah 1be7f44
Fix function mutability
joaobrunoah d08401b
Merge pull request #4 from balancer/angstrom-hook
joaobrunoah 2c21fea
Modify package.json to Angstrom
joaobrunoah 3fedf8e
Readme
joaobrunoah 42f0474
Fix contract names and repo
joaobrunoah d0e5949
docs: update comments and non-semantics
EndymionJkb c770e11
refactor: rename `_nodes` for clarity
EndymionJkb 5a325d7
refactor: add `isRegisteredNode` getter; add `fromValidator` modifier…
EndymionJkb e841b11
refactor: add onlyWhenLocked modifier, and isolate updates in `_unloc…
EndymionJkb 49fd080
refactor: rename validator modifier; simplify unlockAngstrom helper
EndymionJkb b63265a
refactor: simplify/rename unlock functions; move getters from mock; r…
EndymionJkb 28b2500
test: don't need leading underscores in tests
EndymionJkb f6bbc67
test: introduce intermediate test
EndymionJkb 793e9a9
fix: createHook in proper place
EndymionJkb 5b41904
test: propagate intermediate test
EndymionJkb 6632cdd
refactor: rename validator modifier; simplify onBeforeSwap
EndymionJkb 5603a14
refactor: remove redundant code
EndymionJkb 4804023
refactor: rename/reorder
EndymionJkb 124194a
refactor: remove unused function
EndymionJkb 1ca3856
refactor: one more simplification - only revert in one place for each…
EndymionJkb d5b569c
docs: adjust comments after review
EndymionJkb 6b24bc5
Merge pull request #6 from balancer/angstrom-updates-v2
EndymionJkb 459f82a
Merge pull request #7 from balancer/support-hardhat-contracts
joaobrunoah 94c94ac
Fix PR comment
joaobrunoah d23b3f8
Add event when adding/removing node
joaobrunoah ecc153e
Use OwnableAuthentication instead of Singleton
joaobrunoah b8f11ee
Use mcopy instead of a for loop
joaobrunoah b257566
Update contracts/AngstromBalancer.sol
joaobrunoah f26e69e
Unify invalid signature errors
joaobrunoah 657ac83
Change toggle to add/remove
joaobrunoah 418d2a0
Revert add/removeNode if node state is inconsistent
joaobrunoah 2f88693
Fix remappings
joaobrunoah 001b761
Fix Angstrom to use only memory signatures
joaobrunoah eba2693
Add comments
joaobrunoah e6a55a5
Use unlockAngstromWithSignature directly
joaobrunoah 7af693d
Apply suggestions from code review
joaobrunoah c0cedc6
Fix register/deregister nodes
joaobrunoah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| pragma solidity ^0.8.24; | ||
|
|
||
| import "forge-std/Test.sol"; | ||
|
|
||
| import { IAuthentication } from "@balancer-labs/v3-interfaces/contracts/solidity-utils/helpers/IAuthentication.sol"; | ||
| import { | ||
| SwapPathExactAmountIn, | ||
| SwapPathExactAmountOut | ||
| } from "@balancer-labs/v3-interfaces/contracts/vault/BatchRouterTypes.sol"; | ||
|
|
||
| import { ArrayHelpers } from "@balancer-labs/v3-solidity-utils/contracts/test/ArrayHelpers.sol"; | ||
| import { BaseVaultTest } from "@balancer-labs/v3-vault/test/foundry/utils/BaseVaultTest.sol"; | ||
|
|
||
| import { AngstromRouterAndHookMock } from "../../contracts/test/AngstromRouterAndHookMock.sol"; | ||
| import { AngstromRouterAndHook } from "../../contracts/AngstromRouterAndHook.sol"; | ||
|
|
||
| contract AngstromRouterAndHookTest is BaseVaultTest { | ||
| using ArrayHelpers for *; | ||
|
|
||
| AngstromRouterAndHookMock private _angstromRouterAndHook; | ||
|
|
||
| function setUp() public virtual override { | ||
| super.setUp(); | ||
|
|
||
| _angstromRouterAndHook = new AngstromRouterAndHookMock(vault, weth, permit2, "AngstromRouterAndHook Mock v1"); | ||
|
|
||
| authorizer.grantRole(_angstromRouterAndHook.getActionId(AngstromRouterAndHook.toggleNodes.selector), admin); | ||
| } | ||
|
|
||
| function testSwapExactInNotNode() public { | ||
| SwapPathExactAmountIn[] memory paths; | ||
| vm.expectRevert(AngstromRouterAndHook.NotNode.selector); | ||
| _angstromRouterAndHook.swapExactIn(paths, MAX_UINT256, false, bytes("")); | ||
| } | ||
|
|
||
| function testSwapExactInAlreadyUnlocked() public { | ||
| vm.prank(admin); | ||
| _angstromRouterAndHook.toggleNodes([bob].toMemoryArray()); | ||
|
|
||
| SwapPathExactAmountIn[] memory paths; | ||
|
|
||
| vm.startPrank(bob); | ||
| _angstromRouterAndHook.manualUnlockAngstrom(); | ||
| vm.expectRevert(AngstromRouterAndHook.OnlyOncePerBlock.selector); | ||
| _angstromRouterAndHook.swapExactIn(paths, MAX_UINT256, false, bytes("")); | ||
| vm.stopPrank(); | ||
| } | ||
|
|
||
| function testSwapExactInUnlocksAngstrom() public { | ||
| vm.prank(admin); | ||
| _angstromRouterAndHook.toggleNodes([bob].toMemoryArray()); | ||
|
|
||
| SwapPathExactAmountIn[] memory paths; | ||
| vm.prank(bob); | ||
| _angstromRouterAndHook.swapExactIn(paths, MAX_UINT256, false, bytes("")); | ||
| assertEq( | ||
| _angstromRouterAndHook.getLastUnlockBlockNumber(), | ||
| block.number, | ||
| "Last unlock block number is not the current block number" | ||
| ); | ||
| } | ||
|
|
||
| function testSwapExactOutNotNode() public { | ||
| SwapPathExactAmountOut[] memory paths; | ||
| vm.expectRevert(AngstromRouterAndHook.NotNode.selector); | ||
| _angstromRouterAndHook.swapExactOut(paths, MAX_UINT256, false, bytes("")); | ||
| } | ||
|
|
||
| function testSwapExactOutAlreadyUnlocked() public { | ||
| vm.prank(admin); | ||
| _angstromRouterAndHook.toggleNodes([bob].toMemoryArray()); | ||
|
|
||
| SwapPathExactAmountOut[] memory paths; | ||
| vm.startPrank(bob); | ||
| _angstromRouterAndHook.manualUnlockAngstrom(); | ||
| vm.expectRevert(AngstromRouterAndHook.OnlyOncePerBlock.selector); | ||
| _angstromRouterAndHook.swapExactOut(paths, MAX_UINT256, false, bytes("")); | ||
| vm.stopPrank(); | ||
| } | ||
|
|
||
| function testSwapExactOutUnlocksRouter() public { | ||
| vm.prank(admin); | ||
| _angstromRouterAndHook.toggleNodes([bob].toMemoryArray()); | ||
|
|
||
| SwapPathExactAmountOut[] memory paths; | ||
| vm.prank(bob); | ||
| _angstromRouterAndHook.swapExactOut(paths, MAX_UINT256, false, bytes("")); | ||
| assertEq( | ||
| _angstromRouterAndHook.getLastUnlockBlockNumber(), | ||
| block.number, | ||
| "Last unlock block number is not the current block number" | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| pragma solidity ^0.8.24; | ||
|
|
||
| import "forge-std/Test.sol"; | ||
|
|
||
| import { IAuthentication } from "@balancer-labs/v3-interfaces/contracts/solidity-utils/helpers/IAuthentication.sol"; | ||
|
|
||
| import { ArrayHelpers } from "@balancer-labs/v3-solidity-utils/contracts/test/ArrayHelpers.sol"; | ||
| import { BaseVaultTest } from "@balancer-labs/v3-vault/test/foundry/utils/BaseVaultTest.sol"; | ||
|
|
||
| import { AngstromRouterAndHookMock } from "../../contracts/test/AngstromRouterAndHookMock.sol"; | ||
| import { AngstromRouterAndHook } from "../../contracts/AngstromRouterAndHook.sol"; | ||
|
|
||
| contract AngstromRouterAndHookUnitTest is BaseVaultTest { | ||
| using ArrayHelpers for *; | ||
|
|
||
| AngstromRouterAndHookMock private _angstromRouterAndHook; | ||
|
|
||
| function setUp() public virtual override { | ||
| super.setUp(); | ||
|
|
||
| _angstromRouterAndHook = new AngstromRouterAndHookMock(vault, weth, permit2, "AngstromRouterAndHook Mock v1"); | ||
|
|
||
| authorizer.grantRole(_angstromRouterAndHook.getActionId(AngstromRouterAndHook.toggleNodes.selector), admin); | ||
| } | ||
|
|
||
| function testToggleNodesIsAuthenticated() public { | ||
| vm.expectRevert(IAuthentication.SenderNotAllowed.selector); | ||
| _angstromRouterAndHook.toggleNodes([bob].toMemoryArray()); | ||
| } | ||
|
|
||
| function testToggleNodes() public { | ||
| vm.prank(admin); | ||
| _angstromRouterAndHook.toggleNodes([bob].toMemoryArray()); | ||
| assertTrue(_angstromRouterAndHook.isNode(bob), "Bob is not a node"); | ||
| } | ||
|
|
||
| function testAddAndRemoveNodes() public { | ||
| vm.startPrank(admin); | ||
| _angstromRouterAndHook.toggleNodes([bob, alice].toMemoryArray()); | ||
| assertTrue(_angstromRouterAndHook.isNode(bob), "Bob is not a node"); | ||
| assertTrue(_angstromRouterAndHook.isNode(alice), "Alice is not a node"); | ||
| _angstromRouterAndHook.toggleNodes([bob].toMemoryArray()); | ||
| vm.stopPrank(); | ||
| assertFalse(_angstromRouterAndHook.isNode(bob), "Bob is still a node"); | ||
| assertTrue(_angstromRouterAndHook.isNode(alice), "Alice is not a node after bob was removed"); | ||
| } | ||
|
|
||
| function testUnlockAngstromNotNode() public { | ||
| vm.expectRevert(AngstromRouterAndHook.NotNode.selector); | ||
| _angstromRouterAndHook.manualUnlockAngstrom(); | ||
| } | ||
|
|
||
| function testUnlockAngstromTwice() public { | ||
| vm.prank(admin); | ||
| _angstromRouterAndHook.toggleNodes([bob].toMemoryArray()); | ||
|
|
||
| vm.startPrank(bob); | ||
| _angstromRouterAndHook.manualUnlockAngstrom(); | ||
| vm.expectRevert(AngstromRouterAndHook.OnlyOncePerBlock.selector); | ||
| _angstromRouterAndHook.manualUnlockAngstrom(); | ||
| vm.stopPrank(); | ||
| } | ||
|
|
||
| function testUnlockAngstromSetsLastUnlockBlockNumber() public { | ||
| vm.prank(admin); | ||
| _angstromRouterAndHook.toggleNodes([bob].toMemoryArray()); | ||
|
|
||
| assertEq(_angstromRouterAndHook.getLastUnlockBlockNumber(), 0, "Last unlock block number is not 0"); | ||
|
|
||
| vm.prank(bob); | ||
| _angstromRouterAndHook.manualUnlockAngstrom(); | ||
| assertEq( | ||
| _angstromRouterAndHook.getLastUnlockBlockNumber(), | ||
| block.number, | ||
| "Last unlock block number is not the current block number" | ||
| ); | ||
| } | ||
|
|
||
| function testGetVault() public { | ||
| assertEq(address(_angstromRouterAndHook.getVault()), address(vault), "Wrong vault address"); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.