Skip to content

Commit

Permalink
fix: v2 market pause flag (#48)
Browse files Browse the repository at this point in the history
* chore: package update

* feat: gnosis market

* feat: frozen and paused flags

* fix: pool query to fetch Aave V2 market pause status

* chore: remove unused import
  • Loading branch information
defispartan authored Nov 8, 2023
1 parent 209301d commit b52828a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
15 changes: 13 additions & 2 deletions pages/api/aave.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextApiRequest, NextApiResponse } from "next";
import { ethers } from "ethers";
import { Contract, ethers } from "ethers";
import { UiPoolDataProvider } from "@aave/contract-helpers";
import { formatReserves } from "@aave/math-utils";
import dayjs from "dayjs";
Expand All @@ -23,6 +23,7 @@ type configInterface = {
protocol: string;
lendingPoolAddressProvider: string;
uiDataProvider: string;
pool: string;
};

export default async function handler(
Expand All @@ -35,6 +36,7 @@ export default async function handler(
protocol: req.query.protocol as string,
lendingPoolAddressProvider: req.query.lendingPoolAddressProvider as string,
uiDataProvider: req.query.uiDataProvider as string,
pool: req.query.pool as string,
};

const currentTimestamp = dayjs().unix();
Expand All @@ -55,6 +57,15 @@ export default async function handler(
chainId,
});

let paused = false;
if (config.protocol === "v2") {
const abi = [
"function paused() public view returns (bool)"]
const poolContract = new Contract(config.pool, abi, provider);
paused = await poolContract.paused();
}


const reserves = await poolDataProviderContract.getReservesHumanized({
lendingPoolAddressProvider,
});
Expand Down Expand Up @@ -116,7 +127,7 @@ export default async function handler(
: {
symbol: n.symbol,
frozen: n.isFrozen ? "True" : "False",
paused: n.isPaused ? "True" : "False",
paused: paused ? "True" : "False",
canCollateral: n.usageAsCollateralEnabled ? "True" : "False",
LTV: parseInt(n.baseLTVasCollateral) / 100 + "%",
liqThereshold: parseInt(n.reserveLiquidationThreshold) / 100 + "%",
Expand Down
3 changes: 2 additions & 1 deletion services/aave.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ const fetchReservesAny = async (
publicJsonRPCUrl: string;
LENDING_POOL_ADDRESS_PROVIDER: string;
UI_POOL_DATA_PROVIDER: string;
POOL: string;
marketName: string;
},
protocol: string
) => {
try {
const response = await fetch(
`/api/aave?chainId=${config.chainId}&marketName=${config.marketName}&protocol=${protocol}&lendingPoolAddressProvider=${config.LENDING_POOL_ADDRESS_PROVIDER}&uiDataProvider=${config.UI_POOL_DATA_PROVIDER}`
`/api/aave?chainId=${config.chainId}&marketName=${config.marketName}&protocol=${protocol}&lendingPoolAddressProvider=${config.LENDING_POOL_ADDRESS_PROVIDER}&uiDataProvider=${config.UI_POOL_DATA_PROVIDER}&pool=${config.POOL}`
);
const reservesArray = await response.json();
return reservesArray.data;
Expand Down
4 changes: 4 additions & 0 deletions utils/marketconfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,31 @@ export const marketConfig = {
publicJsonRPCUrl: "https://eth-mainnet.alchemyapi.io/v2/demo",
LENDING_POOL_ADDRESS_PROVIDER: AaveV2Ethereum.POOL_ADDRESSES_PROVIDER,
UI_POOL_DATA_PROVIDER: AaveV2Ethereum.UI_POOL_DATA_PROVIDER,
POOL: AaveV2Ethereum.POOL,
marketName: "proto_mainnet",
},
avalanche: {
chainId: ChainId.avalanche,
publicJsonRPCUrl: "https://api.avax.network/ext/bc/C/rpc",
LENDING_POOL_ADDRESS_PROVIDER: AaveV2Avalanche.POOL_ADDRESSES_PROVIDER,
UI_POOL_DATA_PROVIDER: AaveV2Avalanche.UI_POOL_DATA_PROVIDER,
POOL: AaveV2Avalanche.POOL,
marketName: "proto_avalanche",
},
polygon: {
chainId: ChainId.polygon,
publicJsonRPCUrl: "https://polygon-rpc.com",
LENDING_POOL_ADDRESS_PROVIDER: AaveV2Polygon.POOL_ADDRESSES_PROVIDER,
UI_POOL_DATA_PROVIDER: AaveV2Polygon.UI_POOL_DATA_PROVIDER,
POOL: AaveV2Polygon.POOL,
marketName: "proto_polygon",
},
ethamm: {
chainId: ChainId.mainnet,
publicJsonRPCUrl: "https://eth-mainnet.alchemyapi.io/v2/demo",
LENDING_POOL_ADDRESS_PROVIDER: AaveV2EthereumAMM.POOL_ADDRESSES_PROVIDER,
UI_POOL_DATA_PROVIDER: AaveV2EthereumAMM.UI_POOL_DATA_PROVIDER,
POOL: AaveV2EthereumAMM.POOL,
marketName: "amm_mainnet",
},
arbitrum: {
Expand Down

1 comment on commit b52828a

@vercel
Copy link

@vercel vercel bot commented on b52828a Nov 8, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.