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

switch @0x/contract-wrappers to generated wrappers #2037

Merged
merged 5 commits into from
Aug 8, 2019

Conversation

xianny
Copy link
Contributor

@xianny xianny commented Aug 7, 2019

Description

Switch to using generated wrappers in @0x/contract-wrappers.

This PR reproduces the factory class ContractWrappers to help interface with the individual contracts.

This PR does not refactor the current uses of contract-wrappers in the monorepo. Most cases are easy to refactor but there are a couple cases where we will need to implement a workaround. Before publishing the new version of contract-wrappers, we can't specify new vs old version for existing monorepo dependencies, so it will be easier to update them all at the same time and after we have published the new version. There are 5 packages that currently use contract-wrappers:

  • contracts/extensions
  • 0x.js
  • asset-buyer
  • asset-swapper
  • website
  • order-watcher [DEPRECATED]

This PR does not get rid of abi-gen-wrappers. We will remove it after monorepo use cases have been refactored out.

This follow-up work is tracked here: #1989

Testing instructions

I've kept the existing manually written exchange_wrapper_test, which works.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)

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.

@xianny xianny force-pushed the multilang/deprecate-contract-wrappers branch 3 times, most recently from a0a0763 to 49fa73b Compare August 7, 2019 01:51
@buildsize
Copy link

buildsize bot commented Aug 7, 2019

