Skip to content
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
Closed
Show file tree
Hide file tree
Changes from all commits
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
68 changes: 68 additions & 0 deletions diffs/UpgradeableERC20_diff.md
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;

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

Copy link
Contributor Author

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

+ }
+
+ /*///////////////////////////////////////////////////////////////
+ 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) {
```
48 changes: 48 additions & 0 deletions diffs/UpgradeableGhoToken_diff.md
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
```
Loading