1
1
pragma solidity 0.5.17 ;
2
+ pragma experimental ABIEncoderV2;
2
3
3
4
import "@daostack/infra/contracts/votingMachines/IntVoteInterface.sol " ;
4
5
import "@daostack/infra/contracts/votingMachines/ProposalExecuteInterface.sol " ;
5
6
import "../votingMachines/VotingMachineCallbacks.sol " ;
6
- import "../libs/BytesLib.sol " ;
7
7
8
8
9
9
/**
@@ -12,14 +12,12 @@ import "../libs/BytesLib.sol";
12
12
* on one or multiple contracts on behalf of the organization avatar.
13
13
*/
14
14
contract GenericSchemeMultiCall is VotingMachineCallbacks , ProposalExecuteInterface {
15
- using BytesLib for bytes ;
16
15
using SafeMath for uint256 ;
17
16
18
17
// Details of a voting proposal:
19
18
struct MultiCallProposal {
20
19
address [] contractsToCall;
21
- bytes callsData;
22
- uint256 [] callsDataLens;
20
+ bytes [] callsData;
23
21
uint256 [] values;
24
22
bool exist;
25
23
bool passed;
@@ -36,7 +34,7 @@ contract GenericSchemeMultiCall is VotingMachineCallbacks, ProposalExecuteInterf
36
34
event NewMultiCallProposal (
37
35
address indexed _avatar ,
38
36
bytes32 indexed _proposalId ,
39
- bytes _callsData ,
37
+ bytes [] _callsData ,
40
38
uint256 [] _values ,
41
39
string _descriptionHash ,
42
40
address [] _contractsToCall
@@ -51,7 +49,7 @@ contract GenericSchemeMultiCall is VotingMachineCallbacks, ProposalExecuteInterf
51
49
address indexed _avatar ,
52
50
bytes32 indexed _proposalId ,
53
51
address _contractToCall ,
54
- bytes _callsData ,
52
+ bytes _callData ,
55
53
bytes _callDataReturnValue
56
54
);
57
55
@@ -133,10 +131,9 @@ contract GenericSchemeMultiCall is VotingMachineCallbacks, ProposalExecuteInterf
133
131
bytes memory genericCallReturnValue;
134
132
bool success;
135
133
Controller controller = Controller (whitelistedContracts[0 ]);
136
- uint256 startIndex = 0 ;
137
134
138
135
for (uint i = 0 ; i < proposal.contractsToCall.length ; i++ ) {
139
- bytes memory callData = proposal.callsData. slice (startIndex, proposal.callsDataLens [i]) ;
136
+ bytes memory callData = proposal.callsData[i];
140
137
if (proposal.contractsToCall[i] == address (controller)) {
141
138
(IERC20 extToken ,
142
139
address spender ,
@@ -154,7 +151,6 @@ contract GenericSchemeMultiCall is VotingMachineCallbacks, ProposalExecuteInterf
154
151
155
152
/* Whole transaction will be reverted if at least one call fails*/
156
153
require (success, "Proposal call failed " );
157
- startIndex = startIndex.add (proposal.callsDataLens[i]);
158
154
emit ProposalCallExecuted (
159
155
address (avatar),
160
156
_proposalId,
@@ -174,50 +170,46 @@ contract GenericSchemeMultiCall is VotingMachineCallbacks, ProposalExecuteInterf
174
170
* The function trigger NewMultiCallProposal event
175
171
* @param _contractsToCall the contracts to be called
176
172
* @param _callsData - The abi encode data for the calls
177
- * @param _callsDataLens the length of each callData
178
173
* @param _values value(ETH) to transfer with the calls
179
174
* @param _descriptionHash proposal description hash
180
175
* @return an id which represents the proposal
176
+ * Note: The reasone this function is public(and not 'external') is due to
177
+ * known compiler issue handling calldata bytes[] still not solved in 0.5.17
178
+ * see : https://github.com/ethereum/solidity/issues/6835#issuecomment-549895381
181
179
*/
182
180
function proposeCalls (
183
181
address [] memory _contractsToCall ,
184
- bytes memory _callsData ,
185
- uint256 [] memory _callsDataLens ,
182
+ bytes [] memory _callsData ,
186
183
uint256 [] memory _values ,
187
184
string memory _descriptionHash
188
185
)
189
186
public
190
187
returns (bytes32 proposalId )
191
188
{
192
189
require (
193
- (_contractsToCall.length == _callsDataLens .length ) && (_contractsToCall.length == _values.length ),
190
+ (_contractsToCall.length == _callsData .length ) && (_contractsToCall.length == _values.length ),
194
191
"Wrong length of _contractsToCall, _callsDataLens or _values arrays "
195
192
);
196
- uint256 startIndex = 0 ;
197
193
for (uint i = 0 ; i < _contractsToCall.length ; i++ ) {
198
194
require (
199
195
contractWhitelist[_contractsToCall[i]], "contractToCall is not whitelisted "
200
196
);
201
- bytes memory callData = _callsData.slice (startIndex, _callsDataLens[i]);
202
197
if (_contractsToCall[i] == whitelistedContracts[0 ]) {
203
198
204
199
(, address spender ,) =
205
200
abi.decode (
206
- callData ,
201
+ _callsData[i] ,
207
202
(IERC20 , address , uint256 )
208
203
);
209
204
require (contractWhitelist[spender], "spender contract not whitelisted " );
210
205
}
211
- startIndex = startIndex.add (_callsDataLens[i]);
212
206
}
213
- require (startIndex == _callsData.length , "_callsDataLens is wrong " );
214
207
215
208
proposalId = votingMachine.propose (2 , voteParams, msg .sender , address (avatar));
216
209
217
210
proposals[proposalId] = MultiCallProposal ({
218
211
contractsToCall: _contractsToCall,
219
212
callsData: _callsData,
220
- callsDataLens: _callsDataLens,
221
213
values: _values,
222
214
exist: true ,
223
215
passed: false
0 commit comments