-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(world): add batchCallFrom
#1594
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8a6d389
rename CallBatch to BatchCall
alvrs c869e5e
add batchCallFrom
alvrs 2986769
install batchCallFrom
alvrs af1d205
add tests for batch call from
alvrs d66fab2
Create serious-plants-itch.md
alvrs 558222c
update gas report
alvrs 2028558
prettier
alvrs 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 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
"@latticexyz/world": major | ||
--- | ||
|
||
- `IBaseWorld` now has a `batchCallFrom` method, which allows system calls via `callFrom` to be executed in batch. | ||
|
||
```solidity | ||
import { SystemCallFromData } from "@latticexyz/world/modules/core/types.sol"; | ||
|
||
interface IBaseWorld { | ||
function batchCallFrom(SystemCallFromData[] calldata systemCalls) external returns (bytes[] memory returnDatas); | ||
} | ||
``` | ||
|
||
- The `callBatch` method of `IBaseWorld` has been renamed to `batchCall` to align better with the `batchCallFrom` method. | ||
|
||
```diff | ||
interface IBaseWorld { | ||
- function callBatch(SystemCallData[] calldata systemCalls) external returns (bytes[] memory returnDatas); | ||
+ function batchCall(SystemCallData[] calldata systemCalls) external returns (bytes[] memory returnDatas); | ||
} | ||
``` |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
packages/world/src/codegen/interfaces/IBatchCallSystem.sol
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
packages/world/src/codegen/interfaces/ICallBatchSystem.sol
This file was deleted.
Oops, something went wrong.
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
44 changes: 44 additions & 0 deletions
44
packages/world/src/modules/core/implementations/BatchCallSystem.sol
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0; | ||
|
||
import { System } from "../../../System.sol"; | ||
import { IBaseWorld } from "../../../codegen/interfaces/IBaseWorld.sol"; | ||
import { revertWithBytes } from "../../../revertWithBytes.sol"; | ||
|
||
import { SystemCallData, SystemCallFromData } from "../types.sol"; | ||
|
||
contract BatchCallSystem is System { | ||
/** | ||
* Batch calls to multiple systems into a single transaction, return the array of return data. | ||
*/ | ||
function batchCall(SystemCallData[] calldata systemCalls) public returns (bytes[] memory returnDatas) { | ||
IBaseWorld world = IBaseWorld(_world()); | ||
returnDatas = new bytes[](systemCalls.length); | ||
|
||
for (uint256 i; i < systemCalls.length; i++) { | ||
(bool success, bytes memory returnData) = address(world).delegatecall( | ||
abi.encodeCall(world.call, (systemCalls[i].systemId, systemCalls[i].callData)) | ||
); | ||
if (!success) revertWithBytes(returnData); | ||
|
||
returnDatas[i] = abi.decode(returnData, (bytes)); | ||
} | ||
} | ||
|
||
/** | ||
* Batch calls to multiple systems into a single transaction, return the array of return data. | ||
*/ | ||
function batchCallFrom(SystemCallFromData[] calldata systemCalls) public returns (bytes[] memory returnDatas) { | ||
IBaseWorld world = IBaseWorld(_world()); | ||
returnDatas = new bytes[](systemCalls.length); | ||
|
||
for (uint256 i; i < systemCalls.length; i++) { | ||
(bool success, bytes memory returnData) = address(world).delegatecall( | ||
abi.encodeCall(world.callFrom, (systemCalls[i].from, systemCalls[i].systemId, systemCalls[i].callData)) | ||
); | ||
if (!success) revertWithBytes(returnData); | ||
|
||
returnDatas[i] = abi.decode(returnData, (bytes)); | ||
} | ||
} | ||
} |
27 changes: 0 additions & 27 deletions
27
packages/world/src/modules/core/implementations/CallBatchSystem.sol
This file was deleted.
Oops, something went wrong.
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably best to go with this approach for extensibility/flexibility, but I wonder how often we'll want to batch call from different addresses vs the signature being
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to get that you can do this: