-
Notifications
You must be signed in to change notification settings - Fork 96
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
Diffs for UpgradeableGHO-GHO #411
Closed
miguelmtzinf
wants to merge
2
commits into
feat/upgradeable-gho-token
from
fix/upgradeable-gho-token-diff
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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,68 @@ | ||
```diff | ||
diff --git a/src/contracts/gho/ERC20.sol b/src/contracts/gho/UpgradeableERC20.sol | ||
index d0cad6b..aa25fcb 100644 | ||
--- a/src/contracts/gho/ERC20.sol | ||
+++ b/src/contracts/gho/UpgradeableERC20.sol | ||
@@ -4,12 +4,14 @@ pragma solidity ^0.8.0; | ||
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; | ||
|
||
/** | ||
- * @title ERC20 | ||
- * @notice Gas Efficient ERC20 + EIP-2612 implementation | ||
- * @dev Modified version of Solmate ERC20 (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC20.sol), | ||
- * implementing the basic IERC20 | ||
+ * @title UpgradeableERC20 | ||
+ * @author Aave Labs | ||
+ * @notice Upgradeable version of Solmate ERC20 | ||
+ * @dev Contract adaptations: | ||
+ * - Removal of domain separator optimization | ||
+ * - Move of name and symbol definition to initialization stage | ||
*/ | ||
-abstract contract ERC20 is IERC20 { | ||
+abstract contract UpgradeableERC20 is IERC20 { | ||
/*/////////////////////////////////////////////////////////////// | ||
METADATA STORAGE | ||
//////////////////////////////////////////////////////////////*/ | ||
@@ -37,23 +39,23 @@ abstract contract ERC20 is IERC20 { | ||
bytes32 public constant PERMIT_TYPEHASH = | ||
keccak256('Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)'); | ||
|
||
- uint256 internal immutable INITIAL_CHAIN_ID; | ||
- | ||
- bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR; | ||
- | ||
mapping(address => uint256) public nonces; | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
CONSTRUCTOR | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
- constructor(string memory _name, string memory _symbol, uint8 _decimals) { | ||
+ constructor(uint8 _decimals) { | ||
+ decimals = _decimals; | ||
+ } | ||
+ | ||
+ /*/////////////////////////////////////////////////////////////// | ||
+ INITIALIZER | ||
+ //////////////////////////////////////////////////////////////*/ | ||
+ | ||
+ function _ERC20_init(string memory _name, string memory _symbol) internal { | ||
name = _name; | ||
symbol = _symbol; | ||
- decimals = _decimals; | ||
- | ||
- INITIAL_CHAIN_ID = block.chainid; | ||
- INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator(); | ||
} | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
@@ -137,7 +139,7 @@ abstract contract ERC20 is IERC20 { | ||
} | ||
|
||
function DOMAIN_SEPARATOR() public view virtual returns (bytes32) { | ||
- return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator(); | ||
+ return computeDomainSeparator(); | ||
} | ||
|
||
function computeDomainSeparator() internal view virtual returns (bytes32) { | ||
``` |
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,48 @@ | ||
```diff | ||
diff --git a/src/contracts/gho/GhoToken.sol b/src/contracts/gho/UpgradeableGhoToken.sol | ||
index 854e10f..402788c 100644 | ||
--- a/src/contracts/gho/GhoToken.sol | ||
+++ b/src/contracts/gho/UpgradeableGhoToken.sol | ||
@@ -3,14 +3,15 @@ pragma solidity ^0.8.0; | ||
|
||
import {EnumerableSet} from '@openzeppelin/contracts/utils/structs/EnumerableSet.sol'; | ||
import {AccessControl} from '@openzeppelin/contracts/access/AccessControl.sol'; | ||
-import {ERC20} from './ERC20.sol'; | ||
+import {Initializable} from 'solidity-utils/contracts/transparent-proxy/Initializable.sol'; | ||
+import {UpgradeableERC20} from './UpgradeableERC20.sol'; | ||
import {IGhoToken} from './interfaces/IGhoToken.sol'; | ||
|
||
/** | ||
- * @title GHO Token | ||
- * @author Aave | ||
+ * @title Upgradeable GHO Token | ||
+ * @author Aave Labs | ||
*/ | ||
-contract GhoToken is ERC20, AccessControl, IGhoToken { | ||
+contract UpgradeableGhoToken is Initializable, UpgradeableERC20, AccessControl, IGhoToken { | ||
using EnumerableSet for EnumerableSet.AddressSet; | ||
|
||
mapping(address => Facilitator) internal _facilitators; | ||
@@ -24,10 +25,19 @@ contract GhoToken is ERC20, AccessControl, IGhoToken { | ||
|
||
/** | ||
* @dev Constructor | ||
+ */ | ||
+ constructor() UpgradeableERC20(18) { | ||
+ // Intentionally left bank | ||
+ } | ||
+ | ||
+ /** | ||
+ * @dev Initializer | ||
* @param admin This is the initial holder of the default admin role | ||
*/ | ||
- constructor(address admin) ERC20('Gho Token', 'GHO', 18) { | ||
- _setupRole(DEFAULT_ADMIN_ROLE, admin); | ||
+ function initialize(address admin) public virtual initializer { | ||
+ _ERC20_init('Gho Token', 'GHO'); | ||
+ | ||
+ _grantRole(DEFAULT_ADMIN_ROLE, admin); | ||
} | ||
|
||
/// @inheritdoc IGhoToken | ||
``` |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo it's a bit weird to have this immutable when it should always be 18.
Ofc it's quite unlikely to misconfigure, but why even add the option. Imo the path taken by oz making this a constant is more reasonable.
ref: https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/master/contracts/token/ERC20/ERC20Upgradeable.sol#L98
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. However, preference is not change so the diff is little as possible