File name Previous Size New Size Change
init.py 141.35 KB 141.35 KB 0 bytes (0%)
abi_gen_dummy.ts 144.09 KB [deleted]
lib_dummy.ts 4.74 KB [deleted]
test_lib_dummy.ts 12.61 KB [deleted]
environment.pickle 1.56 MB 1.56 MB 0 bytes (0%)
index.doctree 189.53 KB 189.53 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 375 bytes 375 bytes 0 bytes (0%)
py-modindex.html 3.07 KB 3.07 KB 0 bytes (0%)
search.html 2.81 KB 2.81 KB 0 bytes (0%)
searchindex.js 5.83 KB 5.83 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.83 KB 11.83 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 261.76 KB 261.76 KB 0 bytes (0%)
jquery.js 84.63 KB 84.63 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 17.89 KB 17.89 KB 0 bytes (0%)
contract_artifacts.html 7.94 KB 7.94 KB 0 bytes (0%)
_bootstrap.html 142.73 KB 142.73 KB 0 bytes (0%)
json_schemas.html 12.43 KB 12.43 KB 0 bytes (0%)
order_utils.html 44.87 KB 44.87 KB 0 bytes (0%)
erc20_token.html 80.16 KB 80.16 KB 0 bytes (0%)
exchange.html 458.92 KB 458.92 KB 0 bytes (0%)
tx_params.html 8.83 KB 8.83 KB 0 bytes (0%)
local_message_signer.html 15.07 KB 15.07 KB 0 bytes (0%)
asset_data_utils.html 22.65 KB 22.65 KB 0 bytes (0%)
default_api.html 118.49 KB 118.49 KB 0 bytes (0%)
globals.html 13.15 KB [deleted]
asset_proxy_owner.assetproxyownercontract.html 419.2 KB [deleted]
coordinator.coordinatorcontract.html 153.51 KB [deleted]
coordinator_registry.coordinatorregistrycontract.html 95.28 KB [deleted]
dummy_erc20_token.dummyerc20tokencontract.html 250.08 KB [deleted]
dummy_erc721_token.dummyerc721tokencontract.html 291.13 KB [deleted]
dutch_auction.dutchauctioncontract.html 138.38 KB [deleted]
erc20_proxy.erc20proxycontract.html 180.44 KB [deleted]
erc20_token.erc20tokencontract.html 152.99 KB [deleted]
erc721_proxy.erc721proxycontract.html 180.76 KB [deleted]
erc721_token.erc721tokencontract.html 208.09 KB [deleted]
eth_balance_checker.ethbalancecheckercontract.html 63.85 KB [deleted]
exchange.exchangecontract.html 705.67 KB [deleted]
forwarder.forwardercontract.html 166.9 KB [deleted]
i_asset_proxy.iassetproxycontract.html 166.84 KB [deleted]
i_validator.ivalidatorcontract.html 63.74 KB [deleted]
i_wallet.iwalletcontract.html 62.67 KB [deleted]
multi_asset_proxy.multiassetproxycontract.html 218.05 KB [deleted]
order_validator.ordervalidatorcontract.html 137.28 KB [deleted]
weth9.weth9contract.html 201.33 KB [deleted]
zrx_token.zrxtokencontract.html 170.85 KB [deleted]
asset_proxy_owner.assetproxyownerevents.html 26.5 KB [deleted]
coordinator_registry.coordinatorregistryevents.html 12.82 KB [deleted]
dummy_erc20_token.dummyerc20tokenevents.html 13.73 KB [deleted]
dummy_erc721_token.dummyerc721tokenevents.html 15.06 KB [deleted]
erc20_proxy.erc20proxyevents.html 13.94 KB [deleted]
erc20_token.erc20tokenevents.html 13.55 KB [deleted]
erc721_proxy.erc721proxyevents.html 13.97 KB [deleted]
erc721_token.erc721tokenevents.html 14.83 KB [deleted]
exchange.exchangeevents.html 17.13 KB [deleted]
multi_asset_proxy.multiassetproxyevents.html 15.5 KB [deleted]
weth9.weth9events.html 15.51 KB [deleted]
zrx_token.zrxtokenevents.html 13.46 KB [deleted]
asset_proxy_owner.assetproxyownerassetproxyregistrationeventargs.html 17.28 KB [deleted]
asset_proxy_owner.assetproxyownerconfirmationeventargs.html 17.08 KB [deleted]
asset_proxy_owner.assetproxyownerconfirmationtimeseteventargs.html 17.23 KB [deleted]
asset_proxy_owner.assetproxyownerdepositeventargs.html 16.96 KB [deleted]
asset_proxy_owner.assetproxyownerexecutioneventargs.html 16.12 KB [deleted]
asset_proxy_owner.assetproxyownerexecutionfailureeventargs.html 16.17 KB [deleted]
asset_proxy_owner.assetproxyownerowneradditioneventargs.html 16.07 KB [deleted]
asset_proxy_owner.assetproxyownerownerremovaleventargs.html 16.07 KB [deleted]
asset_proxy_owner.assetproxyownerrequirementchangeeventargs.html 16.12 KB [deleted]
asset_proxy_owner.assetproxyownerrevocationeventargs.html 17.06 KB [deleted]
asset_proxy_owner.assetproxyownersubmissioneventargs.html 16.13 KB [deleted]
asset_proxy_owner.assetproxyownertimelockchangeeventargs.html 16.2 KB [deleted]
coordinator_registry.coordinatorregistrycoordinatorendpointseteventargs.html 14.7 KB [deleted]
dummy_erc20_token.dummyerc20tokenapprovaleventargs.html 15.38 KB [deleted]
dummy_erc20_token.dummyerc20tokentransfereventargs.html 15.34 KB [deleted]
dummy_erc721_token.dummyerc721tokenapprovaleventargs.html 15.72 KB [deleted]
dummy_erc721_token.dummyerc721tokenapprovalforalleventargs.html 15.77 KB [deleted]
dummy_erc721_token.dummyerc721tokentransfereventargs.html 15.67 KB [deleted]
erc20_proxy.erc20proxyauthorizedaddressaddedeventargs.html 14.45 KB [deleted]
erc20_proxy.erc20proxyauthorizedaddressremovedeventargs.html 14.47 KB [deleted]
erc20_token.erc20tokenapprovaleventargs.html 15.17 KB [deleted]
erc20_token.erc20tokentransfereventargs.html 15.12 KB [deleted]
erc721_proxy.erc721proxyauthorizedaddressaddedeventargs.html 14.49 KB [deleted]
erc721_proxy.erc721proxyauthorizedaddressremovedeventargs.html 14.5 KB [deleted]
erc721_token.erc721tokenapprovaleventargs.html 15.48 KB [deleted]
erc721_token.erc721tokenapprovalforalleventargs.html 15.53 KB [deleted]
erc721_token.erc721tokentransfereventargs.html 15.43 KB [deleted]
exchange.exchangeassetproxyregisteredeventargs.html 14.95 KB [deleted]
exchange.exchangecanceleventargs.html 18.8 KB [deleted]
exchange.exchangecanceluptoeventargs.html 15.9 KB [deleted]
exchange.exchangefilleventargs.html 23.7 KB [deleted]
exchange.exchangesignaturevalidatorapprovaleventargs.html 16.07 KB [deleted]
multi_asset_proxy.multiassetproxyassetproxyregisteredeventargs.html 14.93 KB [deleted]
multi_asset_proxy.multiassetproxyauthorizedaddressaddedeventargs.html 14.93 KB [deleted]
multi_asset_proxy.multiassetproxyauthorizedaddressremovedeventargs.html 14.95 KB [deleted]
weth9.weth9approvaleventargs.html 15.31 KB [deleted]
weth9.weth9depositeventargs.html 14.42 KB [deleted]
weth9.weth9transfereventargs.html 15.27 KB [deleted]
weth9.weth9withdrawaleventargs.html 14.45 KB [deleted]
zrx_token.zrxtokenapprovaleventargs.html 15.06 KB [deleted]
zrx_token.zrxtokentransfereventargs.html 15.02 KB [deleted]
asset_proxy_owner.html 21.01 KB [deleted]
coordinator.html 10.54 KB [deleted]
coordinator_registry.html 13.35 KB [deleted]
dummy_erc20_token.html 13.78 KB [deleted]
dummy_erc721_token.html 14.55 KB [deleted]
dutch_auction.html 10.57 KB [deleted]
erc20_proxy.html 13.76 KB [deleted]
erc20_token.html 13.54 KB [deleted]
erc721_proxy.html 13.8 KB [deleted]
erc721_token.html 14.26 KB [deleted]
eth_balance_checker.html 10.63 KB [deleted]
exchange.html 15.33 KB [deleted]
forwarder.html 10.52 KB [deleted]
i_asset_proxy.html 10.56 KB [deleted]
i_validator.html 10.54 KB [deleted]
i_wallet.html 10.51 KB [deleted]
multi_asset_proxy.html 14.81 KB [deleted]
order_validator.html 10.59 KB [deleted]
weth9.html 14.36 KB [deleted]
zrx_token.html 13.4 KB [deleted]
main.css 69.04 KB [deleted]
main.css.map 30.1 KB [deleted]
icons.png 9.26 KB [deleted]
[email protected] 27.09 KB [deleted]
widgets.png 480 bytes [deleted]
[email protected] 855 bytes [deleted]
main.js 148.53 KB [deleted]
search.js 517.35 KB [deleted]
erc1155_proxy.erc1155proxycontract.html 194.88 KB [deleted]
static_call_proxy.staticcallproxycontract.html 71.1 KB [deleted]
erc1155_proxy.erc1155proxyevents.html 13.73 KB [deleted]
erc1155_proxy.erc1155proxyauthorizedaddressaddedeventargs.html 14.25 KB [deleted]
erc1155_proxy.erc1155proxyauthorizedaddressremovedeventargs.html 14.27 KB [deleted]
erc1155_proxy.html 13.71 KB [deleted]
static_call_proxy.html 10.61 KB [deleted]

