Skip to content

Commit

Permalink
Merge pull request #3237 from OlympusDAO/cooler-loans-api-update
Browse files Browse the repository at this point in the history
Adds support for multi-reserve cooler loans
  • Loading branch information
brightiron authored Nov 29, 2024
2 parents 8c957c3 + 7621b6a commit 77aee24
Show file tree
Hide file tree
Showing 15 changed files with 517 additions and 497 deletions.
838 changes: 419 additions & 419 deletions src/abi/CoolerFactoryV2.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/components/Migration/MigrationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ function MigrationModal({ open, handleClose }: { open: boolean; handleClose: any
isMigrationComplete || !oldAssetsDetected
? `Migration complete`
: isAllApproved
? `You are now ready to migrate`
: `You have assets ready to migrate to v2`
? `You are now ready to migrate`
: `You have assets ready to migrate to v2`
}
>
<>
Expand Down
38 changes: 25 additions & 13 deletions src/generated/coolerLoans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,18 @@ export type GetSnapshotsParams = {
* Represents the state of the Treasury at the time of the snapshot.
*/
export type SnapshotTreasury = {
/** Total balance of DAI in the active treasury */
/** Total balance of the DAI token in the active treasury */
daiBalance: number;
/** Total balance of sDAI in the active treasury */
/** Total balance of the sDAI token in the active treasury */
sDaiBalance: number;
/** Total balance of sDAI in terms of DAI in the active treasury */
/** Total balance of the sDAI token in terms of DAI in the active treasury */
sDaiInDaiBalance: number;
/** Total balance of the sUSDS token in the active treasury */
sUsdsBalance: number;
/** Total balance of the sUSDS token in terms of USDS in the active treasury */
sUsdsInUsdsBalance: number;
/** Total balance of the USDS token in the active treasury */
usdsBalance: number;
};

/**
Expand Down Expand Up @@ -86,12 +92,18 @@ export type SnapshotExpiryBuckets = {
* Totals for the Clearinghouses at the time of the snapshot.
*/
export type SnapshotClearinghouseTotals = {
/** Total balance of DAI across all Clearinghouses */
/** Total balance of the DAI token across all Clearinghouses */
daiBalance: number;
/** Total balance of sDAI across all Clearinghouses */
/** Total balance of the sDAI token across all Clearinghouses */
sDaiBalance: number;
/** Total balance of sDAI in terms of DAI across all Clearinghouses */
/** Total balance of the sDAI token in terms of DAI across all Clearinghouses */
sDaiInDaiBalance: number;
/** Total balance of the sUSDS token across all Clearinghouses */
sUsdsBalance: number;
/** Total balance of the sUSDS token in terms of USDS across all Clearinghouses */
sUsdsInUsdsBalance: number;
/** Total balance of the USDS token across all Clearinghouses */
usdsBalance: number;
};

export type SnapshotClearinghousesItem = {
Expand All @@ -101,18 +113,18 @@ export type SnapshotClearinghousesItem = {
collateralAddress: string;
/** The address of the CoolerFactory */
coolerFactoryAddress: string;
/** Balance of DAI */
daiBalance: number;
/** The address of the debt */
debtAddress: string;
/** Amount of DAI that the Clearinghouse should be funded with */
/** Amount of the reserve token that the Clearinghouse should be funded with */
fundAmount: number;
/** The cadence of the funding */
fundCadence: number;
/** Balance of sDAI */
sDaiBalance: number;
/** Balance of sDAI in terms of DAI */
sDaiInDaiBalance: number;
/** Balance of the reserve token */
reserveBalance: number;
/** Balance of the sReserve token */
sReserveBalance: number;
/** Balance of the sReserve token in terms of the reserve token */
sReserveInReserveBalance: number;
};

export type Snapshot = {
Expand Down
16 changes: 8 additions & 8 deletions src/hooks/useScreenSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ export const useScreenSize = (size: "xs" | "sm" | "md" | "lg" | "xl") => {
size === "xs"
? "(max-width: 0px)"
: size === "sm"
? "(max-width: 600px)"
: size === "md"
? "(max-width: 900px)"
: size === "lg"
? "(max-width: 1200px)"
: size === "xl"
? "(max-width: 153600px)"
: "";
? "(max-width: 600px)"
: size === "md"
? "(max-width: 900px)"
: size === "lg"
? "(max-width: 1200px)"
: size === "xl"
? "(max-width: 153600px)"
: "";

return useMediaQuery(breakpoint);
};
4 changes: 2 additions & 2 deletions src/hooks/useTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const useTheme = (): [string, (e: KeyboardEvent) => void, boolean] => {
window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches && !localTheme
? setMode("dark")
: localTheme
? setTheme(localTheme)
: setMode("dark");
? setTheme(localTheme)
: setMode("dark");
setMounted(true);
}, []);

Expand Down
4 changes: 2 additions & 2 deletions src/views/Bond/components/BondModal/BondModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ const TokenPrice: React.VFC<{ token: Token; isInverseBond?: boolean; baseSymbol:
const price = sameToken
? formatNumber(1, 2)
: isInverseBond
? formatNumber(ohmPrice, 2)
: `${formatNumber(Number(priceToken.toString({ decimals: 2, format: true, trim: false })), 2)}`;
? formatNumber(ohmPrice, 2)
: `${formatNumber(Number(priceToken.toString({ decimals: 2, format: true, trim: false })), 2)}`;
return price ? (
<>
{price} {isInverseBond ? baseSymbol : quoteSymbol}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ export const BondInputArea: React.VFC<{
{isInverseBond
? `${quoteTokenString} (≈${baseTokenString})`
: props.bond.baseToken === props.bond.quoteToken
? `${baseTokenString}`
: `${baseTokenString} (≈${quoteTokenString})`}
? `${baseTokenString}`
: `${baseTokenString} (≈${quoteTokenString})`}
</span>
}
/>
Expand Down
14 changes: 8 additions & 6 deletions src/views/Bridge/components/BridgeConfirmModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,14 @@ export const BridgeConfirmModal = (props: {
{props.amountExceedsBalance
? "Amount exceeds balance"
: !props.amount || parseFloat(props.amount) === 0
? "Enter an amount"
: !isValidAddress
? `Invalid recipient address: ${shorten(props.recipientAddress)}`
: props.bridgeMutation.isLoading
? "Confirming Bridging in your wallet"
: `Bridge OHM to ${BRIDGE_CHAINS[props.destinationChainId as keyof typeof BRIDGE_CHAINS].name}`}
? "Enter an amount"
: !isValidAddress
? `Invalid recipient address: ${shorten(props.recipientAddress)}`
: props.bridgeMutation.isLoading
? "Confirming Bridging in your wallet"
: `Bridge OHM to ${
BRIDGE_CHAINS[props.destinationChainId as keyof typeof BRIDGE_CHAINS].name
}`}
</PrimaryButton>
</>
</TokenAllowanceGuard>
Expand Down
8 changes: 6 additions & 2 deletions src/views/Lending/Cooler/dashboard/Metrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,19 @@ export const TotalCapacityRemaining = () => {
label="Total Capacity Remaining"
metric={formatCurrency(getTotalCapacity(latestSnapshot), 0, "DAI")}
isLoading={latestSnapshot === undefined}
tooltip={`The capacity remaining is the sum of the DAI and sDAI in the clearinghouse and treasury. As of the latest snapshot, the values (in DAI) are:
tooltip={`The capacity remaining is the sum of the DAI/sDAI and USDS/sUSDS in the clearinghouse and treasury. As of the latest snapshot, the values are:
Clearinghouse:
DAI: ${formatCurrency(latestSnapshot?.clearinghouseTotals.daiBalance || 0, 0, "DAI")}
sDAI: ${formatCurrency(latestSnapshot?.clearinghouseTotals.sDaiInDaiBalance || 0, 0, "DAI")}
USDS: ${formatCurrency(latestSnapshot?.clearinghouseTotals.usdsBalance || 0, 0, "USDS")}
sUSDS: ${formatCurrency(latestSnapshot?.clearinghouseTotals.sUsdsInUsdsBalance || 0, 0, "USDS")}
Treasury:
DAI: ${formatCurrency(latestSnapshot?.treasury?.daiBalance || 0, 0, "DAI")}
sDAI: ${formatCurrency(latestSnapshot?.treasury?.sDaiInDaiBalance || 0, 0, "DAI")}`}
sDAI: ${formatCurrency(latestSnapshot?.treasury?.sDaiInDaiBalance || 0, 0, "DAI")}
USDS: ${formatCurrency(latestSnapshot?.treasury?.usdsBalance || 0, 0, "USDS")}
sUSDS: ${formatCurrency(latestSnapshot?.treasury?.sUsdsInUsdsBalance || 0, 0, "USDS")}`}
/>
);
};
Expand Down
17 changes: 15 additions & 2 deletions src/views/Lending/Cooler/hooks/useSnapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,22 @@ export const getTotalCapacity = (snapshot: Snapshot | undefined): number => {

const treasuryDaiBalance = snapshot.treasury?.daiBalance || 0;
const treasurySDaiInDaiBalance = snapshot.treasury?.sDaiInDaiBalance || 0;
const treasuryUsdsBalance = snapshot.treasury?.usdsBalance || 0;
const treasurySUsdsInUsdsBalance = snapshot.treasury?.sUsdsInUsdsBalance || 0;

const clearinghouseDaiBalance = snapshot.clearinghouseTotals.daiBalance || 0;
const clearinghouseSDaiInDaiBalance = snapshot.clearinghouseTotals.sDaiInDaiBalance || 0;

return treasuryDaiBalance + treasurySDaiInDaiBalance + clearinghouseDaiBalance + clearinghouseSDaiInDaiBalance;
const clearinghouseUsdsBalance = snapshot.clearinghouseTotals.usdsBalance || 0;
const clearinghouseSUsdsInUsdsBalance = snapshot.clearinghouseTotals.sUsdsInUsdsBalance || 0;

return (
treasuryDaiBalance +
treasurySDaiInDaiBalance +
treasuryUsdsBalance +
treasurySUsdsInUsdsBalance +
clearinghouseDaiBalance +
clearinghouseSDaiInDaiBalance +
clearinghouseUsdsBalance +
clearinghouseSUsdsInUsdsBalance
);
};
14 changes: 2 additions & 12 deletions src/views/Lending/Cooler/positions/ConsolidateLoan.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { Box, SvgIcon, Typography } from "@mui/material";
import { InfoNotification, Modal, PrimaryButton } from "@olympusdao/component-library";
import { BigNumber, ethers } from "ethers";
import { BigNumber } from "ethers";
import { formatEther } from "ethers/lib/utils.js";
import { useEffect, useState } from "react";
import lendAndBorrowIcon from "src/assets/icons/lendAndBorrow.svg?react";
import { TokenAllowanceGuard } from "src/components/TokenAllowanceGuard/TokenAllowanceGuard";
import { COOLER_CONSOLIDATION_ADDRESSES, DAI_ADDRESSES, GOHM_ADDRESSES } from "src/constants/addresses";
import { formatNumber } from "src/helpers";
import { DecimalBigNumber } from "src/helpers/DecimalBigNumber/DecimalBigNumber";
import { useBalance } from "src/hooks/useBalance";
import { useTestableNetworks } from "src/hooks/useTestableNetworks";
import { useConsolidateCooler } from "src/views/Lending/Cooler/hooks/useConsolidateCooler";
Expand Down Expand Up @@ -57,8 +50,5 @@ export const ConsolidateLoans = ({
}, [daiBalance, totals.interest]);

console.log("consolidate loans");
return (
<>
</>
);
return <></>;
};
1 change: 0 additions & 1 deletion src/views/Lending/Cooler/positions/Positions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { BorrowRate, OutstandingPrincipal, WeeklyCapacityRemaining } from "src/v
import { useGetClearingHouse } from "src/views/Lending/Cooler/hooks/useGetClearingHouse";
import { useGetCoolerForWallet } from "src/views/Lending/Cooler/hooks/useGetCoolerForWallet";
import { useGetCoolerLoans } from "src/views/Lending/Cooler/hooks/useGetCoolerLoans";
import { ConsolidateLoans } from "src/views/Lending/Cooler/positions/ConsolidateLoan";
import { CreateOrRepayLoan } from "src/views/Lending/Cooler/positions/CreateOrRepayLoan";
import { ExtendLoan } from "src/views/Lending/Cooler/positions/ExtendLoan";
import { useAccount } from "wagmi";
Expand Down
12 changes: 6 additions & 6 deletions src/views/Lending/LendingMarkets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ export const LendingMarkets = () => {
poolFilter === "stable"
? stablePools
: poolFilter === "volatile"
? volatilePools
: poolFilter === "gohm"
? gOHMPools
: poolFilter === "ohm"
? ohmPools
: defiLlamaPools;
? volatilePools
: poolFilter === "gohm"
? gOHMPools
: poolFilter === "ohm"
? ohmPools
: defiLlamaPools;

const poolListByNetwork = networkFilter ? poolList?.filter(pool => pool.chain === networkFilter) : poolList;
const PoolChip = ({ label }: { label: string }) => (
Expand Down
8 changes: 4 additions & 4 deletions src/views/Liquidity/ExternalStakePools/ExternalStakePools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ export const ExternalStakePools = () => {
poolFilter === "stable"
? stablePools
: poolFilter === "volatile"
? volatilePools
: poolFilter === "gohm"
? gOHMPools
: defiLlamaPools;
? volatilePools
: poolFilter === "gohm"
? gOHMPools
: defiLlamaPools;

const poolListByNetwork = networkFilter ? poolList?.filter(pool => pool.chain === networkFilter) : poolList;
const PoolChip = ({ label }: { label: string }) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ const StakeConfirmationModal = (props: {
{props.amountExceedsBalance
? "Amount exceeds balance"
: !props.amount || parseFloat(props.amount) === 0
? "Enter an amount"
: props.currentAction === "STAKE"
? props.isMutating
? "Confirming Wrapping in your wallet"
: "Wrap"
: props.isMutating
? "Confirming Unwrapping in your wallet "
: "Unwrap"}
? "Enter an amount"
: props.currentAction === "STAKE"
? props.isMutating
? "Confirming Wrapping in your wallet"
: "Wrap"
: props.isMutating
? "Confirming Unwrapping in your wallet "
: "Unwrap"}
</PrimaryButton>
</>
)}
Expand All @@ -195,14 +195,14 @@ const StakeConfirmationModal = (props: {
{props.amountExceedsBalance
? "Amount exceeds balance"
: !props.amount || parseFloat(props.amount) === 0
? "Enter an amount"
: props.currentAction === "STAKE"
? props.isMutating
? "Confirming Wrapping in your wallet"
: "Wrap to gOHM"
: props.isMutating
? "Confirming Unwrapping in your wallet "
: "Unwrap"}
? "Enter an amount"
: props.currentAction === "STAKE"
? props.isMutating
? "Confirming Wrapping in your wallet"
: "Wrap to gOHM"
: props.isMutating
? "Confirming Unwrapping in your wallet "
: "Unwrap"}
</PrimaryButton>
)}
</TokenAllowanceGuard>
Expand Down

0 comments on commit 77aee24

Please sign in to comment.