Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions contracts/src/factory/AaveHyperdriveFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,37 @@ contract AaveHyperdriveFactory is HyperdriveFactory {
/// @param _feeCollector The address which should be set as the fee collector in new deployments
/// @param _fees The fees each deployed instance from this contract will have
/// @param _defaultPausers The default addresses which will be set to have the pauser role
/// @param _linkerFactory The address of the linker factory
/// @param _linkerCodeHash The hash of the linker contract's constructor code.
constructor(
address _governance,
IHyperdriveDeployer _deployer,
address _hyperdriveGovernance,
address _feeCollector,
IHyperdrive.Fees memory _fees,
address[] memory _defaultPausers
address[] memory _defaultPausers,
address _linkerFactory,
bytes32 _linkerCodeHash
)
HyperdriveFactory(
_governance,
_deployer,
_hyperdriveGovernance,
_feeCollector,
_fees,
_defaultPausers
_defaultPausers,
_linkerFactory,
_linkerCodeHash
)
{}

/// @notice Deploys a copy of hyperdrive with the given params
/// @param _config The configuration of the Hyperdrive pool.
/// @param _linkerCodeHash The hash of the ERC20 linker contract's
/// constructor code.
/// @param _linkerFactory The address of the factory which is used to deploy
/// the ERC20 linker contracts.
/// @param _contribution Base token to call init with
/// @param _apr The apr to call init with
/// @return The hyperdrive address deployed
function deployAndInitialize(
IHyperdrive.PoolConfig memory _config,
bytes32 _linkerCodeHash,
address _linkerFactory,
bytes32[] memory,
uint256 _contribution,
uint256 _apr
Expand All @@ -81,14 +81,7 @@ contract AaveHyperdriveFactory is HyperdriveFactory {

// Deploy and initialize the hyperdrive instance.
return
super.deployAndInitialize(
_config,
_linkerCodeHash,
_linkerFactory,
extraData,
_contribution,
_apr
);
super.deployAndInitialize(_config, extraData, _contribution, _apr);
}

/// @notice This deploys a data provider for the aave hyperdrive instance
Expand Down
8 changes: 7 additions & 1 deletion contracts/src/factory/DsrHyperdriveFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ contract DsrHyperdriveFactory is HyperdriveFactory {
/// @param _feeCollector The address which should be set as the fee collector in new deployments
/// @param _fees The fees each deployed instance from this contract will have
/// @param _defaultPausers The default addresses which will be set to have the pauser role
/// @param _linkerFactory The address of the linker factory
/// @param _linkerCodeHash The hash of the linker contract's constructor code.
/// @param dsrManager The Maker DSR manger contract address
constructor(
address _governance,
Expand All @@ -33,6 +35,8 @@ contract DsrHyperdriveFactory is HyperdriveFactory {
address _feeCollector,
IHyperdrive.Fees memory _fees,
address[] memory _defaultPausers,
address _linkerFactory,
bytes32 _linkerCodeHash,
address dsrManager
)
HyperdriveFactory(
Expand All @@ -41,7 +45,9 @@ contract DsrHyperdriveFactory is HyperdriveFactory {
_hyperdriveGovernance,
_feeCollector,
_fees,
_defaultPausers
_defaultPausers,
_linkerFactory,
_linkerCodeHash
)
{
manager = DsrManager(dsrManager);
Expand Down
8 changes: 7 additions & 1 deletion contracts/src/factory/ERC4626HyperdriveFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ contract ERC4626HyperdriveFactory is HyperdriveFactory {
/// @param _feeCollector The address which should be set as the fee collector in new deployments
/// @param _fees The fees each deployed instance from this contract will have
/// @param _defaultPausers The default addresses which will be set to have the pauser role
/// @param _linkerFactory The address of the linker factory
/// @param _linkerCodeHash The hash of the linker contract's constructor code.
/// @param _pool The Maker ERC4626 manger contract address
constructor(
address _governance,
Expand All @@ -33,6 +35,8 @@ contract ERC4626HyperdriveFactory is HyperdriveFactory {
address _feeCollector,
IHyperdrive.Fees memory _fees,
address[] memory _defaultPausers,
address _linkerFactory,
bytes32 _linkerCodeHash,
IERC4626 _pool
)
HyperdriveFactory(
Expand All @@ -41,7 +45,9 @@ contract ERC4626HyperdriveFactory is HyperdriveFactory {
_hyperdriveGovernance,
_feeCollector,
_fees,
_defaultPausers
_defaultPausers,
_linkerFactory,
_linkerCodeHash
)
{
pool = _pool;
Expand Down
70 changes: 58 additions & 12 deletions contracts/src/factory/HyperdriveFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ abstract contract HyperdriveFactory {
// The address which should control hyperdrive instances
address public hyperdriveGovernance;

// The linker factory which is used to deploy the ERC20 linker contracts.
address public linkerFactory;

// The hash of the ERC20 linker contract's constructor code.
bytes32 public linkerCodeHash;

// The address which should receive hyperdriveFees
address public feeCollector;

Expand All @@ -38,20 +44,34 @@ abstract contract HyperdriveFactory {
// A constant for the ETH value
address internal constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

// An event that is emitted when a new Hyperdrive instance is deployed.
event Deployed(
uint256 indexed version,
address hyperdrive,
IHyperdrive.PoolConfig config,
address linkerFactory,
bytes32 linkerCodeHash,
bytes32[] extraData
);

/// @notice Deploys the contract
/// @param _governance The address which can update this factory.
/// @param _deployer The contract which holds the bytecode and deploys new versions.
/// @param _hyperdriveGovernance The address which is set as the governor of hyperdrive
/// @param _feeCollector The address which should be set as the fee collector in new deployments
/// @param _fees The fees each deployed instance from this contract will have
/// @param _defaultPausers The default addresses which will be set to have the pauser role
/// @param _linkerFactory The address of the linker factory
/// @param _linkerCodeHash The hash of the linker contract's constructor code.
constructor(
address _governance,
IHyperdriveDeployer _deployer,
address _hyperdriveGovernance,
address _feeCollector,
IHyperdrive.Fees memory _fees,
address[] memory _defaultPausers
address[] memory _defaultPausers,
address _linkerFactory,
bytes32 _linkerCodeHash
) {
governance = _governance;
hyperdriveDeployer = _deployer;
Expand All @@ -60,6 +80,8 @@ abstract contract HyperdriveFactory {
feeCollector = _feeCollector;
fees = _fees;
defaultPausers = _defaultPausers;
linkerFactory = _linkerFactory;
linkerCodeHash = _linkerCodeHash;
}

modifier onlyGovernance() {
Expand Down Expand Up @@ -94,6 +116,25 @@ abstract contract HyperdriveFactory {
hyperdriveGovernance = newGovernance;
}

/// @notice Allows governance to change the linker factory.
/// @param newLinkerFactory The new linker code hash.
function updateLinkerFactory(
address newLinkerFactory
) external onlyGovernance {
// Update the linker factory
linkerFactory = newLinkerFactory;
}

/// @notice Allows governance to change the linker code hash. This allows
/// governance to update the implementation of the ERC20Forwarder.
/// @param newLinkerCodeHash The new linker code hash.
function updateLinkerCodeHash(
bytes32 newLinkerCodeHash
) external onlyGovernance {
// Update the linker code hash
linkerCodeHash = newLinkerCodeHash;
}

/// @notice Allows governance to change the fee collector address
/// @param newFeeCollector The new governor address
function updateFeeCollector(
Expand Down Expand Up @@ -123,18 +164,12 @@ abstract contract HyperdriveFactory {

/// @notice Deploys a copy of hyperdrive with the given params
/// @param _config The configuration of the Hyperdrive pool.
/// @param _linkerCodeHash The hash of the ERC20 linker contract's
/// constructor code.
/// @param _linkerFactory The address of the factory which is used to deploy
/// the ERC20 linker contracts.
/// @param _extraData The extra data is used by some factories
/// @param _contribution Base token to call init with
/// @param _apr The apr to call init with
/// @return The hyperdrive address deployed
function deployAndInitialize(
IHyperdrive.PoolConfig memory _config,
bytes32 _linkerCodeHash,
address _linkerFactory,
bytes32[] memory _extraData,
uint256 _contribution,
uint256 _apr
Expand All @@ -149,17 +184,17 @@ abstract contract HyperdriveFactory {
address dataProvider = deployDataProvider(
_config,
_extraData,
_linkerCodeHash,
_linkerFactory
linkerCodeHash,
linkerFactory
);

// Then we call the simplified factory
IHyperdrive hyperdrive = IHyperdrive(
hyperdriveDeployer.deploy(
_config,
dataProvider,
_linkerCodeHash,
_linkerFactory,
linkerCodeHash,
linkerFactory,
_extraData
)
);
Expand Down Expand Up @@ -197,7 +232,18 @@ abstract contract HyperdriveFactory {
// Mark as a version
isOfficial[address(hyperdrive)] = versionCounter;

return (hyperdrive);
// Emit a deployed event.
_config.governance = hyperdriveGovernance;
emit Deployed(
versionCounter,
address(hyperdrive),
_config,
linkerFactory,
linkerCodeHash,
_extraData
);

return hyperdrive;
}

/// @notice This should deploy a data provider which matches the type of the hyperdrives
Expand Down
8 changes: 7 additions & 1 deletion contracts/src/factory/StethHyperdriveFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ contract StethHyperdriveFactory is HyperdriveFactory {
/// @param _feeCollector The address which should be set as the fee collector in new deployments
/// @param _fees The fees each deployed instance from this contract will have
/// @param _defaultPausers The default addresses which will be set to have the pauser role
/// @param _linkerFactory The address of the linker factory
/// @param _linkerCodeHash The hash of the linker contract's constructor code.
/// @param _lido The Lido contract.
constructor(
address _governance,
Expand All @@ -35,6 +37,8 @@ contract StethHyperdriveFactory is HyperdriveFactory {
address _feeCollector,
IHyperdrive.Fees memory _fees,
address[] memory _defaultPausers,
address _linkerFactory,
bytes32 _linkerCodeHash,
ILido _lido
)
HyperdriveFactory(
Expand All @@ -43,7 +47,9 @@ contract StethHyperdriveFactory is HyperdriveFactory {
_hyperdriveGovernance,
_feeCollector,
_fees,
_defaultPausers
_defaultPausers,
_linkerFactory,
_linkerCodeHash
)
{
lido = _lido;
Expand Down
29 changes: 21 additions & 8 deletions test/integrations/ERC4626.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { IHyperdriveDeployer } from "contracts/src/interfaces/IHyperdriveDeploye
import { AssetId } from "contracts/src/libraries/AssetId.sol";
import { Errors } from "contracts/src/libraries/Errors.sol";
import { FixedPointMath } from "contracts/src/libraries/FixedPointMath.sol";
import { ForwarderFactory } from "contracts/src/token/ForwarderFactory.sol";
import { HyperdriveTest } from "../utils/HyperdriveTest.sol";
import { Mock4626, ERC20 } from "../mocks/Mock4626.sol";
import { MockERC4626Hyperdrive } from "../mocks/Mock4626Hyperdrive.sol";
Expand All @@ -27,7 +28,7 @@ contract HyperdriveER4626Test is HyperdriveTest {
function setUp() public override __mainnet_fork(16_685_972) {
vm.startPrank(deployer);

// Deploy a new yield source
// Deploy the ERC4626Hyperdrive factory and deployer.
pool = IERC4626(
address(new Mock4626(ERC20(address(dai)), "yearn dai", "yDai"))
);
Expand All @@ -37,19 +38,20 @@ contract HyperdriveER4626Test is HyperdriveTest {
);
address[] memory defaults = new address[](1);
defaults[0] = bob;

forwarderFactory = new ForwarderFactory();
factory = new ERC4626HyperdriveFactory(
alice,
simpleDeployer,
bob,
bob,
IHyperdrive.Fees(0, 0, 0),
defaults,
address(forwarderFactory),
forwarderFactory.ERC20LINK_HASH(),
pool
);

address daiWhale = 0x075e72a5eDf65F0A5f44699c7654C1a76941Ddc8;

whaleTransfer(daiWhale, dai, alice);

IHyperdrive.PoolConfig memory config = IHyperdrive.PoolConfig({
Expand Down Expand Up @@ -88,6 +90,9 @@ contract HyperdriveER4626Test is HyperdriveTest {
dai.approve(address(hyperdrive), type(uint256).max);
dai.approve(address(mockHyperdrive), type(uint256).max);
vm.stopPrank();

// Start recording events.
vm.recordLogs();
}

function test_erc4626_deposit() external {
Expand All @@ -105,7 +110,7 @@ contract HyperdriveER4626Test is HyperdriveTest {
assertEq(sharesMinted, 666666666666666666);
assertEq(pool.balanceOf(address(mockHyperdrive)), 666666666666666666);

//Now we try to do a deposit from alice's shares
// Now we try to do a deposit from alice's shares
pool.approve(address(mockHyperdrive), type(uint256).max);
(sharesMinted, sharePrice) = mockHyperdrive.deposit(3e18, false);
assertEq(sharePrice, 1.5e18 + 1);
Expand Down Expand Up @@ -149,7 +154,8 @@ contract HyperdriveER4626Test is HyperdriveTest {
function test_erc4626_testDeploy() external {
setUp();
vm.startPrank(alice);
uint256 apr = 1e16; // 1% apr
uint256 apr = 0.01e18; // 1% apr
uint256 contribution = 2_500e18;
IHyperdrive.PoolConfig memory config = IHyperdrive.PoolConfig({
baseToken: dai,
initialSharePrice: FixedPointMath.ONE_18,
Expand All @@ -165,10 +171,8 @@ contract HyperdriveER4626Test is HyperdriveTest {
dai.approve(address(factory), type(uint256).max);
hyperdrive = factory.deployAndInitialize(
config,
bytes32(0),
address(0),
new bytes32[](0),
2500e18,
contribution,
apr
);

Expand All @@ -180,5 +184,14 @@ contract HyperdriveER4626Test is HyperdriveTest {
);
// lp shares should equal number of share reserves initialized with
assertEq(createdShares, 2500e18);

// Verify that the correct events were emitted.
verifyFactoryEvents(
factory,
alice,
contribution,
apr,
new bytes32[](0)
);
}
}
Loading