Skip to content

Commit

Permalink
feat:Morpho Blue adaptors (#241)
Browse files Browse the repository at this point in the history
* Add alternative asset protos to Cellar 2.5 API

* Add CellarWithMultiAssetDeposit abi bindings

* Update multi asset ABI to fixed version

* Git ignore DS_Store files

* Fmt

* Handlers for multi asset commit functions

* Update test certs

* Protos for Morpho Blue adaptors

* Morpho Blue ABIs + bindings

* Fix typos in proto

* Wire up morpho blue adaptor handlers

* fmt

* get ci running

* get ci running

* Add Morpho Blue position permissions

* Fix unwrap

* Fix lazy eval

* Bump to v3.8.0
  • Loading branch information
cbrit committed Jan 26, 2024
1 parent 38c6c3f commit b2d8606
Show file tree
Hide file tree
Showing 36 changed files with 5,968 additions and 124 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sommelier_steward"
version = "3.7.0"
version = "3.8.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
9 changes: 9 additions & 0 deletions proto/adaptors/aave/aave_v3_debt_token_flash_loan.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import "adaptors/morpho/morpho_aave_v2_debt_token.proto";
import "adaptors/morpho/morpho_aave_v3_a_token_collateral.proto";
import "adaptors/morpho/morpho_aave_v3_a_token_p2p.proto";
import "adaptors/morpho/morpho_aave_v3_debt_token.proto";
import "adaptors/morpho/morpho_blue_collateral.proto";
import "adaptors/morpho/morpho_blue_debt.proto";
import "adaptors/morpho/morpho_blue_supply.proto";
import "adaptors/uniswap/uniswap_v3.proto";
import "adaptors/uniswap/swap_with_uniswap.proto";
import "adaptors/fees_and_reserves.proto";
Expand Down Expand Up @@ -112,6 +115,12 @@ message AaveV3DebtTokenAdaptorV1FlashLoan {
CurveAdaptorV1Calls curve_v1_calls = 28;
// Represents function calls for the AuraERC4626AdaptorV1
AuraERC4626AdaptorV1Calls aura_erc4626_v1_calls = 29;
// Represents function calls for the MorphoBlueCollateralAdaptorV1
MorphoBlueCollateralAdaptorV1Calls morpho_blue_collateral_v1_calls = 30;
// Represents function calls for the MorphoBlueDebtAdaptorV1
MorphoBlueDebtAdaptorV1Calls morpho_blue_debt_v1_calls = 31;
// Represents function calls for the MorphoBlueSupplyAdaptorV1
MorphoBlueSupplyAdaptorV1Calls morpho_blue_supply_v1_calls = 32;
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion proto/adaptors/balancer/balancer_pool_flash_loan.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import "adaptors/morpho/morpho_aave_v2_debt_token.proto";
import "adaptors/morpho/morpho_aave_v3_a_token_collateral.proto";
import "adaptors/morpho/morpho_aave_v3_a_token_p2p.proto";
import "adaptors/morpho/morpho_aave_v3_debt_token.proto";
import "adaptors/morpho/morpho_blue_collateral.proto";
import "adaptors/morpho/morpho_blue_debt.proto";
import "adaptors/morpho/morpho_blue_supply.proto";
import "adaptors/uniswap/uniswap_v3.proto";
import "adaptors/uniswap/swap_with_uniswap.proto";
import "adaptors/fees_and_reserves.proto";
Expand Down Expand Up @@ -110,7 +113,13 @@ message BalancerPoolAdaptorV1FlashLoan {
// Represents function calls for the CurveAdaptorV1
CurveAdaptorV1Calls curve_v1_calls = 29;
// Represents function calls for the AuraERC4626AdaptorV1
AuraERC4626AdaptorV1Calls aura_erc4626_v1_calls = 30;
AuraERC4626AdaptorV1Calls aura_erc4626_v1_calls = 30;
// Represents function calls for the MorphoBlueCollateralAdaptorV1
MorphoBlueCollateralAdaptorV1Calls morpho_blue_collateral_v1_calls = 31;
// Represents function calls for the MorphoBlueDebtAdaptorV1
MorphoBlueDebtAdaptorV1Calls morpho_blue_debt_v1_calls = 32;
// Represents function calls for the MorphoBlueSupplyAdaptorV1
MorphoBlueSupplyAdaptorV1Calls morpho_blue_supply_v1_calls = 33;
}
}
}
Expand Down
58 changes: 58 additions & 0 deletions proto/adaptors/morpho/morpho_blue_collateral.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Protos for function calls to the Morpho Blue Collateral adaptor.
*/

