LibMulticall

The purpose of this library is to enable the execution of multiple delegatecalls to different facets of a Diamond contract in a single transaction.

multicall():

The function begins by accessing the LibDiamond.DiamondStorage storage struct from the Diamond contract using the LibDiamond.diamondStorage() function. This allows the function to access the storage variables of the Diamond contract.

The function checks if the length of selectors is equal to the length of data. If the lengths are not equal, it reverts the transaction by calling revert with the error SelectorsLengthInvalid(). This ensures that each selector has a corresponding data item.

The function then iterates over each element in the data array using a for loop. It retrieves the facet address associated with the selector from the selectorToFacetAndPosition mapping stored in the Diamond contract's storage.

The delegatecall function is invoked on the facet address, passing the corresponding data[i] as the delegatecall data. Delegatecall allows the called contract (facet) to execute the function within the context of the calling contract (the current contract). The delegatecall returns a tuple (bool success, bytes memory returnData).

If the delegatecall was not successful (i.e., success is false), the function reverts the transaction by calling revert with the error InvalidMulticall().

Input:

FieldTypeDescription

an array of function selectors

an array of data that needs to be fed into the selectors

Last updated