Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lidangzzz committed Dec 28, 2023
1 parent ed757a9 commit 037110a
Show file tree
Hide file tree
Showing 10 changed files with 569 additions and 72 deletions.
4 changes: 2 additions & 2 deletions darc-protocol/contracts/protocol/MachineStateManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ contract MachineStateManager {
EnumLogicalOperatorType.UNDEFINED,

// expression: operation == initialOwnerAddress
EnumConditionExpression.UNDEFINED,
0,
new uint256[](0),
NodeParam(
new string[](0),
Expand Down Expand Up @@ -129,7 +129,7 @@ contract MachineStateManager {
EnumLogicalOperatorType.UNDEFINED,

// expression: operation == initialOwnerAddress
EnumConditionExpression.UNDEFINED,
0,
new uint256[](0),
NodeParam(
new string[](0),
Expand Down
1 change: 1 addition & 0 deletions darc-protocol/contracts/protocol/Opcodes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ enum EnumOpcode {
/**
* @notice Set the approval for all transfer operations by address
* @paran address: the address to set approval for all transfer operations
* ADDRESS_2DARRAY[0][0] targetAddress
* ID:29
*/
SET_APPROVAL_FOR_ALL_OPERATIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "../Utilities/StringUtils.sol";
import "../Program.sol";

// import all the condition expression big list
import "./EnumConditionExpression.sol";
//import "./EnumConditionExpression.sol";

// import each implementation of the condition expression function
import "./Conditions/OperatorExpressionFunction.sol";
Expand Down Expand Up @@ -38,7 +38,7 @@ contract ConditionExpressionFactory is
*/
function conditionExpressionCheck(bool bIsBeforeOperation, Operation memory operation, uint256 pluginIndex, uint256 nodeIndex) internal view returns (bool) {
// get current condition expression node
EnumConditionExpression exp = bIsBeforeOperation ?
uint256 exp = bIsBeforeOperation ?
currentMachineState.beforeOpPlugins[pluginIndex].conditionNodes[nodeIndex].conditionExpression :
currentMachineState.afterOpPlugins[pluginIndex].conditionNodes[nodeIndex].conditionExpression;

Expand All @@ -48,13 +48,13 @@ contract ConditionExpressionFactory is
currentMachineState.afterOpPlugins[pluginIndex].conditionNodes[nodeIndex].param;

// check the condition expression node
if (exp == EnumConditionExpression.OPERATION_EQUALS) {
if (exp == 151) {
return exp_OPERATION_EQUALS(operation, param);
}
else if (exp == EnumConditionExpression.OPERATOR_NAME_EQUALS) {
else if (exp == 1) {
return false;//exp_OPERATOR_NAME_EQUALS(bIsBeforeOperation, operation, paramList);
}
else if (exp == EnumConditionExpression.OPERATOR_ADDRESS_EQUALS) {
else if (exp == 3) {
return exp_OPERATOR_ADDRESS_EQUALS(bIsBeforeOperation, operation, param);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ enum EnumConditionExpression{
OPERATOR_ROLE_IN_RANGE, // params: uint256 operatorRoleIndex
OPERATOR_ROLE_IN_LIST, // params: uint256[] operatorRoleIndexArray

OPERATOR_TOKEN_X_LARGER_THAN, // params: uint256 token class, uint256 amount
OPERATOR_TOKEN_X_LESS_THAN, // params: uint256 token class, uint256 amount
OPERATOR_TOKEN_X_IN_RANGE, // params: uint256 token class, uint256 amount
OPERATOR_TOKEN_X_AMOUNT_LARGER_THAN, // params: uint256 token class, uint256 amount
OPERATOR_TOKEN_X_AMOUNT_LESS_THAN, // params: uint256 token class, uint256 amount
OPERATOR_TOKEN_X_AMOUNT_IN_RANGE, // params: uint256 token class, uint256 amount
OPERATOR_TOKEN_X_AMOUNT_EQUALS, // params: uint256 token class, uint256 amount
OPERATOR_TOKEN_X_PERCENTAGE_LARGER_THAN, // params: uint256 token class, uint256 percentage
OPERATOR_TOKEN_X_PERCENTAGE_LESS_THAN, // params: uint256 token class, uint256 percentage
OPERATOR_TOKEN_X_PERCENTAGE_IN_RANGE, // params: uint256 token class, uint256 percentage
Expand All @@ -46,10 +47,12 @@ enum EnumConditionExpression{
OPERATOR_WITHDRAWABLE_CASH_LARGER_THAN, // params: uint256 amount
OPERATOR_WITHDRAWABLE_CASH_LESS_THAN, // params: uint256 amount
OPERATOR_WITHDRAWABLE_CASH_IN_RANGE, // params: uint256 amount
OPERATOR_WITHDRAWABLE_DIVIDENDS_LARGER_THAN, // params: uint256 amount
OPERATOR_WITHDRAWABLE_DIVIDENDS_LESS_THAN, // params: uint256 amount
OPERATOR_WITHDRAWABLE_DIVIDENDS_IN_RANGE, // params: uint256 amount

OPERATOR_ADDRESS_IN_LIST, // params: address[] the list of addresses

OPERATOR_ADDRESS_IN_LIST, // params: address[] the list of addresses、
OPERATOR_NAME_IN_LIST, // params: string[] the list of names

PlaceHolder1,
PlaceHolder2,
PlaceHolder3,
Expand Down Expand Up @@ -78,15 +81,30 @@ enum EnumConditionExpression{
TIMESTAMP_LARGER_THAN,
TIMESTAMP_LESS_THAN,
TIMESTAMP_IN_RANGE,
MEMBER_VOTING_WEIGHT_LARGER_THAN,
MEMBER_VOTING_WEIGHT_LESS_THAN,
MEMBER_VOTING_WEIGHT_IN_RANGE,
MEMBER_DIVIDEND_WEIGHT_LARGER_THAN,
MEMBER_DIVIDEND_WEIGHT_LESS_THAN,
MEMBER_DIVIDEND_WEIGHT_IN_RANGE,
MEMBER_TOKEN_X_LARGER_THAN,
MEMBER_TOKEN_X_LESS_THAN,
MEMBER_TOKEN_X_IN_RANGE,

DATE_YEAR_LARGER_THAN,
DATE_YEAR_LESS_THAN,
DATE_YEAR_IN_RANGE,
DATE_MONTH_LARGER_THAN,
DATE_MONTH_LESS_THAN,
DATE_MONTH_IN_RANGE,
DATE_DAY_LARGER_THAN,
DATE_DAY_LESS_THAN,
DATE_DAY_IN_RANGE,
DATE_HOUR_LARGER_THAN,
DATE_HOUR_LESS_THAN,
DATE_HOUR_IN_RANGE,

ADDRESS_VOTING_WEIGHT_LARGER_THAN,
ADDRESS_VOTING_WEIGHT_LESS_THAN,
ADDRESS_VOTING_WEIGHT_IN_RANGE,
ADDRESS_DIVIDEND_WEIGHT_LARGER_THAN,
ADDRESS_DIVIDEND_WEIGHT_LESS_THAN,
ADDRESS_DIVIDEND_WEIGHT_IN_RANGE,
ADDRESS_TOKEN_X_LARGER_THAN,
ADDRESS_TOKEN_X_LESS_THAN,
ADDRESS_TOKEN_X_IN_RANGE,

TOTAL_VOTING_WEIGHT_LARGER_THAN,
TOTAL_VOTING_WEIGHT_LESS_THAN,
TOTAL_VOTING_WEIGHT_IN_RANGE,
Expand All @@ -97,6 +115,19 @@ enum EnumConditionExpression{
TOTAL_CASH_LESS_THAN,
TOTAL_CASH_IN_RANGE,
TOTAL_CASH_EQUALS,

TOKEN_IN_list_VOTING_WEIGHT_LARGER_THAN,
TOKEN_IN_list_VOTING_WEIGHT_LESS_THAN,
TOKEN_IN_list_VOTING_WEIGHT_IN_RANGE,
TOKEN_IN_list_DIVIDEND_WEIGHT_LARGER_THAN,
TOKEN_IN_list_DIVIDEND_WEIGHT_LESS_THAN,
TOKEN_IN_list_DIVIDEND_WEIGHT_IN_RANGE,
TOKEN_IN_list_AMOUNT_LARGER_THAN,
TOKEN_IN_list_AMOUNT_LESS_THAN,
TOKEN_IN_list_AMOUNT_IN_RANGE,
TOKEN_IN_list_AMOUNT_EQUALS,


PlaceHolder21,
PlaceHolder22,
PlaceHolder23,
Expand Down Expand Up @@ -152,30 +183,62 @@ enum EnumConditionExpression{
OPERATION_EVERYONE_SINCE_LAST_TIME_LARGER_THAN,
OPERATION_EVERYONE_SINCE_LAST_TIME_LESS_THAN,
OPERATION_EVERYONE_SINCE_LAST_TIME_IN_RANGE,
OPEARTION_BY_GROUP_SINCE_LAST_TIME_LARGER_THAN,
OPEARTION_BY_GROUP_SINCE_LAST_TIME_LESS_THAN,
OPEARTION_BY_GROUP_SINCE_LAST_TIME_IN_RANGE,

OPERATION_BATCH_SIZE_LARGER_THAN,
OPERATION_BATCH_SIZE_LESS_THAN,
OPERATION_BATCH_SIZE_IN_RANGE,
OPERATION_BATCH_SIZE_EQUALS,
PlaceHolder61,
PlaceHolder62,
PlaceHolder63,
PlaceHolder64,
PlaceHolder65,
PlaceHolder66,
PlaceHolder67,
PlaceHolder68,
PlaceHolder69,
PlaceHolder70,
PlaceHolder71,
PlaceHolder72,
PlaceHolder73,
PlaceHolder74,
PlaceHolder75,
PlaceHolder76,
PlaceHolder77,
PlaceHolder78,
PlaceHolder79,
PlaceHolder80,

// ----------------------------------------------------------
// Oracle and remote call related expressions
ORACLE_CALL_RESULT_EQUALS,
ORACLE_CALL_RESULT_LARGER_THAN,
ORACLE_CALL_RESULT_LESS_THAN,
ORACLE_CALL_RESULT_IN_RANGE,
ORACLE_CALL_1_LESS_THAN_2,
ORACLE_CALL_1_LARGER_THAN_2,
ORACLE_CALL_1_EQUALS_2,
PlaceHolder141,
PlaceHolder142,
PlaceHolder143,
PlaceHolder144,
PlaceHolder145,
PlaceHolder146,
PlaceHolder147,
PlaceHolder148,
PlaceHolder149,
PlaceHolder150,
ORACLE_CALL_UINT256_RESULT_EQUALS,
ORACLE_CALL_UINT256_RESULT_LARGER_THAN,
ORACLE_CALL_UINT256_RESULT_LESS_THAN,
ORACLE_CALL_UINT256_RESULT_IN_RANGE,
ORACLE_CALL_UINT256_1_LESS_THAN_2,
ORACLE_CALL_UINT256_1_LARGER_THAN_2,
ORACLE_CALL_UINT256_1_EQUALS_2,
ORACLE_CALL_STRING_RESULT_EQUALS,
ORACLE_CALL_STRING_1_EQUALS_2,
PlaceHolder81,
PlaceHolder82,
PlaceHolder83,
PlaceHolder84,
PlaceHolder85,
PlaceHolder86,
PlaceHolder87,
PlaceHolder88,
PlaceHolder89,
PlaceHolder90,
PlaceHolder91,
PlaceHolder92,
PlaceHolder93,
PlaceHolder94,
PlaceHolder95,
PlaceHolder96,
PlaceHolder97,
PlaceHolder98,
PlaceHolder99,
PlaceHolder100,


// ----------------------------------------------------------
Expand All @@ -184,33 +247,82 @@ enum EnumConditionExpression{
MINT_TOKENS_TOTAL_AMOUNT_LESS_THAN,
MINT_TOKENS_TOTAL_AMOUNT_IN_RANGE,
MINT_TOKENS_TOTAL_AMOUNT_EQUALS,
MINT_TOKENS_TARGET_ADDRESS_IN_LIST,

MINT_TOKENS_ALL_TARGETS_ADDRESS_IN_LIST,
MINT_TOKENS_ALL_TARGETS_ADDRESS_TO_ITSELF,
MINT_TOKENS_ALL_TARGETS_ADDRESS_TO_ROLE_INDEX_IN_LIST,
MINT_TOKENS_TOTAL_AMOUNT_LEVEL_X_MORE_THAN,
MINT_TOKENS_TOTAL_AMOUNT_LEVEL_X_LESS_THAN,
MINT_TOKENS_TOTAL_AMOUNT_LEVEL_X_IN_RANGE,
MINT_TOKENS_TOTAL_AMOUNT_LEVEL_X_EQUALS,
MINT_TOKENS_TOTAL_VOTING_WEIGHT_LARGER_THAN,
MINT_TOKENS_TOTAL_VOTING_WEIGHT_LESS_THAN,
MINT_TOKENS_TOTAL_VOTING_WEIGHT_IN_RANGE,
MINT_TOKENS_TOTAL_DIVIDEND_WEIGHT_LARGER_THAN,
MINT_TOKENS_TOTAL_DIVIDEND_WEIGHT_LESS_THAN,
MINT_TOKENS_TOTAL_DIVIDEND_WEIGHT_IN_RANGE,
MINT_TOKEN_EACH_BATCH_AMOUNT_MORE_THAN,
MINT_TOKEN_EACH_BATCH_AMOUNT_LESS_THAN,
MINT_TOKEN_EACH_BATCH_AMOUNT_IN_RANGE,
MINT_TOKEN_EACH_BATCH_AMOUNT_EQUALS,
MINT_TOKEN_EACH_BATCH_AMOUNT_LEVEL_X_MORE_THAN,
MINT_TOKEN_EACH_BATCH_AMOUNT_LEVEL_X_LESS_THAN,
MINT_TOKEN_EACH_BATCH_AMOUNT_LEVEL_X_IN_RANGE,
MINT_TOKEN_EACH_BATCH_AMOUNT_LEVEL_X_EQUALS,
MINT_TOKEN_EACH_BATCH_TARGET_ADDRESS_IN_LIST,
MINT_TOKEN_EACH_BATCH_TARGET_ADDRESS_TO_ROLE_INDEX_IN_LIST,

PlaceHolder101,
PlaceHolder102,
PlaceHolder103,
PlaceHolder104,
PlaceHolder105,
PlaceHolder106,
PlaceHolder107,
PlaceHolder108,
PlaceHolder109,
PlaceHolder110,
PlaceHolder111,
PlaceHolder112,
PlaceHolder113,
PlaceHolder114,
PlaceHolder115,
PlaceHolder116,
PlaceHolder117,
PlaceHolder118,
PlaceHolder119,
PlaceHolder120,



/**
* This condition expression will be ture if the current operation is
* minting new tokens in token class array to any addresses with
* the total voting weight larger than the amount X in the condition node.
* params: uint256 totalVotingWeight
*/
MINT_TOKEN_VOTING_WEIGHT_MORE_THAN,

/**
* This condition expression will be ture if the current operation is
* minting new tokens in token class array to any addresses with
* the total dividend weight larger than the amount X in the condition node.
* params: uint256 totalDividendWeight
*/
MINT_TOKEN_DIVIDEND_WEIGHT_MORE_THAN,


//-----------------------------------------------------------
// burn token related expressions
// ----------------------------------------------------------
// BURN token operation related expressions
BURN_TOKENS_TOTAL_AMOUNT_MORE_THAN,
BURN_TOKENS_TOTAL_AMOUNT_LESS_THAN,
BURN_TOKENS_TOTAL_AMOUNT_IN_RANGE,
BURN_TOKENS_TOTAL_AMOUNT_EQUALS,

BURN_TOKENS_ALL_TARGETS_ADDRESS_IN_LIST,
BURN_TOKENS_ALL_TARGETS_ADDRESS_TO_ITSELF,
BURN_TOKENS_ALL_TARGETS_ADDRESS_TO_ROLE_INDEX_IN_LIST,
BURN_TOKENS_TOTAL_AMOUNT_LEVEL_X_MORE_THAN,
BURN_TOKENS_TOTAL_AMOUNT_LEVEL_X_LESS_THAN,
BURN_TOKENS_TOTAL_AMOUNT_LEVEL_X_IN_RANGE,
BURN_TOKENS_TOTAL_AMOUNT_LEVEL_X_EQUALS,
BURN_TOKENS_TOTAL_VOTING_WEIGHT_LARGER_THAN,
BURN_TOKENS_TOTAL_VOTING_WEIGHT_LESS_THAN,
BURN_TOKENS_TOTAL_VOTING_WEIGHT_IN_RANGE,
BURN_TOKENS_TOTAL_DIVIDEND_WEIGHT_LARGER_THAN,
BURN_TOKENS_TOTAL_DIVIDEND_WEIGHT_LESS_THAN,
BURN_TOKENS_TOTAL_DIVIDEND_WEIGHT_IN_RANGE,
BURN_TOKEN_EACH_BATCH_AMOUNT_MORE_THAN,
BURN_TOKEN_EACH_BATCH_AMOUNT_LESS_THAN,
BURN_TOKEN_EACH_BATCH_AMOUNT_IN_RANGE,
BURN_TOKEN_EACH_BATCH_AMOUNT_EQUALS,
BURN_TOKEN_EACH_BATCH_AMOUNT_LEVEL_X_MORE_THAN,
BURN_TOKEN_EACH_BATCH_AMOUNT_LEVEL_X_LESS_THAN,
BURN_TOKEN_EACH_BATCH_AMOUNT_LEVEL_X_IN_RANGE,
BURN_TOKEN_EACH_BATCH_AMOUNT_LEVEL_X_EQUALS,
BURN_TOKEN_EACH_BATCH_TARGET_ADDRESS_IN_LIST,
BURN_TOKEN_EACH_BATCH_TARGET_ADDRESS_TO_ROLE_INDEX_IN_LIST,

// ----------------------------------------------------------
/**
Expand All @@ -226,6 +338,13 @@ enum EnumConditionExpression{
*/
TRANSFER_TOKEN_MORE_THAN,

/**
* This condition expression will be ture if:
* 1. the current operation is
* 2. transfering tokens to address is in address array



/**
* This condition expression will be ture if:
* 1. the current operation is
Expand Down
4 changes: 1 addition & 3 deletions darc-protocol/contracts/protocol/Plugin/Plugin.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.19;

import './EnumConditionExpression.sol';

/**
* @notice condition node types
*/
Expand Down Expand Up @@ -128,7 +126,7 @@ struct ConditionNode {
/**
* the condition expression of the current condition node
*/
EnumConditionExpression conditionExpression;
uint256 conditionExpression;

/**
* a list of the child nodes of the current condition node
Expand Down
4 changes: 2 additions & 2 deletions darc-protocol/test/MultiDARCTest/Multi_DARC_call_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe("test for multi DARC call test", function () {
node_allow_signer1_target1
],
votingRuleIndex: 0,
note: "0x70997970C51812dc3A010C7d01b50e0d17dc79C8 should operate",
notes: "0x70997970C51812dc3A010C7d01b50e0d17dc79C8 should operate",
bIsEnabled: true,
bIsInitialized: true,
bIsBeforeOperation: true,
Expand All @@ -91,7 +91,7 @@ describe("test for multi DARC call test", function () {
}],
}
)

// next get the ABI of the darc2 contract entrance, and encode it
//const abiDARC2 = darc2.interface.getFunction("entrance").format();

Expand Down
2 changes: 1 addition & 1 deletion darc-protocol/test/pluginTest/operator_AND_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const target2 = '0x90F79bf6EB2c4f870365E785982E1f101E93b906';

const target3 = '0x870526b7973b56163a6997bb7c886f5e4ea53638';

describe.only("operator OR test", function () {
describe("operator AND test", function () {
it ("should pass operator OR test", async function () {


Expand Down
Loading

0 comments on commit 037110a

Please sign in to comment.