Skip to content

Commit

Permalink
Merge pull request #85 from lidangzzz/main
Browse files Browse the repository at this point in the history
Implementation of voting protocol
  • Loading branch information
lidangzzz authored Jan 16, 2024
2 parents e66b737 + 5cfe9e5 commit ca3a449
Show file tree
Hide file tree
Showing 33 changed files with 2,449 additions and 240 deletions.
2 changes: 1 addition & 1 deletion darc-docs/docs/DARC Protocol/OpCodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ By defining these operations through opcodes, the DARC protocol ensures consiste
| BATCH_BURN_TOKENS_AND_REFUND | 30 | `tokenClassArray`: uint256[] <br/> | Batch Burn Tokens and Refund |
| ADD_STORAGE_IPFS_HASH | 31 | `address`: string[] | Add Storage IPFS Hash |
| VOTE | 32 | `voteArray`: bool[] | Vote for a Voting Pending Program |
| EXECUTE_PROGRAM | 33 | N/A | Execute a Program that has been Voted and Approved |
| EXECUTE_PENDING_PROGRAM | 33 | N/A | Execute a Program that has been Voted and Approved |



6 changes: 3 additions & 3 deletions darc-js/src/darcBinary/DARC-latest.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
},
{
"internalType": "bool",
"name": "isEnabled",
"name": "bIsEnabled",
"type": "bool"
},
{
Expand Down Expand Up @@ -866,7 +866,7 @@
},
{
"internalType": "bool",
"name": "isEnabled",
"name": "bIsEnabled",
"type": "bool"
},
{
Expand Down Expand Up @@ -1140,7 +1140,7 @@
},
{
"internalType": "bool",
"name": "isEnabled",
"name": "bIsEnabled",
"type": "bool"
},
{
Expand Down
6 changes: 3 additions & 3 deletions darc-js/src/darcBinary/DARC-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
},
{
"internalType": "bool",
"name": "isEnabled",
"name": "bIsEnabled",
"type": "bool"
},
{
Expand Down Expand Up @@ -911,7 +911,7 @@
},
{
"internalType": "bool",
"name": "isEnabled",
"name": "bIsEnabled",
"type": "bool"
},
{
Expand Down Expand Up @@ -1200,7 +1200,7 @@
},
{
"internalType": "bool",
"name": "isEnabled",
"name": "bIsEnabled",
"type": "bool"
},
{
Expand Down
4 changes: 2 additions & 2 deletions darc-js/src/types/basicTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type VotingRuleStruct = {
approvalThresholdPercentage: PromiseOrValue<BigNumberish>;
votingDurationInSeconds: PromiseOrValue<BigNumberish>;
executionPendingDurationInSeconds: PromiseOrValue<BigNumberish>;
isEnabled: PromiseOrValue<boolean>;
bIsEnabled: PromiseOrValue<boolean>;
notes: PromiseOrValue<string>;
bIsAbsoluteMajority: PromiseOrValue<boolean>;
};
Expand All @@ -38,7 +38,7 @@ export type VotingRuleStructOutput = [
approvalThresholdPercentage: BigNumber;
votingDurationInSeconds: BigNumber;
executionPendingDurationInSeconds: BigNumber;
isEnabled: boolean;
bIsEnabled: boolean;
notes: string;
bIsAbsoluteMajority: boolean;
};
Expand Down
22 changes: 20 additions & 2 deletions darc-protocol/contracts/protocol/Dashboard/Dashboard.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.19;

import "../Runtime/Runtime.sol";
import "../Runtime/Executable/Executable.sol";

/**
* @title DARC Dashboard
Expand All @@ -10,7 +10,7 @@ import "../Runtime/Runtime.sol";
* which is used to read the machine state, including machine state, voting state,
* token information, plugin information, etc.
*/
contract Dashboard is MachineStateManager {
contract Dashboard is Executable {

/**
* @notice The getter function of the machine state plugins
Expand Down Expand Up @@ -131,4 +131,22 @@ contract Dashboard is MachineStateManager {
function getCurrentDividendPerUnit() public view returns (uint256) {
return currentDividendPerUnit(false);
}

/**
* Get all logs of DARC
*/
function getDARClogs() public view returns (string[] memory) {
return DARClogs;
}

/**
* Get all voting items
*/
function getVotingItemsByIndex(uint256 idx) public view returns (VotingItem memory) {
return votingItems[idx];
}

function getLatestVotingItemIndex() public view returns (uint256) {
return latestVotingItemIndex;
}
}
2 changes: 1 addition & 1 deletion darc-protocol/contracts/protocol/MachineState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct MachineState {
* The balance sheet and information of each token class
* TODO: make the length of the tokenList dynamic (not fixed to 10000)
*/
Token[10000] tokenList;
Token[100] tokenList;

/**
* The member list and internal role index number of each token owner,
Expand Down
10 changes: 8 additions & 2 deletions darc-protocol/contracts/protocol/MachineStateManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ enum FiniteState {
EXECUTING_PENDING
}



/**
* @notice The core and base contract of DARC, the manager of the DARC machine state
* Also this contains some basic function of the DARC machine state
Expand All @@ -30,8 +32,8 @@ contract MachineStateManager {
/**
* ======== DARC Machine State ========
*/
MachineState currentMachineState;
MachineState sandboxMachineState;
MachineState public currentMachineState;
MachineState public sandboxMachineState;


/**
Expand Down Expand Up @@ -66,6 +68,10 @@ contract MachineStateManager {
*/
uint256 dividendBufferSize;

/**
* @notice The logs of the DARC machine state
*/
string[] DARClogs;



Expand Down
2 changes: 1 addition & 1 deletion darc-protocol/contracts/protocol/Opcodes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ enum EnumOpcode {
* @notice Execute a program that has been voted and approved
* ID:33
*/
EXECUTE_PROGRAM,
EXECUTE_PENDING_PROGRAM,

/**
* @notice Emergency mode termination. Emergency agents cannot do anything after this operation
Expand Down
24 changes: 23 additions & 1 deletion darc-protocol/contracts/protocol/Plugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ enum EnumLogicalOperatorType {UNDEFINED, AND, OR, NOT }
* 3. plugin Z, return type: NO, level 3
*
* Then the return type of the operation is YES_AND_SKIP_SANDBOX.
*
*
*
* ----------------------------------------------
*
* For before operation plugins, here is the rule:
* 1. If the return type is YES_AND_SKIP_SANDBOX, then all the plugin level L%3 == 1, e.g. [1, 4, 7, 10, ...]
* 2. If the return type is SANDBOX_NEEDED, then all the plugin level L%3 == 2, e.g. [2, 5, 8, 11, ...]
* 3. If the return type is NO, then all the plugin level L%3 == 0, e.g. [3, 6, 9, 12, ...]
*
*
* ----------------------------------------------
*
* For after operation plugins, here is the rule:
* 1. If the return type is YES, then all the plugin level L%3 == 1, e.g. [1, 4, 7, 10, ...]
* 2. If the return type is VOTING_NEEDED, then all the plugin level L%3 == 2, e.g. [2, 5, 8, 11, ...]
* 3. If the return type is NO, then all the plugin level L%3 == 0, e.g. [3, 6, 9, 12, ...]
*
* ----------------------------------------------
*
* If the return type is UNDEFINED, then just throw the error and revert the transaction
*
*/
enum EnumReturnType {

Expand Down Expand Up @@ -167,7 +189,7 @@ struct VotingRule {
/**
* the voting policy is enabled or not
*/
bool isEnabled;
bool bIsEnabled;

/**
* the note of the voting policy
Expand Down
Loading

0 comments on commit ca3a449

Please sign in to comment.