Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lidangzzz committed Dec 19, 2023
1 parent 1c49132 commit e8aeb46
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 88 deletions.
18 changes: 9 additions & 9 deletions darc-docs/docs/DARC Protocol/OpCodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ By defining these operations through opcodes, the DARC protocol ensures consiste
|------------------------|-----------|--------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------|
| UNDEFINED | 0 | N/A | Invalid Operation |
| BATCH_MINT_TOKENS | 1 | `toAddressArray`: address[]<br/>`tokenClassArray`: uint256[]<br/>`amountArray`: uint256[] | Batch Mint Token Operation |
| BATCH_CREATE_TOKEN_CLASS | 2 | `nameArray`: string[]<br/>`tokenIndexArray`: uint256[]<br/>`votingWeightArray`: uint256[]<br/>`dividendWeightArray`: uint256[] | Batch Create Token Class Operation |
| BATCH_CREATE_TOKEN_CLASSES | 2 | `nameArray`: string[]<br/>`tokenIndexArray`: uint256[]<br/>`votingWeightArray`: uint256[]<br/>`dividendWeightArray`: uint256[] | Batch Create Token Class Operation |
| BATCH_TRANSFER_TOKENS | 3 | `toAddressArray`: address[]<br/>`tokenClassArray`: uint256[]<br/>`amountArray`: uint256[] | Batch Transfer Token Operation |
| BATCH_TRANSFER_TOKENS_FROM_TO | 4 | `fromAddressArray`: address[]<br/>`toAddressArray`: address[]<br/>`tokenClassArray`: uint256[]<br/>`amountArray`: uint256[] | Batch Transfer Token From Addr A to Addr B Operation |
| BATCH_BURN_TOKENS | 5 | `tokenClassArray`: uint256[]<br/>`amountArray`: uint256[] | Batch Burn Token Operation |
| BATCH_BURN_TOKENS_FROM | 6 | `fromAddressArray`: address[]<br/>`tokenClassArray`: uint256[]<br/>`amountArray`: uint256[] | Batch Burn Token From Addr A Operation |
| BATCH_ADD_MEMBERSHIP | 7 | `memberAddressArray`: address[]<br/>`memberRoleArray`: uint256[]<br/>`memberNameArray`: string[] | Batch Add Member Operation |
| BATCH_SUSPEND_MEMBERSHIP | 8 | `memberAddressArray`: address[] | Batch Suspend Member Operation |
| BATCH_RESUME_MEMBERSHIP | 9 | `memberAddressArray`: address[] | Batch Resume Member Operation |
| BATCH_CHANGE_MEMBER_ROLE | 10 | `memberAddressArray`: address[]<br/>`memberRoleArray`: uint256[] | Batch Change Member Role Operation |
| BATCH_CHANGE_MEMBER_NAME | 11 | `memberAddressArray`: address[]<br/>`memberNameArray`: string[] | Batch Change Member Name Operation |
| BATCH_ADD_PLUGIN | 12 | `pluginList`: Plugin[] | Batch Add Emergency Agent Operation |
| BATCH_ENABLE_PLUGIN | 13 | `pluginIndexArray`: uint256[]<br/>`isBeforeOperationArray`: bool[] | Batch Enable Plugin Operation |
| BATCH_DISABLE_PLUGIN | 14 | `pluginIndexArray`: uint256[]<br/>`isBeforeOperationArray`: bool[] | Batch Disable Plugin Operation |
| BATCH_ADD_AND_ENABLE_PLUGIN | 15 | `pluginList`: Plugin[] | Batch Add and Enable Plugin Operation |
| BATCH_SET_PARAMETER | 16 | `parameterNameArray`: MachineParameter[]<br/>`parameterValueArray`: uint256[] | Batch Set Parameter Operation |
| BATCH_ADD_WITHDRAWABLE_BALANCE | 17 | `addressArray`: address[]<br/>`amountArray`: uint256[] | Batch Add Withdrawable Balance Operation |
| BATCH_CHANGE_MEMBER_ROLES | 10 | `memberAddressArray`: address[]<br/>`memberRoleArray`: uint256[] | Batch Change Member Role Operation |
| BATCH_CHANGE_MEMBER_NAMES | 11 | `memberAddressArray`: address[]<br/>`memberNameArray`: string[] | Batch Change Member Name Operation |
| BATCH_ADD_PLUGINS | 12 | `pluginList`: Plugin[] | Batch Add Emergency Agent Operation |
| BATCH_ENABLE_PLUGINS | 13 | `pluginIndexArray`: uint256[]<br/>`isBeforeOperationArray`: bool[] | Batch Enable Plugin Operation |
| BATCH_DISABLE_PLUGINS | 14 | `pluginIndexArray`: uint256[]<br/>`isBeforeOperationArray`: bool[] | Batch Disable Plugin Operation |
| BATCH_ADD_AND_ENABLE_PLUGINS | 15 | `pluginList`: Plugin[] | Batch Add and Enable Plugin Operation |
| BATCH_SET_PARAMETERS | 16 | `parameterNameArray`: MachineParameter[]<br/>`parameterValueArray`: uint256[] | Batch Set Parameter Operation |
| BATCH_ADD_WITHDRAWABLE_BALANCES | 17 | `addressArray`: address[]<br/>`amountArray`: uint256[] | Batch Add Withdrawable Balance Operation |
| BATCH_REVOKE_WITHDRAWABLE_BALANCE | 18 | `addressArray`: address[] | Batch Revoke Withdrawable Balance Operation |
| BATCH_WITHDRAW_FROM_BALANCE | 19 | `addressArray`: address[]<br/>`amountArray`: uint256[] | Batch Withdraw From Balance Operation |
| BATCH_PAY_TO_MINT_TOKENS | 20 | `addressArray`: address[]<br/>`tokenClassArray`: uint256[]<br/>`amountArray`: uint256[]<br/>`priceArray`: uint256[] | Batch Pay to Mint Tokens Operation |
Expand Down
2 changes: 1 addition & 1 deletion darc-docs/docs/darc.js/Access to a deployed DARC.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ batch_mint_tokens(
// enable plugins 3, 4 before sandbox checking operation
// and disable plugins 5, 6 after sandbox checking operation
batch_enable_plugins(
BATCH_ENABLE_PLUGINSs(
[3,4,5,6],
[true, true, false, false]
);
Expand Down
30 changes: 18 additions & 12 deletions darc-protocol/contracts/protocol/Opcodes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ enum EnumOpcode {
*
* ID:2
*/
BATCH_CREATE_TOKEN_CLASS,
BATCH_CREATE_TOKEN_CLASSES,

/**
* @notice Batch Transfer Token Operation
Expand Down Expand Up @@ -108,7 +108,7 @@ enum EnumOpcode {
*
* ID:10
*/
BATCH_CHANGE_MEMBER_ROLE,
BATCH_CHANGE_MEMBER_ROLES,

/**
* @notice Batch Change Member Name Operation
Expand All @@ -117,68 +117,68 @@ enum EnumOpcode {
*
* ID:11
*/
BATCH_CHANGE_MEMBER_NAME,
BATCH_CHANGE_MEMBER_NAMES,

/**
* @notice Batch Add Emergency Agent Operation
* @param Plugin[] pluginList: the array of the plugins
* ID:12
*/
BATCH_ADD_PLUGIN,
BATCH_ADD_PLUGINS,

/**
* @notice Batch Enable Plugin Operation
* @param UINT256_ARRAY[0] uint256[] pluginIndexArray: the array of the plugins index to enable
* @param BOOL_ARRAY bool[] isBeforeOperationArray: the array of the flag to indicate if the plugin is before operation
* ID:13
*/
BATCH_ENABLE_PLUGIN,
BATCH_ENABLE_PLUGINS,

/**
* @notice Batch Disable Plugin Operation
* @param UINT256_ARRAY[0] uint256[] pluginIndexArray: the array of the plugins index to disable
* @param BOOL_ARRAY bool[] isBeforeOperationArray: the array of the flag to indicate if the plugin is before operation
* ID:14
*/
BATCH_DISABLE_PLUGIN,
BATCH_DISABLE_PLUGINS,

/**
* @notice Batch Add and Enable Plugin Operation
* @param Plugin[] pluginList: the array of the plugins
* ID:15
*/
BATCH_ADD_AND_ENABLE_PLUGIN,
BATCH_ADD_AND_ENABLE_PLUGINS,

/**
* @notice Batch Set Parameter Operation
* @param MachineParameter[] parameterNameArray: the array of the parameter name
* @param UINT256_2DARRAY[0] uint256[] parameterValueArray: the array of the parameter value
* ID:16
*/
BATCH_SET_PARAMETER,
BATCH_SET_PARAMETERS,

/**
* @notice Batch Add Withdrawable Balance Operation
* @param address[] addressArray: the array of the address to add withdrawable balance
* @param uint256[] amountArray: the array of the amount to add withdrawable balance
* ID:17
*/
BATCH_ADD_WITHDRAWABLE_BALANCE,
BATCH_ADD_WITHDRAWABLE_BALANCES,

/**
* @notice Batch Reduce Withdrawable Balance Operation
* @param address[] addressArray: the array of the address to substract withdrawable balance
* @param uint256[] amountArray: the array of the amount to substract withdrawable balance
* ID:18
*/
BATCH_REDUCE_WITHDRAWABLE_BALANCE,
BATCH_REDUCE_WITHDRAWABLE_BALANCES,

/**
* @notice Batch Add Voting Rules
* @param VotingRule[] votingRuleList: the array of the voting rules
* ID:19
*/
BATCH_ADD_VOTING_RULE,
BATCH_ADD_VOTING_RULES,


/**
Expand Down Expand Up @@ -328,5 +328,11 @@ enum EnumOpcode {
* @notice Upgrade the contract to the latest version
* ID:37
*/
UPGRADE_TO_THE_LATEST
UPGRADE_TO_THE_LATEST,

/**
* @notice Batch Pay to Trasnfer Tokens Operation
* ID:38
*/
op_BATCH_PAY_TO_TRANSFER_TOKENS
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ OfferDividendsInstructions
}

// opcode id == 2
else if (operation.opcode == EnumOpcode.BATCH_CREATE_TOKEN_CLASS ){
op_BATCH_CREATE_TOKEN_CLASS(operation, bIsSandbox);
else if (operation.opcode == EnumOpcode.BATCH_CREATE_TOKEN_CLASSES ){
op_BATCH_CREATE_TOKEN_CLASSES(operation, bIsSandbox);
}

// opcode id == 3
Expand Down Expand Up @@ -90,53 +90,53 @@ OfferDividendsInstructions
}

// opcode id == 10
else if (operation.opcode == EnumOpcode.BATCH_CHANGE_MEMBER_ROLE) {
op_BATCH_CHANGE_MEMBER_ROLE(operation, bIsSandbox);
else if (operation.opcode == EnumOpcode.BATCH_CHANGE_MEMBER_ROLES) {
op_BATCH_CHANGE_MEMBER_ROLES(operation, bIsSandbox);
}

// opcode id == 11
else if (operation.opcode == EnumOpcode.op_BATCH_CHANGE_MEMBER_NAME) {
op_BATCH_CHANGE_MEMBER_NAME(operation, bIsSandbox);
else if (operation.opcode == EnumOpcode.BATCH_CHANGE_MEMBER_NAMES) {
op_BATCH_CHANGE_MEMBER_NAMES(operation, bIsSandbox);
}

// opcode id == 12
else if (operation.opcode == EnumOpcode.BATCH_ADD_PLUGIN) {
op_BATCH_ADD_PLUGIN(operation, bIsSandbox);
else if (operation.opcode == EnumOpcode.BATCH_ADD_PLUGINS) {
op_BATCH_ADD_PLUGINS(operation, bIsSandbox);
}

// opcode id == 13
else if (operation.opcode == EnumOpcode.BATCH_ENABLE_PLUGIN) {
op_BATCH_ENABLE_PLUGIN(operation, bIsSandbox);
else if (operation.opcode == EnumOpcode.BATCH_ENABLE_PLUGINS) {
op_BATCH_ENABLE_PLUGINS(operation, bIsSandbox);
}

// opcode id == 14
else if (operation.opcode == EnumOpcode.BATCH_DISABLE_PLUGIN) {
op_BATCH_DISABLE_PLUGIN(operation, bIsSandbox);
else if (operation.opcode == EnumOpcode.BATCH_DISABLE_PLUGINS) {
op_BATCH_DISABLE_PLUGINS(operation, bIsSandbox);
}

// opcode id == 15
else if (operation.opcode == EnumOpcode.BATCH_ADD_AND_ENABLE_PLUGIN){
op_BATCH_ADD_AND_ENABLE_PLUGIN(operation, bIsSandbox);
else if (operation.opcode == EnumOpcode.BATCH_ADD_AND_ENABLE_PLUGINS){
op_BATCH_ADD_AND_ENABLE_PLUGINS(operation, bIsSandbox);
}

// opcode id == 16
else if (operation.opcode == EnumOpcode.BATCH_SET_PARAMETER) {
op_BATCH_SET_PARAMETER(operation, bIsSandbox);
else if (operation.opcode == EnumOpcode.BATCH_SET_PARAMETERS) {
op_BATCH_SET_PARAMETERS(operation, bIsSandbox);
}

// opcode id == 17
else if (operation.opcode == EnumOpcode.BATCH_ADD_WITHDRAWABLE_BALANCE) {
op_BATCH_ADD_WITHDRAWABLE_BALANCE(operation, bIsSandbox);
else if (operation.opcode == EnumOpcode.BATCH_ADD_WITHDRAWABLE_BALANCES) {
op_BATCH_ADD_WITHDRAWABLE_BALANCES(operation, bIsSandbox);
}

// opcode id == 18
else if (operation.opcode == EnumOpcode.BATCH_REDUCE_WITHDRAWABLE_BALANCE) {
op_BATCH_REDUCE_WITHDRAWABLE_BALANCE(operation, bIsSandbox);
else if (operation.opcode == EnumOpcode.BATCH_REDUCE_WITHDRAWABLE_BALANCES) {
op_BATCH_REDUCE_WITHDRAWABLE_BALANCES(operation, bIsSandbox);
}

// opcode id == 19
else if (operation.opcode == EnumOpcode.BATCH_ADD_VOTING_RULE) {
op_BATCH_ADD_VOTING_RULE(operation, bIsSandbox);
else if (operation.opcode == EnumOpcode.BATCH_ADD_VOTING_RULES) {
op_BATCH_ADD_VOTING_RULES(operation, bIsSandbox);
}

// opcode id == 20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ contract MembershipInstructions is MachineStateManager {


/**
* @notice The function that executes the BATCH_CHANGE_MEMBER_ROLE operation
* @notice The function that executes the BATCH_CHANGE_MEMBER_ROLES operation
* @param operation The operation to be executed
* @param bIsSandbox The flag to indicate if the operation is being executed in sandbox
*/
function op_BATCH_CHANGE_MEMBER_ROLE(Operation memory operation, bool bIsSandbox) internal {
function op_BATCH_CHANGE_MEMBER_ROLES(Operation memory operation, bool bIsSandbox) internal {
// parameter 1 is the array of member addresses
address[] memory members = operation.param.ADDRESS_2DARRAY[0];
// parameter 2 is the array of member role numbers
Expand All @@ -122,11 +122,11 @@ contract MembershipInstructions is MachineStateManager {
}
}
/**
* @notice The function that executes the BATCH_CHANGE_MEMBER_NAME operation
* @notice The function that executes the BATCH_CHANGE_MEMBER_NAMES operation
* @param operation The operation to be executed
* @param bIsSandbox The flag to indicate if the operation is being executed in sandbox
*/
function op_BATCH_CHANGE_MEMBER_NAME(Operation memory operation, bool bIsSandbox) internal {
function op_BATCH_CHANGE_MEMBER_NAMES(Operation memory operation, bool bIsSandbox) internal {
// parameter 1 is the array of member addresses
address[] memory members = operation.param.ADDRESS_2DARRAY[0];
// parameter 2 is the array of member role names
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import "../../../Utilities/ErrorMsg.sol";
*/
contract MoneyInstructions is MachineStateManager {

function op_BATCH_ADD_WITHDRAWABLE_BALANCE(Operation memory operation, bool bIsSandbox) internal {
function op_BATCH_ADD_WITHDRAWABLE_BALANCES(Operation memory operation, bool bIsSandbox) internal {
// todo
}

function op_BATCH_REDUCE_WITHDRAWABLE_BALANCE(Operation memory operation, bool bIsSandbox) internal {
function op_BATCH_REDUCE_WITHDRAWABLE_BALANCES(Operation memory operation, bool bIsSandbox) internal {
// todo
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import "../../../Plugin/Plugin.sol";
import "../../../Utilities/ErrorMsg.sol";

/**
* @title Implementation of the single instruction "BATCH_SET_PARAMETER"
* @title Implementation of the single instruction "BATCH_SET_PARAMETERS"
* @author DARC Team
* @notice null
*/

contract ParameterInstructions is MachineStateManager {
/**
* @notice The implementation of the single instruction "BATCH_SET_PARAMETER"
* @notice The implementation of the single instruction "BATCH_SET_PARAMETERS"
* @param operation The operation index to be executed
* @param bIsSandbox The boolean flag that indicates if the operation is executed in sandbox
*/
function op_BATCH_SET_PARAMETER(Operation memory operation, bool bIsSandbox) internal {
function op_BATCH_SET_PARAMETERS(Operation memory operation, bool bIsSandbox) internal {
// parameter 1 is the Machine Parameter Array
MachineParameter[] memory params = operation.param.PARAMETER_ARRAY;
// parameter 2 is the uint256 array of the parameter UINT256_2DARRAY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import "../../../Plugin/Plugin.sol";
import "../../../Utilities/ErrorMsg.sol";

/**
* @title Implementation of BATCH_ADD_AND_ENABLE_PLUGIN operation
* @title Implementation of BATCH_ADD_AND_ENABLE_PLUGINS operation
* @author DARC Team
* @notice null
*/

contract PluginInstructions is MachineStateManager{
/**
* @notice The function that executes the BATCH_ADD_PLUGIN operation
* @notice The function that executes the BATCH_ADD_PLUGINS operation
* @param operation The operation to be executed
* @param bIsSandbox The flag to indicate if the operation is being executed in sandbox
*/
function op_BATCH_ADD_PLUGIN(Operation memory operation, bool bIsSandbox) internal {
function op_BATCH_ADD_PLUGINS(Operation memory operation, bool bIsSandbox) internal {
// parameter 1 is the array of plugins
Plugin[] memory plugins = operation.param.PLUGIN_ARRAY;
for (uint256 i=0;i<plugins.length;i++){
Expand Down Expand Up @@ -51,11 +51,11 @@ contract PluginInstructions is MachineStateManager{
}
}
/**
* @notice The function that executes the BATCH_ADD_AND_ENABLE_PLUGIN operation
* @notice The function that executes the BATCH_ADD_AND_ENABLE_PLUGINS operation
* @param operation The operation to be executed
* @param bIsSandbox The flag to indicate if the operation is being executed in sandbox
*/
function op_BATCH_ADD_AND_ENABLE_PLUGIN(Operation memory operation, bool bIsSandbox) internal {
function op_BATCH_ADD_AND_ENABLE_PLUGINS(Operation memory operation, bool bIsSandbox) internal {
// parameter 1 is the array of plugins
Plugin[] memory plugins = operation.param.PLUGIN_ARRAY;
for (uint256 i=0;i<plugins.length;i++){
Expand Down Expand Up @@ -87,11 +87,11 @@ contract PluginInstructions is MachineStateManager{
}

/**
* @notice The function that executes the BATCH_ENABLE_PLUGIN operation
* @notice The function that executes the BATCH_ENABLE_PLUGINS operation
* @param operation The operation to be executed
* @param bIsSandbox The flag to indicate if the operation is being executed in sandbox
*/
function op_BATCH_ENABLE_PLUGIN(Operation memory operation, bool bIsSandbox) internal {
function op_BATCH_ENABLE_PLUGINS(Operation memory operation, bool bIsSandbox) internal {
// parameter 1 is the array of plugin indexes to be enabled
uint256[] memory pluginIndexes = operation.param.UINT256_2DARRAY[0];
// parameter 2 is the array of boolean that indicates if the plugin is a before operation plugin
Expand Down Expand Up @@ -132,11 +132,11 @@ contract PluginInstructions is MachineStateManager{
}

/**
* @notice The function that executes the BATCH_DISABLE_PLUGIN operation
* @notice The function that executes the BATCH_DISABLE_PLUGINS operation
* @param operation The operation to be executed
* @param bIsSandbox The flag to indicate if the operation is being executed in sandbox
*/
function op_BATCH_DISABLE_PLUGIN(Operation memory operation, bool bIsSandbox) internal {
function op_BATCH_DISABLE_PLUGINS(Operation memory operation, bool bIsSandbox) internal {
// parameter 1 is the array of plugin indexes to be disabled
uint256[] memory pluginIndexes = operation.param.UINT256_2DARRAY[0];
// parameter 2 is the array of boolean that indicates if the plugin is a before operation plugin
Expand Down
Loading

0 comments on commit e8aeb46

Please sign in to comment.