Skip to content

Commit

Permalink
forge fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ephess committed Jan 8, 2024
1 parent dd94852 commit bcff934
Show file tree
Hide file tree
Showing 8 changed files with 427 additions and 416 deletions.
465 changes: 242 additions & 223 deletions contracts/auction-handler/FastLaneAuctionHandler.sol

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/interfaces/IPaymentProcessor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ interface IPaymentProcessor {
uint256 totalAmount,
bytes calldata data
) external;
}
}
15 changes: 7 additions & 8 deletions contracts/interfaces/IWMatic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ interface WMATIC {
event Transfer(address indexed src, address indexed dst, uint256 wad);
event Withdrawal(address indexed src, uint256 wad);

function allowance(address, address) view external returns (uint256);
function allowance(address, address) external view returns (uint256);
function approve(address guy, uint256 wad) external returns (bool);
function balanceOf(address) view external returns (uint256);
function decimals() view external returns (uint8);
function deposit() payable external;
function name() view external returns (string memory);
function symbol() view external returns (string memory);
function totalSupply() view external returns (uint256);
function balanceOf(address) external view returns (uint256);
function decimals() external view returns (uint8);
function deposit() external payable;
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function totalSupply() external view returns (uint256);
function transfer(address dst, uint256 wad) external returns (bool);
function transferFrom(address src, address dst, uint256 wad) external returns (bool);
function withdraw(uint256 wad) external;
}

57 changes: 30 additions & 27 deletions contracts/searcher-direct/FastLaneSearcherDirect.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.16;

import { ReentrancyGuard } from "solmate/utils/ReentrancyGuard.sol";
import {ReentrancyGuard} from "solmate/utils/ReentrancyGuard.sol";
import "openzeppelin-contracts/contracts/utils/Strings.sol";

