Commit 796dbda5 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

Merge pull request #1344 from ethereum-optimism/sc/contracts-browser-compat

feat: make contracts package browser compatible
parents 3f9941e3 e4fea5e0
---
'@eth-optimism/message-relayer': patch
---
Use latest contracts package for browser compatibility support
---
'@eth-optimism/contracts': patch
---
Makes the contracts package browser compatible.
src/contract-artifacts.ts
......@@ -39,13 +39,14 @@
"lint:fix": "yarn lint:check --fix",
"lint:contracts": "yarn solhint -f table contracts/optimistic-ethereum/**/*.sol",
"clean": "rm -rf ./dist ./artifacts ./artifacts-ovm ./cache ./cache-ovm ./tsconfig.build.tsbuildinfo",
"deploy": "ts-node \"./bin/deploy.ts\" && yarn generate-markdown",
"deploy": "ts-node \"./bin/deploy.ts\" && yarn generate:markdown",
"serve": "./bin/serve_dump.sh",
"prepublishOnly": "yarn copyfiles -u 2 \"contracts/optimistic-ethereum/**/*\" ./",
"postpublish": "rimraf OVM iOVM libraries mockOVM",
"prepack": "yarn prepublishOnly",
"postpack": "yarn postpublish",
"generate-markdown": "node \"./scripts/generate-markdown.js\"",
"generate:markdown": "node \"./scripts/generate-markdown.js\"",
"generate:artifacts": "node \"./scripts/generate-artifacts.js\"",
"pre-commit": "lint-staged"
},
"dependencies": {
......
......@@ -2,6 +2,7 @@
set -e
yarn build:typescript &
yarn build:contracts
yarn build:contracts:ovm
yarn generate:artifacts
yarn build:typescript
#!/usr/bin/env node
const path = require('path')
const glob = require('glob')
const fs = require('fs')
;(async () => {
console.log(`writing contract artifacts typescript file`)
const getContractJsonFiles = (artifactsFolder) => {
return glob.sync(`${artifactsFolder}/**/*.json`).filter((match) => {
return !match.endsWith('.dbg.json')
})
}
const evmArtifactPaths = getContractJsonFiles(
path.resolve(__dirname, `../artifacts/contracts`)
)
const ovmArtifactPaths = getContractJsonFiles(
path.resolve(__dirname, `../artifacts-ovm/contracts`)
)
const content = `
/* eslint-disable @typescript-eslint/no-var-requires, no-empty */
/*
THIS FILE IS AUTOMATICALLY GENERATED.
DO NOT EDIT.
*/
${ovmArtifactPaths
.map((artifactPath) => {
const artifact = require(artifactPath)
const relPath = path.relative(__dirname, artifactPath)
return `
let ovm__${artifact.contractName}
try {
ovm__${artifact.contractName} = require('${relPath}')
} catch {}
`
})
.join('\n')}
${evmArtifactPaths
.map((artifactPath) => {
const artifact = require(artifactPath)
const relPath = path.relative(__dirname, artifactPath)
return `
let ${artifact.contractName}
try {
${artifact.contractName} = require('${relPath}')
} catch {}
`
})
.join('\n')}
export const getContractArtifact = (name: string, ovm: boolean): any => {
if (ovm) {
return {
${ovmArtifactPaths
.map((artifactPath) => {
const artifact = require(artifactPath)
return `${artifact.contractName}: ovm__${artifact.contractName}`
})
.join(',\n')}
}[name]
} else {
return {
${evmArtifactPaths
.map((artifactPath) => {
const artifact = require(artifactPath)
return `${artifact.contractName}: ${artifact.contractName}`
})
.join(',\n')}
}[name]
}
}
`
fs.writeFileSync(`./src/contract-artifacts.ts`, content)
})().catch(console.error)
......@@ -4,10 +4,9 @@ import { expect } from '../../../../setup'
import { ethers } from 'hardhat'
import { Signer, ContractFactory, Contract } from 'ethers'
import { smoddit } from '@eth-optimism/smock'
import { getContractInterface } from '@eth-optimism/contracts'
/* Internal Imports */
import { predeploys } from '../../../../../src'
import { predeploys, getContractInterface } from '../../../../../src'
describe('OVM_L2StandardTokenFactory', () => {
let signer: Signer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment