morpho-contracts-helper 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/contracts/DComp.sol +137 -0
  2. package/contracts/external/Multicall3.sol +216 -0
  3. package/contracts/vendor/@compound-finance/compound-governance/contracts/Comp.sol +301 -0
  4. package/contracts/vendor/@compound-finance/compound-governance/contracts/interfaces/IComp.sol +34 -0
  5. package/dist/hardhat.config.cjs +9 -0
  6. package/dist/hardhat.config.cjs.map +1 -1
  7. package/dist/hardhat.config.d.cts.map +1 -1
  8. package/dist/typechain-types/@openzeppelin/contracts/access/Ownable.d.ts +55 -0
  9. package/dist/typechain-types/@openzeppelin/contracts/access/Ownable.d.ts.map +1 -0
  10. package/dist/typechain-types/@openzeppelin/contracts/access/Ownable.js +3 -0
  11. package/dist/typechain-types/@openzeppelin/contracts/access/Ownable.js.map +1 -0
  12. package/dist/typechain-types/@openzeppelin/contracts/access/Ownable2Step.d.ts +78 -0
  13. package/dist/typechain-types/@openzeppelin/contracts/access/Ownable2Step.d.ts.map +1 -0
  14. package/dist/typechain-types/@openzeppelin/contracts/access/Ownable2Step.js +3 -0
  15. package/dist/typechain-types/@openzeppelin/contracts/access/Ownable2Step.js.map +1 -0
  16. package/dist/typechain-types/@openzeppelin/contracts/access/index.d.ts +3 -0
  17. package/dist/typechain-types/@openzeppelin/contracts/access/index.d.ts.map +1 -0
  18. package/dist/typechain-types/@openzeppelin/contracts/access/index.js +3 -0
  19. package/dist/typechain-types/@openzeppelin/contracts/access/index.js.map +1 -0
  20. package/dist/typechain-types/@openzeppelin/contracts/index.d.ts +4 -0
  21. package/dist/typechain-types/@openzeppelin/contracts/index.d.ts.map +1 -1
  22. package/dist/typechain-types/@openzeppelin/contracts/interfaces/IERC1363.d.ts +232 -0
  23. package/dist/typechain-types/@openzeppelin/contracts/interfaces/IERC1363.d.ts.map +1 -0
  24. package/dist/typechain-types/@openzeppelin/contracts/interfaces/IERC1363.js +3 -0
  25. package/dist/typechain-types/@openzeppelin/contracts/interfaces/IERC1363.js.map +1 -0
  26. package/dist/typechain-types/@openzeppelin/contracts/interfaces/index.d.ts +1 -0
  27. package/dist/typechain-types/@openzeppelin/contracts/interfaces/index.d.ts.map +1 -1
  28. package/dist/typechain-types/@openzeppelin/contracts/token/ERC20/extensions/ERC20Wrapper.d.ts +174 -0
  29. package/dist/typechain-types/@openzeppelin/contracts/token/ERC20/extensions/ERC20Wrapper.d.ts.map +1 -0
  30. package/dist/typechain-types/@openzeppelin/contracts/token/ERC20/extensions/ERC20Wrapper.js +3 -0
  31. package/dist/typechain-types/@openzeppelin/contracts/token/ERC20/extensions/ERC20Wrapper.js.map +1 -0
  32. package/dist/typechain-types/@openzeppelin/contracts/token/ERC20/extensions/index.d.ts +1 -0
  33. package/dist/typechain-types/@openzeppelin/contracts/token/ERC20/extensions/index.d.ts.map +1 -1
  34. package/dist/typechain-types/@openzeppelin/contracts/token/ERC20/index.d.ts +2 -0
  35. package/dist/typechain-types/@openzeppelin/contracts/token/ERC20/index.d.ts.map +1 -1
  36. package/dist/typechain-types/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.d.ts +21 -0
  37. package/dist/typechain-types/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.d.ts.map +1 -0
  38. package/dist/typechain-types/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.js +3 -0
  39. package/dist/typechain-types/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.js.map +1 -0
  40. package/dist/typechain-types/@openzeppelin/contracts/token/ERC20/utils/index.d.ts +2 -0
  41. package/dist/typechain-types/@openzeppelin/contracts/token/ERC20/utils/index.d.ts.map +1 -0
  42. package/dist/typechain-types/@openzeppelin/contracts/token/ERC20/utils/index.js +3 -0
  43. package/dist/typechain-types/@openzeppelin/contracts/token/ERC20/utils/index.js.map +1 -0
  44. package/dist/typechain-types/@openzeppelin/contracts/utils/index.d.ts +3 -0
  45. package/dist/typechain-types/@openzeppelin/contracts/utils/index.d.ts.map +1 -0
  46. package/dist/typechain-types/@openzeppelin/contracts/utils/index.js +3 -0
  47. package/dist/typechain-types/@openzeppelin/contracts/utils/index.js.map +1 -0
  48. package/dist/typechain-types/@openzeppelin/contracts/utils/introspection/IERC165.d.ts +30 -0
  49. package/dist/typechain-types/@openzeppelin/contracts/utils/introspection/IERC165.d.ts.map +1 -0
  50. package/dist/typechain-types/@openzeppelin/contracts/utils/introspection/IERC165.js +3 -0
  51. package/dist/typechain-types/@openzeppelin/contracts/utils/introspection/IERC165.js.map +1 -0
  52. package/dist/typechain-types/@openzeppelin/contracts/utils/introspection/index.d.ts +2 -0
  53. package/dist/typechain-types/@openzeppelin/contracts/utils/introspection/index.d.ts.map +1 -0
  54. package/dist/typechain-types/@openzeppelin/contracts/utils/introspection/index.js +3 -0
  55. package/dist/typechain-types/@openzeppelin/contracts/utils/introspection/index.js.map +1 -0
  56. package/dist/typechain-types/contracts/DComp.d.ts +285 -0
  57. package/dist/typechain-types/contracts/DComp.d.ts.map +1 -0
  58. package/dist/typechain-types/contracts/DComp.js +3 -0
  59. package/dist/typechain-types/contracts/DComp.js.map +1 -0
  60. package/dist/typechain-types/contracts/external/Multicall3.d.ts +229 -0
  61. package/dist/typechain-types/contracts/external/Multicall3.d.ts.map +1 -0
  62. package/dist/typechain-types/contracts/external/Multicall3.js +3 -0
  63. package/dist/typechain-types/contracts/external/Multicall3.js.map +1 -0
  64. package/dist/typechain-types/contracts/external/index.d.ts +1 -0
  65. package/dist/typechain-types/contracts/external/index.d.ts.map +1 -1
  66. package/dist/typechain-types/contracts/index.d.ts +3 -0
  67. package/dist/typechain-types/contracts/index.d.ts.map +1 -1
  68. package/dist/typechain-types/contracts/vendor/@compound-finance/compound-governance/contracts/Comp.d.ts +285 -0
  69. package/dist/typechain-types/contracts/vendor/@compound-finance/compound-governance/contracts/Comp.d.ts.map +1 -0
  70. package/dist/typechain-types/contracts/vendor/@compound-finance/compound-governance/contracts/Comp.js +3 -0
  71. package/dist/typechain-types/contracts/vendor/@compound-finance/compound-governance/contracts/Comp.js.map +1 -0
  72. package/dist/typechain-types/contracts/vendor/@compound-finance/compound-governance/contracts/index.d.ts +4 -0
  73. package/dist/typechain-types/contracts/vendor/@compound-finance/compound-governance/contracts/index.d.ts.map +1 -0
  74. package/dist/typechain-types/contracts/vendor/@compound-finance/compound-governance/contracts/index.js +3 -0
  75. package/dist/typechain-types/contracts/vendor/@compound-finance/compound-governance/contracts/index.js.map +1 -0
  76. package/dist/typechain-types/contracts/vendor/@compound-finance/compound-governance/contracts/interfaces/IComp.d.ts +285 -0
  77. package/dist/typechain-types/contracts/vendor/@compound-finance/compound-governance/contracts/interfaces/IComp.d.ts.map +1 -0
  78. package/dist/typechain-types/contracts/vendor/@compound-finance/compound-governance/contracts/interfaces/IComp.js +3 -0
  79. package/dist/typechain-types/contracts/vendor/@compound-finance/compound-governance/contracts/interfaces/IComp.js.map +1 -0
  80. package/dist/typechain-types/contracts/vendor/@compound-finance/compound-governance/contracts/interfaces/index.d.ts +2 -0
  81. package/dist/typechain-types/contracts/vendor/@compound-finance/compound-governance/contracts/interfaces/index.d.ts.map +1 -0
  82. package/dist/typechain-types/contracts/vendor/@compound-finance/compound-governance/contracts/interfaces/index.js +3 -0
  83. package/dist/typechain-types/contracts/vendor/@compound-finance/compound-governance/contracts/interfaces/index.js.map +1 -0
  84. package/dist/typechain-types/contracts/vendor/@compound-finance/compound-governance/index.d.ts +3 -0
  85. package/dist/typechain-types/contracts/vendor/@compound-finance/compound-governance/index.d.ts.map +1 -0
  86. package/dist/typechain-types/contracts/vendor/@compound-finance/compound-governance/index.js +3 -0
  87. package/dist/typechain-types/contracts/vendor/@compound-finance/compound-governance/index.js.map +1 -0
  88. package/dist/typechain-types/contracts/vendor/@compound-finance/index.d.ts +3 -0
  89. package/dist/typechain-types/contracts/vendor/@compound-finance/index.d.ts.map +1 -0
  90. package/dist/typechain-types/contracts/vendor/@compound-finance/index.js +3 -0
  91. package/dist/typechain-types/contracts/vendor/@compound-finance/index.js.map +1 -0
  92. package/dist/typechain-types/contracts/vendor/index.d.ts +3 -0
  93. package/dist/typechain-types/contracts/vendor/index.d.ts.map +1 -0
  94. package/dist/typechain-types/contracts/vendor/index.js +3 -0
  95. package/dist/typechain-types/contracts/vendor/index.js.map +1 -0
  96. package/dist/typechain-types/factories/@openzeppelin/contracts/access/Ownable2Step__factory.d.ts +96 -0
  97. package/dist/typechain-types/factories/@openzeppelin/contracts/access/Ownable2Step__factory.d.ts.map +1 -0
  98. package/dist/typechain-types/factories/@openzeppelin/contracts/access/Ownable2Step__factory.js +134 -0
  99. package/dist/typechain-types/factories/@openzeppelin/contracts/access/Ownable2Step__factory.js.map +1 -0
  100. package/dist/typechain-types/factories/@openzeppelin/contracts/access/Ownable__factory.d.ts +65 -0
  101. package/dist/typechain-types/factories/@openzeppelin/contracts/access/Ownable__factory.d.ts.map +1 -0
  102. package/dist/typechain-types/factories/@openzeppelin/contracts/access/Ownable__factory.js +95 -0
  103. package/dist/typechain-types/factories/@openzeppelin/contracts/access/Ownable__factory.js.map +1 -0
  104. package/dist/typechain-types/factories/@openzeppelin/contracts/access/index.d.ts +3 -0
  105. package/dist/typechain-types/factories/@openzeppelin/contracts/access/index.d.ts.map +1 -0
  106. package/dist/typechain-types/factories/@openzeppelin/contracts/access/index.js +12 -0
  107. package/dist/typechain-types/factories/@openzeppelin/contracts/access/index.js.map +1 -0
  108. package/dist/typechain-types/factories/@openzeppelin/contracts/index.d.ts +2 -0
  109. package/dist/typechain-types/factories/@openzeppelin/contracts/index.d.ts.map +1 -1
  110. package/dist/typechain-types/factories/@openzeppelin/contracts/index.js +3 -1
  111. package/dist/typechain-types/factories/@openzeppelin/contracts/index.js.map +1 -1
  112. package/dist/typechain-types/factories/@openzeppelin/contracts/interfaces/IERC1363__factory.d.ts +290 -0
  113. package/dist/typechain-types/factories/@openzeppelin/contracts/interfaces/IERC1363__factory.d.ts.map +1 -0
  114. package/dist/typechain-types/factories/@openzeppelin/contracts/interfaces/IERC1363__factory.js +392 -0
  115. package/dist/typechain-types/factories/@openzeppelin/contracts/interfaces/IERC1363__factory.js.map +1 -0
  116. package/dist/typechain-types/factories/@openzeppelin/contracts/interfaces/index.d.ts +1 -0
  117. package/dist/typechain-types/factories/@openzeppelin/contracts/interfaces/index.d.ts.map +1 -1
  118. package/dist/typechain-types/factories/@openzeppelin/contracts/interfaces/index.js +3 -1
  119. package/dist/typechain-types/factories/@openzeppelin/contracts/interfaces/index.js.map +1 -1
  120. package/dist/typechain-types/factories/@openzeppelin/contracts/token/ERC20/extensions/ERC20Wrapper__factory.d.ts +304 -0
  121. package/dist/typechain-types/factories/@openzeppelin/contracts/token/ERC20/extensions/ERC20Wrapper__factory.d.ts.map +1 -0
  122. package/dist/typechain-types/factories/@openzeppelin/contracts/token/ERC20/extensions/ERC20Wrapper__factory.js +412 -0
  123. package/dist/typechain-types/factories/@openzeppelin/contracts/token/ERC20/extensions/ERC20Wrapper__factory.js.map +1 -0
  124. package/dist/typechain-types/factories/@openzeppelin/contracts/token/ERC20/extensions/index.d.ts +1 -0
  125. package/dist/typechain-types/factories/@openzeppelin/contracts/token/ERC20/extensions/index.d.ts.map +1 -1
  126. package/dist/typechain-types/factories/@openzeppelin/contracts/token/ERC20/extensions/index.js +3 -1
  127. package/dist/typechain-types/factories/@openzeppelin/contracts/token/ERC20/extensions/index.js.map +1 -1
  128. package/dist/typechain-types/factories/@openzeppelin/contracts/token/ERC20/index.d.ts +1 -0
  129. package/dist/typechain-types/factories/@openzeppelin/contracts/token/ERC20/index.d.ts.map +1 -1
  130. package/dist/typechain-types/factories/@openzeppelin/contracts/token/ERC20/index.js +2 -1
  131. package/dist/typechain-types/factories/@openzeppelin/contracts/token/ERC20/index.js.map +1 -1
  132. package/dist/typechain-types/factories/@openzeppelin/contracts/token/ERC20/utils/SafeERC20__factory.d.ts +47 -0
  133. package/dist/typechain-types/factories/@openzeppelin/contracts/token/ERC20/utils/SafeERC20__factory.d.ts.map +1 -0
  134. package/dist/typechain-types/factories/@openzeppelin/contracts/token/ERC20/utils/SafeERC20__factory.js +73 -0
  135. package/dist/typechain-types/factories/@openzeppelin/contracts/token/ERC20/utils/SafeERC20__factory.js.map +1 -0
  136. package/dist/typechain-types/factories/@openzeppelin/contracts/token/ERC20/utils/index.d.ts +2 -0
  137. package/dist/typechain-types/factories/@openzeppelin/contracts/token/ERC20/utils/index.d.ts.map +1 -0
  138. package/dist/typechain-types/factories/@openzeppelin/contracts/token/ERC20/utils/index.js +10 -0
  139. package/dist/typechain-types/factories/@openzeppelin/contracts/token/ERC20/utils/index.js.map +1 -0
  140. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/index.d.ts +2 -0
  141. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/index.d.ts.map +1 -0
  142. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/index.js +42 -0
  143. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/index.js.map +1 -0
  144. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/introspection/IERC165__factory.d.ts +22 -0
  145. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/introspection/IERC165__factory.d.ts.map +1 -0
  146. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/introspection/IERC165__factory.js +40 -0
  147. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/introspection/IERC165__factory.js.map +1 -0
  148. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/introspection/index.d.ts +2 -0
  149. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/introspection/index.d.ts.map +1 -0
  150. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/introspection/index.js +10 -0
  151. package/dist/typechain-types/factories/@openzeppelin/contracts/utils/introspection/index.js.map +1 -0
  152. package/dist/typechain-types/factories/contracts/DComp__factory.d.ts +514 -0
  153. package/dist/typechain-types/factories/contracts/DComp__factory.d.ts.map +1 -0
  154. package/dist/typechain-types/factories/contracts/DComp__factory.js +686 -0
  155. package/dist/typechain-types/factories/contracts/DComp__factory.js.map +1 -0
  156. package/dist/typechain-types/factories/contracts/external/Multicall3__factory.d.ts +354 -0
  157. package/dist/typechain-types/factories/contracts/external/Multicall3__factory.d.ts.map +1 -0
  158. package/dist/typechain-types/factories/contracts/external/Multicall3__factory.js +479 -0
  159. package/dist/typechain-types/factories/contracts/external/Multicall3__factory.js.map +1 -0
  160. package/dist/typechain-types/factories/contracts/external/index.d.ts +1 -0
  161. package/dist/typechain-types/factories/contracts/external/index.d.ts.map +1 -1
  162. package/dist/typechain-types/factories/contracts/external/index.js +3 -1
  163. package/dist/typechain-types/factories/contracts/external/index.js.map +1 -1
  164. package/dist/typechain-types/factories/contracts/index.d.ts +2 -0
  165. package/dist/typechain-types/factories/contracts/index.d.ts.map +1 -1
  166. package/dist/typechain-types/factories/contracts/index.js +4 -1
  167. package/dist/typechain-types/factories/contracts/index.js.map +1 -1
  168. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/compound-governance/contracts/Comp__factory.d.ts +397 -0
  169. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/compound-governance/contracts/Comp__factory.d.ts.map +1 -0
  170. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/compound-governance/contracts/Comp__factory.js +530 -0
  171. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/compound-governance/contracts/Comp__factory.js.map +1 -0
  172. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/compound-governance/contracts/index.d.ts +3 -0
  173. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/compound-governance/contracts/index.d.ts.map +1 -0
  174. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/compound-governance/contracts/index.js +44 -0
  175. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/compound-governance/contracts/index.js.map +1 -0
  176. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/compound-governance/contracts/interfaces/IComp__factory.d.ts +374 -0
  177. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/compound-governance/contracts/interfaces/IComp__factory.d.ts.map +1 -0
  178. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/compound-governance/contracts/interfaces/IComp__factory.js +499 -0
  179. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/compound-governance/contracts/interfaces/IComp__factory.js.map +1 -0
  180. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/compound-governance/contracts/interfaces/index.d.ts +2 -0
  181. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/compound-governance/contracts/interfaces/index.d.ts.map +1 -0
  182. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/compound-governance/contracts/interfaces/index.js +10 -0
  183. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/compound-governance/contracts/interfaces/index.js.map +1 -0
  184. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/compound-governance/index.d.ts +2 -0
  185. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/compound-governance/index.d.ts.map +1 -0
  186. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/compound-governance/index.js +42 -0
  187. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/compound-governance/index.js.map +1 -0
  188. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/index.d.ts +2 -0
  189. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/index.d.ts.map +1 -0
  190. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/index.js +42 -0
  191. package/dist/typechain-types/factories/contracts/vendor/@compound-finance/index.js.map +1 -0
  192. package/dist/typechain-types/factories/contracts/vendor/index.d.ts +2 -0
  193. package/dist/typechain-types/factories/contracts/vendor/index.d.ts.map +1 -0
  194. package/dist/typechain-types/factories/contracts/vendor/index.js +42 -0
  195. package/dist/typechain-types/factories/contracts/vendor/index.js.map +1 -0
  196. package/dist/typechain-types/index.d.ts +20 -0
  197. package/dist/typechain-types/index.d.ts.map +1 -1
  198. package/dist/typechain-types/index.js +21 -1
  199. package/dist/typechain-types/index.js.map +1 -1
  200. package/hardhat.config.cts +9 -0
  201. package/package.json +1 -1
