ChargeCoin – v1.1 ChangeLog
Summary of changes between the original ChargeCoin contract (v1.0) and the upgraded v1.1 implementation.
1. Upgrade Overview
The original ChargeCoin contract (referred to as v1.0) has
been
upgraded to ChargeCoinV1_1 (v1.1) to improve security, clarify
economic behavior and make the reward system usable.
Main goals of the upgrade:
- Remove or reduce centralization risk around escrowed user funds.
- Prevent edge cases where sessions could not be closed correctly.
- Make user & station rewards claimable instead of purely accounting-only.
- Align Solidity versioning and architecture with modern best practices.
2. Security-Relevant Changes
rescueERC20 for CHG (Escrow Protection)
In v1.0, the rescueERC20 function allowed the owner to transfer
any ERC-20 token from the contract, including the native CHG token that is
used for user pre-payments (escrow).
In v1.1, the function is updated so that the contract’s own token cannot be rescued:
v1.0 (conceptually)
owner can drain all ERC-20 balances, including escrowed CHG.
v1.1
Additional check added:
require(token != address(this), "Cannot rescue CHG escrow");
rescueERC20.
actualCost > prepayment in stopCharging
In v1.0, if the actual cost of a session exceeded the pre-paid amount, the contract
could
fail to pay the station owner, causing an internal transfer to revert and blocking
stopCharging.
In v1.1, a clear rule is enforced to avoid this problematic state:
require(totalCost <= s.estimatedCost, "Total cost exceeds prepayment");
v1.0 used a very broad pragma (>=0.4.16), while relying on modern
OpenZeppelin contracts that target the 0.8.x line.
v1.1 pins Solidity to a modern, explicit version:
pragma solidity ^0.8.20;
3. Business & Logic Changes
v1.0
- Pre-payment taken via
startChargingusing an estimated cost. stopChargingcomputed the actual cost and attempted to:- pay the station owner,
- refund the difference to the user if any.
- No explicit guard if the actual cost exceeded the pre-paid amount.
v1.1
- Same high-level flow (pre-pay, then settle), but with:
- a defensive check that prevents
actualCost > prepayment, - clearer session states with events.
v1.0
Station.totalEarningsandrewardPointsexisted but were not properly updated.
v1.1
totalEarningsis now increased when payments are sent to the station owner.rewardPointsis updated in parallel with station reward accounting.
4. New Features in v1.1
v1.0
- User rewards were accounted in
rewardBalancesbut there was no way to claim them.
v1.1
- A new function
claimUserRewards()is introduced. - Users can withdraw their pending reward balance in CHG, subject to:
- non-zero reward balance, and
- sufficient CHG balance held by the contract as a reward pool.
v1.0
- Station rewards were tracked in
stationRewardsbut not withdrawable.
v1.1
claimStationRewards(stationId)enables the station owner to withdraw their accumulated station rewards.- The function is protected by
onlyStationOwner, ensuring only the correct owner can claim.
v1.1 introduces explicit management functions to register stations and toggle their active status:
registerStation(...)– creates a station entry with an owner, location, type and hourly rate.setStationActive(stationId, active)– allows the owner (protocol admin) to enable / disable a station.
5. Non-Breaking vs Breaking Aspects
- Token name and symbol remain
"Charge Coin"/"CHG". - Core ERC-20 interface behavior is preserved.
- High-level charging workflow (pre-pay → charge → stop → settle) conceptually stays the same.
- Rewards accounting structure (user + station rewards) is extended, not removed.
-
Owner can no longer use
rescueERC20to withdraw CHG held by the contract. This is an intentional restriction for security. -
Sessions where the calculated actual cost exceeds the pre-payment will now
revert
in
stopCharging. Frontends and off-chain logic must handle this by ensuring reasonable pre-payments. -
The contract is deployed under a new name (
ChargeCoinV1_1), and therefore uses a different address on-chain. Any integration needs to update the token / contract address accordingly.
6. Migration Notes & Recommendations
When migrating from v1.0 to v1.1, the following plan is recommended:
-
Define the Token Migration Strategy
Decide whether:- v1.1 will be the only canonical CHG contract going forward, or
- v1.0 and v1.1 will temporarily coexist during a migration period.
-
Announce the Upgrade
Communicate clearly to the community:- why the upgrade exists (security, rewards, clarity),
- what privileges are reduced (no more owner-escrow draining),
- how rewards can now be claimed by users and stations.
-
Update Frontend & Off-Chain Integrations
Ensure:- all frontends now reference the v1.1 contract address,
- any explorer links, analytics, and dashboards are updated,
- reward claiming UIs call the newly introduced claim functions.
-
Seed the Reward Pool
Send CHG to the v1.1 contract address so that:claimUserRewards()andclaimStationRewards()can succeed,- reward logic is live from day one.
-
Plan deprecation of v1.0
Once liquidity, integrations and balances are migrated, decide:- whether to pause v1.0 token transfers completely,
- or keep it only for historical / archival purposes.