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 d2ea890 commit 1c49132
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 9 deletions.
4 changes: 2 additions & 2 deletions darc-protocol/contracts/protocol/Opcodes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ enum EnumOpcode {
BATCH_ADD_WITHDRAWABLE_BALANCE,

/**
* @notice Batch Substract Withdrawable Balance Operation
* @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_SUBSTRACT_WITHDRAWABLE_BALANCE,
BATCH_REDUCE_WITHDRAWABLE_BALANCE,

/**
* @notice Batch Add Voting Rules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,59 +41,195 @@ OfferDividendsInstructions
*/
function executeOperation (Operation memory operation, bool bIsSandbox) internal {

// opcode id == 0, which is undefined and should not be used
require(operation.opcode != EnumOpcode.UNDEFINED, "Operation type is undefined");

// opcode id == 1
if (operation.opcode == EnumOpcode.BATCH_MINT_TOKENS) {
op_BATCH_MINT_TOKENS(operation, bIsSandbox);
}

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

// opcode id == 3
else if (operation.opcode == EnumOpcode.BATCH_TRANSFER_TOKENS) {
op_BATCH_TRANSFER_TOKENS(operation, bIsSandbox);
}

// opcode id == 4
else if (operation.opcode == EnumOpcode.BATCH_TRANSFER_TOKENS_FROM_TO) {
op_BATCH_TRANSFER_TOKENS_FROM_TO(operation, bIsSandbox);
}

// opcode id == 5
else if (operation.opcode == EnumOpcode.BATCH_BURN_TOKENS) {
op_BATCH_BURN_TOKENS(operation, bIsSandbox);
}

// opcode id == 6
else if (operation.opcode == EnumOpcode.BATCH_BURN_TOKENS_FROM) {
op_BATCH_BURN_TOKENS_FROM(operation, bIsSandbox);
}

// opcode id == 7
else if (operation.opcode == EnumOpcode.BATCH_ADD_MEMBERSHIP) {
op_BATCH_ADD_MEMBERSHIP(operation, bIsSandbox);
}

// opcode id == 8
else if (operation.opcode == EnumOpcode.BATCH_SUSPEND_MEMBERSHIP) {
op_BATCH_SUSPEND_MEMBERSHIP(operation, bIsSandbox);
}

// opcode id == 9
else if (operation.opcode == EnumOpcode.BATCH_RESUME_MEMBERSHIP){
op_BATCH_RESUME_MEMBERSHIP(operation, bIsSandbox);
}
else if (operation.opcode == EnumOpcode.BATCH_ADD_AND_ENABLE_PLUGIN) {
op_BATCH_ADD_AND_ENABLE_PLUGIN(operation, bIsSandbox);

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

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

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

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

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

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

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

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

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

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

// opcode id == 20
else if (operation.opcode == EnumOpcode.BATCH_PAY_TO_MINT_TOKENS) {
op_BATCH_PAY_TO_MINT_TOKENS(operation, bIsSandbox);
}

// opcode id == 21
else if (operation.opcode == EnumOpcode.BATCH_PAY_TO_TRANSFER_TOKENS) {
op_BATCH_PAY_TO_TRANSFER_TOKENS(operation, bIsSandbox);
}

// opcode id == 22
else if (operation.opcode == EnumOpcode.ADD_EMERGENCY) {
op_ADD_EMERGENCY(operation, bIsSandbox);
}

// opcode id == 23
else if (operation.opcode == EnumOpcode.WITHDRAW_CASH_TO) {
op_WITHDRAW_CASH_TO(operation, bIsSandbox);
}

// opcode id == 24
else if (operation.opcode == EnumOpcode.CALL_EMERGENCY) {
op_CALL_EMERGENCY(operation, bIsSandbox);
}

// opcode id == 25
else if (operation.opcode == EnumOpcode.CALL_CONTRACT_ABI) {
op_CALL_CONTRACT_ABI(operation, bIsSandbox);
}

// opcode id == 26
else if (operation.opcode == EnumOpcode.PAY_CASH) {
op_PAY_CASH(operation, bIsSandbox);
}

// opcode id == 27
else if (operation.opcode == EnumOpcode.OFFER_DIVIDENDS) {
op_OFFER_DIVIDENDS(operation, bIsSandbox);
}
else if (operation.opcode == EnumOpcode.BATCH_PAY_TO_MINT_TOKENS){
op_BATCH_PAY_TO_MINT_TOKENS(operation, bIsSandbox);

// opcode id == 28
else if (operation.opcode == EnumOpcode.WITHDRAW_DIVIDENDS_TO) {
op_WITHDRAW_DIVIDENDS_TO(operation, bIsSandbox);
}

// opcode id == 29
else if (operation.opcode == EnumOpcode.SET_APPROVAL_FOR_ALL_OPERATIONS) {
op_SET_APPROVAL_FOR_ALL_OPERATIONS(operation, bIsSandbox);
}

// opcode id == 30
else if (operation.opcode == EnumOpcode.BATCH_BURN_TOKENS_AND_REFUND) {
op_BATCH_BURN_TOKENS_AND_REFUND(operation, bIsSandbox);
}

// opcode id == 31
else if (operation.opcode == EnumOpcode.ADD_STORAGE_IPFS_HASH) {
op_ADD_STORAGE_IPFS_HASH(operation, bIsSandbox);
}

// opcode id == 32
else if (operation.opcode == EnumOpcode.VOTE) {
op_VOTE(operation, bIsSandbox);
}

// opcode id == 33
else if (operation.opcode == EnumOpcode.EXECUTE_PROGRAM) {
op_EXECUTE_PROGRAM(operation, bIsSandbox);
}

// opcode id == 34
else if (operation.opcode == EnumOpcode.END_EMERGENCY) {
op_END_EMERGENCY(operation, bIsSandbox);
}

// opcode id == 35
else if (operation.opcode == EnumOpcode.UPGRADE_TO_ADDRESS) {
op_UPGRADE_TO_ADDRESS(operation, bIsSandbox);
}

// opcode id == 36
else if (operation.opcode == EnumOpcode.CONFIRM_UPGRAED_FROM_ADDRESS) {
op_CONFIRM_UPGRAED_FROM_ADDRESS(operation, bIsSandbox);
}

// opcode id == 37
else if (operation.opcode == EnumOpcode.UPGRADE_TO_THE_LATEST) {
op_UPGRADE_TO_THE_LATEST(operation, bIsSandbox);
}

// opcode id == 38
else if (operation.opcode == EnumOpcode.BATCH_PAY_TO_TRANSFER_TOKENS) {
op_BATCH_PAY_TO_TRANSFER_TOKENS(operation, bIsSandbox);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract MoneyInstructions is MachineStateManager {
// todo
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,26 @@ contract UtilityInstructions is MachineStateManager {
function op_EXECUTE_PROGRAM(Operation memory operation, bool bIsSandbox) internal {

}

function op_END_EMERGENCY(Operation memory operation, bool bIsSandbox) internal {
if (bIsSandbox) {
sandboxMachineState.machineStateParameters.bIsEmergency = false;
delete sandboxMachineState.machineStateParameters.activeEmergencyAgentsAddressList;
} else {
currentMachineState.machineStateParameters.bIsEmergency = false;
delete currentMachineState.machineStateParameters.activeEmergencyAgentsAddressList;
}
}

function op_UPGRADE_TO_ADDRESS(Operation memory operation, bool bIsSandbox) internal {

}

function op_CONFIRM_UPGRAED_FROM_ADDRESS(Operation memory operation, bool bIsSandbox) internal {

}

function op_UPGRADE_TO_THE_LATEST(Operation memory operation, bool bIsSandbox) internal {

}
}
4 changes: 2 additions & 2 deletions darc-protocol/contracts/protocol/Utilities/OpcodeMap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ library OpcodeMap{
if (opcode == EnumOpcode.BATCH_ADD_AND_ENABLE_PLUGIN) return 15;
if (opcode == EnumOpcode.BATCH_SET_PARAMETER) return 16;
if (opcode == EnumOpcode.BATCH_ADD_WITHDRAWABLE_BALANCE) return 17;
if (opcode == EnumOpcode.BATCH_SUBSTRACT_WITHDRAWABLE_BALANCE) return 18;
if (opcode == EnumOpcode.BATCH_REDUCE_WITHDRAWABLE_BALANCE) return 18;
if (opcode == EnumOpcode.BATCH_ADD_VOTING_RULE) return 19;
if (opcode == EnumOpcode.BATCH_PAY_TO_MINT_TOKENS) return 20;
if (opcode == EnumOpcode.BATCH_PAY_TO_TRANSFER_TOKENS) return 21;
Expand Down Expand Up @@ -74,7 +74,7 @@ library OpcodeMap{
if (opcode == EnumOpcode.BATCH_ADD_AND_ENABLE_PLUGIN) return "BATCH_ADD_AND_ENABLE_PLUGIN";
if (opcode == EnumOpcode.BATCH_SET_PARAMETER) return "BATCH_SET_PARAMETER";
if (opcode == EnumOpcode.BATCH_ADD_WITHDRAWABLE_BALANCE) return "BATCH_ADD_WITHDRAWABLE_BALANCE";
if (opcode == EnumOpcode.BATCH_SUBSTRACT_WITHDRAWABLE_BALANCE) return "BATCH_SUBSTRACT_WITHDRAWABLE_BALANCE";
if (opcode == EnumOpcode.BATCH_REDUCE_WITHDRAWABLE_BALANCE) return "BATCH_REDUCE_WITHDRAWABLE_BALANCE";
if (opcode == EnumOpcode.BATCH_ADD_VOTING_RULE) return "BATCH_ADD_VOTING_RULE";
if (opcode == EnumOpcode.BATCH_PAY_TO_MINT_TOKENS) return "BATCH_PAY_TO_MINT_TOKENS";
if (opcode == EnumOpcode.BATCH_PAY_TO_TRANSFER_TOKENS) return "BATCH_PAY_TO_TRANSFER_TOKENS";
Expand Down

0 comments on commit 1c49132

Please sign in to comment.