-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow batch transactions using multicall in the GNS (#485)
Add multicall for batched calls to the GNS By using a multicall a user can batch multiple operations into a single transaction. An example of this is if the owner publishing a subgraph decides to mint some signal on that subgraph. * Use convenience token utils for transferring tokens * Reduce bytecode by using an inline function for access * Introduce a multicall abstract contract for batch calls * Add security tests to multicall
- Loading branch information
Showing
5 changed files
with
154 additions
and
31 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
pragma solidity ^0.7.3; | ||
pragma experimental ABIEncoderV2; | ||
|
||
/** | ||
* @title Multicall interface | ||
* @notice Enables calling multiple methods in a single call to the contract | ||
*/ | ||
interface IMulticall { | ||
/** | ||
* @notice Call multiple functions in the current contract and return the data from all of them if they all succeed | ||
* @param data The encoded function data for each of the calls to make to this contract | ||
* @return results The results from each of the calls passed in via data | ||
*/ | ||
function multicall(bytes[] calldata data) external returns (bytes[] memory results); | ||
} |
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,34 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
pragma solidity ^0.7.3; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import "./IMulticall.sol"; | ||
|
||
// Inspired by https://github.com/Uniswap/uniswap-v3-periphery/blob/main/contracts/base/Multicall.sol | ||
// Note: Removed payable from the multicall | ||
|
||
/** | ||
* @title Multicall | ||
* @notice Enables calling multiple methods in a single call to the contract | ||
*/ | ||
abstract contract Multicall is IMulticall { | ||
/// @inheritdoc IMulticall | ||
function multicall(bytes[] calldata data) external override returns (bytes[] memory results) { | ||
results = new bytes[](data.length); | ||
for (uint256 i = 0; i < data.length; i++) { | ||
(bool success, bytes memory result) = address(this).delegatecall(data[i]); | ||
|
||
if (!success) { | ||
// Next 5 lines from https://ethereum.stackexchange.com/a/83577 | ||
if (result.length < 68) revert(); | ||
assembly { | ||
result := add(result, 0x04) | ||
} | ||
revert(abi.decode(result, (string))); | ||
} | ||
|
||
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
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