-
Notifications
You must be signed in to change notification settings - Fork 4
[DRAFT] V2 => V3 Contract Upgrade #33
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
Open
JamesEarle
wants to merge
6
commits into
feat/token-upgrade
Choose a base branch
from
feat/token-upgrade-v3
base: feat/token-upgrade
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
40b8a91
separate contracts for upgrades and testing
JamesEarle 89cefc8
Merge branch 'feat/token-upgrade' into feat/token-upgrade-v3
JamesEarle 738a85d
more fleshed out tests for v2 => v3 upgrade, added details in google doc
JamesEarle e30eca6
remove redundant code
Whytecrowe 2461600
change init-impl helper to script first not tests, so it accepts the …
JamesEarle b35c1e3
improved tests, some were failing, linter
JamesEarle 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,149 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.3; | ||
|
|
||
| // Slight modifiations from base Open Zeppelin Contracts | ||
| // Consult /oz/README.md for more information | ||
| import "./oz/ERC20Upgradeable.sol"; | ||
| import "./oz/ERC20SnapshotUpgradeable.sol"; | ||
| import "./oz/ERC20PausableUpgradeable.sol"; | ||
|
|
||
| import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | ||
| import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
|
|
||
| import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
|
|
||
| contract ZeroDAOTokenV3 is | ||
| OwnableUpgradeable, | ||
| ERC20Upgradeable, | ||
| ERC20PausableUpgradeable, | ||
| ERC20SnapshotUpgradeable | ||
| { | ||
| using SafeERC20 for IERC20; | ||
|
|
||
| event AuthorizedSnapshotter(address account); | ||
| event DeauthorizedSnapshotter(address account); | ||
| event ERC20TokenWithdrawn( | ||
| IERC20 indexed token, | ||
| address indexed to, | ||
| uint256 indexed amount | ||
| ); | ||
|
|
||
| // Mapping which stores all addresses allowed to snapshot | ||
| mapping(address => bool) authorizedToSnapshot; | ||
|
|
||
| function initialize( | ||
| string memory name, | ||
| string memory symbol | ||
| ) public initializer { | ||
| __ERC20_init(name, symbol); | ||
| } | ||
|
|
||
| // Call this on the implementation contract (not the proxy) | ||
| function initializeImplementation() public initializer {} | ||
|
|
||
| /** | ||
| * Utility function to transfer tokens to many addresses at once. | ||
| * @param recipients The addresses to send tokens to | ||
| * @param amount The amount of tokens to send | ||
| * @return Boolean if the transfer was a success | ||
| */ | ||
| function transferBulk( | ||
| address[] calldata recipients, | ||
| uint256 amount | ||
| ) external returns (bool) { | ||
| address sender = _msgSender(); | ||
|
|
||
| uint256 total = amount * recipients.length; | ||
| require( | ||
| _balances[sender] >= total, | ||
| "ERC20: transfer amount exceeds balance" | ||
| ); | ||
|
|
||
| _balances[sender] -= total; | ||
|
|
||
| for (uint256 i = 0; i < recipients.length; ++i) { | ||
| address recipient = recipients[i]; | ||
| require(recipient != address(0), "ERC20: transfer to the zero address"); | ||
|
|
||
| // Note: _beforeTokenTransfer isn't called here | ||
| // This function emulates what it would do | ||
|
|
||
| _balances[recipient] += amount; | ||
|
|
||
| emit Transfer(sender, recipient, amount); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Utility function to transfer tokens to many addresses at once. | ||
| * @param sender The address to send the tokens from | ||
| * @param recipients The addresses to send tokens to | ||
| * @param amount The amount of tokens to send | ||
| * @return Boolean if the transfer was a success | ||
| */ | ||
| function transferFromBulk( | ||
| address sender, | ||
| address[] calldata recipients, | ||
| uint256 amount | ||
| ) external returns (bool) { | ||
| uint256 total = amount * recipients.length; | ||
| require( | ||
| _balances[sender] >= total, | ||
| "ERC20: transfer amount exceeds balance" | ||
| ); | ||
|
|
||
| // Ensure enough allowance | ||
| uint256 currentAllowance = _allowances[sender][_msgSender()]; | ||
| require( | ||
| currentAllowance >= total, | ||
| "ERC20: transfer total exceeds allowance" | ||
| ); | ||
| _approve(sender, _msgSender(), currentAllowance - total); | ||
|
|
||
| _balances[sender] -= total; | ||
|
|
||
| for (uint256 i = 0; i < recipients.length; ++i) { | ||
| address recipient = recipients[i]; | ||
| require(recipient != address(0), "ERC20: transfer to the zero address"); | ||
|
|
||
| // Note: _beforeTokenTransfer isn't called here | ||
| // This function emulates what it would do (paused and snapshot) | ||
|
|
||
| _balances[recipient] += amount; | ||
|
|
||
| emit Transfer(sender, recipient, amount); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| function _beforeTokenTransfer( | ||
| address from, | ||
| address to, | ||
| uint256 amount | ||
| ) | ||
| internal | ||
| virtual | ||
| override( | ||
| ERC20PausableUpgradeable, | ||
| ERC20SnapshotUpgradeable, | ||
| ERC20Upgradeable | ||
| ) | ||
| { | ||
| super._beforeTokenTransfer(from, to, amount); | ||
| } | ||
|
|
||
| function _transfer( | ||
| address from, | ||
| address to, | ||
| uint256 amount | ||
| ) internal override { | ||
| super._transfer(from, to, amount); | ||
|
|
||
| if (to == address(this)) { | ||
| _burn(to, amount); | ||
| } | ||
| } | ||
| } | ||
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
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
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
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.