Skip to content

Commit

Permalink
Add OP gateway worker
Browse files Browse the repository at this point in the history
  • Loading branch information
makoto committed Oct 17, 2023
1 parent 116cbb3 commit ecb783b
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 13 deletions.
4 changes: 4 additions & 0 deletions l1-gateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ PROVIDER_URL=$PROVIDER_URL TARGET_ADDRESS=$TARGET_ADDRESS yarn remote_test
- Verifier = [0xA63381212fBf7AA2D0b4a2cAe453f8c361B11d06](https://goerli.etherscan.io/address/0xA63381212fBf7AA2D0b4a2cAe453f8c361B11d06)
- TestL1 = [0xD5b1cB24f9BA18C9c35b3D090309E643bC77491e](https://goerli.etherscan.io/address/0xD5b1cB24f9BA18C9c35b3D090309E643bC77491e)
- TestL2 = [0x43c0CBb8943E394FaE4C4def054D7702c29c9037](https://goerli.etherscan.io/address/0x43c0CBb8943E394FaE4C4def054D7702c29c9037)

## Gateway

- http://l1-gateway-worker.ens-cf.workers.dev
6 changes: 6 additions & 0 deletions l1-gateway/env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DEPLOYER_PRIVATE_KEY=""
L1_PROVIDER_URL=""
L2_PROVIDER_URL=""
L1_ETHERSCAN_API_KEY=""
L2_ETHERSCAN_API_KEY=""
L2_OUTPUT_ORACLE=""
48 changes: 48 additions & 0 deletions op-gateway/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,52 @@
# @ensdomains/op-gateway

An instantiation of [evm-gateway](https://github.com/ensdomains/evmgateway/tree/main/evm-gateway) that targets Optimism - that is, it implements a CCIP-Read gateway that generates proofs of contract state on Optimism.

For a detailed readme and usage instructions, see the [monorepo readme](https://github.com/ensdomains/evmgateway/tree/main).

## How to use l1-gateway locally

```
cd l1-gateway
yarn
touch .dev.vars
## set L1_PROVIDER_URL, L2_PROVIDER_URL, DELAY=5
yarn dev
```

## How to deploy l1-gateway to cloudflare

```
cd l1-gateway
npm install -g wrangler
wrngler login
wrangler secret put L1_PROVIDER_URL
wrangler secret put L2_PROVIDER_URL
wrangler secret put L2_OUTPUT_ORACLE
wrangler secret put DELAY
yarn deploy
```

## How to test

```
cd ../l1-verifier l1-gateway
PROVIDER_URL=$PROVIDER_URL TARGET_ADDRESS=$TARGET_ADDRESS yarn remote_test
```

## Current deployments

## Deployments

### Goerli

- OPVerifier = [0x0c2746F20C9c97DBf718de10c04943cf408230A3](https://goerli.etherscan.io/address/0x0c2746F20C9c97DBf718de10c04943cf408230A3)
- TestL1 = [0x5057276e2BD7750Be043595ac6d21dE31e900c3c](https://goerli.etherscan.io/address/0x5057276e2BD7750Be043595ac6d21dE31e900c3c)

### OptimismGoerli

- TestL2 = [0x0FEcD0Fec173807204c7B31e36384acEeB048b0A](https://goerli-optimism.etherscan.io/address/0x0FEcD0Fec173807204c7B31e36384acEeB048b0A)

## Gateway

- http://op-gateway-worker.ens-cf.workers.dev
7 changes: 5 additions & 2 deletions op-gateway/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Server } from '@ensdomains/ccip-read-cf-worker';
interface Env {
L1_PROVIDER_URL: string
L2_PROVIDER_URL: string
L2_OUTPUT_ORACLE: string
DELAY: number
}
interface Router{
Expand All @@ -16,14 +17,16 @@ async function fetch(request:Request, env:Env){
const EVMGateway = (await import('@ensdomains/evm-gateway')).EVMGateway
const OPProofService = (await import('./OPProofService.js')).OPProofService;
// Set PROVIDER_URL under .dev.vars locally. Set the key as secret remotely with `wrangler secret put WORKER_PROVIDER_URL`
const { L1_PROVIDER_URL, L2_PROVIDER_URL, DELAY } = env;
const { L1_PROVIDER_URL, L2_PROVIDER_URL, L2_OUTPUT_ORACLE, DELAY } = env;
const l1Provider = new ethers.JsonRpcProvider(L1_PROVIDER_URL);
const l2Provider = new ethers.JsonRpcProvider(L2_PROVIDER_URL);

console.log({L1_PROVIDER_URL, L2_PROVIDER_URL, DELAY})
const proof = new EVMGateway(
await OPProofService.create(
new OPProofService(
l1Provider,
l2Provider,
L2_OUTPUT_ORACLE,
Number(DELAY)
)
);
Expand Down
4 changes: 2 additions & 2 deletions op-verifier/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ Start up a devnet by following Optimism's instructions [here](https://community.
Then, deploy the L2 contract:

```
hardhat deploy --network opDevnetL2
bun run hardhat deploy --network opDevnetL2
```

Followed by the L1 contract:

```
hardhat deploy --network opDevnetL1
bun run hardhat deploy --network opDevnetL1
```

The L1 contracts contain a reference to the L2 contract, and so will require redeploying if the L2 contract changes.
Expand Down
19 changes: 13 additions & 6 deletions op-verifier/deploy_l1/00_op_verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ import {DeployFunction} from 'hardhat-deploy/types';
import fs from 'fs';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const {deployments, getNamedAccounts} = hre;
const {deployments, getNamedAccounts, network} = hre;
const {deploy} = deployments;

const {deployer} = await getNamedAccounts();

const opAddresses = await (await fetch("http://localhost:8080/addresses.json")).json();

let L2_OUTPUT_ORACLE_ADDRESS, GATEWAY_URL
console.log('00_op_verifier1')
if(network.name === 'opDevnetL1'){
GATEWAY_URL = 'http://localhost:8080/{sender}/{data}.json'
const opAddresses = await (await fetch("http://localhost:8080/addresses.json")).json();
L2_OUTPUT_ORACLE_ADDRESS = opAddresses.L2OutputOracleProxy
}else if('goerli'){
GATEWAY_URL = 'https://op-gateway-worker.ens-cf.workers.dev/{sender}/{data}.json'
L2_OUTPUT_ORACLE_ADDRESS = '0xE6Dfba0953616Bacab0c9A8ecb3a9BBa77FC15c0'
}
console.log('OPVerifier', [[GATEWAY_URL], L2_OUTPUT_ORACLE_ADDRESS])
await deploy('OPVerifier', {
from: deployer,
args: [['test:'], opAddresses.L2OutputOracleProxy],
args: [[GATEWAY_URL], L2_OUTPUT_ORACLE_ADDRESS],
log: true,
});
};
Expand Down
38 changes: 36 additions & 2 deletions op-verifier/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,57 @@ import '@nomicfoundation/hardhat-toolbox';
import 'hardhat-deploy';
import 'hardhat-deploy-ethers';
import { HardhatUserConfig } from 'hardhat/config';
import 'ethers'
const DEPLOYER_PRIVATE_KEY = process.env.DEPLOYER_PRIVATE_KEY ?? "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
const L1_PROVIDER_URL = process.env.L1_PROVIDER_URL
const L1_ETHERSCAN_API_KEY = process.env.L1_ETHERSCAN_API_KEY;
const L2_ETHERSCAN_API_KEY = process.env.L2_ETHERSCAN_API_KEY;

const config: HardhatUserConfig = {
solidity: '0.8.19',
networks: {
opDevnetL1: {
url: "http://localhost:8545/",
accounts: ["ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"],
accounts: [DEPLOYER_PRIVATE_KEY],
deploy: [ "deploy_l1/" ],
companionNetworks: {
l2: "opDevnetL2",
},
},
opDevnetL2: {
url: "http://localhost:9545/",
accounts: ["ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"],
accounts: [DEPLOYER_PRIVATE_KEY],
deploy: [ "deploy_l2/" ],
},
goerli: {
url: L1_PROVIDER_URL,
accounts: [DEPLOYER_PRIVATE_KEY],
deploy: [ "deploy_l1/" ],
companionNetworks: {
l2: "optimismGoerli",
},
},
optimismGoerli: {
url: "https://goerli.optimism.io",
accounts: [DEPLOYER_PRIVATE_KEY],
deploy: [ "deploy_l2/" ],
}
},
etherscan: {
apiKey: {
goerli: L1_ETHERSCAN_API_KEY,
optimismGoerli: L2_ETHERSCAN_API_KEY
},
customChains: [
{
network: "optimismGoerli",
chainId: 420,
urls: {
apiURL: "https://api-goerli-optimism.etherscan.io/api",
browserURL: "https://goerli-optimism.etherscan.io"
}
}
]
},
namedAccounts: {
'deployer': 0,
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"packages": [
"evm-gateway",
"l1-gateway",
"l1-gateway-worker",
"op-gateway",
"evm-verifier",
"l1-verifier",
Expand Down

0 comments on commit ecb783b

Please sign in to comment.