Skip to content

Commit

Permalink
Merge pull request #2 from morpho-org/perf/delegation
Browse files Browse the repository at this point in the history
Perf/delegation
  • Loading branch information
MerlinEgalite authored Oct 14, 2024
2 parents 03ab532 + 1ed972f commit 59e8249
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import {IDelegates} from "./IDelegates.sol";
import {IDelegates} from "./interfaces/IDelegates.sol";

import {ECDSA} from
"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol";
import {ContextUpgradeable} from "lib/openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import {ERC20Upgradeable} from "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol";
import {DelegatesUpgradeable} from "./DelegatesUpgradeable.sol";
import {Initializable} from "lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import {ERC20Upgradeable} from "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol";
/**
* @dev Extension of ERC20 to support token delegation. |
*
Expand All @@ -17,41 +16,13 @@ import {Initializable} from "lib/openzeppelin-contracts-upgradeable/contracts/pr
*/

abstract contract ERC20DelegatesUpgradeable is Initializable, ERC20Upgradeable, DelegatesUpgradeable {
/**
* @dev Total supply cap has been exceeded, introducing a risk of votes overflowing.
*/
error ERC20ExceededSafeSupply(uint256 increasedSupply, uint256 cap);

function __ERC20Delegates_init() internal onlyInitializing {}

function __ERC20Delegates_init_unchained() internal onlyInitializing {}
/**
* @dev Maximum token supply. Defaults to `type(uint208).max` (2^208^ - 1).
*
* This maximum is enforced in {_update}. Increasing this value will not remove the underlying limitation, and
* will cause {_update} to fail because of a math overflow in {_transferVotingUnits}. An override could be
* used to further restrict the total supply (to a lower value) if additional logic requires it. When resolving
* override conflicts on this function, the minimum should be returned.
*/

function _maxSupply() internal view virtual returns (uint256) {
return type(uint256).max;
}

/**
* @dev Move voting power when tokens are transferred.
*
* Emits a {IVotes-DelegateVotesChanged} event.
*/
function _update(address from, address to, uint256 value) internal virtual override {
super._update(from, to, value);
if (from == address(0)) {
uint256 supply = totalSupply();
uint256 cap = _maxSupply();
if (supply > cap) {
revert ERC20ExceededSafeSupply(supply, cap);
}
}
_transferVotingUnits(from, to, value);
}

Expand Down
3 changes: 1 addition & 2 deletions src/MorphoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.13;
import {ERC20Upgradeable} from "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol";
import {Ownable2StepUpgradeable} from
"lib/openzeppelin-contracts-upgradeable/contracts/access/Ownable2StepUpgradeable.sol";
import {ERC20DelegatesUpgradeable} from "./DelegatesContracts/ERC20DelegatesUpgradeable.sol";
import {ERC20DelegatesUpgradeable} from "./ERC20DelegatesUpgradeable.sol";
import {
ERC20PermitUpgradeable,
NoncesUpgradeable
Expand Down Expand Up @@ -35,7 +35,6 @@ contract MorphoToken is ERC20DelegatesUpgradeable, ERC20PermitUpgradeable, Ownab
require(dao != address(0), ZeroAddress());
require(wrapper != address(0), ZeroAddress());

ERC20DelegatesUpgradeable.__ERC20Delegates_init();
ERC20Upgradeable.__ERC20_init(NAME, SYMBOL);
Ownable2StepUpgradeable.__Ownable2Step_init();
ERC20PermitUpgradeable.__ERC20Permit_init(NAME);
Expand Down
File renamed without changes.

0 comments on commit 59e8249

Please sign in to comment.