@xianny xianny force-pushed the multilang/deprecate-contract-wrappers branch from 49fa73b to 79b4ae3 Compare August 7, 2019 02:05
@coveralls
Copy link

coveralls commented Aug 7, 2019

Coverage Status

Coverage decreased (-2.6%) to 79.404% when pulling 92f0dd7 on multilang/deprecate-contract-wrappers into 5ac7ff7 on development.

@xianny xianny force-pushed the multilang/deprecate-contract-wrappers branch 2 times, most recently from c66935c to 01ff674 Compare August 7, 2019 03:11
@@ -48,7 +48,6 @@
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/dev-utils/README.md",
"devDependencies": {
"@0x/abi-gen": "^3.1.2",
"@0x/contract-wrappers": "^10.1.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this package wasn't using contract-wrappers

@@ -47,7 +47,6 @@
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/extensions/README.md",
"devDependencies": {
"@0x/abi-gen": "^3.1.2",
"@0x/contract-wrappers": "^10.1.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this package wasn't using contract-wrappers

@@ -48,7 +48,7 @@
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/extensions/README.md",
"devDependencies": {
"@0x/abi-gen": "^3.1.2",
"@0x/contract-wrappers": "^10.1.0",
"@0x/contract-wrappers": "10.1.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

pinning the version to do a mass refactor later. Some packages will be complicated to refactor, and before publishing, we can't specify 11.0.0 in some packages and 10.1.0 in others. So for now all packages will still use 10.1.0.

@@ -50,7 +50,7 @@
"config": {
"contractsPackages": "@0x/contracts-asset-proxy @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-exchange-libs @0x/contracts-extensions @0x/contracts-multisig @0x/contracts-test-utils @0x/contracts-utils @0x/contracts-coordinator @0x/contracts-dev-utils",
"mnemonic": "concert load couple harbor equip island argue ramp clarify fence smart topic",
"packagesWithDocPages": "0x.js connect json-schemas subproviders web3-wrapper contract-wrappers order-utils order-watcher sol-compiler sol-coverage sol-profiler sol-trace ethereum-types asset-buyer migrations",
"packagesWithDocPages": "0x.js connect json-schemas subproviders web3-wrapper order-utils order-watcher sol-compiler sol-coverage sol-profiler sol-trace ethereum-types asset-buyer migrations",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will publish documentation later. Waiting for #2033. Tracking this in #1989

ERC721ProxyContract,
ExchangeContract,
ForwarderContract,
OrderValidatorContract,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

test:docs_generate complains if we don't include this

if (Object.keys(logDecodeDependencies) !== undefined) {
for (const key of Object.keys(logDecodeDependencies)) {
logDecodeDependenciesAbiOnly[key] = logDecodeDependencies[key].compilerOutput.abi;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was throwing runtime errors.

@@ -54,22 +52,6 @@ To build this package and all other monorepo packages that it depends on, run th
PKG=@0x/contract-wrappers yarn build
```

Or continuously rebuild on change:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

doesn't make sense to continuously rebuild since it's generated

@@ -87,3 +69,9 @@ yarn lint
```bash
yarn test
```

### Documentation
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copied from the existing abi-gen-wrappers README without changes.

import { AsyncMethod, ContractWrappersError, SyncMethod } from '../types';

import { constants } from './constants';
export enum ContractWrappersError {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we get rid of this now or should we wait for V3 better revert reasons? This file mainly converts Ethereum error msgs (e.g. 'out of gas') into these standardised error codes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's keep it for now.

@xianny xianny requested a review from fabioberger August 7, 2019 03:36
@xianny xianny force-pushed the multilang/deprecate-contract-wrappers branch from 01ff674 to ad9e2c9 Compare August 7, 2019 03:36
@xianny xianny requested review from dekz and feuGeneA August 7, 2019 03:36
@xianny xianny force-pushed the multilang/deprecate-contract-wrappers branch from ad9e2c9 to e57d29a Compare August 7, 2019 03:48
@xianny xianny marked this pull request as ready for review August 7, 2019 03:49
packages/contract-wrappers/package.json Outdated Show resolved Hide resolved
@@ -161,9 +115,8 @@ export class ContractWrappers {
*/
public unsubscribeAll(): void {
this.exchange.unsubscribeAll();
this.erc20Token.unsubscribeAll();
this.erc721Token.unsubscribeAll();
this.etherToken.unsubscribeAll();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the WETH contract not included?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The etherTokenWrapper looked like a wrapper around potentially many WETH9 tokens. Users had to pass in the token address for each method call.

_etherTokenContractsByAddress: {
        [address: string]: WETH9Contract;
    } = {};

...
public async depositAsync(
        etherTokenAddress: string,
        amountInWei: BigNumber,
        depositor: string,
        txOpts: TransactionOpts = {},
    ): Promise<string> {
...

Should we change it to work with just the WETH9 contract deployed at addresses in @0x/contract-addresses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

erc20tokenWrapper and erc721tokenWrapper were similar and I just left those out.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, let's do with the WETH contract address in contract-addresses. If they want something else, they can instantiate it themselves.

export { OrderValidatorWrapper } from './contract_wrappers/order_validator_wrapper';
export { DutchAuctionWrapper } from './contract_wrappers/dutch_auction_wrapper';

export { CoordinatorWrapper } from './coordinator_wrapper';
export { TransactionEncoder } from './utils/transaction_encoder';
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is TransactionEncoder still used? I thought this would be replaced with calls to getABIEncodedTransactionData.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, it was still being used in coordinator. removing.

import { AsyncMethod, ContractWrappersError, SyncMethod } from '../types';

import { constants } from './constants';
export enum ContractWrappersError {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's keep it for now.

packages/utils/src/token_utils.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@feuGeneA feuGeneA left a comment

Choose a reason for hiding this comment

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

Aside from Fabio's comments, seems good to me. (Though I must say I feel like I lack enough context to give a strong stamp of approval on the TypeScript side of wrapper generation.)

@@ -4,4 +4,5 @@
*.svg linguist-generated=true
packages/contract-artifacts/artifacts/*json linguist-generated=true
packages/abi-gen-wrappers/src/generated-wrappers/*.ts linguist-generated=true
packages/contract-wrappers/src/generated-wrappers/*.ts linguist-generated=true
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

* erc20Proxy smart contract.
*/
public erc20Proxy: ERC20ProxyWrapper;
public erc20Proxy: ERC20ProxyContract;
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh how I so love to see the word "wrapper" go away!! 😄

- remove TransactionEncoder
- move TokenUtils to @0x/dev-utils
@xianny xianny force-pushed the multilang/deprecate-contract-wrappers branch from ee9b054 to 9ea1936 Compare August 7, 2019 19:32
xianny added 3 commits August 7, 2019 12:37
* fix getAbiEncodedTransactionData convenience method
* export WETH9Contract from 0x.js
* Update CHANGELOG to point to new issue
@xianny xianny force-pushed the multilang/deprecate-contract-wrappers branch from dd6c0c9 to 92f0dd7 Compare August 7, 2019 21:50
@xianny xianny merged commit 8ce390b into development Aug 8, 2019
@xianny xianny deleted the multilang/deprecate-contract-wrappers branch August 8, 2019 14:29
dorothy-zbornak pushed a commit that referenced this pull request Feb 27, 2020
* switch @0x/contract-wrappers to generated wrappers

- remove TransactionEncoder
- move TokenUtils to @0x/dev-utils
- detailed changes in #2040
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants