-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Multicall module #2558
Comments
Interesting, will tackle it! |
could be interresting to use |
FYI: There is a proposal that multicall like design could be used to implement callbacks mechanism that are missing to ERC20.
|
Everyone seems to easily confuse this contract with a |
There is The variation with a callback at the end was my idea, but after tinkering with this and with EIP2271 in the horizon I don't think it would be worth it. Too rigid and complex of a pattern. |
The BoringBatchable seems to have a better multicall. Actually, I'm planning to work on a multicall provider (ethers-io/ethers.js#788). I think it would be helpful if the multicall function allows to not entirely revert if a single call fails. |
IMO neither option is better than the other, they offer different semantics that will be more appropriate in different scenarios. It seems to me that calling all functions regardless of reverts is more appropriate for queries. Given that the For querying it's also not necessary to have multicall embedded in the target contract, a separate "multisend" contract can be used as a forwarding proxy. |
One counter here is that there are times when you'd want to batch mutating function calls, but don't want everything to revert if one fails. For example, say this was integrated into a system like Compound and I want to batch these three transactions:
But if claiming COMP fails (e.g. the Comptroller has insufficient balance to give me the COMP I'm owed), I still want transactions 1 and 2 to succeed. Given that, another option I wanted to throw out is a pattern like the below so you can explicitly specify which transaction can be safely ignored on failure: /// @notice Required parameters for each call
struct Call {
bytes data; // calldata to use
bool requireSuccess; // true if whole tx should revert on failure, false if we ignore when this call fails
}
/// @notice When a call fails, but has requireSuccess as false, emit a failure log with the call's index
event CallFailed(uint256 callIndex);
/// @notice Batch multiple calls to this contract
function multicall(Call[] memory calls) external payable returns (bytes[] memory) {
bytes[] memory returnData = new bytes[](calls.length);
for (uint256 i = 0; i < calls.length; i++) {
(bool success, bytes memory response) = address(this).delegatecall(calls[i].data);
if (!success && calls[i].requireSuccess) {
revert(getRevertMessage(response));
} else if (!success) {
emit CallFailed(i); // don't revert, but emit failure log to make it easier to identify failed calls
}
returnData[i] = response;
}
return returnData;
} |
There are clearly cases in which you want to revert on ANY failure and cases where you want to ignore reverts. BoringBatchable has a |
Thanks everyone for the input. We understand that there will be use cases that would benefit from ignoring reverts, but we still think that the default of failing on reverts will be what's needed in most cases, and it is very clearly to us the safest option in general. We evaluated adding a boolean as suggested, but we think this will fall short in many cases, and anything more complex should probably be coded as a smart contract to be used directly or delegating to it from a smart wallet. There is also the fact that this same function is already present in ENS and Uniswap v3 Periphery, and being compatible with those is very appealing to us because this is the kind of contract that we think will benefit from being a widespread standard. |
This is a very smart piece of code found in the ENS repository that we think could be a useful feature for people to plug into their contracts. I suppose this would be the
utils/Multicall
module, unless we come up with another name!The text was updated successfully, but these errors were encountered: