Skip to content

Commit 824fd2d

Browse files
committed
Fixed supply calculation bug. Adjusted state time for testnet v2.
1 parent 81f4bb2 commit 824fd2d

File tree

3 files changed

+98
-3
lines changed

3 files changed

+98
-3
lines changed

script/Deploy.s.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {TimelockController} from "@openzeppelin/contracts/governance/TimelockCon
1010

1111
// DAO Configuration
1212
uint256 constant TIMELOCK_DELAY = 2 days;
13-
uint128 constant BASE_UPDATE_TIME = uint128(8 hours);
13+
uint128 constant BASE_UPDATE_TIME = uint128(24 hours);
1414
uint8 constant PROPOSAL_THRESHOLD_PERCENTAGE = 66;
1515

1616
contract Deploy is Script {
@@ -20,6 +20,7 @@ contract Deploy is Script {
2020
function run() external {
2121
genesis.push(msg.sender);
2222
genesis.push(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266);
23+
genesis.push(0x25Fde2567cbC578e7739faD0499eD7d5056572Dd);
2324
address[] memory proposers = new address[](0);
2425
address[] memory executors = new address[](0);
2526

src/SmartnodesERC20.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ contract SmartnodesERC20 is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
206206
// Mint initial tokens to genesis nodes
207207
uint256 gensisNodesLength = _genesisNodes.length;
208208
for (uint256 i = 0; i < gensisNodesLength; i++) {
209-
_mint(_genesisNodes[i], (s_validatorLockAmount * 3));
209+
_mint(_genesisNodes[i], (s_validatorLockAmount) * 2);
210210
}
211211
}
212212

@@ -1005,9 +1005,13 @@ contract SmartnodesERC20 is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
10051005
uint256 total = totalSupply();
10061006
uint256 reward = getEmissionRate();
10071007

1008+
// Circulating = minted tokens minus locked and escrowed
1009+
// (unclaimed rewards aren't minted yet, so they don't reduce circulation)
1010+
uint256 circulating = total - s_totalLocked - s_totalEscrowed.sno;
1011+
10081012
return (
10091013
total,
1010-
total - s_totalLocked - s_totalUnclaimed.sno - s_totalEscrowed.sno,
1014+
circulating,
10111015
s_totalLocked,
10121016
s_totalUnclaimed.sno,
10131017
s_totalEscrowed.sno,

test/TokenTest.t.sol

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,4 +993,94 @@ contract SmartnodesTokenTest is BaseSmartnodesTest {
993993
vm.prank(address(core));
994994
token.escrowPayment(user1, largeAmount);
995995
}
996+
997+
/**
998+
* @notice Simulate 100 reward distribution periods and claim all 100 rewards
999+
*/
1000+
function testSimulate100RewardPeriodsAndClaim() public {
1001+
console.log(
1002+
"=== Simulating 100 reward periods and claiming in batches of 100 ==="
1003+
);
1004+
1005+
uint256 NUM_PERIODS = 100;
1006+
uint256 BATCH_SIZE = 100;
1007+
_setupContractFunding();
1008+
1009+
// fund contract for ETH side of rewards
1010+
vm.deal(address(core), ADDITIONAL_ETH_PAYMENT * NUM_PERIODS);
1011+
vm.prank(address(core));
1012+
(bool sent, ) = address(token).call{
1013+
value: ADDITIONAL_ETH_PAYMENT * NUM_PERIODS
1014+
}("");
1015+
require(sent, "funding failed");
1016+
1017+
// pick one worker to repeatedly claim rewards
1018+
Participant[] memory initialWorkers;
1019+
uint256 dummyTotalCapacity;
1020+
(initialWorkers, dummyTotalCapacity) = _setupTestParticipants(5, false);
1021+
1022+
address worker = initialWorkers[0].addr;
1023+
uint256 workerIndex = 0;
1024+
1025+
uint256[] memory distributionIds = new uint256[](NUM_PERIODS);
1026+
uint256[] memory capacities = new uint256[](NUM_PERIODS);
1027+
bytes32[][] memory proofs = new bytes32[][](NUM_PERIODS);
1028+
1029+
// ----- CREATE 10,000 MERKLE DISTRIBUTIONS -----
1030+
for (uint256 i = 0; i < NUM_PERIODS; i++) {
1031+
Participant[] memory participants;
1032+
uint256 totalCapacity;
1033+
1034+
(participants, totalCapacity) = _setupTestParticipants(5, false);
1035+
1036+
require(workerIndex < participants.length, "invalid worker index");
1037+
capacities[i] = participants[workerIndex].capacity;
1038+
1039+
bytes32[] memory leaves = _generateLeaves(
1040+
participants,
1041+
token.s_currentDistributionId() + 1
1042+
);
1043+
proofs[i] = _generateMerkleProof(leaves, workerIndex);
1044+
1045+
vm.warp(block.timestamp + UPDATE_TIME);
1046+
1047+
(uint256 distributionId, ) = _createAndValidateDistribution(
1048+
participants,
1049+
totalCapacity
1050+
);
1051+
1052+
distributionIds[i] = distributionId;
1053+
}
1054+
1055+
uint256 preBal = token.balanceOf(worker);
1056+
uint256 preEth = worker.balance;
1057+
1058+
// ----- CLAIM IN BATCHES OF 100 -----
1059+
vm.startPrank(worker);
1060+
1061+
for (uint256 i = 0; i < NUM_PERIODS; i += BATCH_SIZE) {
1062+
uint256 end = i + BATCH_SIZE;
1063+
if (end > NUM_PERIODS) end = NUM_PERIODS;
1064+
1065+
for (uint256 j = i; j < end; j++) {
1066+
token.claimMerkleRewards(
1067+
distributionIds[j],
1068+
capacities[j],
1069+
proofs[j]
1070+
);
1071+
}
1072+
}
1073+
1074+
vm.stopPrank();
1075+
1076+
uint256 postBal = token.balanceOf(worker);
1077+
uint256 postEth = worker.balance;
1078+
1079+
assertTrue(postBal > preBal, "worker SNO rewards should increase");
1080+
assertTrue(postEth > preEth, "worker ETH rewards should increase");
1081+
1082+
console.log(
1083+
"Successfully created and claimed 10,000 reward periods in batches of 100!"
1084+
);
1085+
}
9961086
}

0 commit comments

Comments
 (0)