Skip to content

Commit 985bccb

Browse files
Yan DevYan Dev
authored andcommitted
update final touches from final project repo;
1 parent eb8ad48 commit 985bccb

File tree

159 files changed

+18079
-7628
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+18079
-7628
lines changed

.DS_Store

0 Bytes
Binary file not shown.

README.md

Lines changed: 87 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
## Virtual Power Plant (VPP) DApp
2-
### VPP DApp is a sample implementation of a Virtual Power Plant based on a fleet of distributed battery resources which are managed by an investment fund.
3-
##### Consensys Course Final Project
4-
##### Author: Yan Man
2+
#### VPP DApp is a sample implementation of a Virtual Power Plant based on a fleet of distributed battery resources which are managed by an investment fund.
3+
###### Consensys Course Final Project
4+
Author: [Yan Man](https://github.com/yan-man)
55

6-
### Overview:
6+
### I. Overview:
77

88
Although customers typically pay a flat energy rate for electricity throughout the day, energy prices in actuality fluctuate drastically depending on real time aggregate energy demand. Due to the unpredictability of real time demand, along with insufficient implementation and availability of large scale energy storage resources, energy response must be managed on a minute by minute basis. Electricity generators respond by turning on so called "Peaker" plants, which are convenient for short term energy generation but are also typically the most [environmentally damaging.](https://www.gogriddy.com/blog/renewable-energy/to-use-clean-energy-avoid-pollution-spewing-peaker-plants/)
99

1010
With flexible energy storage resources such as batteries, energy can be stored when real time energy demand is low, and discharged to the grid when demand, and prices, are high. This serves to effectively smooth the aggregated demand curve throughout the day, improving grid efficiency and stability as well as creating profit through energy trading.
1111

12-
### Example Usage:
13-
In JavaScript, create a VirtualPowerPlant contract from its artifact. You can then begin to interact with its contract functions directly. Remember to invest into the account before adding batteries to the array.
12+
##### Example Usage:
13+
In JavaScript, create a VirtualPowerPlant contract from its artifact. You can then begin to interact with its contract functions directly via JS. Make sure there are sufficient funds invested before adding batteries to the array.
1414

1515
```
1616
VirtualPowerPlant = TruffleContract(VirtualPowerPlantArtifact);
@@ -26,86 +26,118 @@ VirtualPowerPlant.addBattery(
2626

2727
Otherwise, interact with the DApp via the frontend included, which will allow you to invest funds, add batteries, and execute energy transactions.
2828

29-
### Getting Started
29+
### II. Getting Started
3030
#### Required installations:
3131

32-
Install the following packages:
32+
Install the following packages. DApp was developed in the following versions in a [Ubuntu64 18.04](https://www.ubuntu.com/download/desktop) environment.
3333

34-
1. [Truffle v5.0](https://truffleframework.com/docs/truffle/getting-started/installation)
35-
2. [Ganache](https://truffleframework.com/docs/ganache/quickstart)
36-
3. [NPM](https://www.npmjs.com/get-npm)
37-
4. [Lite-Server](https://www.npmjs.com/package/lite-server)
34+
1. [Truffle v5.0.2 (core: 5.0.2)](https://truffleframework.com/docs/truffle/getting-started/installation)
35+
2. [Ganache CLI v6.2.3 (ganache-core: 2.3.1)](https://truffleframework.com/docs/ganache/quickstart)
36+
3. [npm v3.5.2](https://www.npmjs.com/get-npm)
37+
4. [Node v8.10.0](https://nodejs.org/en/)
3838
5. [MetaMask](https://metamask.io/)
39-
Solidity
40-
41-
This DApp was developed in Ubuntu64 16.04 VM environment.
39+
6. [Solidity v0.5.0 (solc-js)](https://solidity.readthedocs.io/en/v0.5.3/)
4240

4341
#### To run:
4442

4543
VPP-Dapp is a truffle project that contains all necessary contract, library, migration and test files. Execute via command line:
4644

47-
1. Clone the repo to your directory
45+
1. Clone the repo to your directory.
46+
47+
```
48+
$ git clone
49+
```
4850
49-
2. In a separate terminal, start ganache development blockchain on port 7545. Create 10 funded accounts
51+
2. In a separate terminal, start ganache development blockchain on port 7545. Create 10 funded accounts.
5052
5153
```
52-
> ganache-cli -p 7545
54+
Terminal 2:
55+
$ ganache-cli -p 7545
5356
```
57+
3. In the first terminal, navigate to the project directory. Test the contract functions via `JavaScript` tests. There are 6 tests, which should pass.
5458
55-
3. In the original terminal, navigate to the project directory. Migrate and compile the Truffle contract to generate the ABI and deploy to the dev blockchain
59+
```
60+
Terminal 1:
61+
$ truffle test
62+
```
63+
3. Migrate and compile the Truffle contract to generate the ABI and deploy the contract to the dev blockchain.
5664
57-
4. Test the contract functions via js tests. All tests should pass
65+
```
66+
$ truffle migrate --reset
67+
```
5868
59-
5. Make sure `MetaMask` is installed. Open `MetaMask` in your Chrome browser and import the development accounts created by `ganache`. Only one address is required to test the DApp.
69+
5. Make sure `MetaMask` is installed. Open `MetaMask` in your Chrome browser and set the network connection to `Custom RPC` and the target RPC url to `http://127.0.0.1:7545` to access the `ganache-cli` accounts. Only one address is required to test the DApp.
6070
61-
6. Start the front end server on ```localhost:3000```
71+
6. Start the front end server on ```localhost:3000``` by using:
6272
6373
```
64-
> git clone
65-
> truffle migrate --reset
66-
> truffle test
67-
> npm run dev
74+
$ npm run dev
6875
```
6976
7077
#### Frontend Interaction:
7178
72-
The first development account (`account[0]`) is used to deploy the parent contract `VirtualPowerPlant.sol`. This address will also be an `admin` and the `owner`. Only one development account is required.
73-
74-
In `MetaMask`, set the connection to `Custom RPC` and the target RPC url to http://127.0.0.1:7545 to access the `ganache-cli` accounts.
79+
The first development account (`account[0]`) is used to deploy the parent contract `VirtualPowerPlant.sol`. This address will also be an `admin` and the `owner`. Only one development account is required for the demo.
7580
7681
To test the DApp, follow instructions on the `index.html` homepage.
7782
7883
1. Start by investing some amount of Eth (around ~50 Eth should be sufficient) into the battery fund by filling in the form input. Click `Invest` to proceed.
7984
80-
2. Once the transaction has been accepted, you can start adding batteries to the fleet. Sample battery options are listed and available, select a few to add by clicking `Add to array`.
85+
2. Once the transaction has been accepted, you can start adding batteries to the fleet. Sample battery options are listed and available, select a few to add by clicking `Add to array` under each battery panel. Make sure you are in the
86+
87+
3. Charge or discharge batteries and execute transactions by clicking `Execute Energy Transactions`. This will update battery charge currently filled and determine whether to charge (green) or discharge (red) the battery to the grid. Remaining investment will be updated to reflect the savings/cost of energy transacted.
88+
89+
90+
91+
### III. Detailed Usage
92+
93+
#### User roles:
8194
82-
3. Charge or discharge batteries by clicking `Execute Energy Transactions`. This will update battery charge currently filled and determine whether to charge (green) or discharge (red) the battery to the grid. Remaining investment will be updated to reflect the savings/cost of energy transacted.
95+
##### 1) Admin
96+
`admin` users are the only ones allowed to perform crucial functions. The initial account that deploys `VirtualPowerPlant.sol` is the `owner` and the first `admin`, and is able to set up other `admins`. `admins` are responsible for performing two main functions:
97+
- Managing batteries: This consists of adding batteries to the fleet and decommissioning them when necessary.
98+
- Managing investments: triggering dividends to pay investors, and distributing the dividends into withdrawal pools for investors to withdraw from.
8399
84-
### Detailed Usage
100+
##### 2) Investors
101+
Investors are composed of any other accounts that want to contribute eth to the fund. Anyone can be an investor, and investors are eligible for dividends that are paid in proportion to the amount of funds invested.
85102
86-
#### Contract Functions / Business Logic:
87-
##### VirtualPowerPlant.sol
88-
- `isAdmin`: check address is an admin
103+
#### Battery-related Assumptions/Calculations:
104+
- A very simple threshold was used to determine whether energy should be purchased or sold, ie if prices were more expensive than the battery's threshold, energy was sold to the grid. Otherwise, energy was purchased.
105+
106+
- The real time energy price was hardcoded to simplify the transaction process. Ideally, it would be connected to an outside Oracle to report the actual, fluctuating real time energy rate.
107+
108+
- The actual energy transaction was simplified. Whereas in reality, a separate contract might have to be implemented to manage energy transactions between the grid and outside suppliers, in this DApp energy was assumed to be traded instantaneously and available immediately.
109+
110+
- Batteries were assumed to have charged instantaneously, with minimal restrictions on battery performance. In reality, charge frequency and other factors would add vastly more constraints.
111+
112+
- Decisions on whether to purchase or sell energy were based on a simple threshold. If energy prices are expensive (ie greater than the battery's price threshold), sell energy to the grid to make a profit. Otherwise purchase energy to charge the battery.
113+
114+
#### Relevant Contract Functions:
115+
##### 1) VirtualPowerPlant.sol
116+
- `isAdmin`: check address is an admin user
89117
- `setAdmin`: set admin to active or inactive
90118
- `toggleContractActive`: to implement circuit breaker design
91-
- `addBattery`: add battery to fleet based on battery characteristics/serial number
92-
- `chargeBattery`: charge battery, ie alter battery state based on amount charged
93-
- `changeBatteryThreshold`: alter battery characteristics
94-
- `decommissionBattery`: render batteries inactive
95-
###### Battery getter functions:
119+
120+
- `addBattery`: add Battery struct to fleet, composed of multiple battery characteristics. Battery
121+
- `decommissionBattery`: render battery inactive (no charging/discharging)
122+
- `chargeBattery`: charge battery, ie alter battery state based on amount charged/discharged
123+
- `changeBatteryThreshold`: alter battery threshold characteristics (affects decision making on energy purchases)
124+
125+
**Battery info getter functions:**
96126
- `getRelevantBatteryInfo`
97127
- `getBatteryChargeRate`
98128
- `getBatteryMapIndex`
99129
100-
##### BatteryInvestment.sol
130+
##### 2) BatteryInvestment.sol
101131
- `updateRemainingInvestment`: update amount of remaining eth in fund
102132
- `investMoney`: ensure Eth is attached when calling this function
103133
- `triggerDividend`: admins can implement a dividend to send payment to investors
104134
- `withdraw`: for investors to retrieve their dividend withdrawal
105135
- `getInvestorInvestment`: getter function to retrieve investment amount for particular investor
106136
107-
##### BatteryEnergy.sol
137+
##### 3) BatteryEnergy.sol
108138
- `checkBatteryEnergy`: loop over batches of batteries, check transaction circumstances for each. Transact energy as required, update the investment fund with profits/energy purchases.
139+
- `getRealTimeEnergyPrice`: hardcoded for this demo. Retrieves the current energy rate on the real time market.
140+
- `energyDecisionAlgorithm`: determines whether to purchase energy or sell it to the grid, based on a simple threshold.
109141
110142
#### Tests:
111143
@@ -123,3 +155,16 @@ Contract tests were written in JavaScript
123155
1. [SafeMath](https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/SafeMath.sol): Use battle tested math functions to avoid overflow errors, etc
124156
2. [Math](https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/Math.sol): Other basic math functions
125157
3. [Ownable](https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/ownership/Ownable.sol): Inherit ownership properties
158+
159+
#### Further
160+
- **[Oraclize](https://docs.oraclize.it/)**: There are two obvious ways to improve this contract implementation -
161+
162+
- Run energy transactions every hour or on a regular time interval. This removes the manual component of transactions.
163+
164+
- Find the actual real time energy price during each transaction. Currently this energy rate was hard coded to a sample value.
165+
166+
- **Energy optimization algorithm**: A very basic threshold was used to determine energy transactions. In reality, energy prices in the context of the market demand and recent history are more important. A more robust optimization algorithm should be used.
167+
168+
- **Battery modeling**: battery characteristics were simplified and and modeled in an elementary manner. Charging/discharging was assumed to be instantaneous, and internal battery chemistry and hardware constraints were not accounted for.
169+
170+
- **Energy trading**: energy was assumed to have just appeared out of thin air. The actual energy transaction needs to be implemented to allow for trading back and forth between grid and battery.

0 commit comments

Comments
 (0)