abstract contract FastLaneSearcherDirectContract is ReentrancyGuard {

address public owner;
address payable private PFLAuction;

Expand All @@ -25,30 +24,36 @@ abstract contract FastLaneSearcherDirectContract is ReentrancyGuard {
// PFL will pass along the original msg.sender as _sender for the searcher to do additional checks
// Do NOT forget `onlyRelayer` and `checkFastLaneEOA(_sender);` or ANYONE will be able to call your contract with arbitrary calldata
function fastLaneCall(
address _sender, // Relay will always set this to msg.sender that called it. Ideally you (owner) or an approvedEOA.
uint256 _bidAmount,
bytes calldata _searcherCallData // contains func selector and calldata for your MEV transaction ie: abi.encodeWithSignature("doStuff(address,uint256)", 0xF00, 1212);
address _sender, // Relay will always set this to msg.sender that called it. Ideally you (owner) or an approvedEOA.
uint256 _bidAmount,
bytes calldata _searcherCallData // contains func selector and calldata for your MEV transaction ie: abi.encodeWithSignature("doStuff(address,uint256)", 0xF00, 1212);
) external payable onlyRelayer nonReentrant returns (bool, bytes memory) {

// Make sure it's your own EOA that's calling your contract
// Make sure it's your own EOA that's calling your contract
checkFastLaneEOA(_sender);

// Execute the searcher's intended function
(bool success, bytes memory returnedData) = address(this).call(_searcherCallData);

// If the call didn't turn out the way you wanted, revert either here or inside your MEV function itself
if (!success) {
return (false, returnedData);
}

// Balance check then Repay PFL at the end
require(
(address(this).balance >= _bidAmount),
string(abi.encodePacked("SearcherInsufficientFunds ", Strings.toString(_bidAmount), " ", Strings.toString(address(this).balance)))
(address(this).balance >= _bidAmount),
string(
abi.encodePacked(
"SearcherInsufficientFunds ",
Strings.toString(_bidAmount),
" ",
Strings.toString(address(this).balance)
)
)
);

safeTransferETH(PFLAuction, _bidAmount);

// /!\ Important to return success true or relay will revert.
// In case of success == false, `returnedData` will be used as revert message that can be decoded with `.humanizeError()`
return (success, returnedData);
Expand Down Expand Up @@ -83,7 +88,7 @@ abstract contract FastLaneSearcherDirectContract is ReentrancyGuard {
approvedEOAs[_eoaAddress] = false;
}

function checkFastLaneEOA(address _eoaAddress) view internal {
function checkFastLaneEOA(address _eoaAddress) internal view {
require(approvedEOAs[_eoaAddress] || _eoaAddress == owner, "SenderEOANotApproved");
}

Expand All @@ -92,34 +97,32 @@ abstract contract FastLaneSearcherDirectContract is ReentrancyGuard {
}

// Be aware with a fallback fn that:
// `address(this).call(_searcherCallData);`
// Will hit this if _searcherCallData function is not implemented.
// `address(this).call(_searcherCallData);`
// Will hit this if _searcherCallData function is not implemented.
// And success will be true.
fallback() external payable {

}
fallback() external payable {}
receive() external payable {}

modifier onlyRelayer {
if (!isTrustedForwarder(msg.sender)) revert("InvalidPermissions");
_;
}
modifier onlyRelayer() {
if (!isTrustedForwarder(msg.sender)) revert("InvalidPermissions");
_;
}
}

contract SearcherContractExample is FastLaneSearcherDirectContract {
// Your own MEV contract / functions here
// Your own MEV contract / functions here
// NOTE: its security checks must be compatible w/ calls from the FastLane Auction Contract

address public anAddress; // just a var to change for the placeholder MEV function
uint256 public anAmount; // another var to change for the placeholder MEV function

function doStuff(address _anAddress, uint256 _anAmount) public payable returns (bool) {
// NOTE: this function can't be external as the FastLaneCall func will call it internally
if (msg.sender != address(this)) {
if (msg.sender != address(this)) {
// NOTE: msg.sender becomes address(this) if using call from inside contract per above example in `fasfastLaneCall`
require(approvedEOAs[msg.sender], "SenderEOANotApproved");
}

// Do MEV stuff here
// placeholder
anAddress = _anAddress;
Expand All @@ -129,13 +132,13 @@ contract SearcherContractExample is FastLaneSearcherDirectContract {
}

function doFail() public payable {
if (msg.sender != address(this)) {
if (msg.sender != address(this)) {
// NOTE: msg.sender becomes address(this) if using call from inside contract per above example in `fasfastLaneCall`
require(approvedEOAs[msg.sender], "SenderEOANotApproved");
}
// Will cause Error(string) of: 0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f4641494c5f4f4e5f505552504f53450000000000000000000000000000000000
// to bubble up to the relay contract.
// Use the read function `FastLaneRelay.humanizeError(bytes error)` to get a human readable version of an error should your searcher contract fail on a require.
require(false,"FAIL_ON_PURPOSE");
require(false, "FAIL_ON_PURPOSE");
}
}
}
47 changes: 25 additions & 22 deletions contracts/searcher-proxy/FastLaneSearcherProxy.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.16;

import { ReentrancyGuard } from "solmate/utils/ReentrancyGuard.sol";
import {ReentrancyGuard} from "solmate/utils/ReentrancyGuard.sol";
import "openzeppelin-contracts/contracts/utils/Strings.sol";

contract FastLaneSearcherProxyContract is ReentrancyGuard {

address public owner;
address payable private PFLAuction;
address payable private searcherContract;
Expand All @@ -27,32 +26,38 @@ contract FastLaneSearcherProxyContract is ReentrancyGuard {
// PFL will pass along the original msg.sender as _sender for the searcher to do additional checks
// Do NOT forget `onlyRelayer` and `checkFastLaneEOA(_sender);` or ANYONE will be able to call your contract with arbitrary calldata
function fastLaneCall(
address _sender, // Relay will always set this to msg.sender that called it. Ideally you (owner) or an approvedEOA.
uint256 _bidAmount,
bytes calldata _searcherCallData // contains func selector and calldata for your MEV transaction ie: abi.encodeWithSignature("doStuff(address,uint256)", 0xF00, 1212);
address _sender, // Relay will always set this to msg.sender that called it. Ideally you (owner) or an approvedEOA.
uint256 _bidAmount,
bytes calldata _searcherCallData // contains func selector and calldata for your MEV transaction ie: abi.encodeWithSignature("doStuff(address,uint256)", 0xF00, 1212);
) external payable onlyRelayer nonReentrant returns (bool, bytes memory) {

// Make sure it's your own EOA that's calling your contract
// Make sure it's your own EOA that's calling your contract
checkFastLaneEOA(_sender);

// Execute the searcher's intended function
// /!\ Don't forget to whitelist `searcherContract` called function
// to allow this contract.
(bool success, bytes memory returnedData) = searcherContract.call(_searcherCallData);

// If the call didn't turn out the way you wanted, revert either here or inside your MEV function itself
if (!success) {
return (false, returnedData);
}

// Balance check then pay FastLane Auction Handler contract at the end
require(
(address(this).balance >= _bidAmount),
string(abi.encodePacked("SearcherInsufficientFunds ", Strings.toString(_bidAmount), " ", Strings.toString(address(this).balance)))
(address(this).balance >= _bidAmount),
string(
abi.encodePacked(
"SearcherInsufficientFunds ",
Strings.toString(_bidAmount),
" ",
Strings.toString(address(this).balance)
)
)
);

safeTransferETH(PFLAuction, _bidAmount);

// /!\ Important to return success true or relay will revert.
// In case of success == false, `returnedData` will be used as revert message that can be decoded with `.humanizeError()`
return (success, returnedData);
Expand Down Expand Up @@ -92,7 +97,7 @@ contract FastLaneSearcherProxyContract is ReentrancyGuard {
approvedEOAs[_eoaAddress] = false;
}

function checkFastLaneEOA(address _eoaAddress) view internal {
function checkFastLaneEOA(address _eoaAddress) internal view {
require(approvedEOAs[_eoaAddress] || _eoaAddress == owner, "SenderEOANotApproved");
}

Expand All @@ -101,16 +106,14 @@ contract FastLaneSearcherProxyContract is ReentrancyGuard {
}

// Be aware with a fallback fn that:
// `address(this).call(_searcherCallData);`
// Will hit this if _searcherCallData function is not implemented.
// `address(this).call(_searcherCallData);`
// Will hit this if _searcherCallData function is not implemented.
// And success will be true.
fallback() external payable {

}
fallback() external payable {}
receive() external payable {}

modifier onlyRelayer {
if (!isTrustedForwarder(msg.sender)) revert("InvalidPermissions");
_;
}
}
modifier onlyRelayer() {
if (!isTrustedForwarder(msg.sender)) revert("InvalidPermissions");
_;
}
}
9 changes: 1 addition & 8 deletions script/EOADeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@ import "forge-std/Script.sol";
import {FastLaneAuctionHandler} from "../contracts/auction-handler/FastLaneAuctionHandler.sol";

contract Deploy is Script {


address public fastlane;

mapping(uint256 => address) public gelatoOpsAddresses;
mapping(uint256 => address) public wrappedNativeAddresses;


function getArgs() public view returns (address initial_bid_token, address ops) {
ops = gelatoOpsAddresses[block.chainid];
initial_bid_token = wrappedNativeAddresses[block.chainid];
}

function run() public {

gelatoOpsAddresses[1] = 0xB3f5503f93d5Ef84b06993a1975B9D21B962892F;
gelatoOpsAddresses[137] = 0x527a819db1eb0e34426297b03bae11F2f8B3A19E;
gelatoOpsAddresses[80001] = 0xB3f5503f93d5Ef84b06993a1975B9D21B962892F;
Expand All @@ -32,10 +28,8 @@ contract Deploy is Script {
wrappedNativeAddresses[80001] = 0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889;
wrappedNativeAddresses[31337] = 0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889;


(address initial_bid_token, address ops) = getArgs();


require(ops != address(0), "O(o)ps");
require(initial_bid_token != address(0), "Wrapped");

Expand All @@ -48,5 +42,4 @@ contract Deploy is Script {

console2.log(fastlane);
}

}
}
Loading

0 comments on commit bcff934

Please sign in to comment.