Skip to content

Commit

Permalink
Ooga Booga 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dezzeus committed Jan 20, 2025
1 parent b984642 commit 4dba5ad
Show file tree
Hide file tree
Showing 156 changed files with 1,599 additions and 560 deletions.
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fs_permissions = [{ access = "read", path = "./test"}]

[profile.deploy]
via_ir = true
optimizer_runs = 800
optimizer_runs = 666

[profile.deploy_small]
via_ir = true
Expand Down
2 changes: 1 addition & 1 deletion script/base/Base.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.10;
pragma solidity 0.8.26;

import { Script, console2 } from "forge-std/Script.sol";

Expand Down
2 changes: 1 addition & 1 deletion script/base/BasePredict.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.10;
pragma solidity 0.8.26;

import { Script, console2 } from "forge-std/Script.sol";
import { Create2Deployer } from "src/base/Create2Deployer.sol";
Expand Down
40 changes: 39 additions & 1 deletion script/base/RBAC.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.10;
pragma solidity 0.8.26;

import { console2 } from "forge-std/Script.sol";
import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.sol";
Expand Down Expand Up @@ -60,4 +60,42 @@ abstract contract RBAC {
);
console2.log("NOTICE: Revoked %s role on %s from %s", role.name, role.contractName, account.name);
}

function _requireRole(RoleDescription memory role, AccountDescription memory account) internal view {
IAccessControl target = IAccessControl(role.contractAddr);

require(
target.hasRole(role.role, account.addr),
string.concat("ERROR: ", account.name, " is missing ", role.name, " role on ", role.contractName)
);
}

/// @notice Transfer a given role from an account to another one
function _transferRole(
RoleDescription memory role,
AccountDescription memory from,
AccountDescription memory to
)
internal
{
string memory transferDescription =
string.concat(role.name, " role on ", role.contractName, " from ", from.name, " to ", to.name);

if (from.addr == to.addr) {
console2.log("NOTICE: skipping transfer of %s: same wallet", transferDescription);
return;
}

IAccessControl target = IAccessControl(role.contractAddr);

require(
target.hasRole(target.getRoleAdmin(role.role), from.addr),
string.concat("ERROR: cannot transfer ", transferDescription, ": missing admin role.")
);

console2.log("INFO: transferring %s", transferDescription);
_grantRole(role, to);
_revokeRole(role, from);
console2.log("NOTICE: transferred %s", transferDescription);
}
}
2 changes: 1 addition & 1 deletion script/base/Storage.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity 0.8.26;

import { Honey } from "src/honey/Honey.sol";
import { HoneyFactory } from "src/honey/HoneyFactory.sol";
Expand Down
2 changes: 1 addition & 1 deletion script/base/actions/ValidateUpgrade.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity 0.8.26;

import { Script, console2 } from "forge-std/Script.sol";
import { Upgrades, Options } from "openzeppelin-foundry-upgrades/Upgrades.sol";
Expand Down
6 changes: 3 additions & 3 deletions script/gov/GovernanceAddresses.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity 0.8.26;

address constant GOVERNANCE_ADDRESS = 0x547e22c34A4D168B18af1f39dafe14ec0d969452;
address constant TIMELOCK_ADDRESS = 0xFb1F4f4012e1C37a692BaB26B9aE4e054c32D039;
address constant GOVERNANCE_ADDRESS = 0x4f4A5c2194B8e856b7a05B348F6ba3978FB6f6D5;
address constant TIMELOCK_ADDRESS = 0xb5f2000b5744f207c931526cAE2134cAa8b6862a;
2 changes: 1 addition & 1 deletion script/gov/GovernancePredictAddresses.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity 0.8.26;

import { BasePredictScript, console2 } from "../base/BasePredict.s.sol";
import { Create2Deployer } from "src/base/Create2Deployer.sol";
Expand Down
2 changes: 1 addition & 1 deletion script/gov/GovernanceSalts.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity 0.8.26;

uint256 constant GOVERNANCE_SALT = 0;
uint256 constant TIMELOCK_SALT = 0;
17 changes: 6 additions & 11 deletions script/gov/deployment/1_DeployGovernance.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity 0.8.26;

