📖 Multicall
- Memory Usage
#82
Closed
kaleb-keny
started this conversation in
Show and tell
Replies: 1 comment
-
Thanks for documenting this behavior @kaleb-keny. The reason why I wrote the contract in this manner, is that I want to keep it as agnostic as possible and people can adjust the statically allocatable memory according to their needs. A possible lightweight version looks like this: # @version ^0.3.7
# @dev Batch struct for ordinary (i.e. `nonpayable`) function calls.
struct Batch:
target: address
allow_failure: bool
call_data: Bytes[1024]
# @dev Result struct for function call results.
struct Result:
success: bool
return_data: Bytes[1024]
@external
def multicall(data: DynArray[Batch, 10]) -> DynArray[Result, 10]:
"""
@dev Aggregates function calls, ensuring that each
function returns successfully if required.
Since this function uses `CALL`, the `msg.sender`
will be the multicall contract itself.
@param data The array of `Batch` structs.
@return DynArray The array of `Result` structs.
"""
results: DynArray[Result, 10] = []
return_data: Bytes[1024] = b""
success: bool = empty(bool)
for batch in data:
if (batch.allow_failure == False):
return_data = raw_call(batch.target, batch.call_data, max_outsize=1024)
success = True
results.append(Result({success: success, return_data: return_data}))
else:
success, return_data = \
raw_call(batch.target, batch.call_data, max_outsize=1024, revert_on_failure=False)
results.append(Result({success: success, return_data: return_data}))
return results I deployed the above contract to |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
There was a discussion around the multicall contract and it is worth noting that having the length of the dynamic array set to 255 (i.e. max_value(uint8)]) results in
out of gas
problems when users attempt to interact with the multicall contract. This is due to block size restrictions as well as vy design, where the size of the data array does not vary based on the length of the array provided on interaction with the contract.Therefore in order to avoid this situation, the easiest approach is to restrict the size the of the array as below, based on the gas intensity of the task in question:
Beta Was this translation helpful? Give feedback.
All reactions