Skip to content

Commit

Permalink
fix (#minor); Morpho; Address QA issues (#2199)
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh9200 authored Jul 24, 2023
1 parent dbf5550 commit 35f17bf
Show file tree
Hide file tree
Showing 27 changed files with 1,340 additions and 541 deletions.
4 changes: 2 additions & 2 deletions deployment/deployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -3090,7 +3090,7 @@
"status": "prod",
"versions": {
"schema": "3.0.1",
"subgraph": "1.0.0",
"subgraph": "1.1.0",
"methodology": "1.0.0"
},
"files": {
Expand Down Expand Up @@ -3120,7 +3120,7 @@
"status": "prod",
"versions": {
"schema": "3.0.1",
"subgraph": "1.0.0",
"subgraph": "1.1.0",
"methodology": "1.0.0"
},
"files": {
Expand Down
42 changes: 42 additions & 0 deletions subgraphs/morpho/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ type LendingProtocol implements Protocol @entity @regularPolling {

##### Morpho Specific #####

## Morpho Compound and morpho aave v2 specific fields
_defaultMaxGasForMatchingSupply: BigInt
_defaultMaxGasForMatchingBorrow: BigInt
_defaultMaxGasForMatchingWithdraw: BigInt
Expand All @@ -551,6 +552,12 @@ type LendingProtocol implements Protocol @entity @regularPolling {
_maxSortedUsers: BigInt
_owner: Bytes
_oracle: Bytes

## Morpho Aave v3 specific fields
_defaultMaxIterationsWithdraw: BigInt
_defaultMaxIterationsRepay: BigInt

_marketIds: [String!]!
}

# helper entity to iterate through all markets
Expand Down Expand Up @@ -1062,6 +1069,24 @@ type Market @entity @regularPolling {
" The p2p borrow index, updated at the last update on Morpho"
_p2pBorrowIndex: BigInt

" The supply rate in P2P, updated at the last pool update "
_p2pSupplyRate: BigInt

" The borrow rate in P2P, updated at the last pool update "
_p2pBorrowRate: BigInt

" The p2p supply index, updated at the last pool update, by recomputing the P2P rates. Used in monitoring "
_p2pSupplyIndexFromRates: BigInt

" The p2p borrow index, updated at the last pool update, by recomputing the P2P rates. Used in monitoring "
_p2pBorrowIndexFromRates: BigInt

" The cursor where the p2p rate is calculated from, without conversion "
_p2pIndexCursor_BI: BigInt

" The percent of revenue from P2P market that is converted to reserves at the current time. "
_reserveFactor_BI: BigInt

" Whether the p2p matching is disabled or not on this market"
_isP2PDisabled: Boolean

Expand All @@ -1080,6 +1105,9 @@ type Market @entity @regularPolling {
" The total amount borrowed peer-to-peer"
_totalBorrowInP2P: BigDecimal

" The total amount of collateral on the underlying pool"
_totalCollateralOnPool: BigDecimal

" The p2pSupplyAmount in scaled units"
_p2pSupplyAmount: BigInt

Expand All @@ -1104,6 +1132,9 @@ type Market @entity @regularPolling {
" The aggregation of the scaled p2p borrow balances if the p2p balances was on pool"
_virtualScaledBorrow: BigInt

" The scaled balance on pool used as collateral"
_scaledPoolCollateral: BigInt

" The poolSupplyAmount in scaled units"
_poolSupplyAmount: BigInt

Expand All @@ -1119,6 +1150,12 @@ type Market @entity @regularPolling {
" Whether the withdraw is paused or not"
_isWithdrawPaused: Boolean

" Whether the withdraw collateral is paused or not"
_isWithdrawCollateralPaused: Boolean

" Whether the supply collateral is paused or not"
_isSupplyCollateralPaused: Boolean

" Whether the repay is paused or not"
_isRepayPaused: Boolean

Expand Down Expand Up @@ -1166,6 +1203,9 @@ type Market @entity @regularPolling {

" The number of decimals of the rates and the indexes, WAD or RAY."
_indexesOffset: Int

" The idle supply on the Morpho contract"
_idleSupply: BigInt
}

#################################
Expand Down Expand Up @@ -2198,4 +2238,6 @@ type UnderlyingTokenMapping @entity {
id: Bytes!
aToken: Bytes!
debtToken: Bytes!
aTokenV3: Bytes
variableDebtTokenV3: Bytes
}
37 changes: 28 additions & 9 deletions subgraphs/morpho/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import {
Address,
BigDecimal,
BigInt,
log,
Bytes,
BigInt,
Address,
ethereum,
log,
BigDecimal,
} from "@graphprotocol/graph-ts";
import { LendingProtocol } from "../generated/schema";

export const BASE_UNITS = BigDecimal.fromString("10000");
export const WAD = BigDecimal.fromString("1000000000000000000");
export const RAY = BigDecimal.fromString("1000000000000000000000000000");
export const RAY_BI = BigInt.fromString("1000000000000000000000000000");

export namespace ProtocolType {
export const LENDING = "LENDING";
}
Expand Down Expand Up @@ -148,9 +143,11 @@ export const INT_ZERO = 0 as i32;
export const INT_ONE = 1 as i32;
export const INT_TWO = 2 as i32;
export const INT_FOUR = 4 as i32;
export const INT_EIGHT = 8 as i32;

export const BIGINT_ZERO = BigInt.fromI32(0);
export const BIGINT_ONE = BigInt.fromI32(1);
export const BIGINT_TWO = BigInt.fromI32(2);
export const BIGINT_THREE = BigInt.fromI32(3);

export const BIGINT_TEN_TO_EIGHTEENTH = BigInt.fromString("10").pow(18);
Expand All @@ -168,6 +165,24 @@ export const SECONDS_PER_DAY = 60 * 60 * 24;
export const BLOCKS_PER_DAY = BigInt.fromI32(7200 as i32);
export const BLOCKS_PER_YEAR = BigInt.fromI32(2632320 as i32); // 7200 blocks per day

///////////////////////////////
///// Protocols variables /////
///////////////////////////////

export const BASE_UNITS = BigDecimal.fromString("10000");
export const BASE_UNITS_BI = BigInt.fromString("10000");
export const HALF_UNITS_BI = BASE_UNITS_BI.div(BIGINT_TWO);
export const WAD = BigDecimal.fromString("1000000000000000000");
export const WAD_BI = BigInt.fromString("1000000000000000000");
export const HALF_WAD_BI = WAD_BI.div(BIGINT_TWO);

export const RAY = BigDecimal.fromString("1000000000000000000000000000");
export const RAY_BI = BigInt.fromString("1000000000000000000000000000");
export const HALF_RAY_BI = RAY_BI.div(BIGINT_TWO);

export const WAD_RAY_RATIO = BigInt.fromI32(10).pow(9);
export const HALF_WAD_RAY_RATIO = WAD_RAY_RATIO.div(BIGINT_TWO);

/////////////////////////////
///// Utility Functions /////
/////////////////////////////
Expand Down Expand Up @@ -206,6 +221,10 @@ export function exponentToBigInt(decimals: i32): BigInt {
return result;
}

export function minBN(b1: BigInt, b2: BigInt): BigInt {
return b1.gt(b2) ? b2 : b1;
}

export function equalsIgnoreCase(a: string, b: string): boolean {
return a.replace("-", "_").toLowerCase() == b.replace("-", "_").toLowerCase();
}
Expand Down
Loading

0 comments on commit 35f17bf

Please sign in to comment.