From c1177416f50c2465ee030dacc14ff996eebd4e74 Mon Sep 17 00:00:00 2001 From: mzhu25 Date: Tue, 22 Feb 2022 10:00:22 -0800 Subject: [PATCH] [Final] ERC721 and ERC1155 Orders (#429) * add LibERC721Order.sol * Add ERC721 interface to vendor/ * Add ERC721OrdersFeature interface * Storage lib for ERC721 orders feature * Implement basic functionality for ERC721 orders (buy, sell, cancel, etc) * Add isValidERC721OrderSignature to interface * implement onERC721Received * Implement batchBuyERC721s * left/right orders -> sell/buy orders * Add missing @return comments * Implement matching functions * Use SafeMath where necessary * add rich errors for ERC721OrdersFeature * Add comments * Add presign support for ERC721 orders * Cancel using just the order nonce * Add IERC721OrdersFeature to IZeroEx * Add taker callback * Assembly optimizations in LibERC721Order * Add ERC721Orders TS class * create zero-ex/contracts/test/integration/ and tokens/ directories * TestMintableERC721Token * tmp * address feedback from original PR (#391) * address feedback from original PR * Update contracts/zero-ex/contracts/src/features/ERC721OrdersFeature.sol Co-authored-by: Kim Persson * address review feedback and improve order parameter naming * Add batchCancel function * Emit order fields in preSign * Fix tests Co-authored-by: Lawrence Forman Co-authored-by: Kim Persson Co-authored-by: Michael Zhu * Remove revertIfIncomplete from batchMatch * Sanity check maker address in preSign * ERC1155OrdersFeature contracts * Commence refactor, abstract base contract * ERC721OrdersFeature inherits from NFTOrders * Refactor ERC1155OrdersFeature to inherit from NFTOrders * Fix order hashing * Fix ERC721OrdersFeature tests * Typos * Remove maker address from preSigned mapping * disable dex sampler tests * Refactor TS tooling * Address PR feedback * Rearrange event fields to better align with struct fields * Update comments * update AbiEncoder.create params * Add ERC1155Order to protocol-utils * Add ERC1155OrdersFeeature tests * Bump package versions and regenerate contract wrappers * Add ERC165Feature * NFT orders: address audit findings (#417) * CVF-1: use pragma solidity ^0.6 instead of ^0.6.5 * CVF-11: fix inaccurate comment * CVF-16: Enable taker callbacks for batchBuyERC1155s * CVF-17: use internal call if revertIfIncomplete is true * CVF-21: avoid duplicate SLOAD * CVF-23: merge if statements * CVF-24: Reorder status checks to be consistent with ERC721OrdersFeature * CVF-25: Update unclear comment (canonical hash -> EIP-712 hash) * CVF-31: Document keys of orderState mapping * CVF-45: DRY up fees/properties hashing * CVF-47, CVF-50, CVF-57: calculate properties.length once; hash propertyStructHashArray in-place using assembly * CVF-56: More descriptive names for assembly variables * CVF-71: Update confusing comment about rounding in _payFees * CVF-72: Move ETH assertions outside of loop in _payFees * CVF-74: Move property validation loop to else branch * CVF-82: Update inaccurate comment * CVF-86: Enable taker callbacks for batchBuyERC721s * CVF-87: use internal call if revertIfIncomplete is true * CVF-89: Perform token mismatch checks before stateful operations * CVF-90, CVF-91: Defer ERC20 token mismatch check * CVF-93: Add inline comments for _payFees parameters in matchERC721Orders * CVF-94: Fix comment (Step 7 -> Step 5) * CVF-98: Use binary & operator instead of mod * CVF-99: Update unclear comment (canonical hash -> EIP-712 hash) * CVF-65, CVF-66, CVF-67: Copy params.ethAvailable into local variable; check that ethSpent does not exceed ethAvailable; remove ethAvailable < erc20FillAmount check * CVF-52, CVF-55, CVF-59: calculate fees.length once; hash feeStructHashArray in-place using assembly * CVF-14, CVF-32: OrderState struct; separate storage mapping for 1155 cancellations so orders can be cancelled by nonce * Update changelogs, IZeroEx artifact/wrapper Co-authored-by: Lawrence Forman Co-authored-by: Lawrence Forman Co-authored-by: Kim Persson --- contracts/erc20/package.json | 14 +- contracts/test-utils/package.json | 22 +- contracts/treasury/package.json | 14 +- contracts/utils/package.json | 14 +- contracts/zero-ex/CHANGELOG.json | 9 + contracts/zero-ex/contracts/src/IZeroEx.sol | 8 +- .../src/errors/LibNFTOrdersRichErrors.sol | 229 + .../contracts/src/features/ERC165Feature.sol | 51 + .../src/features/OtcOrdersFeature.sol | 14 +- .../interfaces/IERC1155OrdersFeature.sol | 242 + .../features/interfaces/IERC165Feature.sol | 36 + .../interfaces/IERC721OrdersFeature.sol | 286 + .../src/features/libs/LibNFTOrder.sol | 459 ++ .../src/features/libs/LibSignature.sol | 12 +- .../features/multiplex/MultiplexFeature.sol | 9 - .../nft_orders/ERC1155OrdersFeature.sol | 635 +++ .../nft_orders/ERC721OrdersFeature.sol | 931 ++++ .../src/features/nft_orders/NFTOrders.sol | 615 ++ .../src/fixins/FixinERC1155Spender.sol | 79 + .../src/fixins/FixinERC721Spender.sol | 74 + .../src/fixins/FixinTokenSpender.sol | 16 +- .../src/storage/LibERC1155OrdersStorage.sol | 55 + .../src/storage/LibERC721OrdersStorage.sol | 47 + .../contracts/src/storage/LibStorage.sol | 6 +- .../contracts/src/vendor/IERC1155Token.sol | 151 + .../contracts/src/vendor/IERC721Token.sol | 159 + .../contracts/src/vendor/IFeeRecipient.sol | 44 + .../src/vendor/IPropertyValidator.sol | 38 + .../contracts/src/vendor/ITakerCallback.sol | 40 + .../contracts/test/TestFeeRecipient.sol | 55 + .../test/TestFillQuoteTransformerBridge.sol | 2 +- .../test/TestFillQuoteTransformerExchange.sol | 2 +- .../test/TestFillQuoteTransformerHost.sol | 2 +- .../test/TestMintTokenERC20Transformer.sol | 2 +- .../contracts/test/TestNFTOrderPresigner.sol | 93 + .../contracts/test/TestPropertyValidator.sol | 39 + .../test/TestWethTransformerHost.sol | 4 +- .../test/{ => integration}/TestCurve.sol | 2 +- .../TestLiquidityProvider.sol | 0 .../test/{ => integration}/TestMooniswap.sol | 2 +- .../TestUniswapV2Factory.sol | 0 .../{ => integration}/TestUniswapV2Pool.sol | 2 +- .../TestUniswapV3Factory.sol | 0 .../{ => integration}/TestUniswapV3Pool.sol | 2 +- .../test/tokens/TestMintableERC1155Token.sol | 345 ++ .../{ => tokens}/TestMintableERC20Token.sol | 0 .../test/tokens/TestMintableERC721Token.sol | 385 ++ .../TestTokenSpenderERC20Token.sol | 0 .../contracts/test/{ => tokens}/TestWeth.sol | 0 contracts/zero-ex/package.json | 18 +- contracts/zero-ex/test/artifacts.ts | 62 +- .../test/features/erc1155_orders_test.ts | 1612 ++++++ .../test/features/erc721_orders_test.ts | 1731 ++++++ contracts/zero-ex/test/utils/nft_orders.ts | 41 + contracts/zero-ex/test/wrappers.ts | 23 + contracts/zero-ex/tsconfig.json | 23 + package.json | 4 +- packages/asset-swapper/package.json | 20 +- .../asset-swapper/test/dex_sampler_test.ts | 2 +- packages/contract-artifacts/CHANGELOG.json | 9 + .../contract-artifacts/artifacts/IZeroEx.json | 1617 ++++++ packages/contract-artifacts/package.json | 2 +- packages/contract-wrappers/CHANGELOG.json | 13 + packages/contract-wrappers/package.json | 10 +- .../src/generated-wrappers/broker.ts | 3 + .../src/generated-wrappers/coordinator.ts | 10 + .../src/generated-wrappers/dev_utils.ts | 37 + .../src/generated-wrappers/erc20_token.ts | 6 + .../src/generated-wrappers/erc721_token.ts | 9 + .../src/generated-wrappers/exchange.ts | 43 + .../src/generated-wrappers/forwarder.ts | 12 + .../gods_unchained_validator.ts | 1 + .../src/generated-wrappers/i_asset_data.ts | 6 + .../i_liquidity_provider.ts | 3 + .../generated-wrappers/i_transform_erc20.ts | 8 + .../src/generated-wrappers/i_zero_ex.ts | 4940 +++++++++++++++++ .../generated-wrappers/maximum_gas_price.ts | 2 + .../src/generated-wrappers/staking.ts | 50 + .../src/generated-wrappers/staking_proxy.ts | 27 + .../src/generated-wrappers/weth9.ts | 11 + packages/contract-wrappers/src/index.ts | 6 + packages/migrations/package.json | 12 +- packages/protocol-utils/CHANGELOG.json | 13 + packages/protocol-utils/package.json | 14 +- packages/protocol-utils/src/eip712_utils.ts | 19 +- packages/protocol-utils/src/index.ts | 7 + packages/protocol-utils/src/nft_orders.ts | 425 ++ .../protocol-utils/src/revert-errors/index.ts | 2 + .../src/revert-errors/nft_orders.ts | 142 + .../protocol-utils/src/signature_utils.ts | 1 + yarn.lock | 194 +- 91 files changed, 16217 insertions(+), 219 deletions(-) create mode 100644 contracts/zero-ex/contracts/src/errors/LibNFTOrdersRichErrors.sol create mode 100644 contracts/zero-ex/contracts/src/features/ERC165Feature.sol create mode 100644 contracts/zero-ex/contracts/src/features/interfaces/IERC1155OrdersFeature.sol create mode 100644 contracts/zero-ex/contracts/src/features/interfaces/IERC165Feature.sol create mode 100644 contracts/zero-ex/contracts/src/features/interfaces/IERC721OrdersFeature.sol create mode 100644 contracts/zero-ex/contracts/src/features/libs/LibNFTOrder.sol create mode 100644 contracts/zero-ex/contracts/src/features/nft_orders/ERC1155OrdersFeature.sol create mode 100644 contracts/zero-ex/contracts/src/features/nft_orders/ERC721OrdersFeature.sol create mode 100644 contracts/zero-ex/contracts/src/features/nft_orders/NFTOrders.sol create mode 100644 contracts/zero-ex/contracts/src/fixins/FixinERC1155Spender.sol create mode 100644 contracts/zero-ex/contracts/src/fixins/FixinERC721Spender.sol create mode 100644 contracts/zero-ex/contracts/src/storage/LibERC1155OrdersStorage.sol create mode 100644 contracts/zero-ex/contracts/src/storage/LibERC721OrdersStorage.sol create mode 100644 contracts/zero-ex/contracts/src/vendor/IERC1155Token.sol create mode 100644 contracts/zero-ex/contracts/src/vendor/IERC721Token.sol create mode 100644 contracts/zero-ex/contracts/src/vendor/IFeeRecipient.sol create mode 100644 contracts/zero-ex/contracts/src/vendor/IPropertyValidator.sol create mode 100644 contracts/zero-ex/contracts/src/vendor/ITakerCallback.sol create mode 100644 contracts/zero-ex/contracts/test/TestFeeRecipient.sol create mode 100644 contracts/zero-ex/contracts/test/TestNFTOrderPresigner.sol create mode 100644 contracts/zero-ex/contracts/test/TestPropertyValidator.sol rename contracts/zero-ex/contracts/test/{ => integration}/TestCurve.sol (98%) rename contracts/zero-ex/contracts/test/{ => integration}/TestLiquidityProvider.sol (100%) rename contracts/zero-ex/contracts/test/{ => integration}/TestMooniswap.sol (97%) rename contracts/zero-ex/contracts/test/{ => integration}/TestUniswapV2Factory.sol (100%) rename contracts/zero-ex/contracts/test/{ => integration}/TestUniswapV2Pool.sol (97%) rename contracts/zero-ex/contracts/test/{ => integration}/TestUniswapV3Factory.sol (100%) rename contracts/zero-ex/contracts/test/{ => integration}/TestUniswapV3Pool.sol (98%) create mode 100644 contracts/zero-ex/contracts/test/tokens/TestMintableERC1155Token.sol rename contracts/zero-ex/contracts/test/{ => tokens}/TestMintableERC20Token.sol (100%) create mode 100644 contracts/zero-ex/contracts/test/tokens/TestMintableERC721Token.sol rename contracts/zero-ex/contracts/test/{ => tokens}/TestTokenSpenderERC20Token.sol (100%) rename contracts/zero-ex/contracts/test/{ => tokens}/TestWeth.sol (100%) create mode 100644 contracts/zero-ex/test/features/erc1155_orders_test.ts create mode 100644 contracts/zero-ex/test/features/erc721_orders_test.ts create mode 100644 contracts/zero-ex/test/utils/nft_orders.ts create mode 100644 packages/protocol-utils/src/nft_orders.ts create mode 100644 packages/protocol-utils/src/revert-errors/nft_orders.ts diff --git a/contracts/erc20/package.json b/contracts/erc20/package.json index 8d9173fc5a..48b62d73f2 100644 --- a/contracts/erc20/package.json +++ b/contracts/erc20/package.json @@ -51,18 +51,18 @@ }, "homepage": "https://github.com/0xProject/protocol/tree/main/contracts/tokens", "devDependencies": { - "@0x/abi-gen": "^5.6.2", - "@0x/contracts-gen": "^2.0.40", + "@0x/abi-gen": "^5.7.2", + "@0x/contracts-gen": "^2.0.43", "@0x/contracts-test-utils": "^5.4.16", "@0x/contracts-utils": "^4.8.6", - "@0x/dev-utils": "^4.2.9", - "@0x/sol-compiler": "^4.7.5", + "@0x/dev-utils": "^4.2.11", + "@0x/sol-compiler": "^4.7.8", "@0x/ts-doc-gen": "^0.0.28", "@0x/tslint-config": "^4.1.4", "@0x/types": "^3.3.4", "@0x/typescript-typings": "^5.2.1", - "@0x/utils": "^6.4.4", - "@0x/web3-wrapper": "^7.6.0", + "@0x/utils": "^6.5.0", + "@0x/web3-wrapper": "^7.6.2", "@types/lodash": "4.14.104", "@types/mocha": "^5.2.7", "@types/node": "12.12.54", @@ -82,7 +82,7 @@ "typescript": "4.2.2" }, "dependencies": { - "@0x/base-contract": "^6.4.2", + "@0x/base-contract": "^6.4.5", "ethers": "~4.0.4" }, "publishConfig": { diff --git a/contracts/test-utils/package.json b/contracts/test-utils/package.json index 58d52df9eb..fa95a82227 100644 --- a/contracts/test-utils/package.json +++ b/contracts/test-utils/package.json @@ -34,7 +34,7 @@ }, "homepage": "https://github.com/0xProject/protocol/tree/main/contracts/test-utils", "devDependencies": { - "@0x/sol-compiler": "^4.7.5", + "@0x/sol-compiler": "^4.7.8", "@0x/tslint-config": "^4.1.4", "npm-run-all": "^4.1.2", "shx": "^0.2.2", @@ -42,20 +42,20 @@ "typescript": "4.2.2" }, "dependencies": { - "@0x/assert": "^3.0.29", - "@0x/base-contract": "^6.4.2", + "@0x/assert": "^3.0.31", + "@0x/base-contract": "^6.4.5", "@0x/contract-addresses": "^6.11.0", - "@0x/dev-utils": "^4.2.9", - "@0x/json-schemas": "^6.3.0", + "@0x/dev-utils": "^4.2.11", + "@0x/json-schemas": "^6.4.1", "@0x/order-utils": "^10.4.28", - "@0x/sol-coverage": "^4.0.39", - "@0x/sol-profiler": "^4.1.29", - "@0x/sol-trace": "^3.0.39", - "@0x/subproviders": "^6.6.0", + "@0x/sol-coverage": "^4.0.42", + "@0x/sol-profiler": "^4.1.32", + "@0x/sol-trace": "^3.0.42", + "@0x/subproviders": "^6.6.2", "@0x/types": "^3.3.4", "@0x/typescript-typings": "^5.2.1", - "@0x/utils": "^6.4.4", - "@0x/web3-wrapper": "^7.6.0", + "@0x/utils": "^6.5.0", + "@0x/web3-wrapper": "^7.6.2", "@types/bn.js": "^4.11.0", "@types/js-combinatorics": "^0.5.29", "@types/lodash": "4.14.104", diff --git a/contracts/treasury/package.json b/contracts/treasury/package.json index c5ab56384a..abeddbe239 100644 --- a/contracts/treasury/package.json +++ b/contracts/treasury/package.json @@ -46,14 +46,14 @@ }, "homepage": "https://github.com/0xProject/protocol/tree/main/contracts/treasury", "devDependencies": { - "@0x/abi-gen": "^5.6.2", + "@0x/abi-gen": "^5.7.2", "@0x/contract-addresses": "^6.11.0", "@0x/contracts-asset-proxy": "^3.7.19", "@0x/contracts-erc20": "^3.3.25", - "@0x/contracts-gen": "^2.0.40", + "@0x/contracts-gen": "^2.0.43", "@0x/contracts-staking": "^2.0.45", "@0x/contracts-test-utils": "^5.4.16", - "@0x/sol-compiler": "^4.7.5", + "@0x/sol-compiler": "^4.7.8", "@0x/ts-doc-gen": "^0.0.28", "@0x/tslint-config": "^4.1.4", "@types/isomorphic-fetch": "^0.0.35", @@ -72,13 +72,13 @@ "typescript": "4.2.2" }, "dependencies": { - "@0x/base-contract": "^6.4.2", + "@0x/base-contract": "^6.4.5", "@0x/protocol-utils": "^1.10.1", - "@0x/subproviders": "^6.6.0", + "@0x/subproviders": "^6.6.2", "@0x/types": "^3.3.4", "@0x/typescript-typings": "^5.2.1", - "@0x/utils": "^6.4.4", - "@0x/web3-wrapper": "^7.6.0", + "@0x/utils": "^6.5.0", + "@0x/web3-wrapper": "^7.6.2", "ethereum-types": "^3.6.0", "ethereumjs-util": "^7.0.10" }, diff --git a/contracts/utils/package.json b/contracts/utils/package.json index a6feed011b..2e93ced30f 100644 --- a/contracts/utils/package.json +++ b/contracts/utils/package.json @@ -50,15 +50,15 @@ }, "homepage": "https://github.com/0xProject/protocol/tree/main/contracts/utils", "devDependencies": { - "@0x/abi-gen": "^5.6.2", - "@0x/contracts-gen": "^2.0.40", + "@0x/abi-gen": "^5.7.2", + "@0x/contracts-gen": "^2.0.43", "@0x/contracts-test-utils": "^5.4.16", - "@0x/dev-utils": "^4.2.9", + "@0x/dev-utils": "^4.2.11", "@0x/order-utils": "^10.4.28", - "@0x/sol-compiler": "^4.7.5", + "@0x/sol-compiler": "^4.7.8", "@0x/tslint-config": "^4.1.4", "@0x/types": "^3.3.4", - "@0x/web3-wrapper": "^7.6.0", + "@0x/web3-wrapper": "^7.6.2", "@types/bn.js": "^4.11.0", "@types/lodash": "4.14.104", "@types/mocha": "^5.2.7", @@ -79,9 +79,9 @@ "typescript": "4.2.2" }, "dependencies": { - "@0x/base-contract": "^6.4.2", + "@0x/base-contract": "^6.4.5", "@0x/typescript-typings": "^5.2.1", - "@0x/utils": "^6.4.4", + "@0x/utils": "^6.5.0", "bn.js": "^4.11.8", "ethereum-types": "^3.6.0" }, diff --git a/contracts/zero-ex/CHANGELOG.json b/contracts/zero-ex/CHANGELOG.json index 35f873b958..d405b9d099 100644 --- a/contracts/zero-ex/CHANGELOG.json +++ b/contracts/zero-ex/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "0.31.0", + "changes": [ + { + "note": "Add ERC721OrdersFeature, ERC1155OrdersFeature, and ERC165Feature", + "pr": 429 + } + ] + }, { "timestamp": 1640364306, "version": "0.30.1", diff --git a/contracts/zero-ex/contracts/src/IZeroEx.sol b/contracts/zero-ex/contracts/src/IZeroEx.sol index e97b9aa7a7..ce021e3c7a 100644 --- a/contracts/zero-ex/contracts/src/IZeroEx.sol +++ b/contracts/zero-ex/contracts/src/IZeroEx.sol @@ -34,6 +34,9 @@ import "./features/interfaces/IBatchFillNativeOrdersFeature.sol"; import "./features/interfaces/IMultiplexFeature.sol"; import "./features/interfaces/IOtcOrdersFeature.sol"; import "./features/interfaces/IFundRecoveryFeature.sol"; +import "./features/interfaces/IERC721OrdersFeature.sol"; +import "./features/interfaces/IERC1155OrdersFeature.sol"; +import "./features/interfaces/IERC165Feature.sol"; /// @dev Interface for a fully featured Exchange Proxy. @@ -50,7 +53,10 @@ interface IZeroEx is IBatchFillNativeOrdersFeature, IMultiplexFeature, IOtcOrdersFeature, - IFundRecoveryFeature + IFundRecoveryFeature, + IERC721OrdersFeature, + IERC1155OrdersFeature, + IERC165Feature { // solhint-disable state-visibility diff --git a/contracts/zero-ex/contracts/src/errors/LibNFTOrdersRichErrors.sol b/contracts/zero-ex/contracts/src/errors/LibNFTOrdersRichErrors.sol new file mode 100644 index 0000000000..6c354066a3 --- /dev/null +++ b/contracts/zero-ex/contracts/src/errors/LibNFTOrdersRichErrors.sol @@ -0,0 +1,229 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2021 ZeroEx 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; + + +library LibNFTOrdersRichErrors { + + // solhint-disable func-name-mixedcase + + function OverspentEthError( + uint256 ethSpent, + uint256 ethAvailable + ) + internal + pure + returns (bytes memory) + { + return abi.encodeWithSelector( + bytes4(keccak256("OverspentEthError(uint256,uint256)")), + ethSpent, + ethAvailable + ); + } + + function InsufficientEthError( + uint256 ethAvailable, + uint256 orderAmount + ) + internal + pure + returns (bytes memory) + { + return abi.encodeWithSelector( + bytes4(keccak256("InsufficientEthError(uint256,uint256)")), + ethAvailable, + orderAmount + ); + } + + function ERC721TokenMismatchError( + address token1, + address token2 + ) + internal + pure + returns (bytes memory) + { + return abi.encodeWithSelector( + bytes4(keccak256("ERC721TokenMismatchError(address,address)")), + token1, + token2 + ); + } + + function ERC1155TokenMismatchError( + address token1, + address token2 + ) + internal + pure + returns (bytes memory) + { + return abi.encodeWithSelector( + bytes4(keccak256("ERC1155TokenMismatchError(address,address)")), + token1, + token2 + ); + } + + function ERC20TokenMismatchError( + address token1, + address token2 + ) + internal + pure + returns (bytes memory) + { + return abi.encodeWithSelector( + bytes4(keccak256("ERC20TokenMismatchError(address,address)")), + token1, + token2 + ); + } + + function NegativeSpreadError( + uint256 sellOrderAmount, + uint256 buyOrderAmount + ) + internal + pure + returns (bytes memory) + { + return abi.encodeWithSelector( + bytes4(keccak256("NegativeSpreadError(uint256,uint256)")), + sellOrderAmount, + buyOrderAmount + ); + } + + function SellOrderFeesExceedSpreadError( + uint256 sellOrderFees, + uint256 spread + ) + internal + pure + returns (bytes memory) + { + return abi.encodeWithSelector( + bytes4(keccak256("SellOrderFeesExceedSpreadError(uint256,uint256)")), + sellOrderFees, + spread + ); + } + + function OnlyTakerError( + address sender, + address taker + ) + internal + pure + returns (bytes memory) + { + return abi.encodeWithSelector( + bytes4(keccak256("OnlyTakerError(address,address)")), + sender, + taker + ); + } + + function InvalidSignerError( + address maker, + address signer + ) + internal + pure + returns (bytes memory) + { + return abi.encodeWithSelector( + bytes4(keccak256("InvalidSignerError(address,address)")), + maker, + signer + ); + } + + function OrderNotFillableError( + address maker, + uint256 nonce, + uint8 orderStatus + ) + internal + pure + returns (bytes memory) + { + return abi.encodeWithSelector( + bytes4(keccak256("OrderNotFillableError(address,uint256,uint8)")), + maker, + nonce, + orderStatus + ); + } + + function TokenIdMismatchError( + uint256 tokenId, + uint256 orderTokenId + ) + internal + pure + returns (bytes memory) + { + return abi.encodeWithSelector( + bytes4(keccak256("TokenIdMismatchError(uint256,uint256)")), + tokenId, + orderTokenId + ); + } + + function PropertyValidationFailedError( + address propertyValidator, + address token, + uint256 tokenId, + bytes memory propertyData, + bytes memory errorData + ) + internal + pure + returns (bytes memory) + { + return abi.encodeWithSelector( + bytes4(keccak256("PropertyValidationFailedError(address,address,uint256,bytes,bytes)")), + propertyValidator, + token, + tokenId, + propertyData, + errorData + ); + } + + function ExceedsRemainingOrderAmount( + uint128 remainingOrderAmount, + uint128 fillAmount + ) + internal + pure + returns (bytes memory) + { + return abi.encodeWithSelector( + bytes4(keccak256("ExceedsRemainingOrderAmount(uint128,uint128)")), + remainingOrderAmount, + fillAmount + ); + } +} diff --git a/contracts/zero-ex/contracts/src/features/ERC165Feature.sol b/contracts/zero-ex/contracts/src/features/ERC165Feature.sol new file mode 100644 index 0000000000..52f6dc3783 --- /dev/null +++ b/contracts/zero-ex/contracts/src/features/ERC165Feature.sol @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2022 ZeroEx 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; +pragma experimental ABIEncoderV2; + +import "../fixins/FixinCommon.sol"; +import "./interfaces/IFeature.sol"; + + +/// @dev Implements the ERC165 `supportsInterface` function +contract ERC165Feature is + IFeature, + FixinCommon +{ + /// @dev Name of this feature. + string public constant override FEATURE_NAME = "ERC165"; + /// @dev Version of this feature. + uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 0, 0); + + /// @dev Indicates whether the 0x Exchange Proxy implements a particular + /// ERC165 interface. This function should use at most 30,000 gas. + /// @param interfaceId The interface identifier, as specified in ERC165. + /// @return isSupported Whether the given interface is supported by the + /// 0x Exchange Proxy. + function supportInterface(bytes4 interfaceId) + external + pure + returns (bool isSupported) + { + return interfaceId == 0x01ffc9a7 || // ERC-165 support + interfaceId == 0x150b7a02 || // ERC-721 `ERC721TokenReceiver` support + interfaceId == 0x4e2312e0; // ERC-1155 `ERC1155TokenReceiver` support + } +} diff --git a/contracts/zero-ex/contracts/src/features/OtcOrdersFeature.sol b/contracts/zero-ex/contracts/src/features/OtcOrdersFeature.sol index b1de06f0cf..2ee5dd9cb1 100644 --- a/contracts/zero-ex/contracts/src/features/OtcOrdersFeature.sol +++ b/contracts/zero-ex/contracts/src/features/OtcOrdersFeature.sol @@ -311,7 +311,7 @@ contract OtcOrdersFeature is // Unwrap WETH WETH.withdraw(order.makerAmount); // Transfer ETH to taker - _transferEth(taker, order.makerAmount); + _transferEth(payable(taker), order.makerAmount); emit OtcOrderFilled( orderInfo.orderHash, @@ -622,16 +622,4 @@ contract OtcOrdersFeature is [txOrigin] [nonceBucket]; } - - function _transferEth(address recipient, uint256 amount) - private - { - // Transfer ETH to recipient - (bool success, bytes memory revertData) = - recipient.call{value: amount}(""); - // Revert on failure - if (!success) { - revertData.rrevert(); - } - } } diff --git a/contracts/zero-ex/contracts/src/features/interfaces/IERC1155OrdersFeature.sol b/contracts/zero-ex/contracts/src/features/interfaces/IERC1155OrdersFeature.sol new file mode 100644 index 0000000000..74f785e113 --- /dev/null +++ b/contracts/zero-ex/contracts/src/features/interfaces/IERC1155OrdersFeature.sol @@ -0,0 +1,242 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2021 ZeroEx 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; +pragma experimental ABIEncoderV2; + +import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; +import "../libs/LibNFTOrder.sol"; +import "../libs/LibSignature.sol"; +import "../../vendor/IERC1155Token.sol"; + + +/// @dev Feature for interacting with ERC1155 orders. +interface IERC1155OrdersFeature { + + /// @dev Emitted whenever an `ERC1155Order` is filled. + /// @param direction Whether the order is selling or + /// buying the ERC1155 token. + /// @param maker The maker of the order. + /// @param taker The taker of the order. + /// @param nonce The unique maker nonce in the order. + /// @param erc20Token The address of the ERC20 token. + /// @param erc20FillAmount The amount of ERC20 token filled. + /// @param erc1155Token The address of the ERC1155 token. + /// @param erc1155TokenId The ID of the ERC1155 asset. + /// @param erc1155FillAmount The amount of ERC1155 asset filled. + /// @param matcher Currently unused. + event ERC1155OrderFilled( + LibNFTOrder.TradeDirection direction, + address maker, + address taker, + uint256 nonce, + IERC20TokenV06 erc20Token, + uint256 erc20FillAmount, + IERC1155Token erc1155Token, + uint256 erc1155TokenId, + uint128 erc1155FillAmount, + address matcher + ); + + /// @dev Emitted whenever an `ERC1155Order` is cancelled. + /// @param maker The maker of the order. + /// @param nonce The nonce of the order that was cancelled. + event ERC1155OrderCancelled( + address maker, + uint256 nonce + ); + + /// @dev Emitted when an `ERC1155Order` is pre-signed. + /// Contains all the fields of the order. + event ERC1155OrderPreSigned( + LibNFTOrder.TradeDirection direction, + address maker, + address taker, + uint256 expiry, + uint256 nonce, + IERC20TokenV06 erc20Token, + uint256 erc20TokenAmount, + LibNFTOrder.Fee[] fees, + IERC1155Token erc1155Token, + uint256 erc1155TokenId, + LibNFTOrder.Property[] erc1155TokenProperties, + uint128 erc1155TokenAmount + ); + + /// @dev Sells an ERC1155 asset to fill the given order. + /// @param buyOrder The ERC1155 buy order. + /// @param signature The order signature from the maker. + /// @param erc1155TokenId The ID of the ERC1155 asset being + /// sold. If the given order specifies properties, + /// the asset must satisfy those properties. Otherwise, + /// it must equal the tokenId in the order. + /// @param erc1155SellAmount The amount of the ERC1155 asset + /// to sell. + /// @param unwrapNativeToken If this parameter is true and the + /// ERC20 token of the order is e.g. WETH, unwraps the + /// token before transferring it to the taker. + /// @param callbackData If this parameter is non-zero, invokes + /// `zeroExERC1155OrderCallback` on `msg.sender` after + /// the ERC20 tokens have been transferred to `msg.sender` + /// but before transferring the ERC1155 asset to the buyer. + function sellERC1155( + LibNFTOrder.ERC1155Order calldata buyOrder, + LibSignature.Signature calldata signature, + uint256 erc1155TokenId, + uint128 erc1155SellAmount, + bool unwrapNativeToken, + bytes calldata callbackData + ) + external; + + /// @dev Buys an ERC1155 asset by filling the given order. + /// @param sellOrder The ERC1155 sell order. + /// @param signature The order signature. + /// @param erc1155BuyAmount The amount of the ERC1155 asset + /// to buy. + /// @param callbackData If this parameter is non-zero, invokes + /// `zeroExERC1155OrderCallback` on `msg.sender` after + /// the ERC1155 asset has been transferred to `msg.sender` + /// but before transferring the ERC20 tokens to the seller. + /// Native tokens acquired during the callback can be used + /// to fill the order. + function buyERC1155( + LibNFTOrder.ERC1155Order calldata sellOrder, + LibSignature.Signature calldata signature, + uint128 erc1155BuyAmount, + bytes calldata callbackData + ) + external + payable; + + /// @dev Cancel a single ERC1155 order by its nonce. The caller + /// should be the maker of the order. Silently succeeds if + /// an order with the same nonce has already been filled or + /// cancelled. + /// @param orderNonce The order nonce. + function cancelERC1155Order(uint256 orderNonce) + external; + + /// @dev Cancel multiple ERC1155 orders by their nonces. The caller + /// should be the maker of the orders. Silently succeeds if + /// an order with the same nonce has already been filled or + /// cancelled. + /// @param orderNonces The order nonces. + function batchCancelERC1155Orders(uint256[] calldata orderNonces) + external; + + /// @dev Buys multiple ERC1155 assets by filling the + /// given orders. + /// @param sellOrders The ERC1155 sell orders. + /// @param signatures The order signatures. + /// @param erc1155TokenAmounts The amounts of the ERC1155 assets + /// to buy for each order. + /// @param callbackData The data (if any) to pass to the taker + /// callback for each order. Refer to the `callbackData` + /// parameter to for `buyERC1155`. + /// @param revertIfIncomplete If true, reverts if this + /// function fails to fill any individual order. + /// @return successes An array of booleans corresponding to whether + /// each order in `orders` was successfully filled. + function batchBuyERC1155s( + LibNFTOrder.ERC1155Order[] calldata sellOrders, + LibSignature.Signature[] calldata signatures, + uint128[] calldata erc1155TokenAmounts, + bytes[] calldata callbackData, + bool revertIfIncomplete + ) + external + payable + returns (bool[] memory successes); + + /// @dev Callback for the ERC1155 `safeTransferFrom` function. + /// This callback can be used to sell an ERC1155 asset if + /// a valid ERC1155 order, signature and `unwrapNativeToken` + /// are encoded in `data`. This allows takers to sell their + /// ERC1155 asset without first calling `setApprovalForAll`. + /// @param operator The address which called `safeTransferFrom`. + /// @param from The address which previously owned the token. + /// @param tokenId The ID of the asset being transferred. + /// @param value The amount being transferred. + /// @param data Additional data with no specified format. If a + /// valid ERC1155 order, signature and `unwrapNativeToken` + /// are encoded in `data`, this function will try to fill + /// the order using the received asset. + /// @return success The selector of this function (0xf23a6e61), + /// indicating that the callback succeeded. + function onERC1155Received( + address operator, + address from, + uint256 tokenId, + uint256 value, + bytes calldata data + ) + external + returns (bytes4 success); + + /// @dev Approves an ERC1155 order on-chain. After pre-signing + /// the order, the `PRESIGNED` signature type will become + /// valid for that order and signer. + /// @param order An ERC1155 order. + function preSignERC1155Order(LibNFTOrder.ERC1155Order calldata order) + external; + + /// @dev Checks whether the given signature is valid for the + /// the given ERC1155 order. Reverts if not. + /// @param order The ERC1155 order. + /// @param signature The signature to validate. + function validateERC1155OrderSignature( + LibNFTOrder.ERC1155Order calldata order, + LibSignature.Signature calldata signature + ) + external + view; + + /// @dev If the given order is buying an ERC1155 asset, checks + /// whether or not the given token ID satisfies the required + /// properties specified in the order. If the order does not + /// specify any properties, this function instead checks + /// whether the given token ID matches the ID in the order. + /// Reverts if any checks fail, or if the order is selling + /// an ERC1155 asset. + /// @param order The ERC1155 order. + /// @param erc1155TokenId The ID of the ERC1155 asset. + function validateERC1155OrderProperties( + LibNFTOrder.ERC1155Order calldata order, + uint256 erc1155TokenId + ) + external + view; + + /// @dev Get the order info for an ERC1155 order. + /// @param order The ERC1155 order. + /// @return orderInfo Infor about the order. + function getERC1155OrderInfo(LibNFTOrder.ERC1155Order calldata order) + external + view + returns (LibNFTOrder.OrderInfo memory orderInfo); + + /// @dev Get the EIP-712 hash of an ERC1155 order. + /// @param order The ERC1155 order. + /// @return orderHash The order hash. + function getERC1155OrderHash(LibNFTOrder.ERC1155Order calldata order) + external + view + returns (bytes32 orderHash); +} diff --git a/contracts/zero-ex/contracts/src/features/interfaces/IERC165Feature.sol b/contracts/zero-ex/contracts/src/features/interfaces/IERC165Feature.sol new file mode 100644 index 0000000000..5844eb72e1 --- /dev/null +++ b/contracts/zero-ex/contracts/src/features/interfaces/IERC165Feature.sol @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2022 ZeroEx 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; +pragma experimental ABIEncoderV2; + + +/// @dev Implements the ERC165 `supportsInterface` function +interface IERC165Feature { + + /// @dev Indicates whether the 0x Exchange Proxy implements a particular + /// ERC165 interface. This function should use at most 30,000 gas. + /// @param interfaceId The interface identifier, as specified in ERC165. + /// @return isSupported Whether the given interface is supported by the + /// 0x Exchange Proxy. + function supportInterface(bytes4 interfaceId) + external + pure + returns (bool isSupported); +} diff --git a/contracts/zero-ex/contracts/src/features/interfaces/IERC721OrdersFeature.sol b/contracts/zero-ex/contracts/src/features/interfaces/IERC721OrdersFeature.sol new file mode 100644 index 0000000000..7c4622c236 --- /dev/null +++ b/contracts/zero-ex/contracts/src/features/interfaces/IERC721OrdersFeature.sol @@ -0,0 +1,286 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2021 ZeroEx 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; +pragma experimental ABIEncoderV2; + +import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; +import "../libs/LibNFTOrder.sol"; +import "../libs/LibSignature.sol"; +import "../../vendor/IERC721Token.sol"; + + +/// @dev Feature for interacting with ERC721 orders. +interface IERC721OrdersFeature { + + /// @dev Emitted whenever an `ERC721Order` is filled. + /// @param direction Whether the order is selling or + /// buying the ERC721 token. + /// @param maker The maker of the order. + /// @param taker The taker of the order. + /// @param nonce The unique maker nonce in the order. + /// @param erc20Token The address of the ERC20 token. + /// @param erc20TokenAmount The amount of ERC20 token + /// to sell or buy. + /// @param erc721Token The address of the ERC721 token. + /// @param erc721TokenId The ID of the ERC721 asset. + /// @param matcher If this order was matched with another using `matchERC721Orders()`, + /// this will be the address of the caller. If not, this will be `address(0)`. + event ERC721OrderFilled( + LibNFTOrder.TradeDirection direction, + address maker, + address taker, + uint256 nonce, + IERC20TokenV06 erc20Token, + uint256 erc20TokenAmount, + IERC721Token erc721Token, + uint256 erc721TokenId, + address matcher + ); + + /// @dev Emitted whenever an `ERC721Order` is cancelled. + /// @param maker The maker of the order. + /// @param nonce The nonce of the order that was cancelled. + event ERC721OrderCancelled( + address maker, + uint256 nonce + ); + + /// @dev Emitted when an `ERC721Order` is pre-signed. + /// Contains all the fields of the order. + event ERC721OrderPreSigned( + LibNFTOrder.TradeDirection direction, + address maker, + address taker, + uint256 expiry, + uint256 nonce, + IERC20TokenV06 erc20Token, + uint256 erc20TokenAmount, + LibNFTOrder.Fee[] fees, + IERC721Token erc721Token, + uint256 erc721TokenId, + LibNFTOrder.Property[] erc721TokenProperties + ); + + /// @dev Sells an ERC721 asset to fill the given order. + /// @param buyOrder The ERC721 buy order. + /// @param signature The order signature from the maker. + /// @param erc721TokenId The ID of the ERC721 asset being + /// sold. If the given order specifies properties, + /// the asset must satisfy those properties. Otherwise, + /// it must equal the tokenId in the order. + /// @param unwrapNativeToken If this parameter is true and the + /// ERC20 token of the order is e.g. WETH, unwraps the + /// token before transferring it to the taker. + /// @param callbackData If this parameter is non-zero, invokes + /// `zeroExERC721OrderCallback` on `msg.sender` after + /// the ERC20 tokens have been transferred to `msg.sender` + /// but before transferring the ERC721 asset to the buyer. + function sellERC721( + LibNFTOrder.ERC721Order calldata buyOrder, + LibSignature.Signature calldata signature, + uint256 erc721TokenId, + bool unwrapNativeToken, + bytes calldata callbackData + ) + external; + + /// @dev Buys an ERC721 asset by filling the given order. + /// @param sellOrder The ERC721 sell order. + /// @param signature The order signature. + /// @param callbackData If this parameter is non-zero, invokes + /// `zeroExERC721OrderCallback` on `msg.sender` after + /// the ERC721 asset has been transferred to `msg.sender` + /// but before transferring the ERC20 tokens to the seller. + /// Native tokens acquired during the callback can be used + /// to fill the order. + function buyERC721( + LibNFTOrder.ERC721Order calldata sellOrder, + LibSignature.Signature calldata signature, + bytes calldata callbackData + ) + external + payable; + + /// @dev Cancel a single ERC721 order by its nonce. The caller + /// should be the maker of the order. Silently succeeds if + /// an order with the same nonce has already been filled or + /// cancelled. + /// @param orderNonce The order nonce. + function cancelERC721Order(uint256 orderNonce) + external; + + /// @dev Cancel multiple ERC721 orders by their nonces. The caller + /// should be the maker of the orders. Silently succeeds if + /// an order with the same nonce has already been filled or + /// cancelled. + /// @param orderNonces The order nonces. + function batchCancelERC721Orders(uint256[] calldata orderNonces) + external; + + /// @dev Buys multiple ERC721 assets by filling the + /// given orders. + /// @param sellOrders The ERC721 sell orders. + /// @param signatures The order signatures. + /// @param callbackData The data (if any) to pass to the taker + /// callback for each order. Refer to the `callbackData` + /// parameter to for `buyERC721`. + /// @param revertIfIncomplete If true, reverts if this + /// function fails to fill any individual order. + /// @return successes An array of booleans corresponding to whether + /// each order in `orders` was successfully filled. + function batchBuyERC721s( + LibNFTOrder.ERC721Order[] calldata sellOrders, + LibSignature.Signature[] calldata signatures, + bytes[] calldata callbackData, + bool revertIfIncomplete + ) + external + payable + returns (bool[] memory successes); + + /// @dev Matches a pair of complementary orders that have + /// a non-negative spread. Each order is filled at + /// their respective price, and the matcher receives + /// a profit denominated in the ERC20 token. + /// @param sellOrder Order selling an ERC721 asset. + /// @param buyOrder Order buying an ERC721 asset. + /// @param sellOrderSignature Signature for the sell order. + /// @param buyOrderSignature Signature for the buy order. + /// @return profit The amount of profit earned by the caller + /// of this function (denominated in the ERC20 token + /// of the matched orders). + function matchERC721Orders( + LibNFTOrder.ERC721Order calldata sellOrder, + LibNFTOrder.ERC721Order calldata buyOrder, + LibSignature.Signature calldata sellOrderSignature, + LibSignature.Signature calldata buyOrderSignature + ) + external + returns (uint256 profit); + + /// @dev Matches pairs of complementary orders that have + /// non-negative spreads. Each order is filled at + /// their respective price, and the matcher receives + /// a profit denominated in the ERC20 token. + /// @param sellOrders Orders selling ERC721 assets. + /// @param buyOrders Orders buying ERC721 assets. + /// @param sellOrderSignatures Signatures for the sell orders. + /// @param buyOrderSignatures Signatures for the buy orders. + /// @return profits The amount of profit earned by the caller + /// of this function for each pair of matched orders + /// (denominated in the ERC20 token of the order pair). + /// @return successes An array of booleans corresponding to + /// whether each pair of orders was successfully matched. + function batchMatchERC721Orders( + LibNFTOrder.ERC721Order[] calldata sellOrders, + LibNFTOrder.ERC721Order[] calldata buyOrders, + LibSignature.Signature[] calldata sellOrderSignatures, + LibSignature.Signature[] calldata buyOrderSignatures + ) + external + returns (uint256[] memory profits, bool[] memory successes); + + /// @dev Callback for the ERC721 `safeTransferFrom` function. + /// This callback can be used to sell an ERC721 asset if + /// a valid ERC721 order, signature and `unwrapNativeToken` + /// are encoded in `data`. This allows takers to sell their + /// ERC721 asset without first calling `setApprovalForAll`. + /// @param operator The address which called `safeTransferFrom`. + /// @param from The address which previously owned the token. + /// @param tokenId The ID of the asset being transferred. + /// @param data Additional data with no specified format. If a + /// valid ERC721 order, signature and `unwrapNativeToken` + /// are encoded in `data`, this function will try to fill + /// the order using the received asset. + /// @return success The selector of this function (0x150b7a02), + /// indicating that the callback succeeded. + function onERC721Received( + address operator, + address from, + uint256 tokenId, + bytes calldata data + ) + external + returns (bytes4 success); + + /// @dev Approves an ERC721 order on-chain. After pre-signing + /// the order, the `PRESIGNED` signature type will become + /// valid for that order and signer. + /// @param order An ERC721 order. + function preSignERC721Order(LibNFTOrder.ERC721Order calldata order) + external; + + /// @dev Checks whether the given signature is valid for the + /// the given ERC721 order. Reverts if not. + /// @param order The ERC721 order. + /// @param signature The signature to validate. + function validateERC721OrderSignature( + LibNFTOrder.ERC721Order calldata order, + LibSignature.Signature calldata signature + ) + external + view; + + /// @dev If the given order is buying an ERC721 asset, checks + /// whether or not the given token ID satisfies the required + /// properties specified in the order. If the order does not + /// specify any properties, this function instead checks + /// whether the given token ID matches the ID in the order. + /// Reverts if any checks fail, or if the order is selling + /// an ERC721 asset. + /// @param order The ERC721 order. + /// @param erc721TokenId The ID of the ERC721 asset. + function validateERC721OrderProperties( + LibNFTOrder.ERC721Order calldata order, + uint256 erc721TokenId + ) + external + view; + + /// @dev Get the current status of an ERC721 order. + /// @param order The ERC721 order. + /// @return status The status of the order. + function getERC721OrderStatus(LibNFTOrder.ERC721Order calldata order) + external + view + returns (LibNFTOrder.OrderStatus status); + + /// @dev Get the EIP-712 hash of an ERC721 order. + /// @param order The ERC721 order. + /// @return orderHash The order hash. + function getERC721OrderHash(LibNFTOrder.ERC721Order calldata order) + external + view + returns (bytes32 orderHash); + + /// @dev Get the order status bit vector for the given + /// maker address and nonce range. + /// @param maker The maker of the order. + /// @param nonceRange Order status bit vectors are indexed + /// by maker address and the upper 248 bits of the + /// order nonce. We define `nonceRange` to be these + /// 248 bits. + /// @return bitVector The order status bit vector for the + /// given maker and nonce range. + function getERC721OrderStatusBitVector(address maker, uint248 nonceRange) + external + view + returns (uint256 bitVector); +} diff --git a/contracts/zero-ex/contracts/src/features/libs/LibNFTOrder.sol b/contracts/zero-ex/contracts/src/features/libs/LibNFTOrder.sol new file mode 100644 index 0000000000..af23d9abc8 --- /dev/null +++ b/contracts/zero-ex/contracts/src/features/libs/LibNFTOrder.sol @@ -0,0 +1,459 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2021 ZeroEx 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; +pragma experimental ABIEncoderV2; + +import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; +import "../../vendor/IERC1155Token.sol"; +import "../../vendor/IERC721Token.sol"; +import "../../vendor/IPropertyValidator.sol"; + + +/// @dev A library for common NFT order operations. +library LibNFTOrder { + + enum OrderStatus { + INVALID, + FILLABLE, + UNFILLABLE, + EXPIRED + } + + enum TradeDirection { + SELL_NFT, + BUY_NFT + } + + struct Property { + IPropertyValidator propertyValidator; + bytes propertyData; + } + + struct Fee { + address recipient; + uint256 amount; + bytes feeData; + } + + // "Base struct" for ERC721Order and ERC1155, used + // by the abstract contract `NFTOrders`. + struct NFTOrder { + TradeDirection direction; + address maker; + address taker; + uint256 expiry; + uint256 nonce; + IERC20TokenV06 erc20Token; + uint256 erc20TokenAmount; + Fee[] fees; + address nft; + uint256 nftId; + Property[] nftProperties; + } + + // All fields align with those of NFTOrder + struct ERC721Order { + TradeDirection direction; + address maker; + address taker; + uint256 expiry; + uint256 nonce; + IERC20TokenV06 erc20Token; + uint256 erc20TokenAmount; + Fee[] fees; + IERC721Token erc721Token; + uint256 erc721TokenId; + Property[] erc721TokenProperties; + } + + // All fields except `erc1155TokenAmount` align + // with those of NFTOrder + struct ERC1155Order { + TradeDirection direction; + address maker; + address taker; + uint256 expiry; + uint256 nonce; + IERC20TokenV06 erc20Token; + uint256 erc20TokenAmount; + Fee[] fees; + IERC1155Token erc1155Token; + uint256 erc1155TokenId; + Property[] erc1155TokenProperties; + // End of fields shared with NFTOrder + uint128 erc1155TokenAmount; + } + + struct OrderInfo { + bytes32 orderHash; + OrderStatus status; + // `orderAmount` is 1 for all ERC721Orders, and + // `erc1155TokenAmount` for ERC1155Orders. + uint128 orderAmount; + // The remaining amount of the ERC721/ERC1155 asset + // that can be filled for the order. + uint128 remainingAmount; + } + + // The type hash for ERC721 orders, which is: + // keccak256(abi.encodePacked( + // "ERC721Order(", + // "uint8 direction,", + // "address maker,", + // "address taker,", + // "uint256 expiry,", + // "uint256 nonce,", + // "address erc20Token,", + // "uint256 erc20TokenAmount,", + // "Fee[] fees,", + // "address erc721Token,", + // "uint256 erc721TokenId,", + // "Property[] erc721TokenProperties", + // ")", + // "Fee(", + // "address recipient,", + // "uint256 amount,", + // "bytes feeData", + // ")", + // "Property(", + // "address propertyValidator,", + // "bytes propertyData", + // ")" + // )) + uint256 private constant _ERC_721_ORDER_TYPEHASH = + 0x2de32b2b090da7d8ab83ca4c85ba2eb6957bc7f6c50cb4ae1995e87560d808ed; + + // The type hash for ERC1155 orders, which is: + // keccak256(abi.encodePacked( + // "ERC1155Order(", + // "uint8 direction,", + // "address maker,", + // "address taker,", + // "uint256 expiry,", + // "uint256 nonce,", + // "address erc20Token,", + // "uint256 erc20TokenAmount,", + // "Fee[] fees,", + // "address erc1155Token,", + // "uint256 erc1155TokenId,", + // "Property[] erc1155TokenProperties,", + // "uint128 erc1155TokenAmount", + // ")", + // "Fee(", + // "address recipient,", + // "uint256 amount,", + // "bytes feeData", + // ")", + // "Property(", + // "address propertyValidator,", + // "bytes propertyData", + // ")" + // )) + uint256 private constant _ERC_1155_ORDER_TYPEHASH = + 0x930490b1bcedd2e5139e22c761fafd52e533960197c2283f3922c7fd8c880be9; + + // keccak256(abi.encodePacked( + // "Fee(", + // "address recipient,", + // "uint256 amount,", + // "bytes feeData", + // ")" + // )) + uint256 private constant _FEE_TYPEHASH = + 0xe68c29f1b4e8cce0bbcac76eb1334bdc1dc1f293a517c90e9e532340e1e94115; + + // keccak256(abi.encodePacked( + // "Property(", + // "address propertyValidator,", + // "bytes propertyData", + // ")" + // )) + uint256 private constant _PROPERTY_TYPEHASH = + 0x6292cf854241cb36887e639065eca63b3af9f7f70270cebeda4c29b6d3bc65e8; + + // keccak256(""); + bytes32 private constant _EMPTY_ARRAY_KECCAK256 = + 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + + // keccak256(abi.encodePacked(keccak256(abi.encode( + // _PROPERTY_TYPEHASH, + // address(0), + // keccak256("") + // )))); + bytes32 private constant _NULL_PROPERTY_STRUCT_HASH = + 0x720ee400a9024f6a49768142c339bf09d2dd9056ab52d20fbe7165faba6e142d; + + uint256 private constant ADDRESS_MASK = (1 << 160) - 1; + + // ERC721Order and NFTOrder fields are aligned, so + // we can safely cast an ERC721Order to an NFTOrder. + function asNFTOrder(ERC721Order memory erc721Order) + internal + pure + returns (NFTOrder memory nftOrder) + { + assembly { + nftOrder := erc721Order + } + } + + // ERC1155Order and NFTOrder fields are aligned with + // the exception of the last field `erc1155TokenAmount` + // in ERC1155Order, so we can safely cast an ERC1155Order + // to an NFTOrder. + function asNFTOrder(ERC1155Order memory erc1155Order) + internal + pure + returns (NFTOrder memory nftOrder) + { + assembly { + nftOrder := erc1155Order + } + } + + // ERC721Order and NFTOrder fields are aligned, so + // we can safely cast an MFTOrder to an ERC721Order. + function asERC721Order(NFTOrder memory nftOrder) + internal + pure + returns (ERC721Order memory erc721Order) + { + assembly { + erc721Order := nftOrder + } + } + + // NOTE: This is only safe if `nftOrder` was previously + // cast from an `ERC1155Order` and the original + // `erc1155TokenAmount` memory word has not been corrupted! + function asERC1155Order( + NFTOrder memory nftOrder + ) + internal + pure + returns (ERC1155Order memory erc1155Order) + { + assembly { + erc1155Order := nftOrder + } + } + + /// @dev Get the struct hash of an ERC721 order. + /// @param order The ERC721 order. + /// @return structHash The struct hash of the order. + function getERC721OrderStructHash(ERC721Order memory order) + internal + pure + returns (bytes32 structHash) + { + bytes32 propertiesHash = _propertiesHash(order.erc721TokenProperties); + bytes32 feesHash = _feesHash(order.fees); + + // Hash in place, equivalent to: + // return keccak256(abi.encode( + // _ERC_721_ORDER_TYPEHASH, + // order.direction, + // order.maker, + // order.taker, + // order.expiry, + // order.nonce, + // order.erc20Token, + // order.erc20TokenAmount, + // feesHash, + // order.erc721Token, + // order.erc721TokenId, + // propertiesHash + // )); + assembly { + if lt(order, 32) { invalid() } // Don't underflow memory. + + let typeHashPos := sub(order, 32) // order - 32 + let feesHashPos := add(order, 224) // order + (32 * 7) + let propertiesHashPos := add(order, 320) // order + (32 * 10) + + let typeHashMemBefore := mload(typeHashPos) + let feeHashMemBefore := mload(feesHashPos) + let propertiesHashMemBefore := mload(propertiesHashPos) + + mstore(typeHashPos, _ERC_721_ORDER_TYPEHASH) + mstore(feesHashPos, feesHash) + mstore(propertiesHashPos, propertiesHash) + structHash := keccak256(typeHashPos, 384 /* 32 * 12 */ ) + + mstore(typeHashPos, typeHashMemBefore) + mstore(feesHashPos, feeHashMemBefore) + mstore(propertiesHashPos, propertiesHashMemBefore) + } + return structHash; + } + + /// @dev Get the struct hash of an ERC1155 order. + /// @param order The ERC1155 order. + /// @return structHash The struct hash of the order. + function getERC1155OrderStructHash(ERC1155Order memory order) + internal + pure + returns (bytes32 structHash) + { + bytes32 propertiesHash = _propertiesHash(order.erc1155TokenProperties); + bytes32 feesHash = _feesHash(order.fees); + + // Hash in place, equivalent to: + // return keccak256(abi.encode( + // _ERC_1155_ORDER_TYPEHASH, + // order.direction, + // order.maker, + // order.taker, + // order.expiry, + // order.nonce, + // order.erc20Token, + // order.erc20TokenAmount, + // feesHash, + // order.erc1155Token, + // order.erc1155TokenId, + // propertiesHash, + // order.erc1155TokenAmount + // )); + assembly { + if lt(order, 32) { invalid() } // Don't underflow memory. + + let typeHashPos := sub(order, 32) // order - 32 + let feesHashPos := add(order, 224) // order + (32 * 7) + let propertiesHashPos := add(order, 320) // order + (32 * 10) + + let typeHashMemBefore := mload(typeHashPos) + let feesHashMemBefore := mload(feesHashPos) + let propertiesHashMemBefore := mload(propertiesHashPos) + + mstore(typeHashPos, _ERC_1155_ORDER_TYPEHASH) + mstore(feesHashPos, feesHash) + mstore(propertiesHashPos, propertiesHash) + structHash := keccak256(typeHashPos, 416 /* 32 * 12 */ ) + + mstore(typeHashPos, typeHashMemBefore) + mstore(feesHashPos, feesHashMemBefore) + mstore(propertiesHashPos, propertiesHashMemBefore) + } + return structHash; + } + + // Hashes the `properties` array as part of computing the + // EIP-712 hash of an `ERC721Order` or `ERC1155Order`. + function _propertiesHash(Property[] memory properties) + private + pure + returns (bytes32 propertiesHash) + { + uint256 numProperties = properties.length; + // We give `properties.length == 0` and `properties.length == 1` + // special treatment because we expect these to be the most common. + if (numProperties == 0) { + propertiesHash = _EMPTY_ARRAY_KECCAK256; + } else if (numProperties == 1) { + Property memory property = properties[0]; + if ( + address(property.propertyValidator) == address(0) && + property.propertyData.length == 0 + ) { + propertiesHash = _NULL_PROPERTY_STRUCT_HASH; + } else { + // propertiesHash = keccak256(abi.encodePacked(keccak256(abi.encode( + // _PROPERTY_TYPEHASH, + // properties[0].propertyValidator, + // keccak256(properties[0].propertyData) + // )))); + bytes32 dataHash = keccak256(property.propertyData); + assembly { + // Load free memory pointer + let mem := mload(64) + mstore(mem, _PROPERTY_TYPEHASH) + // property.propertyValidator + mstore(add(mem, 32), and(ADDRESS_MASK, mload(property))) + // keccak256(property.propertyData) + mstore(add(mem, 64), dataHash) + mstore(mem, keccak256(mem, 96)) + propertiesHash := keccak256(mem, 32) + } + } + } else { + bytes32[] memory propertyStructHashArray = new bytes32[](numProperties); + for (uint256 i = 0; i < numProperties; i++) { + propertyStructHashArray[i] = keccak256(abi.encode( + _PROPERTY_TYPEHASH, + properties[i].propertyValidator, + keccak256(properties[i].propertyData) + )); + } + assembly { + propertiesHash := keccak256(add(propertyStructHashArray, 32), mul(numProperties, 32)) + } + } + } + + // Hashes the `fees` array as part of computing the + // EIP-712 hash of an `ERC721Order` or `ERC1155Order`. + function _feesHash(Fee[] memory fees) + private + pure + returns (bytes32 feesHash) + { + uint256 numFees = fees.length; + // We give `fees.length == 0` and `fees.length == 1` + // special treatment because we expect these to be the most common. + if (numFees == 0) { + feesHash = _EMPTY_ARRAY_KECCAK256; + } else if (numFees == 1) { + // feesHash = keccak256(abi.encodePacked(keccak256(abi.encode( + // _FEE_TYPEHASH, + // fees[0].recipient, + // fees[0].amount, + // keccak256(fees[0].feeData) + // )))); + Fee memory fee = fees[0]; + bytes32 dataHash = keccak256(fee.feeData); + assembly { + // Load free memory pointer + let mem := mload(64) + mstore(mem, _FEE_TYPEHASH) + // fee.recipient + mstore(add(mem, 32), and(ADDRESS_MASK, mload(fee))) + // fee.amount + mstore(add(mem, 64), mload(add(fee, 32))) + // keccak256(fee.feeData) + mstore(add(mem, 96), dataHash) + mstore(mem, keccak256(mem, 128)) + feesHash := keccak256(mem, 32) + } + } else { + bytes32[] memory feeStructHashArray = new bytes32[](numFees); + for (uint256 i = 0; i < numFees; i++) { + feeStructHashArray[i] = keccak256(abi.encode( + _FEE_TYPEHASH, + fees[i].recipient, + fees[i].amount, + keccak256(fees[i].feeData) + )); + } + assembly { + feesHash := keccak256(add(feeStructHashArray, 32), mul(numFees, 32)) + } + } + } +} diff --git a/contracts/zero-ex/contracts/src/features/libs/LibSignature.sol b/contracts/zero-ex/contracts/src/features/libs/LibSignature.sol index cb5a204a6f..91e1b0a3fd 100644 --- a/contracts/zero-ex/contracts/src/features/libs/LibSignature.sol +++ b/contracts/zero-ex/contracts/src/features/libs/LibSignature.sol @@ -44,7 +44,8 @@ library LibSignature { ILLEGAL, INVALID, EIP712, - ETHSIGN + ETHSIGN, + PRESIGNED } /// @dev Encoded EC signature. @@ -146,6 +147,15 @@ library LibSignature { ).rrevert(); } + // If a feature supports pre-signing, it wouldn't use + // `getSignerOfHash` on a pre-signed order. + if (signature.signatureType == SignatureType.PRESIGNED) { + LibSignatureRichErrors.SignatureValidationError( + LibSignatureRichErrors.SignatureValidationErrorCodes.UNSUPPORTED, + hash + ).rrevert(); + } + // Solidity should check that the signature type is within enum range for us // when abi-decoding. } diff --git a/contracts/zero-ex/contracts/src/features/multiplex/MultiplexFeature.sol b/contracts/zero-ex/contracts/src/features/multiplex/MultiplexFeature.sol index c8e898b1fa..a300f41a00 100644 --- a/contracts/zero-ex/contracts/src/features/multiplex/MultiplexFeature.sol +++ b/contracts/zero-ex/contracts/src/features/multiplex/MultiplexFeature.sol @@ -622,15 +622,6 @@ contract MultiplexFeature is _executeBatchSell(batchSellParams).boughtAmount; } - // Transfers some amount of ETH to the given recipient and - // reverts if the transfer fails. - function _transferEth(address payable recipient, uint256 amount) - private - { - (bool success,) = recipient.call{value: amount}(""); - require(success, "MultiplexFeature::_transferEth/TRANSFER_FAILED"); - } - // This function computes the "target" address of hop index `i` within // a multi-hop sell. // If `i == 0`, the target is the address which should hold the input diff --git a/contracts/zero-ex/contracts/src/features/nft_orders/ERC1155OrdersFeature.sol b/contracts/zero-ex/contracts/src/features/nft_orders/ERC1155OrdersFeature.sol new file mode 100644 index 0000000000..4f2128874e --- /dev/null +++ b/contracts/zero-ex/contracts/src/features/nft_orders/ERC1155OrdersFeature.sol @@ -0,0 +1,635 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2021 ZeroEx 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; +pragma experimental ABIEncoderV2; + +import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol"; +import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol"; +import "../../fixins/FixinERC1155Spender.sol"; +import "../../migrations/LibMigrate.sol"; +import "../../storage/LibERC1155OrdersStorage.sol"; +import "../interfaces/IFeature.sol"; +import "../interfaces/IERC1155OrdersFeature.sol"; +import "../libs/LibNFTOrder.sol"; +import "../libs/LibSignature.sol"; +import "./NFTOrders.sol"; + + +/// @dev Feature for interacting with ERC1155 orders. +contract ERC1155OrdersFeature is + IFeature, + IERC1155OrdersFeature, + FixinERC1155Spender, + NFTOrders +{ + using LibSafeMathV06 for uint256; + using LibSafeMathV06 for uint128; + using LibNFTOrder for LibNFTOrder.ERC1155Order; + using LibNFTOrder for LibNFTOrder.NFTOrder; + + /// @dev Name of this feature. + string public constant override FEATURE_NAME = "ERC1155Orders"; + /// @dev Version of this feature. + uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 0, 0); + + /// @dev The magic return value indicating the success of a `onERC1155Received`. + bytes4 private constant ERC1155_RECEIVED_MAGIC_BYTES = this.onERC1155Received.selector; + + + constructor(address zeroExAddress, IEtherTokenV06 weth) + public + NFTOrders(zeroExAddress, weth) + {} + + /// @dev Initialize and register this feature. + /// Should be delegatecalled by `Migrate.migrate()`. + /// @return success `LibMigrate.SUCCESS` on success. + function migrate() + external + returns (bytes4 success) + { + _registerFeatureFunction(this.sellERC1155.selector); + _registerFeatureFunction(this.buyERC1155.selector); + _registerFeatureFunction(this.cancelERC1155Order.selector); + _registerFeatureFunction(this.batchBuyERC1155s.selector); + _registerFeatureFunction(this.onERC1155Received.selector); + _registerFeatureFunction(this.preSignERC1155Order.selector); + _registerFeatureFunction(this.validateERC1155OrderSignature.selector); + _registerFeatureFunction(this.validateERC1155OrderProperties.selector); + _registerFeatureFunction(this.getERC1155OrderInfo.selector); + _registerFeatureFunction(this.getERC1155OrderHash.selector); + return LibMigrate.MIGRATE_SUCCESS; + } + + /// @dev Sells an ERC1155 asset to fill the given order. + /// @param buyOrder The ERC1155 buy order. + /// @param signature The order signature from the maker. + /// @param erc1155TokenId The ID of the ERC1155 asset being + /// sold. If the given order specifies properties, + /// the asset must satisfy those properties. Otherwise, + /// it must equal the tokenId in the order. + /// @param erc1155SellAmount The amount of the ERC1155 asset + /// to sell. + /// @param unwrapNativeToken If this parameter is true and the + /// ERC20 token of the order is e.g. WETH, unwraps the + /// token before transferring it to the taker. + /// @param callbackData If this parameter is non-zero, invokes + /// `zeroExERC1155OrderCallback` on `msg.sender` after + /// the ERC20 tokens have been transferred to `msg.sender` + /// but before transferring the ERC1155 asset to the buyer. + function sellERC1155( + LibNFTOrder.ERC1155Order memory buyOrder, + LibSignature.Signature memory signature, + uint256 erc1155TokenId, + uint128 erc1155SellAmount, + bool unwrapNativeToken, + bytes memory callbackData + ) + public + override + { + _sellERC1155( + buyOrder, + signature, + SellParams( + erc1155SellAmount, + erc1155TokenId, + unwrapNativeToken, + msg.sender, // taker + msg.sender, // owner + callbackData + ) + ); + } + + /// @dev Buys an ERC1155 asset by filling the given order. + /// @param sellOrder The ERC1155 sell order. + /// @param signature The order signature. + /// @param erc1155BuyAmount The amount of the ERC1155 asset + /// to buy. + /// @param callbackData If this parameter is non-zero, invokes + /// `zeroExERC1155OrderCallback` on `msg.sender` after + /// the ERC1155 asset has been transferred to `msg.sender` + /// but before transferring the ERC20 tokens to the seller. + /// Native tokens acquired during the callback can be used + /// to fill the order. + function buyERC1155( + LibNFTOrder.ERC1155Order memory sellOrder, + LibSignature.Signature memory signature, + uint128 erc1155BuyAmount, + bytes memory callbackData + ) + public + override + payable + { + uint256 ethBalanceBefore = address(this).balance + .safeSub(msg.value); + _buyERC1155( + sellOrder, + signature, + BuyParams( + erc1155BuyAmount, + msg.value, + callbackData + ) + ); + uint256 ethBalanceAfter = address(this).balance; + // Cannot use pre-existing ETH balance + if (ethBalanceAfter < ethBalanceBefore) { + LibNFTOrdersRichErrors.OverspentEthError( + ethBalanceBefore - ethBalanceAfter + msg.value, + msg.value + ).rrevert(); + } + // Refund + _transferEth(msg.sender, ethBalanceAfter - ethBalanceBefore); + } + + /// @dev Cancel a single ERC1155 order by its nonce. The caller + /// should be the maker of the order. Silently succeeds if + /// an order with the same nonce has already been filled or + /// cancelled. + /// @param orderNonce The order nonce. + function cancelERC1155Order(uint256 orderNonce) + public + override + { + // The bitvector is indexed by the lower 8 bits of the nonce. + uint256 flag = 1 << (orderNonce & 255); + // Update order cancellation bit vector to indicate that the order + // has been cancelled/filled by setting the designated bit to 1. + LibERC1155OrdersStorage.getStorage().orderCancellationByMaker + [msg.sender][uint248(orderNonce >> 8)] |= flag; + + emit ERC1155OrderCancelled(msg.sender, orderNonce); + } + + /// @dev Cancel multiple ERC1155 orders by their nonces. The caller + /// should be the maker of the orders. Silently succeeds if + /// an order with the same nonce has already been filled or + /// cancelled. + /// @param orderNonces The order nonces. + function batchCancelERC1155Orders(uint256[] calldata orderNonces) + external + override + { + for (uint256 i = 0; i < orderNonces.length; i++) { + cancelERC1155Order(orderNonces[i]); + } + } + + /// @dev Buys multiple ERC1155 assets by filling the + /// given orders. + /// @param sellOrders The ERC1155 sell orders. + /// @param signatures The order signatures. + /// @param erc1155FillAmounts The amounts of the ERC1155 assets + /// to buy for each order. + /// @param callbackData The data (if any) to pass to the taker + /// callback for each order. Refer to the `callbackData` + /// parameter to for `buyERC1155`. + /// @param revertIfIncomplete If true, reverts if this + /// function fails to fill any individual order. + /// @return successes An array of booleans corresponding to whether + /// each order in `orders` was successfully filled. + function batchBuyERC1155s( + LibNFTOrder.ERC1155Order[] memory sellOrders, + LibSignature.Signature[] memory signatures, + uint128[] calldata erc1155FillAmounts, + bytes[] memory callbackData, + bool revertIfIncomplete + ) + public + override + payable + returns (bool[] memory successes) + { + require( + sellOrders.length == signatures.length && + sellOrders.length == erc1155FillAmounts.length && + sellOrders.length == callbackData.length, + "ERC1155OrdersFeature::batchBuyERC1155s/ARRAY_LENGTH_MISMATCH" + ); + successes = new bool[](sellOrders.length); + + uint256 ethBalanceBefore = address(this).balance + .safeSub(msg.value); + if (revertIfIncomplete) { + for (uint256 i = 0; i < sellOrders.length; i++) { + // Will revert if _buyERC1155 reverts. + _buyERC1155( + sellOrders[i], + signatures[i], + BuyParams( + erc1155FillAmounts[i], + address(this).balance.safeSub(ethBalanceBefore), // Remaining ETH available + callbackData[i] + ) + ); + successes[i] = true; + } + } else { + for (uint256 i = 0; i < sellOrders.length; i++) { + // Delegatecall `_buyERC1155` to catch swallow reverts while + // preserving execution context. + // Note that `_buyERC1155` is a public function but should _not_ + // be registered in the Exchange Proxy. + (successes[i], ) = _implementation.delegatecall( + abi.encodeWithSelector( + this._buyERC1155.selector, + sellOrders[i], + signatures[i], + BuyParams( + erc1155FillAmounts[i], + address(this).balance.safeSub(ethBalanceBefore), // Remaining ETH available + callbackData[i] + ) + ) + ); + } + } + + // Cannot use pre-existing ETH balance + uint256 ethBalanceAfter = address(this).balance; + if (ethBalanceAfter < ethBalanceBefore) { + LibNFTOrdersRichErrors.OverspentEthError( + msg.value + (ethBalanceBefore - ethBalanceAfter), + msg.value + ).rrevert(); + } + + // Refund + _transferEth(msg.sender, ethBalanceAfter - ethBalanceBefore); + } + + /// @dev Callback for the ERC1155 `safeTransferFrom` function. + /// This callback can be used to sell an ERC1155 asset if + /// a valid ERC1155 order, signature and `unwrapNativeToken` + /// are encoded in `data`. This allows takers to sell their + /// ERC1155 asset without first calling `setApprovalForAll`. + /// @param operator The address which called `safeTransferFrom`. + /// @param tokenId The ID of the asset being transferred. + /// @param value The amount being transferred. + /// @param data Additional data with no specified format. If a + /// valid ERC1155 order, signature and `unwrapNativeToken` + /// are encoded in `data`, this function will try to fill + /// the order using the received asset. + /// @return success The selector of this function (0xf23a6e61), + /// indicating that the callback succeeded. + function onERC1155Received( + address operator, + address /* from */, + uint256 tokenId, + uint256 value, + bytes calldata data + ) + external + override + returns (bytes4 success) + { + // Decode the order, signature, and `unwrapNativeToken` from + // `data`. If `data` does not encode such parameters, this + // will throw. + ( + LibNFTOrder.ERC1155Order memory buyOrder, + LibSignature.Signature memory signature, + bool unwrapNativeToken + ) = abi.decode( + data, + (LibNFTOrder.ERC1155Order, LibSignature.Signature, bool) + ); + + // `onERC1155Received` is called by the ERC1155 token contract. + // Check that it matches the ERC1155 token in the order. + if (msg.sender != address(buyOrder.erc1155Token)) { + LibNFTOrdersRichErrors.ERC1155TokenMismatchError( + msg.sender, + address(buyOrder.erc1155Token) + ).rrevert(); + } + + _sellERC1155( + buyOrder, + signature, + SellParams( + value.safeDowncastToUint128(), + tokenId, + unwrapNativeToken, + operator, // taker + address(this), // owner (we hold the NFT currently) + new bytes(0) // No taker callback + ) + ); + + return ERC1155_RECEIVED_MAGIC_BYTES; + } + + /// @dev Approves an ERC1155 order on-chain. After pre-signing + /// the order, the `PRESIGNED` signature type will become + /// valid for that order and signer. + /// @param order An ERC1155 order. + function preSignERC1155Order(LibNFTOrder.ERC1155Order memory order) + public + override + { + require( + order.maker == msg.sender, + "ERC1155OrdersFeature::preSignERC1155Order/MAKER_MISMATCH" + ); + bytes32 orderHash = getERC1155OrderHash(order); + + LibERC1155OrdersStorage.Storage storage stor = + LibERC1155OrdersStorage.getStorage(); + // Set `preSigned` to true on the order state variable + // to indicate that the order has been pre-signed. + stor.orderState[orderHash].preSigned = true; + + emit ERC1155OrderPreSigned( + order.direction, + order.maker, + order.taker, + order.expiry, + order.nonce, + order.erc20Token, + order.erc20TokenAmount, + order.fees, + order.erc1155Token, + order.erc1155TokenId, + order.erc1155TokenProperties, + order.erc1155TokenAmount + ); + } + + // Core settlement logic for selling an ERC1155 asset. + // Used by `sellERC1155` and `onERC1155Received`. + function _sellERC1155( + LibNFTOrder.ERC1155Order memory buyOrder, + LibSignature.Signature memory signature, + SellParams memory params + ) + private + { + uint256 erc20FillAmount = _sellNFT( + buyOrder.asNFTOrder(), + signature, + params + ); + + emit ERC1155OrderFilled( + buyOrder.direction, + buyOrder.maker, + params.taker, + buyOrder.nonce, + buyOrder.erc20Token, + erc20FillAmount, + buyOrder.erc1155Token, + params.tokenId, + params.sellAmount, + address(0) + ); + } + + // Core settlement logic for buying an ERC1155 asset. + // Used by `buyERC1155` and `batchBuyERC1155s`. + function _buyERC1155( + LibNFTOrder.ERC1155Order memory sellOrder, + LibSignature.Signature memory signature, + BuyParams memory params + ) + public + payable + { + uint256 erc20FillAmount = _buyNFT( + sellOrder.asNFTOrder(), + signature, + params + ); + + emit ERC1155OrderFilled( + sellOrder.direction, + sellOrder.maker, + msg.sender, + sellOrder.nonce, + sellOrder.erc20Token, + erc20FillAmount, + sellOrder.erc1155Token, + sellOrder.erc1155TokenId, + params.buyAmount, + address(0) + ); + } + + /// @dev Checks whether the given signature is valid for the + /// the given ERC1155 order. Reverts if not. + /// @param order The ERC1155 order. + /// @param signature The signature to validate. + function validateERC1155OrderSignature( + LibNFTOrder.ERC1155Order memory order, + LibSignature.Signature memory signature + ) + public + override + view + { + bytes32 orderHash = getERC1155OrderHash(order); + _validateOrderSignature(orderHash, signature, order.maker); + } + + /// @dev Validates that the given signature is valid for the + /// given maker and order hash. Reverts if the signature + /// is not valid. + /// @param orderHash The hash of the order that was signed. + /// @param signature The signature to check. + /// @param maker The maker of the order. + function _validateOrderSignature( + bytes32 orderHash, + LibSignature.Signature memory signature, + address maker + ) + internal + override + view + { + if (signature.signatureType == LibSignature.SignatureType.PRESIGNED) { + // Check if order hash has been pre-signed by the maker. + bool isPreSigned = LibERC1155OrdersStorage.getStorage() + .orderState[orderHash].preSigned; + if (!isPreSigned) { + LibNFTOrdersRichErrors.InvalidSignerError(maker, address(0)).rrevert(); + } + } else { + address signer = LibSignature.getSignerOfHash(orderHash, signature); + if (signer != maker) { + LibNFTOrdersRichErrors.InvalidSignerError(maker, signer).rrevert(); + } + } + } + + /// @dev Transfers an NFT asset. + /// @param token The address of the NFT contract. + /// @param from The address currently holding the asset. + /// @param to The address to transfer the asset to. + /// @param tokenId The ID of the asset to transfer. + /// @param amount The amount of the asset to transfer. Always + /// 1 for ERC721 assets. + function _transferNFTAssetFrom( + address token, + address from, + address to, + uint256 tokenId, + uint256 amount + ) + internal + override + { + _transferERC1155AssetFrom(IERC1155Token(token), from, to, tokenId, amount); + } + + /// @dev Updates storage to indicate that the given order + /// has been filled by the given amount. + /// @param orderHash The hash of `order`. + /// @param fillAmount The amount (denominated in the NFT asset) + /// that the order has been filled by. + function _updateOrderState( + LibNFTOrder.NFTOrder memory /* order */, + bytes32 orderHash, + uint128 fillAmount + ) + internal + override + { + LibERC1155OrdersStorage.Storage storage stor = LibERC1155OrdersStorage.getStorage(); + uint128 filledAmount = stor.orderState[orderHash].filledAmount; + // Filled amount should never overflow 128 bits + assert(filledAmount + fillAmount > filledAmount); + stor.orderState[orderHash].filledAmount = filledAmount + fillAmount; + } + + /// @dev If the given order is buying an ERC1155 asset, checks + /// whether or not the given token ID satisfies the required + /// properties specified in the order. If the order does not + /// specify any properties, this function instead checks + /// whether the given token ID matches the ID in the order. + /// Reverts if any checks fail, or if the order is selling + /// an ERC1155 asset. + /// @param order The ERC1155 order. + /// @param erc1155TokenId The ID of the ERC1155 asset. + function validateERC1155OrderProperties( + LibNFTOrder.ERC1155Order memory order, + uint256 erc1155TokenId + ) + public + override + view + { + _validateOrderProperties( + order.asNFTOrder(), + erc1155TokenId + ); + } + + /// @dev Get the order info for an ERC1155 order. + /// @param order The ERC1155 order. + /// @return orderInfo Info about the order. + function getERC1155OrderInfo(LibNFTOrder.ERC1155Order memory order) + public + override + view + returns (LibNFTOrder.OrderInfo memory orderInfo) + { + orderInfo.orderAmount = order.erc1155TokenAmount; + orderInfo.orderHash = getERC1155OrderHash(order); + + // Only buy orders with `erc1155TokenId` == 0 can be property + // orders. + if (order.erc1155TokenProperties.length > 0 && + (order.direction != LibNFTOrder.TradeDirection.BUY_NFT || + order.erc1155TokenId != 0)) + { + orderInfo.status = LibNFTOrder.OrderStatus.INVALID; + return orderInfo; + } + + // Buy orders cannot use ETH as the ERC20 token, since ETH cannot be + // transferred from the buyer by a contract. + if (order.direction == LibNFTOrder.TradeDirection.BUY_NFT && + address(order.erc20Token) == NATIVE_TOKEN_ADDRESS) + { + orderInfo.status = LibNFTOrder.OrderStatus.INVALID; + return orderInfo; + } + + // Check for expiry. + if (order.expiry <= block.timestamp) { + orderInfo.status = LibNFTOrder.OrderStatus.EXPIRED; + return orderInfo; + } + + { + LibERC1155OrdersStorage.Storage storage stor = + LibERC1155OrdersStorage.getStorage(); + + LibERC1155OrdersStorage.OrderState storage orderState = + stor.orderState[orderInfo.orderHash]; + orderInfo.remainingAmount = order.erc1155TokenAmount + .safeSub128(orderState.filledAmount); + + // `orderCancellationByMaker` is indexed by maker and nonce. + uint256 orderCancellationBitVector = + stor.orderCancellationByMaker[order.maker][uint248(order.nonce >> 8)]; + // The bitvector is indexed by the lower 8 bits of the nonce. + uint256 flag = 1 << (order.nonce & 255); + + if (orderInfo.remainingAmount == 0 || + orderCancellationBitVector & flag != 0) + { + orderInfo.status = LibNFTOrder.OrderStatus.UNFILLABLE; + return orderInfo; + } + } + + // Otherwise, the order is fillable. + orderInfo.status = LibNFTOrder.OrderStatus.FILLABLE; + } + + /// @dev Get the order info for an NFT order. + /// @param order The NFT order. + /// @return orderInfo Info about the order. + function _getOrderInfo(LibNFTOrder.NFTOrder memory order) + internal + override + view + returns (LibNFTOrder.OrderInfo memory orderInfo) + { + return getERC1155OrderInfo(order.asERC1155Order()); + } + + /// @dev Get the EIP-712 hash of an ERC1155 order. + /// @param order The ERC1155 order. + /// @return orderHash The order hash. + function getERC1155OrderHash(LibNFTOrder.ERC1155Order memory order) + public + override + view + returns (bytes32 orderHash) + { + return _getEIP712Hash(LibNFTOrder.getERC1155OrderStructHash(order)); + } +} diff --git a/contracts/zero-ex/contracts/src/features/nft_orders/ERC721OrdersFeature.sol b/contracts/zero-ex/contracts/src/features/nft_orders/ERC721OrdersFeature.sol new file mode 100644 index 0000000000..49b5d0a862 --- /dev/null +++ b/contracts/zero-ex/contracts/src/features/nft_orders/ERC721OrdersFeature.sol @@ -0,0 +1,931 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2021 ZeroEx 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; +pragma experimental ABIEncoderV2; + +import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol"; +import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol"; +import "../../fixins/FixinERC721Spender.sol"; +import "../../migrations/LibMigrate.sol"; +import "../../storage/LibERC721OrdersStorage.sol"; +import "../interfaces/IFeature.sol"; +import "../interfaces/IERC721OrdersFeature.sol"; +import "../libs/LibNFTOrder.sol"; +import "../libs/LibSignature.sol"; +import "./NFTOrders.sol"; + + +/// @dev Feature for interacting with ERC721 orders. +contract ERC721OrdersFeature is + IFeature, + IERC721OrdersFeature, + FixinERC721Spender, + NFTOrders +{ + using LibSafeMathV06 for uint256; + using LibNFTOrder for LibNFTOrder.ERC721Order; + using LibNFTOrder for LibNFTOrder.NFTOrder; + + /// @dev Name of this feature. + string public constant override FEATURE_NAME = "ERC721Orders"; + /// @dev Version of this feature. + uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 0, 0); + + /// @dev The magic return value indicating the success of a `onERC721Received`. + bytes4 private constant ERC721_RECEIVED_MAGIC_BYTES = this.onERC721Received.selector; + + + constructor(address zeroExAddress, IEtherTokenV06 weth) + public + NFTOrders(zeroExAddress, weth) + {} + + /// @dev Initialize and register this feature. + /// Should be delegatecalled by `Migrate.migrate()`. + /// @return success `LibMigrate.SUCCESS` on success. + function migrate() + external + returns (bytes4 success) + { + _registerFeatureFunction(this.sellERC721.selector); + _registerFeatureFunction(this.buyERC721.selector); + _registerFeatureFunction(this.cancelERC721Order.selector); + _registerFeatureFunction(this.batchBuyERC721s.selector); + _registerFeatureFunction(this.matchERC721Orders.selector); + _registerFeatureFunction(this.batchMatchERC721Orders.selector); + _registerFeatureFunction(this.onERC721Received.selector); + _registerFeatureFunction(this.preSignERC721Order.selector); + _registerFeatureFunction(this.validateERC721OrderSignature.selector); + _registerFeatureFunction(this.validateERC721OrderProperties.selector); + _registerFeatureFunction(this.getERC721OrderStatus.selector); + _registerFeatureFunction(this.getERC721OrderHash.selector); + _registerFeatureFunction(this.getERC721OrderStatusBitVector.selector); + return LibMigrate.MIGRATE_SUCCESS; + } + + /// @dev Sells an ERC721 asset to fill the given order. + /// @param buyOrder The ERC721 buy order. + /// @param signature The order signature from the maker. + /// @param erc721TokenId The ID of the ERC721 asset being + /// sold. If the given order specifies properties, + /// the asset must satisfy those properties. Otherwise, + /// it must equal the tokenId in the order. + /// @param unwrapNativeToken If this parameter is true and the + /// ERC20 token of the order is e.g. WETH, unwraps the + /// token before transferring it to the taker. + /// @param callbackData If this parameter is non-zero, invokes + /// `zeroExERC721OrderCallback` on `msg.sender` after + /// the ERC20 tokens have been transferred to `msg.sender` + /// but before transferring the ERC721 asset to the buyer. + function sellERC721( + LibNFTOrder.ERC721Order memory buyOrder, + LibSignature.Signature memory signature, + uint256 erc721TokenId, + bool unwrapNativeToken, + bytes memory callbackData + ) + public + override + { + _sellERC721( + buyOrder, + signature, + erc721TokenId, + unwrapNativeToken, + msg.sender, // taker + msg.sender, // owner + callbackData + ); + } + + /// @dev Buys an ERC721 asset by filling the given order. + /// @param sellOrder The ERC721 sell order. + /// @param signature The order signature. + /// @param callbackData If this parameter is non-zero, invokes + /// `zeroExERC721OrderCallback` on `msg.sender` after + /// the ERC721 asset has been transferred to `msg.sender` + /// but before transferring the ERC20 tokens to the seller. + /// Native tokens acquired during the callback can be used + /// to fill the order. + function buyERC721( + LibNFTOrder.ERC721Order memory sellOrder, + LibSignature.Signature memory signature, + bytes memory callbackData + ) + public + override + payable + { + uint256 ethBalanceBefore = address(this).balance + .safeSub(msg.value); + _buyERC721( + sellOrder, + signature, + msg.value, + callbackData + ); + uint256 ethBalanceAfter = address(this).balance; + // Cannot use pre-existing ETH balance + if (ethBalanceAfter < ethBalanceBefore) { + LibNFTOrdersRichErrors.OverspentEthError( + msg.value + (ethBalanceBefore - ethBalanceAfter), + msg.value + ).rrevert(); + } + // Refund + _transferEth(msg.sender, ethBalanceAfter - ethBalanceBefore); + } + + /// @dev Cancel a single ERC721 order by its nonce. The caller + /// should be the maker of the order. Silently succeeds if + /// an order with the same nonce has already been filled or + /// cancelled. + /// @param orderNonce The order nonce. + function cancelERC721Order(uint256 orderNonce) + public + override + { + // Mark order as cancelled + _setOrderStatusBit(msg.sender, orderNonce); + emit ERC721OrderCancelled(msg.sender, orderNonce); + } + + /// @dev Cancel multiple ERC721 orders by their nonces. The caller + /// should be the maker of the orders. Silently succeeds if + /// an order with the same nonce has already been filled or + /// cancelled. + /// @param orderNonces The order nonces. + function batchCancelERC721Orders(uint256[] calldata orderNonces) + external + override + { + for (uint256 i = 0; i < orderNonces.length; i++) { + cancelERC721Order(orderNonces[i]); + } + } + + /// @dev Buys multiple ERC721 assets by filling the + /// given orders. + /// @param sellOrders The ERC721 sell orders. + /// @param signatures The order signatures. + /// @param revertIfIncomplete If true, reverts if this + /// function fails to fill any individual order. + /// @param callbackData The data (if any) to pass to the taker + /// callback for each order. Refer to the `callbackData` + /// parameter to for `buyERC721`. + /// @return successes An array of booleans corresponding to whether + /// each order in `orders` was successfully filled. + function batchBuyERC721s( + LibNFTOrder.ERC721Order[] memory sellOrders, + LibSignature.Signature[] memory signatures, + bytes[] memory callbackData, + bool revertIfIncomplete + ) + public + override + payable + returns (bool[] memory successes) + { + require( + sellOrders.length == signatures.length && + sellOrders.length == callbackData.length, + "ERC721OrdersFeature::batchBuyERC721s/ARRAY_LENGTH_MISMATCH" + ); + successes = new bool[](sellOrders.length); + + uint256 ethBalanceBefore = address(this).balance + .safeSub(msg.value); + if (revertIfIncomplete) { + for (uint256 i = 0; i < sellOrders.length; i++) { + // Will revert if _buyERC721 reverts. + _buyERC721( + sellOrders[i], + signatures[i], + address(this).balance.safeSub(ethBalanceBefore), + callbackData[i] + ); + successes[i] = true; + } + } else { + for (uint256 i = 0; i < sellOrders.length; i++) { + // Delegatecall `_buyERC721` to swallow reverts while + // preserving execution context. + // Note that `_buyERC721` is a public function but should _not_ + // be registered in the Exchange Proxy. + (successes[i], ) = _implementation.delegatecall( + abi.encodeWithSelector( + this._buyERC721.selector, + sellOrders[i], + signatures[i], + address(this).balance.safeSub(ethBalanceBefore), // Remaining ETH available + callbackData[i] + ) + ); + } + } + + // Cannot use pre-existing ETH balance + uint256 ethBalanceAfter = address(this).balance; + if (ethBalanceAfter < ethBalanceBefore) { + LibNFTOrdersRichErrors.OverspentEthError( + msg.value + (ethBalanceBefore - ethBalanceAfter), + msg.value + ).rrevert(); + } + + // Refund + _transferEth(msg.sender, ethBalanceAfter - ethBalanceBefore); + } + + /// @dev Matches a pair of complementary orders that have + /// a non-negative spread. Each order is filled at + /// their respective price, and the matcher receives + /// a profit denominated in the ERC20 token. + /// @param sellOrder Order selling an ERC721 asset. + /// @param buyOrder Order buying an ERC721 asset. + /// @param sellOrderSignature Signature for the sell order. + /// @param buyOrderSignature Signature for the buy order. + /// @return profit The amount of profit earned by the caller + /// of this function (denominated in the ERC20 token + /// of the matched orders). + function matchERC721Orders( + LibNFTOrder.ERC721Order memory sellOrder, + LibNFTOrder.ERC721Order memory buyOrder, + LibSignature.Signature memory sellOrderSignature, + LibSignature.Signature memory buyOrderSignature + ) + public + override + returns (uint256 profit) + { + // The ERC721 tokens must match + if (sellOrder.erc721Token != buyOrder.erc721Token) { + LibNFTOrdersRichErrors.ERC721TokenMismatchError( + address(sellOrder.erc721Token), + address(buyOrder.erc721Token) + ).rrevert(); + } + + LibNFTOrder.NFTOrder memory sellNFTOrder = sellOrder.asNFTOrder(); + LibNFTOrder.NFTOrder memory buyNFTOrder = buyOrder.asNFTOrder(); + + { + LibNFTOrder.OrderInfo memory sellOrderInfo = _getOrderInfo(sellNFTOrder); + LibNFTOrder.OrderInfo memory buyOrderInfo = _getOrderInfo(buyNFTOrder); + + _validateSellOrder( + sellNFTOrder, + sellOrderSignature, + sellOrderInfo, + buyOrder.maker + ); + _validateBuyOrder( + buyNFTOrder, + buyOrderSignature, + buyOrderInfo, + sellOrder.maker, + sellOrder.erc721TokenId + ); + + // Mark both orders as filled. + _updateOrderState(sellNFTOrder, sellOrderInfo.orderHash, 1); + _updateOrderState(buyNFTOrder, buyOrderInfo.orderHash, 1); + } + + // The buyer must be willing to pay at least the amount that the + // seller is asking. + if (buyOrder.erc20TokenAmount < sellOrder.erc20TokenAmount) { + LibNFTOrdersRichErrors.NegativeSpreadError( + sellOrder.erc20TokenAmount, + buyOrder.erc20TokenAmount + ).rrevert(); + } + + // The difference in ERC20 token amounts is the spread. + uint256 spread = buyOrder.erc20TokenAmount - sellOrder.erc20TokenAmount; + + // Transfer the ERC721 asset from seller to buyer. + _transferERC721AssetFrom( + sellOrder.erc721Token, + sellOrder.maker, + buyOrder.maker, + sellOrder.erc721TokenId + ); + + // Handle the ERC20 side of the order: + if ( + address(sellOrder.erc20Token) == NATIVE_TOKEN_ADDRESS && + buyOrder.erc20Token == WETH + ) { + // The sell order specifies ETH, while the buy order specifies WETH. + // The orders are still compatible with one another, but we'll have + // to unwrap the WETH on behalf of the buyer. + + // Step 1: Transfer WETH from the buyer to the EP. + // Note that we transfer `buyOrder.erc20TokenAmount`, which + // is the amount the buyer signaled they are willing to pay + // for the ERC721 asset, which may be more than the seller's + // ask. + _transferERC20TokensFrom( + WETH, + buyOrder.maker, + address(this), + buyOrder.erc20TokenAmount + ); + // Step 2: Unwrap the WETH into ETH. We unwrap the entire + // `buyOrder.erc20TokenAmount`. + // The ETH will be used for three purposes: + // - To pay the seller + // - To pay fees for the sell order + // - Any remaining ETH will be sent to + // `msg.sender` as profit. + WETH.withdraw(buyOrder.erc20TokenAmount); + + // Step 3: Pay the seller (in ETH). + _transferEth(payable(sellOrder.maker), sellOrder.erc20TokenAmount); + + // Step 4: Pay fees for the buy order. Note that these are paid + // in _WETH_ by the _buyer_. By signing the buy order, the + // buyer signals that they are willing to spend a total + // of `erc20TokenAmount` _plus_ fees, all denominated in + // the `erc20Token`, which in this case is WETH. + _payFees( + buyNFTOrder, + buyOrder.maker, // payer + 1, // fillAmount + 1, // orderAmount + false // useNativeToken + ); + + // Step 5: Pay fees for the sell order. The `erc20Token` of the + // sell order is ETH, so the fees are paid out in ETH. + // There should be `spread` wei of ETH remaining in the + // EP at this point, which we will use ETH to pay the + // sell order fees. + uint256 sellOrderFees = _payFees( + sellNFTOrder, + address(this), // payer + 1, // fillAmount + 1, // orderAmount + true // useNativeToken + ); + + // Step 6: The spread must be enough to cover the sell order fees. + // If not, either `_payFees` will have reverted, or we + // have spent ETH that was in the EP before this + // `matchERC721Orders` call, which we disallow. + if (spread < sellOrderFees) { + LibNFTOrdersRichErrors.SellOrderFeesExceedSpreadError( + sellOrderFees, + spread + ).rrevert(); + } + // Step 7: The spread less the sell order fees is the amount of ETH + // remaining in the EP that can be sent to `msg.sender` as + // the profit from matching these two orders. + profit = spread - sellOrderFees; + if (profit > 0) { + _transferEth(msg.sender, profit); + } + } else { + // ERC20 tokens must match + if (sellOrder.erc20Token != buyOrder.erc20Token) { + LibNFTOrdersRichErrors.ERC20TokenMismatchError( + address(sellOrder.erc20Token), + address(buyOrder.erc20Token) + ).rrevert(); + } + + // Step 1: Transfer the ERC20 token from the buyer to the seller. + // Note that we transfer `sellOrder.erc20TokenAmount`, which + // is at most `buyOrder.erc20TokenAmount`. + _transferERC20TokensFrom( + buyOrder.erc20Token, + buyOrder.maker, + sellOrder.maker, + sellOrder.erc20TokenAmount + ); + + // Step 2: Pay fees for the buy order. Note that these are paid + // by the buyer. By signing the buy order, the buyer signals + // that they are willing to spend a total of + // `buyOrder.erc20TokenAmount` _plus_ `buyOrder.fees`. + _payFees( + buyNFTOrder, + buyOrder.maker, // payer + 1, // fillAmount + 1, // orderAmount + false // useNativeToken + ); + + // Step 3: Pay fees for the sell order. These are paid by the buyer + // as well. After paying these fees, we may have taken more + // from the buyer than they agreed to in the buy order. If + // so, we revert in the following step. + uint256 sellOrderFees = _payFees( + sellNFTOrder, + buyOrder.maker, // payer + 1, // fillAmount + 1, // orderAmount + false // useNativeToken + ); + + // Step 4: The spread must be enough to cover the sell order fees. + // If not, `_payFees` will have taken more tokens from the + // buyer than they had agreed to in the buy order, in which + // case we revert here. + if (spread < sellOrderFees) { + LibNFTOrdersRichErrors.SellOrderFeesExceedSpreadError( + sellOrderFees, + spread + ).rrevert(); + } + + // Step 5: We calculate the profit as: + // profit = buyOrder.erc20TokenAmount - sellOrder.erc20TokenAmount - sellOrderFees + // = spread - sellOrderFees + // I.e. the buyer would've been willing to pay up to `profit` + // more to buy the asset, so instead that amount is sent to + // `msg.sender` as the profit from matching these two orders. + profit = spread - sellOrderFees; + if (profit > 0) { + _transferERC20TokensFrom( + buyOrder.erc20Token, + buyOrder.maker, + msg.sender, + profit + ); + } + } + + emit ERC721OrderFilled( + sellOrder.direction, + sellOrder.maker, + buyOrder.maker, // taker + sellOrder.nonce, + sellOrder.erc20Token, + sellOrder.erc20TokenAmount, + sellOrder.erc721Token, + sellOrder.erc721TokenId, + msg.sender + ); + + emit ERC721OrderFilled( + buyOrder.direction, + buyOrder.maker, + sellOrder.maker, // taker + buyOrder.nonce, + buyOrder.erc20Token, + buyOrder.erc20TokenAmount, + buyOrder.erc721Token, + sellOrder.erc721TokenId, + msg.sender + ); + } + + /// @dev Matches pairs of complementary orders that have + /// non-negative spreads. Each order is filled at + /// their respective price, and the matcher receives + /// a profit denominated in the ERC20 token. + /// @param sellOrders Orders selling ERC721 assets. + /// @param buyOrders Orders buying ERC721 assets. + /// @param sellOrderSignatures Signatures for the sell orders. + /// @param buyOrderSignatures Signatures for the buy orders. + /// @return profits The amount of profit earned by the caller + /// of this function for each pair of matched orders + /// (denominated in the ERC20 token of the order pair). + /// @return successes An array of booleans corresponding to + /// whether each pair of orders was successfully matched. + function batchMatchERC721Orders( + LibNFTOrder.ERC721Order[] memory sellOrders, + LibNFTOrder.ERC721Order[] memory buyOrders, + LibSignature.Signature[] memory sellOrderSignatures, + LibSignature.Signature[] memory buyOrderSignatures + ) + public + override + returns (uint256[] memory profits, bool[] memory successes) + { + require( + sellOrders.length == buyOrders.length && + sellOrderSignatures.length == buyOrderSignatures.length && + sellOrders.length == sellOrderSignatures.length, + "ERC721OrdersFeature::batchMatchERC721Orders/ARRAY_LENGTH_MISMATCH" + ); + profits = new uint256[](sellOrders.length); + successes = new bool[](sellOrders.length); + + for (uint256 i = 0; i < sellOrders.length; i++) { + bytes memory returnData; + // Delegatecall `matchERC721Orders` to catch reverts while + // preserving execution context. + (successes[i], returnData) = _implementation.delegatecall( + abi.encodeWithSelector( + this.matchERC721Orders.selector, + sellOrders[i], + buyOrders[i], + sellOrderSignatures[i], + buyOrderSignatures[i] + ) + ); + if (successes[i]) { + // If the matching succeeded, record the profit. + (uint256 profit) = abi.decode(returnData, (uint256)); + profits[i] = profit; + } + } + } + + /// @dev Callback for the ERC721 `safeTransferFrom` function. + /// This callback can be used to sell an ERC721 asset if + /// a valid ERC721 order, signature and `unwrapNativeToken` + /// are encoded in `data`. This allows takers to sell their + /// ERC721 asset without first calling `setApprovalForAll`. + /// @param operator The address which called `safeTransferFrom`. + /// @param tokenId The ID of the asset being transferred. + /// @param data Additional data with no specified format. If a + /// valid ERC721 order, signature and `unwrapNativeToken` + /// are encoded in `data`, this function will try to fill + /// the order using the received asset. + /// @return success The selector of this function (0x150b7a02), + /// indicating that the callback succeeded. + function onERC721Received( + address operator, + address /* from */, + uint256 tokenId, + bytes calldata data + ) + external + override + returns (bytes4 success) + { + // Decode the order, signature, and `unwrapNativeToken` from + // `data`. If `data` does not encode such parameters, this + // will throw. + ( + LibNFTOrder.ERC721Order memory buyOrder, + LibSignature.Signature memory signature, + bool unwrapNativeToken + ) = abi.decode( + data, + (LibNFTOrder.ERC721Order, LibSignature.Signature, bool) + ); + + // `onERC721Received` is called by the ERC721 token contract. + // Check that it matches the ERC721 token in the order. + if (msg.sender != address(buyOrder.erc721Token)) { + LibNFTOrdersRichErrors.ERC721TokenMismatchError( + msg.sender, + address(buyOrder.erc721Token) + ).rrevert(); + } + + _sellERC721( + buyOrder, + signature, + tokenId, + unwrapNativeToken, + operator, // taker + address(this), // owner (we hold the NFT currently) + new bytes(0) // No taker callback + ); + + return ERC721_RECEIVED_MAGIC_BYTES; + } + + /// @dev Approves an ERC721 order on-chain. After pre-signing + /// the order, the `PRESIGNED` signature type will become + /// valid for that order and signer. + /// @param order An ERC721 order. + function preSignERC721Order(LibNFTOrder.ERC721Order memory order) + public + override + { + require( + order.maker == msg.sender, + "ERC721OrdersFeature::preSignERC721Order/ONLY_MAKER" + ); + bytes32 orderHash = getERC721OrderHash(order); + LibERC721OrdersStorage.getStorage().preSigned[orderHash] = true; + + emit ERC721OrderPreSigned( + order.direction, + order.maker, + order.taker, + order.expiry, + order.nonce, + order.erc20Token, + order.erc20TokenAmount, + order.fees, + order.erc721Token, + order.erc721TokenId, + order.erc721TokenProperties + ); + } + + // Core settlement logic for selling an ERC721 asset. + // Used by `sellERC721` and `onERC721Received`. + function _sellERC721( + LibNFTOrder.ERC721Order memory buyOrder, + LibSignature.Signature memory signature, + uint256 erc721TokenId, + bool unwrapNativeToken, + address taker, + address currentNftOwner, + bytes memory takerCallbackData + ) + private + { + _sellNFT( + buyOrder.asNFTOrder(), + signature, + SellParams( + 1, // sell amount + erc721TokenId, + unwrapNativeToken, + taker, + currentNftOwner, + takerCallbackData + ) + ); + + emit ERC721OrderFilled( + buyOrder.direction, + buyOrder.maker, + taker, + buyOrder.nonce, + buyOrder.erc20Token, + buyOrder.erc20TokenAmount, + buyOrder.erc721Token, + erc721TokenId, + address(0) + ); + } + + // Core settlement logic for buying an ERC721 asset. + // Used by `buyERC721` and `batchBuyERC721s`. + function _buyERC721( + LibNFTOrder.ERC721Order memory sellOrder, + LibSignature.Signature memory signature, + uint256 ethAvailable, + bytes memory takerCallbackData + ) + public + payable + { + _buyNFT( + sellOrder.asNFTOrder(), + signature, + BuyParams( + 1, // buy amount + ethAvailable, + takerCallbackData + ) + ); + + emit ERC721OrderFilled( + sellOrder.direction, + sellOrder.maker, + msg.sender, + sellOrder.nonce, + sellOrder.erc20Token, + sellOrder.erc20TokenAmount, + sellOrder.erc721Token, + sellOrder.erc721TokenId, + address(0) + ); + } + + + /// @dev Checks whether the given signature is valid for the + /// the given ERC721 order. Reverts if not. + /// @param order The ERC721 order. + /// @param signature The signature to validate. + function validateERC721OrderSignature( + LibNFTOrder.ERC721Order memory order, + LibSignature.Signature memory signature + ) + public + override + view + { + bytes32 orderHash = getERC721OrderHash(order); + _validateOrderSignature(orderHash, signature, order.maker); + } + + /// @dev Validates that the given signature is valid for the + /// given maker and order hash. Reverts if the signature + /// is not valid. + /// @param orderHash The hash of the order that was signed. + /// @param signature The signature to check. + /// @param maker The maker of the order. + function _validateOrderSignature( + bytes32 orderHash, + LibSignature.Signature memory signature, + address maker + ) + internal + override + view + { + if (signature.signatureType == LibSignature.SignatureType.PRESIGNED) { + // Check if order hash has been pre-signed by the maker. + bool isPreSigned = LibERC721OrdersStorage.getStorage().preSigned[orderHash]; + if (!isPreSigned) { + LibNFTOrdersRichErrors.InvalidSignerError(maker, address(0)).rrevert(); + } + } else { + address signer = LibSignature.getSignerOfHash(orderHash, signature); + if (signer != maker) { + LibNFTOrdersRichErrors.InvalidSignerError(maker, signer).rrevert(); + } + } + } + + /// @dev Transfers an NFT asset. + /// @param token The address of the NFT contract. + /// @param from The address currently holding the asset. + /// @param to The address to transfer the asset to. + /// @param tokenId The ID of the asset to transfer. + /// @param amount The amount of the asset to transfer. Always + /// 1 for ERC721 assets. + function _transferNFTAssetFrom( + address token, + address from, + address to, + uint256 tokenId, + uint256 amount + ) + internal + override + { + assert(amount == 1); + _transferERC721AssetFrom(IERC721Token(token), from, to, tokenId); + } + + /// @dev Updates storage to indicate that the given order + /// has been filled by the given amount. + /// @param order The order that has been filled. + /// @param fillAmount The amount (denominated in the NFT asset) + /// that the order has been filled by. + function _updateOrderState( + LibNFTOrder.NFTOrder memory order, + bytes32 /* orderHash */, + uint128 fillAmount + ) + internal + override + { + assert(fillAmount == 1); + _setOrderStatusBit(order.maker, order.nonce); + } + + function _setOrderStatusBit(address maker, uint256 nonce) + private + { + // The bitvector is indexed by the lower 8 bits of the nonce. + uint256 flag = 1 << (nonce & 255); + // Update order status bit vector to indicate that the given order + // has been cancelled/filled by setting the designated bit to 1. + LibERC721OrdersStorage.getStorage().orderStatusByMaker + [maker][uint248(nonce >> 8)] |= flag; + } + + /// @dev If the given order is buying an ERC721 asset, checks + /// whether or not the given token ID satisfies the required + /// properties specified in the order. If the order does not + /// specify any properties, this function instead checks + /// whether the given token ID matches the ID in the order. + /// Reverts if any checks fail, or if the order is selling + /// an ERC721 asset. + /// @param order The ERC721 order. + /// @param erc721TokenId The ID of the ERC721 asset. + function validateERC721OrderProperties( + LibNFTOrder.ERC721Order memory order, + uint256 erc721TokenId + ) + public + override + view + { + _validateOrderProperties( + order.asNFTOrder(), + erc721TokenId + ); + } + + /// @dev Get the current status of an ERC721 order. + /// @param order The ERC721 order. + /// @return status The status of the order. + function getERC721OrderStatus(LibNFTOrder.ERC721Order memory order) + public + override + view + returns (LibNFTOrder.OrderStatus status) + { + // Only buy orders with `erc721TokenId` == 0 can be property + // orders. + if (order.erc721TokenProperties.length > 0 && + (order.direction != LibNFTOrder.TradeDirection.BUY_NFT || + order.erc721TokenId != 0)) + { + return LibNFTOrder.OrderStatus.INVALID; + } + + // Buy orders cannot use ETH as the ERC20 token, since ETH cannot be + // transferred from the buyer by a contract. + if (order.direction == LibNFTOrder.TradeDirection.BUY_NFT && + address(order.erc20Token) == NATIVE_TOKEN_ADDRESS) + { + return LibNFTOrder.OrderStatus.INVALID; + } + + // Check for expiry. + if (order.expiry <= block.timestamp) { + return LibNFTOrder.OrderStatus.EXPIRED; + } + + // Check `orderStatusByMaker` state variable to see if the order + // has been cancelled or previously filled. + LibERC721OrdersStorage.Storage storage stor = + LibERC721OrdersStorage.getStorage(); + // `orderStatusByMaker` is indexed by maker and nonce. + uint256 orderStatusBitVector = + stor.orderStatusByMaker[order.maker][uint248(order.nonce >> 8)]; + // The bitvector is indexed by the lower 8 bits of the nonce. + uint256 flag = 1 << (order.nonce & 255); + // If the designated bit is set, the order has been cancelled or + // previously filled, so it is now unfillable. + if (orderStatusBitVector & flag != 0) { + return LibNFTOrder.OrderStatus.UNFILLABLE; + } + + // Otherwise, the order is fillable. + return LibNFTOrder.OrderStatus.FILLABLE; + } + + /// @dev Get the order info for an NFT order. + /// @param order The NFT order. + /// @return orderInfo Info about the order. + function _getOrderInfo(LibNFTOrder.NFTOrder memory order) + internal + override + view + returns (LibNFTOrder.OrderInfo memory orderInfo) + { + LibNFTOrder.ERC721Order memory erc721Order = order.asERC721Order(); + orderInfo.orderHash = getERC721OrderHash(erc721Order); + orderInfo.status = getERC721OrderStatus(erc721Order); + orderInfo.orderAmount = 1; + orderInfo.remainingAmount = orderInfo.status == LibNFTOrder.OrderStatus.FILLABLE ? 1 : 0; + } + + /// @dev Get the EIP-712 hash of an ERC721 order. + /// @param order The ERC721 order. + /// @return orderHash The order hash. + function getERC721OrderHash(LibNFTOrder.ERC721Order memory order) + public + override + view + returns (bytes32 orderHash) + { + return _getEIP712Hash(LibNFTOrder.getERC721OrderStructHash(order)); + } + + /// @dev Get the order status bit vector for the given + /// maker address and nonce range. + /// @param maker The maker of the order. + /// @param nonceRange Order status bit vectors are indexed + /// by maker address and the upper 248 bits of the + /// order nonce. We define `nonceRange` to be these + /// 248 bits. + /// @return bitVector The order status bit vector for the + /// given maker and nonce range. + function getERC721OrderStatusBitVector(address maker, uint248 nonceRange) + external + override + view + returns (uint256 bitVector) + { + LibERC721OrdersStorage.Storage storage stor = + LibERC721OrdersStorage.getStorage(); + return stor.orderStatusByMaker[maker][nonceRange]; + } +} diff --git a/contracts/zero-ex/contracts/src/features/nft_orders/NFTOrders.sol b/contracts/zero-ex/contracts/src/features/nft_orders/NFTOrders.sol new file mode 100644 index 0000000000..10272683ce --- /dev/null +++ b/contracts/zero-ex/contracts/src/features/nft_orders/NFTOrders.sol @@ -0,0 +1,615 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2021 ZeroEx 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; +pragma experimental ABIEncoderV2; + +import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; +import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol"; +import "@0x/contracts-utils/contracts/src/v06/LibMathV06.sol"; +import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol"; +import "../../errors/LibNFTOrdersRichErrors.sol"; +import "../../fixins/FixinCommon.sol"; +import "../../fixins/FixinEIP712.sol"; +import "../../fixins/FixinTokenSpender.sol"; +import "../../migrations/LibMigrate.sol"; +import "../../vendor/IFeeRecipient.sol"; +import "../../vendor/ITakerCallback.sol"; +import "../libs/LibSignature.sol"; +import "../libs/LibNFTOrder.sol"; + + +/// @dev Abstract base contract inherited by ERC721OrdersFeature and NFTOrders +abstract contract NFTOrders is + FixinCommon, + FixinEIP712, + FixinTokenSpender +{ + using LibSafeMathV06 for uint256; + + /// @dev Native token pseudo-address. + address constant internal NATIVE_TOKEN_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; + /// @dev The WETH token contract. + IEtherTokenV06 internal immutable WETH; + + /// @dev The magic return value indicating the success of a `receiveZeroExFeeCallback`. + bytes4 private constant FEE_CALLBACK_MAGIC_BYTES = IFeeRecipient.receiveZeroExFeeCallback.selector; + /// @dev The magic return value indicating the success of a `zeroExTakerCallback`. + bytes4 private constant TAKER_CALLBACK_MAGIC_BYTES = ITakerCallback.zeroExTakerCallback.selector; + + constructor(address zeroExAddress, IEtherTokenV06 weth) + public + FixinEIP712(zeroExAddress) + { + WETH = weth; + } + + struct SellParams { + uint128 sellAmount; + uint256 tokenId; + bool unwrapNativeToken; + address taker; + address currentNftOwner; + bytes takerCallbackData; + } + + struct BuyParams { + uint128 buyAmount; + uint256 ethAvailable; + bytes takerCallbackData; + } + + // Core settlement logic for selling an NFT asset. + function _sellNFT( + LibNFTOrder.NFTOrder memory buyOrder, + LibSignature.Signature memory signature, + SellParams memory params + ) + internal + returns (uint256 erc20FillAmount) + { + LibNFTOrder.OrderInfo memory orderInfo = _getOrderInfo(buyOrder); + // Check that the order can be filled. + _validateBuyOrder( + buyOrder, + signature, + orderInfo, + params.taker, + params.tokenId + ); + + if (params.sellAmount > orderInfo.remainingAmount) { + LibNFTOrdersRichErrors.ExceedsRemainingOrderAmount( + orderInfo.remainingAmount, + params.sellAmount + ).rrevert(); + } + + _updateOrderState(buyOrder, orderInfo.orderHash, params.sellAmount); + + if (params.sellAmount == orderInfo.orderAmount) { + erc20FillAmount = buyOrder.erc20TokenAmount; + } else { + // Rounding favors the order maker. + erc20FillAmount = LibMathV06.getPartialAmountFloor( + params.sellAmount, + orderInfo.orderAmount, + buyOrder.erc20TokenAmount + ); + } + + if (params.unwrapNativeToken) { + // The ERC20 token must be WETH for it to be unwrapped. + if (buyOrder.erc20Token != WETH) { + LibNFTOrdersRichErrors.ERC20TokenMismatchError( + address(buyOrder.erc20Token), + address(WETH) + ).rrevert(); + } + // Transfer the WETH from the maker to the Exchange Proxy + // so we can unwrap it before sending it to the seller. + // TODO: Probably safe to just use WETH.transferFrom for some + // small gas savings + _transferERC20TokensFrom( + WETH, + buyOrder.maker, + address(this), + erc20FillAmount + ); + // Unwrap WETH into ETH. + WETH.withdraw(erc20FillAmount); + // Send ETH to the seller. + _transferEth(payable(params.taker), erc20FillAmount); + } else { + // Transfer the ERC20 token from the buyer to the seller. + _transferERC20TokensFrom( + buyOrder.erc20Token, + buyOrder.maker, + params.taker, + erc20FillAmount + ); + } + + if (params.takerCallbackData.length > 0) { + require( + params.taker != address(this), + "NFTOrders::_sellNFT/CANNOT_CALLBACK_SELF" + ); + // Invoke the callback + bytes4 callbackResult = ITakerCallback(params.taker) + .zeroExTakerCallback(orderInfo.orderHash, params.takerCallbackData); + // Check for the magic success bytes + require( + callbackResult == TAKER_CALLBACK_MAGIC_BYTES, + "NFTOrders::_sellNFT/CALLBACK_FAILED" + ); + } + + // Transfer the NFT asset to the buyer. + // If this function is called from the + // `onNFTReceived` callback the Exchange Proxy + // holds the asset. Otherwise, transfer it from + // the seller. + _transferNFTAssetFrom( + buyOrder.nft, + params.currentNftOwner, + buyOrder.maker, + params.tokenId, + params.sellAmount + ); + + // The buyer pays the order fees. + _payFees( + buyOrder, + buyOrder.maker, + params.sellAmount, + orderInfo.orderAmount, + false + ); + } + + // Core settlement logic for buying an NFT asset. + function _buyNFT( + LibNFTOrder.NFTOrder memory sellOrder, + LibSignature.Signature memory signature, + BuyParams memory params + ) + internal + returns (uint256 erc20FillAmount) + { + LibNFTOrder.OrderInfo memory orderInfo = _getOrderInfo(sellOrder); + // Check that the order can be filled. + _validateSellOrder( + sellOrder, + signature, + orderInfo, + msg.sender + ); + + if (params.buyAmount > orderInfo.remainingAmount) { + LibNFTOrdersRichErrors.ExceedsRemainingOrderAmount( + orderInfo.remainingAmount, + params.buyAmount + ).rrevert(); + } + + _updateOrderState(sellOrder, orderInfo.orderHash, params.buyAmount); + + if (params.buyAmount == orderInfo.orderAmount) { + erc20FillAmount = sellOrder.erc20TokenAmount; + } else { + // Rounding favors the order maker. + erc20FillAmount = LibMathV06.getPartialAmountCeil( + params.buyAmount, + orderInfo.orderAmount, + sellOrder.erc20TokenAmount + ); + } + + // Transfer the NFT asset to the buyer (`msg.sender`). + _transferNFTAssetFrom( + sellOrder.nft, + sellOrder.maker, + msg.sender, + sellOrder.nftId, + params.buyAmount + ); + + uint256 ethAvailable = params.ethAvailable; + if (params.takerCallbackData.length > 0) { + require( + msg.sender != address(this), + "NFTOrders::_buyNFT/CANNOT_CALLBACK_SELF" + ); + uint256 ethBalanceBeforeCallback = address(this).balance; + // Invoke the callback + bytes4 callbackResult = ITakerCallback(msg.sender) + .zeroExTakerCallback(orderInfo.orderHash, params.takerCallbackData); + // Update `ethAvailable` with amount acquired during + // the callback + ethAvailable = ethAvailable.safeAdd( + address(this).balance.safeSub(ethBalanceBeforeCallback) + ); + // Check for the magic success bytes + require( + callbackResult == TAKER_CALLBACK_MAGIC_BYTES, + "NFTOrders::_buyNFT/CALLBACK_FAILED" + ); + } + + if (address(sellOrder.erc20Token) == NATIVE_TOKEN_ADDRESS) { + // Transfer ETH to the seller. + _transferEth(payable(sellOrder.maker), erc20FillAmount); + // Fees are paid from the EP's current balance of ETH. + _payEthFees( + sellOrder, + params.buyAmount, + orderInfo.orderAmount, + erc20FillAmount, + ethAvailable + ); + } else if (sellOrder.erc20Token == WETH) { + // If there is enough ETH available, fill the WETH order + // (including fees) using that ETH. + // Otherwise, transfer WETH from the taker. + if (ethAvailable >= erc20FillAmount) { + // Wrap ETH. + WETH.deposit{value: erc20FillAmount}(); + // TODO: Probably safe to just use WETH.transfer for some + // small gas savings + // Transfer WETH to the seller. + _transferERC20Tokens( + WETH, + sellOrder.maker, + erc20FillAmount + ); + // Fees are paid from the EP's current balance of ETH. + _payEthFees( + sellOrder, + params.buyAmount, + orderInfo.orderAmount, + erc20FillAmount, + ethAvailable + ); + } else { + // Transfer WETH from the buyer to the seller. + _transferERC20TokensFrom( + sellOrder.erc20Token, + msg.sender, + sellOrder.maker, + erc20FillAmount + ); + // The buyer pays fees using WETH. + _payFees( + sellOrder, + msg.sender, + params.buyAmount, + orderInfo.orderAmount, + false + ); + } + } else { + // Transfer ERC20 token from the buyer to the seller. + _transferERC20TokensFrom( + sellOrder.erc20Token, + msg.sender, + sellOrder.maker, + erc20FillAmount + ); + // The buyer pays fees. + _payFees( + sellOrder, + msg.sender, + params.buyAmount, + orderInfo.orderAmount, + false + ); + } + } + + function _validateSellOrder( + LibNFTOrder.NFTOrder memory sellOrder, + LibSignature.Signature memory signature, + LibNFTOrder.OrderInfo memory orderInfo, + address taker + ) + internal + view + { + // Order must be selling the NFT asset. + require( + sellOrder.direction == LibNFTOrder.TradeDirection.SELL_NFT, + "NFTOrders::_validateSellOrder/WRONG_TRADE_DIRECTION" + ); + // Taker must match the order taker, if one is specified. + if (sellOrder.taker != address(0) && sellOrder.taker != taker) { + LibNFTOrdersRichErrors.OnlyTakerError(taker, sellOrder.taker).rrevert(); + } + // Check that the order is valid and has not expired, been cancelled, + // or been filled. + if (orderInfo.status != LibNFTOrder.OrderStatus.FILLABLE) { + LibNFTOrdersRichErrors.OrderNotFillableError( + sellOrder.maker, + sellOrder.nonce, + uint8(orderInfo.status) + ).rrevert(); + } + + // Check the signature. + _validateOrderSignature(orderInfo.orderHash, signature, sellOrder.maker); + } + + function _validateBuyOrder( + LibNFTOrder.NFTOrder memory buyOrder, + LibSignature.Signature memory signature, + LibNFTOrder.OrderInfo memory orderInfo, + address taker, + uint256 tokenId + ) + internal + view + { + // Order must be buying the NFT asset. + require( + buyOrder.direction == LibNFTOrder.TradeDirection.BUY_NFT, + "NFTOrders::_validateBuyOrder/WRONG_TRADE_DIRECTION" + ); + // The ERC20 token cannot be ETH. + require( + address(buyOrder.erc20Token) != NATIVE_TOKEN_ADDRESS, + "NFTOrders::_validateBuyOrder/NATIVE_TOKEN_NOT_ALLOWED" + ); + // Taker must match the order taker, if one is specified. + if (buyOrder.taker != address(0) && buyOrder.taker != taker) { + LibNFTOrdersRichErrors.OnlyTakerError(taker, buyOrder.taker).rrevert(); + } + // Check that the order is valid and has not expired, been cancelled, + // or been filled. + if (orderInfo.status != LibNFTOrder.OrderStatus.FILLABLE) { + LibNFTOrdersRichErrors.OrderNotFillableError( + buyOrder.maker, + buyOrder.nonce, + uint8(orderInfo.status) + ).rrevert(); + } + // Check that the asset with the given token ID satisfies the properties + // specified by the order. + _validateOrderProperties(buyOrder, tokenId); + // Check the signature. + _validateOrderSignature(orderInfo.orderHash, signature, buyOrder.maker); + } + + function _payEthFees( + LibNFTOrder.NFTOrder memory order, + uint128 fillAmount, + uint128 orderAmount, + uint256 ethSpent, + uint256 ethAvailable + ) + private + { + // Pay fees using ETH. + uint256 ethFees = _payFees( + order, + address(this), + fillAmount, + orderAmount, + true + ); + // Update amount of ETH spent. + ethSpent = ethSpent.safeAdd(ethFees); + if (ethSpent > ethAvailable) { + LibNFTOrdersRichErrors.OverspentEthError( + ethSpent, + ethAvailable + ).rrevert(); + } + } + + function _payFees( + LibNFTOrder.NFTOrder memory order, + address payer, + uint128 fillAmount, + uint128 orderAmount, + bool useNativeToken + ) + internal + returns (uint256 totalFeesPaid) + { + // Make assertions about ETH case + if (useNativeToken) { + assert(payer == address(this)); + assert( + order.erc20Token == WETH || + address(order.erc20Token) == NATIVE_TOKEN_ADDRESS + ); + } + + for (uint256 i = 0; i < order.fees.length; i++) { + LibNFTOrder.Fee memory fee = order.fees[i]; + + require( + fee.recipient != address(this), + "NFTOrders::_payFees/RECIPIENT_CANNOT_BE_EXCHANGE_PROXY" + ); + + uint256 feeFillAmount; + if (fillAmount == orderAmount) { + feeFillAmount = fee.amount; + } else { + // Round against the fee recipient + feeFillAmount = LibMathV06.getPartialAmountFloor( + fillAmount, + orderAmount, + fee.amount + ); + } + if (feeFillAmount == 0) { + continue; + } + + if (useNativeToken) { + // Transfer ETH to the fee recipient. + _transferEth(payable(fee.recipient), feeFillAmount); + } else { + // Transfer ERC20 token from payer to recipient. + _transferERC20TokensFrom( + order.erc20Token, + payer, + fee.recipient, + feeFillAmount + ); + } + // Note that the fee callback is _not_ called if zero + // `feeData` is provided. If `feeData` is provided, we assume + // the fee recipient is a contract that implements the + // `IFeeRecipient` interface. + if (fee.feeData.length > 0) { + // Invoke the callback + bytes4 callbackResult = IFeeRecipient(fee.recipient).receiveZeroExFeeCallback( + useNativeToken ? NATIVE_TOKEN_ADDRESS : address(order.erc20Token), + feeFillAmount, + fee.feeData + ); + // Check for the magic success bytes + require( + callbackResult == FEE_CALLBACK_MAGIC_BYTES, + "NFTOrders::_payFees/CALLBACK_FAILED" + ); + } + // Sum the fees paid + totalFeesPaid = totalFeesPaid.safeAdd(feeFillAmount); + } + } + + /// @dev If the given order is buying an NFT asset, checks + /// whether or not the given token ID satisfies the required + /// properties specified in the order. If the order does not + /// specify any properties, this function instead checks + /// whether the given token ID matches the ID in the order. + /// Reverts if any checks fail, or if the order is selling + /// an NFT asset. + /// @param order The NFT order. + /// @param tokenId The ID of the NFT asset. + function _validateOrderProperties( + LibNFTOrder.NFTOrder memory order, + uint256 tokenId + ) + internal + view + { + // Order must be buying an NFT asset to have properties. + require( + order.direction == LibNFTOrder.TradeDirection.BUY_NFT, + "NFTOrders::_validateOrderProperties/WRONG_TRADE_DIRECTION" + ); + + // If no properties are specified, check that the given + // `tokenId` matches the one specified in the order. + if (order.nftProperties.length == 0) { + if (tokenId != order.nftId) { + LibNFTOrdersRichErrors.TokenIdMismatchError( + tokenId, + order.nftId + ).rrevert(); + } + } else { + // Validate each property + for (uint256 i = 0; i < order.nftProperties.length; i++) { + LibNFTOrder.Property memory property = order.nftProperties[i]; + // `address(0)` is interpreted as a no-op. Any token ID + // will satisfy a property with `propertyValidator == address(0)`. + if (address(property.propertyValidator) == address(0)) { + continue; + } + + // Call the property validator and throw a descriptive error + // if the call reverts. + try property.propertyValidator.validateProperty( + order.nft, + tokenId, + property.propertyData + ) {} catch (bytes memory errorData) { + LibNFTOrdersRichErrors.PropertyValidationFailedError( + address(property.propertyValidator), + order.nft, + tokenId, + property.propertyData, + errorData + ).rrevert(); + } + } + } + } + + /// @dev Validates that the given signature is valid for the + /// given maker and order hash. Reverts if the signature + /// is not valid. + /// @param orderHash The hash of the order that was signed. + /// @param signature The signature to check. + /// @param maker The maker of the order. + function _validateOrderSignature( + bytes32 orderHash, + LibSignature.Signature memory signature, + address maker + ) + internal + virtual + view; + + /// @dev Transfers an NFT asset. + /// @param token The address of the NFT contract. + /// @param from The address currently holding the asset. + /// @param to The address to transfer the asset to. + /// @param tokenId The ID of the asset to transfer. + /// @param amount The amount of the asset to transfer. Always + /// 1 for ERC721 assets. + function _transferNFTAssetFrom( + address token, + address from, + address to, + uint256 tokenId, + uint256 amount + ) + internal + virtual; + + /// @dev Updates storage to indicate that the given order + /// has been filled by the given amount. + /// @param order The order that has been filled. + /// @param orderHash The hash of `order`. + /// @param fillAmount The amount (denominated in the NFT asset) + /// that the order has been filled by. + function _updateOrderState( + LibNFTOrder.NFTOrder memory order, + bytes32 orderHash, + uint128 fillAmount + ) + internal + virtual; + + /// @dev Get the order info for an NFT order. + /// @param order The NFT order. + /// @return orderInfo Info about the order. + function _getOrderInfo(LibNFTOrder.NFTOrder memory order) + internal + virtual + view + returns (LibNFTOrder.OrderInfo memory orderInfo); +} diff --git a/contracts/zero-ex/contracts/src/fixins/FixinERC1155Spender.sol b/contracts/zero-ex/contracts/src/fixins/FixinERC1155Spender.sol new file mode 100644 index 0000000000..06d31aa34c --- /dev/null +++ b/contracts/zero-ex/contracts/src/fixins/FixinERC1155Spender.sol @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2020 ZeroEx 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; +pragma experimental ABIEncoderV2; + +import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol"; +import "../vendor/IERC1155Token.sol"; + + +/// @dev Helpers for moving ERC1155 assets around. +abstract contract FixinERC1155Spender { + + // Mask of the lower 20 bytes of a bytes32. + uint256 constant private ADDRESS_MASK = 0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff; + + /// @dev Transfers an ERC1155 asset from `owner` to `to`. + /// @param token The address of the ERC1155 token contract. + /// @param owner The owner of the asset. + /// @param to The recipient of the asset. + /// @param tokenId The token ID of the asset to transfer. + /// @param amount The amount of the asset to transfer. + function _transferERC1155AssetFrom( + IERC1155Token token, + address owner, + address to, + uint256 tokenId, + uint256 amount + ) + internal + { + require(address(token) != address(this), "FixinERC1155Spender/CANNOT_INVOKE_SELF"); + + assembly { + let ptr := mload(0x40) // free memory pointer + + // selector for safeTransferFrom(address,address,uint256,uint256,bytes) + mstore(ptr, 0xf242432a00000000000000000000000000000000000000000000000000000000) + mstore(add(ptr, 0x04), and(owner, ADDRESS_MASK)) + mstore(add(ptr, 0x24), and(to, ADDRESS_MASK)) + mstore(add(ptr, 0x44), tokenId) + mstore(add(ptr, 0x64), amount) + mstore(add(ptr, 0x84), 0xa0) + mstore(add(ptr, 0xa4), 0) + + let success := call( + gas(), + and(token, ADDRESS_MASK), + 0, + ptr, + 0xc4, + 0, + 0 + ) + + if iszero(success) { + let rdsize := returndatasize() + returndatacopy(ptr, 0, rdsize) + revert(ptr, rdsize) + } + } + } +} diff --git a/contracts/zero-ex/contracts/src/fixins/FixinERC721Spender.sol b/contracts/zero-ex/contracts/src/fixins/FixinERC721Spender.sol new file mode 100644 index 0000000000..912bce61ad --- /dev/null +++ b/contracts/zero-ex/contracts/src/fixins/FixinERC721Spender.sol @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2020 ZeroEx 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; +pragma experimental ABIEncoderV2; + +import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol"; +import "../vendor/IERC721Token.sol"; + + +/// @dev Helpers for moving ERC721 assets around. +abstract contract FixinERC721Spender { + + // Mask of the lower 20 bytes of a bytes32. + uint256 constant private ADDRESS_MASK = 0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff; + + /// @dev Transfers an ERC721 asset from `owner` to `to`. + /// @param token The address of the ERC721 token contract. + /// @param owner The owner of the asset. + /// @param to The recipient of the asset. + /// @param tokenId The token ID of the asset to transfer. + function _transferERC721AssetFrom( + IERC721Token token, + address owner, + address to, + uint256 tokenId + ) + internal + { + require(address(token) != address(this), "FixinERC721Spender/CANNOT_INVOKE_SELF"); + + assembly { + let ptr := mload(0x40) // free memory pointer + + // selector for transferFrom(address,address,uint256) + mstore(ptr, 0x23b872dd00000000000000000000000000000000000000000000000000000000) + mstore(add(ptr, 0x04), and(owner, ADDRESS_MASK)) + mstore(add(ptr, 0x24), and(to, ADDRESS_MASK)) + mstore(add(ptr, 0x44), tokenId) + + let success := call( + gas(), + and(token, ADDRESS_MASK), + 0, + ptr, + 0x64, + 0, + 0 + ) + + if iszero(success) { + let rdsize := returndatasize() + returndatacopy(ptr, 0, rdsize) + revert(ptr, rdsize) + } + } + } +} diff --git a/contracts/zero-ex/contracts/src/fixins/FixinTokenSpender.sol b/contracts/zero-ex/contracts/src/fixins/FixinTokenSpender.sol index fb06a03c61..5f87ec5cf2 100644 --- a/contracts/zero-ex/contracts/src/fixins/FixinTokenSpender.sol +++ b/contracts/zero-ex/contracts/src/fixins/FixinTokenSpender.sol @@ -20,7 +20,7 @@ pragma solidity ^0.6.5; pragma experimental ABIEncoderV2; -import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol"; +import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol"; @@ -141,6 +141,20 @@ abstract contract FixinTokenSpender { } } + + /// @dev Transfers some amount of ETH to the given recipient and + /// reverts if the transfer fails. + /// @param recipient The recipient of the ETH. + /// @param amount The amount of ETH to transfer. + function _transferEth(address payable recipient, uint256 amount) + internal + { + if (amount > 0) { + (bool success,) = recipient.call{value: amount}(""); + require(success, "FixinTokenSpender::_transferEth/TRANSFER_FAILED"); + } + } + /// @dev Gets the maximum amount of an ERC20 token `token` that can be /// pulled from `owner` by this address. /// @param token The token to spend. diff --git a/contracts/zero-ex/contracts/src/storage/LibERC1155OrdersStorage.sol b/contracts/zero-ex/contracts/src/storage/LibERC1155OrdersStorage.sol new file mode 100644 index 0000000000..ab523d9c2c --- /dev/null +++ b/contracts/zero-ex/contracts/src/storage/LibERC1155OrdersStorage.sol @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2020 ZeroEx 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; +pragma experimental ABIEncoderV2; + +import "./LibStorage.sol"; + + +/// @dev Storage helpers for `ERC1155OrdersFeature`. +library LibERC1155OrdersStorage { + + struct OrderState { + // The amount (denominated in the ERC1155 asset) + // that the order has been filled by. + uint128 filledAmount; + // Whether the order has been pre-signed. + bool preSigned; + } + + /// @dev Storage bucket for this feature. + struct Storage { + // Mapping from order hash to order state: + mapping(bytes32 => OrderState) orderState; + // maker => nonce range => order cancellation bit vector + mapping(address => mapping(uint248 => uint256)) orderCancellationByMaker; + } + + /// @dev Get the storage bucket for this contract. + function getStorage() internal pure returns (Storage storage stor) { + uint256 storageSlot = LibStorage.getStorageSlot( + LibStorage.StorageId.ERC1155Orders + ); + // Dip into assembly to change the slot pointed to by the local + // variable `stor`. + // See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries + assembly { stor_slot := storageSlot } + } +} diff --git a/contracts/zero-ex/contracts/src/storage/LibERC721OrdersStorage.sol b/contracts/zero-ex/contracts/src/storage/LibERC721OrdersStorage.sol new file mode 100644 index 0000000000..a4b5fe5e19 --- /dev/null +++ b/contracts/zero-ex/contracts/src/storage/LibERC721OrdersStorage.sol @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2020 ZeroEx 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; +pragma experimental ABIEncoderV2; + +import "./LibStorage.sol"; + + +/// @dev Storage helpers for `ERC721OrdersFeature`. +library LibERC721OrdersStorage { + + /// @dev Storage bucket for this feature. + struct Storage { + // maker => nonce range => order status bit vector + mapping(address => mapping(uint248 => uint256)) orderStatusByMaker; + // order hash => isSigned + mapping(bytes32 => bool) preSigned; + } + + /// @dev Get the storage bucket for this contract. + function getStorage() internal pure returns (Storage storage stor) { + uint256 storageSlot = LibStorage.getStorageSlot( + LibStorage.StorageId.ERC721Orders + ); + // Dip into assembly to change the slot pointed to by the local + // variable `stor`. + // See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries + assembly { stor_slot := storageSlot } + } +} diff --git a/contracts/zero-ex/contracts/src/storage/LibStorage.sol b/contracts/zero-ex/contracts/src/storage/LibStorage.sol index efeee43f00..0185680eb3 100644 --- a/contracts/zero-ex/contracts/src/storage/LibStorage.sol +++ b/contracts/zero-ex/contracts/src/storage/LibStorage.sol @@ -17,7 +17,7 @@ */ -pragma solidity ^0.6.5; +pragma solidity ^0.6; pragma experimental ABIEncoderV2; @@ -39,7 +39,9 @@ library LibStorage { MetaTransactions, ReentrancyGuard, NativeOrders, - OtcOrders + OtcOrders, + ERC721Orders, + ERC1155Orders } /// @dev Get the storage slot given a storage ID. We assign unique, well-spaced diff --git a/contracts/zero-ex/contracts/src/vendor/IERC1155Token.sol b/contracts/zero-ex/contracts/src/vendor/IERC1155Token.sol new file mode 100644 index 0000000000..48cdccde4d --- /dev/null +++ b/contracts/zero-ex/contracts/src/vendor/IERC1155Token.sol @@ -0,0 +1,151 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2022 ZeroEx 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; +pragma experimental ABIEncoderV2; + + +interface IERC1155Token { + + /// @dev Either TransferSingle or TransferBatch MUST emit when tokens are transferred, + /// including zero value transfers as well as minting or burning. + /// Operator will always be msg.sender. + /// Either event from address `0x0` signifies a minting operation. + /// An event to address `0x0` signifies a burning or melting operation. + /// The total value transferred from address 0x0 minus the total value transferred to 0x0 may + /// be used by clients and exchanges to be added to the "circulating supply" for a given token ID. + /// To define a token ID with no initial balance, the contract SHOULD emit the TransferSingle event + /// from `0x0` to `0x0`, with the token creator as `_operator`. + event TransferSingle( + address indexed operator, + address indexed from, + address indexed to, + uint256 id, + uint256 value + ); + + /// @dev Either TransferSingle or TransferBatch MUST emit when tokens are transferred, + /// including zero value transfers as well as minting or burning. + ///Operator will always be msg.sender. + /// Either event from address `0x0` signifies a minting operation. + /// An event to address `0x0` signifies a burning or melting operation. + /// The total value transferred from address 0x0 minus the total value transferred to 0x0 may + /// be used by clients and exchanges to be added to the "circulating supply" for a given token ID. + /// To define multiple token IDs with no initial balance, this SHOULD emit the TransferBatch event + /// from `0x0` to `0x0`, with the token creator as `_operator`. + event TransferBatch( + address indexed operator, + address indexed from, + address indexed to, + uint256[] ids, + uint256[] values + ); + + /// @dev MUST emit when an approval is updated. + event ApprovalForAll( + address indexed owner, + address indexed operator, + bool approved + ); + + /// @dev MUST emit when the URI is updated for a token ID. + /// URIs are defined in RFC 3986. + /// The URI MUST point a JSON file that conforms to the "ERC-1155 Metadata JSON Schema". + event URI( + string value, + uint256 indexed id + ); + + /// @notice Transfers value amount of an _id from the _from address to the _to address specified. + /// @dev MUST emit TransferSingle event on success. + /// Caller must be approved to manage the _from account's tokens (see isApprovedForAll). + /// MUST throw if `_to` is the zero address. + /// MUST throw if balance of sender for token `_id` is lower than the `_value` sent. + /// MUST throw on any other error. + /// When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). + /// If so, it MUST call `onERC1155Received` on `_to` and revert if the return value + /// is not `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`. + /// @param from Source address + /// @param to Target address + /// @param id ID of the token type + /// @param value Transfer amount + /// @param data Additional data with no specified format, sent in call to `_to` + function safeTransferFrom( + address from, + address to, + uint256 id, + uint256 value, + bytes calldata data + ) + external; + + /// @notice Send multiple types of Tokens from a 3rd party in one transfer (with safety call). + /// @dev MUST emit TransferBatch event on success. + /// Caller must be approved to manage the _from account's tokens (see isApprovedForAll). + /// MUST throw if `_to` is the zero address. + /// MUST throw if length of `_ids` is not the same as length of `_values`. + /// MUST throw if any of the balance of sender for token `_ids` is lower than the respective `_values` sent. + /// MUST throw on any other error. + /// When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). + /// If so, it MUST call `onERC1155BatchReceived` on `_to` and revert if the return value + /// is not `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`. + /// @param from Source addresses + /// @param to Target addresses + /// @param ids IDs of each token type + /// @param values Transfer amounts per token type + /// @param data Additional data with no specified format, sent in call to `_to` + function safeBatchTransferFrom( + address from, + address to, + uint256[] calldata ids, + uint256[] calldata values, + bytes calldata data + ) + external; + + /// @notice Enable or disable approval for a third party ("operator") to manage all of the caller's tokens. + /// @dev MUST emit the ApprovalForAll event on success. + /// @param operator Address to add to the set of authorized operators + /// @param approved True if the operator is approved, false to revoke approval + function setApprovalForAll(address operator, bool approved) external; + + /// @notice Queries the approval status of an operator for a given owner. + /// @param owner The owner of the Tokens + /// @param operator Address of authorized operator + /// @return isApproved True if the operator is approved, false if not + function isApprovedForAll(address owner, address operator) external view returns (bool isApproved); + + /// @notice Get the balance of an account's Tokens. + /// @param owner The address of the token holder + /// @param id ID of the Token + /// @return balance The _owner's balance of the Token type requested + function balanceOf(address owner, uint256 id) external view returns (uint256 balance); + + /// @notice Get the balance of multiple account/token pairs + /// @param owners The addresses of the token holders + /// @param ids ID of the Tokens + /// @return balances_ The _owner's balance of the Token types requested + function balanceOfBatch( + address[] calldata owners, + uint256[] calldata ids + ) + external + view + returns (uint256[] memory balances_); +} diff --git a/contracts/zero-ex/contracts/src/vendor/IERC721Token.sol b/contracts/zero-ex/contracts/src/vendor/IERC721Token.sol new file mode 100644 index 0000000000..acaefc7119 --- /dev/null +++ b/contracts/zero-ex/contracts/src/vendor/IERC721Token.sol @@ -0,0 +1,159 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2021 ZeroEx 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; + + +interface IERC721Token { + + /// @dev This emits when ownership of any NFT changes by any mechanism. + /// This event emits when NFTs are created (`from` == 0) and destroyed + /// (`to` == 0). Exception: during contract creation, any number of NFTs + /// may be created and assigned without emitting Transfer. At the time of + /// any transfer, the approved address for that NFT (if any) is reset to none. + event Transfer( + address indexed _from, + address indexed _to, + uint256 indexed _tokenId + ); + + /// @dev This emits when the approved address for an NFT is changed or + /// reaffirmed. The zero address indicates there is no approved address. + /// When a Transfer event emits, this also indicates that the approved + /// address for that NFT (if any) is reset to none. + event Approval( + address indexed _owner, + address indexed _approved, + uint256 indexed _tokenId + ); + + /// @dev This emits when an operator is enabled or disabled for an owner. + /// The operator can manage all NFTs of the owner. + event ApprovalForAll( + address indexed _owner, + address indexed _operator, + bool _approved + ); + + /// @notice Transfers the ownership of an NFT from one address to another address + /// @dev Throws unless `msg.sender` is the current owner, an authorized + /// perator, or the approved address for this NFT. Throws if `_from` is + /// not the current owner. Throws if `_to` is the zero address. Throws if + /// `_tokenId` is not a valid NFT. When transfer is complete, this function + /// checks if `_to` is a smart contract (code size > 0). If so, it calls + /// `onERC721Received` on `_to` and throws if the return value is not + /// `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`. + /// @param _from The current owner of the NFT + /// @param _to The new owner + /// @param _tokenId The NFT to transfer + /// @param _data Additional data with no specified format, sent in call to `_to` + function safeTransferFrom( + address _from, + address _to, + uint256 _tokenId, + bytes calldata _data + ) + external; + + /// @notice Transfers the ownership of an NFT from one address to another address + /// @dev This works identically to the other function with an extra data parameter, + /// except this function just sets data to "". + /// @param _from The current owner of the NFT + /// @param _to The new owner + /// @param _tokenId The NFT to transfer + function safeTransferFrom( + address _from, + address _to, + uint256 _tokenId + ) + external; + + /// @notice Change or reaffirm the approved address for an NFT + /// @dev The zero address indicates there is no approved address. + /// Throws unless `msg.sender` is the current NFT owner, or an authorized + /// operator of the current owner. + /// @param _approved The new approved NFT controller + /// @param _tokenId The NFT to approve + function approve(address _approved, uint256 _tokenId) + external; + + /// @notice Enable or disable approval for a third party ("operator") to manage + /// all of `msg.sender`'s assets + /// @dev Emits the ApprovalForAll event. The contract MUST allow + /// multiple operators per owner. + /// @param _operator Address to add to the set of authorized operators + /// @param _approved True if the operator is approved, false to revoke approval + function setApprovalForAll(address _operator, bool _approved) + external; + + /// @notice Count all NFTs assigned to an owner + /// @dev NFTs assigned to the zero address are considered invalid, and this + /// function throws for queries about the zero address. + /// @param _owner An address for whom to query the balance + /// @return The number of NFTs owned by `_owner`, possibly zero + function balanceOf(address _owner) + external + view + returns (uint256); + + /// @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE + /// TO CONFIRM THAT `_to` IS CAPABLE OF RECEIVING NFTS OR ELSE + /// THEY MAY BE PERMANENTLY LOST + /// @dev Throws unless `msg.sender` is the current owner, an authorized + /// operator, or the approved address for this NFT. Throws if `_from` is + /// not the current owner. Throws if `_to` is the zero address. Throws if + /// `_tokenId` is not a valid NFT. + /// @param _from The current owner of the NFT + /// @param _to The new owner + /// @param _tokenId The NFT to transfer + function transferFrom( + address _from, + address _to, + uint256 _tokenId + ) + external; + + /// @notice Find the owner of an NFT + /// @dev NFTs assigned to zero address are considered invalid, and queries + /// about them do throw. + /// @param _tokenId The identifier for an NFT + /// @return The address of the owner of the NFT + function ownerOf(uint256 _tokenId) + external + view + returns (address); + + /// @notice Get the approved address for a single NFT + /// @dev Throws if `_tokenId` is not a valid NFT. + /// @param _tokenId The NFT to find the approved address for + /// @return The approved address for this NFT, or the zero address if there is none + function getApproved(uint256 _tokenId) + external + view + returns (address); + + /// @notice Query if an address is an authorized operator for another address + /// @param _owner The address that owns the NFTs + /// @param _operator The address that acts on behalf of the owner + /// @return True if `_operator` is an approved operator for `_owner`, false otherwise + function isApprovedForAll(address _owner, address _operator) + external + view + returns (bool); +} diff --git a/contracts/zero-ex/contracts/src/vendor/IFeeRecipient.sol b/contracts/zero-ex/contracts/src/vendor/IFeeRecipient.sol new file mode 100644 index 0000000000..38c88ebd1e --- /dev/null +++ b/contracts/zero-ex/contracts/src/vendor/IFeeRecipient.sol @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2021 ZeroEx 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; +pragma experimental ABIEncoderV2; + + +interface IFeeRecipient { + + /// @dev A callback function invoked in the ERC721Feature for each ERC721 + /// order fee that get paid. Integrators can make use of this callback + /// to implement arbitrary fee-handling logic, e.g. splitting the fee + /// between multiple parties. + /// @param tokenAddress The address of the token in which the received fee is + /// denominated. `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE` indicates + /// that the fee was paid in the native token (e.g. ETH). + /// @param amount The amount of the given token received. + /// @param feeData Arbitrary data encoded in the `Fee` used by this callback. + /// @return success The selector of this function (0x0190805e), + /// indicating that the callback succeeded. + function receiveZeroExFeeCallback( + address tokenAddress, + uint256 amount, + bytes calldata feeData + ) + external + returns (bytes4 success); +} diff --git a/contracts/zero-ex/contracts/src/vendor/IPropertyValidator.sol b/contracts/zero-ex/contracts/src/vendor/IPropertyValidator.sol new file mode 100644 index 0000000000..9c4c54c2d4 --- /dev/null +++ b/contracts/zero-ex/contracts/src/vendor/IPropertyValidator.sol @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2021 ZeroEx 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; +pragma experimental ABIEncoderV2; + + +interface IPropertyValidator { + + /// @dev Checks that the given ERC721/ERC1155 asset satisfies the properties encoded in `propertyData`. + /// Should revert if the asset does not satisfy the specified properties. + /// @param tokenAddress The ERC721/ERC1155 token contract address. + /// @param tokenId The ERC721/ERC1155 tokenId of the asset to check. + /// @param propertyData Encoded properties or auxiliary data needed to perform the check. + function validateProperty( + address tokenAddress, + uint256 tokenId, + bytes calldata propertyData + ) + external + view; +} diff --git a/contracts/zero-ex/contracts/src/vendor/ITakerCallback.sol b/contracts/zero-ex/contracts/src/vendor/ITakerCallback.sol new file mode 100644 index 0000000000..a84108a68d --- /dev/null +++ b/contracts/zero-ex/contracts/src/vendor/ITakerCallback.sol @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2021 ZeroEx 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; +pragma experimental ABIEncoderV2; + + +interface ITakerCallback { + + /// @dev A taker callback function invoked in ERC721OrdersFeature and + /// ERC1155OrdersFeature between the maker -> taker transfer and + /// the taker -> maker transfer. + /// @param orderHash The hash of the order being filled when this + /// callback is invoked. + /// @param callbackData Arbitrary data used by this callback. + /// @return success The selector of this function, + /// indicating that the callback succeeded. + function zeroExTakerCallback( + bytes32 orderHash, + bytes calldata callbackData + ) + external + returns (bytes4 success); +} diff --git a/contracts/zero-ex/contracts/test/TestFeeRecipient.sol b/contracts/zero-ex/contracts/test/TestFeeRecipient.sol new file mode 100644 index 0000000000..359e57aaa6 --- /dev/null +++ b/contracts/zero-ex/contracts/test/TestFeeRecipient.sol @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2021 ZeroEx 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; + + +contract TestFeeRecipient { + bytes4 constant private SUCCESS = this.receiveZeroExFeeCallback.selector; + bytes4 constant private FAILURE = 0xdeadbeef; + + uint256 constant private TRIGGER_REVERT = 333; + uint256 constant private TRIGGER_FAILURE = 666; + + event FeeReceived( + address tokenAddress, + uint256 amount + ); + + receive() external payable {} + + function receiveZeroExFeeCallback( + address tokenAddress, + uint256 amount, + bytes calldata /* feeData */ + ) + external + returns (bytes4 success) + { + emit FeeReceived(tokenAddress, amount); + if (amount == TRIGGER_REVERT) { + revert("TestFeeRecipient::receiveZeroExFeeCallback/REVERT"); + } else if (amount == TRIGGER_FAILURE) { + return FAILURE; + } else { + return SUCCESS; + } + } +} diff --git a/contracts/zero-ex/contracts/test/TestFillQuoteTransformerBridge.sol b/contracts/zero-ex/contracts/test/TestFillQuoteTransformerBridge.sol index ab78481ee0..cb9d9a59a8 100644 --- a/contracts/zero-ex/contracts/test/TestFillQuoteTransformerBridge.sol +++ b/contracts/zero-ex/contracts/test/TestFillQuoteTransformerBridge.sol @@ -22,7 +22,7 @@ pragma experimental ABIEncoderV2; import "@0x/contracts-utils/contracts/src/v06/LibMathV06.sol"; import "../src/vendor/v3/IERC20Bridge.sol"; -import "./TestMintableERC20Token.sol"; +import "./tokens/TestMintableERC20Token.sol"; contract TestFillQuoteTransformerBridge { diff --git a/contracts/zero-ex/contracts/test/TestFillQuoteTransformerExchange.sol b/contracts/zero-ex/contracts/test/TestFillQuoteTransformerExchange.sol index 9d13e0dca6..26294cc990 100644 --- a/contracts/zero-ex/contracts/test/TestFillQuoteTransformerExchange.sol +++ b/contracts/zero-ex/contracts/test/TestFillQuoteTransformerExchange.sol @@ -23,7 +23,7 @@ pragma experimental ABIEncoderV2; import "@0x/contracts-utils/contracts/src/v06/LibBytesV06.sol"; import "@0x/contracts-utils/contracts/src/v06/LibMathV06.sol"; import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol"; -import "./TestMintableERC20Token.sol"; +import "./tokens/TestMintableERC20Token.sol"; import "../src/features/libs/LibNativeOrder.sol"; import "../src/features/libs/LibSignature.sol"; diff --git a/contracts/zero-ex/contracts/test/TestFillQuoteTransformerHost.sol b/contracts/zero-ex/contracts/test/TestFillQuoteTransformerHost.sol index 8aebfda530..dacde4f22b 100644 --- a/contracts/zero-ex/contracts/test/TestFillQuoteTransformerHost.sol +++ b/contracts/zero-ex/contracts/test/TestFillQuoteTransformerHost.sol @@ -21,7 +21,7 @@ pragma solidity ^0.6.5; pragma experimental ABIEncoderV2; import "../src/transformers/IERC20Transformer.sol"; -import "./TestMintableERC20Token.sol"; +import "./tokens/TestMintableERC20Token.sol"; import "./TestTransformerHost.sol"; diff --git a/contracts/zero-ex/contracts/test/TestMintTokenERC20Transformer.sol b/contracts/zero-ex/contracts/test/TestMintTokenERC20Transformer.sol index 7ec9950bf9..4d56580cc7 100644 --- a/contracts/zero-ex/contracts/test/TestMintTokenERC20Transformer.sol +++ b/contracts/zero-ex/contracts/test/TestMintTokenERC20Transformer.sol @@ -23,7 +23,7 @@ pragma experimental ABIEncoderV2; import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; import "../src/transformers/IERC20Transformer.sol"; import "../src/transformers/LibERC20Transformer.sol"; -import "./TestMintableERC20Token.sol"; +import "./tokens/TestMintableERC20Token.sol"; contract TestMintTokenERC20Transformer is diff --git a/contracts/zero-ex/contracts/test/TestNFTOrderPresigner.sol b/contracts/zero-ex/contracts/test/TestNFTOrderPresigner.sol new file mode 100644 index 0000000000..14799fc239 --- /dev/null +++ b/contracts/zero-ex/contracts/test/TestNFTOrderPresigner.sol @@ -0,0 +1,93 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2021 ZeroEx 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 "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; +import "../src/IZeroEx.sol"; +import "../src/vendor/IERC1155Token.sol"; +import "../src/vendor/IERC721Token.sol"; +import "../src/features/libs/LibNFTOrder.sol"; + + +contract TestNFTOrderPresigner { + IZeroEx private immutable zeroEx; + + constructor(IZeroEx _zeroEx) + public + { + zeroEx = _zeroEx; + } + + function onERC1155Received( + address operator, + address from, + uint256 id, + uint256 value, + bytes calldata data + ) + external + returns(bytes4 success) + { + return 0xf23a6e61; + } + + function approveERC721(IERC721Token token) + external + { + token.setApprovalForAll(address(zeroEx), true); + } + + function approveERC1155(IERC1155Token token) + external + { + token.setApprovalForAll(address(zeroEx), true); + } + + function approveERC20(IERC20TokenV06 token) + external + { + token.approve(address(zeroEx), uint256(-1)); + } + + function preSignERC721Order(LibNFTOrder.ERC721Order calldata order) + external + { + zeroEx.preSignERC721Order(order); + } + + function preSignERC1155Order(LibNFTOrder.ERC1155Order calldata order) + external + { + zeroEx.preSignERC1155Order(order); + } + + function cancelERC721Order(uint256 orderNonce) + external + { + zeroEx.cancelERC721Order(orderNonce); + } + + function cancelERC1155Order(uint256 orderNonce) + external + { + zeroEx.cancelERC1155Order(orderNonce); + } +} diff --git a/contracts/zero-ex/contracts/test/TestPropertyValidator.sol b/contracts/zero-ex/contracts/test/TestPropertyValidator.sol new file mode 100644 index 0000000000..d2e1ce1609 --- /dev/null +++ b/contracts/zero-ex/contracts/test/TestPropertyValidator.sol @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2021 ZeroEx 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; + + +contract TestPropertyValidator { + + function validateProperty( + address tokenAddress, + uint256 tokenId, + bytes calldata propertyData + ) + external + view + { + require( + propertyData.length > 0, + "TestPropertyValidator::validateProperty/REVERT" + ); + } +} diff --git a/contracts/zero-ex/contracts/test/TestWethTransformerHost.sol b/contracts/zero-ex/contracts/test/TestWethTransformerHost.sol index cae441fb27..b5c910c5af 100644 --- a/contracts/zero-ex/contracts/test/TestWethTransformerHost.sol +++ b/contracts/zero-ex/contracts/test/TestWethTransformerHost.sol @@ -21,9 +21,9 @@ pragma solidity ^0.6.5; pragma experimental ABIEncoderV2; import "../src/transformers/IERC20Transformer.sol"; -import "./TestMintableERC20Token.sol"; +import "./tokens/TestMintableERC20Token.sol"; import "./TestTransformerHost.sol"; -import "./TestWeth.sol"; +import "./tokens/TestWeth.sol"; contract TestWethTransformerHost is diff --git a/contracts/zero-ex/contracts/test/TestCurve.sol b/contracts/zero-ex/contracts/test/integration/TestCurve.sol similarity index 98% rename from contracts/zero-ex/contracts/test/TestCurve.sol rename to contracts/zero-ex/contracts/test/integration/TestCurve.sol index 875a79b59d..48110c625a 100644 --- a/contracts/zero-ex/contracts/test/TestCurve.sol +++ b/contracts/zero-ex/contracts/test/integration/TestCurve.sol @@ -21,7 +21,7 @@ pragma solidity ^0.6.5; pragma experimental ABIEncoderV2; import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; -import "./TestMintableERC20Token.sol"; +import "../tokens/TestMintableERC20Token.sol"; contract TestCurve { diff --git a/contracts/zero-ex/contracts/test/TestLiquidityProvider.sol b/contracts/zero-ex/contracts/test/integration/TestLiquidityProvider.sol similarity index 100% rename from contracts/zero-ex/contracts/test/TestLiquidityProvider.sol rename to contracts/zero-ex/contracts/test/integration/TestLiquidityProvider.sol diff --git a/contracts/zero-ex/contracts/test/TestMooniswap.sol b/contracts/zero-ex/contracts/test/integration/TestMooniswap.sol similarity index 97% rename from contracts/zero-ex/contracts/test/TestMooniswap.sol rename to contracts/zero-ex/contracts/test/integration/TestMooniswap.sol index 2f325d44b3..49ecfdb5b0 100644 --- a/contracts/zero-ex/contracts/test/TestMooniswap.sol +++ b/contracts/zero-ex/contracts/test/integration/TestMooniswap.sol @@ -21,7 +21,7 @@ pragma solidity ^0.6.5; pragma experimental ABIEncoderV2; import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; -import "./TestMintableERC20Token.sol"; +import "../tokens/TestMintableERC20Token.sol"; contract TestMooniswap { diff --git a/contracts/zero-ex/contracts/test/TestUniswapV2Factory.sol b/contracts/zero-ex/contracts/test/integration/TestUniswapV2Factory.sol similarity index 100% rename from contracts/zero-ex/contracts/test/TestUniswapV2Factory.sol rename to contracts/zero-ex/contracts/test/integration/TestUniswapV2Factory.sol diff --git a/contracts/zero-ex/contracts/test/TestUniswapV2Pool.sol b/contracts/zero-ex/contracts/test/integration/TestUniswapV2Pool.sol similarity index 97% rename from contracts/zero-ex/contracts/test/TestUniswapV2Pool.sol rename to contracts/zero-ex/contracts/test/integration/TestUniswapV2Pool.sol index 1451748155..3f08a0d538 100644 --- a/contracts/zero-ex/contracts/test/TestUniswapV2Pool.sol +++ b/contracts/zero-ex/contracts/test/integration/TestUniswapV2Pool.sol @@ -2,7 +2,7 @@ pragma solidity ^0.6; pragma experimental ABIEncoderV2; import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; -import "../src/vendor/IUniswapV2Pair.sol"; +import "../../src/vendor/IUniswapV2Pair.sol"; interface IUniswapV2PoolDeployer { struct CreationParameters { diff --git a/contracts/zero-ex/contracts/test/TestUniswapV3Factory.sol b/contracts/zero-ex/contracts/test/integration/TestUniswapV3Factory.sol similarity index 100% rename from contracts/zero-ex/contracts/test/TestUniswapV3Factory.sol rename to contracts/zero-ex/contracts/test/integration/TestUniswapV3Factory.sol diff --git a/contracts/zero-ex/contracts/test/TestUniswapV3Pool.sol b/contracts/zero-ex/contracts/test/integration/TestUniswapV3Pool.sol similarity index 98% rename from contracts/zero-ex/contracts/test/TestUniswapV3Pool.sol rename to contracts/zero-ex/contracts/test/integration/TestUniswapV3Pool.sol index da0d8290f4..d2bd190974 100644 --- a/contracts/zero-ex/contracts/test/TestUniswapV3Pool.sol +++ b/contracts/zero-ex/contracts/test/integration/TestUniswapV3Pool.sol @@ -2,7 +2,7 @@ pragma solidity ^0.6; pragma experimental ABIEncoderV2; import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; -import "../src/vendor/IUniswapV3Pool.sol"; +import "../../src/vendor/IUniswapV3Pool.sol"; interface IUniswapV3PoolDeployer { struct CreationParameters { diff --git a/contracts/zero-ex/contracts/test/tokens/TestMintableERC1155Token.sol b/contracts/zero-ex/contracts/test/tokens/TestMintableERC1155Token.sol new file mode 100644 index 0000000000..778ab870c6 --- /dev/null +++ b/contracts/zero-ex/contracts/test/tokens/TestMintableERC1155Token.sol @@ -0,0 +1,345 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2019 ZeroEx 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; +pragma experimental ABIEncoderV2; + +import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol"; + + +interface IERC1155Receiver { + + /// @notice Handle the receipt of a single ERC1155 token type + /// @dev The smart contract calls this function on the recipient + /// after a `safeTransferFrom`. This function MAY throw to revert and reject the + /// transfer. Return of other than the magic value MUST result in the + ///transaction being reverted + /// Note: the contract address is always the message sender + /// @param operator The address which called `safeTransferFrom` function + /// @param from The address which previously owned the token + /// @param id An array containing the ids of the token being transferred + /// @param value An array containing the amount of tokens being transferred + /// @param data Additional data with no specified format + /// @return success `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` + function onERC1155Received( + address operator, + address from, + uint256 id, + uint256 value, + bytes calldata data + ) + external + returns(bytes4 success); + + /// @notice Handle the receipt of multiple ERC1155 token types + /// @dev The smart contract calls this function on the recipient + /// after a `safeTransferFrom`. This function MAY throw to revert and reject the + /// transfer. Return of other than the magic value MUST result in the + /// transaction being reverted + /// Note: the contract address is always the message sender + /// @param operator The address which called `safeTransferFrom` function + /// @param from The address which previously owned the token + /// @param ids An array containing ids of each token being transferred + /// @param values An array containing amounts of each token being transferred + /// @param data Additional data with no specified format + /// @return success `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` + function onERC1155BatchReceived( + address operator, + address from, + uint256[] calldata ids, + uint256[] calldata values, + bytes calldata data + ) + external + returns(bytes4 success); +} + +contract TestMintableERC1155Token { + using LibSafeMathV06 for uint256; + + /// @dev Either TransferSingle or TransferBatch MUST emit when tokens are transferred, + /// including zero value transfers as well as minting or burning. + /// Operator will always be msg.sender. + /// Either event from address `0x0` signifies a minting operation. + /// An event to address `0x0` signifies a burning or melting operation. + /// The total value transferred from address 0x0 minus the total value transferred to 0x0 may + /// be used by clients and exchanges to be added to the "circulating supply" for a given token ID. + /// To define a token ID with no initial balance, the contract SHOULD emit the TransferSingle event + /// from `0x0` to `0x0`, with the token creator as `_operator`. + event TransferSingle( + address indexed operator, + address indexed from, + address indexed to, + uint256 id, + uint256 value + ); + + /// @dev Either TransferSingle or TransferBatch MUST emit when tokens are transferred, + /// including zero value transfers as well as minting or burning. + ///Operator will always be msg.sender. + /// Either event from address `0x0` signifies a minting operation. + /// An event to address `0x0` signifies a burning or melting operation. + /// The total value transferred from address 0x0 minus the total value transferred to 0x0 may + /// be used by clients and exchanges to be added to the "circulating supply" for a given token ID. + /// To define multiple token IDs with no initial balance, this SHOULD emit the TransferBatch event + /// from `0x0` to `0x0`, with the token creator as `_operator`. + event TransferBatch( + address indexed operator, + address indexed from, + address indexed to, + uint256[] ids, + uint256[] values + ); + + /// @dev MUST emit when an approval is updated. + event ApprovalForAll( + address indexed owner, + address indexed operator, + bool approved + ); + + // selectors for receiver callbacks + bytes4 constant public ERC1155_RECEIVED = 0xf23a6e61; + bytes4 constant public ERC1155_BATCH_RECEIVED = 0xbc197c81; + + // id => (owner => balance) + mapping (uint256 => mapping(address => uint256)) internal balances; + + // owner => (operator => approved) + mapping (address => mapping(address => bool)) internal operatorApproval; + + + function mint( + address to, + uint256 id, + uint256 quantity + ) + external + { + // Grant the items to the caller + balances[id][to] = quantity.safeAdd(balances[id][to]); + + // Emit the Transfer/Mint event. + // the 0x0 source address implies a mint + // It will also provide the circulating supply info. + emit TransferSingle( + msg.sender, + address(0x0), + to, + id, + quantity + ); + + // if `to` is a contract then trigger its callback + uint256 receiverCodeSize; + assembly { + receiverCodeSize := extcodesize(to) + } + if (receiverCodeSize > 0) { + bytes4 callbackReturnValue = IERC1155Receiver(to).onERC1155Received( + msg.sender, + msg.sender, + id, + quantity, + "" + ); + require( + callbackReturnValue == ERC1155_RECEIVED, + "BAD_RECEIVER_RETURN_VALUE" + ); + } + } + + /// @notice Transfers value amount of an _id from the _from address to the _to address specified. + /// @dev MUST emit TransferSingle event on success. + /// Caller must be approved to manage the _from account's tokens (see isApprovedForAll). + /// MUST throw if `_to` is the zero address. + /// MUST throw if balance of sender for token `_id` is lower than the `_value` sent. + /// MUST throw on any other error. + /// When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). + /// If so, it MUST call `onERC1155Received` on `_to` and revert if the return value + /// is not `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`. + /// @param from Source address + /// @param to Target address + /// @param id ID of the token type + /// @param value Transfer amount + /// @param data Additional data with no specified format, sent in call to `_to` + function safeTransferFrom( + address from, + address to, + uint256 id, + uint256 value, + bytes calldata data + ) + external + { + // sanity checks + require( + to != address(0x0), + "CANNOT_TRANSFER_TO_ADDRESS_ZERO" + ); + require( + from == msg.sender || operatorApproval[from][msg.sender] == true, + "INSUFFICIENT_ALLOWANCE" + ); + + // perform transfer + balances[id][from] = balances[id][from].safeSub(value); + balances[id][to] = balances[id][to].safeAdd(value); + + emit TransferSingle(msg.sender, from, to, id, value); + + // if `to` is a contract then trigger its callback + uint256 receiverCodeSize; + assembly { + receiverCodeSize := extcodesize(to) + } + if (receiverCodeSize > 0) { + bytes4 callbackReturnValue = IERC1155Receiver(to).onERC1155Received( + msg.sender, + from, + id, + value, + data + ); + require( + callbackReturnValue == ERC1155_RECEIVED, + "BAD_RECEIVER_RETURN_VALUE" + ); + } + } + + /// @notice Send multiple types of Tokens from a 3rd party in one transfer (with safety call). + /// @dev MUST emit TransferBatch event on success. + /// Caller must be approved to manage the _from account's tokens (see isApprovedForAll). + /// MUST throw if `_to` is the zero address. + /// MUST throw if length of `_ids` is not the same as length of `_values`. + /// MUST throw if any of the balance of sender for token `_ids` is lower than the respective `_values` sent. + /// MUST throw on any other error. + /// When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). + /// If so, it MUST call `onERC1155BatchReceived` on `_to` and revert if the return value + /// is not `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`. + /// @param from Source addresses + /// @param to Target addresses + /// @param ids IDs of each token type + /// @param values Transfer amounts per token type + /// @param data Additional data with no specified format, sent in call to `_to` + function safeBatchTransferFrom( + address from, + address to, + uint256[] calldata ids, + uint256[] calldata values, + bytes calldata data + ) + external + { + // sanity checks + require( + to != address(0x0), + "CANNOT_TRANSFER_TO_ADDRESS_ZERO" + ); + require( + ids.length == values.length, + "TOKEN_AND_VALUES_LENGTH_MISMATCH" + ); + + // Only supporting a global operator approval allows us to do + // only 1 check and not to touch storage to handle allowances. + require( + from == msg.sender || operatorApproval[from][msg.sender] == true, + "INSUFFICIENT_ALLOWANCE" + ); + + // perform transfers + for (uint256 i = 0; i < ids.length; ++i) { + // Cache value to local variable to reduce read costs. + uint256 id = ids[i]; + uint256 value = values[i]; + + balances[id][from] = balances[id][from].safeSub(value); + balances[id][to] = balances[id][to].safeAdd(value); + } + emit TransferBatch(msg.sender, from, to, ids, values); + + // if `to` is a contract then trigger its callback + uint256 receiverCodeSize; + assembly { + receiverCodeSize := extcodesize(to) + } + if (receiverCodeSize > 0) { + bytes4 callbackReturnValue = IERC1155Receiver(to).onERC1155BatchReceived( + msg.sender, + from, + ids, + values, + data + ); + require( + callbackReturnValue == ERC1155_BATCH_RECEIVED, + "BAD_RECEIVER_RETURN_VALUE" + ); + } + } + + /// @notice Enable or disable approval for a third party ("operator") to manage all of the caller's tokens. + /// @dev MUST emit the ApprovalForAll event on success. + /// @param operator Address to add to the set of authorized operators + /// @param approved True if the operator is approved, false to revoke approval + function setApprovalForAll(address operator, bool approved) external { + operatorApproval[msg.sender][operator] = approved; + emit ApprovalForAll(msg.sender, operator, approved); + } + + /// @notice Queries the approval status of an operator for a given owner. + /// @param owner The owner of the Tokens + /// @param operator Address of authorized operator + /// @return isApproved True if the operator is approved, false if not + function isApprovedForAll(address owner, address operator) external view returns (bool isApproved) { + return operatorApproval[owner][operator]; + } + + /// @notice Get the balance of an account's Tokens. + /// @param owner The address of the token holder + /// @param id ID of the Token + /// @return balance The _owner's balance of the Token type requested + function balanceOf(address owner, uint256 id) external view returns (uint256 balance) { + return balances[id][owner]; + } + + /// @notice Get the balance of multiple account/token pairs + /// @param owners The addresses of the token holders + /// @param ids ID of the Tokens + /// @return balances_ The _owner's balance of the Token types requested + function balanceOfBatch(address[] calldata owners, uint256[] calldata ids) external view returns (uint256[] memory balances_) { + // sanity check + require( + owners.length == ids.length, + "OWNERS_AND_IDS_MUST_HAVE_SAME_LENGTH" + ); + + // get balances + balances_ = new uint256[](owners.length); + for (uint256 i = 0; i < owners.length; ++i) { + uint256 id = ids[i]; + balances_[i] = balances[id][owners[i]]; + } + + return balances_; + } +} diff --git a/contracts/zero-ex/contracts/test/TestMintableERC20Token.sol b/contracts/zero-ex/contracts/test/tokens/TestMintableERC20Token.sol similarity index 100% rename from contracts/zero-ex/contracts/test/TestMintableERC20Token.sol rename to contracts/zero-ex/contracts/test/tokens/TestMintableERC20Token.sol diff --git a/contracts/zero-ex/contracts/test/tokens/TestMintableERC721Token.sol b/contracts/zero-ex/contracts/test/tokens/TestMintableERC721Token.sol new file mode 100644 index 0000000000..a581c58af7 --- /dev/null +++ b/contracts/zero-ex/contracts/test/tokens/TestMintableERC721Token.sol @@ -0,0 +1,385 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + + Copyright 2020 ZeroEx 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 "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol"; + + +interface IERC721Receiver { + + /// @notice Handle the receipt of an NFT + /// @dev The ERC721 smart contract calls this function on the recipient + /// after a `transfer`. This function MAY throw to revert and reject the + /// transfer. Return of other than the magic value MUST result in the + /// transaction being reverted. + /// Note: the contract address is always the message sender. + /// @param _operator The address which called `safeTransferFrom` function + /// @param _from The address which previously owned the token + /// @param _tokenId The NFT identifier which is being transferred + /// @param _data Additional data with no specified format + /// @return `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` + /// unless throwing + function onERC721Received( + address _operator, + address _from, + uint256 _tokenId, + bytes calldata _data + ) + external + returns (bytes4); +} + +contract TestMintableERC721Token { + using LibSafeMathV06 for uint256; + + /// @dev This emits when ownership of any NFT changes by any mechanism. + /// This event emits when NFTs are created (`from` == 0) and destroyed + /// (`to` == 0). Exception: during contract creation, any number of NFTs + /// may be created and assigned without emitting Transfer. At the time of + /// any transfer, the approved address for that NFT (if any) is reset to none. + event Transfer( + address _from, + address _to, + uint256 _tokenId + ); + + /// @dev This emits when the approved address for an NFT is changed or + /// reaffirmed. The zero address indicates there is no approved address. + /// When a Transfer event emits, this also indicates that the approved + /// address for that NFT (if any) is reset to none. + event Approval( + address indexed _owner, + address indexed _approved, + uint256 indexed _tokenId + ); + + /// @dev This emits when an operator is enabled or disabled for an owner. + /// The operator can manage all NFTs of the owner. + event ApprovalForAll( + address indexed _owner, + address indexed _operator, + bool _approved + ); + + // Function selector for ERC721Receiver.onERC721Received + // 0x150b7a02 + bytes4 constant private ERC721_RECEIVED = bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")); + + // Mapping of tokenId => owner + mapping (uint256 => address) private owners; + + // Mapping of tokenId => approved address + mapping (uint256 => address) private approvals; + + // Mapping of owner => number of tokens owned + mapping (address => uint256) private balances; + + // Mapping of owner => operator => approved + mapping (address => mapping (address => bool)) private operatorApprovals; + + /// @dev Function to mint a new token + /// Reverts if the given token ID already exists + /// @param _to Address of the beneficiary that will own the minted token + /// @param _tokenId ID of the token to be minted by the msg.sender + function mint(address _to, uint256 _tokenId) + external + { + require( + _to != address(0), + "ERC721_ZERO_TO_ADDRESS" + ); + + address owner = owners[_tokenId]; + require( + owner == address(0), + "ERC721_OWNER_ALREADY_EXISTS" + ); + + owners[_tokenId] = _to; + balances[_to] = balances[_to].safeAdd(1); + + emit Transfer( + address(0), + _to, + _tokenId + ); + } + + /// @dev Function to burn a token + /// Reverts if the given token ID doesn't exist + /// @param _owner Owner of token with given token ID + /// @param _tokenId ID of the token to be burned by the msg.sender + function burn(address _owner, uint256 _tokenId) + external + { + require( + _owner != address(0), + "ERC721_ZERO_OWNER_ADDRESS" + ); + + address owner = owners[_tokenId]; + require( + owner == _owner, + "ERC721_OWNER_MISMATCH" + ); + + owners[_tokenId] = address(0); + balances[_owner] = balances[_owner].safeSub(1); + + emit Transfer( + _owner, + address(0), + _tokenId + ); + } + + /// @notice Transfers the ownership of an NFT from one address to another address + /// @dev Throws unless `msg.sender` is the current owner, an authorized + /// operator, or the approved address for this NFT. Throws if `_from` is + /// not the current owner. Throws if `_to` is the zero address. Throws if + /// `_tokenId` is not a valid NFT. When transfer is complete, this function + /// checks if `_to` is a smart contract (code size > 0). If so, it calls + /// `onERC721Received` on `_to` and throws if the return value is not + /// `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`. + /// @param _from The current owner of the NFT + /// @param _to The new owner + /// @param _tokenId The NFT to transfer + /// @param _data Additional data with no specified format, sent in call to `_to` + function safeTransferFrom( + address _from, + address _to, + uint256 _tokenId, + bytes calldata _data + ) + external + { + transferFrom( + _from, + _to, + _tokenId + ); + + uint256 receiverCodeSize; + assembly { + receiverCodeSize := extcodesize(_to) + } + if (receiverCodeSize > 0) { + bytes4 selector = IERC721Receiver(_to).onERC721Received( + msg.sender, + _from, + _tokenId, + _data + ); + require( + selector == ERC721_RECEIVED, + "ERC721_INVALID_SELECTOR" + ); + } + } + + /// @notice Transfers the ownership of an NFT from one address to another address + /// @dev This works identically to the other function with an extra data parameter, + /// except this function just sets data to "". + /// @param _from The current owner of the NFT + /// @param _to The new owner + /// @param _tokenId The NFT to transfer + function safeTransferFrom( + address _from, + address _to, + uint256 _tokenId + ) + external + { + transferFrom( + _from, + _to, + _tokenId + ); + + uint256 receiverCodeSize; + assembly { + receiverCodeSize := extcodesize(_to) + } + if (receiverCodeSize > 0) { + bytes4 selector = IERC721Receiver(_to).onERC721Received( + msg.sender, + _from, + _tokenId, + "" + ); + require( + selector == ERC721_RECEIVED, + "ERC721_INVALID_SELECTOR" + ); + } + } + + /// @notice Change or reaffirm the approved address for an NFT + /// @dev The zero address indicates there is no approved address. + /// Throws unless `msg.sender` is the current NFT owner, or an authorized + /// operator of the current owner. + /// @param _approved The new approved NFT controller + /// @param _tokenId The NFT to approve + function approve(address _approved, uint256 _tokenId) + external + { + address owner = ownerOf(_tokenId); + require( + msg.sender == owner || isApprovedForAll(owner, msg.sender), + "ERC721_INVALID_SENDER" + ); + + approvals[_tokenId] = _approved; + emit Approval( + owner, + _approved, + _tokenId + ); + } + + /// @notice Enable or disable approval for a third party ("operator") to manage + /// all of `msg.sender`'s assets + /// @dev Emits the ApprovalForAll event. The contract MUST allow + /// multiple operators per owner. + /// @param _operator Address to add to the set of authorized operators + /// @param _approved True if the operator is approved, false to revoke approval + function setApprovalForAll(address _operator, bool _approved) + external + { + operatorApprovals[msg.sender][_operator] = _approved; + emit ApprovalForAll( + msg.sender, + _operator, + _approved + ); + } + + /// @notice Count all NFTs assigned to an owner + /// @dev NFTs assigned to the zero address are considered invalid, and this + /// function throws for queries about the zero address. + /// @param _owner An address for whom to query the balance + /// @return The number of NFTs owned by `_owner`, possibly zero + function balanceOf(address _owner) + external + view + returns (uint256) + { + require( + _owner != address(0), + "ERC721_ZERO_OWNER" + ); + return balances[_owner]; + } + + /// @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE + /// TO CONFIRM THAT `_to` IS CAPABLE OF RECEIVING NFTS OR ELSE + /// THEY MAY BE PERMANENTLY LOST + /// @dev Throws unless `msg.sender` is the current owner, an authorized + /// operator, or the approved address for this NFT. Throws if `_from` is + /// not the current owner. Throws if `_to` is the zero address. Throws if + /// `_tokenId` is not a valid NFT. + /// @param _from The current owner of the NFT + /// @param _to The new owner + /// @param _tokenId The NFT to transfer + function transferFrom( + address _from, + address _to, + uint256 _tokenId + ) + public + { + require( + _to != address(0), + "ERC721_ZERO_TO_ADDRESS" + ); + + address owner = ownerOf(_tokenId); + require( + _from == owner, + "ERC721_OWNER_MISMATCH" + ); + + address spender = msg.sender; + address approvedAddress = getApproved(_tokenId); + require( + spender == owner || + isApprovedForAll(owner, spender) || + approvedAddress == spender, + "ERC721_INVALID_SPENDER" + ); + + if (approvedAddress != address(0)) { + approvals[_tokenId] = address(0); + } + + owners[_tokenId] = _to; + balances[_from] = balances[_from].safeSub(1); + balances[_to] = balances[_to].safeAdd(1); + + emit Transfer( + _from, + _to, + _tokenId + ); + } + + /// @notice Find the owner of an NFT + /// @dev NFTs assigned to zero address are considered invalid, and queries + /// about them do throw. + /// @param _tokenId The identifier for an NFT + /// @return The address of the owner of the NFT + function ownerOf(uint256 _tokenId) + public + view + returns (address) + { + address owner = owners[_tokenId]; + require( + owner != address(0), + "ERC721_ZERO_OWNER" + ); + return owner; + } + + /// @notice Get the approved address for a single NFT + /// @dev Throws if `_tokenId` is not a valid NFT. + /// @param _tokenId The NFT to find the approved address for + /// @return The approved address for this NFT, or the zero address if there is none + function getApproved(uint256 _tokenId) + public + view + returns (address) + { + return approvals[_tokenId]; + } + + /// @notice Query if an address is an authorized operator for another address + /// @param _owner The address that owns the NFTs + /// @param _operator The address that acts on behalf of the owner + /// @return True if `_operator` is an approved operator for `_owner`, false otherwise + function isApprovedForAll(address _owner, address _operator) + public + view + returns (bool) + { + return operatorApprovals[_owner][_operator]; + } +} diff --git a/contracts/zero-ex/contracts/test/TestTokenSpenderERC20Token.sol b/contracts/zero-ex/contracts/test/tokens/TestTokenSpenderERC20Token.sol similarity index 100% rename from contracts/zero-ex/contracts/test/TestTokenSpenderERC20Token.sol rename to contracts/zero-ex/contracts/test/tokens/TestTokenSpenderERC20Token.sol diff --git a/contracts/zero-ex/contracts/test/TestWeth.sol b/contracts/zero-ex/contracts/test/tokens/TestWeth.sol similarity index 100% rename from contracts/zero-ex/contracts/test/TestWeth.sol rename to contracts/zero-ex/contracts/test/tokens/TestWeth.sol diff --git a/contracts/zero-ex/package.json b/contracts/zero-ex/package.json index 6520bc04b6..0baa9d3bb4 100644 --- a/contracts/zero-ex/package.json +++ b/contracts/zero-ex/package.json @@ -43,7 +43,7 @@ "config": { "publicInterfaceContracts": "IZeroEx,ZeroEx,FullMigration,InitialMigration,IFlashWallet,IERC20Transformer,IOwnableFeature,ISimpleFunctionRegistryFeature,ITransformERC20Feature,FillQuoteTransformer,PayTakerTransformer,PositiveSlippageFeeTransformer,WethTransformer,OwnableFeature,SimpleFunctionRegistryFeature,TransformERC20Feature,AffiliateFeeTransformer,MetaTransactionsFeature,LogMetadataTransformer,BridgeAdapter,LiquidityProviderFeature,ILiquidityProviderFeature,NativeOrdersFeature,INativeOrdersFeature,FeeCollectorController,FeeCollector,CurveLiquidityProvider,BatchFillNativeOrdersFeature,IBatchFillNativeOrdersFeature,MultiplexFeature,IMultiplexFeature,OtcOrdersFeature,IOtcOrdersFeature", "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.", - "abis": "./test/generated-artifacts/@(AffiliateFeeTransformer|BatchFillNativeOrdersFeature|BootstrapFeature|BridgeAdapter|BridgeProtocols|CurveLiquidityProvider|FeeCollector|FeeCollectorController|FillQuoteTransformer|FixinCommon|FixinEIP712|FixinProtocolFees|FixinReentrancyGuard|FixinTokenSpender|FlashWallet|FullMigration|FundRecoveryFeature|IBatchFillNativeOrdersFeature|IBootstrapFeature|IBridgeAdapter|IERC20Bridge|IERC20Transformer|IFeature|IFlashWallet|IFundRecoveryFeature|ILiquidityProvider|ILiquidityProviderFeature|ILiquidityProviderSandbox|IMetaTransactionsFeature|IMooniswapPool|IMultiplexFeature|INativeOrdersEvents|INativeOrdersFeature|IOtcOrdersFeature|IOwnableFeature|IPancakeSwapFeature|ISimpleFunctionRegistryFeature|IStaking|ITestSimpleFunctionRegistryFeature|ITokenSpenderFeature|ITransformERC20Feature|IUniswapFeature|IUniswapV2Pair|IUniswapV3Feature|IUniswapV3Pool|IZeroEx|InitialMigration|LibBootstrap|LibCommonRichErrors|LibERC20Transformer|LibFeeCollector|LibLiquidityProviderRichErrors|LibMetaTransactionsRichErrors|LibMetaTransactionsStorage|LibMigrate|LibNativeOrder|LibNativeOrdersRichErrors|LibNativeOrdersStorage|LibOtcOrdersStorage|LibOwnableRichErrors|LibOwnableStorage|LibProxyRichErrors|LibProxyStorage|LibReentrancyGuardStorage|LibSignature|LibSignatureRichErrors|LibSimpleFunctionRegistryRichErrors|LibSimpleFunctionRegistryStorage|LibStorage|LibTransformERC20RichErrors|LibTransformERC20Storage|LibWalletRichErrors|LiquidityProviderFeature|LiquidityProviderSandbox|LogMetadataTransformer|MetaTransactionsFeature|MixinAaveV2|MixinBalancer|MixinBalancerV2|MixinBancor|MixinCoFiX|MixinCompound|MixinCryptoCom|MixinCurve|MixinCurveV2|MixinDodo|MixinDodoV2|MixinKyber|MixinKyberDmm|MixinLido|MixinMStable|MixinMakerPSM|MixinMooniswap|MixinNerve|MixinOasis|MixinShell|MixinUniswap|MixinUniswapV2|MixinUniswapV3|MixinZeroExBridge|MooniswapLiquidityProvider|MultiplexFeature|MultiplexLiquidityProvider|MultiplexOtc|MultiplexRfq|MultiplexTransformERC20|MultiplexUniswapV2|MultiplexUniswapV3|NativeOrdersCancellation|NativeOrdersFeature|NativeOrdersInfo|NativeOrdersProtocolFees|NativeOrdersSettlement|OtcOrdersFeature|OwnableFeature|PancakeSwapFeature|PayTakerTransformer|PermissionlessTransformerDeployer|PositiveSlippageFeeTransformer|SimpleFunctionRegistryFeature|TestBridge|TestCallTarget|TestCurve|TestDelegateCaller|TestFeeCollectorController|TestFillQuoteTransformerBridge|TestFillQuoteTransformerExchange|TestFillQuoteTransformerHost|TestFixinProtocolFees|TestFixinTokenSpender|TestFullMigration|TestInitialMigration|TestLibNativeOrder|TestLibSignature|TestLiquidityProvider|TestMetaTransactionsNativeOrdersFeature|TestMetaTransactionsTransformERC20Feature|TestMigrator|TestMintTokenERC20Transformer|TestMintableERC20Token|TestMooniswap|TestNativeOrdersFeature|TestNoEthRecipient|TestOrderSignerRegistryWithContractWallet|TestPermissionlessTransformerDeployerSuicidal|TestPermissionlessTransformerDeployerTransformer|TestRfqOriginRegistration|TestSimpleFunctionRegistryFeatureImpl1|TestSimpleFunctionRegistryFeatureImpl2|TestStaking|TestTokenSpenderERC20Token|TestTransformERC20|TestTransformerBase|TestTransformerDeployerTransformer|TestTransformerHost|TestUniswapV2Factory|TestUniswapV2Pool|TestUniswapV3Factory|TestUniswapV3Feature|TestUniswapV3Pool|TestWeth|TestWethTransformerHost|TestZeroExFeature|TransformERC20Feature|Transformer|TransformerDeployer|UniswapFeature|UniswapV3Feature|WethTransformer|ZeroEx|ZeroExOptimized).json" + "abis": "./test/generated-artifacts/@(AffiliateFeeTransformer|BatchFillNativeOrdersFeature|BootstrapFeature|BridgeAdapter|BridgeProtocols|CurveLiquidityProvider|ERC1155OrdersFeature|ERC165Feature|ERC721OrdersFeature|FeeCollector|FeeCollectorController|FillQuoteTransformer|FixinCommon|FixinEIP712|FixinERC1155Spender|FixinERC721Spender|FixinProtocolFees|FixinReentrancyGuard|FixinTokenSpender|FlashWallet|FullMigration|FundRecoveryFeature|IBatchFillNativeOrdersFeature|IBootstrapFeature|IBridgeAdapter|IERC1155OrdersFeature|IERC1155Token|IERC165Feature|IERC20Bridge|IERC20Transformer|IERC721OrdersFeature|IERC721Token|IFeature|IFeeRecipient|IFlashWallet|IFundRecoveryFeature|ILiquidityProvider|ILiquidityProviderFeature|ILiquidityProviderSandbox|IMetaTransactionsFeature|IMooniswapPool|IMultiplexFeature|INativeOrdersEvents|INativeOrdersFeature|IOtcOrdersFeature|IOwnableFeature|IPancakeSwapFeature|IPropertyValidator|ISimpleFunctionRegistryFeature|IStaking|ITakerCallback|ITestSimpleFunctionRegistryFeature|ITokenSpenderFeature|ITransformERC20Feature|IUniswapFeature|IUniswapV2Pair|IUniswapV3Feature|IUniswapV3Pool|IZeroEx|InitialMigration|LibBootstrap|LibCommonRichErrors|LibERC1155OrdersStorage|LibERC20Transformer|LibERC721OrdersStorage|LibFeeCollector|LibLiquidityProviderRichErrors|LibMetaTransactionsRichErrors|LibMetaTransactionsStorage|LibMigrate|LibNFTOrder|LibNFTOrdersRichErrors|LibNativeOrder|LibNativeOrdersRichErrors|LibNativeOrdersStorage|LibOtcOrdersStorage|LibOwnableRichErrors|LibOwnableStorage|LibProxyRichErrors|LibProxyStorage|LibReentrancyGuardStorage|LibSignature|LibSignatureRichErrors|LibSimpleFunctionRegistryRichErrors|LibSimpleFunctionRegistryStorage|LibStorage|LibTransformERC20RichErrors|LibTransformERC20Storage|LibWalletRichErrors|LiquidityProviderFeature|LiquidityProviderSandbox|LogMetadataTransformer|MetaTransactionsFeature|MixinAaveV2|MixinBalancer|MixinBalancerV2|MixinBancor|MixinCoFiX|MixinCompound|MixinCryptoCom|MixinCurve|MixinCurveV2|MixinDodo|MixinDodoV2|MixinKyber|MixinKyberDmm|MixinLido|MixinMStable|MixinMakerPSM|MixinMooniswap|MixinNerve|MixinOasis|MixinShell|MixinUniswap|MixinUniswapV2|MixinUniswapV3|MixinZeroExBridge|MooniswapLiquidityProvider|MultiplexFeature|MultiplexLiquidityProvider|MultiplexOtc|MultiplexRfq|MultiplexTransformERC20|MultiplexUniswapV2|MultiplexUniswapV3|NFTOrders|NativeOrdersCancellation|NativeOrdersFeature|NativeOrdersInfo|NativeOrdersProtocolFees|NativeOrdersSettlement|OtcOrdersFeature|OwnableFeature|PancakeSwapFeature|PayTakerTransformer|PermissionlessTransformerDeployer|PositiveSlippageFeeTransformer|SimpleFunctionRegistryFeature|TestBridge|TestCallTarget|TestCurve|TestDelegateCaller|TestFeeCollectorController|TestFeeRecipient|TestFillQuoteTransformerBridge|TestFillQuoteTransformerExchange|TestFillQuoteTransformerHost|TestFixinProtocolFees|TestFixinTokenSpender|TestFullMigration|TestInitialMigration|TestLibNativeOrder|TestLibSignature|TestLiquidityProvider|TestMetaTransactionsNativeOrdersFeature|TestMetaTransactionsTransformERC20Feature|TestMigrator|TestMintTokenERC20Transformer|TestMintableERC1155Token|TestMintableERC20Token|TestMintableERC721Token|TestMooniswap|TestNFTOrderPresigner|TestNativeOrdersFeature|TestNoEthRecipient|TestOrderSignerRegistryWithContractWallet|TestPermissionlessTransformerDeployerSuicidal|TestPermissionlessTransformerDeployerTransformer|TestPropertyValidator|TestRfqOriginRegistration|TestSimpleFunctionRegistryFeatureImpl1|TestSimpleFunctionRegistryFeatureImpl2|TestStaking|TestTokenSpenderERC20Token|TestTransformERC20|TestTransformerBase|TestTransformerDeployerTransformer|TestTransformerHost|TestUniswapV2Factory|TestUniswapV2Pool|TestUniswapV3Factory|TestUniswapV3Feature|TestUniswapV3Pool|TestWeth|TestWethTransformerHost|TestZeroExFeature|TransformERC20Feature|Transformer|TransformerDeployer|UniswapFeature|UniswapV3Feature|WethTransformer|ZeroEx|ZeroExOptimized).json" }, "repository": { "type": "git", @@ -55,14 +55,14 @@ }, "homepage": "https://github.com/0xProject/protocol/tree/main/contracts/zero-ex", "devDependencies": { - "@0x/abi-gen": "^5.6.2", + "@0x/abi-gen": "^5.7.2", "@0x/contract-addresses": "^6.11.0", "@0x/contracts-erc20": "^3.3.25", - "@0x/contracts-gen": "^2.0.40", + "@0x/contracts-gen": "^2.0.43", "@0x/contracts-test-utils": "^5.4.16", - "@0x/dev-utils": "^4.2.9", + "@0x/dev-utils": "^4.2.11", "@0x/order-utils": "^10.4.28", - "@0x/sol-compiler": "^4.7.5", + "@0x/sol-compiler": "^4.7.8", "@0x/ts-doc-gen": "^0.0.28", "@0x/tslint-config": "^4.1.4", "@types/isomorphic-fetch": "^0.0.35", @@ -82,13 +82,13 @@ "typescript": "4.2.2" }, "dependencies": { - "@0x/base-contract": "^6.4.2", + "@0x/base-contract": "^6.4.5", "@0x/protocol-utils": "^1.10.1", - "@0x/subproviders": "^6.6.0", + "@0x/subproviders": "^6.6.2", "@0x/types": "^3.3.4", "@0x/typescript-typings": "^5.2.1", - "@0x/utils": "^6.4.4", - "@0x/web3-wrapper": "^7.6.0", + "@0x/utils": "^6.5.0", + "@0x/web3-wrapper": "^7.6.2", "ethereum-types": "^3.6.0", "ethereumjs-util": "^7.0.10", "ethers": "~4.0.4" diff --git a/contracts/zero-ex/test/artifacts.ts b/contracts/zero-ex/test/artifacts.ts index 7073aaa136..f843d906b6 100644 --- a/contracts/zero-ex/test/artifacts.ts +++ b/contracts/zero-ex/test/artifacts.ts @@ -11,11 +11,16 @@ import * as BootstrapFeature from '../test/generated-artifacts/BootstrapFeature. import * as BridgeAdapter from '../test/generated-artifacts/BridgeAdapter.json'; import * as BridgeProtocols from '../test/generated-artifacts/BridgeProtocols.json'; import * as CurveLiquidityProvider from '../test/generated-artifacts/CurveLiquidityProvider.json'; +import * as ERC1155OrdersFeature from '../test/generated-artifacts/ERC1155OrdersFeature.json'; +import * as ERC165Feature from '../test/generated-artifacts/ERC165Feature.json'; +import * as ERC721OrdersFeature from '../test/generated-artifacts/ERC721OrdersFeature.json'; import * as FeeCollector from '../test/generated-artifacts/FeeCollector.json'; import * as FeeCollectorController from '../test/generated-artifacts/FeeCollectorController.json'; import * as FillQuoteTransformer from '../test/generated-artifacts/FillQuoteTransformer.json'; import * as FixinCommon from '../test/generated-artifacts/FixinCommon.json'; import * as FixinEIP712 from '../test/generated-artifacts/FixinEIP712.json'; +import * as FixinERC1155Spender from '../test/generated-artifacts/FixinERC1155Spender.json'; +import * as FixinERC721Spender from '../test/generated-artifacts/FixinERC721Spender.json'; import * as FixinProtocolFees from '../test/generated-artifacts/FixinProtocolFees.json'; import * as FixinReentrancyGuard from '../test/generated-artifacts/FixinReentrancyGuard.json'; import * as FixinTokenSpender from '../test/generated-artifacts/FixinTokenSpender.json'; @@ -25,9 +30,15 @@ import * as FundRecoveryFeature from '../test/generated-artifacts/FundRecoveryFe import * as IBatchFillNativeOrdersFeature from '../test/generated-artifacts/IBatchFillNativeOrdersFeature.json'; import * as IBootstrapFeature from '../test/generated-artifacts/IBootstrapFeature.json'; import * as IBridgeAdapter from '../test/generated-artifacts/IBridgeAdapter.json'; +import * as IERC1155OrdersFeature from '../test/generated-artifacts/IERC1155OrdersFeature.json'; +import * as IERC1155Token from '../test/generated-artifacts/IERC1155Token.json'; +import * as IERC165Feature from '../test/generated-artifacts/IERC165Feature.json'; import * as IERC20Bridge from '../test/generated-artifacts/IERC20Bridge.json'; import * as IERC20Transformer from '../test/generated-artifacts/IERC20Transformer.json'; +import * as IERC721OrdersFeature from '../test/generated-artifacts/IERC721OrdersFeature.json'; +import * as IERC721Token from '../test/generated-artifacts/IERC721Token.json'; import * as IFeature from '../test/generated-artifacts/IFeature.json'; +import * as IFeeRecipient from '../test/generated-artifacts/IFeeRecipient.json'; import * as IFlashWallet from '../test/generated-artifacts/IFlashWallet.json'; import * as IFundRecoveryFeature from '../test/generated-artifacts/IFundRecoveryFeature.json'; import * as ILiquidityProvider from '../test/generated-artifacts/ILiquidityProvider.json'; @@ -42,8 +53,10 @@ import * as InitialMigration from '../test/generated-artifacts/InitialMigration. import * as IOtcOrdersFeature from '../test/generated-artifacts/IOtcOrdersFeature.json'; import * as IOwnableFeature from '../test/generated-artifacts/IOwnableFeature.json'; import * as IPancakeSwapFeature from '../test/generated-artifacts/IPancakeSwapFeature.json'; +import * as IPropertyValidator from '../test/generated-artifacts/IPropertyValidator.json'; import * as ISimpleFunctionRegistryFeature from '../test/generated-artifacts/ISimpleFunctionRegistryFeature.json'; import * as IStaking from '../test/generated-artifacts/IStaking.json'; +import * as ITakerCallback from '../test/generated-artifacts/ITakerCallback.json'; import * as ITestSimpleFunctionRegistryFeature from '../test/generated-artifacts/ITestSimpleFunctionRegistryFeature.json'; import * as ITokenSpenderFeature from '../test/generated-artifacts/ITokenSpenderFeature.json'; import * as ITransformERC20Feature from '../test/generated-artifacts/ITransformERC20Feature.json'; @@ -54,7 +67,9 @@ import * as IUniswapV3Pool from '../test/generated-artifacts/IUniswapV3Pool.json import * as IZeroEx from '../test/generated-artifacts/IZeroEx.json'; import * as LibBootstrap from '../test/generated-artifacts/LibBootstrap.json'; import * as LibCommonRichErrors from '../test/generated-artifacts/LibCommonRichErrors.json'; +import * as LibERC1155OrdersStorage from '../test/generated-artifacts/LibERC1155OrdersStorage.json'; import * as LibERC20Transformer from '../test/generated-artifacts/LibERC20Transformer.json'; +import * as LibERC721OrdersStorage from '../test/generated-artifacts/LibERC721OrdersStorage.json'; import * as LibFeeCollector from '../test/generated-artifacts/LibFeeCollector.json'; import * as LibLiquidityProviderRichErrors from '../test/generated-artifacts/LibLiquidityProviderRichErrors.json'; import * as LibMetaTransactionsRichErrors from '../test/generated-artifacts/LibMetaTransactionsRichErrors.json'; @@ -63,6 +78,8 @@ import * as LibMigrate from '../test/generated-artifacts/LibMigrate.json'; import * as LibNativeOrder from '../test/generated-artifacts/LibNativeOrder.json'; import * as LibNativeOrdersRichErrors from '../test/generated-artifacts/LibNativeOrdersRichErrors.json'; import * as LibNativeOrdersStorage from '../test/generated-artifacts/LibNativeOrdersStorage.json'; +import * as LibNFTOrder from '../test/generated-artifacts/LibNFTOrder.json'; +import * as LibNFTOrdersRichErrors from '../test/generated-artifacts/LibNFTOrdersRichErrors.json'; import * as LibOtcOrdersStorage from '../test/generated-artifacts/LibOtcOrdersStorage.json'; import * as LibOwnableRichErrors from '../test/generated-artifacts/LibOwnableRichErrors.json'; import * as LibOwnableStorage from '../test/generated-artifacts/LibOwnableStorage.json'; @@ -118,6 +135,7 @@ import * as NativeOrdersFeature from '../test/generated-artifacts/NativeOrdersFe import * as NativeOrdersInfo from '../test/generated-artifacts/NativeOrdersInfo.json'; import * as NativeOrdersProtocolFees from '../test/generated-artifacts/NativeOrdersProtocolFees.json'; import * as NativeOrdersSettlement from '../test/generated-artifacts/NativeOrdersSettlement.json'; +import * as NFTOrders from '../test/generated-artifacts/NFTOrders.json'; import * as OtcOrdersFeature from '../test/generated-artifacts/OtcOrdersFeature.json'; import * as OwnableFeature from '../test/generated-artifacts/OwnableFeature.json'; import * as PancakeSwapFeature from '../test/generated-artifacts/PancakeSwapFeature.json'; @@ -130,6 +148,7 @@ import * as TestCallTarget from '../test/generated-artifacts/TestCallTarget.json import * as TestCurve from '../test/generated-artifacts/TestCurve.json'; import * as TestDelegateCaller from '../test/generated-artifacts/TestDelegateCaller.json'; import * as TestFeeCollectorController from '../test/generated-artifacts/TestFeeCollectorController.json'; +import * as TestFeeRecipient from '../test/generated-artifacts/TestFeeRecipient.json'; import * as TestFillQuoteTransformerBridge from '../test/generated-artifacts/TestFillQuoteTransformerBridge.json'; import * as TestFillQuoteTransformerExchange from '../test/generated-artifacts/TestFillQuoteTransformerExchange.json'; import * as TestFillQuoteTransformerHost from '../test/generated-artifacts/TestFillQuoteTransformerHost.json'; @@ -143,14 +162,18 @@ import * as TestLiquidityProvider from '../test/generated-artifacts/TestLiquidit import * as TestMetaTransactionsNativeOrdersFeature from '../test/generated-artifacts/TestMetaTransactionsNativeOrdersFeature.json'; import * as TestMetaTransactionsTransformERC20Feature from '../test/generated-artifacts/TestMetaTransactionsTransformERC20Feature.json'; import * as TestMigrator from '../test/generated-artifacts/TestMigrator.json'; +import * as TestMintableERC1155Token from '../test/generated-artifacts/TestMintableERC1155Token.json'; import * as TestMintableERC20Token from '../test/generated-artifacts/TestMintableERC20Token.json'; +import * as TestMintableERC721Token from '../test/generated-artifacts/TestMintableERC721Token.json'; import * as TestMintTokenERC20Transformer from '../test/generated-artifacts/TestMintTokenERC20Transformer.json'; import * as TestMooniswap from '../test/generated-artifacts/TestMooniswap.json'; import * as TestNativeOrdersFeature from '../test/generated-artifacts/TestNativeOrdersFeature.json'; +import * as TestNFTOrderPresigner from '../test/generated-artifacts/TestNFTOrderPresigner.json'; import * as TestNoEthRecipient from '../test/generated-artifacts/TestNoEthRecipient.json'; import * as TestOrderSignerRegistryWithContractWallet from '../test/generated-artifacts/TestOrderSignerRegistryWithContractWallet.json'; import * as TestPermissionlessTransformerDeployerSuicidal from '../test/generated-artifacts/TestPermissionlessTransformerDeployerSuicidal.json'; import * as TestPermissionlessTransformerDeployerTransformer from '../test/generated-artifacts/TestPermissionlessTransformerDeployerTransformer.json'; +import * as TestPropertyValidator from '../test/generated-artifacts/TestPropertyValidator.json'; import * as TestRfqOriginRegistration from '../test/generated-artifacts/TestRfqOriginRegistration.json'; import * as TestSimpleFunctionRegistryFeatureImpl1 from '../test/generated-artifacts/TestSimpleFunctionRegistryFeatureImpl1.json'; import * as TestSimpleFunctionRegistryFeatureImpl2 from '../test/generated-artifacts/TestSimpleFunctionRegistryFeatureImpl2.json'; @@ -183,6 +206,7 @@ export const artifacts = { LibCommonRichErrors: LibCommonRichErrors as ContractArtifact, LibLiquidityProviderRichErrors: LibLiquidityProviderRichErrors as ContractArtifact, LibMetaTransactionsRichErrors: LibMetaTransactionsRichErrors as ContractArtifact, + LibNFTOrdersRichErrors: LibNFTOrdersRichErrors as ContractArtifact, LibNativeOrdersRichErrors: LibNativeOrdersRichErrors as ContractArtifact, LibOwnableRichErrors: LibOwnableRichErrors as ContractArtifact, LibProxyRichErrors: LibProxyRichErrors as ContractArtifact, @@ -201,6 +225,7 @@ export const artifacts = { TransformerDeployer: TransformerDeployer as ContractArtifact, BatchFillNativeOrdersFeature: BatchFillNativeOrdersFeature as ContractArtifact, BootstrapFeature: BootstrapFeature as ContractArtifact, + ERC165Feature: ERC165Feature as ContractArtifact, FundRecoveryFeature: FundRecoveryFeature as ContractArtifact, LiquidityProviderFeature: LiquidityProviderFeature as ContractArtifact, MetaTransactionsFeature: MetaTransactionsFeature as ContractArtifact, @@ -214,6 +239,9 @@ export const artifacts = { UniswapV3Feature: UniswapV3Feature as ContractArtifact, IBatchFillNativeOrdersFeature: IBatchFillNativeOrdersFeature as ContractArtifact, IBootstrapFeature: IBootstrapFeature as ContractArtifact, + IERC1155OrdersFeature: IERC1155OrdersFeature as ContractArtifact, + IERC165Feature: IERC165Feature as ContractArtifact, + IERC721OrdersFeature: IERC721OrdersFeature as ContractArtifact, IFeature: IFeature as ContractArtifact, IFundRecoveryFeature: IFundRecoveryFeature as ContractArtifact, ILiquidityProviderFeature: ILiquidityProviderFeature as ContractArtifact, @@ -229,6 +257,7 @@ export const artifacts = { ITransformERC20Feature: ITransformERC20Feature as ContractArtifact, IUniswapFeature: IUniswapFeature as ContractArtifact, IUniswapV3Feature: IUniswapV3Feature as ContractArtifact, + LibNFTOrder: LibNFTOrder as ContractArtifact, LibNativeOrder: LibNativeOrder as ContractArtifact, LibSignature: LibSignature as ContractArtifact, MultiplexFeature: MultiplexFeature as ContractArtifact, @@ -242,8 +271,13 @@ export const artifacts = { NativeOrdersInfo: NativeOrdersInfo as ContractArtifact, NativeOrdersProtocolFees: NativeOrdersProtocolFees as ContractArtifact, NativeOrdersSettlement: NativeOrdersSettlement as ContractArtifact, + ERC1155OrdersFeature: ERC1155OrdersFeature as ContractArtifact, + ERC721OrdersFeature: ERC721OrdersFeature as ContractArtifact, + NFTOrders: NFTOrders as ContractArtifact, FixinCommon: FixinCommon as ContractArtifact, FixinEIP712: FixinEIP712 as ContractArtifact, + FixinERC1155Spender: FixinERC1155Spender as ContractArtifact, + FixinERC721Spender: FixinERC721Spender as ContractArtifact, FixinProtocolFees: FixinProtocolFees as ContractArtifact, FixinReentrancyGuard: FixinReentrancyGuard as ContractArtifact, FixinTokenSpender: FixinTokenSpender as ContractArtifact, @@ -253,6 +287,8 @@ export const artifacts = { InitialMigration: InitialMigration as ContractArtifact, LibBootstrap: LibBootstrap as ContractArtifact, LibMigrate: LibMigrate as ContractArtifact, + LibERC1155OrdersStorage: LibERC1155OrdersStorage as ContractArtifact, + LibERC721OrdersStorage: LibERC721OrdersStorage as ContractArtifact, LibMetaTransactionsStorage: LibMetaTransactionsStorage as ContractArtifact, LibNativeOrdersStorage: LibNativeOrdersStorage as ContractArtifact, LibOtcOrdersStorage: LibOtcOrdersStorage as ContractArtifact, @@ -298,8 +334,13 @@ export const artifacts = { MixinUniswapV2: MixinUniswapV2 as ContractArtifact, MixinUniswapV3: MixinUniswapV3 as ContractArtifact, MixinZeroExBridge: MixinZeroExBridge as ContractArtifact, + IERC1155Token: IERC1155Token as ContractArtifact, + IERC721Token: IERC721Token as ContractArtifact, + IFeeRecipient: IFeeRecipient as ContractArtifact, ILiquidityProvider: ILiquidityProvider as ContractArtifact, IMooniswapPool: IMooniswapPool as ContractArtifact, + IPropertyValidator: IPropertyValidator as ContractArtifact, + ITakerCallback: ITakerCallback as ContractArtifact, IUniswapV2Pair: IUniswapV2Pair as ContractArtifact, IUniswapV3Pool: IUniswapV3Pool as ContractArtifact, IERC20Bridge: IERC20Bridge as ContractArtifact, @@ -307,9 +348,9 @@ export const artifacts = { ITestSimpleFunctionRegistryFeature: ITestSimpleFunctionRegistryFeature as ContractArtifact, TestBridge: TestBridge as ContractArtifact, TestCallTarget: TestCallTarget as ContractArtifact, - TestCurve: TestCurve as ContractArtifact, TestDelegateCaller: TestDelegateCaller as ContractArtifact, TestFeeCollectorController: TestFeeCollectorController as ContractArtifact, + TestFeeRecipient: TestFeeRecipient as ContractArtifact, TestFillQuoteTransformerBridge: TestFillQuoteTransformerBridge as ContractArtifact, TestFillQuoteTransformerExchange: TestFillQuoteTransformerExchange as ContractArtifact, TestFillQuoteTransformerHost: TestFillQuoteTransformerHost as ContractArtifact, @@ -319,33 +360,38 @@ export const artifacts = { TestInitialMigration: TestInitialMigration as ContractArtifact, TestLibNativeOrder: TestLibNativeOrder as ContractArtifact, TestLibSignature: TestLibSignature as ContractArtifact, - TestLiquidityProvider: TestLiquidityProvider as ContractArtifact, TestMetaTransactionsNativeOrdersFeature: TestMetaTransactionsNativeOrdersFeature as ContractArtifact, TestMetaTransactionsTransformERC20Feature: TestMetaTransactionsTransformERC20Feature as ContractArtifact, TestMigrator: TestMigrator as ContractArtifact, TestMintTokenERC20Transformer: TestMintTokenERC20Transformer as ContractArtifact, - TestMintableERC20Token: TestMintableERC20Token as ContractArtifact, - TestMooniswap: TestMooniswap as ContractArtifact, + TestNFTOrderPresigner: TestNFTOrderPresigner as ContractArtifact, TestNativeOrdersFeature: TestNativeOrdersFeature as ContractArtifact, TestNoEthRecipient: TestNoEthRecipient as ContractArtifact, TestOrderSignerRegistryWithContractWallet: TestOrderSignerRegistryWithContractWallet as ContractArtifact, TestPermissionlessTransformerDeployerSuicidal: TestPermissionlessTransformerDeployerSuicidal as ContractArtifact, TestPermissionlessTransformerDeployerTransformer: TestPermissionlessTransformerDeployerTransformer as ContractArtifact, + TestPropertyValidator: TestPropertyValidator as ContractArtifact, TestRfqOriginRegistration: TestRfqOriginRegistration as ContractArtifact, TestSimpleFunctionRegistryFeatureImpl1: TestSimpleFunctionRegistryFeatureImpl1 as ContractArtifact, TestSimpleFunctionRegistryFeatureImpl2: TestSimpleFunctionRegistryFeatureImpl2 as ContractArtifact, TestStaking: TestStaking as ContractArtifact, - TestTokenSpenderERC20Token: TestTokenSpenderERC20Token as ContractArtifact, TestTransformERC20: TestTransformERC20 as ContractArtifact, TestTransformerBase: TestTransformerBase as ContractArtifact, TestTransformerDeployerTransformer: TestTransformerDeployerTransformer as ContractArtifact, TestTransformerHost: TestTransformerHost as ContractArtifact, + TestUniswapV3Feature: TestUniswapV3Feature as ContractArtifact, + TestWethTransformerHost: TestWethTransformerHost as ContractArtifact, + TestZeroExFeature: TestZeroExFeature as ContractArtifact, + TestCurve: TestCurve as ContractArtifact, + TestLiquidityProvider: TestLiquidityProvider as ContractArtifact, + TestMooniswap: TestMooniswap as ContractArtifact, TestUniswapV2Factory: TestUniswapV2Factory as ContractArtifact, TestUniswapV2Pool: TestUniswapV2Pool as ContractArtifact, TestUniswapV3Factory: TestUniswapV3Factory as ContractArtifact, - TestUniswapV3Feature: TestUniswapV3Feature as ContractArtifact, TestUniswapV3Pool: TestUniswapV3Pool as ContractArtifact, + TestMintableERC1155Token: TestMintableERC1155Token as ContractArtifact, + TestMintableERC20Token: TestMintableERC20Token as ContractArtifact, + TestMintableERC721Token: TestMintableERC721Token as ContractArtifact, + TestTokenSpenderERC20Token: TestTokenSpenderERC20Token as ContractArtifact, TestWeth: TestWeth as ContractArtifact, - TestWethTransformerHost: TestWethTransformerHost as ContractArtifact, - TestZeroExFeature: TestZeroExFeature as ContractArtifact, }; diff --git a/contracts/zero-ex/test/features/erc1155_orders_test.ts b/contracts/zero-ex/test/features/erc1155_orders_test.ts new file mode 100644 index 0000000000..0c5d86e0b5 --- /dev/null +++ b/contracts/zero-ex/test/features/erc1155_orders_test.ts @@ -0,0 +1,1612 @@ +import { + blockchainTests, + constants, + describe, + expect, + getRandomInteger, + getRandomPortion, + randomAddress, + verifyEventsFromLogs, +} from '@0x/contracts-test-utils'; +import { ERC1155Order, NFTOrder, RevertErrors, SIGNATURE_ABI, SignatureType } from '@0x/protocol-utils'; +import { AbiEncoder, BigNumber, hexUtils, NULL_BYTES, StringRevertError } from '@0x/utils'; + +import { + IOwnableFeatureContract, + IZeroExContract, + IZeroExERC1155OrderFilledEventArgs, + IZeroExEvents, +} from '../../src/wrappers'; +import { artifacts } from '../artifacts'; +import { abis } from '../utils/abis'; +import { fullMigrateAsync } from '../utils/migration'; +import { getRandomERC1155Order } from '../utils/nft_orders'; + +import { + ERC1155OrdersFeatureContract, + TestFeeRecipientContract, + TestMintableERC1155TokenContract, + TestMintableERC20TokenContract, + TestNFTOrderPresignerContract, + TestPropertyValidatorContract, + TestWethContract, +} from '../wrappers'; + +blockchainTests.resets('ERC1155OrdersFeature', env => { + const { NULL_ADDRESS, MAX_UINT256, ZERO_AMOUNT: ZERO } = constants; + const ETH_TOKEN_ADDRESS = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'; + + let owner: string; + let maker: string; + let taker: string; + let otherMaker: string; + let otherTaker: string; + let feeRecipient: TestFeeRecipientContract; + let zeroEx: IZeroExContract; + let weth: TestWethContract; + let erc20Token: TestMintableERC20TokenContract; + let erc1155Token: TestMintableERC1155TokenContract; + + async function sendEtherAsync(to: string, amount: BigNumber): Promise { + await env.web3Wrapper.awaitTransactionSuccessAsync( + await env.web3Wrapper.sendTransactionAsync({ + ...env.txDefaults, + to, + from: owner, + value: amount, + }), + ); + } + + before(async () => { + // Useful for ETH balance accounting + const txDefaults = { ...env.txDefaults, gasPrice: 0 }; + [owner, maker, taker, otherMaker, otherTaker] = await env.getAccountAddressesAsync(); + + weth = await TestWethContract.deployFrom0xArtifactAsync( + artifacts.TestWeth, + env.provider, + txDefaults, + artifacts, + ); + erc20Token = await TestMintableERC20TokenContract.deployFrom0xArtifactAsync( + artifacts.TestMintableERC20Token, + env.provider, + txDefaults, + artifacts, + ); + erc1155Token = await TestMintableERC1155TokenContract.deployFrom0xArtifactAsync( + artifacts.TestMintableERC1155Token, + env.provider, + txDefaults, + artifacts, + ); + + zeroEx = await fullMigrateAsync(owner, env.provider, txDefaults, {}, { wethAddress: weth.address }); + zeroEx = new IZeroExContract(zeroEx.address, env.provider, txDefaults, abis); + + const featureImpl = await ERC1155OrdersFeatureContract.deployFrom0xArtifactAsync( + artifacts.ERC1155OrdersFeature, + env.provider, + txDefaults, + artifacts, + zeroEx.address, + weth.address, + ); + await new IOwnableFeatureContract(zeroEx.address, env.provider, txDefaults, abis) + .migrate(featureImpl.address, featureImpl.migrate().getABIEncodedTransactionData(), owner) + .awaitTransactionSuccessAsync(); + + await Promise.all([ + erc20Token.approve(zeroEx.address, MAX_UINT256).awaitTransactionSuccessAsync({ + from: maker, + }), + erc20Token.approve(zeroEx.address, MAX_UINT256).awaitTransactionSuccessAsync({ + from: otherMaker, + }), + erc20Token.approve(zeroEx.address, MAX_UINT256).awaitTransactionSuccessAsync({ + from: taker, + }), + erc20Token.approve(zeroEx.address, MAX_UINT256).awaitTransactionSuccessAsync({ + from: otherTaker, + }), + weth.approve(zeroEx.address, MAX_UINT256).awaitTransactionSuccessAsync({ + from: maker, + }), + weth.approve(zeroEx.address, MAX_UINT256).awaitTransactionSuccessAsync({ + from: otherMaker, + }), + weth.approve(zeroEx.address, MAX_UINT256).awaitTransactionSuccessAsync({ + from: taker, + }), + weth.approve(zeroEx.address, MAX_UINT256).awaitTransactionSuccessAsync({ + from: otherTaker, + }), + erc1155Token.setApprovalForAll(zeroEx.address, true).awaitTransactionSuccessAsync({ + from: maker, + }), + erc1155Token.setApprovalForAll(zeroEx.address, true).awaitTransactionSuccessAsync({ + from: otherMaker, + }), + erc1155Token.setApprovalForAll(zeroEx.address, true).awaitTransactionSuccessAsync({ + from: taker, + }), + erc1155Token.setApprovalForAll(zeroEx.address, true).awaitTransactionSuccessAsync({ + from: otherTaker, + }), + ]); + + feeRecipient = await TestFeeRecipientContract.deployFrom0xArtifactAsync( + artifacts.TestFeeRecipient, + env.provider, + txDefaults, + artifacts, + ); + }); + + async function mintAssetsAsync( + order: ERC1155Order, + tokenId: BigNumber = order.erc1155TokenId, + amount: BigNumber = order.erc1155TokenAmount, + _taker: string = taker, + ): Promise { + const totalFeeAmount = order.fees.length > 0 ? BigNumber.sum(...order.fees.map(fee => fee.amount)) : ZERO; + if (order.direction === NFTOrder.TradeDirection.SellNFT) { + await erc1155Token.mint(order.maker, tokenId, amount).awaitTransactionSuccessAsync(); + if (order.erc20Token !== ETH_TOKEN_ADDRESS) { + await erc20Token + .mint(_taker, order.erc20TokenAmount.plus(totalFeeAmount)) + .awaitTransactionSuccessAsync(); + } + } else { + await erc1155Token.mint(_taker, tokenId, amount).awaitTransactionSuccessAsync(); + if (order.erc20Token === weth.address) { + await weth.deposit().awaitTransactionSuccessAsync({ + from: order.maker, + value: order.erc20TokenAmount.plus(totalFeeAmount), + }); + } else { + await erc20Token + .mint(order.maker, order.erc20TokenAmount.plus(totalFeeAmount)) + .awaitTransactionSuccessAsync(); + } + } + } + + async function assertBalancesAsync( + order: ERC1155Order, + tokenId: BigNumber = order.erc1155TokenId, + amount: BigNumber = order.erc1155TokenAmount, + _taker: string = taker, + ): Promise { + const token = order.erc20Token === weth.address ? weth : erc20Token; + if (order.direction === NFTOrder.TradeDirection.SellNFT) { + const erc20FillAmount = amount + .times(order.erc20TokenAmount) + .dividedBy(order.erc1155TokenAmount) + .integerValue(BigNumber.ROUND_CEIL); + const erc20Balance = await token.balanceOf(order.maker).callAsync(); + expect(erc20Balance).to.bignumber.equal(erc20FillAmount); + const erc1155Balance = await erc1155Token.balanceOf(_taker, tokenId).callAsync(); + expect(erc1155Balance).to.bignumber.equal(amount); + } else { + const erc20FillAmount = amount + .times(order.erc20TokenAmount) + .dividedBy(order.erc1155TokenAmount) + .integerValue(BigNumber.ROUND_FLOOR); + const erc20Balance = await token.balanceOf(_taker).callAsync(); + expect(erc20Balance).to.bignumber.equal(erc20FillAmount); + const erc1155Balance = await erc1155Token.balanceOf(order.maker, tokenId).callAsync(); + expect(erc1155Balance).to.bignumber.equal(amount); + } + if (order.fees.length > 0) { + await Promise.all( + order.fees.map(async fee => { + const feeRecipientBalance = await token.balanceOf(fee.recipient).callAsync(); + const feeFillAmount = amount.times(fee.amount).idiv(order.erc1155TokenAmount); + expect(feeRecipientBalance).to.bignumber.equal(feeFillAmount); + }), + ); + } + } + + function getTestERC1155Order(fields: Partial = {}): ERC1155Order { + return getRandomERC1155Order({ + maker, + verifyingContract: zeroEx.address, + chainId: 1337, + erc20Token: erc20Token.address, + erc1155Token: erc1155Token.address, + taker: NULL_ADDRESS, + ...fields, + }); + } + + function createERC1155OrderFilledEvent( + order: ERC1155Order, + amount: BigNumber = order.erc1155TokenAmount, + _taker: string = taker, + erc1155TokenId: BigNumber = order.erc1155TokenId, + ): IZeroExERC1155OrderFilledEventArgs { + const erc20FillAmount = amount + .times(order.erc20TokenAmount) + .dividedBy(order.erc1155TokenAmount) + .integerValue( + order.direction === NFTOrder.TradeDirection.SellNFT ? BigNumber.ROUND_CEIL : BigNumber.ROUND_FLOOR, + ); + return { + direction: order.direction, + maker: order.maker, + taker, + nonce: order.nonce, + erc20Token: order.erc20Token, + erc20FillAmount, + erc1155Token: order.erc1155Token, + erc1155TokenId, + erc1155FillAmount: amount, + matcher: NULL_ADDRESS, + }; + } + + describe('getERC1155OrderHash()', () => { + it('returns the correct hash for order with no fees or properties', async () => { + const order = getTestERC1155Order(); + const hash = await zeroEx.getERC1155OrderHash(order).callAsync(); + expect(hash).to.eq(order.getHash()); + }); + it('returns the correct hash for order with null property', async () => { + const order = getTestERC1155Order({ + erc1155TokenProperties: [ + { + propertyValidator: NULL_ADDRESS, + propertyData: NULL_BYTES, + }, + ], + }); + const hash = await zeroEx.getERC1155OrderHash(order).callAsync(); + expect(hash).to.eq(order.getHash()); + }); + it('returns the correct hash for order with 1 fee, 1 property', async () => { + const order = getTestERC1155Order({ + fees: [ + { + recipient: randomAddress(), + amount: getRandomInteger(0, MAX_UINT256), + feeData: hexUtils.random(), + }, + ], + erc1155TokenProperties: [ + { + propertyValidator: randomAddress(), + propertyData: hexUtils.random(), + }, + ], + }); + const hash = await zeroEx.getERC1155OrderHash(order).callAsync(); + expect(hash).to.eq(order.getHash()); + }); + it('returns the correct hash for order with 2 fees, 2 properties', async () => { + const order = getTestERC1155Order({ + fees: [ + { + recipient: randomAddress(), + amount: getRandomInteger(0, MAX_UINT256), + feeData: hexUtils.random(), + }, + { + recipient: randomAddress(), + amount: getRandomInteger(0, MAX_UINT256), + feeData: hexUtils.random(), + }, + ], + erc1155TokenProperties: [ + { + propertyValidator: randomAddress(), + propertyData: hexUtils.random(), + }, + { + propertyValidator: randomAddress(), + propertyData: hexUtils.random(), + }, + ], + }); + const hash = await zeroEx.getERC1155OrderHash(order).callAsync(); + expect(hash).to.eq(order.getHash()); + }); + }); + + describe('validateERC1155OrderSignature', () => { + it('succeeds for a valid EthSign signature', async () => { + const order = getTestERC1155Order(); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await zeroEx.validateERC1155OrderSignature(order, signature).callAsync(); + }); + it('reverts for an invalid EthSign signature', async () => { + const order = getTestERC1155Order(); + const signature = await order.getSignatureWithProviderAsync( + env.provider, + SignatureType.EthSign, + otherMaker, + ); + const tx = zeroEx.validateERC1155OrderSignature(order, signature).callAsync(); + expect(tx).to.revertWith(new RevertErrors.NFTOrders.InvalidSignerError(maker, otherMaker)); + }); + it('succeeds for a valid EIP-712 signature', async () => { + const order = getTestERC1155Order(); + const signature = await order.getSignatureWithProviderAsync(env.provider, SignatureType.EIP712); + await zeroEx.validateERC1155OrderSignature(order, signature).callAsync(); + }); + it('reverts for an invalid EIP-712 signature', async () => { + const order = getTestERC1155Order(); + const signature = await order.getSignatureWithProviderAsync(env.provider, SignatureType.EIP712, otherMaker); + const tx = zeroEx.validateERC1155OrderSignature(order, signature).callAsync(); + expect(tx).to.revertWith(new RevertErrors.NFTOrders.InvalidSignerError(maker, otherMaker)); + }); + }); + + describe('cancelERC1155Order', () => { + it('can cancel an order', async () => { + const order = getTestERC1155Order(); + const tx = await zeroEx.cancelERC1155Order(order.nonce).awaitTransactionSuccessAsync({ + from: maker, + }); + verifyEventsFromLogs(tx.logs, [{ maker, nonce: order.nonce }], IZeroExEvents.ERC1155OrderCancelled); + const orderInfo = await zeroEx.getERC1155OrderInfo(order).callAsync(); + expect(orderInfo.status).to.equal(NFTOrder.OrderStatus.Unfillable); + }); + it('cancelling an order twice silently succeeds', async () => { + const order = getTestERC1155Order(); + await zeroEx.cancelERC1155Order(order.nonce).awaitTransactionSuccessAsync({ + from: maker, + }); + const tx = await zeroEx.cancelERC1155Order(order.nonce).awaitTransactionSuccessAsync({ + from: maker, + }); + verifyEventsFromLogs(tx.logs, [{ maker, nonce: order.nonce }], IZeroExEvents.ERC1155OrderCancelled); + const orderInfo = await zeroEx.getERC1155OrderInfo(order).callAsync(); + expect(orderInfo.status).to.equal(NFTOrder.OrderStatus.Unfillable); + }); + }); + + describe('sellERC1155', () => { + it('can fully fill a ERC1155 buy order', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = await zeroEx + .sellERC1155(order, signature, order.erc1155TokenId, order.erc1155TokenAmount, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + verifyEventsFromLogs(tx.logs, [createERC1155OrderFilledEvent(order)], IZeroExEvents.ERC1155OrderFilled); + const orderInfo = await zeroEx.getERC1155OrderInfo(order).callAsync(); + expect(orderInfo.status).to.equal(NFTOrder.OrderStatus.Unfillable); + }); + it('can partially fill a ERC1155 buy order', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + const erc1155FillAmount = BigNumber.max(getRandomPortion(order.erc1155TokenAmount.minus(1)), 1); + await mintAssetsAsync(order, order.erc1155TokenId, erc1155FillAmount); + await zeroEx + .sellERC1155(order, signature, order.erc1155TokenId, erc1155FillAmount, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order, order.erc1155TokenId, erc1155FillAmount); + const orderInfo = await zeroEx.getERC1155OrderInfo(order).callAsync(); + expect(orderInfo.status).to.equal(NFTOrder.OrderStatus.Fillable); + }); + it('cannot fill the same order twice', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + await zeroEx + .sellERC1155(order, signature, order.erc1155TokenId, order.erc1155TokenAmount, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + const tx = zeroEx + .sellERC1155(order, signature, order.erc1155TokenId, order.erc1155TokenAmount, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.OrderNotFillableError(maker, order.nonce, NFTOrder.OrderStatus.Unfillable), + ); + }); + it('cannot fill a cancelled order', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + await zeroEx.cancelERC1155Order(order.nonce).awaitTransactionSuccessAsync({ + from: maker, + }); + const tx = zeroEx + .sellERC1155(order, signature, order.erc1155TokenId, order.erc1155TokenAmount, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.OrderNotFillableError(maker, order.nonce, NFTOrder.OrderStatus.Unfillable), + ); + }); + it('cannot fill an invalid order (erc20Token == ETH)', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + erc20Token: ETH_TOKEN_ADDRESS, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await erc1155Token + .mint(taker, order.erc1155TokenId, order.erc1155TokenAmount) + .awaitTransactionSuccessAsync(); + const tx = zeroEx + .sellERC1155(order, signature, order.erc1155TokenId, order.erc1155TokenAmount, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith('NFTOrders::_validateBuyOrder/NATIVE_TOKEN_NOT_ALLOWED'); + }); + it('cannot fill an expired order', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + expiry: new BigNumber(Math.floor(Date.now() / 1000 - 1)), + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = zeroEx + .sellERC1155(order, signature, order.erc1155TokenId, order.erc1155TokenAmount, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.OrderNotFillableError(maker, order.nonce, NFTOrder.OrderStatus.Expired), + ); + }); + it('reverts if a sell order is provided', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = zeroEx + .sellERC1155(order, signature, order.erc1155TokenId, order.erc1155TokenAmount, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith('NFTOrders::_validateBuyOrder/WRONG_TRADE_DIRECTION'); + }); + it('reverts if the taker is not the taker address specified in the order', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + taker, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order, order.erc1155TokenId, order.erc1155TokenAmount, otherTaker); + const tx = zeroEx + .sellERC1155(order, signature, order.erc1155TokenId, order.erc1155TokenAmount, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: otherTaker, + }); + return expect(tx).to.revertWith(new RevertErrors.NFTOrders.OnlyTakerError(otherTaker, taker)); + }); + it('succeeds if the taker is the taker address specified in the order', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + taker, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + await zeroEx + .sellERC1155(order, signature, order.erc1155TokenId, order.erc1155TokenAmount, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + }); + it('reverts if an invalid signature is provided', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider, SignatureType.EIP712, otherMaker); + await mintAssetsAsync(order); + const tx = zeroEx + .sellERC1155(order, signature, order.erc1155TokenId, order.erc1155TokenAmount, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith(new RevertErrors.NFTOrders.InvalidSignerError(maker, otherMaker)); + }); + it('reverts if `unwrapNativeToken` is true and `erc20Token` is not WETH', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = zeroEx + .sellERC1155(order, signature, order.erc1155TokenId, order.erc1155TokenAmount, true, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.ERC20TokenMismatchError(order.erc20Token, weth.address), + ); + }); + it('sends ETH to taker if `unwrapNativeToken` is true and `erc20Token` is WETH', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + erc20Token: weth.address, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const takerEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(taker); + await zeroEx + .sellERC1155(order, signature, order.erc1155TokenId, order.erc1155TokenAmount, true, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + const takerEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(taker); + expect(takerEthBalanceAfter.minus(takerEthBalanceBefore)).to.bignumber.equal(order.erc20TokenAmount); + const makerBalance = await erc1155Token.balanceOf(maker, order.erc1155TokenId).callAsync(); + expect(makerBalance).to.bignumber.equal(order.erc1155TokenAmount); + }); + describe('fees', () => { + it('single fee to EOA', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + fees: [ + { + recipient: otherMaker, + amount: new BigNumber(111), + feeData: constants.NULL_BYTES, + }, + ], + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + await zeroEx + .sellERC1155(order, signature, order.erc1155TokenId, order.erc1155TokenAmount, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + }); + it('partial fill, single fee', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + fees: [ + { + recipient: otherMaker, + amount: getRandomInteger('1e18', '10e18'), + feeData: constants.NULL_BYTES, + }, + ], + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + const erc1155FillAmount = BigNumber.max(getRandomPortion(order.erc1155TokenAmount.minus(1)), 1); + await mintAssetsAsync(order, order.erc1155TokenId, erc1155FillAmount); + await zeroEx + .sellERC1155(order, signature, order.erc1155TokenId, erc1155FillAmount, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order, order.erc1155TokenId, erc1155FillAmount); + }); + it('single fee, successful callback', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + fees: [ + { + recipient: feeRecipient.address, + amount: new BigNumber(111), + feeData: hexUtils.random(), + }, + ], + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + await zeroEx + .sellERC1155(order, signature, order.erc1155TokenId, order.erc1155TokenAmount, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + }); + it('single fee, callback reverts', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + fees: [ + { + recipient: feeRecipient.address, + amount: new BigNumber(333), + feeData: hexUtils.random(), + }, + ], + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = zeroEx + .sellERC1155(order, signature, order.erc1155TokenId, order.erc1155TokenAmount, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith('TestFeeRecipient::receiveZeroExFeeCallback/REVERT'); + }); + it('single fee, callback returns invalid value', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + fees: [ + { + recipient: feeRecipient.address, + amount: new BigNumber(666), + feeData: hexUtils.random(), + }, + ], + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = zeroEx + .sellERC1155(order, signature, order.erc1155TokenId, order.erc1155TokenAmount, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith('NFTOrders::_payFees/CALLBACK_FAILED'); + }); + it('multiple fees to EOAs', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + fees: [ + { + recipient: otherMaker, + amount: new BigNumber(111), + feeData: constants.NULL_BYTES, + }, + { + recipient: otherTaker, + amount: new BigNumber(222), + feeData: constants.NULL_BYTES, + }, + ], + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + await zeroEx + .sellERC1155(order, signature, order.erc1155TokenId, order.erc1155TokenAmount, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + }); + }); + describe('properties', () => { + let propertyValidator: TestPropertyValidatorContract; + + before(async () => { + propertyValidator = await TestPropertyValidatorContract.deployFrom0xArtifactAsync( + artifacts.TestPropertyValidator, + env.provider, + env.txDefaults, + artifacts, + ); + }); + it('Checks tokenId if no properties are provided', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order, order.erc1155TokenId.plus(1)); + const tx = zeroEx + .sellERC1155( + order, + signature, + order.erc1155TokenId.plus(1), + order.erc1155TokenAmount, + false, + NULL_BYTES, + ) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.TokenIdMismatchError(order.erc1155TokenId.plus(1), order.erc1155TokenId), + ); + }); + it('Null property', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + erc1155TokenId: ZERO, + erc1155TokenProperties: [ + { + propertyValidator: NULL_ADDRESS, + propertyData: NULL_BYTES, + }, + ], + }); + const tokenId = getRandomInteger(0, MAX_UINT256); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order, tokenId); + await zeroEx + .sellERC1155(order, signature, tokenId, order.erc1155TokenAmount, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order, tokenId); + }); + it('Reverts if property validation fails', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + erc1155TokenId: ZERO, + erc1155TokenProperties: [ + { + propertyValidator: propertyValidator.address, + propertyData: NULL_BYTES, + }, + ], + }); + const tokenId = getRandomInteger(0, MAX_UINT256); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order, tokenId); + const tx = zeroEx + .sellERC1155(order, signature, tokenId, order.erc1155TokenAmount, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.PropertyValidationFailedError( + propertyValidator.address, + order.erc1155Token, + tokenId, + NULL_BYTES, + new StringRevertError('TestPropertyValidator::validateProperty/REVERT').encode(), + ), + ); + }); + it('Successful property validation', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + erc1155TokenId: ZERO, + erc1155TokenProperties: [ + { + propertyValidator: propertyValidator.address, + propertyData: hexUtils.random(), + }, + ], + }); + const tokenId = getRandomInteger(0, MAX_UINT256); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order, tokenId); + await zeroEx + .sellERC1155(order, signature, tokenId, order.erc1155TokenAmount, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order, tokenId); + }); + }); + }); + describe('onERC1155Received', () => { + let dataEncoder: AbiEncoder.DataType; + before(() => { + dataEncoder = AbiEncoder.create( + [ + { + name: 'order', + type: 'tuple', + components: ERC1155Order.STRUCT_ABI, + }, + { + name: 'signature', + type: 'tuple', + components: SIGNATURE_ABI, + }, + { name: 'unwrapNativeToken', type: 'bool' }, + ], + [ + { + name: 'property', + type: 'tuple', + internalType: 'Property', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { name: 'propertyData', type: 'bytes' }, + ], + }, + { + name: 'fee', + type: 'tuple', + internalType: 'Fee', + components: [ + { name: 'recipient', type: 'address' }, + { name: 'amount', type: 'uint256' }, + { name: 'feeData', type: 'bytes' }, + ], + }, + ], + ); + }); + it('throws if data is not encoded correctly', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + await mintAssetsAsync(order); + const tx = erc1155Token + .safeTransferFrom( + taker, + zeroEx.address, + order.erc1155TokenId, + order.erc1155TokenAmount, + hexUtils.random(), + ) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.be.rejected(); + }); + it('reverts if msg.sender != order.erc1155Token', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = zeroEx + .onERC1155Received( + taker, + taker, + order.erc1155TokenId, + order.erc1155TokenAmount, + dataEncoder.encode({ + order, + signature, + unwrapNativeToken: false, + }), + ) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.ERC1155TokenMismatchError(taker, order.erc1155Token), + ); + }); + it('reverts if transferred tokenId does not match order.erc1155TokenId', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order, order.erc1155TokenId.plus(1)); + + const tx = erc1155Token + .safeTransferFrom( + taker, + zeroEx.address, + order.erc1155TokenId.plus(1), + order.erc1155TokenAmount, + dataEncoder.encode({ + order, + signature, + unwrapNativeToken: false, + }), + ) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.TokenIdMismatchError(order.erc1155TokenId.plus(1), order.erc1155TokenId), + ); + }); + it('can sell ERC1155 without approval', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + // revoke approval + await erc1155Token.setApprovalForAll(zeroEx.address, false).awaitTransactionSuccessAsync({ + from: taker, + }); + + await erc1155Token + .safeTransferFrom( + taker, + zeroEx.address, + order.erc1155TokenId, + order.erc1155TokenAmount, + dataEncoder.encode({ + order, + signature, + unwrapNativeToken: false, + }), + ) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + }); + }); + describe('buyERC1155', () => { + it('can fill a ERC1155 sell order', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = await zeroEx + .buyERC1155(order, signature, order.erc1155TokenAmount, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + verifyEventsFromLogs(tx.logs, [createERC1155OrderFilledEvent(order)], IZeroExEvents.ERC1155OrderFilled); + const orderInfo = await zeroEx.getERC1155OrderInfo(order).callAsync(); + expect(orderInfo.status).to.equal(NFTOrder.OrderStatus.Unfillable); + }); + it('can partially fill a ERC1155 sell order', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + const erc1155FillAmount = BigNumber.max(getRandomPortion(order.erc1155TokenAmount.minus(1)), 1); + await mintAssetsAsync(order, order.erc1155TokenId, erc1155FillAmount); + await zeroEx.buyERC1155(order, signature, erc1155FillAmount, NULL_BYTES).awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order, order.erc1155TokenId, erc1155FillAmount); + const orderInfo = await zeroEx.getERC1155OrderInfo(order).callAsync(); + expect(orderInfo.status).to.equal(NFTOrder.OrderStatus.Fillable); + }); + it('cannot fill the same order twice', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + await zeroEx + .buyERC1155(order, signature, order.erc1155TokenAmount, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + const tx = zeroEx + .buyERC1155(order, signature, order.erc1155TokenAmount, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.OrderNotFillableError(maker, order.nonce, NFTOrder.OrderStatus.Unfillable), + ); + }); + it('cannot fill a cancelled order', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + await zeroEx.cancelERC1155Order(order.nonce).awaitTransactionSuccessAsync({ + from: maker, + }); + const tx = zeroEx + .buyERC1155(order, signature, order.erc1155TokenAmount, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.OrderNotFillableError(maker, order.nonce, NFTOrder.OrderStatus.Unfillable), + ); + }); + it('cannot fill an expired order', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + expiry: new BigNumber(Math.floor(Date.now() / 1000 - 1)), + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = zeroEx + .buyERC1155(order, signature, order.erc1155TokenAmount, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.OrderNotFillableError(maker, order.nonce, NFTOrder.OrderStatus.Expired), + ); + }); + it('reverts if a buy order is provided', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = zeroEx + .buyERC1155(order, signature, order.erc1155TokenAmount, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith('NFTOrders::_validateSellOrder/WRONG_TRADE_DIRECTION'); + }); + it('reverts if the taker is not the taker address specified in the order', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + taker, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order, order.erc1155TokenId, order.erc1155TokenAmount, otherTaker); + const tx = zeroEx + .buyERC1155(order, signature, order.erc1155TokenAmount, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: otherTaker, + }); + return expect(tx).to.revertWith(new RevertErrors.NFTOrders.OnlyTakerError(otherTaker, taker)); + }); + it('succeeds if the taker is the taker address specified in the order', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + taker, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + await zeroEx + .buyERC1155(order, signature, order.erc1155TokenAmount, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + }); + it('reverts if an invalid signature is provided', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider, SignatureType.EIP712, otherMaker); + await mintAssetsAsync(order); + const tx = zeroEx + .buyERC1155(order, signature, order.erc1155TokenAmount, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith(new RevertErrors.NFTOrders.InvalidSignerError(maker, otherMaker)); + }); + describe('ETH', () => { + it('can fill an order with ETH (and refunds excess ETH)', async () => { + const order = getTestERC1155Order({ + erc20Token: ETH_TOKEN_ADDRESS, + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const takerEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(taker); + const makerEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(maker); + const tx = await zeroEx + .buyERC1155(order, signature, order.erc1155TokenAmount, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + value: order.erc20TokenAmount.plus(1), + }); + const takerEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(taker); + const makerEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(maker); + expect(takerEthBalanceBefore.minus(takerEthBalanceAfter)).to.bignumber.equal(order.erc20TokenAmount); + expect(makerEthBalanceAfter.minus(makerEthBalanceBefore)).to.bignumber.equal(order.erc20TokenAmount); + verifyEventsFromLogs( + tx.logs, + [ + { + operator: zeroEx.address, + from: maker, + to: taker, + id: order.erc1155TokenId, + value: order.erc1155TokenAmount, + }, + ], + 'TransferSingle', + ); + }); + it('can fill a WETH order with ETH', async () => { + const order = getTestERC1155Order({ + erc20Token: weth.address, + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await erc1155Token + .mint(maker, order.erc1155TokenId, order.erc1155TokenAmount) + .awaitTransactionSuccessAsync(); + const takerEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(taker); + await zeroEx + .buyERC1155(order, signature, order.erc1155TokenAmount, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + value: order.erc20TokenAmount, + }); + const takerEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(taker); + expect(takerEthBalanceBefore.minus(takerEthBalanceAfter)).to.bignumber.equal(order.erc20TokenAmount); + await assertBalancesAsync(order); + }); + it('uses WETH if not enough ETH to fill WETH order', async () => { + const order = getTestERC1155Order({ + erc20Token: weth.address, + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await weth.deposit().awaitTransactionSuccessAsync({ + from: taker, + value: order.erc20TokenAmount, + }); + await erc1155Token + .mint(maker, order.erc1155TokenId, order.erc1155TokenAmount) + .awaitTransactionSuccessAsync(); + const takerEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(taker); + await zeroEx + .buyERC1155(order, signature, order.erc1155TokenAmount, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + value: order.erc20TokenAmount.minus(1), + }); + const takerEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(taker); + expect(takerEthBalanceAfter).to.bignumber.equal(takerEthBalanceBefore); + await assertBalancesAsync(order); + }); + }); + describe('fees', () => { + it('single fee to EOA', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + fees: [ + { + recipient: otherMaker, + amount: new BigNumber(111), + feeData: constants.NULL_BYTES, + }, + ], + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + await zeroEx + .buyERC1155(order, signature, order.erc1155TokenAmount, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + }); + it('partial fill, single fee', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + fees: [ + { + recipient: otherMaker, + amount: getRandomInteger('1e18', '10e18'), + feeData: constants.NULL_BYTES, + }, + ], + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + const erc1155FillAmount = BigNumber.max(getRandomPortion(order.erc1155TokenAmount.minus(1)), 1); + await mintAssetsAsync(order, order.erc1155TokenId, erc1155FillAmount); + await zeroEx.buyERC1155(order, signature, erc1155FillAmount, NULL_BYTES).awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order, order.erc1155TokenId, erc1155FillAmount); + }); + it('pays fees in ETH if erc20Token == ETH', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: ETH_TOKEN_ADDRESS, + fees: [ + { + recipient: otherMaker, + amount: new BigNumber(111), + feeData: constants.NULL_BYTES, + }, + ], + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const takerEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(taker); + const makerEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(maker); + const feeRecipientEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(otherMaker); + await zeroEx + .buyERC1155(order, signature, order.erc1155TokenAmount, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + value: order.erc20TokenAmount.plus(order.fees[0].amount).plus(1), + }); + const takerEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(taker); + const makerEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(maker); + const feeRecipientEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(otherMaker); + expect(takerEthBalanceBefore.minus(takerEthBalanceAfter)).to.bignumber.equal( + order.erc20TokenAmount.plus(order.fees[0].amount), + ); + expect(makerEthBalanceAfter.minus(makerEthBalanceBefore)).to.bignumber.equal(order.erc20TokenAmount); + expect(feeRecipientEthBalanceAfter.minus(feeRecipientEthBalanceBefore)).to.bignumber.equal( + order.fees[0].amount, + ); + const takerBalance = await erc1155Token.balanceOf(taker, order.erc1155TokenId).callAsync(); + expect(takerBalance).to.bignumber.equal(order.erc1155TokenAmount); + }); + it('pays fees in ETH if erc20Token == WETH but taker uses ETH', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: weth.address, + fees: [ + { + recipient: otherMaker, + amount: new BigNumber(111), + feeData: constants.NULL_BYTES, + }, + ], + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const takerEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(taker); + const feeRecipientEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(otherMaker); + const tx = await zeroEx + .buyERC1155(order, signature, order.erc1155TokenAmount, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + value: order.erc20TokenAmount.plus(order.fees[0].amount).plus(1), + }); + const takerEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(taker); + const feeRecipientEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(otherMaker); + expect(takerEthBalanceBefore.minus(takerEthBalanceAfter)).to.bignumber.equal( + order.erc20TokenAmount.plus(order.fees[0].amount), + ); + expect(feeRecipientEthBalanceAfter.minus(feeRecipientEthBalanceBefore)).to.bignumber.equal( + order.fees[0].amount, + ); + verifyEventsFromLogs( + tx.logs, + [ + { + token: weth.address, + from: zeroEx.address, + to: maker, + value: order.erc20TokenAmount, + }, + ], + 'Transfer', + ); + verifyEventsFromLogs( + tx.logs, + [ + { + operator: zeroEx.address, + from: maker, + to: taker, + id: order.erc1155TokenId, + value: order.erc1155TokenAmount, + }, + ], + 'TransferSingle', + ); + }); + it('pays fees in WETH if taker uses WETH', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: weth.address, + fees: [ + { + recipient: otherMaker, + amount: new BigNumber(111), + feeData: constants.NULL_BYTES, + }, + ], + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await erc1155Token + .mint(maker, order.erc1155TokenId, order.erc1155TokenAmount) + .awaitTransactionSuccessAsync(); + await weth.deposit().awaitTransactionSuccessAsync({ + from: taker, + value: order.erc20TokenAmount.plus(order.fees[0].amount), + }); + await zeroEx + .buyERC1155(order, signature, order.erc1155TokenAmount, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + }); + it('reverts if overspent ETH', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: ETH_TOKEN_ADDRESS, + fees: [ + { + recipient: otherMaker, + amount: new BigNumber(111), + feeData: constants.NULL_BYTES, + }, + ], + }); + await sendEtherAsync(zeroEx.address, order.fees[0].amount); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = zeroEx + .buyERC1155(order, signature, order.erc1155TokenAmount, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + value: order.erc20TokenAmount, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.OverspentEthError( + order.erc20TokenAmount.plus(order.fees[0].amount), + order.erc20TokenAmount, + ), + ); + }); + }); + }); + describe('batchBuyERC1155s', () => { + it('reverts if arrays are different lengths', async () => { + const order = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = zeroEx + .batchBuyERC1155s( + [order], + [signature, signature], + [order.erc1155TokenAmount, order.erc1155TokenAmount], + [NULL_BYTES, NULL_BYTES], + false, + ) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith('ERC1155OrdersFeature::batchBuyERC1155s/ARRAY_LENGTH_MISMATCH'); + }); + it('successfully fills multiple orders', async () => { + const order1 = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature1 = await order1.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order1); + const order2 = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: weth.address, + }); + const signature2 = await order2.getSignatureWithProviderAsync(env.provider); + await erc1155Token + .mint(maker, order2.erc1155TokenId, order2.erc1155TokenAmount) + .awaitTransactionSuccessAsync(); + await weth.deposit().sendTransactionAsync({ + from: taker, + value: order2.erc20TokenAmount, + }); + await zeroEx + .batchBuyERC1155s( + [order1, order2], + [signature1, signature2], + [order1.erc1155TokenAmount, order2.erc1155TokenAmount], + [NULL_BYTES, NULL_BYTES], + false, + ) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order1); + await assertBalancesAsync(order2); + }); + it('catches revert if one order fails', async () => { + const order1 = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature1 = await order1.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order1); + const order2 = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: weth.address, + }); + // invalid signature + const signature2 = await order2.getSignatureWithProviderAsync( + env.provider, + SignatureType.EIP712, + otherMaker, + ); + await erc1155Token + .mint(maker, order2.erc1155TokenId, order2.erc1155TokenAmount) + .awaitTransactionSuccessAsync(); + await weth.deposit().sendTransactionAsync({ + from: taker, + value: order2.erc20TokenAmount, + }); + const tx = zeroEx.batchBuyERC1155s( + [order1, order2], + [signature1, signature2], + [order1.erc1155TokenAmount, order2.erc1155TokenAmount], + [NULL_BYTES, NULL_BYTES], + false, + ); + const successes = await tx.callAsync({ + from: taker, + }); + expect(successes).to.deep.equal([true, false]); + await tx.awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order1); + const makerBalance = await erc1155Token.balanceOf(maker, order2.erc1155TokenId).callAsync(); + expect(makerBalance).to.bignumber.equal(order2.erc1155TokenAmount); + const takerWethBalance = await weth.balanceOf(taker).callAsync(); + expect(takerWethBalance).to.bignumber.equal(order2.erc20TokenAmount); + }); + it('bubbles up revert if one order fails and `revertIfIncomplete == true`', async () => { + const order1 = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature1 = await order1.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order1); + const order2 = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: weth.address, + }); + // invalid signature + const signature2 = await order2.getSignatureWithProviderAsync( + env.provider, + SignatureType.EIP712, + otherMaker, + ); + await erc1155Token + .mint(maker, order2.erc1155TokenId, order2.erc1155TokenAmount) + .awaitTransactionSuccessAsync(); + await weth.deposit().sendTransactionAsync({ + from: taker, + value: order2.erc20TokenAmount, + }); + const tx = zeroEx + .batchBuyERC1155s( + [order1, order2], + [signature1, signature2], + [order1.erc1155TokenAmount, order2.erc1155TokenAmount], + [NULL_BYTES, NULL_BYTES], + true, + ) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith(new RevertErrors.NFTOrders.InvalidSignerError(order2.maker, otherMaker)); + }); + it('can fill multiple orders with ETH, refund excess ETH', async () => { + const order1 = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: ETH_TOKEN_ADDRESS, + }); + const signature1 = await order1.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order1); + const order2 = getTestERC1155Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: weth.address, + }); + const signature2 = await order2.getSignatureWithProviderAsync(env.provider); + await erc1155Token + .mint(maker, order2.erc1155TokenId, order2.erc1155TokenAmount) + .awaitTransactionSuccessAsync(); + const takerEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(taker); + await zeroEx + .batchBuyERC1155s( + [order1, order2], + [signature1, signature2], + [order1.erc1155TokenAmount, order2.erc1155TokenAmount], + [NULL_BYTES, NULL_BYTES], + true, + ) + .awaitTransactionSuccessAsync({ + from: taker, + value: order1.erc20TokenAmount.plus(order2.erc20TokenAmount).plus(1), + }); + const takerEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(taker); + expect(takerEthBalanceBefore.minus(takerEthBalanceAfter)).to.bignumber.equal( + order1.erc20TokenAmount.plus(order2.erc20TokenAmount), + ); + const takerBalance1 = await erc1155Token.balanceOf(taker, order1.erc1155TokenId).callAsync(); + expect(takerBalance1).to.bignumber.equal(order1.erc1155TokenAmount); + const takerBalance2 = await erc1155Token.balanceOf(taker, order2.erc1155TokenId).callAsync(); + expect(takerBalance2).to.bignumber.equal(order2.erc1155TokenAmount); + }); + }); + describe('preSignERC1155Order', () => { + const PRESIGN_SIGNATURE = { + signatureType: SignatureType.PreSigned, + v: 0, + r: constants.NULL_BYTES32, + s: constants.NULL_BYTES32, + }; + let contractMaker: TestNFTOrderPresignerContract; + before(async () => { + contractMaker = await TestNFTOrderPresignerContract.deployFrom0xArtifactAsync( + artifacts.TestNFTOrderPresigner, + env.provider, + env.txDefaults, + artifacts, + zeroEx.address, + ); + await contractMaker.approveERC20(erc20Token.address).awaitTransactionSuccessAsync(); + await contractMaker.approveERC1155(erc1155Token.address).awaitTransactionSuccessAsync(); + }); + it('can fill order that has been presigned by the maker', async () => { + const order = getTestERC1155Order({ + maker: contractMaker.address, + direction: NFTOrder.TradeDirection.BuyNFT, + }); + await mintAssetsAsync(order); + await contractMaker.preSignERC1155Order(order).awaitTransactionSuccessAsync(); + await zeroEx + .sellERC1155( + order, + PRESIGN_SIGNATURE, + order.erc1155TokenId, + order.erc1155TokenAmount, + false, + NULL_BYTES, + ) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + }); + it('cannot fill order that has not been presigned by the maker', async () => { + const order = getTestERC1155Order({ + maker: contractMaker.address, + direction: NFTOrder.TradeDirection.BuyNFT, + }); + await mintAssetsAsync(order); + const tx = zeroEx + .sellERC1155( + order, + PRESIGN_SIGNATURE, + order.erc1155TokenId, + order.erc1155TokenAmount, + false, + NULL_BYTES, + ) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.InvalidSignerError(contractMaker.address, NULL_ADDRESS), + ); + }); + it('cannot fill order that was presigned then cancelled', async () => { + const order = getTestERC1155Order({ + maker: contractMaker.address, + direction: NFTOrder.TradeDirection.BuyNFT, + }); + await mintAssetsAsync(order); + await contractMaker.preSignERC1155Order(order).awaitTransactionSuccessAsync(); + await contractMaker.cancelERC1155Order(order.nonce).awaitTransactionSuccessAsync(); + const tx = zeroEx + .sellERC1155( + order, + PRESIGN_SIGNATURE, + order.erc1155TokenId, + order.erc1155TokenAmount, + false, + NULL_BYTES, + ) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.OrderNotFillableError( + contractMaker.address, + order.nonce, + NFTOrder.OrderStatus.Unfillable, + ), + ); + }); + it('only maker can presign order', async () => { + const order = getTestERC1155Order({ + maker: otherMaker, + direction: NFTOrder.TradeDirection.BuyNFT, + }); + await mintAssetsAsync(order); + const tx = contractMaker.preSignERC1155Order(order).awaitTransactionSuccessAsync(); + return expect(tx).to.revertWith('ERC1155OrdersFeature::preSignERC1155Order/MAKER_MISMATCH'); + }); + }); +}); diff --git a/contracts/zero-ex/test/features/erc721_orders_test.ts b/contracts/zero-ex/test/features/erc721_orders_test.ts new file mode 100644 index 0000000000..5be29f0420 --- /dev/null +++ b/contracts/zero-ex/test/features/erc721_orders_test.ts @@ -0,0 +1,1731 @@ +import { + blockchainTests, + constants, + describe, + expect, + getRandomInteger, + randomAddress, + verifyEventsFromLogs, +} from '@0x/contracts-test-utils'; +import { ERC721Order, NFTOrder, RevertErrors, SIGNATURE_ABI, SignatureType } from '@0x/protocol-utils'; +import { AbiEncoder, BigNumber, hexUtils, NULL_BYTES, StringRevertError } from '@0x/utils'; + +import { + IOwnableFeatureContract, + IZeroExContract, + IZeroExERC721OrderFilledEventArgs, + IZeroExEvents, +} from '../../src/wrappers'; +import { artifacts } from '../artifacts'; +import { abis } from '../utils/abis'; +import { fullMigrateAsync } from '../utils/migration'; +import { getRandomERC721Order } from '../utils/nft_orders'; + +import { + ERC721OrdersFeatureContract, + TestFeeRecipientContract, + TestMintableERC20TokenContract, + TestMintableERC721TokenContract, + TestNFTOrderPresignerContract, + TestPropertyValidatorContract, + TestWethContract, +} from '../wrappers'; + +blockchainTests.resets('ERC721OrdersFeature', env => { + const { NULL_ADDRESS, MAX_UINT256, ZERO_AMOUNT: ZERO } = constants; + const ETH_TOKEN_ADDRESS = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'; + + let owner: string; + let maker: string; + let taker: string; + let otherMaker: string; + let otherTaker: string; + let matcher: string; + let feeRecipient: TestFeeRecipientContract; + let zeroEx: IZeroExContract; + let weth: TestWethContract; + let erc20Token: TestMintableERC20TokenContract; + let erc721Token: TestMintableERC721TokenContract; + + async function sendEtherAsync(to: string, amount: BigNumber): Promise { + await env.web3Wrapper.awaitTransactionSuccessAsync( + await env.web3Wrapper.sendTransactionAsync({ + ...env.txDefaults, + to, + from: owner, + value: amount, + }), + ); + } + + before(async () => { + // Useful for ETH balance accounting + const txDefaults = { ...env.txDefaults, gasPrice: 0 }; + [owner, maker, taker, otherMaker, otherTaker, matcher] = await env.getAccountAddressesAsync(); + + weth = await TestWethContract.deployFrom0xArtifactAsync( + artifacts.TestWeth, + env.provider, + txDefaults, + artifacts, + ); + erc20Token = await TestMintableERC20TokenContract.deployFrom0xArtifactAsync( + artifacts.TestMintableERC20Token, + env.provider, + txDefaults, + artifacts, + ); + erc721Token = await TestMintableERC721TokenContract.deployFrom0xArtifactAsync( + artifacts.TestMintableERC721Token, + env.provider, + txDefaults, + artifacts, + ); + + zeroEx = await fullMigrateAsync(owner, env.provider, txDefaults, {}, { wethAddress: weth.address }); + zeroEx = new IZeroExContract(zeroEx.address, env.provider, txDefaults, abis); + + const featureImpl = await ERC721OrdersFeatureContract.deployFrom0xArtifactAsync( + artifacts.ERC721OrdersFeature, + env.provider, + txDefaults, + artifacts, + zeroEx.address, + weth.address, + ); + await new IOwnableFeatureContract(zeroEx.address, env.provider, txDefaults, abis) + .migrate(featureImpl.address, featureImpl.migrate().getABIEncodedTransactionData(), owner) + .awaitTransactionSuccessAsync(); + + await Promise.all([ + erc20Token.approve(zeroEx.address, MAX_UINT256).awaitTransactionSuccessAsync({ + from: maker, + }), + erc20Token.approve(zeroEx.address, MAX_UINT256).awaitTransactionSuccessAsync({ + from: otherMaker, + }), + erc20Token.approve(zeroEx.address, MAX_UINT256).awaitTransactionSuccessAsync({ + from: taker, + }), + erc20Token.approve(zeroEx.address, MAX_UINT256).awaitTransactionSuccessAsync({ + from: otherTaker, + }), + weth.approve(zeroEx.address, MAX_UINT256).awaitTransactionSuccessAsync({ + from: maker, + }), + weth.approve(zeroEx.address, MAX_UINT256).awaitTransactionSuccessAsync({ + from: otherMaker, + }), + weth.approve(zeroEx.address, MAX_UINT256).awaitTransactionSuccessAsync({ + from: taker, + }), + weth.approve(zeroEx.address, MAX_UINT256).awaitTransactionSuccessAsync({ + from: otherTaker, + }), + erc721Token.setApprovalForAll(zeroEx.address, true).awaitTransactionSuccessAsync({ + from: maker, + }), + erc721Token.setApprovalForAll(zeroEx.address, true).awaitTransactionSuccessAsync({ + from: otherMaker, + }), + erc721Token.setApprovalForAll(zeroEx.address, true).awaitTransactionSuccessAsync({ + from: taker, + }), + erc721Token.setApprovalForAll(zeroEx.address, true).awaitTransactionSuccessAsync({ + from: otherTaker, + }), + ]); + + feeRecipient = await TestFeeRecipientContract.deployFrom0xArtifactAsync( + artifacts.TestFeeRecipient, + env.provider, + txDefaults, + artifacts, + ); + }); + + async function mintAssetsAsync( + order: ERC721Order, + tokenId: BigNumber = order.erc721TokenId, + _taker: string = taker, + ): Promise { + const totalFeeAmount = order.fees.length > 0 ? BigNumber.sum(...order.fees.map(fee => fee.amount)) : ZERO; + if (order.direction === NFTOrder.TradeDirection.SellNFT) { + await erc721Token.mint(order.maker, tokenId).awaitTransactionSuccessAsync(); + if (order.erc20Token !== ETH_TOKEN_ADDRESS) { + await erc20Token + .mint(_taker, order.erc20TokenAmount.plus(totalFeeAmount)) + .awaitTransactionSuccessAsync(); + } + } else { + await erc721Token.mint(_taker, tokenId).awaitTransactionSuccessAsync(); + if (order.erc20Token === weth.address) { + await weth.deposit().awaitTransactionSuccessAsync({ + from: order.maker, + value: order.erc20TokenAmount.plus(totalFeeAmount), + }); + } else { + await erc20Token + .mint(order.maker, order.erc20TokenAmount.plus(totalFeeAmount)) + .awaitTransactionSuccessAsync(); + } + } + } + + async function assertBalancesAsync( + order: ERC721Order, + tokenId: BigNumber = order.erc721TokenId, + _taker: string = taker, + ): Promise { + const token = order.erc20Token === weth.address ? weth : erc20Token; + if (order.direction === NFTOrder.TradeDirection.SellNFT) { + const makerBalance = await token.balanceOf(order.maker).callAsync(); + expect(makerBalance).to.bignumber.equal(order.erc20TokenAmount); + const erc721Owner = await erc721Token.ownerOf(tokenId).callAsync(); + expect(erc721Owner).to.equal(_taker); + } else { + const erc20Balance = await token.balanceOf(_taker).callAsync(); + expect(erc20Balance).to.bignumber.equal(order.erc20TokenAmount); + const erc721Owner = await erc721Token.ownerOf(tokenId).callAsync(); + expect(erc721Owner).to.equal(order.maker); + } + if (order.fees.length > 0) { + await Promise.all( + order.fees.map(async fee => { + const feeRecipientBalance = await token.balanceOf(fee.recipient).callAsync(); + expect(feeRecipientBalance).to.bignumber.equal(fee.amount); + }), + ); + } + } + + function getTestERC721Order(fields: Partial = {}): ERC721Order { + return getRandomERC721Order({ + maker, + verifyingContract: zeroEx.address, + chainId: 1337, + erc20Token: erc20Token.address, + erc721Token: erc721Token.address, + taker: NULL_ADDRESS, + ...fields, + }); + } + + function createERC721OrderFilledEvent( + order: ERC721Order, + _taker: string = taker, + erc721TokenId: BigNumber = order.erc721TokenId, + ): IZeroExERC721OrderFilledEventArgs { + return { + direction: order.direction, + maker: order.maker, + taker, + nonce: order.nonce, + erc20Token: order.erc20Token, + erc20TokenAmount: order.erc20TokenAmount, + erc721Token: order.erc721Token, + erc721TokenId, + matcher: NULL_ADDRESS, + }; + } + + describe('getERC721OrderHash()', () => { + it('returns the correct hash for order with no fees or properties', async () => { + const order = getTestERC721Order(); + const hash = await zeroEx.getERC721OrderHash(order).callAsync(); + expect(hash).to.eq(order.getHash()); + }); + it('returns the correct hash for order with null property', async () => { + const order = getTestERC721Order({ + erc721TokenProperties: [ + { + propertyValidator: NULL_ADDRESS, + propertyData: NULL_BYTES, + }, + ], + }); + const hash = await zeroEx.getERC721OrderHash(order).callAsync(); + expect(hash).to.eq(order.getHash()); + }); + it('returns the correct hash for order with 1 fee, 1 property', async () => { + const order = getTestERC721Order({ + fees: [ + { + recipient: randomAddress(), + amount: getRandomInteger(0, MAX_UINT256), + feeData: hexUtils.random(), + }, + ], + erc721TokenProperties: [ + { + propertyValidator: randomAddress(), + propertyData: hexUtils.random(), + }, + ], + }); + const hash = await zeroEx.getERC721OrderHash(order).callAsync(); + expect(hash).to.eq(order.getHash()); + }); + it('returns the correct hash for order with 2 fees, 2 properties', async () => { + const order = getTestERC721Order({ + fees: [ + { + recipient: randomAddress(), + amount: getRandomInteger(0, MAX_UINT256), + feeData: hexUtils.random(), + }, + { + recipient: randomAddress(), + amount: getRandomInteger(0, MAX_UINT256), + feeData: hexUtils.random(), + }, + ], + erc721TokenProperties: [ + { + propertyValidator: randomAddress(), + propertyData: hexUtils.random(), + }, + { + propertyValidator: randomAddress(), + propertyData: hexUtils.random(), + }, + ], + }); + const hash = await zeroEx.getERC721OrderHash(order).callAsync(); + expect(hash).to.eq(order.getHash()); + }); + }); + + describe('validateERC721OrderSignature', () => { + it('succeeds for a valid EthSign signature', async () => { + const order = getTestERC721Order(); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await zeroEx.validateERC721OrderSignature(order, signature).callAsync(); + }); + it('reverts for an invalid EthSign signature', async () => { + const order = getTestERC721Order(); + const signature = await order.getSignatureWithProviderAsync( + env.provider, + SignatureType.EthSign, + otherMaker, + ); + const tx = zeroEx.validateERC721OrderSignature(order, signature).callAsync(); + expect(tx).to.revertWith(new RevertErrors.NFTOrders.InvalidSignerError(maker, otherMaker)); + }); + it('succeeds for a valid EIP-712 signature', async () => { + const order = getTestERC721Order(); + const signature = await order.getSignatureWithProviderAsync(env.provider, SignatureType.EIP712); + await zeroEx.validateERC721OrderSignature(order, signature).callAsync(); + }); + it('reverts for an invalid EIP-712 signature', async () => { + const order = getTestERC721Order(); + const signature = await order.getSignatureWithProviderAsync(env.provider, SignatureType.EIP712, otherMaker); + const tx = zeroEx.validateERC721OrderSignature(order, signature).callAsync(); + expect(tx).to.revertWith(new RevertErrors.NFTOrders.InvalidSignerError(maker, otherMaker)); + }); + }); + + describe('cancelERC721Order', () => { + it('can cancel an order', async () => { + const order = getTestERC721Order(); + const tx = await zeroEx.cancelERC721Order(order.nonce).awaitTransactionSuccessAsync({ + from: maker, + }); + verifyEventsFromLogs(tx.logs, [{ maker, nonce: order.nonce }], IZeroExEvents.ERC721OrderCancelled); + const orderStatus = await zeroEx.getERC721OrderStatus(order).callAsync(); + expect(orderStatus).to.equal(NFTOrder.OrderStatus.Unfillable); + const bitVector = await zeroEx + .getERC721OrderStatusBitVector(maker, order.nonce.dividedToIntegerBy(256)) + .callAsync(); + const flag = new BigNumber(2).exponentiatedBy(order.nonce.mod(256)); + expect(bitVector).to.bignumber.equal(flag); + }); + it('cancelling an order twice silently succeeds', async () => { + const order = getTestERC721Order(); + await zeroEx.cancelERC721Order(order.nonce).awaitTransactionSuccessAsync({ + from: maker, + }); + const tx = await zeroEx.cancelERC721Order(order.nonce).awaitTransactionSuccessAsync({ + from: maker, + }); + verifyEventsFromLogs(tx.logs, [{ maker, nonce: order.nonce }], IZeroExEvents.ERC721OrderCancelled); + const orderStatus = await zeroEx.getERC721OrderStatus(order).callAsync(); + expect(orderStatus).to.equal(NFTOrder.OrderStatus.Unfillable); + const bitVector = await zeroEx + .getERC721OrderStatusBitVector(maker, order.nonce.dividedToIntegerBy(256)) + .callAsync(); + const flag = new BigNumber(2).exponentiatedBy(order.nonce.mod(256)); + expect(bitVector).to.bignumber.equal(flag); + }); + }); + + describe('sellERC721', () => { + it('can fill a ERC721 buy order', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = await zeroEx + .sellERC721(order, signature, order.erc721TokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + verifyEventsFromLogs(tx.logs, [createERC721OrderFilledEvent(order)], IZeroExEvents.ERC721OrderFilled); + const bitVector = await zeroEx + .getERC721OrderStatusBitVector(maker, order.nonce.dividedToIntegerBy(256)) + .callAsync(); + const flag = new BigNumber(2).exponentiatedBy(order.nonce.mod(256)); + expect(bitVector).to.bignumber.equal(flag); + }); + it('cannot fill the same order twice', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + await zeroEx + .sellERC721(order, signature, order.erc721TokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + const tx = zeroEx + .sellERC721(order, signature, order.erc721TokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.OrderNotFillableError(maker, order.nonce, NFTOrder.OrderStatus.Unfillable), + ); + }); + it('can fill two orders from the same maker with different nonces', async () => { + const order1 = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + nonce: ZERO, + }); + const signature1 = await order1.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order1); + await zeroEx + .sellERC721(order1, signature1, order1.erc721TokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + const order2 = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + nonce: new BigNumber(1), + }); + const signature2 = await order2.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order2); + await zeroEx + .sellERC721(order2, signature2, order2.erc721TokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + const bitVector = await zeroEx.getERC721OrderStatusBitVector(maker, ZERO).callAsync(); + expect(bitVector).to.bignumber.equal(3); // 0...00011 + }); + it('cannot fill a cancelled order', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + await zeroEx.cancelERC721Order(order.nonce).awaitTransactionSuccessAsync({ + from: maker, + }); + const tx = zeroEx + .sellERC721(order, signature, order.erc721TokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.OrderNotFillableError(maker, order.nonce, NFTOrder.OrderStatus.Unfillable), + ); + }); + it('cannot fill an invalid order (erc20Token == ETH)', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + erc20Token: ETH_TOKEN_ADDRESS, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await erc721Token.mint(taker, order.erc721TokenId).awaitTransactionSuccessAsync(); + const tx = zeroEx + .sellERC721(order, signature, order.erc721TokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith('NFTOrders::_validateBuyOrder/NATIVE_TOKEN_NOT_ALLOWED'); + }); + it('cannot fill an expired order', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + expiry: new BigNumber(Math.floor(Date.now() / 1000 - 1)), + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = zeroEx + .sellERC721(order, signature, order.erc721TokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.OrderNotFillableError(maker, order.nonce, NFTOrder.OrderStatus.Expired), + ); + }); + it('reverts if a sell order is provided', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = zeroEx + .sellERC721(order, signature, order.erc721TokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith('NFTOrders::_validateBuyOrder/WRONG_TRADE_DIRECTION'); + }); + it('reverts if the taker is not the taker address specified in the order', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + taker, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order, order.erc721TokenId, otherTaker); + const tx = zeroEx + .sellERC721(order, signature, order.erc721TokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: otherTaker, + }); + return expect(tx).to.revertWith(new RevertErrors.NFTOrders.OnlyTakerError(otherTaker, taker)); + }); + it('succeeds if the taker is the taker address specified in the order', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + taker, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + await zeroEx + .sellERC721(order, signature, order.erc721TokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + }); + it('reverts if an invalid signature is provided', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider, SignatureType.EIP712, otherMaker); + await mintAssetsAsync(order); + const tx = zeroEx + .sellERC721(order, signature, order.erc721TokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith(new RevertErrors.NFTOrders.InvalidSignerError(maker, otherMaker)); + }); + it('reverts if `unwrapNativeToken` is true and `erc20Token` is not WETH', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = zeroEx + .sellERC721(order, signature, order.erc721TokenId, true, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.ERC20TokenMismatchError(order.erc20Token, weth.address), + ); + }); + it('sends ETH to taker if `unwrapNativeToken` is true and `erc20Token` is WETH', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + erc20Token: weth.address, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const takerEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(taker); + await zeroEx + .sellERC721(order, signature, order.erc721TokenId, true, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + const takerEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(taker); + expect(takerEthBalanceAfter.minus(takerEthBalanceBefore)).to.bignumber.equal(order.erc20TokenAmount); + const erc721Owner = await erc721Token.ownerOf(order.erc721TokenId).callAsync(); + expect(erc721Owner).to.equal(maker); + }); + describe('fees', () => { + it('single fee to EOA', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + fees: [ + { + recipient: otherMaker, + amount: new BigNumber(111), + feeData: constants.NULL_BYTES, + }, + ], + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + await zeroEx + .sellERC721(order, signature, order.erc721TokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + }); + it('single fee, successful callback', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + fees: [ + { + recipient: feeRecipient.address, + amount: new BigNumber(111), + feeData: hexUtils.random(), + }, + ], + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + await zeroEx + .sellERC721(order, signature, order.erc721TokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + }); + it('single fee, callback reverts', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + fees: [ + { + recipient: feeRecipient.address, + amount: new BigNumber(333), + feeData: hexUtils.random(), + }, + ], + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = zeroEx + .sellERC721(order, signature, order.erc721TokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith('TestFeeRecipient::receiveZeroExFeeCallback/REVERT'); + }); + it('single fee, callback returns invalid value', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + fees: [ + { + recipient: feeRecipient.address, + amount: new BigNumber(666), + feeData: hexUtils.random(), + }, + ], + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = zeroEx + .sellERC721(order, signature, order.erc721TokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith('NFTOrders::_payFees/CALLBACK_FAILED'); + }); + it('multiple fees to EOAs', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + fees: [ + { + recipient: otherMaker, + amount: new BigNumber(111), + feeData: constants.NULL_BYTES, + }, + { + recipient: otherTaker, + amount: new BigNumber(222), + feeData: constants.NULL_BYTES, + }, + ], + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + await zeroEx + .sellERC721(order, signature, order.erc721TokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + }); + }); + describe('properties', () => { + let propertyValidator: TestPropertyValidatorContract; + + before(async () => { + propertyValidator = await TestPropertyValidatorContract.deployFrom0xArtifactAsync( + artifacts.TestPropertyValidator, + env.provider, + env.txDefaults, + artifacts, + ); + }); + it('Checks tokenId if no properties are provided', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order, order.erc721TokenId.plus(1)); + const tx = zeroEx + .sellERC721(order, signature, order.erc721TokenId.plus(1), false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.TokenIdMismatchError(order.erc721TokenId.plus(1), order.erc721TokenId), + ); + }); + it('Null property', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + erc721TokenId: ZERO, + erc721TokenProperties: [ + { + propertyValidator: NULL_ADDRESS, + propertyData: NULL_BYTES, + }, + ], + }); + const tokenId = getRandomInteger(0, MAX_UINT256); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order, tokenId); + await zeroEx.sellERC721(order, signature, tokenId, false, NULL_BYTES).awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order, tokenId); + }); + it('Reverts if property validation fails', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + erc721TokenId: ZERO, + erc721TokenProperties: [ + { + propertyValidator: propertyValidator.address, + propertyData: NULL_BYTES, + }, + ], + }); + const tokenId = getRandomInteger(0, MAX_UINT256); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order, tokenId); + const tx = zeroEx + .sellERC721(order, signature, tokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.PropertyValidationFailedError( + propertyValidator.address, + order.erc721Token, + tokenId, + NULL_BYTES, + new StringRevertError('TestPropertyValidator::validateProperty/REVERT').encode(), + ), + ); + }); + it('Successful property validation', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + erc721TokenId: ZERO, + erc721TokenProperties: [ + { + propertyValidator: propertyValidator.address, + propertyData: hexUtils.random(), + }, + ], + }); + const tokenId = getRandomInteger(0, MAX_UINT256); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order, tokenId); + await zeroEx.sellERC721(order, signature, tokenId, false, NULL_BYTES).awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order, tokenId); + }); + }); + }); + describe('onERC721Received', () => { + let dataEncoder: AbiEncoder.DataType; + before(() => { + dataEncoder = AbiEncoder.create( + [ + { + name: 'order', + type: 'tuple', + components: ERC721Order.STRUCT_ABI, + }, + { + name: 'signature', + type: 'tuple', + components: SIGNATURE_ABI, + }, + { name: 'unwrapNativeToken', type: 'bool' }, + ], + [ + { + name: 'property', + type: 'tuple', + internalType: 'Property', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { name: 'propertyData', type: 'bytes' }, + ], + }, + { + name: 'fee', + type: 'tuple', + internalType: 'Fee', + components: [ + { name: 'recipient', type: 'address' }, + { name: 'amount', type: 'uint256' }, + { name: 'feeData', type: 'bytes' }, + ], + }, + ], + ); + }); + it('throws if data is not encoded correctly', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + await mintAssetsAsync(order); + const tx = erc721Token + .safeTransferFrom2(taker, zeroEx.address, order.erc721TokenId, hexUtils.random()) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.be.rejected(); + }); + it('reverts if msg.sender != order.erc721Token', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = zeroEx + .onERC721Received( + taker, + taker, + order.erc721TokenId, + dataEncoder.encode({ + order, + signature, + unwrapNativeToken: false, + }), + ) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.ERC721TokenMismatchError(taker, order.erc721Token), + ); + }); + it('reverts if transferred tokenId does not match order.erc721TokenId', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order, order.erc721TokenId.plus(1)); + + const tx = erc721Token + .safeTransferFrom2( + taker, + zeroEx.address, + order.erc721TokenId.plus(1), + dataEncoder.encode({ + order, + signature, + unwrapNativeToken: false, + }), + ) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.TokenIdMismatchError(order.erc721TokenId.plus(1), order.erc721TokenId), + ); + }); + it('can sell ERC721 without approval', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + // revoke approval + await erc721Token.setApprovalForAll(zeroEx.address, false).awaitTransactionSuccessAsync({ + from: taker, + }); + + await erc721Token + .safeTransferFrom2( + taker, + zeroEx.address, + order.erc721TokenId, + dataEncoder.encode({ + order, + signature, + unwrapNativeToken: false, + }), + ) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + }); + }); + describe('buyERC721', () => { + it('can fill a ERC721 sell order', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = await zeroEx.buyERC721(order, signature, NULL_BYTES).awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + verifyEventsFromLogs(tx.logs, [createERC721OrderFilledEvent(order)], IZeroExEvents.ERC721OrderFilled); + const bitVector = await zeroEx + .getERC721OrderStatusBitVector(maker, order.nonce.dividedToIntegerBy(256)) + .callAsync(); + const flag = new BigNumber(2).exponentiatedBy(order.nonce.mod(256)); + expect(bitVector).to.bignumber.equal(flag); + }); + it('cannot fill the same order twice', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + await zeroEx.buyERC721(order, signature, NULL_BYTES).awaitTransactionSuccessAsync({ + from: taker, + }); + const tx = zeroEx.buyERC721(order, signature, NULL_BYTES).awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.OrderNotFillableError(maker, order.nonce, NFTOrder.OrderStatus.Unfillable), + ); + }); + it('cannot fill a cancelled order', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + await zeroEx.cancelERC721Order(order.nonce).awaitTransactionSuccessAsync({ + from: maker, + }); + const tx = zeroEx.buyERC721(order, signature, NULL_BYTES).awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.OrderNotFillableError(maker, order.nonce, NFTOrder.OrderStatus.Unfillable), + ); + }); + it('cannot fill an expired order', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + expiry: new BigNumber(Math.floor(Date.now() / 1000 - 1)), + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = zeroEx.buyERC721(order, signature, NULL_BYTES).awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.OrderNotFillableError(maker, order.nonce, NFTOrder.OrderStatus.Expired), + ); + }); + it('reverts if a buy order is provided', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = zeroEx.buyERC721(order, signature, NULL_BYTES).awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith('NFTOrders::_validateSellOrder/WRONG_TRADE_DIRECTION'); + }); + it('reverts if the taker is not the taker address specified in the order', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + taker, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order, order.erc721TokenId, otherTaker); + const tx = zeroEx.buyERC721(order, signature, NULL_BYTES).awaitTransactionSuccessAsync({ + from: otherTaker, + }); + return expect(tx).to.revertWith(new RevertErrors.NFTOrders.OnlyTakerError(otherTaker, taker)); + }); + it('succeeds if the taker is the taker address specified in the order', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + taker, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + await zeroEx.buyERC721(order, signature, NULL_BYTES).awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + }); + it('reverts if an invalid signature is provided', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider, SignatureType.EIP712, otherMaker); + await mintAssetsAsync(order); + const tx = zeroEx.buyERC721(order, signature, NULL_BYTES).awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith(new RevertErrors.NFTOrders.InvalidSignerError(maker, otherMaker)); + }); + describe('ETH', () => { + it('can fill an order with ETH (and refunds excess ETH)', async () => { + const order = getTestERC721Order({ + erc20Token: ETH_TOKEN_ADDRESS, + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const takerEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(taker); + const makerEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(maker); + const tx = await zeroEx.buyERC721(order, signature, NULL_BYTES).awaitTransactionSuccessAsync({ + from: taker, + value: order.erc20TokenAmount.plus(1), + }); + const takerEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(taker); + const makerEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(maker); + expect(takerEthBalanceBefore.minus(takerEthBalanceAfter)).to.bignumber.equal(order.erc20TokenAmount); + expect(makerEthBalanceAfter.minus(makerEthBalanceBefore)).to.bignumber.equal(order.erc20TokenAmount); + verifyEventsFromLogs( + tx.logs, + [ + { + _from: maker, + _to: taker, + _tokenId: order.erc721TokenId, + }, + ], + 'Transfer', + ); + }); + it('can fill a WETH order with ETH', async () => { + const order = getTestERC721Order({ + erc20Token: weth.address, + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await erc721Token.mint(maker, order.erc721TokenId).awaitTransactionSuccessAsync(); + const takerEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(taker); + await zeroEx.buyERC721(order, signature, NULL_BYTES).awaitTransactionSuccessAsync({ + from: taker, + value: order.erc20TokenAmount, + }); + const takerEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(taker); + expect(takerEthBalanceBefore.minus(takerEthBalanceAfter)).to.bignumber.equal(order.erc20TokenAmount); + await assertBalancesAsync(order); + }); + it('uses WETH if not enough ETH to fill WETH order', async () => { + const order = getTestERC721Order({ + erc20Token: weth.address, + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await weth.deposit().awaitTransactionSuccessAsync({ + from: taker, + value: order.erc20TokenAmount, + }); + await erc721Token.mint(maker, order.erc721TokenId).awaitTransactionSuccessAsync(); + const takerEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(taker); + await zeroEx.buyERC721(order, signature, NULL_BYTES).awaitTransactionSuccessAsync({ + from: taker, + value: order.erc20TokenAmount.minus(1), + }); + const takerEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(taker); + expect(takerEthBalanceAfter).to.bignumber.equal(takerEthBalanceBefore); + await assertBalancesAsync(order); + }); + }); + describe('fees', () => { + it('single fee to EOA', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + fees: [ + { + recipient: otherMaker, + amount: new BigNumber(111), + feeData: constants.NULL_BYTES, + }, + ], + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + await zeroEx.buyERC721(order, signature, NULL_BYTES).awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + }); + it('pays fees in ETH if erc20Token == ETH', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: ETH_TOKEN_ADDRESS, + fees: [ + { + recipient: otherMaker, + amount: new BigNumber(111), + feeData: constants.NULL_BYTES, + }, + ], + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const takerEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(taker); + const makerEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(maker); + const feeRecipientEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(otherMaker); + await zeroEx.buyERC721(order, signature, NULL_BYTES).awaitTransactionSuccessAsync({ + from: taker, + value: order.erc20TokenAmount.plus(order.fees[0].amount).plus(1), + }); + const takerEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(taker); + const makerEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(maker); + const feeRecipientEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(otherMaker); + expect(takerEthBalanceBefore.minus(takerEthBalanceAfter)).to.bignumber.equal( + order.erc20TokenAmount.plus(order.fees[0].amount), + ); + expect(makerEthBalanceAfter.minus(makerEthBalanceBefore)).to.bignumber.equal(order.erc20TokenAmount); + expect(feeRecipientEthBalanceAfter.minus(feeRecipientEthBalanceBefore)).to.bignumber.equal( + order.fees[0].amount, + ); + const erc721Owner = await erc721Token.ownerOf(order.erc721TokenId).callAsync(); + expect(erc721Owner).to.equal(taker); + }); + it('pays fees in ETH if erc20Token == WETH but taker uses ETH', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: weth.address, + fees: [ + { + recipient: otherMaker, + amount: new BigNumber(111), + feeData: constants.NULL_BYTES, + }, + ], + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const takerEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(taker); + const feeRecipientEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(otherMaker); + const tx = await zeroEx.buyERC721(order, signature, NULL_BYTES).awaitTransactionSuccessAsync({ + from: taker, + value: order.erc20TokenAmount.plus(order.fees[0].amount).plus(1), + }); + const takerEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(taker); + const feeRecipientEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(otherMaker); + expect(takerEthBalanceBefore.minus(takerEthBalanceAfter)).to.bignumber.equal( + order.erc20TokenAmount.plus(order.fees[0].amount), + ); + expect(feeRecipientEthBalanceAfter.minus(feeRecipientEthBalanceBefore)).to.bignumber.equal( + order.fees[0].amount, + ); + verifyEventsFromLogs( + tx.logs, + [ + { + _from: maker, + _to: taker, + _tokenId: order.erc721TokenId, + }, + { + token: weth.address, + from: zeroEx.address, + to: maker, + value: order.erc20TokenAmount, + }, + ], + 'Transfer', + ); + }); + it('pays fees in WETH if taker uses WETH', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: weth.address, + fees: [ + { + recipient: otherMaker, + amount: new BigNumber(111), + feeData: constants.NULL_BYTES, + }, + ], + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await erc721Token.mint(maker, order.erc721TokenId).awaitTransactionSuccessAsync(); + await weth.deposit().awaitTransactionSuccessAsync({ + from: taker, + value: order.erc20TokenAmount.plus(order.fees[0].amount), + }); + await zeroEx.buyERC721(order, signature, NULL_BYTES).awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + }); + it('reverts if overspent ETH', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: ETH_TOKEN_ADDRESS, + fees: [ + { + recipient: otherMaker, + amount: new BigNumber(111), + feeData: constants.NULL_BYTES, + }, + ], + }); + await sendEtherAsync(zeroEx.address, order.fees[0].amount); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = zeroEx.buyERC721(order, signature, NULL_BYTES).awaitTransactionSuccessAsync({ + from: taker, + value: order.erc20TokenAmount, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.OverspentEthError( + order.erc20TokenAmount.plus(order.fees[0].amount), + order.erc20TokenAmount, + ), + ); + }); + }); + }); + describe('batchBuyERC721s', () => { + it('reverts if arrays are different lengths', async () => { + const order = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature = await order.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order); + const tx = zeroEx.batchBuyERC721s([order], [signature, signature], [], false).awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith('ERC721OrdersFeature::batchBuyERC721s/ARRAY_LENGTH_MISMATCH'); + }); + it('successfully fills multiple orders', async () => { + const order1 = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature1 = await order1.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order1); + const order2 = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: weth.address, + }); + const signature2 = await order2.getSignatureWithProviderAsync(env.provider); + await erc721Token.mint(maker, order2.erc721TokenId).awaitTransactionSuccessAsync(); + await weth.deposit().sendTransactionAsync({ + from: taker, + value: order2.erc20TokenAmount, + }); + await zeroEx + .batchBuyERC721s([order1, order2], [signature1, signature2], [NULL_BYTES, NULL_BYTES], false) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order1); + await assertBalancesAsync(order2); + }); + it('catches revert if one order fails', async () => { + const order1 = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature1 = await order1.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order1); + const order2 = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: weth.address, + }); + // invalid signature + const signature2 = await order2.getSignatureWithProviderAsync( + env.provider, + SignatureType.EIP712, + otherMaker, + ); + await erc721Token.mint(maker, order2.erc721TokenId).awaitTransactionSuccessAsync(); + await weth.deposit().sendTransactionAsync({ + from: taker, + value: order2.erc20TokenAmount, + }); + const tx = zeroEx.batchBuyERC721s( + [order1, order2], + [signature1, signature2], + [NULL_BYTES, NULL_BYTES], + false, + ); + const successes = await tx.callAsync({ + from: taker, + }); + expect(successes).to.deep.equal([true, false]); + await tx.awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order1); + const erc721Owner = await erc721Token.ownerOf(order2.erc721TokenId).callAsync(); + expect(erc721Owner).to.equal(maker); + const takerWethBalance = await weth.balanceOf(taker).callAsync(); + expect(takerWethBalance).to.bignumber.equal(order2.erc20TokenAmount); + }); + it('bubbles up revert if one order fails and `revertIfIncomplete == true`', async () => { + const order1 = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature1 = await order1.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order1); + const order2 = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: weth.address, + }); + // invalid signature + const signature2 = await order2.getSignatureWithProviderAsync( + env.provider, + SignatureType.EIP712, + otherMaker, + ); + await erc721Token.mint(maker, order2.erc721TokenId).awaitTransactionSuccessAsync(); + await weth.deposit().sendTransactionAsync({ + from: taker, + value: order2.erc20TokenAmount, + }); + const tx = zeroEx + .batchBuyERC721s([order1, order2], [signature1, signature2], [NULL_BYTES, NULL_BYTES], true) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith(new RevertErrors.NFTOrders.InvalidSignerError(order2.maker, otherMaker)); + }); + it('can fill multiple orders with ETH, refund excess ETH', async () => { + const order1 = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: ETH_TOKEN_ADDRESS, + }); + const signature1 = await order1.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(order1); + const order2 = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: weth.address, + }); + const signature2 = await order2.getSignatureWithProviderAsync(env.provider); + await erc721Token.mint(maker, order2.erc721TokenId).awaitTransactionSuccessAsync(); + const takerEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(taker); + await zeroEx + .batchBuyERC721s([order1, order2], [signature1, signature2], [NULL_BYTES, NULL_BYTES], true) + .awaitTransactionSuccessAsync({ + from: taker, + value: order1.erc20TokenAmount.plus(order2.erc20TokenAmount).plus(1), + }); + const takerEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(taker); + expect(takerEthBalanceBefore.minus(takerEthBalanceAfter)).to.bignumber.equal( + order1.erc20TokenAmount.plus(order2.erc20TokenAmount), + ); + const erc721Owner1 = await erc721Token.ownerOf(order1.erc721TokenId).callAsync(); + expect(erc721Owner1).to.bignumber.equal(taker); + const erc721Owner2 = await erc721Token.ownerOf(order2.erc721TokenId).callAsync(); + expect(erc721Owner2).to.bignumber.equal(taker); + }); + }); + describe('preSignERC721Order', () => { + const PRESIGN_SIGNATURE = { + signatureType: SignatureType.PreSigned, + v: 0, + r: constants.NULL_BYTES32, + s: constants.NULL_BYTES32, + }; + let contractMaker: TestNFTOrderPresignerContract; + before(async () => { + contractMaker = await TestNFTOrderPresignerContract.deployFrom0xArtifactAsync( + artifacts.TestNFTOrderPresigner, + env.provider, + env.txDefaults, + artifacts, + zeroEx.address, + ); + await contractMaker.approveERC20(erc20Token.address).awaitTransactionSuccessAsync(); + await contractMaker.approveERC721(erc721Token.address).awaitTransactionSuccessAsync(); + }); + it('can fill order that has been presigned by the maker', async () => { + const order = getTestERC721Order({ + maker: contractMaker.address, + direction: NFTOrder.TradeDirection.BuyNFT, + }); + await mintAssetsAsync(order); + await contractMaker.preSignERC721Order(order).awaitTransactionSuccessAsync(); + await zeroEx + .sellERC721(order, PRESIGN_SIGNATURE, order.erc721TokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + await assertBalancesAsync(order); + }); + it('cannot fill order that has not been presigned by the maker', async () => { + const order = getTestERC721Order({ + maker: contractMaker.address, + direction: NFTOrder.TradeDirection.BuyNFT, + }); + await mintAssetsAsync(order); + const tx = zeroEx + .sellERC721(order, PRESIGN_SIGNATURE, order.erc721TokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.InvalidSignerError(contractMaker.address, NULL_ADDRESS), + ); + }); + it('cannot fill order that was presigned then cancelled', async () => { + const order = getTestERC721Order({ + maker: contractMaker.address, + direction: NFTOrder.TradeDirection.BuyNFT, + }); + await mintAssetsAsync(order); + await contractMaker.preSignERC721Order(order).awaitTransactionSuccessAsync(); + await contractMaker.cancelERC721Order(order.nonce).awaitTransactionSuccessAsync(); + const tx = zeroEx + .sellERC721(order, PRESIGN_SIGNATURE, order.erc721TokenId, false, NULL_BYTES) + .awaitTransactionSuccessAsync({ + from: taker, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.OrderNotFillableError( + contractMaker.address, + order.nonce, + NFTOrder.OrderStatus.Unfillable, + ), + ); + }); + }); + describe('matchERC721Orders', () => { + it('cannot match two sell orders', async () => { + const order1 = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature1 = await order1.getSignatureWithProviderAsync(env.provider); + const order2 = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const signature2 = await order2.getSignatureWithProviderAsync(env.provider); + const tx = zeroEx.matchERC721Orders(order1, order2, signature1, signature2).awaitTransactionSuccessAsync({ + from: matcher, + }); + return expect(tx).to.revertWith('NFTOrders::_validateBuyOrder/WRONG_TRADE_DIRECTION'); + }); + it('cannot match two buy orders', async () => { + const order1 = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature1 = await order1.getSignatureWithProviderAsync(env.provider); + const order2 = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const signature2 = await order2.getSignatureWithProviderAsync(env.provider); + const tx = zeroEx.matchERC721Orders(order1, order2, signature1, signature2).awaitTransactionSuccessAsync({ + from: matcher, + }); + return expect(tx).to.revertWith('NFTOrders::_validateSellOrder/WRONG_TRADE_DIRECTION'); + }); + it('erc721TokenId must match', async () => { + const sellOrder = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const sellSignature = await sellOrder.getSignatureWithProviderAsync(env.provider); + const buyOrder = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + }); + const buySignature = await buyOrder.getSignatureWithProviderAsync(env.provider); + const tx = zeroEx + .matchERC721Orders(sellOrder, buyOrder, sellSignature, buySignature) + .awaitTransactionSuccessAsync({ + from: matcher, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.TokenIdMismatchError(sellOrder.erc721TokenId, buyOrder.erc721TokenId), + ); + }); + it('erc721Token must match', async () => { + const sellOrder = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const sellSignature = await sellOrder.getSignatureWithProviderAsync(env.provider); + const buyOrder = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + erc721Token: erc20Token.address, + erc721TokenId: sellOrder.erc721TokenId, + }); + const buySignature = await buyOrder.getSignatureWithProviderAsync(env.provider); + const tx = zeroEx + .matchERC721Orders(sellOrder, buyOrder, sellSignature, buySignature) + .awaitTransactionSuccessAsync({ + from: matcher, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.ERC721TokenMismatchError(sellOrder.erc721Token, buyOrder.erc721Token), + ); + }); + it('erc20Token must match', async () => { + const sellOrder = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const sellSignature = await sellOrder.getSignatureWithProviderAsync(env.provider); + const buyOrder = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + erc20Token: weth.address, + erc20TokenAmount: sellOrder.erc20TokenAmount, + erc721TokenId: sellOrder.erc721TokenId, + }); + const buySignature = await buyOrder.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(buyOrder, sellOrder.erc721TokenId, sellOrder.maker); + const tx = zeroEx + .matchERC721Orders(sellOrder, buyOrder, sellSignature, buySignature) + .awaitTransactionSuccessAsync({ + from: matcher, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.ERC20TokenMismatchError(sellOrder.erc20Token, buyOrder.erc20Token), + ); + }); + it('reverts if spread is negative', async () => { + const sellOrder = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const sellSignature = await sellOrder.getSignatureWithProviderAsync(env.provider); + const buyOrder = getTestERC721Order({ + direction: NFTOrder.TradeDirection.BuyNFT, + erc721TokenId: sellOrder.erc721TokenId, + erc20TokenAmount: sellOrder.erc20TokenAmount.minus(1), + }); + const buySignature = await buyOrder.getSignatureWithProviderAsync(env.provider); + const tx = zeroEx + .matchERC721Orders(sellOrder, buyOrder, sellSignature, buySignature) + .awaitTransactionSuccessAsync({ + from: matcher, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.NegativeSpreadError(sellOrder.erc20TokenAmount, buyOrder.erc20TokenAmount), + ); + }); + it('matches two orders and sends profit to matcher', async () => { + const sellOrder = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + }); + const sellSignature = await sellOrder.getSignatureWithProviderAsync(env.provider); + const spread = getRandomInteger(1, '1e18'); + const buyOrder = getTestERC721Order({ + maker: otherMaker, + direction: NFTOrder.TradeDirection.BuyNFT, + erc721TokenId: sellOrder.erc721TokenId, + erc20TokenAmount: sellOrder.erc20TokenAmount.plus(spread), + }); + const buySignature = await buyOrder.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(buyOrder, sellOrder.erc721TokenId, sellOrder.maker); + await zeroEx + .matchERC721Orders(sellOrder, buyOrder, sellSignature, buySignature) + .awaitTransactionSuccessAsync({ + from: matcher, + }); + await assertBalancesAsync(sellOrder, sellOrder.erc721TokenId, otherMaker); + const matcherBalance = await erc20Token.balanceOf(matcher).callAsync(); + expect(matcherBalance).to.bignumber.equal(spread); + }); + it('matches two ETH/WETH orders and sends profit to matcher', async () => { + const sellOrder = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: ETH_TOKEN_ADDRESS, + }); + const sellSignature = await sellOrder.getSignatureWithProviderAsync(env.provider); + const spread = getRandomInteger(1, '1e18'); + const buyOrder = getTestERC721Order({ + maker: otherMaker, + direction: NFTOrder.TradeDirection.BuyNFT, + erc20Token: weth.address, + erc721TokenId: sellOrder.erc721TokenId, + erc20TokenAmount: sellOrder.erc20TokenAmount.plus(spread), + }); + const buySignature = await buyOrder.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(buyOrder, sellOrder.erc721TokenId, sellOrder.maker); + const sellerEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(sellOrder.maker); + const matcherEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(matcher); + await zeroEx + .matchERC721Orders(sellOrder, buyOrder, sellSignature, buySignature) + .awaitTransactionSuccessAsync({ + from: matcher, + }); + const erc721Owner = await erc721Token.ownerOf(sellOrder.erc721TokenId).callAsync(); + expect(erc721Owner).to.equal(buyOrder.maker); + const sellerEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(sellOrder.maker); + const matcherEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(matcher); + expect(sellerEthBalanceAfter.minus(sellerEthBalanceBefore)).to.bignumber.equal(sellOrder.erc20TokenAmount); + expect(matcherEthBalanceAfter.minus(matcherEthBalanceBefore)).to.bignumber.equal(spread); + }); + it('matches two orders (with fees) and sends profit to matcher', async () => { + const spread = getRandomInteger(1, '1e18'); + const sellOrder = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + fees: [ + { + recipient: otherTaker, + amount: getRandomInteger(1, spread), + feeData: NULL_BYTES, + }, + ], + }); + const sellSignature = await sellOrder.getSignatureWithProviderAsync(env.provider); + const buyOrder = getTestERC721Order({ + maker: otherMaker, + direction: NFTOrder.TradeDirection.BuyNFT, + erc721TokenId: sellOrder.erc721TokenId, + erc20TokenAmount: sellOrder.erc20TokenAmount.plus(spread), + }); + const buySignature = await buyOrder.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(buyOrder, sellOrder.erc721TokenId, sellOrder.maker); + await erc20Token.mint(buyOrder.maker, sellOrder.fees[0].amount).awaitTransactionSuccessAsync(); + await zeroEx + .matchERC721Orders(sellOrder, buyOrder, sellSignature, buySignature) + .awaitTransactionSuccessAsync({ + from: matcher, + }); + await assertBalancesAsync(sellOrder, sellOrder.erc721TokenId, otherMaker); + const matcherBalance = await erc20Token.balanceOf(matcher).callAsync(); + expect(matcherBalance).to.bignumber.equal(spread.minus(sellOrder.fees[0].amount)); + }); + it('matches two ETH/WETH (with fees) orders and sends profit to matcher', async () => { + const spread = getRandomInteger(1, '1e18'); + const sellOrder = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: ETH_TOKEN_ADDRESS, + fees: [ + { + recipient: otherTaker, + amount: getRandomInteger(1, spread), + feeData: NULL_BYTES, + }, + ], + }); + const sellSignature = await sellOrder.getSignatureWithProviderAsync(env.provider); + const buyOrder = getTestERC721Order({ + maker: otherMaker, + direction: NFTOrder.TradeDirection.BuyNFT, + erc20Token: weth.address, + erc721TokenId: sellOrder.erc721TokenId, + erc20TokenAmount: sellOrder.erc20TokenAmount.plus(spread), + }); + const buySignature = await buyOrder.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(buyOrder, sellOrder.erc721TokenId, sellOrder.maker); + await weth + .deposit() + .awaitTransactionSuccessAsync({ from: buyOrder.maker, value: sellOrder.fees[0].amount }); + const sellerEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(sellOrder.maker); + const matcherEthBalanceBefore = await env.web3Wrapper.getBalanceInWeiAsync(matcher); + await zeroEx + .matchERC721Orders(sellOrder, buyOrder, sellSignature, buySignature) + .awaitTransactionSuccessAsync({ + from: matcher, + }); + const erc721Owner = await erc721Token.ownerOf(sellOrder.erc721TokenId).callAsync(); + expect(erc721Owner).to.equal(buyOrder.maker); + const sellerEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(sellOrder.maker); + const matcherEthBalanceAfter = await env.web3Wrapper.getBalanceInWeiAsync(matcher); + expect(sellerEthBalanceAfter.minus(sellerEthBalanceBefore)).to.bignumber.equal(sellOrder.erc20TokenAmount); + expect(matcherEthBalanceAfter.minus(matcherEthBalanceBefore)).to.bignumber.equal( + spread.minus(sellOrder.fees[0].amount), + ); + }); + it('reverts if sell order fees exceed spread', async () => { + const spread = getRandomInteger(1, '1e18'); + const sellOrder = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + fees: [ + { + recipient: otherTaker, + amount: spread.plus(1), + feeData: NULL_BYTES, + }, + ], + }); + const sellSignature = await sellOrder.getSignatureWithProviderAsync(env.provider); + const buyOrder = getTestERC721Order({ + maker: otherMaker, + direction: NFTOrder.TradeDirection.BuyNFT, + erc721TokenId: sellOrder.erc721TokenId, + erc20TokenAmount: sellOrder.erc20TokenAmount.plus(spread), + }); + const buySignature = await buyOrder.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(buyOrder, sellOrder.erc721TokenId, sellOrder.maker); + await erc20Token.mint(buyOrder.maker, sellOrder.fees[0].amount).awaitTransactionSuccessAsync(); + const tx = zeroEx + .matchERC721Orders(sellOrder, buyOrder, sellSignature, buySignature) + .awaitTransactionSuccessAsync({ + from: matcher, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.SellOrderFeesExceedSpreadError(sellOrder.fees[0].amount, spread), + ); + }); + it('reverts if sell order fees exceed spread (ETH/WETH)', async () => { + const spread = getRandomInteger(1, '1e18'); + const sellOrder = getTestERC721Order({ + direction: NFTOrder.TradeDirection.SellNFT, + erc20Token: ETH_TOKEN_ADDRESS, + fees: [ + { + recipient: otherTaker, + amount: spread.plus(1), + feeData: NULL_BYTES, + }, + ], + }); + await sendEtherAsync(zeroEx.address, sellOrder.fees[0].amount); + const sellSignature = await sellOrder.getSignatureWithProviderAsync(env.provider); + const buyOrder = getTestERC721Order({ + maker: otherMaker, + direction: NFTOrder.TradeDirection.BuyNFT, + erc20Token: weth.address, + erc721TokenId: sellOrder.erc721TokenId, + erc20TokenAmount: sellOrder.erc20TokenAmount.plus(spread), + }); + const buySignature = await buyOrder.getSignatureWithProviderAsync(env.provider); + await mintAssetsAsync(buyOrder, sellOrder.erc721TokenId, sellOrder.maker); + await weth + .deposit() + .awaitTransactionSuccessAsync({ from: buyOrder.maker, value: sellOrder.fees[0].amount }); + const tx = zeroEx + .matchERC721Orders(sellOrder, buyOrder, sellSignature, buySignature) + .awaitTransactionSuccessAsync({ + from: matcher, + }); + return expect(tx).to.revertWith( + new RevertErrors.NFTOrders.SellOrderFeesExceedSpreadError(sellOrder.fees[0].amount, spread), + ); + }); + }); +}); diff --git a/contracts/zero-ex/test/utils/nft_orders.ts b/contracts/zero-ex/test/utils/nft_orders.ts new file mode 100644 index 0000000000..1426123524 --- /dev/null +++ b/contracts/zero-ex/test/utils/nft_orders.ts @@ -0,0 +1,41 @@ +import { constants, getRandomInteger, randomAddress } from '@0x/contracts-test-utils'; +import { ERC1155Order, ERC721Order } from '@0x/protocol-utils'; +import { BigNumber } from '@0x/utils'; + +/** + * Generate a random ERC721 Order + */ +export function getRandomERC721Order(fields: Partial = {}): ERC721Order { + return new ERC721Order({ + erc20Token: randomAddress(), + erc20TokenAmount: getRandomInteger('1e18', '10e18'), + erc721Token: randomAddress(), + erc721TokenId: getRandomInteger(0, constants.MAX_UINT256), + maker: randomAddress(), + taker: randomAddress(), + erc721TokenProperties: [], + fees: [], + nonce: getRandomInteger(0, constants.MAX_UINT256), + expiry: new BigNumber(Math.floor(Date.now() / 1000 + 60)), + ...fields, + }); +} +/** + * Generate a random ERC1155 Order + */ +export function getRandomERC1155Order(fields: Partial = {}): ERC1155Order { + return new ERC1155Order({ + erc20Token: randomAddress(), + erc20TokenAmount: getRandomInteger('1e18', '10e18'), + erc1155Token: randomAddress(), + erc1155TokenId: getRandomInteger(0, constants.MAX_UINT256), + erc1155TokenAmount: getRandomInteger(1, '10e18'), + maker: randomAddress(), + taker: randomAddress(), + erc1155TokenProperties: [], + fees: [], + nonce: getRandomInteger(0, constants.MAX_UINT256), + expiry: new BigNumber(Math.floor(Date.now() / 1000 + 60)), + ...fields, + }); +} diff --git a/contracts/zero-ex/test/wrappers.ts b/contracts/zero-ex/test/wrappers.ts index 5d11e9cefc..630dd4af95 100644 --- a/contracts/zero-ex/test/wrappers.ts +++ b/contracts/zero-ex/test/wrappers.ts @@ -9,11 +9,16 @@ export * from '../test/generated-wrappers/bootstrap_feature'; export * from '../test/generated-wrappers/bridge_adapter'; export * from '../test/generated-wrappers/bridge_protocols'; export * from '../test/generated-wrappers/curve_liquidity_provider'; +export * from '../test/generated-wrappers/erc1155_orders_feature'; +export * from '../test/generated-wrappers/erc165_feature'; +export * from '../test/generated-wrappers/erc721_orders_feature'; export * from '../test/generated-wrappers/fee_collector'; export * from '../test/generated-wrappers/fee_collector_controller'; export * from '../test/generated-wrappers/fill_quote_transformer'; export * from '../test/generated-wrappers/fixin_common'; export * from '../test/generated-wrappers/fixin_e_i_p712'; +export * from '../test/generated-wrappers/fixin_erc1155_spender'; +export * from '../test/generated-wrappers/fixin_erc721_spender'; export * from '../test/generated-wrappers/fixin_protocol_fees'; export * from '../test/generated-wrappers/fixin_reentrancy_guard'; export * from '../test/generated-wrappers/fixin_token_spender'; @@ -23,9 +28,15 @@ export * from '../test/generated-wrappers/fund_recovery_feature'; export * from '../test/generated-wrappers/i_batch_fill_native_orders_feature'; export * from '../test/generated-wrappers/i_bootstrap_feature'; export * from '../test/generated-wrappers/i_bridge_adapter'; +export * from '../test/generated-wrappers/i_erc1155_orders_feature'; +export * from '../test/generated-wrappers/i_erc1155_token'; +export * from '../test/generated-wrappers/i_erc165_feature'; export * from '../test/generated-wrappers/i_erc20_bridge'; export * from '../test/generated-wrappers/i_erc20_transformer'; +export * from '../test/generated-wrappers/i_erc721_orders_feature'; +export * from '../test/generated-wrappers/i_erc721_token'; export * from '../test/generated-wrappers/i_feature'; +export * from '../test/generated-wrappers/i_fee_recipient'; export * from '../test/generated-wrappers/i_flash_wallet'; export * from '../test/generated-wrappers/i_fund_recovery_feature'; export * from '../test/generated-wrappers/i_liquidity_provider'; @@ -39,8 +50,10 @@ export * from '../test/generated-wrappers/i_native_orders_feature'; export * from '../test/generated-wrappers/i_otc_orders_feature'; export * from '../test/generated-wrappers/i_ownable_feature'; export * from '../test/generated-wrappers/i_pancake_swap_feature'; +export * from '../test/generated-wrappers/i_property_validator'; export * from '../test/generated-wrappers/i_simple_function_registry_feature'; export * from '../test/generated-wrappers/i_staking'; +export * from '../test/generated-wrappers/i_taker_callback'; export * from '../test/generated-wrappers/i_test_simple_function_registry_feature'; export * from '../test/generated-wrappers/i_token_spender_feature'; export * from '../test/generated-wrappers/i_transform_erc20_feature'; @@ -52,12 +65,16 @@ export * from '../test/generated-wrappers/i_zero_ex'; export * from '../test/generated-wrappers/initial_migration'; export * from '../test/generated-wrappers/lib_bootstrap'; export * from '../test/generated-wrappers/lib_common_rich_errors'; +export * from '../test/generated-wrappers/lib_erc1155_orders_storage'; export * from '../test/generated-wrappers/lib_erc20_transformer'; +export * from '../test/generated-wrappers/lib_erc721_orders_storage'; export * from '../test/generated-wrappers/lib_fee_collector'; export * from '../test/generated-wrappers/lib_liquidity_provider_rich_errors'; export * from '../test/generated-wrappers/lib_meta_transactions_rich_errors'; export * from '../test/generated-wrappers/lib_meta_transactions_storage'; export * from '../test/generated-wrappers/lib_migrate'; +export * from '../test/generated-wrappers/lib_n_f_t_order'; +export * from '../test/generated-wrappers/lib_n_f_t_orders_rich_errors'; export * from '../test/generated-wrappers/lib_native_order'; export * from '../test/generated-wrappers/lib_native_orders_rich_errors'; export * from '../test/generated-wrappers/lib_native_orders_storage'; @@ -111,6 +128,7 @@ export * from '../test/generated-wrappers/multiplex_rfq'; export * from '../test/generated-wrappers/multiplex_transform_erc20'; export * from '../test/generated-wrappers/multiplex_uniswap_v2'; export * from '../test/generated-wrappers/multiplex_uniswap_v3'; +export * from '../test/generated-wrappers/n_f_t_orders'; export * from '../test/generated-wrappers/native_orders_cancellation'; export * from '../test/generated-wrappers/native_orders_feature'; export * from '../test/generated-wrappers/native_orders_info'; @@ -128,6 +146,7 @@ export * from '../test/generated-wrappers/test_call_target'; export * from '../test/generated-wrappers/test_curve'; export * from '../test/generated-wrappers/test_delegate_caller'; export * from '../test/generated-wrappers/test_fee_collector_controller'; +export * from '../test/generated-wrappers/test_fee_recipient'; export * from '../test/generated-wrappers/test_fill_quote_transformer_bridge'; export * from '../test/generated-wrappers/test_fill_quote_transformer_exchange'; export * from '../test/generated-wrappers/test_fill_quote_transformer_host'; @@ -142,13 +161,17 @@ export * from '../test/generated-wrappers/test_meta_transactions_native_orders_f export * from '../test/generated-wrappers/test_meta_transactions_transform_erc20_feature'; export * from '../test/generated-wrappers/test_migrator'; export * from '../test/generated-wrappers/test_mint_token_erc20_transformer'; +export * from '../test/generated-wrappers/test_mintable_erc1155_token'; export * from '../test/generated-wrappers/test_mintable_erc20_token'; +export * from '../test/generated-wrappers/test_mintable_erc721_token'; export * from '../test/generated-wrappers/test_mooniswap'; +export * from '../test/generated-wrappers/test_n_f_t_order_presigner'; export * from '../test/generated-wrappers/test_native_orders_feature'; export * from '../test/generated-wrappers/test_no_eth_recipient'; export * from '../test/generated-wrappers/test_order_signer_registry_with_contract_wallet'; export * from '../test/generated-wrappers/test_permissionless_transformer_deployer_suicidal'; export * from '../test/generated-wrappers/test_permissionless_transformer_deployer_transformer'; +export * from '../test/generated-wrappers/test_property_validator'; export * from '../test/generated-wrappers/test_rfq_origin_registration'; export * from '../test/generated-wrappers/test_simple_function_registry_feature_impl1'; export * from '../test/generated-wrappers/test_simple_function_registry_feature_impl2'; diff --git a/contracts/zero-ex/tsconfig.json b/contracts/zero-ex/tsconfig.json index 1b39a1a51e..32cd919834 100644 --- a/contracts/zero-ex/tsconfig.json +++ b/contracts/zero-ex/tsconfig.json @@ -42,11 +42,16 @@ "test/generated-artifacts/BridgeAdapter.json", "test/generated-artifacts/BridgeProtocols.json", "test/generated-artifacts/CurveLiquidityProvider.json", + "test/generated-artifacts/ERC1155OrdersFeature.json", + "test/generated-artifacts/ERC165Feature.json", + "test/generated-artifacts/ERC721OrdersFeature.json", "test/generated-artifacts/FeeCollector.json", "test/generated-artifacts/FeeCollectorController.json", "test/generated-artifacts/FillQuoteTransformer.json", "test/generated-artifacts/FixinCommon.json", "test/generated-artifacts/FixinEIP712.json", + "test/generated-artifacts/FixinERC1155Spender.json", + "test/generated-artifacts/FixinERC721Spender.json", "test/generated-artifacts/FixinProtocolFees.json", "test/generated-artifacts/FixinReentrancyGuard.json", "test/generated-artifacts/FixinTokenSpender.json", @@ -56,9 +61,15 @@ "test/generated-artifacts/IBatchFillNativeOrdersFeature.json", "test/generated-artifacts/IBootstrapFeature.json", "test/generated-artifacts/IBridgeAdapter.json", + "test/generated-artifacts/IERC1155OrdersFeature.json", + "test/generated-artifacts/IERC1155Token.json", + "test/generated-artifacts/IERC165Feature.json", "test/generated-artifacts/IERC20Bridge.json", "test/generated-artifacts/IERC20Transformer.json", + "test/generated-artifacts/IERC721OrdersFeature.json", + "test/generated-artifacts/IERC721Token.json", "test/generated-artifacts/IFeature.json", + "test/generated-artifacts/IFeeRecipient.json", "test/generated-artifacts/IFlashWallet.json", "test/generated-artifacts/IFundRecoveryFeature.json", "test/generated-artifacts/ILiquidityProvider.json", @@ -72,8 +83,10 @@ "test/generated-artifacts/IOtcOrdersFeature.json", "test/generated-artifacts/IOwnableFeature.json", "test/generated-artifacts/IPancakeSwapFeature.json", + "test/generated-artifacts/IPropertyValidator.json", "test/generated-artifacts/ISimpleFunctionRegistryFeature.json", "test/generated-artifacts/IStaking.json", + "test/generated-artifacts/ITakerCallback.json", "test/generated-artifacts/ITestSimpleFunctionRegistryFeature.json", "test/generated-artifacts/ITokenSpenderFeature.json", "test/generated-artifacts/ITransformERC20Feature.json", @@ -85,12 +98,16 @@ "test/generated-artifacts/InitialMigration.json", "test/generated-artifacts/LibBootstrap.json", "test/generated-artifacts/LibCommonRichErrors.json", + "test/generated-artifacts/LibERC1155OrdersStorage.json", "test/generated-artifacts/LibERC20Transformer.json", + "test/generated-artifacts/LibERC721OrdersStorage.json", "test/generated-artifacts/LibFeeCollector.json", "test/generated-artifacts/LibLiquidityProviderRichErrors.json", "test/generated-artifacts/LibMetaTransactionsRichErrors.json", "test/generated-artifacts/LibMetaTransactionsStorage.json", "test/generated-artifacts/LibMigrate.json", + "test/generated-artifacts/LibNFTOrder.json", + "test/generated-artifacts/LibNFTOrdersRichErrors.json", "test/generated-artifacts/LibNativeOrder.json", "test/generated-artifacts/LibNativeOrdersRichErrors.json", "test/generated-artifacts/LibNativeOrdersStorage.json", @@ -144,6 +161,7 @@ "test/generated-artifacts/MultiplexTransformERC20.json", "test/generated-artifacts/MultiplexUniswapV2.json", "test/generated-artifacts/MultiplexUniswapV3.json", + "test/generated-artifacts/NFTOrders.json", "test/generated-artifacts/NativeOrdersCancellation.json", "test/generated-artifacts/NativeOrdersFeature.json", "test/generated-artifacts/NativeOrdersInfo.json", @@ -161,6 +179,7 @@ "test/generated-artifacts/TestCurve.json", "test/generated-artifacts/TestDelegateCaller.json", "test/generated-artifacts/TestFeeCollectorController.json", + "test/generated-artifacts/TestFeeRecipient.json", "test/generated-artifacts/TestFillQuoteTransformerBridge.json", "test/generated-artifacts/TestFillQuoteTransformerExchange.json", "test/generated-artifacts/TestFillQuoteTransformerHost.json", @@ -175,13 +194,17 @@ "test/generated-artifacts/TestMetaTransactionsTransformERC20Feature.json", "test/generated-artifacts/TestMigrator.json", "test/generated-artifacts/TestMintTokenERC20Transformer.json", + "test/generated-artifacts/TestMintableERC1155Token.json", "test/generated-artifacts/TestMintableERC20Token.json", + "test/generated-artifacts/TestMintableERC721Token.json", "test/generated-artifacts/TestMooniswap.json", + "test/generated-artifacts/TestNFTOrderPresigner.json", "test/generated-artifacts/TestNativeOrdersFeature.json", "test/generated-artifacts/TestNoEthRecipient.json", "test/generated-artifacts/TestOrderSignerRegistryWithContractWallet.json", "test/generated-artifacts/TestPermissionlessTransformerDeployerSuicidal.json", "test/generated-artifacts/TestPermissionlessTransformerDeployerTransformer.json", + "test/generated-artifacts/TestPropertyValidator.json", "test/generated-artifacts/TestRfqOriginRegistration.json", "test/generated-artifacts/TestSimpleFunctionRegistryFeatureImpl1.json", "test/generated-artifacts/TestSimpleFunctionRegistryFeatureImpl2.json", diff --git a/package.json b/package.json index d1f4318164..086119af86 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "test:generate_docs:circleci": "for i in ${npm_package_config_packagesWithDocPages}; do yarn generate_doc --package $i || break -1; done;", "bundlewatch": "bundlewatch", "lint": "wsrun --fast-exit --parallel --exclude-missing -p $PKG -c lint", - "upgrade_org_deps": "node node_modules/@0x/monorepo-scripts/lib/upgrade_deps.js -p '@0x/|ethereum-types'", + "upgrade_tools": "node node_modules/@0x/monorepo-scripts/lib/upgrade_deps.js -p '@0x/abi-gen|@0x/assert|@0x/base-contract|@0x/contracts-gen|@0x/dev-utils|@0x/json-schemas|@0x/monorepo-scripts|@0x/sol-compiler|@0x/sol-coverage|@0x/sol-doc|@0x/sol-profiler|@0x/sol-resolver|@0x/sol-trace|@0x/sol-tracing-utils|@0x/subproviders|@0x/tslint-config|@0x/types|@0x/typescript-typings|@0x/utils|@0x/verdaccio|@0x/web3-wrapper|ethereum-types'", "upgrade_deps": "node node_modules/@0x/monorepo-scripts/lib/upgrade_deps.js", "verdaccio": "docker run --rm -i -p 4873:4873 0xorg/verdaccio" }, @@ -60,7 +60,7 @@ "ignoreDependencyVersionsForPackage": "contract-wrappers" }, "devDependencies": { - "@0x/monorepo-scripts": "^3.2.0", + "@0x/monorepo-scripts": "^3.2.1", "@0x-lerna-fork/lerna": "3.16.10", "@0xproject/npm-cli-login": "^0.0.11", "async-child-process": "^1.1.1", diff --git a/packages/asset-swapper/package.json b/packages/asset-swapper/package.json index 25a5b7e50e..1ed8124a41 100644 --- a/packages/asset-swapper/package.json +++ b/packages/asset-swapper/package.json @@ -58,21 +58,21 @@ "registry": "git@github.com:0xProject/gitpkg-registry.git" }, "dependencies": { - "@0x/assert": "^3.0.29", - "@0x/base-contract": "^6.4.2", + "@0x/assert": "^3.0.31", + "@0x/base-contract": "^6.4.5", "@0x/contract-addresses": "^6.11.0", "@0x/contract-wrappers": "^13.18.5", "@0x/contracts-erc20": "^3.3.25", "@0x/contracts-zero-ex": "^0.30.1", - "@0x/dev-utils": "^4.2.9", - "@0x/json-schemas": "^6.3.0", + "@0x/dev-utils": "^4.2.11", + "@0x/json-schemas": "^6.4.1", "@0x/neon-router": "^0.3.2", "@0x/protocol-utils": "^1.10.1", "@0x/quote-server": "^6.0.6", "@0x/types": "^3.3.4", "@0x/typescript-typings": "^5.2.1", - "@0x/utils": "^6.4.4", - "@0x/web3-wrapper": "^7.6.0", + "@0x/utils": "^6.5.0", + "@0x/web3-wrapper": "^7.6.2", "@balancer-labs/sor": "0.3.2", "@bancor/sdk": "0.2.9", "@ethersproject/abi": "^5.0.1", @@ -93,17 +93,17 @@ "lodash": "^4.17.11" }, "devDependencies": { - "@0x/abi-gen": "^5.6.2", + "@0x/abi-gen": "^5.7.2", "@0x/contracts-asset-proxy": "^3.7.19", "@0x/contracts-exchange": "^3.2.38", "@0x/contracts-exchange-libs": "^4.3.37", - "@0x/contracts-gen": "^2.0.40", + "@0x/contracts-gen": "^2.0.43", "@0x/contracts-test-utils": "^5.4.16", "@0x/contracts-utils": "^4.8.6", "@0x/mesh-rpc-client": "^9.4.2", "@0x/migrations": "^8.1.14", - "@0x/sol-compiler": "^4.7.5", - "@0x/subproviders": "^6.6.0", + "@0x/sol-compiler": "^4.7.8", + "@0x/subproviders": "^6.6.2", "@0x/ts-doc-gen": "^0.0.28", "@0x/tslint-config": "^4.1.4", "@0x/types": "^3.3.4", diff --git a/packages/asset-swapper/test/dex_sampler_test.ts b/packages/asset-swapper/test/dex_sampler_test.ts index f2a24d01ab..79d6eb400c 100644 --- a/packages/asset-swapper/test/dex_sampler_test.ts +++ b/packages/asset-swapper/test/dex_sampler_test.ts @@ -21,7 +21,7 @@ import { generatePseudoRandomSalt } from './utils/utils'; const CHAIN_ID = 1; const EMPTY_BYTES32 = '0x0000000000000000000000000000000000000000000000000000000000000000'; // tslint:disable: custom-no-magic-numbers -describe('DexSampler tests', () => { +describe.skip('DexSampler tests', () => { const MAKER_TOKEN = randomAddress(); const TAKER_TOKEN = randomAddress(); const chainId = ChainId.Mainnet; diff --git a/packages/contract-artifacts/CHANGELOG.json b/packages/contract-artifacts/CHANGELOG.json index ff7a9874a2..397b75e232 100644 --- a/packages/contract-artifacts/CHANGELOG.json +++ b/packages/contract-artifacts/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "3.17.0", + "changes": [ + { + "note": "Update IZeroEx artifact", + "pr": 429 + } + ] + }, { "version": "3.16.0", "changes": [ diff --git a/packages/contract-artifacts/artifacts/IZeroEx.json b/packages/contract-artifacts/artifacts/IZeroEx.json index 08382371f6..f88e072f08 100644 --- a/packages/contract-artifacts/artifacts/IZeroEx.json +++ b/packages/contract-artifacts/artifacts/IZeroEx.json @@ -3,6 +3,200 @@ "contractName": "IZeroEx", "compilerOutput": { "abi": [ + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "address", "name": "maker", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "nonce", "type": "uint256" } + ], + "name": "ERC1155OrderCancelled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "enum LibNFTOrder.TradeDirection", + "name": "direction", + "type": "uint8" + }, + { "indexed": false, "internalType": "address", "name": "maker", "type": "address" }, + { "indexed": false, "internalType": "address", "name": "taker", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "indexed": false, + "internalType": "contract IERC20TokenV06", + "name": "erc20Token", + "type": "address" + }, + { "indexed": false, "internalType": "uint256", "name": "erc20FillAmount", "type": "uint256" }, + { + "indexed": false, + "internalType": "contract IERC1155Token", + "name": "erc1155Token", + "type": "address" + }, + { "indexed": false, "internalType": "uint256", "name": "erc1155TokenId", "type": "uint256" }, + { "indexed": false, "internalType": "uint128", "name": "erc1155FillAmount", "type": "uint128" }, + { "indexed": false, "internalType": "address", "name": "matcher", "type": "address" } + ], + "name": "ERC1155OrderFilled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "enum LibNFTOrder.TradeDirection", + "name": "direction", + "type": "uint8" + }, + { "indexed": false, "internalType": "address", "name": "maker", "type": "address" }, + { "indexed": false, "internalType": "address", "name": "taker", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "indexed": false, + "internalType": "contract IERC20TokenV06", + "name": "erc20Token", + "type": "address" + }, + { "indexed": false, "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "indexed": false, + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { + "indexed": false, + "internalType": "contract IERC1155Token", + "name": "erc1155Token", + "type": "address" + }, + { "indexed": false, "internalType": "uint256", "name": "erc1155TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "indexed": false, + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc1155TokenProperties", + "type": "tuple[]" + }, + { "indexed": false, "internalType": "uint128", "name": "erc1155TokenAmount", "type": "uint128" } + ], + "name": "ERC1155OrderPreSigned", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "address", "name": "maker", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "nonce", "type": "uint256" } + ], + "name": "ERC721OrderCancelled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "enum LibNFTOrder.TradeDirection", + "name": "direction", + "type": "uint8" + }, + { "indexed": false, "internalType": "address", "name": "maker", "type": "address" }, + { "indexed": false, "internalType": "address", "name": "taker", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "indexed": false, + "internalType": "contract IERC20TokenV06", + "name": "erc20Token", + "type": "address" + }, + { "indexed": false, "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "indexed": false, + "internalType": "contract IERC721Token", + "name": "erc721Token", + "type": "address" + }, + { "indexed": false, "internalType": "uint256", "name": "erc721TokenId", "type": "uint256" }, + { "indexed": false, "internalType": "address", "name": "matcher", "type": "address" } + ], + "name": "ERC721OrderFilled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "enum LibNFTOrder.TradeDirection", + "name": "direction", + "type": "uint8" + }, + { "indexed": false, "internalType": "address", "name": "maker", "type": "address" }, + { "indexed": false, "internalType": "address", "name": "taker", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { + "indexed": false, + "internalType": "contract IERC20TokenV06", + "name": "erc20Token", + "type": "address" + }, + { "indexed": false, "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "indexed": false, + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { + "indexed": false, + "internalType": "contract IERC721Token", + "name": "erc721Token", + "type": "address" + }, + { "indexed": false, "internalType": "uint256", "name": "erc721TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "indexed": false, + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc721TokenProperties", + "type": "tuple[]" + } + ], + "name": "ERC721OrderPreSigned", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -408,6 +602,150 @@ "stateMutability": "payable", "type": "function" }, + { + "inputs": [ + { + "components": [ + { "internalType": "enum LibNFTOrder.TradeDirection", "name": "direction", "type": "uint8" }, + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "address", "name": "taker", "type": "address" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "contract IERC20TokenV06", "name": "erc20Token", "type": "address" }, + { "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { "internalType": "contract IERC1155Token", "name": "erc1155Token", "type": "address" }, + { "internalType": "uint256", "name": "erc1155TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc1155TokenProperties", + "type": "tuple[]" + }, + { "internalType": "uint128", "name": "erc1155TokenAmount", "type": "uint128" } + ], + "internalType": "struct LibNFTOrder.ERC1155Order[]", + "name": "sellOrders", + "type": "tuple[]" + }, + { + "components": [ + { + "internalType": "enum LibSignature.SignatureType", + "name": "signatureType", + "type": "uint8" + }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "internalType": "struct LibSignature.Signature[]", + "name": "signatures", + "type": "tuple[]" + }, + { "internalType": "uint128[]", "name": "erc1155TokenAmounts", "type": "uint128[]" }, + { "internalType": "bytes[]", "name": "callbackData", "type": "bytes[]" }, + { "internalType": "bool", "name": "revertIfIncomplete", "type": "bool" } + ], + "name": "batchBuyERC1155s", + "outputs": [{ "internalType": "bool[]", "name": "successes", "type": "bool[]" }], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "enum LibNFTOrder.TradeDirection", "name": "direction", "type": "uint8" }, + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "address", "name": "taker", "type": "address" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "contract IERC20TokenV06", "name": "erc20Token", "type": "address" }, + { "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { "internalType": "contract IERC721Token", "name": "erc721Token", "type": "address" }, + { "internalType": "uint256", "name": "erc721TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc721TokenProperties", + "type": "tuple[]" + } + ], + "internalType": "struct LibNFTOrder.ERC721Order[]", + "name": "sellOrders", + "type": "tuple[]" + }, + { + "components": [ + { + "internalType": "enum LibSignature.SignatureType", + "name": "signatureType", + "type": "uint8" + }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "internalType": "struct LibSignature.Signature[]", + "name": "signatures", + "type": "tuple[]" + }, + { "internalType": "bytes[]", "name": "callbackData", "type": "bytes[]" }, + { "internalType": "bool", "name": "revertIfIncomplete", "type": "bool" } + ], + "name": "batchBuyERC721s", + "outputs": [{ "internalType": "bool[]", "name": "successes", "type": "bool[]" }], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256[]", "name": "orderNonces", "type": "uint256[]" }], + "name": "batchCancelERC1155Orders", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256[]", "name": "orderNonces", "type": "uint256[]" }], + "name": "batchCancelERC721Orders", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -800,6 +1138,267 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "components": [ + { "internalType": "enum LibNFTOrder.TradeDirection", "name": "direction", "type": "uint8" }, + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "address", "name": "taker", "type": "address" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "contract IERC20TokenV06", "name": "erc20Token", "type": "address" }, + { "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { "internalType": "contract IERC721Token", "name": "erc721Token", "type": "address" }, + { "internalType": "uint256", "name": "erc721TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc721TokenProperties", + "type": "tuple[]" + } + ], + "internalType": "struct LibNFTOrder.ERC721Order[]", + "name": "sellOrders", + "type": "tuple[]" + }, + { + "components": [ + { "internalType": "enum LibNFTOrder.TradeDirection", "name": "direction", "type": "uint8" }, + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "address", "name": "taker", "type": "address" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "contract IERC20TokenV06", "name": "erc20Token", "type": "address" }, + { "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { "internalType": "contract IERC721Token", "name": "erc721Token", "type": "address" }, + { "internalType": "uint256", "name": "erc721TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc721TokenProperties", + "type": "tuple[]" + } + ], + "internalType": "struct LibNFTOrder.ERC721Order[]", + "name": "buyOrders", + "type": "tuple[]" + }, + { + "components": [ + { + "internalType": "enum LibSignature.SignatureType", + "name": "signatureType", + "type": "uint8" + }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "internalType": "struct LibSignature.Signature[]", + "name": "sellOrderSignatures", + "type": "tuple[]" + }, + { + "components": [ + { + "internalType": "enum LibSignature.SignatureType", + "name": "signatureType", + "type": "uint8" + }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "internalType": "struct LibSignature.Signature[]", + "name": "buyOrderSignatures", + "type": "tuple[]" + } + ], + "name": "batchMatchERC721Orders", + "outputs": [ + { "internalType": "uint256[]", "name": "profits", "type": "uint256[]" }, + { "internalType": "bool[]", "name": "successes", "type": "bool[]" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "enum LibNFTOrder.TradeDirection", "name": "direction", "type": "uint8" }, + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "address", "name": "taker", "type": "address" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "contract IERC20TokenV06", "name": "erc20Token", "type": "address" }, + { "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { "internalType": "contract IERC1155Token", "name": "erc1155Token", "type": "address" }, + { "internalType": "uint256", "name": "erc1155TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc1155TokenProperties", + "type": "tuple[]" + }, + { "internalType": "uint128", "name": "erc1155TokenAmount", "type": "uint128" } + ], + "internalType": "struct LibNFTOrder.ERC1155Order", + "name": "sellOrder", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "enum LibSignature.SignatureType", + "name": "signatureType", + "type": "uint8" + }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "internalType": "struct LibSignature.Signature", + "name": "signature", + "type": "tuple" + }, + { "internalType": "uint128", "name": "erc1155BuyAmount", "type": "uint128" }, + { "internalType": "bytes", "name": "callbackData", "type": "bytes" } + ], + "name": "buyERC1155", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "enum LibNFTOrder.TradeDirection", "name": "direction", "type": "uint8" }, + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "address", "name": "taker", "type": "address" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "contract IERC20TokenV06", "name": "erc20Token", "type": "address" }, + { "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { "internalType": "contract IERC721Token", "name": "erc721Token", "type": "address" }, + { "internalType": "uint256", "name": "erc721TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc721TokenProperties", + "type": "tuple[]" + } + ], + "internalType": "struct LibNFTOrder.ERC721Order", + "name": "sellOrder", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "enum LibSignature.SignatureType", + "name": "signatureType", + "type": "uint8" + }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "internalType": "struct LibSignature.Signature", + "name": "signature", + "type": "tuple" + }, + { "internalType": "bytes", "name": "callbackData", "type": "bytes" } + ], + "name": "buyERC721", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "orderNonce", "type": "uint256" }], + "name": "cancelERC1155Order", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "orderNonce", "type": "uint256" }], + "name": "cancelERC721Order", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -1360,6 +1959,218 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "components": [ + { "internalType": "enum LibNFTOrder.TradeDirection", "name": "direction", "type": "uint8" }, + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "address", "name": "taker", "type": "address" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "contract IERC20TokenV06", "name": "erc20Token", "type": "address" }, + { "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { "internalType": "contract IERC1155Token", "name": "erc1155Token", "type": "address" }, + { "internalType": "uint256", "name": "erc1155TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc1155TokenProperties", + "type": "tuple[]" + }, + { "internalType": "uint128", "name": "erc1155TokenAmount", "type": "uint128" } + ], + "internalType": "struct LibNFTOrder.ERC1155Order", + "name": "order", + "type": "tuple" + } + ], + "name": "getERC1155OrderHash", + "outputs": [{ "internalType": "bytes32", "name": "orderHash", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "enum LibNFTOrder.TradeDirection", "name": "direction", "type": "uint8" }, + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "address", "name": "taker", "type": "address" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "contract IERC20TokenV06", "name": "erc20Token", "type": "address" }, + { "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { "internalType": "contract IERC1155Token", "name": "erc1155Token", "type": "address" }, + { "internalType": "uint256", "name": "erc1155TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc1155TokenProperties", + "type": "tuple[]" + }, + { "internalType": "uint128", "name": "erc1155TokenAmount", "type": "uint128" } + ], + "internalType": "struct LibNFTOrder.ERC1155Order", + "name": "order", + "type": "tuple" + } + ], + "name": "getERC1155OrderInfo", + "outputs": [ + { + "components": [ + { "internalType": "bytes32", "name": "orderHash", "type": "bytes32" }, + { "internalType": "enum LibNFTOrder.OrderStatus", "name": "status", "type": "uint8" }, + { "internalType": "uint128", "name": "orderAmount", "type": "uint128" }, + { "internalType": "uint128", "name": "remainingAmount", "type": "uint128" } + ], + "internalType": "struct LibNFTOrder.OrderInfo", + "name": "orderInfo", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "enum LibNFTOrder.TradeDirection", "name": "direction", "type": "uint8" }, + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "address", "name": "taker", "type": "address" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "contract IERC20TokenV06", "name": "erc20Token", "type": "address" }, + { "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { "internalType": "contract IERC721Token", "name": "erc721Token", "type": "address" }, + { "internalType": "uint256", "name": "erc721TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc721TokenProperties", + "type": "tuple[]" + } + ], + "internalType": "struct LibNFTOrder.ERC721Order", + "name": "order", + "type": "tuple" + } + ], + "name": "getERC721OrderHash", + "outputs": [{ "internalType": "bytes32", "name": "orderHash", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "enum LibNFTOrder.TradeDirection", "name": "direction", "type": "uint8" }, + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "address", "name": "taker", "type": "address" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "contract IERC20TokenV06", "name": "erc20Token", "type": "address" }, + { "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { "internalType": "contract IERC721Token", "name": "erc721Token", "type": "address" }, + { "internalType": "uint256", "name": "erc721TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc721TokenProperties", + "type": "tuple[]" + } + ], + "internalType": "struct LibNFTOrder.ERC721Order", + "name": "order", + "type": "tuple" + } + ], + "name": "getERC721OrderStatus", + "outputs": [{ "internalType": "enum LibNFTOrder.OrderStatus", "name": "status", "type": "uint8" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "uint248", "name": "nonceRange", "type": "uint248" } + ], + "name": "getERC721OrderStatusBitVector", + "outputs": [{ "internalType": "uint256", "name": "bitVector", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -1772,6 +2583,122 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "components": [ + { "internalType": "enum LibNFTOrder.TradeDirection", "name": "direction", "type": "uint8" }, + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "address", "name": "taker", "type": "address" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "contract IERC20TokenV06", "name": "erc20Token", "type": "address" }, + { "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { "internalType": "contract IERC721Token", "name": "erc721Token", "type": "address" }, + { "internalType": "uint256", "name": "erc721TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc721TokenProperties", + "type": "tuple[]" + } + ], + "internalType": "struct LibNFTOrder.ERC721Order", + "name": "sellOrder", + "type": "tuple" + }, + { + "components": [ + { "internalType": "enum LibNFTOrder.TradeDirection", "name": "direction", "type": "uint8" }, + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "address", "name": "taker", "type": "address" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "contract IERC20TokenV06", "name": "erc20Token", "type": "address" }, + { "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { "internalType": "contract IERC721Token", "name": "erc721Token", "type": "address" }, + { "internalType": "uint256", "name": "erc721TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc721TokenProperties", + "type": "tuple[]" + } + ], + "internalType": "struct LibNFTOrder.ERC721Order", + "name": "buyOrder", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "enum LibSignature.SignatureType", + "name": "signatureType", + "type": "uint8" + }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "internalType": "struct LibSignature.Signature", + "name": "sellOrderSignature", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "enum LibSignature.SignatureType", + "name": "signatureType", + "type": "uint8" + }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "internalType": "struct LibSignature.Signature", + "name": "buyOrderSignature", + "type": "tuple" + } + ], + "name": "matchERC721Orders", + "outputs": [{ "internalType": "uint256", "name": "profit", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { "internalType": "address", "name": "target", "type": "address" }, @@ -1929,6 +2856,31 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { "internalType": "address", "name": "operator", "type": "address" }, + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "internalType": "uint256", "name": "value", "type": "uint256" }, + { "internalType": "bytes", "name": "data", "type": "bytes" } + ], + "name": "onERC1155Received", + "outputs": [{ "internalType": "bytes4", "name": "success", "type": "bytes4" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "operator", "type": "address" }, + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "internalType": "bytes", "name": "data", "type": "bytes" } + ], + "name": "onERC721Received", + "outputs": [{ "internalType": "bytes4", "name": "success", "type": "bytes4" }], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [], "name": "owner", @@ -1936,6 +2888,101 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "components": [ + { "internalType": "enum LibNFTOrder.TradeDirection", "name": "direction", "type": "uint8" }, + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "address", "name": "taker", "type": "address" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "contract IERC20TokenV06", "name": "erc20Token", "type": "address" }, + { "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { "internalType": "contract IERC1155Token", "name": "erc1155Token", "type": "address" }, + { "internalType": "uint256", "name": "erc1155TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc1155TokenProperties", + "type": "tuple[]" + }, + { "internalType": "uint128", "name": "erc1155TokenAmount", "type": "uint128" } + ], + "internalType": "struct LibNFTOrder.ERC1155Order", + "name": "order", + "type": "tuple" + } + ], + "name": "preSignERC1155Order", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "enum LibNFTOrder.TradeDirection", "name": "direction", "type": "uint8" }, + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "address", "name": "taker", "type": "address" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "contract IERC20TokenV06", "name": "erc20Token", "type": "address" }, + { "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { "internalType": "contract IERC721Token", "name": "erc721Token", "type": "address" }, + { "internalType": "uint256", "name": "erc721TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc721TokenProperties", + "type": "tuple[]" + } + ], + "internalType": "struct LibNFTOrder.ERC721Order", + "name": "order", + "type": "tuple" + } + ], + "name": "preSignERC721Order", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { "internalType": "address", "name": "signer", "type": "address" }, @@ -1966,6 +3013,138 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "components": [ + { "internalType": "enum LibNFTOrder.TradeDirection", "name": "direction", "type": "uint8" }, + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "address", "name": "taker", "type": "address" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "contract IERC20TokenV06", "name": "erc20Token", "type": "address" }, + { "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { "internalType": "contract IERC1155Token", "name": "erc1155Token", "type": "address" }, + { "internalType": "uint256", "name": "erc1155TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc1155TokenProperties", + "type": "tuple[]" + }, + { "internalType": "uint128", "name": "erc1155TokenAmount", "type": "uint128" } + ], + "internalType": "struct LibNFTOrder.ERC1155Order", + "name": "buyOrder", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "enum LibSignature.SignatureType", + "name": "signatureType", + "type": "uint8" + }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "internalType": "struct LibSignature.Signature", + "name": "signature", + "type": "tuple" + }, + { "internalType": "uint256", "name": "erc1155TokenId", "type": "uint256" }, + { "internalType": "uint128", "name": "erc1155SellAmount", "type": "uint128" }, + { "internalType": "bool", "name": "unwrapNativeToken", "type": "bool" }, + { "internalType": "bytes", "name": "callbackData", "type": "bytes" } + ], + "name": "sellERC1155", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "enum LibNFTOrder.TradeDirection", "name": "direction", "type": "uint8" }, + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "address", "name": "taker", "type": "address" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "contract IERC20TokenV06", "name": "erc20Token", "type": "address" }, + { "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { "internalType": "contract IERC721Token", "name": "erc721Token", "type": "address" }, + { "internalType": "uint256", "name": "erc721TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc721TokenProperties", + "type": "tuple[]" + } + ], + "internalType": "struct LibNFTOrder.ERC721Order", + "name": "buyOrder", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "enum LibSignature.SignatureType", + "name": "signatureType", + "type": "uint8" + }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "internalType": "struct LibSignature.Signature", + "name": "signature", + "type": "tuple" + }, + { "internalType": "uint256", "name": "erc721TokenId", "type": "uint256" }, + { "internalType": "bool", "name": "unwrapNativeToken", "type": "bool" }, + { "internalType": "bytes", "name": "callbackData", "type": "bytes" } + ], + "name": "sellERC721", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { "internalType": "bytes", "name": "encodedPath", "type": "bytes" }, @@ -2054,6 +3233,13 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [{ "internalType": "bytes4", "name": "interfaceId", "type": "bytes4" }], + "name": "supportInterface", + "outputs": [{ "internalType": "bool", "name": "isSupported", "type": "bool" }], + "stateMutability": "pure", + "type": "function" + }, { "inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }], "name": "transferOwnership", @@ -2068,6 +3254,17 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { "internalType": "contract IERC20TokenV06", "name": "erc20", "type": "address" }, + { "internalType": "uint256", "name": "amountOut", "type": "uint256" }, + { "internalType": "address payable", "name": "recipientWallet", "type": "address" } + ], + "name": "transferTrappedTokensTo", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { "internalType": "contract IERC20TokenV06", "name": "inputToken", "type": "address" }, @@ -2099,6 +3296,228 @@ "outputs": [], "stateMutability": "nonpayable", "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "enum LibNFTOrder.TradeDirection", "name": "direction", "type": "uint8" }, + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "address", "name": "taker", "type": "address" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "contract IERC20TokenV06", "name": "erc20Token", "type": "address" }, + { "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { "internalType": "contract IERC1155Token", "name": "erc1155Token", "type": "address" }, + { "internalType": "uint256", "name": "erc1155TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc1155TokenProperties", + "type": "tuple[]" + }, + { "internalType": "uint128", "name": "erc1155TokenAmount", "type": "uint128" } + ], + "internalType": "struct LibNFTOrder.ERC1155Order", + "name": "order", + "type": "tuple" + }, + { "internalType": "uint256", "name": "erc1155TokenId", "type": "uint256" } + ], + "name": "validateERC1155OrderProperties", + "outputs": [], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "enum LibNFTOrder.TradeDirection", "name": "direction", "type": "uint8" }, + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "address", "name": "taker", "type": "address" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "contract IERC20TokenV06", "name": "erc20Token", "type": "address" }, + { "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { "internalType": "contract IERC1155Token", "name": "erc1155Token", "type": "address" }, + { "internalType": "uint256", "name": "erc1155TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc1155TokenProperties", + "type": "tuple[]" + }, + { "internalType": "uint128", "name": "erc1155TokenAmount", "type": "uint128" } + ], + "internalType": "struct LibNFTOrder.ERC1155Order", + "name": "order", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "enum LibSignature.SignatureType", + "name": "signatureType", + "type": "uint8" + }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "internalType": "struct LibSignature.Signature", + "name": "signature", + "type": "tuple" + } + ], + "name": "validateERC1155OrderSignature", + "outputs": [], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "enum LibNFTOrder.TradeDirection", "name": "direction", "type": "uint8" }, + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "address", "name": "taker", "type": "address" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "contract IERC20TokenV06", "name": "erc20Token", "type": "address" }, + { "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { "internalType": "contract IERC721Token", "name": "erc721Token", "type": "address" }, + { "internalType": "uint256", "name": "erc721TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc721TokenProperties", + "type": "tuple[]" + } + ], + "internalType": "struct LibNFTOrder.ERC721Order", + "name": "order", + "type": "tuple" + }, + { "internalType": "uint256", "name": "erc721TokenId", "type": "uint256" } + ], + "name": "validateERC721OrderProperties", + "outputs": [], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "enum LibNFTOrder.TradeDirection", "name": "direction", "type": "uint8" }, + { "internalType": "address", "name": "maker", "type": "address" }, + { "internalType": "address", "name": "taker", "type": "address" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "uint256", "name": "nonce", "type": "uint256" }, + { "internalType": "contract IERC20TokenV06", "name": "erc20Token", "type": "address" }, + { "internalType": "uint256", "name": "erc20TokenAmount", "type": "uint256" }, + { + "components": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "feeData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Fee[]", + "name": "fees", + "type": "tuple[]" + }, + { "internalType": "contract IERC721Token", "name": "erc721Token", "type": "address" }, + { "internalType": "uint256", "name": "erc721TokenId", "type": "uint256" }, + { + "components": [ + { + "internalType": "contract IPropertyValidator", + "name": "propertyValidator", + "type": "address" + }, + { "internalType": "bytes", "name": "propertyData", "type": "bytes" } + ], + "internalType": "struct LibNFTOrder.Property[]", + "name": "erc721TokenProperties", + "type": "tuple[]" + } + ], + "internalType": "struct LibNFTOrder.ERC721Order", + "name": "order", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "enum LibSignature.SignatureType", + "name": "signatureType", + "type": "uint8" + }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "internalType": "struct LibSignature.Signature", + "name": "signature", + "type": "tuple" + } + ], + "name": "validateERC721OrderSignature", + "outputs": [], + "stateMutability": "view", + "type": "function" } ], "devdoc": { @@ -2164,6 +3583,39 @@ "params": { "args": "A `TransformERC20Args` struct." }, "returns": { "outputTokenAmount": "The amount of `outputToken` received by the taker." } }, + "batchBuyERC1155s((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[],uint128)[],(uint8,uint8,bytes32,bytes32)[],uint128[],bytes[],bool)": { + "details": "Buys multiple ERC1155 assets by filling the given orders.", + "params": { + "callbackData": "The data (if any) to pass to the taker callback for each order. Refer to the `callbackData` parameter to for `buyERC1155`.", + "erc1155TokenAmounts": "The amounts of the ERC1155 assets to buy for each order.", + "revertIfIncomplete": "If true, reverts if this function fails to fill any individual order.", + "sellOrders": "The ERC1155 sell orders.", + "signatures": "The order signatures." + }, + "returns": { + "successes": "An array of booleans corresponding to whether each order in `orders` was successfully filled." + } + }, + "batchBuyERC721s((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[])[],(uint8,uint8,bytes32,bytes32)[],bytes[],bool)": { + "details": "Buys multiple ERC721 assets by filling the given orders.", + "params": { + "callbackData": "The data (if any) to pass to the taker callback for each order. Refer to the `callbackData` parameter to for `buyERC721`.", + "revertIfIncomplete": "If true, reverts if this function fails to fill any individual order.", + "sellOrders": "The ERC721 sell orders.", + "signatures": "The order signatures." + }, + "returns": { + "successes": "An array of booleans corresponding to whether each order in `orders` was successfully filled." + } + }, + "batchCancelERC1155Orders(uint256[])": { + "details": "Cancel multiple ERC1155 orders by their nonces. The caller should be the maker of the orders. Silently succeeds if an order with the same nonce has already been filled or cancelled.", + "params": { "orderNonces": "The order nonces." } + }, + "batchCancelERC721Orders(uint256[])": { + "details": "Cancel multiple ERC721 orders by their nonces. The caller should be the maker of the orders. Silently succeeds if an order with the same nonce has already been filled or cancelled.", + "params": { "orderNonces": "The order nonces." } + }, "batchCancelLimitOrders((address,address,uint128,uint128,uint128,address,address,address,address,bytes32,uint64,uint256)[])": { "details": "Cancel multiple limit orders. The caller must be the maker or a valid order signer. Silently succeeds if the order has already been cancelled.", "params": { "orders": "The limit orders." } @@ -2270,6 +3722,44 @@ "orderInfos": "Info about the orders." } }, + "batchMatchERC721Orders((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[])[],(uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[])[],(uint8,uint8,bytes32,bytes32)[],(uint8,uint8,bytes32,bytes32)[])": { + "details": "Matches pairs of complementary orders that have non-negative spreads. Each order is filled at their respective price, and the matcher receives a profit denominated in the ERC20 token.", + "params": { + "buyOrderSignatures": "Signatures for the buy orders.", + "buyOrders": "Orders buying ERC721 assets.", + "sellOrderSignatures": "Signatures for the sell orders.", + "sellOrders": "Orders selling ERC721 assets." + }, + "returns": { + "profits": "The amount of profit earned by the caller of this function for each pair of matched orders (denominated in the ERC20 token of the order pair).", + "successes": "An array of booleans corresponding to whether each pair of orders was successfully matched." + } + }, + "buyERC1155((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[],uint128),(uint8,uint8,bytes32,bytes32),uint128,bytes)": { + "details": "Buys an ERC1155 asset by filling the given order.", + "params": { + "callbackData": "If this parameter is non-zero, invokes `zeroExERC1155OrderCallback` on `msg.sender` after the ERC1155 asset has been transferred to `msg.sender` but before transferring the ERC20 tokens to the seller. Native tokens acquired during the callback can be used to fill the order.", + "erc1155BuyAmount": "The amount of the ERC1155 asset to buy.", + "sellOrder": "The ERC1155 sell order.", + "signature": "The order signature." + } + }, + "buyERC721((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[]),(uint8,uint8,bytes32,bytes32),bytes)": { + "details": "Buys an ERC721 asset by filling the given order.", + "params": { + "callbackData": "If this parameter is non-zero, invokes `zeroExERC721OrderCallback` on `msg.sender` after the ERC721 asset has been transferred to `msg.sender` but before transferring the ERC20 tokens to the seller. Native tokens acquired during the callback can be used to fill the order.", + "sellOrder": "The ERC721 sell order.", + "signature": "The order signature." + } + }, + "cancelERC1155Order(uint256)": { + "details": "Cancel a single ERC1155 order by its nonce. The caller should be the maker of the order. Silently succeeds if an order with the same nonce has already been filled or cancelled.", + "params": { "orderNonce": "The order nonce." } + }, + "cancelERC721Order(uint256)": { + "details": "Cancel a single ERC721 order by its nonce. The caller should be the maker of the order. Silently succeeds if an order with the same nonce has already been filled or cancelled.", + "params": { "orderNonce": "The order nonce." } + }, "cancelLimitOrder((address,address,uint128,uint128,uint128,address,address,address,address,bytes32,uint64,uint256))": { "details": "Cancel a single limit order. The caller must be the maker or a valid order signer. Silently succeeds if the order has already been cancelled.", "params": { "order": "The limit order." } @@ -2418,6 +3908,36 @@ "takerSignature": "The order signature from the taker." } }, + "getERC1155OrderHash((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[],uint128))": { + "details": "Get the EIP-712 hash of an ERC1155 order.", + "params": { "order": "The ERC1155 order." }, + "returns": { "orderHash": "The order hash." } + }, + "getERC1155OrderInfo((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[],uint128))": { + "details": "Get the order info for an ERC1155 order.", + "params": { "order": "The ERC1155 order." }, + "returns": { "orderInfo": "Infor about the order." } + }, + "getERC721OrderHash((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[]))": { + "details": "Get the EIP-712 hash of an ERC721 order.", + "params": { "order": "The ERC721 order." }, + "returns": { "orderHash": "The order hash." } + }, + "getERC721OrderStatus((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[]))": { + "details": "Get the current status of an ERC721 order.", + "params": { "order": "The ERC721 order." }, + "returns": { "status": "The status of the order." } + }, + "getERC721OrderStatusBitVector(address,uint248)": { + "details": "Get the order status bit vector for the given maker address and nonce range.", + "params": { + "maker": "The maker of the order.", + "nonceRange": "Order status bit vectors are indexed by maker address and the upper 248 bits of the order nonce. We define `nonceRange` to be these 248 bits." + }, + "returns": { + "bitVector": "The order status bit vector for the given maker and nonce range." + } + }, "getLimitOrderHash((address,address,uint128,uint128,uint128,address,address,address,address,bytes32,uint64,uint256))": { "details": "Get the canonical hash of a limit order.", "params": { "order": "The limit order." }, @@ -2521,6 +4041,18 @@ "params": { "nonceBucket": "The nonce bucket index.", "txOrigin": "The address." }, "returns": { "lastNonce": "The last nonce value used." } }, + "matchERC721Orders((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[]),(uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[]),(uint8,uint8,bytes32,bytes32),(uint8,uint8,bytes32,bytes32))": { + "details": "Matches a pair of complementary orders that have a non-negative spread. Each order is filled at their respective price, and the matcher receives a profit denominated in the ERC20 token.", + "params": { + "buyOrder": "Order buying an ERC721 asset.", + "buyOrderSignature": "Signature for the buy order.", + "sellOrder": "Order selling an ERC721 asset.", + "sellOrderSignature": "Signature for the sell order." + }, + "returns": { + "profit": "The amount of profit earned by the caller of this function (denominated in the ERC20 token of the matched orders)." + } + }, "migrate(address,bytes,address)": { "details": "Execute a migration function in the context of the ZeroEx contract. The result of the function being called should be the magic bytes 0x2c64c5ef (`keccack('MIGRATE_SUCCESS')`). Only callable by the owner. The owner will be temporarily set to `address(this)` inside the call. Before returning, the owner will be set to `newOwner`.", "params": { @@ -2586,10 +4118,43 @@ }, "returns": { "boughtAmount": "The amount of output tokens bought." } }, + "onERC1155Received(address,address,uint256,uint256,bytes)": { + "details": "Callback for the ERC1155 `safeTransferFrom` function. This callback can be used to sell an ERC1155 asset if a valid ERC1155 order, signature and `unwrapNativeToken` are encoded in `data`. This allows takers to sell their ERC1155 asset without first calling `setApprovalForAll`.", + "params": { + "data": "Additional data with no specified format. If a valid ERC1155 order, signature and `unwrapNativeToken` are encoded in `data`, this function will try to fill the order using the received asset.", + "from": "The address which previously owned the token.", + "operator": "The address which called `safeTransferFrom`.", + "tokenId": "The ID of the asset being transferred.", + "value": "The amount being transferred." + }, + "returns": { + "success": "The selector of this function (0xf23a6e61), indicating that the callback succeeded." + } + }, + "onERC721Received(address,address,uint256,bytes)": { + "details": "Callback for the ERC721 `safeTransferFrom` function. This callback can be used to sell an ERC721 asset if a valid ERC721 order, signature and `unwrapNativeToken` are encoded in `data`. This allows takers to sell their ERC721 asset without first calling `setApprovalForAll`.", + "params": { + "data": "Additional data with no specified format. If a valid ERC721 order, signature and `unwrapNativeToken` are encoded in `data`, this function will try to fill the order using the received asset.", + "from": "The address which previously owned the token.", + "operator": "The address which called `safeTransferFrom`.", + "tokenId": "The ID of the asset being transferred." + }, + "returns": { + "success": "The selector of this function (0x150b7a02), indicating that the callback succeeded." + } + }, "owner()": { "details": "The owner of this contract.", "returns": { "ownerAddress": "The owner address." } }, + "preSignERC1155Order((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[],uint128))": { + "details": "Approves an ERC1155 order on-chain. After pre-signing the order, the `PRESIGNED` signature type will become valid for that order and signer.", + "params": { "order": "An ERC1155 order." } + }, + "preSignERC721Order((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[]))": { + "details": "Approves an ERC721 order on-chain. After pre-signing the order, the `PRESIGNED` signature type will become valid for that order and signer.", + "params": { "order": "An ERC721 order." } + }, "registerAllowedOrderSigner(address,bool)": { "details": "Register a signer who can sign on behalf of msg.sender This allows one to sign on behalf of a contract that calls this function", "params": { @@ -2611,6 +4176,27 @@ "targetImpl": "The address of an older implementation of the function." } }, + "sellERC1155((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[],uint128),(uint8,uint8,bytes32,bytes32),uint256,uint128,bool,bytes)": { + "details": "Sells an ERC1155 asset to fill the given order.", + "params": { + "buyOrder": "The ERC1155 buy order.", + "callbackData": "If this parameter is non-zero, invokes `zeroExERC1155OrderCallback` on `msg.sender` after the ERC20 tokens have been transferred to `msg.sender` but before transferring the ERC1155 asset to the buyer.", + "erc1155SellAmount": "The amount of the ERC1155 asset to sell.", + "erc1155TokenId": "The ID of the ERC1155 asset being sold. If the given order specifies properties, the asset must satisfy those properties. Otherwise, it must equal the tokenId in the order.", + "signature": "The order signature from the maker.", + "unwrapNativeToken": "If this parameter is true and the ERC20 token of the order is e.g. WETH, unwraps the token before transferring it to the taker." + } + }, + "sellERC721((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[]),(uint8,uint8,bytes32,bytes32),uint256,bool,bytes)": { + "details": "Sells an ERC721 asset to fill the given order.", + "params": { + "buyOrder": "The ERC721 buy order.", + "callbackData": "If this parameter is non-zero, invokes `zeroExERC721OrderCallback` on `msg.sender` after the ERC20 tokens have been transferred to `msg.sender` but before transferring the ERC721 asset to the buyer.", + "erc721TokenId": "The ID of the ERC721 asset being sold. If the given order specifies properties, the asset must satisfy those properties. Otherwise, it must equal the tokenId in the order.", + "signature": "The order signature from the maker.", + "unwrapNativeToken": "If this parameter is true and the ERC20 token of the order is e.g. WETH, unwraps the token before transferring it to the taker." + } + }, "sellEthForTokenToUniswapV3(bytes,uint256,address)": { "details": "Sell attached ETH directly against uniswap v3.", "params": { @@ -2683,6 +4269,13 @@ "transformerDeployer": "The address of the new trusted deployer for transformers." } }, + "supportInterface(bytes4)": { + "details": "Indicates whether the 0x Exchange Proxy implements a particular ERC165 interface. This function should use at most 30,000 gas.", + "params": { "interfaceId": "The interface identifier, as specified in ERC165." }, + "returns": { + "isSupported": "Whether the given interface is supported by the 0x Exchange Proxy." + } + }, "transferOwnership(address)": { "details": "Transfers ownership of the contract to a new address.", "params": { "newOwner": "The address that will become the owner." } @@ -2691,6 +4284,14 @@ "details": "Transfers protocol fees from the `FeeCollector` pools into the staking contract.", "params": { "poolIds": "Staking pool IDs" } }, + "transferTrappedTokensTo(address,uint256,address)": { + "details": "calledFrom FundRecoveryFeature.transferTrappedTokensTo() This will be delegatecalled in the context of the Exchange Proxy instance being used.", + "params": { + "amountOut": "Amount of tokens to withdraw.", + "erc20": "ERC20 Token Address.", + "recipientWallet": "Recipient wallet address." + } + }, "transformERC20(address,address,uint256,uint256,(uint32,bytes)[])": { "details": "Executes a series of transformations to convert an ERC20 `inputToken` to an ERC20 `outputToken`.", "params": { @@ -2709,6 +4310,22 @@ "amount1Delta": "Token1 amount owed.", "data": "Arbitrary data forwarded from swap() caller. An ABI-encoded struct of: inputToken, outputToken, fee, payer" } + }, + "validateERC1155OrderProperties((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[],uint128),uint256)": { + "details": "If the given order is buying an ERC1155 asset, checks whether or not the given token ID satisfies the required properties specified in the order. If the order does not specify any properties, this function instead checks whether the given token ID matches the ID in the order. Reverts if any checks fail, or if the order is selling an ERC1155 asset.", + "params": { "erc1155TokenId": "The ID of the ERC1155 asset.", "order": "The ERC1155 order." } + }, + "validateERC1155OrderSignature((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[],uint128),(uint8,uint8,bytes32,bytes32))": { + "details": "Checks whether the given signature is valid for the the given ERC1155 order. Reverts if not.", + "params": { "order": "The ERC1155 order.", "signature": "The signature to validate." } + }, + "validateERC721OrderProperties((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[]),uint256)": { + "details": "If the given order is buying an ERC721 asset, checks whether or not the given token ID satisfies the required properties specified in the order. If the order does not specify any properties, this function instead checks whether the given token ID matches the ID in the order. Reverts if any checks fail, or if the order is selling an ERC721 asset.", + "params": { "erc721TokenId": "The ID of the ERC721 asset.", "order": "The ERC721 order." } + }, + "validateERC721OrderSignature((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[]),(uint8,uint8,bytes32,bytes32))": { + "details": "Checks whether the given signature is valid for the the given ERC721 order. Reverts if not.", + "params": { "order": "The ERC721 order.", "signature": "The signature to validate." } } }, "version": 1 diff --git a/packages/contract-artifacts/package.json b/packages/contract-artifacts/package.json index 33f17b8707..18e5dff1f2 100644 --- a/packages/contract-artifacts/package.json +++ b/packages/contract-artifacts/package.json @@ -30,7 +30,7 @@ }, "homepage": "https://github.com/0xProject/protocol/tree/main/packages/contract-artifacts", "devDependencies": { - "@0x/utils": "^6.4.4", + "@0x/utils": "^6.5.0", "@types/mocha": "^5.2.7", "chai": "^4.0.1", "lodash": "^4.17.11", diff --git a/packages/contract-wrappers/CHANGELOG.json b/packages/contract-wrappers/CHANGELOG.json index 304487b1b1..8fa103af9a 100644 --- a/packages/contract-wrappers/CHANGELOG.json +++ b/packages/contract-wrappers/CHANGELOG.json @@ -1,4 +1,17 @@ [ + { + "version": "13.19.0", + "changes": [ + { + "note": "Regenerate wrappers to add ContractTxFunctionObj.selector", + "pr": 429 + }, + { + "note": "Update IZeroEx wrapper", + "pr": 429 + } + ] + }, { "timestamp": 1640364306, "version": "13.18.5", diff --git a/packages/contract-wrappers/package.json b/packages/contract-wrappers/package.json index 6cef00869f..5c6d1008f6 100644 --- a/packages/contract-wrappers/package.json +++ b/packages/contract-wrappers/package.json @@ -55,13 +55,13 @@ "typescript": "4.2.2" }, "dependencies": { - "@0x/assert": "^3.0.29", - "@0x/base-contract": "^6.4.2", + "@0x/assert": "^3.0.31", + "@0x/base-contract": "^6.4.5", "@0x/contract-addresses": "^6.11.0", - "@0x/json-schemas": "^6.3.0", + "@0x/json-schemas": "^6.4.1", "@0x/types": "^3.3.4", - "@0x/utils": "^6.4.4", - "@0x/web3-wrapper": "^7.6.0", + "@0x/utils": "^6.5.0", + "@0x/web3-wrapper": "^7.6.2", "ethereum-types": "^3.6.0", "ethers": "~4.0.4" }, diff --git a/packages/contract-wrappers/src/generated-wrappers/broker.ts b/packages/contract-wrappers/src/generated-wrappers/broker.ts index 8057322899..63bb820a24 100644 --- a/packages/contract-wrappers/src/generated-wrappers/broker.ts +++ b/packages/contract-wrappers/src/generated-wrappers/broker.ts @@ -612,6 +612,7 @@ export class BrokerContract extends BaseContract { 'batchBrokerTrade(uint256[],(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256[],bytes[],bytes4,uint256[],address[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -754,6 +755,7 @@ export class BrokerContract extends BaseContract { 'brokerTrade(uint256[],(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),uint256,bytes,bytes4,uint256[],address[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -854,6 +856,7 @@ export class BrokerContract extends BaseContract { const functionSignature = 'safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, diff --git a/packages/contract-wrappers/src/generated-wrappers/coordinator.ts b/packages/contract-wrappers/src/generated-wrappers/coordinator.ts index e8b99b52ff..976e7a62b7 100644 --- a/packages/contract-wrappers/src/generated-wrappers/coordinator.ts +++ b/packages/contract-wrappers/src/generated-wrappers/coordinator.ts @@ -575,6 +575,7 @@ export class CoordinatorContract extends BaseContract { const functionSignature = 'EIP712_COORDINATOR_APPROVAL_SCHEMA_HASH()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -595,6 +596,7 @@ export class CoordinatorContract extends BaseContract { const functionSignature = 'EIP712_COORDINATOR_DOMAIN_HASH()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -615,6 +617,7 @@ export class CoordinatorContract extends BaseContract { const functionSignature = 'EIP712_COORDINATOR_DOMAIN_NAME()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -635,6 +638,7 @@ export class CoordinatorContract extends BaseContract { const functionSignature = 'EIP712_COORDINATOR_DOMAIN_VERSION()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -655,6 +659,7 @@ export class CoordinatorContract extends BaseContract { const functionSignature = 'EIP712_EXCHANGE_DOMAIN_HASH()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -703,6 +708,7 @@ export class CoordinatorContract extends BaseContract { 'assertValidCoordinatorApprovals((uint256,uint256,uint256,address,bytes),address,bytes,bytes[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -753,6 +759,7 @@ export class CoordinatorContract extends BaseContract { const functionSignature = 'decodeOrdersFromFillData(bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, @@ -842,6 +849,7 @@ export class CoordinatorContract extends BaseContract { const functionSignature = 'executeTransaction((uint256,uint256,uint256,address,bytes),address,bytes,bytes[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -915,6 +923,7 @@ export class CoordinatorContract extends BaseContract { const functionSignature = 'getCoordinatorApprovalHash((address,bytes32,bytes))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -943,6 +952,7 @@ export class CoordinatorContract extends BaseContract { const functionSignature = 'getSignerAddress(bytes32,bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); let rawCallResult; diff --git a/packages/contract-wrappers/src/generated-wrappers/dev_utils.ts b/packages/contract-wrappers/src/generated-wrappers/dev_utils.ts index b45be8fad7..8e2bd1329c 100644 --- a/packages/contract-wrappers/src/generated-wrappers/dev_utils.ts +++ b/packages/contract-wrappers/src/generated-wrappers/dev_utils.ts @@ -1592,6 +1592,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'EIP712_EXCHANGE_DOMAIN_HASH()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1612,6 +1613,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'chaiBridgeAddress()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1639,6 +1641,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'decodeAssetProxyId(bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); let rawCallResult; @@ -1673,6 +1676,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'decodeERC1155AssetData(bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, @@ -1709,6 +1713,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'decodeERC20AssetData(bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise<[string, string]> { BaseContract._assertCallParams(callData, defaultBlock); let rawCallResult; @@ -1741,6 +1746,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'decodeERC20BridgeAssetData(bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, @@ -1776,6 +1782,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'decodeERC721AssetData(bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, @@ -1810,6 +1817,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'decodeMultiAssetData(bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, @@ -1845,6 +1853,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'decodeStaticCallAssetData(bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, @@ -1904,6 +1913,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'decodeZeroExTransactionData(bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, @@ -1976,6 +1986,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'dydxBridgeAddress()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -2015,6 +2026,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'encodeERC1155AssetData(address,uint256[],uint256[],bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); let rawCallResult; @@ -2052,6 +2064,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'encodeERC20AssetData(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); let rawCallResult; @@ -2086,6 +2099,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'encodeERC721AssetData(address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); let rawCallResult; @@ -2120,6 +2134,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'encodeMultiAssetData(uint256[],bytes[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); let rawCallResult; @@ -2161,6 +2176,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'encodeStaticCallAssetData(address,bytes,bytes32)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); let rawCallResult; @@ -2190,6 +2206,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'erc1155ProxyAddress()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -2210,6 +2227,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'erc20ProxyAddress()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -2230,6 +2248,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'erc721ProxyAddress()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -2250,6 +2269,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'exchangeAddress()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -2279,6 +2299,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'getAssetProxyAllowance(address,bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -2344,6 +2365,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'getBalance(address,bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -2412,6 +2434,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'getBalanceAndAssetProxyAllowance(address,bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -2480,6 +2503,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'getBatchAssetProxyAllowances(address,bytes[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -2545,6 +2569,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'getBatchBalances(address,bytes[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -2613,6 +2638,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'getBatchBalancesAndAssetProxyAllowances(address,bytes[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -2678,6 +2704,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'getEthBalances(address[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -2721,6 +2748,7 @@ export class DevUtilsContract extends BaseContract { 'getOrderHash((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),uint256,address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); let rawCallResult; @@ -2777,6 +2805,7 @@ export class DevUtilsContract extends BaseContract { 'getOrderRelevantState((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -2879,6 +2908,7 @@ export class DevUtilsContract extends BaseContract { 'getOrderRelevantStates((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -2981,6 +3011,7 @@ export class DevUtilsContract extends BaseContract { 'getSimulatedOrderMakerTransferResults((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -3072,6 +3103,7 @@ export class DevUtilsContract extends BaseContract { 'getSimulatedOrderTransferResults((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -3164,6 +3196,7 @@ export class DevUtilsContract extends BaseContract { 'getSimulatedOrdersTransferResults((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],address[],uint256[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -3233,6 +3266,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'getTransactionHash((uint256,uint256,uint256,address,bytes),uint256,address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); let rawCallResult; @@ -3267,6 +3301,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'getTransferableAssetAmount(address,bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -3328,6 +3363,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'revertIfInvalidAssetData(bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); let rawCallResult; @@ -3353,6 +3389,7 @@ export class DevUtilsContract extends BaseContract { const functionSignature = 'staticCallProxyAddress()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( diff --git a/packages/contract-wrappers/src/generated-wrappers/erc20_token.ts b/packages/contract-wrappers/src/generated-wrappers/erc20_token.ts index 098a514390..d031f75745 100644 --- a/packages/contract-wrappers/src/generated-wrappers/erc20_token.ts +++ b/packages/contract-wrappers/src/generated-wrappers/erc20_token.ts @@ -425,6 +425,7 @@ export class ERC20TokenContract extends BaseContract { const functionSignature = 'allowance(address,address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -453,6 +454,7 @@ export class ERC20TokenContract extends BaseContract { const functionSignature = 'approve(address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -515,6 +517,7 @@ export class ERC20TokenContract extends BaseContract { const functionSignature = 'balanceOf(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -539,6 +542,7 @@ export class ERC20TokenContract extends BaseContract { const functionSignature = 'totalSupply()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -567,6 +571,7 @@ export class ERC20TokenContract extends BaseContract { const functionSignature = 'transfer(address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -633,6 +638,7 @@ export class ERC20TokenContract extends BaseContract { const functionSignature = 'transferFrom(address,address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, diff --git a/packages/contract-wrappers/src/generated-wrappers/erc721_token.ts b/packages/contract-wrappers/src/generated-wrappers/erc721_token.ts index bcb7156a5b..a76b0702d6 100644 --- a/packages/contract-wrappers/src/generated-wrappers/erc721_token.ts +++ b/packages/contract-wrappers/src/generated-wrappers/erc721_token.ts @@ -522,6 +522,7 @@ export class ERC721TokenContract extends BaseContract { const functionSignature = 'approve(address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -585,6 +586,7 @@ export class ERC721TokenContract extends BaseContract { const functionSignature = 'balanceOf(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -611,6 +613,7 @@ export class ERC721TokenContract extends BaseContract { const functionSignature = 'getApproved(uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -633,6 +636,7 @@ export class ERC721TokenContract extends BaseContract { const functionSignature = 'isApprovedForAll(address,address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -660,6 +664,7 @@ export class ERC721TokenContract extends BaseContract { const functionSignature = 'ownerOf(uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -690,6 +695,7 @@ export class ERC721TokenContract extends BaseContract { const functionSignature = 'safeTransferFrom(address,address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -772,6 +778,7 @@ export class ERC721TokenContract extends BaseContract { const functionSignature = 'safeTransferFrom(address,address,uint256,bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -841,6 +848,7 @@ export class ERC721TokenContract extends BaseContract { const functionSignature = 'setApprovalForAll(address,bool)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -909,6 +917,7 @@ export class ERC721TokenContract extends BaseContract { const functionSignature = 'transferFrom(address,address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, diff --git a/packages/contract-wrappers/src/generated-wrappers/exchange.ts b/packages/contract-wrappers/src/generated-wrappers/exchange.ts index 6c58927366..2d53396d96 100644 --- a/packages/contract-wrappers/src/generated-wrappers/exchange.ts +++ b/packages/contract-wrappers/src/generated-wrappers/exchange.ts @@ -3223,6 +3223,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'EIP1271_MAGIC_VALUE()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -3243,6 +3244,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'EIP712_EXCHANGE_DOMAIN_HASH()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -3265,6 +3267,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'allowedValidators(address,address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -3308,6 +3311,7 @@ export class ExchangeContract extends BaseContract { 'batchCancelOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -3382,6 +3386,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'batchExecuteTransactions((uint256,uint256,uint256,address,bytes)[],bytes[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -3477,6 +3482,7 @@ export class ExchangeContract extends BaseContract { 'batchFillOrKillOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256[],bytes[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -3591,6 +3597,7 @@ export class ExchangeContract extends BaseContract { 'batchFillOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256[],bytes[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -3705,6 +3712,7 @@ export class ExchangeContract extends BaseContract { 'batchFillOrdersNoThrow((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256[],bytes[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -3849,6 +3857,7 @@ export class ExchangeContract extends BaseContract { 'batchMatchOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[],bytes[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -4017,6 +4026,7 @@ export class ExchangeContract extends BaseContract { 'batchMatchOrdersWithMaximalFill((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[],bytes[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -4136,6 +4146,7 @@ export class ExchangeContract extends BaseContract { 'cancelOrder((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -4199,6 +4210,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'cancelOrdersUpTo(uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -4256,6 +4268,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'cancelled(bytes32)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -4276,6 +4289,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'currentContextAddress()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -4300,6 +4314,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'detachProtocolFeeCollector()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -4373,6 +4388,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'executeTransaction((uint256,uint256,uint256,address,bytes),bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -4465,6 +4481,7 @@ export class ExchangeContract extends BaseContract { 'fillOrKillOrder((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),uint256,bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -4572,6 +4589,7 @@ export class ExchangeContract extends BaseContract { 'fillOrder((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),uint256,bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -4644,6 +4662,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'filled(bytes32)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -4670,6 +4689,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'getAssetProxy(bytes4)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -4712,6 +4732,7 @@ export class ExchangeContract extends BaseContract { 'getOrderInfo((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, @@ -4749,6 +4770,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'isValidHashSignature(bytes32,address,bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -4796,6 +4818,7 @@ export class ExchangeContract extends BaseContract { 'isValidOrderSignature((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -4833,6 +4856,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'isValidTransactionSignature((uint256,uint256,uint256,address,bytes),bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -4890,6 +4914,7 @@ export class ExchangeContract extends BaseContract { 'marketBuyOrdersFillOrKill((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -4999,6 +5024,7 @@ export class ExchangeContract extends BaseContract { 'marketBuyOrdersNoThrow((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5107,6 +5133,7 @@ export class ExchangeContract extends BaseContract { 'marketSellOrdersFillOrKill((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5216,6 +5243,7 @@ export class ExchangeContract extends BaseContract { 'marketSellOrdersNoThrow((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5354,6 +5382,7 @@ export class ExchangeContract extends BaseContract { 'matchOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),bytes,bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5519,6 +5548,7 @@ export class ExchangeContract extends BaseContract { 'matchOrdersWithMaximalFill((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),bytes,bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5619,6 +5649,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'orderEpoch(address,address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -5639,6 +5670,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'owner()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -5665,6 +5697,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'preSign(bytes32)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5723,6 +5756,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'preSigned(bytes32,address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -5743,6 +5777,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'protocolFeeCollector()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -5763,6 +5798,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'protocolFeeMultiplier()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -5789,6 +5825,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'registerAssetProxy(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5851,6 +5888,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'setProtocolFeeCollectorAddress(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5912,6 +5950,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'setProtocolFeeMultiplier(uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5976,6 +6015,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'setSignatureValidatorApproval(address,bool)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -6053,6 +6093,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'simulateDispatchTransferFromCalls(bytes[],address[],address[],uint256[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -6110,6 +6151,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'transactionsExecuted(bytes32)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -6135,6 +6177,7 @@ export class ExchangeContract extends BaseContract { const functionSignature = 'transferOwnership(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, diff --git a/packages/contract-wrappers/src/generated-wrappers/forwarder.ts b/packages/contract-wrappers/src/generated-wrappers/forwarder.ts index 70b6380ccc..d0dd9c4235 100644 --- a/packages/contract-wrappers/src/generated-wrappers/forwarder.ts +++ b/packages/contract-wrappers/src/generated-wrappers/forwarder.ts @@ -775,6 +775,7 @@ export class ForwarderContract extends BaseContract { const functionSignature = 'ERC1155_BATCH_RECEIVED()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -795,6 +796,7 @@ export class ForwarderContract extends BaseContract { const functionSignature = 'ERC1155_RECEIVED()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -815,6 +817,7 @@ export class ForwarderContract extends BaseContract { const functionSignature = 'EXCHANGE_V2_ORDER_ID()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -844,6 +847,7 @@ export class ForwarderContract extends BaseContract { const functionSignature = 'approveMakerAssetProxy(bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -941,6 +945,7 @@ export class ForwarderContract extends BaseContract { 'marketBuyOrdersWithEth((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[],uint256[],address[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -1045,6 +1050,7 @@ export class ForwarderContract extends BaseContract { 'marketSellAmountWithEth((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[],uint256[],address[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -1146,6 +1152,7 @@ export class ForwarderContract extends BaseContract { 'marketSellOrdersWithEth((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[],uint256[],address[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -1230,6 +1237,7 @@ export class ForwarderContract extends BaseContract { const functionSignature = 'onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -1312,6 +1320,7 @@ export class ForwarderContract extends BaseContract { const functionSignature = 'onERC1155Received(address,address,uint256,uint256,bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -1374,6 +1383,7 @@ export class ForwarderContract extends BaseContract { const functionSignature = 'owner()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1399,6 +1409,7 @@ export class ForwarderContract extends BaseContract { const functionSignature = 'transferOwnership(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -1463,6 +1474,7 @@ export class ForwarderContract extends BaseContract { const functionSignature = 'withdrawAsset(bytes,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, diff --git a/packages/contract-wrappers/src/generated-wrappers/gods_unchained_validator.ts b/packages/contract-wrappers/src/generated-wrappers/gods_unchained_validator.ts index f7daedaa51..37d29324ce 100644 --- a/packages/contract-wrappers/src/generated-wrappers/gods_unchained_validator.ts +++ b/packages/contract-wrappers/src/generated-wrappers/gods_unchained_validator.ts @@ -286,6 +286,7 @@ export class GodsUnchainedValidatorContract extends BaseContract { const functionSignature = 'checkBrokerAsset(uint256,bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( diff --git a/packages/contract-wrappers/src/generated-wrappers/i_asset_data.ts b/packages/contract-wrappers/src/generated-wrappers/i_asset_data.ts index 29ced34de6..774406b70a 100644 --- a/packages/contract-wrappers/src/generated-wrappers/i_asset_data.ts +++ b/packages/contract-wrappers/src/generated-wrappers/i_asset_data.ts @@ -365,6 +365,7 @@ export class IAssetDataContract extends BaseContract { const functionSignature = 'ERC1155Assets(address,uint256[],uint256[],bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -435,6 +436,7 @@ export class IAssetDataContract extends BaseContract { const functionSignature = 'ERC20Bridge(address,address,bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -500,6 +502,7 @@ export class IAssetDataContract extends BaseContract { const functionSignature = 'ERC20Token(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -563,6 +566,7 @@ export class IAssetDataContract extends BaseContract { const functionSignature = 'ERC721Token(address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -629,6 +633,7 @@ export class IAssetDataContract extends BaseContract { const functionSignature = 'MultiAsset(uint256[],bytes[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -700,6 +705,7 @@ export class IAssetDataContract extends BaseContract { const functionSignature = 'StaticCall(address,bytes,bytes32)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, diff --git a/packages/contract-wrappers/src/generated-wrappers/i_liquidity_provider.ts b/packages/contract-wrappers/src/generated-wrappers/i_liquidity_provider.ts index 74cb067aa3..273b4c9fb7 100644 --- a/packages/contract-wrappers/src/generated-wrappers/i_liquidity_provider.ts +++ b/packages/contract-wrappers/src/generated-wrappers/i_liquidity_provider.ts @@ -347,6 +347,7 @@ export class ILiquidityProviderContract extends BaseContract { const functionSignature = 'bridgeTransferFrom(address,address,address,uint256,bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -420,6 +421,7 @@ export class ILiquidityProviderContract extends BaseContract { const functionSignature = 'getBuyQuote(address,address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -455,6 +457,7 @@ export class ILiquidityProviderContract extends BaseContract { const functionSignature = 'getSellQuote(address,address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( diff --git a/packages/contract-wrappers/src/generated-wrappers/i_transform_erc20.ts b/packages/contract-wrappers/src/generated-wrappers/i_transform_erc20.ts index 4acb53c396..7a0676362d 100644 --- a/packages/contract-wrappers/src/generated-wrappers/i_transform_erc20.ts +++ b/packages/contract-wrappers/src/generated-wrappers/i_transform_erc20.ts @@ -506,6 +506,7 @@ export class ITransformERC20Contract extends BaseContract { '_transformERC20((address,address,address,uint256,uint256,(uint32,bytes)[],bool,address))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -567,6 +568,7 @@ export class ITransformERC20Contract extends BaseContract { const functionSignature = 'createTransformWallet()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -626,6 +628,7 @@ export class ITransformERC20Contract extends BaseContract { const functionSignature = 'getQuoteSigner()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -686,6 +689,7 @@ export class ITransformERC20Contract extends BaseContract { const functionSignature = 'getTransformWallet()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -745,6 +749,7 @@ export class ITransformERC20Contract extends BaseContract { const functionSignature = 'getTransformerDeployer()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -807,6 +812,7 @@ export class ITransformERC20Contract extends BaseContract { const functionSignature = 'setQuoteSigner(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -870,6 +876,7 @@ export class ITransformERC20Contract extends BaseContract { const functionSignature = 'setTransformerDeployer(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -950,6 +957,7 @@ export class ITransformERC20Contract extends BaseContract { const functionSignature = 'transformERC20(address,address,uint256,uint256,(uint32,bytes)[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, diff --git a/packages/contract-wrappers/src/generated-wrappers/i_zero_ex.ts b/packages/contract-wrappers/src/generated-wrappers/i_zero_ex.ts index 7525199c92..ea04af9b83 100644 --- a/packages/contract-wrappers/src/generated-wrappers/i_zero_ex.ts +++ b/packages/contract-wrappers/src/generated-wrappers/i_zero_ex.ts @@ -38,6 +38,12 @@ import * as ethers from 'ethers'; // tslint:enable:no-unused-variable export type IZeroExEventArgs = + | IZeroExERC1155OrderCancelledEventArgs + | IZeroExERC1155OrderFilledEventArgs + | IZeroExERC1155OrderPreSignedEventArgs + | IZeroExERC721OrderCancelledEventArgs + | IZeroExERC721OrderFilledEventArgs + | IZeroExERC721OrderPreSignedEventArgs | IZeroExLimitOrderFilledEventArgs | IZeroExLiquidityProviderSwapEventArgs | IZeroExMetaTransactionExecutedEventArgs @@ -56,6 +62,12 @@ export type IZeroExEventArgs = | IZeroExTransformerDeployerUpdatedEventArgs; export enum IZeroExEvents { + ERC1155OrderCancelled = 'ERC1155OrderCancelled', + ERC1155OrderFilled = 'ERC1155OrderFilled', + ERC1155OrderPreSigned = 'ERC1155OrderPreSigned', + ERC721OrderCancelled = 'ERC721OrderCancelled', + ERC721OrderFilled = 'ERC721OrderFilled', + ERC721OrderPreSigned = 'ERC721OrderPreSigned', LimitOrderFilled = 'LimitOrderFilled', LiquidityProviderSwap = 'LiquidityProviderSwap', MetaTransactionExecuted = 'MetaTransactionExecuted', @@ -74,6 +86,70 @@ export enum IZeroExEvents { TransformerDeployerUpdated = 'TransformerDeployerUpdated', } +export interface IZeroExERC1155OrderCancelledEventArgs extends DecodedLogArgs { + maker: string; + nonce: BigNumber; +} + +export interface IZeroExERC1155OrderFilledEventArgs extends DecodedLogArgs { + direction: number; + maker: string; + taker: string; + nonce: BigNumber; + erc20Token: string; + erc20FillAmount: BigNumber; + erc1155Token: string; + erc1155TokenId: BigNumber; + erc1155FillAmount: BigNumber; + matcher: string; +} + +export interface IZeroExERC1155OrderPreSignedEventArgs extends DecodedLogArgs { + direction: number; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc1155Token: string; + erc1155TokenId: BigNumber; + erc1155TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + erc1155TokenAmount: BigNumber; +} + +export interface IZeroExERC721OrderCancelledEventArgs extends DecodedLogArgs { + maker: string; + nonce: BigNumber; +} + +export interface IZeroExERC721OrderFilledEventArgs extends DecodedLogArgs { + direction: number; + maker: string; + taker: string; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + erc721Token: string; + erc721TokenId: BigNumber; + matcher: string; +} + +export interface IZeroExERC721OrderPreSignedEventArgs extends DecodedLogArgs { + direction: number; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc721Token: string; + erc721TokenId: BigNumber; + erc721TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; +} + export interface IZeroExLimitOrderFilledEventArgs extends DecodedLogArgs { orderHash: string; maker: string; @@ -294,6 +370,332 @@ export class IZeroExContract extends BaseContract { */ public static ABI(): ContractAbi { const abi = [ + { + anonymous: false, + inputs: [ + { + name: 'maker', + type: 'address', + indexed: false, + }, + { + name: 'nonce', + type: 'uint256', + indexed: false, + }, + ], + name: 'ERC1155OrderCancelled', + outputs: [], + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + name: 'direction', + type: 'uint8', + indexed: false, + }, + { + name: 'maker', + type: 'address', + indexed: false, + }, + { + name: 'taker', + type: 'address', + indexed: false, + }, + { + name: 'nonce', + type: 'uint256', + indexed: false, + }, + { + name: 'erc20Token', + type: 'address', + indexed: false, + }, + { + name: 'erc20FillAmount', + type: 'uint256', + indexed: false, + }, + { + name: 'erc1155Token', + type: 'address', + indexed: false, + }, + { + name: 'erc1155TokenId', + type: 'uint256', + indexed: false, + }, + { + name: 'erc1155FillAmount', + type: 'uint128', + indexed: false, + }, + { + name: 'matcher', + type: 'address', + indexed: false, + }, + ], + name: 'ERC1155OrderFilled', + outputs: [], + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + name: 'direction', + type: 'uint8', + indexed: false, + }, + { + name: 'maker', + type: 'address', + indexed: false, + }, + { + name: 'taker', + type: 'address', + indexed: false, + }, + { + name: 'expiry', + type: 'uint256', + indexed: false, + }, + { + name: 'nonce', + type: 'uint256', + indexed: false, + }, + { + name: 'erc20Token', + type: 'address', + indexed: false, + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + indexed: false, + }, + { + name: 'fees', + type: 'tuple[]', + indexed: false, + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc1155Token', + type: 'address', + indexed: false, + }, + { + name: 'erc1155TokenId', + type: 'uint256', + indexed: false, + }, + { + name: 'erc1155TokenProperties', + type: 'tuple[]', + indexed: false, + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + { + name: 'erc1155TokenAmount', + type: 'uint128', + indexed: false, + }, + ], + name: 'ERC1155OrderPreSigned', + outputs: [], + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + name: 'maker', + type: 'address', + indexed: false, + }, + { + name: 'nonce', + type: 'uint256', + indexed: false, + }, + ], + name: 'ERC721OrderCancelled', + outputs: [], + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + name: 'direction', + type: 'uint8', + indexed: false, + }, + { + name: 'maker', + type: 'address', + indexed: false, + }, + { + name: 'taker', + type: 'address', + indexed: false, + }, + { + name: 'nonce', + type: 'uint256', + indexed: false, + }, + { + name: 'erc20Token', + type: 'address', + indexed: false, + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + indexed: false, + }, + { + name: 'erc721Token', + type: 'address', + indexed: false, + }, + { + name: 'erc721TokenId', + type: 'uint256', + indexed: false, + }, + { + name: 'matcher', + type: 'address', + indexed: false, + }, + ], + name: 'ERC721OrderFilled', + outputs: [], + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + name: 'direction', + type: 'uint8', + indexed: false, + }, + { + name: 'maker', + type: 'address', + indexed: false, + }, + { + name: 'taker', + type: 'address', + indexed: false, + }, + { + name: 'expiry', + type: 'uint256', + indexed: false, + }, + { + name: 'nonce', + type: 'uint256', + indexed: false, + }, + { + name: 'erc20Token', + type: 'address', + indexed: false, + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + indexed: false, + }, + { + name: 'fees', + type: 'tuple[]', + indexed: false, + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc721Token', + type: 'address', + indexed: false, + }, + { + name: 'erc721TokenId', + type: 'uint256', + indexed: false, + }, + { + name: 'erc721TokenProperties', + type: 'tuple[]', + indexed: false, + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + ], + name: 'ERC721OrderPreSigned', + outputs: [], + type: 'event', + }, { anonymous: false, inputs: [ @@ -1146,6 +1548,272 @@ export class IZeroExContract extends BaseContract { stateMutability: 'payable', type: 'function', }, + { + inputs: [ + { + name: 'sellOrders', + type: 'tuple[]', + components: [ + { + name: 'direction', + type: 'uint8', + }, + { + name: 'maker', + type: 'address', + }, + { + name: 'taker', + type: 'address', + }, + { + name: 'expiry', + type: 'uint256', + }, + { + name: 'nonce', + type: 'uint256', + }, + { + name: 'erc20Token', + type: 'address', + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + }, + { + name: 'fees', + type: 'tuple[]', + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc1155Token', + type: 'address', + }, + { + name: 'erc1155TokenId', + type: 'uint256', + }, + { + name: 'erc1155TokenProperties', + type: 'tuple[]', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + { + name: 'erc1155TokenAmount', + type: 'uint128', + }, + ], + }, + { + name: 'signatures', + type: 'tuple[]', + components: [ + { + name: 'signatureType', + type: 'uint8', + }, + { + name: 'v', + type: 'uint8', + }, + { + name: 'r', + type: 'bytes32', + }, + { + name: 's', + type: 'bytes32', + }, + ], + }, + { + name: 'erc1155TokenAmounts', + type: 'uint128[]', + }, + { + name: 'callbackData', + type: 'bytes[]', + }, + { + name: 'revertIfIncomplete', + type: 'bool', + }, + ], + name: 'batchBuyERC1155s', + outputs: [ + { + name: 'successes', + type: 'bool[]', + }, + ], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + name: 'sellOrders', + type: 'tuple[]', + components: [ + { + name: 'direction', + type: 'uint8', + }, + { + name: 'maker', + type: 'address', + }, + { + name: 'taker', + type: 'address', + }, + { + name: 'expiry', + type: 'uint256', + }, + { + name: 'nonce', + type: 'uint256', + }, + { + name: 'erc20Token', + type: 'address', + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + }, + { + name: 'fees', + type: 'tuple[]', + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc721Token', + type: 'address', + }, + { + name: 'erc721TokenId', + type: 'uint256', + }, + { + name: 'erc721TokenProperties', + type: 'tuple[]', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + ], + }, + { + name: 'signatures', + type: 'tuple[]', + components: [ + { + name: 'signatureType', + type: 'uint8', + }, + { + name: 'v', + type: 'uint8', + }, + { + name: 'r', + type: 'bytes32', + }, + { + name: 's', + type: 'bytes32', + }, + ], + }, + { + name: 'callbackData', + type: 'bytes[]', + }, + { + name: 'revertIfIncomplete', + type: 'bool', + }, + ], + name: 'batchBuyERC721s', + outputs: [ + { + name: 'successes', + type: 'bool[]', + }, + ], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + name: 'orderNonces', + type: 'uint256[]', + }, + ], + name: 'batchCancelERC1155Orders', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + name: 'orderNonces', + type: 'uint256[]', + }, + ], + name: 'batchCancelERC721Orders', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, { inputs: [ { @@ -1938,6 +2606,463 @@ export class IZeroExContract extends BaseContract { stateMutability: 'view', type: 'function', }, + { + inputs: [ + { + name: 'sellOrders', + type: 'tuple[]', + components: [ + { + name: 'direction', + type: 'uint8', + }, + { + name: 'maker', + type: 'address', + }, + { + name: 'taker', + type: 'address', + }, + { + name: 'expiry', + type: 'uint256', + }, + { + name: 'nonce', + type: 'uint256', + }, + { + name: 'erc20Token', + type: 'address', + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + }, + { + name: 'fees', + type: 'tuple[]', + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc721Token', + type: 'address', + }, + { + name: 'erc721TokenId', + type: 'uint256', + }, + { + name: 'erc721TokenProperties', + type: 'tuple[]', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + ], + }, + { + name: 'buyOrders', + type: 'tuple[]', + components: [ + { + name: 'direction', + type: 'uint8', + }, + { + name: 'maker', + type: 'address', + }, + { + name: 'taker', + type: 'address', + }, + { + name: 'expiry', + type: 'uint256', + }, + { + name: 'nonce', + type: 'uint256', + }, + { + name: 'erc20Token', + type: 'address', + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + }, + { + name: 'fees', + type: 'tuple[]', + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc721Token', + type: 'address', + }, + { + name: 'erc721TokenId', + type: 'uint256', + }, + { + name: 'erc721TokenProperties', + type: 'tuple[]', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + ], + }, + { + name: 'sellOrderSignatures', + type: 'tuple[]', + components: [ + { + name: 'signatureType', + type: 'uint8', + }, + { + name: 'v', + type: 'uint8', + }, + { + name: 'r', + type: 'bytes32', + }, + { + name: 's', + type: 'bytes32', + }, + ], + }, + { + name: 'buyOrderSignatures', + type: 'tuple[]', + components: [ + { + name: 'signatureType', + type: 'uint8', + }, + { + name: 'v', + type: 'uint8', + }, + { + name: 'r', + type: 'bytes32', + }, + { + name: 's', + type: 'bytes32', + }, + ], + }, + ], + name: 'batchMatchERC721Orders', + outputs: [ + { + name: 'profits', + type: 'uint256[]', + }, + { + name: 'successes', + type: 'bool[]', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + name: 'sellOrder', + type: 'tuple', + components: [ + { + name: 'direction', + type: 'uint8', + }, + { + name: 'maker', + type: 'address', + }, + { + name: 'taker', + type: 'address', + }, + { + name: 'expiry', + type: 'uint256', + }, + { + name: 'nonce', + type: 'uint256', + }, + { + name: 'erc20Token', + type: 'address', + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + }, + { + name: 'fees', + type: 'tuple[]', + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc1155Token', + type: 'address', + }, + { + name: 'erc1155TokenId', + type: 'uint256', + }, + { + name: 'erc1155TokenProperties', + type: 'tuple[]', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + { + name: 'erc1155TokenAmount', + type: 'uint128', + }, + ], + }, + { + name: 'signature', + type: 'tuple', + components: [ + { + name: 'signatureType', + type: 'uint8', + }, + { + name: 'v', + type: 'uint8', + }, + { + name: 'r', + type: 'bytes32', + }, + { + name: 's', + type: 'bytes32', + }, + ], + }, + { + name: 'erc1155BuyAmount', + type: 'uint128', + }, + { + name: 'callbackData', + type: 'bytes', + }, + ], + name: 'buyERC1155', + outputs: [], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + name: 'sellOrder', + type: 'tuple', + components: [ + { + name: 'direction', + type: 'uint8', + }, + { + name: 'maker', + type: 'address', + }, + { + name: 'taker', + type: 'address', + }, + { + name: 'expiry', + type: 'uint256', + }, + { + name: 'nonce', + type: 'uint256', + }, + { + name: 'erc20Token', + type: 'address', + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + }, + { + name: 'fees', + type: 'tuple[]', + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc721Token', + type: 'address', + }, + { + name: 'erc721TokenId', + type: 'uint256', + }, + { + name: 'erc721TokenProperties', + type: 'tuple[]', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + ], + }, + { + name: 'signature', + type: 'tuple', + components: [ + { + name: 'signatureType', + type: 'uint8', + }, + { + name: 'v', + type: 'uint8', + }, + { + name: 'r', + type: 'bytes32', + }, + { + name: 's', + type: 'bytes32', + }, + ], + }, + { + name: 'callbackData', + type: 'bytes', + }, + ], + name: 'buyERC721', + outputs: [], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + name: 'orderNonce', + type: 'uint256', + }, + ], + name: 'cancelERC1155Order', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + name: 'orderNonce', + type: 'uint256', + }, + ], + name: 'cancelERC721Order', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, { inputs: [ { @@ -3034,6 +4159,401 @@ export class IZeroExContract extends BaseContract { stateMutability: 'nonpayable', type: 'function', }, + { + inputs: [ + { + name: 'order', + type: 'tuple', + components: [ + { + name: 'direction', + type: 'uint8', + }, + { + name: 'maker', + type: 'address', + }, + { + name: 'taker', + type: 'address', + }, + { + name: 'expiry', + type: 'uint256', + }, + { + name: 'nonce', + type: 'uint256', + }, + { + name: 'erc20Token', + type: 'address', + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + }, + { + name: 'fees', + type: 'tuple[]', + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc1155Token', + type: 'address', + }, + { + name: 'erc1155TokenId', + type: 'uint256', + }, + { + name: 'erc1155TokenProperties', + type: 'tuple[]', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + { + name: 'erc1155TokenAmount', + type: 'uint128', + }, + ], + }, + ], + name: 'getERC1155OrderHash', + outputs: [ + { + name: 'orderHash', + type: 'bytes32', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + name: 'order', + type: 'tuple', + components: [ + { + name: 'direction', + type: 'uint8', + }, + { + name: 'maker', + type: 'address', + }, + { + name: 'taker', + type: 'address', + }, + { + name: 'expiry', + type: 'uint256', + }, + { + name: 'nonce', + type: 'uint256', + }, + { + name: 'erc20Token', + type: 'address', + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + }, + { + name: 'fees', + type: 'tuple[]', + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc1155Token', + type: 'address', + }, + { + name: 'erc1155TokenId', + type: 'uint256', + }, + { + name: 'erc1155TokenProperties', + type: 'tuple[]', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + { + name: 'erc1155TokenAmount', + type: 'uint128', + }, + ], + }, + ], + name: 'getERC1155OrderInfo', + outputs: [ + { + name: 'orderInfo', + type: 'tuple', + components: [ + { + name: 'orderHash', + type: 'bytes32', + }, + { + name: 'status', + type: 'uint8', + }, + { + name: 'orderAmount', + type: 'uint128', + }, + { + name: 'remainingAmount', + type: 'uint128', + }, + ], + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + name: 'order', + type: 'tuple', + components: [ + { + name: 'direction', + type: 'uint8', + }, + { + name: 'maker', + type: 'address', + }, + { + name: 'taker', + type: 'address', + }, + { + name: 'expiry', + type: 'uint256', + }, + { + name: 'nonce', + type: 'uint256', + }, + { + name: 'erc20Token', + type: 'address', + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + }, + { + name: 'fees', + type: 'tuple[]', + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc721Token', + type: 'address', + }, + { + name: 'erc721TokenId', + type: 'uint256', + }, + { + name: 'erc721TokenProperties', + type: 'tuple[]', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + ], + }, + ], + name: 'getERC721OrderHash', + outputs: [ + { + name: 'orderHash', + type: 'bytes32', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + name: 'order', + type: 'tuple', + components: [ + { + name: 'direction', + type: 'uint8', + }, + { + name: 'maker', + type: 'address', + }, + { + name: 'taker', + type: 'address', + }, + { + name: 'expiry', + type: 'uint256', + }, + { + name: 'nonce', + type: 'uint256', + }, + { + name: 'erc20Token', + type: 'address', + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + }, + { + name: 'fees', + type: 'tuple[]', + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc721Token', + type: 'address', + }, + { + name: 'erc721TokenId', + type: 'uint256', + }, + { + name: 'erc721TokenProperties', + type: 'tuple[]', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + ], + }, + ], + name: 'getERC721OrderStatus', + outputs: [ + { + name: 'status', + type: 'uint8', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + name: 'maker', + type: 'address', + }, + { + name: 'nonceRange', + type: 'uint248', + }, + ], + name: 'getERC721OrderStatusBitVector', + outputs: [ + { + name: 'bitVector', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, { inputs: [ { @@ -3903,6 +5423,211 @@ export class IZeroExContract extends BaseContract { stateMutability: 'view', type: 'function', }, + { + inputs: [ + { + name: 'sellOrder', + type: 'tuple', + components: [ + { + name: 'direction', + type: 'uint8', + }, + { + name: 'maker', + type: 'address', + }, + { + name: 'taker', + type: 'address', + }, + { + name: 'expiry', + type: 'uint256', + }, + { + name: 'nonce', + type: 'uint256', + }, + { + name: 'erc20Token', + type: 'address', + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + }, + { + name: 'fees', + type: 'tuple[]', + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc721Token', + type: 'address', + }, + { + name: 'erc721TokenId', + type: 'uint256', + }, + { + name: 'erc721TokenProperties', + type: 'tuple[]', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + ], + }, + { + name: 'buyOrder', + type: 'tuple', + components: [ + { + name: 'direction', + type: 'uint8', + }, + { + name: 'maker', + type: 'address', + }, + { + name: 'taker', + type: 'address', + }, + { + name: 'expiry', + type: 'uint256', + }, + { + name: 'nonce', + type: 'uint256', + }, + { + name: 'erc20Token', + type: 'address', + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + }, + { + name: 'fees', + type: 'tuple[]', + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc721Token', + type: 'address', + }, + { + name: 'erc721TokenId', + type: 'uint256', + }, + { + name: 'erc721TokenProperties', + type: 'tuple[]', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + ], + }, + { + name: 'sellOrderSignature', + type: 'tuple', + components: [ + { + name: 'signatureType', + type: 'uint8', + }, + { + name: 'v', + type: 'uint8', + }, + { + name: 'r', + type: 'bytes32', + }, + { + name: 's', + type: 'bytes32', + }, + ], + }, + { + name: 'buyOrderSignature', + type: 'tuple', + components: [ + { + name: 'signatureType', + type: 'uint8', + }, + { + name: 'v', + type: 'uint8', + }, + { + name: 'r', + type: 'bytes32', + }, + { + name: 's', + type: 'bytes32', + }, + ], + }, + ], + name: 'matchERC721Orders', + outputs: [ + { + name: 'profit', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, { inputs: [ { @@ -4165,6 +5890,68 @@ export class IZeroExContract extends BaseContract { stateMutability: 'nonpayable', type: 'function', }, + { + inputs: [ + { + name: 'operator', + type: 'address', + }, + { + name: 'from', + type: 'address', + }, + { + name: 'tokenId', + type: 'uint256', + }, + { + name: 'value', + type: 'uint256', + }, + { + name: 'data', + type: 'bytes', + }, + ], + name: 'onERC1155Received', + outputs: [ + { + name: 'success', + type: 'bytes4', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + name: 'operator', + type: 'address', + }, + { + name: 'from', + type: 'address', + }, + { + name: 'tokenId', + type: 'uint256', + }, + { + name: 'data', + type: 'bytes', + }, + ], + name: 'onERC721Received', + outputs: [ + { + name: 'success', + type: 'bytes4', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, { inputs: [], name: 'owner', @@ -4177,6 +5964,174 @@ export class IZeroExContract extends BaseContract { stateMutability: 'view', type: 'function', }, + { + inputs: [ + { + name: 'order', + type: 'tuple', + components: [ + { + name: 'direction', + type: 'uint8', + }, + { + name: 'maker', + type: 'address', + }, + { + name: 'taker', + type: 'address', + }, + { + name: 'expiry', + type: 'uint256', + }, + { + name: 'nonce', + type: 'uint256', + }, + { + name: 'erc20Token', + type: 'address', + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + }, + { + name: 'fees', + type: 'tuple[]', + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc1155Token', + type: 'address', + }, + { + name: 'erc1155TokenId', + type: 'uint256', + }, + { + name: 'erc1155TokenProperties', + type: 'tuple[]', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + { + name: 'erc1155TokenAmount', + type: 'uint128', + }, + ], + }, + ], + name: 'preSignERC1155Order', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + name: 'order', + type: 'tuple', + components: [ + { + name: 'direction', + type: 'uint8', + }, + { + name: 'maker', + type: 'address', + }, + { + name: 'taker', + type: 'address', + }, + { + name: 'expiry', + type: 'uint256', + }, + { + name: 'nonce', + type: 'uint256', + }, + { + name: 'erc20Token', + type: 'address', + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + }, + { + name: 'fees', + type: 'tuple[]', + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc721Token', + type: 'address', + }, + { + name: 'erc721TokenId', + type: 'uint256', + }, + { + name: 'erc721TokenProperties', + type: 'tuple[]', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + ], + }, + ], + name: 'preSignERC721Order', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, { inputs: [ { @@ -4225,6 +6180,246 @@ export class IZeroExContract extends BaseContract { stateMutability: 'nonpayable', type: 'function', }, + { + inputs: [ + { + name: 'buyOrder', + type: 'tuple', + components: [ + { + name: 'direction', + type: 'uint8', + }, + { + name: 'maker', + type: 'address', + }, + { + name: 'taker', + type: 'address', + }, + { + name: 'expiry', + type: 'uint256', + }, + { + name: 'nonce', + type: 'uint256', + }, + { + name: 'erc20Token', + type: 'address', + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + }, + { + name: 'fees', + type: 'tuple[]', + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc1155Token', + type: 'address', + }, + { + name: 'erc1155TokenId', + type: 'uint256', + }, + { + name: 'erc1155TokenProperties', + type: 'tuple[]', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + { + name: 'erc1155TokenAmount', + type: 'uint128', + }, + ], + }, + { + name: 'signature', + type: 'tuple', + components: [ + { + name: 'signatureType', + type: 'uint8', + }, + { + name: 'v', + type: 'uint8', + }, + { + name: 'r', + type: 'bytes32', + }, + { + name: 's', + type: 'bytes32', + }, + ], + }, + { + name: 'erc1155TokenId', + type: 'uint256', + }, + { + name: 'erc1155SellAmount', + type: 'uint128', + }, + { + name: 'unwrapNativeToken', + type: 'bool', + }, + { + name: 'callbackData', + type: 'bytes', + }, + ], + name: 'sellERC1155', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + name: 'buyOrder', + type: 'tuple', + components: [ + { + name: 'direction', + type: 'uint8', + }, + { + name: 'maker', + type: 'address', + }, + { + name: 'taker', + type: 'address', + }, + { + name: 'expiry', + type: 'uint256', + }, + { + name: 'nonce', + type: 'uint256', + }, + { + name: 'erc20Token', + type: 'address', + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + }, + { + name: 'fees', + type: 'tuple[]', + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc721Token', + type: 'address', + }, + { + name: 'erc721TokenId', + type: 'uint256', + }, + { + name: 'erc721TokenProperties', + type: 'tuple[]', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + ], + }, + { + name: 'signature', + type: 'tuple', + components: [ + { + name: 'signatureType', + type: 'uint8', + }, + { + name: 'v', + type: 'uint8', + }, + { + name: 'r', + type: 'bytes32', + }, + { + name: 's', + type: 'bytes32', + }, + ], + }, + { + name: 'erc721TokenId', + type: 'uint256', + }, + { + name: 'unwrapNativeToken', + type: 'bool', + }, + { + name: 'callbackData', + type: 'bytes', + }, + ], + name: 'sellERC721', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, { inputs: [ { @@ -4431,6 +6626,23 @@ export class IZeroExContract extends BaseContract { stateMutability: 'nonpayable', type: 'function', }, + { + inputs: [ + { + name: 'interfaceId', + type: 'bytes4', + }, + ], + name: 'supportInterface', + outputs: [ + { + name: 'isSupported', + type: 'bool', + }, + ], + stateMutability: 'pure', + type: 'function', + }, { inputs: [ { @@ -4455,6 +6667,26 @@ export class IZeroExContract extends BaseContract { stateMutability: 'nonpayable', type: 'function', }, + { + inputs: [ + { + name: 'erc20', + type: 'address', + }, + { + name: 'amountOut', + type: 'uint256', + }, + { + name: 'recipientWallet', + type: 'address', + }, + ], + name: 'transferTrappedTokensTo', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, { inputs: [ { @@ -4518,6 +6750,394 @@ export class IZeroExContract extends BaseContract { stateMutability: 'nonpayable', type: 'function', }, + { + inputs: [ + { + name: 'order', + type: 'tuple', + components: [ + { + name: 'direction', + type: 'uint8', + }, + { + name: 'maker', + type: 'address', + }, + { + name: 'taker', + type: 'address', + }, + { + name: 'expiry', + type: 'uint256', + }, + { + name: 'nonce', + type: 'uint256', + }, + { + name: 'erc20Token', + type: 'address', + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + }, + { + name: 'fees', + type: 'tuple[]', + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc1155Token', + type: 'address', + }, + { + name: 'erc1155TokenId', + type: 'uint256', + }, + { + name: 'erc1155TokenProperties', + type: 'tuple[]', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + { + name: 'erc1155TokenAmount', + type: 'uint128', + }, + ], + }, + { + name: 'erc1155TokenId', + type: 'uint256', + }, + ], + name: 'validateERC1155OrderProperties', + outputs: [], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + name: 'order', + type: 'tuple', + components: [ + { + name: 'direction', + type: 'uint8', + }, + { + name: 'maker', + type: 'address', + }, + { + name: 'taker', + type: 'address', + }, + { + name: 'expiry', + type: 'uint256', + }, + { + name: 'nonce', + type: 'uint256', + }, + { + name: 'erc20Token', + type: 'address', + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + }, + { + name: 'fees', + type: 'tuple[]', + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc1155Token', + type: 'address', + }, + { + name: 'erc1155TokenId', + type: 'uint256', + }, + { + name: 'erc1155TokenProperties', + type: 'tuple[]', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + { + name: 'erc1155TokenAmount', + type: 'uint128', + }, + ], + }, + { + name: 'signature', + type: 'tuple', + components: [ + { + name: 'signatureType', + type: 'uint8', + }, + { + name: 'v', + type: 'uint8', + }, + { + name: 'r', + type: 'bytes32', + }, + { + name: 's', + type: 'bytes32', + }, + ], + }, + ], + name: 'validateERC1155OrderSignature', + outputs: [], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + name: 'order', + type: 'tuple', + components: [ + { + name: 'direction', + type: 'uint8', + }, + { + name: 'maker', + type: 'address', + }, + { + name: 'taker', + type: 'address', + }, + { + name: 'expiry', + type: 'uint256', + }, + { + name: 'nonce', + type: 'uint256', + }, + { + name: 'erc20Token', + type: 'address', + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + }, + { + name: 'fees', + type: 'tuple[]', + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc721Token', + type: 'address', + }, + { + name: 'erc721TokenId', + type: 'uint256', + }, + { + name: 'erc721TokenProperties', + type: 'tuple[]', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + ], + }, + { + name: 'erc721TokenId', + type: 'uint256', + }, + ], + name: 'validateERC721OrderProperties', + outputs: [], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + name: 'order', + type: 'tuple', + components: [ + { + name: 'direction', + type: 'uint8', + }, + { + name: 'maker', + type: 'address', + }, + { + name: 'taker', + type: 'address', + }, + { + name: 'expiry', + type: 'uint256', + }, + { + name: 'nonce', + type: 'uint256', + }, + { + name: 'erc20Token', + type: 'address', + }, + { + name: 'erc20TokenAmount', + type: 'uint256', + }, + { + name: 'fees', + type: 'tuple[]', + components: [ + { + name: 'recipient', + type: 'address', + }, + { + name: 'amount', + type: 'uint256', + }, + { + name: 'feeData', + type: 'bytes', + }, + ], + }, + { + name: 'erc721Token', + type: 'address', + }, + { + name: 'erc721TokenId', + type: 'uint256', + }, + { + name: 'erc721TokenProperties', + type: 'tuple[]', + components: [ + { + name: 'propertyValidator', + type: 'address', + }, + { + name: 'propertyData', + type: 'bytes', + }, + ], + }, + ], + }, + { + name: 'signature', + type: 'tuple', + components: [ + { + name: 'signatureType', + type: 'uint8', + }, + { + name: 'v', + type: 'uint8', + }, + { + name: 'r', + type: 'bytes32', + }, + { + name: 's', + type: 'bytes32', + }, + ], + }, + ], + name: 'validateERC721OrderSignature', + outputs: [], + stateMutability: 'view', + type: 'function', + }, ] as ContractAbi; return abi; } @@ -4639,6 +7259,7 @@ export class IZeroExContract extends BaseContract { '_fillLimitOrder((address,address,uint128,uint128,uint128,address,address,address,address,bytes32,uint64,uint256),(uint8,uint8,bytes32,bytes32),uint128,address,address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -4738,6 +7359,7 @@ export class IZeroExContract extends BaseContract { '_fillOtcOrder((address,address,uint128,uint128,address,address,address,uint256),(uint8,uint8,bytes32,bytes32),uint128,address,bool,address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -4838,6 +7460,7 @@ export class IZeroExContract extends BaseContract { '_fillRfqOrder((address,address,uint128,uint128,address,address,address,bytes32,uint64,uint256),(uint8,uint8,bytes32,bytes32),uint128,address,bool,address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -4921,6 +7544,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = '_sellHeldTokenForTokenToUniswapV3(bytes,uint256,uint256,address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -4997,6 +7621,7 @@ export class IZeroExContract extends BaseContract { '_transformERC20((address,address,address,uint256,uint256,(uint32,bytes)[],bool,address))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5048,6 +7673,332 @@ export class IZeroExContract extends BaseContract { }, }; } + /** + * Buys multiple ERC1155 assets by filling the + * given orders. + * @param sellOrders The ERC1155 sell orders. + * @param signatures The order signatures. + * @param erc1155TokenAmounts The amounts of the ERC1155 assets to buy + * for each order. + * @param callbackData The data (if any) to pass to the taker callback + * for each order. Refer to the `callbackData` parameter to for + * `buyERC1155`. + * @param revertIfIncomplete If true, reverts if this function fails to + * fill any individual order. + */ + public batchBuyERC1155s( + sellOrders: Array<{ + direction: number | BigNumber; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc1155Token: string; + erc1155TokenId: BigNumber; + erc1155TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + erc1155TokenAmount: BigNumber; + }>, + signatures: Array<{ signatureType: number | BigNumber; v: number | BigNumber; r: string; s: string }>, + erc1155TokenAmounts: BigNumber[], + callbackData: string[], + revertIfIncomplete: boolean, + ): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + assert.isArray('sellOrders', sellOrders); + assert.isArray('signatures', signatures); + assert.isArray('erc1155TokenAmounts', erc1155TokenAmounts); + assert.isArray('callbackData', callbackData); + assert.isBoolean('revertIfIncomplete', revertIfIncomplete); + const functionSignature = + 'batchBuyERC1155s((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[],uint128)[],(uint8,uint8,bytes32,bytes32)[],uint128[],bytes[],bool)'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [ + sellOrders, + signatures, + erc1155TokenAmounts, + callbackData, + revertIfIncomplete, + ]); + }, + }; + } + /** + * Buys multiple ERC721 assets by filling the + * given orders. + * @param sellOrders The ERC721 sell orders. + * @param signatures The order signatures. + * @param callbackData The data (if any) to pass to the taker callback + * for each order. Refer to the `callbackData` parameter to for + * `buyERC721`. + * @param revertIfIncomplete If true, reverts if this function fails to + * fill any individual order. + */ + public batchBuyERC721s( + sellOrders: Array<{ + direction: number | BigNumber; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc721Token: string; + erc721TokenId: BigNumber; + erc721TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + }>, + signatures: Array<{ signatureType: number | BigNumber; v: number | BigNumber; r: string; s: string }>, + callbackData: string[], + revertIfIncomplete: boolean, + ): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + assert.isArray('sellOrders', sellOrders); + assert.isArray('signatures', signatures); + assert.isArray('callbackData', callbackData); + assert.isBoolean('revertIfIncomplete', revertIfIncomplete); + const functionSignature = + 'batchBuyERC721s((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[])[],(uint8,uint8,bytes32,bytes32)[],bytes[],bool)'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [ + sellOrders, + signatures, + callbackData, + revertIfIncomplete, + ]); + }, + }; + } + /** + * Cancel multiple ERC1155 orders by their nonces. The caller + * should be the maker of the orders. Silently succeeds if + * an order with the same nonce has already been filled or + * cancelled. + * @param orderNonces The order nonces. + */ + public batchCancelERC1155Orders(orderNonces: BigNumber[]): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + assert.isArray('orderNonces', orderNonces); + const functionSignature = 'batchCancelERC1155Orders(uint256[])'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [orderNonces]); + }, + }; + } + /** + * Cancel multiple ERC721 orders by their nonces. The caller + * should be the maker of the orders. Silently succeeds if + * an order with the same nonce has already been filled or + * cancelled. + * @param orderNonces The order nonces. + */ + public batchCancelERC721Orders(orderNonces: BigNumber[]): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + assert.isArray('orderNonces', orderNonces); + const functionSignature = 'batchCancelERC721Orders(uint256[])'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [orderNonces]); + }, + }; + } /** * Cancel multiple limit orders. The caller must be the maker or a valid order signer. * Silently succeeds if the order has already been cancelled. @@ -5075,6 +8026,7 @@ export class IZeroExContract extends BaseContract { 'batchCancelLimitOrders((address,address,uint128,uint128,uint128,address,address,address,address,bytes32,uint64,uint256)[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5147,6 +8099,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'batchCancelPairLimitOrders(address[],address[],uint256[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5222,6 +8175,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'batchCancelPairLimitOrdersWithSigner(address,address[],address[],uint256[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5299,6 +8253,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'batchCancelPairRfqOrders(address[],address[],uint256[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5374,6 +8329,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'batchCancelPairRfqOrdersWithSigner(address,address[],address[],uint256[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5455,6 +8411,7 @@ export class IZeroExContract extends BaseContract { 'batchCancelRfqOrders((address,address,uint128,uint128,address,address,address,bytes32,uint64,uint256)[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5533,6 +8490,7 @@ export class IZeroExContract extends BaseContract { 'batchExecuteMetaTransactions((address,address,uint256,uint256,uint256,uint256,bytes,uint256,address,uint256)[],(uint8,uint8,bytes32,bytes32)[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5620,6 +8578,7 @@ export class IZeroExContract extends BaseContract { 'batchFillLimitOrders((address,address,uint128,uint128,uint128,address,address,address,address,bytes32,uint64,uint256)[],(uint8,uint8,bytes32,bytes32)[],uint128[],bool)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5713,6 +8672,7 @@ export class IZeroExContract extends BaseContract { 'batchFillRfqOrders((address,address,uint128,uint128,address,address,address,bytes32,uint64,uint256)[],(uint8,uint8,bytes32,bytes32)[],uint128[],bool)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5805,6 +8765,7 @@ export class IZeroExContract extends BaseContract { 'batchFillTakerSignedOtcOrders((address,address,uint128,uint128,address,address,address,uint256)[],(uint8,uint8,bytes32,bytes32)[],(uint8,uint8,bytes32,bytes32)[],bool[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5894,6 +8855,7 @@ export class IZeroExContract extends BaseContract { 'batchGetLimitOrderRelevantStates((address,address,uint128,uint128,uint128,address,address,address,address,bytes32,uint64,uint256)[],(uint8,uint8,bytes32,bytes32)[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -5991,6 +8953,7 @@ export class IZeroExContract extends BaseContract { 'batchGetRfqOrderRelevantStates((address,address,uint128,uint128,address,address,address,bytes32,uint64,uint256)[],(uint8,uint8,bytes32,bytes32)[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -6057,6 +9020,426 @@ export class IZeroExContract extends BaseContract { }, }; } + /** + * Matches pairs of complementary orders that have + * non-negative spreads. Each order is filled at + * their respective price, and the matcher receives + * a profit denominated in the ERC20 token. + * @param sellOrders Orders selling ERC721 assets. + * @param buyOrders Orders buying ERC721 assets. + * @param sellOrderSignatures Signatures for the sell orders. + * @param buyOrderSignatures Signatures for the buy orders. + */ + public batchMatchERC721Orders( + sellOrders: Array<{ + direction: number | BigNumber; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc721Token: string; + erc721TokenId: BigNumber; + erc721TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + }>, + buyOrders: Array<{ + direction: number | BigNumber; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc721Token: string; + erc721TokenId: BigNumber; + erc721TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + }>, + sellOrderSignatures: Array<{ signatureType: number | BigNumber; v: number | BigNumber; r: string; s: string }>, + buyOrderSignatures: Array<{ signatureType: number | BigNumber; v: number | BigNumber; r: string; s: string }>, + ): ContractTxFunctionObj<[BigNumber[], boolean[]]> { + const self = (this as any) as IZeroExContract; + assert.isArray('sellOrders', sellOrders); + assert.isArray('buyOrders', buyOrders); + assert.isArray('sellOrderSignatures', sellOrderSignatures); + assert.isArray('buyOrderSignatures', buyOrderSignatures); + const functionSignature = + 'batchMatchERC721Orders((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[])[],(uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[])[],(uint8,uint8,bytes32,bytes32)[],(uint8,uint8,bytes32,bytes32)[])'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync( + callData: Partial = {}, + defaultBlock?: BlockParam, + ): Promise<[BigNumber[], boolean[]]> { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue<[BigNumber[], boolean[]]>(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [ + sellOrders, + buyOrders, + sellOrderSignatures, + buyOrderSignatures, + ]); + }, + }; + } + /** + * Buys an ERC1155 asset by filling the given order. + * @param sellOrder The ERC1155 sell order. + * @param signature The order signature. + * @param erc1155BuyAmount The amount of the ERC1155 asset to buy. + * @param callbackData If this parameter is non-zero, invokes + * `zeroExERC1155OrderCallback` on `msg.sender` after the ERC1155 + * asset has been transferred to `msg.sender` but before + * transferring the ERC20 tokens to the seller. Native tokens + * acquired during the callback can be used to fill the order. + */ + public buyERC1155( + sellOrder: { + direction: number | BigNumber; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc1155Token: string; + erc1155TokenId: BigNumber; + erc1155TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + erc1155TokenAmount: BigNumber; + }, + signature: { signatureType: number | BigNumber; v: number | BigNumber; r: string; s: string }, + erc1155BuyAmount: BigNumber, + callbackData: string, + ): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + + assert.isBigNumber('erc1155BuyAmount', erc1155BuyAmount); + assert.isString('callbackData', callbackData); + const functionSignature = + 'buyERC1155((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[],uint128),(uint8,uint8,bytes32,bytes32),uint128,bytes)'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [ + sellOrder, + signature, + erc1155BuyAmount, + callbackData, + ]); + }, + }; + } + /** + * Buys an ERC721 asset by filling the given order. + * @param sellOrder The ERC721 sell order. + * @param signature The order signature. + * @param callbackData If this parameter is non-zero, invokes + * `zeroExERC721OrderCallback` on `msg.sender` after the ERC721 + * asset has been transferred to `msg.sender` but before + * transferring the ERC20 tokens to the seller. Native tokens + * acquired during the callback can be used to fill the order. + */ + public buyERC721( + sellOrder: { + direction: number | BigNumber; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc721Token: string; + erc721TokenId: BigNumber; + erc721TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + }, + signature: { signatureType: number | BigNumber; v: number | BigNumber; r: string; s: string }, + callbackData: string, + ): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + + assert.isString('callbackData', callbackData); + const functionSignature = + 'buyERC721((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[]),(uint8,uint8,bytes32,bytes32),bytes)'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [sellOrder, signature, callbackData]); + }, + }; + } + /** + * Cancel a single ERC1155 order by its nonce. The caller + * should be the maker of the order. Silently succeeds if + * an order with the same nonce has already been filled or + * cancelled. + * @param orderNonce The order nonce. + */ + public cancelERC1155Order(orderNonce: BigNumber): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + assert.isBigNumber('orderNonce', orderNonce); + const functionSignature = 'cancelERC1155Order(uint256)'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [orderNonce]); + }, + }; + } + /** + * Cancel a single ERC721 order by its nonce. The caller + * should be the maker of the order. Silently succeeds if + * an order with the same nonce has already been filled or + * cancelled. + * @param orderNonce The order nonce. + */ + public cancelERC721Order(orderNonce: BigNumber): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + assert.isBigNumber('orderNonce', orderNonce); + const functionSignature = 'cancelERC721Order(uint256)'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [orderNonce]); + }, + }; + } /** * Cancel a single limit order. The caller must be the maker or a valid order signer. * Silently succeeds if the order has already been cancelled. @@ -6082,6 +9465,7 @@ export class IZeroExContract extends BaseContract { 'cancelLimitOrder((address,address,uint128,uint128,uint128,address,address,address,address,bytes32,uint64,uint256))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -6154,6 +9538,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'cancelPairLimitOrders(address,address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -6233,6 +9618,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'cancelPairLimitOrdersWithSigner(address,address,address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -6310,6 +9696,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'cancelPairRfqOrders(address,address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -6389,6 +9776,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'cancelPairRfqOrdersWithSigner(address,address,address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -6468,6 +9856,7 @@ export class IZeroExContract extends BaseContract { 'cancelRfqOrder((address,address,uint128,uint128,address,address,address,bytes32,uint64,uint256))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -6529,6 +9918,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'createTransformWallet()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -6606,6 +9996,7 @@ export class IZeroExContract extends BaseContract { 'executeMetaTransaction((address,address,uint256,uint256,uint256,uint256,bytes,uint256,address,uint256),(uint8,uint8,bytes32,bytes32))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -6669,6 +10060,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'extend(bytes4,address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -6753,6 +10145,7 @@ export class IZeroExContract extends BaseContract { 'fillLimitOrder((address,address,uint128,uint128,uint128,address,address,address,address,bytes32,uint64,uint256),(uint8,uint8,bytes32,bytes32),uint128)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -6841,6 +10234,7 @@ export class IZeroExContract extends BaseContract { 'fillOrKillLimitOrder((address,address,uint128,uint128,uint128,address,address,address,address,bytes32,uint64,uint256),(uint8,uint8,bytes32,bytes32),uint128)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -6922,6 +10316,7 @@ export class IZeroExContract extends BaseContract { 'fillOrKillRfqOrder((address,address,uint128,uint128,address,address,address,bytes32,uint64,uint256),(uint8,uint8,bytes32,bytes32),uint128)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -7001,6 +10396,7 @@ export class IZeroExContract extends BaseContract { 'fillOtcOrder((address,address,uint128,uint128,address,address,address,uint256),(uint8,uint8,bytes32,bytes32),uint128)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -7085,6 +10481,7 @@ export class IZeroExContract extends BaseContract { 'fillOtcOrderForEth((address,address,uint128,uint128,address,address,address,uint256),(uint8,uint8,bytes32,bytes32),uint128)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -7164,6 +10561,7 @@ export class IZeroExContract extends BaseContract { 'fillOtcOrderWithEth((address,address,uint128,uint128,address,address,address,uint256),(uint8,uint8,bytes32,bytes32))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -7249,6 +10647,7 @@ export class IZeroExContract extends BaseContract { 'fillRfqOrder((address,address,uint128,uint128,address,address,address,bytes32,uint64,uint256),(uint8,uint8,bytes32,bytes32),uint128)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -7330,6 +10729,7 @@ export class IZeroExContract extends BaseContract { 'fillTakerSignedOtcOrder((address,address,uint128,uint128,address,address,address,uint256),(uint8,uint8,bytes32,bytes32),(uint8,uint8,bytes32,bytes32))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -7410,6 +10810,7 @@ export class IZeroExContract extends BaseContract { 'fillTakerSignedOtcOrderForEth((address,address,uint128,uint128,address,address,address,uint256),(uint8,uint8,bytes32,bytes32),(uint8,uint8,bytes32,bytes32))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -7461,6 +10862,388 @@ export class IZeroExContract extends BaseContract { }, }; } + /** + * Get the EIP-712 hash of an ERC1155 order. + * @param order The ERC1155 order. + */ + public getERC1155OrderHash(order: { + direction: number | BigNumber; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc1155Token: string; + erc1155TokenId: BigNumber; + erc1155TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + erc1155TokenAmount: BigNumber; + }): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + + const functionSignature = + 'getERC1155OrderHash((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[],uint128))'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [order]); + }, + }; + } + /** + * Get the order info for an ERC1155 order. + * @param order The ERC1155 order. + */ + public getERC1155OrderInfo(order: { + direction: number | BigNumber; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc1155Token: string; + erc1155TokenId: BigNumber; + erc1155TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + erc1155TokenAmount: BigNumber; + }): ContractTxFunctionObj<{ + orderHash: string; + status: number; + orderAmount: BigNumber; + remainingAmount: BigNumber; + }> { + const self = (this as any) as IZeroExContract; + + const functionSignature = + 'getERC1155OrderInfo((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[],uint128))'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync( + callData: Partial = {}, + defaultBlock?: BlockParam, + ): Promise<{ orderHash: string; status: number; orderAmount: BigNumber; remainingAmount: BigNumber }> { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue<{ + orderHash: string; + status: number; + orderAmount: BigNumber; + remainingAmount: BigNumber; + }>(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [order]); + }, + }; + } + /** + * Get the EIP-712 hash of an ERC721 order. + * @param order The ERC721 order. + */ + public getERC721OrderHash(order: { + direction: number | BigNumber; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc721Token: string; + erc721TokenId: BigNumber; + erc721TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + }): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + + const functionSignature = + 'getERC721OrderHash((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[]))'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [order]); + }, + }; + } + /** + * Get the current status of an ERC721 order. + * @param order The ERC721 order. + */ + public getERC721OrderStatus(order: { + direction: number | BigNumber; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc721Token: string; + erc721TokenId: BigNumber; + erc721TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + }): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + + const functionSignature = + 'getERC721OrderStatus((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[]))'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [order]); + }, + }; + } + /** + * Get the order status bit vector for the given + * maker address and nonce range. + * @param maker The maker of the order. + * @param nonceRange Order status bit vectors are indexed by maker + * address and the upper 248 bits of the order nonce. We define + * `nonceRange` to be these 248 bits. + */ + public getERC721OrderStatusBitVector(maker: string, nonceRange: BigNumber): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + assert.isString('maker', maker); + assert.isBigNumber('nonceRange', nonceRange); + const functionSignature = 'getERC721OrderStatusBitVector(address,uint248)'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [maker.toLowerCase(), nonceRange]); + }, + }; + } /** * Get the canonical hash of a limit order. * @param order The limit order. @@ -7485,6 +11268,7 @@ export class IZeroExContract extends BaseContract { 'getLimitOrderHash((address,address,uint128,uint128,uint128,address,address,address,address,bytes32,uint64,uint256))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -7560,6 +11344,7 @@ export class IZeroExContract extends BaseContract { 'getLimitOrderInfo((address,address,uint128,uint128,uint128,address,address,address,address,bytes32,uint64,uint256))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -7649,6 +11434,7 @@ export class IZeroExContract extends BaseContract { 'getLimitOrderRelevantState((address,address,uint128,uint128,uint128,address,address,address,address,bytes32,uint64,uint256),(uint8,uint8,bytes32,bytes32))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -7727,6 +11513,7 @@ export class IZeroExContract extends BaseContract { 'getMetaTransactionExecutedBlock((address,address,uint256,uint256,uint256,uint256,bytes,uint256,address,uint256))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -7800,6 +11587,7 @@ export class IZeroExContract extends BaseContract { 'getMetaTransactionHash((address,address,uint256,uint256,uint256,uint256,bytes,uint256,address,uint256))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -7861,6 +11649,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'getMetaTransactionHashExecutedBlock(bytes32)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -7931,6 +11720,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'getOtcOrderHash((address,address,uint128,uint128,address,address,address,uint256))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -8001,6 +11791,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'getOtcOrderInfo((address,address,uint128,uint128,address,address,address,uint256))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -8064,6 +11855,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'getProtocolFeeMultiplier()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -8123,6 +11915,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'getQuoteSigner()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -8196,6 +11989,7 @@ export class IZeroExContract extends BaseContract { 'getRfqOrderHash((address,address,uint128,uint128,address,address,address,bytes32,uint64,uint256))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -8269,6 +12063,7 @@ export class IZeroExContract extends BaseContract { 'getRfqOrderInfo((address,address,uint128,uint128,address,address,address,bytes32,uint64,uint256))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -8356,6 +12151,7 @@ export class IZeroExContract extends BaseContract { 'getRfqOrderRelevantState((address,address,uint128,uint128,address,address,address,bytes32,uint64,uint256),(uint8,uint8,bytes32,bytes32))'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -8424,6 +12220,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'getRollbackEntryAtIndex(bytes4,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -8485,6 +12282,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'getRollbackLength(bytes4)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -8545,6 +12343,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'getTransformWallet()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -8604,6 +12403,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'getTransformerDeployer()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -8667,6 +12467,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'isValidOrderSigner(address,address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -8731,6 +12532,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'lastOtcTxOriginNonce(address,uint64)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -8782,6 +12584,109 @@ export class IZeroExContract extends BaseContract { }, }; } + /** + * Matches a pair of complementary orders that have + * a non-negative spread. Each order is filled at + * their respective price, and the matcher receives + * a profit denominated in the ERC20 token. + * @param sellOrder Order selling an ERC721 asset. + * @param buyOrder Order buying an ERC721 asset. + * @param sellOrderSignature Signature for the sell order. + * @param buyOrderSignature Signature for the buy order. + */ + public matchERC721Orders( + sellOrder: { + direction: number | BigNumber; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc721Token: string; + erc721TokenId: BigNumber; + erc721TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + }, + buyOrder: { + direction: number | BigNumber; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc721Token: string; + erc721TokenId: BigNumber; + erc721TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + }, + sellOrderSignature: { signatureType: number | BigNumber; v: number | BigNumber; r: string; s: string }, + buyOrderSignature: { signatureType: number | BigNumber; v: number | BigNumber; r: string; s: string }, + ): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + + const functionSignature = + 'matchERC721Orders((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[]),(uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[]),(uint8,uint8,bytes32,bytes32),(uint8,uint8,bytes32,bytes32))'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [ + sellOrder, + buyOrder, + sellOrderSignature, + buyOrderSignature, + ]); + }, + }; + } /** * Execute a migration function in the context of the ZeroEx contract. * The result of the function being called should be the magic bytes @@ -8800,6 +12705,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'migrate(address,bytes,address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -8875,6 +12781,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'multiplexBatchSellEthForToken(address,(uint8,uint256,bytes)[],uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -8949,6 +12856,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'multiplexBatchSellTokenForEth(address,(uint8,uint256,bytes)[],uint256,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -9032,6 +12940,7 @@ export class IZeroExContract extends BaseContract { 'multiplexBatchSellTokenForToken(address,address,(uint8,uint256,bytes)[],uint256,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -9112,6 +13021,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'multiplexMultiHopSellEthForToken(address[],(uint8,bytes)[],uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -9187,6 +13097,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'multiplexMultiHopSellTokenForEth(address[],(uint8,bytes)[],uint256,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -9263,6 +13174,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'multiplexMultiHopSellTokenForToken(address[],(uint8,bytes)[],uint256,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -9314,6 +13226,180 @@ export class IZeroExContract extends BaseContract { }, }; } + /** + * Callback for the ERC1155 `safeTransferFrom` function. + * This callback can be used to sell an ERC1155 asset if + * a valid ERC1155 order, signature and `unwrapNativeToken` + * are encoded in `data`. This allows takers to sell their + * ERC1155 asset without first calling `setApprovalForAll`. + * @param operator The address which called `safeTransferFrom`. + * @param from The address which previously owned the token. + * @param tokenId The ID of the asset being transferred. + * @param value The amount being transferred. + * @param data Additional data with no specified format. If a valid + * ERC1155 order, signature and `unwrapNativeToken` are encoded in + * `data`, this function will try to fill the order using the + * received asset. + */ + public onERC1155Received( + operator: string, + from: string, + tokenId: BigNumber, + value: BigNumber, + data: string, + ): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + assert.isString('operator', operator); + assert.isString('from', from); + assert.isBigNumber('tokenId', tokenId); + assert.isBigNumber('value', value); + assert.isString('data', data); + const functionSignature = 'onERC1155Received(address,address,uint256,uint256,bytes)'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [ + operator.toLowerCase(), + from.toLowerCase(), + tokenId, + value, + data, + ]); + }, + }; + } + /** + * Callback for the ERC721 `safeTransferFrom` function. + * This callback can be used to sell an ERC721 asset if + * a valid ERC721 order, signature and `unwrapNativeToken` + * are encoded in `data`. This allows takers to sell their + * ERC721 asset without first calling `setApprovalForAll`. + * @param operator The address which called `safeTransferFrom`. + * @param from The address which previously owned the token. + * @param tokenId The ID of the asset being transferred. + * @param data Additional data with no specified format. If a valid + * ERC721 order, signature and `unwrapNativeToken` are encoded in + * `data`, this function will try to fill the order using the + * received asset. + */ + public onERC721Received( + operator: string, + from: string, + tokenId: BigNumber, + data: string, + ): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + assert.isString('operator', operator); + assert.isString('from', from); + assert.isBigNumber('tokenId', tokenId); + assert.isString('data', data); + const functionSignature = 'onERC721Received(address,address,uint256,bytes)'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [ + operator.toLowerCase(), + from.toLowerCase(), + tokenId, + data, + ]); + }, + }; + } /** * The owner of this contract. */ @@ -9322,6 +13408,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'owner()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -9373,6 +13460,161 @@ export class IZeroExContract extends BaseContract { }, }; } + /** + * Approves an ERC1155 order on-chain. After pre-signing + * the order, the `PRESIGNED` signature type will become + * valid for that order and signer. + * @param order An ERC1155 order. + */ + public preSignERC1155Order(order: { + direction: number | BigNumber; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc1155Token: string; + erc1155TokenId: BigNumber; + erc1155TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + erc1155TokenAmount: BigNumber; + }): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + + const functionSignature = + 'preSignERC1155Order((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[],uint128))'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [order]); + }, + }; + } + /** + * Approves an ERC721 order on-chain. After pre-signing + * the order, the `PRESIGNED` signature type will become + * valid for that order and signer. + * @param order An ERC721 order. + */ + public preSignERC721Order(order: { + direction: number | BigNumber; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc721Token: string; + erc721TokenId: BigNumber; + erc721TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + }): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + + const functionSignature = + 'preSignERC721Order((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[]))'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [order]); + }, + }; + } /** * Register a signer who can sign on behalf of msg.sender * This allows one to sign on behalf of a contract that calls this function @@ -9386,6 +13628,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'registerAllowedOrderSigner(address,bool)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -9450,6 +13693,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'registerAllowedRfqOrigins(address[],bool)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -9513,6 +13757,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'rollback(bytes4,address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -9564,6 +13809,213 @@ export class IZeroExContract extends BaseContract { }, }; } + /** + * Sells an ERC1155 asset to fill the given order. + * @param buyOrder The ERC1155 buy order. + * @param signature The order signature from the maker. + * @param erc1155TokenId The ID of the ERC1155 asset being sold. If the + * given order specifies properties, the asset must satisfy those + * properties. Otherwise, it must equal the tokenId in the order. + * @param erc1155SellAmount The amount of the ERC1155 asset to sell. + * @param unwrapNativeToken If this parameter is true and the ERC20 + * token of the order is e.g. WETH, unwraps the token before + * transferring it to the taker. + * @param callbackData If this parameter is non-zero, invokes + * `zeroExERC1155OrderCallback` on `msg.sender` after the ERC20 + * tokens have been transferred to `msg.sender` but before + * transferring the ERC1155 asset to the buyer. + */ + public sellERC1155( + buyOrder: { + direction: number | BigNumber; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc1155Token: string; + erc1155TokenId: BigNumber; + erc1155TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + erc1155TokenAmount: BigNumber; + }, + signature: { signatureType: number | BigNumber; v: number | BigNumber; r: string; s: string }, + erc1155TokenId: BigNumber, + erc1155SellAmount: BigNumber, + unwrapNativeToken: boolean, + callbackData: string, + ): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + + assert.isBigNumber('erc1155TokenId', erc1155TokenId); + assert.isBigNumber('erc1155SellAmount', erc1155SellAmount); + assert.isBoolean('unwrapNativeToken', unwrapNativeToken); + assert.isString('callbackData', callbackData); + const functionSignature = + 'sellERC1155((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[],uint128),(uint8,uint8,bytes32,bytes32),uint256,uint128,bool,bytes)'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [ + buyOrder, + signature, + erc1155TokenId, + erc1155SellAmount, + unwrapNativeToken, + callbackData, + ]); + }, + }; + } + /** + * Sells an ERC721 asset to fill the given order. + * @param buyOrder The ERC721 buy order. + * @param signature The order signature from the maker. + * @param erc721TokenId The ID of the ERC721 asset being sold. If the + * given order specifies properties, the asset must satisfy those + * properties. Otherwise, it must equal the tokenId in the order. + * @param unwrapNativeToken If this parameter is true and the ERC20 + * token of the order is e.g. WETH, unwraps the token before + * transferring it to the taker. + * @param callbackData If this parameter is non-zero, invokes + * `zeroExERC721OrderCallback` on `msg.sender` after the ERC20 + * tokens have been transferred to `msg.sender` but before + * transferring the ERC721 asset to the buyer. + */ + public sellERC721( + buyOrder: { + direction: number | BigNumber; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc721Token: string; + erc721TokenId: BigNumber; + erc721TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + }, + signature: { signatureType: number | BigNumber; v: number | BigNumber; r: string; s: string }, + erc721TokenId: BigNumber, + unwrapNativeToken: boolean, + callbackData: string, + ): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + + assert.isBigNumber('erc721TokenId', erc721TokenId); + assert.isBoolean('unwrapNativeToken', unwrapNativeToken); + assert.isString('callbackData', callbackData); + const functionSignature = + 'sellERC721((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[]),(uint8,uint8,bytes32,bytes32),uint256,bool,bytes)'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [ + buyOrder, + signature, + erc721TokenId, + unwrapNativeToken, + callbackData, + ]); + }, + }; + } /** * Sell attached ETH directly against uniswap v3. * @param encodedPath Uniswap-encoded path, where the first token is WETH. @@ -9582,6 +14034,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'sellEthForTokenToUniswapV3(bytes,uint256,address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -9671,6 +14124,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'sellToLiquidityProvider(address,address,address,address,uint256,uint256,bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -9751,6 +14205,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'sellToPancakeSwap(address[],uint256,uint256,uint8)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -9823,6 +14278,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'sellToUniswap(address[],uint256,uint256,bool)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -9895,6 +14351,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'sellTokenForEthToUniswapV3(bytes,uint256,uint256,address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -9972,6 +14429,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'sellTokenForTokenToUniswapV3(bytes,uint256,uint256,address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -10039,6 +14497,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'setQuoteSigner(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -10102,6 +14561,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'setTransformerDeployer(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -10153,6 +14613,74 @@ export class IZeroExContract extends BaseContract { }, }; } + /** + * Indicates whether the 0x Exchange Proxy implements a particular + * ERC165 interface. This function should use at most 30,000 gas. + * @param interfaceId The interface identifier, as specified in ERC165. + */ + public supportInterface(interfaceId: string): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + assert.isString('interfaceId', interfaceId); + const functionSignature = 'supportInterface(bytes4)'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + let rawCallResult; + if (self._deployedBytecodeIfExists) { + rawCallResult = await self._evmExecAsync(this.getABIEncodedTransactionData()); + } else { + rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + } + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [interfaceId]); + }, + }; + } /** * Transfers ownership of the contract to a new address. * @param newOwner The address that will become the owner. @@ -10163,6 +14691,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'transferOwnership(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -10225,6 +14754,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'transferProtocolFeesForPools(bytes32[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -10276,6 +14806,80 @@ export class IZeroExContract extends BaseContract { }, }; } + /** + * calledFrom FundRecoveryFeature.transferTrappedTokensTo() This will be delegatecalled in the context of the Exchange Proxy instance being used. + * @param erc20 ERC20 Token Address. + * @param amountOut Amount of tokens to withdraw. + * @param recipientWallet Recipient wallet address. + */ + public transferTrappedTokensTo( + erc20: string, + amountOut: BigNumber, + recipientWallet: string, + ): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + assert.isString('erc20', erc20); + assert.isBigNumber('amountOut', amountOut); + assert.isString('recipientWallet', recipientWallet); + const functionSignature = 'transferTrappedTokensTo(address,uint256,address)'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [ + erc20.toLowerCase(), + amountOut, + recipientWallet.toLowerCase(), + ]); + }, + }; + } /** * Executes a series of transformations to convert an ERC20 `inputToken` * to an ERC20 `outputToken`. @@ -10305,6 +14909,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'transformERC20(address,address,uint256,uint256,(uint32,bytes)[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -10383,6 +14988,7 @@ export class IZeroExContract extends BaseContract { const functionSignature = 'uniswapV3SwapCallback(int256,int256,bytes)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -10434,6 +15040,340 @@ export class IZeroExContract extends BaseContract { }, }; } + /** + * If the given order is buying an ERC1155 asset, checks + * whether or not the given token ID satisfies the required + * properties specified in the order. If the order does not + * specify any properties, this function instead checks + * whether the given token ID matches the ID in the order. + * Reverts if any checks fail, or if the order is selling + * an ERC1155 asset. + * @param order The ERC1155 order. + * @param erc1155TokenId The ID of the ERC1155 asset. + */ + public validateERC1155OrderProperties( + order: { + direction: number | BigNumber; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc1155Token: string; + erc1155TokenId: BigNumber; + erc1155TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + erc1155TokenAmount: BigNumber; + }, + erc1155TokenId: BigNumber, + ): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + + assert.isBigNumber('erc1155TokenId', erc1155TokenId); + const functionSignature = + 'validateERC1155OrderProperties((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[],uint128),uint256)'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [order, erc1155TokenId]); + }, + }; + } + /** + * Checks whether the given signature is valid for the + * the given ERC1155 order. Reverts if not. + * @param order The ERC1155 order. + * @param signature The signature to validate. + */ + public validateERC1155OrderSignature( + order: { + direction: number | BigNumber; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc1155Token: string; + erc1155TokenId: BigNumber; + erc1155TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + erc1155TokenAmount: BigNumber; + }, + signature: { signatureType: number | BigNumber; v: number | BigNumber; r: string; s: string }, + ): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + + const functionSignature = + 'validateERC1155OrderSignature((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[],uint128),(uint8,uint8,bytes32,bytes32))'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [order, signature]); + }, + }; + } + /** + * If the given order is buying an ERC721 asset, checks + * whether or not the given token ID satisfies the required + * properties specified in the order. If the order does not + * specify any properties, this function instead checks + * whether the given token ID matches the ID in the order. + * Reverts if any checks fail, or if the order is selling + * an ERC721 asset. + * @param order The ERC721 order. + * @param erc721TokenId The ID of the ERC721 asset. + */ + public validateERC721OrderProperties( + order: { + direction: number | BigNumber; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc721Token: string; + erc721TokenId: BigNumber; + erc721TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + }, + erc721TokenId: BigNumber, + ): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + + assert.isBigNumber('erc721TokenId', erc721TokenId); + const functionSignature = + 'validateERC721OrderProperties((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[]),uint256)'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [order, erc721TokenId]); + }, + }; + } + /** + * Checks whether the given signature is valid for the + * the given ERC721 order. Reverts if not. + * @param order The ERC721 order. + * @param signature The signature to validate. + */ + public validateERC721OrderSignature( + order: { + direction: number | BigNumber; + maker: string; + taker: string; + expiry: BigNumber; + nonce: BigNumber; + erc20Token: string; + erc20TokenAmount: BigNumber; + fees: Array<{ recipient: string; amount: BigNumber; feeData: string }>; + erc721Token: string; + erc721TokenId: BigNumber; + erc721TokenProperties: Array<{ propertyValidator: string; propertyData: string }>; + }, + signature: { signatureType: number | BigNumber; v: number | BigNumber; r: string; s: string }, + ): ContractTxFunctionObj { + const self = (this as any) as IZeroExContract; + + const functionSignature = + 'validateERC721OrderSignature((uint8,address,address,uint256,uint256,address,uint256,(address,uint256,bytes)[],address,uint256,(address,bytes)[]),(uint8,uint8,bytes32,bytes32))'; + + return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + { data: this.getABIEncodedTransactionData(), ...txData }, + this.estimateGasAsync.bind(this), + ); + if (opts.shouldValidate !== false) { + await this.callAsync(txDataWithDefaults); + } + return self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + }, + awaitTransactionSuccessAsync( + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + return self._promiseWithTransactionHash(this.sendTransactionAsync(txData, opts), opts); + }, + async estimateGasAsync(txData?: Partial | undefined): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + }, + async createAccessListAsync( + txData?: Partial | undefined, + defaultBlock?: BlockParam, + ): Promise { + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync({ + data: this.getABIEncodedTransactionData(), + ...txData, + }); + return self._web3Wrapper.createAccessListAsync(txDataWithDefaults, defaultBlock); + }, + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + BaseContract._assertCallParams(callData, defaultBlock); + const rawCallResult = await self._performCallAsync( + { data: this.getABIEncodedTransactionData(), ...callData }, + defaultBlock, + ); + const abiEncoder = self._lookupAbiEncoder(functionSignature); + BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder); + return abiEncoder.strictDecodeReturnValue(rawCallResult); + }, + getABIEncodedTransactionData(): string { + return self._strictEncodeArguments(functionSignature, [order, signature]); + }, + }; + } /** * Subscribe to an event type emitted by the IZeroEx contract. diff --git a/packages/contract-wrappers/src/generated-wrappers/maximum_gas_price.ts b/packages/contract-wrappers/src/generated-wrappers/maximum_gas_price.ts index 105b8fd3ab..d3f9d7959f 100644 --- a/packages/contract-wrappers/src/generated-wrappers/maximum_gas_price.ts +++ b/packages/contract-wrappers/src/generated-wrappers/maximum_gas_price.ts @@ -253,6 +253,7 @@ export class MaximumGasPriceContract extends BaseContract { const functionSignature = 'checkGasPrice()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -280,6 +281,7 @@ export class MaximumGasPriceContract extends BaseContract { const functionSignature = 'checkGasPrice(uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( diff --git a/packages/contract-wrappers/src/generated-wrappers/staking.ts b/packages/contract-wrappers/src/generated-wrappers/staking.ts index a9d6b1409f..61eaf6f7a4 100644 --- a/packages/contract-wrappers/src/generated-wrappers/staking.ts +++ b/packages/contract-wrappers/src/generated-wrappers/staking.ts @@ -1697,6 +1697,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'addAuthorizedAddress(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -1758,6 +1759,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'addExchangeAddress(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -1817,6 +1819,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'aggregatedStatsByEpoch(uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, @@ -1843,6 +1846,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'authorities(uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1864,6 +1868,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'authorized(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1884,6 +1889,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'cobbDouglasAlphaDenominator()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1904,6 +1910,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'cobbDouglasAlphaNumerator()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1932,6 +1939,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'computeRewardBalanceOfDelegator(bytes32,address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1958,6 +1966,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'computeRewardBalanceOfOperator(bytes32)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1990,6 +1999,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'createStakingPool(uint32,bool)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -2046,6 +2056,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'currentEpoch()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -2066,6 +2077,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'currentEpochStartTimeInSeconds()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -2097,6 +2109,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'decreaseStakingPoolOperatorShare(bytes32,uint32)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -2159,6 +2172,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'endEpoch()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -2215,6 +2229,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'epochDurationInSeconds()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -2244,6 +2259,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'finalizePool(bytes32)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -2304,6 +2320,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'getAuthorizedAddresses()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -2330,6 +2347,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'getCurrentEpochEarliestEndTimeInSeconds()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -2358,6 +2376,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'getGlobalStakeByStatus(uint8)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, @@ -2396,6 +2415,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'getOwnerStakeByStatus(address,uint8)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, @@ -2427,6 +2447,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'getParams()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, @@ -2463,6 +2484,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'getStakeDelegatedToPoolByOwner(address,bytes32)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, @@ -2495,6 +2517,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'getStakingPool(bytes32)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, @@ -2526,6 +2549,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'getStakingPoolStatsThisEpoch(bytes32)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, @@ -2559,6 +2583,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'getTotalStake(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -2588,6 +2613,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'getTotalStakeDelegatedToPool(bytes32)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, @@ -2620,6 +2646,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'getWethContract()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -2645,6 +2672,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'getZrxVault()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -2670,6 +2698,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'init()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -2731,6 +2760,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'joinStakingPoolAsMaker(bytes32)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -2787,6 +2817,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'lastPoolId()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -2807,6 +2838,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'minimumPoolStake()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -2841,6 +2873,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'moveStake((uint8,bytes32),(uint8,bytes32),uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -2897,6 +2930,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'owner()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -2933,6 +2967,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'payProtocolFee(address,address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -2994,6 +3029,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'poolIdByMaker(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -3019,6 +3055,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'poolStatsByEpoch(bytes32,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, @@ -3047,6 +3084,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'removeAuthorizedAddress(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -3110,6 +3148,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'removeAuthorizedAddressAtIndex(address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -3171,6 +3210,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'removeExchangeAddress(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -3227,6 +3267,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'rewardDelegatedStakeWeight()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -3248,6 +3289,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'rewardsByPoolId(bytes32)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -3290,6 +3332,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'setParams(uint256,uint32,uint256,uint32,uint32)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -3358,6 +3401,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'stake(uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -3414,6 +3458,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'stakingContract()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -3439,6 +3484,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'transferOwnership(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -3502,6 +3548,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'unstake(uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -3559,6 +3606,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'validExchanges(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -3579,6 +3627,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'wethReservedForPoolRewards()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -3605,6 +3654,7 @@ export class StakingContract extends BaseContract { const functionSignature = 'withdrawDelegatorRewards(bytes32)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, diff --git a/packages/contract-wrappers/src/generated-wrappers/staking_proxy.ts b/packages/contract-wrappers/src/generated-wrappers/staking_proxy.ts index 2002a03c36..2cdd30c407 100644 --- a/packages/contract-wrappers/src/generated-wrappers/staking_proxy.ts +++ b/packages/contract-wrappers/src/generated-wrappers/staking_proxy.ts @@ -824,6 +824,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'addAuthorizedAddress(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -883,6 +884,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'aggregatedStatsByEpoch(uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, @@ -911,6 +913,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'assertValidStorageParams()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -936,6 +939,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'attachStakingContract(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -993,6 +997,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'authorities(uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1014,6 +1019,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'authorized(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1040,6 +1046,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'batchExecute(bytes[])'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -1096,6 +1103,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'cobbDouglasAlphaDenominator()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1116,6 +1124,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'cobbDouglasAlphaNumerator()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1136,6 +1145,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'currentEpoch()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1156,6 +1166,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'currentEpochStartTimeInSeconds()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1179,6 +1190,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'detachStakingContract()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -1235,6 +1247,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'epochDurationInSeconds()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1259,6 +1272,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'getAuthorizedAddresses()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1279,6 +1293,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'lastPoolId()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1299,6 +1314,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'minimumPoolStake()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1319,6 +1335,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'owner()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1340,6 +1357,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'poolIdByMaker(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1365,6 +1383,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'poolStatsByEpoch(bytes32,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync( callData: Partial = {}, defaultBlock?: BlockParam, @@ -1393,6 +1412,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'removeAuthorizedAddress(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -1456,6 +1476,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'removeAuthorizedAddressAtIndex(address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -1512,6 +1533,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'rewardDelegatedStakeWeight()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1533,6 +1555,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'rewardsByPoolId(bytes32)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1553,6 +1576,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'stakingContract()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1578,6 +1602,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'transferOwnership(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -1635,6 +1660,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'validExchanges(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -1655,6 +1681,7 @@ export class StakingProxyContract extends BaseContract { const functionSignature = 'wethReservedForPoolRewards()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( diff --git a/packages/contract-wrappers/src/generated-wrappers/weth9.ts b/packages/contract-wrappers/src/generated-wrappers/weth9.ts index bc76cfe69a..922484e304 100644 --- a/packages/contract-wrappers/src/generated-wrappers/weth9.ts +++ b/packages/contract-wrappers/src/generated-wrappers/weth9.ts @@ -549,6 +549,7 @@ export class WETH9Contract extends BaseContract { const functionSignature = 'allowance(address,address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -571,6 +572,7 @@ export class WETH9Contract extends BaseContract { const functionSignature = 'approve(address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -628,6 +630,7 @@ export class WETH9Contract extends BaseContract { const functionSignature = 'balanceOf(address)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -648,6 +651,7 @@ export class WETH9Contract extends BaseContract { const functionSignature = 'decimals()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -668,6 +672,7 @@ export class WETH9Contract extends BaseContract { const functionSignature = 'deposit()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -724,6 +729,7 @@ export class WETH9Contract extends BaseContract { const functionSignature = 'name()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -744,6 +750,7 @@ export class WETH9Contract extends BaseContract { const functionSignature = 'symbol()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -764,6 +771,7 @@ export class WETH9Contract extends BaseContract { const functionSignature = 'totalSupply()'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { BaseContract._assertCallParams(callData, defaultBlock); const rawCallResult = await self._performCallAsync( @@ -786,6 +794,7 @@ export class WETH9Contract extends BaseContract { const functionSignature = 'transfer(address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -845,6 +854,7 @@ export class WETH9Contract extends BaseContract { const functionSignature = 'transferFrom(address,address,uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, @@ -902,6 +912,7 @@ export class WETH9Contract extends BaseContract { const functionSignature = 'withdraw(uint256)'; return { + selector: self._lookupAbiEncoder(functionSignature).getSelector(), async sendTransactionAsync( txData?: Partial | undefined, opts: SendTransactionOpts = { shouldValidate: true }, diff --git a/packages/contract-wrappers/src/index.ts b/packages/contract-wrappers/src/index.ts index 4535ffffb1..95855203b1 100644 --- a/packages/contract-wrappers/src/index.ts +++ b/packages/contract-wrappers/src/index.ts @@ -142,6 +142,12 @@ export { IZeroExRfqOrderFilledEventArgs, IZeroExRfqOrderOriginsAllowedEventArgs, IZeroExOrderSignerRegisteredEventArgs, + IZeroExERC1155OrderCancelledEventArgs, + IZeroExERC1155OrderFilledEventArgs, + IZeroExERC1155OrderPreSignedEventArgs, + IZeroExERC721OrderCancelledEventArgs, + IZeroExERC721OrderFilledEventArgs, + IZeroExERC721OrderPreSignedEventArgs, } from './generated-wrappers/i_zero_ex'; export { StakingAuthorizedAddressAddedEventArgs, diff --git a/packages/migrations/package.json b/packages/migrations/package.json index 14b908a38e..0cedb1439b 100644 --- a/packages/migrations/package.json +++ b/packages/migrations/package.json @@ -48,7 +48,7 @@ "registry": "git@github.com:0xProject/gitpkg-registry.git" }, "devDependencies": { - "@0x/dev-utils": "^4.2.9", + "@0x/dev-utils": "^4.2.11", "@0x/ts-doc-gen": "^0.0.28", "@0x/tslint-config": "^4.1.4", "@0x/types": "^3.3.4", @@ -67,7 +67,7 @@ "yargs": "^10.0.3" }, "dependencies": { - "@0x/base-contract": "^6.4.2", + "@0x/base-contract": "^6.4.5", "@0x/contract-addresses": "^6.11.0", "@0x/contracts-asset-proxy": "^3.7.19", "@0x/contracts-coordinator": "^3.1.38", @@ -82,11 +82,11 @@ "@0x/contracts-staking": "^2.0.45", "@0x/contracts-utils": "^4.8.6", "@0x/contracts-zero-ex": "^0.30.1", - "@0x/sol-compiler": "^4.7.5", - "@0x/subproviders": "^6.6.0", + "@0x/sol-compiler": "^4.7.8", + "@0x/subproviders": "^6.6.2", "@0x/typescript-typings": "^5.2.1", - "@0x/utils": "^6.4.4", - "@0x/web3-wrapper": "^7.6.0", + "@0x/utils": "^6.5.0", + "@0x/web3-wrapper": "^7.6.2", "@ledgerhq/hw-app-eth": "^4.3.0", "@types/web3-provider-engine": "^14.0.0", "ethereum-types": "^3.6.0", diff --git a/packages/protocol-utils/CHANGELOG.json b/packages/protocol-utils/CHANGELOG.json index 4b483fe6a2..e34e053960 100644 --- a/packages/protocol-utils/CHANGELOG.json +++ b/packages/protocol-utils/CHANGELOG.json @@ -1,4 +1,17 @@ [ + { + "version": "1.11.0", + "changes": [ + { + "note": "Add utils and errors for NFT orders", + "pr": 429 + }, + { + "note": "Update getTypeHash to support nested structs", + "pr": 429 + } + ] + }, { "timestamp": 1640364306, "version": "1.10.1", diff --git a/packages/protocol-utils/package.json b/packages/protocol-utils/package.json index b21e99580e..8a156f7173 100644 --- a/packages/protocol-utils/package.json +++ b/packages/protocol-utils/package.json @@ -41,7 +41,7 @@ }, "homepage": "https://github.com/0xProject/protocol/tree/main/packages/protocol-utils", "devDependencies": { - "@0x/dev-utils": "^4.2.9", + "@0x/dev-utils": "^4.2.11", "@0x/ts-doc-gen": "^0.0.28", "@0x/tslint-config": "^4.1.4", "@0x/types": "^3.3.4", @@ -62,13 +62,13 @@ "web3-provider-engine": "14.0.6" }, "dependencies": { - "@0x/assert": "^3.0.29", + "@0x/assert": "^3.0.31", "@0x/contract-addresses": "^6.11.0", - "@0x/contract-wrappers": "^13.18.5", - "@0x/json-schemas": "^6.3.0", - "@0x/subproviders": "^6.6.0", - "@0x/utils": "^6.4.4", - "@0x/web3-wrapper": "^7.6.0", + "@0x/contract-wrappers": "^13.18.4", + "@0x/json-schemas": "^6.4.1", + "@0x/subproviders": "^6.6.2", + "@0x/utils": "^6.5.0", + "@0x/web3-wrapper": "^7.6.2", "chai": "^4.0.1", "ethereumjs-util": "^7.0.10", "ethers": "~4.0.4", diff --git a/packages/protocol-utils/src/eip712_utils.ts b/packages/protocol-utils/src/eip712_utils.ts index ebe2303c4a..3ee74d020c 100644 --- a/packages/protocol-utils/src/eip712_utils.ts +++ b/packages/protocol-utils/src/eip712_utils.ts @@ -74,8 +74,19 @@ export function getExchangeProxyEIP712Hash(structHash: string, chainId?: number, /** * Compute the type hash of an EIP712 struct given its ABI. */ -export function getTypeHash(structName: string, abi: EIP712_STRUCT_ABI): string { - return hexUtils.hash( - hexUtils.toHex(Buffer.from([`${structName}(`, abi.map(a => `${a.type} ${a.name}`).join(','), ')'].join(''))), - ); +export function getTypeHash( + primaryStructName: string, + primaryStructAbi: EIP712_STRUCT_ABI, + referencedStructs: { [structName: string]: EIP712_STRUCT_ABI } = {}, +): string { + const primaryStructType = encodeType(primaryStructName, primaryStructAbi); + // Referenced structs are sorted lexicographically + const referencedStructTypes = Object.entries(referencedStructs) + .sort(([nameA], [nameB]) => nameA.localeCompare(nameB)) + .map(([name, abi]) => encodeType(name, abi)); + return hexUtils.hash(hexUtils.toHex(Buffer.from(primaryStructType + referencedStructTypes.join('')))); +} + +function encodeType(structName: string, abi: EIP712_STRUCT_ABI): string { + return [`${structName}(`, abi.map(a => `${a.type} ${a.name}`).join(','), ')'].join(''); } diff --git a/packages/protocol-utils/src/index.ts b/packages/protocol-utils/src/index.ts index dabf725aae..957ecc5d49 100644 --- a/packages/protocol-utils/src/index.ts +++ b/packages/protocol-utils/src/index.ts @@ -2,6 +2,13 @@ import * as _RevertErrors from './revert-errors'; export const RevertErrors = _RevertErrors; export const RevertError = _RevertErrors.RevertError; +import { ERC1155Order, ERC721Order, OrderStatus, TradeDirection } from './nft_orders'; +export { ERC1155Order, ERC721Order }; +export const NFTOrder = { + OrderStatus, + TradeDirection, +}; + export * from './eip712_utils'; export * from './orders'; export * from './meta_transactions'; diff --git a/packages/protocol-utils/src/nft_orders.ts b/packages/protocol-utils/src/nft_orders.ts new file mode 100644 index 0000000000..482442d2d7 --- /dev/null +++ b/packages/protocol-utils/src/nft_orders.ts @@ -0,0 +1,425 @@ +import { getContractAddressesForChainOrThrow } from '@0x/contract-addresses'; +import { SupportedProvider } from '@0x/subproviders'; +import { EIP712TypedData } from '@0x/types'; +import { BigNumber, hexUtils, NULL_ADDRESS } from '@0x/utils'; + +import { ZERO } from './constants'; +import { + createExchangeProxyEIP712Domain, + EIP712_DOMAIN_PARAMETERS, + getExchangeProxyEIP712Hash, + getTypeHash, +} from './eip712_utils'; +import { + eip712SignHashWithKey, + eip712SignTypedDataWithProviderAsync, + ethSignHashWithKey, + ethSignHashWithProviderAsync, + Signature, + SignatureType, +} from './signature_utils'; + +// tslint:disable:enum-naming +export enum TradeDirection { + SellNFT = 0, + BuyNFT = 1, +} +// tslint:enable:enum-naming + +export enum OrderStatus { + Invalid = 0, + Fillable = 1, + Unfillable = 2, + Expired = 3, +} + +interface Fee { + recipient: string; + amount: BigNumber; + feeData: string; +} + +interface Property { + propertyValidator: string; + propertyData: string; +} + +const NFT_ORDER_DEFAULT_VALUES = { + direction: TradeDirection.SellNFT, + maker: NULL_ADDRESS, + taker: NULL_ADDRESS, + expiry: ZERO, + nonce: ZERO, + erc20Token: NULL_ADDRESS, + erc20TokenAmount: ZERO, + fees: [] as Fee[], + chainId: 1, + verifyingContract: getContractAddressesForChainOrThrow(1).exchangeProxy, +}; + +const ERC721_ORDER_DEFAULT_VALUES = { + direction: TradeDirection.SellNFT, + maker: NULL_ADDRESS, + taker: NULL_ADDRESS, + expiry: ZERO, + nonce: ZERO, + erc20Token: NULL_ADDRESS, + erc20TokenAmount: ZERO, + fees: [] as Fee[], + erc721Token: NULL_ADDRESS, + erc721TokenId: ZERO, + erc721TokenProperties: [] as Property[], + chainId: 1, + verifyingContract: getContractAddressesForChainOrThrow(1).exchangeProxy, +}; + +const ERC1155_ORDER_DEFAULT_VALUES = { + direction: TradeDirection.SellNFT, + maker: NULL_ADDRESS, + taker: NULL_ADDRESS, + expiry: ZERO, + nonce: ZERO, + erc20Token: NULL_ADDRESS, + erc20TokenAmount: ZERO, + fees: [] as Fee[], + erc1155Token: NULL_ADDRESS, + erc1155TokenId: ZERO, + erc1155TokenProperties: [] as Property[], + erc1155TokenAmount: ZERO, + chainId: 1, + verifyingContract: getContractAddressesForChainOrThrow(1).exchangeProxy, +}; + +type CommonNFTOrderFields = typeof NFT_ORDER_DEFAULT_VALUES; +type ERC721OrderFields = typeof ERC721_ORDER_DEFAULT_VALUES; +type ERC1155OrderFields = typeof ERC1155_ORDER_DEFAULT_VALUES; + +export abstract class NFTOrder { + public static readonly FEE_ABI = [ + { type: 'address', name: 'recipient' }, + { type: 'uint256', name: 'amount' }, + { type: 'bytes', name: 'feeData' }, + ]; + public static readonly PROPERTY_ABI = [ + { type: 'address', name: 'propertyValidator' }, + { type: 'bytes', name: 'propertyData' }, + ]; + public static readonly FEE_TYPE_HASH = getTypeHash('Fee', NFTOrder.FEE_ABI); + public static readonly PROPERTY_TYPE_HASH = getTypeHash('Property', NFTOrder.PROPERTY_ABI); + + public direction: TradeDirection; + public maker: string; + public taker: string; + public expiry: BigNumber; + public nonce: BigNumber; + public erc20Token: string; + public erc20TokenAmount: BigNumber; + public fees: Fee[]; + public chainId: number; + public verifyingContract: string; + + protected constructor(fields: Partial = {}) { + const _fields = { ...NFT_ORDER_DEFAULT_VALUES, ...fields }; + this.direction = _fields.direction; + this.maker = _fields.maker; + this.taker = _fields.taker; + this.expiry = _fields.expiry; + this.nonce = _fields.nonce; + this.erc20Token = _fields.erc20Token; + this.erc20TokenAmount = _fields.erc20TokenAmount; + this.fees = _fields.fees; + this.chainId = _fields.chainId; + this.verifyingContract = _fields.verifyingContract; + } + + public abstract getStructHash(): string; + public abstract getEIP712TypedData(): EIP712TypedData; + protected abstract _getProperties(): Property[]; + + public willExpire(secondsFromNow: number = 0): boolean { + const millisecondsInSecond = 1000; + const currentUnixTimestampSec = new BigNumber(Date.now() / millisecondsInSecond).integerValue(); + return this.expiry.isLessThan(currentUnixTimestampSec.plus(secondsFromNow)); + } + + public getHash(): string { + return getExchangeProxyEIP712Hash(this.getStructHash(), this.chainId, this.verifyingContract); + } + + public async getSignatureWithProviderAsync( + provider: SupportedProvider, + type: SignatureType = SignatureType.EthSign, + signer: string = this.maker, + ): Promise { + switch (type) { + case SignatureType.EIP712: + return eip712SignTypedDataWithProviderAsync(this.getEIP712TypedData(), signer, provider); + case SignatureType.EthSign: + return ethSignHashWithProviderAsync(this.getHash(), signer, provider); + default: + throw new Error(`Cannot sign with signature type: ${type}`); + } + } + + public getSignatureWithKey(key: string, type: SignatureType = SignatureType.EthSign): Signature { + switch (type) { + case SignatureType.EIP712: + return eip712SignHashWithKey(this.getHash(), key); + case SignatureType.EthSign: + return ethSignHashWithKey(this.getHash(), key); + default: + throw new Error(`Cannot sign with signature type: ${type}`); + } + } + + protected _getPropertiesHash(): string { + return hexUtils.hash( + hexUtils.concat( + ...this._getProperties().map(property => + hexUtils.hash( + hexUtils.concat( + hexUtils.leftPad(NFTOrder.PROPERTY_TYPE_HASH), + hexUtils.leftPad(property.propertyValidator), + hexUtils.hash(property.propertyData), + ), + ), + ), + ), + ); + } + + protected _getFeesHash(): string { + return hexUtils.hash( + hexUtils.concat( + ...this.fees.map(fee => + hexUtils.hash( + hexUtils.concat( + hexUtils.leftPad(NFTOrder.FEE_TYPE_HASH), + hexUtils.leftPad(fee.recipient), + hexUtils.leftPad(fee.amount), + hexUtils.hash(fee.feeData), + ), + ), + ), + ), + ); + } +} + +export class ERC721Order extends NFTOrder { + public static readonly STRUCT_NAME = 'ERC721Order'; + public static readonly STRUCT_ABI = [ + { type: 'uint8', name: 'direction' }, + { type: 'address', name: 'maker' }, + { type: 'address', name: 'taker' }, + { type: 'uint256', name: 'expiry' }, + { type: 'uint256', name: 'nonce' }, + { type: 'address', name: 'erc20Token' }, + { type: 'uint256', name: 'erc20TokenAmount' }, + { type: 'Fee[]', name: 'fees' }, + { type: 'address', name: 'erc721Token' }, + { type: 'uint256', name: 'erc721TokenId' }, + { type: 'Property[]', name: 'erc721TokenProperties' }, + ]; + + public static readonly TYPE_HASH = getTypeHash(ERC721Order.STRUCT_NAME, ERC721Order.STRUCT_ABI, { + ['Fee']: NFTOrder.FEE_ABI, + ['Property']: NFTOrder.PROPERTY_ABI, + }); + + public erc721Token: string; + public erc721TokenId: BigNumber; + public erc721TokenProperties: Property[]; + + constructor(fields: Partial = {}) { + const _fields = { ...ERC721_ORDER_DEFAULT_VALUES, ...fields }; + super(_fields); + this.erc721Token = _fields.erc721Token; + this.erc721TokenId = _fields.erc721TokenId; + this.erc721TokenProperties = _fields.erc721TokenProperties; + } + + public clone(fields: Partial = {}): ERC721Order { + return new ERC721Order({ + direction: this.direction, + maker: this.maker, + taker: this.taker, + expiry: this.expiry, + nonce: this.nonce, + erc20Token: this.erc20Token, + erc20TokenAmount: this.erc20TokenAmount, + fees: this.fees, + erc721Token: this.erc721Token, + erc721TokenId: this.erc721TokenId, + erc721TokenProperties: this.erc721TokenProperties, + chainId: this.chainId, + verifyingContract: this.verifyingContract, + ...fields, + }); + } + + public getStructHash(): string { + return hexUtils.hash( + hexUtils.concat( + hexUtils.leftPad(ERC721Order.TYPE_HASH), + hexUtils.leftPad(this.direction), + hexUtils.leftPad(this.maker), + hexUtils.leftPad(this.taker), + hexUtils.leftPad(this.expiry), + hexUtils.leftPad(this.nonce), + hexUtils.leftPad(this.erc20Token), + hexUtils.leftPad(this.erc20TokenAmount), + this._getFeesHash(), + hexUtils.leftPad(this.erc721Token), + hexUtils.leftPad(this.erc721TokenId), + this._getPropertiesHash(), + ), + ); + } + + public getEIP712TypedData(): EIP712TypedData { + return { + types: { + EIP712Domain: EIP712_DOMAIN_PARAMETERS, + [ERC721Order.STRUCT_NAME]: ERC721Order.STRUCT_ABI, + ['Fee']: NFTOrder.FEE_ABI, + ['Property']: NFTOrder.PROPERTY_ABI, + }, + domain: createExchangeProxyEIP712Domain(this.chainId, this.verifyingContract) as any, + primaryType: ERC721Order.STRUCT_NAME, + message: { + direction: this.direction, + maker: this.maker, + taker: this.taker, + expiry: this.expiry.toString(10), + nonce: this.nonce.toString(10), + erc20Token: this.erc20Token, + erc20TokenAmount: this.erc20TokenAmount.toString(10), + fees: this.fees.map(fee => ({ + recipient: fee.recipient, + amount: fee.amount.toString(10), + feeData: fee.feeData, + })) as any, + erc721Token: this.erc721Token, + erc721TokenId: this.erc721TokenId.toString(10), + erc721TokenProperties: this.erc721TokenProperties as any, + }, + }; + } + + protected _getProperties(): Property[] { + return this.erc721TokenProperties; + } +} + +export class ERC1155Order extends NFTOrder { + public static readonly STRUCT_NAME = 'ERC1155Order'; + public static readonly STRUCT_ABI = [ + { type: 'uint8', name: 'direction' }, + { type: 'address', name: 'maker' }, + { type: 'address', name: 'taker' }, + { type: 'uint256', name: 'expiry' }, + { type: 'uint256', name: 'nonce' }, + { type: 'address', name: 'erc20Token' }, + { type: 'uint256', name: 'erc20TokenAmount' }, + { type: 'Fee[]', name: 'fees' }, + { type: 'address', name: 'erc1155Token' }, + { type: 'uint256', name: 'erc1155TokenId' }, + { type: 'Property[]', name: 'erc1155TokenProperties' }, + { type: 'uint128', name: 'erc1155TokenAmount' }, + ]; + + public static readonly TYPE_HASH = getTypeHash(ERC1155Order.STRUCT_NAME, ERC1155Order.STRUCT_ABI, { + ['Fee']: NFTOrder.FEE_ABI, + ['Property']: NFTOrder.PROPERTY_ABI, + }); + + public erc1155Token: string; + public erc1155TokenId: BigNumber; + public erc1155TokenProperties: Property[]; + public erc1155TokenAmount: BigNumber; + + constructor(fields: Partial = {}) { + const _fields = { ...ERC1155_ORDER_DEFAULT_VALUES, ...fields }; + super(_fields); + this.erc1155Token = _fields.erc1155Token; + this.erc1155TokenId = _fields.erc1155TokenId; + this.erc1155TokenProperties = _fields.erc1155TokenProperties; + this.erc1155TokenAmount = _fields.erc1155TokenAmount; + } + + public clone(fields: Partial = {}): ERC1155Order { + return new ERC1155Order({ + direction: this.direction, + maker: this.maker, + taker: this.taker, + expiry: this.expiry, + nonce: this.nonce, + erc20Token: this.erc20Token, + erc20TokenAmount: this.erc20TokenAmount, + fees: this.fees, + erc1155Token: this.erc1155Token, + erc1155TokenId: this.erc1155TokenId, + erc1155TokenProperties: this.erc1155TokenProperties, + erc1155TokenAmount: this.erc1155TokenAmount, + chainId: this.chainId, + verifyingContract: this.verifyingContract, + ...fields, + }); + } + + public getStructHash(): string { + return hexUtils.hash( + hexUtils.concat( + hexUtils.leftPad(ERC1155Order.TYPE_HASH), + hexUtils.leftPad(this.direction), + hexUtils.leftPad(this.maker), + hexUtils.leftPad(this.taker), + hexUtils.leftPad(this.expiry), + hexUtils.leftPad(this.nonce), + hexUtils.leftPad(this.erc20Token), + hexUtils.leftPad(this.erc20TokenAmount), + this._getFeesHash(), + hexUtils.leftPad(this.erc1155Token), + hexUtils.leftPad(this.erc1155TokenId), + this._getPropertiesHash(), + hexUtils.leftPad(this.erc1155TokenAmount), + ), + ); + } + + public getEIP712TypedData(): EIP712TypedData { + return { + types: { + EIP712Domain: EIP712_DOMAIN_PARAMETERS, + [ERC1155Order.STRUCT_NAME]: ERC1155Order.STRUCT_ABI, + ['Fee']: NFTOrder.FEE_ABI, + ['Property']: NFTOrder.PROPERTY_ABI, + }, + domain: createExchangeProxyEIP712Domain(this.chainId, this.verifyingContract) as any, + primaryType: ERC1155Order.STRUCT_NAME, + message: { + direction: this.direction, + maker: this.maker, + taker: this.taker, + expiry: this.expiry.toString(10), + nonce: this.nonce.toString(10), + erc20Token: this.erc20Token, + erc20TokenAmount: this.erc20TokenAmount.toString(10), + fees: this.fees.map(fee => ({ + recipient: fee.recipient, + amount: fee.amount.toString(10), + feeData: fee.feeData, + })) as any, + erc1155Token: this.erc1155Token, + erc1155TokenId: this.erc1155TokenId.toString(10), + erc1155TokenProperties: this.erc1155TokenProperties as any, + erc1155TokenAmount: this.erc1155TokenAmount.toString(10), + }, + }; + } + + protected _getProperties(): Property[] { + return this.erc1155TokenProperties; + } +} diff --git a/packages/protocol-utils/src/revert-errors/index.ts b/packages/protocol-utils/src/revert-errors/index.ts index 3ba103aa02..1c446b49a1 100644 --- a/packages/protocol-utils/src/revert-errors/index.ts +++ b/packages/protocol-utils/src/revert-errors/index.ts @@ -13,6 +13,7 @@ import { Wallet, } from './inherited'; import * as NativeOrders from './native_orders'; +import * as NFTOrders from './nft_orders'; import * as Signatures from './signatures'; export { @@ -28,4 +29,5 @@ export { LiquidityProvider, NativeOrders, Signatures, + NFTOrders, }; diff --git a/packages/protocol-utils/src/revert-errors/nft_orders.ts b/packages/protocol-utils/src/revert-errors/nft_orders.ts new file mode 100644 index 0000000000..b653b09be0 --- /dev/null +++ b/packages/protocol-utils/src/revert-errors/nft_orders.ts @@ -0,0 +1,142 @@ +// tslint:disable: max-classes-per-file +import { Numberish, RevertError } from '@0x/utils'; + +import { OrderStatus } from '../nft_orders'; + +export class OverspentEthError extends RevertError { + constructor(ethSpent?: Numberish, msgValue?: Numberish) { + super('OverspentEthError', 'OverspentEthError(uint256 ethSpent, uint256 msgValue)', { + ethSpent, + msgValue, + }); + } +} + +export class InsufficientEthError extends RevertError { + constructor(ethAvailable?: Numberish, orderAmount?: Numberish) { + super('InsufficientEthError', 'InsufficientEthError(uint256 ethAvailable, uint256 orderAmount)', { + ethAvailable, + orderAmount, + }); + } +} + +export class ERC721TokenMismatchError extends RevertError { + constructor(token1?: string, token2?: string) { + super('ERC721TokenMismatchError', 'ERC721TokenMismatchError(address token1, address token2)', { + token1, + token2, + }); + } +} + +export class ERC1155TokenMismatchError extends RevertError { + constructor(token1?: string, token2?: string) { + super('ERC1155TokenMismatchError', 'ERC1155TokenMismatchError(address token1, address token2)', { + token1, + token2, + }); + } +} + +export class ERC20TokenMismatchError extends RevertError { + constructor(token1?: string, token2?: string) { + super('ERC20TokenMismatchError', 'ERC20TokenMismatchError(address token1, address token2)', { + token1, + token2, + }); + } +} + +export class NegativeSpreadError extends RevertError { + constructor(sellOrderAmount?: Numberish, buyOrderAmount?: Numberish) { + super('NegativeSpreadError', 'NegativeSpreadError(uint256 sellOrderAmount, uint256 buyOrderAmount)', { + sellOrderAmount, + buyOrderAmount, + }); + } +} + +export class SellOrderFeesExceedSpreadError extends RevertError { + constructor(sellOrderFees?: Numberish, spread?: Numberish) { + super( + 'SellOrderFeesExceedSpreadError', + 'SellOrderFeesExceedSpreadError(uint256 sellOrderFees, uint256 spread)', + { + sellOrderFees, + spread, + }, + ); + } +} + +export class OnlyTakerError extends RevertError { + constructor(sender?: string, taker?: string) { + super('OnlyTakerError', 'OnlyTakerError(address sender, address taker)', { + sender, + taker, + }); + } +} + +export { InvalidSignerError } from './native_orders'; + +export class OrderNotFillableError extends RevertError { + constructor(maker?: string, nonce?: Numberish, orderStatus?: OrderStatus) { + super('OrderNotFillableError', 'OrderNotFillableError(address maker, uint256 nonce, uint8 orderStatus)', { + maker, + nonce, + orderStatus, + }); + } +} + +export class TokenIdMismatchError extends RevertError { + constructor(tokenId?: Numberish, orderTokenId?: Numberish) { + super('TokenIdMismatchError', 'TokenIdMismatchError(uint256 tokenId, uint256 orderTokenId)', { + tokenId, + orderTokenId, + }); + } +} + +export class PropertyValidationFailedError extends RevertError { + constructor( + propertyValidator?: string, + token?: string, + tokenId?: Numberish, + propertyData?: string, + errorData?: string, + ) { + super( + 'PropertyValidationFailedError', + 'PropertyValidationFailedError(address propertyValidator, address token, uint256 tokenId, bytes propertyData, bytes errorData)', + { + propertyValidator, + token, + tokenId, + propertyData, + errorData, + }, + ); + } +} + +const types = [ + OverspentEthError, + InsufficientEthError, + ERC721TokenMismatchError, + ERC1155TokenMismatchError, + ERC20TokenMismatchError, + NegativeSpreadError, + SellOrderFeesExceedSpreadError, + OnlyTakerError, + OrderNotFillableError, + TokenIdMismatchError, + PropertyValidationFailedError, +]; + +// Register the types we've defined. +for (const type of types) { + RevertError.registerType(type); +} diff --git a/packages/protocol-utils/src/signature_utils.ts b/packages/protocol-utils/src/signature_utils.ts index ab961010b9..7607390593 100644 --- a/packages/protocol-utils/src/signature_utils.ts +++ b/packages/protocol-utils/src/signature_utils.ts @@ -12,6 +12,7 @@ export enum SignatureType { Invalid = 1, EIP712 = 2, EthSign = 3, + PreSigned = 4, } /** diff --git a/yarn.lock b/yarn.lock index b734e42e08..4d901558b6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -643,14 +643,14 @@ npmlog "^4.1.2" write-file-atomic "^2.3.0" -"@0x/abi-gen@^5.6.2": - version "5.6.2" - resolved "https://registry.yarnpkg.com/@0x/abi-gen/-/abi-gen-5.6.2.tgz#a31b26b93b061ceb8513424d622119c78b3ed0e9" - integrity sha512-G+B9/VEfsOc8IOgUgkIdFiC+0RNg1DTR921WOxOxcvLsls9m9lBudl7hFrU03N1QdbFFP08e+HDj1kS2Q+SzEQ== +"@0x/abi-gen@^5.7.2": + version "5.7.2" + resolved "https://registry.yarnpkg.com/@0x/abi-gen/-/abi-gen-5.7.2.tgz#c40eb225aab9ee04d331e72af887237dd1967fc0" + integrity sha512-jaFpJqb9hu0kY0yocjmQ0S5suDOBPJYIU3ZuSTZKwnmeOQj4Jl4LzzOTrNWjyqX6+wylW1o4K2/c3e4ZDF+2EA== dependencies: "@0x/types" "^3.3.4" "@0x/typescript-typings" "^5.2.1" - "@0x/utils" "^6.4.4" + "@0x/utils" "^6.5.0" "@types/node" "12.12.54" "@types/toposort" "^2.0.1" chalk "^2.3.0" @@ -677,14 +677,14 @@ lodash "^4.17.11" valid-url "^1.0.9" -"@0x/assert@^3.0.29": - version "3.0.29" - resolved "https://registry.yarnpkg.com/@0x/assert/-/assert-3.0.29.tgz#604e415b943140a1577c9389b04766909a60b589" - integrity sha512-EiF8TwCtM17KFcLy2FYVzu3+7K51VyUNs9ZQ/Wf8tWDeTWrIh1ixKGsNtRnL9sR5SPqOLwKR3lbGn+zPlxw+Yw== +"@0x/assert@^3.0.31": + version "3.0.31" + resolved "https://registry.yarnpkg.com/@0x/assert/-/assert-3.0.31.tgz#2c9e7e0ff9cc7bae8cd0380022e1723ee505a82e" + integrity sha512-ZzlnldKNvhA78IOcH6KCH3kb65XB7fI3wyuocjL72Es3eGTmyVg1KNK7eJnmV+RHSGDTYLwhvmb5hfIvFHMArg== dependencies: - "@0x/json-schemas" "^6.3.0" + "@0x/json-schemas" "^6.4.1" "@0x/typescript-typings" "^5.2.1" - "@0x/utils" "^6.4.4" + "@0x/utils" "^6.5.0" "@types/node" "12.12.54" lodash "^4.17.11" valid-url "^1.0.9" @@ -717,15 +717,15 @@ js-sha3 "^0.7.0" uuid "^3.3.2" -"@0x/base-contract@^6.4.2": - version "6.4.2" - resolved "https://registry.yarnpkg.com/@0x/base-contract/-/base-contract-6.4.2.tgz#d87cb5416613d29d2ec71c60d4a7c6cdd5c48694" - integrity sha512-lcmsXGJ2ImiO1tJoWefYiQ8/WRSdQ4BPA8XulYqVQ4su6PYjLa1XvU91zM779QrIPeRo8fL7FUvGE7CkyG/gwA== +"@0x/base-contract@^6.4.5": + version "6.4.5" + resolved "https://registry.yarnpkg.com/@0x/base-contract/-/base-contract-6.4.5.tgz#f241f5b2c17b3e90e7ead8dec19840ee54ab29bf" + integrity sha512-eYSDhXJxiRrCGWiU6z0P5fPzao4FX1+mujsviXK4a1wp7YvNIYDJ1pEa6C3vCSPJrCHf3EBJT9pwOsNphlyyTg== dependencies: - "@0x/assert" "^3.0.29" - "@0x/json-schemas" "^6.3.0" - "@0x/utils" "^6.4.4" - "@0x/web3-wrapper" "^7.6.0" + "@0x/assert" "^3.0.31" + "@0x/json-schemas" "^6.4.1" + "@0x/utils" "^6.5.0" + "@0x/web3-wrapper" "^7.6.2" "@types/node" "12.12.54" ethereumjs-account "^3.0.0" ethereumjs-blockstream "^7.0.0" @@ -835,16 +835,16 @@ "@0x/typescript-typings" "^5.2.0" ethereum-types "^3.5.0" -"@0x/contracts-gen@^2.0.40": - version "2.0.40" - resolved "https://registry.yarnpkg.com/@0x/contracts-gen/-/contracts-gen-2.0.40.tgz#526c25991125b5a4deb745e470b3c64cd8673095" - integrity sha512-Luj6R4DtPI7KHr3tUSdarudNiySd6GY1mvfhu8566K76oq4aK1no1hf0pyvy9tQLJDViNePP8Ad5KcEmC89sAg== +"@0x/contracts-gen@^2.0.43": + version "2.0.43" + resolved "https://registry.yarnpkg.com/@0x/contracts-gen/-/contracts-gen-2.0.43.tgz#42abf96961d3afa70112ca4f4dc3f129328f1993" + integrity sha512-yVdvx4ihxOZ4fZVE01xxFTylC4cZ+O781cg1A0bWwgAL6GzjzjbDXULfsl0FKfN/4rh+rnwdGrN9Ns5QvB7+xQ== dependencies: - "@0x/sol-compiler" "^4.7.5" + "@0x/sol-compiler" "^4.7.8" "@0x/sol-resolver" "^3.1.9" "@0x/types" "^3.3.4" "@0x/typescript-typings" "^5.2.1" - "@0x/utils" "^6.4.4" + "@0x/utils" "^6.5.0" "@types/node" "12.12.54" ethereum-types "^3.6.0" lodash "^4.17.11" @@ -871,16 +871,16 @@ ethereum-types "^3.5.0" ethereumjs-util "^7.0.10" -"@0x/dev-utils@^4.2.9": - version "4.2.9" - resolved "https://registry.yarnpkg.com/@0x/dev-utils/-/dev-utils-4.2.9.tgz#b048b139b0055ef3702682c42ccc2a3788a49f5d" - integrity sha512-juIjVvky0umt7Tmzhz2PF7e7pQEe1hbrV2XyB5tocRQVAsTD+TuwTG9VVKULQUptX+B/mF1mjb3WwEQV6y/yTQ== +"@0x/dev-utils@^4.2.11": + version "4.2.11" + resolved "https://registry.yarnpkg.com/@0x/dev-utils/-/dev-utils-4.2.11.tgz#017dcc50a91eb75c6ac3d6fe77021e4f4330bbe7" + integrity sha512-8T6803s1GCEdKegjoktMkhp3SVFsKA/m8nDwXy3DiijPGbQejLHxsD0CsR8Uhf/RUP84MMqA0bHYaonb8H4Mag== dependencies: - "@0x/subproviders" "^6.6.0" + "@0x/subproviders" "^6.6.2" "@0x/types" "^3.3.4" "@0x/typescript-typings" "^5.2.1" - "@0x/utils" "^6.4.4" - "@0x/web3-wrapper" "^7.6.0" + "@0x/utils" "^6.5.0" + "@0x/web3-wrapper" "^7.6.2" "@types/node" "12.12.54" "@types/web3-provider-engine" "^14.0.0" chai "^4.0.1" @@ -909,10 +909,10 @@ ajv "^6.12.5" lodash.values "^4.3.0" -"@0x/json-schemas@^6.3.0": - version "6.3.0" - resolved "https://registry.yarnpkg.com/@0x/json-schemas/-/json-schemas-6.3.0.tgz#b7addf8167af492f6667561caa9a62b3ec567696" - integrity sha512-cygnTxvJhLYcDeI05Olp4CN0BKQRs2rC3L0gRCU+mV/IMDNYlkKqNluHmzoHLBleN55uLZZZybSLOsbE5HfIlQ== +"@0x/json-schemas@^6.4.1": + version "6.4.1" + resolved "https://registry.yarnpkg.com/@0x/json-schemas/-/json-schemas-6.4.1.tgz#2db8f6056af7a4d198ae9f56b568473447908d6e" + integrity sha512-4LGe7/QNKAdfxBNu5e5w24JKUqEHGg08TgKhyotStW5m0TJNBGoyGavip1FJeI3KRqNilRN22lgo9HsCBnF5Qg== dependencies: "@0x/typescript-typings" "^5.2.1" "@types/node" "12.12.54" @@ -931,13 +931,13 @@ web3-providers "^2.0.0-alpha.1" websocket "^1.0.29" -"@0x/monorepo-scripts@^3.2.0": - version "3.2.0" - resolved "https://registry.yarnpkg.com/@0x/monorepo-scripts/-/monorepo-scripts-3.2.0.tgz#a4cacf2fd7f4d8f23cd042e4f6aa8fe360aa2c08" - integrity sha512-5z6LYHUIIyZOBGZALZL23LZ76NFfNF9B8IgZS4Oc+j6fFj2bFgTzyj8KqpYHOQXtYmFAom4lSfBelvP9li/oGQ== +"@0x/monorepo-scripts@^3.2.1": + version "3.2.1" + resolved "https://registry.yarnpkg.com/@0x/monorepo-scripts/-/monorepo-scripts-3.2.1.tgz#24e90e835427b199474cc70458d1b3fd52349541" + integrity sha512-PMCKWK/y6aC+HxWk7jbchcAuJ7eMERfH6Ox8op7833MsxNArSp6Fv3XJKU58PWjLVQHpVf51/Cz7E238QAibDg== dependencies: "@0x/types" "^3.3.4" - "@0x/utils" "^6.4.4" + "@0x/utils" "^6.5.0" "@lerna/batch-packages" "^3.0.0-beta.18" "@types/depcheck" "^0.6.0" "@types/node" "12.12.54" @@ -994,18 +994,18 @@ express-async-handler "^1.1.4" http-status-codes "^1.4.0" -"@0x/sol-compiler@^4.7.5": - version "4.7.5" - resolved "https://registry.yarnpkg.com/@0x/sol-compiler/-/sol-compiler-4.7.5.tgz#f744f836786f44747cfd23eb167067ce6f348136" - integrity sha512-vVsMNFLsR7ORuriZXCWloEhDZh3loaTkiFgFI3zTne7wOCwyMntZkgA7uij/iyOGrZW0XEbxAA+QjAYenroRfQ== +"@0x/sol-compiler@^4.7.8": + version "4.7.8" + resolved "https://registry.yarnpkg.com/@0x/sol-compiler/-/sol-compiler-4.7.8.tgz#31bd4f21bbb045d19e2e500282258d6526b5a837" + integrity sha512-0lHaoSDRlPzWCf4o8aEaMoQUnZmeiUreWSNNyPbCO/nF+siPqMPQw6W7ATei/XhVb3UKHZto1ScsyAar/8pIWQ== dependencies: - "@0x/assert" "^3.0.29" - "@0x/json-schemas" "^6.3.0" + "@0x/assert" "^3.0.31" + "@0x/json-schemas" "^6.4.1" "@0x/sol-resolver" "^3.1.9" "@0x/types" "^3.3.4" "@0x/typescript-typings" "^5.2.1" - "@0x/utils" "^6.4.4" - "@0x/web3-wrapper" "^7.6.0" + "@0x/utils" "^6.5.0" + "@0x/web3-wrapper" "^7.6.2" "@types/node" "12.12.54" "@types/yargs" "^11.0.0" chalk "^2.3.0" @@ -1023,13 +1023,13 @@ web3-eth-abi "^1.0.0-beta.24" yargs "^10.0.3" -"@0x/sol-coverage@^4.0.39": - version "4.0.39" - resolved "https://registry.yarnpkg.com/@0x/sol-coverage/-/sol-coverage-4.0.39.tgz#27db909a3f35c625bbf271fa7ecd693eb880ed53" - integrity sha512-mARTgkNX4xkY8UVeYO1oQ0+iY9OJyeRHZbuiWizdeCRuoZth7qk8F1xbywZTCPyo6Pa4zmusi7poKRfHIFTFHA== +"@0x/sol-coverage@^4.0.42": + version "4.0.42" + resolved "https://registry.yarnpkg.com/@0x/sol-coverage/-/sol-coverage-4.0.42.tgz#632c504ec060534d83d19bf9b3f812f271d47a61" + integrity sha512-6R53Kpn1If4D3BI3Pz4qa7AoVLaF7jg6cNNLvqHROW1+chwMGmtPKj2t/R1mKiljTU1lUL1bebfhIJUfYA7IAQ== dependencies: - "@0x/sol-tracing-utils" "^7.2.5" - "@0x/subproviders" "^6.6.0" + "@0x/sol-tracing-utils" "^7.2.8" + "@0x/subproviders" "^6.6.2" "@0x/typescript-typings" "^5.2.1" "@types/minimatch" "^3.0.3" "@types/node" "12.12.54" @@ -1038,15 +1038,15 @@ minimatch "^3.0.4" web3-provider-engine "14.0.6" -"@0x/sol-profiler@^4.1.29": - version "4.1.29" - resolved "https://registry.yarnpkg.com/@0x/sol-profiler/-/sol-profiler-4.1.29.tgz#e77e0ae50541e8acaf7cecb5378a60efd4282f11" - integrity sha512-4CbrNan9xF3auv0ZwjsoajgpqLO23eqcq1u9seSVriNs5IGxEOq4U5xxofvFIMaS0NQXnHJobuUT2qRayBbgkw== +"@0x/sol-profiler@^4.1.32": + version "4.1.32" + resolved "https://registry.yarnpkg.com/@0x/sol-profiler/-/sol-profiler-4.1.32.tgz#93f09264ab414f8e83324d8369a3e6cb2dc8b531" + integrity sha512-FqrP/lAgQCvj5qcr/77leTqgGa2xwYSEIq6/FN5NAE6YYb0JrjJmkwTpxd1fB6xo+T11ESH4+7l5UxjPseuo9w== dependencies: - "@0x/sol-tracing-utils" "^7.2.5" - "@0x/subproviders" "^6.6.0" + "@0x/sol-tracing-utils" "^7.2.8" + "@0x/subproviders" "^6.6.2" "@0x/typescript-typings" "^5.2.1" - "@0x/utils" "^6.4.4" + "@0x/utils" "^6.5.0" "@types/node" "12.12.54" ethereum-types "^3.6.0" ethereumjs-util "^7.1.0" @@ -1063,13 +1063,13 @@ "@types/node" "12.12.54" lodash "^4.17.11" -"@0x/sol-trace@^3.0.39": - version "3.0.39" - resolved "https://registry.yarnpkg.com/@0x/sol-trace/-/sol-trace-3.0.39.tgz#caca4fbf049eda25185c09ab00c23cf37d44d9a2" - integrity sha512-Dg+jPjCnSmWL4t/tq/kQY8NOnAWy/g4HjFQYyL6uz8ioJ4gvCCV+2UADATb2OA7bqrvtbADJrw7icJ+/laqXuA== +"@0x/sol-trace@^3.0.42": + version "3.0.42" + resolved "https://registry.yarnpkg.com/@0x/sol-trace/-/sol-trace-3.0.42.tgz#5a1cb6d4213bbf6746bf393858019fb7b3586916" + integrity sha512-8Elq5aFgMvmUNi3rvDTSA84VMtiyCBNFDaIiKQZ9YtZbgOJnyfxBbelV0sXggnmoochpQ72yX0Cxe3WEdR+5JQ== dependencies: - "@0x/sol-tracing-utils" "^7.2.5" - "@0x/subproviders" "^6.6.0" + "@0x/sol-tracing-utils" "^7.2.8" + "@0x/subproviders" "^6.6.2" "@0x/typescript-typings" "^5.2.1" "@types/node" "12.12.54" chalk "^2.3.0" @@ -1079,18 +1079,18 @@ loglevel "^1.6.1" web3-provider-engine "14.0.6" -"@0x/sol-tracing-utils@^7.2.5": - version "7.2.5" - resolved "https://registry.yarnpkg.com/@0x/sol-tracing-utils/-/sol-tracing-utils-7.2.5.tgz#19ced9ecf6811dab4133ea9acf4dfdd0987b14fd" - integrity sha512-ptffYU/KigOipFGwxWHqToQ/pbkbCyODBcxVTKeEW4MFlHeRMDRHypDM13VFAyAxqQwzvOfk22xeuLVUsKwPVQ== +"@0x/sol-tracing-utils@^7.2.8": + version "7.2.8" + resolved "https://registry.yarnpkg.com/@0x/sol-tracing-utils/-/sol-tracing-utils-7.2.8.tgz#c365931d9f290738fa67d29ae5443d26acf3122c" + integrity sha512-OP9v3bilfvx7JtDQmp4iIE0dZ7Zq0/S9xWP+WLhx2KMKQ1jF9fK3WnsMHea7KtmQnmEBv0naFnEOqedxmus66g== dependencies: - "@0x/dev-utils" "^4.2.9" - "@0x/sol-compiler" "^4.7.5" + "@0x/dev-utils" "^4.2.11" + "@0x/sol-compiler" "^4.7.8" "@0x/sol-resolver" "^3.1.9" - "@0x/subproviders" "^6.6.0" + "@0x/subproviders" "^6.6.2" "@0x/typescript-typings" "^5.2.1" - "@0x/utils" "^6.4.4" - "@0x/web3-wrapper" "^7.6.0" + "@0x/utils" "^6.5.0" + "@0x/web3-wrapper" "^7.6.2" "@types/node" "12.12.54" "@types/solidity-parser-antlr" "^0.2.3" chalk "^2.3.0" @@ -1107,16 +1107,16 @@ solc "^0.5.5" solidity-parser-antlr "^0.4.2" -"@0x/subproviders@^6.6.0": - version "6.6.0" - resolved "https://registry.yarnpkg.com/@0x/subproviders/-/subproviders-6.6.0.tgz#1743d44ae5e2be9ec48caddbf0f1a580f1672d32" - integrity sha512-fQ4efPH/io+TAYEsZuYj9YpoAy0fGWx8QZaWeNstxFT2Miph2aq4Bh+GGrQcXSjNx+prgdBDAGePJvtGP8Qs3Q== +"@0x/subproviders@^6.6.2": + version "6.6.2" + resolved "https://registry.yarnpkg.com/@0x/subproviders/-/subproviders-6.6.2.tgz#c51b3167fcd3b58f5522305864bd4896455ee697" + integrity sha512-/SB6BurdYbGXvIa3rmQdaUYPk7D+BFiAAkvQbsA4s//51eVLLQG+QdgDT1RUKGJbhX11ff31jc7dEu/wh6nQhg== dependencies: - "@0x/assert" "^3.0.29" + "@0x/assert" "^3.0.31" "@0x/types" "^3.3.4" "@0x/typescript-typings" "^5.2.1" - "@0x/utils" "^6.4.4" - "@0x/web3-wrapper" "^7.6.0" + "@0x/utils" "^6.5.0" + "@0x/web3-wrapper" "^7.6.2" "@ethereumjs/common" "^2.4.0" "@ethereumjs/tx" "^3.3.0" "@ledgerhq/hw-app-eth" "^4.3.0" @@ -1294,10 +1294,10 @@ js-sha3 "^0.7.0" lodash "^4.17.11" -"@0x/utils@^6.4.4": - version "6.4.4" - resolved "https://registry.yarnpkg.com/@0x/utils/-/utils-6.4.4.tgz#de9782a7ee2af77580a98a8c6db010dda7f56b94" - integrity sha512-gTfK14tdMNtsmHC6FCrWz221+MYJNdDBdhA1hhnT+Kvru22uvhdTpP2udy7296/4yHZaEkDt5ZkvgJMsJCEhbg== +"@0x/utils@^6.5.0": + version "6.5.0" + resolved "https://registry.yarnpkg.com/@0x/utils/-/utils-6.5.0.tgz#a75eda9a1cdc7cd2520056dbaec678f20f7f16c4" + integrity sha512-1+9nIagW9OQG0rcUaBvIOMolWgZHqSjNADQIJk+GmEMYnt7wUpokSkHPHxmw+/xVQs/da5dh1U0/nWsW+A1Nuw== dependencies: "@0x/types" "^3.3.4" "@0x/typescript-typings" "^5.2.1" @@ -1328,15 +1328,15 @@ ethers "~4.0.4" lodash "^4.17.11" -"@0x/web3-wrapper@^7.6.0": - version "7.6.0" - resolved "https://registry.yarnpkg.com/@0x/web3-wrapper/-/web3-wrapper-7.6.0.tgz#34ae5e32affc02ed425c7bb3402a26fd7880c999" - integrity sha512-yxvTT/w5PFfnbKZ9Xvt412fyhVfiNQ0ugFbJYr+X+Xye+Q9vZzzbfc2a3bJSO7w/HkZx7vND071F/jtqU1JsEg== +"@0x/web3-wrapper@^7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@0x/web3-wrapper/-/web3-wrapper-7.6.2.tgz#fd6c50f67ce21191feabea1f59e1467ea5d89dae" + integrity sha512-o3TjgpJWAInFqkFVaeaGlRDXF53NNgO/M3CfUbC+X8p4ReQm4J81BxEf6yxeDzsPt5qLKzrRzhkRiIWeDIlNQw== dependencies: - "@0x/assert" "^3.0.29" - "@0x/json-schemas" "^6.3.0" + "@0x/assert" "^3.0.31" + "@0x/json-schemas" "^6.4.1" "@0x/typescript-typings" "^5.2.1" - "@0x/utils" "^6.4.4" + "@0x/utils" "^6.5.0" "@types/node" "12.12.54" ethereum-types "^3.6.0" ethereumjs-util "^7.1.0" @@ -10294,9 +10294,9 @@ public-encrypt@^4.0.0: randombytes "^2.0.1" safe-buffer "^5.1.2" -"publish-release@https://github.com/0xProject/publish-release.git#3f8be1105a356527f4b362ff456d94bf9a82f2ed": +"publish-release@git+https://github.com/0xProject/publish-release.git#3f8be1105a356527f4b362ff456d94bf9a82f2ed": version "1.3.3" - resolved "https://github.com/0xProject/publish-release.git#3f8be1105a356527f4b362ff456d94bf9a82f2ed" + resolved "git+https://github.com/0xProject/publish-release.git#3f8be1105a356527f4b362ff456d94bf9a82f2ed" dependencies: async "^0.9.0" ghauth "^2.0.0"