Skip to content

Commit

Permalink
Merge branch 'dev' into marcinciarka/sc-14956/omni-kit-clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinciarka authored Mar 25, 2024
2 parents e08e2a6 + 4f5d5fe commit 4103523
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 29 deletions.
74 changes: 70 additions & 4 deletions features/content/faqs/erc4626/earn/en.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,81 @@
import { FaqLayout } from 'features/content/faqs/FaqLayout'
import { EXTERNAL_LINKS } from 'helpers/applicationLinks'
import React from 'react'
import { Text } from 'theme-ui'
import { Box, Text } from 'theme-ui'

export default () => (
<FaqLayout
learnMoreUrl="/"
learnMoreUrl={EXTERNAL_LINKS.DOCS.MORPHO_BLUE.HUB}
noTitle={true}
contents={[
{
title: 'Lorem ipsum dolor sit amet',
body: <Text as="p">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</Text>,
title: 'Do I need to manage this MetaMorpho position?',
body: (
<Text as="p">
This position risk is managed by the Vault curator. This means the Vault curator takes
care of selecting the markets within Morpho Blue to get the best yield at the right
risk.
</Text>
),
},
{
title: 'What are the risks?',
body: (
<Box as="ol">
<Box as="li">
Bad debt risk: Under high stress market conditions, the liquidations of the protocol
could not perform as expect at all times. This could leave some market with bad debt
which is socialized among all lenders in the market.
</Box>
<Box as="li">
Curator risk: The strategy assumes that the curator as owner of the Vault performs its
duties and manages the risk appropriately, taking into account all relevant risks
parameters and market conditions.
</Box>
<Box as="li">
Systemic risk: Smart contract bugs, and fatal errors in any of the protocols being
used.
</Box>
</Box>
),
},
{
title: 'Where does the yield come from?',
body: (
<Text as="p">
The return comes from the interest paid from Morpho Blue borrowers in each underlying
market. As the vault deposits on different markets, it earns an interest rate
proportional to the allocation on each market.
</Text>
),
},
{
title: 'Where is my capital?',
body: (
<Text as="p">
This Earn position deposits into MetaMorpho Vaults which in turn allocate the funds to
different Morpho Blue markets according to the risk parameters set by the Vault Curator.
</Text>
),
},
{
title: 'How much does it cost?',
body: (
<Text as="p">
Summer.fi charges no fee on this Earn position. Each MetaMorpho Vault has a different
fee expressed in the position overview that's controlled by the Vault Curator, this fee
is charged for the risk management work done by them.
</Text>
),
},
{
title: 'Is this a short or long-term position?',
body: (
<Text as="p">
This is a long-term position that can be passively held assuming Curators handle risks
of the position.
</Text>
),
},
]}
/>
Expand Down
4 changes: 2 additions & 2 deletions features/omni-kit/controllers/OmniProductController.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { isCorrelatedPosition } from '@oasisdex/dma-library'
import { getNetworkById } from 'blockchain/networks'
import type { Tickers } from 'blockchain/prices.types'
import { WithConnection } from 'components/connectWallet'
Expand All @@ -9,6 +8,7 @@ import { OmniLayoutController } from 'features/omni-kit/controllers'
import {
getOmniExtraTokenData,
getOmniHeadlineProps,
getOmniIsOmniYieldLoop,
getOmniProductContextProviderData,
getOmniRawProtocol,
} from 'features/omni-kit/helpers'
Expand Down Expand Up @@ -158,7 +158,7 @@ export const OmniProductController = <Auction, History, Position>({
if (dpmPositionData === null) void replace(INTERNAL_LINKS.notFound)
}, [dpmPositionData])

const isYieldLoop = isCorrelatedPosition(collateralToken, quoteToken)
const isYieldLoop = getOmniIsOmniYieldLoop({ collateralToken, pseudoProtocol, quoteToken })

// Flag to determine whether full yield-loop UI experience is available for given protocol & pair
const isYieldLoopWithData = !!settings.yieldLoopPairsWithData?.[networkId]?.includes(
Expand Down
18 changes: 18 additions & 0 deletions features/omni-kit/helpers/getOmniIsOmniYieldLoop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isCorrelatedPosition } from '@oasisdex/dma-library'
import { Erc4626PseudoProtocol } from 'features/omni-kit/protocols/morpho-blue/constants'

interface GetOmniIsOmniYieldLoopParams {
collateralToken: string
pseudoProtocol?: string
quoteToken: string
}

export function getOmniIsOmniYieldLoop({
collateralToken,
pseudoProtocol,
quoteToken,
}: GetOmniIsOmniYieldLoopParams) {
if (pseudoProtocol === Erc4626PseudoProtocol) return false

return isCorrelatedPosition(collateralToken, quoteToken)
}
15 changes: 8 additions & 7 deletions features/omni-kit/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
export * from './getOmniAutomationPrimaryButtonLabelKey'
export * from './getOmniBorrowDebtMax'
export * from './getOmniBorrowishChangeVariant'
export * from './getOmniBorrowPaybackMax'
export * from './getOmniCommonValidations'
export * from './getOmniEntryToken'
export * from './getOmniEntryToken'
export * from './getOmniExtraTokenData'
export * from './getOmniFlowStateConfig'
export * from './getOmniFormDefaultParams'
export * from './getOmniHeadlineProps'
export * from './getOmniIsEarnFormEmpty'
export * from './getOmniIsFormEmpty'
export * from './useOmniLendingValidations'
export * from './getOmniIsOmniYieldLoop'
export * from './getOmniNetValue'
export * from './getOmniNetValuePnlData.types'
export * from './getOmniNetValuePnlData'
export * from './getOmniPositionUrl'
export * from './getOmniPrimaryButtonLabelKey'
export * from './getOmniProductContextProviderData'
export * from './getOmniProtocolUrlMap'
export * from './getOmniProtocolUrlMap'
export * from './getOmniRawProtocol'
export * from './getOmniSidebarButtonsStatus'
export * from './getOmniAutomationSidebarButtonsStatus'
Expand All @@ -28,13 +31,11 @@ export * from './isOmniFormValid'
export * from './isOmniSupportedNetworkId'
export * from './isShortPosition'
export * from './mapBorrowCumulativesToOmniCumulatives'
export * from './mapBorrowCumulativesToOmniCumulatives'
export * from './mapOmniEarnCumulatives'
export * from './mapOmniEarnCumulatives'
export * from './mapOmniLendingCumulatives'
export * from './mapOmniLendingCumulatives'
export * from './omniMetadataSupplyHandlerGuard'
export * from './resolvePaybackAmount'
export * from './mapOmniLendingCumulatives'
export * from './mapOmniEarnCumulatives'
export * from './mapBorrowCumulativesToOmniCumulatives'
export * from './getOmniProtocolUrlMap'
export * from './getOmniEntryToken'
export * from './getOmniAutomationPrimaryButtonLabelKey'
export * from './useOmniLendingValidations'
3 changes: 3 additions & 0 deletions features/omni-kit/protocols/ajna/helpers/formatSwapData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export const formatSwapData = ({
return {
...swapData,
fromTokenAmount: swapData.fromTokenAmount.shiftedBy(-fromTokenPrecision),
fromTokenAmountRaw: swapData.fromTokenAmount,
toTokenAmount: swapData.toTokenAmount.shiftedBy(-toTokenPrecision),
toTokenAmountRaw: swapData.toTokenAmount,
minToTokenAmount: swapData.minToTokenAmount.shiftedBy(-toTokenPrecision),
minToTokenAmountRaw: swapData.minToTokenAmount,
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
import { amountFromWei } from 'blockchain/utils'
import { InfoSection } from 'components/infoSection/InfoSection'
import { OmniGasEstimation } from 'features/omni-kit/components/sidebars'
import type { SecondaryVariantType } from 'components/infoSection/Item'
import {
OmniGasEstimation,
OmniSlippageInfoWithSettings,
} from 'features/omni-kit/components/sidebars'
import { useOmniGeneralContext, useOmniProductContext } from 'features/omni-kit/contexts'
import { omniExchangeQuote$ } from 'features/omni-kit/observables'
import {
resolveIfCachedPosition,
resolveIfCachedSwap,
} from 'features/omni-kit/protocols/ajna/helpers'
import { OmniProductType } from 'features/omni-kit/types'
import { formatCryptoBalance, formatUsdValue } from 'helpers/formatters/format'
import { calculatePriceImpact } from 'features/shared/priceImpact'
import { notAvailable } from 'handlers/portfolio/constants'
import {
formatCryptoBalance,
formatDecimalAsPercent,
formatUsdValue,
} from 'helpers/formatters/format'
import { useObservable } from 'helpers/observableHook'
import { one } from 'helpers/zero'
import { useTranslation } from 'next-i18next'
import type { FC } from 'react'
import React from 'react'
import React, { useMemo } from 'react'
import { EMPTY } from 'rxjs'
import { Flex, Text } from 'theme-ui'

export const Erc4626FormOrder: FC = () => {
const { t } = useTranslation()

const {
environment: { quotePrecision, quotePrice, quoteToken },
environment: {
isStrategyWithDefaultSlippage,
networkId,
quotePrecision,
quotePrice,
quoteToken,
slippage,
slippageSource,
},
steps: { isFlowStateReady },
tx: { isTxSuccess, txDetails },
tx: { isTxSuccess, txDetails, setSlippageSource },
} = useOmniGeneralContext()
const {
form: {
Expand All @@ -40,6 +62,34 @@ export const Erc4626FormOrder: FC = () => {
cachedSwap: swap?.cached,
})

const [initialQuote] = useObservable(
useMemo(
() =>
pullToken && depositAmount
? omniExchangeQuote$({
networkId,
collateralToken: pullToken.token,
slippage,
amount: one.div(quotePrice),
action: 'BUY_COLLATERAL',
exchangeType: 'defaultExchange',
quoteToken,
})
: EMPTY,
[depositAmount, networkId, pullToken, quotePrice, quoteToken, slippage],
),
)

const priceImpact =
initialQuote?.status === 'SUCCESS' && swapData && pullToken
? calculatePriceImpact(
initialQuote.tokenPrice,
amountFromWei(swapData.toTokenAmountRaw, quotePrecision).div(
amountFromWei(swapData.fromTokenAmountRaw, pullToken.precision),
),
).div(100)
: undefined

const oasisFee =
swapData &&
pullToken &&
Expand All @@ -55,7 +105,16 @@ export const Erc4626FormOrder: FC = () => {
simulationData?.quoteTokenAmount &&
`${formatCryptoBalance(simulationData.quoteTokenAmount)} ${quoteToken}`,
swappingFrom: depositAmount && `${formatCryptoBalance(depositAmount)} ${pullToken?.token}`,
swappingTo: swapData && `${formatCryptoBalance(swapData.minToTokenAmount)} ${quoteToken}`,
swappingTo:
swapData &&
`${formatCryptoBalance(
amountFromWei(swapData.minToTokenAmountRaw, quotePrecision),
)} ${quoteToken}`,
marketPrice: pullToken
? `${formatCryptoBalance(pullToken.price.div(quotePrice))} ${pullToken.token}/${quoteToken}`
: notAvailable,
marketPriceImpact: priceImpact ? formatDecimalAsPercent(priceImpact) : notAvailable,
slippageLimit: formatDecimalAsPercent(slippage),
oasisFee: oasisFee && formatUsdValue(oasisFee),
totalCost: txDetails?.txCost ? formatUsdValue(txDetails.txCost) : '-',
}
Expand All @@ -70,14 +129,37 @@ export const Erc4626FormOrder: FC = () => {
change: formatted.afterTotalDeposit,
isLoading,
},
...(swapData
...(swapData && pullToken
? [
{
label: t('erc-4626.position-page.earn.form-order.swapping'),
value: formatted.swappingFrom,
change: formatted.swappingTo,
isLoading,
},
{
label: t('vault-changes.price-impact', {
token: `${pullToken.token}/${quoteToken}`,
}),
value: formatted.marketPrice,
secondary: {
value: formatted.marketPriceImpact,
variant: 'negative' as SecondaryVariantType,
},
isLoading,
},
{
label: t('vault-changes.slippage-limit'),
value: (
<OmniSlippageInfoWithSettings
changeSlippage={setSlippageSource}
getSlippageFrom={slippageSource}
slippage={formatted.slippageLimit}
withDefaultSlippage={isStrategyWithDefaultSlippage}
/>
),
isLoading,
},
]
: []),
...(isTxSuccess
Expand Down
16 changes: 16 additions & 0 deletions features/omni-kit/protocols/erc-4626/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ export const erc4626Vaults: Erc4626Config[] = [
symbol: 'USDT',
},
},
{
address: '0xBEEf050ecd6a16c4e7bfFbB52Ebba7846C4b8cD4',
curator: steakhouseCurator,
id: 'steakhouse-ETH',
name: 'Steakhouse ETH',
protocol: LendingProtocol.MorphoBlue,
networkId: NetworkIds.MAINNET,
pricePicker: morphoPricePicker,
rewards: [morphoRewards],
strategy: 'MetaMorpho Lending',
token: {
address: getNetworkContracts(NetworkIds.MAINNET).tokens.ETH.address,
precision: getToken('ETH').precision,
symbol: 'ETH',
},
},
]

export const erc4626VaultsById = keyBy(erc4626Vaults, 'id')
Expand Down
7 changes: 6 additions & 1 deletion features/omni-kit/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,12 @@ export interface OmniSimulationCommon {
getValidations: (params: GetOmniValidationResolverParams) => OmniValidations
}

export type OmniSimulationSwap = Swap & SwapData
export type OmniSimulationSwap = Swap &
SwapData & {
fromTokenAmountRaw: BigNumber
minToTokenAmountRaw: BigNumber
toTokenAmountRaw: BigNumber
}

export interface OmniValidationItem {
message: { translationKey?: string; component?: JSX.Element; params?: { [key: string]: string } }
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oasis-borrow",
"version": "12.16.0",
"version": "12.17.2",
"license": "Apache-2.0",
"engines": {
"node": ">=18.12"
Expand Down Expand Up @@ -45,7 +45,7 @@
"@metamask/eth-sig-util": "^5.0.2",
"@oasisdex/addresses": "0.1.54",
"@oasisdex/automation": "1.6.5",
"@oasisdex/dma-library": "0.6.48",
"@oasisdex/dma-library": "0.6.49",
"@oasisdex/multiply": "^0.2.11",
"@oasisdex/transactions": "0.1.4-alpha.0",
"@oasisdex/utils": "^0.0.8",
Expand Down
Loading

0 comments on commit 4103523

Please sign in to comment.