Skip to content

Commit

Permalink
⏯ Add Proof of Reserve pausing to TrueUSDWithPoR in contracts-por (#1201
Browse files Browse the repository at this point in the history
)

Add Proof of Reserve pausing
  • Loading branch information
msieczko authored Oct 18, 2022
1 parent 47f0bf9 commit 91ae5f9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
33 changes: 25 additions & 8 deletions packages/contracts-por/contracts/TrueCurrencyWithPoR.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ import {SafeMath} from "@openzeppelin/contracts/math/SafeMath.sol";
abstract contract TrueCurrencyWithPoR is TrueCurrency, IPoRToken {
using SafeMath for uint256;

constructor() public {
uint256 INITIAL_CHAIN_RESERVE_HEARTBEAT = 7 days;
chainReserveHeartbeat = INITIAL_CHAIN_RESERVE_HEARTBEAT;
}

/**
* @notice Overriden mint function that checks the specified proof-of-reserves feed to
* ensure that the total supply of this TrueCurrency is not greater than the reported
Expand All @@ -30,7 +25,7 @@ abstract contract TrueCurrencyWithPoR is TrueCurrency, IPoRToken {
* @param amount The amount of tokens to mint
*/
function _mint(address account, uint256 amount) internal virtual override {
if (chainReserveFeed == address(0)) {
if (chainReserveFeed == address(0) || !proofOfReserveEnabled) {
super._mint(account, amount);
return;
}
Expand Down Expand Up @@ -61,18 +56,40 @@ abstract contract TrueCurrencyWithPoR is TrueCurrency, IPoRToken {
* @dev Admin function to set a new feed
* @param newFeed Address of the new feed
*/
function setChainReserveFeed(address newFeed) external override onlyOwner returns (uint256) {
function setChainReserveFeed(address newFeed) external override onlyOwner {
emit NewChainReserveFeed(chainReserveFeed, newFeed);
chainReserveFeed = newFeed;
if (newFeed == address(0) && proofOfReserveEnabled) {
proofOfReserveEnabled = false;
}
}

/**
* @notice Sets the feed's heartbeat expectation
* @dev Admin function to set the heartbeat
* @param newHeartbeat Value of the age of the latest update from the feed
*/
function setChainReserveHeartbeat(uint256 newHeartbeat) external override onlyOwner returns (uint256) {
function setChainReserveHeartbeat(uint256 newHeartbeat) external override onlyOwner {
emit NewChainReserveHeartbeat(chainReserveHeartbeat, newHeartbeat);
chainReserveHeartbeat = newHeartbeat;
}

/**
* @notice Disable Proof of Reserve check
* @dev Admin function to disable Proof of Reserve
*/
function disableProofOfReserve() external override onlyOwner {
emit ProofOfReserveDisabled();
proofOfReserveEnabled = false;
}

/**
* @notice Enable Proof of Reserve check
* @dev Admin function to enable Proof of Reserve
*/
function enableProofOfReserve() external override onlyOwner {
require(chainReserveFeed != address(0), "TrueCurrency: chainReserveFeed not set");
emit ProofOfReserveEnabled();
proofOfReserveEnabled = true;
}
}
1 change: 1 addition & 0 deletions packages/contracts-por/contracts/common/ProxyStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ contract ProxyStorage {
// PoR feed-related variables
uint256 public chainReserveHeartbeat;
address public chainReserveFeed;
bool public proofOfReserveEnabled;

/* Additionally, we have several keccak-based storage locations.
* If you add more keccak-based storage mappings, such as mappings, you must document them here.
Expand Down
18 changes: 16 additions & 2 deletions packages/contracts-por/contracts/interface/IPoRToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,23 @@ interface IPoRToken {
*/
event NewChainReserveHeartbeat(uint256 oldHeartbeat, uint256 newHeartbeat);

/**
* @notice Event emitted when Proof of Reserve is enabled
*/
event ProofOfReserveEnabled();

/**
* @notice Event emitted when Proof of Reserve is disabled
*/
event ProofOfReserveDisabled();

/*** Admin Functions ***/

function setChainReserveFeed(address newFeed) external returns (uint256);
function setChainReserveFeed(address newFeed) external;

function setChainReserveHeartbeat(uint256 newHeartbeat) external;

function enableProofOfReserve() external;

function setChainReserveHeartbeat(uint256 newHeartbeat) external returns (uint256);
function disableProofOfReserve() external;
}

0 comments on commit 91ae5f9

Please sign in to comment.