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

feat: batch multiplex #1

Open
wants to merge 45 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c686e47
feat: add batch multiplex feature
gabririgo Dec 29, 2023
72caeec
move BatchMultiplexValidator contract to /examples folder
gabririgo Dec 29, 2023
085b237
use _getValidateSelector private method
gabririgo Dec 29, 2023
d00b7a4
minor fixes in BatchMultiplexFeature
gabririgo Dec 29, 2023
c86a07b
create new contracts artifacts
gabririgo Dec 29, 2023
9a00232
amend solc versions for compilation
gabririgo Dec 29, 2023
2012d50
update solc comments
gabririgo Dec 29, 2023
5bd76c3
correctly build artifacts with solc v6
gabririgo Dec 29, 2023
639d588
style: lint contracts
gabririgo Dec 30, 2023
a9ea1aa
fix import in tests
gabririgo Dec 30, 2023
b1761ba
chore: remove fixed solc in zerp-ex/foundry.sol
gabririgo Dec 30, 2023
1b007fd
remove unnecessary input
gabririgo Dec 30, 2023
059610d
style: improvements
gabririgo Dec 30, 2023
8fc4a18
minor fix
gabririgo Dec 30, 2023
08199f5
update copy
gabririgo Dec 30, 2023
c885a4c
add comments
gabririgo Jan 4, 2024
85418da
test: add initial batch multiplex test file
gabririgo Jan 4, 2024
c9dc5b9
test: fix linting error
gabririgo Jan 5, 2024
10d250f
test: fix initial batchMultiplex tests
gabririgo Jan 5, 2024
ce0c4dd
only revert if error handling is revert
gabririgo Jan 9, 2024
e3a998c
initial error handling tests
gabririgo Jan 9, 2024
249eb15
comments and docs linting
gabririgo Jan 9, 2024
29ddaba
test contract linting
gabririgo Jan 9, 2024
b6d315c
style: fixed comments
gabririgo Jan 13, 2024
adeb8df
improve error returned msg and remove TODO comment
gabririgo Jan 13, 2024
6f0e417
refund up to sent eth excluding prev balance
gabririgo Jan 16, 2024
eaa13af
add .ts batchMultiplex tests
gabririgo Jan 19, 2024
2f8f2af
uncomment commented assertiong in foundry batch multiplex tests
gabririgo Jan 19, 2024
606fbaf
batch multiplex improvement
gabririgo Jan 19, 2024
b8e6feb
lint test file
gabririgo Jan 19, 2024
e8959b9
test: add batch of swaps with multiple features
gabririgo Jan 20, 2024
f04ecca
handle ETH transfer
gabririgo Jan 21, 2024
48f645e
lint new changes
gabririgo Jan 21, 2024
31fffe0
ci: add new constructor param in .ts tests
gabririgo Jan 21, 2024
14075e0
minor refactoring
gabririgo Jan 21, 2024
02884e2
style: lint batch multiplex changes
gabririgo Jan 21, 2024
fa3da7c
retrieve target implementations from proxy storage
gabririgo Jan 21, 2024
028a51f
simplify batch multiplex storage
gabririgo Jan 22, 2024
8a6afd1
lint changes
gabririgo Jan 22, 2024
07844bf
style: reorder methods
gabririgo Jan 22, 2024
f189991
limit use of .call where required
gabririgo Jan 23, 2024
c4daa73
custom-route `fillLimitOrder` method
gabririgo Jan 23, 2024
3e1db28
update tests
gabririgo Jan 23, 2024
7cd9a25
feat: add BatchMultiplexV2Feature
gabririgo Jan 24, 2024
3b2ffa7
variables and methods renaming
gabririgo Jan 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions contracts/zero-ex/compiler.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"./contracts/src/errors/LibSimpleFunctionRegistryRichErrors.sol",
"./contracts/src/errors/LibTransformERC20RichErrors.sol",
"./contracts/src/errors/LibWalletRichErrors.sol",
"./contracts/src/examples/BatchMultiplexValidator.sol",
"./contracts/src/external/FeeCollector.sol",
"./contracts/src/external/FeeCollectorController.sol",
"./contracts/src/external/FlashWallet.sol",
Expand All @@ -41,6 +42,7 @@
"./contracts/src/features/UniswapFeature.sol",
"./contracts/src/features/UniswapV3Feature.sol",
"./contracts/src/features/interfaces/IBatchFillNativeOrdersFeature.sol",
"./contracts/src/features/interfaces/IBatchMultiplexFeature.sol",
"./contracts/src/features/interfaces/IBootstrapFeature.sol",
"./contracts/src/features/interfaces/IERC1155OrdersFeature.sol",
"./contracts/src/features/interfaces/IERC165Feature.sol",
Expand All @@ -64,6 +66,7 @@
"./contracts/src/features/libs/LibNFTOrder.sol",
"./contracts/src/features/libs/LibNativeOrder.sol",
"./contracts/src/features/libs/LibSignature.sol",
"./contracts/src/features/multiplex/BatchMultiplexFeature.sol",
"./contracts/src/features/multiplex/MultiplexFeature.sol",
"./contracts/src/features/multiplex/MultiplexLiquidityProvider.sol",
"./contracts/src/features/multiplex/MultiplexOtc.sol",
Expand Down
6 changes: 5 additions & 1 deletion contracts/zero-ex/contracts/src/IZeroEx.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import "./features/interfaces/IFundRecoveryFeature.sol";
import "./features/interfaces/IERC721OrdersFeature.sol";
import "./features/interfaces/IERC1155OrdersFeature.sol";
import "./features/interfaces/IERC165Feature.sol";
import "./features/interfaces/IBatchMultiplexFeature.sol";
import "./features/interfaces/IBatchMultiplexFeatureV2.sol";

