Skip to content

Commit 3ece151

Browse files
g1nt0kitomrpl
andauthored
Morpho-blue (DefiLlama#8658)
* feat(morpho-blue): adding Morpho Blue adapter * feat(morpho-blue): updating morpho blue markets * code refactor --------- Co-authored-by: Tom Rpl <[email protected]> Co-authored-by: Reppelin Tom <[email protected]>
1 parent 635a878 commit 3ece151

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

projects/helper/abis/morpho.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
"marketsCreated": "address[]:marketsCreated",
1212
"market": "function market(address underlying) returns (tuple( tuple(uint128 poolIndex, uint128 p2pIndex) supply, tuple(uint128 poolIndex, uint128 p2pIndex) borrow) indexes, tuple( tuple(uint256 scaledDelta, uint256 scaledP2PTotal) supply, tuple(uint256 scaledDelta, uint256 scaledP2PTotal) borrow) deltas, address underlying, tuple( bool isP2PDisabled, bool isSupplyPaused, bool isSupplyCollateralPaused, bool isBorrowPaused, bool isWithdrawPaused, bool isWithdrawCollateralPaused, bool isRepayPaused, bool isLiquidateCollateralPaused, bool isLiquidateBorrowPaused, bool isDeprecated) pauseStatues, bool isCollateral, address variableDebtToken, uint32 lastUpdateTimestamp, uint16 reserveFactor, uint16 p2pIndexCursor, address aToken, address stableDebtToken, uint256 idleSupply)"
1313
},
14-
"pool": {
15-
16-
}
17-
}
14+
"morphoBlueFunctions": {
15+
"underlying": "address:underlying",
16+
"idToMarketParams": "function idToMarketParams(bytes32 Id) returns (address loanToken, address collateralToken, address oracle, address irm, uint256 lltv)",
17+
"market": "function market(bytes32 input) returns (uint128 totalSupplyAssets, uint128 totalSupplyShares, uint128 totalBorrowAssets, uint128 totalBorrowShares, uint128 lastUpdate, uint128 fee)"
18+
},
19+
"pool": {}
20+
}

projects/morpho-blue/addresses.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const wethWstethChainlinkAdaptiveCurveIRM945 =
2+
"0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41";
3+
const usdcWstethChainlinkAdaptiveCurveIRM860 =
4+
"0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc";
5+
6+
module.exports = {
7+
morphoBlue: "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb",
8+
whitelistedIds: [
9+
wethWstethChainlinkAdaptiveCurveIRM945,
10+
usdcWstethChainlinkAdaptiveCurveIRM860,
11+
],
12+
};

projects/morpho-blue/index.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const { getLogs } = require('../helper/cache/getLogs')
2+
const abi = require("../helper/abis/morpho.json");
3+
const { morphoBlue, whitelistedIds } = require("./addresses");
4+
5+
module.exports = {
6+
methodology: `Collateral (supply minus borrows) in the balance of the Morpho contracts`,
7+
doublecounted: true,
8+
};
9+
10+
const config = {
11+
ethereum: { morphoBlue, fromBlock: 18883124 }
12+
}
13+
14+
Object.keys(config).forEach(chain => {
15+
const { morphoBlue, fromBlock } = config[chain]
16+
module.exports[chain] = {
17+
tvl: async (_, _b, _cb, { api, }) => {
18+
const marketIds = await getMarkets(api)
19+
const tokens = (await api.multiCall({ target: morphoBlue, calls: marketIds, abi: abi.morphoBlueFunctions.idToMarketParams })).map(i => [i.collateralToken, i.loanToken]).flat()
20+
return api.sumTokens({ owner: morphoBlue, tokens })
21+
},
22+
borrowed: async (_, _b, _cb, { api, }) => {
23+
const marketIds = await getMarkets(api)
24+
const marketInfo = await api.multiCall({ target: morphoBlue, calls: marketIds, abi: abi.morphoBlueFunctions.idToMarketParams })
25+
const marketData = await api.multiCall({ target: morphoBlue, calls: marketIds, abi: abi.morphoBlueFunctions.market })
26+
marketData.forEach((i, idx) => {
27+
api.add(marketInfo[idx].loanToken, i.totalBorrowAssets)
28+
})
29+
return api.getBalances()
30+
},
31+
}
32+
33+
async function getMarkets(api) {
34+
const logs = await getLogs({
35+
api, target: morphoBlue,
36+
eventAbi: 'event CreateMarket(bytes32 indexed id, (address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams)',
37+
onlyArgs: true, fromBlock,
38+
})
39+
return logs.map(i => i.id).concat(whitelistedIds)
40+
}
41+
})

0 commit comments

Comments
 (0)