From dd698ba1411bfd8ad8df181ac76f9ae8b83f4458 Mon Sep 17 00:00:00 2001 From: leifu Date: Mon, 12 Jun 2023 15:51:14 +0300 Subject: [PATCH 1/5] fix: slider steps per max value & code clean (#2457) * Updated the slider step * Update the step based on the max value * Clean the code * Fixed the lint error * Try to make the step close to 1% of the value * Adjusted the step to 0.1% --- components/Slider/Slider.tsx | 2 +- sdk/constants/futures.ts | 2 +- sections/futures/MarketInfo/MarketHead.tsx | 2 -- sections/futures/Trade/ShowPercentage.tsx | 4 ---- 4 files changed, 2 insertions(+), 8 deletions(-) diff --git a/components/Slider/Slider.tsx b/components/Slider/Slider.tsx index cf445a15d5..86fd26f94d 100644 --- a/components/Slider/Slider.tsx +++ b/components/Slider/Slider.tsx @@ -45,7 +45,7 @@ export const getStep = (maxValue: number) => { if (maxValue < 10) return 0.01; if (maxValue < 100) return 1; if (maxValue < 10000) return 10; - return 100; + return Math.pow(10, Math.floor(Math.log10(maxValue)) - 3); }; const styledMarkLabel = css` diff --git a/sdk/constants/futures.ts b/sdk/constants/futures.ts index 233b7563f1..2cce97ba9b 100644 --- a/sdk/constants/futures.ts +++ b/sdk/constants/futures.ts @@ -19,7 +19,7 @@ export const KWENTA_TRACKING_CODE = formatBytes32String('KWENTA'); export const DEFAULT_NUMBER_OF_TRADES = 32; export const DEFAULT_PRICE_IMPACT_DELTA_PERCENT = { - MARKET: '4', + MARKET: '1', STOP: '4', LIMIT: '4', STOP_LOSS: '5', diff --git a/sections/futures/MarketInfo/MarketHead.tsx b/sections/futures/MarketInfo/MarketHead.tsx index 44f6e69fd2..034d6162e4 100644 --- a/sections/futures/MarketInfo/MarketHead.tsx +++ b/sections/futures/MarketInfo/MarketHead.tsx @@ -2,12 +2,10 @@ import Head from 'next/head'; import { FC } from 'react'; import { useTranslation } from 'react-i18next'; -import { DEFAULT_CRYPTO_DECIMALS } from 'constants/defaults'; import { getDisplayAsset } from 'sdk/utils/futures'; import { formatCurrency } from 'sdk/utils/number'; import { selectMarketAsset, selectSkewAdjustedPrice } from 'state/futures/selectors'; import { useAppSelector } from 'state/hooks'; -import { isDecimalFour } from 'utils/futures'; const MarketHead: FC = () => { const { t } = useTranslation(); diff --git a/sections/futures/Trade/ShowPercentage.tsx b/sections/futures/Trade/ShowPercentage.tsx index 127638e51f..a5de55b14b 100644 --- a/sections/futures/Trade/ShowPercentage.tsx +++ b/sections/futures/Trade/ShowPercentage.tsx @@ -21,10 +21,6 @@ const ShowPercentage: React.FC = ({ leverageWei, }) => { const calculatePercentage = useMemo(() => { - // eslint-disable-next-line no-console - console.log( - `targetPrice: ${targetPrice}, currentPrice: ${currentPrice}, leverageSide: ${leverageSide}` - ); if (!targetPrice || !currentPrice || !leverageSide) return ''; const priceWei = wei(targetPrice); const diff = From 7a9a15a0671d4457ebb2202a74a8cb7289708b95 Mon Sep 17 00:00:00 2001 From: leifu Date: Mon, 12 Jun 2023 21:14:10 +0300 Subject: [PATCH 2/5] fix: position table column width and data source (#2464) * Increase the width of the size column * Reduce the column width of the size and update the market margin source * Update the column width --- sections/futures/UserInfo/PositionsTable.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sections/futures/UserInfo/PositionsTable.tsx b/sections/futures/UserInfo/PositionsTable.tsx index a4b8cdfdee..dad0d8af8a 100644 --- a/sections/futures/UserInfo/PositionsTable.tsx +++ b/sections/futures/UserInfo/PositionsTable.tsx @@ -74,6 +74,7 @@ const PositionsTable: FC = () => { const markPrice = markPrices[market?.marketKey!] ?? ZERO_WEI; return { market: market!, + remainingMargin: position.remainingMargin, position: position.position!, avgEntryPrice: thisPositionHistory?.avgEntryPrice, stopLoss: position.stopLoss?.targetPrice, @@ -205,7 +206,7 @@ const PositionsTable: FC = () => { - + {accountType === 'cross_margin' && ( Date: Mon, 12 Jun 2023 23:44:44 +0530 Subject: [PATCH 3/5] feat: open account address in trade history (#2455) feat: open account address when trade history row is clicked --- sections/futures/TradingHistory/TradesHistoryTable.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sections/futures/TradingHistory/TradesHistoryTable.tsx b/sections/futures/TradingHistory/TradesHistoryTable.tsx index 6dfb4228ae..e4dcdb04dc 100644 --- a/sections/futures/TradingHistory/TradesHistoryTable.tsx +++ b/sections/futures/TradingHistory/TradesHistoryTable.tsx @@ -6,6 +6,7 @@ import styled, { css } from 'styled-components'; import Table, { TableHeader } from 'components/Table'; import { Body } from 'components/Text'; import { NO_VALUE } from 'constants/placeholder'; +import { blockExplorer } from 'containers/Connector/Connector'; import useGetFuturesTrades from 'queries/futures/useGetFuturesTrades'; import { formatNumber } from 'sdk/utils/number'; import { selectMarketKey } from 'state/futures/selectors'; @@ -44,6 +45,7 @@ const TradesHistoryTable: FC = ({ mobile }) => { time: Number(trade?.timestamp), id: trade?.txnHash, orderType: trade?.orderType, + account: trade?.account, }; }) : []; @@ -103,10 +105,9 @@ const TradesHistoryTable: FC = ({ mobile }) => { lastRef={lastElementRef} $mobile={mobile} onTableRowClick={(_row) => { - // TODO: Open tx to creator not executor - // row.original.id !== NO_VALUE - // ? window.open(`${blockExplorer.txLink(row.original.id)}`) - // : undefined + return _row.original.id !== NO_VALUE + ? window.open(`${blockExplorer.addressLink(_row.original.account)}`) + : undefined; }} highlightRowsOnHover columns={[ From a1f6c09363ea20a937b9b766ce7b5925ef40db12 Mon Sep 17 00:00:00 2001 From: Adam Clarke Date: Mon, 12 Jun 2023 21:04:17 +0200 Subject: [PATCH 4/5] fix: negative price impact (#2466) * Fix negative price impact * chore: est. fill price language --------- Co-authored-by: platschi --- sdk/utils/futures.ts | 4 ++-- sections/futures/TradeConfirmation/TradeConfirmationModal.tsx | 2 +- translations/en.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/utils/futures.ts b/sdk/utils/futures.ts index c2cf593a4e..8e19add4ec 100644 --- a/sdk/utils/futures.ts +++ b/sdk/utils/futures.ts @@ -345,7 +345,7 @@ export const formatPotentialTrade = ( const notionalValue = wei(size).mul(wei(basePrice)); const leverage = margin.gt(0) ? notionalValue.div(wei(margin)) : ZERO_WEI; - const priceImpact = wei(price).sub(basePrice).div(basePrice); + const priceImpact = wei(price).sub(basePrice).div(basePrice).abs(); const slippageDirection = nativeSizeDelta.gt(0) ? priceImpact.gt(0) ? -1 @@ -353,7 +353,6 @@ export const formatPotentialTrade = ( ? priceImpact.lt(0) : -1 : 1; - return { fee: wei(fee), liqPrice: wei(liqPrice), @@ -434,6 +433,7 @@ export const mapConditionalOrderFromContract = ( const asset = MarketAssetByKey[marketKey]; const sizeDelta = wei(orderDetails.sizeDelta); const size = sizeDelta.abs(); + return { id: orderDetails.id, subgraphId: `CM-${account}-${orderDetails.id}`, diff --git a/sections/futures/TradeConfirmation/TradeConfirmationModal.tsx b/sections/futures/TradeConfirmation/TradeConfirmationModal.tsx index 514f420a91..0d007965d8 100644 --- a/sections/futures/TradeConfirmation/TradeConfirmationModal.tsx +++ b/sections/futures/TradeConfirmation/TradeConfirmationModal.tsx @@ -137,7 +137,7 @@ export default function TradeConfirmationModal({ value: formatDollars(orderPrice, { suggestDecimals: true }), } : { - label: 'fill price', + label: 'Est. fill price', value: formatDollars(positionDetails?.price ?? ZERO_WEI, { suggestDecimals: true }), }, diff --git a/translations/en.json b/translations/en.json index 61b718bbdd..58a2ac35d4 100644 --- a/translations/en.json +++ b/translations/en.json @@ -951,7 +951,7 @@ "margin-change": "Margin", "liquidation": "Liquidation", "price-impact": "Price Impact", - "fill-price": "Fill Price", + "fill-price": "Est. Fill Price", "submit-size": "Submit size change", "submit-margin-withdraw": "Withdraw Margin", "submit-margin-deposit": "Deposit Margin", From f496c45b3b0daba920a90580e0f65fcb86ce3a61 Mon Sep 17 00:00:00 2001 From: platschi Date: Mon, 12 Jun 2023 16:07:33 -0300 Subject: [PATCH 5/5] chore: bump version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index bfbe07408b..7bfea9bb44 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "kwenta", - "version": "7.2.2", + "version": "7.2.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "kwenta", - "version": "7.2.2", + "version": "7.2.4", "hasInstallScript": true, "dependencies": { "@eth-optimism/contracts": "0.5.37", diff --git a/package.json b/package.json index 3e5f076485..aadbb70e55 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kwenta", - "version": "7.2.2", + "version": "7.2.4", "scripts": { "dev": "next", "build": "next build",