Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/base 1 #12

Merged
merged 3 commits into from
Dec 19, 2022
Merged

Feat/base 1 #12

merged 3 commits into from
Dec 19, 2022

Conversation

pakim249CAL
Copy link
Contributor

@pakim249CAL pakim249CAL commented Dec 17, 2022

A proposed initial layout of the contract structure.

@pakim249CAL pakim249CAL marked this pull request as ready for review December 17, 2022 16:50
Copy link
Contributor

@MerlinEgalite MerlinEgalite left a comment

Choose a reason for hiding this comment

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

Love the ideas. I added some comments too

.prettierrc.json Outdated Show resolved Hide resolved
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: GNU AGPLv3
Copy link
Contributor

Choose a reason for hiding this comment

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

should be accessible from lib

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what you mean. How can a lib cannot access this?

Copy link
Contributor

Choose a reason for hiding this comment

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

from the imported library aave-core-v3 I mean

@@ -0,0 +1,76 @@
// SPDX-License-Identifier: GNU AGPLv3
Copy link
Contributor

Choose a reason for hiding this comment

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

same

@@ -0,0 +1,19 @@
// SPDX-License-Identifier: UNLICENSED
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really get the usage of this file tbh

Copy link
Contributor Author

@pakim249CAL pakim249CAL Dec 18, 2022

Choose a reason for hiding this comment

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

This library is meant to aggregate the libraries we use in Morpho. This IMO is important in our case so that we are less likely to run into the issue of using two versions of the same library accidentally. It doesn't have to be this way, but I think this is one way we can softly enforce what libraries we use in our contracts.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok we can go with it for now

src/libraries/MarketLib.sol Outdated Show resolved Hide resolved
src/MatchingEngine.sol Outdated Show resolved Hide resolved
src/MatchingEngine.sol Outdated Show resolved Hide resolved
src/MatchingEngine.sol Outdated Show resolved Hide resolved
src/MorphoInternal.sol Outdated Show resolved Hide resolved
src/MorphoInternal.sol Outdated Show resolved Hide resolved
@pakim249CAL pakim249CAL force-pushed the feat/base-1 branch 4 times, most recently from dfe2958 to 64a999c Compare December 18, 2022 15:52
Copy link
Contributor

@MerlinEgalite MerlinEgalite left a comment

Choose a reason for hiding this comment

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

I'm globally ok with the changes :)

Note that I didn't check the in-depth logic, security, etc.

@pakim249CAL pakim249CAL requested a review from a team December 18, 2022 16:33
Copy link
Collaborator

@Rubilmax Rubilmax left a comment

Choose a reason for hiding this comment

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

I really like the internal-by-default pattern
I also like the library-based plug-in logic

There a lot of conventions introduced in this PR, which I am for or not against, but we shouldn't consider them set in stone as quick as this PR is merged because we (at least I) need to test how they behave

src/interfaces/IERC1155.sol Show resolved Hide resolved
@@ -1,4 +1,6 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;

