Skip to content

Commit 4ac4e45

Browse files
committed
refactor: batch function
1 parent b5df197 commit 4ac4e45

File tree

6 files changed

+59
-185
lines changed

6 files changed

+59
-185
lines changed

Diff for: bun.lockb

466 Bytes
Binary file not shown.

Diff for: remappings.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/
22
@prb/math/=node_modules/@prb/math/
3-
forge-std/=node_modules/forge-std/
4-
solady/=node_modules/solady/
3+
forge-std/=node_modules/forge-std/
4+
solady/=node_modules/solady/

Diff for: src/abstracts/Batch.sol

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
11
// SPDX-License-Identifier: GPL-3.0-or-later
2+
// solhint-disable no-inline-assembly
23
pragma solidity >=0.8.22;
34

45
import { IBatch } from "../interfaces/IBatch.sol";
5-
import { Errors } from "../libraries/Errors.sol";
66

77
/// @title Batch
88
/// @notice See the documentation in {IBatch}.
9-
/// @dev Forked from: https://github.com/boringcrypto/BoringSolidity/blob/master/contracts/BoringBatchable.sol
109
abstract contract Batch is IBatch {
1110
/*//////////////////////////////////////////////////////////////////////////
1211
USER-FACING NON-CONSTANT FUNCTIONS
1312
//////////////////////////////////////////////////////////////////////////*/
1413

1514
/// @inheritdoc IBatch
16-
function batch(bytes[] calldata calls) external payable override {
15+
/// @dev Since `msg.value` can be reused across calls, be VERY CAREFUL when using it. Refer to
16+
/// https://paradigm.xyz/2021/08/two-rights-might-make-a-wrong for more information.
17+
function batch(bytes[] calldata calls) external payable override returns (bytes[] memory results) {
1718
uint256 count = calls.length;
19+
results = new bytes[](count);
1820

1921
for (uint256 i = 0; i < count; ++i) {
2022
(bool success, bytes memory result) = address(this).delegatecall(calls[i]);
23+
24+
// Check: If the delegatecall failed, load and bubble up the revert data.
2125
if (!success) {
22-
revert Errors.BatchError(result);
26+
assembly {
27+
// Get the length of the result stored in the first 32 bytes.
28+
let resultSize := mload(result)
29+
30+
// Forward the pointer by 32 bytes to skip the length argument, and revert with the result.
31+
revert(add(32, result), resultSize)
32+
}
2333
}
34+
35+
// Push the result into the results array.
36+
results[i] = result;
2437
}
2538
}
2639
}

Diff for: src/interfaces/IBatch.sol

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ pragma solidity >=0.8.22;
33

44
/// @notice This contract implements logic to batch call any function.
55
interface IBatch {
6-
/// @notice Allows batched call to self, `this` contract.
6+
/// @notice Allows batched calls to self, i.e., `this` contract.
7+
/// @dev Since `msg.value` can be reused across calls, be VERY CAREFUL when using it. Refer to
8+
/// https://paradigm.xyz/2021/08/two-rights-might-make-a-wrong for more information.
79
/// @param calls An array of inputs for each call.
8-
function batch(bytes[] calldata calls) external payable;
10+
/// @return results An array of results from each call. Empty when the calls do not return anything.
11+
function batch(bytes[] calldata calls) external payable returns (bytes[] memory results);
912
}

Diff for: tests/fork/Fork.t.sol

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pragma solidity >=0.8.22;
33

44
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
55
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
6-
import { ISablierFlow } from "src/interfaces/ISablierFlow.sol";
76
import { SablierFlow } from "src/SablierFlow.sol";
87

98
import { Base_Test } from "../Base.t.sol";

0 commit comments

Comments
 (0)