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 23, 2023
2 parents f657bd2 + 20fbf86 commit 575621f
Show file tree
Hide file tree
Showing 35 changed files with 177 additions and 1,822 deletions.
2 changes: 1 addition & 1 deletion darc-js/src/SDK/includes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { TokenOperations } from "./struct/token-operation-map";
import { Plugin } from "./struct/Plugin";
import { OperationStruct } from "./struct/basicTypes";
import { OperationStruct } from "../types/basicTypes";

import { op_batch_mint_tokens } from "./opcodes/op_batch_mint_tokens";
import { op_batch_create_token_class } from "./opcodes/op_batch_create_token_class";
Expand Down
6 changes: 3 additions & 3 deletions darc-js/src/SDK/opcodes/op_batch_create_token_class.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from "ethers";
import {OperationStruct} from "../struct/basicTypes";
import {OperationStruct} from "../../types/basicTypes";

/**
* @notice Batch Create Token Class Operation
Expand Down Expand Up @@ -64,8 +64,8 @@ export function op_batch_create_token_class(
operatorAddress: "", // address will be filled in later
opcode: 2, // mint token
param: {
UINT256_ARRAY: [],
ADDRESS_ARRAY: [],


STRING_ARRAY: nameArray,
BOOL_ARRAY: [],
VOTING_RULE_ARRAY: [],
Expand Down
6 changes: 3 additions & 3 deletions darc-js/src/SDK/opcodes/op_batch_mint_tokens.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from "ethers";
import {OperationStruct} from "../struct/basicTypes";
import {OperationStruct} from "../../types/basicTypes";

export function op_batch_mint_tokens(addressArray: string[], tokenClass: bigint[], amountArray: bigint[]): OperationStruct {
// make sure the length of addressArray and amountArray are the same
Expand Down Expand Up @@ -45,8 +45,8 @@ export function op_batch_mint_tokens(addressArray: string[], tokenClass: bigint[
operatorAddress: "",
opcode: 1, // mint token
param: {
UINT256_ARRAY: [],
ADDRESS_ARRAY: [],


STRING_ARRAY: [],
BOOL_ARRAY: [],
VOTING_RULE_ARRAY: [],
Expand Down
2 changes: 1 addition & 1 deletion darc-js/src/SDK/runtime.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as instructions from "./includes";
import { ethers, Contract } from 'ethers';
import { OperationStruct, OperationStructOutput, ProgramStruct } from "./struct/basicTypes";
import { OperationStruct, OperationStructOutput, ProgramStruct } from "../types/basicTypes";
import * as DARC from "../DARC/DARC";


Expand Down
109 changes: 27 additions & 82 deletions darc-js/src/darcBinary/DARC-latest.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,25 @@ export type VotingRuleStructOutput = [
};

export type NodeParamStruct = {
UINT256_ARRAY: PromiseOrValue<BigNumberish>[];
ADDRESS_ARRAY: PromiseOrValue<string>[];
STRING_ARRAY: PromiseOrValue<string>[];
UINT256_2DARRAY: PromiseOrValue<BigNumberish>[][];
ADDRESS_2DARRAY: PromiseOrValue<string>[][];
STRING_2DARRAY: PromiseOrValue<string>[][];
BYTES: PromiseOrValue<BytesLike>;
};

export type NodeParamStructOutput = [
BigNumber[],
string[],
string[],
BigNumber[][],
string[][],
string[][]
string[][],
string
] & {
UINT256_ARRAY: BigNumber[];
ADDRESS_ARRAY: string[];
STRING_ARRAY: string[];
UINT256_2DARRAY: BigNumber[][];
ADDRESS_2DARRAY: string[][];
STRING_2DARRAY: string[][];
BYTES: string;
};

export type ConditionNodeStruct = {
Expand Down Expand Up @@ -125,8 +122,6 @@ export type PluginStructOutput = [
};

export type ParamStruct = {
UINT256_ARRAY: PromiseOrValue<BigNumberish>[];
ADDRESS_ARRAY: PromiseOrValue<string>[];
STRING_ARRAY: PromiseOrValue<string>[];
BOOL_ARRAY: PromiseOrValue<boolean>[];
VOTING_RULE_ARRAY: VotingRuleStruct[];
Expand All @@ -138,8 +133,6 @@ export type ParamStruct = {
};

export type ParamStructOutput = [
BigNumber[],
string[],
string[],
boolean[],
VotingRuleStructOutput[],
Expand All @@ -149,8 +142,6 @@ export type ParamStructOutput = [
string[][],
string
] & {
UINT256_ARRAY: BigNumber[];
ADDRESS_ARRAY: string[];
STRING_ARRAY: string[];
BOOL_ARRAY: boolean[];
VOTING_RULE_ARRAY: VotingRuleStructOutput[];
Expand Down
24 changes: 11 additions & 13 deletions darc-js/tests/basic-DARC-test/dashboard-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'mocha';
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545/');
import { DARC_VERSION, darcBinary } from '../../src/darcBinary/darcBinary';
import * as DARC from '../../src/DARC/DARC';
import { OperationStruct, ProgramStruct } from '../../src/SDK/struct/basicTypes';
import { OperationStruct, ProgramStruct } from '../../src/types/basicTypes';

describe('class DARC dashboard test',
() => {
Expand Down Expand Up @@ -52,8 +52,8 @@ describe('class DARC dashboard test',
operatorAddress: programOperatorAddress,
opcode: 1, // mint token
param: {
UINT256_ARRAY: [],
ADDRESS_ARRAY: [],


STRING_ARRAY: [],
BOOL_ARRAY: [],
VOTING_RULE_ARRAY: [],
Expand All @@ -72,9 +72,7 @@ describe('class DARC dashboard test',
{
operatorAddress: programOperatorAddress,
opcode: 3, // transfer tokens
param:{
UINT256_ARRAY: [],
ADDRESS_ARRAY: [],
param:{
STRING_ARRAY: [],
BOOL_ARRAY: [],
VOTING_RULE_ARRAY: [],
Expand All @@ -100,8 +98,8 @@ describe('class DARC dashboard test',
operatorAddress: programOperatorAddress,
opcode: 2, // create token class
param: {
UINT256_ARRAY: [],
ADDRESS_ARRAY: [],


STRING_ARRAY: ["Class1", "Class2"],
BOOL_ARRAY: [],
VOTING_RULE_ARRAY: [],
Expand All @@ -123,8 +121,8 @@ describe('class DARC dashboard test',
operatorAddress: programOperatorAddress,
opcode: 1, // mint token
param: {
UINT256_ARRAY: [],
ADDRESS_ARRAY: [],


STRING_ARRAY: [],
BOOL_ARRAY: [],
VOTING_RULE_ARRAY: [],
Expand All @@ -144,8 +142,8 @@ describe('class DARC dashboard test',
operatorAddress: programOperatorAddress,
opcode: 3, // transfer tokens
param:{
UINT256_ARRAY: [],
ADDRESS_ARRAY: [],


STRING_ARRAY: [],
BOOL_ARRAY: [],
VOTING_RULE_ARRAY: [],
Expand Down Expand Up @@ -181,7 +179,7 @@ describe('class DARC dashboard test',
// check the number of token classes. If it is 0, then create a token class first
const token_class_count = await attached_local_darc2.getNumberOfTokenClasses();

console.log("token_class_count: " + token_class_count.toString());
//console.log("token_class_count: " + token_class_count.toString());

console.log(token_class_count.toString() === "0");
if (token_class_count.toString() === "0") {
Expand Down
24 changes: 12 additions & 12 deletions darc-js/tests/basic-DARC-test/deploy-DARC-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ethers} from 'ethers';
import { expect } from 'chai';
import { deployDARC } from '../../src/deployDARC/deployDARC';
import {ProgramStruct} from '../../src/SDK/struct/basicTypes';
import {ProgramStruct} from '../../src/types/basicTypes';

import 'mocha';
//import { setTimeout } from "timers/promises";
Expand Down Expand Up @@ -53,8 +53,8 @@ describe('class DARC test',
operatorAddress: programOperatorAddress,
opcode: 1, // mint token
param: {
UINT256_ARRAY: [],
ADDRESS_ARRAY: [],


STRING_ARRAY: [],
BOOL_ARRAY: [],
VOTING_RULE_ARRAY: [],
Expand All @@ -74,8 +74,8 @@ describe('class DARC test',
operatorAddress: programOperatorAddress,
opcode: 3, // transfer tokens
param:{
UINT256_ARRAY: [],
ADDRESS_ARRAY: [],


STRING_ARRAY: [],
BOOL_ARRAY: [],
VOTING_RULE_ARRAY: [],
Expand All @@ -101,8 +101,8 @@ describe('class DARC test',
operatorAddress: programOperatorAddress,
opcode: 2, // create token class
param: {
UINT256_ARRAY: [],
ADDRESS_ARRAY: [],


STRING_ARRAY: ["Class1", "Class2"],
BOOL_ARRAY: [],
VOTING_RULE_ARRAY: [],
Expand All @@ -124,8 +124,8 @@ describe('class DARC test',
operatorAddress: programOperatorAddress,
opcode: 1, // mint token
param: {
UINT256_ARRAY: [],
ADDRESS_ARRAY: [],


STRING_ARRAY: [],
BOOL_ARRAY: [],
VOTING_RULE_ARRAY: [],
Expand All @@ -145,8 +145,8 @@ describe('class DARC test',
operatorAddress: programOperatorAddress,
opcode: 3, // transfer tokens
param:{
UINT256_ARRAY: [],
ADDRESS_ARRAY: [],


STRING_ARRAY: [],
BOOL_ARRAY: [],
VOTING_RULE_ARRAY: [],
Expand Down Expand Up @@ -182,7 +182,7 @@ describe('class DARC test',
// check the number of token classes. If it is 0, then create a token class first
const token_class_count = await attached_local_darc2.getNumberOfTokenClasses();

console.log("token_class_count: " + token_class_count.toString());
//console.log("token_class_count: " + token_class_count.toString());

console.log(token_class_count.toString() === "0");
if (token_class_count.toString() === "0") {
Expand Down
2 changes: 1 addition & 1 deletion darc-js/tests/runtime-test/basic-runtime-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Runtime execution test', () => {
it('should run the program', async () => {
const darc_contract_address = await deployDARC(DARC_VERSION.Latest, signer);

await run(code, signer, darc_contract_address).then(async ()=>{
await run(code, signer, darc_contract_address, DARC_VERSION.Latest).then(async ()=>{

const attached_local_darc2 = new DARC.DARC({
address: darc_contract_address,
Expand Down
5 changes: 2 additions & 3 deletions darc-protocol/contracts/protocol/MachineStateManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,11 @@ contract MachineStateManager {
EnumConditionExpression.UNDEFINED,
new uint256[](0),
NodeParam(
new uint256[](0),
new address[](0),
new string[](0),
new uint256[][](0),
new address[][](0),
new string[][](0)
new string[][](0),
new bytes(0)
)
);
currentMachineState.beforeOpPlugins.push(Plugin(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract ConditionExpressionFactory is
return false;//exp_OPERATOR_NAME_EQUALS(bIsBeforeOperation, operation, paramList);
}
else if (exp == EnumConditionExpression.OPERATOR_ADDRESS_EQUALS) {
return exp_OPERATOR_ADDRESS_EUQALS(bIsBeforeOperation, operation, param);
return exp_OPERATOR_ADDRESS_EQUALS(bIsBeforeOperation, operation, param);
}

// default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ contract OperatorExpressionFunctions is MachineStateManager {
* 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) {
//get the uint256 value of the first parameter
uint256 paramOpcodeID = param.UINT256_ARRAY[0];
//get the uint256 value of the UINT256_2DARRAY[0][0]
uint256 paramOpcodeID = param.UINT256_2DARRAY[0][0];
// compare
return OpcodeMap.opcodeVal(operation.opcode) == paramOpcodeID;
}
Expand All @@ -52,7 +52,7 @@ contract OperatorExpressionFunctions is MachineStateManager {
* @param param: the parameters of the condition node.
* This is function to check if the operator name of the current/sandbox machine state is equal to the operator name of the condition node
*/
function exp_OPERATOR_NAME_EQUALS(bool bIsBeforeOperation, Operation memory operation, Param memory param) internal view returns (bool) {
function exp_OPERATOR_NAME_EQUALS(bool bIsBeforeOperation, Operation memory operation, NodeParam memory param) internal view returns (bool) {
// get operator address from opeartion
address operatorAddress = operation.operatorAddress;

Expand All @@ -72,12 +72,12 @@ contract OperatorExpressionFunctions is MachineStateManager {
* @param param: the parameters of the condition node.
* This is function to check if the operator role of the current/sandbox machine state is equal to the operator role of the condition node
*/
function exp_OPERATOR_ROLE_INDEX_EQUALS(bool bIsBeforeOperation, Operation memory operation, Param memory param) internal view returns (bool) {
function exp_OPERATOR_ROLE_INDEX_EQUALS(bool bIsBeforeOperation, Operation memory operation, NodeParam memory param) internal view returns (bool) {
// get the operator address from the operation
address operatorAddress = operation.operatorAddress;

//get the uint256 value of the first parameter
uint256 currentOperatorRole = param.UINT256_ARRAY[0];
//get the uint256 value of the UINT256_2DARRAY[0][0]
uint256 currentOperatorRole = param.UINT256_2DARRAY[0][0];
if (bIsBeforeOperation) {
return currentMachineState.memberInfoMap[operatorAddress].role == currentOperatorRole;
} else {
Expand All @@ -92,7 +92,7 @@ contract OperatorExpressionFunctions is MachineStateManager {
* @param param: the parameters of the condition node.
* This is function to check if the operator address is equal to the operator role of the condition node
*/
function exp_OPERATOR_ADDRESS_EUQALS(bool bIsBeforeOperation, Operation memory operation, NodeParam memory param) internal view returns (bool) {
function exp_OPERATOR_ADDRESS_EQUALS(bool bIsBeforeOperation, Operation memory operation, NodeParam memory param) internal view returns (bool) {
// the address is the ADDRESS_2DARRAY[0][0]
require (param.ADDRESS_2DARRAY.length == 1, "Operator address is not provided");
require(param.ADDRESS_2DARRAY[0].length == 1, "Operator address is not provided");
Expand Down
5 changes: 3 additions & 2 deletions darc-protocol/contracts/protocol/Plugin/Plugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ enum EnumPluginParamType {
* Each expression node has a list of uint256,
*/
struct NodeParam {
uint256[] UINT256_ARRAY;
address[] ADDRESS_ARRAY;
// uint256[] UINT256_ARRAY;
// address[] ADDRESS_ARRAY;
string[] STRING_ARRAY;
uint256[][] UINT256_2DARRAY;
address[][] ADDRESS_2DARRAY;
string[][] STRING_2DARRAY;
bytes BYTES;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions darc-protocol/contracts/protocol/Program.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ enum MachineParameter{
}

struct Param{
uint256[] UINT256_ARRAY;
address[] ADDRESS_ARRAY;
// uint256[] UINT256_ARRAY;
// address[] ADDRESS_ARRAY;
string[] STRING_ARRAY;
bool[] BOOL_ARRAY;
VotingRule[] VOTING_RULE_ARRAY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ contract DelegateCallTest {
operatorAddress: address(this),
opcode: EnumOpcode.BATCH_CREATE_TOKEN_CLASSES,
param: Param({
UINT256_ARRAY: new uint256[](0),
ADDRESS_ARRAY: new address[](0),
STRING_ARRAY: new string[](0),
BOOL_ARRAY: new bool[](0),
VOTING_RULE_ARRAY: new VotingRule[](0),
Expand Down
Loading

0 comments on commit 575621f

Please sign in to comment.