library Errors {}
library Errors {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This library will be used much like an enum and the common naming standard of enum is singular
This is obviously not mandatory

Copy link
Contributor

Choose a reason for hiding this comment

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

Whatever works for you guys

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean having the library renamed to be a single letter? @Rubilmax

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, I should have been more specific. I had in mind to name it Error instead of Errors, to use it like revert Error.MarketNotCreated()


library Events {}
library Events {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This library will be used much like an enum and the common naming standard of enum is singular
This is obviously not mandatory

src/libraries/Constants.sol Show resolved Hide resolved
Comment on lines +39 to +50
uint256 p2pSupplyIndex; // 256 bits
uint256 p2pBorrowIndex; // 256 bits
BorrowMask borrowMask; // 256 bits
Delta deltas; // 1024 bits
uint32 lastUpdateTimestamp; // 32 bits
uint112 poolSupplyIndex; // 112 bits
uint112 poolBorrowIndex; // 112 bits
address underlying; // 168 bits
address variableDebtToken; // 168 bits
uint16 reserveFactor; // 16 bits
uint16 p2pIndexCursor; // 16 bits
PauseStatuses pauseStatuses; // 64 bits
Copy link
Collaborator

@Rubilmax Rubilmax Dec 19, 2022

Choose a reason for hiding this comment

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

Could we count in bytes? 😁

EDIT: Actually I don't know if it's a good idea

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bytes seems okay as this is the minimal unit of each variable, but I prefer bits since it requires no translation between something like uint256 to bytes.

function setSupplying(Types.UserMarkets memory userMarkets, Types.BorrowMask memory borrowMask, bool supplying)
internal
pure
returns (Types.UserMarkets memory newUserMarket)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we modify the input struct and return it? Or is it bad software design?

Comment on lines 55 to 58
ThreeHeapOrdering.HeapArray suppliersP2P; // in scaled unit
ThreeHeapOrdering.HeapArray suppliersPool; // in scaled unit
ThreeHeapOrdering.HeapArray borrowersP2P; // in scaled unit
ThreeHeapOrdering.HeapArray borrowersPool; // in scaled unit
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
ThreeHeapOrdering.HeapArray suppliersP2P; // in scaled unit
ThreeHeapOrdering.HeapArray suppliersPool; // in scaled unit
ThreeHeapOrdering.HeapArray borrowersP2P; // in scaled unit
ThreeHeapOrdering.HeapArray borrowersPool; // in scaled unit
ThreeHeapOrdering.HeapArray p2pSuppliers; // in scaled unit
ThreeHeapOrdering.HeapArray poolSuppliers; // in scaled unit
ThreeHeapOrdering.HeapArray p2pBorrowers; // in scaled unit
ThreeHeapOrdering.HeapArray poolBorrowers; // in scaled unit

Comment on lines +70 to +83
struct AssetLiquidityData {
uint256 decimals; // The number of decimals of the underlying token.
uint256 tokenUnit; // The token unit considering its decimals.
uint256 liquidationThreshold; // The liquidation threshold applied on this token (in basis point).
uint256 ltv; // The LTV applied on this token (in basis point).
uint256 underlyingPrice; // The price of the token (In base currency in wad).
}

struct LiquidityData {
uint256 collateral; // The collateral value (In base currency in wad).
uint256 maxDebt; // The max debt value (In base currency in wad).
uint256 liquidationThresholdValue; // The liquidation threshold value (In base currency in wad).
uint256 debt; // The debt value (In base currency in wad).
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

These could be updated to match branch upgrade-morpho-1

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm remember we're dealing with Aave V3. So we first need to make sure that it's using the same units

Copy link
Collaborator

Choose a reason for hiding this comment

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

And it depends on the network lol... So value may be the best keyword in this case (in place of Usd or Eth). Any better proposal?

src/libraries/Types.sol Show resolved Hide resolved
Comment on lines +62 to +68
struct UserMarkets {
bytes32 data;
}

struct BorrowMask {
bytes32 data;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why wrap these inside structs?

Copy link
Contributor Author

@pakim249CAL pakim249CAL Dec 19, 2022

Choose a reason for hiding this comment

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

I believe that the UserMarkets and BorrowMask should be treated as strongly typed, similar to what aave does. This should prevent any developer mistakes when working with these variables (including us)

Copy link
Contributor

Choose a reason for hiding this comment

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

Note that we might come back to the way we're handling it with Morpho-Compound (namely keeping the list of user's entered markets)

@morpho-org morpho-org deleted a comment from MerlinEgalite Dec 19, 2022
Copy link
Collaborator

@Rubilmax Rubilmax left a comment

Choose a reason for hiding this comment

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

Approving this to merge, but keeping conversations unresolved for future reference

@pakim249CAL pakim249CAL merged commit 138c8bd into feat/base Dec 19, 2022
@Rubilmax Rubilmax deleted the feat/base-1 branch December 19, 2022 17:17
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.

3 participants