@openzeppelin/confidential-contracts 0.2.0-rc.1

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 (31) hide show
  1. package/README.md +24 -0
  2. package/build/contracts/Checkpoints.json +16 -0
  3. package/build/contracts/CheckpointsConfidential.json +16 -0
  4. package/build/contracts/ConfidentialFungibleToken.json +614 -0
  5. package/build/contracts/ConfidentialFungibleTokenERC20Wrapper.json +793 -0
  6. package/build/contracts/ConfidentialFungibleTokenUtils.json +10 -0
  7. package/build/contracts/ConfidentialFungibleTokenVotes.json +1002 -0
  8. package/build/contracts/ERC7821WithExecutor.json +145 -0
  9. package/build/contracts/IConfidentialFungibleToken.json +458 -0
  10. package/build/contracts/IConfidentialFungibleTokenReceiver.json +45 -0
  11. package/build/contracts/TFHESafeMath.json +10 -0
  12. package/build/contracts/VestingWalletCliffConfidential.json +275 -0
  13. package/build/contracts/VestingWalletCliffExecutorConfidential.json +424 -0
  14. package/build/contracts/VestingWalletCliffExecutorConfidentialFactory.json +290 -0
  15. package/build/contracts/VestingWalletConfidential.json +246 -0
  16. package/build/contracts/VotesConfidential.json +412 -0
  17. package/finance/ERC7821WithExecutor.sol +46 -0
  18. package/finance/VestingWalletCliffConfidential.sol +62 -0
  19. package/finance/VestingWalletCliffExecutorConfidentialFactory.sol +203 -0
  20. package/finance/VestingWalletConfidential.sol +130 -0
  21. package/governance/utils/VotesConfidential.sol +202 -0
  22. package/interfaces/IConfidentialFungibleToken.sol +135 -0
  23. package/interfaces/IConfidentialFungibleTokenReceiver.sol +19 -0
  24. package/package.json +39 -0
  25. package/token/ConfidentialFungibleToken.sol +314 -0
  26. package/token/extensions/ConfidentialFungibleTokenERC20Wrapper.sol +175 -0
  27. package/token/extensions/ConfidentialFungibleTokenVotes.sol +29 -0
  28. package/token/utils/ConfidentialFungibleTokenUtils.sol +46 -0
  29. package/utils/TFHESafeMath.sol +37 -0
  30. package/utils/structs/CheckpointsConfidential.sol +193 -0
  31. package/utils/structs/temporary-Checkpoints.sol +835 -0
