Skip to content

Commit

Permalink
Merge branch 'flashbots:main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
pistomat authored Jul 1, 2024
2 parents 03ad8ea + 1951066 commit d4ef704
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
15 changes: 15 additions & 0 deletions src/protocols/Builder/Session.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ contract Session is Test {
bytes memory root = HexStrings.fromHexString(HexStrings.stripQuotesAndPrefix(output.at('"root"').value()));
}

function doCall(address target, bytes memory data) public returns (bytes memory) {
bytes memory encodedRequest = abi.encodePacked(
'{"to":"', LibString.toHexStringChecksummed(target), '","data":"', LibString.toHexString(data), '"}'
);
return doCall(encodedRequest);
}

function doCall(bytes memory encodedRequest) public returns (bytes memory) {
bytes memory input = abi.encodePacked(session, ",", encodedRequest);
JSONParserLib.Item memory item = callImpl("call", input);

bytes memory result = HexStrings.fromHexString(HexStrings.stripQuotesAndPrefix(item.value()));
return result;
}

function callImpl(string memory method, bytes memory args) internal returns (JSONParserLib.Item memory) {
Suave.HttpRequest memory request;
request.method = "POST";
Expand Down
18 changes: 13 additions & 5 deletions src/protocols/Bundle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ library Bundle {
return Suave.doHTTPRequest(request);
}

function encodeBundle(BundleObj memory args) internal pure returns (Suave.HttpRequest memory) {
require(args.txns.length > 0, "Bundle: no txns");

bytes memory params =
abi.encodePacked('{"blockNumber": "', LibString.toHexString(args.blockNumber), '", "txs": [');
/// @notice encode a bundle in json format.
/// @param args the bundle to encode.
/// @return params JSON-encoded bytes: `{blockNumber, txs, minTimestamp, maxTimestamp}`
function encodeBundleParams(BundleObj memory args) internal pure returns (bytes memory params) {
params = abi.encodePacked('{"blockNumber": "', LibString.toMinimalHexString(args.blockNumber), '", "txs": [');
for (uint256 i = 0; i < args.txns.length; i++) {
params = abi.encodePacked(params, '"', LibString.toHexString(args.txns[i]), '"');
if (i < args.txns.length - 1) {
Expand All @@ -53,7 +53,15 @@ library Bundle {
params = abi.encodePacked(params, ', "maxTimestamp": ', LibString.toString(args.maxTimestamp));
}
params = abi.encodePacked(params, "}");
}

/// @notice encode a call to `eth_sendBundle` as an HttpRequest.
/// @param args the bundle to encode.
/// @return request the HttpRequest to send the bundle.
function encodeBundle(BundleObj memory args) internal pure returns (Suave.HttpRequest memory) {
require(args.txns.length > 0, "Bundle: no txns");

bytes memory params = encodeBundleParams(args);
bytes memory body =
abi.encodePacked('{"jsonrpc":"2.0","method":"eth_sendBundle","params":[', params, '],"id":1}');

Expand Down
2 changes: 2 additions & 0 deletions src/suavelib/Suave.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ library Suave {
/// @param headers HTTP Headers
/// @param body Body of the request (if Post or Put)
/// @param withFlashbotsSignature Whether to include the Flashbots signature
/// @param timeout Timeout of the request in milliseconds
struct HttpRequest {
string url;
string method;
string[] headers;
bytes body;
bool withFlashbotsSignature;
uint64 timeout;
}

/// @notice Result of a simulated transaction.
Expand Down
6 changes: 3 additions & 3 deletions test/protocols/Bundle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract EthSendBundle is Test {
Suave.HttpRequest memory request = Bundle.encodeBundle(bundle);
assertEq(
string(request.body),
'{"jsonrpc":"2.0","method":"eth_sendBundle","params":[{"blockNumber": "0x01", "txs": ["0x1234"]}],"id":1}'
'{"jsonrpc":"2.0","method":"eth_sendBundle","params":[{"blockNumber": "0x1", "txs": ["0x1234"]}],"id":1}'
);
assertTrue(request.withFlashbotsSignature);

Expand All @@ -28,7 +28,7 @@ contract EthSendBundle is Test {
Suave.HttpRequest memory request2 = Bundle.encodeBundle(bundle);
assertEq(
string(request2.body),
'{"jsonrpc":"2.0","method":"eth_sendBundle","params":[{"blockNumber": "0x01", "txs": ["0x1234"], "minTimestamp": 2}],"id":1}'
'{"jsonrpc":"2.0","method":"eth_sendBundle","params":[{"blockNumber": "0x1", "txs": ["0x1234"], "minTimestamp": 2}],"id":1}'
);

// encode with 'maxTimestamp'
Expand All @@ -37,7 +37,7 @@ contract EthSendBundle is Test {
Suave.HttpRequest memory request3 = Bundle.encodeBundle(bundle);
assertEq(
string(request3.body),
'{"jsonrpc":"2.0","method":"eth_sendBundle","params":[{"blockNumber": "0x01", "txs": ["0x1234"], "minTimestamp": 2, "maxTimestamp": 3}],"id":1}'
'{"jsonrpc":"2.0","method":"eth_sendBundle","params":[{"blockNumber": "0x1", "txs": ["0x1234"], "minTimestamp": 2, "maxTimestamp": 3}],"id":1}'
);
}

Expand Down
7 changes: 7 additions & 0 deletions tools/docs-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ func readForgeArtifacts(path string) ([]*artifact, error) {
if d.IsDir() {
return nil
}

// ignore if parent directory doesn't end w/ ".sol"
parentDir := filepath.Base(filepath.Dir(path))
if !strings.HasSuffix(parentDir, ".sol") {
return nil
}

ext := filepath.Ext(d.Name())
if ext != ".json" {
return nil
Expand Down

0 comments on commit d4ef704

Please sign in to comment.