-
Notifications
You must be signed in to change notification settings - Fork 61
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
feat: modify batcher contract to support erc20 sendMany #192
Conversation
f4779d5
to
7a1176e
Compare
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.
Please add tests for the method
contracts/Batcher.sol
Outdated
address[] calldata recipients, | ||
uint256[] calldata amounts | ||
) external lockCall { | ||
require(recipients.length == amounts.length, "Length mismatch"); |
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.
I think we should add other validations which are there in batch method here as well
require(recipients.length != 0, 'Must send to at least one person');
require(recipients.length < 256, 'Too many recipients');
should check what this number should be instead of 256
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.
Also length mismatch error is bit ambiguous. let's make this error message same as batch method
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.
kept the limit dynamic since it can be different for different chains.
added a function changeBatchTransferLimit
to change the limit.
contracts/Batcher.sol
Outdated
) external lockCall { | ||
require(recipients.length == amounts.length, "Length mismatch"); | ||
for (uint256 i = 0; i < recipients.length; i++) { | ||
TransferHelper.safeTransferFrom(token, msg.sender, recipients[i], amounts[i]); |
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.
Ideally there should not be a case of partial success, either we send successfully to all the recipients, or none of the transfer should go through.
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.
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.
as suggested, I tried to send to 5 recipients while giving the gas limit for only 2.
the tx failed on chain.
https://holesky.etherscan.io/tx/0x42d64222124a57e5ee7135be7794fcf3d81df5563be3b55cb5a4df81803f2bf9
7a1176e
to
54c9321
Compare
contracts/Batcher.sol
Outdated
) external lockCall { | ||
require(recipients.length != 0, 'Must send to at least one person'); | ||
require(recipients.length == amounts.length, "Unequal recipients and values"); | ||
for (uint256 i = 0; i < recipients.length; i++) { |
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.
for (uint256 i = 0; i < recipients.length; i++) { | |
for (uint8 i = 0; i < recipients.length; i++) { |
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 can also change the contract to use custom errors instead of require statements
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.
used uint16.
also added custom errors.
54c9321
to
91304b5
Compare
91304b5
to
85c7b1f
Compare
85c7b1f
to
2506542
Compare
2506542
to
5a2cf63
Compare
added few tests. |
5a2cf63
to
73ecc14
Compare
73ecc14
to
eca5b19
Compare
e79e1f9
to
92bc37b
Compare
92bc37b
to
932dbb5
Compare
error EmptyRecipientsList(); | ||
error UnequalRecipientsAndValues(); | ||
error TooManyRecipients(uint256 provided, uint256 limit); | ||
error TokenTransferFailed(address token, address from, address to, uint256 amount); |
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.
Add comments following the natspec format for everything
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.
done
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.
NIT: comments on errros
932dbb5
to
ae2cb27
Compare
ae2cb27
to
aec9d8d
Compare
aec9d8d
to
83e6911
Compare
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.
Good Work!!
error EmptyRecipientsList(); | ||
error UnequalRecipientsAndValues(); | ||
error TooManyRecipients(uint256 provided, uint256 limit); | ||
error TokenTransferFailed(address token, address from, address to, uint256 amount); |
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.
NIT: comments on errros
await checkBalance(sender, 500); | ||
await checkBalance(recipients[0], 0); | ||
await checkBalance(recipients[1], 0); |
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.
NIT: you can use promise.all
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.
will make changes here.
https://bitgoinc.atlassian.net/browse/COIN-3005
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.
LGTM
Have we figured out the owner and how do we interact with the contract?
|
||
IERC20 safeToken = IERC20(token); | ||
for (uint16 i = 0; i < recipients.length; i++) { | ||
safeToken.safeTransferFrom(msg.sender, recipients[i], amounts[i]); |
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.
should we allow 0
value transfers ?
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.
will handle it here.
https://bitgoinc.atlassian.net/browse/COIN-3005
what is the expected behaviour?
- should it skip the 0 value transfers and continue with other transfers?
- fail entirely (keeping it atomic).
Not sure about the owner. |
Ticket: COIN-2782