Skip to content

Commit

Permalink
Merge branch 'plugin-dev-planning'
Browse files Browse the repository at this point in the history
  • Loading branch information
lidangzzz committed Dec 28, 2023
2 parents 575621f + 037110a commit 3e60425
Show file tree
Hide file tree
Showing 76 changed files with 2,052 additions and 457 deletions.
6 changes: 3 additions & 3 deletions darc-js/src/SDK/struct/Plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { ConditionNode } from "../plugins/ConditionNode";
import { VotingParameters } from "./voting-param";

class Plugin {
note: string;
notes: string;
conditionExpressionTreeRootNode: ConditionNode;
restrictionPluginReturnType: RestrictionPluginReturnType;
votingParameters: VotingParameters | null;
restrictionPluginType: RestrictionPluginType;
constructor(note: string, conditionExpressionTreeRootNode: ConditionNode, restrictionPluginReturnType: RestrictionPluginReturnType, votingParameters: VotingParameters | null, restrictionPluginType: RestrictionPluginType) {
this.note = note;
constructor(inputNotes: string, conditionExpressionTreeRootNode: ConditionNode, restrictionPluginReturnType: RestrictionPluginReturnType, votingParameters: VotingParameters | null, restrictionPluginType: RestrictionPluginType) {
this.notes = inputNotes;
this.conditionExpressionTreeRootNode = conditionExpressionTreeRootNode;
this.restrictionPluginReturnType = restrictionPluginReturnType;
this.votingParameters = votingParameters;
Expand Down
39 changes: 7 additions & 32 deletions darc-js/src/darcBinary/DARC-latest.json

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions darc-js/src/types/basicTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export type NodeParamStruct = {
STRING_ARRAY: PromiseOrValue<string>[];
UINT256_2DARRAY: PromiseOrValue<BigNumberish>[][];
ADDRESS_2DARRAY: PromiseOrValue<string>[][];
STRING_2DARRAY: PromiseOrValue<string>[][];
BYTES: PromiseOrValue<BytesLike>;
};

Expand All @@ -61,7 +60,6 @@ export type NodeParamStructOutput = [
STRING_ARRAY: string[];
UINT256_2DARRAY: BigNumber[][];
ADDRESS_2DARRAY: string[][];
STRING_2DARRAY: string[][];
BYTES: string;
};

Expand Down Expand Up @@ -95,7 +93,7 @@ export type PluginStruct = {
level: PromiseOrValue<BigNumberish>;
conditionNodes: ConditionNodeStruct[];
votingRuleIndex: PromiseOrValue<BigNumberish>;
note: PromiseOrValue<string>;
notes: PromiseOrValue<string>;
bIsEnabled: PromiseOrValue<boolean>;
bIsInitialized: PromiseOrValue<boolean>;
bIsBeforeOperation: PromiseOrValue<boolean>;
Expand All @@ -115,7 +113,7 @@ export type PluginStructOutput = [
level: BigNumber;
conditionNodes: ConditionNodeStructOutput[];
votingRuleIndex: BigNumber;
note: string;
notes: string;
bIsEnabled: boolean;
bIsInitialized: boolean;
bIsBeforeOperation: boolean;
Expand Down
2 changes: 1 addition & 1 deletion darc-js/tests/runtime-test/pressure-mint-token-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('Pressure mint token execution test', () => {

const token_owner_balance = await attached_local_darc2.getTokenOwnerBalance(BigInt(0),my_wallet_address);

console.log("token_info", token_owner_balance);
//console.log("token_info", token_owner_balance);
expect(token_owner_balance.toString()).to.equal("100000");
});
}
Expand Down
2 changes: 1 addition & 1 deletion darc-protocol/contracts/protocol/DARC.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.9;
pragma solidity ^0.8.19;

import "./Runtime/Runtime.sol";
import "./Program.sol";
Expand Down
2 changes: 1 addition & 1 deletion darc-protocol/contracts/protocol/Dashboard/Dashboard.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.9;
pragma solidity ^0.8.19;

import "../Runtime/Runtime.sol";

Expand Down
2 changes: 1 addition & 1 deletion darc-protocol/contracts/protocol/MachineState.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.9;
pragma solidity ^0.8.19;
import "./Program.sol";
import "./Plugin/Plugin.sol";
/**
Expand Down
50 changes: 40 additions & 10 deletions darc-protocol/contracts/protocol/MachineStateManager.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.9;
pragma solidity ^0.8.19;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "./MachineState.sol";
import "./Plugin/Plugin.sol";
Expand Down Expand Up @@ -83,38 +83,68 @@ contract MachineStateManager {
dividendBufferSize = 10000;

/**
* Todo:
* 1. create a plugin that allows all the operation by the initial owner address
* We need to initialze the first plugin for both before operation
* plugin system and after operation plugin system.
*
* Before-op Rule: If the operation is executed by the initial owner, then skip the plugin system
* After-op Rule: If the operation is executed by the initial owner, then approve the operation
*
* Level: both before-op and after-op plugin system, level 1, the lowest level
*/
ConditionNode[] memory conditionNodes = new ConditionNode[](1);
conditionNodes[0] = ConditionNode(
0,
EnumConditionNodeType.BOOLEAN_TRUE, //todo: change to "operator==tx.origin"
EnumConditionNodeType.BOOLEAN_TRUE,
EnumLogicalOperatorType.UNDEFINED,
EnumConditionExpression.UNDEFINED,

// expression: operation == initialOwnerAddress
0,
new uint256[](0),
NodeParam(
new string[](0),
new uint256[][](0),

// leave the address 2d array as 1x1
new address[][](0),
new string[][](0),
new bytes(0)
)
);


currentMachineState.beforeOpPlugins.push(Plugin(
EnumReturnType.YES_AND_SKIP_SANDBOX,
1, //todo: change it back to 1
1, //YES_AND_SKIP_SANDBOX can be set to level%3 == 1
conditionNodes,
0,
"",
true,
true,
true
));

ConditionNode[] memory conditionNodes_afterOp = new ConditionNode[](1);
conditionNodes_afterOp[0] = ConditionNode(
0,
EnumConditionNodeType.BOOLEAN_TRUE,
EnumLogicalOperatorType.UNDEFINED,

// expression: operation == initialOwnerAddress
0,
new uint256[](0),
NodeParam(
new string[](0),
new uint256[][](0),

// leave the address 2d array as 1x1
new address[][](0),
//new string[][](0),
new bytes(0)
)
);
currentMachineState.afterOpPlugins.push(Plugin(
EnumReturnType.NO,
1, // todo: change it back to 1
conditionNodes,
EnumReturnType.YES, //
1, // YES can be set to level%3 == 1
conditionNodes_afterOp,
0,
"",
true,
Expand Down
5 changes: 3 additions & 2 deletions darc-protocol/contracts/protocol/Opcodes.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.9;
pragma solidity ^0.8.19;


/*
Expand Down 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 All @@ -278,7 +279,7 @@ enum EnumOpcode {

/**
* @notice Add storage IPFS hash to the storage list permanently
* @paran STRING_2DARRAY[0] address: the address to set approval for all cash withdraw operations
* @paran STRING_ARRAY[0][0] address: the address to set approval for all cash withdraw operations
* ID:31
*/
ADD_STORAGE_IPFS_HASH,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.9;


import "../MachineState.sol";

pragma solidity ^0.8.19;
import "../MachineState.sol";
import "../MachineStateManager.sol";
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 @@ -42,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 @@ -52,13 +48,13 @@ contract ConditionExpressionFactory is
currentMachineState.afterOpPlugins[pluginIndex].conditionNodes[nodeIndex].param;

// check the condition expression node
if (exp == EnumConditionExpression.OPERATION_NAME_EQUALS) {
return exp_OPERATION_NAME_EQUALS(operation, param);
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
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.9;
pragma solidity ^0.8.19;
/**
* @title ConditionExpressionFunctions
* @author DARC Team
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.9;
pragma solidity ^0.8.19;
/**
* @title ConditionExpressionFunctions
* @author DARC Team
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.9;
pragma solidity ^0.8.19;
/**
* @title MintTokensExpressionFunctions
* @author DARC Team
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.9;
pragma solidity ^0.8.19;
/**
* @title ConditionExpressionFunctions
* @author DARC Team
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.9;
pragma solidity ^0.8.19;
/**
* @title ConditionExpressionFunctions
* @author DARC Team
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.9;
pragma solidity ^0.8.19;
/**
* @title ConditionExpressionFunctions
* @author DARC Team
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.9;
pragma solidity ^0.8.19;
/**
* @title ConditionExpressionFunctions
* @author DARC Team
Expand Down Expand Up @@ -38,7 +38,7 @@ contract OperatorExpressionFunctions is MachineStateManager {
* The first parameter is the opcode ID (in uint256) of the condition node
* This is function to check if the opcode of the current/sandbox machine state is equal to the opcode of the condition node
*/
function exp_OPERATION_NAME_EQUALS(Operation memory operation, NodeParam memory param) internal pure returns (bool) {
function exp_OPERATION_EQUALS(Operation memory operation, NodeParam memory param) internal pure returns (bool) {
//get the uint256 value of the UINT256_2DARRAY[0][0]
uint256 paramOpcodeID = param.UINT256_2DARRAY[0][0];
// compare
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.9;
pragma solidity ^0.8.19;
/**
* @title ConditionExpressionFunctions
* @author DARC Team
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.9;
pragma solidity ^0.8.19;
/**
* @title ConditionExpressionFunctions
* @author DARC Team
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.9;
pragma solidity ^0.8.19;
/**
* @title ConditionExpressionFunctions
* @author DARC Team
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.9;
pragma solidity ^0.8.19;
/**
* @title ConditionExpressionFunctions
* @author DARC Team
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.9;
pragma solidity ^0.8.19;
/**
* @title TransferTokenExpressionFunctions
* @author DARC Team
Expand Down
Loading

0 comments on commit 3e60425

Please sign in to comment.