@dolomite-exchange/dolomite-margin 0.2.6 → 0.2.7

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 (200) hide show
  1. package/build/contracts/Account.json +11 -11
  2. package/build/contracts/Actions.json +11 -11
  3. package/build/contracts/Address.json +1 -1
  4. package/build/contracts/Admin.json +23 -23
  5. package/build/contracts/AdminImpl.json +35 -307
  6. package/build/contracts/AdvancedMath.json +7 -7
  7. package/build/contracts/AmmRebalancerProxy.json +577 -621
  8. package/build/contracts/AmmRebalancerProxyV1.json +78 -32
  9. package/build/contracts/Babylonian.json +1 -1
  10. package/build/contracts/Bits.json +9 -9
  11. package/build/contracts/Cache.json +13 -13
  12. package/build/contracts/ChainlinkPriceOracleV1.json +16 -16
  13. package/build/contracts/Context.json +1 -1
  14. package/build/contracts/CustomTestToken.json +9 -9
  15. package/build/contracts/Decimal.json +9 -9
  16. package/build/contracts/DelayedMultiSig.json +9 -9
  17. package/build/contracts/DolomiteAmmERC20.json +11 -11
  18. package/build/contracts/DolomiteAmmFactory.json +14 -52
  19. package/build/contracts/DolomiteAmmLibrary.json +24 -24
  20. package/build/contracts/DolomiteAmmPair.json +27 -27
  21. package/build/contracts/DolomiteAmmRouterProxy.json +30 -363
  22. package/build/contracts/DolomiteMargin.json +21 -67
  23. package/build/contracts/DoubleExponentInterestSetter.json +15 -21
  24. package/build/contracts/EnumerableSet.json +7 -7
  25. package/build/contracts/ErroringOmiseToken.json +9 -9
  26. package/build/contracts/ErroringToken.json +10 -10
  27. package/build/contracts/Events.json +17 -17
  28. package/build/contracts/ExcessivelySafeCall.json +35 -35
  29. package/build/contracts/Exchange.json +15 -15
  30. package/build/contracts/Expiry.json +36 -36
  31. package/build/contracts/Getters.json +33 -33
  32. package/build/contracts/IAutoTrader.json +9 -9
  33. package/build/contracts/ICallee.json +7 -7
  34. package/build/contracts/IChainlinkAggregator.json +5 -5
  35. package/build/contracts/IDolomiteAmmERC20.json +5 -5
  36. package/build/contracts/IDolomiteAmmFactory.json +9 -9
  37. package/build/contracts/IDolomiteAmmPair.json +9 -9
  38. package/build/contracts/IDolomiteMargin.json +23 -23
  39. package/build/contracts/IERC20.json +1 -1
  40. package/build/contracts/IERC20Detailed.json +5 -5
  41. package/build/contracts/IExchangeWrapper.json +5 -5
  42. package/build/contracts/IExpiry.json +9 -9
  43. package/build/contracts/IInterestSetter.json +7 -7
  44. package/build/contracts/ILiquidationCallback.json +7 -7
  45. package/build/contracts/IMakerOracle.json +5 -5
  46. package/build/contracts/IOasisDex.json +5 -5
  47. package/build/contracts/IPriceOracle.json +7 -7
  48. package/build/contracts/IRecyclable.json +9 -9
  49. package/build/contracts/ITransferProxy.json +5 -5
  50. package/build/contracts/IUniswapV2Callee.json +5 -5
  51. package/build/contracts/IUniswapV2Factory.json +5 -5
  52. package/build/contracts/IUniswapV2Pair.json +5 -5
  53. package/build/contracts/IUniswapV2Router.json +5 -5
  54. package/build/contracts/IWETH.json +5 -5
  55. package/build/contracts/Interest.json +15 -15
  56. package/build/contracts/LiquidateOrVaporizeImpl.json +32 -83
  57. package/build/contracts/LiquidatorProxyHelper.json +23 -23
  58. package/build/contracts/LiquidatorProxyV1.json +30 -36
  59. package/build/contracts/LiquidatorProxyV1WithAmm.json +49 -105
  60. package/build/contracts/Math.json +1 -1
  61. package/build/contracts/Migrations.json +8 -14
  62. package/build/contracts/Monetary.json +7 -7
  63. package/build/contracts/MultiCall.json +8 -14
  64. package/build/contracts/MultiSig.json +7 -7
  65. package/build/contracts/OmiseToken.json +8 -8
  66. package/build/contracts/OnlyDolomiteMargin.json +11 -11
  67. package/build/contracts/Operation.json +15 -15
  68. package/build/contracts/OperationImpl.json +39 -47
  69. package/build/contracts/Ownable.json +1 -1
  70. package/build/contracts/PartiallyDelayedMultiSig.json +9 -9
  71. package/build/contracts/PayableProxy.json +17 -23
  72. package/build/contracts/Permission.json +11 -11
  73. package/build/contracts/PolynomialInterestSetter.json +13 -13
  74. package/build/contracts/RecyclableTokenProxy.json +25 -25
  75. package/build/contracts/ReentrancyGuard.json +1 -1
  76. package/build/contracts/Require.json +7 -7
  77. package/build/contracts/SafeERC20.json +1 -1
  78. package/build/contracts/SafeETH.json +7 -7
  79. package/build/contracts/SafeLiquidationCallback.json +17 -17
  80. package/build/contracts/SafeMath.json +1 -1
  81. package/build/contracts/SignedOperationProxy.json +21 -104
  82. package/build/contracts/SimpleFeeOwner.json +18 -63
  83. package/build/contracts/State.json +9 -9
  84. package/build/contracts/Storage.json +37 -37
  85. package/build/contracts/TestAmmRebalancerProxy.json +32 -58
  86. package/build/contracts/TestAutoTrader.json +22 -22
  87. package/build/contracts/TestBtcUsdChainlinkAggregator.json +10 -10
  88. package/build/contracts/TestCallee.json +19 -19
  89. package/build/contracts/TestChainlinkPriceOracleV1.json +10 -94
  90. package/build/contracts/TestCounter.json +7 -7
  91. package/build/contracts/TestDaiUsdChainlinkAggregator.json +11 -11
  92. package/build/contracts/TestDolomiteMargin.json +22 -22
  93. package/build/contracts/TestDoubleExponentInterestSetter.json +10 -10
  94. package/build/contracts/TestEthUsdChainlinkAggregator.json +11 -11
  95. package/build/contracts/TestExchangeWrapper.json +28 -28
  96. package/build/contracts/TestInterestSetter.json +13 -13
  97. package/build/contracts/TestLib.json +22 -22
  98. package/build/contracts/TestLinkUsdChainlinkAggregator.json +11 -11
  99. package/build/contracts/TestLiquidateCallback.json +719 -719
  100. package/build/contracts/TestLiquidationCallback.json +13 -13
  101. package/build/contracts/TestLrcEthChainlinkAggregator.json +11 -11
  102. package/build/contracts/TestMakerOracle.json +10 -10
  103. package/build/contracts/TestMaticUsdChainlinkAggregator.json +10 -10
  104. package/build/contracts/TestOasisDex.json +12 -12
  105. package/build/contracts/TestOperationImpl.json +14 -14
  106. package/build/contracts/TestPolynomialInterestSetter.json +10 -10
  107. package/build/contracts/TestPriceAggregator.json +9 -9
  108. package/build/contracts/TestPriceOracle.json +13 -13
  109. package/build/contracts/TestRecyclableToken.json +9 -9
  110. package/build/contracts/TestSimpleCallee.json +15 -15
  111. package/build/contracts/TestToken.json +9 -9
  112. package/build/contracts/TestTrader.json +17 -17
  113. package/build/contracts/TestUniswapAmmRebalancerProxy.json +16 -16
  114. package/build/contracts/TestUsdcUsdChainlinkAggregator.json +11 -11
  115. package/build/contracts/TestWETH.json +9 -9
  116. package/build/contracts/Time.json +9 -9
  117. package/build/contracts/Token.json +9 -9
  118. package/build/contracts/TokenA.json +10 -10
  119. package/build/contracts/TokenB.json +10 -10
  120. package/build/contracts/TokenC.json +10 -10
  121. package/build/contracts/TokenD.json +10 -10
  122. package/build/contracts/TokenE.json +10 -10
  123. package/build/contracts/TokenF.json +10 -10
  124. package/build/contracts/TransferProxy.json +22 -28
  125. package/build/contracts/TypedSignature.json +9 -9
  126. package/build/contracts/Types.json +9 -9
  127. package/build/contracts/UQ112x112.json +7 -7
  128. package/build/contracts/UniswapV2ERC20.json +7 -7
  129. package/build/contracts/UniswapV2Factory.json +12 -12
  130. package/build/contracts/UniswapV2Library.json +20 -20
  131. package/build/contracts/UniswapV2Pair.json +17 -17
  132. package/build/contracts/UniswapV2Router02.json +16 -16
  133. package/build/contracts/WETH9.json +1 -1
  134. package/contracts/external/amm/DolomiteAmmERC20.sol +135 -0
  135. package/contracts/external/amm/DolomiteAmmFactory.sol +122 -0
  136. package/contracts/external/amm/DolomiteAmmPair.sol +573 -0
  137. package/contracts/external/amm/SimpleFeeOwner.sol +107 -0
  138. package/contracts/external/helpers/LiquidatorProxyHelper.sol +252 -0
  139. package/contracts/external/helpers/OnlyDolomiteMargin.sol +63 -0
  140. package/contracts/external/interestsetters/DoubleExponentInterestSetter.sol +212 -0
  141. package/contracts/external/interestsetters/PolynomialInterestSetter.sol +205 -0
  142. package/contracts/external/interfaces/IChainlinkAggregator.sol +33 -0
  143. package/contracts/external/interfaces/IDolomiteAmmERC20.sol +52 -0
  144. package/contracts/external/interfaces/IDolomiteAmmFactory.sol +42 -0
  145. package/contracts/external/interfaces/IDolomiteAmmPair.sol +116 -0
  146. package/contracts/external/interfaces/IExpiry.sol +70 -0
  147. package/contracts/external/interfaces/IMakerOracle.sol +52 -0
  148. package/contracts/external/interfaces/IOasisDex.sol +326 -0
  149. package/contracts/external/interfaces/ITransferProxy.sol +53 -0
  150. package/contracts/external/interfaces/IUniswapV2Router.sol +134 -0
  151. package/contracts/external/lib/AdvancedMath.sol +23 -0
  152. package/contracts/external/lib/DolomiteAmmLibrary.sol +323 -0
  153. package/contracts/external/lib/TypedSignature.sol +120 -0
  154. package/contracts/external/lib/UQ112x112.sol +22 -0
  155. package/contracts/external/multisig/DelayedMultiSig.sol +206 -0
  156. package/contracts/external/multisig/MultiSig.sol +571 -0
  157. package/contracts/external/multisig/PartiallyDelayedMultiSig.sol +174 -0
  158. package/contracts/external/oracles/ChainlinkPriceOracleV1.sol +197 -0
  159. package/contracts/external/oracles/TestChainlinkPriceOracleV1.sol +98 -0
  160. package/contracts/external/proxies/AmmRebalancerProxyV1.sol +465 -0
  161. package/contracts/external/proxies/DolomiteAmmRouterProxy.sol +877 -0
  162. package/contracts/external/proxies/LiquidatorProxyV1.sol +507 -0
  163. package/contracts/external/proxies/LiquidatorProxyV1WithAmm.sol +574 -0
  164. package/contracts/external/proxies/PayableProxy.sol +146 -0
  165. package/contracts/external/proxies/RecyclableTokenProxy.sol +463 -0
  166. package/contracts/external/proxies/SignedOperationProxy.sol +553 -0
  167. package/contracts/external/proxies/TransferProxy.sol +207 -0
  168. package/contracts/external/traders/Expiry.sol +532 -0
  169. package/contracts/external/uniswap-v2/UniswapV2ERC20.sol +118 -0
  170. package/contracts/external/uniswap-v2/UniswapV2Factory.sol +67 -0
  171. package/contracts/external/uniswap-v2/UniswapV2Pair.sol +283 -0
  172. package/contracts/external/uniswap-v2/UniswapV2Router02.sol +566 -0
  173. package/contracts/external/uniswap-v2/interfaces/IUniswapV2Callee.sol +13 -0
  174. package/contracts/external/uniswap-v2/interfaces/IUniswapV2Factory.sol +18 -0
  175. package/contracts/external/uniswap-v2/interfaces/IUniswapV2Pair.sol +67 -0
  176. package/contracts/external/uniswap-v2/interfaces/IWETH.sol +7 -0
  177. package/contracts/external/uniswap-v2/libraries/SafeETH.sol +29 -0
  178. package/contracts/external/uniswap-v2/libraries/UniswapV2Library.sol +117 -0
  179. package/contracts/external/utils/MultiCall.sol +95 -0
  180. package/contracts/protocol/impl/artifacts/OperationImpl.json +80 -0
  181. package/contracts/protocol/impl/artifacts/OperationImpl_metadata.json +193 -0
  182. package/dist/build/published_contracts/AdminImpl.json +2 -2
  183. package/dist/build/published_contracts/AmmRebalancerProxyV1.json +5 -0
  184. package/dist/build/published_contracts/ChainlinkPriceOracleV1.json +1 -1
  185. package/dist/build/published_contracts/DolomiteAmmFactory.json +1 -1
  186. package/dist/build/published_contracts/DolomiteAmmRouterProxy.json +1 -1
  187. package/dist/build/published_contracts/DoubleExponentInterestSetter.json +2 -2
  188. package/dist/build/published_contracts/Expiry.json +1 -1
  189. package/dist/build/published_contracts/LiquidatorProxyV1.json +1 -1
  190. package/dist/build/published_contracts/LiquidatorProxyV1WithAmm.json +1 -1
  191. package/dist/build/published_contracts/MultiCall.json +1 -1
  192. package/dist/build/published_contracts/PayableProxy.json +2 -2
  193. package/dist/build/published_contracts/SignedOperationProxy.json +2 -2
  194. package/dist/build/published_contracts/SimpleFeeOwner.json +1 -1
  195. package/dist/build/published_contracts/TestUniswapAmmRebalancerProxy.json +140 -0
  196. package/dist/build/published_contracts/TransferProxy.json +1 -1
  197. package/dist/src/lib/Contracts.d.ts +3 -1
  198. package/dist/src/lib/Contracts.js +7 -3
  199. package/dist/src/lib/Contracts.js.map +1 -1
  200. package/package.json +2 -1
