Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lidangzzz committed Dec 10, 2023
1 parent 5e24c0c commit 5bad992
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ add_and_enable_plugins( // add and enable plugins (as index 7)
condition: // define the condition:
(operation == "transfer_tokens") // if operation is transfer_tokens
& (operator_total_voting_power_percentage > 25), // and addr1's voting power > 25%
return_type: vote_needed, // return type: requires a vote
return_type: voting_needed, // return type: requires a vote
return_level: 100, // priority: 100
votingRuleIndex: 5 // voting rule index 5 (ask board of directors to vote and must 100% approve)
note: "100% Approval is needed by board members to transfer tokens by major shareholders (>25%)"
Expand All @@ -96,7 +96,7 @@ add_and_enable_plugins( // add and enable plugins (as index 7)
After above By-Law Script is executed, the DARC VM contract will add a new plugin and voting rule, and the plugin will
be effective immediately (if there exists any voting procedure related to `add_voting_rule()`
and `add_and_enable_plugins()`, the plugin will be effective after the voting process is approved). If the
operator (`addr1`) tries to transfer tokens to addr2, the plugin will check the condition and return `vote_needed` to
operator (`addr1`) tries to transfer tokens to addr2, the plugin will check the condition and return `voting_needed` to
the DARC VM contract, and the DARC VM contract will ask the board of directors (level-1 token owners) to vote. If the
board of directors approves the operation, the operation will be executed in the sandbox, otherwise the operation will
be rejected. For example, if there are 3 voting rules are triggerd, the voting operation will be:
Expand Down Expand Up @@ -320,7 +320,7 @@ const add_board_member = {
(mint_tokens_level == 2) & // the token level is 2
(mint_tokens_amount == 1) & // the amount is 1
(operator_total_voting_power_percentage >= 10), // the operator address holds at least 10% of the total voting power
return_type: vote_needed,
return_type: voting_needed,
voting_rule: 1, // Under the voting rule 1, the operation will be approved if and only if 2/3 of all the board members approve the operation
return_level: 100,
is_before_operation: false, // make the decision after executing in sandbox
Expand All @@ -337,7 +337,7 @@ const enable_plugin = {
(operator_total_voting_power_percentage >= 7) & // the operator address holds at least 7% of the total voting power
(operator_last_operation_window("enable_plugin") >= 864000), // each operator can try to enable plugins once per 864000 seconds (10 days)

return_type: vote_needed,
return_type: voting_needed,
voting_rule: 2, // Under the voting rule 2, the operation will be approved if and only if 100% of all the board members approve the operation
return_level: 100,
is_before_operation: false, // make the decision after executing in sandbox
Expand All @@ -359,7 +359,7 @@ const disable_2_3_4 = {
) & // disable after operation plugins 2,3 and 4
(operator_total_voting_power_percentage >= 20) & // the operator address holds at least 20% of the total voting power
(operator_last_operation_window("disable_plugins") >= 1296000), // each operator can try to disable plugins once per 1296000 seconds (15 days)
return_type: vote_needed,
return_type: voting_needed,
voting_rule: 3, // Under the voting rule 3, the operation will be approved if and only if 70% of all the common stock holders approve the operation
is_before_operation: false, // make the decision after sandbox check
}
Expand Down
10 changes: 5 additions & 5 deletions README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ add_and_enable_plugins( // 新增插件并立即生效
condition: // 定义插件生效条件
(operation == "transfer_tokens") // 如果是代币转让操作
& (operator_total_voting_power_percentage > 25), // 并且操作者地址的投票权 > 25%
return_type: vote_needed, // 返回类型:需要投票
return_type: voting_needed, // 返回类型:需要投票
return_level: 100, // 优先级:100
votingRuleIndex: 5 // 使用投票规则序号为 5 的投票规则(即 100% 的董事会成员们必须投票通过)
note: "100% Approval is needed by board members to transfer tokens by major shareholders (>25%)"
Expand All @@ -89,7 +89,7 @@ add_and_enable_plugins( // 新增插件并立即生效

执行以上的 By-law Script 程序后,DARC VM 合约将添加一个新的插件和投票规则,并且插件将立即生效(如果存在与 add_voting_rule()
和 add_and_enable_plugins() 相关的任何投票程序,则插件将在投票流程通过后生效)。如果操作员(addr1)尝试将代币转移给
addr2,插件将检查条件并返回 vote_needed 给 DARC VM 合约,DARC VM
addr2,插件将检查条件并返回 voting_needed 给 DARC VM 合约,DARC VM
合约将要求董事会(一级代币所有者)进行投票。如果董事会批准该操作,则该操作将在沙盒中执行,否则该操作将被拒绝。例如,如果触发了3个投票规则,则投票操作将是:

```javascript
Expand Down Expand Up @@ -299,7 +299,7 @@ const add_board_member = {
(operator_total_voting_power_percentage >= 10), // 操作者拥有的总投票权大于等于10%

// 插件决策:需要投票
return_type: vote_needed,
return_type: voting_needed,
voting_rule: 1, // 在决策投票规则1下,超过2/3的董事会成员批准该操作,则该操作被批准
return_level: 100,
is_before_operation: false, // 沙箱检查之后才进行投票
Expand All @@ -315,7 +315,7 @@ const enable_plugin = {
(operator_total_voting_power_percentage >= 7) & // 该用户拥有的总投票权大于等于7%
(operator_last_operation_window("enable_plugin") >= 864000), //每个用户可以每 864000 seconds (10 days) 天尝试一次

return_type: vote_needed,
return_type: voting_needed,
voting_rule: 2, // 在投票规则2下,超过所有董事会成员的100%批准该操作,则该操作被批准
return_level: 100,
is_before_operation: false, // 沙箱检查之后才进行投票
Expand All @@ -335,7 +335,7 @@ const disable_2_3_4 = {
) & // 废除插件2、3 或者 4
(operator_total_voting_power_percentage >= 20) & // 操作者拥有的总投票权大于等于20%
(operator_last_operation_window("disable_plugins") >= 1296000), // 每个用户可以每 1296000 seconds (15 days) 天尝试一次
return_type: vote_needed,
return_type: voting_needed,
voting_rule: 3, // 在投票规则3下,超过所有普通股代币(级别为0的代币)所有投票人的70%的相对多数批准该操作,则该操作被批准
is_before_operation: false, // 沙箱检查之后才进行投票
}
Expand Down
10 changes: 5 additions & 5 deletions darc-protocol/contracts/protocol/Plugin/Plugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ enum EnumLogicalOperatorType {UNDEFINED, AND, OR, NOT }
* 4. Otherwise, the program is invalid and should be rejected.
*
* For the After Operation Plugin System (after executed in sandbox), the priority of the return value is:
* NO > VOTE_NEEDED > YES > UNDEFINED,
* NO > VOTING_NEEDED > YES > UNDEFINED,
* which means:
* 1. If any operation in the program is NO (disapproved), the program is invalid and should be rejected.
* 2. Otherwise, if any operation in the program is VOTE_NEEDED, a voting item should be created.
* 2. Otherwise, if any operation in the program is VOTING_NEEDED, a voting item should be created.
*
* ----------------------------------------------
*
Expand Down Expand Up @@ -67,9 +67,9 @@ enum EnumReturnType {

/**
* The decision is pending and a voting item should be created at this level.
* Only AFTER operation plugin system may return VOTE_NEEDED.
* Only AFTER operation plugin system may return VOTING_NEEDED.
*/
VOTE_NEEDED,
VOTING_NEEDED,

/**
* The operation is approved and should skip the sandbox check.
Expand Down Expand Up @@ -221,7 +221,7 @@ struct Plugin {
ConditionNode[] conditionNodes;

/**
* the voting rule id of the current plugin if the return type is VOTE_NEEDED
* the voting rule id of the current plugin if the return type is VOTING_NEEDED
*/
uint256 votingRuleIndex;

Expand Down
2 changes: 1 addition & 1 deletion darc-protocol/contracts/protocol/Plugin/PluginFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract PluginFactory is ConditionExpressionFactory{
* @param pluginIndex The index of the plugin in the plugin system
* @return uint256 The return level of the plugin
* @return EnumReturnType The return type of the plugin
* @return uint256 The index of the plugin in the plugin system (if not VOTE_NEEDED, return 0)
* @return uint256 The index of the plugin in the plugin system (if not VOTING_NEEDED, return 0)
*/
function pluginCheck(bool bIsBeforeOperation, Operation memory operation, uint256 pluginIndex) internal view returns (uint256, EnumReturnType, uint256) {

Expand Down
22 changes: 11 additions & 11 deletions darc-protocol/contracts/protocol/Plugin/PluginSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ contract PluginSystem is PluginFactory{
}

// if the return type is vote needed, add the voting policy to the current voting rule list
if (currentReturnType == EnumReturnType.VOTE_NEEDED) {
if (currentReturnType == EnumReturnType.VOTING_NEEDED) {
currentOperationVotingRuleList[currentOperationVotingRuleIndex] = currentVotingRuleIdx;
currentOperationVotingRuleIndex++;
}
Expand All @@ -114,7 +114,7 @@ contract PluginSystem is PluginFactory{
// check if the return type is vote needed
else if (currentReturnLevel == highestReturnLevel && currentReturnType != EnumReturnType.UNDEFINED) {
// if the return type is vote needed, add the voting policy to the voting policy list
if (currentReturnType == EnumReturnType.VOTE_NEEDED) {
if (currentReturnType == EnumReturnType.VOTING_NEEDED) {
currentOperationVotingRuleList[currentOperationVotingRuleIndex] = currentVotingRuleIdx;
currentOperationVotingRuleIndex++;
}
Expand All @@ -130,7 +130,7 @@ contract PluginSystem is PluginFactory{
operationReturnTypeList[operationIndex] = highestReturnType;

// if the highest return type is vote needed, add the voting rule list to the voting rule list
if (highestReturnType == EnumReturnType.VOTE_NEEDED) {
if (highestReturnType == EnumReturnType.VOTING_NEEDED) {
for (uint256 i = 0; i < currentOperationVotingRuleIndex; i++) {
VotingRuleIndexList[VotingRuleIndex] = currentOperationVotingRuleList[i];
VotingRuleIndex++;
Expand All @@ -155,10 +155,10 @@ contract PluginSystem is PluginFactory{
* 4. Otherwise, the program is invalid and should be rejected.
*
* For the After Operation Plugin System (after executed in sandbox), the priority of the return value is:
* NO > VOTE_NEEDED > YES > UNDEFINED,
* NO > VOTING_NEEDED > YES > UNDEFINED,
* which means:
* 1. If any operation in the program is NO (disapproved), the program is invalid and should be rejected.
* 2. Otherwise, if any operation in the program is VOTE_NEEDED, a voting item should be created.
* 2. Otherwise, if any operation in the program is VOTING_NEEDED, a voting item should be created.
*
* ----------------------------------------------
*
Expand Down Expand Up @@ -192,19 +192,19 @@ contract PluginSystem is PluginFactory{
}
else {
//3.1.2 for after operation plugin system, the priority of the return value is:
// NO > VOTE_NEEDED > YES > UNDEFINED
// NO > VOTING_NEEDED > YES > UNDEFINED
for (uint256 i = 0; i < operationReturnTypeList.length; i++) {
if (operationReturnTypeList[i] == EnumReturnType.NO) {
finalReturnType = EnumReturnType.NO;

}
else if (operationReturnTypeList[i] == EnumReturnType.VOTE_NEEDED
else if (operationReturnTypeList[i] == EnumReturnType.VOTING_NEEDED
&& finalReturnType != EnumReturnType.NO) {
finalReturnType = EnumReturnType.VOTE_NEEDED;
finalReturnType = EnumReturnType.VOTING_NEEDED;

}
else if (operationReturnTypeList[i] == EnumReturnType.YES
&& finalReturnType != EnumReturnType.VOTE_NEEDED
&& finalReturnType != EnumReturnType.VOTING_NEEDED
&& finalReturnType != EnumReturnType.NO) {
finalReturnType = EnumReturnType.YES;

Expand All @@ -214,7 +214,7 @@ contract PluginSystem is PluginFactory{

//3.2 if voting is needed, reconstruct the voting rule list
// otherwise, return an empty list
if (finalReturnType != EnumReturnType.VOTE_NEEDED) {
if (finalReturnType != EnumReturnType.VOTING_NEEDED) {
VotingRuleIndex = 0;
}
uint256[] memory trimmedList = new uint256[](VotingRuleIndex);
Expand All @@ -233,7 +233,7 @@ contract PluginSystem is PluginFactory{
* @param pluginIndex The index of the plugin to be checked
* @return uint256 The return level of the plugin
* @return EnumReturnType The return type of the plugin
* @return uint256 The corresponding voting rule index of the plugin in current machine state (if not VOTE_NEEDED, return 0)
* @return uint256 The corresponding voting rule index of the plugin in current machine state (if not VOTING_NEEDED, return 0)
*/
function checkPluginForOperation(bool bIsBeforeOperation, Operation memory operation, uint256 pluginIndex) internal view returns (uint256, EnumReturnType, uint256) {
// simply return the entrance check(bIsBeforeOperation, operation, pluginIndex) from the Plugin Factory
Expand Down
2 changes: 1 addition & 1 deletion darc-protocol/contracts/protocol/Program.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ enum EnumParameterType {
STRING_ARRAY,
BOOL_ARRAY,
PLUGIN_ARRAY
}
}

enum MachineParameter{
UNDEFINED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ contract Executable is MachineStateManager, PluginSystem, VotingMachine, Instruc
}

// 2.4 If the program is voting needed, initialize the voting machine
else if (afterReturnType == EnumReturnType.VOTE_NEEDED){
else if (afterReturnType == EnumReturnType.VOTING_NEEDED){
this.initializeVoting(afterRuleIdxList, currentProgram);
}

Expand All @@ -70,7 +70,7 @@ contract Executable is MachineStateManager, PluginSystem, VotingMachine, Instruc
function checkBeforeOperationPlugins(Program memory currentProgram) internal view returns (EnumReturnType) {
(EnumReturnType result, uint256[] memory list ) = pluginSystemJudgment(true, currentProgram);
require(list.length == 0, "The before operation plugin system should not return a voting rule list");
require(result != EnumReturnType.VOTE_NEEDED, "The before operation plugin system should not return vote needed");
require(result != EnumReturnType.VOTING_NEEDED, "The before operation plugin system should not return vote needed");
return result;
}

Expand Down

0 comments on commit 5bad992

Please sign in to comment.