forked from bgd-labs/aave-governance-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlotUtils.sol
47 lines (44 loc) · 1.43 KB
/
SlotUtils.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
library SlotUtils {
/**
* @notice method to calculate the slot hash of the a mapping indexed by account
* @param account address of the balance holder
* @param balanceMappingPosition base position of the storage slot of the balance on a token contract
* @return the slot hash
*/
function getAccountSlotHash(
address account,
uint256 balanceMappingPosition
) internal pure returns (bytes32) {
return
keccak256(
abi.encodePacked(
bytes32(uint256(uint160(account))),
balanceMappingPosition
)
);
}
/**
* @notice method to calculate the slot hash of the a mapping indexed by voter and chainId
* @param voter address of the voter
* @param chainId id of the chain of the votingMachine
* @param representativesMappingPosition base position of the storage slot of the representatives on governance contract
* @return the slot hash
* @dev mapping(address => mapping(uint256 => address))
*/
function getRepresentativeSlotHash(
address voter,
uint256 chainId,
uint256 representativesMappingPosition
) internal pure returns (bytes32) {
bytes32 voterMappingIndex = keccak256(
abi.encodePacked(
bytes32(uint256(uint160(voter))),
representativesMappingPosition
)
);
return
keccak256(abi.encodePacked(bytes32(chainId), uint256(voterMappingIndex)));
}
}