@@ -0,0 +1,571 @@
1
+ /*
2
+
3
+ Copyright 2019 dYdX Trading Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ */
18
+
19
+ pragma solidity ^0.5.7;
20
+ pragma experimental ABIEncoderV2;
21
+
22
+
23
+ /**
24
+ * @title MultiSig
25
+ * @author dYdX
26
+ *
27
+ * Multi-Signature Wallet.
28
+ * Allows multiple parties to agree on transactions before execution.
29
+ * Adapted from Stefan George's MultiSigWallet contract.
30
+ *
31
+ * Logic Changes:
32
+ * - Removed the fallback function
33
+ * - Ensure newOwner is notNull
34
+ *
35
+ * Syntax Changes:
36
+ * - Update Solidity syntax for 0.5.X: use `emit` keyword (events), use `view` keyword (functions)
37
+ * - Add braces to all `if` and `for` statements
38
+ * - Remove named return variables
39
+ * - Add space before and after comparison operators
40
+ * - Add ADDRESS_ZERO as a constant
41
+ * - uint => uint256
42
+ * - external_call => externalCall
43
+ */
44
+ contract MultiSig {
45
+
46
+ // ============ Events ============
47
+
48
+ event Confirmation(address indexed sender, uint256 indexed transactionId);
49
+ event Revocation(address indexed sender, uint256 indexed transactionId);
50
+ event Submission(uint256 indexed transactionId);
51
+ event Execution(uint256 indexed transactionId);
52
+ event ExecutionFailure(uint256 indexed transactionId);
53
+ event OwnerAddition(address indexed owner);
54
+ event OwnerRemoval(address indexed owner);
55
+ event RequirementChange(uint256 required);
56
+
57
+ // ============ Constants ============
58
+
59
+ uint256 constant public MAX_OWNER_COUNT = 50;
60
+ address constant ADDRESS_ZERO = address(0x0);
61
+
62
+ // ============ Storage ============
63
+
64
+ mapping (uint256 => Transaction) public transactions;
65
+ mapping (uint256 => mapping (address => bool)) public confirmations;
66
+ mapping (address => bool) public isOwner;
67
+ address[] public owners;
68
+ uint256 public required;
69
+ uint256 public transactionCount;
70
+
71
+ // ============ Structs ============
72
+
73
+ struct Transaction {
74
+ address destination;
75
+ uint256 value;
76
+ bytes data;
77
+ bool executed;
78
+ }
79
+
80
+ // ============ Modifiers ============
81
+
82
+ modifier onlyWallet() {
83
+ require(msg.sender == address(this), "ONLY_WALLET");
84
+ _;
85
+ }
86
+
87
+ modifier ownerDoesNotExist(
88
+ address owner
89
+ ) {
90
+ require(!isOwner[owner], "OWNER_EXISTS");
91
+ _;
92
+ }
93
+
94
+ modifier ownerExists(
95
+ address owner
96
+ ) {
97
+ require(isOwner[owner], "OWNER_DOES_NOT_EXIST");
98
+ _;
99
+ }
100
+
101
+ modifier transactionExists(
102
+ uint256 transactionId
103
+ ) {
104
+ require(transactions[transactionId].destination != ADDRESS_ZERO, "TRANSACTION_DOES_NOT_EXIST");
105
+ _;
106
+ }
107
+
108
+ modifier confirmed(
109
+ uint256 transactionId,
110
+ address owner
111
+ ) {
112
+ require(confirmations[transactionId][owner], "TRANSACTION_NOT_CONFIRMED");
113
+ _;
114
+ }
115
+
116
+ modifier notConfirmed(
117
+ uint256 transactionId,
118
+ address owner
119
+ ) {
120
+ require(!confirmations[transactionId][owner], "TRANSACTION_ALREADY_CONFIRMED");
121
+ _;
122
+ }
123
+
124
+ modifier notExecuted(
125
+ uint256 transactionId
126
+ ) {
127
+ require(!transactions[transactionId].executed, "TRANSACTION_ALREADY_EXECUTED");
128
+ _;
129
+ }
130
+
131
+ modifier notNull(
132
+ address _address
133
+ ) {
134
+ require(_address != ADDRESS_ZERO, "ADDRESS_IS_NULL");
135
+ _;
136
+ }
137
+
138
+ modifier validRequirement(
139
+ uint256 ownerCount,
140
+ uint256 _required
141
+ ) {
142
+ require(
143
+ ownerCount <= MAX_OWNER_COUNT
144
+ && _required <= ownerCount
145
+ && _required != 0
146
+ && ownerCount != 0,
147
+ "NO_REQUIREMENTS"
148
+ );
149
+ _;
150
+ }
151
+
152
+ // ============ Constructor ============
153
+
154
+ /**
155
+ * Contract constructor sets initial owners and required number of confirmations.
156
+ *
157
+ * @param _owners List of initial owners.
158
+ * @param _required Number of required confirmations.
159
+ */
160
+ constructor(
161
+ address[] memory _owners,
162
+ uint256 _required
163
+ )
164
+ public
165
+ validRequirement(_owners.length, _required)
166
+ {
167
+ for (uint256 i = 0; i < _owners.length; i++) {
168
+ require(!isOwner[_owners[i]] && _owners[i] != ADDRESS_ZERO, "ALREADY_OWNER");
169
+ isOwner[_owners[i]] = true;
170
+ }
171
+ owners = _owners;
172
+ required = _required;
173
+ }
174
+
175
+ // ============ Wallet-Only Functions ============
176
+
177
+ /**
178
+ * Allows to add a new owner. Transaction has to be sent by wallet.
179
+ *
180
+ * @param owner Address of new owner.
181
+ */
182
+ function addOwner(
183
+ address owner
184
+ )
185
+ public
186
+ onlyWallet
187
+ ownerDoesNotExist(owner)
188
+ notNull(owner)
189
+ validRequirement(owners.length + 1, required)
190
+ {
191
+ isOwner[owner] = true;
192
+ owners.push(owner);
193
+ emit OwnerAddition(owner);
194
+ }
195
+
196
+ /**
197
+ * Allows to remove an owner. Transaction has to be sent by wallet.
198
+ *
199
+ * @param owner Address of owner.
200
+ */
201
+ function removeOwner(
202
+ address owner
203
+ )
204
+ public
205
+ onlyWallet
206
+ ownerExists(owner)
207
+ {
208
+ isOwner[owner] = false;
209
+ for (uint256 i = 0; i < owners.length - 1; i++) {
210
+ if (owners[i] == owner) {
211
+ owners[i] = owners[owners.length - 1];
212
+ break;
213
+ }
214
+ }
215
+ owners.length -= 1;
216
+ if (required > owners.length) {
217
+ changeRequirement(owners.length);
218
+ }
219
+ emit OwnerRemoval(owner);
220
+ }
221
+
222
+ /**
223
+ * Allows to replace an owner with a new owner. Transaction has to be sent by wallet.
224
+ *
225
+ * @param owner Address of owner to be replaced.
226
+ * @param newOwner Address of new owner.
227
+ */
228
+ function replaceOwner(
229
+ address owner,
230
+ address newOwner
231
+ )
232
+ public
233
+ onlyWallet
234
+ ownerExists(owner)
235
+ ownerDoesNotExist(newOwner)
236
+ notNull(newOwner)
237
+ {
238
+ for (uint256 i = 0; i < owners.length; i++) {
239
+ if (owners[i] == owner) {
240
+ owners[i] = newOwner;
241
+ break;
242
+ }
243
+ }
244
+ isOwner[owner] = false;
245
+ isOwner[newOwner] = true;
246
+ emit OwnerRemoval(owner);
247
+ emit OwnerAddition(newOwner);
248
+ }
249
+
250
+ /**
251
+ * Allows to change the number of required confirmations. Transaction has to be sent by wallet.
252
+ *
253
+ * @param _required Number of required confirmations.
254
+ */
255
+ function changeRequirement(
256
+ uint256 _required
257
+ )
258
+ public
259
+ onlyWallet
260
+ validRequirement(owners.length, _required)
261
+ {
262
+ required = _required;
263
+ emit RequirementChange(_required);
264
+ }
265
+
266
+ // ============ Admin Functions ============
267
+
268
+ /**
269
+ * Allows an owner to submit and confirm a transaction.
270
+ *
271
+ * @param destination Transaction target address.
272
+ * @param value Transaction ether value.
273
+ * @param data Transaction data payload.
274
+ * @return Transaction ID.
275
+ */
276
+ function submitTransaction(
277
+ address destination,
278
+ uint256 value,
279
+ bytes memory data
280
+ )
281
+ public
282
+ returns (uint256)
283
+ {
284
+ uint256 transactionId = addTransaction(destination, value, data);
285
+ confirmTransaction(transactionId);
286
+ return transactionId;
287
+ }
288
+
289
+ /**
290
+ * Allows an owner to confirm a transaction.
291
+ *
292
+ * @param transactionId Transaction ID.
293
+ */
294
+ function confirmTransaction(
295
+ uint256 transactionId
296
+ )
297
+ public
298
+ ownerExists(msg.sender)
299
+ transactionExists(transactionId)
300
+ notConfirmed(transactionId, msg.sender)
301
+ {
302
+ confirmations[transactionId][msg.sender] = true;
303
+ emit Confirmation(msg.sender, transactionId);
304
+ executeTransaction(transactionId);
305
+ }
306
+
307
+ /**
308
+ * Allows an owner to revoke a confirmation for a transaction.
309
+ *
310
+ * @param transactionId Transaction ID.
311
+ */
312
+ function revokeConfirmation(
313
+ uint256 transactionId
314
+ )
315
+ public
316
+ ownerExists(msg.sender)
317
+ confirmed(transactionId, msg.sender)
318
+ notExecuted(transactionId)
319
+ {
320
+ confirmations[transactionId][msg.sender] = false;
321
+ emit Revocation(msg.sender, transactionId);
322
+ }
323
+
324
+ /**
325
+ * Allows an owner to execute a confirmed transaction.
326
+ *
327
+ * @param transactionId Transaction ID.
328
+ */
329
+ function executeTransaction(
330
+ uint256 transactionId
331
+ )
332
+ public
333
+ ownerExists(msg.sender)
334
+ confirmed(transactionId, msg.sender)
335
+ notExecuted(transactionId)
336
+ {
337
+ if (isConfirmed(transactionId)) {
338
+ Transaction storage txn = transactions[transactionId];
339
+ txn.executed = true;
340
+ if (externalCall(
341
+ txn.destination,
342
+ txn.value,
343
+ txn.data.length,
344
+ txn.data)
345
+ ) {
346
+ emit Execution(transactionId);
347
+ } else {
348
+ emit ExecutionFailure(transactionId);
349
+ txn.executed = false;
350
+ }
351
+ }
352
+ }
353
+
354
+ // ============ Getter Functions ============
355
+
356
+ /**
357
+ * Returns the confirmation status of a transaction.
358
+ *
359
+ * @param transactionId Transaction ID.
360
+ * @return Confirmation status.
361
+ */
362
+ function isConfirmed(
363
+ uint256 transactionId
364
+ )
365
+ public
366
+ view
367
+ returns (bool)
368
+ {
369
+ uint256 count = 0;
370
+ for (uint256 i = 0; i < owners.length; i++) {
371
+ if (confirmations[transactionId][owners[i]]) {
372
+ count += 1;
373
+ }
374
+ if (count == required) {
375
+ return true;
376
+ }
377
+ }
378
+ return false;
379
+ }
380
+
381
+ /**
382
+ * Returns number of confirmations of a transaction.
383
+ *
384
+ * @param transactionId Transaction ID.
385
+ * @return Number of confirmations.
386
+ */
387
+ function getConfirmationCount(
388
+ uint256 transactionId
389
+ )
390
+ public
391
+ view
392
+ returns (uint256)
393
+ {
394
+ uint256 count = 0;
395
+ for (uint256 i = 0; i < owners.length; i++) {
396
+ if (confirmations[transactionId][owners[i]]) {
397
+ count += 1;
398
+ }
399
+ }
400
+ return count;
401
+ }
402
+
403
+ /**
404
+ * Returns total number of transactions after filers are applied.
405
+ *
406
+ * @param pending Include pending transactions.
407
+ * @param executed Include executed transactions.
408
+ * @return Total number of transactions after filters are applied.
409
+ */
410
+ function getTransactionCount(
411
+ bool pending,
412
+ bool executed
413
+ )
414
+ public
415
+ view
416
+ returns (uint256)
417
+ {
418
+ uint256 count = 0;
419
+ for (uint256 i = 0; i < transactionCount; i++) {
420
+ if (
421
+ pending && !transactions[i].executed
422
+ || executed && transactions[i].executed
423
+ ) {
424
+ count += 1;
425
+ }
426
+ }
427
+ return count;
428
+ }
429
+
430
+ /**
431
+ * Returns array of owners.
432
+ *
433
+ * @return Array of owner addresses.
434
+ */
435
+ function getOwners()
436
+ public
437
+ view
438
+ returns (address[] memory)
439
+ {
440
+ return owners;
441
+ }
442
+
443
+ /**
444
+ * Returns array with owner addresses, which confirmed transaction.
445
+ *
446
+ * @param transactionId Transaction ID.
447
+ * @return Array of owner addresses.
448
+ */
449
+ function getConfirmations(
450
+ uint256 transactionId
451
+ )
452
+ public
453
+ view
454
+ returns (address[] memory)
455
+ {
456
+ address[] memory confirmationsTemp = new address[](owners.length);
457
+ uint256 count = 0;
458
+ uint256 i;
459
+ for (i = 0; i < owners.length; i++) {
460
+ if (confirmations[transactionId][owners[i]]) {
461
+ confirmationsTemp[count] = owners[i];
462
+ count += 1;
463
+ }
464
+ }
465
+ address[] memory _confirmations = new address[](count);
466
+ for (i = 0; i < count; i++) {
467
+ _confirmations[i] = confirmationsTemp[i];
468
+ }
469
+ return _confirmations;
470
+ }
471
+
472
+ /**
473
+ * Returns list of transaction IDs in defined range.
474
+ *
475
+ * @param from Index start position of transaction array.
476
+ * @param to Index end position of transaction array.
477
+ * @param pending Include pending transactions.
478
+ * @param executed Include executed transactions.
479
+ * @return Array of transaction IDs.
480
+ */
481
+ function getTransactionIds(
482
+ uint256 from,
483
+ uint256 to,
484
+ bool pending,
485
+ bool executed
486
+ )
487
+ public
488
+ view
489
+ returns (uint256[] memory)
490
+ {
491
+ uint256[] memory transactionIdsTemp = new uint256[](transactionCount);
492
+ uint256 count = 0;
493
+ uint256 i;
494
+ for (i = 0; i < transactionCount; i++) {
495
+ if (
496
+ pending && !transactions[i].executed
497
+ || executed && transactions[i].executed
498
+ ) {
499
+ transactionIdsTemp[count] = i;
500
+ count += 1;
501
+ }
502
+ }
503
+ uint256[] memory _transactionIds = new uint256[](to - from);
504
+ for (i = from; i < to; i++) {
505
+ _transactionIds[i - from] = transactionIdsTemp[i];
506
+ }
507
+ return _transactionIds;
508
+ }
509
+
510
+ // ============ Helper Functions ============
511
+
512
+ // call has been separated into its own function in order to take advantage
513
+ // of the Solidity's code generator to produce a loop that copies tx.data into memory.
514
+ function externalCall(
515
+ address destination,
516
+ uint256 value,
517
+ uint256 dataLength,
518
+ bytes memory data
519
+ )
520
+ internal
521
+ returns (bool)
522
+ {
523
+ bool result;
524
+ /* solium-disable-next-line security/no-inline-assembly */
525
+ assembly {
526
+ let x := mload(0x40) // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
527
+ let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
528
+ result := call(
529
+ sub(gas, 34710), // 34710 is the value that solidity is currently emitting
530
+ // It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
531
+ // callNewAccountGas (25000, in case the destination address does not exist and needs creating)
532
+ destination,
533
+ value,
534
+ d,
535
+ dataLength, // Size of the input (in bytes) - this is what fixes the padding problem
536
+ x,
537
+ 0 // Output is ignored, therefore the output size is zero
538
+ )
539
+ }
540
+ return result;
541
+ }
542
+
543
+ /**
544
+ * Adds a new transaction to the transaction mapping, if transaction does not exist yet.
545
+ *
546
+ * @param destination Transaction target address.
547
+ * @param value Transaction ether value.
548
+ * @param data Transaction data payload.
549
+ * @return Transaction ID.
550
+ */
551
+ function addTransaction(
552
+ address destination,
553
+ uint256 value,
554
+ bytes memory data
555
+ )
556
+ internal
557
+ notNull(destination)
558
+ returns (uint256)
559
+ {
560
+ uint256 transactionId = transactionCount;
561
+ transactions[transactionId] = Transaction({
562
+ destination: destination,
563
+ value: value,
564
+ data: data,
565
+ executed: false
566
+ });
567
+ transactionCount += 1;
568
+ emit Submission(transactionId);
569
+ return transactionId;
570
+ }
571
+ }