Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

@0x/contracts-exchange-forwarder: ERC20Bridge buy support in Forwarder #2356

Merged
merged 8 commits into from
Nov 26, 2019

Conversation

moodlezoup
Copy link
Contributor

@moodlezoup moodlezoup commented Nov 20, 2019

Description

Adds support for ERC20Bridge orders in the Forwarder. The changes to the Forwarder contracts themselves are pretty small, the only notable exception is the addition of an _isPercentageFee function which checks whether the takerFeeAssetData is equalish to the makerAssetData, e.g. we support orders where the maker asset if from an ERC20 bridge and the taker fee asset is the non-bridge equivalent.
The bulk of the code additions are from test stuff, including:

  • unit tests for _isPercentageFee and _transferAssetToSender
  • Forwarder <> bridge integration tests. The tests basically use the real bridge proxy and bridge contracts, which interact with stubbed out versions of Uniswap and Eth2Dai. These integration tests also required a bunch of scattered changes
  • Added the ERC20BridgeProxy to the DeploymentManager

Testing instructions

Types of changes

Checklist:

  • Prefix PR title with [WIP] if necessary.
  • Add tests to cover changes as needed.
  • Update documentation as needed.
  • Add new entries to the relevant CHANGELOG.jsons.

@moodlezoup moodlezoup force-pushed the feature/forwarder/erc20-bridge-buy branch 2 times, most recently from e05d09f to 91774b1 Compare November 20, 2019 23:10
@moodlezoup moodlezoup marked this pull request as ready for review November 20, 2019 23:33
@coveralls
Copy link

coveralls commented Nov 20, 2019

Coverage Status

Coverage remained the same at 77.804% when pulling aa90253 on feature/forwarder/erc20-bridge-buy into 42c4fe5 on development.

@0xProject 0xProject deleted a comment from buildsize bot Nov 20, 2019
Copy link
Member

@abandeali1 abandeali1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought of another edge case that I couldn't comment on in this review: what happens if the ERC20Bridge transfer actually transfers more of the asset than expected? This isn't reflected in the fillResults.

@0xProject 0xProject deleted a comment from buildsize bot Nov 22, 2019
@buildsize
Copy link

buildsize bot commented Nov 22, 2019

File name Previous Size New Size Change
init.py 60.25 KB 60.25 KB 0 bytes (0%)
abi_gen_dummy.ts 77.71 KB [deleted]
lib_dummy.ts 7.08 KB [deleted]
test_lib_dummy.ts 10.34 KB [deleted]
environment.pickle 1.61 MB 1.61 MB 0 bytes (0%)
index.doctree 187.35 KB 187.35 KB 0 bytes (0%)
.buildinfo 230 bytes 230 bytes 0 bytes (0%)
genindex.html 5.6 KB 5.6 KB 0 bytes (0%)
index.html 2.52 KB 2.52 KB 0 bytes (0%)
objects.inv 380 bytes 380 bytes 0 bytes (0%)
py-modindex.html 3.07 KB 3.07 KB 0 bytes (0%)
search.html 2.84 KB 2.84 KB 0 bytes (0%)
searchindex.js 6.31 KB 6.31 KB 0 bytes (0%)
index.rst.txt 415 bytes 415 bytes 0 bytes (0%)
alabaster.css 10.92 KB 10.92 KB 0 bytes (0%)
basic.css 11.89 KB 11.89 KB 0 bytes (0%)
custom.css 42 bytes 42 bytes 0 bytes (0%)
doctools.js 9.05 KB 9.05 KB 0 bytes (0%)
documentation_options.js 303 bytes 303 bytes 0 bytes (0%)
file.png 286 bytes 286 bytes 0 bytes (0%)
jquery-[version].js 273.79 KB 273.79 KB 0 bytes (0%)
jquery.js 86.08 KB 86.08 KB 0 bytes (0%)
language_data.js 10.59 KB 10.59 KB 0 bytes (0%)
minus.png 90 bytes 90 bytes 0 bytes (0%)
plus.png 90 bytes 90 bytes 0 bytes (0%)
pygments.css 4.69 KB 4.69 KB 0 bytes (0%)
searchtools.js 15.61 KB 15.61 KB 0 bytes (0%)
underscore-[version].js 34.34 KB 34.34 KB 0 bytes (0%)
underscore.js 11.86 KB 11.86 KB 0 bytes (0%)
contract_addresses.html 16.8 KB 16.8 KB 0 bytes (0%)
contract_artifacts.html 8.24 KB 8.24 KB 0 bytes (0%)
json_schemas.html 12.56 KB 12.56 KB 0 bytes (0%)
order_utils.html 47.14 KB 47.14 KB 0 bytes (0%)
erc20_token.html 93.56 KB 93.56 KB 0 bytes (0%)
exchange.html 718.38 KB 718.38 KB 0 bytes (0%)
tx_params.html 9.41 KB 9.41 KB 0 bytes (0%)
local_message_signer.html 15.08 KB 15.08 KB 0 bytes (0%)
asset_data_utils.html 22.66 KB 22.66 KB 0 bytes (0%)
default_api.html 113.17 KB 113.17 KB 0 bytes (0%)
asset_proxy_owner.html 337.39 KB 337.39 KB 0 bytes (0%)
coordinator.html 128.72 KB 128.72 KB 0 bytes (0%)
coordinator_registry.html 39.59 KB 39.59 KB 0 bytes (0%)
dutch_auction.html 66.13 KB 66.13 KB 0 bytes (0%)
erc20_proxy.html 109.07 KB 109.07 KB 0 bytes (0%)
erc721_proxy.html 109.19 KB 109.19 KB 0 bytes (0%)
erc721_token.html 150.2 KB 150.2 KB 0 bytes (0%)
forwarder.html 121.64 KB 121.64 KB 0 bytes (0%)
i_asset_proxy.html 40.18 KB 40.18 KB 0 bytes (0%)
i_validator.html 27.06 KB 27.06 KB 0 bytes (0%)
i_wallet.html 24.9 KB 24.9 KB 0 bytes (0%)
multi_asset_proxy.html 144.04 KB 144.04 KB 0 bytes (0%)
order_validator.html 107.69 KB 107.69 KB 0 bytes (0%)
weth9.html 132.09 KB 132.09 KB 0 bytes (0%)
zrx_token.html 107.61 KB 107.61 KB 0 bytes (0%)
dev_utils.html 526.89 KB 526.89 KB 0 bytes (0%)
types.html 8.54 KB 8.54 KB 0 bytes (0%)
erc1155_mintable.html 276.51 KB 276.51 KB 0 bytes (0%)
erc1155_proxy.html 130.38 KB 130.38 KB 0 bytes (0%)
static_call_proxy.html 34.04 KB 34.04 KB 0 bytes (0%)

