Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/v0.2.0 #5

Merged
merged 48 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
2930404
init next app;
yan-man Nov 30, 2021
40f6f07
update packages;
yan-man Nov 30, 2021
67af7ae
update git ignore;
yan-man Nov 30, 2021
275ccd3
update from git ignore;
yan-man Nov 30, 2021
ca00d88
initialize battery details;
yan-man Nov 30, 2021
a69c4ba
init components;
yan-man Nov 30, 2021
8c03655
refactor into components;
yan-man Dec 1, 2021
b132ef8
add global CSS;
yan-man Dec 1, 2021
6344861
implement carousel for batteries;
yan-man Dec 1, 2021
2e52ce6
turn off carousel autoplay;
yan-man Dec 1, 2021
ccfbc66
deploy BatteryInvestment contract;
yan-man Dec 7, 2021
c82f995
deploy all 3 contracts required;
yan-man Dec 9, 2021
ef4e250
remove unneeded contract files;
yan-man Dec 9, 2021
5c278c7
init tests in solidity;
yan-man Dec 11, 2021
f81f450
add more contract testing in js;
yan-man Feb 21, 2022
9d43e3d
init some base test cases that work;
yan-man Feb 22, 2022
d9d9929
working base case to refer to later;
yan-man Feb 22, 2022
535fe39
expand testing for BatteryInvestment contract;
yan-man Feb 22, 2022
7963cb3
update safemath;
yan-man Feb 22, 2022
668870a
split tests, remove commented out test details;
yan-man Feb 22, 2022
61a12ca
Merge pull request #1 from yan-man/feature/2.21.22-expand-testing
yan-man Feb 22, 2022
f85d74d
fix deploy contracts - dependency on vpp contract;
yan-man Feb 22, 2022
ed1c82e
init web3 contract definitions;
yan-man Feb 23, 2022
c2829fe
init contracts and accounts;
yan-man Feb 23, 2022
6a06cb2
also use @truffle/contract package to access contracts;
yan-man Feb 23, 2022
4423831
get user account balance;
yan-man Feb 23, 2022
2b16474
load other child contracts;
yan-man Feb 23, 2022
035ac06
refactor initContract method;
yan-man Feb 23, 2022
1fc4936
refactor folder structure, add components and api inside pages;
yan-man Feb 23, 2022
56507f0
refactor VPP instructions section, ui display;
yan-man Feb 23, 2022
2abd78d
compare BN without converting toNumber;
yan-man Feb 23, 2022
d27968d
update assertions for BN for more tests;
yan-man Feb 23, 2022
0bdbafe
update test ...check BatteryInvestment triggerDividend;
yan-man Feb 23, 2022
b27e564
update ...check BatteryInvestment triggerDividend test;
yan-man Feb 23, 2022
7ce86f6
debug with larger investment values in wei, deal with BN exponentials;
yan-man Feb 23, 2022
7446d7e
update testing;
yan-man Feb 23, 2022
1604b97
Merge branch 'feature/2.21.22-expand-testing' into feature/2.22.22-tr…
yan-man Feb 23, 2022
4ad1112
create initial UI for establishing fund investment and purchasing bat…
yan-man Feb 23, 2022
0bf45da
update header, title text;
yan-man Feb 23, 2022
a4b02ac
Merge pull request #2 from yan-man/feature/2.22.22-truffle-contract-i…
yan-man Feb 23, 2022
d159c95
remove requirement for file.secret for dev testing;
yan-man Feb 23, 2022
6880192
clean up file structure;
yan-man Feb 23, 2022
127d4fb
clean up file structure, package content version details;
yan-man Feb 23, 2022
814775f
update package name to match previous;
yan-man Feb 23, 2022
d755b0a
Merge branch 'merge/v0.1.0' into dev
yan-man Feb 23, 2022
387b4ce
update package lock;
yan-man Feb 23, 2022
2c49e51
update readme;
yan-man Feb 24, 2022
a0ad1e1
Merge branch 'dev' into release/v0.2.0
yan-man Feb 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
deploy all 3 contracts required;
implement step 1 - invest, step 2 - adding batteries to array;
clean up battery cost details;
  • Loading branch information
