-
Notifications
You must be signed in to change notification settings - Fork 12k
Add Multicall module #2608
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
Merged
Merged
Add Multicall module #2608
Changes from 10 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
15a5e91
Kickstart batchcall
martriay d63bc31
add tests
martriay b3c24d2
fix linting
martriay 4e40344
fix tests
martriay 874d7b2
add documentation
martriay 17b6e70
improve docs
martriay 2f366b9
make batchCall payable
martriay fc31e89
Merge branch 'master' into batch-call
martriay c6b2dc7
add changelog
martriay d1518a9
rename test case
martriay a7397c5
go back to pre-existing naming
martriay 01c2a03
go back to existing naming across files *
martriay b01bd97
fix tests
martriay 754ddeb
remove payable from multicall signature
martriay 833f5fc
rename batchcall -> multicall test files
martriay c27b7f2
add 'return values' and 'sequential reverts' tests
martriay c7e2ebd
remove hardhat console
martriay 15b861a
Merge branch 'master' into batch-call
martriay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "../utils/BatchCall.sol"; | ||
import "./ERC20Mock.sol"; | ||
|
||
contract BatchCallTokenMock is ERC20Mock, BatchCall { | ||
constructor (uint256 initialBalance) ERC20Mock("BatchCallToken", "BCT", msg.sender, initialBalance) {} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "./Address.sol"; | ||
|
||
/* | ||
* @dev Provides a function to batch together multiple calls in a single external call. | ||
*/ | ||
abstract contract BatchCall { | ||
/** | ||
* @dev Receives and executes a batch of function calls on this contract. | ||
*/ | ||
function batchCall(bytes[] calldata data) external payable returns(bytes[] memory results) { | ||
results = new bytes[](data.length); | ||
for (uint i = 0; i < data.length; i++) { | ||
results[i] = Address.functionDelegateCall(address(this), data[i]); | ||
} | ||
return results; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const { BN, expectRevert } = require('@openzeppelin/test-helpers'); | ||
const BatchCallTokenMock = artifacts.require('BatchCallTokenMock'); | ||
|
||
contract('BatchCallToken', function (accounts) { | ||
const [deployer, alice, bob] = accounts; | ||
const amount = 12000; | ||
|
||
beforeEach(async function () { | ||
this.batchCallToken = await BatchCallTokenMock.new(new BN(amount), { from: deployer }); | ||
}); | ||
|
||
it('batches function calls', async function () { | ||
expect(await this.batchCallToken.balanceOf(alice)).to.be.bignumber.equal(new BN('0')); | ||
expect(await this.batchCallToken.balanceOf(bob)).to.be.bignumber.equal(new BN('0')); | ||
|
||
await this.batchCallToken.batchCall([ | ||
this.batchCallToken.contract.methods.transfer(alice, amount / 2).encodeABI(), | ||
this.batchCallToken.contract.methods.transfer(bob, amount / 3).encodeABI(), | ||
], { from: deployer }); | ||
|
||
expect(await this.batchCallToken.balanceOf(alice)).to.be.bignumber.equal(new BN(amount / 2)); | ||
expect(await this.batchCallToken.balanceOf(bob)).to.be.bignumber.equal(new BN(amount / 3)); | ||
}); | ||
|
||
it('bubbles up revert reasons', async function () { | ||
const call = this.batchCallToken.batchCall([ | ||
this.batchCallToken.contract.methods.transfer(alice, amount).encodeABI(), | ||
this.batchCallToken.contract.methods.transfer(bob, amount).encodeABI(), | ||
], { from: deployer }); | ||
|
||
await expectRevert(call, 'ERC20: transfer amount exceeds balance'); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.