Skip to content

Commit

Permalink
v6.1.2
Browse files Browse the repository at this point in the history
v6.1.2
  • Loading branch information
platschi authored Feb 14, 2023
2 parents 83dad14 + 048927a commit 4654486
Show file tree
Hide file tree
Showing 24 changed files with 152 additions and 175 deletions.
22 changes: 20 additions & 2 deletions components/TVChart/DataFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ const splitBaseQuote = (symbolName: string) => {
return { base, quote };
};

const getPriceScale = (asset: string | null) => {
switch (asset) {
case 'BTC':
case 'BNB':
case 'ETH':
case 'XAU':
return 100;
case 'DOGE':
case 'FTM':
case 'AUD':
return 10000;
default:
return 1000;
}
};

const fetchCombinedCandles = async (
base: string,
quote: string,
Expand Down Expand Up @@ -194,16 +210,18 @@ const DataFeedFactory = (
resolveSymbol: (symbolName: string, onSymbolResolvedCallback: (val: any) => any) => {
const { base, quote } = splitBaseQuote(symbolName);

const asset = getDisplayAsset(base);

var symbol_stub = {
name: symbolName,
description: `${getDisplayAsset(base)} / ${getDisplayAsset(quote)} (Oracle)`,
description: `${asset} / ${getDisplayAsset(quote)} (Oracle)`,
type: 'crypto',
session: '24x7',
timezone: 'Etc/UTC',
ticker: symbolName,
exchange: '',
minmov: 1,
pricescale: 10000,
pricescale: getPriceScale(asset),
has_intraday: true,
intraday_multipliers: supportedResolutions,
supported_resolution: supportedResolutions,
Expand Down
3 changes: 3 additions & 0 deletions sdk/constants/period.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export enum Period {
ONE_DAY = 'ONE_DAY',
ONE_WEEK = 'ONE_WEEK',
ONE_MONTH = 'ONE_MONTH',
ONE_YEAR = 'ONE_YEAR',
}

export const PERIOD_IN_HOURS: Record<Period, number> = {
Expand All @@ -12,6 +13,7 @@ export const PERIOD_IN_HOURS: Record<Period, number> = {
ONE_DAY: 24,
ONE_MONTH: 672,
ONE_WEEK: 168,
ONE_YEAR: 8766,
};

export const PERIOD_IN_SECONDS: Record<Period, number> = {
Expand All @@ -20,6 +22,7 @@ export const PERIOD_IN_SECONDS: Record<Period, number> = {
ONE_DAY: 24 * 60 * 60,
ONE_MONTH: 672 * 60 * 60,
ONE_WEEK: 168 * 60 * 60,
ONE_YEAR: 8766 * 60 * 60,
};

export const SECONDS_PER_DAY = 24 * 60 * 60;
49 changes: 23 additions & 26 deletions sdk/services/futures.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NetworkId } from '@synthetixio/contracts-interface';
import Wei, { wei } from '@synthetixio/wei';
import { Contract as EthCallContract } from 'ethcall';
import { BigNumber, ContractTransaction, ethers } from 'ethers';
import { BigNumber, ethers } from 'ethers';
import { formatBytes32String, parseBytes32String } from 'ethers/lib/utils';
import request, { gql } from 'graphql-request';
import { orderBy } from 'lodash';
Expand Down Expand Up @@ -631,28 +631,29 @@ export default class FuturesService {
sizeDelta: Wei,
priceImpactDelta: Wei,
options?: ModifyPositionOptions<T>
): TxReturn<T> {
) {
const market = PerpsV2Market__factory.connect(marketAddress, this.sdk.context.signer);
const root = options?.estimationOnly ? market.estimateGas : market;

return options?.delayed && options?.offchain
? (root.submitOffchainDelayedOrderWithTracking(
sizeDelta.toBN(),
priceImpactDelta.toBN(),
KWENTA_TRACKING_CODE
) as any)
: options?.delayed
? (root.submitDelayedOrderWithTracking(
sizeDelta.toBN(),
priceImpactDelta.toBN(),
wei(DEFAULT_DESIRED_TIMEDELTA).toBN(),
KWENTA_TRACKING_CODE
) as any)
: (root.modifyPositionWithTracking(
sizeDelta.toBN(),
priceImpactDelta.toBN(),
KWENTA_TRACKING_CODE
) as any);

if (options?.delayed && options.offchain) {
return this.sdk.transactions.createContractTxn(
market,
'submitOffchainDelayedOrderWithTracking',
[sizeDelta.toBN(), priceImpactDelta.toBN(), KWENTA_TRACKING_CODE]
);
} else if (options?.delayed) {
return this.sdk.transactions.createContractTxn(market, 'submitDelayedOrderWithTracking', [
sizeDelta.toBN(),
priceImpactDelta.toBN(),
wei(DEFAULT_DESIRED_TIMEDELTA).toBN(),
KWENTA_TRACKING_CODE,
]);
} else {
return this.sdk.transactions.createContractTxn(market, 'modifyPositionWithTracking', [
sizeDelta.toBN(),
priceImpactDelta.toBN(),
KWENTA_TRACKING_CODE,
]);
}
}

public async cancelDelayedOrder(marketAddress: string, account: string, isOffchain: boolean) {
Expand Down Expand Up @@ -806,7 +807,3 @@ export default class FuturesService {
]);
}
}

type TxReturn<T extends boolean = false> = Promise<
T extends true ? BigNumber : ContractTransaction
>;
4 changes: 3 additions & 1 deletion sdk/utils/futures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,9 @@ export const calculateCrossMarginFee = (
};

export const getPythNetworkUrl = (networkId: NetworkId) => {
return networkId === 420 ? 'https://xc-testnet.pyth.network' : 'https://xc-mainnet.pyth.network';
return networkId === 420
? 'https://api.synthetix.io/pyth-testnet/api'
: 'https://api.synthetix.io/pyth-mainnet/api';
};

export const normalizePythId = (id: string) => (id.startsWith('0x') ? id : '0x' + id);
Expand Down
16 changes: 6 additions & 10 deletions sections/dashboard/FuturesHistoryTable/FuturesHistoryTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Currency from 'components/Currency';
import { DesktopOnlyView, MobileOrTabletView } from 'components/Media';
import FuturesIcon from 'components/Nav/FuturesIcon';
import Table, { TableNoResults } from 'components/Table';
import { DEFAULT_CRYPTO_DECIMALS } from 'constants/defaults';
import { ETH_UNIT } from 'constants/network';
import { NO_VALUE } from 'constants/placeholder';
import ROUTES from 'constants/routes';
Expand All @@ -34,7 +33,7 @@ import { FetchStatus } from 'state/types';
import { selectNetwork } from 'state/wallet/selectors';
import { formatShortDateWithoutYear } from 'utils/formatters/date';
import { formatCryptoCurrency, formatDollars } from 'utils/formatters/number';
import { getDisplayAsset, getMarketName, isDecimalFour, MarketKeyByAsset } from 'utils/futures';
import { getDisplayAsset, getMarketName, MarketKeyByAsset } from 'utils/futures';

import TimeDisplay from '../../futures/Trades/TimeDisplay';

Expand Down Expand Up @@ -160,7 +159,7 @@ const FuturesHistoryTable: FC = () => {
Cell: (cellProps: CellProps<FuturesTrade>) => {
return conditionalRender(
cellProps.row.original.size,
<>{formatCryptoCurrency(cellProps.value)}</>
<>{formatCryptoCurrency(cellProps.value, { suggestDecimals: true })}</>
);
},
width: 100,
Expand All @@ -169,12 +168,9 @@ const FuturesHistoryTable: FC = () => {
Header: <div>{t('dashboard.history.futures-history-table.price')}</div>,
accessor: 'price',
Cell: (cellProps: CellProps<FuturesTrade>) => {
const formatOptions = isDecimalFour(cellProps.row.original.asset)
? { sign: '$', minDecimals: DEFAULT_CRYPTO_DECIMALS }
: { sign: '$' };
return conditionalRender(
cellProps.row.original.price,
<>{formatDollars(cellProps.value, formatOptions)}</>
<>{formatDollars(cellProps.value, { suggestDecimals: true })}</>
);
},
width: 120,
Expand All @@ -189,7 +185,7 @@ const FuturesHistoryTable: FC = () => {
<PNL normal>--</PNL>
) : (
<PNL negative={cellProps.value.lt(wei(0))}>
{formatDollars(cellProps.value)}
{formatDollars(cellProps.value, { suggestDecimals: true })}
</PNL>
)
);
Expand Down Expand Up @@ -309,7 +305,7 @@ const FuturesHistoryTable: FC = () => {
return conditionalRender(
cellProps.row.original.price,
<div>
<div>{formatCryptoCurrency(cellProps.value)}</div>
<div>{formatCryptoCurrency(cellProps.value, { suggestDecimals: true })}</div>
<div>{formatDollars(cellProps.row.original.price ?? 0)}</div>
</div>
);
Expand All @@ -326,7 +322,7 @@ const FuturesHistoryTable: FC = () => {
<PNL normal>--</PNL>
) : (
<PNL negative={cellProps.value.lt(wei(0))}>
{formatDollars(cellProps.value)}
{formatDollars(cellProps.value, { suggestDecimals: true })}
</PNL>
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import ColoredPrice from 'components/ColoredPrice';
import Currency from 'components/Currency';
import { DesktopOnlyView, MobileOrTabletView } from 'components/Media';
import Table, { TableHeader } from 'components/Table';
import { DEFAULT_CRYPTO_DECIMALS } from 'constants/defaults';
import ROUTES from 'constants/routes';
import Connector from 'containers/Connector';
import { FuturesMarketAsset } from 'sdk/types/futures';
Expand Down Expand Up @@ -119,8 +118,7 @@ const FuturesMarketsTable: FC = () => {
accessor: 'price',
Cell: (cellProps: CellProps<typeof data[number]>) => {
const formatOptions = {
minDecimals: DEFAULT_CRYPTO_DECIMALS,
isAssetPrice: true,
suggestDecimals: true,
};
return (
<ColoredPrice priceInfo={cellProps.row.original.priceInfo}>
Expand Down Expand Up @@ -297,7 +295,7 @@ const FuturesMarketsTable: FC = () => {
currencyKey="sUSD"
price={cellProps.row.original.price}
sign="$"
formatOptions={{ minDecimals: DEFAULT_CRYPTO_DECIMALS, isAssetPrice: true }}
formatOptions={{ suggestDecimals: true }}
/>
</MarketContainer>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Currency from 'components/Currency';
import { DesktopOnlyView, MobileOrTabletView } from 'components/Media';
import Table, { TableNoResults } from 'components/Table';
import { Body } from 'components/Text';
import { DEFAULT_CRYPTO_DECIMALS } from 'constants/defaults';
import { EXTERNAL_LINKS } from 'constants/links';
import { NO_VALUE } from 'constants/placeholder';
import ROUTES from 'constants/routes';
Expand Down Expand Up @@ -71,7 +70,7 @@ const FuturesPositionsTable: FC<FuturesPositionTableProps> = ({
market,
position: position.position,
description,
avgEntryPrice: thisPositionHistory?.entryPrice,
avgEntryPrice: thisPositionHistory?.avgEntryPrice,
};
})
.filter(
Expand Down Expand Up @@ -230,8 +229,7 @@ const FuturesPositionsTable: FC<FuturesPositionTableProps> = ({
accessor: 'avgEntryPrice',
Cell: (cellProps: CellProps<any>) => {
const formatOptions = {
minDecimals: DEFAULT_CRYPTO_DECIMALS,
isAssetPrice: true,
suggestDecimals: true,
};
return cellProps.row.original.avgEntryPrice === undefined ? (
<DefaultCell>{NO_VALUE}</DefaultCell>
Expand All @@ -256,8 +254,7 @@ const FuturesPositionsTable: FC<FuturesPositionTableProps> = ({
accessor: 'liquidationPrice',
Cell: (cellProps: CellProps<any>) => {
const formatOptions = {
minDecimals: DEFAULT_CRYPTO_DECIMALS,
isAssetPrice: true,
suggestDecimals: true,
};
return (
<Currency.Price
Expand Down
59 changes: 33 additions & 26 deletions sections/dashboard/FuturesPositionsTable/MobilePositionRow.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
import { wei } from '@synthetixio/wei';
import Wei, { wei } from '@synthetixio/wei';
import { memo, FC } from 'react';
import styled, { css } from 'styled-components';

import { border } from 'components/Button';
import ChangePercent from 'components/ChangePercent';
import Currency from 'components/Currency';
import { DEFAULT_CRYPTO_DECIMALS } from 'constants/defaults';
import { PositionSide } from 'sdk/types/futures';
import { FuturesFilledPosition, FuturesMarket, PositionSide } from 'sdk/types/futures';
import { selectMarkPrices } from 'state/futures/selectors';
import { useAppSelector } from 'state/hooks';
import { selectPrices } from 'state/prices/selectors';
import { formatNumber } from 'utils/formatters/number';
import { getDisplayAsset, isDecimalFour } from 'utils/futures';
import { MarketKeyByAsset, getDisplayAsset, isDecimalFour } from 'utils/futures';

type MobilePositionRowProps = {
// TODO: specify type
row: any;
row: {
market?: FuturesMarket;
position: FuturesFilledPosition | null;
description: string;
avgEntryPrice?: Wei;
};
onClick(): void;
};

const MobilePositionRow: FC<MobilePositionRowProps> = memo(({ row, onClick }) => {
const prices = useAppSelector(selectPrices);
const marketPrice =
prices[row.market.asset]?.offChain ?? prices[row.market.asset]?.onChain ?? wei(0);
return (
<OpenPositionContainer side={row.position.position} key={row.market.asset} onClick={onClick}>
const prices = useAppSelector(selectMarkPrices);
const marketPrice = !!row.market ? prices[MarketKeyByAsset[row.market.asset]] ?? wei(0) : wei(0);
return !!row.position && !!row.market ? (
<OpenPositionContainer side={row.position?.side} key={row.market?.asset} onClick={onClick}>
<CurrencyDetailsContainer>
<StyledCurrencyIcon currencyKey={row.market.marketKey} />
<StyledCurrencyIcon currencyKey={row.market?.marketKey} />
<div>
<OpenPositionSize>
{formatNumber(row.position.size ?? 0)}
<OpenPositionMarketName>{getDisplayAsset(row.market.asset)}</OpenPositionMarketName>
{formatNumber(row.position?.size ?? 0)}
<OpenPositionMarketName>{getDisplayAsset(row.market?.asset)}</OpenPositionMarketName>
</OpenPositionSize>
<OpenPositionSide side={row.position.side ?? PositionSide.LONG}>
<span className="side">{row.position.side ?? PositionSide.LONG}</span>{' '}
<OpenPositionSide side={row.position?.side ?? PositionSide.LONG}>
<span className="side">{row.position?.side ?? PositionSide.LONG}</span>{' '}
<span className="at">@</span>{' '}
<span className="leverage">
{formatNumber(row.position.leverage ?? 0, { maxDecimals: 1 })}x
{formatNumber(row.position?.leverage ?? 0, { maxDecimals: 1 })}x
</span>
</OpenPositionSide>
</div>
Expand All @@ -48,19 +51,21 @@ const MobilePositionRow: FC<MobilePositionRowProps> = memo(({ row, onClick }) =>
price={marketPrice}
sign="$"
formatOptions={
isDecimalFour(row.asset) ? { minDecimals: DEFAULT_CRYPTO_DECIMALS } : {}
isDecimalFour(row.market.asset) ? { minDecimals: DEFAULT_CRYPTO_DECIMALS } : {}
}
/>
</div>
<EntryPrice>
<Currency.Price
currencyKey="sUSD"
price={marketPrice}
sign="$"
formatOptions={
isDecimalFour(row.market.asset) ? { minDecimals: DEFAULT_CRYPTO_DECIMALS } : {}
}
/>
{row.avgEntryPrice && (
<Currency.Price
currencyKey="sUSD"
price={row.avgEntryPrice}
sign="$"
formatOptions={
isDecimalFour(row.market.asset) ? { minDecimals: DEFAULT_CRYPTO_DECIMALS } : {}
}
/>
)}
</EntryPrice>
</div>
<div>
Expand All @@ -71,6 +76,8 @@ const MobilePositionRow: FC<MobilePositionRowProps> = memo(({ row, onClick }) =>
</div>
</RightColumnsContainer>
</OpenPositionContainer>
) : (
<></>
);
});

Expand Down
4 changes: 2 additions & 2 deletions sections/earn/StakeGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { GridContainer } from 'sections/earn/grid';
import { claimRewards, fetchEarnTokenPrices } from 'state/earn/actions';
import { selectEarnApy, selectEarnedRewards, selectYieldPerDay } from 'state/earn/selectors';
import { useAppDispatch, useAppSelector, usePollAction } from 'state/hooks';
import { formatPercent, toWei, truncateNumbers } from 'utils/formatters/number';
import { formatPercent, truncateNumbers } from 'utils/formatters/number';

import GridData from './GridData';

Expand Down Expand Up @@ -48,7 +48,7 @@ const StakeGrid = () => {
</GridData>
<GridData
title={t('dashboard.stake.tabs.staking.annual-percentage-rate')}
value={formatPercent(earnApy.div(toWei('100')), { minDecimals: 2 })}
value={formatPercent(earnApy, { minDecimals: 2 })}
/>
<TimeRemainingData />
</GridContainer>
Expand Down
Loading

0 comments on commit 4654486

Please sign in to comment.