yan-man committed Dec 9, 2021
commit c82f995ee0c38f6ddc31f5e465fa003401fcf99f
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/pages/index.js",
"console": "integratedTerminal"
}
]
}
29 changes: 22 additions & 7 deletions components/BatteryCarousel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@ import Carousel from "react-bootstrap/Carousel";
import Row from "react-bootstrap/Row";
import Image from "next/image";
import styles from "../styles/BatteryCarousel.module.css";

import web3Contracts from "../services/web3Contracts";
class BatteryList extends React.Component {
Web3Contracts = {};
componentDidMount = async () => {
console.log("use effect; init web3");
this.Web3Contracts = new web3Contracts();
await this.Web3Contracts.init();
};
handleAddBattery = async (event) => {
// console.log(this.Web3Contracts);
// console.log(event)
this.Web3Contracts.addBattery(event);
};
render() {
return (
<React.Fragment>
<Row className={styles.carousel}>
<Carousel interval={null}>
{this.props.batteries.map((batt, ind) => {
{this.props.batteries.map((battery, ind) => {
return (
<Carousel.Item key={ind}>
<img
Expand All @@ -18,16 +31,18 @@ class BatteryList extends React.Component {
alt="Second slide"
/>
<Carousel.Caption>
<h4>{batt.name}</h4>
<p>Battery Capacity: {batt.capacity} MWh</p>
<p>Current Amount Filled: {batt.currentFilled} MWh</p>
<p>Battery Cost: {batt.cost} Eth</p>
<p>Price Threshold: {batt.priceThreshold} Eth/kWh</p>
<p>Charge Rate: {batt.chargeRate} MWh/hr</p>
<h4>{battery.name}</h4>
<p>Battery Capacity: {battery.capacity} MWh</p>
<p>Current Amount Filled: {battery.currentFilled} MWh</p>
<p>Battery Cost: {battery.cost} Eth</p>
<p>Price Threshold: {battery.priceThreshold} Eth/kWh</p>
<p>Charge Rate: {battery.chargeRate} MWh/hr</p>
<button
className="btn-add-battery"
type="button"
data-id="0"
value={battery}
onClick={() => {this.handleAddBattery(battery)}}
>
Add to array
</button>
Expand Down
150 changes: 132 additions & 18 deletions components/VirtualPowerPlantInstructions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,115 @@ import React, { Component } from "react";
import Row from "react-bootstrap/Row";
import Container from "react-bootstrap/Container";
import Col from "react-bootstrap/Col";

import web3Contracts from "../services/web3Contracts";
class VirtualPowerPlantInstructions extends Component {
state = {
value: 0.0,
totalInvestment: 0,
remainingInvestment: 0,
numBatteries: 0,
};
Web3Contracts = {};
componentDidMount = async () => {
console.log("use effect; init web3");
this.timerID = setInterval(() => this.tick(), 1000);

this.Web3Contracts = new web3Contracts();
await this.Web3Contracts.init();
await this.updateStats();
};
componentWillUnmount() {
clearInterval(this.timerID);
}
async tick() {
this.updateStats();
}

updateStats = async () => {
if (this.Web3Contracts.contracts) {
let totalInvestment =
await this.Web3Contracts.contracts.BatteryInvestment.methods
.totalInvestment()
.call();
totalInvestment = this.Web3Contracts.web3.utils.fromWei(
totalInvestment,
"ether"
);

let remainingInvestment =
await this.Web3Contracts.contracts.BatteryInvestment.methods
.remainingInvestment()
.call();
remainingInvestment = this.Web3Contracts.web3.utils.fromWei(
remainingInvestment,
"ether"
);

// let test = await this.Web3Contracts.contracts.VirtualPowerPlant.methods
// .batteryInvestmentAddress()
// .call();
// console.log(test);
// let test2 = await this.Web3Contracts.contracts.VirtualPowerPlant.methods
// .batteryInvestmentContract()
// .call();
// console.log(test2);

// console.log(this.Web3Contracts.contracts.BatteryInvestment.options.address)

let numBatteries =
await this.Web3Contracts.contracts.VirtualPowerPlant.methods
.numBatteries()
.call();

// console.log(remainingInvestment)
// console.log(totalInvestment)
// console.log(numBatteries)

let batteryMapping =
await this.Web3Contracts.contracts.VirtualPowerPlant.methods
.getBatteryMapping()
.call();

console.log(batteryMapping);
for (let i = 0; i <= numBatteries; i++) {
// console.log(i);
}

this.setState({ totalInvestment, remainingInvestment, numBatteries });
}
};
handleSubmit = async (event) => {
event.preventDefault();
await this.Web3Contracts.invest(String(this.state.value));
await this.updateStats();
};
handleChange = (event) => {
this.setState({ value: event.target.value });
};
render() {
// console.log(this.Web3Contracts);
return (
<React.Fragment>
<Row>
<Col>
<h5>Total Amount Invested:</h5>
<h4>
<span id="totalInvestment">0</span> Eth
<span id="totalInvestment">{this.state.totalInvestment}</span> Eth
</h4>
</Col>
<Col>
<h5>Remaining Amount Invested:</h5>
<h5>Remaining Amount Left:</h5>
<h4>
<span id="remainingInvestment">0</span> Eth
<span id="remainingInvestment">
{this.state.remainingInvestment}
</span>{" "}
Eth
</h4>
</Col>
<Col>
<h5>Number of Battery Assets:</h5>
<h5>Number of Batteries:</h5>
<h4>
<span id="numBatteries">0</span>
<span id="numBatteries">{this.state.numBatteries}</span>
</h4>
</Col>
</Row>
Expand All @@ -38,17 +125,23 @@ class VirtualPowerPlantInstructions extends Component {
</p>
</Row>
<Row>
<div>
<button className="btn-invest" type="button">
Invest
</button>
<input
type="number"
name="investmentAmount"
className="investmentAmount"
placeholder="[Eth]"
></input>
</div>
<form onSubmit={this.handleSubmit}>
<div>
<button
className="btn-invest"
type="button"
onClick={this.handleSubmit}
>
Invest
</button>
<input
onChange={this.handleChange}
className="investmentAmount"
placeholder="[Eth]"
value={this.state.value}
></input>
</div>
</form>
</Row>
<Row>
<h3>Step 2:</h3>
Expand All @@ -58,7 +151,28 @@ class VirtualPowerPlantInstructions extends Component {
accounts[0]) to maintain admin permissions (Click "Add to array")
</p>
<p>
Virtual Power Plant Admin: <span id="owner"></span>
Virtual Power Plant Admin:{" "}
<span id="owner">
{this.Web3Contracts.accounts
? this.Web3Contracts.accounts[0]
: ""}
</span>
</p>
<p>
Virtual Power Plant Contract:{" "}
<span id="virtualPowerPlantContract">
{this.Web3Contracts.contracts
? this.Web3Contracts.contracts.VirtualPowerPlant.options.address
: ""}
</span>
</p>
<p>
Battery Investment Contract:{" "}
<span id="batteryInvestment">
{this.Web3Contracts.contracts
? this.Web3Contracts.contracts.BatteryInvestment.options.address
: ""}
</span>
</p>
</Row>
<Row>
Expand Down
9 changes: 7 additions & 2 deletions contracts/BatteryEnergy.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
pragma solidity >=0.5.0;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/math/Math.sol";

import "./VirtualPowerPlant.sol";
import "./SafeMath.sol";
import "./Math.sol";
// import "./SafeMath.sol";
// import "./Math.sol";

/// @author Yan Man
/// @title Manage charging/discharging of batteries
contract BatteryEnergy {

using SafeMath for uint;

// Type declarations
VirtualPowerPlant VirtualPowerPlantContract;

Expand Down
5 changes: 4 additions & 1 deletion contracts/BatteryInvestment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ contract BatteryInvestment {
/// @return whether var succesfully updated
function updateRemainingInvestment (uint _remainingInvestment) external returns (bool) {
remainingInvestment = _remainingInvestment;
return true;
return (remainingInvestment==_remainingInvestment);
}

/// @notice invest eth into fund
Expand All @@ -108,6 +108,9 @@ contract BatteryInvestment {
totalInvestment += investAmount;
// update the remaining amount of investment
remainingInvestment += investAmount;

VirtualPowerPlantContract.setContractAddress(address(this));

emit LogNewInvestment(msg.sender, investAmount);
}

Expand Down
Loading