@@ -0,0 +1,137 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity 0.8.27;
3
+
4
+ import {
5
+ Ownable,
6
+ Ownable2Step
7
+ } from "@openzeppelin/contracts/access/Ownable2Step.sol";
8
+ import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
9
+ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
10
+ import {ERC20Wrapper} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Wrapper.sol";
11
+ import {IComp} from "./vendor/@compound-finance/compound-governance/contracts/interfaces/IComp.sol";
12
+
13
+ /// @title dCOMP
14
+ /// @author API3 DAO
15
+ /// @notice 1:1 wrapper token for COMP built on OpenZeppelin ERC20Wrapper
16
+ contract DComp is ERC20Wrapper, Ownable2Step {
17
+ address internal constant COMP_ADDRESS =
18
+ 0xc00e94Cb662C3520282E6f5717214004A7f26888;
19
+ IComp internal immutable comp = IComp(COMP_ADDRESS);
20
+
21
+ /// @notice Tracks which addresses are allowed to deposit COMP.
22
+ /// @dev Withdrawals are never restricted by this whitelist, including when dCOMP is transferred,
23
+ /// when a depositor is later removed from the whitelist, or when COMP is deposited for another address via `depositFor`.
24
+ mapping(address => bool) public isDepositorWhitelisted;
25
+
26
+ /// @notice Emitted when an address whitelist status changes
27
+ /// @param account Address whose whitelist status changed
28
+ /// @param isWhitelisted New whitelist status
29
+ event DepositorWhitelistStatusUpdated(
30
+ address indexed account,
31
+ bool isWhitelisted
32
+ );
33
+
34
+ modifier onlyWhitelisted() {
35
+ require(
36
+ isDepositorWhitelisted[msg.sender],
37
+ "Caller is not whitelisted"
38
+ );
39
+ _;
40
+ }
41
+
42
+ /// @notice Constructs the dCOMP wrapper
43
+ /// @param initialOwner Address of the initial owner
44
+ /// @param initialDelegatee Address of the initial delegatee for COMP voting power
45
+ /// @param whitelistedDepositors Initial addresses allowed to deposit COMP
46
+ constructor(
47
+ address initialOwner,
48
+ address initialDelegatee,
49
+ address[] memory whitelistedDepositors
50
+ )
51
+ ERC20("dCOMP", "dCOMP")
52
+ ERC20Wrapper(IERC20(COMP_ADDRESS))
53
+ Ownable(initialOwner)
54
+ {
55
+ _setDelegatee(initialDelegatee);
56
+
57
+ for (uint256 i = 0; i < whitelistedDepositors.length; ++i) {
58
+ _setDepositorWhitelistStatus(whitelistedDepositors[i], true);
59
+ }
60
+ }
61
+
62
+ /// @notice Returns the current COMP delegatee for voting power held by this wrapper
63
+ /// @return delegateeAddress Current delegatee address
64
+ function delegatee() external view returns (address) {
65
+ return comp.delegates(address(this));
66
+ }
67
+
68
+ /// @notice Wraps COMP tokens into dCOMP for a specific recipient at a 1:1 ratio
69
+ /// @param account Recipient of newly minted dCOMP
70
+ /// @param value Amount of COMP to deposit
71
+ /// @return success Whether wrapping succeeded
72
+ function depositFor(
73
+ address account,
74
+ uint256 value
75
+ ) public override onlyWhitelisted returns (bool) {
76
+ return super.depositFor(account, value);
77
+ }
78
+
79
+ /// @notice Wraps COMP tokens for the caller at a 1:1 ratio
80
+ /// @param value Amount of COMP to deposit
81
+ /// @return success Whether wrapping succeeded
82
+ function deposit(uint256 value) external onlyWhitelisted returns (bool) {
83
+ return depositFor(msg.sender, value);
84
+ }
85
+
86
+ /// @notice Unwraps dCOMP tokens for the caller at a 1:1 ratio
87
+ /// @param value Amount of dCOMP to burn and withdraw as COMP
88
+ /// @return success Whether unwrapping succeeded
89
+ function withdraw(uint256 value) external returns (bool) {
90
+ return withdrawTo(msg.sender, value);
91
+ }
92
+
93
+ /// @notice Updates depositor whitelist
94
+ /// @param addresses Addresses whose whitelist status will be updated
95
+ /// @param isAddressWhitelisted New whitelist status for each corresponding address
96
+ function updateWhitelistedDepositors(
97
+ address[] calldata addresses,
98
+ bool[] calldata isAddressWhitelisted
99
+ ) external onlyOwner {
100
+ require(
101
+ addresses.length == isAddressWhitelisted.length,
102
+ "Mismatched array lengths"
103
+ );
104
+
105
+ for (uint256 i = 0; i < addresses.length; ++i) {
106
+ _setDepositorWhitelistStatus(addresses[i], isAddressWhitelisted[i]);
107
+ }
108
+ }
109
+
110
+ /// @notice Allows the owner to change who receives the aggregated voting power
111
+ /// @param newDelegatee The new address to receive the COMP voting power
112
+ function setDelegatee(address newDelegatee) external onlyOwner {
113
+ _setDelegatee(newDelegatee);
114
+ }
115
+
116
+ /// @notice Updates whitelist status for a depositor
117
+ /// @param account Address whose whitelist status is being updated
118
+ /// @param isWhitelisted New whitelist status for the address
119
+ function _setDepositorWhitelistStatus(
120
+ address account,
121
+ bool isWhitelisted
122
+ ) internal {
123
+ require(
124
+ isDepositorWhitelisted[account] != isWhitelisted,
125
+ "No change in whitelist status"
126
+ );
127
+
128
+ isDepositorWhitelisted[account] = isWhitelisted;
129
+ emit DepositorWhitelistStatusUpdated(account, isWhitelisted);
130
+ }
131
+
132
+ /// @notice Updates delegated voting power recipient for COMP held by this wrapper
133
+ /// @param newDelegatee New delegatee address
134
+ function _setDelegatee(address newDelegatee) internal {
135
+ comp.delegate(newDelegatee);
136
+ }
137
+ }
@@ -0,0 +1,216 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity 0.8.12;
3
+
4
+ /// @title Multicall3
5
+ /// @notice Aggregate results from multiple function calls
6
+ /// @dev Multicall & Multicall2 backwards-compatible
7
+ /// @dev Aggregate methods are marked `payable` to save 24 gas per call
8
+ /// @author Michael Elliot <mike@makerdao.com>
9
+ /// @author Joshua Levine <joshua@makerdao.com>
10
+ /// @author Nick Johnson <arachnid@notdot.net>
11
+ /// @author Andreas Bigger <andreas@nascent.xyz>
12
+ /// @author Matt Solomon <matt@mattsolomon.dev>
13
+ contract Multicall3 {
14
+ struct Call {
15
+ address target;
16
+ bytes callData;
17
+ }
18
+
19
+ struct Call3 {
20
+ address target;
21
+ bool allowFailure;
22
+ bytes callData;
23
+ }
24
+
25
+ struct Call3Value {
26
+ address target;
27
+ bool allowFailure;
28
+ uint256 value;
29
+ bytes callData;
30
+ }
31
+
32
+ struct Result {
33
+ bool success;
34
+ bytes returnData;
35
+ }
36
+
37
+ /// @notice Backwards-compatible call aggregation with Multicall
38
+ /// @param calls An array of Call structs
39
+ /// @return blockNumber The block number where the calls were executed
40
+ /// @return returnData An array of bytes containing the responses
41
+ function aggregate(Call[] calldata calls) public payable returns (uint256 blockNumber, bytes[] memory returnData) {
42
+ blockNumber = block.number;
43
+ uint256 length = calls.length;
44
+ returnData = new bytes[](length);
45
+ Call calldata call;
46
+ for (uint256 i = 0; i < length;) {
47
+ bool success;
48
+ call = calls[i];
49
+ (success, returnData[i]) = call.target.call(call.callData);
50
+ require(success, "Multicall3: call failed");
51
+ unchecked { ++i; }
52
+ }
53
+ }
54
+
55
+ /// @notice Backwards-compatible with Multicall2
56
+ /// @notice Aggregate calls without requiring success
57
+ /// @param requireSuccess If true, require all calls to succeed
58
+ /// @param calls An array of Call structs
59
+ /// @return returnData An array of Result structs
60
+ function tryAggregate(bool requireSuccess, Call[] calldata calls) public payable returns (Result[] memory returnData) {
61
+ uint256 length = calls.length;
62
+ returnData = new Result[](length);
63
+ Call calldata call;
64
+ for (uint256 i = 0; i < length;) {
65
+ Result memory result = returnData[i];
66
+ call = calls[i];
67
+ (result.success, result.returnData) = call.target.call(call.callData);
68
+ if (requireSuccess) require(result.success, "Multicall3: call failed");
69
+ unchecked { ++i; }
70
+ }
71
+ }
72
+
73
+ /// @notice Backwards-compatible with Multicall2
74
+ /// @notice Aggregate calls and allow failures using tryAggregate
75
+ /// @param calls An array of Call structs
76
+ /// @return blockNumber The block number where the calls were executed
77
+ /// @return blockHash The hash of the block where the calls were executed
78
+ /// @return returnData An array of Result structs
79
+ function tryBlockAndAggregate(bool requireSuccess, Call[] calldata calls) public payable returns (uint256 blockNumber, bytes32 blockHash, Result[] memory returnData) {
80
+ blockNumber = block.number;
81
+ blockHash = blockhash(block.number);
82
+ returnData = tryAggregate(requireSuccess, calls);
83
+ }
84
+
85
+ /// @notice Backwards-compatible with Multicall2
86
+ /// @notice Aggregate calls and allow failures using tryAggregate
87
+ /// @param calls An array of Call structs
88
+ /// @return blockNumber The block number where the calls were executed
89
+ /// @return blockHash The hash of the block where the calls were executed
90
+ /// @return returnData An array of Result structs
91
+ function blockAndAggregate(Call[] calldata calls) public payable returns (uint256 blockNumber, bytes32 blockHash, Result[] memory returnData) {
92
+ (blockNumber, blockHash, returnData) = tryBlockAndAggregate(true, calls);
93
+ }
94
+
95
+ /// @notice Aggregate calls, ensuring each returns success if required
96
+ /// @param calls An array of Call3 structs
97
+ /// @return returnData An array of Result structs
98
+ function aggregate3(Call3[] calldata calls) public payable returns (Result[] memory returnData) {
99
+ uint256 length = calls.length;
100
+ returnData = new Result[](length);
101
+ Call3 calldata calli;
102
+ for (uint256 i = 0; i < length;) {
103
+ Result memory result = returnData[i];
104
+ calli = calls[i];
105
+ (result.success, result.returnData) = calli.target.call(calli.callData);
106
+ assembly {
107
+ // Revert if the call fails and failure is not allowed
108
+ // `allowFailure := calldataload(add(calli, 0x20))` and `success := mload(result)`
109
+ if iszero(or(calldataload(add(calli, 0x20)), mload(result))) {
110
+ // set "Error(string)" signature: bytes32(bytes4(keccak256("Error(string)")))
111
+ mstore(0x00, 0x08c379a000000000000000000000000000000000000000000000000000000000)
112
+ // set data offset
113
+ mstore(0x04, 0x0000000000000000000000000000000000000000000000000000000000000020)
114
+ // set length of revert string
115
+ mstore(0x24, 0x0000000000000000000000000000000000000000000000000000000000000017)
116
+ // set revert string: bytes32(abi.encodePacked("Multicall3: call failed"))
117
+ mstore(0x44, 0x4d756c746963616c6c333a2063616c6c206661696c6564000000000000000000)
118
+ revert(0x00, 0x64)
119
+ }
120
+ }
121
+ unchecked { ++i; }
122
+ }
123
+ }
124
+
125
+ /// @notice Aggregate calls with a msg value
126
+ /// @notice Reverts if msg.value is less than the sum of the call values
127
+ /// @param calls An array of Call3Value structs
128
+ /// @return returnData An array of Result structs
129
+ function aggregate3Value(Call3Value[] calldata calls) public payable returns (Result[] memory returnData) {
130
+ uint256 valAccumulator;
131
+ uint256 length = calls.length;
132
+ returnData = new Result[](length);
133
+ Call3Value calldata calli;
134
+ for (uint256 i = 0; i < length;) {
135
+ Result memory result = returnData[i];
136
+ calli = calls[i];
137
+ uint256 val = calli.value;
138
+ // Humanity will be a Type V Kardashev Civilization before this overflows - andreas
139
+ // ~ 10^25 Wei in existence << ~ 10^76 size uint fits in a uint256
140
+ unchecked { valAccumulator += val; }
141
+ (result.success, result.returnData) = calli.target.call{value: val}(calli.callData);
142
+ assembly {
143
+ // Revert if the call fails and failure is not allowed
144
+ // `allowFailure := calldataload(add(calli, 0x20))` and `success := mload(result)`
145
+ if iszero(or(calldataload(add(calli, 0x20)), mload(result))) {
146
+ // set "Error(string)" signature: bytes32(bytes4(keccak256("Error(string)")))
147
+ mstore(0x00, 0x08c379a000000000000000000000000000000000000000000000000000000000)
148
+ // set data offset
149
+ mstore(0x04, 0x0000000000000000000000000000000000000000000000000000000000000020)
150
+ // set length of revert string
151
+ mstore(0x24, 0x0000000000000000000000000000000000000000000000000000000000000017)
152
+ // set revert string: bytes32(abi.encodePacked("Multicall3: call failed"))
153
+ mstore(0x44, 0x4d756c746963616c6c333a2063616c6c206661696c6564000000000000000000)
154
+ revert(0x00, 0x84)
155
+ }
156
+ }
157
+ unchecked { ++i; }
158
+ }
159
+ // Finally, make sure the msg.value = SUM(call[0...i].value)
160
+ require(msg.value == valAccumulator, "Multicall3: value mismatch");
161
+ }
162
+
163
+ /// @notice Returns the block hash for the given block number
164
+ /// @param blockNumber The block number
165
+ function getBlockHash(uint256 blockNumber) public view returns (bytes32 blockHash) {
166
+ blockHash = blockhash(blockNumber);
167
+ }
168
+
169
+ /// @notice Returns the block number
170
+ function getBlockNumber() public view returns (uint256 blockNumber) {
171
+ blockNumber = block.number;
172
+ }
173
+
174
+ /// @notice Returns the block coinbase
175
+ function getCurrentBlockCoinbase() public view returns (address coinbase) {
176
+ coinbase = block.coinbase;
177
+ }
178
+
179
+ /// @notice Returns the block difficulty
180
+ function getCurrentBlockDifficulty() public view returns (uint256 difficulty) {
181
+ difficulty = block.difficulty;
182
+ }
183
+
184
+ /// @notice Returns the block gas limit
185
+ function getCurrentBlockGasLimit() public view returns (uint256 gaslimit) {
186
+ gaslimit = block.gaslimit;
187
+ }
188
+
189
+ /// @notice Returns the block timestamp
190
+ function getCurrentBlockTimestamp() public view returns (uint256 timestamp) {
191
+ timestamp = block.timestamp;
192
+ }
193
+
194
+ /// @notice Returns the (ETH) balance of a given address
195
+ function getEthBalance(address addr) public view returns (uint256 balance) {
196
+ balance = addr.balance;
197
+ }
198
+
199
+ /// @notice Returns the block hash of the last block
200
+ function getLastBlockHash() public view returns (bytes32 blockHash) {
201
+ unchecked {
202
+ blockHash = blockhash(block.number - 1);
203
+ }
204
+ }
205
+
206
+ /// @notice Gets the base fee of the given block
207
+ /// @notice Can revert if the BASEFEE opcode is not implemented by the given chain
208
+ function getBasefee() public view returns (uint256 basefee) {
209
+ basefee = block.basefee;
210
+ }
211
+
212
+ /// @notice Returns the chain id
213
+ function getChainId() public view returns (uint256 chainid) {
214
+ chainid = block.chainid;
215
+ }
216
+ }
@@ -0,0 +1,301 @@
1
+ // SPDX-License-Identifier: BSD-3-Clause
2
+ pragma solidity ^0.8.10;
3
+
4
+ contract Comp {
5
+ /// @notice EIP-20 token name for this token
6
+ string public constant name = "Compound";
7
+
8
+ /// @notice EIP-20 token symbol for this token
9
+ string public constant symbol = "COMP";
10
+
11
+ /// @notice EIP-20 token decimals for this token
12
+ uint8 public constant decimals = 18;
13
+
14
+ /// @notice Total number of tokens in circulation
15
+ uint public constant totalSupply = 10000000e18; // 10 million Comp
16
+
17
+ /// @notice Allowance amounts on behalf of others
18
+ mapping (address => mapping (address => uint96)) internal allowances;
19
+
20
+ /// @notice Official record of token balances for each account
21
+ mapping (address => uint96) internal balances;
22
+
23
+ /// @notice A record of each accounts delegate
24
+ mapping (address => address) public delegates;
25
+
26
+ /// @notice A checkpoint for marking number of votes from a given block
27
+ struct Checkpoint {
28
+ uint32 fromBlock;
29
+ uint96 votes;
30
+ }
31
+
32
+ /// @notice A record of votes checkpoints for each account, by index
33
+ mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;
34
+
35
+ /// @notice The number of checkpoints for each account
36
+ mapping (address => uint32) public numCheckpoints;
37
+
38
+ /// @notice The EIP-712 typehash for the contract's domain
39
+ bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
40
+
41
+ /// @notice The EIP-712 typehash for the delegation struct used by the contract
42
+ bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
43
+
44
+ /// @notice A record of states for signing / validating signatures
45
+ mapping (address => uint) public nonces;
46
+
47
+ /// @notice An event thats emitted when an account changes its delegate
48
+ event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
49
+
50
+ /// @notice An event thats emitted when a delegate account's vote balance changes
51
+ event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);
52
+
53
+ /// @notice The standard EIP-20 transfer event
54
+ event Transfer(address indexed from, address indexed to, uint256 amount);
55
+
56
+ /// @notice The standard EIP-20 approval event
57
+ event Approval(address indexed owner, address indexed spender, uint256 amount);
58
+
59
+ /**
60
+ * @notice Construct a new Comp token
61
+ * @param account The initial account to grant all the tokens
62
+ */
63
+ constructor(address account) {
64
+ balances[account] = uint96(totalSupply);
65
+ emit Transfer(address(0), account, totalSupply);
66
+ }
67
+
68
+ /**
69
+ * @notice Get the number of tokens `spender` is approved to spend on behalf of `account`
70
+ * @param account The address of the account holding the funds
71
+ * @param spender The address of the account spending the funds
72
+ * @return The number of tokens approved
73
+ */
74
+ function allowance(address account, address spender) external view returns (uint) {
75
+ return allowances[account][spender];
76
+ }
77
+
78
+ /**
79
+ * @notice Approve `spender` to transfer up to `amount` from `src`
80
+ * @dev This will overwrite the approval amount for `spender`
81
+ * and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)
82
+ * @param spender The address of the account which may transfer tokens
83
+ * @param rawAmount The number of tokens that are approved (2^256-1 means infinite)
84
+ * @return Whether or not the approval succeeded
85
+ */
86
+ function approve(address spender, uint rawAmount) external returns (bool) {
87
+ uint96 amount;
88
+ if (rawAmount == type(uint).max) {
89
+ amount = type(uint96).max;
90
+ } else {
91
+ amount = safe96(rawAmount, "Comp::approve: amount exceeds 96 bits");
92
+ }
93
+
94
+ allowances[msg.sender][spender] = amount;
95
+
96
+ emit Approval(msg.sender, spender, amount);
97
+ return true;
98
+ }
99
+
100
+ /**
101
+ * @notice Get the number of tokens held by the `account`
102
+ * @param account The address of the account to get the balance of
103
+ * @return The number of tokens held
104
+ */
105
+ function balanceOf(address account) external view returns (uint) {
106
+ return balances[account];
107
+ }
108
+
109
+ /**
110
+ * @notice Transfer `amount` tokens from `msg.sender` to `dst`
111
+ * @param dst The address of the destination account
112
+ * @param rawAmount The number of tokens to transfer
113
+ * @return Whether or not the transfer succeeded
114
+ */
115
+ function transfer(address dst, uint rawAmount) external returns (bool) {
116
+ uint96 amount = safe96(rawAmount, "Comp::transfer: amount exceeds 96 bits");
117
+ _transferTokens(msg.sender, dst, amount);
118
+ return true;
119
+ }
120
+
121
+ /**
122
+ * @notice Transfer `amount` tokens from `src` to `dst`
123
+ * @param src The address of the source account
124
+ * @param dst The address of the destination account
125
+ * @param rawAmount The number of tokens to transfer
126
+ * @return Whether or not the transfer succeeded
127
+ */
128
+ function transferFrom(address src, address dst, uint rawAmount) external returns (bool) {
129
+ address spender = msg.sender;
130
+ uint96 spenderAllowance = allowances[src][spender];
131
+ uint96 amount = safe96(rawAmount, "Comp::approve: amount exceeds 96 bits");
132
+
133
+ if (spender != src && spenderAllowance != type(uint96).max) {
134
+ uint96 newAllowance = sub96(spenderAllowance, amount, "Comp::transferFrom: transfer amount exceeds spender allowance");
135
+ allowances[src][spender] = newAllowance;
136
+
137
+ emit Approval(src, spender, newAllowance);
138
+ }
139
+
140
+ _transferTokens(src, dst, amount);
141
+ return true;
142
+ }
143
+
144
+ /**
145
+ * @notice Delegate votes from `msg.sender` to `delegatee`
146
+ * @param delegatee The address to delegate votes to
147
+ */
148
+ function delegate(address delegatee) public {
149
+ return _delegate(msg.sender, delegatee);
150
+ }
151
+
152
+ /**
153
+ * @notice Delegates votes from signatory to `delegatee`
154
+ * @param delegatee The address to delegate votes to
155
+ * @param nonce The contract state required to match the signature
156
+ * @param expiry The time at which to expire the signature
157
+ * @param v The recovery byte of the signature
158
+ * @param r Half of the ECDSA signature pair
159
+ * @param s Half of the ECDSA signature pair
160
+ */
161
+ function delegateBySig(address delegatee, uint nonce, uint expiry, uint8 v, bytes32 r, bytes32 s) public {
162
+ bytes32 domainSeparator = keccak256(abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name)), getChainId(), address(this)));
163
+ bytes32 structHash = keccak256(abi.encode(DELEGATION_TYPEHASH, delegatee, nonce, expiry));
164
+ bytes32 digest = keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
165
+ address signatory = ecrecover(digest, v, r, s);
166
+ require(signatory != address(0), "Comp::delegateBySig: invalid signature");
167
+ require(nonce == nonces[signatory]++, "Comp::delegateBySig: invalid nonce");
168
+ require(block.timestamp <= expiry, "Comp::delegateBySig: signature expired");
169
+ return _delegate(signatory, delegatee);
170
+ }
171
+
172
+ /**
173
+ * @notice Gets the current votes balance for `account`
174
+ * @param account The address to get votes balance
175
+ * @return The number of current votes for `account`
176
+ */
177
+ function getCurrentVotes(address account) external view returns (uint96) {
178
+ uint32 nCheckpoints = numCheckpoints[account];
179
+ return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
180
+ }
181
+
182
+ /**
183
+ * @notice Determine the prior number of votes for an account as of a block number
184
+ * @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
185
+ * @param account The address of the account to check
186
+ * @param blockNumber The block number to get the vote balance at
187
+ * @return The number of votes the account had as of the given block
188
+ */
189
+ function getPriorVotes(address account, uint blockNumber) public view returns (uint96) {
190
+ require(blockNumber < block.number, "Comp::getPriorVotes: not yet determined");
191
+
192
+ uint32 nCheckpoints = numCheckpoints[account];
193
+ if (nCheckpoints == 0) {
194
+ return 0;
195
+ }
196
+
197
+ // First check most recent balance
198
+ if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
199
+ return checkpoints[account][nCheckpoints - 1].votes;
200
+ }
201
+
202
+ // Next check implicit zero balance
203
+ if (checkpoints[account][0].fromBlock > blockNumber) {
204
+ return 0;
205
+ }
206
+
207
+ uint32 lower = 0;
208
+ uint32 upper = nCheckpoints - 1;
209
+ while (upper > lower) {
210
+ uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
211
+ Checkpoint memory cp = checkpoints[account][center];
212
+ if (cp.fromBlock == blockNumber) {
213
+ return cp.votes;
214
+ } else if (cp.fromBlock < blockNumber) {
215
+ lower = center;
216
+ } else {
217
+ upper = center - 1;
218
+ }
219
+ }
220
+ return checkpoints[account][lower].votes;
221
+ }
222
+
223
+ function _delegate(address delegator, address delegatee) internal {
224
+ address currentDelegate = delegates[delegator];
225
+ uint96 delegatorBalance = balances[delegator];
226
+ delegates[delegator] = delegatee;
227
+
228
+ emit DelegateChanged(delegator, currentDelegate, delegatee);
229
+
230
+ _moveDelegates(currentDelegate, delegatee, delegatorBalance);
231
+ }
232
+
233
+ function _transferTokens(address src, address dst, uint96 amount) internal {
234
+ require(src != address(0), "Comp::_transferTokens: cannot transfer from the zero address");
235
+ require(dst != address(0), "Comp::_transferTokens: cannot transfer to the zero address");
236
+
237
+ balances[src] = sub96(balances[src], amount, "Comp::_transferTokens: transfer amount exceeds balance");
238
+ balances[dst] = add96(balances[dst], amount, "Comp::_transferTokens: transfer amount overflows");
239
+ emit Transfer(src, dst, amount);
240
+
241
+ _moveDelegates(delegates[src], delegates[dst], amount);
242
+ }
243
+
244
+ function _moveDelegates(address srcRep, address dstRep, uint96 amount) internal {
245
+ if (srcRep != dstRep && amount > 0) {
246
+ if (srcRep != address(0)) {
247
+ uint32 srcRepNum = numCheckpoints[srcRep];
248
+ uint96 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
249
+ uint96 srcRepNew = sub96(srcRepOld, amount, "Comp::_moveVotes: vote amount underflows");
250
+ _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
251
+ }
252
+
253
+ if (dstRep != address(0)) {
254
+ uint32 dstRepNum = numCheckpoints[dstRep];
255
+ uint96 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
256
+ uint96 dstRepNew = add96(dstRepOld, amount, "Comp::_moveVotes: vote amount overflows");
257
+ _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
258
+ }
259
+ }
260
+ }
261
+
262
+ function _writeCheckpoint(address delegatee, uint32 nCheckpoints, uint96 oldVotes, uint96 newVotes) internal {
263
+ uint32 blockNumber = safe32(block.number, "Comp::_writeCheckpoint: block number exceeds 32 bits");
264
+
265
+ if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
266
+ checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
267
+ } else {
268
+ checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
269
+ numCheckpoints[delegatee] = nCheckpoints + 1;
270
+ }
271
+
272
+ emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
273
+ }
274
+
275
+ function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {
276
+ require(n < 2**32, errorMessage);
277
+ return uint32(n);
278
+ }
279
+
280
+ function safe96(uint n, string memory errorMessage) internal pure returns (uint96) {
281
+ require(n < 2**96, errorMessage);
282
+ return uint96(n);
283
+ }
284
+
285
+ function add96(uint96 a, uint96 b, string memory errorMessage) internal pure returns (uint96) {
286
+ uint96 c = a + b;
287
+ require(c >= a, errorMessage);
288
+ return c;
289
+ }
290
+
291
+ function sub96(uint96 a, uint96 b, string memory errorMessage) internal pure returns (uint96) {
292
+ require(b <= a, errorMessage);
293
+ return a - b;
294
+ }
295
+
296
+ function getChainId() internal view returns (uint) {
297
+ uint256 chainId;
298
+ assembly { chainId := chainid() }
299
+ return chainId;
300
+ }
301
+ }
@@ -0,0 +1,34 @@
1
+ // SPDX-License-Identifier: BSD-3-Clause
2
+ pragma solidity ^0.8.26;
3
+
4
+ interface IComp {
5
+ struct Checkpoint {
6
+ uint32 fromBlock;
7
+ uint96 votes;
8
+ }
9
+
10
+ event Approval(address indexed owner, address indexed spender, uint256 amount);
11
+ event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
12
+ event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance);
13
+ event Transfer(address indexed from, address indexed to, uint256 amount);
14
+
15
+ function DELEGATION_TYPEHASH() external view returns (bytes32);
16
+ function DOMAIN_TYPEHASH() external view returns (bytes32);
17
+ function allowance(address account, address spender) external view returns (uint256);
18
+ function approve(address spender, uint256 rawAmount) external returns (bool);
19
+ function balanceOf(address account) external view returns (uint256);
20
+ function checkpoints(address, uint32) external view returns (uint32 fromBlock, uint96 votes);
21
+ function decimals() external view returns (uint8);
22
+ function delegate(address delegatee) external;
23
+ function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) external;
24
+ function delegates(address) external view returns (address);
25
+ function getCurrentVotes(address account) external view returns (uint96);
26
+ function getPriorVotes(address account, uint256 blockNumber) external view returns (uint96);
27
+ function name() external view returns (string memory);
28
+ function nonces(address) external view returns (uint256);
29
+ function numCheckpoints(address) external view returns (uint32);
30
+ function symbol() external view returns (string memory);
31
+ function totalSupply() external view returns (uint256);
32
+ function transfer(address dst, uint256 rawAmount) external returns (bool);
33
+ function transferFrom(address src, address dst, uint256 rawAmount) external returns (bool);
34
+ }