Skip to content

Commit

Permalink
Morpho Base fix (#3949)
Browse files Browse the repository at this point in the history
  • Loading branch information
piekczyk committed Jun 17, 2024
1 parent d535728 commit 9ba58d1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function useSetupTriggersStateContext(
),
autoBuyTrigger: autobuyStateMachine,
autoSellTrigger: autosellStateMachine,
currentTriggers: omniPositionTriggersDataDefault,
currentTriggers: omniPositionTriggersDataDefault(),
}),
{ devTools: env.NODE_ENV !== 'production' },
).start()
Expand Down
2 changes: 1 addition & 1 deletion features/aave/manage/state/triggersAaveStateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ export const triggersAaveStateMachine = createMachine(
} = context

if (!dpm) {
return omniPositionTriggersDataDefault
return omniPositionTriggersDataDefault()
}

return await getTriggersRequest({ dpmProxy: dpm.proxy, networkId, protocol })
Expand Down
11 changes: 9 additions & 2 deletions features/omni-kit/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion features/omni-kit/hooks/useOmniTriggersData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -54,6 +55,7 @@ export const useMorphoMetadata: GetOmniMetadata = (productContext) => {
quoteBalance,
quotePrecision,
isOpening,
networkId,
},
steps: { currentStep },
tx: { txDetails },
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions helpers/lambda/triggers/get-triggers/get-triggers-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const getTriggersRequest = async ({
protocol,
}: GetTriggersParams): Promise<GetTriggersResponse> => {
if (dpmProxy && isZeroAddress(dpmProxy)) {
return omniPositionTriggersDataDefault
return omniPositionTriggersDataDefault(poolId)
}

const { url } = getTriggersConfig({
Expand All @@ -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)
}
}

0 comments on commit 9ba58d1

Please sign in to comment.