diff --git a/.github/workflows/slither.yml b/.github/workflows/slither.yml index 55a9f72..4134b29 100644 --- a/.github/workflows/slither.yml +++ b/.github/workflows/slither.yml @@ -13,4 +13,5 @@ jobs: - uses: actions/checkout@v4 - uses: crytic/slither-action@v0.4.0 with: - target: 'foundry/' \ No newline at end of file + target: 'foundry/' + slither-args: '--filter-paths foundry/lib/' \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b61da93 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "foundry/lib/openzeppelin-contracts"] + path = foundry/lib/openzeppelin-contracts + url = https://github.com/OpenZeppelin/openzeppelin-contracts +[submodule "foundry/lib/permit2"] + path = foundry/lib/permit2 + url = https://github.com/Uniswap/permit2 diff --git a/foundry/lib/openzeppelin-contracts b/foundry/lib/openzeppelin-contracts new file mode 160000 index 0000000..acd4ff7 --- /dev/null +++ b/foundry/lib/openzeppelin-contracts @@ -0,0 +1 @@ +Subproject commit acd4ff74de833399287ed6b31b4debf6b2b35527 diff --git a/foundry/lib/permit2 b/foundry/lib/permit2 new file mode 160000 index 0000000..cc56ad0 --- /dev/null +++ b/foundry/lib/permit2 @@ -0,0 +1 @@ +Subproject commit cc56ad0f3439c502c246fc5cfcc3db92bb8b7219 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(); + } +}