syntax = "proto3";
package steward.v3;

option go_package = "/steward_proto";

import "adaptors/base.proto";
import "common.proto";

// Represents call data for the Morpho Blue Collateral adaptor.
message MorphoBlueCollateralAdaptorV1 {
oneof function {
/***** BASE ADAPTOR FUNCTIONS *****/

// Represents function `revokeApproval(ERC20 asset, address spender)`
RevokeApproval revoke_approval = 1;

/***** ADAPTOR-SPECIFIC FUNCTIONS *****/

// Represents function `addCollateral(MarketParams memory _market, uint256 _collateralToDeposit)`
AddCollateral add_collateral = 2;
// Represents function `removeCollateral(MarketParams memory _market, uint256 _collateralAmount)`
RemoveCollateral remove_collateral = 3;
}

/*
* Allows strategists to add collateral to the respective cellar position on specified MB Market, enabling borrowing.
*
* Represents function `addCollateral(MarketParams memory _market, uint256 _collateralToDeposit)`
*/
message AddCollateral {
// Identifier of a Morpho Blue Market
MarketParams market = 1;

// The amount of collateral to add
string collateral_to_deposit = 2;
}

/*
* Allows strategists to remove collateral from the respective cellar position on specified MB Market.
*
* Represents function `removeCollateral(MarketParams memory _market, uint256 _collateralAmount)`
*/
message RemoveCollateral {
// Identifier of a Morpho Blue Market
MarketParams market = 1;

// The amount of collateral to remove
string collateral_amount = 2;
}
}

message MorphoBlueCollateralAdaptorV1Calls {
repeated MorphoBlueCollateralAdaptorV1 calls = 1;
}
58 changes: 58 additions & 0 deletions proto/adaptors/morpho/morpho_blue_debt.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Protos for function calls to the Morpho Blue Debt adaptor.
*/

syntax = "proto3";
package steward.v3;

option go_package = "/steward_proto";

import "adaptors/base.proto";
import "common.proto";

// Represents call data for the Morpho Blue Debt adaptor.
message MorphoBlueDebtAdaptorV1 {
oneof function {
/***** BASE ADAPTOR FUNCTIONS *****/

// Represents function `revokeApproval(ERC20 asset, address spender)`
RevokeApproval revoke_approval = 1;

/***** ADAPTOR-SPECIFIC FUNCTIONS *****/

// Represents function `borrowFromMorphoBlue(MarketParams memory _market, uint256 _amountToBorrow)`
BorrowFromMorphoBlue borrow_from_morpho_blue = 2;
// Represents function `repayMorphoBlueDebt(MarketParams memory _market, uint256 _debtTokenRepayAmount)`
RepayMorphoBlueDebt repay_morpho_blue_debt = 3;
}

/*
* Allows strategists borrow a specific amount of an asset on Morpho Blue
*
* Represents function `borrowFromMorphoBlue(MarketParams memory _market, uint256 _amountToBorrow)`
*/
message BorrowFromMorphoBlue {
// Identifier of a Morpho Blue Market
MarketParams market = 1;

// The amount of the debt token to borrow
string amount_to_borrow = 2;
}

/*
* Allows strategists to repay loan debt on Morph Blue Lending Market. Make sure to call addInterest() beforehand to ensure we are repaying what is required.
*
* Represents function `repayMorphoBlueDebt(MarketParams memory _market, uint256 _debtTokenRepayAmount)`
*/
message RepayMorphoBlueDebt {
// Identifier of a Morpho Blue Market
MarketParams market = 1;

// The amount of the debt token to repay
string debt_token_repay_amount = 2;
}
}

message MorphoBlueDebtAdaptorV1Calls {
repeated MorphoBlueDebtAdaptorV1 calls = 1;
}
58 changes: 58 additions & 0 deletions proto/adaptors/morpho/morpho_blue_supply.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Protos for function calls to the Morpho Blue Supply adaptor.
*/

syntax = "proto3";
package steward.v3;

option go_package = "/steward_proto";

import "adaptors/base.proto";
import "common.proto";

// Represents call data for the Morpho Blue Supply adaptor.
message MorphoBlueSupplyAdaptorV1 {
oneof function {
/***** BASE ADAPTOR FUNCTIONS *****/

// Represents function `revokeApproval(ERC20 asset, address spender)`
RevokeApproval revoke_approval = 1;

/***** ADAPTOR-SPECIFIC FUNCTIONS *****/

// Represents function `lendToMorphoBlue(MarketParams memory _market, uint256 _assets)`
LendToMorphoBlue lend_to_morpho_blue = 2;
// Represents function `withdrawFromMorphoBlue(MarketParams memory _market, uint256 _assets)`
WithdrawFromMorphoBlue withdraw_from_morpho_blue = 3;
}

/*
* Allows strategists to lend a specific amount for an asset on Morpho Blue
*
* Represents function `lendToMorphoBlue(MarketParams memory _market, uint256 _assets)`
*/
message LendToMorphoBlue {
// Identifier of a Morpho Blue Market
MarketParams market = 1;

// The amount of the loan token to lend
string assets = 2;
}

/*
* Allows strategists to withdraw the underlying asset plus interest
*
* Represents function `withdrawFromMorphoBlue(MarketParams memory _market, uint256 _assets)`
*/
message WithdrawFromMorphoBlue {
// Identifier of a Morpho Blue Market
MarketParams market = 1;

// The amount of the loan token to lend
string assets = 2;
}
}

message MorphoBlueSupplyAdaptorV1Calls {
repeated MorphoBlueSupplyAdaptorV1 calls = 1;
}
9 changes: 9 additions & 0 deletions proto/cellar_v2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import "adaptors/morpho/morpho_aave_v2_debt_token.proto";
import "adaptors/morpho/morpho_aave_v3_a_token_collateral.proto";
import "adaptors/morpho/morpho_aave_v3_a_token_p2p.proto";
import "adaptors/morpho/morpho_aave_v3_debt_token.proto";
import "adaptors/morpho/morpho_blue_collateral.proto";
import "adaptors/morpho/morpho_blue_debt.proto";
import "adaptors/morpho/morpho_blue_supply.proto";
import "adaptors/uniswap/uniswap_v3.proto";
import "adaptors/uniswap/swap_with_uniswap.proto";
import "adaptors/fees_and_reserves.proto";
Expand Down Expand Up @@ -778,5 +781,11 @@ message AdaptorCall {
CurveAdaptorV1Calls curve_v1_calls = 31;
// Represents function calls for the AuraERC4626AdaptorV1
AuraERC4626AdaptorV1Calls aura_erc4626_v1_calls = 32;
// Represents function calls for the MorphoBlueCollateralAdaptorV1
MorphoBlueCollateralAdaptorV1Calls morpho_blue_collateral_v1_calls = 33;
// Represents function calls for the MorphoBlueDebtAdaptorV1
MorphoBlueDebtAdaptorV1Calls morpho_blue_debt_v1_calls = 34;
// Represents function calls for the MorphoBlueSupplyAdaptorV1
MorphoBlueSupplyAdaptorV1Calls morpho_blue_supply_v1_calls = 35;
}
}
20 changes: 20 additions & 0 deletions proto/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,23 @@ message OracleSwapParams {
UniV3OracleSwapParams univ3_params = 2;
}
}

/*
* Represents parameters for a Morpho Blue market
*/
message MarketParams {
// The address of the loan token
string loan_token = 1;

// The address of the collateral token
string collateral_token = 2;

// The address of the oracle
string oracle = 3;

// The address of the interest rate model
string irm = 4;

// The loan-to-value ratio
string lltv = 5;
}
2 changes: 1 addition & 1 deletion steward/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "steward"
authors = []
version = "3.7.0"
version = "3.8.0"
edition = "2018"

