Skip to content

Commit

Permalink
Remove CM (#4037)
Browse files Browse the repository at this point in the history
* Remove CM

* fix translation file typo
  • Loading branch information
piekczyk authored Sep 27, 2024
1 parent 3bab84e commit 931aa0c
Show file tree
Hide file tree
Showing 114 changed files with 65 additions and 3,560 deletions.
6 changes: 0 additions & 6 deletions analytics/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export enum MixpanelPages {
StopLoss = 'StopLoss',
AutoBuy = 'AutoBuy',
AutoSell = 'AutoSell',
ConstantMultiple = 'ConstantMultiple',
TakeProfit = 'TakeProfit',
DAISavingsRate = 'DAISavingsRate',
ProductHub = 'ProductHub',
Expand All @@ -47,7 +46,6 @@ export enum MixpanelAutomationEventIds {
SelectStopLoss = 'SelectStopLoss',
SelectAutoSell = 'SelectAutoSell',
SelectAutoBuy = 'SelectAutoBuy',
SelectConstantMultiple = 'SelectConstantMultiple',
SelectTakeProfit = 'SelectTakeProfit',

AddStopLoss = 'AddStopLoss',
Expand All @@ -62,10 +60,6 @@ export enum MixpanelAutomationEventIds {
EditAutoSell = 'EditAutoSell',
RemoveAutoSell = 'RemoveAutoSell',

AddConstantMultiple = 'AddConstantMultiple',
EditConstantMultiple = 'EditConstantMultiple',
RemoveConstantMultiple = 'RemoveConstantMultiple',

AddTakeProfit = 'AddTakeProfit',
EditTakeProfit = 'EditTakeProfit',
RemoveTakeProfit = 'RemoveAutoTakeProfit',
Expand Down
22 changes: 2 additions & 20 deletions blockchain/calls/automationBotAggregator.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,9 @@ import { getNetworkContracts } from 'blockchain/contracts'
import { contractDesc, NetworkIds } from 'blockchain/networks'
import type { DsProxy } from 'types/web3-v1-contracts'

import {
getAddAutomationAggregatotTriggerCallData,
getRemoveAutomationBotAggregatorTriggersCallData,
} from './automationBotAggregator'
import type {
AutomationBotAddAggregatorTriggerData,
AutomationBotRemoveTriggersData,
} from './automationBotAggregator.types'
import { getRemoveAutomationBotAggregatorTriggersCallData } from './automationBotAggregator'
import type { AutomationBotRemoveTriggersData } from './automationBotAggregator.types'

export const addAutomationBotAggregatorTrigger: TransactionDef<AutomationBotAddAggregatorTriggerData> =
{
call: ({ proxyAddress }, { contract }) => {
return contract<DsProxy>(contractDesc(dsProxy, proxyAddress)).methods[
'execute(address,bytes)'
]
},
prepareArgs: (data, context) => [
getNetworkContracts(NetworkIds.MAINNET, context.chainId).automationBotAggregator.address,
getAddAutomationAggregatotTriggerCallData(data, context).encodeABI(),
],
}
export const removeAutomationBotAggregatorTriggers: TransactionDef<AutomationBotRemoveTriggersData> =
{
call: ({ proxyAddress }, { contract }) => {
Expand Down
24 changes: 1 addition & 23 deletions blockchain/calls/automationBotAggregator.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@
import BigNumber from 'bignumber.js'
import { getNetworkContracts } from 'blockchain/contracts'
import type { ContextConnected } from 'blockchain/network.types'
import { NetworkIds } from 'blockchain/networks'
import { CONSTANT_MULTIPLE_GROUP_TYPE } from 'features/automation/optimization/constantMultiple/state/useConstantMultipleStateInitialization.constants'
import type { AutomationBotAggregator } from 'types/web3-v1-contracts'

import type {
AutomationBotAddAggregatorTriggerData,
AutomationBotRemoveTriggersData,
} from './automationBotAggregator.types'

export function getAddAutomationAggregatotTriggerCallData(
data: AutomationBotAddAggregatorTriggerData,
context: ContextConnected,
) {
const { contract, chainId } = context

return contract<AutomationBotAggregator>(
getNetworkContracts(NetworkIds.MAINNET, chainId).automationBotAggregator,
).methods.addTriggerGroup(
CONSTANT_MULTIPLE_GROUP_TYPE,
data.replacedTriggerIds.map((id: BigNumber) =>
BigNumber.isBigNumber(id) ? id.toString() : id,
),
data.triggersData,
)
}
import type { AutomationBotRemoveTriggersData } from './automationBotAggregator.types'

export function getRemoveAutomationBotAggregatorTriggersCallData(
data: AutomationBotRemoveTriggersData,
Expand Down
3 changes: 1 addition & 2 deletions components/AutomationIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { StatefulTooltip } from 'components/Tooltip'
import type { PortfolioPosition } from 'handlers/portfolio/types'
import { useTranslation } from 'next-i18next'
import React from 'react'
import { auto_buy, auto_sell, constant_multiple, stop_loss, take_profit } from 'theme/icons'
import { auto_buy, auto_sell, stop_loss, take_profit } from 'theme/icons'

interface AutomationIconProps {
enabled: boolean
Expand All @@ -15,7 +15,6 @@ interface AutomationIconProps {
const automationIconMap: Record<keyof PortfolioPosition['automations'], IconProps['icon']> = {
autoBuy: auto_buy,
autoSell: auto_sell,
constantMultiple: constant_multiple,
stopLoss: stop_loss,
takeProfit: take_profit,
}
Expand Down
1 change: 0 additions & 1 deletion components/Banner.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { BannerGradientPresetsArray } from './Banner.types'
export const bannerGradientPresets: BannerGradientPresetsArray = {
autoBuy: ['#e0e7ff', '#fae2fc'],
autoSell: ['#fef1e1', '#fef5d6'],
constantMultiply: ['#ffdde7', '#ffe7f5'],
stopLoss: ['#ffeaea', '#fff5ea'],
trailingStopLoss: ['#ffeaea', '#fff5ea'],
partialTakeProfit: ['#ffeaea', '#fff5ea'],
Expand Down
22 changes: 0 additions & 22 deletions components/context/AutomationContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@ import type {
AutoBSMetadata,
AutomationDefinitionMetadata,
AutoTakeProfitMetadata,
ConstantMultipleMetadata,
OverwriteTriggersDefaults,
StopLossMetadata,
} from 'features/automation/metadata/types'
import { extractAutoTakeProfitData } from 'features/automation/optimization/autoTakeProfit/state/autoTakeProfitTriggerData'
import type { AutoTakeProfitTriggerData } from 'features/automation/optimization/autoTakeProfit/state/autoTakeProfitTriggerData.types'
import { defaultAutoTakeProfitData } from 'features/automation/optimization/autoTakeProfit/state/defaultAutoTakeProfitData'
import { useAutoTakeProfitStateInitializator } from 'features/automation/optimization/autoTakeProfit/state/useAutoTakeProfitStateInitializator'
import { extractConstantMultipleData } from 'features/automation/optimization/constantMultiple/state/constantMultipleTriggerData'
import { defaultConstantMultipleData } from 'features/automation/optimization/constantMultiple/state/constantMultipleTriggerData.constants'
import type { ConstantMultipleTriggerData } from 'features/automation/optimization/constantMultiple/state/constantMultipleTriggerData.types'
import { useConstantMultipleStateInitialization } from 'features/automation/optimization/constantMultiple/state/useConstantMultipleStateInitialization'
import { extractStopLossData } from 'features/automation/protection/stopLoss/state/stopLossTriggerData'
import { defaultStopLossData } from 'features/automation/protection/stopLoss/state/stopLossTriggerData.constants'
import type { StopLossTriggerData } from 'features/automation/protection/stopLoss/state/stopLossTriggerData.types'
Expand Down Expand Up @@ -83,7 +78,6 @@ export interface AutomationContext {
autoBuyMetadata: AutoBSMetadata
autoSellMetadata: AutoBSMetadata
autoTakeProfitMetadata: AutoTakeProfitMetadata
constantMultipleMetadata: ConstantMultipleMetadata
stopLossMetadata: StopLossMetadata
}
positionData: AutomationPositionData
Expand All @@ -92,7 +86,6 @@ export interface AutomationContext {
autoBuyTriggerData: AutoBSTriggerData
autoSellTriggerData: AutoBSTriggerData
autoTakeProfitTriggerData: AutoTakeProfitTriggerData
constantMultipleTriggerData: ConstantMultipleTriggerData
stopLossTriggerData: StopLossTriggerData
}
}
Expand Down Expand Up @@ -180,7 +173,6 @@ export function AutomationContextProvider({
autoBuyTriggerData: defaultAutoBSData,
autoSellTriggerData: defaultAutoBSData,
autoTakeProfitTriggerData: defaultAutoTakeProfitData,
constantMultipleTriggerData: defaultConstantMultipleData,
stopLossTriggerData: defaultStopLossData,
}

Expand Down Expand Up @@ -235,19 +227,6 @@ export function AutomationContextProvider({
type: TriggerType.BasicBuy,
})

useConstantMultipleStateInitialization({
autoBuyTriggerData: autoContext.triggerData.autoBuyTriggerData,
autoSellTriggerData: autoContext.triggerData.autoSellTriggerData,
constantMultipleTriggerData: autoContext.triggerData.constantMultipleTriggerData,
stopLossTriggerData: autoContext.triggerData.stopLossTriggerData,
debt: positionData.debt,
debtFloor: positionData.debtFloor,
ilk: positionData.ilk,
liquidationRatio: positionData.liquidationRatio,
lockedCollateral: positionData.lockedCollateral,
positionRatio: positionData.positionRatio,
})

useAutoTakeProfitStateInitializator({
autoTakeProfitTriggerData: autoContext.triggerData.autoTakeProfitTriggerData,
debt: positionData.debt,
Expand Down Expand Up @@ -275,7 +254,6 @@ export function AutomationContextProvider({
triggerType: TriggerType.BasicSell,
}),
autoTakeProfitTriggerData: extractAutoTakeProfitData(resolvedAutomationTriggersData),
constantMultipleTriggerData: extractConstantMultipleData(resolvedAutomationTriggersData),
stopLossTriggerData: extractStopLossData(
resolvedAutomationTriggersData,
overwriteTriggersDefaults.stopLossTriggerData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ export const PortfolioPositionAutomationIcons = ({
iconNotActiveBg={iconNotActiveBg}
/>
)}
{automations.constantMultiple && (
<AutomationIcon
enabled={automations.constantMultiple.enabled}
type="constantMultiple"
iconNotActiveBg={iconNotActiveBg}
/>
)}
</>
)
}
7 changes: 2 additions & 5 deletions components/vault/GeneralManageTabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,14 @@ export function GeneralManageTabBar({
autoBuyTriggerData,
autoSellTriggerData,
autoTakeProfitTriggerData,
constantMultipleTriggerData,
stopLossTriggerData,
},
} = useAutomationContext()

const protectionEnabled =
stopLossTriggerData.isStopLossEnabled || autoSellTriggerData.isTriggerEnabled
const optimizationEnabled =
autoBuyTriggerData.isTriggerEnabled ||
constantMultipleTriggerData.isTriggerEnabled ||
autoTakeProfitTriggerData.isTriggerEnabled
autoBuyTriggerData.isTriggerEnabled || autoTakeProfitTriggerData.isTriggerEnabled

useEffect(() => {
const uiChanges$ = uiChanges.subscribe<TabChange>(TAB_CHANGE_SUBJECT)
Expand Down Expand Up @@ -96,7 +93,7 @@ export function GeneralManageTabBar({
label: t('system.optimization'),
value: VaultViewMode.Optimization,
tag: { include: true, active: optimizationEnabled },
content: <OptimizationControl vaultHistory={vaultHistory} />,
content: <OptimizationControl />,
callback: () => {
trackingEvents.automation.buttonClick(
MixpanelAutomationEventIds.SelectOptimization,
Expand Down
46 changes: 7 additions & 39 deletions components/vault/OptimizationControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import { AUTO_TAKE_PROFIT_FORM_CHANGE } from 'features/automation/optimization/a
import type { AutoTakeProfitFormChange } from 'features/automation/optimization/autoTakeProfit/state/autoTakeProfitFormChange.types'
import { OptimizationDetailsControl } from 'features/automation/optimization/common/controls/OptimizationDetailsControl'
import { OptimizationFormControl } from 'features/automation/optimization/common/controls/OptimizationFormControl'
import { CONSTANT_MULTIPLE_FORM_CHANGE } from 'features/automation/optimization/constantMultiple/state/constantMultipleFormChange.constants'
import type { ConstantMultipleFormChange } from 'features/automation/optimization/constantMultiple/state/constantMultipleFormChange.types'
import { VaultNotice } from 'features/notices/VaultsNoticesView'
import type { VaultHistoryEvent } from 'features/vaultHistory/vaultHistory.types'
import { EXTERNAL_LINKS } from 'helpers/applicationLinks'
import { VaultContainerSpinner, WithLoadingIndicator } from 'helpers/AppSpinner'
import { useAppConfig } from 'helpers/config'
Expand Down Expand Up @@ -63,32 +60,19 @@ function ZeroDebtOptimizationBanner({
}
function getZeroDebtOptimizationBannerProps({
readOnlyAutoBSEnabled,
constantMultipleReadOnlyEnabled,
readOnlyAutoTakeProfitEnabled,
isVaultDebtZero,
vaultHasNoActiveBuyTrigger,
vaultHasNoActiveConstantMultipleTriggers,
vaultHasNoActiveAutoTakeProfitTrigger,
}: {
readOnlyAutoBSEnabled: boolean
constantMultipleReadOnlyEnabled: boolean
readOnlyAutoTakeProfitEnabled: boolean
isVaultDebtZero: boolean
vaultHasNoActiveBuyTrigger?: boolean
vaultHasNoActiveConstantMultipleTriggers?: boolean
vaultHasNoActiveAutoTakeProfitTrigger?: boolean
}): ZeroDebtOptimizationBannerProps {
if (
!readOnlyAutoBSEnabled &&
!constantMultipleReadOnlyEnabled &&
!readOnlyAutoTakeProfitEnabled
) {
if (
isVaultDebtZero &&
vaultHasNoActiveBuyTrigger &&
vaultHasNoActiveConstantMultipleTriggers &&
vaultHasNoActiveAutoTakeProfitTrigger
) {
if (!readOnlyAutoBSEnabled && !readOnlyAutoTakeProfitEnabled) {
if (isVaultDebtZero && vaultHasNoActiveBuyTrigger && vaultHasNoActiveAutoTakeProfitTrigger) {
return {
header: 'optimization.zero-debt-heading',
description: 'optimization.zero-debt-description',
Expand All @@ -108,65 +92,49 @@ function getZeroDebtOptimizationBannerProps({
}
}

interface OptimizationControlProps {
vaultHistory: VaultHistoryEvent[]
}

export function OptimizationControl({ vaultHistory }: OptimizationControlProps) {
export function OptimizationControl() {
const {
positionData: { debt },
triggerData: { autoBuyTriggerData, autoTakeProfitTriggerData, constantMultipleTriggerData },
triggerData: { autoBuyTriggerData, autoTakeProfitTriggerData },
} = useAutomationContext()
const { txHelpers$ } = useMainContext()
const [txHelpersData] = useObservable(txHelpers$)
const [autoBuyState] = useUIChanges<AutoBSFormChange>(AUTO_BUY_FORM_CHANGE)
const [autoTakeProfitState] = useUIChanges<AutoTakeProfitFormChange>(AUTO_TAKE_PROFIT_FORM_CHANGE)
const [constantMultipleState] = useUIChanges<ConstantMultipleFormChange>(
CONSTANT_MULTIPLE_FORM_CHANGE,
)

const {
ReadOnlyBasicBS: readOnlyAutoBSEnabled,
ConstantMultipleReadOnly: constantMultipleReadOnlyEnabled,
ReadOnlyAutoTakeProfit: readOnlyAutoTakeProfitEnabled,
} = useAppConfig('features')

const vaultHasActiveAutoBuyTrigger = autoBuyTriggerData.isTriggerEnabled
const vaultHasActiveConstantMultipleTrigger = constantMultipleTriggerData.isTriggerEnabled
const vaultHasActiveAutoTakeProfitTrigger = autoTakeProfitTriggerData.isTriggerEnabled

return (
<WithLoadingIndicator
value={[autoBuyState, autoTakeProfitState, constantMultipleState]}
value={[autoBuyState, autoTakeProfitState]}
customLoader={<VaultContainerSpinner />}
>
{() =>
(!vaultHasActiveAutoBuyTrigger && !vaultHasActiveAutoTakeProfitTrigger && debt.isZero()) ||
(!vaultHasActiveAutoBuyTrigger &&
!vaultHasActiveConstantMultipleTrigger &&
!vaultHasActiveAutoTakeProfitTrigger &&
debt.isZero()) ||
(!vaultHasActiveAutoBuyTrigger &&
!vaultHasActiveConstantMultipleTrigger &&
!vaultHasActiveAutoTakeProfitTrigger &&
readOnlyAutoBSEnabled &&
constantMultipleReadOnlyEnabled &&
readOnlyAutoTakeProfitEnabled) ? (
<Container variant="vaultPageContainer" sx={{ zIndex: 0 }}>
<ZeroDebtOptimizationBanner
{...getZeroDebtOptimizationBannerProps({
readOnlyAutoBSEnabled,
isVaultDebtZero: debt.isZero(),
vaultHasNoActiveBuyTrigger: !vaultHasActiveAutoBuyTrigger,
constantMultipleReadOnlyEnabled,
readOnlyAutoTakeProfitEnabled,
vaultHasNoActiveConstantMultipleTriggers: !vaultHasActiveConstantMultipleTrigger,
vaultHasNoActiveAutoTakeProfitTrigger: !vaultHasActiveAutoTakeProfitTrigger,
})}
/>
</Container>
) : (
<DefaultVaultLayout
detailsViewControl={<OptimizationDetailsControl vaultHistory={vaultHistory} />}
detailsViewControl={<OptimizationDetailsControl />}
editForm={<OptimizationFormControl txHelpers={txHelpersData} />}
/>
)
Expand Down
7 changes: 0 additions & 7 deletions components/vault/VaultErrors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export function VaultErrors({
maxGenerateAmount = zero,
maxWithdrawAmount = zero,
ilkData: { debtFloor, token } = { debtFloor: zero, token: '' },
autoType,
infoBag,
}: VaultErrorsProps) {
const { t } = useTranslation()
Expand Down Expand Up @@ -146,10 +145,6 @@ export function VaultErrors({
return translate('after-coll-ratio-below-auto-sell-ratio')
case 'afterCollRatioAboveAutoBuyRatio':
return translate('after-coll-ratio-above-auto-buy-ratio')
case 'afterCollRatioBelowConstantMultipleSellRatio':
return translate('after-coll-ratio-below-constant-multiple-sell-ratio')
case 'afterCollRatioAboveConstantMultipleBuyRatio':
return translate('after-coll-ratio-above-constant-multiple-buy-ratio')
case 'vaultWillBeTakenUnderMinActiveColRatio':
return translate('vault-will-be-taken-under-min-active-col-ratio')
case 'stopLossOnNearLiquidationRatio':
Expand All @@ -168,8 +163,6 @@ export function VaultErrors({
return translate('stop-loss-trigger-higher-than-auto-buy-target')
case 'stopLossTriggerLtvLowerThanAutoBuy':
return translate('stop-loss-trigger-ltv-lower-than-auto-buy')
case 'cantSetupAutoBuyOrSellWhenConstantMultipleEnabled':
return translate('cant-setup-auto-buy-or-sell-when-constant-multiple-enabled', { autoType })
case 'minSellPriceWillPreventSellTrigger':
return translate('min-sell-price-will-prevent-sell-trigger')
case 'maxBuyPriceWillPreventBuyTrigger':
Expand Down
Loading

0 comments on commit 931aa0c

Please sign in to comment.