-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevolveMultisignwallet.sol
412 lines (324 loc) · 14 KB
/
evolveMultisignwallet.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
interface Ivalidator {
function renounceOwnership() external;
function transferOwnership(address newOwner) external ;
function updateGasSettings(uint _validatorPartPercent, uint _burnPartPercent,
uint _burnStopAmount, uint _coinPoolPercent,
uint _ownerPoolPercent, uint _foundationPercent) external;
function updateParams(address _foundationWallet, address _ownerPool, address _coinPool,
uint256 _ownerPoolColLimit, uint16 _MaxValidators, uint256 _MinimalStakingCoin,
uint256 _minimumValidatorStaking) external;
}
contract MultiSignWallet{
//--------------------Storage-------------------
address[] public owners;
mapping(address=>bool) public isOwner;
Ivalidator public validatorContract;
uint256 public WalletRequired;
Transaction[] public transactions;
mapping(uint256=> mapping(address=>bool)) public approved;
struct Transaction{
bool isExecuted;
uint functionTracker;
}
struct UpdateGasSetting{
uint validatorPartPercent;
uint burnPartPercent;
uint burnStopAmount;
uint coinPoolPercent;
uint ownerPoolPercent;
uint foundationPercent;
}
UpdateGasSetting[] public updateGasSettingInfo;
struct TransferOwnerTo{
address to;
}
TransferOwnerTo[] public transferOwner;
struct UpdateParam{
address foundationWallet;
address ownerPool;
address coinPool;
uint256 ownerPoolColLimit;
uint16 maxValidators;
uint256 minimalStakingCoin;
uint256 minimumValidatorStaking;
}
UpdateParam[] public paramsInfo;
/*
Constructor Function:
- Initializes the contract with provided parameters.
- Requires at least one owner and a valid number of required wallets.
- Validates and adds owners to the contract.
- Sets required wallets for transaction execution.
- Assigns the address of another contract interface.
Parameters:
@_owners: Array of owner addresses.
@_requiredWallet: Number of wallets needed for transaction execution.
@validatorContractAddress: Address of another contract interface.
Note:
Ensure this constructor is only called once during contract deployment.
*/
constructor(address[] memory _owners,uint256 _requiredWallet,address validatorContractAddress){
require(_owners.length>0,"owner required");
require(_requiredWallet>0 && _requiredWallet<=_owners.length,"invalid required number of owner wallets");
for(uint256 i=0;i<_owners.length;i++){
address owner = _owners[i];
require(owner!=address(0),"invalid owner");
require(!isOwner[owner],"owner is already there!");
isOwner[owner]=true;
owners.push(owner);
}
WalletRequired =_requiredWallet; // you need at least this number wallet to execute transaction
validatorContract = Ivalidator(validatorContractAddress);
}
//-----------------------EVENTS-------------------
event AssignRenounceOwnershipTx(uint256 trnx);
event AssignTransferOwnershipTx(uint256 trnx);
event AssignUpdateGasTx(uint256 trnx);
event AssignparamUpdateTx(uint256 trnx);
event Approve(address owner, uint256 trnxId);
event Revoke(address owner, uint256 trnxId);
event Execute(uint256 trnxId);
//----------------------Modifier-------------------
modifier onlyOwner(){
require(isOwner[msg.sender],"you are not the owner");
_;
}
modifier trnxExists(uint256 _trnxId){
require(_trnxId<transactions.length,"Transaction does not exist");
_;
}
modifier notApproved(uint256 _trnxId){
require(!approved[_trnxId][msg.sender],"Transaction has already done");
_;
}
modifier notExecuted(uint256 _trnxId){
Transaction storage _transactions = transactions[_trnxId];
require(!_transactions.isExecuted,"Transaction has already executed");
_;
}
/*
Description:
- Enables an owner to transfer ownership of the contract to another address.
- Registers the transfer request and logs a new transaction for tracking purposes.
Parameters:
@_to: The address to which ownership will be transferred.
Modifiers:
- onlyOwner: Restricts execution to only owners.
Returns:
- The index of the recorded transaction in the transactions array.
Note:
- This function appends a transfer ownership request to the transferOwner array.
- It also creates a new transaction entry in the transactions array with a functionTracker value of 4.
- An event is emitted to signify the assignment of a transfer ownership transaction.
*/
function transferOwnership(address _to) external onlyOwner returns(uint256){
transferOwner.push(TransferOwnerTo({
to:_to
}));
transactions.push(Transaction({
isExecuted:false,
functionTracker:4
}));
emit AssignTransferOwnershipTx(transactions.length-1);
return transactions.length-1;
}
/*
Description:
- Allows an owner to renounce their ownership of the contract.
- Logs a new transaction for tracking purposes and emits events for the renouncement and gas update.
Modifiers:
- onlyOwner: Ensures that only owners can execute this function.
Returns:
- The index of the recorded transaction in the transactions array.
Note:
- This function records a new transaction in the transactions array with a functionTracker value of 3,
indicating a renouncement of ownership.
- Emits events to signal the assignment of a gas update transaction and the renouncement of ownership.
*/
function renounceOwnership() external onlyOwner returns(uint) {
emit AssignUpdateGasTx(transactions.length-1);
transactions.push(Transaction({
isExecuted:false,
functionTracker:3
}));
emit AssignRenounceOwnershipTx(transactions.length-1);
return transactions.length-1;
}
/*
Function: updateGasSettings
Description:
- Allows the contract owner to update gas settings.
- Records the updated gas settings and logs a new transaction for tracking purposes.
Parameters:
@_validatorPartPercent: The percentage of gas allocated for validators.
@_burnPartPercent: The percentage of gas allocated for burning tokens.
@_burnStopAmount: The amount at which burning of tokens stops.
@_coinPoolPercent: The percentage of gas allocated for the coin pool.
@_ownerPoolPercent: The percentage of gas allocated for the owner pool.
@_foundationPercent: The percentage of gas allocated for the foundation.
Modifiers:
- onlyOwner: Ensures that only owners can execute this function.
Returns:
- The index of the recorded transaction in the transactions array.
*/
function updateGasSettings(uint _validatorPartPercent,uint _burnPartPercent,uint _burnStopAmount,uint _coinPoolPercent,uint _ownerPoolPercent,uint _foundationPercent) external onlyOwner returns(uint256){
updateGasSettingInfo.push(UpdateGasSetting({
validatorPartPercent: _validatorPartPercent,
burnPartPercent:_burnPartPercent,
burnStopAmount:_burnStopAmount,
coinPoolPercent:_coinPoolPercent,
ownerPoolPercent:_ownerPoolPercent,
foundationPercent:_foundationPercent
}));
transactions.push(Transaction({
isExecuted:false,
functionTracker:1
}));
emit AssignUpdateGasTx(transactions.length-1);
return transactions.length-1;
}
/*
Function: updateParams
Description:
- Allows the contract owner to update various parameters of the contract.
- Records the updated parameters and logs a new transaction for tracking purposes.
Parameters:
@_foundationWallet: The address of the foundation wallet.
@_ownerPool: The address of the owner pool.
@_coinPool: The address of the coin pool.
@_ownerPoolColLimit: The limit for owner pool collections.
@_MaxValidators: The maximum number of validators.
@_MinimalStakingCoin: The minimal staking amount of coins.
@_minimumValidatorStaking: The minimum staking amount for validators.
Modifiers:
- onlyOwner: Ensures that only owners can execute this function.
Returns:
- The index of the recorded transaction in the transactions array.
*/
function updateParams(address _foundationWallet,address _ownerPool,address _coinPool,uint _ownerPoolColLimit,uint16 _MaxValidators, uint256 _MinimalStakingCoin, uint256 _minimumValidatorStaking) external onlyOwner returns(uint256){
paramsInfo.push(UpdateParam({
foundationWallet:_foundationWallet,
ownerPool:_ownerPool,
coinPool:_coinPool,
ownerPoolColLimit:_ownerPoolColLimit,
maxValidators:_MaxValidators,
minimalStakingCoin:_MinimalStakingCoin,
minimumValidatorStaking:_minimumValidatorStaking
}));
transactions.push(Transaction({
isExecuted:false,
functionTracker:2
}));
emit AssignparamUpdateTx(transactions.length-1);
return transactions.length-1;
}
/*
Function: approveTransaction
Description:
- Allows an owner to approve a transaction.
- Marks the transaction as approved by the owner and emits an approval event.
- If the transaction receives the required number of approvals, it is executed.
Parameters:
@_trnxId: The ID of the transaction to be approved.
Modifiers:
- onlyOwner: Ensures that only owners can execute this function.
- trnxExists: Ensures that the transaction exists.
- notApproved: Ensures that the transaction has not been previously approved by the caller.
- notExecuted: Ensures that the transaction has not been executed.
*/
function approveTransaction(uint256 _trnxId)
external onlyOwner
trnxExists(_trnxId)
notApproved(_trnxId)
notExecuted(_trnxId)
{
approved[_trnxId][msg.sender]=true;
emit Approve(msg.sender,_trnxId);
if(_getAprrovalCount(_trnxId) >= WalletRequired){
executeTransaction(_trnxId);
}
}
/*
Internal Function: _getApprovalCount
Description:
- Calculates the number of approvals for a transaction.
- Iterates through the list of owners and checks if each owner has approved the transaction.
- Returns the count of approvals.
Parameters:
@_trnxId: The ID of the transaction for which to count approvals.
Returns:
- The count of approvals for the specified transaction.
*/
function _getAprrovalCount(uint256 _trnxId) public view returns(uint256 ){
uint256 count;
for(uint256 i=0; i<owners.length;i++){
if (approved[_trnxId][owners[i]]){
count+=1;
}
}
return count;
}
/*
Internal Function: executeTransaction
Description:
- Executes a transaction by calling the appropriate function on the validator contract.
- Marks the transaction as executed and emits an execution event.
Parameters:
@_trnxId: The ID of the transaction to be executed.
Modifiers:
- trnxExists: Ensures that the transaction exists.
- notExecuted: Ensures that the transaction has not been executed.
Note:
- Depending on the functionTracker value of the transaction, different functions on the validator contract are called.
*/
function executeTransaction(uint256 _trnxId) internal trnxExists(_trnxId) notExecuted(_trnxId){
require(_getAprrovalCount(_trnxId)>=WalletRequired,"you do not have sufficient approval");
Transaction storage _transactions = transactions[_trnxId];
if(_transactions.functionTracker == 1)
{
UpdateGasSetting storage _updateGasSettings = updateGasSettingInfo[updateGasSettingInfo.length-1];
validatorContract.updateGasSettings(_updateGasSettings.validatorPartPercent,_updateGasSettings.burnPartPercent,
_updateGasSettings.burnStopAmount, _updateGasSettings.coinPoolPercent,
_updateGasSettings.ownerPoolPercent, _updateGasSettings.foundationPercent);
}
else if(_transactions.functionTracker == 2){
UpdateParam storage _updateParams = paramsInfo[paramsInfo.length-1];
validatorContract.updateParams(_updateParams.foundationWallet,_updateParams.ownerPool, _updateParams.coinPool,
_updateParams.ownerPoolColLimit, _updateParams.maxValidators, _updateParams.minimalStakingCoin,
_updateParams.minimumValidatorStaking);
}
else if(_transactions.functionTracker == 3){
validatorContract.renounceOwnership();
}
else if(_transactions.functionTracker == 4){
TransferOwnerTo storage _transferOwnership = transferOwner[transferOwner.length-1];
validatorContract.transferOwnership(_transferOwnership.to);
}
_transactions.isExecuted=true;
emit Execute(_trnxId);
}
/*
Description:
- Allows an owner to revoke their approval for a transaction.
- Marks the owner's approval for the transaction as false and emits a revoke event.
Parameters:
@_trnxId: The ID of the transaction for which to revoke approval.
Modifiers:
- onlyOwner: Ensures that only owners can execute this function.
- trnxExists: Ensures that the transaction exists.
- notExecuted: Ensures that the transaction has not been executed.
Reverts:
- If the transaction has not been approved by the caller.
*/
function revoke(uint256 _trnxId) external
onlyOwner
trnxExists(_trnxId)
notExecuted(_trnxId)
{
require(approved[_trnxId][msg.sender],"Transaction has not been approve");
approved[_trnxId][msg.sender]=false;
emit Revoke(msg.sender,_trnxId);
}
}