From 3b70c064ccd1eda0b5a16925179ef8092076140d Mon Sep 17 00:00:00 2001 From: leifu Date: Wed, 21 Dec 2022 13:13:45 +0200 Subject: [PATCH 1/3] Removed the duplicated headers on exchange desktop (#1790) * Fixed the duplicated header on exchange desktop * Fixed the lint --- pages/exchange.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/pages/exchange.tsx b/pages/exchange.tsx index 69919a3e1a..2ec153d252 100644 --- a/pages/exchange.tsx +++ b/pages/exchange.tsx @@ -7,7 +7,6 @@ import Connector from 'containers/Connector'; import ExchangeContent from 'sections/exchange/ExchangeContent'; import ExchangeHead from 'sections/exchange/ExchangeHead'; import AppLayout from 'sections/shared/Layout/AppLayout'; -import Header from 'sections/shared/Layout/AppLayout/Header'; import { resetCurrencies } from 'state/exchange/actions'; import { useAppDispatch, useAppSelector } from 'state/hooks'; import { FullScreenContainer, MobileScreenContainer } from 'styles/common'; @@ -34,7 +33,6 @@ const Exchange: ExchangeComponent = () => { -
From f73166e384af5ff8fe6ec926f609966f5a51f33f Mon Sep 17 00:00:00 2001 From: "metadiver.eth" <75746881+metadiver@users.noreply.github.com> Date: Thu, 22 Dec 2022 00:57:09 +1100 Subject: [PATCH 2/3] fix: add commit hash to staking ui (#1788) --- pages/dashboard/staking.tsx | 2 ++ sections/dashboard/Stake/StakingTabs.tsx | 1 + 2 files changed, 3 insertions(+) diff --git a/pages/dashboard/staking.tsx b/pages/dashboard/staking.tsx index 19b2c45b70..bfbf80fa24 100644 --- a/pages/dashboard/staking.tsx +++ b/pages/dashboard/staking.tsx @@ -5,6 +5,7 @@ import { useTranslation } from 'react-i18next'; import DashboardLayout from 'sections/dashboard/DashboardLayout'; import StakingPortfolio, { StakeTab } from 'sections/dashboard/Stake/StakingPortfolio'; import StakingTabs from 'sections/dashboard/Stake/StakingTabs'; +import GitHashID from 'sections/shared/Layout/AppLayout/GitHashID'; import { useAppDispatch, useAppSelector } from 'state/hooks'; import { fetchClaimableRewards, fetchEscrowData, fetchStakingData } from 'state/staking/actions'; @@ -39,6 +40,7 @@ const StakingPage: StakingComponent = () => { + ); }; diff --git a/sections/dashboard/Stake/StakingTabs.tsx b/sections/dashboard/Stake/StakingTabs.tsx index 66fb842f14..267ed04d5b 100644 --- a/sections/dashboard/Stake/StakingTabs.tsx +++ b/sections/dashboard/Stake/StakingTabs.tsx @@ -185,6 +185,7 @@ const StakingTabsHeader = styled.div` `; const StakingTabsContainer = styled.div` + margin-bottom: 50px; ${media.lessThan('md')` padding: 15px; `} From dab5592c4ab43f18911584634754cf6e158e563b Mon Sep 17 00:00:00 2001 From: Adam Clarke Date: Wed, 21 Dec 2022 14:22:53 +0000 Subject: [PATCH 3/3] deprecate next price orders (#1784) * Deprecate next price orders * Fix lint warnings * fix lint warning Co-authored-by: platschi --- constants/defaults.ts | 3 - constants/futures.ts | 2 +- constants/queryKeys.ts | 5 - queries/futures/subgraph.ts | 2 +- queries/futures/types.ts | 2 +- queries/futures/utils.ts | 21 +- sdk/services/futures.ts | 12 +- sdk/types/futures.ts | 9 +- sections/futures/FeeInfoBox/FeeInfoBox.tsx | 43 +-- .../futures/LeverageInput/LeverageInput.tsx | 15 - .../futures/MarketInfoBox/MarketInfoBox.tsx | 39 +-- sections/futures/Trade/ManagePosition.tsx | 18 +- sections/futures/Trade/NextPrice.tsx | 35 --- .../Trade/NextPriceConfirmationModal.tsx | 266 ------------------ .../TradeConfirmationModalIsolatedMargin.tsx | 2 - .../futures/Trade/TradeIsolatedMargin.tsx | 24 +- .../TradeCrossMargin/CrossMarginInfoBox.tsx | 3 +- sections/futures/UserInfo/OpenOrdersTable.tsx | 78 +---- state/futures/actions.ts | 11 +- state/futures/selectors.ts | 16 +- state/futures/types.ts | 3 +- translations/en.json | 1 - utils/costCalculations.ts | 8 +- utils/futures.ts | 4 - 24 files changed, 39 insertions(+), 583 deletions(-) delete mode 100644 sections/futures/Trade/NextPrice.tsx delete mode 100644 sections/futures/Trade/NextPriceConfirmationModal.tsx diff --git a/constants/defaults.ts b/constants/defaults.ts index 3dd508d4f9..e0dcf85380 100644 --- a/constants/defaults.ts +++ b/constants/defaults.ts @@ -41,9 +41,6 @@ export const MAX_TIMESTAMP: number = 8640000000000000; // for Fee History export const DEFAULT_NUMBER_OF_FUTURES_FEE: number = 9999; -// leverage adjustment -export const DEFAULT_NP_LEVERAGE_ADJUSTMENT: number = 0.9975; - // for mobile leaderboard export const DEFAULT_LEADERBOARD_ROWS = 20; diff --git a/constants/futures.ts b/constants/futures.ts index 14d5b0e532..b9a2f8e96f 100644 --- a/constants/futures.ts +++ b/constants/futures.ts @@ -2,7 +2,7 @@ import { wei } from '@synthetixio/wei'; import { FuturesOrderType } from 'queries/futures/types'; -export const ISOLATED_MARGIN_ORDER_TYPES: FuturesOrderType[] = ['market', 'next price']; +export const ISOLATED_MARGIN_ORDER_TYPES: FuturesOrderType[] = ['market']; export const CROSS_MARGIN_ORDER_TYPES: FuturesOrderType[] = ['market', 'limit', 'stop market']; export const ORDER_KEEPER_ETH_DEPOSIT = wei(0.01); export const DEFAULT_MAX_LEVERAGE = wei(10); diff --git a/constants/queryKeys.ts b/constants/queryKeys.ts index 8d2f932afd..f0f232b380 100644 --- a/constants/queryKeys.ts +++ b/constants/queryKeys.ts @@ -279,11 +279,6 @@ export const QUERY_KEYS = { networkId, market, ], - NextPriceDetails: ( - networkId: NetworkId, - walletAddress: string | null, - currencyKey: string | null - ) => ['futures', 'currentRoundId', networkId, walletAddress, currencyKey], OverviewStats: (networkId: NetworkId) => ['futures', 'overview-stats', networkId], CrossMarginSettings: (networkId: NetworkId, settingsAddress: string) => [ 'futures', diff --git a/queries/futures/subgraph.ts b/queries/futures/subgraph.ts index fcf4b4483f..db25e30ef5 100644 --- a/queries/futures/subgraph.ts +++ b/queries/futures/subgraph.ts @@ -4308,5 +4308,5 @@ export const getTotals = async function ( // additional types export type FuturesAccountType = 'isolated_margin' | 'cross_margin'; -export type FuturesOrderType = 'NextPrice' | 'Limit' | 'Market' | 'StopMarket'; +export type FuturesOrderType = 'Limit' | 'Market' | 'StopMarket'; export type FuturesOrderStatus = 'Pending' | 'Filled' | 'Cancelled' | 'Open'; diff --git a/queries/futures/types.ts b/queries/futures/types.ts index 463ab41801..1b3044e8ba 100644 --- a/queries/futures/types.ts +++ b/queries/futures/types.ts @@ -196,7 +196,7 @@ export type FuturesTradeInputs = { orderPrice?: Wei | undefined; }; -export type FuturesOrderType = 'market' | 'next price' | 'stop market' | 'limit'; +export type FuturesOrderType = 'market' | 'stop market' | 'limit'; export type SpotsFee = { timestamp: string; diff --git a/queries/futures/utils.ts b/queries/futures/utils.ts index 4df0364285..5aa3cbe674 100644 --- a/queries/futures/utils.ts +++ b/queries/futures/utils.ts @@ -8,7 +8,7 @@ import { chain } from 'wagmi'; import { ETH_UNIT } from 'constants/network'; import { MarketClosureReason } from 'hooks/useMarketClosed'; import { SynthsTrades, SynthsVolumes } from 'queries/synths/type'; -import { FuturesMarket, FuturesOrder, FuturesOrderTypeDisplay } from 'sdk/types/futures'; +import { FuturesOrder, FuturesOrderTypeDisplay } from 'sdk/types/futures'; import { formatCurrency, formatDollars, weiFromWei } from 'utils/formatters/number'; import { FuturesMarketAsset, @@ -49,22 +49,14 @@ export const getFuturesMarketContract = (asset: string | null, contracts: Contra }; const mapOrderType = (orderType: Partial): FuturesOrderTypeDisplay => { - return orderType === 'NextPrice' - ? 'Next Price' - : orderType === 'StopMarket' - ? 'Stop Market' - : orderType; + return orderType === 'StopMarket' ? 'Stop Market' : orderType; }; -export const mapFuturesOrders = ( - o: FuturesOrderResult, - marketInfo: FuturesMarket | undefined -): FuturesOrder => { +export const mapFuturesOrders = (o: FuturesOrderResult): FuturesOrder => { const asset: FuturesMarketAsset = parseBytes32String(o.asset) as FuturesMarketAsset; const size = weiFromWei(o.size); const targetPrice = weiFromWei(o.targetPrice ?? 0); const targetRoundId = new Wei(o.targetRoundId, 0); - const currentRoundId = wei(marketInfo?.currentRoundId ?? 0); const marginDelta = weiFromWei(o.marginDelta); return { ...o, @@ -82,11 +74,8 @@ export const mapFuturesOrders = ( }), targetPriceTxt: formatDollars(targetPrice), side: size.gt(0) ? PositionSide.LONG : PositionSide.SHORT, - isStale: o.orderType === 'NextPrice' && currentRoundId.gte(wei(o.targetRoundId).add(2)), - isExecutable: - o.orderType === 'NextPrice' && targetRoundId - ? currentRoundId.eq(targetRoundId) || currentRoundId.eq(targetRoundId.add(1)) - : false, + isStale: false, + isExecutable: false, }; }; diff --git a/sdk/services/futures.ts b/sdk/services/futures.ts index 4cd4f520b7..3ba500e030 100644 --- a/sdk/services/futures.ts +++ b/sdk/services/futures.ts @@ -157,8 +157,6 @@ export default class FuturesService { feeRates: { makerFee: wei(feeRates.makerFee), takerFee: wei(feeRates.takerFee), - makerFeeNextPrice: wei(feeRates.makerFeeNextPrice), - takerFeeNextPrice: wei(feeRates.takerFeeNextPrice), }, openInterest: { shortPct: wei(marketSize).eq(0) @@ -385,7 +383,7 @@ export default class FuturesService { }; } - public async getOpenOrders(account: string, markets: FuturesMarket[]) { + public async getOpenOrders(account: string) { const response = await request( this.futuresGqlEndpoint, gql` @@ -409,8 +407,7 @@ export default class FuturesService { const openOrders: FuturesOrder[] = response ? response.futuresOrders.map((o: any) => { - const marketInfo = markets.find((m) => m.asset === o.asset); - return mapFuturesOrders(o, marketInfo); + return mapFuturesOrders(o); }) : []; return openOrders; @@ -519,14 +516,11 @@ export default class FuturesService { public async modifyIsolatedMarginPosition( marketAddress: string, sizeDelta: Wei, - useNextPrice = false, estimationOnly: T ): TxReturn { const market = FuturesMarket__factory.connect(marketAddress, this.sdk.context.signer); const root = estimationOnly ? market.estimateGas : market; - return useNextPrice - ? (root.submitNextPriceOrderWithTracking(sizeDelta.toBN(), KWENTA_TRACKING_CODE) as any) - : (root.modifyPositionWithTracking(sizeDelta.toBN(), KWENTA_TRACKING_CODE) as any); + return root.modifyPositionWithTracking(sizeDelta.toBN(), KWENTA_TRACKING_CODE) as any; } } diff --git a/sdk/types/futures.ts b/sdk/types/futures.ts index 57d557e383..deac7b8a5b 100644 --- a/sdk/types/futures.ts +++ b/sdk/types/futures.ts @@ -27,8 +27,6 @@ export type FuturesMarket = { feeRates: { makerFee: T; takerFee: T; - makerFeeNextPrice: T; - takerFeeNextPrice: T; }; openInterest?: { shortPct: number; @@ -168,12 +166,7 @@ export type FuturesPosition = { }; // This type exists to rename enum types from the subgraph to display-friendly types -export type FuturesOrderTypeDisplay = - | 'Next Price' - | 'Limit' - | 'Stop Market' - | 'Market' - | 'Liquidation'; +export type FuturesOrderTypeDisplay = 'Limit' | 'Stop Market' | 'Market' | 'Liquidation'; export type FuturesOrder = { id: string; diff --git a/sections/futures/FeeInfoBox/FeeInfoBox.tsx b/sections/futures/FeeInfoBox/FeeInfoBox.tsx index d1471ad12b..1553248cb9 100644 --- a/sections/futures/FeeInfoBox/FeeInfoBox.tsx +++ b/sections/futures/FeeInfoBox/FeeInfoBox.tsx @@ -17,7 +17,7 @@ import { selectTradeSizeInputs, } from 'state/futures/selectors'; import { useAppSelector } from 'state/hooks'; -import { computeNPFee, computeMarketFee } from 'utils/costCalculations'; +import { computeMarketFee } from 'utils/costCalculations'; import { formatCurrency, formatDollars, formatPercent, zeroBN } from 'utils/formatters/number'; const FeeInfoBox: React.FC = () => { @@ -32,19 +32,6 @@ const FeeInfoBox: React.FC = () => { ); const marketInfo = useAppSelector(selectMarketInfo); - const { commitDeposit, nextPriceFee } = useMemo(() => computeNPFee(marketInfo, nativeSizeDelta), [ - marketInfo, - nativeSizeDelta, - ]); - - const totalDeposit = useMemo(() => { - return (commitDeposit ?? zeroBN).add(marketInfo?.keeperDeposit ?? zeroBN); - }, [commitDeposit, marketInfo?.keeperDeposit]); - - const nextPriceDiscount = useMemo(() => { - return (nextPriceFee ?? zeroBN).sub(commitDeposit ?? zeroBN); - }, [commitDeposit, nextPriceFee]); - const staticRate = useMemo(() => computeMarketFee(marketInfo, nativeSizeDelta), [ marketInfo, nativeSizeDelta, @@ -114,30 +101,6 @@ const FeeInfoBox: React.FC = () => { }, }; } - if (orderType === 'next price') { - return { - 'Keeper Deposit': { - value: !!marketInfo?.keeperDeposit ? formatDollars(marketInfo.keeperDeposit) : NO_VALUE, - }, - 'Commit Deposit': { - value: !!commitDeposit - ? formatDollars(commitDeposit, { minDecimals: commitDeposit.lt(0.01) ? 4 : 2 }) - : NO_VALUE, - }, - 'Total Deposit': { - value: formatDollars(totalDeposit), - spaceBeneath: true, - }, - 'Next Price Discount': { - value: !!nextPriceDiscount ? formatDollars(nextPriceDiscount) : NO_VALUE, - color: nextPriceDiscount.lt(0) ? 'green' : nextPriceDiscount.gt(0) ? 'red' : undefined, - }, - 'Estimated Fees': { - value: formatDollars(totalDeposit.add(nextPriceDiscount ?? zeroBN)), - keyNode: dynamicFeeRate?.gt(0) ? : null, - }, - }; - } return accountType === 'isolated_margin' ? { Fee: { @@ -154,13 +117,9 @@ const FeeInfoBox: React.FC = () => { isolatedMarginFee, crossMarginFees, orderFeeRate, - dynamicFeeRate, - commitDeposit, accountType, marketInfo?.keeperDeposit, - nextPriceDiscount, marketCostTooltip, - totalDeposit, ]); return ; diff --git a/sections/futures/LeverageInput/LeverageInput.tsx b/sections/futures/LeverageInput/LeverageInput.tsx index 1571771e26..326a0d27fa 100644 --- a/sections/futures/LeverageInput/LeverageInput.tsx +++ b/sections/futures/LeverageInput/LeverageInput.tsx @@ -14,8 +14,6 @@ import { selectMarketAssetRate, selectMarketInfo, selectMaxLeverage, - selectNextPriceDisclaimer, - selectOrderType, selectPosition, } from 'state/futures/selectors'; import { useAppDispatch, useAppSelector } from 'state/hooks'; @@ -29,8 +27,6 @@ const LeverageInput: FC = () => { const dispatch = useAppDispatch(); const [mode, setMode] = useState<'slider' | 'input'>('input'); const leverage = useAppSelector(selectIsolatedMarginLeverage); - const orderType = useAppSelector(selectOrderType); - const isDisclaimerDisplayed = useAppSelector(selectNextPriceDisclaimer); const position = useAppSelector(selectPosition); const marketInfo = useAppSelector(selectMarketInfo); const maxLeverage = useAppSelector(selectMaxLeverage); @@ -83,11 +79,6 @@ const LeverageInput: FC = () => { {modeButton} - {orderType === 'next price' && isDisclaimerDisplayed && ( - - {t('futures.market.trade.input.leverage.disclaimer')} - - )} {mode === 'slider' ? ( props.theme.colors.selectedTheme.gray}; - margin: 0 8px 12px; -`; - export const StyledInput = styled(CustomNumericInput)` font-family: ${(props) => props.theme.fonts.mono}; text-overflow: ellipsis; diff --git a/sections/futures/MarketInfoBox/MarketInfoBox.tsx b/sections/futures/MarketInfoBox/MarketInfoBox.tsx index 3ffba5630e..e211a61eb8 100644 --- a/sections/futures/MarketInfoBox/MarketInfoBox.tsx +++ b/sections/futures/MarketInfoBox/MarketInfoBox.tsx @@ -6,22 +6,17 @@ import InfoBox from 'components/InfoBox'; import PreviewArrow from 'components/PreviewArrow'; import { FuturesPotentialTradeDetails } from 'sdk/types/futures'; import { - selectLeverageSide, selectMarketInfo, selectMaxLeverage, - selectOrderType, selectPosition, selectTradePreview, selectTradeSizeInputs, } from 'state/futures/selectors'; import { useAppSelector } from 'state/hooks'; -import { computeNPFee } from 'utils/costCalculations'; import { formatDollars, formatPercent, zeroBN } from 'utils/formatters/number'; const MarketInfoBox: React.FC = () => { - const orderType = useAppSelector(selectOrderType); - const leverageSide = useAppSelector(selectLeverageSide); - const { nativeSize, nativeSizeDelta } = useAppSelector(selectTradeSizeInputs); + const { nativeSizeDelta } = useAppSelector(selectTradeSizeInputs); const potentialTrade = useAppSelector(selectTradePreview); const marketInfo = useAppSelector(selectMarketInfo); @@ -41,26 +36,6 @@ const MarketInfoBox: React.FC = () => { marketInfo?.minInitialMargin, ]); - const isNextPriceOrder = orderType === 'next price'; - - const positionSize = position?.position?.size ? wei(position?.position?.size) : zeroBN; - const orderDetails = useMemo(() => { - return { - newSize: nativeSize, - size: (positionSize ?? zeroBN).add(nativeSizeDelta).abs(), - }; - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [leverageSide, positionSize]); - - const { commitDeposit } = useMemo(() => computeNPFee(marketInfo, wei(orderDetails.newSize)), [ - marketInfo, - orderDetails, - ]); - - const totalDeposit = useMemo(() => { - return (commitDeposit ?? zeroBN).add(marketInfo?.keeperDeposit ?? zeroBN); - }, [commitDeposit, marketInfo?.keeperDeposit]); - const getPotentialAvailableMargin = useCallback( (trade: FuturesPotentialTradeDetails | null, marketMaxLeverage: Wei | undefined) => { let inaccessible; @@ -88,16 +63,8 @@ const MarketInfoBox: React.FC = () => { potentialTrade, marketInfo?.maxLeverage ); - return isNextPriceOrder - ? potentialAvailableMargin?.sub(totalDeposit) ?? zeroBN - : potentialAvailableMargin; - }, [ - potentialTrade, - marketInfo?.maxLeverage, - isNextPriceOrder, - totalDeposit, - getPotentialAvailableMargin, - ]); + return potentialAvailableMargin; + }, [potentialTrade, marketInfo?.maxLeverage, getPotentialAvailableMargin]); const previewTradeData = React.useMemo(() => { const size = nativeSizeDelta.abs(); diff --git a/sections/futures/Trade/ManagePosition.tsx b/sections/futures/Trade/ManagePosition.tsx index 0633edf582..47572542d8 100644 --- a/sections/futures/Trade/ManagePosition.tsx +++ b/sections/futures/Trade/ManagePosition.tsx @@ -7,10 +7,8 @@ import Error from 'components/Error'; import Loader from 'components/Loader'; import { useFuturesContext } from 'contexts/FuturesContext'; import { previewErrorI18n } from 'queries/futures/constants'; -import { PositionSide } from 'queries/futures/types'; import { setOpenModal } from 'state/app/reducer'; import { selectOpenModal } from 'state/app/selectors'; -import { changeLeverageSide, editTradeSizeInput } from 'state/futures/actions'; import { selectMarketInfo, selectIsMarketCapReached, @@ -38,7 +36,6 @@ import { orderPriceInvalidLabel } from 'utils/futures'; import ClosePositionModalCrossMargin from '../PositionCard/ClosePositionModalCrossMargin'; import ClosePositionModalIsolatedMargin from '../PositionCard/ClosePositionModalIsolatedMargin'; -import NextPriceConfirmationModal from './NextPriceConfirmationModal'; import TradeConfirmationModalCrossMargin from './TradeConfirmationModalCrossMargin'; import TradeConfirmationModalIsolatedMargin from './TradeConfirmationModalIsolatedMargin'; @@ -164,18 +161,7 @@ const ManagePosition: React.FC = () => { noOutline variant="danger" onClick={() => { - if (orderType === 'next price' && position?.position?.size) { - const newTradeSize = position.position.size; - const newLeverageSide = - position.position.side === PositionSide.LONG - ? PositionSide.SHORT - : PositionSide.LONG; - dispatch(changeLeverageSide(newLeverageSide)); - dispatch(editTradeSizeInput(newTradeSize.toString(), 'native')); - dispatch(setOpenModal('futures_modify_position_confirm')); - } else { - dispatch(setOpenModal('futures_close_position_confirm')); - } + dispatch(setOpenModal('futures_close_position_confirm')); }} disabled={!positionDetails || marketInfo?.isSuspended || isAdvancedOrder} > @@ -198,8 +184,6 @@ const ManagePosition: React.FC = () => { {isConfirmationModalOpen && (selectedAccountType === 'cross_margin' ? ( - ) : orderType === 'next price' ? ( - ) : ( ))} diff --git a/sections/futures/Trade/NextPrice.tsx b/sections/futures/Trade/NextPrice.tsx deleted file mode 100644 index 2a92641209..0000000000 --- a/sections/futures/Trade/NextPrice.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import React from 'react'; -import { useTranslation } from 'react-i18next'; -import styled from 'styled-components'; - -import { EXTERNAL_LINKS } from 'constants/links'; - -const NextPrice: React.FC = () => { - const { t } = useTranslation(); - - return ( - -

- {t('futures.market.trade.next-price.description')}{' '} - - {t('futures.market.trade.next-price.learn-more')} ↗ - -

-
- ); -}; - -const NextPriceContainer = styled.div` - margin-bottom: 16px; - - .next-price-description { - color: ${(props) => props.theme.colors.selectedTheme.gray}; - margin: 0 8px; - - a { - color: ${(props) => props.theme.colors.selectedTheme.button.text.primary}; - } - } -`; - -export default NextPrice; diff --git a/sections/futures/Trade/NextPriceConfirmationModal.tsx b/sections/futures/Trade/NextPriceConfirmationModal.tsx deleted file mode 100644 index 4ea7e9819b..0000000000 --- a/sections/futures/Trade/NextPriceConfirmationModal.tsx +++ /dev/null @@ -1,266 +0,0 @@ -import useSynthetixQueries from '@synthetixio/queries'; -import { wei } from '@synthetixio/wei'; -import { FC, useCallback, useEffect, useMemo } from 'react'; -import { useTranslation } from 'react-i18next'; -import styled from 'styled-components'; - -import BaseModal from 'components/BaseModal'; -import Button from 'components/Button'; -import { ButtonLoader } from 'components/Loader/Loader'; -import { DesktopOnlyView, MobileOrTabletView } from 'components/Media'; -import { NO_VALUE } from 'constants/placeholder'; -import Connector from 'containers/Connector'; -import useSelectedPriceCurrency from 'hooks/useSelectedPriceCurrency'; -import GasPriceSelect from 'sections/shared/components/GasPriceSelect'; -import { setOpenModal } from 'state/app/reducer'; -import { modifyIsolatedPosition, modifyIsolatedPositionEstimateGas } from 'state/futures/actions'; -import { - selectIsModifyingIsolatedPosition, - selectLeverageSide, - selectMarketAsset, - selectMarketInfo, - selectModifyIsolatedGasEstimate, - selectNextPriceDisclaimer, - selectPosition, - selectTradeSizeInputs, -} from 'state/futures/selectors'; -import { useAppDispatch, useAppSelector } from 'state/hooks'; -import { FlexDivCol, FlexDivCentered } from 'styles/common'; -import { computeNPFee } from 'utils/costCalculations'; -import { zeroBN, formatCurrency, formatDollars } from 'utils/formatters/number'; - -import BaseDrawer from '../MobileTrade/drawers/BaseDrawer'; -import { PositionSide } from '../types'; -import { MobileConfirmTradeButton } from './TradeConfirmationModal'; - -const NextPriceConfirmationModal: FC = () => { - const { t } = useTranslation(); - const { synthsMap } = Connector.useContainer(); - const isDisclaimerDisplayed = useAppSelector(selectNextPriceDisclaimer); - const { useEthGasPriceQuery } = useSynthetixQueries(); - const { selectedPriceCurrency } = useSelectedPriceCurrency(); - const ethGasPriceQuery = useEthGasPriceQuery(); - const dispatch = useAppDispatch(); - - const { nativeSize, nativeSizeDelta } = useAppSelector(selectTradeSizeInputs); - const leverageSide = useAppSelector(selectLeverageSide); - const position = useAppSelector(selectPosition); - const marketInfo = useAppSelector(selectMarketInfo); - const marketAsset = useAppSelector(selectMarketAsset); - const submitting = useAppSelector(selectIsModifyingIsolatedPosition); - const gasEstimate = useAppSelector(selectModifyIsolatedGasEstimate); - - const gasPrices = useMemo( - () => (ethGasPriceQuery.isSuccess ? ethGasPriceQuery?.data ?? undefined : undefined), - [ethGasPriceQuery.isSuccess, ethGasPriceQuery.data] - ); - - useEffect(() => { - dispatch( - modifyIsolatedPositionEstimateGas({ - sizeDelta: nativeSizeDelta, - useNextPrice: true, - }) - ); - }, [nativeSizeDelta, dispatch]); - - const transactionFee = useMemo(() => gasEstimate?.cost ?? zeroBN, [gasEstimate?.cost]); - - const positionSize = position?.position?.size ?? zeroBN; - - const orderDetails = useMemo(() => { - const newSize = leverageSide === PositionSide.LONG ? wei(nativeSize) : wei(nativeSize).neg(); - - return { newSize, size: (positionSize ?? zeroBN).add(newSize).abs() }; - }, [leverageSide, nativeSize, positionSize]); - - const { commitDeposit, nextPriceFee } = useMemo( - () => computeNPFee(marketInfo, wei(orderDetails.newSize)), - [marketInfo, orderDetails] - ); - - const totalDeposit = useMemo(() => { - return (commitDeposit ?? zeroBN).add(marketInfo?.keeperDeposit ?? zeroBN); - }, [commitDeposit, marketInfo?.keeperDeposit]); - - const nextPriceDiscount = useMemo(() => { - return (nextPriceFee ?? zeroBN).sub(commitDeposit ?? zeroBN); - }, [commitDeposit, nextPriceFee]); - - const dataRows = useMemo( - () => [ - { - label: t('futures.market.user.position.modal.order-type'), - value: t('futures.market.user.position.modal.next-price-order'), - }, - { - label: t('futures.market.user.position.modal.side'), - value: (leverageSide ?? PositionSide.LONG).toUpperCase(), - }, - { - label: t('futures.market.user.position.modal.size'), - value: formatCurrency(marketAsset || '', orderDetails.newSize.abs() ?? zeroBN, { - sign: marketAsset ? synthsMap[marketAsset]?.sign : '', - }), - }, - { - label: t('futures.market.user.position.modal.deposit'), - value: formatDollars(totalDeposit), - }, - { - label: t('futures.market.user.position.modal.np-discount'), - value: !!nextPriceDiscount ? formatDollars(nextPriceDiscount) : NO_VALUE, - }, - { - label: t('futures.market.user.position.modal.fee-total'), - value: formatCurrency( - selectedPriceCurrency.name, - totalDeposit.add(nextPriceDiscount ?? zeroBN), - { - minDecimals: 2, - sign: selectedPriceCurrency.sign, - } - ), - }, - ], - [ - t, - orderDetails, - marketAsset, - synthsMap, - leverageSide, - nextPriceDiscount, - totalDeposit, - selectedPriceCurrency.name, - selectedPriceCurrency.sign, - ] - ); - - const onDismiss = useCallback(() => { - dispatch(setOpenModal(null)); - }, [dispatch]); - - const handleConfirmOrder = async () => { - dispatch( - modifyIsolatedPosition({ - sizeDelta: nativeSizeDelta, - useNextPrice: true, - }) - ); - }; - - return ( - <> - - - {dataRows.map(({ label, value }, i) => ( - - - {value} - - ))} - - - - {isDisclaimerDisplayed && ( - - {t('futures.market.trade.confirmation.modal.max-leverage-disclaimer')} - - )} - - {submitting ? ( - - ) : ( - t('futures.market.trade.confirmation.modal.confirm-order') - )} - - - - - - {submitting ? ( - - ) : ( - t('futures.market.trade.confirmation.modal.confirm-order') - )} - - } - /> - - - ); -}; - -const StyledBaseModal = styled(BaseModal)` - [data-reach-dialog-content] { - width: 400px; - } - .card-body { - padding: 28px; - } -`; - -const Row = styled(FlexDivCentered)` - justify-content: space-between; -`; - -const Label = styled.div` - color: ${(props) => props.theme.colors.selectedTheme.gray}; - font-size: 12px; - text-transform: capitalize; - margin-top: 6px; -`; - -const Value = styled.div` - font-family: ${(props) => props.theme.fonts.mono}; - color: ${(props) => props.theme.colors.selectedTheme.button.text.primary}; - font-size: 12px; - margin-top: 6px; -`; - -const NetworkFees = styled(FlexDivCol)` - margin-top: 12px; -`; - -const StyledGasPriceSelect = styled(GasPriceSelect)` - padding: 5px 0; - display: flex; - justify-content: space-between; - width: auto; - border-bottom: 1px solid ${(props) => props.theme.colors.selectedTheme.border}; - color: ${(props) => props.theme.colors.selectedTheme.gray}; - font-size: 12px; - font-family: ${(props) => props.theme.fonts.regular}; - text-transform: capitalize; - margin-bottom: 8px; -`; - -const ConfirmTradeButton = styled(Button)` - margin-top: 24px; - text-overflow: ellipsis; - overflow: hidden; - white-space: nowrap; - height: 55px; -`; - -const Disclaimer = styled.div` - font-size: 12px; - color: ${(props) => props.theme.colors.selectedTheme.gray}; - margin-top: 12px; - margin-bottom: 12px; -`; - -export default NextPriceConfirmationModal; diff --git a/sections/futures/Trade/TradeConfirmationModalIsolatedMargin.tsx b/sections/futures/Trade/TradeConfirmationModalIsolatedMargin.tsx index a72503d6c2..63ae1b5b41 100644 --- a/sections/futures/Trade/TradeConfirmationModalIsolatedMargin.tsx +++ b/sections/futures/Trade/TradeConfirmationModalIsolatedMargin.tsx @@ -27,7 +27,6 @@ export default function TradeConfirmationModalIsolatedMargin() { dispatch( modifyIsolatedPositionEstimateGas({ sizeDelta: nativeSizeDelta, - useNextPrice: false, }) ); }, [nativeSizeDelta, dispatch]); @@ -40,7 +39,6 @@ export default function TradeConfirmationModalIsolatedMargin() { dispatch( modifyIsolatedPosition({ sizeDelta: nativeSizeDelta, - useNextPrice: false, }) ); }; diff --git a/sections/futures/Trade/TradeIsolatedMargin.tsx b/sections/futures/Trade/TradeIsolatedMargin.tsx index f23abe0a7e..69c31350e8 100644 --- a/sections/futures/Trade/TradeIsolatedMargin.tsx +++ b/sections/futures/Trade/TradeIsolatedMargin.tsx @@ -1,12 +1,7 @@ -import styled from 'styled-components'; - -import SegmentedControl from 'components/SegmentedControl'; -import { ISOLATED_MARGIN_ORDER_TYPES } from 'constants/futures'; import { setOpenModal } from 'state/app/reducer'; import { selectOpenModal } from 'state/app/selectors'; import { changeLeverageSide } from 'state/futures/actions'; -import { setOrderType } from 'state/futures/reducer'; -import { selectLeverageSide, selectOrderType, selectPosition } from 'state/futures/selectors'; +import { selectLeverageSide, selectPosition } from 'state/futures/selectors'; import { useAppDispatch, useAppSelector } from 'state/hooks'; import { zeroBN } from 'utils/formatters/number'; @@ -16,7 +11,6 @@ import MarketInfoBox from '../MarketInfoBox'; import OrderSizing from '../OrderSizing'; import PositionButtons from '../PositionButtons'; import ManagePosition from './ManagePosition'; -import NextPrice from './NextPrice'; import TradePanelHeader from './TradePanelHeader'; import TransferIsolatedMarginModal from './TransferIsolatedMarginModal'; @@ -31,7 +25,6 @@ const TradeIsolatedMargin = ({ isMobile }: Props) => { const position = useAppSelector(selectPosition); const openModal = useAppSelector(selectOpenModal); - const orderType = useAppSelector(selectOrderType); const totalMargin = position?.remainingMargin ?? zeroBN; return ( @@ -44,17 +37,6 @@ const TradeIsolatedMargin = ({ isMobile }: Props) => { {!isMobile && } - { - dispatch(setOrderType(oType === 0 ? 'market' : 'next price')); - }} - /> - - {orderType === 'next price' && } - { @@ -80,7 +62,3 @@ const TradeIsolatedMargin = ({ isMobile }: Props) => { }; export default TradeIsolatedMargin; - -const StyledSegmentedControl = styled(SegmentedControl)` - margin-bottom: 16px; -`; diff --git a/sections/futures/TradeCrossMargin/CrossMarginInfoBox.tsx b/sections/futures/TradeCrossMargin/CrossMarginInfoBox.tsx index 1c16051741..a1b687903f 100644 --- a/sections/futures/TradeCrossMargin/CrossMarginInfoBox.tsx +++ b/sections/futures/TradeCrossMargin/CrossMarginInfoBox.tsx @@ -111,8 +111,7 @@ function MarginInfoBox({ editingLeverage }: Props) { return { showPreview: - ((orderType === 'market' || orderType === 'next price') && - (!size.eq(0) || !marginDelta.eq(0))) || + (orderType === 'market' && (!size.eq(0) || !marginDelta.eq(0))) || ((orderType === 'limit' || orderType === 'stop market') && !!orderPrice && !size.eq(0)), totalMargin: potentialTrade?.margin.sub(crossMarginFee) || zeroBN, freeAccountMargin: crossMarginFreeMargin.sub(marginDelta), diff --git a/sections/futures/UserInfo/OpenOrdersTable.tsx b/sections/futures/UserInfo/OpenOrdersTable.tsx index 01ac3cac4d..25af9ae0eb 100644 --- a/sections/futures/UserInfo/OpenOrdersTable.tsx +++ b/sections/futures/UserInfo/OpenOrdersTable.tsx @@ -1,8 +1,6 @@ -import useSynthetixQueries from '@synthetixio/queries'; -import { useEffect, useState, useCallback, useMemo } from 'react'; +import { useState, useCallback, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { CellProps } from 'react-table'; -import { useRecoilValue } from 'recoil'; import styled, { css } from 'styled-components'; import Badge from 'components/Badge'; @@ -17,61 +15,27 @@ import useIsL2 from 'hooks/useIsL2'; import useNetworkSwitcher from 'hooks/useNetworkSwitcher'; import { PositionSide } from 'queries/futures/types'; import { FuturesOrder } from 'sdk/types/futures'; -import { selectFuturesAccount, selectMarketAsset, selectOpenOrders } from 'state/futures/selectors'; +import { selectMarketAsset, selectOpenOrders } from 'state/futures/selectors'; import { useAppSelector } from 'state/hooks'; -import { gasSpeedState } from 'store/wallet'; import { formatDollars } from 'utils/formatters/number'; -import { getDisplayAsset } from 'utils/futures'; import logError from 'utils/logError'; import OrderDrawer from '../MobileTrade/drawers/OrderDrawer'; const OpenOrdersTable: React.FC = () => { const { t } = useTranslation(); - const { useSynthetixTxn, useEthGasPriceQuery } = useSynthetixQueries(); const { crossMarginAccountContract } = useCrossMarginContracts(); const { handleRefetch } = useRefetchContext(); - const ethGasPriceQuery = useEthGasPriceQuery(); const { switchToL2 } = useNetworkSwitcher(); const marketAsset = useAppSelector(selectMarketAsset); const isL2 = useIsL2(); - const gasSpeed = useRecoilValue(gasSpeedState); const openOrders = useAppSelector(selectOpenOrders); - const selectedFuturesAddress = useAppSelector(selectFuturesAccount); const [cancelling, setCancelling] = useState(null); const [selectedOrder, setSelectedOrder] = useState(); - const gasPrice = ethGasPriceQuery.data?.[gasSpeed]; - - const synthetixTxCb = { - enabled: !!selectedFuturesAddress, - onError: () => { - setCancelling(null); - }, - onSettled: () => { - setCancelling(null); - }, - }; - - const cancelNextPriceOrder = useSynthetixTxn( - `FuturesMarket${getDisplayAsset(marketAsset)}`, - `cancelNextPriceOrder`, - [selectedFuturesAddress], - gasPrice, - synthetixTxCb - ); - - const executeNextPriceOrder = useSynthetixTxn( - `FuturesMarket${getDisplayAsset(marketAsset)}`, - `executeNextPriceOrder`, - [selectedFuturesAddress], - gasPrice, - synthetixTxCb - ); - const handleTx = useCallback( (txHash: string) => { monitorTransaction({ @@ -88,32 +52,19 @@ const OpenOrdersTable: React.FC = () => { async (order: FuturesOrder | undefined) => { if (!order) return; setCancelling(order.id); - if (order.orderType === 'Limit' || order.orderType === 'Stop Market') { - try { - const id = order.id.split('-')[2]; - const tx = await crossMarginAccountContract?.cancelOrder(id); - if (tx?.hash) handleTx(tx.hash); - setCancelling(null); - } catch (err) { - setCancelling(null); - logError(err); - } - } else { - cancelNextPriceOrder.mutate(); + try { + const id = order.id.split('-')[2]; + const tx = await crossMarginAccountContract?.cancelOrder(id); + if (tx?.hash) handleTx(tx.hash); + setCancelling(null); + } catch (err) { + setCancelling(null); + logError(err); } }, - [crossMarginAccountContract, cancelNextPriceOrder, handleTx] + [crossMarginAccountContract, handleTx] ); - useEffect(() => { - if (cancelNextPriceOrder.hash) { - handleTx(cancelNextPriceOrder.hash); - } else if (executeNextPriceOrder.hash) { - handleTx(executeNextPriceOrder.hash); - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [cancelNextPriceOrder.hash, executeNextPriceOrder.hash]); - const rowsData = useMemo(() => { const ordersWithCancel = openOrders .map((o) => ({ ...o, cancel: () => onCancel(o) })) @@ -250,11 +201,6 @@ const OpenOrdersTable: React.FC = () => { {t('futures.market.user.open-orders.actions.cancel')} - {cellProps.row.original.isExecutable && ( - executeNextPriceOrder.mutate()}> - {t('futures.market.user.open-orders.actions.execute')} - - )} ); }, @@ -328,7 +274,7 @@ const OpenOrdersTable: React.FC = () => { order={selectedOrder} closeDrawer={() => setSelectedOrder(undefined)} onCancel={onCancel} - onExecute={executeNextPriceOrder.mutate} + onExecute={() => {}} /> diff --git a/state/futures/actions.ts b/state/futures/actions.ts index 0b5ffdbdae..46da3fbd2d 100644 --- a/state/futures/actions.ts +++ b/state/futures/actions.ts @@ -40,7 +40,6 @@ import { serializeFuturesOrders, serializeFuturesVolumes, serializeMarkets, - unserializeMarkets, } from 'utils/futures'; import logError from 'utils/logError'; import { getTransactionPrice } from 'utils/network'; @@ -268,7 +267,7 @@ export const fetchOpenOrders = createAsyncThunk< if (!account) { throw new Error('No account to fetch orders'); } - const orders = await sdk.futures.getOpenOrders(account, unserializeMarkets(futures.markets)); + const orders = await sdk.futures.getOpenOrders(account); return { orders: serializeFuturesOrders(orders), account: account, @@ -698,7 +697,7 @@ export const modifyIsolatedPosition = createAsyncThunk< ThunkConfig >( 'futures/modifyIsolatedPosition', - async ({ sizeDelta, useNextPrice }, { getState, dispatch, extra: { sdk } }) => { + async ({ sizeDelta }, { getState, dispatch, extra: { sdk } }) => { const marketInfo = selectMarketInfo(getState()); if (!marketInfo) throw new Error('Market info not found'); try { @@ -712,7 +711,6 @@ export const modifyIsolatedPosition = createAsyncThunk< const tx = await sdk.futures.modifyIsolatedMarginPosition( marketInfo.market, sizeDelta, - useNextPrice, false ); dispatch(updateTransactionHash(tx.hash)); @@ -734,12 +732,11 @@ export const modifyIsolatedPositionEstimateGas = createAsyncThunk< ThunkConfig >( 'futures/modifyIsolatedPositionEstimateGas', - async ({ sizeDelta, useNextPrice }, { getState, dispatch, extra: { sdk } }) => { + async ({ sizeDelta }, { getState, dispatch, extra: { sdk } }) => { const marketInfo = selectMarketInfo(getState()); if (!marketInfo) throw new Error('Market info not found'); estimateGasInteralAction( - () => - sdk.futures.modifyIsolatedMarginPosition(marketInfo.market, sizeDelta, useNextPrice, true), + () => sdk.futures.modifyIsolatedMarginPosition(marketInfo.market, sizeDelta, true), 'modify_isolated', { getState, dispatch } ); diff --git a/state/futures/selectors.ts b/state/futures/selectors.ts index bd2a12a0b5..a77c229b31 100644 --- a/state/futures/selectors.ts +++ b/state/futures/selectors.ts @@ -1,7 +1,7 @@ import { createSelector } from '@reduxjs/toolkit'; import { wei } from '@synthetixio/wei'; -import { DEFAULT_LEVERAGE, DEFAULT_NP_LEVERAGE_ADJUSTMENT } from 'constants/defaults'; +import { DEFAULT_LEVERAGE } from 'constants/defaults'; import { DEFAULT_MAX_LEVERAGE } from 'constants/futures'; import { TransactionStatus } from 'sdk/types/common'; import { FuturesPosition } from 'sdk/types/futures'; @@ -288,10 +288,7 @@ export const selectMaxLeverage = createSelector( const positionLeverage = position?.position?.leverage ?? wei(0); const positionSide = position?.position?.side; const marketMaxLeverage = market?.maxLeverage ?? DEFAULT_MAX_LEVERAGE; - const adjustedMaxLeverage = - orderType === 'next price' - ? marketMaxLeverage.mul(DEFAULT_NP_LEVERAGE_ADJUSTMENT) - : marketMaxLeverage; + const adjustedMaxLeverage = marketMaxLeverage; if (!positionLeverage || positionLeverage.eq(wei(0))) return adjustedMaxLeverage; if (futuresType === 'cross_margin') return adjustedMaxLeverage; @@ -396,14 +393,6 @@ export const selectIsolatedMarginLeverage = createSelector( } ); -export const selectNextPriceDisclaimer = createSelector( - selectMaxLeverage, - selectCrossMarginTradeInputs, - (maxLeverage, { leverage }) => { - return wei(leverage || 0).gte(maxLeverage.sub(wei(1))) && wei(leverage || 0).lte(maxLeverage); - } -); - export const selectPlaceOrderTranslationKey = createSelector( selectPosition, selectFuturesType, @@ -419,7 +408,6 @@ export const selectPlaceOrderTranslationKey = createSelector( remainingMargin = positionMargin.add(freeMargin); } - if (orderType === 'next price') return 'futures.market.trade.button.place-next-price-order'; if (orderType === 'limit') return 'futures.market.trade.button.place-limit-order'; if (orderType === 'stop market') return 'futures.market.trade.button.place-stop-order'; if (!!position?.position) return 'futures.market.trade.button.modify-position'; diff --git a/state/futures/types.ts b/state/futures/types.ts index 0ab0d39ecf..f3d355a35e 100644 --- a/state/futures/types.ts +++ b/state/futures/types.ts @@ -13,7 +13,7 @@ import { PositionSide } from 'sections/futures/types'; import { QueryStatus } from 'state/types'; import { FuturesMarketAsset, FuturesMarketKey } from 'utils/futures'; -export type IsolatedMarginOrderType = 'next price' | 'market'; +export type IsolatedMarginOrderType = 'market'; export type CrossMarginOrderType = 'market' | 'stop market' | 'limit'; export type TradeSizeInputs = { @@ -178,7 +178,6 @@ export type IsolatedMarginState = { export type ModifyIsolatedPositionInputs = { sizeDelta: Wei; - useNextPrice: boolean; }; export const futuresPositionKeys = new Set([ diff --git a/translations/en.json b/translations/en.json index 5e3a437b68..b787545665 100644 --- a/translations/en.json +++ b/translations/en.json @@ -745,7 +745,6 @@ "modify-position": "modify", "deposit-margin-minimum": "Deposit Margin", "oi-caps-reached": "Open Interest Cap Reached", - "place-next-price-order": "Place Next Price Order", "place-limit-order": "Place Limit Order", "place-stop-order": "Place Stop Market Order", "connect-wallet": "Connect Wallet" diff --git a/utils/costCalculations.ts b/utils/costCalculations.ts index c0a454668a..25a9d7e40c 100644 --- a/utils/costCalculations.ts +++ b/utils/costCalculations.ts @@ -10,29 +10,23 @@ export const computeNPFee = (market: FuturesMarket | undefined, sizeDelta: Wei) !market?.price || !market?.feeRates.takerFee || !market?.feeRates.makerFee || - !market?.feeRates.takerFeeNextPrice || - !market?.feeRates.makerFeeNextPrice || !sizeDelta ) { - return { commitDeposit: undefined, nextPriceFee: undefined }; + return { commitDeposit: undefined }; } const notionalDiff = sizeDelta.mul(market.price); let staticRate: Wei; - let staticRateNP: Wei; if (sameSide(notionalDiff, market.marketSkew)) { staticRate = market.feeRates.takerFee; - staticRateNP = market.feeRates.takerFeeNextPrice; } else { staticRate = market.feeRates.makerFee; - staticRateNP = market.feeRates.makerFeeNextPrice; } return { commitDeposit: notionalDiff.mul(staticRate).abs(), - nextPriceFee: notionalDiff.mul(staticRateNP).abs(), }; }; diff --git a/utils/futures.ts b/utils/futures.ts index d582735aea..293dc71360 100644 --- a/utils/futures.ts +++ b/utils/futures.ts @@ -375,8 +375,6 @@ export const serializeMarkets = (markets: FuturesMarket[]): FuturesMarket[]): FuturesMar feeRates: { makerFee: wei(m.feeRates.makerFee), takerFee: wei(m.feeRates.takerFee), - makerFeeNextPrice: wei(m.feeRates.makerFeeNextPrice), - takerFeeNextPrice: wei(m.feeRates.takerFeeNextPrice), }, openInterest: m.openInterest ? {