From 9ba58d1becfa82ebac3de204307099009929698d Mon Sep 17 00:00:00 2001 From: piekczyk Date: Mon, 17 Jun 2024 15:09:58 +0200 Subject: [PATCH] Morpho Base fix (#3949) --- .../contexts/triggers-aave-state-machine-context.tsx | 2 +- .../aave/manage/state/triggersAaveStateMachine.ts | 2 +- features/omni-kit/constants.ts | 11 +++++++++-- features/omni-kit/hooks/useOmniTriggersData.ts | 2 +- .../morpho-blue/metadata/useMorphoMetadata.tsx | 5 ++++- .../triggers/get-triggers/get-triggers-request.ts | 4 ++-- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/features/aave/manage/contexts/triggers-aave-state-machine-context.tsx b/features/aave/manage/contexts/triggers-aave-state-machine-context.tsx index 935efc9b5b..3a684affca 100644 --- a/features/aave/manage/contexts/triggers-aave-state-machine-context.tsx +++ b/features/aave/manage/contexts/triggers-aave-state-machine-context.tsx @@ -63,7 +63,7 @@ function useSetupTriggersStateContext( ), autoBuyTrigger: autobuyStateMachine, autoSellTrigger: autosellStateMachine, - currentTriggers: omniPositionTriggersDataDefault, + currentTriggers: omniPositionTriggersDataDefault(), }), { devTools: env.NODE_ENV !== 'production' }, ).start() diff --git a/features/aave/manage/state/triggersAaveStateMachine.ts b/features/aave/manage/state/triggersAaveStateMachine.ts index a3cdf4b657..8cfd813902 100644 --- a/features/aave/manage/state/triggersAaveStateMachine.ts +++ b/features/aave/manage/state/triggersAaveStateMachine.ts @@ -587,7 +587,7 @@ export const triggersAaveStateMachine = createMachine( } = context if (!dpm) { - return omniPositionTriggersDataDefault + return omniPositionTriggersDataDefault() } return await getTriggersRequest({ dpmProxy: dpm.proxy, networkId, protocol }) diff --git a/features/omni-kit/constants.ts b/features/omni-kit/constants.ts index ce1b199166..8f326214b5 100644 --- a/features/omni-kit/constants.ts +++ b/features/omni-kit/constants.ts @@ -100,7 +100,7 @@ export const omniDefaultOverviewSimulationDeposit = new BigNumber(100) export const omniYieldLoopMaxRiskLtvDefaultOffset = new BigNumber(0.02) // Default response to avoid unnecessary API calls if automation is not available on given protocol -export const omniPositionTriggersDataDefault: GetTriggersResponse = { +export const omniPositionTriggersDataDefault = (poolId?: string): GetTriggersResponse => ({ triggers: { aave3: {}, spark: {}, @@ -120,10 +120,17 @@ export const omniPositionTriggersDataDefault: GetTriggersResponse = { isStopLossEnabled: false, isTrailingStopLossEnabled: false, }, + [`morphoblue-${poolId}`]: { + isBasicBuyEnabled: false, + isBasicSellEnabled: false, + isPartialTakeProfitEnabled: false, + isStopLossEnabled: false, + isTrailingStopLossEnabled: false, + }, }, triggerGroup: {}, triggersCount: 0, -} +}) export const omniProtectionLikeAutomationFeatures = [ AutomationFeatures.STOP_LOSS, diff --git a/features/omni-kit/hooks/useOmniTriggersData.ts b/features/omni-kit/hooks/useOmniTriggersData.ts index 4c07918990..19126682ac 100644 --- a/features/omni-kit/hooks/useOmniTriggersData.ts +++ b/features/omni-kit/hooks/useOmniTriggersData.ts @@ -42,7 +42,7 @@ export function useOmniTriggersData({ ? dpmPositionData ? getTriggersRequest$({ dpmProxy: dpmPositionData.proxy, networkId, poolId, protocol }) : EMPTY - : of(omniPositionTriggersDataDefault), + : of(omniPositionTriggersDataDefault(poolId)), [dpmPositionData, isOpening, networkId, poolId, protocol, settings.availableAutomations], ), ) diff --git a/features/omni-kit/protocols/morpho-blue/metadata/useMorphoMetadata.tsx b/features/omni-kit/protocols/morpho-blue/metadata/useMorphoMetadata.tsx index 0b6d830f1e..9fd1c1fa10 100644 --- a/features/omni-kit/protocols/morpho-blue/metadata/useMorphoMetadata.tsx +++ b/features/omni-kit/protocols/morpho-blue/metadata/useMorphoMetadata.tsx @@ -1,5 +1,6 @@ import type { MorphoBluePosition } from '@oasisdex/dma-library' import { negativeToZero } from '@oasisdex/dma-library' +import { NetworkIds } from 'blockchain/networks' import type { DetailsSectionNotificationItem } from 'components/DetailsSectionNotification' import faqBorrow from 'features/content/faqs/morphoblue/borrow/en' import faqMultiply from 'features/content/faqs/morphoblue/multiply/en' @@ -54,6 +55,7 @@ export const useMorphoMetadata: GetOmniMetadata = (productContext) => { quoteBalance, quotePrecision, isOpening, + networkId, }, steps: { currentStep }, tx: { txDetails }, @@ -88,7 +90,8 @@ export const useMorphoMetadata: GetOmniMetadata = (productContext) => { ltv: resolvedSimulation?.maxRiskRatio.loanToValue || position.maxRiskRatio.loanToValue, }) - const refinanceBanner = !isOpening ? useOmniRefinanceBanner() : undefined + const refinanceBanner = + !isOpening && networkId === NetworkIds.MAINNET ? useOmniRefinanceBanner() : undefined return { notifications, diff --git a/helpers/lambda/triggers/get-triggers/get-triggers-request.ts b/helpers/lambda/triggers/get-triggers/get-triggers-request.ts index 53f9303773..95e3060e3e 100644 --- a/helpers/lambda/triggers/get-triggers/get-triggers-request.ts +++ b/helpers/lambda/triggers/get-triggers/get-triggers-request.ts @@ -11,7 +11,7 @@ export const getTriggersRequest = async ({ protocol, }: GetTriggersParams): Promise => { if (dpmProxy && isZeroAddress(dpmProxy)) { - return omniPositionTriggersDataDefault + return omniPositionTriggersDataDefault(poolId) } const { url } = getTriggersConfig({ @@ -28,6 +28,6 @@ export const getTriggersRequest = async ({ } catch (e) { console.error('Failed to read data about triggers from server', e) // We are returning a default response to ensure that UI won't crash and user will have access to position - return omniPositionTriggersDataDefault + return omniPositionTriggersDataDefault(poolId) } }