forked from Uniswap/universal-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
82 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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,9 @@ | ||
# narwhal | ||
|
||
## Usage | ||
|
||
``` | ||
forge install | ||
forge build | ||
forge test | ||
``` |
This file contains 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 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 was deleted.
Oops, something went wrong.
This file contains 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,18 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.15; | ||
|
||
contract Router { | ||
struct ModuleCall { | ||
address module; | ||
bytes data; | ||
} | ||
|
||
function route(ModuleCall[] calldata calls) external { | ||
for (uint256 i = 0; i < calls.length; i++) { | ||
(bool success, bytes memory resultData) = calls[i].module.delegatecall(calls[i].data); | ||
if (!success) assembly { | ||
revert(add(resultData, 32), mload(resultData)) | ||
} | ||
} | ||
} | ||
} |
This file contains 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,16 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.15; | ||
|
||
contract ExampleModule { | ||
event ExampleModuleEvent(string message); | ||
|
||
error CauseRevert(); | ||
|
||
function logEvent() public { | ||
emit ExampleModuleEvent('testEvent'); | ||
} | ||
|
||
function causeRevert() public pure { | ||
revert CauseRevert(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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,32 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.15; | ||
|
||
import 'forge-std/Test.sol'; | ||
import {Router} from '../src/Router.sol'; | ||
import {ExampleModule} from '../src/modules/ExampleModule.sol'; | ||
|
||
contract RouterTest is Test { | ||
Router router; | ||
ExampleModule testModule; | ||
Router.ModuleCall[] calls; | ||
|
||
function setUp() public { | ||
router = new Router(); | ||
testModule = new ExampleModule(); | ||
} | ||
|
||
event ExampleModuleEvent(string message); | ||
|
||
function testCallModule() public { | ||
calls.push(Router.ModuleCall(address(testModule), abi.encode(testModule.logEvent.selector))); | ||
vm.expectEmit(false, false, false, true); | ||
emit ExampleModuleEvent('testEvent'); | ||
router.route(calls); | ||
} | ||
|
||
function testModuleRevert() public { | ||
calls.push(Router.ModuleCall(address(testModule), abi.encode(testModule.causeRevert.selector))); | ||
vm.expectRevert(ExampleModule.CauseRevert.selector); | ||
router.route(calls); | ||
} | ||
} |