dedupe registry.length assignments
This commit is contained in:
parent
c45cd363b9
commit
17413f5662
32
chains.json
32
chains.json
|
@ -750,5 +750,37 @@
|
|||
"address": "0x9c888ff4D7d4F512C79073ad5016116327fD8315"
|
||||
}
|
||||
}
|
||||
},
|
||||
"0x434aba1e9737c8527b5514ba9b1dbd2330705ce02243cb119510c11668159714": {
|
||||
"contracts": {
|
||||
"0xe5413cb03538126884d14df481da47efdeba969bd6c7e3609abaf1dc42973b1a": {
|
||||
"name": "MiniMeTokenFactory",
|
||||
"address": "0x7078E9E73FeFf15eC5C4C58233adc19447719979"
|
||||
},
|
||||
"0x1dc86cbe444c7243c6565fc68d02a9a0623e97a7d9470f1debede7951c2acb37": {
|
||||
"name": "SNT",
|
||||
"address": "0x195fcB5B1D04E58C90813a5d67a5Ab84Bc4D85e5"
|
||||
},
|
||||
"0x2b62fb48a19b53e76d5137574f996db9188d511227d1971c3997820ecdbe9d04": {
|
||||
"name": "Meritocracy",
|
||||
"address": "0x9c888ff4D7d4F512C79073ad5016116327fD8315"
|
||||
}
|
||||
}
|
||||
},
|
||||
"0xed91b3f34bf33b1fd575587cbdf56f3cf146d6d01942680ec63207f3de1fb8ba": {
|
||||
"contracts": {
|
||||
"0xe5413cb03538126884d14df481da47efdeba969bd6c7e3609abaf1dc42973b1a": {
|
||||
"name": "MiniMeTokenFactory",
|
||||
"address": "0x7078E9E73FeFf15eC5C4C58233adc19447719979"
|
||||
},
|
||||
"0x1dc86cbe444c7243c6565fc68d02a9a0623e97a7d9470f1debede7951c2acb37": {
|
||||
"name": "SNT",
|
||||
"address": "0x195fcB5B1D04E58C90813a5d67a5Ab84Bc4D85e5"
|
||||
},
|
||||
"0x2b62fb48a19b53e76d5137574f996db9188d511227d1971c3997820ecdbe9d04": {
|
||||
"name": "Meritocracy",
|
||||
"address": "0x9c888ff4D7d4F512C79073ad5016116327fD8315"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ contract Meritocracy {
|
|||
mapping(address => bool) public admins;
|
||||
mapping(address => Contributor) public contributors;
|
||||
|
||||
// Modifiers -------------------------------------------------------------------------------------------------
|
||||
// Modifiers --------------------------------------------------------------------------------------------
|
||||
|
||||
// Functions only Owner can call
|
||||
modifier onlyOwner() {
|
||||
|
@ -62,7 +62,7 @@ contract Meritocracy {
|
|||
_;
|
||||
}
|
||||
|
||||
// Open Functions ----------------------------------------------------------------------------------------
|
||||
// Open Functions --------------------------------------------------------------------------------------
|
||||
|
||||
// Split amount over each contributor in registry, any contributor can allocate? TODO maybe relax this restriction, so anyone can allocate tokens
|
||||
function allocate(uint256 _amount) external {
|
||||
|
@ -85,7 +85,7 @@ contract Meritocracy {
|
|||
return registry.length;
|
||||
}
|
||||
|
||||
// Contributor Functions -------------------------------------------------------------------------------
|
||||
// Contributor Functions --------------------------------------------------------------------------------
|
||||
|
||||
// Allows a contributor to withdraw their received Token, when their allocation is 0
|
||||
function withdraw() external {
|
||||
|
@ -143,10 +143,12 @@ contract Meritocracy {
|
|||
|
||||
// Add Multiple Contributors to the Registry in one tx
|
||||
function addContributors(address[] calldata _newContributors ) external onlyAdmin() {
|
||||
// Locals
|
||||
uint256 newContributorLength = _newContributors.length;
|
||||
// Requirements
|
||||
require(registry.length + _newContributors.length <= maxContributors); // Don't go out of bounds
|
||||
require(registry.length + newContributorLength <= maxContributors); // Don't go out of bounds
|
||||
// Body
|
||||
for (uint256 i = 0; i < _newContributors.length; i++) {
|
||||
for (uint256 i = 0; i < newContributorLength; i++) {
|
||||
addContributor(_newContributors[i]);
|
||||
}
|
||||
}
|
||||
|
@ -155,20 +157,14 @@ contract Meritocracy {
|
|||
// Note: Should not be easy to remove multiple contributors in one tx
|
||||
// WARN: Changed to idx, client can do loop by enumerating registry
|
||||
function removeContributor(uint256 idx) external onlyAdmin() { // address _contributor
|
||||
// Locals
|
||||
uint256 registryLen = registry.length - 1;
|
||||
// Requirements
|
||||
require(idx < registry.length - 1); // idx needs to be smaller than registry.length - 1 OR maxContributors
|
||||
require(idx < registryLen); // idx needs to be smaller than registry.length - 1 OR maxContributors
|
||||
// Body
|
||||
// Find id of contributor address
|
||||
// uint256 idx = 0;
|
||||
// for (uint256 i = 0; i < registry.length; i++) { // should never be longer than maxContributors, see addContributor
|
||||
// if (registry[i] == _contributor) {
|
||||
// idx = i;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
address c = registry[idx];
|
||||
// Swap & Pop!
|
||||
registry[idx] = registry[registry.length - 1];
|
||||
registry[idx] = registry[registryLen];
|
||||
registry.pop();
|
||||
delete contributors[c]; // TODO check if this works
|
||||
}
|
||||
|
@ -182,11 +178,13 @@ contract Meritocracy {
|
|||
|
||||
// Zero-out allocations for contributors, minimum once a week, if allocation still exists, add to burn
|
||||
function forfeitAllocations() public onlyAdmin() {
|
||||
// Locals
|
||||
uint256 registryLen = registry.length;
|
||||
// Requirements
|
||||
require(block.timestamp >= lastForfeit + 1 weeks); // prevents multiple admins accidently calling too quickly.
|
||||
// Body
|
||||
lastForfeit = block.timestamp;
|
||||
|
||||
for (uint256 i = 0; i < registry.length; i++) { // should never be longer than maxContributors, see addContributor
|
||||
for (uint256 i = 0; i < registryLen; i++) { // should never be longer than maxContributors, see addContributor
|
||||
Contributor storage c = contributors[registry[i]];
|
||||
c.totalForfeited += c.allocation; // Shaaaaame!
|
||||
c.allocation = 0;
|
||||
|
@ -247,7 +245,9 @@ contract Meritocracy {
|
|||
escape();
|
||||
}
|
||||
|
||||
// Set Token address and initial maxContributors
|
||||
// Constructor ------------------------------------------------------------------------------------------
|
||||
|
||||
// Set Owner, Token address and initial maxContributors
|
||||
constructor(address _token, uint256 _maxContributors) public {
|
||||
// Body
|
||||
owner = msg.sender;
|
||||
|
|
Loading…
Reference in New Issue