-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: batch function * test: add a payable test for batch
- Loading branch information
1 parent
b5df197
commit f06873d
Showing
5 changed files
with
63 additions
and
186 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 |
---|---|---|
@@ -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 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 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
Oops, something went wrong.