Skip to content

Commit e66b737

Browse files
committed
Merge branch 'main' into merging-with-main
2 parents 1b05137 + e27aafa commit e66b737

File tree

6 files changed

+172
-46
lines changed

6 files changed

+172
-46
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Screenshots**
24+
If applicable, add screenshots to help explain your problem.
25+
26+
**Desktop (please complete the following information):**
27+
- OS: [e.g. iOS]
28+
- Browser [e.g. chrome, safari]
29+
- Version [e.g. 22]
30+
31+
**Smartphone (please complete the following information):**
32+
- Device: [e.g. iPhone6]
33+
- OS: [e.g. iOS8.1]
34+
- Browser [e.g. stock browser, safari]
35+
- Version [e.g. 22]
36+
37+
**Additional context**
38+
Add any other context about the problem here.

.github/ISSUE_TEMPLATE/custom.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
name: Custom issue template
3+
about: Describe this issue template's purpose here.
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

darc-protocol/contracts/protocol/DARC.sol

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ contract DARC is Runtime, Dashboard {
2323
function entrance(Program memory program) public payable returns (string memory) {
2424
require(program.programOperatorAddress == msg.sender,
2525
string.concat(string.concat("Invalid program address. Msg.sender: ", StringUtils.toAsciiString(msg.sender)), string.concat(", and program operator address: ", StringUtils.toAsciiString(program.programOperatorAddress))));
26-
for (uint256 opIdx = 0; opIdx < program.operations.length; opIdx++) {
26+
for (uint256 opIdx; opIdx < program.operations.length;) {
2727
require(program.operations[opIdx].operatorAddress == msg.sender,
2828
string.concat(string.concat("Invalid program address. Msg.sender: ", StringUtils.toAsciiString(msg.sender)), string.concat(", and program operator address: ", StringUtils.toAsciiString(program.operations[opIdx].operatorAddress))));
29+
unchecked {
30+
++opIdx;
31+
}
2932
}
3033
return runtimeEntrance(program);
3134
}
@@ -44,8 +47,8 @@ contract DARC is Runtime, Dashboard {
4447
require(amount <= currentMachineState.withdrawableCashMap[msg.sender], string.concat("Invalid withdraw amount. Amount: ", Strings.toString(amount), ", and withdrawable cash: ", Strings.toString(currentMachineState.withdrawableCashMap[msg.sender])));
4548

4649
// first update the withdrawable cash map
47-
bool bIsValid = false;
48-
uint256 result = 0;
50+
bool bIsValid;
51+
uint256 result;
4952
(bIsValid, result) = SafeMathUpgradeable.trySub(currentMachineState.withdrawableCashMap[msg.sender], amount);
5053
require(bIsValid, string.concat("Invalid withdraw amount. Amount: ", Strings.toString(amount), ", and withdrawable cash: ", Strings.toString(currentMachineState.withdrawableCashMap[msg.sender])));
5154

@@ -54,18 +57,25 @@ contract DARC is Runtime, Dashboard {
5457
// if the message sender owns zero withdrawable cash balance, then remove it from the withdrawable cash owner list
5558
if (currentMachineState.withdrawableCashMap[msg.sender] == 0) {
5659
address[] memory newWithdrawableCashOwnerList = new address[](currentMachineState.withdrawableCashOwnerList.length);
57-
uint256 pt = 0;
58-
for (uint256 index = 0; index < currentMachineState.withdrawableCashOwnerList.length; index++) {
60+
uint256 pt;
61+
for (uint256 index; index < currentMachineState.withdrawableCashOwnerList.length;) {
5962
if (currentMachineState.withdrawableCashOwnerList[index] != msg.sender) {
6063
newWithdrawableCashOwnerList[pt] = currentMachineState.withdrawableCashOwnerList[index];
6164
pt++;
6265
}
66+
67+
unchecked {
68+
++index;
69+
}
6370
}
6471

6572
// update the withdrawable cash owner list
6673
currentMachineState.withdrawableCashOwnerList = new address[](pt);
67-
for (uint256 index = 0; index < pt; index++) {
74+
for (uint256 index; index < pt;) {
6875
currentMachineState.withdrawableCashOwnerList[index] = newWithdrawableCashOwnerList[index];
76+
unchecked {
77+
++index;
78+
}
6979
}
7080
}
7181

@@ -74,7 +84,7 @@ contract DARC is Runtime, Dashboard {
7484
}
7585

7686
/**
77-
* This is the only way to withdraw dividens from the DARC virtual machine
87+
* This is the only way to withdraw dividends from the DARC virtual machine
7888
* @param amount The amount of cash to be withdrawn
7989
*/
8090
function withdrawDividends(uint256 amount) public {
@@ -86,8 +96,8 @@ contract DARC is Runtime, Dashboard {
8696
require(amount <= currentMachineState.withdrawableDividendMap[msg.sender], string.concat("Invalid withdraw amount. Amount: ", Strings.toString(amount), ", and withdrawable dividends: ", Strings.toString(currentMachineState.withdrawableDividendMap[msg.sender])));
8797

8898
// first update the withdrawable cash map
89-
bool bIsValid = false;
90-
uint256 result = 0;
99+
bool bIsValid;
100+
uint256 result;
91101
(bIsValid, result) = SafeMathUpgradeable.trySub(currentMachineState.withdrawableDividendMap[msg.sender], amount);
92102
require(bIsValid, string.concat("Invalid withdraw amount. Amount: ", Strings.toString(amount), ", and withdrawable dividends: ", Strings.toString(currentMachineState.withdrawableDividendMap[msg.sender])));
93103

@@ -100,20 +110,27 @@ contract DARC is Runtime, Dashboard {
100110
// if the message sender owns zero withdrawable dividend balance, then remove it from the withdrawable dividend owner list
101111
if (currentMachineState.withdrawableDividendMap[msg.sender] == 0) {
102112
address[] memory newWithdrawableDividendsOwnerList = new address[](currentMachineState.withdrawableDividendOwnerList.length);
103-
uint256 pt = 0;
104-
for (uint256 index = 0; index < currentMachineState.withdrawableDividendOwnerList.length; index++) {
113+
uint256 pt;
114+
for (uint256 index; index < currentMachineState.withdrawableDividendOwnerList.length;) {
105115
if (currentMachineState.withdrawableDividendOwnerList[index] != msg.sender) {
106116
newWithdrawableDividendsOwnerList[pt] = currentMachineState.withdrawableDividendOwnerList[index];
107117
pt++;
108118
}
119+
120+
unchecked {
121+
++index;
122+
}
109123
}
110124

111125
// update the withdrawable cash owner list
112126
currentMachineState.withdrawableDividendOwnerList = new address[](pt);
113-
for (uint256 index = 0; index < pt; index++) {
127+
for (uint256 index; index < pt;) {
114128
currentMachineState.withdrawableDividendOwnerList[index] = newWithdrawableDividendsOwnerList[index];
129+
unchecked {
130+
++index;
131+
}
115132
}
116133
}
117134

118135
}
119-
}
136+
}

darc-protocol/contracts/protocol/Dashboard/Dashboard.sol

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import "../Runtime/Runtime.sol";
88
* @author DARC Team
99
* @notice The dashboard (a set of view functions) of the DARC machine state,
1010
* which is used to read the machine state, including machine state, voting state,
11-
* token informatin, plugin information, etc.
11+
* token information, plugin information, etc.
1212
*/
1313
contract Dashboard is MachineStateManager {
1414

@@ -20,14 +20,18 @@ contract Dashboard is MachineStateManager {
2020
}
2121

2222
/**
23-
* @notice Get the avaiilable token classes
23+
* @notice Get the available token classes
2424
*/
2525
function getNumberOfTokenClasses() public view returns (uint256) {
26-
uint256 i = 0;
27-
for (; i < currentMachineState.tokenList.length; i++) {
26+
uint256 i;
27+
for (; i < currentMachineState.tokenList.length;) {
2828
if (!currentMachineState.tokenList[i].bIsInitialized) {
2929
break;
3030
}
31+
32+
unchecked {
33+
++i;
34+
}
3135
}
3236
return i;
3337
}

0 commit comments

Comments
 (0)