Skip to content

Commit

Permalink
Bugfix/implied rate issues (#739)
Browse files Browse the repository at this point in the history
* fix: various issues

* fix: manage convert roll labels

* fix: remove vault returns
  • Loading branch information
jeffywu authored Apr 5, 2024
1 parent 5381de3 commit 26c96b5
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 42 deletions.
3 changes: 2 additions & 1 deletion packages/core-entities/src/client/oracle-registry-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class OracleRegistryClient extends ClientRegistry<OracleDefinition> {

if (
oracle.oracleType === 'fCashOracleRate' ||
oracle.oracleAddress === 'fCashSpotRate'
oracle.oracleType === 'fCashSpotRate'
) {
// Suppress historical fcash rates
const { maturity } = decodeERC1155Id(oracle.quote);
Expand Down Expand Up @@ -198,6 +198,7 @@ export class OracleRegistryClient extends ClientRegistry<OracleDefinition> {

// Uses oracle rates historically
if (subjectMapOverride) {
node = { ...n };
node.id = node.id.replace(FCASH_RATE_SOURCE, 'fCashOracleRate');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import {
Network,
TXN_HISTORY_TYPE,
TABLE_WARNINGS,
leveragedYield,
formatMaturity,
} from '@notional-finance/util';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { messages } from '../messages';
import {
TradeContext,
useAllMarkets,
usePrimeCash,
usePrimeDebt,
} from '@notional-finance/notionable-hooks';
import {
formatNumberAsPercent,
Expand Down Expand Up @@ -48,9 +50,22 @@ export const SelectConvertAsset = ({
const { nonLeveragedYields } = useAllMarkets(selectedNetwork);
const { options, initialConvertFromBalance: balance } =
useConvertOptions(state);
const convertFromToken = tradeType === 'ConvertAsset' ? debt : collateral;

let convertFromToken = tradeType === 'ConvertAsset' ? debt : collateral;
const pCash = usePrimeCash(selectedNetwork, convertFromToken?.currencyId);
const pDebt = usePrimeDebt(selectedNetwork, convertFromToken?.currencyId);
if (convertFromToken?.tokenType === 'PrimeCash') {
convertFromToken = pDebt;
} else if (convertFromToken?.tokenType === 'PrimeDebt') {
convertFromToken = pCash;
}

const convertFromBalance =
tradeType === 'ConvertAsset' ? debtBalance : collateralBalance;
convertFromToken &&
(tradeType === 'ConvertAsset' ? debtBalance : collateralBalance)?.toToken(
convertFromToken
);

const marketApy = nonLeveragedYields.find(
(y) => y.token.id === convertFromToken?.id
)?.totalAPY;
Expand Down
26 changes: 1 addition & 25 deletions packages/features/vault/src/vault-view/vault-summary.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { Box, useTheme } from '@mui/material';
import {
Faq,
FaqHeader,
DataTable,
TABLE_VARIANTS,
TotalRow,
} from '@notional-finance/mui';
import { Faq, FaqHeader, DataTable, TotalRow } from '@notional-finance/mui';
import { useContext } from 'react';
import { FormattedMessage } from 'react-intl';
import { MobileVaultSummary } from '../components';
Expand All @@ -18,7 +12,6 @@ import {
import {
useVaultReinvestmentTable,
useVaultExistingFactors,
useReturnDrivers,
useVaultFaq,
} from '../hooks';
import { PRIME_CASH_VAULT_MATURITY } from '@notional-finance/util';
Expand All @@ -35,10 +28,6 @@ export const VaultSummary = () => {
deposit,
vaultTVL,
} = state;
const { tableColumns, returnDrivers } = useReturnDrivers(
vaultAddress,
selectedNetwork
);
const { vaultShare, assetLiquidationPrice, priorBorrowRate, leverageRatio } =
useVaultExistingFactors();
const { faqHeaderLinks, faqs } = useVaultFaq(
Expand Down Expand Up @@ -124,19 +113,6 @@ export const VaultSummary = () => {
vaultCollateral={vaultShare}
vaultLiquidationPrice={assetLiquidationPrice}
/>
<DataTable
data={returnDrivers}
columns={tableColumns}
tableVariant={TABLE_VARIANTS.TOTAL_ROW}
tableTitle={
<div>
<FormattedMessage
defaultMessage="Return Drivers"
description="Return Drivers Table Title"
/>
</div>
}
/>
<Box
sx={{
marginBottom: theme.spacing(5),
Expand Down
19 changes: 12 additions & 7 deletions packages/shared/notionable-hooks/src/use-market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,16 @@ export const useSpotMaturityData = (
export function useTradedValue(amount: TokenBalance | undefined) {
const fCashMarket = useFCashMarket(amount?.token);
const primeCash = usePrimeCash(amount?.network, amount?.currencyId);
return primeCash && fCashMarket
? exchangeToLocalPrime(
amount,
fCashMarket,
primeCash
).localPrime.toUnderlying()
: undefined;
try {
return primeCash && fCashMarket
? exchangeToLocalPrime(
amount,
fCashMarket,
primeCash
).localPrime.toUnderlying()
: undefined;
} catch (e) {
console.error(e);
return undefined;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function useMaxLiquidityWithdraw(context: BaseTradeContext) {
]);

return {
onMaxValue,
onMaxValue: maxWithdrawUnderlying ? onMaxValue : undefined,
currencyInputRef,
setCurrencyInput,
maxWithdrawUnderlying,
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/trade/src/hooks/use-max-withdraw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function useMaxWithdraw(context: BaseTradeContext) {
}, [maxWithdraw, updateState, setCurrencyInput, debt, maxWithdrawUnderlying]);

return {
onMaxValue,
onMaxValue: maxWithdraw ? onMaxValue : undefined,
currencyInputRef,
setCurrencyInput,
maxWithdrawUnderlying,
Expand Down
4 changes: 0 additions & 4 deletions packages/shared/wallet/src/onboard-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ export const modules = [
label: 'Coinbase Wallet',
icon: CoinbaseWallet,
},
{
label: 'Gnosis Safe',
icon: CoinbaseWallet,
},
];

const email = process.env['NX_CONTACT_EMAIL'] as string;
Expand Down

0 comments on commit 26c96b5

Please sign in to comment.