You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### 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)
5
5
6
-
### Overview:
6
+
### I. Overview:
7
7
8
8
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/)
9
9
10
10
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.
11
11
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.
Otherwise, interact with the DApp via the frontend included, which will allow you to invest funds, add batteries, and execute energy transactions.
28
28
29
-
### Getting Started
29
+
### II. Getting Started
30
30
#### Required installations:
31
31
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.
VPP-Dapp is a truffle project that contains all necessary contract, library, migration and test files. Execute via command line:
46
44
47
-
1. Clone the repo to your directory
45
+
1. Clone the repo to your directory.
46
+
47
+
```
48
+
$ git clone
49
+
```
48
50
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.
50
52
51
53
```
52
-
> ganache-cli -p 7545
54
+
Terminal 2:
55
+
$ ganache-cli -p 7545
53
56
```
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.
54
58
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.
56
64
57
-
4. Test the contract functions via js tests. All tests should pass
65
+
```
66
+
$ truffle migrate --reset
67
+
```
58
68
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.
60
70
61
-
6. Start the front end server on ```localhost:3000```
71
+
6. Start the front end server on ```localhost:3000``` by using:
62
72
63
73
```
64
-
> git clone
65
-
> truffle migrate --reset
66
-
> truffle test
67
-
> npm run dev
74
+
$ npm run dev
68
75
```
69
76
70
77
#### Frontend Interaction:
71
78
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.
75
80
76
81
To test the DApp, follow instructions on the `index.html` homepage.
77
82
78
83
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.
79
84
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:
81
94
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.
83
99
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.
85
102
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
89
117
- `setAdmin`: set admin to active or inactive
90
118
- `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
- `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:**
96
126
- `getRelevantBatteryInfo`
97
127
- `getBatteryChargeRate`
98
128
- `getBatteryMapIndex`
99
129
100
-
##### BatteryInvestment.sol
130
+
##### 2) BatteryInvestment.sol
101
131
- `updateRemainingInvestment`: update amount of remaining eth in fund
102
132
- `investMoney`: ensure Eth is attached when calling this function
103
133
- `triggerDividend`: admins can implement a dividend to send payment to investors
104
134
- `withdraw`: for investors to retrieve their dividend withdrawal
105
135
- `getInvestorInvestment`: getter function to retrieve investment amount for particular investor
106
136
107
-
##### BatteryEnergy.sol
137
+
##### 3) BatteryEnergy.sol
108
138
- `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.
109
141
110
142
#### Tests:
111
143
@@ -123,3 +155,16 @@ Contract tests were written in JavaScript
123
155
1. [SafeMath](https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/SafeMath.sol): Use battle tested math functions to avoid overflow errors, etc
124
156
2. [Math](https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/Math.sol): Other basic math functions
- **[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