-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6260 from ethereum-optimism/07-11-feat_Add_ts_con…
…tract_package_for_TS feat: Add ts contract package for TS
- Loading branch information
Showing
29 changed files
with
72,444 additions
and
358 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
artifacts | ||
cache | ||
typechain | ||
.deps | ||
.envrc | ||
.env | ||
/dist/ | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
artifacts | ||
cache | ||
typechain | ||
.deps | ||
.envrc | ||
.env | ||
/dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
...require('../../.prettierrc.js'), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.