-
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.
Adding ovm-truffle-provider-wrapper (#12)
Adding ovm-truffle-provider-wrapper
- Loading branch information
1 parent
bbca409
commit 9973526
Showing
9 changed files
with
119 additions
and
28 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
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 wrapProvider = 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 wrapProvider(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", | ||
} | ||
} | ||
} | ||
``` |
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,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 | ||
} |
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,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" | ||
} | ||
} |
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 @@ | ||
{ | ||
"extends": "./../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./build", | ||
"resolveJsonModule": true | ||
}, | ||
"include": ["*.ts"] | ||
} |
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,6 @@ | ||
{ | ||
"extends": ["./../../tslint.json"], | ||
"rules": { | ||
"prettier": [true, "../../prettier-config.json"] | ||
} | ||
} |