Skip to content

Conversation

@ChaoticWalrus
Copy link
Contributor

@ChaoticWalrus ChaoticWalrus commented Apr 18, 2024

Proposal Doc: https://docs.google.com/document/d/1C1nN6BkCMS0Z9EnizU0pNYNNOiRd_FH6E2Vd-ZPULro/edit?usp=sharing

High-Level Notes on Design

This avoid making any changes to existing "core" protocol contracts, and is instead purely additive.
In particular, this change is effectively turning the strategyWhitelister role in the StrategyManager into a smart contract -- the ability to whitelist particular strategies is maintained with a pass-through function, while the ability to whitelist factory-generated strategy contracts is made permissionless.

Summary

The StrategyFactory allows any caller to deploy a StrategyBase contract for any ERC20 token

  • Technically, a BeaconProxy contract is deployed, pointing to a reference implementation
  • Upgrades are controlled by a new BeaconProxy, with the same control of upgrades as our existing contracts
  • Pausing power is also given to the same PauserRegistry as we use now
  • The token cannot already have a Strategy deployed for it (only one deployment from the factory per token)
  • We store a mapping(IERC20 token => IStrategy) public tokenStrategies and check against previous writes
  • Owner can pass-through this contract to whitelist new strategy contracts
  • The StrategyFactory contract is itself upgradeable, to potentially allow other feature additions in the future

Still needs a few things, including documentation that provides warnings against using reentrant tokens (e.g. ERC777), or other non-standard tokens, and more extensive testing

Deployment

  • Deploy Upgradeable Beacon for Beacon Proxies, with ownership given to the executor multisig (so upgrade rights work like our existing contracts)
  • Deploy StrategyFactory implementation, pointing to Strategy Manager (immutable variable)
  • Deploy StrategyFactory (proxy), giving ownership to Ops Multisig (so it maintains similar manual-whitelisting powers), pausing powers to the existing protocol-wide PausingRegistry, and proxy upgrade powers to the existing protocol-wide ProxyAdmin (+ pointing to the Upgradeable Beacon & StrategyFactory implementation deployed above)
  • Transfer strategyWhitelister role in the StrategyManager to the StrategyFactory (proxy) -- this will require an executor multisig action and thus be subject to a 10-day timelock delay if accomplished via the ops multisig

@github-actions

This comment was marked as duplicate.

@wadealexc wadealexc force-pushed the feat-StrategyFactory branch from fd751e3 to 6da040d Compare July 1, 2024 18:14
Copy link
Contributor

@wadealexc wadealexc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks fine, but IMO we want the BeaconProxy pattern!

@ChaoticWalrus
Copy link
Contributor Author

Overall looks fine, but IMO we want the BeaconProxy pattern!

switch to beacon proxies implemented in 5d19597

Copy link

@scotthconner scotthconner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comments here mostly reflect what I put in the technical proposal. Nothing super critical, but understanding the core contract interactions and where state is managed is one piece that sticks out to me.

@github-actions

This comment was marked as duplicate.

@github-actions

This comment was marked as duplicate.

@wadealexc wadealexc force-pushed the feat-StrategyFactory branch from ce213b4 to bb5f30b Compare July 12, 2024 15:16
Comment on lines 12 to 13
// @notice Upgradeable beacon which new Strategies deployed by this contract point to
IBeacon public strategyBeacon;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add immutable?

Copy link
Contributor

@wadealexc wadealexc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs docs. I'll put something together tomorrow :)

Copy link
Collaborator

@ypatil12 ypatil12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment

