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
remove unneeded contract files;
call safemath library properly;
  • Loading branch information
yan-man committed Dec 9, 2021
commit ef4e25025aa3cda2edf7c1554a5edfee49a605c1
28 changes: 13 additions & 15 deletions contracts/BatteryEnergy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/math/Math.sol";

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

/// @author Yan Man
/// @title Manage charging/discharging of batteries
Expand Down Expand Up @@ -72,7 +70,7 @@ contract BatteryEnergy {
returns (uint calculateEnergyToTransact)
{
// convert seconds to hours
uint purchaseIntervalHours = SafeMath.div(purchaseInterval, 3600);
uint purchaseIntervalHours = purchaseInterval.div(3600);
// how much energy is available in battery
uint emptyCapacity = _capacity - _currentFilled;

Expand All @@ -82,17 +80,18 @@ contract BatteryEnergy {
require(emptyCapacity > 0, "Battery should have remaining capacity in order to charge");
// charge rate * time interval gives total energy amount to be added
// but energy amount cannot exceed empty capacity
calculateEnergyToTransact = Math.min(SafeMath.mul(_chargeRate, purchaseIntervalHours), emptyCapacity);
uint charge = _chargeRate.mul(purchaseIntervalHours);
calculateEnergyToTransact = charge.min(emptyCapacity);
// find remaining investment in fund
uint remainingInvestment = (VirtualPowerPlantContract.batteryInvestmentContract()).remainingInvestment();
// cost = energy amount * energy price
uint costOfEnergyPurchase = SafeMath.mul(calculateEnergyToTransact, _energyPrice);
uint costOfEnergyPurchase = calculateEnergyToTransact.mul(_energyPrice);
// make sure there is enough investment to cover energy purchase
if (costOfEnergyPurchase > remainingInvestment) {
// energy purchase costs at most are the remaining investment
costOfEnergyPurchase = remainingInvestment;
// back calculate the energy based on the max eth available
calculateEnergyToTransact = SafeMath.div(remainingInvestment, _energyPrice);
calculateEnergyToTransact = remainingInvestment.div(_energyPrice);
}
// purchase energy
buyEnergy(_batteryID, calculateEnergyToTransact, _energyPrice);
Expand All @@ -103,7 +102,7 @@ contract BatteryEnergy {
);
} else {
// maximum energy to sell is the current amount in the battery
calculateEnergyToTransact = Math.min(SafeMath.mul(_chargeRate, purchaseIntervalHours), _currentFilled);
calculateEnergyToTransact = Math.min(_chargeRate.mul(purchaseIntervalHours), _currentFilled);
sellEnergy(_batteryID, calculateEnergyToTransact, _energyPrice);
emit LogEnergySold(
_serialNumber,
Expand All @@ -124,10 +123,9 @@ contract BatteryEnergy {
uint _energyPrice
) private returns (bool) {
// calculate remaining investment money after energy purchase
uint newRemainingInvestment = SafeMath.sub(
(VirtualPowerPlantContract.batteryInvestmentContract()).remainingInvestment(),
SafeMath.mul(
_energyAmountToPurchase,
uint oldRemainingInvestment = VirtualPowerPlantContract.batteryInvestmentContract().remainingInvestment();
uint newRemainingInvestment = oldRemainingInvestment.sub(
_energyAmountToPurchase.mul(
_energyPrice
)
);
Expand All @@ -151,10 +149,10 @@ contract BatteryEnergy {
uint _energyAmountToSell,
uint _energyPrice
) private returns (bool) {
uint newRemainingInvestment = SafeMath.add(
(VirtualPowerPlantContract.batteryInvestmentContract()).remainingInvestment(),
SafeMath.mul(
_energyAmountToSell,

uint oldRemainingInvestment = VirtualPowerPlantContract.batteryInvestmentContract().remainingInvestment();
uint newRemainingInvestment = oldRemainingInvestment.add(
_energyAmountToSell.mul(
_energyPrice
)
);
Expand Down
31 changes: 0 additions & 31 deletions contracts/Math.sol

This file was deleted.

118 changes: 0 additions & 118 deletions contracts/SafeMath.sol

This file was deleted.

13 changes: 0 additions & 13 deletions contracts/SimpleStorage.sol

This file was deleted.