Skip to content

Commit

Permalink
Merge branch 'main' of github.com:morpho-org/morpho-token-upgradeable…
Browse files Browse the repository at this point in the history
… into feat/optimism-morpho-token
  • Loading branch information
Jean-Grimal committed Oct 18, 2024
2 parents c02a6cc + caa2c37 commit 66462e6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/openzeppelin-contracts-upgradeable
20 changes: 11 additions & 9 deletions src/ERC20DelegatesUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {Initializable} from "lib/openzeppelin-contracts-upgradeable/contracts/pr
///
/// This extension keeps track of each account's vote power. Vote power can be delegated either by calling the
/// {delegate} function directly, or by providing a signature to be used with {delegateBySig}. Voting power can be
/// queried through the public accessor {getVotes}.
/// queried through the external accessor {getVotes}.
///
/// By default, token balance does not account for voting power. This makes transfers cheaper. The downside is that it
/// requires users to delegate to themselves in order to activate their voting power.
Expand Down Expand Up @@ -49,26 +49,28 @@ abstract contract ERC20DelegatesUpgradeable is

/* PUBLIC */

/// @dev Returns the current amount of votes that `account` has.
function getVotes(address account) public view returns (uint256) {
ERC20DelegatesStorage storage $ = _getERC20DelegatesStorage();
return $._votingPower[account];
}

/// @dev Returns the delegate that `account` has chosen.
function delegates(address account) public view returns (address) {
ERC20DelegatesStorage storage $ = _getERC20DelegatesStorage();
return $._delegatee[account];
}

/* EXTERNAL */

/// @dev Returns the current amount of votes that `account` has.
function getVotes(address account) external view returns (uint256) {
ERC20DelegatesStorage storage $ = _getERC20DelegatesStorage();
return $._votingPower[account];
}

/// @dev Delegates votes from the sender to `delegatee`.
function delegate(address delegatee) public {
function delegate(address delegatee) external {
address account = _msgSender();
_delegate(account, delegatee);
}

/// @dev Delegates votes from signer to `delegatee`.
function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) public {
function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) external {
if (block.timestamp > expiry) {
revert DelegatesExpiredSignature(expiry);
}
Expand Down
1 change: 0 additions & 1 deletion src/MorphoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ contract MorphoToken is ERC20DelegatesUpgradeable, ERC20PermitUpgradeable, Ownab
/// @param wrapper The wrapper contract address to migrate legacy MORPHO tokens to the new one.
function initialize(address dao, address wrapper) public initializer {
require(dao != address(0), ZeroAddress());
require(wrapper != address(0), ZeroAddress());

ERC20Upgradeable.__ERC20_init(NAME, SYMBOL);
Ownable2StepUpgradeable.__Ownable2Step_init();
Expand Down
6 changes: 6 additions & 0 deletions test/MorphoToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,10 @@ contract MorphoTokenTest is BaseTest {
assertEq(newMorpho.getVotes(delegatee1), initialAmount - transferredAmount);
assertEq(newMorpho.getVotes(delegatee2), transferredAmount);
}

function testERC20DelegatesStorageLocation() public pure {
bytes32 expected =
keccak256(abi.encode(uint256(keccak256("morpho.storage.ERC20Delegates")) - 1)) & ~bytes32(uint256(0xff));
assertEq(expected, 0x1dc92b2c6e971ab6e08dfd7dcec0e9496d223ced663ba2a06543451548549500);
}
}
4 changes: 2 additions & 2 deletions test/MorphoTokenMigration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ contract MorphoTokenMigrationTest is BaseTest {
new Wrapper(address(0));
}

function testTotalSupply() public {
function testTotalSupply() public view {
assertEq(newMorpho.totalSupply(), 1_000_000_000e18);
}

function testInitialWrapperBalances() public {
function testInitialWrapperBalances() public view {
assertEq(legacyMorpho.balanceOf(address(wrapper)), 0);
assertEq(newMorpho.balanceOf(address(wrapper)), 1_000_000_000e18);
}
Expand Down

0 comments on commit 66462e6

Please sign in to comment.