-
Notifications
You must be signed in to change notification settings - Fork 3.9k
docs: add hardhat example + ci #641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a7c112c
feat(hardhat-ovm): allow overriding the polling interval for the prov…
gakonst ff9aaf4
chore: add changeset
gakonst 709317b
docs: add hardhat example
platocrat daa7552
ci: add deploy/deploy:ovm
gakonst c979b2b
fix(contracts): wait for contracts to finish
gakonst 0328d96
fix: use istanbul hard fork
gakonst 1a8f5e9
test(contracts): remove hardcoded post-state in nuisance gas test
gakonst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| --- | ||
| "@eth-optimism/hardhat-ovm": minor | ||
| --- | ||
|
|
||
| allow overriding the ethers polling interval |
This file contains hidden or 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 hidden or 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 @@ | ||
| # The Official™ Optimism Tutorial | ||
|
|
||
| [](https://discord.com/channels/667044843901681675) | ||
| [](https://twitter.com/optimismPBC) | ||
|
|
||
| ### For the full README, please see the [guided repository of the `optimism-tutorial`](https://github.com/ethereum-optimism/optimism-tutorial) repository |
This file contains hidden or 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,196 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity >0.6.0 <0.8.0; | ||
|
|
||
| /** | ||
| * @title ERC20 | ||
| * @dev A super simple ERC20 implementation! | ||
| */ | ||
| contract ERC20 { | ||
|
|
||
| /********** | ||
| * Events * | ||
| **********/ | ||
|
|
||
| event Transfer( | ||
| address indexed _from, | ||
| address indexed _to, | ||
| uint256 _value | ||
| ); | ||
|
|
||
| event Approval( | ||
| address indexed _owner, | ||
| address indexed _spender, | ||
| uint256 _value | ||
| ); | ||
|
|
||
|
|
||
| /************* | ||
| * Variables * | ||
| *************/ | ||
|
|
||
| mapping (address => uint256) public balances; | ||
| mapping (address => mapping (address => uint256)) public allowances; | ||
|
|
||
| // Some optional extra goodies. | ||
| uint256 public totalSupply; | ||
| string public name; | ||
|
|
||
|
|
||
| /*************** | ||
| * Constructor * | ||
| ***************/ | ||
|
|
||
| /** | ||
| * @param _initialSupply Initial maximum token supply. | ||
| * @param _name A name for our ERC20 (technically optional, but it's fun ok jeez). | ||
| */ | ||
| constructor( | ||
| uint256 _initialSupply, | ||
| string memory _name | ||
| ) | ||
| public | ||
| { | ||
| balances[msg.sender] = _initialSupply; | ||
| totalSupply = _initialSupply; | ||
| name = _name; | ||
| } | ||
|
|
||
|
|
||
| /******************** | ||
| * Public Functions * | ||
| ********************/ | ||
|
|
||
| /** | ||
| * Checks the balance of an address. | ||
| * @param _owner Address to check a balance for. | ||
| * @return Balance of the address. | ||
| */ | ||
| function balanceOf( | ||
| address _owner | ||
| ) | ||
| external | ||
| view | ||
| returns ( | ||
| uint256 | ||
| ) | ||
| { | ||
| return balances[_owner]; | ||
| } | ||
|
|
||
| /** | ||
| * Transfers a balance from your account to someone else's account! | ||
| * @param _to Address to transfer a balance to. | ||
| * @param _amount Amount to transfer to the other account. | ||
| * @return true if the transfer was successful. | ||
| */ | ||
| function transfer( | ||
| address _to, | ||
| uint256 _amount | ||
| ) | ||
| external | ||
| returns ( | ||
| bool | ||
| ) | ||
| { | ||
| require( | ||
| balances[msg.sender] >= _amount, | ||
| "You don't have enough balance to make this transfer!" | ||
| ); | ||
|
|
||
| balances[msg.sender] -= _amount; | ||
| balances[_to] += _amount; | ||
|
|
||
| emit Transfer( | ||
| msg.sender, | ||
| _to, | ||
| _amount | ||
| ); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Transfers a balance from someone else's account to another account. You need an allowance | ||
| * from the sending account for this to work! | ||
| * @param _from Account to transfer a balance from. | ||
| * @param _to Account to transfer a balance to. | ||
| * @param _amount Amount to transfer to the other account. | ||
| * @return true if the transfer was successful. | ||
| */ | ||
| function transferFrom( | ||
| address _from, | ||
| address _to, | ||
| uint256 _amount | ||
| ) | ||
| external | ||
| returns ( | ||
| bool | ||
| ) | ||
| { | ||
| require( | ||
| balances[_from] >= _amount, | ||
| "Can't transfer from the desired account because it doesn't have enough balance." | ||
| ); | ||
|
|
||
| require( | ||
| allowances[_from][msg.sender] >= _amount, | ||
| "Can't transfer from the desired account because you don't have enough of an allowance." | ||
| ); | ||
|
|
||
| balances[_to] += _amount; | ||
| balances[_from] -= _amount; | ||
|
|
||
| emit Transfer( | ||
| _from, | ||
| _to, | ||
| _amount | ||
| ); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Approves an account to spend some amount from your account. | ||
| * @param _spender Account to approve a balance for. | ||
| * @param _amount Amount to allow the account to spend from your account. | ||
| * @return true if the allowance was successful. | ||
| */ | ||
| function approve( | ||
| address _spender, | ||
| uint256 _amount | ||
| ) | ||
| external | ||
| returns ( | ||
| bool | ||
| ) | ||
| { | ||
| allowances[msg.sender][_spender] = _amount; | ||
|
|
||
| emit Approval( | ||
| msg.sender, | ||
| _spender, | ||
| _amount | ||
| ); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Checks how much a given account is allowed to spend from another given account. | ||
| * @param _owner Address of the account to check an allowance from. | ||
| * @param _spender Address of the account trying to spend from the owner. | ||
| * @return Allowance for the spender from the owner. | ||
| */ | ||
| function allowance( | ||
| address _owner, | ||
| address _spender | ||
| ) | ||
| external | ||
| view | ||
| returns ( | ||
| uint256 | ||
| ) | ||
| { | ||
| return allowances[_owner][_spender]; | ||
| } | ||
| } |
This file contains hidden or 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,20 @@ | ||
| // Just a standard hardhat-deploy deployment definition file! | ||
| const func = async (hre) => { | ||
| const { deployments, getNamedAccounts } = hre | ||
| const { deploy } = deployments | ||
| const { deployer } = await getNamedAccounts() | ||
|
|
||
| const initialSupply = 1000000 | ||
| const name = 'My Optimistic Token' | ||
|
|
||
| await deploy('ERC20', { | ||
| from: deployer, | ||
| args: [initialSupply, name], | ||
| gasPrice: hre.ethers.BigNumber.from('0'), | ||
| gasLimit: 8999999, | ||
| log: true | ||
| }) | ||
| } | ||
|
|
||
| func.tags = ['ERC20'] | ||
| module.exports = func |
This file contains hidden or 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 @@ | ||
| require('@nomiclabs/hardhat-ethers') | ||
| require('@nomiclabs/hardhat-waffle') | ||
| require('hardhat-deploy') | ||
| require("@eth-optimism/hardhat-ovm") | ||
|
|
||
| module.exports = { | ||
| networks: { | ||
| // Add this network to your config! | ||
| optimism: { | ||
| url: 'http://127.0.0.1:8545', | ||
| // instantiate with a mnemonic so that you have >1 accounts available | ||
| accounts: { | ||
| mnemonic: 'test test test test test test test test test test test junk' | ||
| }, | ||
| // This sets the gas price to 0 for all transactions on L2. We do this | ||
| // because account balances are not automatically initiated with an ETH | ||
| // balance (yet, sorry!). | ||
| gasPrice: 0, | ||
| ovm: true // This sets the network as using the ovm and ensure contract will be compiled against that. | ||
| }, | ||
| }, | ||
| solidity: '0.7.6', | ||
| ovm: { | ||
| solcVersion: '0.7.6' | ||
| }, | ||
| namedAccounts: { | ||
| deployer: 0 | ||
| }, | ||
| } |
This file contains hidden or 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,28 @@ | ||
| { | ||
| "name": "@eth-optimism/hardhat-example", | ||
| "private": true, | ||
| "version": "1.0.0", | ||
| "main": "index.js", | ||
| "license": "MIT", | ||
| "scripts": { | ||
| "deploy": "hardhat deploy", | ||
| "deploy:ovm": "hardhat deploy --network optimism", | ||
| "compile": "hardhat compile", | ||
| "compile:ovm": "hardhat compile --network optimism", | ||
| "test": "hardhat test", | ||
| "test:ovm": "hardhat test --network optimism", | ||
| "clean": "rimraf ./cache-ovm ./cache ./artifacts-ovm ./artifacts ./deployments" | ||
| }, | ||
| "devDependencies": { | ||
| "@eth-optimism/hardhat-ovm": "^0.0.3", | ||
| "@nomiclabs/hardhat-ethers": "^2.0.1", | ||
| "@nomiclabs/hardhat-waffle": "^2.0.1", | ||
| "chai": "4.3.4", | ||
| "chai-as-promised": "^7.1.1", | ||
| "ethereum-waffle": "^3.3.0", | ||
| "ethers": "^5.1.4", | ||
| "hardhat": "^2.2.0", | ||
| "hardhat-deploy": "^0.7.5", | ||
| "mocha": "^8.2.1" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.