Skip to content

Commit

Permalink
Update PiCoinValueSetter.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 28, 2024
1 parent cedae5d commit 659900f
Showing 1 changed file with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pragma solidity ^0.8.0;

import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol";

contract PiCoinValueSetter {
// Set the target value of Pi Coin
uint256 public targetValue = 314159000000000000000; // $314.159
Expand All @@ -10,14 +12,22 @@ contract PiCoinValueSetter {
// Event emitted when the mainnet is launched
event MainnetLaunched();

// Event emitted when the Pi Coin value is updated
event PiCoinValueUpdated(uint256 newValue);

// Mapping of Pi Coin values
mapping (address => uint256) public piCoinValues;

// Function to set the value of Pi Coin when the mainnet is launched
function setPiCoinValue() public {
// Check if the mainnet has been launched
require(mainnetLaunchTimestamp != 0, "Mainnet has not been launched");

// Set the value of Pi Coin to the target value
PiCoin piCoin = PiCoin(address);
piCoin.setValue(targetValue);
for (address user in piCoinValues) {
piCoinValues[user] = targetValue;
emit PiCoinValueUpdated(targetValue);
}

// Emit the MainnetLaunched event
emit MainnetLaunched();
Expand All @@ -27,4 +37,25 @@ contract PiCoinValueSetter {
function setMainnetLaunchTimestamp(uint256 _timestamp) public {
mainnetLaunchTimestamp = _timestamp;
}

// Function to get the value of a Pi Coin
function getPiCoinValue(address _user) public view returns (uint256) {
return piCoinValues[_user];
}

// Function to update the value of a Pi Coin
function updatePiCoinValue(address _user, uint256 _newValue) public {
require(piCoinValues[_user] > 0, "Pi Coin value must be set before updating");
piCoinValues[_user] = _newValue;
emit PiCoinValueUpdated(_newValue);
}

// Function to calculate the total value of all Pi Coins
function getTotalPiCoinValue() public view returns (uint256) {
uint256 totalValue = 0;
for (address user in piCoinValues) {
totalValue = SafeMath.add(totalValue, piCoinValues[user]);
}
return totalValue;
}
}

0 comments on commit 659900f

Please sign in to comment.