This repository was archived by the owner on Apr 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
refactor: batch function #358
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| @openzeppelin/contracts/=node_modules/@openzeppelin/contracts/ | ||
| @prb/math/=node_modules/@prb/math/ | ||
| forge-std/=node_modules/forge-std/ | ||
| solady/=node_modules/solady/ | ||
| forge-std/=node_modules/forge-std/ | ||
| solady/=node_modules/solady/ |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,26 +1,39 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| // solhint-disable no-inline-assembly | ||
| pragma solidity >=0.8.22; | ||
|
|
||
| import { IBatch } from "../interfaces/IBatch.sol"; | ||
| import { Errors } from "../libraries/Errors.sol"; | ||
|
|
||
| /// @title Batch | ||
| /// @notice See the documentation in {IBatch}. | ||
| /// @dev Forked from: https://github.com/boringcrypto/BoringSolidity/blob/master/contracts/BoringBatchable.sol | ||
| abstract contract Batch is IBatch { | ||
| /*////////////////////////////////////////////////////////////////////////// | ||
| USER-FACING NON-CONSTANT FUNCTIONS | ||
| //////////////////////////////////////////////////////////////////////////*/ | ||
|
|
||
| /// @inheritdoc IBatch | ||
| function batch(bytes[] calldata calls) external payable override { | ||
| /// @dev Since `msg.value` can be reused across calls, be VERY CAREFUL when using it. Refer to | ||
| /// https://paradigm.xyz/2021/08/two-rights-might-make-a-wrong for more information. | ||
| function batch(bytes[] calldata calls) external payable override returns (bytes[] memory results) { | ||
| uint256 count = calls.length; | ||
| results = new bytes[](count); | ||
|
|
||
| for (uint256 i = 0; i < count; ++i) { | ||
| (bool success, bytes memory result) = address(this).delegatecall(calls[i]); | ||
|
|
||
| // Check: If the delegatecall failed, load and bubble up the revert data. | ||
| if (!success) { | ||
| revert Errors.BatchError(result); | ||
| assembly { | ||
| // Get the length of the result stored in the first 32 bytes. | ||
| let resultSize := mload(result) | ||
|
|
||
| // Forward the pointer by 32 bytes to skip the length argument, and revert with the result. | ||
| revert(add(32, result), resultSize) | ||
| } | ||
| } | ||
|
|
||
| // Push the result into the results array. | ||
| results[i] = result; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.