import { console2 } from "forge-std/Script.sol";
import { IERC20 } from "forge-std/interfaces/IERC20.sol";
Expand All @@ -18,19 +18,15 @@ contract DeployGovernance is BaseScript {
address constant GOV_GUARDIAN = address(0);

/// Governance params
/// @notice The average block time in milli-seconds
uint256 internal constant AVG_BLOCK_TIME_MS = 1020;
/// @notice Minimum amount of delegated governance tokens for proposal creation
/// @dev This is a pure number; the decimals are handled later on.
uint256 public constant GOV_PROPOSAL_THRESHOLD = 1000;
uint256 public constant GOV_PROPOSAL_THRESHOLD = 10_000;
/// @notice Time delay between proposal creation and voting period
/// @dev This is time-based; the blocks are computed later on.
uint256 public constant GOV_VOTING_DELAY = 1 hours;
/// @notice Time duration of the voting period
/// @dev This is time-based; the blocks are computed later on.
uint256 public constant GOV_VOTING_PERIOD = 7 days;
uint256 public constant GOV_VOTING_PERIOD = 5 days;
/// @notice Numerator of the needed quorum percentage
uint256 public constant GOV_QUORUM_NUMERATOR = 10;
uint256 public constant GOV_QUORUM_NUMERATOR = 20;
/// @notice Time duration of the enforced time-lock
uint256 public constant TIMELOCK_MIN_DELAY = 2 days;

Expand All @@ -41,7 +37,6 @@ contract DeployGovernance is BaseScript {
GovDeployer govDeployer = new GovDeployer(
BGT_ADDRESS,
GOV_GUARDIAN,
AVG_BLOCK_TIME_MS,
GOV_PROPOSAL_THRESHOLD,
GOV_VOTING_DELAY,
GOV_VOTING_PERIOD,
Expand All @@ -58,8 +53,8 @@ contract DeployGovernance is BaseScript {
require(address(gov.timelock()) == TIMELOCK_ADDRESS, "Governance timelock address mismatch");
uint256 threshold = GOV_PROPOSAL_THRESHOLD * 10 ** IERC20(BGT_ADDRESS).decimals();
require(gov.proposalThreshold() == threshold, "Governance proposal threshold mismatch");
require(gov.votingDelay() == govDeployer.timeToBlocks(GOV_VOTING_DELAY), "Governance voting delay mismatch");
require(gov.votingPeriod() == govDeployer.timeToBlocks(GOV_VOTING_PERIOD), "Governance voting period mismatch");
require(gov.votingDelay() == GOV_VOTING_DELAY, "Governance voting delay mismatch");
require(gov.votingPeriod() == GOV_VOTING_PERIOD, "Governance voting period mismatch");
require(gov.quorumNumerator() == GOV_QUORUM_NUMERATOR, "Governance quorum numerator mismatch");

TimeLock timelock = TimeLock(payable(govDeployer.TIMELOCK_CONTROLLER()));
Expand Down
8 changes: 4 additions & 4 deletions script/honey/HoneyAddresses.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity 0.8.26;

address constant HONEY_ADDRESS = 0xd137593CDB341CcC78426c54Fb98435C60Da193c;
address constant HONEY_FACTORY_ADDRESS = 0xA81F0019d442f19f66880bcf2698B4E5D5Ec249A;
address constant HONEY_FACTORY_READER_ADDRESS = 0x8C4A67395d60D235827F5edE446941E84d30a5B1;
address constant HONEY_ADDRESS = 0xFCBD14DC51f0A4d49d5E53C2E0950e0bC26d0Dce;
address constant HONEY_FACTORY_ADDRESS = 0xA4aFef880F5cE1f63c9fb48F661E27F8B4216401;
address constant HONEY_FACTORY_READER_ADDRESS = 0x285e147060CDc5ba902786d3A471224ee6cE0F91;
2 changes: 1 addition & 1 deletion script/honey/HoneyPredictAddresses.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity 0.8.26;

import { BasePredictScript, console2 } from "../base/BasePredict.s.sol";
import { Create2Deployer } from "src/base/Create2Deployer.sol";
Expand Down
2 changes: 1 addition & 1 deletion script/honey/HoneySalts.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity 0.8.26;

uint256 constant HONEY_SALT = 1;
uint256 constant HONEY_FACTORY_SALT = 1;
Expand Down
26 changes: 23 additions & 3 deletions script/honey/actions/AddCollateral.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity 0.8.26;

import { console2 } from "forge-std/Script.sol";
import { BaseScript } from "../../base/Base.s.sol";
Expand All @@ -13,19 +13,27 @@ import { IPriceOracle } from "src/extras/IPriceOracle.sol";
/// @notice Creates a collateral vault for the given token.
contract AddCollateralVaultScript is BaseScript {
// Placeholders. Change before run script.
string constant COLLATERAL_NAME = "COLLATERAL_NAME"; // "USDT" "DAI" "USDC"
string constant COLLATERAL_NAME = "COLLATERAL_NAME"; // "USDC" "pyUSD" - MAKE SURE TO SET ONE OF THOSE.
address constant COLLATERAL_ADDRESS = address(0); // USDT_ADDRESS DAI_ADDRESS USDC_ADDRESS
// REMOVE AFTER TRANSFER OWNERSHIP TO THE GOVERNANCE
uint256 constant USDC_PEG_OFFSET = 0.001e18;
// REMOVE AFTER TRANSFER OWNERSHIP TO THE GOVERNANCE
uint256 constant pyUSD_RELATIVE_CAP = 0.5e18;

function run() public virtual broadcast {
require(COLLATERAL_ADDRESS != address(0), "COLLATERAL_ADDRESS not set");

_validateCode("HoneyFactory", HONEY_FACTORY_ADDRESS);
_validateCode("COLLATERAL_NAME", COLLATERAL_ADDRESS);
_validateCode(COLLATERAL_NAME, COLLATERAL_ADDRESS);
addCollateralVault(COLLATERAL_ADDRESS);
}

/// @dev requires MANAGER_ROLE to be granted to msg.sender
function addCollateralVault(address collateral) internal {
bool isUSDC = keccak256(abi.encodePacked(COLLATERAL_NAME)) == keccak256(abi.encodePacked("USDC"));
bool isPyUSD = keccak256(abi.encodePacked(COLLATERAL_NAME)) == keccak256(abi.encodePacked("pyUSD"));
require(isUSDC || isPyUSD, "collateral not supported");

_validateCode("Collateral", collateral);
HoneyFactory honeyFactory = HoneyFactory(HONEY_FACTORY_ADDRESS);

Expand All @@ -39,5 +47,17 @@ contract AddCollateralVaultScript is BaseScript {

ERC4626 vault = honeyFactory.createVault(collateral);
console2.log("Collateral Vault deployed at:", address(vault));
// Set mint rate to 1:1
// Only for initial launch
honeyFactory.setMintRate(collateral, 1e18);

if (isUSDC) {
// Set peg offset for USDC
honeyFactory.setDepegOffsets(collateral, USDC_PEG_OFFSET, USDC_PEG_OFFSET);
}
if (isPyUSD) {
// Set relative cap for pyUSD
honeyFactory.setRelativeCap(collateral, pyUSD_RELATIVE_CAP);
}
}
}
2 changes: 1 addition & 1 deletion script/honey/actions/MintHoney.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity 0.8.26;

import { console2 } from "forge-std/Script.sol";
import { BaseScript } from "../../base/Base.s.sol";
Expand Down
74 changes: 47 additions & 27 deletions script/honey/deployment/1_DeployHoney.s.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity 0.8.26;

import { console2 } from "forge-std/Script.sol";
import { HoneyDeployer } from "src/honey/HoneyDeployer.sol";
import { BaseScript } from "../../base/Base.s.sol";
import { RBAC } from "../../base/RBAC.sol";
import { HONEY_ADDRESS, HONEY_FACTORY_ADDRESS, HONEY_FACTORY_READER_ADDRESS } from "../HoneyAddresses.sol";
import { PYTH_PRICE_ORACLE_ADDRESS } from "../../oracles/OraclesAddresses.sol";
import { PEGGED_PRICE_ORACLE_ADDRESS } from "../../oracles/OraclesAddresses.sol";
import { FEE_COLLECTOR_ADDRESS as POL_FEE_COLLECTOR_ADDRESS } from "../../pol/POLAddresses.sol";
import { HONEY_SALT, HONEY_FACTORY_SALT, HONEY_FACTORY_READER_SALT } from "../HoneySalts.sol";
import { Storage } from "../../base/Storage.sol";

contract DeployHoneyScript is BaseScript, Storage {
contract DeployHoneyScript is RBAC, BaseScript, Storage {
// Placeholder. Change before deployment
address internal constant FEE_RECEIVER = POL_FEE_COLLECTOR_ADDRESS;

Expand All @@ -23,14 +24,16 @@ contract DeployHoneyScript is BaseScript, Storage {
function deployHoney() internal {
console2.log("Deploying Honey and HoneyFactory...");
_validateCode("POL FeeCollector", POL_FEE_COLLECTOR_ADDRESS);
_validateCode("IPriceOracle", PEGGED_PRICE_ORACLE_ADDRESS);

honeyDeployer = new HoneyDeployer(
msg.sender,
POL_FEE_COLLECTOR_ADDRESS,
FEE_RECEIVER,
HONEY_SALT,
HONEY_FACTORY_SALT,
HONEY_FACTORY_READER_SALT,
PYTH_PRICE_ORACLE_ADDRESS
PEGGED_PRICE_ORACLE_ADDRESS
);

console2.log("HoneyDeployer deployed at:", address(honeyDeployer));
Expand All @@ -50,36 +53,53 @@ contract DeployHoneyScript is BaseScript, Storage {
require(honeyFactory.polFeeCollector() == POL_FEE_COLLECTOR_ADDRESS, "Pol fee collector not set");
console2.log("Pol fee collector set to:", POL_FEE_COLLECTOR_ADDRESS);

// check roles and grant manager role to msg.sender.
require(
honey.hasRole(honey.DEFAULT_ADMIN_ROLE(), msg.sender),
"Honey's DEFAULT_ADMIN_ROLE not granted to msg.sender"
);
// check roles
RBAC.AccountDescription memory deployer = RBAC.AccountDescription({ name: "deployer", addr: msg.sender });

RBAC.RoleDescription memory honeyAdminRole = RBAC.RoleDescription({
contractName: "Honey",
contractAddr: HONEY_ADDRESS,
name: "DEFAULT_ADMIN_ROLE",
role: honey.DEFAULT_ADMIN_ROLE()
});
_requireRole(honeyAdminRole, deployer);
console2.log("Honey's DEFAULT_ADMIN_ROLE granted to:", msg.sender);

require(
honeyFactory.hasRole(honeyFactory.DEFAULT_ADMIN_ROLE(), msg.sender),
"HoneyFactory's DEFAULT_ADMIN_ROLE not granted to msg.sender"
);
RBAC.RoleDescription memory honeyFactoryAdminRole = RBAC.RoleDescription({
contractName: "HoneyFactory",
contractAddr: HONEY_FACTORY_ADDRESS,
name: "DEFAULT_ADMIN_ROLE",
role: honeyFactory.DEFAULT_ADMIN_ROLE()
});
_requireRole(honeyFactoryAdminRole, deployer);
console2.log("HoneyFactory's DEFAULT_ADMIN_ROLE granted to:", msg.sender);

RBAC.RoleDescription memory honeyFactoryReaderAdminRole = RBAC.RoleDescription({
contractName: "HoneyFactoryReader",
contractAddr: HONEY_FACTORY_READER_ADDRESS,
name: "DEFAULT_ADMIN_ROLE",
role: honeyFactoryReader.DEFAULT_ADMIN_ROLE()
});
_requireRole(honeyFactoryReaderAdminRole, deployer);
console2.log("HoneyFactoryReader's DEFAULT_ADMIN_ROLE granted to:", msg.sender);

// granting MANAGER_ROLE to msg.sender as we need to call
// setMintRate and setRedeemRate while doing `addCollateral`
honeyFactory.grantRole(honeyFactory.MANAGER_ROLE(), msg.sender);

require(
honeyFactory.hasRole(honeyFactory.MANAGER_ROLE(), msg.sender),
"HoneyFactory's MANAGER_ROLE not granted to msg.sender"
);
console2.log("HoneyFactory's MANAGER_ROLE granted to:", msg.sender);
RBAC.RoleDescription memory managerRole = RBAC.RoleDescription({
contractName: "HoneyFactory",
contractAddr: HONEY_FACTORY_ADDRESS,
name: "MANAGER_ROLE",
role: honeyFactory.MANAGER_ROLE()
});
_grantRole(managerRole, deployer);

// grant the PAUSER_ROLE to msg.sender
honeyFactory.grantRole(honeyFactory.PAUSER_ROLE(), msg.sender);

require(
honeyFactory.hasRole(honeyFactory.PAUSER_ROLE(), msg.sender),
"HoneyFactory's PAUSER_ROLE not granted to msg.sender"
);
console2.log("HoneyFactory's PAUSER_ROLE granted to:", msg.sender);
RBAC.RoleDescription memory pauserRole = RBAC.RoleDescription({
contractName: "HoneyFactory",
contractAddr: HONEY_FACTORY_ADDRESS,
name: "PAUSER_ROLE",
role: honeyFactory.PAUSER_ROLE()
});
_grantRole(pauserRole, deployer);
}
}
Loading

0 comments on commit 4dba5ad

Please sign in to comment.