|
| 1 | +diff --git a/docs/3.4/diffs/BaseDelegation.sol b/src/contracts/protocol/tokenization/delegation/BaseDelegation.sol |
| 2 | +index c1a95d08..f15ccb69 100644 |
| 3 | +--- a/docs/3.4/diffs/BaseDelegation.sol |
| 4 | ++++ b/src/contracts/protocol/tokenization/delegation/BaseDelegation.sol |
| 5 | +@@ -1,11 +1,14 @@ |
| 6 | + // SPDX-License-Identifier: MIT |
| 7 | + pragma solidity ^0.8.0; |
| 8 | + |
| 9 | +-import {ECDSA} from 'openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol'; |
| 10 | ++import {MessageHashUtils} from 'openzeppelin-contracts/contracts/utils/cryptography/MessageHashUtils.sol'; |
| 11 | ++import {SafeCast} from 'openzeppelin-contracts/contracts/utils/math/SafeCast.sol'; |
| 12 | + |
| 13 | +-import {SafeCast72} from './utils/SafeCast72.sol'; |
| 14 | +-import {IGovernancePowerDelegationToken} from './interfaces/IGovernancePowerDelegationToken.sol'; |
| 15 | +-import {DelegationMode} from './DelegationAwareBalance.sol'; |
| 16 | ++import {WadRayMath} from '../../libraries/math/WadRayMath.sol'; |
| 17 | ++import {Errors} from '../../libraries/helpers/Errors.sol'; |
| 18 | ++ |
| 19 | ++import {IBaseDelegation} from './interfaces/IBaseDelegation.sol'; |
| 20 | ++import {DelegationMode} from '../base/DelegationMode.sol'; |
| 21 | + |
| 22 | + /** |
| 23 | + * @notice The contract implements generic delegation functionality for the upcoming governance v3 |
| 24 | +@@ -18,7 +21,7 @@ import {DelegationMode} from './DelegationAwareBalance.sol'; |
| 25 | + * otherwise at least POWER_SCALE_FACTOR should be adjusted !!! |
| 26 | + * ************************************************************* |
| 27 | + */ |
| 28 | +-abstract contract BaseDelegation is IGovernancePowerDelegationToken { |
| 29 | ++abstract contract BaseDelegation is IBaseDelegation { |
| 30 | + struct DelegationState { |
| 31 | + uint72 delegatedPropositionBalance; |
| 32 | + uint72 delegatedVotingBalance; |
| 33 | +@@ -81,7 +84,7 @@ abstract contract BaseDelegation is IGovernancePowerDelegationToken { |
| 34 | + DelegationState memory delegationState |
| 35 | + ) internal virtual; |
| 36 | + |
| 37 | +- /// @inheritdoc IGovernancePowerDelegationToken |
| 38 | ++ /// @inheritdoc IBaseDelegation |
| 39 | + function delegateByType( |
| 40 | + address delegatee, |
| 41 | + GovernancePowerType delegationType |
| 42 | +@@ -89,13 +92,13 @@ abstract contract BaseDelegation is IGovernancePowerDelegationToken { |
| 43 | + _delegateByType(msg.sender, delegatee, delegationType); |
| 44 | + } |
| 45 | + |
| 46 | +- /// @inheritdoc IGovernancePowerDelegationToken |
| 47 | ++ /// @inheritdoc IBaseDelegation |
| 48 | + function delegate(address delegatee) external override { |
| 49 | + _delegateByType(msg.sender, delegatee, GovernancePowerType.VOTING); |
| 50 | + _delegateByType(msg.sender, delegatee, GovernancePowerType.PROPOSITION); |
| 51 | + } |
| 52 | + |
| 53 | +- /// @inheritdoc IGovernancePowerDelegationToken |
| 54 | ++ /// @inheritdoc IBaseDelegation |
| 55 | + function getDelegateeByType( |
| 56 | + address delegator, |
| 57 | + GovernancePowerType delegationType |
| 58 | +@@ -103,7 +106,7 @@ abstract contract BaseDelegation is IGovernancePowerDelegationToken { |
| 59 | + return _getDelegateeByType(delegator, _getDelegationState(delegator), delegationType); |
| 60 | + } |
| 61 | + |
| 62 | +- /// @inheritdoc IGovernancePowerDelegationToken |
| 63 | ++ /// @inheritdoc IBaseDelegation |
| 64 | + function getDelegates(address delegator) external view override returns (address, address) { |
| 65 | + DelegationState memory delegatorBalance = _getDelegationState(delegator); |
| 66 | + return ( |
| 67 | +@@ -112,7 +115,7 @@ abstract contract BaseDelegation is IGovernancePowerDelegationToken { |
| 68 | + ); |
| 69 | + } |
| 70 | + |
| 71 | +- /// @inheritdoc IGovernancePowerDelegationToken |
| 72 | ++ /// @inheritdoc IBaseDelegation |
| 73 | + function getPowerCurrent( |
| 74 | + address user, |
| 75 | + GovernancePowerType delegationType |
| 76 | +@@ -122,10 +125,12 @@ abstract contract BaseDelegation is IGovernancePowerDelegationToken { |
| 77 | + ? _getBalance(user) |
| 78 | + : 0; |
| 79 | + uint256 userDelegatedPower = _getDelegatedPowerByType(userState, delegationType); |
| 80 | ++ |
| 81 | ++ // The power returned is the scaled power, assuming an index of 1e27. The voting strategy is based on the same assumption. |
| 82 | + return userOwnPower + userDelegatedPower; |
| 83 | + } |
| 84 | + |
| 85 | +- /// @inheritdoc IGovernancePowerDelegationToken |
| 86 | ++ /// @inheritdoc IBaseDelegation |
| 87 | + function getPowersCurrent(address user) external view override returns (uint256, uint256) { |
| 88 | + return ( |
| 89 | + getPowerCurrent(user, GovernancePowerType.VOTING), |
| 90 | +@@ -133,7 +138,7 @@ abstract contract BaseDelegation is IGovernancePowerDelegationToken { |
| 91 | + ); |
| 92 | + } |
| 93 | + |
| 94 | +- /// @inheritdoc IGovernancePowerDelegationToken |
| 95 | ++ /// @inheritdoc IBaseDelegation |
| 96 | + function metaDelegateByType( |
| 97 | + address delegator, |
| 98 | + address delegatee, |
| 99 | +@@ -143,10 +148,11 @@ abstract contract BaseDelegation is IGovernancePowerDelegationToken { |
| 100 | + bytes32 r, |
| 101 | + bytes32 s |
| 102 | + ) external override { |
| 103 | +- require(delegator != address(0), 'INVALID_OWNER'); |
| 104 | ++ require(delegator != address(0), Errors.ZeroAddressNotValid()); |
| 105 | + //solium-disable-next-line |
| 106 | +- require(block.timestamp <= deadline, 'INVALID_EXPIRATION'); |
| 107 | +- bytes32 digest = ECDSA.toTypedDataHash( |
| 108 | ++ require(block.timestamp <= deadline, Errors.InvalidExpiration()); |
| 109 | ++ |
| 110 | ++ bytes32 digest = MessageHashUtils.toTypedDataHash( |
| 111 | + _getDomainSeparator(), |
| 112 | + keccak256( |
| 113 | + abi.encode( |
| 114 | +@@ -160,11 +166,12 @@ abstract contract BaseDelegation is IGovernancePowerDelegationToken { |
| 115 | + ) |
| 116 | + ); |
| 117 | + |
| 118 | +- require(delegator == ECDSA.recover(digest, v, r, s), 'INVALID_SIGNATURE'); |
| 119 | ++ require(delegator == ecrecover(digest, v, r, s), Errors.InvalidSignature()); |
| 120 | ++ |
| 121 | + _delegateByType(delegator, delegatee, delegationType); |
| 122 | + } |
| 123 | + |
| 124 | +- /// @inheritdoc IGovernancePowerDelegationToken |
| 125 | ++ /// @inheritdoc IBaseDelegation |
| 126 | + function metaDelegate( |
| 127 | + address delegator, |
| 128 | + address delegatee, |
| 129 | +@@ -173,17 +180,19 @@ abstract contract BaseDelegation is IGovernancePowerDelegationToken { |
| 130 | + bytes32 r, |
| 131 | + bytes32 s |
| 132 | + ) external override { |
| 133 | +- require(delegator != address(0), 'INVALID_OWNER'); |
| 134 | ++ require(delegator != address(0), Errors.ZeroAddressNotValid()); |
| 135 | + //solium-disable-next-line |
| 136 | +- require(block.timestamp <= deadline, 'INVALID_EXPIRATION'); |
| 137 | +- bytes32 digest = ECDSA.toTypedDataHash( |
| 138 | ++ require(block.timestamp <= deadline, Errors.InvalidExpiration()); |
| 139 | ++ |
| 140 | ++ bytes32 digest = MessageHashUtils.toTypedDataHash( |
| 141 | + _getDomainSeparator(), |
| 142 | + keccak256( |
| 143 | + abi.encode(DELEGATE_TYPEHASH, delegator, delegatee, _incrementNonces(delegator), deadline) |
| 144 | + ) |
| 145 | + ); |
| 146 | + |
| 147 | +- require(delegator == ECDSA.recover(digest, v, r, s), 'INVALID_SIGNATURE'); |
| 148 | ++ require(delegator == ecrecover(digest, v, r, s), Errors.InvalidSignature()); |
| 149 | ++ |
| 150 | + _delegateByType(delegator, delegatee, GovernancePowerType.VOTING); |
| 151 | + _delegateByType(delegator, delegatee, GovernancePowerType.PROPOSITION); |
| 152 | + } |
| 153 | +@@ -213,10 +222,10 @@ abstract contract BaseDelegation is IGovernancePowerDelegationToken { |
| 154 | + |
| 155 | + // we use uint72, because this is the most optimal for AaveTokenV3 |
| 156 | + // To make delegated balance fit into uint72 we're decreasing precision of delegated balance by POWER_SCALE_FACTOR |
| 157 | +- uint72 impactOnDelegationBefore72 = SafeCast72.toUint72( |
| 158 | ++ uint72 impactOnDelegationBefore72 = SafeCast.toUint72( |
| 159 | + impactOnDelegationBefore / POWER_SCALE_FACTOR |
| 160 | + ); |
| 161 | +- uint72 impactOnDelegationAfter72 = SafeCast72.toUint72( |
| 162 | ++ uint72 impactOnDelegationAfter72 = SafeCast.toUint72( |
| 163 | + impactOnDelegationAfter / POWER_SCALE_FACTOR |
| 164 | + ); |
0 commit comments