From c982ed99e8bd1a01ec637aa1b9cd2c5ae69ddac4 Mon Sep 17 00:00:00 2001 From: royvardhan Date: Fri, 24 Jan 2025 18:12:56 +0530 Subject: [PATCH 1/6] feat: add pause/unpause methods --- foundry/src/TychoRouter.sol | 22 ++++++++++++++++++++-- foundry/test/Constants.sol | 2 ++ foundry/test/TychoRouter.t.sol | 25 +++++++++++++++++++++++++ foundry/test/TychoRouterTestSetup.sol | 2 ++ 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/foundry/src/TychoRouter.sol b/foundry/src/TychoRouter.sol index 4383618..7a4df3f 100644 --- a/foundry/src/TychoRouter.sol +++ b/foundry/src/TychoRouter.sol @@ -7,6 +7,7 @@ import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@permit2/src/interfaces/IAllowanceTransfer.sol"; import "./SwapExecutionDispatcher.sol"; import "./CallbackVerificationDispatcher.sol"; +import "@openzeppelin/contracts/utils/Pausable.sol"; error TychoRouter__WithdrawalFailed(); error TychoRouter__AddressZero(); @@ -16,7 +17,8 @@ error TychoRouter__NonContractVerifier(); contract TychoRouter is AccessControl, SwapExecutionDispatcher, - CallbackVerificationDispatcher + CallbackVerificationDispatcher, + Pausable { IAllowanceTransfer public immutable permit2; @@ -29,6 +31,8 @@ contract TychoRouter is 0xe6ad9a47fbda1dc18de1eb5eeb7d935e5e81b4748f3cfc61e233e64f88182060; bytes32 public constant PAUSER_ROLE = 0x65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a; + bytes32 public constant UNPAUSER_ROLE = + 0x427da25fe773164f88948d3e215c94b6554e2ed5e5f203a821c9f2f6131cf75a; bytes32 public constant FUND_RESCUER_ROLE = 0x912e45d663a6f4cc1d0491d8f046e06c616f40352565ea1cdb86a0e1aaefa41b; @@ -62,6 +66,20 @@ contract TychoRouter is // TODO execute generic callback } + /** + * @dev Pauses the contract + */ + function pause() external onlyRole(PAUSER_ROLE) { + _pause(); + } + + /** + * @dev Unpauses the contract + */ + function unpause() external onlyRole(UNPAUSER_ROLE) { + _unpause(); + } + /** * @dev Executes a swap graph supporting internal splits token amount * splits, checking that the user gets more than minUserAmount of buyToken. @@ -76,7 +94,7 @@ contract TychoRouter is bytes calldata swaps, IAllowanceTransfer.PermitSingle calldata permitSingle, bytes calldata signature - ) external returns (uint256 amountOut) { + ) external whenNotPaused returns (uint256 amountOut) { amountOut = 0; // TODO } diff --git a/foundry/test/Constants.sol b/foundry/test/Constants.sol index 521dff7..fe12d79 100644 --- a/foundry/test/Constants.sol +++ b/foundry/test/Constants.sol @@ -11,4 +11,6 @@ contract Constants is Test { // dummy contracts address DUMMY = makeAddr("dummy"); address FEE_RECEIVER = makeAddr("feeReceiver"); + address PAUSER = makeAddr("pauser"); + address UNPAUSER = makeAddr("unpauser"); } diff --git a/foundry/test/TychoRouter.t.sol b/foundry/test/TychoRouter.t.sol index fb9ad4b..ebfc6c8 100644 --- a/foundry/test/TychoRouter.t.sol +++ b/foundry/test/TychoRouter.t.sol @@ -206,4 +206,29 @@ contract TychoRouterTest is TychoRouterTestSetup { tychoRouter.setFeeReceiver(FEE_RECEIVER); vm.stopPrank(); } + + function testPause() public { + vm.startPrank(PAUSER); + assertEq(tychoRouter.paused(), false); + tychoRouter.pause(); + assertEq(tychoRouter.paused(), true); + vm.stopPrank(); + + vm.startPrank(UNPAUSER); + tychoRouter.unpause(); + assertEq(tychoRouter.paused(), false); + vm.stopPrank(); + } + + function testPauseFailures() public { + vm.startPrank(BOB); + vm.expectRevert(); + tychoRouter.pause(); + vm.stopPrank(); + + vm.startPrank(UNPAUSER); + vm.expectRevert(); + tychoRouter.unpause(); + vm.stopPrank(); + } } diff --git a/foundry/test/TychoRouterTestSetup.sol b/foundry/test/TychoRouterTestSetup.sol index 9765d76..31fb266 100644 --- a/foundry/test/TychoRouterTestSetup.sol +++ b/foundry/test/TychoRouterTestSetup.sol @@ -17,6 +17,8 @@ contract TychoRouterTestSetup is Test, Constants { tychoRouter.grantRole(keccak256("EXECUTOR_SETTER_ROLE"), BOB); tychoRouter.grantRole(keccak256("FUND_RESCUER_ROLE"), FUND_RESCUER); tychoRouter.grantRole(keccak256("FEE_SETTER_ROLE"), FEE_SETTER); + tychoRouter.grantRole(keccak256("PAUSER_ROLE"), PAUSER); + tychoRouter.grantRole(keccak256("UNPAUSER_ROLE"), UNPAUSER); executorSetter = BOB; deployDummyContract(); vm.stopPrank(); From f0f9339101afcc36c9ca8fc0ddd61f44bb5b3817 Mon Sep 17 00:00:00 2001 From: royvardhan Date: Fri, 24 Jan 2025 22:00:13 +0530 Subject: [PATCH 2/6] chore: add TODO in test --- foundry/test/TychoRouter.t.sol | 3 +++ 1 file changed, 3 insertions(+) diff --git a/foundry/test/TychoRouter.t.sol b/foundry/test/TychoRouter.t.sol index ebfc6c8..d62b11a 100644 --- a/foundry/test/TychoRouter.t.sol +++ b/foundry/test/TychoRouter.t.sol @@ -212,12 +212,15 @@ contract TychoRouterTest is TychoRouterTestSetup { assertEq(tychoRouter.paused(), false); tychoRouter.pause(); assertEq(tychoRouter.paused(), true); + // TODO: test swap calls when implemeted vm.stopPrank(); vm.startPrank(UNPAUSER); tychoRouter.unpause(); assertEq(tychoRouter.paused(), false); vm.stopPrank(); + + } function testPauseFailures() public { From 4fe0a76cf928f4f1b573a7d908b673639cef6559 Mon Sep 17 00:00:00 2001 From: royvardhan Date: Fri, 24 Jan 2025 22:01:18 +0530 Subject: [PATCH 3/6] chore: fmt --- foundry/test/TychoRouter.t.sol | 2 -- 1 file changed, 2 deletions(-) diff --git a/foundry/test/TychoRouter.t.sol b/foundry/test/TychoRouter.t.sol index d62b11a..39b582d 100644 --- a/foundry/test/TychoRouter.t.sol +++ b/foundry/test/TychoRouter.t.sol @@ -219,8 +219,6 @@ contract TychoRouterTest is TychoRouterTestSetup { tychoRouter.unpause(); assertEq(tychoRouter.paused(), false); vm.stopPrank(); - - } function testPauseFailures() public { From 5734b535548338adcd3a738feb559b5b16105766 Mon Sep 17 00:00:00 2001 From: royvardhan Date: Mon, 27 Jan 2025 17:11:47 +0530 Subject: [PATCH 4/6] fix: test pauser --- foundry/test/TychoRouter.t.sol | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/foundry/test/TychoRouter.t.sol b/foundry/test/TychoRouter.t.sol index 39b582d..72141a3 100644 --- a/foundry/test/TychoRouter.t.sol +++ b/foundry/test/TychoRouter.t.sol @@ -219,17 +219,17 @@ contract TychoRouterTest is TychoRouterTestSetup { tychoRouter.unpause(); assertEq(tychoRouter.paused(), false); vm.stopPrank(); - } - - function testPauseFailures() public { - vm.startPrank(BOB); - vm.expectRevert(); - tychoRouter.pause(); - vm.stopPrank(); vm.startPrank(UNPAUSER); vm.expectRevert(); tychoRouter.unpause(); vm.stopPrank(); } + + function testPauseNonRole() public { + vm.startPrank(BOB); + vm.expectRevert(); + tychoRouter.pause(); + vm.stopPrank(); + } } From 4ee337d1ee3fa5cda7bbec64b760e39028165a60 Mon Sep 17 00:00:00 2001 From: royvardhan Date: Mon, 27 Jan 2025 20:44:01 +0530 Subject: [PATCH 5/6] fix: ci --- foundry/src/TychoRouter.sol | 2 +- foundry/test/Constants.sol | 1 - test/TychoRouter.t.sol | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 test/TychoRouter.t.sol diff --git a/foundry/src/TychoRouter.sol b/foundry/src/TychoRouter.sol index 62d899b..da92429 100644 --- a/foundry/src/TychoRouter.sol +++ b/foundry/src/TychoRouter.sol @@ -15,7 +15,7 @@ error TychoRouter__NonContractVerifier(); contract TychoRouter is AccessControl, - SwapExecutionDispatcher, + ExecutionDispatcher, CallbackVerificationDispatcher, Pausable { diff --git a/foundry/test/Constants.sol b/foundry/test/Constants.sol index 7c2a31f..ed1b66f 100644 --- a/foundry/test/Constants.sol +++ b/foundry/test/Constants.sol @@ -12,7 +12,6 @@ contract Constants is Test { // Dummy contracts address DUMMY = makeAddr("dummy"); - address FEE_RECEIVER = makeAddr("feeReceiver"); address PAUSER = makeAddr("pauser"); address UNPAUSER = makeAddr("unpauser"); diff --git a/test/TychoRouter.t.sol b/test/TychoRouter.t.sol new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/test/TychoRouter.t.sol @@ -0,0 +1 @@ + \ No newline at end of file From 5be639e5106f6faffb9b44437d32f0e3e6c6c89b Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 27 Jan 2025 15:18:32 +0000 Subject: [PATCH 6/6] chore(release): 0.17.0 [skip ci] ## [0.17.0](https://github.com/propeller-heads/tycho-execution/compare/0.16.0...0.17.0) (2025-01-27) ### Features * add pause/unpause methods ([c982ed9](https://github.com/propeller-heads/tycho-execution/commit/c982ed99e8bd1a01ec637aa1b9cd2c5ae69ddac4)) ### Bug Fixes * ci ([4ee337d](https://github.com/propeller-heads/tycho-execution/commit/4ee337d1ee3fa5cda7bbec64b760e39028165a60)) * test pauser ([5734b53](https://github.com/propeller-heads/tycho-execution/commit/5734b535548338adcd3a738feb559b5b16105766)) --- CHANGELOG.md | 13 +++++++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d291a5..6f73ca7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +## [0.17.0](https://github.com/propeller-heads/tycho-execution/compare/0.16.0...0.17.0) (2025-01-27) + + +### Features + +* add pause/unpause methods ([c982ed9](https://github.com/propeller-heads/tycho-execution/commit/c982ed99e8bd1a01ec637aa1b9cd2c5ae69ddac4)) + + +### Bug Fixes + +* ci ([4ee337d](https://github.com/propeller-heads/tycho-execution/commit/4ee337d1ee3fa5cda7bbec64b760e39028165a60)) +* test pauser ([5734b53](https://github.com/propeller-heads/tycho-execution/commit/5734b535548338adcd3a738feb559b5b16105766)) + ## [0.16.0](https://github.com/propeller-heads/tycho-execution/compare/0.15.0...0.16.0) (2025-01-27) diff --git a/Cargo.lock b/Cargo.lock index 67969c5..1bfe46c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4163,7 +4163,7 @@ dependencies = [ [[package]] name = "tycho-execution" -version = "0.16.0" +version = "0.17.0" dependencies = [ "alloy", "alloy-primitives", diff --git a/Cargo.toml b/Cargo.toml index ba4c9f2..1065e67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tycho-execution" -version = "0.16.0" +version = "0.17.0" edition = "2021" [dependencies]