Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3401c49
fix: handle vr vaults in vault selector
marcomariscal May 10, 2023
13535ef
chore: remove unnecessary types
marcomariscal May 10, 2023
ab95b38
fix: deps
marcomariscal May 10, 2023
70957c9
fix: max collat button handle for vr
marcomariscal May 10, 2023
55f4786
fix: clean the input
marcomariscal May 10, 2023
281cbda
fix: update deps
marcomariscal May 10, 2023
91810d6
chore: remove unused
marcomariscal May 10, 2023
a5afe4a
feat: use gradient for vr vault
marcomariscal May 10, 2023
38f90d6
feat: use variable language for vr borrow
marcomariscal May 10, 2023
0c96b62
fix: match tx codes
marcomariscal May 10, 2023
17daba5
feat: update vaults
marcomariscal May 10, 2023
7ba9270
chore: remove unused
marcomariscal May 10, 2023
79767db
fix: getting vault after borrow
marcomariscal May 10, 2023
c1d2cc3
feat: handle erc1155 allowance to output bignumber
marcomariscal May 10, 2023
45bc70f
fix: handling eth borrowing and using as collat
marcomariscal May 10, 2023
5f7d276
fix: better check
marcomariscal May 10, 2023
085adb7
fix: make sure there is assetPairInfo
marcomariscal May 10, 2023
4fa976f
fix: stricter vr logic
marcomariscal May 10, 2023
cdf7aeb
fix: explicitly set selected series to null on selecting vr
marcomariscal May 10, 2023
e3ce209
fix: deps
marcomariscal May 10, 2023
b94b452
chore: remove unused
marcomariscal May 10, 2023
5cd4aab
fix: deps
marcomariscal May 10, 2023
2bd4512
fix: handling selected vaults between fr and vr
marcomariscal May 10, 2023
3add074
fix: set selected vr when vaults is vr
marcomariscal May 10, 2023
1c418f2
fix: handle new vr vault
marcomariscal May 10, 2023
2adc596
fix: get vault id from receipt for both vr and fr
marcomariscal May 10, 2023
197027e
chore: clean
marcomariscal May 10, 2023
33fe18f
fix: make sure there is a selected vault
marcomariscal May 10, 2023
e172ecc
feat: add repay vr args type
marcomariscal May 10, 2023
d606280
fix: handle repaying vr
marcomariscal May 10, 2023
f02e7fa
chore: remove log
marcomariscal May 10, 2023
8716bad
chore: clean
marcomariscal May 10, 2023
f1212bc
fix: update loading
marcomariscal May 10, 2023
7d5f8a0
fix: handle load
marcomariscal May 10, 2023
570f048
Merge branch 'feat/VR' into feat/vr-borrow
marcomariscal May 10, 2023
4a5fc2b
fix: disable if loading
marcomariscal May 11, 2023
df2e2a8
feat: handle repaying less than all debt
marcomariscal May 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/components/PositionAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ function PositionAvatar({
return (
<Outer width={condensed ? '36px' : 'auto'}>
<Avatar
background={vyToken ? 'gradient-transparent' : series?.seriesIsMature ? 'lightGrey' : series?.color}
background={
vyToken
? 'gradient-transparent'
: series?.seriesIsMature
? 'lightGrey'
: series
? series.color
: 'gradient-transparent'
}
size={condensed ? '36px' : undefined}
>
<Box round="large" background="white" pad="xxsmall">
Expand Down
8 changes: 3 additions & 5 deletions src/components/positionItems/DummyVaultItem.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { useRouter } from 'next/router';

import { Box, Text } from 'grommet';
import { ActionType, ISeries } from '../../types';

import PositionAvatar from '../PositionAvatar';
import ItemWrap from '../wraps/ItemWrap';
import { abbreviateHash } from '../../utils/appUtils';
Expand All @@ -13,7 +11,7 @@ function DummyVaultItem({
index = 0,
condensed,
}: {
series: ISeries;
series: ISeries | undefined;
vaultId: string;
index?: number;
condensed?: boolean;
Expand All @@ -28,7 +26,7 @@ function DummyVaultItem({
return (
<ItemWrap action={() => handleSelect(vaultId)} index={index}>
<Box direction="row" gap="small" align="center" pad="small" height={condensed ? '3rem' : undefined}>
<PositionAvatar position={series} condensed={condensed} actionType={ActionType.LEND} />
<PositionAvatar position={series!} condensed={condensed} actionType={ActionType.LEND} />
<Box
fill={condensed ? 'horizontal' : undefined}
justify={condensed ? 'between' : undefined}
Expand All @@ -40,7 +38,7 @@ function DummyVaultItem({
</Text>
<Box direction="column">
<Text weight={450} size="xsmall">
{series.displayName}
{series?.displayName}
</Text>
</Box>
</Box>
Expand Down
6 changes: 3 additions & 3 deletions src/components/positionItems/VaultItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ function VaultItem({ vault, index, condensed }: { vault: IVault; index: number;
} as GA_Properties.position_opened);
};

const { isLoading: vaultsLoadingVR } = useVaultsVR();
const vaultBase = assetMap?.get(vault.baseId);
const vaultIlk = assetMap?.get(vault.ilkId);
const vaultIsVR = !vault?.seriesId;
const { isLoading: vaultsLoadingVR } = useVaultsVR();
const vaultIsVR = !vault.seriesId;

const { data: assetPair } = useAssetPair(vaultBase?.id, vaultIlk?.id);

Expand Down Expand Up @@ -84,7 +84,7 @@ function VaultItem({ vault, index, condensed }: { vault: IVault; index: number;
)}
{vaultIsVR && (
<Text weight={450} size="xsmall">
{!debtInBase_ ? <SkeletonWrap width={30} /> : cleanValue(debtInBase_, 2)}
{!debtInBase_ || vaultsLoadingVR ? <SkeletonWrap width={30} /> : cleanValue(debtInBase_, 2)}
</Text>
)}
</Box>
Expand Down
17 changes: 5 additions & 12 deletions src/components/selectors/SeriesSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,6 @@ function SeriesSelector({ selectSeriesLocally, inputValue, actionType, cardLayou

/* Keeping options/selection fresh and valid: */
useEffect(() => {
console.log('seriesSelector useEffect', selectedSeries, options);
// if (selectedVR && selectedSeries === null) {
// setOptions(options);
// return;
// }
const opts = Array.from(seriesMap?.values()!);

/* filter out options based on base Id ( or proxyId ) and if mature */
Expand All @@ -189,14 +184,12 @@ function SeriesSelector({ selectSeriesLocally, inputValue, actionType, cardLayou

setOptions(filteredOpts.sort((a, b) => a.maturity - b.maturity));
}, [
seriesMap,
selectedBase,
selectSeriesLocally,
_selectedSeries,
userActions,
selectedSeries,
actionType,
selectedVault,
selectedBase?.proxyId,
selectedSeries?.baseId,
selectedSeries?.id,
selectedSeries?.maturity,
seriesMap,
]);

const handleSelect = (_series: ISeries) => {
Expand Down
7 changes: 5 additions & 2 deletions src/components/selectors/VariableRate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const VariableRate = () => {

const {
userState: { selectedVR },
userActions: { setSelectedVR },
userActions: { setSelectedVR, setSelectedSeries },
} = useContext(UserContext);

return (
Expand All @@ -84,7 +84,10 @@ const VariableRate = () => {
round="large"
background={selectedVR ? 'purple' : '#00000007'}
elevation="xsmall"
onClick={() => setSelectedVR(true)}
onClick={() => {
setSelectedVR(true);
setSelectedSeries(null);
}}
className="VR-container"
>
<Box pad="medium" width="small" height="medium" direction="row" gap="small" fill>
Expand Down
86 changes: 46 additions & 40 deletions src/components/views/Borrow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useCallback, useContext, useEffect, useState } from 'react';
import { Box, CheckBox, Keyboard, ResponsiveContext, Text, TextInput } from 'grommet';

import { FiClock, FiPocket, FiPercent, FiTrendingUp } from 'react-icons/fi';

import SeriesSelector from '../selectors/SeriesSelector';
Expand All @@ -9,7 +8,6 @@ import AssetSelector from '../selectors/AssetSelector';
import InputWrap from '../wraps/InputWrap';
import ActionButtonWrap from '../wraps/ActionButtonWrap';
import SectionWrap from '../wraps/SectionWrap';

import MaxButton from '../buttons/MaxButton';

import { UserContext } from '../../contexts/UserContext';
Expand All @@ -18,7 +16,6 @@ import PanelWrap from '../wraps/PanelWrap';
import CenterPanelWrap from '../wraps/CenterPanelWrap';
import VaultSelector from '../selectors/VaultPositionSelector';
import ActiveTransaction from '../ActiveTransaction';

import { cleanValue, getVaultIdFromReceipt, nFormatter } from '../../utils/appUtils';

import YieldInfo from '../FooterInfo';
Expand All @@ -41,22 +38,22 @@ import { useBorrowHelpersVR } from '../../hooks/viewHelperHooks/useBorrowHelpers
import InputInfoWrap from '../wraps/InputInfoWrap';
import ColorText from '../texts/ColorText';
import { useProcess } from '../../hooks/useProcess';

import DummyVaultItem from '../positionItems/DummyVaultItem';
import SeriesOrStrategySelectorModal from '../selectors/SeriesOrStrategySelectorModal';
import Navigation from '../Navigation';
import VaultItem from '../positionItems/VaultItem';
import Line from '../elements/Line';
import { useAccount, useNetwork } from 'wagmi';
import { GA_Event, GA_Properties, GA_View } from '../../types/analytics';
import useAnalytics from '../../hooks/useAnalytics';
import { WETH } from '../../config/assets';
import useContracts from '../../hooks/useContracts';
import useAccountPlus from '../../hooks/useAccountPlus';

import VariableRate from '../selectors/VariableRate';
import useBasesVR from '../../hooks/views/useBasesVR';
import useAssetPair from '../../hooks/viewHelperHooks/useAssetPair/useAssetPair';
import useVaultsVR from '../../hooks/entities/useVaultsVR';
import { ContractNames } from '../../config/contracts';
import { Cauldron, VRCauldron } from '../../contracts';

const Borrow = () => {
const mobile: boolean = useContext<any>(ResponsiveContext) === 'small';
Expand All @@ -65,17 +62,8 @@ const Borrow = () => {

/* STATE FROM CONTEXT */
const { userState, userActions } = useContext(UserContext);
const {
assetMap,
vaultMap,
vaultsLoading,
seriesMap,
selectedSeries,
selectedIlk,
selectedBase,
selectedVault,
selectedVR,
} = userState;
const { assetMap, vaultMap, vaultsLoading, selectedSeries, selectedIlk, selectedBase, selectedVault, selectedVR } =
userState;
const { setSelectedIlk } = userActions;

const { address: activeAccount } = useAccountPlus();
Expand Down Expand Up @@ -103,6 +91,7 @@ const Borrow = () => {
const { apr } = useApr(borrowInput, ActionType.BORROW, selectedSeries);
const { data: assetPair } = useAssetPair(selectedBase?.id, selectedIlk?.id);
const { data: basesVR } = useBasesVR();
const { data: vaultsVR } = useVaultsVR();

const {
collateralizationPercent,
Expand All @@ -121,13 +110,13 @@ const Borrow = () => {
maxDebt_: maxDebtFR_,
borrowPossible: borrowPossibleFR,
borrowEstimate_,
} = useBorrowHelpersFR(borrowInput, collatInput, vaultToUse, assetPair, selectedSeries);
} = useBorrowHelpersFR(borrowInput, collatInput, selectedSeries ? vaultToUse : undefined, assetPair, selectedSeries);

const {
minDebt_: minDebtVR_,
maxDebt_: maxDebtVR_,
borrowPossible: borrowPossibleVR,
} = useBorrowHelpersVR(borrowInput, vaultToUse, assetPair);
} = useBorrowHelpersVR(borrowInput, selectedVR ? vaultToUse : undefined, assetPair);

const minDebt_ = selectedVR ? minDebtVR_ : minDebtFR_;
const maxDebt_ = selectedVR ? maxDebtVR_ : maxDebtFR_;
Expand All @@ -145,7 +134,10 @@ const Borrow = () => {
]);

/* TX info (for disabling buttons) */
const { txProcess: borrowProcess, resetProcess } = useProcess(ActionCodes.BORROW, selectedSeries?.id!);
const { txProcess: borrowProcess, resetProcess } = useProcess(
ActionCodes.BORROW,
selectedVR ? 'VR' : selectedSeries?.id!
);

/** LOCAL ACTION FNS */
const handleBorrow = () => {
Expand Down Expand Up @@ -263,18 +255,18 @@ const Borrow = () => {

/* CHECK the list of current vaults which match the current series/ilk selection */ // TODO look at moving this to helper hook?
useEffect(() => {
if (selectedBase && selectedSeries && selectedIlk) {
const arr: IVault[] = Array.from(vaultMap?.values()!) as IVault[];
const _matchingVaults = arr.filter(
(v: IVault) =>
if (selectedBase && selectedIlk) {
const vaults = [...(selectedVR ? (vaultsVR || []).values() : (vaultMap || []).values())];
const matchingVaults = vaults.filter(
(v) =>
v.ilkId === selectedIlk.proxyId &&
v.baseId === selectedBase.proxyId &&
v.seriesId === selectedSeries.id &&
(selectedVR ? true : v.seriesId === selectedSeries?.id) &&
v.isActive
);
setMatchingVaults(_matchingVaults);
setMatchingVaults(matchingVaults);
}
}, [vaultMap, selectedBase, selectedIlk, selectedSeries]);
}, [vaultMap, selectedBase, selectedIlk, selectedSeries, vaultsVR, selectedVR]);

/* handle selected vault */
useEffect(() => {
Expand All @@ -283,22 +275,33 @@ const Borrow = () => {
}

if (selectedVault) {
return setVaultToUse(selectedVault);
// if using an already selected vault with series
if (selectedSeries && selectedVault.seriesId === selectedSeries.id) {
return setVaultToUse(selectedVault);
}

// if using an already selected vr vault
if (selectedVR && selectedVault.baseId === selectedBase?.id) {
return setVaultToUse(selectedVault);
}
}

setVaultToUse(undefined);
}, [matchingVaults, selectedVault]);
}, [matchingVaults, selectedBase?.id, selectedSeries, selectedVR, selectedVault]);

useEffect(() => {
if (
borrowProcess?.stage === ProcessStage.PROCESS_COMPLETE &&
borrowProcess?.tx.status === TxState.SUCCESSFUL &&
!vaultToUse
) {
setNewVaultId(getVaultIdFromReceipt(borrowProcess?.tx?.receipt, contracts)!);
const cauldron = contracts?.get(selectedVR ? ContractNames.VR_CAULDRON : ContractNames.CAULDRON) as
| VRCauldron
| Cauldron;
setNewVaultId(getVaultIdFromReceipt(borrowProcess?.tx?.receipt, cauldron!));
}
borrowProcess?.stage === ProcessStage.PROCESS_COMPLETE_TIMEOUT && resetInputs();
}, [borrowProcess, contracts, resetInputs, vaultToUse]);
}, [borrowProcess, contracts, resetInputs, selectedVR, vaultToUse]);

return (
<Keyboard onEsc={() => setCollatInput('')} onEnter={() => console.log('ENTER smashed')} target="document">
Expand Down Expand Up @@ -471,7 +474,8 @@ const Borrow = () => {
<MaxButton
action={() => maxCollateral && handleMaxAction(ActionCodes.ADD_COLLATERAL)}
disabled={
!selectedSeries || collatInput === maxCollateral || selectedSeries.seriesIsMature
((!selectedSeries || selectedSeries.seriesIsMature) && !selectedVR) ||
collatInput === maxCollateral
}
clearAction={() => setCollatInput('')}
showingMax={!!collatInput && collatInput === maxCollateral}
Expand Down Expand Up @@ -541,12 +545,12 @@ const Borrow = () => {
icon={<FiPocket />}
value={`${cleanValue(borrowInput, selectedBase?.digitFormat!)} ${selectedBase?.displaySymbol}`}
/>
{!selectedVR && (
{selectedSeries && (
<div>
<InfoBite
label="Series Maturity"
icon={<FiClock />}
value={`${selectedSeries?.displayName}`}
value={`${selectedSeries.displayName}`}
/>

<InfoBite
Expand All @@ -558,7 +562,11 @@ const Borrow = () => {
/>
</div>
)}
<InfoBite label="Effective APR" icon={<FiPercent />} value={`${apr}%`} />
<InfoBite
label={`${selectedVR ? 'Variable' : 'Effective'} APR`}
icon={<FiPercent />}
value={`${apr}%`}
/>
<InfoBite
label="Total Supporting Collateral"
icon={
Expand Down Expand Up @@ -592,12 +600,10 @@ const Borrow = () => {
borrowProcess?.stage === ProcessStage.PROCESS_COMPLETE &&
borrowProcess?.tx.status === TxState.SUCCESSFUL && (
<Box pad="large" gap="small">
<Text size="small"> View Vault: </Text>
{vaultToUse && !vaultsLoading && (
<VaultItem vault={vaultMap?.get(vaultToUse.id)!} condensed index={1} />
)}
<Text size="small">View Vault:</Text>
{vaultToUse && <VaultItem vault={vaultToUse} condensed index={1} />}
{!vaultToUse && newVaultId && (
<DummyVaultItem series={selectedSeries!} vaultId={newVaultId!} condensed />
<DummyVaultItem series={selectedSeries!} vaultId={newVaultId} condensed />
)}
</Box>
)}
Expand Down
Loading