@@ -0,0 +1,193 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // OpenZeppelin Confidential Contracts (last updated v0.2.0-rc.1) (utils/structs/CheckpointsConfidential.sol)
3
+ // This file was procedurally generated from scripts/generate/templates/CheckpointsConfidential.js.
4
+
5
+ pragma solidity ^0.8.24;
6
+
7
+ import {euint32, euint64} from "@fhevm/solidity/lib/FHE.sol";
8
+ import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
9
+ import {Checkpoints} from "./temporary-Checkpoints.sol";
10
+
11
+ /**
12
+ * @dev This library defines the `Trace*` struct, for checkpointing values as they change at different points in
13
+ * time, and later looking up past values by block number.
14
+ *
15
+ * To create a history of checkpoints, define a variable type `CheckpointsConfidential.Trace*` in your contract, and store a new
16
+ * checkpoint for the current transaction block using the {push} function.
17
+ */
18
+ library CheckpointsConfidential {
19
+ using Checkpoints for Checkpoints.Trace256;
20
+
21
+ /**
22
+ * @dev A value was attempted to be inserted on a past checkpoint.
23
+ */
24
+ error CheckpointUnorderedInsertion();
25
+
26
+ struct TraceEuint32 {
27
+ Checkpoints.Trace256 _inner;
28
+ }
29
+
30
+ /**
31
+ * @dev Pushes a (`key`, `value`) pair into a TraceEuint32 so that it is stored as the checkpoint.
32
+ *
33
+ * Returns previous value and new value.
34
+ *
35
+ * IMPORTANT: Never accept `key` as a user input, since an arbitrary `type(uint256).max` key set will disable the
36
+ * library.
37
+ */
38
+ function push(
39
+ TraceEuint32 storage self,
40
+ uint256 key,
41
+ euint32 value
42
+ ) internal returns (euint32 oldValue, euint32 newValue) {
43
+ (uint256 oldValueAsUint256, uint256 newValueAsUint256) = self._inner.push(key, uint256(euint32.unwrap(value)));
44
+ oldValue = euint32.wrap(bytes32(oldValueAsUint256));
45
+ newValue = euint32.wrap(bytes32(newValueAsUint256));
46
+ }
47
+
48
+ /**
49
+ * @dev Returns the value in the first (oldest) checkpoint with key greater or equal than the search key, or zero if
50
+ * there is none.
51
+ */
52
+ function lowerLookup(TraceEuint32 storage self, uint256 key) internal view returns (euint32) {
53
+ return euint32.wrap(bytes32(self._inner.lowerLookup(key)));
54
+ }
55
+
56
+ /**
57
+ * @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero
58
+ * if there is none.
59
+ */
60
+ function upperLookup(TraceEuint32 storage self, uint256 key) internal view returns (euint32) {
61
+ return euint32.wrap(bytes32(self._inner.upperLookup(key)));
62
+ }
63
+
64
+ /**
65
+ * @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero
66
+ * if there is none.
67
+ *
68
+ * NOTE: This is a variant of {upperLookup} that is optimized to find "recent" checkpoint (checkpoints with high
69
+ * keys).
70
+ */
71
+ function upperLookupRecent(TraceEuint32 storage self, uint256 key) internal view returns (euint32) {
72
+ return euint32.wrap(bytes32(self._inner.upperLookupRecent(key)));
73
+ }
74
+
75
+ /**
76
+ * @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.
77
+ */
78
+ function latest(TraceEuint32 storage self) internal view returns (euint32) {
79
+ return euint32.wrap(bytes32(self._inner.latest()));
80
+ }
81
+
82
+ /**
83
+ * @dev Returns whether there is a checkpoint in the structure (i.e. it is not empty), and if so the key and value
84
+ * in the most recent checkpoint.
85
+ */
86
+ function latestCheckpoint(
87
+ TraceEuint32 storage self
88
+ ) internal view returns (bool exists, uint256 key, euint32 value) {
89
+ uint256 valueAsUint256;
90
+ (exists, key, valueAsUint256) = self._inner.latestCheckpoint();
91
+ value = euint32.wrap(bytes32(valueAsUint256));
92
+ }
93
+
94
+ /**
95
+ * @dev Returns the number of checkpoints.
96
+ */
97
+ function length(TraceEuint32 storage self) internal view returns (uint256) {
98
+ return self._inner.length();
99
+ }
100
+
101
+ /**
102
+ * @dev Returns checkpoint at given position.
103
+ */
104
+ function at(TraceEuint32 storage self, uint32 pos) internal view returns (uint256 key, euint32 value) {
105
+ Checkpoints.Checkpoint256 memory checkpoint = self._inner.at(pos);
106
+ key = checkpoint._key;
107
+ value = euint32.wrap(bytes32(checkpoint._value));
108
+ }
109
+
110
+ struct TraceEuint64 {
111
+ Checkpoints.Trace256 _inner;
112
+ }
113
+
114
+ /**
115
+ * @dev Pushes a (`key`, `value`) pair into a TraceEuint64 so that it is stored as the checkpoint.
116
+ *
117
+ * Returns previous value and new value.
118
+ *
119
+ * IMPORTANT: Never accept `key` as a user input, since an arbitrary `type(uint256).max` key set will disable the
120
+ * library.
121
+ */
122
+ function push(
123
+ TraceEuint64 storage self,
124
+ uint256 key,
125
+ euint64 value
126
+ ) internal returns (euint64 oldValue, euint64 newValue) {
127
+ (uint256 oldValueAsUint256, uint256 newValueAsUint256) = self._inner.push(key, uint256(euint64.unwrap(value)));
128
+ oldValue = euint64.wrap(bytes32(oldValueAsUint256));
129
+ newValue = euint64.wrap(bytes32(newValueAsUint256));
130
+ }
131
+
132
+ /**
133
+ * @dev Returns the value in the first (oldest) checkpoint with key greater or equal than the search key, or zero if
134
+ * there is none.
135
+ */
136
+ function lowerLookup(TraceEuint64 storage self, uint256 key) internal view returns (euint64) {
137
+ return euint64.wrap(bytes32(self._inner.lowerLookup(key)));
138
+ }
139
+
140
+ /**
141
+ * @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero
142
+ * if there is none.
143
+ */
144
+ function upperLookup(TraceEuint64 storage self, uint256 key) internal view returns (euint64) {
145
+ return euint64.wrap(bytes32(self._inner.upperLookup(key)));
146
+ }
147
+
148
+ /**
149
+ * @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero
150
+ * if there is none.
151
+ *
152
+ * NOTE: This is a variant of {upperLookup} that is optimized to find "recent" checkpoint (checkpoints with high
153
+ * keys).
154
+ */
155
+ function upperLookupRecent(TraceEuint64 storage self, uint256 key) internal view returns (euint64) {
156
+ return euint64.wrap(bytes32(self._inner.upperLookupRecent(key)));
157
+ }
158
+
159
+ /**
160
+ * @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.
161
+ */
162
+ function latest(TraceEuint64 storage self) internal view returns (euint64) {
163
+ return euint64.wrap(bytes32(self._inner.latest()));
164
+ }
165
+
166
+ /**
167
+ * @dev Returns whether there is a checkpoint in the structure (i.e. it is not empty), and if so the key and value
168
+ * in the most recent checkpoint.
169
+ */
170
+ function latestCheckpoint(
171
+ TraceEuint64 storage self
172
+ ) internal view returns (bool exists, uint256 key, euint64 value) {
173
+ uint256 valueAsUint256;
174
+ (exists, key, valueAsUint256) = self._inner.latestCheckpoint();
175
+ value = euint64.wrap(bytes32(valueAsUint256));
176
+ }
177
+
178
+ /**
179
+ * @dev Returns the number of checkpoints.
180
+ */
181
+ function length(TraceEuint64 storage self) internal view returns (uint256) {
182
+ return self._inner.length();
183
+ }
184
+
185
+ /**
186
+ * @dev Returns checkpoint at given position.
187
+ */
188
+ function at(TraceEuint64 storage self, uint32 pos) internal view returns (uint256 key, euint64 value) {
189
+ Checkpoints.Checkpoint256 memory checkpoint = self._inner.at(pos);
190
+ key = checkpoint._key;
191
+ value = euint64.wrap(bytes32(checkpoint._value));
192
+ }
193
+ }