"pr": 2356
}
],
"timestamp": 1574461784
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No timestamp for unpublished versions.

Copy link
Member

@abandeali1 abandeali1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, these changes look solid!

Copy link
Contributor

@dorothy-zbornak dorothy-zbornak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good!
Just some small changes and a Q, but otherwise g2g.

.transferAssetToSender(erc721AssetData, invalidAmount)
.awaitTransactionSuccessAsync({ from: receiver });
const expectedError = new ForwarderRevertErrors.Erc721AmountMustEqualOneError(invalidAmount);
expect(tx).to.revertWith(expectedError);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(tx).to.revertWith(expectedError);
return expect(tx).to.revertWith(expectedError);

.transferAssetToSender(randomBytes, TRANSFER_AMOUNT)
.awaitTransactionSuccessAsync({ from: receiver });
const expectedError = new ForwarderRevertErrors.UnsupportedAssetProxyError(hexSlice(randomBytes, 0, 4));
expect(tx).to.revertWith(expectedError);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(tx).to.revertWith(expectedError);
return expect(tx).to.revertWith(expectedError);

import { deployForwarderAsync } from './deploy_forwarder';
import { ForwarderTestFactory } from './forwarder_test_factory';

blockchainTests.resets.only('Forwarder <> ERC20Bridge integration tests', env => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
blockchainTests.resets.only('Forwarder <> ERC20Bridge integration tests', env => {
blockchainTests.resets('Forwarder <> ERC20Bridge integration tests', env => {

// Account for the ERC20Bridge transfering more of the maker asset than expected.
if (makerAssetProxyId == erc20BridgeProxyId) {
uint256 balanceAfter = IERC20Token(tokenAddress).balanceOf(address(this));
makerAssetAcquiredAmount = LibSafeMath.max256(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we just set makerAssetAcquiredAmount to max(makerAssetAcquiredAmount, balanceAfter)? Would that be so wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two edge cases:

  • someone accidentally transfers tokens to the Forwarder
  • makerAsset is WETH, which seems silly but given the flexibility of the bridge pattern I could see there being a use case for this at some point 🤷‍♂

@moodlezoup moodlezoup changed the title ERC20Bridge buy support in Forwarder @0x/contracts-exchange-forwarder: ERC20Bridge buy support in Forwarder Nov 26, 2019
@moodlezoup moodlezoup force-pushed the feature/forwarder/erc20-bridge-buy branch from 210bc91 to 4157665 Compare November 26, 2019 22:20
@moodlezoup moodlezoup merged commit 38dd45c into development Nov 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants