Skip to content

Commit 71c6688

Browse files
authored
fix: Locked down the sweep function (#473)
* Locked down the `sweep` function * Added a check on `isSweepable` in `test_erc4626_sweep` * Appeased the linter * Turned optimizer down to avoid code size issues * Addressed review feedback from @jrhea
1 parent 014108a commit 71c6688

10 files changed

Lines changed: 375 additions & 177 deletions

cSpell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
"streetsidesoftware",
113113
"struct",
114114
"structs",
115+
"Sweepable",
115116
"timestretch",
116117
"totalweth",
117118
"tsmerge",

contracts/src/factory/ERC4626HyperdriveDeployer.sol

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ contract ERC4626HyperdriveDeployer is IHyperdriveDeployer {
2525
/// @notice Deploys a copy of hyperdrive with the given params.
2626
/// @param _config The configuration of the Hyperdrive pool.
2727
/// @param _dataProvider The address of the data provider.
28+
/// @param _extraData The extra data that contains the sweep targets.
2829
/// @param _linkerCodeHash The hash of the ERC20 linker contract's
2930
/// constructor code.
3031
/// @param _linkerFactory The address of the factory which is used to deploy
@@ -35,16 +36,24 @@ contract ERC4626HyperdriveDeployer is IHyperdriveDeployer {
3536
address _dataProvider,
3637
bytes32 _linkerCodeHash,
3738
address _linkerFactory,
38-
bytes32[] calldata
39+
bytes32[] memory _extraData
3940
) external override returns (address) {
41+
// Convert the extra data to an array of addresses.
42+
address[] memory sweepTargets;
43+
assembly ("memory-safe") {
44+
sweepTargets := _extraData
45+
}
46+
47+
// Deploy the ERC4626Hyperdrive instance.
4048
return (
4149
address(
4250
new ERC4626Hyperdrive(
4351
_config,
4452
_dataProvider,
4553
_linkerCodeHash,
4654
_linkerFactory,
47-
pool
55+
pool,
56+
sweepTargets
4857
)
4958
)
5059
);

contracts/src/factory/ERC4626HyperdriveFactory.sol

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,28 @@ import { IERC4626 } from "../interfaces/IERC4626.sol";
1616
/// only, and is not intended to, and does not, have any
1717
/// particular legal or regulatory significance.
1818
contract ERC4626HyperdriveFactory is HyperdriveFactory {
19+
/// @dev The address of the ERC4626 pool used in this factory.
1920
IERC4626 internal immutable pool;
2021

21-
/// @notice Deploys the contract
22+
/// @notice The sweep targets used in deployed instances. This specifies
23+
/// the addresses that the fee collector can sweep to collect
24+
/// incentives and redistribute them.
25+
address[] internal _sweepTargets;
26+
27+
/// @notice Initializes the factory.
2228
/// @param _factoryConfig The variables that configure the factory;
23-
/// @param _deployer The contract which holds the bytecode and deploys new versions.
24-
/// @param _linkerFactory The address of the linker factory.
29+
/// @param _deployer The contract that deploys new hyperdrive instances.
30+
/// @param _linkerFactory The linker factory.
2531
/// @param _linkerCodeHash The hash of the linker contract's constructor code.
26-
/// @param _pool The Maker ERC4626 manger contract address
32+
/// @param _pool The ERC4626 pool.
33+
/// @param _sweepTargets_ The addresses that can be swept by the fee collector.
2734
constructor(
2835
FactoryConfig memory _factoryConfig,
2936
IHyperdriveDeployer _deployer,
3037
address _linkerFactory,
3138
bytes32 _linkerCodeHash,
32-
IERC4626 _pool
39+
IERC4626 _pool,
40+
address[] memory _sweepTargets_
3341
)
3442
HyperdriveFactory(
3543
_factoryConfig,
@@ -38,7 +46,48 @@ contract ERC4626HyperdriveFactory is HyperdriveFactory {
3846
_linkerCodeHash
3947
)
4048
{
49+
// Initialize the ERC4626 pool.
4150
pool = _pool;
51+
52+
// Initialize the default sweep targets.
53+
_sweepTargets = _sweepTargets_;
54+
}
55+
56+
/// @notice Allows governance to change the sweep targets used in deployed
57+
/// instances.
58+
/// @param _sweepTargets_ The new sweep targets.
59+
function updateSweepTargets(
60+
address[] calldata _sweepTargets_
61+
) external onlyGovernance {
62+
_sweepTargets = _sweepTargets_;
63+
}
64+
65+
/// @notice This deploys and initializes a new ERC4626Hyperdrive instance.
66+
/// @param _config The pool configuration.
67+
/// @param _contribution The contribution amount.
68+
/// @param _apr The initial spot rate.
69+
function deployAndInitialize(
70+
IHyperdrive.PoolConfig memory _config,
71+
bytes32[] memory,
72+
uint256 _contribution,
73+
uint256 _apr
74+
) public payable override returns (IHyperdrive) {
75+
// Deploy and initialize the ERC4626 hyperdrive instance with the
76+
// default sweep targets provided as extra data.
77+
address[] memory sweepTargets_ = _sweepTargets;
78+
bytes32[] memory extraData;
79+
assembly ("memory-safe") {
80+
extraData := sweepTargets_
81+
}
82+
IHyperdrive hyperdrive = super.deployAndInitialize(
83+
_config,
84+
extraData,
85+
_contribution,
86+
_apr
87+
);
88+
89+
// Return the hyperdrive instance.
90+
return hyperdrive;
4291
}
4392

4493
/// @notice This deploys a data provider for the ERC4626 hyperdrive instance
@@ -62,4 +111,10 @@ contract ERC4626HyperdriveFactory is HyperdriveFactory {
62111
)
63112
);
64113
}
114+
115+
/// @notice Gets the sweep targets.
116+
/// @return The sweep targets.
117+
function getSweepTargets() external view returns (address[] memory) {
118+
return _sweepTargets;
119+
}
65120
}

0 commit comments

Comments
 (0)