Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"dependencies": {
"@eth-optimism/solc-transpiler": "~0.0.1-alpha.7",
"@eth-optimism/ovm-truffle-provider-wrapper": "~0.0.1-alpha.8",
"ethereum-waffle": "2.1.0",
"rimraf": "^2.6.3",
"truffle": "^5.1.12",
Expand Down
16 changes: 3 additions & 13 deletions packages/examples/truffle-config-ovm.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const HDWalletProvider = require('truffle-hdwallet-provider');

const OvmTruffleProviderWrapper = require('@eth-optimism/ovm-truffle-provider-wrapper');
const mnemonic = 'candy maple cake sugar pudding cream honey rich smooth crumble sweet treat';

// Set this to the desired Execution Manager Address -- required for the transpiler
process.env.EXECUTION_MANAGER_ADDRESS = process.env.EXECUTION_MANAGER_ADDRESS || "0xA193E42526F1FEA8C99AF609dcEabf30C1c29fAA";
const gasPrice = process.env.OVM_DEFAULT_GAS_PRICE || 0;
const gas = process.env.OVM_DEFAULT_GAS || 9000000;
const chainId = process.env.OVM_CHAIN_ID || 108;


module.exports = {
/**
Expand All @@ -21,17 +21,7 @@ module.exports = {
test: {
network_id: 108,
provider: function() {
const wallet = new HDWalletProvider(mnemonic, "http://127.0.0.1:8545/", 0, 10);
const sendAsync = wallet.sendAsync

wallet.sendAsync = function (...args) {
if (args[0].method === 'eth_sendTransaction') {
// HACK TO PROPERLY SET CHAIN ID
args[0].params[0].chainId = chainId
}
sendAsync.apply(this, args)
};
return wallet;
return OvmTruffleProviderWrapper(new HDWalletProvider(mnemonic, "http://127.0.0.1:8545/", 0, 10))
},
gasPrice: gasPrice,
gas: gas,
Expand Down
29 changes: 29 additions & 0 deletions packages/ovm-truffle-provider-wrapper/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# OVM Truffle Provider Wrapper
The OVM uses a specific `chainId`, which Truffle, at the moment, does not allow to be configured globally within a project, so this package simply wraps the provider that is used in order to set the `chainId` field on all transactions.

## Configuration
ChainId defaults to 108 but is configurable by setting the `OVM_CHAIN_ID` environment variable.

## Example Usage in truffle-config.js:
```$javascript
const HDWalletProvider = require('truffle-hdwallet-provider');
const WrappedProvider = require('@eth-optimism/ovm-truffle-provider-wrapper');
const mnemonic = 'candy maple cake sugar pudding cream honey rich smooth crumble sweet treat';

module.exports = {
networks: {
// Note: Requires running the rollup-full-node locally.
test: {
provider: function () {
return WrappedProvider(new HDWalletProvider(mnemonic, "http://127.0.0.1:8545/", 0, 10))
},
},
},
compilers: {
solc: {
// Add path to the solc-transpiler
version: "../../node_modules/@eth-optimism/solc-transpiler",
}
}
}
```
19 changes: 19 additions & 0 deletions packages/ovm-truffle-provider-wrapper/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = (provider: any) => {
if (typeof provider !== 'object' || !provider['sendAsync']) {
throw Error(
'Invalid provider. Exepcted provider to conform to Truffle provider interface!'
)
}

const chainId = process.env.OVM_CHAIN_ID || 108
const sendAsync = provider.sendAsync

provider.sendAsync = function(...args) {
if (args[0].method === 'eth_sendTransaction') {
// To properly set chainID for all transactions.
args[0].params[0].chainId = chainId
}
sendAsync.apply(this, args)
}
return provider
}
41 changes: 41 additions & 0 deletions packages/ovm-truffle-provider-wrapper/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@eth-optimism/ovm-truffle-provider-wrapper",
"version": "0.0.1-alpha.8",
"description": "Optimism Truffle Provider Wrapper",
"main": "build/index.js",
"files": [
"build/index.js"
],
"scripts": {
"all": "yarn clean && yarn build && yarn fix && yarn lint",
"build": "tsc -p .",
"clean": "rimraf build/",
"fix": "prettier --config ../../prettier-config.json --write 'index.ts' ",
"lint": "tslint --format stylish --project ."
},
"keywords": [
"optimism",
"rollup",
"optimistic",
"ethereum",
"client"
],
"homepage": "https://github.com/ethereum-optimism/optimism-monorepo/tree/master/packages/ovm-truffle-provider-wrapper#readme",
"license": "MIT",
"author": "Optimism PBC",
"repository": {
"type": "git",
"url": "https://github.com/ethereum-optimism/optimism-monorepo.git"
},
"dependencies": {
},
"devDependencies": {
"@types/node": "^12.0.7",
"rimraf": "^2.6.3",
"ts-node": "^8.2.0",
"typescript": "^3.5.1"
},
"publishConfig": {
"access": "public"
}
}
8 changes: 8 additions & 0 deletions packages/ovm-truffle-provider-wrapper/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./../../tsconfig.json",
"compilerOptions": {
"outDir": "./build",
"resolveJsonModule": true
},
"include": ["*.ts"]
}
6 changes: 6 additions & 0 deletions packages/ovm-truffle-provider-wrapper/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": ["./../../tslint.json"],
"rules": {
"prettier": [true, "../../prettier-config.json"]
}
}