/// @dev Interface for a fully featured Exchange Proxy.
interface IZeroEx is
Expand All @@ -52,7 +54,9 @@ interface IZeroEx is
IFundRecoveryFeature,
IERC721OrdersFeature,
IERC1155OrdersFeature,
IERC165Feature
IERC165Feature,
IBatchMultiplexFeature,
IBatchMultiplexFeatureV2
{
/// @dev Fallback for just receiving ether.
receive() external payable;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2024 ZeroEx Intl., Rigo Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

pragma solidity ^0.6.5;
pragma experimental ABIEncoderV2;

/// @dev A sample validator contract for the batck multiplex method.
/// @notice Do not fall for ERC2771 address spoofing attack when implementing validation. The 0x protocol will
/// always verify order signatures for meta transactions from signer regardless who is sending the transactions.
contract BatchMultiplexValidator {
struct Batch {
bytes[] calls;
}

// TODO: check how this validation can be skipped, i.e. if the validator input is not as expected.
// Also check if instead of boolean could return calls, as a validator contract may filter some calls.
/// @dev Validates the data passed from the 0x exchange proxy against the validator's requirements.
/// @param encodedCalls The swaps in 0x-protocol format.
/// @param /*extraData*/ An arbitrary string to be used as extra validation.
/// @param /*sender*/ The address that sent the transaction to the network.
/// @return isValid Boolean the bundle is valid.
/// @notice Visibility is not `pure` to potentially allow reading from state.
function validate(
bytes calldata encodedCalls,
bytes calldata /*extraData*/,
address /*sender*/
) external view returns (bool isValid) {
// here the first four bytes of the transaction (the selector) can be extracted and each swap call can
// be decoded against its respective 0x-protocol format type.
Batch memory swaps = abi.decode(encodedCalls, (Batch));
assert(swaps.calls.length > 0);
isValid = true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2024 ZeroEx Intl., Rigo Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

pragma solidity ^0.6.5;
pragma experimental ABIEncoderV2;

import "../../features/libs/LibTypes.sol";
import "../../storage/LibBatchMultiplexStorage.sol";

interface IBatchMultiplexFeature {
struct UpdateSelectorStatus {
// The selector of the function call.
bytes4 selector;
// The status of the selector.
LibBatchMultiplexStorage.SelectorStatus status;
}

/// @dev Emitted whenever the owner updates the selectors' status.
/// @param status Array of tuples of selectors and status (Whitelisted, Blacklisted, RequiresRouting).
event SelectorStatusUpdated(UpdateSelectorStatus[] status);

/// @dev Routes the swaps in the `data` array to the EP.
/// @param data The array of swap transactions.
/// @return results The array of returned values from the swap calls.
function batchMultiplexCall(bytes[] calldata data) external payable returns (bytes[] memory results);

/// @dev Routes the swaps in the `data` array to the EP after validating them in an external validator
/// contract and passes extra data and the desired error behavior.
/// @param data The array of swap transactions.
/// @param extraData A string of extra data for project-specific validation.
/// @param validatorAddress The address of the validator contract.
/// @param errorBehavior Number of the error behavior type when one of the swaps fails.
/// @return results The array of returned values from the swap calls.
function batchMultiplexOptionalParamsCall(
bytes[] calldata data,
bytes calldata extraData,
address validatorAddress,
LibTypes.ErrorBehavior errorBehavior
) external payable returns (bytes[] memory results);

/// @dev A method to update the batch multiplex storage slot. It is restricted to the EP owner.
/// @param selectorsTuple Array of tuples of selector and selector status.
function updateSelectorsStatus(UpdateSelectorStatus[] calldata selectorsTuple) external;

/// @dev A public method to query whether a method is restricted.
/// @notice Can be used by batchMultiplex for querying status of multiple selectors.
function getSelectorStatus(bytes4) external view returns (LibBatchMultiplexStorage.SelectorStatus selectorStatus);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2024 ZeroEx Intl., Rigo Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

pragma solidity ^0.6.5;
pragma experimental ABIEncoderV2;

import "../../features/libs/LibTypes.sol";

interface IBatchMultiplexFeatureV2 {
/// @dev Routes multiple swaps in a `data` array to the EP.
/// @notice Non-payable, does not support ETH to tokens calls.
/// @param data The array of swap transactions.
/// @return results The array of returned values from the swap calls.
function batchMultiplexCallV2(bytes[] calldata data) external returns (bytes[] memory results);

/// @dev Routes multiple swaps in a `data` array to the EP with the desired error behavior.
/// @notice Non-payable, does not support ETH to tokens calls.
/// @param data The array of swap transactions.
/// @param errorBehavior Number of the error behavior type when one of the swaps fails.
/// @return results The array of returned values from the swap calls.
function batchMultiplexOptionalParamsCallV2(
bytes[] calldata data,
LibTypes.ErrorBehavior errorBehavior
) external returns (bytes[] memory results);
}
24 changes: 24 additions & 0 deletions contracts/zero-ex/contracts/src/features/libs/LibTypes.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2024 ZeroEx Intl., Rigo Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

pragma solidity ^0.6.5;

/// @dev A library for defining types.
library LibTypes {
enum ErrorBehavior {
REVERT,
STOP,
CONTINUE
}
}
Loading
Loading