Skip to content

Commit

Permalink
(p2) PR again, mistakenly merged the previous approved P2 into wrong …
Browse files Browse the repository at this point in the history
…branch (#78)

- Morpho actions
  • Loading branch information
cwang25 authored Sep 12, 2024
1 parent c6c524e commit 9e6cf93
Show file tree
Hide file tree
Showing 18 changed files with 2,892 additions and 99 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/gas-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
| tee .gas-snapshot.new
env:
MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }}
BASE_MAINNET_RPC_URL: ${{ secrets.BASE_MAINNET_RPC_URL }}
SEPOLIA_RPC_URL: ${{ secrets.SEPOLIA_RPC_URL }}
BASE_SEPOLIA_RPC_URL: ${{ secrets.BASE_SEPOLIA_RPC_URL }}

- name: Check diff tolerance
run: |
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ jobs:
id: test
env:
MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }}
BASE_MAINNET_RPC_URL: ${{ secrets.BASE_MAINNET_RPC_URL }}
SEPOLIA_RPC_URL: ${{ secrets.SEPOLIA_RPC_URL }}
BASE_SEPOLIA_RPC_URL: ${{ secrets.BASE_SEPOLIA_RPC_URL }}
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

0 comments on commit 9e6cf93

Please sign in to comment.