Skip to content

Commit

Permalink
Merge branch 'plugin-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
lidangzzz committed Dec 17, 2023
2 parents 088d447 + dce46c1 commit 2453437
Show file tree
Hide file tree
Showing 85 changed files with 1,289 additions and 201 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ darc-docs/.docusaurus

# Darc docs Compiled output
darc-docs/build
darc-docs/static/api
darc-docs/static/api
darc-js/dist
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
15 changes: 15 additions & 0 deletions darc-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,18 @@ const myDeployedDARC_readOnly = new darcjs.DARC({
// Read information from the DARC
const memberList = await myDARC_readOnly.getMemberList();
```

### Test

Before running the test, you need to start a Hardhat Network in your neighbour folder `darc-protocol`

```bash
cd ../darc-protocol
npx hardhat node
```

Then, you can run the test in `darc-js` folder. Run below command in another terminal.

```bash
pnpm run test
```
1 change: 1 addition & 0 deletions darc-js/dist/SDK/SDK.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//# sourceMappingURL=SDK.d.ts.map
1 change: 1 addition & 0 deletions darc-js/dist/SDK/SDK.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions darc-js/dist/SDK/SDK.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions darc-js/dist/SDK/SDK.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions darc-js/dist/SDK/instructions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { TokenOperations } from "./struct/token-operation-map";
import { Plugin } from "./struct/Plugin";
export declare let operationList: never[];
declare function withdraw_dividends(): void;
declare function withdraw_money(amount: number): void;
declare function withdraw_money_and_send_to_address(amount: number, targetAddress: string): void;
declare function pay_money(amount: number): void;
declare function enable_plugin_index(pluginIndex: number): void;
declare function disable_plugin_index(pluginIndex: number): void;
declare function add_plugin(currentRestrictionPlugin: Plugin): void;
declare function add_and_enable_plugin(currentRestrictionPlugin: Plugin): void;
declare function burn_tokens(tokenID: number, amount: number, targetAddress: string): void;
declare function batch_transfer_tokens(tokenOperations: TokenOperations): void;
declare function batch_mint_tokens(tokenOperations: TokenOperations): void;
declare function batch_burn_tokens(tokenOperations: TokenOperations): void;
declare function call_emergency(emergency_id: number): void;
declare function set_parameter(parameter: string, value: string): void;
declare function add_to_member_list(alias: string, role: string, address: string): void;
declare function modify_member_list(alias: string, role: string, address: string): void;
declare function suspend_member_list(address: string): void;
declare function reactivate_member_list(address: string): void;
export { withdraw_dividends, withdraw_money, withdraw_money_and_send_to_address, pay_money, enable_plugin_index, disable_plugin_index, add_plugin, add_and_enable_plugin, burn_tokens, batch_transfer_tokens, batch_mint_tokens, batch_burn_tokens, call_emergency, set_parameter, add_to_member_list, modify_member_list, suspend_member_list, reactivate_member_list };
//# sourceMappingURL=instructions.d.ts.map
1 change: 1 addition & 0 deletions darc-js/dist/SDK/instructions.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions darc-js/dist/SDK/instructions.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions darc-js/dist/SDK/instructions.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions darc-js/dist/SDK/plugin/ConditionNode.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Expression } from "./Expression";
declare enum ConditionNodeType {
ExpressionNode = 0,
LogicalOperatorNode = 1,
BooleanValueNode = 2
}
declare enum LogicalOperatorType {
AND = 0,
OR = 1,
NOT = 2
}
declare class ConditionNode {
type: ConditionNodeType;
expression: Expression | null;
logicalOperator: LogicalOperatorType | null;
expressionParameters: (number | string | bigint)[] | null;
booleanValue: boolean | null;
childList: ConditionNode[];
constructor(type: ConditionNodeType, expression: Expression | null, logicalOperator: LogicalOperatorType | null, expressionParameters: (number | string | bigint)[] | null, booleanValue?: boolean | null);
serializeToString(): string;
isValidLogicalOperatorNode(): void;
isValidExpressionNode(): void;
isValidBooleanValueNode(): void;
}
export { ConditionNode, Expression, ConditionNodeType, LogicalOperatorType };
//# sourceMappingURL=ConditionNode.d.ts.map
1 change: 1 addition & 0 deletions darc-js/dist/SDK/plugin/ConditionNode.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2453437

Please sign in to comment.