-
Notifications
You must be signed in to change notification settings - Fork 465
Add workflow for copying compiled artifacts to 0x/contract-artifacts #1842
Conversation
Let's make sure that |
This PR does change a lot of the artifacts, but for the most part they are just formatting changes that remove excess whitespace. However, there are changes to the |
I agree with @albrow. Copying of the new artifacts into |
@albrow @fabioberger, gotcha on updating Can we guarantee/assume that any contract development happens in a separate branch and is published immediately after merging? Or some other way to keep track of what is deployed? Otherwise, if there are incremental un-deployed contract changes, how do we generate artifacts to use in monorepo development? For example right now |
Thanks @xianny. Yeah, that's really annoying. We didn't do a good job of having the protocol team work on V3 in a separate branch from the get-go. Typically that should happen moving forward. Right @abandeali1? That being said, updating the artifacts in our tooling should still remain a separate deliberate step. |
5ab73ed
to
a0333dd
Compare
@fabioberger @dekz ready for re-review. Much simpler changes now. @hysz and I discussed on Slack and decided that the contract artifacts should remain as standard compiler output during development. Fields should only be removed/added prior to being published in This means the This PR makes the following changes to
|
"build": "yarn tsc -b", | ||
"build:ci": "yarn build", | ||
"test": "yarn run_mocha", | ||
"test:circleci": "yarn test", | ||
"run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js --bail --exit", | ||
"clean": "shx rm -rf lib" | ||
}, | ||
"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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the script, let's actually read it from the root package.json
instead of duplicating this here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To get this to build, I had to change rootDir: ./
to rootDir: ../..
in the tsconfig.json
. Waiting for CI to see if it causes any issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wound up breaking relative links by introducing nesting to the build output. I'm not sure it's worth it to introduce this weirdness here.
Build output:
lib
├── package.json
└── packages
└── contract-artifacts
├── artifacts
│ ├── AssetProxyOwner.json
│ ├── Coordinator.json
│ ├── CoordinatorRegistry.json
│ ├── DummyERC20Token.json
│ ├── DummyERC721Token.json
│ ├── DutchAuction.json
│ ├── ERC20Proxy.json
│ ├── ERC20Token.json
│ ├── ERC721Proxy.json
│ ├── ERC721Token.json
│ ├── Exchange.json
│ ├── Forwarder.json
│ ├── IAssetProxy.json
│ ├── IValidator.json
│ ├── IWallet.json
│ ├── MultiAssetProxy.json
│ ├── OrderValidator.json
│ ├── WETH9.json
│ └── ZRXToken.json
├── src
│ ├── copy.d.ts
│ ├── copy.d.ts.map
│ ├── copy.js
│ ├── copy.js.map
│ ├── index.d.ts
│ ├── index.d.ts.map
│ ├── index.js
│ ├── index.js.map
│ ├── transform.d.ts
│ ├── transform.d.ts.map
│ ├── transform.js
│ └── transform.js.map
└── test
├── contract_artifacts_test.d.ts
├── contract_artifacts_test.d.ts.map
├── contract_artifacts_test.js
└── contract_artifacts_test.js.map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use fs.readFile
fs.copyFileSync(_path, targetPathPython); | ||
utils.log(`Copied from ${_path} to ${targetPath}`); | ||
} | ||
utils.log(`Finished copying contract-artifacts. Remember to lint artifacts before using abi-gen.`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utils.log(`Finished copying contract-artifacts. Remember to lint artifacts before using abi-gen.`); | |
utils.log(`Finished copying contract-artifacts.`); |
The transform happens automatically now right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily. The yarn shortcut runs copy && transform
, but this script only does copy
, so I think we should keep this log line in case the script is used alone.
The resulting output looks like this:
[17:24:58]contract-artifacts (feature/prepublish-contract-artifacts)$ yarn artifacts_update
yarn run v1.9.4
$ yarn artifacts_copy && yarn artifacts_transform
$ node lib/src/copy.js ${npm_package_config_contractsPackages}
Finished copying contract-artifacts. Remember to transform artifacts before publishing or using abi-gen
$ node lib/src/transform.js ./artifacts && prettier --write ./artifacts/*.json && cp -r ./artifacts/ ../../python-packages/contract_artifacts/src/zero_ex/contract_artifacts/artifacts/
Deleting forbidden properties from artifacts in ./artifacts. Output to ./artifacts
artifacts/AssetProxyOwner.json 117ms
artifacts/Coordinator.json 37ms
artifacts/CoordinatorRegistry.json 22ms
artifacts/DummyERC20Token.json 27ms
artifacts/DummyERC721Token.json 37ms
artifacts/DutchAuction.json 22ms
artifacts/ERC20Proxy.json 27ms
artifacts/ERC20Token.json 25ms
artifacts/ERC721Proxy.json 23ms
artifacts/ERC721Token.json 19ms
artifacts/Exchange.json 74ms
artifacts/Forwarder.json 20ms
artifacts/IAssetProxy.json 9ms
artifacts/IValidator.json 8ms
artifacts/IWallet.json 7ms
artifacts/MultiAssetProxy.json 12ms
artifacts/OrderValidator.json 21ms
artifacts/WETH9.json 14ms
artifacts/ZRXToken.json 13ms
✨ Done in 2.54s.
[17:25:12]contract-artifacts (feature/prepublish-contract-artifacts)$
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
import { deleteNestedProperty, logUtils } from '@0x/utils'; | ||
import * as fs from 'fs'; | ||
|
||
export const REQUIRE_PROPERTIES: string[] = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const REQUIRE_PROPERTIES: string[] = [ | |
export const REQUIRED_PROPERTIES: string[] = [ |
…xProject#1842) The contract artifacts should remain as standard compiler output during development. Fields should only be removed/added prior to being published in `@0x/contract-artifacts`. This PR adds the `yarn transform` script to `@0x/contract-artifacts` to facilitate this. Going forward, `abi-gen-templates` will have to support both standard artifacts and modified artifacts if they diverge, since the templates are used for `contract-artifacts`/`abi-gen-wrappers` (modified artifact) *and* development in all the `contracts/*` packages (standard artifact). This PR makes the following changes to `contract-artifacts`: - remove `evm.bytecode.linkReferences` from all artifacts - remove `evm.deployedBytecode` and `sourceTreeHashHex` from Coordinator artifact - prettify all artifacts (whitespace only changes)
Description
Currently we have to copy compiled artifacts manually into
@0x/contract-artifacts
. This is tedious and error-prone.I added a
contracts:postcompile
step to copy the compiled artifacts into thepackages/contract-artifacts/artifacts
. This will only copy files that are exported from the@0x/contract-artifacts
package.I also added a linter script to remove the unneeded properties from the compiler output, so that we don't unnecessarily bloat bundle size.
The workflow is as follows:
yarn contracts:compile
as usual. This compiles and then copies the files to contract-artifacts. There will be a prompt to lintcontract-artifacts
.yarn lint
insidecontract-artifacts
, then runyarn test
to confirm it works.Question: Should we add the lint step to the compile+postcompile step?
Part II
This PR also updates the artifacts to include
deployedBytecode
which is needed for the multilang project.Testing instructions
Follow above workflow.
Types of changes
Checklist:
[WIP]
if necessary.