From ab28a4730dbdd9d2eb5523b0cadfffdb18569618 Mon Sep 17 00:00:00 2001 From: TAMARA LIPOWSKI Date: Mon, 20 Jan 2025 17:21:46 -0500 Subject: [PATCH] feat: initial TychoRouter skeleton - remappings.txt is used for more elegant imports - decided not to include all helper methods in skeleton - just main swap method. They are properly documented in the jira tasks. - add filter-paths to slither to exclude submodules, otherwise we will get slither warnings about permit2 and open-zeppelin using different solidity versions: ``` - Version constraint ^0.8.20 is used by: -^0.8.20 (lib/openzeppelin-contracts/contracts/access/AccessControl.sol#4) -^0.8.20 (lib/openzeppelin-contracts/contracts/access/IAccessControl.sol#4) -^0.8.20 (lib/openzeppelin-contracts/contracts/utils/Context.sol#4) -^0.8.20 (lib/openzeppelin-contracts/contracts/utils/introspection/ERC165.sol#4) -^0.8.20 (lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol#4) - Version constraint ^0.8.0 is used by: -^0.8.0 (lib/permit2/src/interfaces/IAllowanceTransfer.sol#2) -^0.8.0 (lib/permit2/src/interfaces/IEIP712.sol#2) - Version constraint ^0.8.28 is used by: ``` --- foundry/remappings.txt | 3 ++ foundry/slither.config.json | 3 ++ foundry/src/TychoRouter.sol | 66 ++++++++++++++++++++++++++++++++-- foundry/test/TychoRouter.t.sol | 19 ++++++++++ 4 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 foundry/remappings.txt create mode 100644 foundry/slither.config.json create mode 100644 foundry/test/TychoRouter.t.sol diff --git a/foundry/remappings.txt b/foundry/remappings.txt new file mode 100644 index 0000000..f1fbdf6 --- /dev/null +++ b/foundry/remappings.txt @@ -0,0 +1,3 @@ +@openzeppelin/=lib/openzeppelin-contracts/ +@permit2/=lib/permit2/ +@src/=src/ \ No newline at end of file diff --git a/foundry/slither.config.json b/foundry/slither.config.json new file mode 100644 index 0000000..fd69b55 --- /dev/null +++ b/foundry/slither.config.json @@ -0,0 +1,3 @@ +{ + "filter_paths": "lib" +} \ No newline at end of file diff --git a/foundry/src/TychoRouter.sol b/foundry/src/TychoRouter.sol index 36034d4..f63a780 100644 --- a/foundry/src/TychoRouter.sol +++ b/foundry/src/TychoRouter.sol @@ -1,6 +1,68 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.28; -contract TychoRouter { - constructor() {} +import "@openzeppelin/contracts/access/AccessControl.sol"; +import "@permit2/src/interfaces/IAllowanceTransfer.sol"; + +contract TychoRouter is AccessControl { + IAllowanceTransfer public immutable permit2; + + //keccak256("NAME_OF_ROLE") : save gas on deployment + bytes32 public constant EXECUTOR_SETTER_ROLE = + 0x6a1dd52dcad5bd732e45b6af4e7344fa284e2d7d4b23b5b09cb55d36b0685c87; + bytes32 public constant FEE_SETTER_ROLE = + 0xe6ad9a47fbda1dc18de1eb5eeb7d935e5e81b4748f3cfc61e233e64f88182060; + bytes32 public constant PAUSER_ROLE = + 0x65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a; + bytes32 public constant FUND_RESCUER_ROLE = + 0x912e45d663a6f4cc1d0491d8f046e06c616f40352565ea1cdb86a0e1aaefa41b; + + constructor(address _permit2) { + permit2 = IAllowanceTransfer(_permit2); + _grantRole(DEFAULT_ADMIN_ROLE, msg.sender); + } + + /** + * @dev We use the fallback function to allow flexibility on callback. + * This function will delegate call a verifier contract and should revert if the + * caller is not a pool. + */ + fallback() external { + // TODO execute generic callback + } + + /** + * @dev Executes a swap graph supporting internal splits token amount + * splits, checking that the user gets more than minUserAmount of buyToken. + */ + function swap( + uint256 amountIn, + address tokenIn, + uint256 minUserAmount, + bool wrapEth, + bool unwrapEth, + uint256 nTokens, + bytes calldata swaps, + IAllowanceTransfer.PermitSingle calldata permitSingle, + bytes calldata signature + ) external returns (uint256 amountOut) { + amountOut = 0; + // TODO + } + + /** + * @dev Allows granting roles to multiple accounts in a single call. + */ + function batchGrantRole(bytes32 role, address[] memory accounts) + external + onlyRole(DEFAULT_ADMIN_ROLE) + { + // TODO + } + + /** + * @dev Allows this contract to receive native token + */ + // TODO Uncomment once withdraw method is implemented - or else Slither fails + // receive() external payable {} } diff --git a/foundry/test/TychoRouter.t.sol b/foundry/test/TychoRouter.t.sol new file mode 100644 index 0000000..3f28459 --- /dev/null +++ b/foundry/test/TychoRouter.t.sol @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.28; + +import {Test, console} from "forge-std/Test.sol"; +import {TychoRouter} from "@src/TychoRouter.sol"; + +contract TychoRouterTest is Test { + TychoRouter public tychoRouter; + + function setupTychoRouter() public { + address permit2Address = + address(0x000000000022D473030F116dDEE9F6B43aC78BA3); + tychoRouter = new TychoRouter(permit2Address); + } + + function testSetupTychoRouter() public { + setupTychoRouter(); + } +}