Skip to content

Commit 5e5aa4a

Browse files
committed
Adding DAO percentage to reward generation and fees in Token contract.
1 parent cb17627 commit 5e5aa4a

File tree

3 files changed

+18
-66
lines changed

3 files changed

+18
-66
lines changed

src/SmartnodesCoordinator.sol

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ contract SmartnodesCoordinator is ReentrancyGuard {
269269

270270
// Verify proposal data integrity
271271
bytes32 computedHash = _computeProposalHash(
272-
proposalId,
273272
merkleRoot,
274273
validatorsToRemove,
275274
jobHashes,
@@ -557,7 +556,6 @@ contract SmartnodesCoordinator is ReentrancyGuard {
557556
}
558557

559558
function _computeProposalHash(
560-
uint8 proposalId,
561559
bytes32 merkleRoot,
562560
address[] calldata validatorsToRemove,
563561
bytes32[] calldata jobHashes,
@@ -567,7 +565,6 @@ contract SmartnodesCoordinator is ReentrancyGuard {
567565
return
568566
keccak256(
569567
abi.encode(
570-
proposalId,
571568
merkleRoot,
572569
validatorsToRemove,
573570
jobHashes,

src/SmartnodesToken.sol

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ contract SmartnodesToken is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
3838
error Token__ETHTransferFailed();
3939
error Token__OnlyDAO();
4040
error Token__DAOAlreadySet();
41-
error Token__InvalidBiasValidator();
4241
error Token__DistributionTooEarly();
4342
error Token__InvalidInterval();
4443

@@ -277,50 +276,30 @@ contract SmartnodesToken is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
277276
// ============ Emissions & Halving ============
278277

279278
/**
280-
* @notice Distribute validator rewards with configurable bias validator
279+
* @notice Distribute validator rewards
281280
* @param _approvedValidators List of validators that voted
282281
* @param _validatorReward Total reward amounts for validators
283282
* @param _distributionId Current distribution ID for events
284-
* @param _biasValidator Address of validator to receive bias (replaces tx.origin)
285-
* @dev 10% of validator rewards go to bias validator, remaining 90% split equally among all validators
286-
* @dev Bias validator receives both the bias amount and their equal share
283+
* @param _dustValidator Validator that gets the scraps (proposal creator)
287284
*/
288285
function _distributeValidatorRewards(
289286
address[] memory _approvedValidators,
290287
PaymentAmounts memory _validatorReward,
291288
uint256 _distributionId,
292-
address _biasValidator
289+
address _dustValidator
293290
) internal {
294291
uint8 _nValidators = uint8(_approvedValidators.length);
295292

296-
// Validate bias validator is in the approved list
297-
bool biasValidatorFound = false;
298-
for (uint256 i = 0; i < _nValidators; i++) {
299-
if (_approvedValidators[i] == _biasValidator) {
300-
biasValidatorFound = true;
301-
break;
302-
}
303-
}
304-
if (!biasValidatorFound) revert Token__InvalidBiasValidator();
305-
306-
// Calculate bias amount (10% of total validator reward goes to bias validator)
307-
uint256 snoBiasAmount = (uint256(_validatorReward.sno) * 10) / 100;
308-
uint256 ethBiasAmount = (uint256(_validatorReward.eth) * 10) / 100;
309-
310-
// Remaining 90% to be split equally among all validators
311-
uint256 snoRemainingPool = uint256(_validatorReward.sno) -
312-
snoBiasAmount;
313-
uint256 ethRemainingPool = uint256(_validatorReward.eth) -
314-
ethBiasAmount;
293+
// Remaining pool to be split equally among validators
294+
uint256 snoPool = uint256(_validatorReward.sno);
295+
uint256 ethPool = uint256(_validatorReward.eth);
315296

316-
uint256 snoPerValidator = snoRemainingPool / _nValidators;
317-
uint256 ethPerValidator = ethRemainingPool / _nValidators;
297+
uint256 snoPerValidator = snoPool / _nValidators;
298+
uint256 ethPerValidator = ethPool / _nValidators;
318299

319300
// Handle dust/remainder
320-
uint256 snoRemainder = snoRemainingPool -
321-
(snoPerValidator * _nValidators);
322-
uint256 ethRemainder = ethRemainingPool -
323-
(ethPerValidator * _nValidators);
301+
uint256 snoRemainder = snoPool - (snoPerValidator * _nValidators);
302+
uint256 ethRemainder = ethPool - (ethPerValidator * _nValidators);
324303

325304
// Distribute to validators
326305
for (uint256 i = 0; i < _nValidators; i++) {
@@ -330,14 +309,8 @@ contract SmartnodesToken is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
330309
uint256 snoShare = snoPerValidator;
331310
uint256 ethShare = ethPerValidator;
332311

333-
// Bias validator gets the bias amount
334-
if (validator == _biasValidator) {
335-
snoShare += snoBiasAmount;
336-
ethShare += ethBiasAmount;
337-
}
338-
339-
// First validator gets remainder to avoid dust
340-
if (i == 0) {
312+
// Give dust to first validator to avoid lost remainder
313+
if (_dustValidator == validator) {
341314
snoShare += snoRemainder;
342315
ethShare += ethRemainder;
343316
}
@@ -388,7 +361,7 @@ contract SmartnodesToken is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
388361
* @param _totalCapacity Total capacity of contributed workers
389362
* @param _payments Additional payments to be added to the current emission rate
390363
* @param _approvedValidators List of validators that voted
391-
* @param _biasValidator Address of validator to receive bias rewards
364+
* @param _dustValidator Address of validator to receive dust rewards (usually the proposal executor)
392365
* @dev Workers receive 90% of the total reward, validators receive 10%
393366
* @dev Rewards are distributed with bias towards specified validator, then proportionally to workers based on their capacities
394367
* @dev This function is called by SmartnodesCore during state updates to distribute rewards.
@@ -398,11 +371,10 @@ contract SmartnodesToken is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
398371
uint256 _totalCapacity,
399372
address[] memory _approvedValidators,
400373
PaymentAmounts calldata _payments,
401-
address _biasValidator
374+
address _dustValidator
402375
) external onlySmartnodesCore nonReentrant {
403376
uint8 _nValidators = uint8(_approvedValidators.length);
404377
if (_nValidators == 0) revert Token__InvalidValidatorLength();
405-
if (_biasValidator == address(0)) revert Token__InvalidBiasValidator();
406378

407379
// Total rewards to be distributed
408380
PaymentAmounts memory totalReward = PaymentAmounts({
@@ -423,7 +395,7 @@ contract SmartnodesToken is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
423395
_approvedValidators,
424396
totalReward,
425397
distributionId,
426-
_biasValidator
398+
_dustValidator
427399
);
428400
return; // exit early
429401
}
@@ -469,7 +441,7 @@ contract SmartnodesToken is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
469441
_approvedValidators,
470442
validatorReward,
471443
distributionId,
472-
_biasValidator
444+
_dustValidator
473445
);
474446
}
475447

@@ -812,7 +784,7 @@ contract SmartnodesToken is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
812784
* @param _user The address of the user whose escrowed ETH payment is being released
813785
* @param _amount The amount of escrowed ETH payment to be released
814786
* @dev This releases the escrowed ETH to be available for distribution as rewards
815-
* @dev The ETH stays in the contract but is no longer considered "escrowed"
787+
* @dev The ETH stays in the contract but is no longer considered escrowed
816788
*/
817789
function releaseEscrowedEthPayment(
818790
address _user,
@@ -896,7 +868,7 @@ contract SmartnodesToken is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
896868
return address(s_smartnodesCore);
897869
}
898870

899-
// ============ ERC20Votes Overrides ============
871+
// ============ Required Overrides ============
900872

901873
/**
902874
* @dev Override to prevent voting with locked tokens
@@ -922,8 +894,6 @@ contract SmartnodesToken is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
922894
return balance;
923895
}
924896

925-
// ============ Required Overrides ============
926-
927897
/**
928898
* @dev Override required by Solidity for multiple inheritance
929899
*/

test/CoordinatorTest.t.sol

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ contract SmartnodesCoordinatorTest is BaseSmartnodesTest {
5151

5252
bytes32 proposalHash = keccak256(
5353
abi.encode(
54-
1,
5554
merkleRoot,
5655
validatorsToRemove,
5756
jobHashes,
@@ -148,7 +147,6 @@ contract SmartnodesCoordinatorTest is BaseSmartnodesTest {
148147

149148
bytes32 proposalHash = keccak256(
150149
abi.encode(
151-
1,
152150
merkleRoot,
153151
validatorsToRemove,
154152
jobHashes,
@@ -235,7 +233,6 @@ contract SmartnodesCoordinatorTest is BaseSmartnodesTest {
235233

236234
bytes32 proposalHash = keccak256(
237235
abi.encode(
238-
1,
239236
merkleRoot,
240237
validatorsToRemove,
241238
jobHashes,
@@ -282,7 +279,6 @@ contract SmartnodesCoordinatorTest is BaseSmartnodesTest {
282279

283280
bytes32 proposalHash = keccak256(
284281
abi.encode(
285-
1,
286282
merkleRoot,
287283
validatorsToRemove,
288284
jobHashes,
@@ -305,15 +301,4 @@ contract SmartnodesCoordinatorTest is BaseSmartnodesTest {
305301

306302
console.log("Voting successful. Total votes:", proposal.votes);
307303
}
308-
309-
function testCannotVoteTwice() public {
310-
(uint128 updateTime, ) = coordinator.timeConfig();
311-
vm.warp(block.timestamp + updateTime * 2);
312-
313-
uint256 numWorkers = 1;
314-
(
315-
Participant[] memory participants,
316-
uint256 totalCapacity
317-
) = _setupTestParticipants(numWorkers, false);
318-
}
319304
}

0 commit comments

Comments
 (0)