Skip to content

Commit 1c272f3

Browse files
committed
Refactor SmartnodesToken to SmartnodesERC20
1 parent 4ad8007 commit 1c272f3

File tree

11 files changed

+227
-47
lines changed

11 files changed

+227
-47
lines changed

.DS_Store

0 Bytes
Binary file not shown.

script/Deploy.s.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pragma solidity ^0.8.22;
33

44
import {Script, console} from "forge-std/Script.sol";
55
import {SmartnodesCore} from "../src/SmartnodesCore.sol";
6-
import {SmartnodesToken} from "../src/SmartnodesToken.sol";
6+
import {SmartnodesERC20} from "../src/SmartnodesERC20.sol";
77
import {SmartnodesCoordinator} from "../src/SmartnodesCoordinator.sol";
88
import {SmartnodesDAO} from "../src/SmartnodesDAO.sol";
99

@@ -21,7 +21,7 @@ contract Deploy is Script {
2121

2222
vm.startBroadcast();
2323

24-
SmartnodesToken token = new SmartnodesToken(
24+
SmartnodesERC20 token = new SmartnodesERC20(
2525
DEPLOYMENT_MULTIPLIER,
2626
genesis
2727
);

src/SmartnodesCoordinator.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pragma solidity ^0.8.22;
33

44
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
55
import {ISmartnodesCore} from "./interfaces/ISmartnodesCore.sol";
6-
import {ISmartnodesToken} from "./interfaces/ISmartnodesToken.sol";
6+
import {ISmartnodesERC20} from "./interfaces/ISmartnodesERC20.sol";
77

88
/**
99
* @title SmartnodesCoordinator
@@ -31,7 +31,7 @@ contract SmartnodesCoordinator is ReentrancyGuard {
3131

3232
// ============= State Variables ==============
3333
ISmartnodesCore private immutable i_smartnodesCore;
34-
ISmartnodesToken private immutable i_smartnodesToken;
34+
ISmartnodesERC20 private immutable i_smartnodesToken;
3535
uint8 private immutable i_requiredApprovalsPercentage;
3636

3737
// Packed time-related variables
@@ -134,7 +134,7 @@ contract SmartnodesCoordinator is ReentrancyGuard {
134134
}
135135

136136
i_smartnodesCore = ISmartnodesCore(_smartnodesCore);
137-
i_smartnodesToken = ISmartnodesToken(_smartnodesToken);
137+
i_smartnodesToken = ISmartnodesERC20(_smartnodesToken);
138138
i_requiredApprovalsPercentage = _requiredApprovalsPercentage;
139139

140140
timeConfig = TimeConfig({

src/SmartnodesCore.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.22;
33

44
import {ISmartnodesCoordinator} from "./interfaces/ISmartnodesCoordinator.sol";
5-
import {ISmartnodesToken, PaymentAmounts} from "./interfaces/ISmartnodesToken.sol";
5+
import {ISmartnodesERC20, PaymentAmounts} from "./interfaces/ISmartnodesERC20.sol";
66

77
/**
88
* @title SmartnodesCore - Job Management System for Secure, Incentivised, Multi-Network P2P Resource Sharing
@@ -55,7 +55,7 @@ contract SmartnodesCore {
5555
/** Constants */
5656
uint24 private constant UNLOCK_PERIOD = 14 days;
5757

58-
ISmartnodesToken private immutable i_tokenContract;
58+
ISmartnodesERC20 private immutable i_tokenContract;
5959

6060
/** State Variables */
6161
ISmartnodesCoordinator private validatorContract;
@@ -83,7 +83,7 @@ contract SmartnodesCore {
8383
}
8484

8585
constructor(address _tokenContract) {
86-
i_tokenContract = ISmartnodesToken(_tokenContract);
86+
i_tokenContract = ISmartnodesERC20(_tokenContract);
8787
jobCounter = 0;
8888
}
8989

src/SmartnodesDAO.sol

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ contract SmartnodesDAO is ReentrancyGuard {
6767
bool queued;
6868
address[] targets;
6969
bytes[] calldatas;
70+
uint256[] values;
7071
string description;
7172
}
7273

@@ -137,6 +138,7 @@ contract SmartnodesDAO is ReentrancyGuard {
137138
function propose(
138139
address[] calldata targets,
139140
bytes[] calldata calldatas,
141+
uint256[] calldata values,
140142
string calldata description
141143
) external returns (uint256) {
142144
uint256 targetsLength = targets.length;
@@ -168,13 +170,9 @@ contract SmartnodesDAO is ReentrancyGuard {
168170
p.startTime = uint128(block.timestamp);
169171
p.endTime = uint128(block.timestamp + votingPeriod);
170172

171-
// Copy arrays
172-
p.targets = new address[](targetsLength);
173-
p.calldatas = new bytes[](targetsLength);
174-
for (uint256 i = 0; i < targetsLength; ++i) {
175-
p.targets[i] = targets[i];
176-
p.calldatas[i] = calldatas[i];
177-
}
173+
p.targets = targets;
174+
p.calldatas = calldatas;
175+
p.values = values;
178176
p.description = description;
179177

180178
emit ProposalCreated(
@@ -269,9 +267,10 @@ contract SmartnodesDAO is ReentrancyGuard {
269267
// Execute all calls
270268
uint256 targetsLength = p.targets.length;
271269
for (uint256 i = 0; i < targetsLength; ++i) {
272-
(bool success, bytes memory returnData) = p.targets[i].call(
273-
p.calldatas[i]
274-
);
270+
(bool success, bytes memory returnData) = p.targets[i].call{
271+
value: p.values[i]
272+
}(p.calldatas[i]);
273+
275274
if (!success) {
276275
// Handle revert reason
277276
if (returnData.length > 0) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol
1919
* @dev Uses simple DAO-based access control system to control staking requirements and upgrades
2020
* @dev to SmartnodesCore and SmartnodesCoordinator.
2121
*/
22-
contract SmartnodesToken is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
22+
contract SmartnodesERC20 is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
2323
/** Errors */
2424
error Token__InsufficientBalance();
2525
error Token__InvalidAddress();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ struct PaymentAmounts {
77
}
88

99
/**
10-
* @title ISmartnodesToken Interface
10+
* @title ISmartnodesERC20 Interface
1111
* @dev Interface for the SmartnodesToken contract
1212
*/
13-
interface ISmartnodesToken {
13+
interface ISmartnodesERC20 {
1414
function setValidatorLockAmount(uint256 _newAmount) external;
1515

1616
function setUserLockAmount(uint256 _newAmount) external;

test/BaseTest.sol

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.22;
33

44
import {Test, console} from "forge-std/Test.sol";
5-
import {SmartnodesToken} from "../src/SmartnodesToken.sol";
5+
import {SmartnodesERC20} from "../src/SmartnodesERC20.sol";
66
import {SmartnodesCore} from "../src/SmartnodesCore.sol";
77
import {SmartnodesCoordinator} from "../src/SmartnodesCoordinator.sol";
88
import {SmartnodesDAO} from "../src/SmartnodesDAO.sol";
@@ -34,7 +34,7 @@ abstract contract BaseSmartnodesTest is Test {
3434
}
3535

3636
// Contract instances
37-
SmartnodesToken public token;
37+
SmartnodesERC20 public token;
3838
SmartnodesCore public core;
3939
SmartnodesCoordinator public coordinator;
4040
SmartnodesDAO public dao;
@@ -80,7 +80,7 @@ abstract contract BaseSmartnodesTest is Test {
8080
// genesisNodes.push(worker2);
8181
// genesisNodes.push(worker3);
8282

83-
token = new SmartnodesToken(DEPLOYMENT_MULTIPLIER, genesisNodes);
83+
token = new SmartnodesERC20(DEPLOYMENT_MULTIPLIER, genesisNodes);
8484
dao = new SmartnodesDAO(address(token), DAO_VOTING_PERIOD, 500);
8585
core = new SmartnodesCore(address(token));
8686

@@ -123,9 +123,10 @@ abstract contract BaseSmartnodesTest is Test {
123123
function createDAOProposal(
124124
address[] memory targets,
125125
bytes[] memory calldatas,
126+
uint256[] memory values,
126127
string memory description
127128
) internal returns (uint256 proposalId) {
128-
proposalId = dao.propose(targets, calldatas, description);
129+
proposalId = dao.propose(targets, calldatas, values, description);
129130
}
130131

131132
// Helper function to vote on DAO proposals in tests

test/CoordinatorTest.t.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pragma solidity ^0.8.22;
33

44
import {Test, console} from "forge-std/Test.sol";
55
import {SmartnodesCoordinator} from "../src/SmartnodesCoordinator.sol";
6-
import {SmartnodesToken} from "../src/SmartnodesToken.sol";
6+
import {SmartnodesERC20} from "../src/SmartnodesERC20.sol";
77
import {BaseSmartnodesTest} from "./BaseTest.sol";
88

99
/**
@@ -90,7 +90,7 @@ contract SmartnodesCoordinatorTest is BaseSmartnodesTest {
9090

9191
(
9292
bytes32 storedRoot,
93-
SmartnodesToken.PaymentAmounts memory workerReward,
93+
SmartnodesERC20.PaymentAmounts memory workerReward,
9494
uint256 storedCapacity,
9595
bool active,
9696
uint256 timestamp
@@ -192,7 +192,7 @@ contract SmartnodesCoordinatorTest is BaseSmartnodesTest {
192192

193193
(
194194
bytes32 storedRoot,
195-
SmartnodesToken.PaymentAmounts memory workerReward,
195+
SmartnodesERC20.PaymentAmounts memory workerReward,
196196
uint256 storedCapacity,
197197
bool active,
198198
uint256 timestamp

0 commit comments

Comments
 (0)