Skip to content
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

Make "batch" function payable #1090

Closed
2 tasks done
PaulRBerg opened this issue Nov 18, 2024 · 9 comments
Closed
2 tasks done

Make "batch" function payable #1090

PaulRBerg opened this issue Nov 18, 2024 · 9 comments
Assignees
Labels
effort: low Easy or tiny task that takes less than a day. priority: 1 This is important. It should be dealt with shortly. type: feature New feature or request. work: clear Sense-categorize-respond. The relationship between cause and effect is clear.

Comments

@PaulRBerg
Copy link
Member

PaulRBerg commented Nov 18, 2024

https://github.com/sablier-labs/company-discussions/discussions/72#discussioncomment-11292236

  • Mark all functions as payable.
  • Do NOT emit the fee in any event because the withdraw function can be called in multiple ways, e.g, directly via withdraw, via withdrawMultiple, or via batch, which would make the accounting difficult to handle.

We will keep track of ETH transfers through other means, e.g., Etherscan, subgraphs, etc.

@PaulRBerg PaulRBerg added type: feature New feature or request. priority: 1 This is important. It should be dealt with shortly. effort: low Easy or tiny task that takes less than a day. work: clear Sense-categorize-respond. The relationship between cause and effect is clear. labels Nov 18, 2024
@smol-ninja
Copy link
Member

Lets include this change alongside making other withdraw functions payable (withdrawMultiple) as a part of #1087 (cc @andreivladbrg).

@smol-ninja smol-ninja removed their assignment Nov 18, 2024
@andreivladbrg
Copy link
Member

andreivladbrg commented Nov 20, 2024

I was trying to implement this and am facing some issues. I’m afraid we won’t be able to achieve this via batch.

If we declare batch as payable and actually send a msg.value greater than 0, all functions within the calls array would also need to be declared as payable; otherwise, it would revert. Also, if we declare the batch function as payable (and all the other functions within calls are also payable), the fee paid by the caller would be msg.value * length of the array, which we don’t want.

This leads to the conclusion that we can’t declare it as payable, and we can’t use the withdraw function within the batch function.

@smol-ninja
Copy link
Member

In the for loop inside batch, we can compare the selectors and if it matches with withdraw and withdraw related functions, then only we would forward msg.value to the delegate call.

What do you think of this?

@andreivladbrg
Copy link
Member

don't think will work as the delegatecall does not have "value" option

@smol-ninja
Copy link
Member

smol-ninja commented Nov 20, 2024

delegatecall forwards msg.value. See here without specifying value option as long as the batch is payable.

One thing to test is that if a function is not marked as payable, can it still access msg.value? If it does not, then its good for us. So that only functions with payable modifier will be able to access msg.value.

@andreivladbrg
Copy link
Member

we can't do this: address(this).delegatecall{ value: msg.value }(calls[i]);

@razgraf
Copy link
Member

razgraf commented Nov 20, 2024

Curious, why does Uniswap's multicall work? What's different in their implementation?

Note: as you can see they don't specify a value in delegatecall

@PaulRBerg
Copy link
Member Author

Uniswap has a different problem situation, which is not related to our problem situation.

Our problem is that we want to charge a flat, per-transaction ETH fee regardless of how many withdrawals are made in a transaction. Since the withdraw function cannot (at the moment) differentiate whether it was called directly or via withdrawMultiple or via batch, we would need to introduce some programmatic gymnastics to account for these possibilities in order to emit a correct msg.value. Here's an example:

  • User withdraws from 5 streams
  • The event CollectFee would get emitted 5 times, with the same msg.value logged each time
  • That would be wrong because the msg.value was charged only once

@andreivladbrg
Copy link
Member

andreivladbrg commented Nov 20, 2024

@github-project-automation github-project-automation bot moved this from 🕵🏻‍♂️ In Review to ✅ Done in Lockup 2.0.0 Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: low Easy or tiny task that takes less than a day. priority: 1 This is important. It should be dealt with shortly. type: feature New feature or request. work: clear Sense-categorize-respond. The relationship between cause and effect is clear.
Projects
No open projects
Status: ✅ Done
Development

No branches or pull requests

4 participants