Skip to content

Commit

Permalink
Added a Morpho Blue integration (#1094)
Browse files Browse the repository at this point in the history
* Implemented a basic version of the `addLiquidity` circuit breaker

* Fixed `test_lp_withdrawal_long_and_short_maturity`

* Fixed the remaining tests

* add priceDiscoveryCheck to LPMath and also check it in initialize

* use initial price

* add tests and fix placement of check

* remove lib from LPMath

* remove comment

* remove console import

* remove console import

* fix price discovery tests

* fixed tests

* commit test to investigate

* add test_solvency_at_0_apr

* add test_solvency_cross_checkpoint_long_short

* address review feedback

* Update test/integrations/hyperdrive/PriceDiscovery.t.sol

* Added some testing examples

* Minor updates

* Updated `verifyPriceDiscovery` to `calculateSolvencyAfterMaxLong`

* Cleaned up the tests

* Increased the efficiency of the solvency check

* Fixed the code size issue

* Addressed Saw Mon's comment

* Improved one of the price discovery tests

* Updated the price discovery tests

* Fixed the remaining tests

* Addressed review feedback from @mcclurejt

* Fixed the deployment scripts

* Generated the code for the Aave integration

* forge install: aave-v3-core

v1.19.1

* Fixed codegen and compiler errors

* Implemented `_convertToBase` and `_convertToShares` for AaveHyperdrive

* Implemented the deposit functions for the AaveHyperdrive instance

* Implemented the withdrawal logic for ATokens

* Addressed most of the remaining FIXMEs

* Reduced the code-size of the Aave integration

* Copied over the instance test

* Added a fourth target to fix the codesize issues

* Started work on the AaveHyperdrive tests

* Fixed some of the tests

* Fixed more tests

* Fixed the remaining Aave instance tests

* Fixed the other instance tests

* Addressed remaining FIXMEs and fixed the code generator

* Fixed the publish scripts

* Lowered the minimum share reserves

* Addressed review feedback from @jrhea

* Added conversion functions to the public interfaces for instances and deployer coordinators

* Added the skeleton for `MorphoBlueHyperdrive`

* Sketched out the implementation plan

* forge install: morpho-blue

v1.0.0

* Made some progress on the Morpho integration

* Updated the Morpho Blue integration to use a struct in the constructors

* Addressed the remaining FIXMEs in the Morpho Blue integration

* Wrote the morpho tests

* Updated some tests

* "Fixed" the tests

* Improved the Morpho Blue tests to add confidence in the integration

* Fixed tests

* Fixed the stETH tests

* Addressed review feedback from @jrhea and @mcclurejt

---------

Co-authored-by: jonny rhea <[email protected]>
Co-authored-by: Jonny Rhea <[email protected]>
  • Loading branch information
3 people authored Jul 18, 2024
1 parent c8b9ece commit 2514eec
Show file tree
Hide file tree
Showing 33 changed files with 2,098 additions and 133 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
[submodule "lib/aave-v3-core"]
path = lib/aave-v3-core
url = https://github.com/aave/aave-v3-core
[submodule "lib/morpho-blue"]
path = lib/morpho-blue
url = https://github.com/morpho-org/morpho-blue
11 changes: 7 additions & 4 deletions codegen/example/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@
name:
# Capitalized version of the name to be used i.e. for contract names, file
# names, and comments.
capitalized: "TestETH"
capitalized: "MorphoBlue"

# All upper case name to be used for constants.
uppercase: "MORPHO_BLUE"

# All upper case name to be used for constants.
uppercase: "TEST_ETH"

# All lower case name to be used for directories.
lowercase: "testeth"
lowercase: "morpho-blue"

# Camel case name to be used i.e. for variables.
camelcase: "testEth"
camelcase: "morphoBlue"

# Configuration parameters for the hyperdrive instance.
contract:
# If the contract is payable in Ether. If it is, then logic should be added
# to accept Ether, and deposit into the vault to obtain vault shares.
payable: true
payable: false

# If the contract can accept base to convert to valut shares on behalf of the
# user.
Expand Down
12 changes: 11 additions & 1 deletion codegen/templates/deployers/HyperdriveCoreDeployer.sol.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ contract {{ name.capitalized }}HyperdriveCoreDeployer is IHyperdriveCoreDeployer
/// @param _target1 The target1 address.
/// @param _target2 The target2 address.
/// @param _target3 The target3 address.
/// @param _target4 The target4 address.
/// @param _salt The create2 salt used in the deployment.
/// @return The address of the newly deployed {{ name.capitalized }}Hyperdrive instance.
function deployHyperdrive(
Expand All @@ -29,6 +30,7 @@ contract {{ name.capitalized }}HyperdriveCoreDeployer is IHyperdriveCoreDeployer
address _target1,
address _target2,
address _target3,
address _target4,
bytes32 _salt
) external returns (address) {
return (
Expand All @@ -37,7 +39,15 @@ contract {{ name.capitalized }}HyperdriveCoreDeployer is IHyperdriveCoreDeployer
// front-running of deployments.
new {{ name.capitalized }}Hyperdrive{
salt: keccak256(abi.encode(msg.sender, _salt))
}(_config, _target0, _target1, _target2, _target3)
}(
__name,
_config,
_target0,
_target1,
_target2,
_target3,
_target4
)
)
);
}
Expand Down
10 changes: 9 additions & 1 deletion codegen/templates/instances/Hyperdrive.sol.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ contract {{ name.capitalized }}Hyperdrive is Hyperdrive, {{ name.capitalized }}B
address _target3,
address _target4
)
Hyperdrive(_config, _target0, _target1, _target2, _target3)
Hyperdrive(
__name,
_config,
_target0,
_target1,
_target2,
_target3,
_target4
)
{
// ****************************************************************
// FIXME: Implement this for new instances. ERC4626 example provided.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ contract AaveHyperdriveDeployerCoordinator is
/// pool.
/// @return The initial vault share price of the Hyperdrive pool.
function _getInitialVaultSharePrice(
IHyperdrive.PoolDeployConfig memory _deployConfig, // unused _deployConfig
IHyperdrive.PoolDeployConfig memory _deployConfig,
bytes memory // unused _extraData
) internal view override returns (uint256) {
// We calculate the vault share price by converting 1e18 vault shares to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,12 @@ contract LsETHHyperdriveDeployerCoordinator is
uint256 _contribution,
IHyperdrive.Options memory _options
) internal override returns (uint256) {
// Depositing as base is disallowed.
// Depositing with base is not supported.
if (_options.asBase) {
revert IHyperdrive.UnsupportedToken();
}

// Transfer vault shares from the LP and approve the
// Hyperdrive pool.
// Transfer vault shares from the LP and approve the Hyperdrive pool.
ERC20(address(river)).safeTransferFrom(
_lp,
address(this),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.20;

import { IHyperdrive } from "../../interfaces/IHyperdrive.sol";
import { IHyperdriveCoreDeployer } from "../../interfaces/IHyperdriveCoreDeployer.sol";
import { IMorphoBlueHyperdrive } from "../../interfaces/IMorphoBlueHyperdrive.sol";
import { MorphoBlueHyperdrive } from "../../instances/morpho-blue/MorphoBlueHyperdrive.sol";

/// @author DELV
/// @title MorphoBlueHyperdriveCoreDeployer
/// @notice The core deployer for the MorphoBlueHyperdrive implementation.
/// @custom:disclaimer The language used in this code is for coding convenience
/// only, and is not intended to, and does not, have any
/// particular legal or regulatory significance.
contract MorphoBlueHyperdriveCoreDeployer is IHyperdriveCoreDeployer {
/// @notice Deploys a Hyperdrive instance with the given parameters.
/// @param __name The name of the Hyperdrive pool.
/// @param _config The configuration of the Hyperdrive pool.
/// @param _extraData The extra data for the Morpho instance. This contains
/// the market parameters that weren't specified in the config.
/// @param _target0 The target0 address.
/// @param _target1 The target1 address.
/// @param _target2 The target2 address.
/// @param _target3 The target3 address.
/// @param _target4 The target4 address.
/// @param _salt The create2 salt used in the deployment.
/// @return The address of the newly deployed MorphoBlueHyperdrive instance.
function deployHyperdrive(
string memory __name,
IHyperdrive.PoolConfig memory _config,
bytes memory _extraData,
address _target0,
address _target1,
address _target2,
address _target3,
address _target4,
bytes32 _salt
) external returns (address) {
IMorphoBlueHyperdrive.MorphoBlueParams memory params = abi.decode(
_extraData,
(IMorphoBlueHyperdrive.MorphoBlueParams)
);
return (
address(
// NOTE: We hash the sender with the salt to prevent the
// front-running of deployments.
new MorphoBlueHyperdrive{
salt: keccak256(abi.encode(msg.sender, _salt))
}(
__name,
_config,
_target0,
_target1,
_target2,
_target3,
_target4,
params
)
)
);
}
}
Loading

0 comments on commit 2514eec

Please sign in to comment.