[dependencies]
Expand Down
18 changes: 3 additions & 15 deletions steward/src/cellars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,7 @@ lazy_static! {

pub const ALLOWED_V2_0_SETUP_ADAPTORS: [(&str, &str); 0] = [];
pub const ALLOWED_V2_2_CATALOGUE_ADAPTORS: [(&str, &str); 0] = [];
pub const ALLOWED_V2_5_CATALOGUE_ADAPTORS: [(&str, &str); 5] = [
(CELLAR_TURBO_EETH, ADAPTOR_UNIV3_V3_DEPLOYMENT_2),
(CELLAR_TURBO_EETH, ADAPTOR_VESTING_SIMPLE_V1_1_DEPLOYMENT2),
(CELLAR_TURBO_EETH, ADAPTOR_CURVE_ADAPTOR_V1),
(CELLAR_TURBO_EETH, ADAPTOR_BALANCER_POOL_V1),
(CELLAR_TURBO_EETH, ADAPTOR_AURA_ERC4626_ADAPTOR_V1),
];
pub const ALLOWED_V2_5_CATALOGUE_ADAPTORS: [(&str, &str); 0] = [];

// due to position size limits in v2.0, positions must be added and removed from the limited list
// and thus approved positions need to be allowed to be re-added, hence this large list
Expand All @@ -108,14 +102,8 @@ pub const ALLOWED_V2_0_POSITIONS: [(&str, u32); 20] = [
(CELLAR_RYUSD, 29),
];
pub const ALLOWED_V2_2_CATALOGUE_POSITIONS: [(&str, u32); 0] = [];
pub const ALLOWED_V2_5_CATALOGUE_POSITIONS: [(&str, u32); 6] = [
(CELLAR_TURBO_EETH, 12),
(CELLAR_TURBO_EETH, 1000009),
(CELLAR_TURBO_EETH, 100000006),
(CELLAR_TURBO_EETH, 6000002),
(CELLAR_TURBO_EETH, 7000001),
(CELLAR_TURBO_EETH, 7500001),
];
pub const ALLOWED_V2_5_CATALOGUE_POSITIONS: [(&str, u32); 2] =
[(CELLAR_TURBO_EETH, 7000002), (CELLAR_TURBO_EETH, 7500002)];

pub const BLOCKED_ADAPTORS: [&str; 3] = [
ADAPTOR_UNIV3_V1,
Expand Down
9 changes: 9 additions & 0 deletions steward/src/cellars/adaptors/aave_v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,15 @@ fn get_encoded_adaptor_calls(
AuraErc4626V1Calls(params) => {
calls.extend(adaptors::aura::aura_erc4626_adaptor_v1_calls(params)?)
}
MorphoBlueCollateralV1Calls(params) => calls.extend(
adaptors::morpho::morpho_blue_collateral_adaptor_v1_calls(params)?,
),
MorphoBlueDebtV1Calls(params) => {
calls.extend(adaptors::morpho::morpho_blue_debt_adaptor_v1_calls(params)?)
}
MorphoBlueSupplyV1Calls(params) => calls.extend(
adaptors::morpho::morpho_blue_supply_adaptor_v1_calls(params)?,
),
};

result.push(AbiAdaptorCall {
Expand Down
9 changes: 9 additions & 0 deletions steward/src/cellars/adaptors/balancer_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,15 @@ fn get_encoded_adaptor_calls(
AuraErc4626V1Calls(params) => {
calls.extend(adaptors::aura::aura_erc4626_adaptor_v1_calls(params)?)
}
MorphoBlueCollateralV1Calls(params) => calls.extend(
adaptors::morpho::morpho_blue_collateral_adaptor_v1_calls(params)?,
),
MorphoBlueDebtV1Calls(params) => {
calls.extend(adaptors::morpho::morpho_blue_debt_adaptor_v1_calls(params)?)
}
MorphoBlueSupplyV1Calls(params) => calls.extend(
adaptors::morpho::morpho_blue_supply_adaptor_v1_calls(params)?,
),
};

result.push(AbiAdaptorCall {
Expand Down
Loading

0 comments on commit b2d8606

Please sign in to comment.