Skip to content

Commit

Permalink
feat: Add ts contract package for TS
Browse files Browse the repository at this point in the history
different package nah

do it right

Update packages/contracts-ts/CODE_GEN.md

Update packages/contracts-ts/CODE_GEN.md

Update packages/contracts-ts/package.json

Update packages/contracts-ts/package.json

Update packages/contracts-ts/package.json

Update packages/contracts-ts/package.json

Update packages/contracts-ts/package.json

Update packages/contracts-ts/wagmi.config.ts

Update packages/contracts-ts/wagmi.config.ts

feat: generate abis too

feat: Update op-bindings README

feat: Add lint

feat: Add circleci

fix: Fix deploy config

fix: Add coverage

fix: linter

self review nits

fix: Test was not doing what it thought it was doing

linter
  • Loading branch information
Will Cory authored and Will Cory committed Jul 19, 2023
1 parent 5eb852b commit 9a5e879
Show file tree
Hide file tree
Showing 29 changed files with 49,584 additions and 329 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"changelog": ["@changesets/changelog-github", { "repo": "ethereum-optimism/optimism" }],
"commit": false,
"fixed": [],
"linked": [],
"linked": [["contracts-bedrock", "contracts-ts"]],
"access": "public",
"baseBranch": "develop",
"updateInternalDependencies": "patch",
Expand Down
28 changes: 28 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,27 @@ jobs:
name: Upload coverage
command: codecov --verbose --clean --flags <<parameters.coverage_flag>>

contracts-ts-tests:
docker:
- image: us-docker.pkg.dev/oplabs-tools-artifacts/images/ci-builder:latest
resource_class: large
steps:
- checkout
- attach_workspace: { at: "." }
- restore_cache:
name: Restore pnpm Package Cache
keys:
- pnpm-packages-v2-{{ checksum "pnpm.lock.yaml" }}
- check-changed:
patterns: sdk,contracts-bedrock,contracts
- run:
name: Check generated and build
command: pnpm generate:check
working_directory: packages/contracts-ts
- run:
name: typecheck
command: pnpm typecheck

sdk-next-tests:
docker:
- image: us-docker.pkg.dev/oplabs-tools-artifacts/images/ci-builder:latest
Expand Down Expand Up @@ -1336,6 +1357,13 @@ workflows:
dependencies: "(common-ts|core-utils|sdk)"
requires:
- pnpm-monorepo
- js-lint-test:
name: contracts-ts-tests
coverage_flag: contracts-ts-tests
package_name: contracts-ts
dependencies: '(contracts-bedrock|contracts-ts)'
requires:
- pnpm-monorepo
- js-lint-test:
name: sdk-next-tests
coverage_flag: sdk-next-tests
Expand Down
3 changes: 3 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
"inputs": ["default", "testing", "^production"],
"dependsOn": ["^build"]
},
"generate": {
"dependsOn": ["^build"]
},
"build:contracts": {
"inputs": [
"configsProject",
Expand Down
4 changes: 4 additions & 0 deletions op-bindings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ $ make devtools
```

The geth docs for `abigen` can be found [here](https://geth.ethereum.org/docs/dapp/native-bindings).

## See also

TypeScript bindings are also generated in [@eth-optimism/contracts-ts](../packages/contracts-ts/)
6 changes: 4 additions & 2 deletions packages/contracts-bedrock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
"contracts/**/*.sol"
],
"scripts": {
"bindings": "cd ../../op-bindings && make",
"build": "npx nx build:contracts",
"bindings": "pnpm bindings:ts && pnpm bindings:go",
"bindings:ts": "nx generate @eth-optimism/contracts-ts",
"bindings:go": "cd ../../op-bindings && make",
"build": "nx build:contracts",
"prebuild:contracts": "./scripts/verify-foundry-install.sh",
"build:contracts": "pnpm build:forge",
"build:forge": "forge build",
Expand Down
8 changes: 8 additions & 0 deletions packages/contracts-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
artifacts
cache
typechain
.deps
.envrc
.env
/dist/
coverage
7 changes: 7 additions & 0 deletions packages/contracts-ts/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
artifacts
cache
typechain
.deps
.envrc
.env
/dist/
3 changes: 3 additions & 0 deletions packages/contracts-ts/.prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('../../.prettierrc.js'),
}
14 changes: 14 additions & 0 deletions packages/contracts-ts/CODE_GEN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Code gen

Summary -

- This package is generated from [contracts-bedrock](../contracts-bedrock/)
- It's version is kept in sync with contracts bedrock via the [changeset config](../../.changeset/config.json) e.g. if contracts-bedrock is `4.2.0` this package will have the same version.

## Code gen instructions

To run the code gen run the `generate` script from [package.json](./package.json). Make sure node modules is installed.

```bash
pnpm i && pnpm generate
```
21 changes: 21 additions & 0 deletions packages/contracts-ts/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Optimism

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
64 changes: 64 additions & 0 deletions packages/contracts-ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
## Contracts TS

[![codecov](https://codecov.io/gh/ethereum-optimism/optimism/branch/develop/graph/badge.svg?token=0VTG7PG7YR&flag=contracts-bedrock-tests)](https://codecov.io/gh/ethereum-optimism/optimism)

ABI and Address constants + generated code from [@eth-optimism/contracts-bedrock/](../contracts-bedrock/) for use in TypeScript.

Much of this package is generated. See [CODE_GEN.md](./CODE_GEN.md) for instructions on how to generate.

#### @eth-optimism/contracts-ts

The main entrypoint exports constants related to contracts bedrock as const. As const allows it to be [used in TypeScript with stronger typing than importing JSON](https://github.com/microsoft/TypeScript/issues/32063).

- Exports contract abis.
- Exports contract addresses

```typescript
import {
l2OutputOracleProxyABI,
l2OutputOracleAddresses,
} from '@eth-optimism/contracts-ts'

console.log(l2OutputOracleAddresses[10], abi)
```

Addresses are also exported as an object for convenience.

```typescript
import { addresses } from '@eth-optimism/contracts-ts'

console.log(addresses.l2OutputOracle[10])
```

#### @eth-optimism/contracts-ts/react

- All [React hooks](https://wagmi.sh/cli/plugins/react) `@eth-optimism/contracts-ts/react`

```typescript
import { useAddressManagerAddress } from '@eth-optimism/contracts-ts/react'

const component = () => {
const { data, error, loading } = useAddressManagerAddress()
if (loading) {
return <div>Loading</div>
}
if (err) {
return <div>Error</div>
}
return <div>{data}</div>
}
```

#### @eth-optimism/contracts-ts/actions

- All [wagmi actions](https://wagmi.sh/react/actions) for use in Vanilla JS or non react code

```typescript
import { readSystemConfig } from '@eth-optimism/contracts-ts/actions'
console.log(await readSystemConfig())
```

#### See Also

- [Contracts bedrock specs](../../specs/)
- [Wagmi](https://wagmi.sh)
Loading

0 comments on commit 9a5e879

Please sign in to comment.