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

(p2) PR again, mistakenly merged the previous approved P2 into wrong branch #78

Merged
merged 51 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
ad7ab8a
initial commit on morpho integration
cwang25 Aug 19, 2024
b7dd247
Morpho DEFI scripts with tests
cwang25 Aug 20, 2024
3c84509
split morpho out of defi scripts
Aug 29, 2024
e441352
add tests for bundle actions
Aug 29, 2024
6759c44
address comments
Aug 29, 2024
95dffa9
remove unnecessary if check
Aug 31, 2024
104b7bd
remove unnecessary if check
Aug 31, 2024
c28d957
remove unused import
cwang25 Aug 31, 2024
9d7f486
address comments, move MorphoScripts out of defi_integrations folder,…
cwang25 Aug 31, 2024
687abbc
add repay max custom logics to MorphoScripts so client doesn't have t…
cwang25 Sep 1, 2024
1d88bc8
After some consideration, we can just trim off all other functions as…
cwang25 Sep 1, 2024
965d172
address comments
cwang25 Sep 3, 2024
75cdb39
incorporate SharesMathLib for replacing confusing shares# assertions …
cwang25 Sep 5, 2024
dc4d380
abstract shares away from morpho scripts, remove shares repay test
cwang25 Sep 5, 2024
1050105
add more assertions to test
cwang25 Sep 5, 2024
c27fca7
morpho stuff
cwang25 Aug 21, 2024
0ddbb34
Add MorphoInfo with hardcoded file, and simple test to verify the add…
cwang25 Aug 22, 2024
9da3c01
add known vaults (hand picked)
cwang25 Aug 22, 2024
4121683
migrated account info, and migrated all the dependencies :sweat:
cwang25 Aug 23, 2024
5940d6b
repay and borrow
cwang25 Aug 23, 2024
3f01dff
morpho borrow tests set
cwang25 Aug 27, 2024
4ef02bb
weird stock too deep error, probably need to split QuarkBuilder.sol i…
cwang25 Aug 27, 2024
525b99e
add tests
cwang25 Aug 28, 2024
355bb76
add withdraw collateral
cwang25 Aug 29, 2024
8e53e39
adjust code for moving defiscripts code to p1 pr
cwang25 Aug 29, 2024
b8280ac
since max is handled by the morphoscripts, don't need to pass in shar…
Sep 2, 2024
bbcd6e9
change names to drop Blue, and update tests to reflect the new no-sha…
Sep 2, 2024
67c6ec5
rename assetPosition to collateralAssetPosition
Sep 2, 2024
215203b
add chainId check on getMorphoAddress
Sep 2, 2024
764ef10
typo
Sep 2, 2024
4df8d32
typo morphor -> morpho
Sep 2, 2024
a93dcbf
add new action type, cuz builder code need that to distinguish betwee…
Sep 2, 2024
3bdeba9
handle morpho action types
Sep 2, 2024
f8781a8
add test net to morphoinfo and intent
Sep 2, 2024
cd590a3
fix typo Potential > Potentially
cwang25 Sep 4, 2024
4dc55a2
add NOTE on renaming generic actions to comet's action
cwang25 Sep 4, 2024
642cc16
as no more shares tracking, borrowedBalacnes became borrowed just lik…
cwang25 Sep 4, 2024
8a48c7d
replace address(0) to PaymentInfo.NON_TOKEN_PAYEMNT
cwang25 Sep 6, 2024
2a83d51
add empty action context MorphoBorrow and MorphoRepay, and added back…
cwang25 Sep 6, 2024
685531b
use return instead of named
cwang25 Sep 6, 2024
8a5630f
don't pre-declare as there is no loop to check
cwang25 Sep 6, 2024
208767d
don't pre-declare as no loop to check, forgot to check in this file a…
cwang25 Sep 6, 2024
dd2ea0f
rename tests, and use helper to get script address
cwang25 Sep 6, 2024
707a240
update repay to also ateempt to bridge payment token
cwang25 Sep 6, 2024
d91604e
drop TODOs
cwang25 Sep 6, 2024
69d0c3c
Merge remote-tracking branch 'origin/main' into hans/morpho-integrati…
cwang25 Sep 11, 2024
cad44ff
RPC endpoint update
cwang25 Sep 11, 2024
f176c44
add new rpc url
cwang25 Sep 11, 2024
e5b3264
rename folder to - instead of _
cwang25 Sep 11, 2024
9ff003f
fix typo in folder name
cwang25 Sep 11, 2024
44b9297
include other rpc endpoints
cwang25 Sep 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/builder/Accounts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ library Accounts {
QuarkState[] quarkStates;
AssetPositions[] assetPositionsList;
CometPositions[] cometPositions;
MorphoPositions[] morphoPositions;
}

// We map this to the Portfolio data structure that the client will already have.
Expand Down Expand Up @@ -57,6 +58,25 @@ library Accounts {
uint256[] balances;
}

struct MorphoPositions {
bytes32 marketId;
address morpho;
address loanToken;
address collateralToken;
MorphoBorrowPosition borrowPosition;
MorphoCollateralPosition collateralPosition;
}

struct MorphoBorrowPosition {
address[] accounts;
uint256[] borrowed;
}

struct MorphoCollateralPosition {
address[] accounts;
uint256[] balances;
}

function findChainAccounts(uint256 chainId, ChainAccounts[] memory chainAccountsList)
internal
pure
Expand All @@ -82,6 +102,23 @@ library Accounts {
}
}

function findMorphoPositions(
uint256 chainId,
address loanToken,
address collateralToken,
ChainAccounts[] memory chainAccountsList
) internal pure returns (MorphoPositions memory found) {
ChainAccounts memory chainAccounts = findChainAccounts(chainId, chainAccountsList);
for (uint256 i = 0; i < chainAccounts.morphoPositions.length; ++i) {
if (
chainAccounts.morphoPositions[i].loanToken == loanToken
&& chainAccounts.morphoPositions[i].collateralToken == collateralToken
) {
return found = chainAccounts.morphoPositions[i];
}
}
}

function findAssetPositions(string memory assetSymbol, AssetPositions[] memory assetPositionsList)
internal
pure
Expand Down Expand Up @@ -253,4 +290,20 @@ library Accounts {
}
}
}

function totalMorphoBorrowForAccount(
Accounts.ChainAccounts[] memory chainAccountsList,
uint256 chainId,
address loanToken,
address collateralToken,
address account
) internal pure returns (uint256 totalBorrow) {
Accounts.MorphoPositions memory morphoPositions =
findMorphoPositions(chainId, loanToken, collateralToken, chainAccountsList);
for (uint256 i = 0; i < morphoPositions.borrowPosition.accounts.length; ++i) {
if (morphoPositions.borrowPosition.accounts[i] == account) {
totalBorrow = morphoPositions.borrowPosition.borrowed[i];
}
}
}
}
Loading
Loading