* @notice Owner-only function to prevent strategies from being created for given tokens.
* @param tokens An array of token addresses to blacklist.
*/
function blacklistTokens(IERC20[] calldata tokens) external onlyOwner {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the plan to blacklist already deployed tokens via the initializer? We don't want to get frontrun on a permissionless deployment

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved offline -> the deployment requires us to wait to transfer the strategyWhitelister role so we won't need to add this functionality in the initializer

Comment on lines +56 to +63
IStrategy strategy = IStrategy(
address(
new BeaconProxy(
address(strategyBeacon),
abi.encodeWithSelector(StrategyBase.initialize.selector, token, pauserRegistry)
)
)
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be using Create2 like we do in the EigenPodManager?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an outsider, I definitely +1 this

@Layr-Labs Layr-Labs deleted a comment from github-actions bot Jul 26, 2024
* $dev Immense caution is warranted for non-standard ERC20 tokens, particularly "reentrant" tokens
* like those that conform to ERC777.
*/
function deployNewStrategy(IERC20 token)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not find an event emitted when a new strategy gets deployed. EigenPodManager, for example, emits a PodDeployed event whenever an EigenPod is created, which can be used in subgraph templates to index instantiated contracts. Is it possible to do the same here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use the StrategyAddedToDepositWhitelist event in the StrategyManager instead? Or do you want to track the count of contracts deployed from this contract?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StrategyAddedToDepositWhitelist tracks only EigenLayer approved strategies that are shown on the UI, right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we deploy a strategy through this method, it is added to the deposit whitelist. So it would be both EigenLayer approved AND permissionless strategies

@ypatil12 ypatil12 force-pushed the feat-StrategyFactory branch from 14aa656 to aa05081 Compare August 5, 2024 17:50
@github-actions
Copy link

github-actions bot commented Aug 7, 2024

Reading tracefile ./lcov.info.pruned
                                             |Lines      |Functions|Branches  
Filename                                       |Rate    Num|Rate  Num|Rate   Num
================================================================================
[src/contracts/]
core/AVSDirectory.sol                          |77.8%    27|77.8%   9|    -    0
core/DelegationManager.sol                     |96.5%   198|92.3%  39|    -    0
core/RewardsCoordinator.sol                    |90.8%   119|81.2%  32|    -    0
core/StrategyManager.sol                       |95.2%    83|95.8%  24|    -    0
libraries/BeaconChainProofs.sol                |94.7%    38|91.7%  12|    -    0
libraries/BytesLib.sol                         | 2.6%   156| 7.1%  14|    -    0
libraries/EIP1271SignatureUtils.sol            | 100%     3| 100%   1|    -    0
libraries/Endian.sol                           | 100%     2| 100%   1|    -    0
libraries/Merkle.sol                           | 100%    38| 100%   5|    -    0
libraries/StructuredLinkedList.sol             | 0.0%    45| 0.0%  19|    -    0
permissions/Pausable.sol                       |95.7%    23|90.9%  11|    -    0
permissions/PauserRegistry.sol                 | 100%    12| 100%   6|    -    0
pods/DelayedWithdrawalRouter.sol               |93.2%    59|85.7%  14|    -    0
pods/EigenPod.sol                              | 100%   145| 100%  33|    -    0
pods/EigenPodManager.sol                       |98.8%    84|89.5%  19|    -    0
strategies/EigenStrategy.sol                   | 0.0%    10| 0.0%   5|    -    0
strategies/StrategyBase.sol                    |90.9%    44|78.9%  19|    -    0
strategies/StrategyBaseTVLLimits.sol           | 100%    12|83.3%   6|    -    0
strategies/StrategyFactory.sol                 |94.3%    35|88.9%   9|    -    0
token/BackingEigen.sol                         |72.0%    25|50.0%  10|    -    0
token/Eigen.sol                                |38.5%    39|50.0%  12|    -    0
utils/UpgradeableSignatureCheckingUtils.sol    | 0.0%     6| 0.0%   4|    -    0
================================================================================
                                       Total:|76.2%  1203|75.0% 304|    -    0

@Layr-Labs Layr-Labs deleted a comment from github-actions bot Aug 7, 2024
@Layr-Labs Layr-Labs deleted a comment from github-actions bot Aug 7, 2024
@Layr-Labs Layr-Labs deleted a comment from github-actions bot Aug 7, 2024
@Layr-Labs Layr-Labs deleted a comment from github-actions bot Aug 7, 2024
@Layr-Labs Layr-Labs deleted a comment from github-actions bot Aug 7, 2024
@Layr-Labs Layr-Labs deleted a comment from github-actions bot Aug 7, 2024
@Layr-Labs Layr-Labs deleted a comment from github-actions bot Aug 7, 2024
@Layr-Labs Layr-Labs deleted a comment from github-actions bot Aug 7, 2024
@Layr-Labs Layr-Labs deleted a comment from github-actions bot Aug 7, 2024
@Layr-Labs Layr-Labs deleted a comment from github-actions bot Aug 7, 2024
@Layr-Labs Layr-Labs deleted a comment from github-actions bot Aug 7, 2024
@Layr-Labs Layr-Labs deleted a comment from github-actions bot Aug 7, 2024
@wadealexc wadealexc dismissed stale reviews from ypatil12 and scotthconner August 7, 2024 18:49

old

@wadealexc wadealexc force-pushed the feat-StrategyFactory branch from bd1cc42 to 0960524 Compare August 7, 2024 18:51
@wadealexc wadealexc marked this pull request as ready for review August 7, 2024 18:52
* fix: make the StrategyFactory actually whitelist new strategies

* feat: add several unit tests for the StrategyFactory

* feat: switch to beacon proxies

* feat: split storage, create interface, and rename

- separate storage contract

- create interface -- storage contract inherits from it

- rename `tokenStrategies` => `tokenStrategy` for clarity

* chore: move events to interface

* feat: additional unit tests, interface cleanup

* feat: reduce owner powers, make mapping behavior strict

- remove `editTokenStrategiesMapping` and `setStrategyBeacon` functions

- make the `whitelistStrategies` pass-through function no longer edit the `tokenStrategy` mapping

- delete and modify related tests, as necessary

* feat: add several unit tests for the StrategyFactory

* feat: switch to beacon proxies

* feat: additional unit tests, interface cleanup

* feat: reduce owner powers, make mapping behavior strict

- remove `editTokenStrategiesMapping` and `setStrategyBeacon` functions

- make the `whitelistStrategies` pass-through function no longer edit the `tokenStrategy` mapping

- delete and modify related tests, as necessary

* chore: formatting

feat: add `blacklistTokens` fn

refactor: separate mapping

Feat: add `sharesToUnderlying` event (#644)

* feat: add `sharesToUnderlying` event

* refactor: cleanup

* refactor: separate logic to new fn

* test: sanity

feat: emit exchange rate on deposits/withdrawals (#647)

* feat: exchange rate in deposits/withdrawals

* chore: forge fmt

---------

Co-authored-by: clandestine.eth <96172957+0xClandestine@users.noreply.github.com>

fix: strategy unit tests

feat: add pass thoughts for all `strategyWhitelister` gated functions (#648)

docs: add documentation for strategy factory methods

chore: make bindings

feat: change name of tokenStrategy mapping to deployedStrategies (#657)

feat: auto remove strategies from whitelist (#658)

feat: limit total shares on `StrategyBase` (#659)

* feat: limit totalShares

* chore: update natspec

* chore: bindings & formatting

* chore: bindings

* docs: update docs with max total shares change

* chore: fix formatting

---------

Co-authored-by: wadealexc <pragma-services@proton.me>

fix: natspec strategy factory (#660)

* fix: natspec

* chore: format

* chore: bindings

* chore: bindings

* chore: bindings

feat: integration tests

docs: wip readme update

docs: finalize deployment info in readme
@wadealexc wadealexc force-pushed the feat-StrategyFactory branch from 0960524 to b8694e9 Compare August 7, 2024 18:54
@wadealexc
Copy link
Contributor

wadealexc commented Aug 7, 2024

All the activity you're seeing here is:

  • squashing the PR into a single commit to make rebasing easier (git rebase -i HEAD~18, then squashing all the commits into 1)
  • rebasing on top of dev to make merging clean (git rebase dev, then fix the conflicts)
  • force push when done (git push --force)

@github-actions
Copy link

github-actions bot commented Aug 7, 2024

Reading tracefile ./lcov.info.pruned
                                             |Lines      |Functions|Branches  
Filename                                       |Rate    Num|Rate  Num|Rate   Num
================================================================================
[src/contracts/]
core/AVSDirectory.sol                          |77.8%    27|77.8%   9|    -    0
core/DelegationManager.sol                     |96.5%   198|92.3%  39|    -    0
core/RewardsCoordinator.sol                    |90.8%   119|81.2%  32|    -    0
core/StrategyManager.sol                       |95.2%    83|95.8%  24|    -    0
libraries/BeaconChainProofs.sol                |94.7%    38|91.7%  12|    -    0
libraries/BytesLib.sol                         | 2.6%   156| 7.1%  14|    -    0
libraries/EIP1271SignatureUtils.sol            | 100%     3| 100%   1|    -    0
libraries/Endian.sol                           | 100%     2| 100%   1|    -    0
libraries/Merkle.sol                           | 100%    38| 100%   5|    -    0
libraries/StructuredLinkedList.sol             | 0.0%    45| 0.0%  19|    -    0
permissions/Pausable.sol                       |95.7%    23|90.9%  11|    -    0
permissions/PauserRegistry.sol                 | 100%    12| 100%   6|    -    0
pods/DelayedWithdrawalRouter.sol               |93.2%    59|85.7%  14|    -    0
pods/EigenPod.sol                              | 100%   145| 100%  33|    -    0
pods/EigenPodManager.sol                       |98.8%    84|89.5%  19|    -    0
strategies/EigenStrategy.sol                   | 0.0%    10| 0.0%   5|    -    0
strategies/StrategyBase.sol                    |90.9%    44|78.9%  19|    -    0
strategies/StrategyBaseTVLLimits.sol           | 100%    12|83.3%   6|    -    0
strategies/StrategyFactory.sol                 |94.3%    35|88.9%   9|    -    0
token/BackingEigen.sol                         |72.0%    25|50.0%  10|    -    0
token/Eigen.sol                                |38.5%    39|50.0%  12|    -    0
utils/UpgradeableSignatureCheckingUtils.sol    | 0.0%     6| 0.0%   4|    -    0
================================================================================
                                       Total:|76.2%  1203|75.0% 304|    -    0

1 similar comment
@github-actions
Copy link

github-actions bot commented Aug 7, 2024

Reading tracefile ./lcov.info.pruned
                                             |Lines      |Functions|Branches  
Filename                                       |Rate    Num|Rate  Num|Rate   Num
================================================================================
[src/contracts/]
core/AVSDirectory.sol                          |77.8%    27|77.8%   9|    -    0
core/DelegationManager.sol                     |96.5%   198|92.3%  39|    -    0
core/RewardsCoordinator.sol                    |90.8%   119|81.2%  32|    -    0
core/StrategyManager.sol                       |95.2%    83|95.8%  24|    -    0
libraries/BeaconChainProofs.sol                |94.7%    38|91.7%  12|    -    0
libraries/BytesLib.sol                         | 2.6%   156| 7.1%  14|    -    0
libraries/EIP1271SignatureUtils.sol            | 100%     3| 100%   1|    -    0
libraries/Endian.sol                           | 100%     2| 100%   1|    -    0
libraries/Merkle.sol                           | 100%    38| 100%   5|    -    0
libraries/StructuredLinkedList.sol             | 0.0%    45| 0.0%  19|    -    0
permissions/Pausable.sol                       |95.7%    23|90.9%  11|    -    0
permissions/PauserRegistry.sol                 | 100%    12| 100%   6|    -    0
pods/DelayedWithdrawalRouter.sol               |93.2%    59|85.7%  14|    -    0
pods/EigenPod.sol                              | 100%   145| 100%  33|    -    0
pods/EigenPodManager.sol                       |98.8%    84|89.5%  19|    -    0
strategies/EigenStrategy.sol                   | 0.0%    10| 0.0%   5|    -    0
strategies/StrategyBase.sol                    |90.9%    44|78.9%  19|    -    0
strategies/StrategyBaseTVLLimits.sol           | 100%    12|83.3%   6|    -    0
strategies/StrategyFactory.sol                 |94.3%    35|88.9%   9|    -    0
token/BackingEigen.sol                         |72.0%    25|50.0%  10|    -    0
token/Eigen.sol                                |38.5%    39|50.0%  12|    -    0
utils/UpgradeableSignatureCheckingUtils.sol    | 0.0%     6| 0.0%   4|    -    0
================================================================================
                                       Total:|76.2%  1203|75.0% 304|    -    0

@wadealexc wadealexc merged commit d3730b5 into dev Aug 7, 2024
@wadealexc wadealexc deleted the feat-StrategyFactory branch August 7, 2024 19:01
@github-actions
Copy link

github-actions bot commented Aug 7, 2024

Reading tracefile ./lcov.info.pruned
                                             |Lines      |Functions|Branches  
Filename                                       |Rate    Num|Rate  Num|Rate   Num
================================================================================
[src/contracts/]
core/AVSDirectory.sol                          |77.8%    27|77.8%   9|    -    0
core/DelegationManager.sol                     |96.5%   198|92.3%  39|    -    0
core/RewardsCoordinator.sol                    |90.8%   119|81.2%  32|    -    0
core/StrategyManager.sol                       |95.2%    83|95.8%  24|    -    0
libraries/BeaconChainProofs.sol                |94.7%    38|91.7%  12|    -    0
libraries/BytesLib.sol                         | 2.6%   156| 7.1%  14|    -    0
libraries/EIP1271SignatureUtils.sol            | 100%     3| 100%   1|    -    0
libraries/Endian.sol                           | 100%     2| 100%   1|    -    0
libraries/Merkle.sol                           | 100%    38| 100%   5|    -    0
libraries/StructuredLinkedList.sol             | 0.0%    45| 0.0%  19|    -    0
permissions/Pausable.sol                       |95.7%    23|90.9%  11|    -    0
permissions/PauserRegistry.sol                 | 100%    12| 100%   6|    -    0
pods/DelayedWithdrawalRouter.sol               |93.2%    59|85.7%  14|    -    0
pods/EigenPod.sol                              | 100%   145| 100%  33|    -    0
pods/EigenPodManager.sol                       |98.8%    84|89.5%  19|    -    0
strategies/EigenStrategy.sol                   | 0.0%    10| 0.0%   5|    -    0
strategies/StrategyBase.sol                    |90.9%    44|78.9%  19|    -    0
strategies/StrategyBaseTVLLimits.sol           | 100%    12|83.3%   6|    -    0
strategies/StrategyFactory.sol                 |94.3%    35|88.9%   9|    -    0
token/BackingEigen.sol                         |72.0%    25|50.0%  10|    -    0
token/Eigen.sol                                |38.5%    39|50.0%  12|    -    0
utils/UpgradeableSignatureCheckingUtils.sol    | 0.0%     6| 0.0%   4|    -    0
================================================================================
                                       Total:|76.2%  1203|75.0% 304|    -    0

1 similar comment
@github-actions
Copy link

github-actions bot commented Aug 7, 2024

Reading tracefile ./lcov.info.pruned
                                             |Lines      |Functions|Branches  
Filename                                       |Rate    Num|Rate  Num|Rate   Num
================================================================================
[src/contracts/]
core/AVSDirectory.sol                          |77.8%    27|77.8%   9|    -    0
core/DelegationManager.sol                     |96.5%   198|92.3%  39|    -    0
core/RewardsCoordinator.sol                    |90.8%   119|81.2%  32|    -    0
core/StrategyManager.sol                       |95.2%    83|95.8%  24|    -    0
libraries/BeaconChainProofs.sol                |94.7%    38|91.7%  12|    -    0
libraries/BytesLib.sol                         | 2.6%   156| 7.1%  14|    -    0
libraries/EIP1271SignatureUtils.sol            | 100%     3| 100%   1|    -    0
libraries/Endian.sol                           | 100%     2| 100%   1|    -    0
libraries/Merkle.sol                           | 100%    38| 100%   5|    -    0
libraries/StructuredLinkedList.sol             | 0.0%    45| 0.0%  19|    -    0
permissions/Pausable.sol                       |95.7%    23|90.9%  11|    -    0
permissions/PauserRegistry.sol                 | 100%    12| 100%   6|    -    0
pods/DelayedWithdrawalRouter.sol               |93.2%    59|85.7%  14|    -    0
pods/EigenPod.sol                              | 100%   145| 100%  33|    -    0
pods/EigenPodManager.sol                       |98.8%    84|89.5%  19|    -    0
strategies/EigenStrategy.sol                   | 0.0%    10| 0.0%   5|    -    0
strategies/StrategyBase.sol                    |90.9%    44|78.9%  19|    -    0
strategies/StrategyBaseTVLLimits.sol           | 100%    12|83.3%   6|    -    0
strategies/StrategyFactory.sol                 |94.3%    35|88.9%   9|    -    0
token/BackingEigen.sol                         |72.0%    25|50.0%  10|    -    0
token/Eigen.sol                                |38.5%    39|50.0%  12|    -    0
utils/UpgradeableSignatureCheckingUtils.sol    | 0.0%     6| 0.0%   4|    -    0
================================================================================
                                       Total:|76.2%  1203|75.0% 304|    -    0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants