-
Notifications
You must be signed in to change notification settings - Fork 75
feat: add multicall handler #489
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
Conversation
Signed-off-by: Matt Rice <matthewcrice32@gmail.com>
|
|
||
| for (uint256 i = 0; i < calls.length; ) { | ||
| Call memory call = calls[i]; | ||
| (bool success, ) = call.target.call{ value: call.value }(call.callData); |
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.
How does this contract get value? Doesn't it receive WETH as a contract?
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.
You might unwrap the WETH in one of your calls, right?
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.
yeah fair
I think this makes sense. OOC could we also have a byte at the start of |
| address, | ||
| bytes memory message | ||
| ) external nonReentrant { | ||
| Call[] memory calls = abi.decode(message, (Call[])); |
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.
Is there any validation we want to do here on converting message into Call[]
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.
What sort of validation would you suggest?
My understanding is that abi.decode will cause a revert if the format is wrong.
From what I found, the price of deployment in gas scales by around
If it is a simple implementation, I'd say its a good idea. |
Yep! I don't think the deployment costs are a big deal. I worry about the complexity. When people integrate, instead of saying "use contract 0x1234" we'll have to split by use case. We'll say "if you want to send value, use contract 0x1234, if you want to allow reverts, use contract 0x5678", etc.
Agreed. We'll probably have to upgrade the OZ library, but seems valuable enough to get both variants audited. |
Yep, I thought a little about something like this. Downside is that it makes building the message more complex. abi encoding your params is a common pattern, but appending extra bytes to the front to create a tagged-union-like structure isn't. So it would require more effort and would have more footguns than the alternative I think. |
ad3cece to
9e4ca50
Compare
This is a generic handler where the user can perform a series of calls (multicall) after their tokens are received in the contract.
User can specify a fallback address that is:
If the user doesn't specify a fallback address, the call must succeed.
The user can call drainLeftoverTokens on the handler in their calls to drain any remaining amount of any token or ETH in their calls. This is meant as a way to deal with calls where the amount of tokens they take isn't known a priori.