From cf2cbe6b0659f9cca8de3d75372f9e14b6ef8aa0 Mon Sep 17 00:00:00 2001 From: brightiron Date: Sat, 30 Nov 2024 14:24:12 -0600 Subject: [PATCH 1/5] fix formatting --- src/views/Emission/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/Emission/index.tsx b/src/views/Emission/index.tsx index b5b1581c8..14597c8ca 100644 --- a/src/views/Emission/index.tsx +++ b/src/views/Emission/index.tsx @@ -11,7 +11,7 @@ export const Emission = () => {
- {emissionConfig?.activeMarketId && ( + {Boolean(emissionConfig?.activeMarketId) && ( From de2c11b078ab89a01002e735092f03c891e908b9 Mon Sep 17 00:00:00 2001 From: brightiron Date: Sat, 30 Nov 2024 20:47:45 -0600 Subject: [PATCH 2/5] usds icon --- .../Lending/Cooler/positions/Positions.tsx | 395 +++++++++--------- 1 file changed, 202 insertions(+), 193 deletions(-) diff --git a/src/views/Lending/Cooler/positions/Positions.tsx b/src/views/Lending/Cooler/positions/Positions.tsx index c944ee3cf..c55c2eea6 100644 --- a/src/views/Lending/Cooler/positions/Positions.tsx +++ b/src/views/Lending/Cooler/positions/Positions.tsx @@ -1,10 +1,8 @@ import { Box, Grid, - MenuItem, Paper, - Select, - Skeleton, + SvgIcon, Table, TableBody, TableCell, @@ -12,11 +10,11 @@ import { TableHead, TableRow, Typography, - useTheme, } from "@mui/material"; import { OHMTokenProps, PrimaryButton, SecondaryButton, Token } from "@olympusdao/component-library"; import { ethers } from "ethers"; -import { useEffect, useState } from "react"; +import { useState } from "react"; +import usdsIcon from "src/assets/tokens/usds.svg?react"; import { BorrowRate, OutstandingPrincipal, WeeklyCapacityRemaining } from "src/views/Lending/Cooler/dashboard/Metrics"; import { useGetClearingHouse } from "src/views/Lending/Cooler/hooks/useGetClearingHouse"; import { useGetCoolerForWallet } from "src/views/Lending/Cooler/hooks/useGetCoolerForWallet"; @@ -27,8 +25,6 @@ import { useAccount } from "wagmi"; export const CoolerPositions = () => { const { address } = useAccount(); - const [currentClearingHouse, setCurrentClearingHouse] = useState<"v1" | "v2" | "v3">("v3"); - // Get clearing house data for all versions const clearingHouses = { v1: useGetClearingHouse({ clearingHouse: "clearingHouseV1" }).data, v2: useGetClearingHouse({ clearingHouse: "clearingHouseV2" }).data, @@ -81,46 +77,60 @@ export const CoolerPositions = () => { clearingHouseVersion: "clearingHouseV3", }); - // Organize version data - const versionData = { - v1: { - loans: { data: loansV1, isFetched: isFetchedLoansV1 }, - coolerAddress: { data: coolerAddressV1 }, - }, - v2: { - loans: { data: loansV2, isFetched: isFetchedLoansV2 }, - coolerAddress: { data: coolerAddressV2 }, - }, - v3: { - loans: { data: loansV3, isFetched: isFetchedLoansV3 }, - coolerAddress: { data: coolerAddressV3 }, - }, + const [extendLoan, setExtendLoan] = useState[number] | undefined>(undefined); + const [repayLoan, setRepayLoan] = useState[number] | undefined>(undefined); + + const getAllLoans = () => { + const allLoans = [ + ...(loansV1 || []).map(loan => ({ ...loan, version: "v1" })), + ...(loansV2 || []).map(loan => ({ ...loan, version: "v2" })), + ...(loansV3 || []).map(loan => ({ ...loan, version: "v3" })), + ]; + return allLoans; }; - const currentData = versionData[currentClearingHouse]; - const coolerAddress = currentData.coolerAddress.data; - const clearingHouse = clearingHouses[currentClearingHouse]; - const loans = currentData.loans.data; - const isFetchedLoans = currentData.loans.isFetched; + const getActiveClearingHouse = () => { + if (clearingHouses.v3?.isActive && clearingHouses.v3?.capacity.gt(0)) { + return { version: "v3", ...clearingHouses.v3 }; + } + if (clearingHouses.v2?.isActive && clearingHouses.v2?.capacity.gt(0)) { + return { version: "v2", ...clearingHouses.v2 }; + } + return null; + }; - const [extendLoan, setExtendLoan] = useState(null); - const [repayLoan, setRepayLoan] = useState(null); - const theme = useTheme(); + const activeClearingHouse = getActiveClearingHouse(); + const allLoans = getAllLoans(); - // Update the clearing house version when the data is available - useEffect(() => { - if (clearingHouses.v3?.isActive && clearingHouses.v3?.capacity.gt(0)) { - setCurrentClearingHouse("v3"); - } else if (clearingHouses.v2?.isActive && clearingHouses.v2?.capacity.gt(0)) { - setCurrentClearingHouse("v2"); + const getClearingHouseForLoan = (version: string) => { + const clearingHouse = clearingHouses[version as keyof typeof clearingHouses]; + if (!clearingHouse) throw new Error(`No clearing house found for version ${version}`); + return clearingHouse; + }; + + const getCoolerAddressForLoan = (version: string) => { + switch (version) { + case "v1": + return coolerAddressV1; + case "v2": + return coolerAddressV2; + case "v3": + return coolerAddressV3; + default: + return undefined; } - }, [clearingHouses.v2, clearingHouses.v3]); + }; + + console.log(allLoans, isFetchedLoansV1, isFetchedLoansV2, isFetchedLoansV3, address); return (
- + @@ -129,46 +139,6 @@ export const CoolerPositions = () => { - {([(loansV1 || []).length > 0, (loansV2 || []).length > 0].filter(Boolean).length > 0 || - (clearingHouses.v3?.isActive && - clearingHouses.v3?.capacity.gt(0) && - ((loansV1 && loansV1.length > 0) || (loansV2 && loansV2.length > 0)))) && ( - - - - )} Your Positions @@ -181,17 +151,11 @@ export const CoolerPositions = () => { )} - {address && !isFetchedLoans && ( - - - - )} - - {loans && loans.length == 0 && isFetchedLoans && ( + {allLoans.length === 0 && isFetchedLoansV1 && isFetchedLoansV2 && isFetchedLoansV3 && address && ( You currently have no Cooler loans - {clearingHouse?.isActive && clearingHouse.capacity.gt(0) && ( + {activeClearingHouse && ( <> Borrow against gOHM at a fixed rate and maturity @@ -201,7 +165,7 @@ export const CoolerPositions = () => { setCreateLoanModalOpen(true); }} > - Borrow {clearingHouse?.debtAssetName} & Open Position + Borrow {activeClearingHouse.debtAssetName} & Open Position @@ -210,132 +174,177 @@ export const CoolerPositions = () => { )} - {coolerAddress && ( + {address && (!isFetchedLoansV1 || !isFetchedLoansV2 || !isFetchedLoansV3) && ( + + Loading your positions... + + )} + + {allLoans.length > 0 && ( <> - {loans && loans.length > 0 && ( - <> - - - - - Collateral - - Interest Rate + +
+ + + Version + Collateral + + Interest Rate + + + Repayment + + + Maturity Date + + + + + + {allLoans.map((loan, index) => { + const principalAndInterest = loan.principal.add(loan.interestDue || 0) || 0; + return ( + + ClearingHouse {loan.version.toUpperCase()} + + + {loan.collateral && Number(ethers.utils.formatUnits(loan.collateral.toString())).toFixed(4)}{" "} + gOHM + - - Repayment + + {loan.request?.interest && ( + {Number(ethers.utils.formatUnits(loan.request.interest.toString())) * 100}% + )} - - Maturity Date + + {principalAndInterest && ( + + {Number(ethers.utils.formatUnits(principalAndInterest.toString())).toFixed(2)}{" "} + {loan.debtAssetName}{" "} + {loan.debtAssetName === "USDS" ? ( + + ) : ( + + )} + + )} + + + {loan.expiry && ( + + {new Date(Number(loan.expiry.toString()) * 1000).toLocaleString([], { + month: "long", + day: "numeric", + year: "numeric", + }) || ""} + + )} + + + + { + setRepayLoan(loan); + setCreateLoanModalOpen(true); + }} + > + Repay + + setExtendLoan(loan)}>Extend + - - - - {loans?.map((loan, index) => { - const principalAndInterest = loan.principal.add(loan.interestDue || 0) || 0; - return ( - - - - {loan.collateral && - Number(ethers.utils.formatUnits(loan.collateral.toString())).toFixed(4)}{" "} - gOHM - - - - {loan.request?.interest && ( - {Number(ethers.utils.formatUnits(loan.request.interest.toString())) * 100}% - )} - - - {principalAndInterest && ( - - {Number(ethers.utils.formatUnits(principalAndInterest.toString())).toFixed(2)}{" "} - {loan.debtAssetName}{" "} - - - )} - - - {loan.expiry && ( - - {new Date(Number(loan.expiry.toString()) * 1000).toLocaleString([], { - month: "long", - day: "numeric", - year: "numeric", - }) || ""} - - )} - - - - { - setRepayLoan(loan); - setCreateLoanModalOpen(true); - }} - > - Repay - - setExtendLoan(loan)}>Extend - - - - ); - })} - -
-
- {clearingHouse?.isActive && clearingHouse.capacity.gt(0) && ( - - { - setRepayLoan(undefined); - setCreateLoanModalOpen(true); - }} - > - Borrow {clearingHouse.debtAssetName} & Open Position - - - )} - + ); + })} + + + + {activeClearingHouse && ( + + { + setRepayLoan(undefined); + setCreateLoanModalOpen(true); + }} + > + Borrow {activeClearingHouse.debtAssetName} & Open Position + + )} )} - {clearingHouse && ( + {activeClearingHouse && ( <> - {extendLoan && ( + {extendLoan && getClearingHouseForLoan(extendLoan.version) && getCoolerAddressForLoan(extendLoan.version) && ( )} )} From e1b72258ea60b3a96089e0ff58753e0be5bae369 Mon Sep 17 00:00:00 2001 From: brightiron Date: Sat, 30 Nov 2024 20:50:02 -0600 Subject: [PATCH 3/5] remove version column from testing --- src/views/Lending/Cooler/positions/Positions.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/views/Lending/Cooler/positions/Positions.tsx b/src/views/Lending/Cooler/positions/Positions.tsx index c55c2eea6..f69e0d1b8 100644 --- a/src/views/Lending/Cooler/positions/Positions.tsx +++ b/src/views/Lending/Cooler/positions/Positions.tsx @@ -186,7 +186,6 @@ export const CoolerPositions = () => { - Version Collateral Interest Rate @@ -205,7 +204,6 @@ export const CoolerPositions = () => { const principalAndInterest = loan.principal.add(loan.interestDue || 0) || 0; return ( - ClearingHouse {loan.version.toUpperCase()} {loan.collateral && Number(ethers.utils.formatUnits(loan.collateral.toString())).toFixed(4)}{" "} From 1ceb9ecf12874a2aab467ad2e696eb1529e86a03 Mon Sep 17 00:00:00 2001 From: brightiron Date: Mon, 2 Dec 2024 11:43:24 -0600 Subject: [PATCH 4/5] decimals for emission manager --- src/views/Emission/hooks/useGetEmissionConfig.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/views/Emission/hooks/useGetEmissionConfig.ts b/src/views/Emission/hooks/useGetEmissionConfig.ts index 82931d7ac..11d2bf76c 100644 --- a/src/views/Emission/hooks/useGetEmissionConfig.ts +++ b/src/views/Emission/hooks/useGetEmissionConfig.ts @@ -51,12 +51,12 @@ export const useGetEmissionConfig = () => { return { baseEmissionRate: `${Number(formatUnits(baseEmissionRate, 9)) * 100}%`, // 1e9 = 100% backing: formatUnits(backing, 18), - premium: `${Number(formatUnits(premium, 18)) * 100}%`, - minimumPremium: `${Number(formatUnits(minimumPremium, 18)) * 100}%`, // 1e18 = 100% + premium: `${(Number(formatUnits(premium, 18)) * 100).toFixed(2)}%`, + minimumPremium: `${(Number(formatUnits(minimumPremium, 18)) * 100).toFixed(2)}%`, // 1e18 = 100% nextSale: { - premium: `${Number(formatUnits(nextSalePremium, 18)) * 100}%`, // 1e18 = 100% - emissionRate: `${Number(formatUnits(nextSaleEmissionRate, 9)) * 100}%`, // OHM scale - emission: `${formatUnits(nextSaleEmission, 9)} OHM`, // OHM scale + premium: `${(Number(formatUnits(nextSalePremium, 18)) * 100).toFixed(2)}%`, // 1e18 = 100% + emissionRate: `${(Number(formatUnits(nextSaleEmissionRate, 9)) * 100).toFixed(2)}%`, // OHM scale + emission: `${Number(formatUnits(nextSaleEmission, 9)).toFixed(2)} OHM`, // OHM scale }, rateChange: { changeBy: formatUnits(rateChange.changeBy, 9), // OHM scale @@ -66,7 +66,7 @@ export const useGetEmissionConfig = () => { activeMarketId: activeMarketId.toNumber(), vestingPeriod: vestingPeriod.toString(), // uint48 (in seconds) // reserves: formatUnits(reserves, 18), // DAI scale (18 decimals) - currentEmissionRate: `${Number(Number(formatUnits(currentEmissionRate, 9)) * 100).toFixed(4)}%`, // OHM scale + currentEmissionRate: `${(Number(formatUnits(currentEmissionRate, 9)) * 100).toFixed(4)}%`, // OHM scale currentEmission: `${Number(formatUnits(currentEmission, 9)).toFixed(2)} OHM`, // OHM scale tellerAddress, reserveAddress, From 6e3b15a3c205ec550adcd70bb2a1e38bd4f62c35 Mon Sep 17 00:00:00 2001 From: brightiron Date: Mon, 2 Dec 2024 11:48:19 -0600 Subject: [PATCH 5/5] disable rbs env variable --- src/components/Sidebar/NavContent.tsx | 3 ++- src/helpers/environment/Environment/Environment.ts | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/Sidebar/NavContent.tsx b/src/components/Sidebar/NavContent.tsx index 1e036914e..f49f260fd 100644 --- a/src/components/Sidebar/NavContent.tsx +++ b/src/components/Sidebar/NavContent.tsx @@ -32,6 +32,7 @@ const NavContent: React.VFC = () => { const protocolMetricsEnabled = Boolean(Environment.getWundergraphNodeUrl()); const emissionsManagerEnabled = Environment.getEmissionsManagerEnabled(); + const rbsDisabled = Environment.getRbsDisabled(); return ( @@ -62,7 +63,7 @@ const NavContent: React.VFC = () => { to="/lending/cooler" /> {emissionsManagerEnabled && } - {!emissionsManagerEnabled && } + {!rbsDisabled && } diff --git a/src/helpers/environment/Environment/Environment.ts b/src/helpers/environment/Environment/Environment.ts index de073e8ee..3f65dd7f7 100644 --- a/src/helpers/environment/Environment/Environment.ts +++ b/src/helpers/environment/Environment/Environment.ts @@ -75,6 +75,13 @@ export class Environment { fallback: "false", }) === "true"; + public static getRbsDisabled = (): boolean => + this._get({ + first: true, + key: "VITE_RBS_DISABLED", + fallback: "false", + }) === "true"; + public static getGovernanceSubgraphUrl = (): string => { const subgraphApiKey = this.getSubgraphApiKey(); return this._get({