Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lidangzzz committed May 18, 2023
1 parent 0221046 commit ae8e2ee
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 11 deletions.
32 changes: 32 additions & 0 deletions darc-protocol/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# DARC Protocol

This is the core protocol for the DARC(Decentralized Autonomous Regulated Corporation) project.

## Installation

Since Hardhat does not support any package management tools except npm, you need to use npm only to install the dependencies.

To install all dependencies, run the following command:

```bash
npm install
```

## Compile

To compile the contracts, run the following command:

```bash
npx hardhat compile
```

The compiled contracts will be stored in the `artifacts` directory.

## Test

To run the tests, run the following command:

```bash
npx hardhat test
```

24 changes: 23 additions & 1 deletion darc-protocol/contracts/Dashboard/Dashboard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,32 @@ contract Dashboard is MachineStateManager {
/**
* @notice Get the current dividend balance of the address
*/
function getWithdrawableCash(address member) public view returns (uint256) {
function getWithdrawableCashBalance(address member) public view returns (uint256) {
return currentMachineState.withdrawableCashMap[member];
}

/**
* @notice Get the current list of the addresses that can withdraw the dividend
*/
function getWithdrawableCashOwnerList() public view returns (address[] memory) {
return currentMachineState.withdrawableCashOwnerList;
}

/**
* @notice Get the current dividend balance of the address
* @param member the address of the member
*/
function getWithdrawableDividendBalance(address member) public view returns (uint256) {
return currentMachineState.withdrawableDividendMap[member];
}

/**
* @notice Get the current list of the addresses that can withdraw the dividend
*/
function getWithdrawableDividendOwnerList() public view returns (address[] memory) {
return currentMachineState.withdrawableDividendOwnerList;
}

function getMyInfo() public view returns (address) {
return msg.sender;
}
Expand Down
4 changes: 2 additions & 2 deletions darc-protocol/contracts/MachineState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ struct MachineState {
* Cash withdrawal balance mapping,
* the withdrawal balance of each token owner as cash (ETH, BNB, Polygon, etc.)
*/
mapping (address => uint256) withdrawableDividendsMap;
mapping (address => uint256) withdrawableDividendMap;

/**
* The list of cash withdrawal owners
*/
address[] withdrawableDividendsOwnerList;
address[] withdrawableDividendOwnerList;

/**
* The history log of approved operations for each address
Expand Down
16 changes: 8 additions & 8 deletions darc-protocol/contracts/MachineStateManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -219,20 +219,20 @@ contract MachineStateManager {

// 7. Clone the wirhdarwable dividends from sandbox to current machine state
// 7.1 clean all value in sandbox
for (uint256 i = 0; i < sandboxMachineState.withdrawableDividendsOwnerList.length; i++) {
delete sandboxMachineState.withdrawableDividendsMap[sandboxMachineState.withdrawableDividendsOwnerList[i]];
for (uint256 i = 0; i < sandboxMachineState.withdrawableDividendOwnerList.length; i++) {
delete sandboxMachineState.withdrawableDividendMap[sandboxMachineState.withdrawableDividendOwnerList[i]];
}

// 7.2 copy the withdrawable dividends owner list from current machine state to sandbox
sandboxMachineState.withdrawableDividendsOwnerList = new address[](currentMachineState.withdrawableDividendsOwnerList.length);
for (uint256 i = 0; i < currentMachineState.withdrawableDividendsOwnerList.length; i++) {
sandboxMachineState.withdrawableDividendsOwnerList[i] = currentMachineState.withdrawableDividendsOwnerList[i];
sandboxMachineState.withdrawableDividendOwnerList = new address[](currentMachineState.withdrawableDividendOwnerList.length);
for (uint256 i = 0; i < currentMachineState.withdrawableDividendOwnerList.length; i++) {
sandboxMachineState.withdrawableDividendOwnerList[i] = currentMachineState.withdrawableDividendOwnerList[i];
}

// 7.3 copy the withdrawable dividends map from current machine state to sandbox
for (uint256 i = 0; i < currentMachineState.withdrawableDividendsOwnerList.length; i++) {
sandboxMachineState.withdrawableDividendsMap[currentMachineState.withdrawableDividendsOwnerList[i]]
= currentMachineState.withdrawableDividendsMap[currentMachineState.withdrawableDividendsOwnerList[i]];
for (uint256 i = 0; i < currentMachineState.withdrawableDividendOwnerList.length; i++) {
sandboxMachineState.withdrawableDividendMap[currentMachineState.withdrawableDividendOwnerList[i]]
= currentMachineState.withdrawableDividendMap[currentMachineState.withdrawableDividendOwnerList[i]];
}

}
Expand Down

0 comments on commit ae8e2ee

Please sign in to comment.