Skip to content

Commit

Permalink
feat: update governance delay time in contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
evandrosaturnino committed May 8, 2024
1 parent 5c3fac0 commit 35bd6b0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
5 changes: 5 additions & 0 deletions packages/contracts/contracts/Interfaces/ITHUSDToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ interface ITHUSDToken is IERC20Metadata, IERC2612 {
event StabilityPoolAddressAdded(address _newStabilityPoolAddress);
event BorrowerOperationsAddressAdded(address _newBorrowerOperationsAddress);

event GovernanceTimeDelayIncreased(uint256 _newGovernanceTimeDelay);

event THUSDTokenBalanceUpdated(address _user, uint256 _amount);

// --- External Functions ---
Expand All @@ -27,6 +29,9 @@ interface ITHUSDToken is IERC20Metadata, IERC2612 {

function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool);

// --- Getters Functions ---
function getGovernanceTimeDelay() external view returns (uint256);

// --- Governance functions ---
function startRevokeMintList(address _account) external;
function finalizeRevokeMintList() external;
Expand Down
10 changes: 5 additions & 5 deletions packages/contracts/contracts/PCV.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract PCV is IPCV, Ownable, CheckContract, SendCollateral {

uint256 constant public BOOTSTRAP_LOAN = 1e26; // 100M thUSD

uint256 public immutable governanceTimeDelay;
uint256 public governanceTimeDelay;

ITHUSDToken public thusdToken;
BorrowerOperations public borrowerOperations;
Expand All @@ -38,10 +38,6 @@ contract PCV is IPCV, Ownable, CheckContract, SendCollateral {
address public pendingTreasuryAddress;
uint256 public changingRolesInitiated;

constructor(uint256 _governanceTimeDelay) {
governanceTimeDelay = _governanceTimeDelay;
}

modifier onlyAfterDebtPaid() {
require(isInitialized && debtToPay == 0, "PCV: debt must be paid");
_;
Expand Down Expand Up @@ -179,6 +175,8 @@ contract PCV is IPCV, Ownable, CheckContract, SendCollateral {
require(_council != council || _treasury != treasury, "PCV: these roles already set");

changingRolesInitiated = block.timestamp;
governanceTimeDelay = thusdToken.getGovernanceTimeDelay();

if (council == address(0) && treasury == address(0)) {
changingRolesInitiated -= governanceTimeDelay; // skip delay if no roles set
}
Expand All @@ -195,6 +193,8 @@ contract PCV is IPCV, Ownable, CheckContract, SendCollateral {
}

function finalizeChangingRoles() external override onlyOwner {
governanceTimeDelay = thusdToken.getGovernanceTimeDelay();

require(changingRolesInitiated > 0, "PCV: Change not initiated");
require(
block.timestamp >= changingRolesInitiated + governanceTimeDelay,
Expand Down
29 changes: 24 additions & 5 deletions packages/contracts/contracts/THUSDToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ contract THUSDToken is Ownable, CheckContract, ITHUSDToken {
mapping(address => bool) public burnList;
mapping(address => bool) public mintList;

uint256 public immutable governanceTimeDelay;
uint256 public governanceTimeDelay;

address public pendingTroveManager;
address public pendingStabilityPool;
Expand All @@ -78,8 +78,7 @@ contract THUSDToken is Ownable, CheckContract, ITHUSDToken {
address _borrowerOperationsAddress1,
address _troveManagerAddress2,
address _stabilityPoolAddress2,
address _borrowerOperationsAddress2,
uint256 _governanceTimeDelay
address _borrowerOperationsAddress2
)
{
// when created its linked to one set of contracts and collateral, other collateral types can be added via governance
Expand All @@ -94,8 +93,6 @@ contract THUSDToken is Ownable, CheckContract, ITHUSDToken {
_HASHED_VERSION = hashedVersion;
_CACHED_CHAIN_ID = block.chainid;
_CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(_TYPE_HASH, hashedName, hashedVersion);
governanceTimeDelay = _governanceTimeDelay;
require(governanceTimeDelay <= 30 weeks, "Governance delay is too big");
}

modifier onlyAfterGovernanceDelay(
Expand All @@ -109,6 +106,22 @@ contract THUSDToken is Ownable, CheckContract, ITHUSDToken {
_;
}

function increaseGovernanceTimeDelay(
uint256 _governanceTimeDelay
)
external
onlyOwner
{
require(
_governanceTimeDelay >= governanceTimeDelay,
"The governance time delay can only be increased"
);
require(_governanceTimeDelay <= 30 weeks, "Governance delay is too big");

governanceTimeDelay = _governanceTimeDelay;
emit GovernanceTimeDelayIncreased(_governanceTimeDelay);
}

// --- Governance ---

function startRevokeMintList(address _account)
Expand Down Expand Up @@ -240,6 +253,12 @@ contract THUSDToken is Ownable, CheckContract, ITHUSDToken {
_burn(_account, _amount);
}

// --- thUSD property getters ---

function getGovernanceTimeDelay() external view override returns (uint256) {
return governanceTimeDelay;
}

// --- External functions ---

function totalSupply() external view override returns (uint256) {
Expand Down
3 changes: 1 addition & 2 deletions packages/contracts/contracts/TestContracts/EchidnaTester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ contract EchidnaTester {
address(borrowerOperations),
address(0),
address(0),
address(0),
90 * 24 * 60 * 60
address(0)
);

collSurplusPool = new CollSurplusPool();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ contract THUSDTokenTester is THUSDToken {
constructor(
address _troveManagerAddress,
address _stabilityPoolAddress,
address _borrowerOperationsAddress,
uint256 _governanceTimeDelay
address _borrowerOperationsAddress
)
THUSDToken(_troveManagerAddress,
_stabilityPoolAddress,
_borrowerOperationsAddress,
address(0),
address(0),
address(0),
_governanceTimeDelay
address(0)
) {}

function unprotectedMint(address _account, uint256 _amount) external {
Expand Down

0 comments on commit 35bd6b0

Please sign in to comment.